* [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions @ 2018-03-29 14:49 Daniel Schultz 2018-03-29 14:50 ` [PATCH v5 2/2] mfd: rk808: Add restart functionality Daniel Schultz 2018-04-16 9:38 ` [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions Lee Jones 0 siblings, 2 replies; 5+ messages in thread From: Daniel Schultz @ 2018-03-29 14:49 UTC (permalink / raw) To: lee.jones; +Cc: zyw, zhangqing, xsf, tony.xie, w.egorov, linux-kernel Since all three shutdown functions have almost the same code, all logic from the shutdown functions can be refactored to a new function "rk808_update_bits", which can update a register by a given address and bitmask. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> --- Changes: v2: Re-submit with recipients from Rockchip. v3: - Added devicetree property to enable the PMIC reset seperate from "rockchip,system-power-controller". - Dropped the first patch of this serie. v4: Splitted refactoring and the new reset feature. v5: Removed null pointer from rk808_update_bits. drivers/mfd/rk808.c | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c index 216fbf6..1cb1b3a 100644 --- a/drivers/mfd/rk808.c +++ b/drivers/mfd/rk808.c @@ -369,58 +369,38 @@ static const struct regmap_irq_chip rk818_irq_chip = { static struct i2c_client *rk808_i2c_client; -static void rk805_device_shutdown(void) +static void rk808_update_bits(unsigned int reg, unsigned int bit_mask) { int ret; struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client); if (!rk808) { dev_warn(&rk808_i2c_client->dev, - "have no rk805, so do nothing here\n"); + "have no rk805/rk808/rk818, so do nothing here\n"); return; } ret = regmap_update_bits(rk808->regmap, - RK805_DEV_CTRL_REG, - DEV_OFF, DEV_OFF); + reg, + bit_mask, bit_mask); if (ret) - dev_err(&rk808_i2c_client->dev, "power off error!\n"); + dev_err(&rk808_i2c_client->dev, + "can't write to register 0x%x: %x!\n", reg, ret); } -static void rk808_device_shutdown(void) +static void rk805_device_shutdown(void) { - int ret; - struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client); - - if (!rk808) { - dev_warn(&rk808_i2c_client->dev, - "have no rk808, so do nothing here\n"); - return; - } + rk808_update_bits(RK805_DEV_CTRL_REG, DEV_OFF); +} - ret = regmap_update_bits(rk808->regmap, - RK808_DEVCTRL_REG, - DEV_OFF_RST, DEV_OFF_RST); - if (ret) - dev_err(&rk808_i2c_client->dev, "power off error!\n"); +static void rk808_device_shutdown(void) +{ + rk808_update_bits(RK808_DEVCTRL_REG, DEV_OFF_RST); } static void rk818_device_shutdown(void) { - int ret; - struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client); - - if (!rk808) { - dev_warn(&rk808_i2c_client->dev, - "have no rk818, so do nothing here\n"); - return; - } - - ret = regmap_update_bits(rk808->regmap, - RK818_DEVCTRL_REG, - DEV_OFF, DEV_OFF); - if (ret) - dev_err(&rk808_i2c_client->dev, "power off error!\n"); + rk808_update_bits(RK818_DEVCTRL_REG, DEV_OFF); } static const struct of_device_id rk808_of_match[] = { -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 2/2] mfd: rk808: Add restart functionality 2018-03-29 14:49 [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions Daniel Schultz @ 2018-03-29 14:50 ` Daniel Schultz 2018-04-16 9:38 ` Lee Jones 2018-04-16 9:38 ` [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions Lee Jones 1 sibling, 1 reply; 5+ messages in thread From: Daniel Schultz @ 2018-03-29 14:50 UTC (permalink / raw) To: lee.jones; +Cc: zyw, zhangqing, xsf, tony.xie, w.egorov, linux-kernel When using Rockchip SoCs with rk805/808/818 PMICs, restarts are realized by setting the reset registers in the "Clock and Reset Unit". Now, the driver can trigger a restart in the PMIC. Like the shutdown function, the restart is bound to an independent "rockchip,system-reset-controller" devicetree property can easily enabled by adding this. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> --- Changes: v2: Re-submit with recipients from Rockchip. v3: - Added devicetree property to enable the PMIC reset seperate from "rockchip,system-power-controller". - Dropped the first patch of this serie. v4: Splitted refactoring and the new reset feature. v5: - drivers/mfd/rk808.c | 58 ++++++++++++++++++++++++++++++++++++++++++----- include/linux/mfd/rk808.h | 1 + 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c index 1cb1b3a..7f5c3d7 100644 --- a/drivers/mfd/rk808.c +++ b/drivers/mfd/rk808.c @@ -27,6 +27,7 @@ #include <linux/module.h> #include <linux/of_device.h> #include <linux/regmap.h> +#include <linux/reboot.h> struct rk808_reg_data { int addr; @@ -392,16 +393,49 @@ static void rk805_device_shutdown(void) { rk808_update_bits(RK805_DEV_CTRL_REG, DEV_OFF); } +static int rk805_restart_notify(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + rk808_update_bits(RK805_DEV_CTRL_REG, DEV_OFF_RST); + return NOTIFY_DONE; +} static void rk808_device_shutdown(void) { rk808_update_bits(RK808_DEVCTRL_REG, DEV_OFF_RST); } +static int rk808_restart_notify(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + rk808_update_bits(RK808_DEVCTRL_REG, DEV_OFF); + return NOTIFY_DONE; +} static void rk818_device_shutdown(void) { rk808_update_bits(RK818_DEVCTRL_REG, DEV_OFF); } +static int rk818_restart_notify(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + rk808_update_bits(RK818_DEVCTRL_REG, DEV_OFF_RST); + return NOTIFY_DONE; +} + +static struct notifier_block rk805_restart_handler = { + .notifier_call = rk805_restart_notify, + .priority = 196, +}; + +static struct notifier_block rk808_restart_handler = { + .notifier_call = rk808_restart_notify, + .priority = 196, +}; + +static struct notifier_block rk818_restart_handler = { + .notifier_call = rk818_restart_notify, + .priority = 196, +}; static const struct of_device_id rk808_of_match[] = { { .compatible = "rockchip,rk805" }, @@ -421,7 +455,7 @@ static int rk808_probe(struct i2c_client *client, void (*pm_pwroff_fn)(void); int nr_pre_init_regs; int nr_cells; - int pm_off = 0, msb, lsb; + int pm_off = 0, pm_rst_off = 0, msb, lsb; int ret; int i; @@ -456,6 +490,7 @@ static int rk808_probe(struct i2c_client *client, cells = rk805s; nr_cells = ARRAY_SIZE(rk805s); pm_pwroff_fn = rk805_device_shutdown; + rk808->nb = &rk805_restart_handler; break; case RK808_ID: rk808->regmap_cfg = &rk808_regmap_config; @@ -465,6 +500,7 @@ static int rk808_probe(struct i2c_client *client, cells = rk808s; nr_cells = ARRAY_SIZE(rk808s); pm_pwroff_fn = rk808_device_shutdown; + rk808->nb = &rk808_restart_handler; break; case RK818_ID: rk808->regmap_cfg = &rk818_regmap_config; @@ -474,6 +510,7 @@ static int rk808_probe(struct i2c_client *client, cells = rk818s; nr_cells = ARRAY_SIZE(rk818s); pm_pwroff_fn = rk818_device_shutdown; + rk808->nb = &rk818_restart_handler; break; default: dev_err(&client->dev, "Unsupported RK8XX ID %lu\n", @@ -524,13 +561,20 @@ static int rk808_probe(struct i2c_client *client, goto err_irq; } - pm_off = of_property_read_bool(np, - "rockchip,system-power-controller"); - if (pm_off && !pm_power_off) { - rk808_i2c_client = client; + rk808_i2c_client = client; + + pm_off = of_property_read_bool(np, "rockchip,system-power-controller"); + if (pm_off && !pm_power_off) pm_power_off = pm_pwroff_fn; - } + pm_rst_off = of_property_read_bool(np, + "rockchip,system-reset-controller"); + if (pm_rst_off && rk808->nb) { + ret = register_restart_handler(rk808->nb); + if (ret) + dev_err(&client->dev, + "cannot register restart handler, %d\n", ret); + } return 0; err_irq: @@ -544,6 +588,8 @@ static int rk808_remove(struct i2c_client *client) regmap_del_irq_chip(client->irq, rk808->irq_data); pm_power_off = NULL; + if (rk808->nb) + unregister_restart_handler(rk808->nb); return 0; } diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h index d315659..6f8583b 100644 --- a/include/linux/mfd/rk808.h +++ b/include/linux/mfd/rk808.h @@ -453,5 +453,6 @@ struct rk808 { long variant; const struct regmap_config *regmap_cfg; const struct regmap_irq_chip *regmap_irq_chip; + struct notifier_block *nb; }; #endif /* __LINUX_REGULATOR_RK808_H */ -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5 2/2] mfd: rk808: Add restart functionality 2018-03-29 14:50 ` [PATCH v5 2/2] mfd: rk808: Add restart functionality Daniel Schultz @ 2018-04-16 9:38 ` Lee Jones 0 siblings, 0 replies; 5+ messages in thread From: Lee Jones @ 2018-04-16 9:38 UTC (permalink / raw) To: Daniel Schultz; +Cc: zyw, zhangqing, xsf, tony.xie, w.egorov, linux-kernel On Thu, 29 Mar 2018, Daniel Schultz wrote: > When using Rockchip SoCs with rk805/808/818 PMICs, restarts are realized by > setting the reset registers in the "Clock and Reset Unit". > > Now, the driver can trigger a restart in the PMIC. Like the > shutdown function, the restart is bound to an independent > "rockchip,system-reset-controller" devicetree property can easily > enabled by adding this. > > Signed-off-by: Daniel Schultz <d.schultz@phytec.de> > --- > Changes: > v2: Re-submit with recipients from Rockchip. > v3: - Added devicetree property to enable the PMIC reset seperate from > "rockchip,system-power-controller". > - Dropped the first patch of this serie. > v4: Splitted refactoring and the new reset feature. > v5: - > > drivers/mfd/rk808.c | 58 ++++++++++++++++++++++++++++++++++++++++++----- > include/linux/mfd/rk808.h | 1 + > 2 files changed, 53 insertions(+), 6 deletions(-) I'd still like an Ack/Review from the Rockchip guys please. -- Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions 2018-03-29 14:49 [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions Daniel Schultz 2018-03-29 14:50 ` [PATCH v5 2/2] mfd: rk808: Add restart functionality Daniel Schultz @ 2018-04-16 9:38 ` Lee Jones 2018-07-24 9:39 ` Wadim Egorov 1 sibling, 1 reply; 5+ messages in thread From: Lee Jones @ 2018-04-16 9:38 UTC (permalink / raw) To: Daniel Schultz; +Cc: zyw, zhangqing, xsf, tony.xie, w.egorov, linux-kernel On Thu, 29 Mar 2018, Daniel Schultz wrote: > Since all three shutdown functions have almost the same code, all logic > from the shutdown functions can be refactored to a new function > "rk808_update_bits", which can update a register by a given address and > bitmask. > > Signed-off-by: Daniel Schultz <d.schultz@phytec.de> > --- > Changes: > v2: Re-submit with recipients from Rockchip. > v3: - Added devicetree property to enable the PMIC reset seperate from > "rockchip,system-power-controller". > - Dropped the first patch of this serie. > v4: Splitted refactoring and the new reset feature. > v5: Removed null pointer from rk808_update_bits. > > drivers/mfd/rk808.c | 46 +++++++++++++--------------------------------- > 1 file changed, 13 insertions(+), 33 deletions(-) I'd still like an Ack/Review from the Rockchip guys please. -- Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions 2018-04-16 9:38 ` [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions Lee Jones @ 2018-07-24 9:39 ` Wadim Egorov 0 siblings, 0 replies; 5+ messages in thread From: Wadim Egorov @ 2018-07-24 9:39 UTC (permalink / raw) To: Lee Jones, Daniel Schultz, linux-rockchip Cc: zyw, zhangqing, xsf, tony.xie, linux-kernel Hi, Am 16.04.2018 um 11:38 schrieb Lee Jones: > On Thu, 29 Mar 2018, Daniel Schultz wrote: > >> Since all three shutdown functions have almost the same code, all logic >> from the shutdown functions can be refactored to a new function >> "rk808_update_bits", which can update a register by a given address and >> bitmask. >> >> Signed-off-by: Daniel Schultz <d.schultz@phytec.de> >> --- >> Changes: >> v2: Re-submit with recipients from Rockchip. >> v3: - Added devicetree property to enable the PMIC reset seperate from >> "rockchip,system-power-controller". >> - Dropped the first patch of this serie. >> v4: Splitted refactoring and the new reset feature. >> v5: Removed null pointer from rk808_update_bits. >> >> drivers/mfd/rk808.c | 46 +++++++++++++--------------------------------- >> 1 file changed, 13 insertions(+), 33 deletions(-) > I'd still like an Ack/Review from the Rockchip guys please. > can someone from Rockchip reply to this? ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-07-24 9:49 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-03-29 14:49 [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions Daniel Schultz 2018-03-29 14:50 ` [PATCH v5 2/2] mfd: rk808: Add restart functionality Daniel Schultz 2018-04-16 9:38 ` Lee Jones 2018-04-16 9:38 ` [PATCH v5 1/2] mfd: rk808: Refactor shutdown functions Lee Jones 2018-07-24 9:39 ` Wadim Egorov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).