2014-02-19 14:56:40 +00:00
|
|
|
/*
|
|
|
|
* pbias-regulator.c
|
|
|
|
*
|
2020-07-19 20:06:23 +00:00
|
|
|
* Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/
|
2014-02-19 14:56:40 +00:00
|
|
|
* Author: Balaji T K <balajitk@ti.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
|
|
|
|
* kind, whether express or implied; without even the implied warranty
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mfd/syscon.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
|
|
|
#include <linux/regulator/of_regulator.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
|
|
|
|
struct pbias_reg_info {
|
|
|
|
u32 enable;
|
|
|
|
u32 enable_mask;
|
2015-07-27 11:24:10 +00:00
|
|
|
u32 disable_val;
|
2014-02-19 14:56:40 +00:00
|
|
|
u32 vmode;
|
|
|
|
unsigned int enable_time;
|
|
|
|
char *name;
|
2017-08-31 10:18:45 +00:00
|
|
|
const unsigned int *pbias_volt_table;
|
|
|
|
int n_voltages;
|
2014-02-19 14:56:40 +00:00
|
|
|
};
|
|
|
|
|
2015-09-03 06:50:37 +00:00
|
|
|
struct pbias_of_data {
|
|
|
|
unsigned int offset;
|
|
|
|
};
|
|
|
|
|
2017-08-31 10:18:45 +00:00
|
|
|
static const unsigned int pbias_volt_table_3_0V[] = {
|
2014-03-08 03:56:47 +00:00
|
|
|
1800000,
|
|
|
|
3000000
|
|
|
|
};
|
2014-02-19 14:56:40 +00:00
|
|
|
|
2017-08-31 10:18:45 +00:00
|
|
|
static const unsigned int pbias_volt_table_3_3V[] = {
|
|
|
|
1800000,
|
|
|
|
3300000
|
|
|
|
};
|
|
|
|
|
2017-01-28 14:55:21 +00:00
|
|
|
static const struct regulator_ops pbias_regulator_voltage_ops = {
|
2014-03-08 03:56:47 +00:00
|
|
|
.list_voltage = regulator_list_voltage_table,
|
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
2014-04-15 04:02:08 +00:00
|
|
|
.enable = regulator_enable_regmap,
|
2014-03-08 03:56:47 +00:00
|
|
|
.disable = regulator_disable_regmap,
|
2014-04-15 04:02:08 +00:00
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
2014-02-19 14:56:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_reg_info pbias_mmc_omap2430 = {
|
|
|
|
.enable = BIT(1),
|
|
|
|
.enable_mask = BIT(1),
|
|
|
|
.vmode = BIT(0),
|
2015-07-27 11:24:10 +00:00
|
|
|
.disable_val = 0,
|
2014-02-19 14:56:40 +00:00
|
|
|
.enable_time = 100,
|
2017-08-31 10:18:45 +00:00
|
|
|
.pbias_volt_table = pbias_volt_table_3_0V,
|
|
|
|
.n_voltages = 2,
|
2014-02-19 14:56:40 +00:00
|
|
|
.name = "pbias_mmc_omap2430"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_reg_info pbias_sim_omap3 = {
|
|
|
|
.enable = BIT(9),
|
|
|
|
.enable_mask = BIT(9),
|
|
|
|
.vmode = BIT(8),
|
|
|
|
.enable_time = 100,
|
2017-08-31 10:18:45 +00:00
|
|
|
.pbias_volt_table = pbias_volt_table_3_0V,
|
|
|
|
.n_voltages = 2,
|
2014-02-19 14:56:40 +00:00
|
|
|
.name = "pbias_sim_omap3"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_reg_info pbias_mmc_omap4 = {
|
|
|
|
.enable = BIT(26) | BIT(22),
|
|
|
|
.enable_mask = BIT(26) | BIT(25) | BIT(22),
|
2015-07-27 11:24:10 +00:00
|
|
|
.disable_val = BIT(25),
|
2014-02-19 14:56:40 +00:00
|
|
|
.vmode = BIT(21),
|
|
|
|
.enable_time = 100,
|
2017-08-31 10:18:45 +00:00
|
|
|
.pbias_volt_table = pbias_volt_table_3_0V,
|
|
|
|
.n_voltages = 2,
|
2014-02-19 14:56:40 +00:00
|
|
|
.name = "pbias_mmc_omap4"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_reg_info pbias_mmc_omap5 = {
|
|
|
|
.enable = BIT(27) | BIT(26),
|
|
|
|
.enable_mask = BIT(27) | BIT(25) | BIT(26),
|
2015-07-27 11:24:10 +00:00
|
|
|
.disable_val = BIT(25),
|
2014-02-19 14:56:40 +00:00
|
|
|
.vmode = BIT(21),
|
|
|
|
.enable_time = 100,
|
2017-08-31 10:18:45 +00:00
|
|
|
.pbias_volt_table = pbias_volt_table_3_3V,
|
|
|
|
.n_voltages = 2,
|
2014-02-19 14:56:40 +00:00
|
|
|
.name = "pbias_mmc_omap5"
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct of_regulator_match pbias_matches[] = {
|
|
|
|
{ .name = "pbias_mmc_omap2430", .driver_data = (void *)&pbias_mmc_omap2430},
|
|
|
|
{ .name = "pbias_sim_omap3", .driver_data = (void *)&pbias_sim_omap3},
|
|
|
|
{ .name = "pbias_mmc_omap4", .driver_data = (void *)&pbias_mmc_omap4},
|
|
|
|
{ .name = "pbias_mmc_omap5", .driver_data = (void *)&pbias_mmc_omap5},
|
|
|
|
};
|
|
|
|
#define PBIAS_NUM_REGS ARRAY_SIZE(pbias_matches)
|
|
|
|
|
2015-09-03 06:50:37 +00:00
|
|
|
/* Offset from SCM general area (and syscon) base */
|
|
|
|
|
|
|
|
static const struct pbias_of_data pbias_of_data_omap2 = {
|
|
|
|
.offset = 0x230,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_of_data pbias_of_data_omap3 = {
|
|
|
|
.offset = 0x2b0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_of_data pbias_of_data_omap4 = {
|
|
|
|
.offset = 0x60,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_of_data pbias_of_data_omap5 = {
|
|
|
|
.offset = 0x60,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pbias_of_data pbias_of_data_dra7 = {
|
|
|
|
.offset = 0xe00,
|
|
|
|
};
|
|
|
|
|
2014-02-19 14:56:40 +00:00
|
|
|
static const struct of_device_id pbias_of_match[] = {
|
|
|
|
{ .compatible = "ti,pbias-omap", },
|
2015-09-03 06:50:37 +00:00
|
|
|
{ .compatible = "ti,pbias-omap2", .data = &pbias_of_data_omap2, },
|
|
|
|
{ .compatible = "ti,pbias-omap3", .data = &pbias_of_data_omap3, },
|
|
|
|
{ .compatible = "ti,pbias-omap4", .data = &pbias_of_data_omap4, },
|
|
|
|
{ .compatible = "ti,pbias-omap5", .data = &pbias_of_data_omap5, },
|
|
|
|
{ .compatible = "ti,pbias-dra7", .data = &pbias_of_data_dra7, },
|
2014-02-19 14:56:40 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, pbias_of_match);
|
|
|
|
|
|
|
|
static int pbias_regulator_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
struct resource *res;
|
|
|
|
struct regulator_config cfg = { };
|
2019-10-07 11:43:20 +00:00
|
|
|
struct regulator_desc *desc;
|
|
|
|
struct regulator_dev *rdev;
|
2014-02-19 14:56:40 +00:00
|
|
|
struct regmap *syscon;
|
|
|
|
const struct pbias_reg_info *info;
|
2019-10-07 11:43:20 +00:00
|
|
|
int ret, count, idx;
|
2015-09-03 06:50:37 +00:00
|
|
|
const struct pbias_of_data *data;
|
|
|
|
unsigned int offset;
|
2014-02-19 14:56:40 +00:00
|
|
|
|
|
|
|
count = of_regulator_match(&pdev->dev, np, pbias_matches,
|
|
|
|
PBIAS_NUM_REGS);
|
|
|
|
if (count < 0)
|
|
|
|
return count;
|
|
|
|
|
2019-10-07 11:43:20 +00:00
|
|
|
desc = devm_kcalloc(&pdev->dev, count, sizeof(*desc), GFP_KERNEL);
|
|
|
|
if (!desc)
|
2014-02-19 14:56:40 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
syscon = syscon_regmap_lookup_by_phandle(np, "syscon");
|
|
|
|
if (IS_ERR(syscon))
|
|
|
|
return PTR_ERR(syscon);
|
|
|
|
|
2019-09-25 10:12:56 +00:00
|
|
|
data = of_device_get_match_data(&pdev->dev);
|
|
|
|
if (data) {
|
2015-09-03 06:50:37 +00:00
|
|
|
offset = data->offset;
|
|
|
|
} else {
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
offset = res->start;
|
|
|
|
dev_WARN(&pdev->dev,
|
|
|
|
"using legacy dt data for pbias offset\n");
|
|
|
|
}
|
|
|
|
|
2014-03-08 03:56:47 +00:00
|
|
|
cfg.regmap = syscon;
|
2014-02-19 14:56:40 +00:00
|
|
|
cfg.dev = &pdev->dev;
|
|
|
|
|
2019-10-07 11:43:20 +00:00
|
|
|
for (idx = 0; idx < PBIAS_NUM_REGS && count; idx++) {
|
2014-02-19 14:56:40 +00:00
|
|
|
if (!pbias_matches[idx].init_data ||
|
|
|
|
!pbias_matches[idx].of_node)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
info = pbias_matches[idx].driver_data;
|
|
|
|
if (!info)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2019-10-07 11:43:20 +00:00
|
|
|
desc->name = info->name;
|
|
|
|
desc->owner = THIS_MODULE;
|
|
|
|
desc->type = REGULATOR_VOLTAGE;
|
|
|
|
desc->ops = &pbias_regulator_voltage_ops;
|
|
|
|
desc->volt_table = info->pbias_volt_table;
|
|
|
|
desc->n_voltages = info->n_voltages;
|
|
|
|
desc->enable_time = info->enable_time;
|
|
|
|
desc->vsel_reg = offset;
|
|
|
|
desc->vsel_mask = info->vmode;
|
|
|
|
desc->enable_reg = offset;
|
|
|
|
desc->enable_mask = info->enable_mask;
|
|
|
|
desc->enable_val = info->enable;
|
|
|
|
desc->disable_val = info->disable_val;
|
2014-02-19 14:56:40 +00:00
|
|
|
|
|
|
|
cfg.init_data = pbias_matches[idx].init_data;
|
|
|
|
cfg.of_node = pbias_matches[idx].of_node;
|
|
|
|
|
2019-10-07 11:43:20 +00:00
|
|
|
rdev = devm_regulator_register(&pdev->dev, desc, &cfg);
|
|
|
|
if (IS_ERR(rdev)) {
|
|
|
|
ret = PTR_ERR(rdev);
|
2014-02-19 14:56:40 +00:00
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"Failed to register regulator: %d\n", ret);
|
2019-10-07 11:43:20 +00:00
|
|
|
return ret;
|
2014-02-19 14:56:40 +00:00
|
|
|
}
|
2019-10-07 11:43:20 +00:00
|
|
|
desc++;
|
|
|
|
count--;
|
2014-02-19 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
2019-10-07 11:43:20 +00:00
|
|
|
return 0;
|
2014-02-19 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver pbias_regulator_driver = {
|
|
|
|
.probe = pbias_regulator_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "pbias-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-16 19:54:38 +00:00
|
|
|
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
2014-02-19 14:56:40 +00:00
|
|
|
.of_match_table = of_match_ptr(pbias_of_match),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(pbias_regulator_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Balaji T K <balajitk@ti.com>");
|
|
|
|
MODULE_DESCRIPTION("pbias voltage regulator");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:pbias-regulator");
|