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)  * Regulator driver for RICOH RC5T583 power management chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2011-2012, NVIDIA CORPORATION.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Laxman dewangan <ldewangan@nvidia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * based on code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *      Copyright (C) 2011 RICOH COMPANY,LTD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/mfd/rc5t583.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct rc5t583_regulator_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int			deepsleep_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	/* Regulator register address.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	uint8_t			reg_disc_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	uint8_t			disc_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	uint8_t			deepsleep_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	/* Regulator specific turn-on delay  and voltage settling time*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	int			enable_uv_per_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* Used by regulator core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct regulator_desc	desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int rc5t583_regulator_enable_time(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct rc5t583_regulator_info *reg_info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int vsel = regulator_get_voltage_sel_regmap(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int curr_uV = regulator_list_voltage_linear(rdev, vsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return DIV_ROUND_UP(curr_uV, reg_info->enable_uv_per_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static const struct regulator_ops rc5t583_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.is_enabled		= regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.enable			= regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.disable		= regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.enable_time		= rc5t583_regulator_enable_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.list_voltage		= regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.map_voltage		= regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		_vout_mask, _min_mv, _max_mv, _step_uV, _enable_mv) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.reg_disc_reg	= RC5T583_REG_##_disc_reg,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.disc_bit	= _disc_bit,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.deepsleep_reg	= RC5T583_REG_##_id##DAC_DS,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.enable_uv_per_us = _enable_mv * 1000,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.deepsleep_id	= RC5T583_DS_##_id,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.desc = {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.name = "rc5t583-regulator-"#_id,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		.id = RC5T583_REGULATOR_##_id,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		.n_voltages = (_max_mv - _min_mv) * 1000 / _step_uV + 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		.ops = &rc5t583_ops,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		.type = REGULATOR_VOLTAGE,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		.owner = THIS_MODULE,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		.vsel_reg = RC5T583_REG_##_id##DAC,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		.vsel_mask = _vout_mask,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		.enable_reg = RC5T583_REG_##_en_reg,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.enable_mask = BIT(_en_bit),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		.min_uV	= _min_mv * 1000,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		.uV_step = _step_uV,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.ramp_delay = 40 * 1000,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	},							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static struct rc5t583_regulator_info rc5t583_reg_info[RC5T583_REGULATOR_MAX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	RC5T583_REG(DC0, DC0CTL, 0, DC0CTL, 1, 0x7F, 700, 1500, 12500, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	RC5T583_REG(DC1, DC1CTL, 0, DC1CTL, 1, 0x7F, 700, 1500, 12500, 14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	RC5T583_REG(DC2, DC2CTL, 0, DC2CTL, 1, 0x7F, 900, 2400, 12500, 14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	RC5T583_REG(DC3, DC3CTL, 0, DC3CTL, 1, 0x7F, 900, 2400, 12500, 14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	RC5T583_REG(LDO0, LDOEN2, 0, LDODIS2, 0, 0x7F, 900, 3400, 25000, 160),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	RC5T583_REG(LDO1, LDOEN2, 1, LDODIS2, 1, 0x7F, 900, 3400, 25000, 160),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	RC5T583_REG(LDO2, LDOEN2, 2, LDODIS2, 2, 0x7F, 900, 3400, 25000, 160),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	RC5T583_REG(LDO3, LDOEN2, 3, LDODIS2, 3, 0x7F, 900, 3400, 25000, 160),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	RC5T583_REG(LDO4, LDOEN2, 4, LDODIS2, 4, 0x3F, 750, 1500, 12500, 133),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	RC5T583_REG(LDO5, LDOEN2, 5, LDODIS2, 5, 0x7F, 900, 3400, 25000, 267),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	RC5T583_REG(LDO6, LDOEN2, 6, LDODIS2, 6, 0x7F, 900, 3400, 25000, 133),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	RC5T583_REG(LDO7, LDOEN2, 7, LDODIS2, 7, 0x7F, 900, 3400, 25000, 233),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	RC5T583_REG(LDO8, LDOEN1, 0, LDODIS1, 0, 0x7F, 900, 3400, 25000, 233),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	RC5T583_REG(LDO9, LDOEN1, 1, LDODIS1, 1, 0x7F, 900, 3400, 25000, 133),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int rc5t583_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct rc5t583_regulator_info *ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		dev_err(&pdev->dev, "No platform data, exiting...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return -ENODEV;
^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) 	for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		ri = &rc5t583_reg_info[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (ri->deepsleep_id == RC5T583_DS_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			goto skip_ext_pwr_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		ret = rc5t583_ext_power_req_config(rc5t583->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				ri->deepsleep_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				pdata->regulator_ext_pwr_control[id],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				pdata->regulator_deepsleep_slot[id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		 * Configuring external control is not a major issue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		 * just give warning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			dev_warn(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				"Failed to configure ext control %d\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) skip_ext_pwr_config:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		config.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		config.init_data = pdata->reg_init_data[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		config.driver_data = ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		config.regmap = rc5t583->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			dev_err(&pdev->dev, "Failed to register regulator %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 						ri->desc.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static struct platform_driver rc5t583_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		.name	= "rc5t583-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.probe		= rc5t583_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static int __init rc5t583_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return platform_driver_register(&rc5t583_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) subsys_initcall(rc5t583_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static void __exit rc5t583_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	platform_driver_unregister(&rc5t583_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) module_exit(rc5t583_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) MODULE_DESCRIPTION("RC5T583 regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) MODULE_ALIAS("platform:rc5t583-regulator");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) MODULE_LICENSE("GPL v2");