From patchwork Thu Jun 30 08:26:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MyungJoo Ham X-Patchwork-Id: 932132 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5U8RcJj018508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 30 Jun 2011 08:27:58 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QcCae-0004nE-30; Thu, 30 Jun 2011 08:27:12 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QcCac-0005uu-SO; Thu, 30 Jun 2011 08:27:10 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QcCZz-0005nr-93 for linux-arm-kernel@lists.infradead.org; Thu, 30 Jun 2011 08:26:33 +0000 Received: from epcpsbgm1.samsung.com (mailout2.samsung.com [203.254.224.25]) by mailout2.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0LNL006PFGRS1CI0@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 30 Jun 2011 17:26:28 +0900 (KST) X-AuditID: cbfee61a-b7c53ae000002dc1-50-4e0c33347ff2 Received: from epmmp1 ( [203.254.227.16]) by epcpsbgm1.samsung.com (MMPCPMTA) with SMTP id AA.6F.11713.4333C0E4; Thu, 30 Jun 2011 17:26:28 +0900 (KST) Received: from TNRNDGASPAPP1.tn.corp.samsungelectronics.net ([165.213.149.150]) by mmp1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LNL00I55GS49P@mmp1.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 30 Jun 2011 17:26:28 +0900 (KST) Received: from localhost.localdomain ([165.213.219.116]) by TNRNDGASPAPP1.tn.corp.samsungelectronics.net with Microsoft SMTPSVC(6.0.3790.4675); Thu, 30 Jun 2011 17:26:42 +0900 Date: Thu, 30 Jun 2011 17:26:26 +0900 From: MyungJoo Ham Subject: [PATCH 2/3] Samsung SoC: ready to use NTC value inside kernel In-reply-to: <1309422387-11546-1-git-send-email-myungjoo.ham@samsung.com> To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Message-id: <1309422387-11546-3-git-send-email-myungjoo.ham@samsung.com> X-Mailer: git-send-email 1.7.4.1 References: <1309422387-11546-1-git-send-email-myungjoo.ham@samsung.com> X-OriginalArrivalTime: 30 Jun 2011 08:26:42.0871 (UTC) FILETIME=[7115B470:01CC36FF] X-Brightmail-Tracker: AAAAAA== X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110630_042631_638783_03CBC147 X-CRM114-Status: GOOD ( 19.89 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [203.254.224.25 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Kukjin Kim , Mark Brown , dg77.kim@samsung.com, Kyungmin Park , myungjoo.ham@gmail.com, Changhwan Youn , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 30 Jun 2011 08:27:59 +0000 (UTC) This patch allows kernel codes to use values from NTC LM-Sensor driver, which allows SYSFS access only. Signed-off-by: MyungJoo Ham Signed-off-by: Kyungmin Park --- arch/arm/plat-samsung/dev-adc.c | 62 ++++++++++++++++++++++++++ arch/arm/plat-samsung/include/plat/adc-ntc.h | 19 ++++++++ 2 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 arch/arm/plat-samsung/include/plat/adc-ntc.h diff --git a/arch/arm/plat-samsung/dev-adc.c b/arch/arm/plat-samsung/dev-adc.c index 622972c..526097a 100644 --- a/arch/arm/plat-samsung/dev-adc.c +++ b/arch/arm/plat-samsung/dev-adc.c @@ -22,6 +22,8 @@ #include #include +#include "../../../fs/sysfs/sysfs.h" + static struct resource s3c_adc_resource[] = { [0] = { .start = SAMSUNG_PA_ADC, @@ -101,3 +103,63 @@ struct platform_device s3c_device_adc_ntc_thermistor = { .platform_data = &ntc_adc_pdata, }, }; + +static struct device_attribute *ntc_attr; + +static int init_s3c_adc_ntc_read(void) +{ + struct kobject *ntc; + struct sysfs_dirent *ntc_d; + + ntc = &s3c_device_adc_ntc_thermistor.dev.kobj; + ntc_d = sysfs_get_dirent(ntc->sd, get_ktype(ntc)->namespace(ntc), + "temp1_input"); + if (!ntc_d || sysfs_type(ntc_d) != SYSFS_KOBJ_ATTR) { + dev_err(&s3c_device_adc_ntc_thermistor.dev, + "Cannot initialize thermistor dirent info.\n"); + if (ntc_d) + sysfs_put(ntc_d); + return -ENODEV; + } + ntc_attr = container_of(ntc_d->s_attr.attr, struct device_attribute, + attr); + + sysfs_put(ntc_d); + if (IS_ERR(ntc_attr)) { + dev_err(&s3c_device_adc_ntc_thermistor.dev, + "Cannot access NTC thermistor.\n"); + return PTR_ERR(ntc_attr); + } + + return 0; +} + +/* A helper function to read values from NTC, in 1/1000 Centigrade */ +int read_s3c_adc_ntc(int *mC) +{ + char buf[32]; + int ret; + + /* init should be done after ADC and NTC are probed */ + if (ntc_attr == NULL) { + ret = init_s3c_adc_ntc_read(); + if (ret) { + if (ntc_attr == NULL) + ntc_attr = ERR_PTR(ret); + return ret; + } + } + + if (IS_ERR(ntc_attr)) + return -ENODEV; + + if (!ntc_attr->show) + return -EINVAL; + + ret = ntc_attr->show(&s3c_device_adc_ntc_thermistor.dev, ntc_attr, buf); + if (ret < 0) + return ret; + sscanf(buf, "%d", mC); + + return 0; +} diff --git a/arch/arm/plat-samsung/include/plat/adc-ntc.h b/arch/arm/plat-samsung/include/plat/adc-ntc.h new file mode 100644 index 0000000..3d74118 --- /dev/null +++ b/arch/arm/plat-samsung/include/plat/adc-ntc.h @@ -0,0 +1,19 @@ +/* linux/arch/arm/plat-samsung/include/plat/adc-ntc.h + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * NTC Thermistor attached to Samsung ADC Controller driver information + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. +*/ + +#ifndef __PLAT_ADC_NTC_H +#define __PLAT_ADC_NTC_H __FILE__ + +extern void s3c_adc_ntc_init(int port); +extern int read_s3c_adc_ntc(int *mC); + +#endif /* __PLAT_ADC_NTC_H */