From patchwork Sun Jun 23 16:41:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011783 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B75EC17D2 for ; Sun, 23 Jun 2019 16:42:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A615D28AA2 for ; Sun, 23 Jun 2019 16:42:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 995C228AD1; Sun, 23 Jun 2019 16:42:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 979BB28A8C for ; Sun, 23 Jun 2019 16:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726879AbfFWQmO (ORCPT ); Sun, 23 Jun 2019 12:42:14 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44028 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726768AbfFWQmO (ORCPT ); Sun, 23 Jun 2019 12:42:14 -0400 Received: by mail-pf1-f193.google.com with SMTP id i189so6098364pfg.10; Sun, 23 Jun 2019 09:42:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zPNVR7pGpaDNHjObNtKjy5ol22Mjb0O+wvgCUguxj4M=; b=FatigfnLmHqFsL7YC0OQ1HJ09wRzljDgz0ZqDWEAnXr0a3vmMXZp7k7MgxED2pGUQv bbeclohb1iPALVvJbPWB7W2dfGv3UQyp6KtYw3dTWRohnkUZklF137GbAvVzVMG78Q4c FDts9QzbCnnkdIbP6s9SqkQ/cTBk0Exrbq07QYXHEOvEMzMJRyGefHl4+ktWvJufJA7a yZgKStRtgohOl66zrWb5/+Pou4hqqTZvi47/rxkYWaPCoWaAEhIJGZpZnBUZC6EKYNTO QqvHl3wRfNUcvsP4TYNxFpNOAWAjkhlYvqbr2MNg7Y03URYku9PA3Z3mkQj4TcRmJcQp t1cw== 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:in-reply-to :references; bh=zPNVR7pGpaDNHjObNtKjy5ol22Mjb0O+wvgCUguxj4M=; b=gEt9SgMWyU+ycjPlIuHfJOg1NR3hiIgjQl6HjOLvNXNh4wNLO0ilmF7y9WPZg5Y53S 4VYXaKhgF4Os4vaw68YAby98AtDVTvrGhC7dtKFqE/8/L6AmdqWdnrq3mLd3CJ5szt3r r+hJ4AikHCMAoO4NgPg+uWWNxWN2X9QR+GqWrV7G4AOex3L81MaQ1sbfIY29/eeaWUMG +xfyhyEwivo2XCVQLv+azFDii60g8T01L5Sg5VaKuC+/+Go3OT2XuciV1eRsbhaXyw1v 0yNRObJyyCn63rhJzQdQEMtviy4kj1GflFL3BG+lR3hSD+BF/2E3EqvFG1WggwuvX1EL +a/Q== X-Gm-Message-State: APjAAAXwIn6LtTg1TTohi2f5msyzDoaQx2UIhLLRL//nIgGUm1/PvPYw rZ/ZI2p+CjsHtPiPIBzCR2w= X-Google-Smtp-Source: APXvYqzgXXB5mStrhkzan4KG83X85VVzIkYWjQhk0oUFo284KlLsFL8+4uVLRmeHxQx2CDuv77AJHg== X-Received: by 2002:a17:90a:7f02:: with SMTP id k2mr19641473pjl.78.1561308133116; Sun, 23 Jun 2019 09:42:13 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id y185sm8560343pfy.110.2019.06.23.09.42.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:12 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 01/11] thermal: sun8i: add thermal driver for h6 Date: Sun, 23 Jun 2019 12:41:56 -0400 Message-Id: <20190623164206.7467-2-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the support for allwinner thermal sensor, within allwinner SoC. It will register sensors for thermal framework and use device tree to bind cooling device. Signed-off-by: Yangtao Li --- MAINTAINERS | 7 + drivers/thermal/Kconfig | 14 ++ drivers/thermal/Makefile | 1 + drivers/thermal/sun8i_thermal.c | 405 ++++++++++++++++++++++++++++++++ 4 files changed, 427 insertions(+) create mode 100644 drivers/thermal/sun8i_thermal.c diff --git a/MAINTAINERS b/MAINTAINERS index 36a84614d6c3..67e7fcfaded2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -674,6 +674,13 @@ L: linux-crypto@vger.kernel.org S: Maintained F: drivers/crypto/sunxi-ss/ +ALLWINNER THERMAL DRIVER +M: Yangtao Li +L: linux-pm@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml +F: drivers/thermal/sun8i_thermal.c + ALLWINNER VPU DRIVER M: Maxime Ripard M: Paul Kocialkowski diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 9966364a6deb..f8b73b32b92d 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -262,6 +262,20 @@ config SPEAR_THERMAL Enable this to plug the SPEAr thermal sensor driver into the Linux thermal framework. +config SUN8I_THERMAL + tristate "Allwinner sun8i thermal driver" + depends on ARCH_SUNXI || COMPILE_TEST + depends on HAS_IOMEM + depends on NVMEM + depends on OF + depends on RESET_CONTROLLER + help + Support for the sun8i thermal sensor driver into the Linux thermal + framework. + + To compile this driver as a module, choose M here: the + module will be called sun8i-thermal. + config ROCKCHIP_THERMAL tristate "Rockchip thermal driver" depends on ARCH_ROCKCHIP || COMPILE_TEST diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 74a37c7f847a..fa6f8b206281 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -31,6 +31,7 @@ thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o obj-y += broadcom/ obj-$(CONFIG_THERMAL_MMIO) += thermal_mmio.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o +obj-$(CONFIG_SUN8I_THERMAL) += sun8i_thermal.o obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o obj-$(CONFIG_RCAR_GEN3_THERMAL) += rcar_gen3_thermal.o diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c new file mode 100644 index 000000000000..d6918c62682b --- /dev/null +++ b/drivers/thermal/sun8i_thermal.c @@ -0,0 +1,405 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Thermal sensor driver for Allwinner SOC + * Copyright (C) 2019 Yangtao Li + * + * Based on the work of Icenowy Zheng + * Based on the work of Ondrej Jirman + * Based on the work of Josef Gajdusek + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_SENSOR_NUM 4 + +#define SUN50I_H6_SENSOR_NUM 2 +#define SUN50I_H6_OFFSET -2794 +#define SUN50I_H6_SCALE -67 + +#define FT_TEMP_MASK GENMASK(11, 0) +#define TEMP_CALIB_MASK GENMASK(11, 0) +#define TEMP_TO_REG 672 +#define CALIBRATE_DEFAULT 0x800 + +#define SUN50I_THS_CTRL0 0x00 +#define SUN50I_H6_THS_ENABLE 0x04 +#define SUN50I_H6_THS_PC 0x08 +#define SUN50I_H6_THS_DIC 0x10 +#define SUN50I_H6_THS_DIS 0x20 +#define SUN50I_H6_THS_MFC 0x30 +#define SUN50I_H6_THS_TEMP_CALIB 0xa0 +#define SUN50I_H6_THS_TEMP_DATA 0xc0 + +#define SUN50I_THS_CTRL0_T_ACQ(x) ((GENMASK(15, 0) & (x)) << 16) +#define SUN50I_THS_FILTER_EN BIT(2) +#define SUN50I_THS_FILTER_TYPE(x) (GENMASK(1, 0) & (x)) +#define SUN50I_H6_THS_PC_TEMP_PERIOD(x) ((GENMASK(19, 0) & (x)) << 12) +#define SUN50I_H6_THS_DATA_IRQ_STS(x) BIT(x) + +/* millidegree celsius */ +#define SUN50I_H6_FT_DEVIATION 7000 + +struct ths_device; + +struct tsensor { + struct ths_device *tmdev; + struct thermal_zone_device *tzd; + int id; +}; + +struct ths_device { + struct device *dev; + struct regmap *regmap; + struct reset_control *reset; + struct clk *bus_clk; + struct tsensor sensor[MAX_SENSOR_NUM]; +}; + +/* Temp Unit: millidegree Celsius */ +static int sun8i_ths_reg2temp(struct ths_device *tmdev, + int reg) +{ + return (reg + SUN50I_H6_OFFSET) * SUN50I_H6_SCALE; +} + +static int sun8i_ths_get_temp(void *data, int *temp) +{ + struct tsensor *s = data; + struct ths_device *tmdev = s->tmdev; + int val; + + regmap_read(tmdev->regmap, SUN50I_H6_THS_TEMP_DATA + + 0x4 * s->id, &val); + + /* ths have no data yet */ + if (!val) + return -EBUSY; + + *temp = sun8i_ths_reg2temp(tmdev, val); + /* + * XX - According to the original sdk, there are some platforms(rarely) + * that add a fixed offset value after calculating the temperature + * value. We can't simply put it on the formula for calculating the + * temperature above, because the formula for calculating the + * temperature above is also used when the sensor is calibrated. If + * do this, the correct calibration formula is hard to know. + */ + *temp += SUN50I_H6_FT_DEVIATION; + + return 0; +} + +static const struct thermal_zone_of_device_ops ths_ops = { + .get_temp = sun8i_ths_get_temp, +}; + +static const struct regmap_config config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .fast_io = true, +}; + +static irqreturn_t sun50i_h6_irq_thread(int irq, void *data) +{ + struct ths_device *tmdev = data; + int i, state; + + regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); + + for (i = 0; i < SUN50I_H6_SENSOR_NUM; i++) { + + if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) { + /* clear data irq pending */ + regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, + SUN50I_H6_THS_DATA_IRQ_STS(i)); + + thermal_zone_device_update(tmdev->sensor[i].tzd, + THERMAL_EVENT_UNSPECIFIED); + } + } + + return IRQ_HANDLED; +} + +static int sun50i_ths_calibrate(struct ths_device *tmdev) +{ + struct nvmem_cell *calcell; + struct device *dev = tmdev->dev; + u16 *caldata; + size_t callen; + int ft_temp; + int i, ret = 0; + + calcell = devm_nvmem_cell_get(dev, "calib"); + if (IS_ERR(calcell)) { + if (PTR_ERR(calcell) == -EPROBE_DEFER) + return -EPROBE_DEFER; + /* + * Even if the external calibration data stored in sid is + * not accessible, the THS hardware can still work, although + * the data won't be so accurate. + * + * The default value of calibration register is 0x800 for + * every sensor, and the calibration value is usually 0x7xx + * or 0x8xx, so they won't be away from the default value + * for a lot. + * + * So here we do not return error if the calibartion data is + * not available, except the probe needs deferring. + */ + goto out; + } + + caldata = nvmem_cell_read(calcell, &callen); + if (IS_ERR(caldata)) { + ret = PTR_ERR(caldata); + goto out; + } + + if (!caldata[0] || callen < 2 + 2 * SUN50I_H6_SENSOR_NUM) { + ret = -EINVAL; + goto out_free; + } + + /* + * efuse layout: + * + * 0 11 16 32 + * +-------+-------+-------+ + * |temp| |sensor0|sensor1| + * +-------+-------+-------+ + * + * The calibration data on the H6 is the ambient temperature and + * sensor values that are filled during the factory test stage. + * + * The unit of stored FT temperature is 0.1 degreee celusis. + * Through the stored ambient temperature and the data read + * by the sensor, after a certain calculation, the calibration + * value to be compensated can be obtained. + */ + ft_temp = caldata[0] & FT_TEMP_MASK; + + for (i = 0; i < SUN50I_H6_SENSOR_NUM; i++) { + int reg = (int)caldata[i + 1]; + int sensor_temp = sun8i_ths_reg2temp(tmdev, reg); + int delta, cdata, calib_offest; + + /* + * To calculate the calibration value: + * + * X(in Celsius) = Ts - ft_temp + * delta = X * 10000 / TEMP_TO_REG + * cdata = CALIBRATE_DEFAULT - delta + * + * cdata: calibration value + */ + delta = (sensor_temp - ft_temp * 100) * 10 / TEMP_TO_REG; + cdata = CALIBRATE_DEFAULT - delta; + if (cdata & ~TEMP_CALIB_MASK) { + /* + * Calibration value more than 12-bit, but calibration + * register is 12-bit. In this case, ths hardware can + * still work without calibration, although the data + * won't be so accurate. + */ + dev_warn(dev, "sensor%d is not calibrated.\n", i); + + continue; + } + + calib_offest = SUN50I_H6_THS_TEMP_CALIB + (i / 2) * 0x4; + + if (i % 2) { + int val; + + regmap_read(tmdev->regmap, calib_offest, &val); + val = (val & TEMP_CALIB_MASK) | (cdata << 16); + regmap_write(tmdev->regmap, calib_offest, val); + } else { + regmap_write(tmdev->regmap, calib_offest, cdata); + } + } + +out_free: + kfree(caldata); +out: + return ret; +} + +static int sun8i_ths_resource_init(struct ths_device *tmdev) +{ + struct device *dev = tmdev->dev; + struct platform_device *pdev = to_platform_device(dev); + struct resource *mem; + void __iomem *base; + int ret; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + base = devm_ioremap_resource(dev, mem); + if (IS_ERR(base)) + return PTR_ERR(base); + + tmdev->regmap = devm_regmap_init_mmio(dev, base, &config); + if (IS_ERR(tmdev->regmap)) + return PTR_ERR(tmdev->regmap); + + tmdev->reset = devm_reset_control_get(dev, 0); + if (IS_ERR(tmdev->reset)) + return PTR_ERR(tmdev->reset); + + tmdev->bus_clk = devm_clk_get(&pdev->dev, "bus"); + if (IS_ERR(tmdev->bus_clk)) + return PTR_ERR(tmdev->bus_clk); + + ret = reset_control_deassert(tmdev->reset); + if (ret) + return ret; + + ret = clk_prepare_enable(tmdev->bus_clk); + if (ret) + goto assert_reset; + + ret = sun50i_ths_calibrate(tmdev); + if (ret) + goto bus_disable; + + return 0; + +bus_disable: + clk_disable_unprepare(tmdev->bus_clk); +assert_reset: + reset_control_assert(tmdev->reset); + + return ret; +} + +static int sun50i_thermal_init(struct ths_device *tmdev) +{ + int val; + + /* + * clkin = 24MHz + * T acquire = clkin / (x + 1) + * = 20us + */ + regmap_write(tmdev->regmap, SUN50I_THS_CTRL0, + SUN50I_THS_CTRL0_T_ACQ(479)); + /* average over 4 samples */ + regmap_write(tmdev->regmap, SUN50I_H6_THS_MFC, + SUN50I_THS_FILTER_EN | + SUN50I_THS_FILTER_TYPE(1)); + /* period = (x + 1) * 4096 / clkin; ~10ms */ + regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, + SUN50I_H6_THS_PC_TEMP_PERIOD(58)); + /* enable sensor */ + val = GENMASK(SUN50I_H6_SENSOR_NUM - 1, 0); + regmap_write(tmdev->regmap, SUN50I_H6_THS_ENABLE, val); + /* thermal data interrupt enable */ + val = GENMASK(SUN50I_H6_SENSOR_NUM - 1, 0); + regmap_write(tmdev->regmap, SUN50I_H6_THS_DIC, val); + + return 0; +} + +static int sun8i_ths_register(struct ths_device *tmdev) +{ + struct thermal_zone_device *tzd; + int i; + + for (i = 0; i < SUN50I_H6_SENSOR_NUM; i++) { + tmdev->sensor[i].tmdev = tmdev; + tmdev->sensor[i].id = i; + tmdev->sensor[i].tzd = + devm_thermal_zone_of_sensor_register(tmdev->dev, + i, + &tmdev->sensor[i], + &ths_ops); + if (IS_ERR(tmdev->sensor[i].tzd)) + return PTR_ERR(tzd); + } + + return 0; +} + +static int sun8i_ths_probe(struct platform_device *pdev) +{ + struct ths_device *tmdev; + struct device *dev = &pdev->dev; + int ret, irq; + + tmdev = devm_kzalloc(dev, sizeof(*tmdev), GFP_KERNEL); + if (!tmdev) + return -ENOMEM; + + tmdev->dev = dev; + platform_set_drvdata(pdev, tmdev); + + ret = sun8i_ths_resource_init(tmdev); + if (ret) + return ret; + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + + ret = sun50i_thermal_init(tmdev); + if (ret) + return ret; + + ret = sun8i_ths_register(tmdev); + if (ret) + return ret; + + /* + * Avoid entering the interrupt handler, the thermal device is not + * registered yet, we deffer the registration of the interrupt to + * the end. + */ + ret = devm_request_threaded_irq(dev, irq, NULL, + sun50i_h6_irq_thread, + IRQF_ONESHOT, "ths", tmdev); + if (ret) + return ret; + + return ret; +} + +static int sun8i_ths_remove(struct platform_device *pdev) +{ + struct ths_device *tmdev = platform_get_drvdata(pdev); + + clk_disable_unprepare(tmdev->bus_clk); + reset_control_assert(tmdev->reset); + + return 0; +} + +static const struct of_device_id of_ths_match[] = { + { .compatible = "allwinner,sun50i-h6-ths"}, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, of_ths_match); + +static struct platform_driver ths_driver = { + .probe = sun8i_ths_probe, + .remove = sun8i_ths_remove, + .driver = { + .name = "sun8i-thermal", + .of_match_table = of_ths_match, + }, +}; +module_platform_driver(ths_driver); + +MODULE_DESCRIPTION("Thermal sensor driver for Allwinner SOC"); +MODULE_LICENSE("GPL v2"); From patchwork Sun Jun 23 16:41:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011807 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 565A714E5 for ; Sun, 23 Jun 2019 16:43:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46D2328A8C for ; Sun, 23 Jun 2019 16:43:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ADAF28AD1; Sun, 23 Jun 2019 16:43:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB95628A8C for ; Sun, 23 Jun 2019 16:43:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726896AbfFWQmQ (ORCPT ); Sun, 23 Jun 2019 12:42:16 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41192 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbfFWQmP (ORCPT ); Sun, 23 Jun 2019 12:42:15 -0400 Received: by mail-pf1-f193.google.com with SMTP id m30so6103234pff.8; Sun, 23 Jun 2019 09:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GJ1/rKutIQEKHvyH14ecs6l1ZdLbW/7MgqbbW+zZyME=; b=aPkTDQYg6YxMR3LTtRqUOO2PX5D4buJBQKeJG5SSksdp94O1WOG6qh7fzioBgPa3I9 hC6vdUBCy3i4vqfbfzBTA/md92U4B/cEKPIelHy0Q3bl9TkucGocmA290racdD5hqA+D /l1E+fld70hWvvHqRU9W0Hl0SiUJelPC8gB4jRE1AXcm9za3kNhEYLxEjdVMP2lVRP/u q68qtw9uV3ZNjoh+qa2qr3NpaKh/sVlNciRaVcdWxwiQLWsDJGeP9N42hO1pWYH9u6hW wM1OpitX/5R8JL7GRo8ez064bZhvDxyKXToUaaYc1pEbJS8fEUhWqhXsCOJnA7JigVzr RVlw== 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:in-reply-to :references; bh=GJ1/rKutIQEKHvyH14ecs6l1ZdLbW/7MgqbbW+zZyME=; b=Vg+8j1sC9a9om6KwtoNfhgP4khAd1lVmIqzrXGjVazokc0gIEOnTTPBplqOYZj+yN1 Dvi/eIAeccYo47ya+N7UaTBUwh6yildp8Jm9qJ6E249LwsdOCO2iOzi3R2g/1dUhZo/H XfEqMD6MMOTGSgNFB7ULKrKKbCvrKlbyW4MWwXxYZ4jbmfNaZiYTnCQtVtTP3SovhyX/ TteF9enfs82+Zk3iFKlV566ZzpXXjYZG98G0wNfLYXW9ecEaP4BqKv/cW0XMB8UAsMil TcjjTXgEkMKxgzDL9hopAvgmbGK/uo4sQR6hClHPsuqWVPYKeIAygb7pnx0Ov8d2siXM qHng== X-Gm-Message-State: APjAAAUw0gbmuXWWwQN7i551sdkB4VlTVyAPwkOfh6ksUvvdNJNobkVj vmdFD4p5s7SOxosk+Imb85k= X-Google-Smtp-Source: APXvYqzr3IL15+QRlPgzFQhfOuJbPNix+LH7PczxPb49B9YhZvIzUrQxfMsNEB8dxxedXBBzTMPQWw== X-Received: by 2002:a63:4553:: with SMTP id u19mr28484919pgk.420.1561308134980; Sun, 23 Jun 2019 09:42:14 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id k16sm9059855pfa.87.2019.06.23.09.42.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:14 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 02/11] dt-bindings: thermal: add binding document for h6 thermal controller Date: Sun, 23 Jun 2019 12:41:57 -0400 Message-Id: <20190623164206.7467-3-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds binding document for allwinner h6 thermal controller. Signed-off-by: Yangtao Li --- .../bindings/thermal/sun8i-thermal.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml diff --git a/Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml b/Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml new file mode 100644 index 000000000000..2c5acc61ed03 --- /dev/null +++ b/Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml @@ -0,0 +1,71 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/sun8i-thermal.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Allwinner SUN8I Thermal Controller Device Tree Bindings + +maintainers: + - Yangtao Li + +description: |- + This describes the device tree binding for the Allwinner thermal + controller which measures the on-SoC temperatures. + +properties: + compatible: + enum: + - allwinner,sun50i-h6-ths + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + resets: + maxItems: 1 + + clocks: + minItems: 1 + maxItems: 1 + + clock-names: + const: bus + + '#thermal-sensor-cells': + const: 1 + + nvmem-cells: + items: + - description: ths calibrate data + + nvmem-cell-names: + items: + - const: calib + +required: + - compatible + - reg + - reset + - clocks + - clock-names + - interrupts + - '#thermal-sensor-cells' + +examples: + - | + ths: ths@5070400 { + compatible = "allwinner,sun50i-h6-ths"; + reg = <0x05070400 0x100>; + clocks = <&ccu CLK_BUS_THS>; + clock-names = "bus"; + resets = <&ccu RST_BUS_THS>; + interrupts = ; + nvmem-cells = <&tsen_calib>; + nvmem-cell-names = "calib"; + #thermal-sensor-cells = <1>; + }; + +... From patchwork Sun Jun 23 16:41:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011805 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7CF717D2 for ; Sun, 23 Jun 2019 16:43:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D79F628A8C for ; Sun, 23 Jun 2019 16:43:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBEA428AD1; Sun, 23 Jun 2019 16:43:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7942C28A8C for ; Sun, 23 Jun 2019 16:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726916AbfFWQmS (ORCPT ); Sun, 23 Jun 2019 12:42:18 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40938 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726908AbfFWQmR (ORCPT ); Sun, 23 Jun 2019 12:42:17 -0400 Received: by mail-pf1-f196.google.com with SMTP id p184so6107032pfp.7; Sun, 23 Jun 2019 09:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l52fWtW3aoPkxwNQa5fIqgZrHE13Sc/TSQJ/idB7mO0=; b=e522gMpk4cJiXZ8WanDck6Eu2glNq4tzW8JKnszog3QBvg4Ippfq8hNQnuBo94orbX u2gMCzLLiqfDEbsZASmbJ/LDbnQHM3WuwjsSQks2HwbcjZwW8bYclLUg8YNHN4cRskuG 1mxiV6/zUeI2UHI4i07lZEVAddmJg3NlXLYI0Cea4XUSP2KJCoRdXJCu5ywoyQBBrO4J gSDJzHwbDUQ41U4Hp9VyyQS5koSpmaIYzZII/KVK+V0OGPFxqs7Nb+IC82AvHAMrHN62 NMkiDDwZjezT0qG3aFg6JiCw+YhtJ2roIWJnfE6wpzAZTmn7ZmgEwFn1BGH1knsQvnET Lwug== 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:in-reply-to :references; bh=l52fWtW3aoPkxwNQa5fIqgZrHE13Sc/TSQJ/idB7mO0=; b=uXINXBbNJa3Vl8COQ3OB9TW439GKpeimY/ctnF/hLhRgTQ9TfantSuH7P+NZzHE4zo ET55s57SjOre7EnqZPTgSOIvt0pfX14x+AUjVe2t9OSPwHkuA0fCqh/y06upVj8B+Twr O+b/f12G37GR8UILIA5RLWVyTHV65IGONncWoH9g4cMpp5YVwjjAuyvGUgLz06C1l/Dd 3HybF726/lal4e2FqxWzkHkSb3aD4noDrsnhwQ46FdEi3CuFo+Xa/3iRcGSshdiTi3oO RWZxe+IAPWtcdI1d8kXSjgLYvRgskK8d0xE7jMJFfbaRXkjG7GhOjqrxQ31+AhywF96i a/MQ== X-Gm-Message-State: APjAAAUIMPosMngMEW8y50HWWxEPSl0FIAWjlXkN/y45efwag4bF1Zwi x9t4QyrLhctVP8I406pkwD/sOLEk X-Google-Smtp-Source: APXvYqxwcVFm4cX8NcFvvREnvAiZRJODJ0isOyybQ/E6r9Z7HRNVzLSobEYtQ42YhiYekF7fI++91Q== X-Received: by 2002:a63:8341:: with SMTP id h62mr17783424pge.206.1561308137073; Sun, 23 Jun 2019 09:42:17 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id m6sm9744878pjl.18.2019.06.23.09.42.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:16 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 03/11] thermal: fix indentation in makefile Date: Sun, 23 Jun 2019 12:41:58 -0400 Message-Id: <20190623164206.7467-4-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To unify code style. Signed-off-by: Yangtao Li --- drivers/thermal/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index fa6f8b206281..d7eafb5ef8ef 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -5,7 +5,7 @@ obj-$(CONFIG_THERMAL) += thermal_sys.o thermal_sys-y += thermal_core.o thermal_sysfs.o \ - thermal_helpers.o + thermal_helpers.o # interface to/from other layers providing sensors thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o @@ -25,11 +25,11 @@ thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o # devfreq cooling -thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o +thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o # platform thermal drivers obj-y += broadcom/ -obj-$(CONFIG_THERMAL_MMIO) += thermal_mmio.o +obj-$(CONFIG_THERMAL_MMIO) += thermal_mmio.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o obj-$(CONFIG_SUN8I_THERMAL) += sun8i_thermal.o obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o @@ -50,7 +50,7 @@ obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/ obj-y += st/ obj-$(CONFIG_QCOM_TSENS) += qcom/ obj-y += tegra/ -obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o +obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o obj-$(CONFIG_ZX2967_THERMAL) += zx2967_thermal.o From patchwork Sun Jun 23 16:41:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011803 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 863C117D2 for ; Sun, 23 Jun 2019 16:43:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74B0C28A8C for ; Sun, 23 Jun 2019 16:43:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68CF328AD1; Sun, 23 Jun 2019 16:43:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC0A528A8C for ; Sun, 23 Jun 2019 16:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbfFWQmz (ORCPT ); Sun, 23 Jun 2019 12:42:55 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34698 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbfFWQmT (ORCPT ); Sun, 23 Jun 2019 12:42:19 -0400 Received: by mail-pg1-f195.google.com with SMTP id p10so5800074pgn.1; Sun, 23 Jun 2019 09:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=61YRhTYZzpPAbsdw4ql6MdZ8eDEIqaY2tionq5H4meo=; b=Wzrz9SjgCzNqQkzWoSMQqAL1h3gNd+lI94LXDB/ydu9Z8V5mO205tsym53MOSa7sW5 +6rdMWKOr4rPzevDBAEwwn3hxXiQFvYk7nzcRCamQ4cpeaOe1lTnd39tYp3QLHotHkrf H9Gqqwx9cuvPLmydJrXROfFy7XQX4E0veSpIcrt3VPWOIaWnog2/DdVzcC9SoN7Ly/2y y6hbEuiD/dwWJZzid73WhW7L5OeZao0Pqcdwye2c8fGjKNNck19ziC0E0bgNsHHxISq8 pxrC+K9DVFBjw6xaWwof4EPLGizmWrDNoNj4VJC5mOVV8FoklOpLkYrV4791DFZ69Tll znPA== 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:in-reply-to :references; bh=61YRhTYZzpPAbsdw4ql6MdZ8eDEIqaY2tionq5H4meo=; b=VKGW0ebh7HKmJdLlHciWm56ztzL1EW9A1dJ8AwsJXS+CsuodpZK1ODjbFujPELx8jn J1vb+sm/JyNYl2sMwsIJjJlD+6jhvbkuegbwQ9PmWApe8i9NCRX7tIUYIDb47MImvkMt RWBkhsXTRDqTnvDK9Ap3IJqYNznTlMJJWe9MYR8bM/5u+hJGHht2oU30hd7p/DpX8dRY nUQNhT9b5PjMphzdG8sTJkaz0lGekmsETDHm9ahS96QRe5XL+wTU0fHQD71ir9AGLrH/ mPA2xOAjSi3AwwmxUz5M3hTjRnCJOqnrflRfP+o/vT2wsUDyX/QPpLU79Q4Dn97JjAA1 AvLQ== X-Gm-Message-State: APjAAAXxyjpa2+5Io38uwP3tcsMA3ZD6GUAP8zE52HJB/PMZOrm45lH4 PWZem9qo+k6qpOc3ynI9Tl4= X-Google-Smtp-Source: APXvYqzRoYiCci88ppuvAJgfSh+3g9qZBEaERQz6llUSQx4SEJvBp6v+YlGwm14rPG59UsiG008gBQ== X-Received: by 2002:a17:90a:1c1:: with SMTP id 1mr19678268pjd.72.1561308138834; Sun, 23 Jun 2019 09:42:18 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id k22sm8405914pfk.157.2019.06.23.09.42.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:18 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 04/11] thermal: sun8i: get ths sensor number from device compatible Date: Sun, 23 Jun 2019 12:41:59 -0400 Message-Id: <20190623164206.7467-5-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For different socs, the number of ths sensors is different. So we need to do some work in order to support more soc. Signed-off-by: Yangtao Li --- drivers/thermal/sun8i_thermal.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index d6918c62682b..c37e1c51a543 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -22,7 +22,6 @@ #define MAX_SENSOR_NUM 4 -#define SUN50I_H6_SENSOR_NUM 2 #define SUN50I_H6_OFFSET -2794 #define SUN50I_H6_SCALE -67 @@ -57,7 +56,12 @@ struct tsensor { int id; }; +struct ths_thermal_chip { + int sensor_num; +}; + struct ths_device { + const struct ths_thermal_chip *chip; struct device *dev; struct regmap *regmap; struct reset_control *reset; @@ -117,7 +121,7 @@ static irqreturn_t sun50i_h6_irq_thread(int irq, void *data) regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); - for (i = 0; i < SUN50I_H6_SENSOR_NUM; i++) { + for (i = 0; i < tmdev->chip->sensor_num; i++) { if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) { /* clear data irq pending */ @@ -167,7 +171,7 @@ static int sun50i_ths_calibrate(struct ths_device *tmdev) goto out; } - if (!caldata[0] || callen < 2 + 2 * SUN50I_H6_SENSOR_NUM) { + if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num) { ret = -EINVAL; goto out_free; } @@ -190,7 +194,7 @@ static int sun50i_ths_calibrate(struct ths_device *tmdev) */ ft_temp = caldata[0] & FT_TEMP_MASK; - for (i = 0; i < SUN50I_H6_SENSOR_NUM; i++) { + for (i = 0; i < tmdev->chip->sensor_num; i++) { int reg = (int)caldata[i + 1]; int sensor_temp = sun8i_ths_reg2temp(tmdev, reg); int delta, cdata, calib_offest; @@ -303,10 +307,10 @@ static int sun50i_thermal_init(struct ths_device *tmdev) regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, SUN50I_H6_THS_PC_TEMP_PERIOD(58)); /* enable sensor */ - val = GENMASK(SUN50I_H6_SENSOR_NUM - 1, 0); + val = GENMASK(tmdev->chip->sensor_num - 1, 0); regmap_write(tmdev->regmap, SUN50I_H6_THS_ENABLE, val); /* thermal data interrupt enable */ - val = GENMASK(SUN50I_H6_SENSOR_NUM - 1, 0); + val = GENMASK(tmdev->chip->sensor_num - 1, 0); regmap_write(tmdev->regmap, SUN50I_H6_THS_DIC, val); return 0; @@ -317,7 +321,7 @@ static int sun8i_ths_register(struct ths_device *tmdev) struct thermal_zone_device *tzd; int i; - for (i = 0; i < SUN50I_H6_SENSOR_NUM; i++) { + for (i = 0; i < tmdev->chip->sensor_num; i++) { tmdev->sensor[i].tmdev = tmdev; tmdev->sensor[i].id = i; tmdev->sensor[i].tzd = @@ -343,6 +347,10 @@ static int sun8i_ths_probe(struct platform_device *pdev) return -ENOMEM; tmdev->dev = dev; + tmdev->chip = of_device_get_match_data(&pdev->dev); + if (!tmdev->chip) + return -EINVAL; + platform_set_drvdata(pdev, tmdev); ret = sun8i_ths_resource_init(tmdev); @@ -385,8 +393,12 @@ static int sun8i_ths_remove(struct platform_device *pdev) return 0; } +static const struct ths_thermal_chip sun50i_h6_ths = { + .sensor_num = 2, +}; + static const struct of_device_id of_ths_match[] = { - { .compatible = "allwinner,sun50i-h6-ths"}, + { .compatible = "allwinner,sun50i-h6-ths", .data = &sun50i_h6_ths }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, of_ths_match); From patchwork Sun Jun 23 16:42:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011801 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4BD314E5 for ; Sun, 23 Jun 2019 16:42:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A41A828A8C for ; Sun, 23 Jun 2019 16:42:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9864E28AD1; Sun, 23 Jun 2019 16:42:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3ED0E28A8C for ; Sun, 23 Jun 2019 16:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726948AbfFWQmW (ORCPT ); Sun, 23 Jun 2019 12:42:22 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35110 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726944AbfFWQmV (ORCPT ); Sun, 23 Jun 2019 12:42:21 -0400 Received: by mail-pf1-f193.google.com with SMTP id d126so6118466pfd.2; Sun, 23 Jun 2019 09:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9UNcpWLQ0SBIIcBRxbN1qX4s3ChEMbjvtnWO+dtNEsA=; b=q7GZ/jpCAu9MK3iPRrcZ9ANkg2i3u6OpwBfpBxftNrbB7qb5Ql/dv/7UGy8QXCCGpy GiGyjFSWSWxOwbxw3caI4V/cmdLbmXW63FudgJkGpzzRJsXBhSZ1oIcSv5VoS0sgYpmT wKshYQ+CHPlieOztlOpzZaI86gqTUced4iJPd7tSBo/mzcRsYUdjvXC2dB8u8KVi7a7o Ad48cjNJiPK/Q5LWyupyPXWmQ32wJAU3q8xCbrm4bSi+5gJJdf6+g+Or/gdUlua2/v82 yAmGhMZ0tWH3/3vnG0wz4DebTviCokra90Eq2UiRVcArotY86r1DhHK+Sogw5UxpNXEM bv5g== 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:in-reply-to :references; bh=9UNcpWLQ0SBIIcBRxbN1qX4s3ChEMbjvtnWO+dtNEsA=; b=YVYyhJjY2lB2i4OUEl1iukMKULnmYnNd2NbPvMsFn7Ua8qBdRVlw1wAvxI+ErIwtyD QUd5JRAp/Re98FqYn9Ee3009j3d5Lg2C+iQIKAKRuXFszS/iIaN2rPtx9ClahuDs2YKN +AK2ugPvK7Wn3iVBb/XqZcD/Zq85mB8orrqr9kevvpwAzEO+OC7M61gINGdAgVBtbV6M /Oo4tNvqs99zuG5fgZyauPTakt1asj8DZ9J3SkOG6qHHOEZWUescek5oC+2JhmHePp4N Eqz1txQGF2dp+LM9N2cbbn0k0FiaFdSZspRPWrpSEVVQT9beToZjnxsE1sPRaAv3Eg0h F2BQ== X-Gm-Message-State: APjAAAU30SoAbirSHr7wSJlz1tFAQUyRAJTU0WKCgwLNueRLCvbPdsp3 hB0a1RfUbdRTIVnv3RUdOKkbnFCpP8c= X-Google-Smtp-Source: APXvYqy7Clm/F/UW+Jya2jGhzAWsBCgiuAG/VXNp/xiWo2mAetLliQqzE0GZg6EIu+TjhZV50wTfIg== X-Received: by 2002:a17:90a:bb01:: with SMTP id u1mr19254865pjr.92.1561308141132; Sun, 23 Jun 2019 09:42:21 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id z186sm9183351pfz.7.2019.06.23.09.42.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:20 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 05/11] thermal: sun8i: rework for sun8i_ths_get_temp() Date: Sun, 23 Jun 2019 12:42:00 -0400 Message-Id: <20190623164206.7467-6-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For different socs, the way they get and calculate the temperature is roughly the same. So get the difference from device compatible. Difference point: 1) temperature calculation formula parameters 2) ths data register start address Signed-off-by: Yangtao Li --- drivers/thermal/sun8i_thermal.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index c37e1c51a543..e473a5651436 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -22,9 +22,6 @@ #define MAX_SENSOR_NUM 4 -#define SUN50I_H6_OFFSET -2794 -#define SUN50I_H6_SCALE -67 - #define FT_TEMP_MASK GENMASK(11, 0) #define TEMP_CALIB_MASK GENMASK(11, 0) #define TEMP_TO_REG 672 @@ -58,6 +55,10 @@ struct tsensor { struct ths_thermal_chip { int sensor_num; + int offset; + int scale; + int ft_deviation; + int temp_data_base; }; struct ths_device { @@ -73,7 +74,7 @@ struct ths_device { static int sun8i_ths_reg2temp(struct ths_device *tmdev, int reg) { - return (reg + SUN50I_H6_OFFSET) * SUN50I_H6_SCALE; + return (reg + tmdev->chip->offset) * tmdev->chip->scale; } static int sun8i_ths_get_temp(void *data, int *temp) @@ -82,7 +83,7 @@ static int sun8i_ths_get_temp(void *data, int *temp) struct ths_device *tmdev = s->tmdev; int val; - regmap_read(tmdev->regmap, SUN50I_H6_THS_TEMP_DATA + + regmap_read(tmdev->regmap, tmdev->chip->temp_data_base + 0x4 * s->id, &val); /* ths have no data yet */ @@ -98,7 +99,7 @@ static int sun8i_ths_get_temp(void *data, int *temp) * temperature above is also used when the sensor is calibrated. If * do this, the correct calibration formula is hard to know. */ - *temp += SUN50I_H6_FT_DEVIATION; + *temp += tmdev->chip->ft_deviation; return 0; } @@ -395,6 +396,10 @@ static int sun8i_ths_remove(struct platform_device *pdev) static const struct ths_thermal_chip sun50i_h6_ths = { .sensor_num = 2, + .offset = -2794, + .scale = -67, + .ft_deviation = SUN50I_H6_FT_DEVIATION, + .temp_data_base = SUN50I_H6_THS_TEMP_DATA, }; static const struct of_device_id of_ths_match[] = { From patchwork Sun Jun 23 16:42:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011799 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E537617D2 for ; Sun, 23 Jun 2019 16:42:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D470528A8C for ; Sun, 23 Jun 2019 16:42:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8A9E28AD1; Sun, 23 Jun 2019 16:42:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7986B28A8C for ; Sun, 23 Jun 2019 16:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726966AbfFWQmY (ORCPT ); Sun, 23 Jun 2019 12:42:24 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44536 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726958AbfFWQmY (ORCPT ); Sun, 23 Jun 2019 12:42:24 -0400 Received: by mail-pl1-f193.google.com with SMTP id t7so5490150plr.11; Sun, 23 Jun 2019 09:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QeuzSFtFULNoQbGg4hqLSd4xmo0B4o8ksbknu1n0KZM=; b=WX3Yrc0OvQ8B4sl+cSv2hgv3FAi1TFu+BMpDsDcgG2niFAPlDuUCFFhgZT32h1myEe OtI8aFmwrPENLyEXeOboC0R5ChT8PcsJwGPZdcnK3obduopK7EL8O618V8I3vX87FsGM W+SifyHWCKQJGj9xfXnzDbwRP+jNnE/bFXZgvpt3bw7BxHfNUZmo+7zeM6pjWJHXyh59 5nF4UUTVWkTN3xE34blNimLRleCmmRIMDrVgnf3u251YCFwHLS9r0nQs/ukEinAW4XTE iIpCgUsg22Bwbo+a6b9zUJ3sewCrvqe41ug9HGsuSntXfo2ffqGkG7r/D6iJaaZIFqCb /Glg== 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:in-reply-to :references; bh=QeuzSFtFULNoQbGg4hqLSd4xmo0B4o8ksbknu1n0KZM=; b=lOqXxhIkZXFS+9a0s/uUhueEnIcq7zJrH7hh3D08kJLU5LQSAZnMWGdpT/McSwhEva hkUQpmeln2ncxc1plzNTBi13aHSssYWIayCMPzC8BLenZOUVsVJdVvcuRWiUMVt6fpxi EJO2cxDmG5I1ySlJmKwPjyrwYTS/jNQfUH/JLHACZe43zOf1CSB53fwB2WVdlz2K+oLr zq/qDiOWMTGGyMaI/gYxEQpkRQpNQ/9Bn3T6sG9bQpiOXdUpCiENYeG1NRGN9Duw433l Jj8C3vth3P++S5TDThXwg/iuz+dit1yJFExQsvWmd5yf0sAsJaJJITv4y2JbQVE063k+ Ueng== X-Gm-Message-State: APjAAAWiTngzjkPJvOGtCxs4HPSGqqQYN7pTl+g9CcVe4OBaMD+bST5W Am0QjPRVH/rLfBe29sveF1mrtiBKMWA= X-Google-Smtp-Source: APXvYqwmAwNO0tRQc1DYoa+hJd5YtKf6VLWWVmJUG+ZzCkzrIkvCUZwARJRuxYe6faj0d1GPkbIWBg== X-Received: by 2002:a17:902:6b02:: with SMTP id o2mr48701805plk.133.1561308143647; Sun, 23 Jun 2019 09:42:23 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id e6sm9766388pfn.71.2019.06.23.09.42.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:23 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 06/11] thermal: sun8i: get ths init func from device compatible Date: Sun, 23 Jun 2019 12:42:01 -0400 Message-Id: <20190623164206.7467-7-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are some differences in register initialization for different socs. So we get different initialization functions from device compatible. Signed-off-by: Yangtao Li --- drivers/thermal/sun8i_thermal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index e473a5651436..59acbbac76e4 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -59,6 +59,7 @@ struct ths_thermal_chip { int scale; int ft_deviation; int temp_data_base; + int (*init)(struct ths_device *tmdev); }; struct ths_device { @@ -362,7 +363,7 @@ static int sun8i_ths_probe(struct platform_device *pdev) if (irq < 0) return irq; - ret = sun50i_thermal_init(tmdev); + ret = tmdev->chip->init(tmdev); if (ret) return ret; @@ -400,6 +401,7 @@ static const struct ths_thermal_chip sun50i_h6_ths = { .scale = -67, .ft_deviation = SUN50I_H6_FT_DEVIATION, .temp_data_base = SUN50I_H6_THS_TEMP_DATA, + .init = sun50i_thermal_init, }; static const struct of_device_id of_ths_match[] = { From patchwork Sun Jun 23 16:42:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011787 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90E0714E5 for ; Sun, 23 Jun 2019 16:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F74A28A8C for ; Sun, 23 Jun 2019 16:42:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7300028AD1; Sun, 23 Jun 2019 16:42:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19DFE28A8C for ; Sun, 23 Jun 2019 16:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbfFWQm1 (ORCPT ); Sun, 23 Jun 2019 12:42:27 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34774 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726977AbfFWQm1 (ORCPT ); Sun, 23 Jun 2019 12:42:27 -0400 Received: by mail-pf1-f196.google.com with SMTP id c85so6126297pfc.1; Sun, 23 Jun 2019 09:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wEqIKiIjMDW4aKJ2RgXaFik3U88pUoE48jM/nfBTuhA=; b=OvgjTayEeWn9V1P+UsSgcRUgHzKlA20WHH1U2kasI2U4zb1dZGsyz8z+mFheACxqL1 kPQOapIXQt8yaWoIMb9oE6e8TmtvbvSh0mKDrymGbV6gADJwZzIR14jVItFURLk/R1O4 +GScwEEjNqEtdFG/g4cvA6puWFeFqK8UA8P6UhcnIk1zjq0E2eP5akr8PRqW2ZIUSbTx 1ltLgVyXxvuDz8eJtBiiJtFFEgqCocluxqoAs7ahM06e73JXU346rRymL3oOaaneDdSB GguJpVfIgppIARigTk4XyddmTJ6SS8LyjzNMqcjcAQpIDW4PpUFX5jAPUxqtvjAC9y5x +blg== 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:in-reply-to :references; bh=wEqIKiIjMDW4aKJ2RgXaFik3U88pUoE48jM/nfBTuhA=; b=EOxzDmNofYvxZMSiUAXRHhW4lcG1FJ5j1LpYHY6TFOtLarWrJH271FtqJvMqK58SqG X3jSQ2lEbSuKiPXTIhX3PgEwj/1itG4I2ZoD6+35M3f2x5DXjYWPIhw98yoL35neFats Crz/OABFwe2onOfIRFaVUr985qYwrKbF9oNWopTAAw79QsjohjDoPC6tfBWZWfbcRv34 RW1FkgL5E6N3tjpq1AuJsadYILnEmNpGKFii7GVa48c0ETi2CJxvUrhpWtpOAoGeNg6V /ASp69pAlwK0h6Jes0SmOLD2emEeEPhjFHcorEzMLldtCTiqXmtPIyJ3R18EkREjOhSl 0Zcw== X-Gm-Message-State: APjAAAX6LmksPcNcy8Yvay3u7vYbnrDhsqeZetQmynzMZJLYcrzfxfTC LawVSVLW7ILDATcIiWfhhrY= X-Google-Smtp-Source: APXvYqzqdPeNJDKT2GHT0UxSYGePTtYbn2c7WuA7YrqBRcCXj1cMwuqZDcNhsdj2Me9OR655VE0O4g== X-Received: by 2002:a63:a046:: with SMTP id u6mr12950599pgn.122.1561308146440; Sun, 23 Jun 2019 09:42:26 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id a3sm9503098pfo.49.2019.06.23.09.42.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:25 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 07/11] thermal: sun8i: rework for ths irq handler func Date: Sun, 23 Jun 2019 12:42:02 -0400 Message-Id: <20190623164206.7467-8-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Here, we do something to prepare for the subsequent support of multiple platforms. 1) rename sun50i_h6_irq_thread to sun8i_irq_thread, because this function should be suitable for all platforms. 2) introduce irq_ack callback to mask interrupt register differences. Signed-off-by: Yangtao Li --- drivers/thermal/sun8i_thermal.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index 59acbbac76e4..ed1c19bb27cf 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -60,6 +60,7 @@ struct ths_thermal_chip { int ft_deviation; int temp_data_base; int (*init)(struct ths_device *tmdev); + int (*irq_ack)(struct ths_device *tmdev); }; struct ths_device { @@ -116,23 +117,34 @@ static const struct regmap_config config = { .fast_io = true, }; -static irqreturn_t sun50i_h6_irq_thread(int irq, void *data) +static int sun50i_h6_irq_ack(struct ths_device *tmdev) { - struct ths_device *tmdev = data; - int i, state; + int i, state, ret = 0; regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); for (i = 0; i < tmdev->chip->sensor_num; i++) { - if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) { - /* clear data irq pending */ regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, SUN50I_H6_THS_DATA_IRQ_STS(i)); + ret |= BIT(i); + } + } + + return ret; +} +static irqreturn_t sun8i_irq_thread(int irq, void *data) +{ + struct ths_device *tmdev = data; + int i, state; + + state = tmdev->chip->irq_ack(tmdev); + + for (i = 0; i < tmdev->chip->sensor_num; i++) { + if (state & BIT(i)) thermal_zone_device_update(tmdev->sensor[i].tzd, THERMAL_EVENT_UNSPECIFIED); - } } return IRQ_HANDLED; @@ -377,7 +389,7 @@ static int sun8i_ths_probe(struct platform_device *pdev) * the end. */ ret = devm_request_threaded_irq(dev, irq, NULL, - sun50i_h6_irq_thread, + sun8i_irq_thread, IRQF_ONESHOT, "ths", tmdev); if (ret) return ret; @@ -402,6 +414,7 @@ static const struct ths_thermal_chip sun50i_h6_ths = { .ft_deviation = SUN50I_H6_FT_DEVIATION, .temp_data_base = SUN50I_H6_THS_TEMP_DATA, .init = sun50i_thermal_init, + .irq_ack = sun50i_h6_irq_ack, }; static const struct of_device_id of_ths_match[] = { From patchwork Sun Jun 23 16:42:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011797 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D4D417D2 for ; Sun, 23 Jun 2019 16:42:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C77828A8C for ; Sun, 23 Jun 2019 16:42:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3CFE28AD1; Sun, 23 Jun 2019 16:42:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 949D328A8C for ; Sun, 23 Jun 2019 16:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbfFWQmb (ORCPT ); Sun, 23 Jun 2019 12:42:31 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41540 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726989AbfFWQma (ORCPT ); Sun, 23 Jun 2019 12:42:30 -0400 Received: by mail-pl1-f194.google.com with SMTP id m7so5477942pls.8; Sun, 23 Jun 2019 09:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ddH5x5C4Xtp9rpA7ryYSwYalCmUTcgexoa3qISyw2Ug=; b=tsMXbUAgFpwgrGExbojVFp6U+eGCSeVvQ9COwf0RIP4o6x6lu/cIpPJiU6z+BFl/nK 9uFezX6fSwPv9SbDVCJn3nhgK/wYhAFSTfVVRRAhcNasUfzmZNRNBq5NprqM6MXbisSq rP+DULOHG0lJXd/9kgnzSrzrblAND0GWor0omm6c0+wmv5e+fOLhzGZjm7zOzgfuEABy EfrYFjcW3IBzwSMs9sbgOeJ77y8uOu5Y7HxeZXjGZXnEXTILq1rFPK51guGEWRnO8mqK Fl40iQX/QBS5ZgxCR5H+2+oJHs4rCVb6WIRs3UE5BrsYv6TcH8ldw/s+ObnC9wRjr8gT JZNw== 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:in-reply-to :references; bh=ddH5x5C4Xtp9rpA7ryYSwYalCmUTcgexoa3qISyw2Ug=; b=jp86XKVu9KpDDvZ7NINRUECULfpFHE8o1qhnfyUe3ScWbKFC2IRnfvksHLIwWINKux MMYblL24cE2VPhBnTQhyahmewJQCCiFOMghYAhb6VXmosNMhxxiuXavu9i4In7GseUrB 70Q+9ozQROuil/8oQjNo9hOSMyoUw5niiOhrySEsOc+ALE+MI186uQDsUfDiC0SkZKU9 TEanmDdL2qaOPe1nxk2puneSPI3E6+giYJMVs8Vzm9BE0TwXPYu2ebn6dbuZc9YxEqd2 s4UpQGWpMPC0xB1DqjGb9tm3B94aRZM3NU07Pc893iatZDEdPf2/sO+drgAyedBCvGZj Mwuw== X-Gm-Message-State: APjAAAXhb1NSBGwYDyJrSZvZ7b28LE1TD+pL2QXUGOROCmQ2N4ASw0Lv qh0AXrsD9oGpX484bvH2PV0= X-Google-Smtp-Source: APXvYqykivldidC6OTPZpmATBM7ATqQAb23IP4aVg9WLyjsROhNPDhwqIZxuE7cbseWPK8Nr0H/tlQ== X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr142206227plg.190.1561308149084; Sun, 23 Jun 2019 09:42:29 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id l13sm7708993pjq.20.2019.06.23.09.42.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:28 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 08/11] thermal: sun8i: support ahb clocks Date: Sun, 23 Jun 2019 12:42:03 -0400 Message-Id: <20190623164206.7467-9-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP H3 has extra clock, so introduce something in ths_thermal_chip/ths_device and adds the process of the clock. This is pre-work for supprt it. Signed-off-by: Yangtao Li --- drivers/thermal/sun8i_thermal.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index ed1c19bb27cf..04f53ffb6a14 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -54,6 +54,7 @@ struct tsensor { }; struct ths_thermal_chip { + bool has_ahb_clk; int sensor_num; int offset; int scale; @@ -69,6 +70,7 @@ struct ths_device { struct regmap *regmap; struct reset_control *reset; struct clk *bus_clk; + struct clk *ahb_clk; struct tsensor sensor[MAX_SENSOR_NUM]; }; @@ -280,6 +282,12 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev) if (IS_ERR(tmdev->bus_clk)) return PTR_ERR(tmdev->bus_clk); + if (tmdev->chip->has_ahb_clk) { + tmdev->ahb_clk = devm_clk_get(&pdev->dev, "ahb"); + if (IS_ERR(tmdev->ahb_clk)) + return PTR_ERR(tmdev->ahb_clk); + } + ret = reset_control_deassert(tmdev->reset); if (ret) return ret; @@ -288,12 +296,18 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev) if (ret) goto assert_reset; - ret = sun50i_ths_calibrate(tmdev); + ret = clk_prepare_enable(tmdev->ahb_clk); if (ret) goto bus_disable; + ret = sun50i_ths_calibrate(tmdev); + if (ret) + goto ahb_disable; + return 0; +ahb_disable: + clk_disable_unprepare(tmdev->ahb_clk); bus_disable: clk_disable_unprepare(tmdev->bus_clk); assert_reset: @@ -401,6 +415,7 @@ static int sun8i_ths_remove(struct platform_device *pdev) { struct ths_device *tmdev = platform_get_drvdata(pdev); + clk_disable_unprepare(tmdev->ahb_clk); clk_disable_unprepare(tmdev->bus_clk); reset_control_assert(tmdev->reset); From patchwork Sun Jun 23 16:42:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011795 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7583F14E5 for ; Sun, 23 Jun 2019 16:42:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 649D828A8C for ; Sun, 23 Jun 2019 16:42:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57BC528AD1; Sun, 23 Jun 2019 16:42:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD8EB28A8C for ; Sun, 23 Jun 2019 16:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727031AbfFWQmd (ORCPT ); Sun, 23 Jun 2019 12:42:33 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35413 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727010AbfFWQmd (ORCPT ); Sun, 23 Jun 2019 12:42:33 -0400 Received: by mail-pg1-f193.google.com with SMTP id s27so5795476pgl.2; Sun, 23 Jun 2019 09:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RTcK3pbraTehLFDRf/5iQTqAdMG2KSczJRXJiBCvB5Y=; b=J79n+G0FL6XsNrisl6wbrkk+LaSJR6g3/f6ISU3BTLA9JY3Gqkm4YYdTSvx/+5Kqg7 kbr1y5dzXFGY1CYoZ83vKdhe7nZ7CKTdLOBaDy/ML+spf/jCjKex5kzhqJeI0IPbN3N0 yxwnVWyDo28A2xTdG5uWbE1xAfskgvDsey1vfABp8IHb7J7YnXcj8Y8Zlvaiz49r1b3L fGNKV8818ts9AVqoiVfZU1XtTPsUtfmFVkjgmtVGGiVuSofPy0kZbll+M8ozOW+x+JPa PRBDcTuudkpmeEV4rk5FT8U1nNgL7daeNWgAMoZeaBYmT2mk/vxpb9lzrniT2jLpukwd HhRA== 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:in-reply-to :references; bh=RTcK3pbraTehLFDRf/5iQTqAdMG2KSczJRXJiBCvB5Y=; b=EblGvD7/ycTZ4XWIfgTFkfHbXN0/K5WjUMrd99e2AxQKNsQN9ydF92b7PCuMCZ4H7I TosFrfpaLcTumTPlG+Rfyp2hgaByk1ltvqmeNs0muQ6Ls1zGmdt9IITEk+f1HpQ1JcBS m895VQaETO9ttXfcrLRKl6dRM4JakOog1/ZloLEr3iU7fFQLRRBFuzDmYMwijBOKmbDz ns5XJ3WwQAOPKqQVsC4npvOon1kB/Tz6nuAUhq6ledRmTDM7uejbLeBBbq/dRco5h2my UTJoO6T5nttPpQQ3r+mDXuiWSzxeMNyMe0eV9m+izz6Ma7iT+wWbLbMsaqLMITimx49m k5Uw== X-Gm-Message-State: APjAAAUaI3V8CMQy+u2hGDm7KEbg8BU4zlSDEWUKIlPMhdeNGfVjZTOg OnaMgiiaiv0ue2Mo4t/dpls= X-Google-Smtp-Source: APXvYqzGanD57O3MhuhLaVMM/J9OguOZ9knpULHKCKx5u7OSJ407HPyX7xnw3TY+8qmoUkfWdIvHGw== X-Received: by 2002:a65:418d:: with SMTP id a13mr29100398pgq.332.1561308151893; Sun, 23 Jun 2019 09:42:31 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id w3sm8457242pgl.31.2019.06.23.09.42.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:31 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 09/11] thermal: sun8i: rework for ths calibrate func Date: Sun, 23 Jun 2019 12:42:04 -0400 Message-Id: <20190623164206.7467-10-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Here, we do something to prepare for the subsequent support of multiple platforms. 1) rename sun50i_ths_calibrate to sun8i_ths_calibrate, because this function should be suitable for all platforms now. 2) introduce calibrate callback to mask calibration method differences. Signed-off-by: Yangtao Li --- drivers/thermal/sun8i_thermal.c | 86 ++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index 04f53ffb6a14..260b24340f5b 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -60,6 +60,8 @@ struct ths_thermal_chip { int scale; int ft_deviation; int temp_data_base; + int (*calibrate)(struct ths_device *tmdev, + u16 *caldata, int callen); int (*init)(struct ths_device *tmdev); int (*irq_ack)(struct ths_device *tmdev); }; @@ -152,45 +154,14 @@ static irqreturn_t sun8i_irq_thread(int irq, void *data) return IRQ_HANDLED; } -static int sun50i_ths_calibrate(struct ths_device *tmdev) +static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, + u16 *caldata, int callen) { - struct nvmem_cell *calcell; struct device *dev = tmdev->dev; - u16 *caldata; - size_t callen; - int ft_temp; - int i, ret = 0; - - calcell = devm_nvmem_cell_get(dev, "calib"); - if (IS_ERR(calcell)) { - if (PTR_ERR(calcell) == -EPROBE_DEFER) - return -EPROBE_DEFER; - /* - * Even if the external calibration data stored in sid is - * not accessible, the THS hardware can still work, although - * the data won't be so accurate. - * - * The default value of calibration register is 0x800 for - * every sensor, and the calibration value is usually 0x7xx - * or 0x8xx, so they won't be away from the default value - * for a lot. - * - * So here we do not return error if the calibartion data is - * not available, except the probe needs deferring. - */ - goto out; - } + int i, ft_temp; - caldata = nvmem_cell_read(calcell, &callen); - if (IS_ERR(caldata)) { - ret = PTR_ERR(caldata); - goto out; - } - - if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num) { - ret = -EINVAL; - goto out_free; - } + if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num) + return -EINVAL; /* * efuse layout: @@ -251,7 +222,45 @@ static int sun50i_ths_calibrate(struct ths_device *tmdev) } } -out_free: + return 0; +} + +static int sun8i_ths_calibrate(struct ths_device *tmdev) +{ + struct nvmem_cell *calcell; + struct device *dev = tmdev->dev; + u16 *caldata; + size_t callen; + int ret = 0; + + calcell = devm_nvmem_cell_get(dev, "calib"); + if (IS_ERR(calcell)) { + if (PTR_ERR(calcell) == -EPROBE_DEFER) + return -EPROBE_DEFER; + /* + * Even if the external calibration data stored in sid is + * not accessible, the THS hardware can still work, although + * the data won't be so accurate. + * + * The default value of calibration register is 0x800 for + * every sensor, and the calibration value is usually 0x7xx + * or 0x8xx, so they won't be away from the default value + * for a lot. + * + * So here we do not return error if the calibartion data is + * not available, except the probe needs deferring. + */ + goto out; + } + + caldata = nvmem_cell_read(calcell, &callen); + if (IS_ERR(caldata)) { + ret = PTR_ERR(caldata); + goto out; + } + + tmdev->chip->calibrate(tmdev, caldata, callen); + kfree(caldata); out: return ret; @@ -300,7 +309,7 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev) if (ret) goto bus_disable; - ret = sun50i_ths_calibrate(tmdev); + ret = sun8i_ths_calibrate(tmdev); if (ret) goto ahb_disable; @@ -428,6 +437,7 @@ static const struct ths_thermal_chip sun50i_h6_ths = { .scale = -67, .ft_deviation = SUN50I_H6_FT_DEVIATION, .temp_data_base = SUN50I_H6_THS_TEMP_DATA, + .calibrate = sun50i_h6_ths_calibrate, .init = sun50i_thermal_init, .irq_ack = sun50i_h6_irq_ack, }; From patchwork Sun Jun 23 16:42:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011793 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5DE014E5 for ; Sun, 23 Jun 2019 16:42:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A647D28A8C for ; Sun, 23 Jun 2019 16:42:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A61028AD1; Sun, 23 Jun 2019 16:42:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D8D528A8C for ; Sun, 23 Jun 2019 16:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727051AbfFWQmm (ORCPT ); Sun, 23 Jun 2019 12:42:42 -0400 Received: from mail-pf1-f178.google.com ([209.85.210.178]:38028 "EHLO mail-pf1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727036AbfFWQme (ORCPT ); Sun, 23 Jun 2019 12:42:34 -0400 Received: by mail-pf1-f178.google.com with SMTP id y15so1470748pfn.5; Sun, 23 Jun 2019 09:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Vc2TrqpD10fc/Gfq4unesnc+WEyy7mH5ktLy+6dZnog=; b=na5YZxEqKvs5q15uC5P1TVCCMSkxBW5asCpG+6XNTePIxjvDEvT+nm/nJ7Mhtz5n20 IOL8H362bj7nNRmdZxlMJuiG43M5be4/MzEz/4tbEjzcZIhVOpUlTVZQD3SkHTx+r9gD vhAV2xRiKaGcRlZ0j5RsCsvmR4GdP+CxJnSyGdkB3YcG2lDyALrhAZKPreixUBDpkOPe KbhdYO+xaP7XWzoUy9L27kkSPZymBFpNFsOzgZypoZfhhSN/vKyRxfU630VyVWxq8iV8 Fn+epGdLDRGIJdu/0IBsiiuui42sm5NKERE9jBgfZZyF+QvXmeFWmLs5x5oGd5IgyUFO k15w== 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:in-reply-to :references; bh=Vc2TrqpD10fc/Gfq4unesnc+WEyy7mH5ktLy+6dZnog=; b=Rx/x0chVGBgJrtPb68zM5Kac/lTQd/VKYFyt0PsgTnCy4jFHbxZ7B8ZzU6w2/Qb9Qk Av9FdKwMJ0Ps9mYprj5Rj4I90EJo3tbKOR986RKlIYY5u02BczW+MyGp0t3PqcR93laQ NAXTY5O3T2/NUfZCV6VmhSZIWsn9gU/3uqsllPDf8HTIP6DGBIFtdXavnckXsgW/jk5f W4Eep9zUiM9PJG6r4t54X7+5UZuwzqJmIA1pfrxmDvKklMJJLcv3iKVCUbww0i5gvurf Y4DXFg2piFzvnvhI4Hw1pRJuscU8fkFdohBT80ZVHp18Dg9Zro5EYRJSrLZNlwBR8sXe oTDQ== X-Gm-Message-State: APjAAAW8AJ/Smf0roleEH5sLc2+EYNd4jUGrg3p9WLyt8/hmUikRL+hH eLG0HdjssZvFg0+3PAiPYO4= X-Google-Smtp-Source: APXvYqyN7ZztOZynAS2zVYioqIvY15L9IUm9DgxfrduwN8r28+SgkhFt/Fx4DayR43s+eDagPc/BCg== X-Received: by 2002:a17:90a:ac11:: with SMTP id o17mr19898276pjq.134.1561308153126; Sun, 23 Jun 2019 09:42:33 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id j2sm10687361pfn.135.2019.06.23.09.42.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:32 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 10/11] dt-bindings: thermal: add binding document for h3 thermal controller Date: Sun, 23 Jun 2019 12:42:05 -0400 Message-Id: <20190623164206.7467-11-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds binding document for allwinner h3 thermal controller. Signed-off-by: Yangtao Li --- .../bindings/thermal/sun8i-thermal.yaml | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml b/Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml index 2c5acc61ed03..1eaf68b5dd5a 100644 --- a/Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml +++ b/Documentation/devicetree/bindings/thermal/sun8i-thermal.yaml @@ -16,6 +16,7 @@ description: |- properties: compatible: enum: + - allwinner,sun8i-h3-ths - allwinner,sun50i-h6-ths reg: @@ -29,13 +30,22 @@ properties: clocks: minItems: 1 - maxItems: 1 + maxItems: 2 clock-names: - const: bus + items: + - const: bus + - const: ahb '#thermal-sensor-cells': - const: 1 + enum: [ 0, 1 ] + description: | + Definition depends on soc version: + + For "allwinner,sun8i-h3-ths", + value must be 0. + For "allwinner,sun50i-h6-ths", + value must be 1. nvmem-cells: items: @@ -55,6 +65,19 @@ required: - '#thermal-sensor-cells' examples: + - | + ths: ths@1c25000 { + compatible = "allwinner,sun8i-h3-ths"; + reg = <0x01c25000 0x400>; + clocks = <&ccu CLK_BUS_THS>, <&ccu CLK_THS>; + clock-names = "bus", "ahb"; + resets = <&ccu RST_BUS_THS>; + interrupts = ; + nvmem-cells = <&tsen_calib>; + nvmem-cell-names = "calib"; + #thermal-sensor-cells = <0>; + }; + - | ths: ths@5070400 { compatible = "allwinner,sun50i-h6-ths"; From patchwork Sun Jun 23 16:42:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 11011791 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C79914E5 for ; Sun, 23 Jun 2019 16:42:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A3E228A8C for ; Sun, 23 Jun 2019 16:42:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E57B28AD1; Sun, 23 Jun 2019 16:42:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0DCC28AA2 for ; Sun, 23 Jun 2019 16:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727063AbfFWQmf (ORCPT ); Sun, 23 Jun 2019 12:42:35 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34780 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727051AbfFWQmf (ORCPT ); Sun, 23 Jun 2019 12:42:35 -0400 Received: by mail-pf1-f195.google.com with SMTP id c85so6126389pfc.1; Sun, 23 Jun 2019 09:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Wt7RMWJEU5nf2APAW5wITney1vGRi8ExyzwA2ly5tbM=; b=DO56xL8GNC3pRjMbczek/js2aH+Jr00XhhADU2CusMADs20FUQ6om0QfFNRcH7bIok utY8iKwz2gs/7WHR18tlrl+XRM9KtdS9MZyCglgz5ZWErisPeGVp+BPEcw81Ezw1KyjP +I7gFX+cYEvLyjmwJRHb04L6mRZ4LjmdVX+GURXCGE4Ky2HFiZkXGwRma8nQVRg7xzb1 OpjjtLiiCN+Zc/sg6Vk26H04UbcX2a5L9ZDyAyFJkne9LJuc3SjKpjccxQ4NfVaSg62X sX8QGDvadx5+1F6N6uKmqbh/oIFj9SbUUmdqZyIvf9VMIoiCKn8bIS68Io+mfdDuE05u 4YKQ== 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:in-reply-to :references; bh=Wt7RMWJEU5nf2APAW5wITney1vGRi8ExyzwA2ly5tbM=; b=fuO5jCXvT1vmpjRvtSuaDIkIg7S+7itQPALdSigBTo1jNPKqr0yf8Dx0+lljpn5ZnE Y7wx43I3jTcF/jLWNG1xsZM66eosR8ZukLbd/Q+vP+Eqt6sDCHdHnoc4kKBLckAcVmlO rL9tlvuPW1tqKyBSTzGw54rDqlo3IxTDbfw6knFH0TcctocewGuudeEaJGsmTzYMAHzG /6ZCmCUPKrH+a81RT767/E5rhZjxLQ1kUBM2+hhtc1wQ010ndZc+xCFPtVeLfqnl1xab Rx1pVE+YxKHMNHgkwfUN8qrAS4+/jbZj8vg3ul/3tO0m/1q0wJA1+xnqDUqtfkm48kiC vZxA== X-Gm-Message-State: APjAAAVQHO5c5sns6gO7YkZPIOAX/sTt94K5OVx3W4YGnTByMEZPPGZ2 JmsewR9rTpyCUo6IqmFaZN0= X-Google-Smtp-Source: APXvYqyPdz3cE/WXdIcDs7kmAR8F/niCfqMamQH54dQcogysOpQv1BP/blKrSSByCMUg+zO2djgwVA== X-Received: by 2002:a17:90a:7f02:: with SMTP id k2mr19642846pjl.78.1561308154262; Sun, 23 Jun 2019 09:42:34 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id y17sm4923619pfe.148.2019.06.23.09.42.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2019 09:42:33 -0700 (PDT) From: Yangtao Li To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, linus.walleij@linaro.org, nicolas.ferre@microchip.com, paulmck@linux.ibm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v4 11/11] thermal: sun8i: add thermal driver for h3 Date: Sun, 23 Jun 2019 12:42:06 -0400 Message-Id: <20190623164206.7467-12-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190623164206.7467-1-tiny.windzz@gmail.com> References: <20190623164206.7467-1-tiny.windzz@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the support for allwinner h3 thermal sensor. Signed-off-by: Yangtao Li --- drivers/thermal/sun8i_thermal.c | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index 260b24340f5b..c8ee291f3b17 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -27,6 +27,14 @@ #define TEMP_TO_REG 672 #define CALIBRATE_DEFAULT 0x800 +#define SUN8I_THS_CTRL0 0x00 +#define SUN8I_THS_CTRL2 0x40 +#define SUN8I_THS_IC 0x44 +#define SUN8I_THS_IS 0x48 +#define SUN8I_THS_MFC 0x70 +#define SUN8I_THS_TEMP_CALIB 0x74 +#define SUN8I_THS_TEMP_DATA 0x80 + #define SUN50I_THS_CTRL0 0x00 #define SUN50I_H6_THS_ENABLE 0x04 #define SUN50I_H6_THS_PC 0x08 @@ -36,6 +44,9 @@ #define SUN50I_H6_THS_TEMP_CALIB 0xa0 #define SUN50I_H6_THS_TEMP_DATA 0xc0 +#define SUN8I_THS_CTRL0_T_ACQ0(x) (GENMASK(15, 0) & (x)) +#define SUN8I_THS_CTRL2_T_ACQ1(x) ((GENMASK(15, 0) & (x)) << 16) + #define SUN50I_THS_CTRL0_T_ACQ(x) ((GENMASK(15, 0) & (x)) << 16) #define SUN50I_THS_FILTER_EN BIT(2) #define SUN50I_THS_FILTER_TYPE(x) (GENMASK(1, 0) & (x)) @@ -121,6 +132,21 @@ static const struct regmap_config config = { .fast_io = true, }; +static int sun8i_h3_irq_ack(struct ths_device *tmdev) +{ + int state, ret = 0; + + regmap_read(tmdev->regmap, SUN8I_THS_IS, &state); + + if (state & BIT(8)) { + regmap_write(tmdev->regmap, SUN8I_THS_IS, + BIT(8)); + ret |= BIT(1); + } + + return ret; +} + static int sun50i_h6_irq_ack(struct ths_device *tmdev) { int i, state, ret = 0; @@ -154,6 +180,14 @@ static irqreturn_t sun8i_irq_thread(int irq, void *data) return IRQ_HANDLED; } +static int sun8i_h3_ths_calibrate(struct ths_device *tmdev, + u16 *caldata, int callen) +{ + regmap_write(tmdev->regmap, SUN8I_THS_TEMP_CALIB, *caldata); + + return 0; +} + static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, u16 *caldata, int callen) { @@ -325,6 +359,32 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev) return ret; } +static int sun8i_h3_thermal_init(struct ths_device *tmdev) +{ + /* average over 4 samples */ + regmap_write(tmdev->regmap, SUN8I_THS_MFC, + SUN50I_THS_FILTER_EN | + SUN50I_THS_FILTER_TYPE(1)); + /* + * period = (x + 1) * 4096 / clkin; ~10ms + * enable data interrupt + */ + regmap_write(tmdev->regmap, SUN8I_THS_IC, + SUN50I_H6_THS_PC_TEMP_PERIOD(58) | BIT(8)); + /* + * clkin = 24MHz + * T acquire = clkin / (x + 1) + * = 20us + * enable sensor + */ + regmap_write(tmdev->regmap, SUN8I_THS_CTRL0, + SUN8I_THS_CTRL0_T_ACQ0(479)); + regmap_write(tmdev->regmap, SUN8I_THS_CTRL2, + SUN8I_THS_CTRL2_T_ACQ1(479) | BIT(0)); + + return 0; +} + static int sun50i_thermal_init(struct ths_device *tmdev) { int val; @@ -431,6 +491,17 @@ static int sun8i_ths_remove(struct platform_device *pdev) return 0; } +static const struct ths_thermal_chip sun8i_h3_ths = { + .sensor_num = 1, + .offset = -1794, + .scale = -121, + .has_ahb_clk = true, + .temp_data_base = SUN8I_THS_TEMP_DATA, + .calibrate = sun8i_h3_ths_calibrate, + .init = sun8i_h3_thermal_init, + .irq_ack = sun8i_h3_irq_ack, +}; + static const struct ths_thermal_chip sun50i_h6_ths = { .sensor_num = 2, .offset = -2794, @@ -443,6 +514,7 @@ static const struct ths_thermal_chip sun50i_h6_ths = { }; static const struct of_device_id of_ths_match[] = { + { .compatible = "allwinner,sun8i-h3-ths", .data = &sun8i_h3_ths }, { .compatible = "allwinner,sun50i-h6-ths", .data = &sun50i_h6_ths }, { /* sentinel */ }, };