Skip to content

Commit 4fec8a5

Browse files
srelag-linaro
authored andcommitted
mfd: rk808: Convert to device managed resources
Fully convert the driver to device managed resources. Tested-by: Diederik de Haas <didi.debian@cknow.org> # Rock64, Quartz64 Model A + B Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # Pine64 QuartzPro64 Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20230504173618.142075-3-sebastian.reichel@collabora.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 2dc51ca commit 4fec8a5

1 file changed

Lines changed: 22 additions & 42 deletions

File tree

drivers/mfd/rk808.c

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,11 @@ static const struct regmap_irq_chip rk818_irq_chip = {
548548
.init_ack_masked = true,
549549
};
550550

551-
static struct i2c_client *rk808_i2c_client;
552-
553-
static void rk808_pm_power_off(void)
551+
static int rk808_power_off(struct sys_off_data *data)
554552
{
553+
struct rk808 *rk808 = data->cb_data;
555554
int ret;
556555
unsigned int reg, bit;
557-
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
558556

559557
switch (rk808->variant) {
560558
case RK805_ID:
@@ -575,16 +573,18 @@ static void rk808_pm_power_off(void)
575573
bit = DEV_OFF;
576574
break;
577575
default:
578-
return;
576+
return NOTIFY_DONE;
579577
}
580578
ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
581579
if (ret)
582-
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
580+
dev_err(&rk808->i2c->dev, "Failed to shutdown device!\n");
581+
582+
return NOTIFY_DONE;
583583
}
584584

585-
static int rk808_restart_notify(struct notifier_block *this, unsigned long mode, void *cmd)
585+
static int rk808_restart(struct sys_off_data *data)
586586
{
587-
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
587+
struct rk808 *rk808 = data->cb_data;
588588
unsigned int reg, bit;
589589
int ret;
590590

@@ -600,16 +600,11 @@ static int rk808_restart_notify(struct notifier_block *this, unsigned long mode,
600600
}
601601
ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
602602
if (ret)
603-
dev_err(&rk808_i2c_client->dev, "Failed to restart device!\n");
603+
dev_err(&rk808->i2c->dev, "Failed to restart device!\n");
604604

605605
return NOTIFY_DONE;
606606
}
607607

608-
static struct notifier_block rk808_restart_handler = {
609-
.notifier_call = rk808_restart_notify,
610-
.priority = 192,
611-
};
612-
613608
static void rk8xx_shutdown(struct i2c_client *client)
614609
{
615610
struct rk808 *rk808 = i2c_get_clientdata(client);
@@ -745,9 +740,9 @@ static int rk808_probe(struct i2c_client *client)
745740
return -EINVAL;
746741
}
747742

748-
ret = regmap_add_irq_chip(rk808->regmap, client->irq,
749-
IRQF_ONESHOT, -1,
750-
rk808->regmap_irq_chip, &rk808->irq_data);
743+
ret = devm_regmap_add_irq_chip(&client->dev, rk808->regmap, client->irq,
744+
IRQF_ONESHOT, -1,
745+
rk808->regmap_irq_chip, &rk808->irq_data);
751746
if (ret) {
752747
dev_err(&client->dev, "Failed to add irq_chip %d\n", ret);
753748
return ret;
@@ -771,17 +766,23 @@ static int rk808_probe(struct i2c_client *client)
771766
regmap_irq_get_domain(rk808->irq_data));
772767
if (ret) {
773768
dev_err(&client->dev, "failed to add MFD devices %d\n", ret);
774-
goto err_irq;
769+
return ret;
775770
}
776771

777772
if (of_property_read_bool(np, "rockchip,system-power-controller")) {
778-
rk808_i2c_client = client;
779-
pm_power_off = rk808_pm_power_off;
773+
ret = devm_register_sys_off_handler(&client->dev,
774+
SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_PRIO_HIGH,
775+
&rk808_power_off, rk808);
776+
if (ret)
777+
return dev_err_probe(&client->dev, ret,
778+
"failed to register poweroff handler\n");
780779

781780
switch (rk808->variant) {
782781
case RK809_ID:
783782
case RK817_ID:
784-
ret = register_restart_handler(&rk808_restart_handler);
783+
ret = devm_register_sys_off_handler(&client->dev,
784+
SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH,
785+
&rk808_restart, rk808);
785786
if (ret)
786787
dev_warn(&client->dev, "failed to register rst handler, %d\n", ret);
787788
break;
@@ -792,26 +793,6 @@ static int rk808_probe(struct i2c_client *client)
792793
}
793794

794795
return 0;
795-
796-
err_irq:
797-
regmap_del_irq_chip(client->irq, rk808->irq_data);
798-
return ret;
799-
}
800-
801-
static void rk808_remove(struct i2c_client *client)
802-
{
803-
struct rk808 *rk808 = i2c_get_clientdata(client);
804-
805-
regmap_del_irq_chip(client->irq, rk808->irq_data);
806-
807-
/**
808-
* pm_power_off may points to a function from another module.
809-
* Check if the pointer is set by us and only then overwrite it.
810-
*/
811-
if (pm_power_off == rk808_pm_power_off)
812-
pm_power_off = NULL;
813-
814-
unregister_restart_handler(&rk808_restart_handler);
815796
}
816797

817798
static int __maybe_unused rk8xx_suspend(struct device *dev)
@@ -868,7 +849,6 @@ static struct i2c_driver rk808_i2c_driver = {
868849
.pm = &rk8xx_pm_ops,
869850
},
870851
.probe_new = rk808_probe,
871-
.remove = rk808_remove,
872852
.shutdown = rk8xx_shutdown,
873853
};
874854

0 commit comments

Comments
 (0)