thermal: sy7636a: Use "vcom" regulator for power on
Use its own regulator "vcom" for turning on the epd pmic when checking temperature. This avoids duplicate code, and prevents a pile of bugs.zero-sugar
parent
f6bb4d231b
commit
cf22985f20
|
@ -18,57 +18,35 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/thermal.h>
|
#include <linux/thermal.h>
|
||||||
|
#include <linux/regulator/consumer.h>
|
||||||
|
|
||||||
#include <linux/mfd/sy7636a.h>
|
#include <linux/mfd/sy7636a.h>
|
||||||
|
|
||||||
struct sy7636a_data {
|
struct sy7636a_data {
|
||||||
struct sy7636a *sy7636a;
|
struct sy7636a *sy7636a;
|
||||||
struct thermal_zone_device *thermal_zone_dev;
|
struct thermal_zone_device *thermal_zone_dev;
|
||||||
|
struct regulator *regulator;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sy7636a_get_temp(void *arg, int *res)
|
static int sy7636a_get_temp(void *arg, int *res)
|
||||||
{
|
{
|
||||||
unsigned int reg_val, mode_ctr;
|
unsigned int reg_val;
|
||||||
int ret;
|
int ret;
|
||||||
struct sy7636a_data *data = arg;
|
struct sy7636a_data *data = arg;
|
||||||
bool isVoltageActive;
|
|
||||||
|
|
||||||
mutex_lock(&data->sy7636a->reglock);
|
ret = regulator_enable(data->regulator);
|
||||||
|
|
||||||
ret = regmap_read(data->sy7636a->regmap,
|
|
||||||
SY7636A_REG_OPERATION_MODE_CRL, &mode_ctr);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto done;
|
return ret;
|
||||||
|
|
||||||
isVoltageActive = mode_ctr & SY7636A_OPERATION_MODE_CRL_ONOFF;
|
|
||||||
|
|
||||||
if (!isVoltageActive) {
|
|
||||||
ret = regmap_write(data->sy7636a->regmap,
|
|
||||||
SY7636A_REG_OPERATION_MODE_CRL,
|
|
||||||
mode_ctr | SY7636A_OPERATION_MODE_CRL_ONOFF);
|
|
||||||
if (ret)
|
|
||||||
goto done;
|
|
||||||
usleep_range(1000, 1500);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = regmap_read(data->sy7636a->regmap,
|
ret = regmap_read(data->sy7636a->regmap,
|
||||||
SY7636A_REG_TERMISTOR_READOUT, ®_val);
|
SY7636A_REG_TERMISTOR_READOUT, ®_val);
|
||||||
if (ret)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
if (!isVoltageActive) {
|
if (!ret) {
|
||||||
ret = regmap_write(data->sy7636a->regmap,
|
*res = *((signed char*)®_val);
|
||||||
SY7636A_REG_OPERATION_MODE_CRL,
|
*res *= 1000;
|
||||||
mode_ctr);
|
|
||||||
if (ret)
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*res = *((signed char*)®_val);
|
regulator_disable(data->regulator);
|
||||||
*res *= 1000;
|
|
||||||
|
|
||||||
done:
|
|
||||||
mutex_unlock(&data->sy7636a->reglock);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +69,14 @@ static int sy7636a_thermal_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
platform_set_drvdata(pdev, data);
|
platform_set_drvdata(pdev, data);
|
||||||
|
|
||||||
|
data->regulator = devm_regulator_get(&pdev->dev, "vcom");
|
||||||
|
if (IS_ERR(data->regulator)) {
|
||||||
|
dev_err(&pdev->dev,
|
||||||
|
"Unable to get vcom regulator, returned %ld\n",
|
||||||
|
PTR_ERR(data->regulator));
|
||||||
|
return PTR_ERR(data->regulator);
|
||||||
|
}
|
||||||
|
|
||||||
data->sy7636a = sy7636a;
|
data->sy7636a = sy7636a;
|
||||||
data->thermal_zone_dev = devm_thermal_zone_of_sensor_register(
|
data->thermal_zone_dev = devm_thermal_zone_of_sensor_register(
|
||||||
pdev->dev.parent,
|
pdev->dev.parent,
|
||||||
|
|
Loading…
Reference in New Issue