Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * arch/arm/mach-u300/regulator.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2009 ST-Ericsson AB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Handle board-bound regulators and board power not related
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * to any devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Linus Walleij <linus.walleij@stericsson.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* Power Management Control 16bit (R/W) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define U300_SYSCON_PMCR					(0x50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define U300_SYSCON_PMCR_DCON_ENABLE				(0x0002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define U300_SYSCON_PMCR_PWR_MGNT_ENABLE			(0x0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * Regulators that power the board and chip and which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * not copuled to specific drivers are hogged in these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * instances.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct regulator *main_power_15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * This function is used from pm.h to shut down the system by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * resetting all regulators in turn and then disable regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * LDO D (main power).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) void u300_pm_poweroff(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	sigset_t old, all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	sigfillset(&all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (!sigprocmask(SIG_BLOCK, &all, &old)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		/* Disable LDO D to shut down the system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		if (main_power_15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			regulator_disable(main_power_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			pr_err("regulator not available to shut down system\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		(void) sigprocmask(SIG_SETMASK, &old, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * Hog the regulators needed to power up the board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static int __init __u300_init_boardpower(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct device_node *syscon_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	pr_info("U300: setting up board power\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	syscon_np = of_parse_phandle(np, "syscon", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (!syscon_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		pr_crit("U300: no syscon node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	regmap = syscon_node_to_regmap(syscon_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		pr_crit("U300: could not locate syscon regmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	main_power_15 = regulator_get(&pdev->dev, "vana15");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (IS_ERR(main_power_15)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		pr_err("could not get vana15");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return PTR_ERR(main_power_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	err = regulator_enable(main_power_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		pr_err("could not enable vana15\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 * On U300 a special system controller register pulls up the DC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * until the vana15 (LDO D) regulator comes up. At this point, all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * regulators are set and we do not need power control via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * DC ON anymore. This function will likely be moved whenever
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 * the rest of the U300 power management is implemented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	pr_info("U300: disable system controller pull-up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	regmap_update_bits(regmap, U300_SYSCON_PMCR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			   U300_SYSCON_PMCR_DCON_ENABLE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* Register globally exported PM poweroff hook */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	pm_power_off = u300_pm_poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int __init s365_board_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return __u300_init_boardpower(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static const struct of_device_id s365_board_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	{ .compatible = "stericsson,s365" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct platform_driver s365_board_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		.name   = "s365-board",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		.of_match_table = s365_board_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * So at module init time we hog the regulator!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int __init u300_init_boardpower(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return platform_driver_probe(&s365_board_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				     s365_board_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) device_initcall(u300_init_boardpower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) MODULE_AUTHOR("Linus Walleij");