2019-05-02 22:36:37 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
//
|
|
|
|
// da9052-regulator.c: Regulator driver for DA9052
|
|
|
|
//
|
|
|
|
// Copyright(c) 2011 Dialog Semiconductor Ltd.
|
|
|
|
//
|
|
|
|
// Author: David Dajun Chen <dchen@diasemi.com>
|
2011-12-09 07:18:20 -07:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
2012-04-16 01:54:24 -07:00
|
|
|
#include <linux/of.h>
|
2012-04-13 06:37:41 -07:00
|
|
|
#include <linux/regulator/of_regulator.h>
|
2011-12-09 07:18:20 -07:00
|
|
|
|
|
|
|
#include <linux/mfd/da9052/da9052.h>
|
|
|
|
#include <linux/mfd/da9052/reg.h>
|
|
|
|
#include <linux/mfd/da9052/pdata.h>
|
|
|
|
|
|
|
|
/* Buck step size */
|
|
|
|
#define DA9052_BUCK_PERI_3uV_STEP 100000
|
|
|
|
#define DA9052_BUCK_PERI_REG_MAP_UPTO_3uV 24
|
|
|
|
#define DA9052_CONST_3uV 3000000
|
|
|
|
|
|
|
|
#define DA9052_MIN_UA 0
|
|
|
|
#define DA9052_MAX_UA 3
|
|
|
|
#define DA9052_CURRENT_RANGE 4
|
|
|
|
|
|
|
|
/* Bit masks */
|
|
|
|
#define DA9052_BUCK_ILIM_MASK_EVEN 0x0c
|
|
|
|
#define DA9052_BUCK_ILIM_MASK_ODD 0xc0
|
|
|
|
|
2012-03-15 04:58:39 -07:00
|
|
|
/* DA9052 REGULATOR IDs */
|
|
|
|
#define DA9052_ID_BUCK1 0
|
|
|
|
#define DA9052_ID_BUCK2 1
|
|
|
|
#define DA9052_ID_BUCK3 2
|
|
|
|
#define DA9052_ID_BUCK4 3
|
|
|
|
#define DA9052_ID_LDO1 4
|
|
|
|
#define DA9052_ID_LDO2 5
|
|
|
|
#define DA9052_ID_LDO3 6
|
|
|
|
#define DA9052_ID_LDO4 7
|
|
|
|
#define DA9052_ID_LDO5 8
|
|
|
|
#define DA9052_ID_LDO6 9
|
|
|
|
#define DA9052_ID_LDO7 10
|
|
|
|
#define DA9052_ID_LDO8 11
|
|
|
|
#define DA9052_ID_LDO9 12
|
|
|
|
#define DA9052_ID_LDO10 13
|
|
|
|
|
2011-12-09 07:18:20 -07:00
|
|
|
static const u32 da9052_current_limits[3][4] = {
|
|
|
|
{700000, 800000, 1000000, 1200000}, /* DA9052-BC BUCKs */
|
|
|
|
{1600000, 2000000, 2400000, 3000000}, /* DA9053-AA/Bx BUCK-CORE */
|
|
|
|
{800000, 1000000, 1200000, 1500000}, /* DA9053-AA/Bx BUCK-PRO,
|
|
|
|
* BUCK-MEM and BUCK-PERI
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
struct da9052_regulator_info {
|
|
|
|
struct regulator_desc reg_desc;
|
|
|
|
int step_uV;
|
|
|
|
int min_uV;
|
|
|
|
int max_uV;
|
2013-10-16 02:33:59 -07:00
|
|
|
unsigned char activate_bit;
|
2011-12-09 07:18:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct da9052_regulator {
|
|
|
|
struct da9052 *da9052;
|
2024-09-09 06:51:12 -07:00
|
|
|
const struct da9052_regulator_info *info;
|
2011-12-09 07:18:20 -07:00
|
|
|
struct regulator_dev *rdev;
|
|
|
|
};
|
|
|
|
|
2024-09-09 06:51:12 -07:00
|
|
|
static int verify_range(const struct da9052_regulator_info *info,
|
2011-12-09 07:18:20 -07:00
|
|
|
int min_uV, int max_uV)
|
|
|
|
{
|
|
|
|
if (min_uV > info->max_uV || max_uV < info->min_uV)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9052_dcdc_get_current_limit(struct regulator_dev *rdev)
|
|
|
|
{
|
|
|
|
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
|
|
|
|
int offset = rdev_get_id(rdev);
|
|
|
|
int ret, row = 2;
|
|
|
|
|
|
|
|
ret = da9052_reg_read(regulator->da9052, DA9052_BUCKA_REG + offset/2);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Determine the even or odd position of the buck current limit
|
|
|
|
* register field
|
|
|
|
*/
|
|
|
|
if (offset % 2 == 0)
|
|
|
|
ret = (ret & DA9052_BUCK_ILIM_MASK_EVEN) >> 2;
|
|
|
|
else
|
|
|
|
ret = (ret & DA9052_BUCK_ILIM_MASK_ODD) >> 6;
|
|
|
|
|
|
|
|
/* Select the appropriate current limit range */
|
|
|
|
if (regulator->da9052->chip_id == DA9052)
|
|
|
|
row = 0;
|
|
|
|
else if (offset == 0)
|
|
|
|
row = 1;
|
|
|
|
|
|
|
|
return da9052_current_limits[row][ret];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9052_dcdc_set_current_limit(struct regulator_dev *rdev, int min_uA,
|
|
|
|
int max_uA)
|
|
|
|
{
|
|
|
|
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
|
|
|
|
int offset = rdev_get_id(rdev);
|
|
|
|
int reg_val = 0;
|
|
|
|
int i, row = 2;
|
|
|
|
|
|
|
|
/* Select the appropriate current limit range */
|
|
|
|
if (regulator->da9052->chip_id == DA9052)
|
|
|
|
row = 0;
|
|
|
|
else if (offset == 0)
|
|
|
|
row = 1;
|
|
|
|
|
2012-08-08 05:23:54 -07:00
|
|
|
for (i = DA9052_CURRENT_RANGE - 1; i >= 0; i--) {
|
2012-11-26 00:23:38 -07:00
|
|
|
if ((min_uA <= da9052_current_limits[row][i]) &&
|
|
|
|
(da9052_current_limits[row][i] <= max_uA)) {
|
2011-12-09 07:18:20 -07:00
|
|
|
reg_val = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 00:23:38 -07:00
|
|
|
if (i < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-12-09 07:18:20 -07:00
|
|
|
/* Determine the even or odd position of the buck current limit
|
|
|
|
* register field
|
|
|
|
*/
|
|
|
|
if (offset % 2 == 0)
|
|
|
|
return da9052_reg_update(regulator->da9052,
|
|
|
|
DA9052_BUCKA_REG + offset/2,
|
|
|
|
DA9052_BUCK_ILIM_MASK_EVEN,
|
|
|
|
reg_val << 2);
|
|
|
|
else
|
|
|
|
return da9052_reg_update(regulator->da9052,
|
|
|
|
DA9052_BUCKA_REG + offset/2,
|
|
|
|
DA9052_BUCK_ILIM_MASK_ODD,
|
|
|
|
reg_val << 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9052_list_voltage(struct regulator_dev *rdev,
|
|
|
|
unsigned int selector)
|
|
|
|
{
|
|
|
|
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
|
2024-09-09 06:51:12 -07:00
|
|
|
const struct da9052_regulator_info *info = regulator->info;
|
2012-03-15 05:00:07 -07:00
|
|
|
int id = rdev_get_id(rdev);
|
2011-12-09 07:18:20 -07:00
|
|
|
int volt_uV;
|
|
|
|
|
2012-03-15 05:00:07 -07:00
|
|
|
if ((id == DA9052_ID_BUCK4) && (regulator->da9052->chip_id == DA9052)
|
|
|
|
&& (selector >= DA9052_BUCK_PERI_REG_MAP_UPTO_3uV)) {
|
|
|
|
volt_uV = ((DA9052_BUCK_PERI_REG_MAP_UPTO_3uV * info->step_uV)
|
|
|
|
+ info->min_uV);
|
|
|
|
volt_uV += (selector - DA9052_BUCK_PERI_REG_MAP_UPTO_3uV)
|
|
|
|
* (DA9052_BUCK_PERI_3uV_STEP);
|
|
|
|
} else {
|
|
|
|
volt_uV = (selector * info->step_uV) + info->min_uV;
|
|
|
|
}
|
2011-12-09 07:18:20 -07:00
|
|
|
|
|
|
|
if (volt_uV > info->max_uV)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return volt_uV;
|
|
|
|
}
|
|
|
|
|
2012-05-15 22:12:35 -07:00
|
|
|
static int da9052_map_voltage(struct regulator_dev *rdev,
|
|
|
|
int min_uV, int max_uV)
|
2011-12-09 07:18:20 -07:00
|
|
|
{
|
|
|
|
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
|
2024-09-09 06:51:12 -07:00
|
|
|
const struct da9052_regulator_info *info = regulator->info;
|
2012-03-15 05:00:07 -07:00
|
|
|
int id = rdev_get_id(rdev);
|
2012-05-15 22:12:35 -07:00
|
|
|
int ret, sel;
|
2011-12-09 07:18:20 -07:00
|
|
|
|
|
|
|
ret = verify_range(info, min_uV, max_uV);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (min_uV < info->min_uV)
|
|
|
|
min_uV = info->min_uV;
|
|
|
|
|
2012-03-15 05:00:07 -07:00
|
|
|
if ((id == DA9052_ID_BUCK4) && (regulator->da9052->chip_id == DA9052)
|
|
|
|
&& (min_uV >= DA9052_CONST_3uV)) {
|
2012-05-15 22:12:35 -07:00
|
|
|
sel = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV +
|
|
|
|
DIV_ROUND_UP(min_uV - DA9052_CONST_3uV,
|
|
|
|
DA9052_BUCK_PERI_3uV_STEP);
|
2012-03-15 05:00:07 -07:00
|
|
|
} else {
|
2012-05-15 22:12:35 -07:00
|
|
|
sel = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
|
2012-03-15 05:00:07 -07:00
|
|
|
}
|
2011-12-09 07:18:20 -07:00
|
|
|
|
2012-05-15 22:12:35 -07:00
|
|
|
ret = da9052_list_voltage(rdev, sel);
|
2011-12-09 07:18:20 -07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2012-05-15 22:12:35 -07:00
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
2013-10-16 02:33:59 -07:00
|
|
|
static int da9052_regulator_set_voltage_sel(struct regulator_dev *rdev,
|
|
|
|
unsigned int selector)
|
|
|
|
{
|
|
|
|
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
|
2024-09-09 06:51:12 -07:00
|
|
|
const struct da9052_regulator_info *info = regulator->info;
|
2013-10-16 02:33:59 -07:00
|
|
|
int id = rdev_get_id(rdev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = da9052_reg_update(regulator->da9052, rdev->desc->vsel_reg,
|
|
|
|
rdev->desc->vsel_mask, selector);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Some LDOs and DCDCs are DVC controlled which requires enabling of
|
|
|
|
* the activate bit to implment the changes on the output.
|
|
|
|
*/
|
|
|
|
switch (id) {
|
|
|
|
case DA9052_ID_BUCK1:
|
|
|
|
case DA9052_ID_BUCK2:
|
|
|
|
case DA9052_ID_BUCK3:
|
|
|
|
case DA9052_ID_LDO2:
|
|
|
|
case DA9052_ID_LDO3:
|
|
|
|
ret = da9052_reg_update(regulator->da9052, DA9052_SUPPLY_REG,
|
|
|
|
info->activate_bit, info->activate_bit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-06 07:35:21 -07:00
|
|
|
static int da9052_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
|
|
|
|
unsigned int old_sel,
|
|
|
|
unsigned int new_sel)
|
|
|
|
{
|
|
|
|
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
|
2024-09-09 06:51:12 -07:00
|
|
|
const struct da9052_regulator_info *info = regulator->info;
|
2014-02-06 07:35:21 -07:00
|
|
|
int id = rdev_get_id(rdev);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* The DVC controlled LDOs and DCDCs ramp with 6.25mV/µs after enabling
|
|
|
|
* the activate bit.
|
|
|
|
*/
|
|
|
|
switch (id) {
|
|
|
|
case DA9052_ID_BUCK1:
|
|
|
|
case DA9052_ID_BUCK2:
|
|
|
|
case DA9052_ID_BUCK3:
|
|
|
|
case DA9052_ID_LDO2:
|
|
|
|
case DA9052_ID_LDO3:
|
2021-06-18 07:14:11 -07:00
|
|
|
ret = DIV_ROUND_UP(abs(new_sel - old_sel) * info->step_uV,
|
|
|
|
6250);
|
2014-02-06 07:35:21 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-19 08:07:09 -07:00
|
|
|
static const struct regulator_ops da9052_dcdc_ops = {
|
2011-12-09 07:18:20 -07:00
|
|
|
.get_current_limit = da9052_dcdc_get_current_limit,
|
|
|
|
.set_current_limit = da9052_dcdc_set_current_limit,
|
|
|
|
|
|
|
|
.list_voltage = da9052_list_voltage,
|
2012-05-15 22:12:35 -07:00
|
|
|
.map_voltage = da9052_map_voltage,
|
2012-04-23 18:54:38 -07:00
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
2013-10-16 02:33:59 -07:00
|
|
|
.set_voltage_sel = da9052_regulator_set_voltage_sel,
|
2014-02-06 07:35:21 -07:00
|
|
|
.set_voltage_time_sel = da9052_regulator_set_voltage_time_sel,
|
2012-04-16 20:34:32 -07:00
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
2011-12-09 07:18:20 -07:00
|
|
|
};
|
|
|
|
|
2015-12-19 08:07:09 -07:00
|
|
|
static const struct regulator_ops da9052_ldo_ops = {
|
2011-12-09 07:18:20 -07:00
|
|
|
.list_voltage = da9052_list_voltage,
|
2012-05-15 22:12:35 -07:00
|
|
|
.map_voltage = da9052_map_voltage,
|
2012-04-23 18:54:38 -07:00
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
2013-10-16 02:33:59 -07:00
|
|
|
.set_voltage_sel = da9052_regulator_set_voltage_sel,
|
2014-02-06 07:35:21 -07:00
|
|
|
.set_voltage_time_sel = da9052_regulator_set_voltage_time_sel,
|
2012-04-16 20:34:32 -07:00
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
2011-12-09 07:18:20 -07:00
|
|
|
};
|
|
|
|
|
2019-01-25 08:37:05 -07:00
|
|
|
#define DA9052_LDO(_id, _name, step, min, max, sbits, ebits, abits) \
|
2011-12-09 07:18:20 -07:00
|
|
|
{\
|
|
|
|
.reg_desc = {\
|
2019-01-25 08:37:05 -07:00
|
|
|
.name = #_name,\
|
2019-03-12 08:47:58 -07:00
|
|
|
.of_match = of_match_ptr(#_name),\
|
|
|
|
.regulators_node = of_match_ptr("regulators"),\
|
2011-12-09 07:18:20 -07:00
|
|
|
.ops = &da9052_ldo_ops,\
|
|
|
|
.type = REGULATOR_VOLTAGE,\
|
2012-03-15 04:58:39 -07:00
|
|
|
.id = DA9052_ID_##_id,\
|
2012-03-05 05:04:32 -07:00
|
|
|
.n_voltages = (max - min) / step + 1, \
|
2011-12-09 07:18:20 -07:00
|
|
|
.owner = THIS_MODULE,\
|
2012-04-23 18:54:38 -07:00
|
|
|
.vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
|
|
|
|
.vsel_mask = (1 << (sbits)) - 1,\
|
2012-04-16 20:34:32 -07:00
|
|
|
.enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
|
|
|
|
.enable_mask = 1 << (ebits),\
|
2011-12-09 07:18:20 -07:00
|
|
|
},\
|
|
|
|
.min_uV = (min) * 1000,\
|
|
|
|
.max_uV = (max) * 1000,\
|
|
|
|
.step_uV = (step) * 1000,\
|
2013-10-16 02:33:59 -07:00
|
|
|
.activate_bit = (abits),\
|
2011-12-09 07:18:20 -07:00
|
|
|
}
|
|
|
|
|
2019-01-25 08:37:05 -07:00
|
|
|
#define DA9052_DCDC(_id, _name, step, min, max, sbits, ebits, abits) \
|
2011-12-09 07:18:20 -07:00
|
|
|
{\
|
|
|
|
.reg_desc = {\
|
2019-01-25 08:37:05 -07:00
|
|
|
.name = #_name,\
|
2019-03-12 08:47:58 -07:00
|
|
|
.of_match = of_match_ptr(#_name),\
|
|
|
|
.regulators_node = of_match_ptr("regulators"),\
|
2011-12-09 07:18:20 -07:00
|
|
|
.ops = &da9052_dcdc_ops,\
|
|
|
|
.type = REGULATOR_VOLTAGE,\
|
2012-03-15 04:58:39 -07:00
|
|
|
.id = DA9052_ID_##_id,\
|
2012-03-05 05:04:32 -07:00
|
|
|
.n_voltages = (max - min) / step + 1, \
|
2011-12-09 07:18:20 -07:00
|
|
|
.owner = THIS_MODULE,\
|
2012-04-23 18:54:38 -07:00
|
|
|
.vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
|
|
|
|
.vsel_mask = (1 << (sbits)) - 1,\
|
2012-04-16 20:34:32 -07:00
|
|
|
.enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
|
|
|
|
.enable_mask = 1 << (ebits),\
|
2011-12-09 07:18:20 -07:00
|
|
|
},\
|
|
|
|
.min_uV = (min) * 1000,\
|
|
|
|
.max_uV = (max) * 1000,\
|
|
|
|
.step_uV = (step) * 1000,\
|
2013-10-16 02:33:59 -07:00
|
|
|
.activate_bit = (abits),\
|
2011-12-09 07:18:20 -07:00
|
|
|
}
|
|
|
|
|
2024-09-09 06:51:12 -07:00
|
|
|
static const struct da9052_regulator_info da9052_regulator_info[] = {
|
2019-01-25 08:37:05 -07:00
|
|
|
DA9052_DCDC(BUCK1, buck1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO),
|
|
|
|
DA9052_DCDC(BUCK2, buck2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO),
|
|
|
|
DA9052_DCDC(BUCK3, buck3, 25, 950, 2525, 6, 6, DA9052_SUPPLY_VBMEMGO),
|
|
|
|
DA9052_DCDC(BUCK4, buck4, 50, 1800, 3600, 5, 6, 0),
|
|
|
|
DA9052_LDO(LDO1, ldo1, 50, 600, 1800, 5, 6, 0),
|
|
|
|
DA9052_LDO(LDO2, ldo2, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO),
|
|
|
|
DA9052_LDO(LDO3, ldo3, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO),
|
|
|
|
DA9052_LDO(LDO4, ldo4, 25, 1725, 3300, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO5, ldo5, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO6, ldo6, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO7, ldo7, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO8, ldo8, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO9, ldo9, 50, 1250, 3650, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO10, ldo10, 50, 1200, 3600, 6, 6, 0),
|
2011-12-09 07:18:20 -07:00
|
|
|
};
|
|
|
|
|
2024-09-09 06:51:12 -07:00
|
|
|
static const struct da9052_regulator_info da9053_regulator_info[] = {
|
2019-01-25 08:37:05 -07:00
|
|
|
DA9052_DCDC(BUCK1, buck1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO),
|
|
|
|
DA9052_DCDC(BUCK2, buck2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO),
|
|
|
|
DA9052_DCDC(BUCK3, buck3, 25, 950, 2525, 6, 6, DA9052_SUPPLY_VBMEMGO),
|
|
|
|
DA9052_DCDC(BUCK4, buck4, 25, 950, 2525, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO1, ldo1, 50, 600, 1800, 5, 6, 0),
|
|
|
|
DA9052_LDO(LDO2, ldo2, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO),
|
|
|
|
DA9052_LDO(LDO3, ldo3, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO),
|
|
|
|
DA9052_LDO(LDO4, ldo4, 25, 1725, 3300, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO5, ldo5, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO6, ldo6, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO7, ldo7, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO8, ldo8, 50, 1200, 3600, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO9, ldo9, 50, 1250, 3650, 6, 6, 0),
|
|
|
|
DA9052_LDO(LDO10, ldo10, 50, 1200, 3600, 6, 6, 0),
|
2011-12-09 07:18:20 -07:00
|
|
|
};
|
|
|
|
|
2024-09-09 06:51:12 -07:00
|
|
|
static inline const struct da9052_regulator_info *find_regulator_info(u8 chip_id,
|
|
|
|
int id)
|
2011-12-09 07:18:20 -07:00
|
|
|
{
|
2024-09-09 06:51:12 -07:00
|
|
|
const struct da9052_regulator_info *info;
|
2011-12-09 07:18:20 -07:00
|
|
|
int i;
|
|
|
|
|
2011-12-15 06:29:53 -07:00
|
|
|
switch (chip_id) {
|
|
|
|
case DA9052:
|
2011-12-09 07:18:20 -07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(da9052_regulator_info); i++) {
|
|
|
|
info = &da9052_regulator_info[i];
|
|
|
|
if (info->reg_desc.id == id)
|
|
|
|
return info;
|
|
|
|
}
|
2011-12-15 06:29:53 -07:00
|
|
|
break;
|
|
|
|
case DA9053_AA:
|
|
|
|
case DA9053_BA:
|
|
|
|
case DA9053_BB:
|
2015-10-16 01:55:54 -07:00
|
|
|
case DA9053_BC:
|
2011-12-09 07:18:20 -07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(da9053_regulator_info); i++) {
|
|
|
|
info = &da9053_regulator_info[i];
|
|
|
|
if (info->reg_desc.id == id)
|
|
|
|
return info;
|
|
|
|
}
|
2011-12-15 06:29:53 -07:00
|
|
|
break;
|
2011-12-09 07:18:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:22:22 -07:00
|
|
|
static int da9052_regulator_probe(struct platform_device *pdev)
|
2011-12-09 07:18:20 -07:00
|
|
|
{
|
2015-05-15 07:27:40 -07:00
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
2012-04-03 16:50:22 -07:00
|
|
|
struct regulator_config config = { };
|
2011-12-09 07:18:20 -07:00
|
|
|
struct da9052_regulator *regulator;
|
|
|
|
struct da9052 *da9052;
|
|
|
|
struct da9052_pdata *pdata;
|
|
|
|
|
2011-12-15 06:29:53 -07:00
|
|
|
regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9052_regulator),
|
|
|
|
GFP_KERNEL);
|
2011-12-09 07:18:20 -07:00
|
|
|
if (!regulator)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
da9052 = dev_get_drvdata(pdev->dev.parent);
|
2013-07-30 01:20:47 -07:00
|
|
|
pdata = dev_get_platdata(da9052->dev);
|
2011-12-09 07:18:20 -07:00
|
|
|
regulator->da9052 = da9052;
|
|
|
|
|
|
|
|
regulator->info = find_regulator_info(regulator->da9052->chip_id,
|
2015-05-15 07:27:40 -07:00
|
|
|
cell->id);
|
2011-12-09 07:18:20 -07:00
|
|
|
if (regulator->info == NULL) {
|
|
|
|
dev_err(&pdev->dev, "invalid regulator ID specified\n");
|
2012-04-04 21:08:58 -07:00
|
|
|
return -EINVAL;
|
2011-12-09 07:18:20 -07:00
|
|
|
}
|
2012-04-03 16:50:22 -07:00
|
|
|
|
2019-03-12 08:47:58 -07:00
|
|
|
config.dev = da9052->dev;
|
2012-04-03 16:50:22 -07:00
|
|
|
config.driver_data = regulator;
|
2012-04-16 20:34:32 -07:00
|
|
|
config.regmap = da9052->regmap;
|
2019-03-12 08:47:58 -07:00
|
|
|
if (pdata)
|
2015-05-15 07:27:40 -07:00
|
|
|
config.init_data = pdata->regulators[cell->id];
|
2012-04-03 16:50:22 -07:00
|
|
|
|
2013-09-02 23:24:46 -07:00
|
|
|
regulator->rdev = devm_regulator_register(&pdev->dev,
|
|
|
|
®ulator->info->reg_desc,
|
|
|
|
&config);
|
2011-12-09 07:18:20 -07:00
|
|
|
if (IS_ERR(regulator->rdev)) {
|
|
|
|
dev_err(&pdev->dev, "failed to register regulator %s\n",
|
|
|
|
regulator->info->reg_desc.name);
|
2012-04-04 21:08:58 -07:00
|
|
|
return PTR_ERR(regulator->rdev);
|
2011-12-09 07:18:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, regulator);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver da9052_regulator_driver = {
|
|
|
|
.probe = da9052_regulator_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "da9052-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 12:54:38 -07:00
|
|
|
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
2011-12-09 07:18:20 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init da9052_regulator_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&da9052_regulator_driver);
|
|
|
|
}
|
|
|
|
subsys_initcall(da9052_regulator_init);
|
|
|
|
|
|
|
|
static void __exit da9052_regulator_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&da9052_regulator_driver);
|
|
|
|
}
|
|
|
|
module_exit(da9052_regulator_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
|
|
|
|
MODULE_DESCRIPTION("Power Regulator driver for Dialog DA9052 PMIC");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:da9052-regulator");
|