Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8046010imu; Thu, 15 Nov 2018 05:51:27 -0800 (PST) X-Google-Smtp-Source: AJdET5dzxyAMWgRMoaBhxfRVlwxa1l/xadYDVNbl8UlENHvDp2Js46MPtxuHFfYo/RJfHtIcxZwn X-Received: by 2002:a17:902:d806:: with SMTP id a6mr6139752plz.172.1542289887290; Thu, 15 Nov 2018 05:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542289887; cv=none; d=google.com; s=arc-20160816; b=skHfCTZkhDgs6ZADXhQEEcxZtmIsxtxnmm18EgvZQ3fhTWDRfSE6NHkI4d7VtWY9o/ RjTOWNfWzzP/f72kHII01Oh0c1qzkNJVXxLvM2Nrt3CjADR6fDbRkNhIhAeUnUC+F6N6 +TuIIbiOZIsn06OrUwA2uFsU4XQeDYZ3zh4+eNo39xU3AgaWEsbzgEUolmmdpufoGrrw axGl/SKlghA3PigDDAJeP6mgMBzmZ2+5Lfq/3Ci1r6/dcPyP1QTlzdDf3RWYMT+WE4b4 jB8I5tmTaQNKrmDwoo0NMeA/XEtniyOe42I1+S9j8hcjwD6D/Rmg1YvX17C7JpcBVnaz IECw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=sFwKTXT844OT2qtMzSqtdI+VmuY/QkQf8Sf9Ya70xhQ=; b=lOBATQA37inslbiQZnttW+poF6M2AOKlXHBpYBlyf4leBEEINOe4zAFwd6ZquaKAgz Hasqx82Wi1fwWxMrNwaZM+CsC/UxVzk2WpAMCUkOmt5RV2NMTpFBzhJQ+dyfAf0j19oi jX5PKSnBeRaz/8ofjUfNvkJHS0UXbSFNw7qjMNU5W7qixkZU4CH3NAYFsAT5l8wXkMu+ odCyGcj7BmZGxqqqK1EDc6GnFjpwdFtzJtSY9yZWHcSt0+akS+N3Lj6IY+le7TiPPu6U P/jtGRoqCWjrF7ldYrmMz3O/nkfpdssOJw9x8VGP0R9319i5LsrKiMLpC0DlGUo5hMDS W4zw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3-v6si27897685plb.262.2018.11.15.05.51.12; Thu, 15 Nov 2018 05:51:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388404AbeKOX6V (ORCPT + 99 others); Thu, 15 Nov 2018 18:58:21 -0500 Received: from ms.tdt.de ([195.243.126.94]:34341 "EHLO mail.dev.tdt.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387989AbeKOX6V (ORCPT ); Thu, 15 Nov 2018 18:58:21 -0500 Received: from feckert01.dev.tdt.de (unknown [10.2.3.40]) by mail.dev.tdt.de (Postfix) with ESMTPSA id 97A0A21A6C; Thu, 15 Nov 2018 13:50:22 +0000 (UTC) From: Florian Eckert To: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Florian Eckert Subject: [PATCH v3 2/2] hwmon: (adcxx) Add device tree support Date: Thu, 15 Nov 2018 14:50:13 +0100 Message-Id: <20181115135013.30723-3-fe@dev.tdt.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181115135013.30723-1-fe@dev.tdt.de> References: <20181115135013.30723-1-fe@dev.tdt.de> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.dev.tdt.de Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add device tree supoort for this driver. Set reference voltage of ADC with the regulator device tree property. If not set use default 3300000uV (3.3V). - vref-supply Signed-off-by: Florian Eckert --- drivers/hwmon/adcxx.c | 62 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c index 69e0bb97e597..6f3e7d65b5b8 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,16 @@ #include #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 +167,60 @@ 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; + struct regulator *vref; + int vref_uv; + 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; + vref = devm_regulator_get_optional(&spi->dev, "vref"); + if (!IS_ERR(vref)) { + vref_uv = regulator_get_voltage(vref); + adc->reference = DIV_ROUND_CLOSEST(vref_uv, 1000); + } + if (!adc->reference) + adc->reference = 3300; + dev_dbg(&spi->dev, "Reference voltage set to %dmV\n", adc->reference); + adc->channels = channels; mutex_init(&adc->lock); @@ -223,10 +270,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 +281,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, -- 2.11.0