History

mfd: rk808: Add reboot support to rk808.c

This adds reboot support to the rk808 pmic driver and enables it for the rk809 and rk817 devices. This only enables if the rockchip,system-power-controller flag is set.

Peter Geis committed 4 years ago

Commit 56f216d1 parent a96f6882 files · +45 −0Browse files

Unified · Split

2 files
  1. drivers/mfd/rk808.c +44 −0
  2. include/linux/mfd/rk808.h +1 −0
drivers/mfd/rk808.c+44−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <linux/module.h>
2020 #include <linux/of_device.h>
2121 #include <linux/regmap.h>
22+#include <linux/reboot.h>
2223
2324 struct rk808_reg_data {
2425 int addr;
@@ -543,6 +544,7 @@ static void rk808_pm_power_off(void) · 518 unmodified lines
543544 reg = RK808_DEVCTRL_REG,
544545 bit = DEV_OFF_RST;
545546 break;
547+ case RK809_ID:
546548 case RK817_ID:
547549 reg = RK817_SYS_CFG(3);
548550 bit = DEV_OFF;
@@ -559,6 +561,34 @@ static void rk808_pm_power_off(void) · 10 unmodified lines
559561 dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
560562 }
561563
564+static int rk808_restart_notify(struct notifier_block *this, unsigned long mode, void *cmd)
565+{
566+ struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
567+ unsigned int reg, bit;
568+ int ret;
569+
570+ switch (rk808->variant) {
571+ case RK809_ID:
572+ case RK817_ID:
573+ reg = RK817_SYS_CFG(3);
574+ bit = DEV_RST;
575+ break;
576+
577+ default:
578+ return NOTIFY_DONE;
579+ }
580+ ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
581+ if (ret)
582+ dev_err(&rk808_i2c_client->dev, "Failed to restart device!\n");
583+
584+ return NOTIFY_DONE;
585+}
586+
587+static struct notifier_block rk808_restart_handler = {
588+ .notifier_call = rk808_restart_notify,
589+ .priority = 192,
590+};
591+
562592 static void rk8xx_shutdown(struct i2c_client *client)
563593 {
564594 struct rk808 *rk808 = i2c_get_clientdata(client);
@@ -727,6 +757,18 @@ static int rk808_probe(struct i2c_client *client, · 162 unmodified lines
727757 if (of_property_read_bool(np, "rockchip,system-power-controller")) {
728758 rk808_i2c_client = client;
729759 pm_power_off = rk808_pm_power_off;
760+
761+ switch (rk808->variant) {
762+ case RK809_ID:
763+ case RK817_ID:
764+ ret = register_restart_handler(&rk808_restart_handler);
765+ if (ret)
766+ dev_warn(&client->dev, "failed to register rst handler, %d\n", ret);
767+ break;
768+ default:
769+ dev_dbg(&client->dev, "pmic controlled board reset not supported\n");
770+ break;
771+ }
730772 }
731773
732774 return 0;
@@ -749,6 +791,8 @@ static int rk808_remove(struct i2c_client *client) · 16 unmodified lines
749791 if (pm_power_off == rk808_pm_power_off)
750792 pm_power_off = NULL;
751793
794+ unregister_restart_handler(&rk808_restart_handler);
795+
752796 return 0;
753797 }
754798
include/linux/mfd/rk808.h+1−0
@@ -373,6 +373,7 @@ enum rk805_reg { · 372 unmodified lines
373373 #define SWITCH2_EN BIT(6)
374374 #define SWITCH1_EN BIT(5)
375375 #define DEV_OFF_RST BIT(3)
376+#define DEV_RST BIT(2)
376377 #define DEV_OFF BIT(0)
377378 #define RTC_STOP BIT(0)
378379

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t