2019-05-01 09:11:31 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// Device driver for regulators in Hi655x IC
|
|
|
|
//
|
2021-05-22 18:25:51 +08:00
|
|
|
// Copyright (c) 2016 HiSilicon Ltd.
|
2019-05-01 09:11:31 +08:00
|
|
|
//
|
|
|
|
// Authors:
|
|
|
|
// Chen Feng <puck.chen@hisilicon.com>
|
|
|
|
// Fei Wang <w.f@huawei.com>
|
2016-02-14 14:29:22 +08:00
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
|
|
|
#include <linux/regulator/of_regulator.h>
|
|
|
|
#include <linux/mfd/hi655x-pmic.h>
|
|
|
|
|
|
|
|
struct hi655x_regulator {
|
|
|
|
unsigned int disable_reg;
|
|
|
|
unsigned int status_reg;
|
|
|
|
struct regulator_desc rdesc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* LDO7 & LDO10 */
|
|
|
|
static const unsigned int ldo7_voltages[] = {
|
|
|
|
1800000, 1850000, 2850000, 2900000,
|
|
|
|
3000000, 3100000, 3200000, 3300000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned int ldo19_voltages[] = {
|
|
|
|
1800000, 1850000, 1900000, 1750000,
|
|
|
|
2800000, 2850000, 2900000, 3000000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned int ldo22_voltages[] = {
|
|
|
|
900000, 1000000, 1050000, 1100000,
|
|
|
|
1150000, 1175000, 1185000, 1200000,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum hi655x_regulator_id {
|
|
|
|
HI655X_LDO0,
|
|
|
|
HI655X_LDO1,
|
|
|
|
HI655X_LDO2,
|
|
|
|
HI655X_LDO3,
|
|
|
|
HI655X_LDO4,
|
|
|
|
HI655X_LDO5,
|
|
|
|
HI655X_LDO6,
|
|
|
|
HI655X_LDO7,
|
|
|
|
HI655X_LDO8,
|
|
|
|
HI655X_LDO9,
|
|
|
|
HI655X_LDO10,
|
|
|
|
HI655X_LDO11,
|
|
|
|
HI655X_LDO12,
|
|
|
|
HI655X_LDO13,
|
|
|
|
HI655X_LDO14,
|
|
|
|
HI655X_LDO15,
|
|
|
|
HI655X_LDO16,
|
|
|
|
HI655X_LDO17,
|
|
|
|
HI655X_LDO18,
|
|
|
|
HI655X_LDO19,
|
|
|
|
HI655X_LDO20,
|
|
|
|
HI655X_LDO21,
|
|
|
|
HI655X_LDO22,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hi655x_is_enabled(struct regulator_dev *rdev)
|
|
|
|
{
|
|
|
|
unsigned int value = 0;
|
2021-06-20 21:27:15 +08:00
|
|
|
const struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
|
2016-02-14 14:29:22 +08:00
|
|
|
|
|
|
|
regmap_read(rdev->regmap, regulator->status_reg, &value);
|
2019-04-08 20:09:33 +08:00
|
|
|
return (value & rdev->desc->enable_mask);
|
2016-02-14 14:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hi655x_disable(struct regulator_dev *rdev)
|
|
|
|
{
|
2021-06-20 21:27:15 +08:00
|
|
|
const struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
|
2016-02-14 14:29:22 +08:00
|
|
|
|
2019-04-08 20:09:33 +08:00
|
|
|
return regmap_write(rdev->regmap, regulator->disable_reg,
|
|
|
|
rdev->desc->enable_mask);
|
2016-02-14 14:29:22 +08:00
|
|
|
}
|
|
|
|
|
2017-01-28 22:10:08 +08:00
|
|
|
static const struct regulator_ops hi655x_regulator_ops = {
|
2016-02-14 14:29:22 +08:00
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = hi655x_disable,
|
|
|
|
.is_enabled = hi655x_is_enabled,
|
|
|
|
.list_voltage = regulator_list_voltage_table,
|
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
|
|
|
};
|
|
|
|
|
2017-01-28 22:10:08 +08:00
|
|
|
static const struct regulator_ops hi655x_ldo_linear_ops = {
|
2016-02-14 14:29:22 +08:00
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = hi655x_disable,
|
|
|
|
.is_enabled = hi655x_is_enabled,
|
|
|
|
.list_voltage = regulator_list_voltage_linear,
|
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define HI655X_LDO(_ID, vreg, vmask, ereg, dreg, \
|
|
|
|
sreg, cmask, vtable) { \
|
|
|
|
.rdesc = { \
|
|
|
|
.name = #_ID, \
|
|
|
|
.of_match = of_match_ptr(#_ID), \
|
|
|
|
.ops = &hi655x_regulator_ops, \
|
|
|
|
.regulators_node = of_match_ptr("regulators"), \
|
|
|
|
.type = REGULATOR_VOLTAGE, \
|
|
|
|
.id = HI655X_##_ID, \
|
|
|
|
.owner = THIS_MODULE, \
|
|
|
|
.n_voltages = ARRAY_SIZE(vtable), \
|
|
|
|
.volt_table = vtable, \
|
|
|
|
.vsel_reg = HI655X_BUS_ADDR(vreg), \
|
|
|
|
.vsel_mask = vmask, \
|
|
|
|
.enable_reg = HI655X_BUS_ADDR(ereg), \
|
|
|
|
.enable_mask = BIT(cmask), \
|
|
|
|
}, \
|
|
|
|
.disable_reg = HI655X_BUS_ADDR(dreg), \
|
|
|
|
.status_reg = HI655X_BUS_ADDR(sreg), \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HI655X_LDO_LINEAR(_ID, vreg, vmask, ereg, dreg, \
|
|
|
|
sreg, cmask, minv, nvolt, vstep) { \
|
|
|
|
.rdesc = { \
|
|
|
|
.name = #_ID, \
|
|
|
|
.of_match = of_match_ptr(#_ID), \
|
|
|
|
.ops = &hi655x_ldo_linear_ops, \
|
|
|
|
.regulators_node = of_match_ptr("regulators"), \
|
|
|
|
.type = REGULATOR_VOLTAGE, \
|
|
|
|
.id = HI655X_##_ID, \
|
|
|
|
.owner = THIS_MODULE, \
|
|
|
|
.min_uV = minv, \
|
|
|
|
.n_voltages = nvolt, \
|
|
|
|
.uV_step = vstep, \
|
|
|
|
.vsel_reg = HI655X_BUS_ADDR(vreg), \
|
|
|
|
.vsel_mask = vmask, \
|
|
|
|
.enable_reg = HI655X_BUS_ADDR(ereg), \
|
|
|
|
.enable_mask = BIT(cmask), \
|
|
|
|
}, \
|
|
|
|
.disable_reg = HI655X_BUS_ADDR(dreg), \
|
|
|
|
.status_reg = HI655X_BUS_ADDR(sreg), \
|
|
|
|
}
|
|
|
|
|
2019-04-08 20:09:32 +08:00
|
|
|
static const struct hi655x_regulator regulators[] = {
|
2016-02-14 14:29:22 +08:00
|
|
|
HI655X_LDO_LINEAR(LDO2, 0x72, 0x07, 0x29, 0x2a, 0x2b, 0x01,
|
|
|
|
2500000, 8, 100000),
|
|
|
|
HI655X_LDO(LDO7, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x06, ldo7_voltages),
|
|
|
|
HI655X_LDO(LDO10, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x01, ldo7_voltages),
|
|
|
|
HI655X_LDO_LINEAR(LDO13, 0x7e, 0x07, 0x2c, 0x2d, 0x2e, 0x04,
|
|
|
|
1600000, 8, 50000),
|
|
|
|
HI655X_LDO_LINEAR(LDO14, 0x7f, 0x07, 0x2c, 0x2d, 0x2e, 0x05,
|
|
|
|
2500000, 8, 100000),
|
|
|
|
HI655X_LDO_LINEAR(LDO15, 0x80, 0x07, 0x2c, 0x2d, 0x2e, 0x06,
|
|
|
|
1600000, 8, 50000),
|
|
|
|
HI655X_LDO_LINEAR(LDO17, 0x82, 0x07, 0x2f, 0x30, 0x31, 0x00,
|
|
|
|
2500000, 8, 100000),
|
|
|
|
HI655X_LDO(LDO19, 0x84, 0x07, 0x2f, 0x30, 0x31, 0x02, ldo19_voltages),
|
|
|
|
HI655X_LDO_LINEAR(LDO21, 0x86, 0x07, 0x2f, 0x30, 0x31, 0x04,
|
|
|
|
1650000, 8, 50000),
|
|
|
|
HI655X_LDO(LDO22, 0x87, 0x07, 0x2f, 0x30, 0x31, 0x05, ldo22_voltages),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hi655x_regulator_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct hi655x_pmic *pmic;
|
|
|
|
struct regulator_config config = { };
|
|
|
|
struct regulator_dev *rdev;
|
|
|
|
|
|
|
|
pmic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
if (!pmic) {
|
|
|
|
dev_err(&pdev->dev, "no pmic in the regulator parent node\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
config.dev = pdev->dev.parent;
|
|
|
|
config.regmap = pmic->regmap;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
|
2021-06-20 21:27:15 +08:00
|
|
|
config.driver_data = (void *) ®ulators[i];
|
|
|
|
|
2016-02-14 14:29:22 +08:00
|
|
|
rdev = devm_regulator_register(&pdev->dev,
|
|
|
|
®ulators[i].rdesc,
|
|
|
|
&config);
|
|
|
|
if (IS_ERR(rdev)) {
|
|
|
|
dev_err(&pdev->dev, "failed to register regulator %s\n",
|
2021-06-20 21:27:15 +08:00
|
|
|
regulators[i].rdesc.name);
|
2016-02-14 14:29:22 +08:00
|
|
|
return PTR_ERR(rdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-03 13:28:42 +08:00
|
|
|
static const struct platform_device_id hi655x_regulator_table[] = {
|
|
|
|
{ .name = "hi655x-regulator" },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, hi655x_regulator_table);
|
|
|
|
|
2016-02-14 14:29:22 +08:00
|
|
|
static struct platform_driver hi655x_regulator_driver = {
|
2017-04-03 13:28:42 +08:00
|
|
|
.id_table = hi655x_regulator_table,
|
2016-02-14 14:29:22 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "hi655x-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,
|
2016-02-14 14:29:22 +08:00
|
|
|
},
|
|
|
|
.probe = hi655x_regulator_probe,
|
|
|
|
};
|
|
|
|
module_platform_driver(hi655x_regulator_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Chen Feng <puck.chen@hisilicon.com>");
|
|
|
|
MODULE_DESCRIPTION("Hisilicon Hi655x regulator driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|