From patchwork Sat Mar 3 11:06:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 7073 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2681B23EA8 for ; Sat, 3 Mar 2012 11:08:38 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id DC997A185D0 for ; Sat, 3 Mar 2012 11:08:37 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so4610587iag.11 for ; Sat, 03 Mar 2012 03:08:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.207.72 with SMTP id lu8mr1248684igc.0.1330772917680; Sat, 03 Mar 2012 03:08:37 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.53.18 with SMTP id k18csp4960ibg; Sat, 3 Mar 2012 03:08:37 -0800 (PST) Received: by 10.68.221.73 with SMTP id qc9mr21875848pbc.139.1330772916721; Sat, 03 Mar 2012 03:08:36 -0800 (PST) Received: from mail-pz0-f44.google.com (mail-pz0-f44.google.com [209.85.210.44]) by mx.google.com with ESMTPS id l9si12153176pbi.129.2012.03.03.03.08.35 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 03 Mar 2012 03:08:36 -0800 (PST) Received-SPF: pass (google.com: domain of amitdanielk@gmail.com designates 209.85.210.44 as permitted sender) client-ip=209.85.210.44; Authentication-Results: mx.google.com; spf=pass (google.com: domain of amitdanielk@gmail.com designates 209.85.210.44 as permitted sender) smtp.mail=amitdanielk@gmail.com; dkim=pass header.i=@gmail.com Received: by dakl33 with SMTP id l33so7008944dak.17 for ; Sat, 03 Mar 2012 03:08:35 -0800 (PST) Received-SPF: pass (google.com: domain of amitdanielk@gmail.com designates 10.68.240.164 as permitted sender) client-ip=10.68.240.164; Received: from mr.google.com ([10.68.240.164]) by 10.68.240.164 with SMTP id wb4mr26697139pbc.57.1330772915927 (num_hops = 1); Sat, 03 Mar 2012 03:08:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=mN2gvbxsikUMVhcargs4S2CGw11k9aTnvmGxvbA+T5I=; b=iUQsYCre6kyvvWOFPhVEywt1P+Xt3333ZFG5rx4WxQPOwNqBFYnYVDcRz/7fDOJagx CtScKi8i8cPlaoM3CLayQkl2qJjFx0x9GYxnE57ajxmsGzlvorxH+5kjQub4icRmAxC7 L5zBuLXSZ4OaHONhRQQ8TQPn1nb1HG98jPeOyMTWM5UwRLoXm59zJa9c1fSK39tFTTbc H2U21816tFDwzE9+b5EQiHJPn1y8wXBI3ucKME2qJZ/ynywVuejlNDBH/4uZh2n4DsTd w/1T64SWt3akaSmy6Vah4P/aubE1Y3qBMprpJ4DiN09UwqM2PuViLFmBFjkh54iismi5 fJ3A== Received: by 10.68.240.164 with SMTP id wb4mr22447608pbc.57.1330772915858; Sat, 03 Mar 2012 03:08:35 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id kx17sm7578369pbb.19.2012.03.03.03.08.31 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 03 Mar 2012 03:08:35 -0800 (PST) Sender: amit kachhap From: Amit Daniel Kachhap To: linux-pm@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mjg59@srcf.ucam.org, linux-acpi@vger.kernel.org, lenb@kernel.org, linaro-dev@lists.linaro.org, lm-sensors@lm-sensors.org, amit.kachhap@linaro.org, eduardo.valentin@ti.com, durgadoss.r@intel.com, patches@linaro.org Subject: [PATCH 3/4] thermal: exynos4: Register the tmu sensor with the thermal interface layer Date: Sat, 3 Mar 2012 16:36:06 +0530 Message-Id: <1330772767-16120-4-git-send-email-amit.kachhap@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1330772767-16120-1-git-send-email-amit.kachhap@linaro.org> References: <1330772767-16120-1-git-send-email-amit.kachhap@linaro.org> X-Gm-Message-State: ALoCoQm3j0qmDPazF8PHiUBj57nM6OrlIPMxVHy9ChXaim7hZAITt8Brrq4ukWWYeUC0AqmYIscS Export and register information from the tmu temperature sensor to the samsung exynos kernel thermal framework where different cooling devices and thermal zone are binded. The exported information is based according to the data structure thermal_sensor_conf present in exynos_thermal.h. HWMON sysfs functions are removed as all of them are present in generic linux thermal layer. Also the platform data structure is modified to pass frequency cooling in percentages for each thermal level. Signed-off-by: Amit Daniel Kachhap --- Documentation/mfd/exynos4_tmu | 35 +------- drivers/mfd/exynos4_tmu.c | 139 +++++++---------------------- include/linux/platform_data/exynos4_tmu.h | 7 ++ 3 files changed, 44 insertions(+), 137 deletions(-) diff --git a/Documentation/mfd/exynos4_tmu b/Documentation/mfd/exynos4_tmu index c3c6b41..2b46f67 100644 --- a/Documentation/mfd/exynos4_tmu +++ b/Documentation/mfd/exynos4_tmu @@ -46,36 +46,7 @@ The threshold levels are defined as follows: The threshold and each trigger_level are set through the corresponding registers. -When an interrupt occurs, this driver notify user space of -one of four threshold levels for the interrupt -through kobject_uevent_env and sysfs_notify functions. +When an interrupt occurs, this driver notify kernel thermal framework +with the function exynos4_report_trigger. Although an interrupt condition for level_0 can be set, -it is not notified to user space through sysfs_notify function. - -Sysfs Interface ---------------- -name name of the temperature sensor - RO - -temp1_input temperature - RO - -temp1_max temperature for level_1 interrupt - RO - -temp1_crit temperature for level_2 interrupt - RO - -temp1_emergency temperature for level_3 interrupt - RO - -temp1_max_alarm alarm for level_1 interrupt - RO - -temp1_crit_alarm - alarm for level_2 interrupt - RO - -temp1_emergency_alarm - alarm for level_3 interrupt - RO +it can be used to synchronize the cooling action. diff --git a/drivers/mfd/exynos4_tmu.c b/drivers/mfd/exynos4_tmu.c index f2359a0..e343923 100644 --- a/drivers/mfd/exynos4_tmu.c +++ b/drivers/mfd/exynos4_tmu.c @@ -33,10 +33,10 @@ #include #include -#include -#include - #include +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +#include +#endif #define EXYNOS4_TMU_REG_TRIMINFO 0x0 #define EXYNOS4_TMU_REG_CONTROL 0x20 @@ -70,7 +70,6 @@ struct exynos4_tmu_data { struct exynos4_tmu_platform_data *pdata; - struct device *hwmon_dev; struct resource *mem; void __iomem *base; int irq; @@ -246,12 +245,12 @@ static void exynos4_tmu_work(struct work_struct *work) writel(EXYNOS4_TMU_INTCLEAR_VAL, data->base + EXYNOS4_TMU_REG_INTCLEAR); - kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE); - - enable_irq(data->irq); - clk_disable(data->clk); mutex_unlock(&data->lock); +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE + exynos4_report_trigger(); +#endif + enable_irq(data->irq); } static irqreturn_t exynos4_tmu_irq(int irq, void *id) @@ -264,92 +263,19 @@ static irqreturn_t exynos4_tmu_irq(int irq, void *id) return IRQ_HANDLED; } -static ssize_t exynos4_tmu_show_name(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return sprintf(buf, "exynos4-tmu\n"); -} - -static ssize_t exynos4_tmu_show_temp(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct exynos4_tmu_data *data = dev_get_drvdata(dev); - int ret; - - ret = exynos4_tmu_read(data); - if (ret < 0) - return ret; - - /* convert from degree Celsius to millidegree Celsius */ - return sprintf(buf, "%d\n", ret * 1000); -} - -static ssize_t exynos4_tmu_show_alarm(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct exynos4_tmu_data *data = dev_get_drvdata(dev); - struct exynos4_tmu_platform_data *pdata = data->pdata; - int temp; - unsigned int trigger_level; - - temp = exynos4_tmu_read(data); - if (temp < 0) - return temp; - - trigger_level = pdata->threshold + pdata->trigger_levels[attr->index]; - - return sprintf(buf, "%d\n", !!(temp > trigger_level)); -} - -static ssize_t exynos4_tmu_show_level(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct exynos4_tmu_data *data = dev_get_drvdata(dev); - struct exynos4_tmu_platform_data *pdata = data->pdata; - unsigned int temp = pdata->threshold + - pdata->trigger_levels[attr->index]; - - return sprintf(buf, "%u\n", temp * 1000); -} - -static DEVICE_ATTR(name, S_IRUGO, exynos4_tmu_show_name, NULL); -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, exynos4_tmu_show_temp, NULL, 0); - -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, - exynos4_tmu_show_alarm, NULL, 1); -static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, - exynos4_tmu_show_alarm, NULL, 2); -static SENSOR_DEVICE_ATTR(temp1_emergency_alarm, S_IRUGO, - exynos4_tmu_show_alarm, NULL, 3); - -static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, exynos4_tmu_show_level, NULL, 1); -static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, exynos4_tmu_show_level, NULL, 2); -static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, - exynos4_tmu_show_level, NULL, 3); - -static struct attribute *exynos4_tmu_attributes[] = { - &dev_attr_name.attr, - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, - &sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr, - &sensor_dev_attr_temp1_max.dev_attr.attr, - &sensor_dev_attr_temp1_crit.dev_attr.attr, - &sensor_dev_attr_temp1_emergency.dev_attr.attr, - NULL, -}; - -static const struct attribute_group exynos4_tmu_attr_group = { - .attrs = exynos4_tmu_attributes, +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE +static struct thermal_sensor_conf exynos4_sensor_conf = { + .name = "exynos4-therm", + .read_temperature = (int (*)(void *))exynos4_tmu_read, }; +#endif +/*CONFIG_SAMSUNG_THERMAL_INTERFACE*/ static int __devinit exynos4_tmu_probe(struct platform_device *pdev) { struct exynos4_tmu_data *data; struct exynos4_tmu_platform_data *pdata = pdev->dev.platform_data; - int ret; + int ret, i; if (!pdata) { dev_err(&pdev->dev, "No platform init data supplied.\n"); @@ -418,25 +344,27 @@ static int __devinit exynos4_tmu_probe(struct platform_device *pdev) goto err_clk; } - ret = sysfs_create_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); + exynos4_tmu_control(pdev, true); +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE + (&exynos4_sensor_conf)->private_data = data; + exynos4_sensor_conf.trip_data.trip_count = 3; + for (i = 0; i < exynos4_sensor_conf.trip_data.trip_count; i++) + exynos4_sensor_conf.trip_data.trip_val[i] = + pdata->threshold + pdata->trigger_levels[i + 1]; + + exynos4_sensor_conf.cooling_data.freq_pctg_count = + pdata->freq_tab_count; + for (i = 0; i < pdata->freq_tab_count; i++) + exynos4_sensor_conf.cooling_data.freq_data[i].freq_clip_pctg = + pdata->freq_tab[i].freq_clip_pctg; + + ret = exynos4_register_thermal(&exynos4_sensor_conf); if (ret) { - dev_err(&pdev->dev, "Failed to create sysfs group\n"); + dev_err(&pdev->dev, "Failed to register thermal interface\n"); goto err_clk; } - - data->hwmon_dev = hwmon_device_register(&pdev->dev); - if (IS_ERR(data->hwmon_dev)) { - ret = PTR_ERR(data->hwmon_dev); - dev_err(&pdev->dev, "Failed to register hwmon device\n"); - goto err_create_group; - } - - exynos4_tmu_control(pdev, true); - +#endif return 0; - -err_create_group: - sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); err_clk: platform_set_drvdata(pdev, NULL); clk_put(data->clk); @@ -458,8 +386,9 @@ static int __devexit exynos4_tmu_remove(struct platform_device *pdev) exynos4_tmu_control(pdev, false); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); +#ifdef CONFIG_SAMSUNG_THERMAL_INTERFACE + exynos4_unregister_thermal(); +#endif clk_put(data->clk); diff --git a/include/linux/platform_data/exynos4_tmu.h b/include/linux/platform_data/exynos4_tmu.h index 39e038c..642c508 100644 --- a/include/linux/platform_data/exynos4_tmu.h +++ b/include/linux/platform_data/exynos4_tmu.h @@ -21,6 +21,7 @@ #ifndef _LINUX_EXYNOS4_TMU_H #define _LINUX_EXYNOS4_TMU_H +#include enum calibration_type { TYPE_ONE_POINT_TRIMMING, @@ -64,6 +65,9 @@ enum calibration_type { * in the positive-TC generator block * 0 <= reference_voltage <= 31 * @cal_type: calibration type for temperature + * @freq_pctg_table: Table representing frequency reduction percentage. + * @freq_tab_count: Count of the above table as frequency reduction may + * applicable to only some of the trigger levels. * * This structure is required for configuration of exynos4_tmu driver. */ @@ -79,5 +83,8 @@ struct exynos4_tmu_platform_data { u8 reference_voltage; enum calibration_type cal_type; + + struct freq_pctg_table freq_tab[4]; + unsigned int freq_tab_count; }; #endif /* _LINUX_EXYNOS4_TMU_H */