From patchwork Fri Dec 7 23:15:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nobuhiro Iwamatsu X-Patchwork-Id: 1852051 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id A9207DF2EE for ; Fri, 7 Dec 2012 23:06:11 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Th6xH-0002by-7Z; Fri, 07 Dec 2012 23:03:39 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Th6x6-0002av-Ff for linux-arm-kernel@lists.infradead.org; Fri, 07 Dec 2012 23:03:30 +0000 Received: by mail-pb0-f49.google.com with SMTP id un15so606326pbc.36 for ; Fri, 07 Dec 2012 15:03:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=fP7F9o5Ed4U2QDkMSyREGoeD/92i/v63mPeeasd5hR8=; b=Cjb+LHi2O7Sjp6Hk3kNBqcn144M5ndyhaw83Xlog/HsAJEyVLtYeULsMx3xPaHywez MsWziXpgOf8IOU7/m1P5MO3qgqbbHRl9jcgjRz5MXR0Hgx9Ypdb/qCRAQIfSBTUzFImC RDAm+Ob2m1tyTvLdCQeSKO8NIIFtmy1PIA5NVkx2Cnul2DiEGc+ooiOSgWjlmakb8n4i FftP8DBRp5xhsGPTrHcjsVgYcYfNRrBjLrWmkNh6BS39ExUsz1opZi0bU1j2qA3Dx0dM Wq7Op7wfmJVW8/wQrPyTp+Em/1b01ajpL5Yc37lWISXmrpyRdgF18wlwwOziaS6aT98H 26HA== Received: by 10.66.88.196 with SMTP id bi4mr17401244pab.16.1354921405608; Fri, 07 Dec 2012 15:03:25 -0800 (PST) Received: from chimagu (y104036.dynamic.ppp.asahi-net.or.jp. [118.243.104.36]) by mx.google.com with ESMTPS id na4sm7380853pbc.18.2012.12.07.15.03.23 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 07 Dec 2012 15:03:24 -0800 (PST) Received: from iwamatsu by chimagu with local (Exim 4.80) (envelope-from ) id 1Th796-0000qx-OW; Sat, 08 Dec 2012 08:15:52 +0900 From: Nobuhiro Iwamatsu To: linux-pm@vger.kernel.org Subject: [PATCH 1/2] thermal: Add support for thermal sensor for Kirkwood SoC Date: Sat, 8 Dec 2012 08:15:50 +0900 Message-Id: <1354922151-3250-1-git-send-email-iwamatsu@nigauri.org> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQlXA4a4wgkUhVN7bp+BdPuPcY4dMAZtMNJJqL5s0ca5BA4QYcDawpWtrVhZsz174V7qK5GU X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121207_180328_775555_262B082D X-CRM114-Status: GOOD ( 18.30 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Nobuhiro Iwamatsu , rui.zhang@intel.com, jason@lakedaemon.net, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 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 Some kirkwood SoC has thermal sensor. This patch adds support for 88F6282 and 88F6283. Signed-off-by: Nobuhiro Iwamatsu Tested-by: Jason Gunthorpe --- drivers/thermal/Kconfig | 7 ++ drivers/thermal/Makefile | 1 + drivers/thermal/kirkwood_thermal.c | 131 ++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 drivers/thermal/kirkwood_thermal.c diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index e1cb6bd..8710ac2 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -55,3 +55,10 @@ config EXYNOS_THERMAL help If you say yes here you get support for TMU (Thermal Managment Unit) on SAMSUNG EXYNOS series of SoC. + +config KIRKWOOD_THERMAL + tristate "Temperature sensor on Marvel Kirkwood" + depends on ARCH_KIRKWOOD && THERMAL + help + Support for the Kirkwood thermal sensor driver into the Linux thermal + framework. This supports only 88F6282 and 88F6283. diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 885550d..4dbe5e1 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_THERMAL) += thermal_sys.o obj-$(CONFIG_CPU_THERMAL) += cpu_cooling.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o +obj-$(CONFIG_KIRKWOOD_THERMAL) += kirkwood_thermal.o obj-$(CONFIG_EXYNOS_THERMAL) += exynos_thermal.o diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c new file mode 100644 index 0000000..bddcf49 --- /dev/null +++ b/drivers/thermal/kirkwood_thermal.c @@ -0,0 +1,131 @@ +/* + * kirkwood thermal sensor driver + * + * Copyright (C) 2012 Nobuhiro Iwamatsu + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define THERMAL_VALID_OFFSET 9 +#define THERMAL_VALID_MASK 0x1 +#define THERMAL_TEMP_OFFSET 10 +#define THERMAL_TEMP_MASK 0x1FF + +/* Kirkwood Thermal Sensor Dev Structure */ +struct kirkwood_thermal_dev { + void __iomem *base_addr; +}; + +static inline int kirkwood_get_temp(struct thermal_zone_device *thermal, + unsigned long *temp) +{ + unsigned long reg; + struct kirkwood_thermal_dev *thermal_dev = thermal->devdata; + + reg = readl_relaxed(thermal_dev->base_addr); + + /* Valid check */ + if (!(reg >> THERMAL_VALID_OFFSET) & THERMAL_VALID_MASK) { + dev_info(&thermal->device, "Reading temperature is not valid\n"); + return -EIO; + } + + reg = (reg >> THERMAL_TEMP_OFFSET) & THERMAL_TEMP_MASK; + /* Calculate temperature. See Table 814 in hardware manual. */ + *temp = ((322 - reg) * 10000) / 13625; + + return 0; +} + +static struct thermal_zone_device_ops ops = { + .get_temp = kirkwood_get_temp, +}; + +static int kirkwood_thermal_probe(struct platform_device *pdev) +{ + struct thermal_zone_device *thermal = NULL; + struct kirkwood_thermal_dev *thermal_dev; + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "Failed to get platform resource\n"); + return -ENODEV; + } + + thermal_dev + = devm_kzalloc(&pdev->dev, sizeof(*thermal_dev), GFP_KERNEL); + if (!thermal_dev) { + dev_err(&pdev->dev, "kzalloc fail\n"); + return -ENOMEM; + } + + thermal_dev->base_addr = devm_ioremap(&pdev->dev, res->start, + resource_size(res)); + if (!thermal_dev->base_addr) { + dev_err(&pdev->dev, "Failed to ioremap memory\n"); + return -ENOMEM; + } + + thermal = thermal_zone_device_register("kirkwood_thermal", 0, 0, + thermal_dev, &ops, 0, 0); + if (IS_ERR(thermal)) { + dev_err(&pdev->dev, "Failed to register thermal zone device\n"); + return PTR_ERR(thermal); + } + + platform_set_drvdata(pdev, thermal); + + dev_info(&thermal->device, KBUILD_MODNAME ": Thermal sensor registered\n"); + + return 0; +} + +static int kirkwood_thermal_exit(struct platform_device *pdev) +{ + struct thermal_zone_device *kirkwood_thermal + = platform_get_drvdata(pdev); + + thermal_zone_device_unregister(kirkwood_thermal); + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static const struct of_device_id kirkwood_thermal_id_table[] = { + { .compatible = "marvel,thermal-kirkwood" }, + {} +}; +MODULE_DEVICE_TABLE(of, kirkwood_thermal_id_table); + +static struct platform_driver kirkwood_thermal_driver = { + .probe = kirkwood_thermal_probe, + .remove = kirkwood_thermal_exit, + .driver = { + .name = "kirkwood_thermal", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(kirkwood_thermal_id_table), + }, +}; + +module_platform_driver(kirkwood_thermal_driver); + +MODULE_AUTHOR("Nobuhiro Iwamatsu "); +MODULE_DESCRIPTION("kirkwood thermal driver"); +MODULE_LICENSE("GPL");