2 * Rockchip Generic power configuration support.
4 * Copyright (c) 2017 ROCKCHIP, Co. Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/arm-smccc.h>
12 #include <linux/bitops.h>
13 #include <linux/cpu.h>
14 #include <linux/of_gpio.h>
15 #include <linux/platform_device.h>
16 #include <linux/regulator/machine.h>
17 #include <linux/rockchip/rockchip_sip.h>
18 #include <linux/suspend.h>
20 #define PM_INVALID_GPIO 0xffff
22 static const struct of_device_id pm_match_table[] = {
23 { .compatible = "rockchip,pm-rk3399",},
27 static int __init pm_config_init(struct platform_device *pdev)
29 const struct of_device_id *match_id;
30 struct device_node *node;
32 u32 wakeup_config = 0;
33 u32 pwm_regulator_config = 0;
35 u32 sleep_debug_en = 0;
36 u32 apios_suspend = 0;
37 enum of_gpio_flags flags;
41 match_id = of_match_node(pm_match_table, pdev->dev.of_node);
45 node = of_find_node_by_name(NULL, "rockchip-suspend");
47 if (IS_ERR_OR_NULL(node)) {
48 dev_err(&pdev->dev, "%s dev node err\n", __func__);
52 if (of_property_read_u32_array(node,
53 "rockchip,sleep-mode-config",
55 dev_warn(&pdev->dev, "not set sleep mode config\n");
57 sip_smc_set_suspend_mode(SUSPEND_MODE_CONFIG, mode_config, 0);
59 if (of_property_read_u32_array(node,
60 "rockchip,wakeup-config",
62 dev_warn(&pdev->dev, "not set wakeup-config\n");
64 sip_smc_set_suspend_mode(WKUP_SOURCE_CONFIG, wakeup_config, 0);
66 if (of_property_read_u32_array(node,
67 "rockchip,pwm-regulator-config",
68 &pwm_regulator_config, 1))
69 dev_warn(&pdev->dev, "not set pwm-regulator-config\n");
71 sip_smc_set_suspend_mode(PWM_REGULATOR_CONFIG,
75 length = of_gpio_named_count(node, "rockchip,power-ctrl");
77 if (length > 0 && length < 10) {
78 for (i = 0; i < length; i++) {
79 gpio_temp[i] = of_get_named_gpio_flags(node,
80 "rockchip,power-ctrl",
83 if (!gpio_is_valid(gpio_temp[i]))
85 sip_smc_set_suspend_mode(GPIO_POWER_CONFIG,
90 sip_smc_set_suspend_mode(GPIO_POWER_CONFIG, i, PM_INVALID_GPIO);
92 if (!of_property_read_u32_array(node,
93 "rockchip,sleep-debug-en",
95 sip_smc_set_suspend_mode(SUSPEND_DEBUG_ENABLE,
99 if (!of_property_read_u32_array(node,
100 "rockchip,apios-suspend",
102 sip_smc_set_suspend_mode(APIOS_SUSPEND_CONFIG,
109 static struct platform_driver pm_driver = {
111 .name = "rockchip-pm",
112 .of_match_table = pm_match_table,
116 static int __init rockchip_pm_drv_register(void)
118 return platform_driver_probe(&pm_driver, pm_config_init);
120 subsys_initcall(rockchip_pm_drv_register);