blob: a4befd2d683d03ae79f123cee2cb2a73010894d2 [file] [log] [blame]
Ezequiel Garciafa0d6542013-04-02 01:37:41 +00001/*
Miquel Raynala9d58a12017-12-22 17:14:10 +01002 * Marvell EBU Armada SoCs thermal sensor driver
Ezequiel Garciafa0d6542013-04-02 01:37:41 +00003 *
4 * Copyright (C) 2013 Marvell
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16#include <linux/device.h>
17#include <linux/err.h>
18#include <linux/io.h>
19#include <linux/kernel.h>
20#include <linux/of.h>
21#include <linux/module.h>
22#include <linux/delay.h>
23#include <linux/platform_device.h>
24#include <linux/of_device.h>
25#include <linux/thermal.h>
Miquel Raynal64163682017-12-22 17:14:12 +010026#include <linux/iopoll.h>
Ezequiel Garciafa0d6542013-04-02 01:37:41 +000027
Ezequiel Garciafa0d6542013-04-02 01:37:41 +000028/* Thermal Manager Control and Status Register */
29#define PMU_TDC0_SW_RST_MASK (0x1 << 1)
30#define PMU_TM_DISABLE_OFFS 0
31#define PMU_TM_DISABLE_MASK (0x1 << PMU_TM_DISABLE_OFFS)
32#define PMU_TDC0_REF_CAL_CNT_OFFS 11
33#define PMU_TDC0_REF_CAL_CNT_MASK (0x1ff << PMU_TDC0_REF_CAL_CNT_OFFS)
34#define PMU_TDC0_OTF_CAL_MASK (0x1 << 30)
35#define PMU_TDC0_START_CAL_MASK (0x1 << 25)
36
Ezequiel Garciae2d5f052014-05-06 13:59:50 -030037#define A375_UNIT_CONTROL_SHIFT 27
38#define A375_UNIT_CONTROL_MASK 0x7
39#define A375_READOUT_INVERT BIT(15)
40#define A375_HW_RESETn BIT(8)
41
Miquel Raynal2f28e4c2017-12-22 17:14:06 +010042/* Legacy bindings */
43#define LEGACY_CONTROL_MEM_LEN 0x4
44
45/* Current bindings with the 2 control registers under the same memory area */
46#define LEGACY_CONTROL1_OFFSET 0x0
47#define CONTROL0_OFFSET 0x0
48#define CONTROL1_OFFSET 0x4
49
Miquel Raynal8c0b8882017-12-22 17:14:11 +010050/* Errata fields */
51#define CONTROL0_TSEN_TC_TRIM_MASK 0x7
52#define CONTROL0_TSEN_TC_TRIM_VAL 0x3
53
Baruch Siach2ff12792017-12-22 17:14:08 +010054/* TSEN refers to the temperature sensors within the AP */
55#define CONTROL0_TSEN_START BIT(0)
56#define CONTROL0_TSEN_RESET BIT(1)
57#define CONTROL0_TSEN_ENABLE BIT(2)
58
Baruch Siachccf8f522017-12-22 17:14:09 +010059/* EXT_TSEN refers to the external temperature sensors, out of the AP */
60#define CONTROL1_EXT_TSEN_SW_RESET BIT(7)
61#define CONTROL1_EXT_TSEN_HW_RESETn BIT(8)
62
Miquel Raynal64163682017-12-22 17:14:12 +010063#define STATUS_POLL_PERIOD_US 1000
64#define STATUS_POLL_TIMEOUT_US 100000
65
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -030066struct armada_thermal_data;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +000067
68/* Marvell EBU Thermal Sensor Dev Structure */
69struct armada_thermal_priv {
Miquel Raynal8371b8a2017-12-22 17:14:07 +010070 void __iomem *status;
Miquel Raynal2f28e4c2017-12-22 17:14:06 +010071 void __iomem *control0;
72 void __iomem *control1;
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -030073 struct armada_thermal_data *data;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +000074};
75
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -030076struct armada_thermal_data {
Ezequiel Garciafa0d6542013-04-02 01:37:41 +000077 /* Initialize the sensor */
Ezequiel Garcia04bf3d72014-05-06 13:59:48 -030078 void (*init_sensor)(struct platform_device *pdev,
79 struct armada_thermal_priv *);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +000080
81 /* Test for a valid sensor value (optional) */
82 bool (*is_valid)(struct armada_thermal_priv *);
Ezequiel Garcia9484bc62014-05-06 13:59:46 -030083
Baruch Siach0cf3a1a2017-09-14 18:06:57 +030084 /* Formula coeficients: temp = (b - m * reg) / div */
Baruch Siach2ff12792017-12-22 17:14:08 +010085 s64 coef_b;
86 s64 coef_m;
87 u32 coef_div;
Ezequiel Garciafd2c94d2014-05-06 13:59:49 -030088 bool inverted;
Baruch Siach2ff12792017-12-22 17:14:08 +010089 bool signed_sample;
Ezequiel Garcia1fcacca2014-05-06 13:59:47 -030090
91 /* Register shift and mask to access the sensor temperature */
92 unsigned int temp_shift;
93 unsigned int temp_mask;
Miquel Raynal27d92f22017-12-22 17:14:05 +010094 u32 is_valid_bit;
Miquel Raynal2f28e4c2017-12-22 17:14:06 +010095 bool needs_control0;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +000096};
97
Ezequiel Garcia04bf3d72014-05-06 13:59:48 -030098static void armadaxp_init_sensor(struct platform_device *pdev,
99 struct armada_thermal_priv *priv)
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000100{
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100101 u32 reg;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000102
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100103 reg = readl_relaxed(priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000104 reg |= PMU_TDC0_OTF_CAL_MASK;
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100105 writel(reg, priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000106
107 /* Reference calibration value */
108 reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
109 reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100110 writel(reg, priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000111
112 /* Reset the sensor */
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100113 reg = readl_relaxed(priv->control1);
114 writel((reg | PMU_TDC0_SW_RST_MASK), priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000115
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100116 writel(reg, priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000117
118 /* Enable the sensor */
Miquel Raynal8371b8a2017-12-22 17:14:07 +0100119 reg = readl_relaxed(priv->status);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000120 reg &= ~PMU_TM_DISABLE_MASK;
Miquel Raynal8371b8a2017-12-22 17:14:07 +0100121 writel(reg, priv->status);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000122}
123
Ezequiel Garcia04bf3d72014-05-06 13:59:48 -0300124static void armada370_init_sensor(struct platform_device *pdev,
125 struct armada_thermal_priv *priv)
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000126{
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100127 u32 reg;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000128
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100129 reg = readl_relaxed(priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000130 reg |= PMU_TDC0_OTF_CAL_MASK;
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100131 writel(reg, priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000132
133 /* Reference calibration value */
134 reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
135 reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100136 writel(reg, priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000137
138 reg &= ~PMU_TDC0_START_CAL_MASK;
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100139 writel(reg, priv->control1);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000140
Baruch Siach7f3be012017-12-22 17:14:04 +0100141 msleep(10);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000142}
143
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300144static void armada375_init_sensor(struct platform_device *pdev,
145 struct armada_thermal_priv *priv)
146{
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100147 u32 reg;
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300148
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100149 reg = readl(priv->control1);
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300150 reg &= ~(A375_UNIT_CONTROL_MASK << A375_UNIT_CONTROL_SHIFT);
151 reg &= ~A375_READOUT_INVERT;
152 reg &= ~A375_HW_RESETn;
153
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100154 writel(reg, priv->control1);
Baruch Siach7f3be012017-12-22 17:14:04 +0100155 msleep(20);
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300156
157 reg |= A375_HW_RESETn;
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100158 writel(reg, priv->control1);
Baruch Siach7f3be012017-12-22 17:14:04 +0100159 msleep(50);
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300160}
161
Miquel Raynal64163682017-12-22 17:14:12 +0100162static void armada_wait_sensor_validity(struct armada_thermal_priv *priv)
163{
164 u32 reg;
165
166 readl_relaxed_poll_timeout(priv->status, reg,
167 reg & priv->data->is_valid_bit,
168 STATUS_POLL_PERIOD_US,
169 STATUS_POLL_TIMEOUT_US);
170}
171
Ezequiel Garciae6e0a682014-05-06 13:59:51 -0300172static void armada380_init_sensor(struct platform_device *pdev,
173 struct armada_thermal_priv *priv)
174{
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100175 u32 reg = readl_relaxed(priv->control1);
Ezequiel Garciae6e0a682014-05-06 13:59:51 -0300176
Baruch Siachccf8f522017-12-22 17:14:09 +0100177 /* Disable the HW/SW reset */
178 reg |= CONTROL1_EXT_TSEN_HW_RESETn;
179 reg &= ~CONTROL1_EXT_TSEN_SW_RESET;
180 writel(reg, priv->control1);
Miquel Raynal8c0b8882017-12-22 17:14:11 +0100181
182 /* Set Tsen Tc Trim to correct default value (errata #132698) */
183 if (priv->control0) {
184 reg = readl_relaxed(priv->control0);
185 reg &= ~CONTROL0_TSEN_TC_TRIM_MASK;
186 reg |= CONTROL0_TSEN_TC_TRIM_VAL;
187 writel(reg, priv->control0);
Miquel Raynal8c0b8882017-12-22 17:14:11 +0100188 }
Miquel Raynal64163682017-12-22 17:14:12 +0100189
190 /* Wait the sensors to be valid or the core will warn the user */
191 armada_wait_sensor_validity(priv);
Ezequiel Garciae6e0a682014-05-06 13:59:51 -0300192}
193
Baruch Siach2ff12792017-12-22 17:14:08 +0100194static void armada_ap806_init_sensor(struct platform_device *pdev,
195 struct armada_thermal_priv *priv)
196{
197 u32 reg;
198
199 reg = readl_relaxed(priv->control0);
200 reg &= ~CONTROL0_TSEN_RESET;
201 reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_ENABLE;
202 writel(reg, priv->control0);
Miquel Raynal64163682017-12-22 17:14:12 +0100203
204 /* Wait the sensors to be valid or the core will warn the user */
205 armada_wait_sensor_validity(priv);
Baruch Siach2ff12792017-12-22 17:14:08 +0100206}
207
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000208static bool armada_is_valid(struct armada_thermal_priv *priv)
209{
Miquel Raynal8371b8a2017-12-22 17:14:07 +0100210 u32 reg = readl_relaxed(priv->status);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000211
Miquel Raynal27d92f22017-12-22 17:14:05 +0100212 return reg & priv->data->is_valid_bit;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000213}
214
215static int armada_get_temp(struct thermal_zone_device *thermal,
Baruch Siach2ff12792017-12-22 17:14:08 +0100216 int *temp)
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000217{
218 struct armada_thermal_priv *priv = thermal->devdata;
Baruch Siach2ff12792017-12-22 17:14:08 +0100219 u32 reg, div;
220 s64 sample, b, m;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000221
222 /* Valid check */
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -0300223 if (priv->data->is_valid && !priv->data->is_valid(priv)) {
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000224 dev_err(&thermal->device,
225 "Temperature sensor reading not valid\n");
226 return -EIO;
227 }
228
Miquel Raynal8371b8a2017-12-22 17:14:07 +0100229 reg = readl_relaxed(priv->status);
Ezequiel Garcia1fcacca2014-05-06 13:59:47 -0300230 reg = (reg >> priv->data->temp_shift) & priv->data->temp_mask;
Baruch Siach2ff12792017-12-22 17:14:08 +0100231 if (priv->data->signed_sample)
232 /* The most significant bit is the sign bit */
233 sample = sign_extend32(reg, fls(priv->data->temp_mask) - 1);
234 else
235 sample = reg;
Ezequiel Garcia9484bc62014-05-06 13:59:46 -0300236
237 /* Get formula coeficients */
238 b = priv->data->coef_b;
239 m = priv->data->coef_m;
240 div = priv->data->coef_div;
241
Ezequiel Garciafd2c94d2014-05-06 13:59:49 -0300242 if (priv->data->inverted)
Baruch Siach2ff12792017-12-22 17:14:08 +0100243 *temp = div_s64((m * sample) - b, div);
Ezequiel Garciafd2c94d2014-05-06 13:59:49 -0300244 else
Baruch Siach2ff12792017-12-22 17:14:08 +0100245 *temp = div_s64(b - (m * sample), div);
246
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000247 return 0;
248}
249
250static struct thermal_zone_device_ops ops = {
251 .get_temp = armada_get_temp,
252};
253
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -0300254static const struct armada_thermal_data armadaxp_data = {
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000255 .init_sensor = armadaxp_init_sensor,
Ezequiel Garcia1fcacca2014-05-06 13:59:47 -0300256 .temp_shift = 10,
257 .temp_mask = 0x1ff,
Baruch Siach2ff12792017-12-22 17:14:08 +0100258 .coef_b = 3153000000ULL,
259 .coef_m = 10000000ULL,
Ezequiel Garcia9484bc62014-05-06 13:59:46 -0300260 .coef_div = 13825,
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000261};
262
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -0300263static const struct armada_thermal_data armada370_data = {
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000264 .is_valid = armada_is_valid,
265 .init_sensor = armada370_init_sensor,
Miquel Raynal27d92f22017-12-22 17:14:05 +0100266 .is_valid_bit = BIT(9),
Ezequiel Garcia1fcacca2014-05-06 13:59:47 -0300267 .temp_shift = 10,
268 .temp_mask = 0x1ff,
Baruch Siach2ff12792017-12-22 17:14:08 +0100269 .coef_b = 3153000000ULL,
270 .coef_m = 10000000ULL,
Ezequiel Garcia9484bc62014-05-06 13:59:46 -0300271 .coef_div = 13825,
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000272};
273
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300274static const struct armada_thermal_data armada375_data = {
275 .is_valid = armada_is_valid,
276 .init_sensor = armada375_init_sensor,
Miquel Raynal27d92f22017-12-22 17:14:05 +0100277 .is_valid_bit = BIT(10),
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300278 .temp_shift = 0,
279 .temp_mask = 0x1ff,
Baruch Siach2ff12792017-12-22 17:14:08 +0100280 .coef_b = 3171900000ULL,
281 .coef_m = 10000000ULL,
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300282 .coef_div = 13616,
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100283 .needs_control0 = true,
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300284};
285
Ezequiel Garciae6e0a682014-05-06 13:59:51 -0300286static const struct armada_thermal_data armada380_data = {
287 .is_valid = armada_is_valid,
288 .init_sensor = armada380_init_sensor,
Miquel Raynal27d92f22017-12-22 17:14:05 +0100289 .is_valid_bit = BIT(10),
Ezequiel Garciae6e0a682014-05-06 13:59:51 -0300290 .temp_shift = 0,
291 .temp_mask = 0x3ff,
Baruch Siach2ff12792017-12-22 17:14:08 +0100292 .coef_b = 1172499100ULL,
293 .coef_m = 2000096ULL,
Nadav Haklaib56100d2015-08-06 18:03:49 +0200294 .coef_div = 4201,
Ezequiel Garciae6e0a682014-05-06 13:59:51 -0300295 .inverted = true,
296};
297
Baruch Siach2ff12792017-12-22 17:14:08 +0100298static const struct armada_thermal_data armada_ap806_data = {
299 .is_valid = armada_is_valid,
300 .init_sensor = armada_ap806_init_sensor,
301 .is_valid_bit = BIT(16),
302 .temp_shift = 0,
303 .temp_mask = 0x3ff,
304 .coef_b = -150000LL,
305 .coef_m = 423ULL,
306 .coef_div = 1,
307 .inverted = true,
308 .signed_sample = true,
309 .needs_control0 = true,
310};
311
Baruch Siachccf8f522017-12-22 17:14:09 +0100312static const struct armada_thermal_data armada_cp110_data = {
313 .is_valid = armada_is_valid,
314 .init_sensor = armada380_init_sensor,
315 .is_valid_bit = BIT(10),
316 .temp_shift = 0,
317 .temp_mask = 0x3ff,
318 .coef_b = 1172499100ULL,
319 .coef_m = 2000096ULL,
320 .coef_div = 4201,
321 .inverted = true,
322 .needs_control0 = true,
323};
324
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000325static const struct of_device_id armada_thermal_id_table[] = {
326 {
327 .compatible = "marvell,armadaxp-thermal",
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -0300328 .data = &armadaxp_data,
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000329 },
330 {
331 .compatible = "marvell,armada370-thermal",
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -0300332 .data = &armada370_data,
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000333 },
334 {
Ezequiel Garciae2d5f052014-05-06 13:59:50 -0300335 .compatible = "marvell,armada375-thermal",
336 .data = &armada375_data,
337 },
338 {
Ezequiel Garciae6e0a682014-05-06 13:59:51 -0300339 .compatible = "marvell,armada380-thermal",
340 .data = &armada380_data,
341 },
342 {
Baruch Siach2ff12792017-12-22 17:14:08 +0100343 .compatible = "marvell,armada-ap806-thermal",
344 .data = &armada_ap806_data,
345 },
346 {
Baruch Siachccf8f522017-12-22 17:14:09 +0100347 .compatible = "marvell,armada-cp110-thermal",
348 .data = &armada_cp110_data,
349 },
350 {
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000351 /* sentinel */
352 },
353};
354MODULE_DEVICE_TABLE(of, armada_thermal_id_table);
355
356static int armada_thermal_probe(struct platform_device *pdev)
357{
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100358 void __iomem *control = NULL;
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000359 struct thermal_zone_device *thermal;
360 const struct of_device_id *match;
361 struct armada_thermal_priv *priv;
362 struct resource *res;
363
364 match = of_match_device(armada_thermal_id_table, &pdev->dev);
365 if (!match)
366 return -ENODEV;
367
368 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
369 if (!priv)
370 return -ENOMEM;
371
372 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Miquel Raynal8371b8a2017-12-22 17:14:07 +0100373 priv->status = devm_ioremap_resource(&pdev->dev, res);
374 if (IS_ERR(priv->status))
375 return PTR_ERR(priv->status);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000376
377 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100378 control = devm_ioremap_resource(&pdev->dev, res);
379 if (IS_ERR(control))
380 return PTR_ERR(control);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000381
Ezequiel Garcia66fdb7b2014-05-06 13:59:45 -0300382 priv->data = (struct armada_thermal_data *)match->data;
Miquel Raynal2f28e4c2017-12-22 17:14:06 +0100383
384 /*
385 * Legacy DT bindings only described "control1" register (also referred
386 * as "control MSB" on old documentation). New bindings cover
387 * "control0/control LSB" and "control1/control MSB" registers within
388 * the same resource, which is then of size 8 instead of 4.
389 */
390 if (resource_size(res) == LEGACY_CONTROL_MEM_LEN) {
391 /* ->control0 unavailable in this configuration */
392 if (priv->data->needs_control0) {
393 dev_err(&pdev->dev, "No access to control0 register\n");
394 return -EINVAL;
395 }
396
397 priv->control1 = control + LEGACY_CONTROL1_OFFSET;
398 } else {
399 priv->control0 = control + CONTROL0_OFFSET;
400 priv->control1 = control + CONTROL1_OFFSET;
401 }
402
Ezequiel Garcia04bf3d72014-05-06 13:59:48 -0300403 priv->data->init_sensor(pdev, priv);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000404
405 thermal = thermal_zone_device_register("armada_thermal", 0, 0,
406 priv, &ops, NULL, 0, 0);
407 if (IS_ERR(thermal)) {
408 dev_err(&pdev->dev,
409 "Failed to register thermal zone device\n");
410 return PTR_ERR(thermal);
411 }
412
413 platform_set_drvdata(pdev, thermal);
414
415 return 0;
416}
417
418static int armada_thermal_exit(struct platform_device *pdev)
419{
420 struct thermal_zone_device *armada_thermal =
421 platform_get_drvdata(pdev);
422
423 thermal_zone_device_unregister(armada_thermal);
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000424
425 return 0;
426}
427
428static struct platform_driver armada_thermal_driver = {
429 .probe = armada_thermal_probe,
430 .remove = armada_thermal_exit,
431 .driver = {
432 .name = "armada_thermal",
Sachin Kamat1d089e02013-05-16 10:28:08 +0000433 .of_match_table = armada_thermal_id_table,
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000434 },
435};
436
437module_platform_driver(armada_thermal_driver);
438
439MODULE_AUTHOR("Ezequiel Garcia <ezequiel.garcia@free-electrons.com>");
Miquel Raynala9d58a12017-12-22 17:14:10 +0100440MODULE_DESCRIPTION("Marvell EBU Armada SoCs thermal driver");
Ezequiel Garciafa0d6542013-04-02 01:37:41 +0000441MODULE_LICENSE("GPL v2");