mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 08:31:13 +00:00
mfd: rk808: Reduce shutdown duplication
Rather than having 3 almost-identical functions plus the machinery to keep track of them, it's far simpler to just dynamically select the appropriate register field per variant. Signed-off-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
This commit is contained in:
parent
90df3a8230
commit
7a52cbccee
2 changed files with 20 additions and 42 deletions
|
@ -448,21 +448,6 @@ static const struct regmap_irq_chip rk818_irq_chip = {
|
||||||
|
|
||||||
static struct i2c_client *rk808_i2c_client;
|
static struct i2c_client *rk808_i2c_client;
|
||||||
|
|
||||||
static void rk805_device_shutdown(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
|
|
||||||
|
|
||||||
if (!rk808)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ret = regmap_update_bits(rk808->regmap,
|
|
||||||
RK805_DEV_CTRL_REG,
|
|
||||||
DEV_OFF, DEV_OFF);
|
|
||||||
if (ret)
|
|
||||||
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rk805_device_shutdown_prepare(void)
|
static void rk805_device_shutdown_prepare(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -478,32 +463,29 @@ static void rk805_device_shutdown_prepare(void)
|
||||||
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
|
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rk808_device_shutdown(void)
|
static void rk808_pm_power_off(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
unsigned int reg, bit;
|
||||||
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
|
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
|
||||||
|
|
||||||
if (!rk808)
|
switch (rk808->variant) {
|
||||||
|
case RK805_ID:
|
||||||
|
reg = RK805_DEV_CTRL_REG;
|
||||||
|
bit = DEV_OFF;
|
||||||
|
break;
|
||||||
|
case RK808_ID:
|
||||||
|
reg = RK808_DEVCTRL_REG,
|
||||||
|
bit = DEV_OFF_RST;
|
||||||
|
break;
|
||||||
|
case RK818_ID:
|
||||||
|
reg = RK818_DEVCTRL_REG;
|
||||||
|
bit = DEV_OFF;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
ret = regmap_update_bits(rk808->regmap,
|
ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
|
||||||
RK808_DEVCTRL_REG,
|
|
||||||
DEV_OFF_RST, DEV_OFF_RST);
|
|
||||||
if (ret)
|
|
||||||
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rk818_device_shutdown(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
|
|
||||||
|
|
||||||
if (!rk808)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ret = regmap_update_bits(rk808->regmap,
|
|
||||||
RK818_DEVCTRL_REG,
|
|
||||||
DEV_OFF, DEV_OFF);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
|
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
|
||||||
}
|
}
|
||||||
|
@ -592,7 +574,6 @@ static int rk808_probe(struct i2c_client *client,
|
||||||
nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
|
nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
|
||||||
cells = rk805s;
|
cells = rk805s;
|
||||||
nr_cells = ARRAY_SIZE(rk805s);
|
nr_cells = ARRAY_SIZE(rk805s);
|
||||||
rk808->pm_pwroff_fn = rk805_device_shutdown;
|
|
||||||
rk808->pm_pwroff_prep_fn = rk805_device_shutdown_prepare;
|
rk808->pm_pwroff_prep_fn = rk805_device_shutdown_prepare;
|
||||||
break;
|
break;
|
||||||
case RK808_ID:
|
case RK808_ID:
|
||||||
|
@ -602,7 +583,6 @@ static int rk808_probe(struct i2c_client *client,
|
||||||
nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
|
nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
|
||||||
cells = rk808s;
|
cells = rk808s;
|
||||||
nr_cells = ARRAY_SIZE(rk808s);
|
nr_cells = ARRAY_SIZE(rk808s);
|
||||||
rk808->pm_pwroff_fn = rk808_device_shutdown;
|
|
||||||
break;
|
break;
|
||||||
case RK818_ID:
|
case RK818_ID:
|
||||||
rk808->regmap_cfg = &rk818_regmap_config;
|
rk808->regmap_cfg = &rk818_regmap_config;
|
||||||
|
@ -611,7 +591,6 @@ static int rk808_probe(struct i2c_client *client,
|
||||||
nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
|
nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
|
||||||
cells = rk818s;
|
cells = rk818s;
|
||||||
nr_cells = ARRAY_SIZE(rk818s);
|
nr_cells = ARRAY_SIZE(rk818s);
|
||||||
rk808->pm_pwroff_fn = rk818_device_shutdown;
|
|
||||||
break;
|
break;
|
||||||
case RK809_ID:
|
case RK809_ID:
|
||||||
case RK817_ID:
|
case RK817_ID:
|
||||||
|
@ -673,7 +652,7 @@ static int rk808_probe(struct i2c_client *client,
|
||||||
|
|
||||||
if (of_property_read_bool(np, "rockchip,system-power-controller")) {
|
if (of_property_read_bool(np, "rockchip,system-power-controller")) {
|
||||||
rk808_i2c_client = client;
|
rk808_i2c_client = client;
|
||||||
pm_power_off = rk808->pm_pwroff_fn;
|
pm_power_off = rk808_pm_power_off;
|
||||||
pm_power_off_prepare = rk808->pm_pwroff_prep_fn;
|
pm_power_off_prepare = rk808->pm_pwroff_prep_fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,7 +673,7 @@ static int rk808_remove(struct i2c_client *client)
|
||||||
* pm_power_off may points to a function from another module.
|
* pm_power_off may points to a function from another module.
|
||||||
* Check if the pointer is set by us and only then overwrite it.
|
* Check if the pointer is set by us and only then overwrite it.
|
||||||
*/
|
*/
|
||||||
if (rk808->pm_pwroff_fn && pm_power_off == rk808->pm_pwroff_fn)
|
if (pm_power_off == rk808_pm_power_off)
|
||||||
pm_power_off = NULL;
|
pm_power_off = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -620,7 +620,6 @@ struct rk808 {
|
||||||
long variant;
|
long variant;
|
||||||
const struct regmap_config *regmap_cfg;
|
const struct regmap_config *regmap_cfg;
|
||||||
const struct regmap_irq_chip *regmap_irq_chip;
|
const struct regmap_irq_chip *regmap_irq_chip;
|
||||||
void (*pm_pwroff_fn)(void);
|
|
||||||
void (*pm_pwroff_prep_fn)(void);
|
void (*pm_pwroff_prep_fn)(void);
|
||||||
};
|
};
|
||||||
#endif /* __LINUX_REGULATOR_RK808_H */
|
#endif /* __LINUX_REGULATOR_RK808_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue