From patchwork Fri Oct 20 10:39:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Porte X-Patchwork-Id: 10019699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 27BF160234 for ; Fri, 20 Oct 2017 10:40:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 162CF28EC0 for ; Fri, 20 Oct 2017 10:40:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09EA128EE1; Fri, 20 Oct 2017 10:40:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28D4F28EC0 for ; Fri, 20 Oct 2017 10:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752917AbdJTKkP (ORCPT ); Fri, 20 Oct 2017 06:40:15 -0400 Received: from mail-he1eur01on0098.outbound.protection.outlook.com ([104.47.0.98]:52800 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752912AbdJTKkN (ORCPT ); Fri, 20 Oct 2017 06:40:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=EZwbDFDP83KwC5ole9uKTYaCpEs0uchFzPUfxDnZO/4=; b=V/ENmEFfSFhziXEUUfDZ5xBPKPcpW0xMIZZ1pRJ+y066BulgKAQ7QzBeBhd2nJrGHDRRO+7Qk0bKdGEA73iy8ZEAr5U7kdSkSIcRPeVhaxG/X1p1livfn4FB3GSBNfShQ2igmnWKRijyRZ5pwT8cDjPjHcIu+2/VDBJU4kmhzOs= Received: from AM5PR0701CA0067.eurprd07.prod.outlook.com (2603:10a6:203:2::29) by AM4PR07MB3489.eurprd07.prod.outlook.com (2603:10a6:205:b::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.156.4; Fri, 20 Oct 2017 10:40:11 +0000 Received: from VE1EUR03FT005.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::205) by AM5PR0701CA0067.outlook.office365.com (2603:10a6:203:2::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.178.2 via Frontend Transport; Fri, 20 Oct 2017 10:40:11 +0000 Authentication-Results: spf=pass (sender IP is 131.228.2.240) smtp.mailfrom=nokia.com; nokia.com; dkim=none (message not signed) header.d=none; nokia.com; dmarc=pass action=none header.from=nokia.com; Received-SPF: Pass (protection.outlook.com: domain of nokia.com designates 131.228.2.240 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.240; helo=mailrelay.int.nokia.com; Received: from mailrelay.int.nokia.com (131.228.2.240) by VE1EUR03FT005.mail.protection.outlook.com (10.152.18.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.77.10 via Frontend Transport; Fri, 20 Oct 2017 10:40:10 +0000 Received: from fihe3nok0734.emea.nsn-net.net (localhost [127.0.0.1]) by fihe3nok0734.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id v9KAdd3V000975 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2017 13:39:39 +0300 Received: from localhost.localdomain ([172.27.221.159]) by fihe3nok0734.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id v9KAdSsn000587; Fri, 20 Oct 2017 13:39:38 +0300 X-HPESVCS-Source-Ip: 172.27.221.159 From: Romain Porte To: CC: , , Romain Porte Subject: [PATCH 1/2] pmbus: added tps544c20 driver with trimming support Date: Fri, 20 Oct 2017 12:39:15 +0200 Message-ID: <20171020103916.3309-2-romain.porte@nokia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171020103916.3309-1-romain.porte@nokia.com> References: <20171020103916.3309-1-romain.porte@nokia.com> X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:131.228.2.240; IPV:CAL; SCL:-1; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(376002)(39860400002)(346002)(2980300002)(438002)(189002)(199003)(1076002)(68736007)(2950100002)(106002)(6916009)(305945005)(53936002)(86362001)(4326008)(575784001)(107886003)(6666003)(50986999)(76176999)(356003)(36756003)(5003940100001)(22756006)(47776003)(2351001)(33646002)(8936002)(97736004)(26826003)(478600001)(48376002)(77096006)(50226002)(50466002)(316002)(189998001)(54906003)(2906002)(16586007)(8676002)(5660300001)(81166006)(81156014)(106466001)(49486002)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM4PR07MB3489; H:mailrelay.int.nokia.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; VE1EUR03FT005; 1:6eIdEnKmU4rS9nC9fD4rVn6whhWwJm0b7kHG9sGjX5qsupOUTRbAtruzUjU0JBWfx22TzqSnFarTxhM/RSApm/rHApYfsJWNrmV2RTjkp4+5eHH8IBZUt20LmfKmsAWS MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 058c67d4-ab90-414c-276c-08d517a6f094 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(8251501002)(4534020)(4602075)(4627075)(201703031133081)(201702281549075)(2017052603199); SRVR:AM4PR07MB3489; X-Microsoft-Exchange-Diagnostics: 1; AM4PR07MB3489; 3:FmFDoRMMN7u55jvdDBRGyPQ3MXj/lILjviAfpmhsh2ARs0sqyQSxIbJczokV6HYmF3pvqCd7U/gxQ02oZps39ICizp4g9gIIBCCgG/yP3S0dZzr5XwX9nAjYkAU4ezCIAC4ZZ5CQG72qtsKxViKHXE3G+qMT4433809HzIHkYSpAlShhav430x/bQUYXxjZ2NKHv6FOY3Asd4Q0LWvx4Ap67GTIwwrQjwVpu1kIRun9bAqMxG/5Li4JZeq1lau3m9vV0eTInNrX0iFyft14mj7kcHYRaAMnC5h2dKOWs5i2uU3Pp6FGqt0yyP6twOYW3yLyrBNA879PZ/YOu+YQ75CUBRM4XbweM/jL+kXmvtbg=; 25:CvYnGCgvEgVeAqDFcef3vwYvJwPGrrQCd66eXUQ17NF1IZdwCW8YTLz9gV9c4Q2MLyiMNVI8lVM0Yxa4vGOd3HNZDtGsFeXmfVJdvRejMkhEXYtizanG3MIMDgVlCaAI8TQZipxL5T85+CtViunb1lVWE78DcIhpRvhUcibAvQCOj7d5Q/w0/0a6R5QEVEeSp3i6AzB9YuDIBeoNOfvYe7OrjvAQ0uz2E8UVWhbtel2urBjC+aEGmN5W2o89Kk0qoneTdIhq5TBp35xXXDAWZ86ZIWqmd7tbZGqwolWd3W3uf5dPYIJPvz3YtC5jwqeFW6S0FYG5SwNVbCMxJTp//+VDGkQzx6kDHzbalj/3+QM= X-MS-TrafficTypeDiagnostic: AM4PR07MB3489: X-Microsoft-Exchange-Diagnostics: 1; AM4PR07MB3489; 31:VuHr31x5yoBwG6iGJNsSrDar0oBK4V600VVMioRfeeiVsoFw9b7llTNgc+xj+NpX/TjDKrvPqgrob0gHzGvhqRn4IpIBkHnuj0RAN2pvVvCrXZ2JCWzgvLRJZQnWFrN3bJqCFatIS7a2bhcSL+5IKeqRPY3iUZ7A3dh3wdDjCuPMVr4knt/oqJr5t/o1l20gaVEYcSfEcl+RlxhgTxvW04z1kVLrJyoFMtDngLbpKXg=; 20:ezgspf+35ZG0Mp9SGpO5pghEHcJLK74HpN+7VFnMhn27NHs6rmOgOa7U4NtfE6b3B0ikNCBulj1UMqew+IB/iJ/Ano1CM6Qi9Z03HrXjWgMBDLtl46HNNun24ibe4PonjZy8cMZ++tnEf0+FDnv1DNihylHfiq3d+V/Am+pD0N4DTTSv1hREQcAb+VmZUmxw3IsgJrb494E0qIOOtWkFnUVVD8c+7o3f8Tqd8e1gG3QucU9B+4pWLpnYGUs9bSXbkC4rytJcHY0DKeFD1TvMGjcQ+zo7gOtLrPcR31MXZEUn+6swbuYUVmU2Frjh+G5sCQU1Up3p7KI53cv4Po980WUN10UfmZ0H7TUV9F/fSimazfFFRa+ywSsuSbP8oPsUGmBTuNBdGr2EvMe9yfhbooznlVMKiXx9feqpitD1MN7GZqPSspRLqrQeLK+uDM+5UDvUH6OSHek9q7PrxCVbxIU2fiNBZqTFIpcK0gMqMkWnSNHOXJwC3+0FBWaSIiKNCRCjbsedEhithW2y/PR6TfY7rOgyQ7C8riT4u9z3CwU4y7MxT1+cKsQ8vZA6hIBLWPY5lTGEoHvQM4yYaTcaqMFQvLuOLGuk1oRc0YaHYN8= X-Exchange-Antispam-Report-Test: UriScan:(72170088055959)(82608151540597); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(3231020)(3002001)(10201501046)(93006095)(93004095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR07MB3489; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR07MB3489; X-Microsoft-Exchange-Diagnostics: 1; AM4PR07MB3489; 4:r+8lgLR+OvmWLOB59mmUHrDrrXue8hnuiYLCrRIFZYkf2YQKB5tRwQ8z4WGgQziVCrmh7d+QaFhydWpXSnhNRoTL7SDjKXNxyfnbdmKGFTqNbBZHtACXYg4dNlza0qGeRGeo36m5AaL6KsOs8hEn8JId9+FRTsg+XOIAwoK4vQ9HOtPYVpFp+8YkW4ba42lSw7hBoCQBK2ItPxarEaWoSBcF5DM0bABLzNKIJktt01D/6yho2QJWB/KH76m38Pq13eIgBxlQKOn3mdMgnD37x9S18aMedbrJm/Oh6HjXtP80y7oYSolKAxybo8/hxn6k+CaolaP1BzrXH/j6lMG1Jw== X-Forefront-PRVS: 0466CA5A45 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR07MB3489; 23:LDGYeYv1+rf7Lv6/1Y+JZrvidWONPDe013EGgFPm/?= =?us-ascii?Q?QMx4bDOKrqdlQBrp3RlhnIb2t55qpp/aGPZFpND/q1FQbWJ3VwRA1we7KHQw?= =?us-ascii?Q?TwjXTjd6MuWmpMhmHOF1mV91qCjIJIoRRHwpCt40EOjN3/+O4QfjgwmWONB4?= =?us-ascii?Q?JodLlD/tnwKjWdZy5Ah+zKICAQ41qssnBq1Exw8qiRKZPdfD0REO87vHxIwO?= =?us-ascii?Q?kjs9mRtUbhPGCArMk3rPjSVK7ki2VbOeUFmuowhBv97ej/jm8ovC5I2HzM+T?= =?us-ascii?Q?FmGo8HmG7wu2tZpNdJEs1VnD2v7/aEIgRwvqOknEv5J84JcfJTZMHdHRqVVq?= =?us-ascii?Q?2SYxUPwwsxZOagPLrXiFACBvraz9QAew4MsJItKX20vyeCxtD0C2YBnHb9Ch?= =?us-ascii?Q?Tw2RjatPsB4/5nlaEUMyLx7IDI7M8nImZpyouBHl38x1kzb/a7w+k62X1kqT?= =?us-ascii?Q?Hq/2ufXQp0i3qKUIwk2V/A2AqghONxIsF7Tp9ZporJVNmRnfxrMjqc9W0tCp?= =?us-ascii?Q?2oNftDrT+oBnO0SvVMvU1fJkBarUsiVTIU5+r2MW945QmgnzF+aDxnnNWvkg?= =?us-ascii?Q?fB3jL35M5i2QXaWoKm3dvzXodVT7P2tozVT/xXtlM377Xn4o0SSkbAdb9UQd?= =?us-ascii?Q?snabZggXVKnnhhGSJusRU0tLn3byh34MyYeUoyUFacXwwNB/AStJ9rZJd2CZ?= =?us-ascii?Q?REwnCuF9GB+h6eYs3olQ2Pnl8iJD08eMR/GVP4DgZWNLLpHFD8MC1BJQcpmw?= =?us-ascii?Q?LzoVbGp7nfedUrG7GTnF9WkSDj4ZPkg3jZU/WfQjiMACfXZxkfl/CM4sOOit?= =?us-ascii?Q?1y912YX5S33bnEPdCvaKpL5mompRb1QNK0vdvZ/VidNVF6ookwxcsLsLTezM?= =?us-ascii?Q?P2SLe4Rs7rbJwvAzqMZCMpXeyYzOtc9uGz1ZLySZnr2yHJsTtpenR4DfYI44?= =?us-ascii?Q?iQkmyRJTD9mm57EFlkgHEKY1s8mrRMG04W5+xHIV2dQSY+Dyt+J2EMaU3HD6?= =?us-ascii?Q?A9cMypMf9vEvhjls8TAAYhXNt3IFrIUxn8qtilH99QUB4QaHx9oSNPQk5kV/?= =?us-ascii?Q?75qmFOyU9nVLv4I3W5AooNOxo/fBRuuDulcuiv0RW63xUx3f12eoE1vsMKMW?= =?us-ascii?Q?ZwR25e+De1yE3Yj37b1UDOuqMhwZFEZ0/sJMOgEr74RVUrMj1jM8A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM4PR07MB3489; 6:P04t3ZRTpF80A600H7rNT4jVSLbVD5WeUlOxP81/mqkBMDDXp+saMomP9YOskqRzMNV72rwlhynrQc6jkAnIw8U/pspC/Xe9ItXriD2zFJaGBShjl4xo6k9SOMoKnBE91CSxWw4rIEQ51dIdzlSSELLYOe2KXx9bbnjOnegXhTbqXxyIy7rPalu1dI8TG9P7k1Kt15foCRzRjF6u3yrVSzuKmJBRK8Gca/4P5mTQFUzdVGZNe3RIIetKz/P7rKAClh/BwIpq+rVjWmsbXuKcn6UZKwcxPMfyyj7bCSQoankY+woLHg5O1q6MGeD7wmIcLiWHXm8JhjBLu1WKRtgMYQ==; 5:vkv4BJo7NPt6WkcF9Nb8gXCh9ahWQ9GDdzyA3E5ySDOFap9PVusaj9W6T6Gqa9skliVb83etSeEpMl1Ob6EGKeVjweDqxR/GsYM3RKJTKR7Sbzt1w+CsVJPKBaNMjiL/ACfRH8Y1W4dJVdq9G55uxw==; 24:XJKbFkEAH6Y5e3IkICS+3WnFFQSU5iH9fztQEa4AKh3TfY1JdtN8VLLW4wizP1N8xMt+CxLLslWJ4oU1llT/sy7J1+JCj8gPdOwk/NHRqfI=; 7:6BOtfaOL8dPD+wQW12VQgZkjDSkHRPFKENnngKNxH6QSgy8gMDmU5QD8A2FS9Q08QbSPJWegNw4mtc0mbrr+daK6SanBnDr+fMvahfcvCyIGY5xxXlwjx11ZH0hdQL2XqhjzGyk0iY5m/6LqwogbdBa+6QKWEN6JdDhyDa0FSDvJNaKG44zWRAboVBMTmloOQlxBsY8lAOvxzZGql8Oc8qH48FarjeQ3N0niDxY87R4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2017 10:40:10.9013 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 058c67d4-ab90-414c-276c-08d517a6f094 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.240]; Helo=[mailrelay.int.nokia.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR07MB3489 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Trimming is a manufacturer-specific command provided by TPS544C20. Since there is no generic interface for trimming yet this patch proposes a new driver with dedicated sysfs entries for trimming support for the component, according to its datasheet. This allows users to access the VREF_TRIM and STORE_USER_ALL commands. --- drivers/hwmon/pmbus/Kconfig | 10 +++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/tps544c20.c | 164 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 drivers/hwmon/pmbus/tps544c20.c diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig index 40019325b517..6f46e17d2004 100644 --- a/drivers/hwmon/pmbus/Kconfig +++ b/drivers/hwmon/pmbus/Kconfig @@ -153,6 +153,16 @@ config SENSORS_TPS53679 This driver can also be built as a module. If so, the module will be called tps53679. +config SENSORS_TPS544C20 + tristate "TI TPS544C20" + default n + help + If you say yes here you get hardware monitoring support for TI + TPS544C20 with trimming support. + + This driver can also be built as a module. If so, the module will + be called tps544c20. + config SENSORS_UCD9000 tristate "TI UCD90120, UCD90124, UCD90160, UCD9090, UCD90910" default n diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile index 459a6be3390e..5b8e0a37551a 100644 --- a/drivers/hwmon/pmbus/Makefile +++ b/drivers/hwmon/pmbus/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_SENSORS_MAX34440) += max34440.o obj-$(CONFIG_SENSORS_MAX8688) += max8688.o obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o obj-$(CONFIG_SENSORS_TPS53679) += tps53679.o +obj-$(CONFIG_SENSORS_TPS544C20) += tps544c20.o obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o obj-$(CONFIG_SENSORS_ZL6100) += zl6100.o diff --git a/drivers/hwmon/pmbus/tps544c20.c b/drivers/hwmon/pmbus/tps544c20.c new file mode 100644 index 000000000000..241c030fc216 --- /dev/null +++ b/drivers/hwmon/pmbus/tps544c20.c @@ -0,0 +1,164 @@ +/* + * Hardware monitoring driver for TI TPS544C20 with trim support + * + * Copyright (c) 2017 Nokia Solutions and Networks. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include "pmbus.h" + +#define VREF_TRIM_ADDR 0xD4 +#define STORE_USER_ALL_ADDR 0x15 + +static struct pmbus_driver_info tps544c20_info = { + .pages = 1, + .format[PSC_VOLTAGE_IN] = linear, + .format[PSC_VOLTAGE_OUT] = linear, + .format[PSC_TEMPERATURE] = linear, + .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2 + | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP + | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, +}; + +static ssize_t show_vref_trim(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret; + struct i2c_client *client = to_i2c_client(dev); + + ret = pmbus_read_word_data(client, 0, VREF_TRIM_ADDR); + if (ret < 0) { + dev_err(dev, "error reading vref_trim (%d)\n", ret); + return ret; + } + + ret = snprintf(buf, PAGE_SIZE, "%d\n", (int16_t) ret); + return ret; +} + +static ssize_t store_vref_trim(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + int ret; + int value; + struct i2c_client *client = to_i2c_client(dev); + + ret = sscanf(buf, "%d", &value); + if (ret != 1) { + dev_err(dev, "bad value, please write integer\n"); + return -EINVAL; + } + + ret = pmbus_write_word_data(client, 0, VREF_TRIM_ADDR, (int16_t) value); + if (ret < 0) { + dev_err(dev, "error writing vref_trim\n"); + return ret; + } + + /* Delay of at least 15 us/mV of change (0.067 mV/us), lets wait 10ms */ + msleep(10); + + return count; +} + +static ssize_t set_store_user_all(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + int read_value; + struct i2c_client *client = to_i2c_client(dev); + + ret = sscanf(buf, "%d", &read_value); + if (ret != 1 || read_value != 1) { + dev_err(dev, "bad value, write 1 to store. abort\n"); + return -EINVAL; + } + + ret = pmbus_write_byte(client, 0, STORE_USER_ALL_ADDR); + if (ret < 0) { + dev_err(dev, "error writing store_user_all\n"); + return ret; + } + + return count; +} + +DEVICE_ATTR(vref_trim, S_IWUSR | S_IRUGO, show_vref_trim, store_vref_trim); +DEVICE_ATTR(store_user_all, S_IWUSR, NULL, set_store_user_all); + +static struct attribute *tps544c20_attributes[] = { + &dev_attr_vref_trim.attr, + &dev_attr_store_user_all.attr, + NULL +}; + +static const struct attribute_group tps544c20_group = { + .attrs = tps544c20_attributes, +}; + +static int tps544c20_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int ret; + + ret = pmbus_do_probe(client, id, &tps544c20_info); + if (ret < 0) { + pr_err("error during pmbus probe\n"); + return ret; + } + + ret = sysfs_create_group(&client->dev.kobj, &tps544c20_group); + if (ret < 0) { + pr_err("error creating sysfs\n"); + return ret; + } + + return 0; +} + +static int tps544c20_remove(struct i2c_client *client) +{ + sysfs_remove_group(&client->dev.kobj, &tps544c20_group); + + return pmbus_do_remove(client); +} + +static const struct i2c_device_id tps544c20_id[] = { + {"tps544c20", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, tps544c20_id); + +/* This is the driver that will be inserted */ +static struct i2c_driver tps544c20_driver = { + .driver = { + .name = "tps544c20", + }, + .probe = tps544c20_probe, + .remove = tps544c20_remove, + .id_table = tps544c20_id, +}; + +module_i2c_driver(tps544c20_driver); + +MODULE_AUTHOR("Romain Porte "); +MODULE_DESCRIPTION("PMBus driver for TI TPS544C20 with trim support"); +MODULE_LICENSE("GPL");