Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2754017imj; Mon, 18 Feb 2019 11:33:25 -0800 (PST) X-Google-Smtp-Source: AHgI3Iatey8dn5CBHRl/3rw5zlQen7xsBlmPwLq+ThDT0JRkR/3V0eGV6BJRN/7lnk42G0TRO9Le X-Received: by 2002:a17:902:a50a:: with SMTP id s10mr8908329plq.223.1550518405151; Mon, 18 Feb 2019 11:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550518405; cv=none; d=google.com; s=arc-20160816; b=UmLKsctGqQqnRJeuAB1TquKVsTPdZbv5P0B806p7YbHLrGpAQoLoGroVGnXnzLCOjM /b+27o3m6eyema5tbkkewv4/q4Cctfna3oW5qDGBZImY0CYLjTCplwsEetrlvEJY/g43 5TVRMy6PhQOK2hR8PXohq9IUg2IsR6k3jiGFfN3NobMvh72IXVshczJzy/650u9ImICI AOmBxlXpU/4VWiJIlqHSlxgMKvpyArDyuurnNL+h+fTdhS8QK6JMzQkGYOmxUMKXl+ie btUExtIpyug/CjssJT5VP+Pe3OatwGrBtZqkUn7U5wlapxwEwsOsb09ImNZdKAFDrMGg RhWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IdPVPuEItDnwPeK60nkAnUjf6UZpWVTdqGrlfCeQJY8=; b=hORoCL3H1BIyHqGwU6zAxkRn8Kbq/YT02LM7ZyBiZXpnMW2DuyTN0/01i3oVBF7ujn FvrO88IDqAVm8AQBtZ9d0H/iB62YR5PoRZh5Bz5VXMkpvysklXz1I3uQ91S/nR9MT/ci RkK0JaqcAZHnlBHUpgPVKcPEt96ldGYS2W94XYCu7t9ThtC3Y5vyRnowzqk22gSkdZ5s rX42U8tGHnor5T14TeaAh3mHTX3ssz1AB8QvowEhS2CL67YTjYcgzHY2wffHLkkmsa/+ VmgCMt3SQr5kXzwut10e9Ue5GXs7TftGe3NJMgRDCK6Vw6UZ+al+isGais5KKNWYAB5m ZjpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ICrn/E3o"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u25si12064509pgm.532.2019.02.18.11.33.09; Mon, 18 Feb 2019 11:33:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ICrn/E3o"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728853AbfBRTMX (ORCPT + 99 others); Mon, 18 Feb 2019 14:12:23 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34373 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728698AbfBRTMQ (ORCPT ); Mon, 18 Feb 2019 14:12:16 -0500 Received: by mail-pl1-f194.google.com with SMTP id d15so2036956plr.1; Mon, 18 Feb 2019 11:12:15 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=IdPVPuEItDnwPeK60nkAnUjf6UZpWVTdqGrlfCeQJY8=; b=ICrn/E3oIZYvK2gWlCUyH0f0zGyqiE+Yo1rohr7Gz+V5VM26o1HPye+N9AFCQ3d+KB sJnAuSQJClVTPOomI7AdmiBs1rk0NiUwmervsgh8PYq8CMFOhUlTMxuJdOEYJo55xypF KQFDsm0HwgvLCZhlDbzy+CjILmuNXvHXK+QHnx3qxN3RYZZoL5RG6PQWXj6UyJ5yZVS7 a7uYLgU2vTDdC9pemKgMZj/cXzUrP4XDBhKtVONEjslaAiPVLJHBGqQYTTnRATjBpAby yP+TqRHMxAnslIx98Ms4BYdMHnw0wRYXAVH5huh0+kRx8cKOTXr8/+IFHbAjaL8liktZ T3UQ== 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:mime-version:content-transfer-encoding; bh=IdPVPuEItDnwPeK60nkAnUjf6UZpWVTdqGrlfCeQJY8=; b=U0o4BR/s/ggD0ppxK/Bm3z25TVYkj+cMGYhQxt3Wr4y9KY9Cx57NNYSOKUyIdoVXGo FAxwwBpL9j0PQrrTS/5MaxkrPI9W8Bqd4iI5/PLOsIJep/rgAEWVLa6lSlsoDvGuMXg+ dPsklK+Fkinxn6y5G2vE+RXC5GvWmqTaNB98i16Jvsh8Phtlqq/gudYxnDqQpHzGY5d3 06ysjJFWtNTel1673b2hRfPCyfIKBZSx0k09fiM7liIIatrU4s6TPas1+rEJpE7gyVpn XQf1jii8yOK5zqjpZ6BnPejH2sWIKaQNOZd+r+CUBbHXNF08tlrOhch8wnLJyGoNWP4u JT7A== X-Gm-Message-State: AHQUAubd5kphqDFoNPCkIfRaka5qUF+QILJHsgHGLApXpg6yo95HPF5j Vt8NEg5anejkbCt/YZW9xDhABD+B X-Received: by 2002:a17:902:5a42:: with SMTP id f2mr16767498plm.157.1550517135092; Mon, 18 Feb 2019 11:12:15 -0800 (PST) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id t12sm33189727pgq.68.2019.02.18.11.12.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 11:12:14 -0800 (PST) From: Andrey Smirnov To: linux-pm@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , Zhang Rui , Eduardo Valentin , Daniel Lezcano , linux-imx@nxp.com, linux-kernel@vger.kernel.org Subject: [PATCH 12/12] thermal: qoriq: Add support for multiple thremal sites Date: Mon, 18 Feb 2019 11:11:41 -0800 Message-Id: <20190218191141.3729-13-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218191141.3729-1-andrew.smirnov@gmail.com> References: <20190218191141.3729-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TMU IP block provides temerature measurement for up to 16 sites, current implementation of the driver however hardcodes a single site ID. Change the code so it would be possible to reference multiple sites as indivudial sensors and get their temperature readings. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Zhang Rui Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 132 ++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 48 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index f746c62789b0..6cc6e6b36fb0 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -24,6 +24,8 @@ #define TMR_DISABLE 0x0 #define TMR_ME 0x80000000 #define TMR_ALPF 0x0c000000 +#define TMR_ALPF_MASK GENMASK(27, 26) + #define REGS_TMTMIR 0x008 /* Temperature measurement interval Register */ #define TMTMIR_DEFAULT 0x0000000f @@ -41,21 +43,32 @@ #define REGS_TTRnCR(n) (0xf10 + 4 * (n)) /* Temperature Range n * Control Register */ +struct qoriq_tmu_sensor { + struct thermal_zone_device *tz; + int id; +}; + /* * Thermal zone data */ struct qoriq_tmu_data { struct thermal_zone_device *tz; struct regmap *regmap; - int sensor_id; + struct qoriq_tmu_sensor sensors[SITES_MAX]; }; +static struct qoriq_tmu_data *qoriq_sensor_to_data(struct qoriq_tmu_sensor *s) +{ + return container_of(s, struct qoriq_tmu_data, sensors[s->id]); +} + static int tmu_get_temp(void *p, int *temp) { u32 val; - struct qoriq_tmu_data *data = p; + struct qoriq_tmu_sensor *s = p; + struct qoriq_tmu_data *data = qoriq_sensor_to_data(s); - regmap_read(data->regmap, REGS_TRITSR(data->sensor_id), &val); + regmap_read(data->regmap, REGS_TRITSR(s->id), &val); if (!(val & TRITSR_V)) return -ENODATA; @@ -63,38 +76,86 @@ static int tmu_get_temp(void *p, int *temp) return 0; } -static int qoriq_tmu_get_sensor_id(void) +static const struct thermal_zone_of_device_ops tmu_tz_ops = { + .get_temp = tmu_get_temp, +}; + +static int qoriq_tmu_populate_sensors(struct device *dev, + struct qoriq_tmu_data *data) { - int ret, id; + int ret, id, i, count = 0; struct of_phandle_args sensor_specs; struct device_node *np, *sensor_np; + struct qoriq_tmu_sensor *s; np = of_find_node_by_name(NULL, "thermal-zones"); if (!np) return -ENODEV; - sensor_np = of_get_next_child(np, NULL); - ret = of_parse_phandle_with_args(sensor_np, "thermal-sensors", - "#thermal-sensor-cells", - 0, &sensor_specs); - if (ret) { - id = ret; - goto out; + for_each_child_of_node(np, sensor_np) { + u16 msite; + + ret = of_parse_phandle_with_args(sensor_np, "thermal-sensors", + "#thermal-sensor-cells", + 0, &sensor_specs); + if (ret) + break; + + if (sensor_specs.args_count != 1) { + pr_err("%pOFn: Invalid number of cells in sensor specifier %d\n", + sensor_specs.np, sensor_specs.args_count); + ret = -EINVAL; + break; + } + + id = sensor_specs.args[0]; + if (id >= SITES_MAX) { + ret = -EINVAL; + dev_err(dev, "Sensor id %d is out of range\n", id); + break; + } + + msite = BIT(15 - id); + /* Enable monitoring of that particular sensor*/ + regmap_update_bits(data->regmap, REGS_TMR, msite, msite); + + s = &data->sensors[id]; + s->id = id; + count++; } - if (sensor_specs.args_count != 1) { - pr_err("%pOFn: Invalid number of cells in sensor specifier %d\n", - sensor_specs.np, sensor_specs.args_count); - id = -EINVAL; - goto out; + of_node_put(np); + if (ret) { + /* We only need to "put" sensor_np if we exited the + * loop early with "break" + */ + of_node_put(sensor_np); + return ret; } - id = sensor_specs.args[0]; -out: - of_node_put(np); - of_node_put(sensor_np); + /* Enable monitoring */ + regmap_update_bits(data->regmap, REGS_TMR, TMR_ME | TMR_ALPF_MASK, + TMR_ME | TMR_ALPF); + + for (i = 0; i < count; i++) { + s = &data->sensors[i]; + s->tz = devm_thermal_zone_of_sensor_register(dev, s->id, s, + &tmu_tz_ops); + if (IS_ERR(s->tz)) { + ret = PTR_ERR(s->tz); + dev_err(dev, + "Failed to register thermal zone device %d\n", + ret); + break; + } + + ret = devm_thermal_add_hwmon_sysfs(s->tz); + if (ret) + break; + + } - return id; + return ret; } static int qoriq_tmu_calibration(struct device *dev, @@ -142,10 +203,6 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data) regmap_write(data->regmap, REGS_TMR, TMR_DISABLE); } -static const struct thermal_zone_of_device_ops tmu_tz_ops = { - .get_temp = tmu_get_temp, -}; - static const struct regmap_range qiriq_wr_yes_ranges[] = { regmap_reg_range(REGS_TMR, REGS_TSCFGR), regmap_reg_range(REGS_TTRnCR(0), REGS_TTRnCR(3)), @@ -187,19 +244,12 @@ static int qoriq_tmu_probe(struct platform_device *pdev) .max_register = SZ_4K, }; void __iomem *base; - u32 site; data = devm_kzalloc(dev, sizeof(struct qoriq_tmu_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->sensor_id = qoriq_tmu_get_sensor_id(); - if (data->sensor_id < 0) { - dev_err(dev, "Failed to get sensor id\n"); - return -ENODEV; - } - io = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!io) { dev_err(dev, "Failed to get memory region\n"); @@ -225,21 +275,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev) if (ret < 0) return ret; - /* Enable monitoring */ - site = 0x1 << (15 - data->sensor_id); - regmap_write(data->regmap, REGS_TMR, site | TMR_ME | TMR_ALPF); - - data->tz = devm_thermal_zone_of_sensor_register(dev, - data->sensor_id, - data, &tmu_tz_ops); - if (IS_ERR(data->tz)) { - ret = PTR_ERR(data->tz); - dev_err(dev, "Failed to register thermal zone device %d\n", - ret); - goto disable_monitoring; - } - - ret = devm_thermal_add_hwmon_sysfs(data->tz); + ret = qoriq_tmu_populate_sensors(dev, data); if (ret) goto disable_monitoring; -- 2.20.1