1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Spreadtrum Communications Inc.
4 * Copyright (C) 2018 Linaro Ltd.
8 #include <linux/kernel.h>
9 #include <linux/platform_device.h>
11 #include <linux/regmap.h>
12 #include <linux/syscore_ops.h>
14 #define SC27XX_PWR_PD_HW 0xc2c
15 #define SC27XX_PWR_OFF_EN BIT(0)
17 static struct regmap
*regmap
;
20 * On Spreadtrum platform, we need power off system through external SC27xx
21 * series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC,
22 * which is not fast io access.
24 * So before stopping other cores, we need release other cores' resource by
25 * taking cpus down to avoid racing regmap or spi mutex lock when poweroff
26 * system through PMIC.
28 static void sc27xx_poweroff_shutdown(void)
30 #ifdef CONFIG_PM_SLEEP_SMP
31 int cpu
= smp_processor_id();
33 freeze_secondary_cpus(cpu
);
37 static struct syscore_ops poweroff_syscore_ops
= {
38 .shutdown
= sc27xx_poweroff_shutdown
,
41 static void sc27xx_poweroff_do_poweroff(void)
43 regmap_write(regmap
, SC27XX_PWR_PD_HW
, SC27XX_PWR_OFF_EN
);
46 static int sc27xx_poweroff_probe(struct platform_device
*pdev
)
51 regmap
= dev_get_regmap(pdev
->dev
.parent
, NULL
);
55 pm_power_off
= sc27xx_poweroff_do_poweroff
;
56 register_syscore_ops(&poweroff_syscore_ops
);
60 static struct platform_driver sc27xx_poweroff_driver
= {
61 .probe
= sc27xx_poweroff_probe
,
63 .name
= "sc27xx-poweroff",
66 builtin_platform_driver(sc27xx_poweroff_driver
);