Received: by 10.213.65.68 with SMTP id h4csp1416235imn; Mon, 19 Mar 2018 03:40:48 -0700 (PDT) X-Google-Smtp-Source: AG47ELsKBtDZrBZvzfnKY0pe21KGtCFXuuADMj9HLVZjHiOlaOP8Oq08TX8pufNnOYZVDyqS8DjC X-Received: by 2002:a17:902:6b0c:: with SMTP id o12-v6mr12222082plk.295.1521456048837; Mon, 19 Mar 2018 03:40:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521456048; cv=none; d=google.com; s=arc-20160816; b=Xaz/rJ9PYu7msqmFfJNRlk637uiRbj6aFMIjld2v+lg3zwH3ltYdNrlv7FLjiflLY7 qFH7w4Q2v+SqO89VOA8uYEFDPYehoG0UL97MOFUBXwO6IJ/X5DX/9BAOYJokXVcwGsf/ CZitSPUC3pK90J2sIDOxuOe9muWSDDeh68eLxNg13SvkxsmRsUKbOYiw2oezSul7RSqk GhYonxtAAPqD5s8AeqfnVBEFB+ArnKBXCfP7SCB25J9VsxrYIWR3Z//Hy/lZmh4WSQil 0KJFe/bp4UCrjdAiZ3mMweevvRt30Rrft7Sw0vs2VPMClHAbqA4BeVwnaNcBHOhwVkJ9 febw== 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=O5x7/+/zsFugdZ7vvzbWzbdt52Bn1jItiGGchZFNkgY=; b=tiTzFeapRVoDC0/v8+zC/2i5hZeCWgcwDQK9xFwi5lyrg9UG18ipL9JRfmpU/HC2Sq nuznBzkb20ifM0ffPrmgqaDMVOgqVi3dn5Tfv0v/9epnOpbv9bsLOvNM6V+CDiNL35/b eNL/H/etwtAUQ+/LWKzXLBV/VZhOiGanufumS+S/0CdzWFGgRrbPcSAwDlrt1k35+b2C n5IJGZRnjHX0CvnaA+vsiF0swsPGn5rNwm3JljLmaTtyDDMTYFdxPRPRObjzBpceYQtS 4BUBLKoB7GYFxRHnS6fRBFIM15BUT//b9PpuRIWfvlYZnzRb6XbwHNBFZL9jy1RydbVV zYEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cogentembedded-com.20150623.gappssmtp.com header.s=20150623 header.b=GoAeAdh2; 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 h2-v6si11757829plr.1.2018.03.19.03.40.34; Mon, 19 Mar 2018 03:40:48 -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=GoAeAdh2; 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 S932619AbeCSKiA (ORCPT + 99 others); Mon, 19 Mar 2018 06:38:00 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:44925 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755372AbeCSKh4 (ORCPT ); Mon, 19 Mar 2018 06:37:56 -0400 Received: by mail-lf0-f68.google.com with SMTP id g203-v6so10167624lfg.11 for ; Mon, 19 Mar 2018 03:37:55 -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=O5x7/+/zsFugdZ7vvzbWzbdt52Bn1jItiGGchZFNkgY=; b=GoAeAdh2Wo/oac1jbl0gur47uJIozOmqDaohSNIK7Mfpb91NNrQajmERdWs9n02Edw MMdl+MgapRomBwEJFnFESw24AP2gbo1c7GKE5/Ag2PVz0hcsq0KBj+oyRPkAmSJpuROC u7jgOJbI9HP/jwlhj4cCbgXPZxF9DDPVHiElU98/k6kMJAVgkkG8/Uo1uoaHl9XDHTcf 2ER6IDqPXXQ4Rl4VYU92QlaSTm3qsyByXUAqAfNDwEELdjAqSmcFI6Y+XIBj3LM2SZjs zNGDV4e+KjmKL6zMVUAFvZc21v/yGqB3qUVMiLtMvTbtvF8NK7ISNCHTrJWzULNpCstr UzOw== 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=O5x7/+/zsFugdZ7vvzbWzbdt52Bn1jItiGGchZFNkgY=; b=GtV9CSx72PLgHhV0ejxUt+fwKYxxymRtRUwLIKkSs134kvPXpKcRkGroKRHem5IyUQ C311+WYupmdlrr/AF8Vtm2mQ616Mt4bo8ztWs8txuoOxxBV0TCcBmX0/9qnjGju6tVjG LHiN0ekKuGMCVhB1vRXzfLDnWCbf5lGu/tmDHPFCYwaDpyFluRLYOZSk6X10lYx9SllO 7mYmNueLbz2HVJroBbhasN6+FTUjqrFOrq2WPaf4IWislqu2gthi3Ngv4B0vLhXoBk4H w5jK/Pl9jUiGJj2nnZYPSDaeZwGi5D5MIF+wYFC+u+IfmPWz8S+7De3phdUaRSQLefae +xdQ== X-Gm-Message-State: AElRT7GkMwNS1EKfO2JxOr74W5G/PHXf7z0SYNdmHA/imIhIkRTMr1fo RLyCZNKz6G8yDhP6DI7upyCZrA== X-Received: by 2002:a19:519a:: with SMTP id g26-v6mr7474809lfl.50.1521455874792; Mon, 19 Mar 2018 03:37:54 -0700 (PDT) Received: from localhost.localdomain (178-16-155-142.obit.ru. [178.16.155.142]) by smtp.gmail.com with ESMTPSA id a30sm3077942ljd.80.2018.03.19.03.37.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Mar 2018 03:37:54 -0700 (PDT) From: Andrey Gusakov To: jdelvare@suse.com, linux@roeck-us.net, lee.jones@linaro.org, cphealy@gmail.com Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Andrey Gusakov Subject: [PATCH] hwmon: MC13982: add uid and die temperature sensor inputs Date: Mon, 19 Mar 2018 13:38:46 +0300 Message-Id: <1521455926-26423-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 tenperature sensor to channels 16 and 17. Signed-off-by: Andrey Gusakov --- drivers/hwmon/mc13783-adc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/mfd/mc13xxx-core.c | 15 ++++++++++++++- include/linux/mfd/mc13xxx.h | 2 ++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c index 960a1db..ee42133 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,40 @@ 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; + int ret = mc13783_adc_read(dev, devattr, &val); + + if (ret) + return ret; + + /* + * UID is scaled with 0.9 factor. + * input range is [0, 2.555V], val is 10 bits + */ + return sprintf(buf, "%d\n", + DIV_ROUND_CLOSEST(val * 2555, 1024)); +} + +static ssize_t mc13783_adc_read_temp(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + unsigned int val; + int ret = mc13783_adc_read(dev, devattr, &val); + + if (ret) + return ret; + + /* + * Return value is raw temperature. + * Convert per MC13892 datasheet. + */ + return sprintf(buf, "%d\n", + DIV_ROUND_CLOSEST(-2635920 + val * 4244, 10)); +} + 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 +162,8 @@ 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(uid_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 +171,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_uid_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..2178c784 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_UIDEN; + channel = 7; + } else if (channel == 17) { + adc0 |= MC13XXX_ADC0_DTHEN; + 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..6389a98 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_DTHEN (1 << 4) +#define MC13XXX_ADC0_UIDEN (1 << 5) #define MC13XXX_ADC0_ADREFEN (1 << 10) #define MC13XXX_ADC0_TSMOD0 (1 << 12) #define MC13XXX_ADC0_TSMOD1 (1 << 13) -- 1.9.1