Received: by 10.213.65.68 with SMTP id h4csp1396233imn; Wed, 21 Mar 2018 09:39:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELtuauEPVmumQtNZD2rkFmvtell74UEKzzE+VxwwdosBoWH6SnrJvFfveM0sVacI60ZR/mmi X-Received: by 10.99.144.199 with SMTP id a190mr15190332pge.359.1521650351329; Wed, 21 Mar 2018 09:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521650351; cv=none; d=google.com; s=arc-20160816; b=JKfTqGp7scQKuOC+I9KdX323f/Ezsr4ulf/qXUVibEcWYpW0V2WqLlKkQL8RC23tnc 4MeAQNWCwO25o2BvL1makTi1zMVkFkRVIL1bgNPAA051KhuAcaj0FUHtg8XR21ZrdBFC xTtenZGDNkPuGJqRc65SR2oFJhZkxCFKNfcqjzba1xaPL8rlutpVH//dx35HQSzBX5dm g7sLkX/DOJTmihVNDWUEoGQutvAj3q0cCb9wdWff77fvFKZ6NZmGTPfvtnRS+znImjVP 1BL0AoUwv2zql+r6+ALK6CeKXOVpD0TU9bEAsg2qTDCRi6/rx0SbCKEwC1uDwXG6NChZ aPIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=tW+dgJEwZC4pXaJTEfl1RSdz6vqHikaarMZUbB75qbE=; b=JSfBtMrWOm/8GEvi/RXueIWA3iLRA8d7rM6bY9mjE35x13W0ywUY6W25PN71C5G0kl pjORB2mdZow+HhOT5G1qocnX3kxJoQqleOHCcn+WwjyjqTKeW2tOGNZtLI8Pn9lSv6Fg LqzzUFnBxkfMXfJ11rRD//B5hQHkKTXEyeOB+/l2FqfuiRzmvDHULMWcCEISTSbVAjNV Zl9c69+EPgOdbDE7JCwYkIKrHenHID4QNoyen6AIzUVpIyLVThgyFS2JG5tElj+8Dph6 HMm1TMBXMzMTFx9r6OfxCO5JDLvXba+zCAjTUvAJ2yUfS9NznjdaSDpEtgOUc/yOh9ST Qh3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cogentembedded-com.20150623.gappssmtp.com header.s=20150623 header.b=xUzh1LlM; 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 s13-v6si4118500plp.664.2018.03.21.09.38.56; Wed, 21 Mar 2018 09:39:11 -0700 (PDT) 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; dkim=pass header.i=@cogentembedded-com.20150623.gappssmtp.com header.s=20150623 header.b=xUzh1LlM; 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 S1752840AbeCUQhy (ORCPT + 99 others); Wed, 21 Mar 2018 12:37:54 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:43375 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751832AbeCUQhm (ORCPT ); Wed, 21 Mar 2018 12:37:42 -0400 Received: by mail-lf0-f65.google.com with SMTP id v207-v6so8826170lfa.10 for ; Wed, 21 Mar 2018 09:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=tW+dgJEwZC4pXaJTEfl1RSdz6vqHikaarMZUbB75qbE=; b=xUzh1LlMTLgHiH8kmhj064FFtJbF7Zz0xxjZyZavwGX6pzuplKAyX3zSuUfzYiI8rX y3JgWt8kP+SnpSWaBnue3Q2gnCiiEXJ3EwqSlp1DwguVSL8fSlNTJoKYqqXYVbxggDr+ DrK1pW15v89+kcA0zmh8ZtQtQO2CsHZnAfxCiuN2AkvjkAqlWpOmJCEEYDuoD73yPePw Kj+ZmymSkj5+PykBN24E5Gm3evhbQ0+h8aMnlP7IfS85rgW68Uhz4V2O1qBacWupLAIa P9xzrxTwOWauwbwIzPm9XaQrV6shS7ErKnrU1u+iDgem3rWTJKpROTjM6r6JNWwAIy/3 19IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tW+dgJEwZC4pXaJTEfl1RSdz6vqHikaarMZUbB75qbE=; b=bxpWDLAe6v1EI4Xh0Hyn4s60up+J6u4bx4Y40fEy4g+b5ob3IKn5UQWBaTfXobyRtO kl8FGuwXo7Fd9QHxGZzvb9spiM/V9Vj0PjWjb8Vk6s1RhAla8Obe/kGRheDD8ier/dGl Kxl3NeGJvuuGFRBFsOnw7MRhtDiY9wtw4kqRBuEcSxE33Cqf+9qG2f4t1Q4DZ3fGTmt8 Co685xls0zPX6j+Hgl5bJYMkqK759sR22Ybkxek+3HPWffsdRGv2DTrDtDjb9JFRJziC r9rhnkNCBdN/4GavSya1Cw6CvEXB0r1Gf/e1ri/cg23fm730LMCxJGXI1Rf1PVuhBwl3 MarQ== X-Gm-Message-State: AElRT7GQNByYnUo1rITBM6Odz/1QvA0ShHTo6w3GyQ8MSmzlGBoLWBv3 /Gz+8+v6yhGGFkr+fGpVBjwXsQ== X-Received: by 10.46.9.150 with SMTP id 144mr14507029ljj.117.1521650260464; Wed, 21 Mar 2018 09:37:40 -0700 (PDT) Received: from localhost.localdomain (178-16-155-142.obit.ru. [178.16.155.142]) by smtp.gmail.com with ESMTPSA id k12-v6sm1111103lfe.93.2018.03.21.09.37.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Mar 2018 09:37:39 -0700 (PDT) From: Andrey Gusakov To: jdelvare@suse.com, linux@roeck-us.net, lee.jones@linaro.org, cphealy@gmail.com, andrew.smirnov@gmail.com Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Andrey Gusakov Subject: [PATCH v3] hwmon: MC13783: add uid and die temperature sensor inputs Date: Wed, 21 Mar 2018 19:39:26 +0300 Message-Id: <1521650366-32506-1-git-send-email-andrey.gusakov@cogentembedded.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The uid and die temperature can be read out on the ADIN7 using input mux. Map uid and die temperature sensor to channels 16 and 17. Signed-off-by: Andrey Gusakov --- Changes in v3: - comment style fixes Changes in v2: - suport both mc13783 and mc13892 - uid_input renamed to in16_input - style fixes --- drivers/hwmon/mc13783-adc.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ drivers/mfd/mc13xxx-core.c | 15 +++++++++++- include/linux/mfd/mc13xxx.h | 2 ++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c index 960a1db..840d8fc 100644 --- a/drivers/hwmon/mc13783-adc.c +++ b/drivers/hwmon/mc13783-adc.c @@ -63,6 +63,10 @@ static int mc13783_adc_read(struct device *dev, if (ret) return ret; + /* ADIN7 subchannels */ + if (channel >= 16) + channel = 7; + channel &= 0x7; *val = (sample[channel % 4] >> (channel > 3 ? 14 : 2)) & 0x3ff; @@ -111,6 +115,56 @@ static ssize_t mc13783_adc_read_gp(struct device *dev, return sprintf(buf, "%u\n", val); } +static ssize_t mc13783_adc_read_uid(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + unsigned int val; + struct platform_device *pdev = to_platform_device(dev); + kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data; + int ret = mc13783_adc_read(dev, devattr, &val); + + if (ret) + return ret; + + if (driver_data & MC13783_ADC_BPDIV2) + /* MC13892 have 1/2 divider, input range is [0, 4.800V] */ + val = DIV_ROUND_CLOSEST(val * 4800, 1024); + else + /* MC13783 have 0.9 divider, input range is [0, 2.555V] */ + val = DIV_ROUND_CLOSEST(val * 2555, 1024); + + return sprintf(buf, "%u\n", val); +} + +static ssize_t mc13783_adc_read_temp(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + unsigned int val; + struct platform_device *pdev = to_platform_device(dev); + kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data; + int ret = mc13783_adc_read(dev, devattr, &val); + + if (ret) + return ret; + + if (driver_data & MC13783_ADC_BPDIV2) { + /* + * MC13892: + * Die Temperature Read Out Code at 25C 680 + * Temperature change per LSB +0.4244C + */ + ret = DIV_ROUND_CLOSEST(-2635920 + val * 4244, 10); + } else { + /* MC13783: + * Die Temperature Read Out Code at 25C 282 + * Temperature change per LSB -1.14C + */ + ret = 346480 - 1140 * val; + } + + return sprintf(buf, "%d\n", ret); +} + static DEVICE_ATTR_RO(name); static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, mc13783_adc_read_bp, NULL, 2); static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, mc13783_adc_read_gp, NULL, 5); @@ -124,6 +178,9 @@ static ssize_t mc13783_adc_read_gp(struct device *dev, static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, mc13783_adc_read_gp, NULL, 13); static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, mc13783_adc_read_gp, NULL, 14); static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, mc13783_adc_read_gp, NULL, 15); +static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, mc13783_adc_read_uid, NULL, 16); +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, + mc13783_adc_read_temp, NULL, 17); static struct attribute *mc13783_attr_base[] = { &dev_attr_name.attr, @@ -131,6 +188,8 @@ static ssize_t mc13783_adc_read_gp(struct device *dev, &sensor_dev_attr_in5_input.dev_attr.attr, &sensor_dev_attr_in6_input.dev_attr.attr, &sensor_dev_attr_in7_input.dev_attr.attr, + &sensor_dev_attr_in16_input.dev_attr.attr, + &sensor_dev_attr_temp1_input.dev_attr.attr, NULL }; diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c index d7f54e4..c63e331 100644 --- a/drivers/mfd/mc13xxx-core.c +++ b/drivers/mfd/mc13xxx-core.c @@ -279,8 +279,21 @@ int mc13xxx_adc_do_conversion(struct mc13xxx *mc13xxx, unsigned int mode, adc0 = MC13XXX_ADC0_ADINC1 | MC13XXX_ADC0_ADINC2; adc1 = MC13XXX_ADC1_ADEN | MC13XXX_ADC1_ADTRIGIGN | MC13XXX_ADC1_ASC; - if (channel > 7) + /* + * Channels mapped through ADIN7: + * 7 - General purpose ADIN7 + * 16 - UID + * 17 - Die temperature + */ + if (channel > 7 && channel < 16) { adc1 |= MC13XXX_ADC1_ADSEL; + } else if (channel == 16) { + adc0 |= MC13XXX_ADC0_ADIN7SEL_UID; + channel = 7; + } else if (channel == 17) { + adc0 |= MC13XXX_ADC0_ADIN7SEL_DIE; + channel = 7; + } switch (mode) { case MC13XXX_ADC_MODE_TS: diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h index 638222e..54a3cd8 100644 --- a/include/linux/mfd/mc13xxx.h +++ b/include/linux/mfd/mc13xxx.h @@ -243,6 +243,8 @@ struct mc13xxx_platform_data { #define MC13XXX_ADC0_LICELLCON (1 << 0) #define MC13XXX_ADC0_CHRGICON (1 << 1) #define MC13XXX_ADC0_BATICON (1 << 2) +#define MC13XXX_ADC0_ADIN7SEL_DIE (1 << 4) +#define MC13XXX_ADC0_ADIN7SEL_UID (2 << 4) #define MC13XXX_ADC0_ADREFEN (1 << 10) #define MC13XXX_ADC0_TSMOD0 (1 << 12) #define MC13XXX_ADC0_TSMOD1 (1 << 13) -- 1.9.1