From patchwork Thu Aug 17 11:17:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Eckert X-Patchwork-Id: 9905737 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 244376038C for ; Thu, 17 Aug 2017 11:27:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F27EB28A72 for ; Thu, 17 Aug 2017 11:27:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E770528AE0; Thu, 17 Aug 2017 11:27:13 +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 52CFE28A72 for ; Thu, 17 Aug 2017 11:27:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751666AbdHQL1M (ORCPT ); Thu, 17 Aug 2017 07:27:12 -0400 Received: from ms.tdt.de ([195.243.126.94]:52719 "EHLO mail.dev.tdt.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751626AbdHQL1L (ORCPT ); Thu, 17 Aug 2017 07:27:11 -0400 X-Greylist: delayed 596 seconds by postgrey-1.27 at vger.kernel.org; Thu, 17 Aug 2017 07:27:11 EDT Received: from feckert01.dev.tdt.de (unknown [10.1.3.40]) by mail.dev.tdt.de (Postfix) with ESMTPSA id C7EA321917; Thu, 17 Aug 2017 11:17:13 +0000 (UTC) From: Florian Eckert To: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org Subject: [PATCH 2/2] hwmon: (adcxx) Add device tree support Date: Thu, 17 Aug 2017 13:17:05 +0200 Message-Id: <20170817111705.24419-2-fe@dev.tdt.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170817111705.24419-1-fe@dev.tdt.de> References: <20170817111705.24419-1-fe@dev.tdt.de> 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. Set reference voltage of ADC with device tree property. If not set use default 3300mV. - reference-voltage-millivolt Signed-off-by: Florian Eckert --- drivers/hwmon/adcxx.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c index 69e0bb97e597..34e241ea86a0 100644 --- a/drivers/hwmon/adcxx.c +++ b/drivers/hwmon/adcxx.c @@ -4,6 +4,7 @@ * The adcxx4s is an AD converter family from National Semiconductor (NS). * * Copyright (c) 2008 Marc Pignat + * Copyright (c) 2017 Florian Eckert * * The adcxx4s communicates with a host processor via an SPI/Microwire Bus * interface. This driver supports the whole family of devices with name @@ -46,9 +47,15 @@ #include #include #include +#include #define DRVNAME "adcxx" +#define ADCXX1S 1 +#define ADCXX2S 2 +#define ADCXX4S 4 +#define ADCXX8S 8 + struct adcxx { struct device *hwmon_dev; struct mutex lock; @@ -159,21 +166,58 @@ static struct sensor_device_attribute ad_input[] = { SENSOR_ATTR(in7_input, S_IRUGO, adcxx_read, NULL, 7), }; +#ifdef CONFIG_OF +static const struct of_device_id adcxx_of_ids[] = { + { + .compatible = "national,adcxx1s", + .data = (void *) ADCXX1S, + }, + { + .compatible = "national,adcxx2s", + .data = (void *) ADCXX2S, + }, + { + .compatible = "national,adcxx4s", + .data = (void *) ADCXX4S, + }, + { + .compatible = "national,adcxx8s", + . data = (void *) ADCXX8S, + }, + {}, +}; +MODULE_DEVICE_TABLE(of, adcxx_of_ids); +#endif + /*----------------------------------------------------------------------*/ static int adcxx_probe(struct spi_device *spi) { - int channels = spi_get_device_id(spi)->driver_data; + const struct of_device_id *match; + int channels; struct adcxx *adc; int status; int i; + match = of_match_device(adcxx_of_ids, &spi->dev); + if (match) + channels = (int)(uintptr_t)match->data; + else + channels = spi_get_device_id(spi)->driver_data; + adc = devm_kzalloc(&spi->dev, sizeof(*adc), GFP_KERNEL); if (!adc) return -ENOMEM; /* set a default value for the reference */ - adc->reference = 3300; + if (spi->dev.of_node) + of_property_read_u32(spi->dev.of_node, + "reference-voltage-millivolt", + &adc->reference); + if (!adc->reference) + adc->reference = 3300; + dev_info(&spi->dev, "Reference voltage set to %dmV\n", adc->reference); + adc->channels = channels; mutex_init(&adc->lock); @@ -223,10 +267,10 @@ static int adcxx_remove(struct spi_device *spi) } static const struct spi_device_id adcxx_ids[] = { - { "adcxx1s", 1 }, - { "adcxx2s", 2 }, - { "adcxx4s", 4 }, - { "adcxx8s", 8 }, + { "adcxx1s", ADCXX1S }, + { "adcxx2s", ADCXX2S }, + { "adcxx4s", ADCXX4S }, + { "adcxx8s", ADCXX8S }, { }, }; MODULE_DEVICE_TABLE(spi, adcxx_ids); @@ -234,6 +278,7 @@ MODULE_DEVICE_TABLE(spi, adcxx_ids); static struct spi_driver adcxx_driver = { .driver = { .name = "adcxx", + .of_match_table = of_match_ptr(adcxx_of_ids), }, .id_table = adcxx_ids, .probe = adcxx_probe,