Commit 69b628ac authored by Amit Kucheria's avatar Amit Kucheria Committed by Eduardo Valentin

drivers: thermal: tsens: Rename variable tmdev

tmdev seems to imply that this is a device pointer when in fact it is
just private platform data for each tsens device. Rename it to priv
improve code readability.
Signed-off-by: default avatarAmit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent 24ae4472
...@@ -39,23 +39,23 @@ ...@@ -39,23 +39,23 @@
#define CAL_SEL_MASK 0xe0000000 #define CAL_SEL_MASK 0xe0000000
#define CAL_SEL_SHIFT 29 #define CAL_SEL_SHIFT 29
static int calibrate_8916(struct tsens_priv *tmdev) static int calibrate_8916(struct tsens_priv *priv)
{ {
int base0 = 0, base1 = 0, i; int base0 = 0, base1 = 0, i;
u32 p1[5], p2[5]; u32 p1[5], p2[5];
int mode = 0; int mode = 0;
u32 *qfprom_cdata, *qfprom_csel; u32 *qfprom_cdata, *qfprom_csel;
qfprom_cdata = (u32 *)qfprom_read(tmdev->dev, "calib"); qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata)) if (IS_ERR(qfprom_cdata))
return PTR_ERR(qfprom_cdata); return PTR_ERR(qfprom_cdata);
qfprom_csel = (u32 *)qfprom_read(tmdev->dev, "calib_sel"); qfprom_csel = (u32 *)qfprom_read(priv->dev, "calib_sel");
if (IS_ERR(qfprom_csel)) if (IS_ERR(qfprom_csel))
return PTR_ERR(qfprom_csel); return PTR_ERR(qfprom_csel);
mode = (qfprom_csel[0] & CAL_SEL_MASK) >> CAL_SEL_SHIFT; mode = (qfprom_csel[0] & CAL_SEL_MASK) >> CAL_SEL_SHIFT;
dev_dbg(tmdev->dev, "calibration mode is %d\n", mode); dev_dbg(priv->dev, "calibration mode is %d\n", mode);
switch (mode) { switch (mode) {
case TWO_PT_CALIB: case TWO_PT_CALIB:
...@@ -65,7 +65,7 @@ static int calibrate_8916(struct tsens_priv *tmdev) ...@@ -65,7 +65,7 @@ static int calibrate_8916(struct tsens_priv *tmdev)
p2[2] = (qfprom_cdata[1] & S2_P2_MASK) >> S2_P2_SHIFT; p2[2] = (qfprom_cdata[1] & S2_P2_MASK) >> S2_P2_SHIFT;
p2[3] = (qfprom_cdata[1] & S3_P2_MASK) >> S3_P2_SHIFT; p2[3] = (qfprom_cdata[1] & S3_P2_MASK) >> S3_P2_SHIFT;
p2[4] = (qfprom_cdata[1] & S4_P2_MASK) >> S4_P2_SHIFT; p2[4] = (qfprom_cdata[1] & S4_P2_MASK) >> S4_P2_SHIFT;
for (i = 0; i < tmdev->num_sensors; i++) for (i = 0; i < priv->num_sensors; i++)
p2[i] = ((base1 + p2[i]) << 3); p2[i] = ((base1 + p2[i]) << 3);
/* Fall through */ /* Fall through */
case ONE_PT_CALIB2: case ONE_PT_CALIB2:
...@@ -75,18 +75,18 @@ static int calibrate_8916(struct tsens_priv *tmdev) ...@@ -75,18 +75,18 @@ static int calibrate_8916(struct tsens_priv *tmdev)
p1[2] = (qfprom_cdata[0] & S2_P1_MASK) >> S2_P1_SHIFT; p1[2] = (qfprom_cdata[0] & S2_P1_MASK) >> S2_P1_SHIFT;
p1[3] = (qfprom_cdata[1] & S3_P1_MASK) >> S3_P1_SHIFT; p1[3] = (qfprom_cdata[1] & S3_P1_MASK) >> S3_P1_SHIFT;
p1[4] = (qfprom_cdata[1] & S4_P1_MASK) >> S4_P1_SHIFT; p1[4] = (qfprom_cdata[1] & S4_P1_MASK) >> S4_P1_SHIFT;
for (i = 0; i < tmdev->num_sensors; i++) for (i = 0; i < priv->num_sensors; i++)
p1[i] = (((base0) + p1[i]) << 3); p1[i] = (((base0) + p1[i]) << 3);
break; break;
default: default:
for (i = 0; i < tmdev->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
p1[i] = 500; p1[i] = 500;
p2[i] = 780; p2[i] = 780;
} }
break; break;
} }
compute_intercept_slope(tmdev, p1, p2, mode); compute_intercept_slope(priv, p1, p2, mode);
return 0; return 0;
} }
......
...@@ -56,21 +56,21 @@ ...@@ -56,21 +56,21 @@
#define TRDY_MASK BIT(7) #define TRDY_MASK BIT(7)
#define TIMEOUT_US 100 #define TIMEOUT_US 100
static int suspend_8960(struct tsens_priv *tmdev) static int suspend_8960(struct tsens_priv *priv)
{ {
int ret; int ret;
unsigned int mask; unsigned int mask;
struct regmap *map = tmdev->tm_map; struct regmap *map = priv->tm_map;
ret = regmap_read(map, THRESHOLD_ADDR, &tmdev->ctx.threshold); ret = regmap_read(map, THRESHOLD_ADDR, &priv->ctx.threshold);
if (ret) if (ret)
return ret; return ret;
ret = regmap_read(map, CNTL_ADDR, &tmdev->ctx.control); ret = regmap_read(map, CNTL_ADDR, &priv->ctx.control);
if (ret) if (ret)
return ret; return ret;
if (tmdev->num_sensors > 1) if (priv->num_sensors > 1)
mask = SLP_CLK_ENA | EN; mask = SLP_CLK_ENA | EN;
else else
mask = SLP_CLK_ENA_8660 | EN; mask = SLP_CLK_ENA_8660 | EN;
...@@ -82,10 +82,10 @@ static int suspend_8960(struct tsens_priv *tmdev) ...@@ -82,10 +82,10 @@ static int suspend_8960(struct tsens_priv *tmdev)
return 0; return 0;
} }
static int resume_8960(struct tsens_priv *tmdev) static int resume_8960(struct tsens_priv *priv)
{ {
int ret; int ret;
struct regmap *map = tmdev->tm_map; struct regmap *map = priv->tm_map;
ret = regmap_update_bits(map, CNTL_ADDR, SW_RST, SW_RST); ret = regmap_update_bits(map, CNTL_ADDR, SW_RST, SW_RST);
if (ret) if (ret)
...@@ -95,80 +95,80 @@ static int resume_8960(struct tsens_priv *tmdev) ...@@ -95,80 +95,80 @@ static int resume_8960(struct tsens_priv *tmdev)
* Separate CONFIG restore is not needed only for 8660 as * Separate CONFIG restore is not needed only for 8660 as
* config is part of CTRL Addr and its restored as such * config is part of CTRL Addr and its restored as such
*/ */
if (tmdev->num_sensors > 1) { if (priv->num_sensors > 1) {
ret = regmap_update_bits(map, CONFIG_ADDR, CONFIG_MASK, CONFIG); ret = regmap_update_bits(map, CONFIG_ADDR, CONFIG_MASK, CONFIG);
if (ret) if (ret)
return ret; return ret;
} }
ret = regmap_write(map, THRESHOLD_ADDR, tmdev->ctx.threshold); ret = regmap_write(map, THRESHOLD_ADDR, priv->ctx.threshold);
if (ret) if (ret)
return ret; return ret;
ret = regmap_write(map, CNTL_ADDR, tmdev->ctx.control); ret = regmap_write(map, CNTL_ADDR, priv->ctx.control);
if (ret) if (ret)
return ret; return ret;
return 0; return 0;
} }
static int enable_8960(struct tsens_priv *tmdev, int id) static int enable_8960(struct tsens_priv *priv, int id)
{ {
int ret; int ret;
u32 reg, mask; u32 reg, mask;
ret = regmap_read(tmdev->tm_map, CNTL_ADDR, &reg); ret = regmap_read(priv->tm_map, CNTL_ADDR, &reg);
if (ret) if (ret)
return ret; return ret;
mask = BIT(id + SENSOR0_SHIFT); mask = BIT(id + SENSOR0_SHIFT);
ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg | SW_RST); ret = regmap_write(priv->tm_map, CNTL_ADDR, reg | SW_RST);
if (ret) if (ret)
return ret; return ret;
if (tmdev->num_sensors > 1) if (priv->num_sensors > 1)
reg |= mask | SLP_CLK_ENA | EN; reg |= mask | SLP_CLK_ENA | EN;
else else
reg |= mask | SLP_CLK_ENA_8660 | EN; reg |= mask | SLP_CLK_ENA_8660 | EN;
ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg); ret = regmap_write(priv->tm_map, CNTL_ADDR, reg);
if (ret) if (ret)
return ret; return ret;
return 0; return 0;
} }
static void disable_8960(struct tsens_priv *tmdev) static void disable_8960(struct tsens_priv *priv)
{ {
int ret; int ret;
u32 reg_cntl; u32 reg_cntl;
u32 mask; u32 mask;
mask = GENMASK(tmdev->num_sensors - 1, 0); mask = GENMASK(priv->num_sensors - 1, 0);
mask <<= SENSOR0_SHIFT; mask <<= SENSOR0_SHIFT;
mask |= EN; mask |= EN;
ret = regmap_read(tmdev->tm_map, CNTL_ADDR, &reg_cntl); ret = regmap_read(priv->tm_map, CNTL_ADDR, &reg_cntl);
if (ret) if (ret)
return; return;
reg_cntl &= ~mask; reg_cntl &= ~mask;
if (tmdev->num_sensors > 1) if (priv->num_sensors > 1)
reg_cntl &= ~SLP_CLK_ENA; reg_cntl &= ~SLP_CLK_ENA;
else else
reg_cntl &= ~SLP_CLK_ENA_8660; reg_cntl &= ~SLP_CLK_ENA_8660;
regmap_write(tmdev->tm_map, CNTL_ADDR, reg_cntl); regmap_write(priv->tm_map, CNTL_ADDR, reg_cntl);
} }
static int init_8960(struct tsens_priv *tmdev) static int init_8960(struct tsens_priv *priv)
{ {
int ret, i; int ret, i;
u32 reg_cntl; u32 reg_cntl;
tmdev->tm_map = dev_get_regmap(tmdev->dev, NULL); priv->tm_map = dev_get_regmap(priv->dev, NULL);
if (!tmdev->tm_map) if (!priv->tm_map)
return -ENODEV; return -ENODEV;
/* /*
...@@ -177,21 +177,21 @@ static int init_8960(struct tsens_priv *tmdev) ...@@ -177,21 +177,21 @@ static int init_8960(struct tsens_priv *tmdev)
* but the control registers stay in the same place, i.e * but the control registers stay in the same place, i.e
* directly after the first 5 status registers. * directly after the first 5 status registers.
*/ */
for (i = 0; i < tmdev->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
if (i >= 5) if (i >= 5)
tmdev->sensor[i].status = S0_STATUS_ADDR + 40; priv->sensor[i].status = S0_STATUS_ADDR + 40;
tmdev->sensor[i].status += i * 4; priv->sensor[i].status += i * 4;
} }
reg_cntl = SW_RST; reg_cntl = SW_RST;
ret = regmap_update_bits(tmdev->tm_map, CNTL_ADDR, SW_RST, reg_cntl); ret = regmap_update_bits(priv->tm_map, CNTL_ADDR, SW_RST, reg_cntl);
if (ret) if (ret)
return ret; return ret;
if (tmdev->num_sensors > 1) { if (priv->num_sensors > 1) {
reg_cntl |= SLP_CLK_ENA | (MEASURE_PERIOD << 18); reg_cntl |= SLP_CLK_ENA | (MEASURE_PERIOD << 18);
reg_cntl &= ~SW_RST; reg_cntl &= ~SW_RST;
ret = regmap_update_bits(tmdev->tm_map, CONFIG_ADDR, ret = regmap_update_bits(priv->tm_map, CONFIG_ADDR,
CONFIG_MASK, CONFIG); CONFIG_MASK, CONFIG);
} else { } else {
reg_cntl |= SLP_CLK_ENA_8660 | (MEASURE_PERIOD << 16); reg_cntl |= SLP_CLK_ENA_8660 | (MEASURE_PERIOD << 16);
...@@ -199,30 +199,30 @@ static int init_8960(struct tsens_priv *tmdev) ...@@ -199,30 +199,30 @@ static int init_8960(struct tsens_priv *tmdev)
reg_cntl |= CONFIG_8660 << CONFIG_SHIFT_8660; reg_cntl |= CONFIG_8660 << CONFIG_SHIFT_8660;
} }
reg_cntl |= GENMASK(tmdev->num_sensors - 1, 0) << SENSOR0_SHIFT; reg_cntl |= GENMASK(priv->num_sensors - 1, 0) << SENSOR0_SHIFT;
ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg_cntl); ret = regmap_write(priv->tm_map, CNTL_ADDR, reg_cntl);
if (ret) if (ret)
return ret; return ret;
reg_cntl |= EN; reg_cntl |= EN;
ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg_cntl); ret = regmap_write(priv->tm_map, CNTL_ADDR, reg_cntl);
if (ret) if (ret)
return ret; return ret;
return 0; return 0;
} }
static int calibrate_8960(struct tsens_priv *tmdev) static int calibrate_8960(struct tsens_priv *priv)
{ {
int i; int i;
char *data; char *data;
ssize_t num_read = tmdev->num_sensors; ssize_t num_read = priv->num_sensors;
struct tsens_sensor *s = tmdev->sensor; struct tsens_sensor *s = priv->sensor;
data = qfprom_read(tmdev->dev, "calib"); data = qfprom_read(priv->dev, "calib");
if (IS_ERR(data)) if (IS_ERR(data))
data = qfprom_read(tmdev->dev, "calib_backup"); data = qfprom_read(priv->dev, "calib_backup");
if (IS_ERR(data)) if (IS_ERR(data))
return PTR_ERR(data); return PTR_ERR(data);
...@@ -243,21 +243,21 @@ static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s) ...@@ -243,21 +243,21 @@ static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s)
return adc_code * slope + offset; return adc_code * slope + offset;
} }
static int get_temp_8960(struct tsens_priv *tmdev, int id, int *temp) static int get_temp_8960(struct tsens_priv *priv, int id, int *temp)
{ {
int ret; int ret;
u32 code, trdy; u32 code, trdy;
const struct tsens_sensor *s = &tmdev->sensor[id]; const struct tsens_sensor *s = &priv->sensor[id];
unsigned long timeout; unsigned long timeout;
timeout = jiffies + usecs_to_jiffies(TIMEOUT_US); timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
do { do {
ret = regmap_read(tmdev->tm_map, INT_STATUS_ADDR, &trdy); ret = regmap_read(priv->tm_map, INT_STATUS_ADDR, &trdy);
if (ret) if (ret)
return ret; return ret;
if (!(trdy & TRDY_MASK)) if (!(trdy & TRDY_MASK))
continue; continue;
ret = regmap_read(tmdev->tm_map, s->status, &code); ret = regmap_read(priv->tm_map, s->status, &code);
if (ret) if (ret)
return ret; return ret;
*temp = code_to_mdegC(code, s); *temp = code_to_mdegC(code, s);
......
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
#define BIT_APPEND 0x3 #define BIT_APPEND 0x3
static int calibrate_8974(struct tsens_priv *tmdev) static int calibrate_8974(struct tsens_priv *priv)
{ {
int base1 = 0, base2 = 0, i; int base1 = 0, base2 = 0, i;
u32 p1[11], p2[11]; u32 p1[11], p2[11];
...@@ -99,11 +99,11 @@ static int calibrate_8974(struct tsens_priv *tmdev) ...@@ -99,11 +99,11 @@ static int calibrate_8974(struct tsens_priv *tmdev)
u32 *calib, *bkp; u32 *calib, *bkp;
u32 calib_redun_sel; u32 calib_redun_sel;
calib = (u32 *)qfprom_read(tmdev->dev, "calib"); calib = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(calib)) if (IS_ERR(calib))
return PTR_ERR(calib); return PTR_ERR(calib);
bkp = (u32 *)qfprom_read(tmdev->dev, "calib_backup"); bkp = (u32 *)qfprom_read(priv->dev, "calib_backup");
if (IS_ERR(bkp)) if (IS_ERR(bkp))
return PTR_ERR(bkp); return PTR_ERR(bkp);
...@@ -184,25 +184,25 @@ static int calibrate_8974(struct tsens_priv *tmdev) ...@@ -184,25 +184,25 @@ static int calibrate_8974(struct tsens_priv *tmdev)
switch (mode) { switch (mode) {
case ONE_PT_CALIB: case ONE_PT_CALIB:
for (i = 0; i < tmdev->num_sensors; i++) for (i = 0; i < priv->num_sensors; i++)
p1[i] += (base1 << 2) | BIT_APPEND; p1[i] += (base1 << 2) | BIT_APPEND;
break; break;
case TWO_PT_CALIB: case TWO_PT_CALIB:
for (i = 0; i < tmdev->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
p2[i] += base2; p2[i] += base2;
p2[i] <<= 2; p2[i] <<= 2;
p2[i] |= BIT_APPEND; p2[i] |= BIT_APPEND;
} }
/* Fall through */ /* Fall through */
case ONE_PT_CALIB2: case ONE_PT_CALIB2:
for (i = 0; i < tmdev->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
p1[i] += base1; p1[i] += base1;
p1[i] <<= 2; p1[i] <<= 2;
p1[i] |= BIT_APPEND; p1[i] |= BIT_APPEND;
} }
break; break;
default: default:
for (i = 0; i < tmdev->num_sensors; i++) for (i = 0; i < priv->num_sensors; i++)
p2[i] = 780; p2[i] = 780;
p1[0] = 502; p1[0] = 502;
p1[1] = 509; p1[1] = 509;
...@@ -218,7 +218,7 @@ static int calibrate_8974(struct tsens_priv *tmdev) ...@@ -218,7 +218,7 @@ static int calibrate_8974(struct tsens_priv *tmdev)
break; break;
} }
compute_intercept_slope(tmdev, p1, p2, mode); compute_intercept_slope(priv, p1, p2, mode);
return 0; return 0;
} }
......
...@@ -46,18 +46,18 @@ char *qfprom_read(struct device *dev, const char *cname) ...@@ -46,18 +46,18 @@ char *qfprom_read(struct device *dev, const char *cname)
* and offset values are derived from tz->tzp->slope and tz->tzp->offset * and offset values are derived from tz->tzp->slope and tz->tzp->offset
* resp. * resp.
*/ */
void compute_intercept_slope(struct tsens_priv *tmdev, u32 *p1, void compute_intercept_slope(struct tsens_priv *priv, u32 *p1,
u32 *p2, u32 mode) u32 *p2, u32 mode)
{ {
int i; int i;
int num, den; int num, den;
for (i = 0; i < tmdev->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
dev_dbg(tmdev->dev, dev_dbg(priv->dev,
"sensor%d - data_point1:%#x data_point2:%#x\n", "sensor%d - data_point1:%#x data_point2:%#x\n",
i, p1[i], p2[i]); i, p1[i], p2[i]);
tmdev->sensor[i].slope = SLOPE_DEFAULT; priv->sensor[i].slope = SLOPE_DEFAULT;
if (mode == TWO_PT_CALIB) { if (mode == TWO_PT_CALIB) {
/* /*
* slope (m) = adc_code2 - adc_code1 (y2 - y1)/ * slope (m) = adc_code2 - adc_code1 (y2 - y1)/
...@@ -66,13 +66,13 @@ void compute_intercept_slope(struct tsens_priv *tmdev, u32 *p1, ...@@ -66,13 +66,13 @@ void compute_intercept_slope(struct tsens_priv *tmdev, u32 *p1,
num = p2[i] - p1[i]; num = p2[i] - p1[i];
num *= SLOPE_FACTOR; num *= SLOPE_FACTOR;
den = CAL_DEGC_PT2 - CAL_DEGC_PT1; den = CAL_DEGC_PT2 - CAL_DEGC_PT1;
tmdev->sensor[i].slope = num / den; priv->sensor[i].slope = num / den;
} }
tmdev->sensor[i].offset = (p1[i] * SLOPE_FACTOR) - priv->sensor[i].offset = (p1[i] * SLOPE_FACTOR) -
(CAL_DEGC_PT1 * (CAL_DEGC_PT1 *
tmdev->sensor[i].slope); priv->sensor[i].slope);
dev_dbg(tmdev->dev, "offset:%d\n", tmdev->sensor[i].offset); dev_dbg(priv->dev, "offset:%d\n", priv->sensor[i].offset);
} }
} }
...@@ -95,15 +95,15 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) ...@@ -95,15 +95,15 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s)
return degc; return degc;
} }
int get_temp_common(struct tsens_priv *tmdev, int id, int *temp) int get_temp_common(struct tsens_priv *priv, int id, int *temp)
{ {
struct tsens_sensor *s = &tmdev->sensor[id]; struct tsens_sensor *s = &priv->sensor[id];
u32 code; u32 code;
unsigned int status_reg; unsigned int status_reg;
int last_temp = 0, ret; int last_temp = 0, ret;
status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * SN_ADDR_OFFSET; status_reg = priv->tm_offset + STATUS_OFFSET + s->hw_id * SN_ADDR_OFFSET;
ret = regmap_read(tmdev->tm_map, status_reg, &code); ret = regmap_read(priv->tm_map, status_reg, &code);
if (ret) if (ret)
return ret; return ret;
last_temp = code & SN_ST_TEMP_MASK; last_temp = code & SN_ST_TEMP_MASK;
...@@ -127,21 +127,21 @@ static const struct regmap_config tsens_srot_config = { ...@@ -127,21 +127,21 @@ static const struct regmap_config tsens_srot_config = {
.reg_stride = 4, .reg_stride = 4,
}; };
int __init init_common(struct tsens_priv *tmdev) int __init init_common(struct tsens_priv *priv)
{ {
void __iomem *tm_base, *srot_base; void __iomem *tm_base, *srot_base;
struct resource *res; struct resource *res;
u32 code; u32 code;
int ret; int ret;
struct platform_device *op = of_find_device_by_node(tmdev->dev->of_node); struct platform_device *op = of_find_device_by_node(priv->dev->of_node);
u16 ctrl_offset = tmdev->reg_offsets[SROT_CTRL_OFFSET]; u16 ctrl_offset = priv->reg_offsets[SROT_CTRL_OFFSET];
if (!op) if (!op)
return -EINVAL; return -EINVAL;
if (op->num_resources > 1) { if (op->num_resources > 1) {
/* DT with separate SROT and TM address space */ /* DT with separate SROT and TM address space */
tmdev->tm_offset = 0; priv->tm_offset = 0;
res = platform_get_resource(op, IORESOURCE_MEM, 1); res = platform_get_resource(op, IORESOURCE_MEM, 1);
srot_base = devm_ioremap_resource(&op->dev, res); srot_base = devm_ioremap_resource(&op->dev, res);
if (IS_ERR(srot_base)) { if (IS_ERR(srot_base)) {
...@@ -149,16 +149,15 @@ int __init init_common(struct tsens_priv *tmdev) ...@@ -149,16 +149,15 @@ int __init init_common(struct tsens_priv *tmdev)
goto err_put_device; goto err_put_device;
} }
tmdev->srot_map = devm_regmap_init_mmio(tmdev->dev, srot_base, priv->srot_map = devm_regmap_init_mmio(priv->dev, srot_base,
&tsens_srot_config); &tsens_srot_config);
if (IS_ERR(tmdev->srot_map)) { if (IS_ERR(priv->srot_map)) {
ret = PTR_ERR(tmdev->srot_map); ret = PTR_ERR(priv->srot_map);
goto err_put_device; goto err_put_device;
} }
} else { } else {
/* old DTs where SROT and TM were in a contiguous 2K block */ /* old DTs where SROT and TM were in a contiguous 2K block */
tmdev->tm_offset = 0x1000; priv->tm_offset = 0x1000;
} }
res = platform_get_resource(op, IORESOURCE_MEM, 0); res = platform_get_resource(op, IORESOURCE_MEM, 0);
...@@ -168,18 +167,18 @@ int __init init_common(struct tsens_priv *tmdev) ...@@ -168,18 +167,18 @@ int __init init_common(struct tsens_priv *tmdev)
goto err_put_device; goto err_put_device;
} }
tmdev->tm_map = devm_regmap_init_mmio(tmdev->dev, tm_base, &tsens_config); priv->tm_map = devm_regmap_init_mmio(priv->dev, tm_base, &tsens_config);
if (IS_ERR(tmdev->tm_map)) { if (IS_ERR(priv->tm_map)) {
ret = PTR_ERR(tmdev->tm_map); ret = PTR_ERR(priv->tm_map);
goto err_put_device; goto err_put_device;
} }
if (tmdev->srot_map) { if (priv->srot_map) {
ret = regmap_read(tmdev->srot_map, ctrl_offset, &code); ret = regmap_read(priv->srot_map, ctrl_offset, &code);
if (ret) if (ret)
goto err_put_device; goto err_put_device;
if (!(code & TSENS_EN)) { if (!(code & TSENS_EN)) {
dev_err(tmdev->dev, "tsens device is not enabled\n"); dev_err(priv->dev, "tsens device is not enabled\n");
ret = -ENODEV; ret = -ENODEV;
goto err_put_device; goto err_put_device;
} }
......
...@@ -12,16 +12,16 @@ ...@@ -12,16 +12,16 @@
#define LAST_TEMP_MASK 0xfff #define LAST_TEMP_MASK 0xfff
#define STATUS_VALID_BIT BIT(21) #define STATUS_VALID_BIT BIT(21)
static int get_temp_tsens_v2(struct tsens_priv *tmdev, int id, int *temp) static int get_temp_tsens_v2(struct tsens_priv *priv, int id, int *temp)
{ {
struct tsens_sensor *s = &tmdev->sensor[id]; struct tsens_sensor *s = &priv->sensor[id];
u32 code; u32 code;
unsigned int status_reg; unsigned int status_reg;
u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0; u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0;
int ret; int ret;
status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * 4; status_reg = priv->tm_offset + STATUS_OFFSET + s->hw_id * 4;
ret = regmap_read(tmdev->tm_map, status_reg, &code); ret = regmap_read(priv->tm_map, status_reg, &code);
if (ret) if (ret)
return ret; return ret;
last_temp = code & LAST_TEMP_MASK; last_temp = code & LAST_TEMP_MASK;
...@@ -29,7 +29,7 @@ static int get_temp_tsens_v2(struct tsens_priv *tmdev, int id, int *temp) ...@@ -29,7 +29,7 @@ static int get_temp_tsens_v2(struct tsens_priv *tmdev, int id, int *temp)
goto done; goto done;
/* Try a second time */ /* Try a second time */
ret = regmap_read(tmdev->tm_map, status_reg, &code); ret = regmap_read(priv->tm_map, status_reg, &code);
if (ret) if (ret)
return ret; return ret;
if (code & STATUS_VALID_BIT) { if (code & STATUS_VALID_BIT) {
...@@ -40,7 +40,7 @@ static int get_temp_tsens_v2(struct tsens_priv *tmdev, int id, int *temp) ...@@ -40,7 +40,7 @@ static int get_temp_tsens_v2(struct tsens_priv *tmdev, int id, int *temp)
} }
/* Try a third/last time */ /* Try a third/last time */
ret = regmap_read(tmdev->tm_map, status_reg, &code); ret = regmap_read(priv->tm_map, status_reg, &code);
if (ret) if (ret)
return ret; return ret;
if (code & STATUS_VALID_BIT) { if (code & STATUS_VALID_BIT) {
......
...@@ -15,38 +15,38 @@ ...@@ -15,38 +15,38 @@
static int tsens_get_temp(void *data, int *temp) static int tsens_get_temp(void *data, int *temp)
{ {
const struct tsens_sensor *s = data; const struct tsens_sensor *s = data;
struct tsens_priv *tmdev = s->tmdev; struct tsens_priv *priv = s->priv;
return tmdev->ops->get_temp(tmdev, s->id, temp); return priv->ops->get_temp(priv, s->id, temp);
} }
static int tsens_get_trend(void *p, int trip, enum thermal_trend *trend) static int tsens_get_trend(void *p, int trip, enum thermal_trend *trend)
{ {
const struct tsens_sensor *s = p; const struct tsens_sensor *s = p;
struct tsens_priv *tmdev = s->tmdev; struct tsens_priv *priv = s->priv;
if (tmdev->ops->get_trend) if (priv->ops->get_trend)
return tmdev->ops->get_trend(tmdev, s->id, trend); return priv->ops->get_trend(priv, s->id, trend);
return -ENOTSUPP; return -ENOTSUPP;
} }
static int __maybe_unused tsens_suspend(struct device *dev) static int __maybe_unused tsens_suspend(struct device *dev)
{ {
struct tsens_priv *tmdev = dev_get_drvdata(dev); struct tsens_priv *priv = dev_get_drvdata(dev);
if (tmdev->ops && tmdev->ops->suspend) if (priv->ops && priv->ops->suspend)
return tmdev->ops->suspend(tmdev); return priv->ops->suspend(priv);
return 0; return 0;
} }
static int __maybe_unused tsens_resume(struct device *dev) static int __maybe_unused tsens_resume(struct device *dev)
{ {
struct tsens_priv *tmdev = dev_get_drvdata(dev); struct tsens_priv *priv = dev_get_drvdata(dev);
if (tmdev->ops && tmdev->ops->resume) if (priv->ops && priv->ops->resume)
return tmdev->ops->resume(tmdev); return priv->ops->resume(priv);
return 0; return 0;
} }
...@@ -76,22 +76,22 @@ static const struct thermal_zone_of_device_ops tsens_of_ops = { ...@@ -76,22 +76,22 @@ static const struct thermal_zone_of_device_ops tsens_of_ops = {
.get_trend = tsens_get_trend, .get_trend = tsens_get_trend,
}; };
static int tsens_register(struct tsens_priv *tmdev) static int tsens_register(struct tsens_priv *priv)
{ {
int i; int i;
struct thermal_zone_device *tzd; struct thermal_zone_device *tzd;
for (i = 0; i < tmdev->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
tmdev->sensor[i].tmdev = tmdev; priv->sensor[i].priv = priv;
tmdev->sensor[i].id = i; priv->sensor[i].id = i;
tzd = devm_thermal_zone_of_sensor_register(tmdev->dev, i, tzd = devm_thermal_zone_of_sensor_register(priv->dev, i,
&tmdev->sensor[i], &priv->sensor[i],
&tsens_of_ops); &tsens_of_ops);
if (IS_ERR(tzd)) if (IS_ERR(tzd))
continue; continue;
tmdev->sensor[i].tzd = tzd; priv->sensor[i].tzd = tzd;
if (tmdev->ops->enable) if (priv->ops->enable)
tmdev->ops->enable(tmdev, i); priv->ops->enable(priv, i);
} }
return 0; return 0;
} }
...@@ -101,7 +101,7 @@ static int tsens_probe(struct platform_device *pdev) ...@@ -101,7 +101,7 @@ static int tsens_probe(struct platform_device *pdev)
int ret, i; int ret, i;
struct device *dev; struct device *dev;
struct device_node *np; struct device_node *np;
struct tsens_priv *tmdev; struct tsens_priv *priv;
const struct tsens_plat_data *data; const struct tsens_plat_data *data;
const struct of_device_id *id; const struct of_device_id *id;
u32 num_sensors; u32 num_sensors;
...@@ -129,55 +129,55 @@ static int tsens_probe(struct platform_device *pdev) ...@@ -129,55 +129,55 @@ static int tsens_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
tmdev = devm_kzalloc(dev, priv = devm_kzalloc(dev,
struct_size(tmdev, sensor, num_sensors), struct_size(priv, sensor, num_sensors),
GFP_KERNEL); GFP_KERNEL);
if (!tmdev) if (!priv)
return -ENOMEM; return -ENOMEM;
tmdev->dev = dev; priv->dev = dev;
tmdev->num_sensors = num_sensors; priv->num_sensors = num_sensors;
tmdev->ops = data->ops; priv->ops = data->ops;
for (i = 0; i < tmdev->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
if (data->hw_ids) if (data->hw_ids)
tmdev->sensor[i].hw_id = data->hw_ids[i]; priv->sensor[i].hw_id = data->hw_ids[i];
else else
tmdev->sensor[i].hw_id = i; priv->sensor[i].hw_id = i;
} }
for (i = 0; i < REG_ARRAY_SIZE; i++) { for (i = 0; i < REG_ARRAY_SIZE; i++) {
tmdev->reg_offsets[i] = data->reg_offsets[i]; priv->reg_offsets[i] = data->reg_offsets[i];
} }
if (!tmdev->ops || !tmdev->ops->init || !tmdev->ops->get_temp) if (!priv->ops || !priv->ops->init || !priv->ops->get_temp)
return -EINVAL; return -EINVAL;
ret = tmdev->ops->init(tmdev); ret = priv->ops->init(priv);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "tsens init failed\n"); dev_err(dev, "tsens init failed\n");
return ret; return ret;
} }
if (tmdev->ops->calibrate) { if (priv->ops->calibrate) {
ret = tmdev->ops->calibrate(tmdev); ret = priv->ops->calibrate(priv);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "tsens calibration failed\n"); dev_err(dev, "tsens calibration failed\n");
return ret; return ret;
} }
} }
ret = tsens_register(tmdev); ret = tsens_register(priv);
platform_set_drvdata(pdev, tmdev); platform_set_drvdata(pdev, priv);
return ret; return ret;
} }
static int tsens_remove(struct platform_device *pdev) static int tsens_remove(struct platform_device *pdev)
{ {
struct tsens_priv *tmdev = platform_get_drvdata(pdev); struct tsens_priv *priv = platform_get_drvdata(pdev);
if (tmdev->ops->disable) if (priv->ops->disable)
tmdev->ops->disable(tmdev); priv->ops->disable(priv);
return 0; return 0;
} }
......
...@@ -16,7 +16,7 @@ struct tsens_priv; ...@@ -16,7 +16,7 @@ struct tsens_priv;
/** /**
* struct tsens_sensor - data for each sensor connected to the tsens device * struct tsens_sensor - data for each sensor connected to the tsens device
* @tmdev: tsens device instance that this sensor is connected to * @priv: tsens device instance that this sensor is connected to
* @tzd: pointer to the thermal zone that this sensor is in * @tzd: pointer to the thermal zone that this sensor is in
* @offset: offset of temperature adjustment curve * @offset: offset of temperature adjustment curve
* @id: Sensor ID * @id: Sensor ID
...@@ -25,7 +25,7 @@ struct tsens_priv; ...@@ -25,7 +25,7 @@ struct tsens_priv;
* @status: 8960-specific variable to track 8960 and 8660 status register offset * @status: 8960-specific variable to track 8960 and 8660 status register offset
*/ */
struct tsens_sensor { struct tsens_sensor {
struct tsens_priv *tmdev; struct tsens_priv *priv;
struct thermal_zone_device *tzd; struct thermal_zone_device *tzd;
int offset; int offset;
int id; int id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment