2019-05-29 01:10:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-04-04 15:14:00 +08:00
|
|
|
/*
|
|
|
|
* Regulator driver for RICOH RC5T583 power management chip.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
* Author: Laxman dewangan <ldewangan@nvidia.com>
|
|
|
|
*
|
|
|
|
* based on code
|
|
|
|
* Copyright (C) 2011 RICOH COMPANY,LTD
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/mfd/rc5t583.h>
|
|
|
|
|
|
|
|
struct rc5t583_regulator_info {
|
|
|
|
int deepsleep_id;
|
|
|
|
|
|
|
|
/* Regulator register address.*/
|
|
|
|
uint8_t reg_disc_reg;
|
|
|
|
uint8_t disc_bit;
|
|
|
|
uint8_t deepsleep_reg;
|
|
|
|
|
|
|
|
/* Regulator specific turn-on delay and voltage settling time*/
|
|
|
|
int enable_uv_per_us;
|
|
|
|
|
|
|
|
/* Used by regulator core */
|
|
|
|
struct regulator_desc desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rc5t583_regulator_enable_time(struct regulator_dev *rdev)
|
|
|
|
{
|
2019-03-27 19:54:13 +08:00
|
|
|
struct rc5t583_regulator_info *reg_info = rdev_get_drvdata(rdev);
|
2012-04-24 09:56:43 +08:00
|
|
|
int vsel = regulator_get_voltage_sel_regmap(rdev);
|
2012-05-14 10:54:46 +08:00
|
|
|
int curr_uV = regulator_list_voltage_linear(rdev, vsel);
|
2012-04-24 09:56:43 +08:00
|
|
|
|
2019-03-27 19:54:13 +08:00
|
|
|
return DIV_ROUND_UP(curr_uV, reg_info->enable_uv_per_us);
|
2012-04-04 15:14:00 +08:00
|
|
|
}
|
|
|
|
|
2017-01-28 23:18:51 +08:00
|
|
|
static const struct regulator_ops rc5t583_ops = {
|
2012-04-17 14:11:31 +08:00
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
2012-04-04 15:14:00 +08:00
|
|
|
.enable_time = rc5t583_regulator_enable_time,
|
2012-04-24 09:56:43 +08:00
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
2012-05-14 10:55:50 +08:00
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
2012-05-14 10:54:46 +08:00
|
|
|
.list_voltage = regulator_list_voltage_linear,
|
2012-05-14 10:55:50 +08:00
|
|
|
.map_voltage = regulator_map_voltage_linear,
|
2012-06-19 09:26:52 +08:00
|
|
|
.set_voltage_time_sel = regulator_set_voltage_time_sel,
|
2012-04-04 15:14:00 +08:00
|
|
|
};
|
|
|
|
|
2012-04-06 08:01:36 +08:00
|
|
|
#define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \
|
|
|
|
_vout_mask, _min_mv, _max_mv, _step_uV, _enable_mv) \
|
2012-04-04 15:14:00 +08:00
|
|
|
{ \
|
|
|
|
.reg_disc_reg = RC5T583_REG_##_disc_reg, \
|
|
|
|
.disc_bit = _disc_bit, \
|
2012-04-06 08:01:36 +08:00
|
|
|
.deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \
|
2012-04-04 15:14:00 +08:00
|
|
|
.enable_uv_per_us = _enable_mv * 1000, \
|
|
|
|
.deepsleep_id = RC5T583_DS_##_id, \
|
|
|
|
.desc = { \
|
|
|
|
.name = "rc5t583-regulator-"#_id, \
|
|
|
|
.id = RC5T583_REGULATOR_##_id, \
|
2012-04-05 14:04:48 +08:00
|
|
|
.n_voltages = (_max_mv - _min_mv) * 1000 / _step_uV + 1, \
|
2012-04-04 15:14:00 +08:00
|
|
|
.ops = &rc5t583_ops, \
|
|
|
|
.type = REGULATOR_VOLTAGE, \
|
|
|
|
.owner = THIS_MODULE, \
|
2012-04-24 09:56:43 +08:00
|
|
|
.vsel_reg = RC5T583_REG_##_id##DAC, \
|
|
|
|
.vsel_mask = _vout_mask, \
|
2012-04-17 14:11:31 +08:00
|
|
|
.enable_reg = RC5T583_REG_##_en_reg, \
|
|
|
|
.enable_mask = BIT(_en_bit), \
|
2012-05-14 10:54:46 +08:00
|
|
|
.min_uV = _min_mv * 1000, \
|
|
|
|
.uV_step = _step_uV, \
|
2012-06-19 09:26:52 +08:00
|
|
|
.ramp_delay = 40 * 1000, \
|
2012-04-04 15:14:00 +08:00
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rc5t583_regulator_info rc5t583_reg_info[RC5T583_REGULATOR_MAX] = {
|
2012-04-06 08:01:36 +08:00
|
|
|
RC5T583_REG(DC0, DC0CTL, 0, DC0CTL, 1, 0x7F, 700, 1500, 12500, 4),
|
|
|
|
RC5T583_REG(DC1, DC1CTL, 0, DC1CTL, 1, 0x7F, 700, 1500, 12500, 14),
|
|
|
|
RC5T583_REG(DC2, DC2CTL, 0, DC2CTL, 1, 0x7F, 900, 2400, 12500, 14),
|
|
|
|
RC5T583_REG(DC3, DC3CTL, 0, DC3CTL, 1, 0x7F, 900, 2400, 12500, 14),
|
|
|
|
RC5T583_REG(LDO0, LDOEN2, 0, LDODIS2, 0, 0x7F, 900, 3400, 25000, 160),
|
|
|
|
RC5T583_REG(LDO1, LDOEN2, 1, LDODIS2, 1, 0x7F, 900, 3400, 25000, 160),
|
|
|
|
RC5T583_REG(LDO2, LDOEN2, 2, LDODIS2, 2, 0x7F, 900, 3400, 25000, 160),
|
|
|
|
RC5T583_REG(LDO3, LDOEN2, 3, LDODIS2, 3, 0x7F, 900, 3400, 25000, 160),
|
|
|
|
RC5T583_REG(LDO4, LDOEN2, 4, LDODIS2, 4, 0x3F, 750, 1500, 12500, 133),
|
|
|
|
RC5T583_REG(LDO5, LDOEN2, 5, LDODIS2, 5, 0x7F, 900, 3400, 25000, 267),
|
|
|
|
RC5T583_REG(LDO6, LDOEN2, 6, LDODIS2, 6, 0x7F, 900, 3400, 25000, 133),
|
|
|
|
RC5T583_REG(LDO7, LDOEN2, 7, LDODIS2, 7, 0x7F, 900, 3400, 25000, 233),
|
|
|
|
RC5T583_REG(LDO8, LDOEN1, 0, LDODIS1, 0, 0x7F, 900, 3400, 25000, 233),
|
|
|
|
RC5T583_REG(LDO9, LDOEN1, 1, LDODIS1, 1, 0x7F, 900, 3400, 25000, 133),
|
2012-04-04 15:14:00 +08:00
|
|
|
};
|
|
|
|
|
2012-11-20 02:22:22 +08:00
|
|
|
static int rc5t583_regulator_probe(struct platform_device *pdev)
|
2012-04-04 15:14:00 +08:00
|
|
|
{
|
|
|
|
struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev);
|
2012-04-04 07:50:22 +08:00
|
|
|
struct regulator_config config = { };
|
2012-04-04 15:14:00 +08:00
|
|
|
struct regulator_dev *rdev;
|
|
|
|
struct rc5t583_regulator_info *ri;
|
|
|
|
int ret;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->dev, "No platform data, exiting...\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) {
|
|
|
|
ri = &rc5t583_reg_info[id];
|
|
|
|
|
|
|
|
if (ri->deepsleep_id == RC5T583_DS_NONE)
|
|
|
|
goto skip_ext_pwr_config;
|
|
|
|
|
|
|
|
ret = rc5t583_ext_power_req_config(rc5t583->dev,
|
|
|
|
ri->deepsleep_id,
|
|
|
|
pdata->regulator_ext_pwr_control[id],
|
|
|
|
pdata->regulator_deepsleep_slot[id]);
|
|
|
|
/*
|
|
|
|
* Configuring external control is not a major issue,
|
|
|
|
* just give warning.
|
|
|
|
*/
|
|
|
|
if (ret < 0)
|
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"Failed to configure ext control %d\n", id);
|
|
|
|
|
|
|
|
skip_ext_pwr_config:
|
2012-04-04 07:50:22 +08:00
|
|
|
config.dev = &pdev->dev;
|
2014-02-06 14:49:11 +08:00
|
|
|
config.init_data = pdata->reg_init_data[id];
|
2019-03-27 19:54:13 +08:00
|
|
|
config.driver_data = ri;
|
2012-04-17 14:11:31 +08:00
|
|
|
config.regmap = rc5t583->regmap;
|
2012-04-04 07:50:22 +08:00
|
|
|
|
2013-09-04 14:31:02 +08:00
|
|
|
rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
|
2012-04-04 19:52:35 +08:00
|
|
|
if (IS_ERR(rdev)) {
|
2012-04-04 15:14:00 +08:00
|
|
|
dev_err(&pdev->dev, "Failed to register regulator %s\n",
|
|
|
|
ri->desc.name);
|
2013-09-04 14:31:02 +08:00
|
|
|
return PTR_ERR(rdev);
|
2012-04-04 15:14:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver rc5t583_regulator_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "rc5t583-regulator",
|
regulator: Set PROBE_PREFER_ASYNCHRONOUS for drivers that existed in 4.14
Probing of regulators can be a slow operation and can contribute to
slower boot times. This is especially true if a regulator is turned on
at probe time (with regulator-boot-on or regulator-always-on) and the
regulator requires delays (off-on-time, ramp time, etc).
While the overall kernel is not ready to switch to async probe by
default, as per the discussion on the mailing lists [1] it is believed
that the regulator subsystem is in good shape and we can move
regulator drivers over wholesale. There is no way to just magically
opt in all regulators (regulators are just normal drivers like
platform_driver), so we set PROBE_PREFER_ASYNCHRONOUS for all
regulators found in 'drivers/regulator' individually.
Given the number of drivers touched and the impossibility to test this
ahead of time, it wouldn't be shocking at all if this caused a
regression for someone. If there is a regression caused by this patch,
it's likely to be one of the cases talked about in [1]. As a "quick
fix", drivers involved in the regression could be fixed by changing
them to PROBE_FORCE_SYNCHRONOUS. That being said, the correct fix
would be to directly fix the problem that caused the issue with async
probe.
The approach here follows a similar approach that was used for the mmc
subsystem several years ago [2]. In fact, I ran nearly the same python
script to auto-generate the changes. The only thing I changed was to
search for "i2c_driver", "spmi_driver", and "spi_driver" in addition
to "platform_driver".
[1] https://lore.kernel.org/r/06db017f-e985-4434-8d1d-02ca2100cca0@sirena.org.uk
[2] https://lore.kernel.org/r/20200903232441.2694866-1-dianders@chromium.org/
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20230316125351.1.I2a4677392a38db5758dee0788b2cea5872562a82@changeid
Signed-off-by: Mark Brown <broonie@kernel.org>
2023-03-17 03:54:38 +08:00
|
|
|
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
2012-04-04 15:14:00 +08:00
|
|
|
},
|
|
|
|
.probe = rc5t583_regulator_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init rc5t583_regulator_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&rc5t583_regulator_driver);
|
|
|
|
}
|
|
|
|
subsys_initcall(rc5t583_regulator_init);
|
|
|
|
|
|
|
|
static void __exit rc5t583_regulator_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&rc5t583_regulator_driver);
|
|
|
|
}
|
|
|
|
module_exit(rc5t583_regulator_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
|
|
|
|
MODULE_DESCRIPTION("RC5T583 regulator driver");
|
|
|
|
MODULE_ALIAS("platform:rc5t583-regulator");
|
2012-04-06 13:28:33 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|