From patchwork Wed Feb 15 12:45:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Franchi X-Patchwork-Id: 9573987 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 391EC600F6 for ; Wed, 15 Feb 2017 12:44:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F2582842E for ; Wed, 15 Feb 2017 12:44:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13B6C28481; Wed, 15 Feb 2017 12:44:44 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 5888A28480 for ; Wed, 15 Feb 2017 12:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751609AbdBOMom (ORCPT ); Wed, 15 Feb 2017 07:44:42 -0500 Received: from mail-by2nam03on0054.outbound.protection.outlook.com ([104.47.42.54]:28980 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751412AbdBOMok (ORCPT ); Wed, 15 Feb 2017 07:44:40 -0500 Received: from DM5PR03CA0002.namprd03.prod.outlook.com (10.175.104.12) by BN1PR0301MB0723.namprd03.prod.outlook.com (10.160.78.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Wed, 15 Feb 2017 12:44:38 +0000 Received: from BN1BFFO11FD047.protection.gbl (2a01:111:f400:7c10::1:172) by DM5PR03CA0002.outlook.office365.com (2603:10b6:3:118::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.919.13 via Frontend Transport; Wed, 15 Feb 2017 12:44:37 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=fail action=none header.from=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1BFFO11FD047.mail.protection.outlook.com (10.58.145.2) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.904.16 via Frontend Transport; Wed, 15 Feb 2017 12:44:37 +0000 Received: from b58965-3.am.freescale.net (b58965-3.am.freescale.net [10.29.244.100]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v1FCiYvP028541; Wed, 15 Feb 2017 05:44:35 -0700 From: Marco Franchi To: CC: , , , , , Marco Franchi Subject: [PATCH v3 2/2] hwmon: (sht15) Add device tree support Date: Wed, 15 Feb 2017 10:45:00 -0200 Message-ID: <1487162701-12097-1-git-send-email-marco.franchi@nxp.com> X-Mailer: git-send-email 2.7.4 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131316362776679684; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(336005)(39860400002)(39450400003)(39410400002)(39400400002)(39380400002)(39840400002)(39850400002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(38730400002)(54906002)(97736004)(5660300001)(92566002)(81156014)(4326007)(81166006)(50986999)(6666003)(8676002)(47776003)(189998001)(85426001)(110136004)(33646002)(48376002)(39060400002)(305945005)(2351001)(50226002)(50466002)(8936002)(86362001)(36756003)(68736007)(626004)(106466001)(6916009)(2906002)(5003940100001)(77096006)(8656002)(104016004)(356003)(53936002)(105606002)(389900002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0723; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD047; 1:lLPwrzho7Ren7QUgQ7YCwReYq5IfFAR90talovc2vbCOUykFjKdhiHSVM/iyBcBKAyY+VkD0OV4ZEYOFdLBoQOTA0GpDcW/AxBrDFDEE8AwN4FV/XObvFKYXDegeWBUbzJ/m/a46JqMLsv7rkBQw3lcUSD0Z+FzlRbKJmLqlivctCBjNYlOwr7sL3NjDaqkPjMr5F3OPNAxWV0VDxPkrh7rOpGjypfShfc/TtvVb5ZTycrpbiMaVfqvv3TaHIzv4pJ1cOYiObUmUOiFvaMipkCdjzRAVSRptDZncSnCXTN3eq2SJfjj2aYJV3p9gagDPk9Zjr3RAhVS305OVRddy4jDUwbVpvQvMqkeD6M3Bdx19gMevj2WqPZMdWH15PFW5B2hZNeKA/4E0a31IIw9eGX9QXKqyJfWnjQjtoFioa+fIwL+n1leFnXfDpf3VCyHDpB8nc19Q7M2CMF+V2XbOS9LzdCRpX0HEk6WI/3ReBVkUEoxxAoO6c7weQbEqlCBr/VTnlxGBZNnWXgXTUpKujojWw27VqTUAQRUXuH/g/3C0BO3HP94edletYe2JnEGer19jrBoPY7A7LRdojpcAQNX9SPsCbgbXNZmL/4+MSYkfQ8t8VsvkMA+azUo6Xq/LI3LyXw6ehOwssHQ3bAOQ1VNS7gDtdJAhyOcTrkoH9XLVJnDrzN//vjQnS2kjrExcaTFSSax+Tbjjqo8xS3KKKQ== MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: cb5ebd4d-2423-4b01-b3a6-08d455a066f4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN1PR0301MB0723; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0723; 3:0JgoGsy/+vnamrTclaM3F6r7PP35KQBQ6es//Q7Aanub40cqrKk2MtVExiDmOBrGlJXRnAb3GA6ga8Y1xp5MDmD2r4GsL/rEdT7HKi/0H/5jCEaYTfYi7/PuEMz1ulg7NnzBdbZ9FuDNFM2lo7DIuMA9VlI5gDFotc9cmaY1kzz+K18KsKYgO/UZvgZ/g3ZIaqR1yUYDRx56DaGXv/bf3D9K4bvMB7uMlH/alMAAVSDVGyHKPOV6zL7l+ica8kJ8Jlfg6mVhwql6jeKbs/EOE/m4CuqytFuF6EWrdz/pcjdugcHDYfVjutFT4nska16cKZyfnohLCWJMh8VcAiBkDuKYoT3TscsziEkz64hDnO/lI07vsSBeBcUE1kitfYFK; 25:zLV8VT5eLPWmYl5br7TtbZLQd4ucnNOKHO5RSsWiYbOIGbBcecZGLolvo1bm5bCsECBkKlGRSQagMc4nsWejdyUl15EA7wgH82nvPfDB5V0sr8aJpzCYaVGk+rIehUSSmpsA9hQ0prxGq+0R6cXRdcWF9WFCCJ6gmt9KEqeNnGtuBDPhQTgOa+a3mGdVbnqP0uFGtC3p7/Mq+meDkugQeCsxu/6T9DXCI28s2t8v2B+9T/YNfdvsuqZ7VSirzS2c8rLl3HoFzf4GwB+4ycenfYG5qjkl6NK4CVXy0CYuZYbss6ZD6uUXo2+pDZAEdKACUhVy5G3anAnit+bZs4isf3oBe3D3qODqqmX9sByWYJykN6hGZvG2PFjpol0CTlp8PLRvlum9SwF6u2zfvfKT622rKVSf1FF7weEnqYrYf1OIRraqZ6xIal2yTFHXeAoU6EHOJgn6d1uaIkh09PrznA== X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0723; 31:w/Mk7mumw11Wtb7UceqFGtVh9nrpa30DDI1HEsKZW89X/LnP6rQSWxTazL3iT7ny/RLBEEG8Ma4Zrm8yaa+j/qqLBFTW8CzEPKPDO3bz2NQoIpYTvWJoOPYfNxTS8zW6rEmynTf1vUTtRAYTdOY7M3K/kUZv1wccG4R9vKEwmHzr7LvQ8vq2eVEzPqo+zztRfcGQZWHTnlqBnr9ILJK8/vhBgQ9YPF/tiwfRrXHnErLOo2wwIOHDLXttq+rsFjPx1pRmIaz7K+5as8IxxeO9oA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(13023025)(13015025)(13017025)(5005006)(8121501046)(13018025)(13024025)(3002001)(10201501046)(6055026)(6096035)(20161123563025)(20161123561025)(20161123556025)(20161123559025)(20161123565025); SRVR:BN1PR0301MB0723; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0723; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0723; 4:2ycPNNfGDT9wS9nnqDYbCpmRHxIaye3OsAxQcmW4LoxPMBNuirVotXvVy5Vie5BLIMBWqsMpeOasiRU5CZ/vOoQjnEo8IQHugMTplfuTtb97bbP/u4n6rYivflA3ke5VKt31FT3A3YYeQDrFfsZJzkS0AiLoFwKNwWUybBOgh1hchB+O3D8blh1v/uwgKH8uyfqnpeZo8er7ZoYWmm0G9s9DlL/HPCEhRAQYBIJCPPVU02cxK8Bq/XYOLBb+6ZSWYPCAfBS0owdgPSuYgipTiaxWyG6KefUzdtqSUzS+0Kl0p93C52Hk4zPPnV+72F4GGZdyeevghGmRkoGCKaP98sA8FQoS8SERZAc5vR1D9wU3INm5baDV13Hf/pQ6wsh2F2ma5WLMpzoHGoGknncZ2M1cUspGulr8ZZf5IPed/d8eMPX4XXDoEDGC5pFiEIbbDG0pFU8FnjSFSx4G5Vi426pWoK9wF0OslAT31G6vgOxLmZzVyb8hehbb+7LNQ43XsVoL8d1oWlm6wOaSpOn+9MQOYNOW7KNtu6UiaV3M6fddkvb32hpjDfaAtB824wdImnFC5xyWLfpZdMi+6G0zT2ichpp9tQ7RIOXFatDswF7VP4/0NHlcl6eFDmC9Ztx99uPhV1kX/Jlt4BoLLhNt49P5XgyvaIDWCspZpQE9VIhCJp/4JfE4piclmfJuy3rcvxy4Z02UBBd0uFpsF33+zMXy1gf5ZGS1kBdKFuXOPzTU23dESFiy51LWftA4rpYZ X-Forefront-PRVS: 021975AE46 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0723; 23:Y01bbuKxpupFFJAhPbsC943nwVfV8zwo2dzcHgy?= =?us-ascii?Q?JczXy+Ia2SwAjQmwrUJOHHqL6BfSyyCcFSYKzlQxvqExBBP+SO8IR+TVguy3?= =?us-ascii?Q?zQDhOX5uZbnIwpI35nhtB4wx4QJnq4+hjtUUQ74QnYPxEehIuR24Y8+j6o52?= =?us-ascii?Q?s55jr9+soLlvpwY8kXhGwRO97z+8JjN0CANnI+B+7rF9UYmH734TjGVD35th?= =?us-ascii?Q?faqykSy6i/QKpc3sMQo6U6tcfJXS8M4moPpaxXWO/0v8dvjQv1gReIRwtrPC?= =?us-ascii?Q?h5VPCqmcxAXaMEO5DcniPUqodiWQEcT3yRV1OOCBjuFili6BdREKMls1uBDF?= =?us-ascii?Q?NQQzUpQ9vEpbrfE/vkYHHZ1GcTkCDJiuS8pKDqSPeiJNqeBidz1Yx1SHrXAw?= =?us-ascii?Q?tNx+8SU1q78X5/GooAH3B+IRN96GeiD4usXk8T+c21z43ZcRqx272Y3sDaUt?= =?us-ascii?Q?I7pI+sMbW+KWSHIpS6d5+TcOj5C7HoRGXQBSGZZqh6Z3XBqU8mcq301C+Lfb?= =?us-ascii?Q?FZp6haRHrbnAzP3D8K0CK1w0l1IwQCXO4OIE6FlcvMcEkHHD9ehulLN7I0eF?= =?us-ascii?Q?oX7AuqH0yHLhhTCmoKr3EAtPUIoY5ShKzFxklozxGYwGZOSEB6qD7ZbK6k72?= =?us-ascii?Q?MYxoYySL6MhnVE78A6eMvXIfGaEH7yGgWFqLdfgdleWCjD/I+5JSNwQ2nCO0?= =?us-ascii?Q?1cSPuogwCB2AIHp3XcnFucXHVUZKyCU90PrJlMo3pqqQetWqAfg+wCXyGxFn?= =?us-ascii?Q?jlR3kddqdX6apTQun5PI5djaudohaFw+oGuDohlPhf7LaOPe5ACpZJEBZQZO?= =?us-ascii?Q?dfk+QB/bpXH71S//wZ08Hb2564pZQRgB8ejhbxvrUxI7NhvnC76Owo3ogErs?= =?us-ascii?Q?1K+ckGLkzDGPS9HcKNyn/brIKdH/OKf/jNl8oxK82ZyfQBq7ViS3uXYaJqiE?= =?us-ascii?Q?4wb9oVt+NudLzvVp0s/c52KobBMPu6x1hIRvDzr5zZIbSGt1PcMSlCMa+GWQ?= =?us-ascii?Q?559ak911UP0+vExBDvmBu3BJMh9hgtiC2e96385uxHs7ZZA7pm53dE+CWn+h?= =?us-ascii?Q?f9DWu8iPs0dxRZPxqbWSkfMkqmgvnanD4p1LIsL4vNntPRc6oRpnx0Pw9LiG?= =?us-ascii?Q?Et+ZOfNwXABGADN9m0cZ1w1r8Df9hi0xnG0SjyD8+U6q4IOK6+2C2xrL4JgF?= =?us-ascii?Q?Ql9MST43bGbZFel/GA5iZK5F7ylFauqL6xl4E9gbdO2svAXZ9Ubai+RNp32o?= =?us-ascii?Q?DUTEysujRqu85M2RiUOj3TfYbrbxIy0as3NAeiX2EDcVbTEqc4YQRTPpzKiS?= =?us-ascii?Q?iijM4BmQy91HHkyrI1o+/du8=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0723; 6:B49IJERz2M6U7ltij5bp/4p+jpaTzXajYOGlRYi8vVU6Fda1/FhpgO2PA4tteFuZUulRcFcNHENQofiXDtpZbuu9QU4hKeAOIBHvzCMRa6nmfRf37YsDNaGYw90DwahtBA8IiulDSuinZYEn3YUNyDhcXclaLRoqVTz+4C7SYksB3oaJZFVuFhMOPZx5XaH0le/xd75+kYK7EbHs8Esqp+s57X3iiux8+9vxjFnPTTeS8DxZloBRjFdD4YbEapF2iQYpWqZB4Nqz4IUPZ5FzMGR3brCaktKAwHEbOPFkUKAQJw498NaZ5AjBgIyb+y7+lLDr0/ZuKSBC/cgOPI23pGgBiZjXzqwzMkHdNbs54gwDa82ew0Yu2W2QIT+iiYsjVkH4dz7h6XKXAJEyXDGO/1fm3C2L3DRfO40Qd8nkInk=; 5:S6zybTsClRUqD3VJ6QOJvKctBcSwak2izR3B/LXp39+P8UlbpT/niwnLV7rwdlQdphejBCe+DZsFnIjSBnKAgcoaL9zvATRDVnqawEFm9go0EWdqd+FkWpuuDC+p8cMChmAQE6OgqerEAl+yiNn6OsVdaqmCWE9IFYzLtFZtsDI01FbszmRvxuSa3Kw27qTc; 24:c7gleh5LtvTuvIrugPwAFZ+k9LqQbHtG5j83NzYGnhFSmc23lOgk8gU44bdvy7tBZNKDREXX2vUBG3u7EkVpaMnnjVPgLJjJ23p3jpkm/7E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0723; 7:+hkUi0QfdIMY3PEsYIDs/8X1edOw9D/Zh7ILZzKgovWBBtV3cgBVTzy5laHwMsJUdPeLOxxjfvitTmhTzhUu61Juz0iQvPLKp5Hp6gWgej52diovfPiEJh35CaXlmCfI0oAlML1fWl8qtCBq3r+JCg9mkICmphL81ZgWEO97BmMajefmK5A2i4alBijjItJtzB7dWQUQpb3mNYL2A3HeQ90eerW8JEp21riUsWgKSWP6MPrv/D57FMw0Fvze/vgD0eUY32xbMvTNPUtxGwvF39cq4+3ePcqAwiDQSh9pApeWSkUQb2rOdb0c/5wX6POlScMB1pJGrZ5FWiIi2OO+qA2IqJNnSv10EjWi0uxLyFMu3yJn53MckXZVPfvTDremjz6bXz66zhYbUjFTd5LU8jwr771INXogro0hwoyuIpw+53+FiQ/n8TxwU4DSX4olEvDKefcwpgDKMesvBOeab7mC1I58il4YRFaCLpS87/xeCpTr9HIUJhCBVBoQEHek3OFIiH/OZPpCda0slOt4fA== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2017 12:44:37.4651 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0723 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 Allow the driver to work with device tree support. Based on initial patch submission from Peter Fox. Tested on a imx7d-sdb board connected to a SHT15 board via Mikro Bus. Signed-off-by: Marco Franchi --- Changes since v2: - Propagate the real error code when of_get_named_gpio() fails - Do not print error on EPROBE_DEFER case - Changed the sht15_probe_dt function comments to be compatible with the returns values Documentation/devicetree/bindings/hwmon/sht15.txt | 25 +++++++++ drivers/hwmon/sht15.c | 68 +++++++++++++++++++++-- 2 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/sht15.txt diff --git a/Documentation/devicetree/bindings/hwmon/sht15.txt b/Documentation/devicetree/bindings/hwmon/sht15.txt new file mode 100644 index 0000000..ddbc5a9 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/sht15.txt @@ -0,0 +1,25 @@ +Sensirion SHT15 Humidity and Temperature Sensor + +Required properties: + + - "compatible": must be "sensirion,sht15". + - "data-gpios": GPIO connected to the data line. + - "clk-gpios": GPIO connected to the clock line. + - "vcc-supply": regulator that drives the VCC pin. + +Optional properties: + + - "checksum": boolean property that when present enables the CRC validation of the readings. + - "no-otp-reload": boolean property that when present indicates not to reload from OTP. + - "low-resolution": boolean property that when present indicates that the device operates in + low-resolution mode. +Example: + + temp_humid_sensor: sht15 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_sensor>; + compatible = "sensirion,sht15"; + clk-gpios = <&gpio4 12 0>; + data-gpios = <&gpio4 13 0>; + vcc-supply = <®_sht15>; + }; diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c index f16687c..7f86ded 100644 --- a/drivers/hwmon/sht15.c +++ b/drivers/hwmon/sht15.c @@ -34,6 +34,7 @@ #include #include #include +#include /* Commands */ #define SHT15_MEASURE_TEMP 0x03 @@ -911,6 +912,58 @@ static int sht15_invalidate_voltage(struct notifier_block *nb, return NOTIFY_OK; } +#ifdef CONFIG_OF +static const struct of_device_id sht15_dt_match[] = { + { .compatible = "sensirion,sht15" }, + { }, +}; +MODULE_DEVICE_TABLE(of, sht15_dt_match); + +/* + * This function returns NULL if pdev isn't a device instatiated by dt, + * a pointer to pdata if it could successfully get all information + * from dt or a negative ERR_PTR() on error. + */ +static struct sht15_platform_data *sht15_probe_dt(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct sht15_platform_data *pdata; + + /* no device tree device */ + if (!np) + return NULL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + pdata->gpio_data = of_get_named_gpio(np, "data-gpios", 0); + if (pdata->gpio_data < 0) { + if (pdata->gpio_data != -EPROBE_DEFER) + dev_err(dev, "data-gpios not found\n"); + return ERR_PTR(pdata->gpio_data); + } + + pdata->gpio_sck = of_get_named_gpio(np, "clk-gpios", 0); + if (pdata->gpio_sck < 0) { + if (pdata->gpio_sck != -EPROBE_DEFER) + dev_err(dev, "clk-gpios not found\n"); + return ERR_PTR(pdata->gpio_sck); + } + + pdata->checksum = of_property_read_bool(np, "checksum"); + pdata->no_otp_reload = of_property_read_bool(np, "no-otp-reload"); + pdata->low_resolution = of_property_read_bool(np, "low-resolution"); + + return pdata; +} +#else +static inline struct sht15_platform_data *sht15_probe_dt(struct device *dev) +{ + return NULL; +} +#endif + static int sht15_probe(struct platform_device *pdev) { int ret; @@ -928,11 +981,17 @@ static int sht15_probe(struct platform_device *pdev) data->dev = &pdev->dev; init_waitqueue_head(&data->wait_queue); - if (dev_get_platdata(&pdev->dev) == NULL) { - dev_err(&pdev->dev, "no platform data supplied\n"); - return -EINVAL; + data->pdata = sht15_probe_dt(&pdev->dev); + if (IS_ERR(data->pdata)) + return PTR_ERR(data->pdata); + if (data->pdata == NULL) { + data->pdata = dev_get_platdata(&pdev->dev); + if (data->pdata == NULL) { + dev_err(&pdev->dev, "no platform data supplied\n"); + return -EINVAL; + } } - data->pdata = dev_get_platdata(&pdev->dev); + data->supply_uv = data->pdata->supply_mv * 1000; if (data->pdata->checksum) data->checksumming = true; @@ -1075,6 +1134,7 @@ MODULE_DEVICE_TABLE(platform, sht15_device_ids); static struct platform_driver sht15_driver = { .driver = { .name = "sht15", + .of_match_table = of_match_ptr(sht15_dt_match), }, .probe = sht15_probe, .remove = sht15_remove,