Commit cdd8b3f7 authored by Brian Norris's avatar Brian Norris Committed by Eduardo Valentin

thermal: rockchip: don't pass table structs by value

This driver passes struct chip_tsadc_table by value throughout; this is
inefficient, and AFAICT, there is no reason for it. Let's pass pointers
instead.
Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
Reviewed-by: default avatarCaesar Wang <wxt@rock-chips.com>
Signed-off-by: default avatarCaesar Wang <wxt@rock-chips.com>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent e6ed1b4a
......@@ -118,11 +118,11 @@ struct rockchip_tsadc_chip {
void (*control)(void __iomem *reg, bool on);
/* Per-sensor methods */
int (*get_temp)(struct chip_tsadc_table table,
int (*get_temp)(const struct chip_tsadc_table *table,
int chn, void __iomem *reg, int *temp);
void (*set_alarm_temp)(struct chip_tsadc_table table,
void (*set_alarm_temp)(const struct chip_tsadc_table *table,
int chn, void __iomem *reg, int temp);
void (*set_tshut_temp)(struct chip_tsadc_table table,
void (*set_tshut_temp)(const struct chip_tsadc_table *table,
int chn, void __iomem *reg, int temp);
void (*set_tshut_mode)(int chn, void __iomem *reg, enum tshut_mode m);
......@@ -397,26 +397,26 @@ static const struct tsadc_table rk3399_code_table[] = {
{TSADCV3_DATA_MASK, 125000},
};
static u32 rk_tsadcv2_temp_to_code(struct chip_tsadc_table table,
static u32 rk_tsadcv2_temp_to_code(const struct chip_tsadc_table *table,
int temp)
{
int high, low, mid;
u32 error = 0;
low = 0;
high = table.length - 1;
high = table->length - 1;
mid = (high + low) / 2;
/* Return mask code data when the temp is over table range */
if (temp < table.id[low].temp || temp > table.id[high].temp) {
error = table.data_mask;
if (temp < table->id[low].temp || temp > table->id[high].temp) {
error = table->data_mask;
goto exit;
}
while (low <= high) {
if (temp == table.id[mid].temp)
return table.id[mid].code;
else if (temp < table.id[mid].temp)
if (temp == table->id[mid].temp)
return table->id[mid].code;
else if (temp < table->id[mid].temp)
high = mid - 1;
else
low = mid + 1;
......@@ -429,28 +429,28 @@ static u32 rk_tsadcv2_temp_to_code(struct chip_tsadc_table table,
return error;
}
static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code,
int *temp)
static int rk_tsadcv2_code_to_temp(const struct chip_tsadc_table *table,
u32 code, int *temp)
{
unsigned int low = 1;
unsigned int high = table.length - 1;
unsigned int high = table->length - 1;
unsigned int mid = (low + high) / 2;
unsigned int num;
unsigned long denom;
WARN_ON(table.length < 2);
WARN_ON(table->length < 2);
switch (table.mode) {
switch (table->mode) {
case ADC_DECREMENT:
code &= table.data_mask;
if (code < table.id[high].code)
code &= table->data_mask;
if (code < table->id[high].code)
return -EAGAIN; /* Incorrect reading */
while (low <= high) {
if (code >= table.id[mid].code &&
code < table.id[mid - 1].code)
if (code >= table->id[mid].code &&
code < table->id[mid - 1].code)
break;
else if (code < table.id[mid].code)
else if (code < table->id[mid].code)
low = mid + 1;
else
high = mid - 1;
......@@ -459,15 +459,15 @@ static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code,
}
break;
case ADC_INCREMENT:
code &= table.data_mask;
if (code < table.id[low].code)
code &= table->data_mask;
if (code < table->id[low].code)
return -EAGAIN; /* Incorrect reading */
while (low <= high) {
if (code <= table.id[mid].code &&
code > table.id[mid - 1].code)
if (code <= table->id[mid].code &&
code > table->id[mid - 1].code)
break;
else if (code > table.id[mid].code)
else if (code > table->id[mid].code)
low = mid + 1;
else
high = mid - 1;
......@@ -476,7 +476,7 @@ static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code,
}
break;
default:
pr_err("%s: unknown table mode: %d\n", __func__, table.mode);
pr_err("%s: unknown table mode: %d\n", __func__, table->mode);
return -EINVAL;
}
......@@ -486,10 +486,10 @@ static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code,
* temperature between 2 table entries is linear and interpolate
* to produce less granular result.
*/
num = table.id[mid].temp - table.id[mid - 1].temp;
num *= abs(table.id[mid - 1].code - code);
denom = abs(table.id[mid - 1].code - table.id[mid].code);
*temp = table.id[mid - 1].temp + (num / denom);
num = table->id[mid].temp - table->id[mid - 1].temp;
num *= abs(table->id[mid - 1].code - code);
denom = abs(table->id[mid - 1].code - table->id[mid].code);
*temp = table->id[mid - 1].temp + (num / denom);
return 0;
}
......@@ -640,7 +640,7 @@ static void rk_tsadcv3_control(void __iomem *regs, bool enable)
writel_relaxed(val, regs + TSADCV2_AUTO_CON);
}
static int rk_tsadcv2_get_temp(struct chip_tsadc_table table,
static int rk_tsadcv2_get_temp(const struct chip_tsadc_table *table,
int chn, void __iomem *regs, int *temp)
{
u32 val;
......@@ -650,17 +650,17 @@ static int rk_tsadcv2_get_temp(struct chip_tsadc_table table,
return rk_tsadcv2_code_to_temp(table, val, temp);
}
static void rk_tsadcv2_alarm_temp(struct chip_tsadc_table table,
static void rk_tsadcv2_alarm_temp(const struct chip_tsadc_table *table,
int chn, void __iomem *regs, int temp)
{
u32 alarm_value, int_en;
/* Make sure the value is valid */
alarm_value = rk_tsadcv2_temp_to_code(table, temp);
if (alarm_value == table.data_mask)
if (alarm_value == table->data_mask)
return;
writel_relaxed(alarm_value & table.data_mask,
writel_relaxed(alarm_value & table->data_mask,
regs + TSADCV2_COMP_INT(chn));
int_en = readl_relaxed(regs + TSADCV2_INT_EN);
......@@ -668,14 +668,14 @@ static void rk_tsadcv2_alarm_temp(struct chip_tsadc_table table,
writel_relaxed(int_en, regs + TSADCV2_INT_EN);
}
static void rk_tsadcv2_tshut_temp(struct chip_tsadc_table table,
static void rk_tsadcv2_tshut_temp(const struct chip_tsadc_table *table,
int chn, void __iomem *regs, int temp)
{
u32 tshut_value, val;
/* Make sure the value is valid */
tshut_value = rk_tsadcv2_temp_to_code(table, temp);
if (tshut_value == table.data_mask)
if (tshut_value == table->data_mask)
return;
writel_relaxed(tshut_value, regs + TSADCV2_COMP_SHUT(chn));
......@@ -885,7 +885,7 @@ static int rockchip_thermal_set_trips(void *_sensor, int low, int high)
dev_dbg(&thermal->pdev->dev, "%s: sensor %d: low: %d, high %d\n",
__func__, sensor->id, low, high);
tsadc->set_alarm_temp(tsadc->table,
tsadc->set_alarm_temp(&tsadc->table,
sensor->id, thermal->regs, high);
return 0;
......@@ -898,7 +898,7 @@ static int rockchip_thermal_get_temp(void *_sensor, int *out_temp)
const struct rockchip_tsadc_chip *tsadc = sensor->thermal->chip;
int retval;
retval = tsadc->get_temp(tsadc->table,
retval = tsadc->get_temp(&tsadc->table,
sensor->id, thermal->regs, out_temp);
dev_dbg(&thermal->pdev->dev, "sensor %d - temp: %d, retval: %d\n",
sensor->id, *out_temp, retval);
......@@ -984,7 +984,7 @@ rockchip_thermal_register_sensor(struct platform_device *pdev,
int error;
tsadc->set_tshut_mode(id, thermal->regs, thermal->tshut_mode);
tsadc->set_tshut_temp(tsadc->table, id, thermal->regs,
tsadc->set_tshut_temp(&tsadc->table, id, thermal->regs,
thermal->tshut_temp);
sensor->thermal = thermal;
......@@ -1198,7 +1198,7 @@ static int __maybe_unused rockchip_thermal_resume(struct device *dev)
thermal->chip->set_tshut_mode(id, thermal->regs,
thermal->tshut_mode);
thermal->chip->set_tshut_temp(thermal->chip->table,
thermal->chip->set_tshut_temp(&thermal->chip->table,
id, thermal->regs,
thermal->tshut_temp);
}
......
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