2019-04-29 19:35:42 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// Copyright (C) 2012 ARM Limited
|
2012-09-25 01:56:54 +08:00
|
|
|
|
|
|
|
#define DRVNAME "vexpress-regulator"
|
|
|
|
#define pr_fmt(fmt) DRVNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
|
|
|
#include <linux/regulator/of_regulator.h>
|
|
|
|
#include <linux/vexpress.h>
|
|
|
|
|
|
|
|
static int vexpress_regulator_get_voltage(struct regulator_dev *regdev)
|
|
|
|
{
|
2019-04-29 19:35:41 +08:00
|
|
|
unsigned int uV;
|
|
|
|
int err = regmap_read(regdev->regmap, 0, &uV);
|
2012-09-25 01:56:54 +08:00
|
|
|
|
|
|
|
return err ? err : uV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vexpress_regulator_set_voltage(struct regulator_dev *regdev,
|
|
|
|
int min_uV, int max_uV, unsigned *selector)
|
|
|
|
{
|
2019-04-29 19:35:41 +08:00
|
|
|
return regmap_write(regdev->regmap, 0, min_uV);
|
2012-09-25 01:56:54 +08:00
|
|
|
}
|
|
|
|
|
2019-04-11 00:19:37 +08:00
|
|
|
static const struct regulator_ops vexpress_regulator_ops_ro = {
|
2012-09-25 01:56:54 +08:00
|
|
|
.get_voltage = vexpress_regulator_get_voltage,
|
|
|
|
};
|
|
|
|
|
2019-04-11 00:19:37 +08:00
|
|
|
static const struct regulator_ops vexpress_regulator_ops = {
|
2012-09-25 01:56:54 +08:00
|
|
|
.get_voltage = vexpress_regulator_get_voltage,
|
|
|
|
.set_voltage = vexpress_regulator_set_voltage,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int vexpress_regulator_probe(struct platform_device *pdev)
|
|
|
|
{
|
2019-04-29 19:35:41 +08:00
|
|
|
struct regulator_desc *desc;
|
2012-09-25 01:56:54 +08:00
|
|
|
struct regulator_init_data *init_data;
|
|
|
|
struct regulator_config config = { };
|
2019-04-29 19:35:41 +08:00
|
|
|
struct regulator_dev *rdev;
|
|
|
|
struct regmap *regmap;
|
2012-09-25 01:56:54 +08:00
|
|
|
|
2019-04-29 19:35:41 +08:00
|
|
|
desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
|
|
|
|
if (!desc)
|
mfd: vexpress: Convert custom func API to regmap
Components of the Versatile Express platform (configuration
microcontrollers on motherboard and daughterboards in particular)
talk to each other over a custom configuration bus. They
provide miscellaneous functions (from clock generator control
to energy sensors) which are represented as platform devices
(and Device Tree nodes). The transactions on the bus can
be generated by different "bridges" in the system, some
of which are universal for the whole platform (for the price
of high transfer latencies), others restricted to a subsystem
(but much faster).
Until now drivers for such functions were using custom "func"
API, which is being replaced in this patch by regmap calls.
This required:
* a rework (and move to drivers/bus directory, as suggested
by Samuel and Arnd) of the config bus core, which is much
simpler now and uses device model infrastructure (class)
to keep track of the bridges; non-DT case (soon to be
retired anyway) is simply covered by a special device
registration function
* the new config-bus driver also takes over device population,
so there is no need for special matching table for
of_platform_populate nor "simple-bus" hack in the arm64
model dtsi file (relevant bindings documentation has
been updated); this allows all the vexpress devices
fit into normal device model, making it possible
to remove plenty of early inits and other hacks in
the near future
* adaptation of the syscfg bridge implementation in the
sysreg driver, again making it much simpler; there is
a special case of the "energy" function spanning two
registers, where they should be both defined in the tree
now, but backward compatibility is maintained in the code
* modification of the relevant drivers:
* hwmon - just a straight-forward API change
* power/reset driver - API change
* regulator - API change plus error handling
simplification
* osc clock driver - this one required larger rework
in order to turn in into a standard platform driver
Signed-off-by: Pawel Moll <pawel.moll@arm.com>
Acked-by: Mark Brown <broonie@linaro.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Mike Turquette <mturquette@linaro.org>
2014-04-30 23:46:29 +08:00
|
|
|
return -ENOMEM;
|
2012-09-25 01:56:54 +08:00
|
|
|
|
2019-04-29 19:35:41 +08:00
|
|
|
regmap = devm_regmap_init_vexpress_config(&pdev->dev);
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
2012-09-25 01:56:54 +08:00
|
|
|
|
2019-04-29 19:35:41 +08:00
|
|
|
desc->name = dev_name(&pdev->dev);
|
|
|
|
desc->type = REGULATOR_VOLTAGE;
|
|
|
|
desc->owner = THIS_MODULE;
|
|
|
|
desc->continuous_voltage_range = true;
|
2012-09-25 01:56:54 +08:00
|
|
|
|
2014-11-10 21:43:53 +08:00
|
|
|
init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
|
2019-04-29 19:35:41 +08:00
|
|
|
desc);
|
mfd: vexpress: Convert custom func API to regmap
Components of the Versatile Express platform (configuration
microcontrollers on motherboard and daughterboards in particular)
talk to each other over a custom configuration bus. They
provide miscellaneous functions (from clock generator control
to energy sensors) which are represented as platform devices
(and Device Tree nodes). The transactions on the bus can
be generated by different "bridges" in the system, some
of which are universal for the whole platform (for the price
of high transfer latencies), others restricted to a subsystem
(but much faster).
Until now drivers for such functions were using custom "func"
API, which is being replaced in this patch by regmap calls.
This required:
* a rework (and move to drivers/bus directory, as suggested
by Samuel and Arnd) of the config bus core, which is much
simpler now and uses device model infrastructure (class)
to keep track of the bridges; non-DT case (soon to be
retired anyway) is simply covered by a special device
registration function
* the new config-bus driver also takes over device population,
so there is no need for special matching table for
of_platform_populate nor "simple-bus" hack in the arm64
model dtsi file (relevant bindings documentation has
been updated); this allows all the vexpress devices
fit into normal device model, making it possible
to remove plenty of early inits and other hacks in
the near future
* adaptation of the syscfg bridge implementation in the
sysreg driver, again making it much simpler; there is
a special case of the "energy" function spanning two
registers, where they should be both defined in the tree
now, but backward compatibility is maintained in the code
* modification of the relevant drivers:
* hwmon - just a straight-forward API change
* power/reset driver - API change
* regulator - API change plus error handling
simplification
* osc clock driver - this one required larger rework
in order to turn in into a standard platform driver
Signed-off-by: Pawel Moll <pawel.moll@arm.com>
Acked-by: Mark Brown <broonie@linaro.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Mike Turquette <mturquette@linaro.org>
2014-04-30 23:46:29 +08:00
|
|
|
if (!init_data)
|
|
|
|
return -EINVAL;
|
2012-09-25 01:56:54 +08:00
|
|
|
|
|
|
|
init_data->constraints.apply_uV = 0;
|
|
|
|
if (init_data->constraints.min_uV && init_data->constraints.max_uV)
|
2019-04-29 19:35:41 +08:00
|
|
|
desc->ops = &vexpress_regulator_ops;
|
2012-09-25 01:56:54 +08:00
|
|
|
else
|
2019-04-29 19:35:41 +08:00
|
|
|
desc->ops = &vexpress_regulator_ops_ro;
|
2012-09-25 01:56:54 +08:00
|
|
|
|
2019-04-29 19:35:41 +08:00
|
|
|
config.regmap = regmap;
|
2012-09-25 01:56:54 +08:00
|
|
|
config.dev = &pdev->dev;
|
|
|
|
config.init_data = init_data;
|
|
|
|
config.of_node = pdev->dev.of_node;
|
|
|
|
|
2019-04-29 19:35:41 +08:00
|
|
|
rdev = devm_regulator_register(&pdev->dev, desc, &config);
|
2019-11-18 18:59:22 +08:00
|
|
|
return PTR_ERR_OR_ZERO(rdev);
|
2012-09-25 01:56:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 16:09:12 +08:00
|
|
|
static const struct of_device_id vexpress_regulator_of_match[] = {
|
2012-09-25 01:56:54 +08:00
|
|
|
{ .compatible = "arm,vexpress-volt", },
|
2012-10-17 09:00:20 +08:00
|
|
|
{ }
|
2012-09-25 01:56:54 +08:00
|
|
|
};
|
2015-09-19 01:09:51 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, vexpress_regulator_of_match);
|
2012-09-25 01:56:54 +08:00
|
|
|
|
|
|
|
static struct platform_driver vexpress_regulator_driver = {
|
|
|
|
.probe = vexpress_regulator_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = DRVNAME,
|
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-09-25 01:56:54 +08:00
|
|
|
.of_match_table = vexpress_regulator_of_match,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(vexpress_regulator_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Pawel Moll <pawel.moll@arm.com>");
|
|
|
|
MODULE_DESCRIPTION("Versatile Express regulator");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:vexpress-regulator");
|