2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-03-11 23:46:13 +08:00
|
|
|
/*
|
|
|
|
* Broadcom BCM590xx regulator driver
|
|
|
|
*
|
|
|
|
* Copyright 2014 Linaro Limited
|
|
|
|
* Author: Matt Porter <mporter@linaro.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mfd/bcm590xx.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
|
|
|
#include <linux/regulator/of_regulator.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
2014-04-24 07:21:32 +08:00
|
|
|
/* I2C slave 0 registers */
|
2014-03-11 23:46:13 +08:00
|
|
|
#define BCM590XX_RFLDOPMCTRL1 0x60
|
|
|
|
#define BCM590XX_IOSR1PMCTRL1 0x7a
|
|
|
|
#define BCM590XX_IOSR2PMCTRL1 0x7c
|
|
|
|
#define BCM590XX_CSRPMCTRL1 0x7e
|
|
|
|
#define BCM590XX_SDSR1PMCTRL1 0x82
|
|
|
|
#define BCM590XX_SDSR2PMCTRL1 0x86
|
|
|
|
#define BCM590XX_MSRPMCTRL1 0x8a
|
|
|
|
#define BCM590XX_VSRPMCTRL1 0x8e
|
|
|
|
#define BCM590XX_RFLDOCTRL 0x96
|
|
|
|
#define BCM590XX_CSRVOUT1 0xc0
|
2014-04-24 07:21:32 +08:00
|
|
|
|
|
|
|
/* I2C slave 1 registers */
|
|
|
|
#define BCM590XX_GPLDO5PMCTRL1 0x16
|
|
|
|
#define BCM590XX_GPLDO6PMCTRL1 0x18
|
|
|
|
#define BCM590XX_GPLDO1CTRL 0x1a
|
|
|
|
#define BCM590XX_GPLDO2CTRL 0x1b
|
|
|
|
#define BCM590XX_GPLDO3CTRL 0x1c
|
|
|
|
#define BCM590XX_GPLDO4CTRL 0x1d
|
|
|
|
#define BCM590XX_GPLDO5CTRL 0x1e
|
|
|
|
#define BCM590XX_GPLDO6CTRL 0x1f
|
|
|
|
#define BCM590XX_OTG_CTRL 0x40
|
|
|
|
#define BCM590XX_GPLDO1PMCTRL1 0x57
|
|
|
|
#define BCM590XX_GPLDO2PMCTRL1 0x59
|
|
|
|
#define BCM590XX_GPLDO3PMCTRL1 0x5b
|
|
|
|
#define BCM590XX_GPLDO4PMCTRL1 0x5d
|
|
|
|
|
|
|
|
#define BCM590XX_REG_ENABLE BIT(7)
|
|
|
|
#define BCM590XX_VBUS_ENABLE BIT(2)
|
2014-03-11 23:46:13 +08:00
|
|
|
#define BCM590XX_LDO_VSEL_MASK GENMASK(5, 3)
|
|
|
|
#define BCM590XX_SR_VSEL_MASK GENMASK(5, 0)
|
|
|
|
|
2014-04-24 07:21:32 +08:00
|
|
|
/*
|
|
|
|
* RFLDO to VSR regulators are
|
|
|
|
* accessed via I2C slave 0
|
|
|
|
*/
|
|
|
|
|
2014-03-11 23:46:13 +08:00
|
|
|
/* LDO regulator IDs */
|
|
|
|
#define BCM590XX_REG_RFLDO 0
|
|
|
|
#define BCM590XX_REG_CAMLDO1 1
|
|
|
|
#define BCM590XX_REG_CAMLDO2 2
|
|
|
|
#define BCM590XX_REG_SIMLDO1 3
|
|
|
|
#define BCM590XX_REG_SIMLDO2 4
|
|
|
|
#define BCM590XX_REG_SDLDO 5
|
|
|
|
#define BCM590XX_REG_SDXLDO 6
|
|
|
|
#define BCM590XX_REG_MMCLDO1 7
|
|
|
|
#define BCM590XX_REG_MMCLDO2 8
|
|
|
|
#define BCM590XX_REG_AUDLDO 9
|
|
|
|
#define BCM590XX_REG_MICLDO 10
|
|
|
|
#define BCM590XX_REG_USBLDO 11
|
|
|
|
#define BCM590XX_REG_VIBLDO 12
|
|
|
|
|
|
|
|
/* DCDC regulator IDs */
|
|
|
|
#define BCM590XX_REG_CSR 13
|
|
|
|
#define BCM590XX_REG_IOSR1 14
|
|
|
|
#define BCM590XX_REG_IOSR2 15
|
|
|
|
#define BCM590XX_REG_MSR 16
|
|
|
|
#define BCM590XX_REG_SDSR1 17
|
|
|
|
#define BCM590XX_REG_SDSR2 18
|
|
|
|
#define BCM590XX_REG_VSR 19
|
|
|
|
|
2014-04-24 07:21:32 +08:00
|
|
|
/*
|
|
|
|
* GPLDO1 to VBUS regulators are
|
|
|
|
* accessed via I2C slave 1
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define BCM590XX_REG_GPLDO1 20
|
|
|
|
#define BCM590XX_REG_GPLDO2 21
|
|
|
|
#define BCM590XX_REG_GPLDO3 22
|
|
|
|
#define BCM590XX_REG_GPLDO4 23
|
|
|
|
#define BCM590XX_REG_GPLDO5 24
|
|
|
|
#define BCM590XX_REG_GPLDO6 25
|
|
|
|
#define BCM590XX_REG_VBUS 26
|
|
|
|
|
|
|
|
#define BCM590XX_NUM_REGS 27
|
2014-03-11 23:46:13 +08:00
|
|
|
|
|
|
|
#define BCM590XX_REG_IS_LDO(n) (n < BCM590XX_REG_CSR)
|
2014-04-24 07:21:32 +08:00
|
|
|
#define BCM590XX_REG_IS_GPLDO(n) \
|
|
|
|
((n > BCM590XX_REG_VSR) && (n < BCM590XX_REG_VBUS))
|
|
|
|
#define BCM590XX_REG_IS_VBUS(n) (n == BCM590XX_REG_VBUS)
|
2014-03-11 23:46:13 +08:00
|
|
|
|
|
|
|
/* LDO group A: supported voltages in microvolts */
|
|
|
|
static const unsigned int ldo_a_table[] = {
|
|
|
|
1200000, 1800000, 2500000, 2700000, 2800000,
|
|
|
|
2900000, 3000000, 3300000,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* LDO group C: supported voltages in microvolts */
|
|
|
|
static const unsigned int ldo_c_table[] = {
|
|
|
|
3100000, 1800000, 2500000, 2700000, 2800000,
|
|
|
|
2900000, 3000000, 3300000,
|
|
|
|
};
|
|
|
|
|
2014-06-19 03:42:10 +08:00
|
|
|
static const unsigned int ldo_vbus[] = {
|
|
|
|
5000000,
|
|
|
|
};
|
|
|
|
|
2014-03-11 23:46:13 +08:00
|
|
|
/* DCDC group CSR: supported voltages in microvolts */
|
|
|
|
static const struct regulator_linear_range dcdc_csr_ranges[] = {
|
|
|
|
REGULATOR_LINEAR_RANGE(860000, 2, 50, 10000),
|
|
|
|
REGULATOR_LINEAR_RANGE(1360000, 51, 55, 20000),
|
|
|
|
REGULATOR_LINEAR_RANGE(900000, 56, 63, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* DCDC group IOSR1: supported voltages in microvolts */
|
|
|
|
static const struct regulator_linear_range dcdc_iosr1_ranges[] = {
|
|
|
|
REGULATOR_LINEAR_RANGE(860000, 2, 51, 10000),
|
|
|
|
REGULATOR_LINEAR_RANGE(1500000, 52, 52, 0),
|
|
|
|
REGULATOR_LINEAR_RANGE(1800000, 53, 53, 0),
|
|
|
|
REGULATOR_LINEAR_RANGE(900000, 54, 63, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* DCDC group SDSR1: supported voltages in microvolts */
|
|
|
|
static const struct regulator_linear_range dcdc_sdsr1_ranges[] = {
|
|
|
|
REGULATOR_LINEAR_RANGE(860000, 2, 50, 10000),
|
|
|
|
REGULATOR_LINEAR_RANGE(1340000, 51, 51, 0),
|
|
|
|
REGULATOR_LINEAR_RANGE(900000, 52, 63, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bcm590xx_info {
|
|
|
|
const char *name;
|
|
|
|
const char *vin_name;
|
|
|
|
u8 n_voltages;
|
|
|
|
const unsigned int *volt_table;
|
|
|
|
u8 n_linear_ranges;
|
|
|
|
const struct regulator_linear_range *linear_ranges;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BCM590XX_REG_TABLE(_name, _table) \
|
|
|
|
{ \
|
|
|
|
.name = #_name, \
|
|
|
|
.n_voltages = ARRAY_SIZE(_table), \
|
|
|
|
.volt_table = _table, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BCM590XX_REG_RANGES(_name, _ranges) \
|
|
|
|
{ \
|
|
|
|
.name = #_name, \
|
2014-04-11 04:04:00 +08:00
|
|
|
.n_voltages = 64, \
|
2014-03-11 23:46:13 +08:00
|
|
|
.n_linear_ranges = ARRAY_SIZE(_ranges), \
|
|
|
|
.linear_ranges = _ranges, \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bcm590xx_info bcm590xx_regs[] = {
|
|
|
|
BCM590XX_REG_TABLE(rfldo, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(camldo1, ldo_c_table),
|
|
|
|
BCM590XX_REG_TABLE(camldo2, ldo_c_table),
|
|
|
|
BCM590XX_REG_TABLE(simldo1, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(simldo2, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(sdldo, ldo_c_table),
|
|
|
|
BCM590XX_REG_TABLE(sdxldo, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(mmcldo1, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(mmcldo2, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(audldo, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(micldo, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(usbldo, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(vibldo, ldo_c_table),
|
|
|
|
BCM590XX_REG_RANGES(csr, dcdc_csr_ranges),
|
|
|
|
BCM590XX_REG_RANGES(iosr1, dcdc_iosr1_ranges),
|
|
|
|
BCM590XX_REG_RANGES(iosr2, dcdc_iosr1_ranges),
|
|
|
|
BCM590XX_REG_RANGES(msr, dcdc_iosr1_ranges),
|
|
|
|
BCM590XX_REG_RANGES(sdsr1, dcdc_sdsr1_ranges),
|
|
|
|
BCM590XX_REG_RANGES(sdsr2, dcdc_iosr1_ranges),
|
|
|
|
BCM590XX_REG_RANGES(vsr, dcdc_iosr1_ranges),
|
2014-04-24 07:21:32 +08:00
|
|
|
BCM590XX_REG_TABLE(gpldo1, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(gpldo2, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(gpldo3, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(gpldo4, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(gpldo5, ldo_a_table),
|
|
|
|
BCM590XX_REG_TABLE(gpldo6, ldo_a_table),
|
2014-06-19 03:42:10 +08:00
|
|
|
BCM590XX_REG_TABLE(vbus, ldo_vbus),
|
2014-03-11 23:46:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bcm590xx_reg {
|
|
|
|
struct regulator_desc *desc;
|
|
|
|
struct bcm590xx *mfd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bcm590xx_get_vsel_register(int id)
|
|
|
|
{
|
|
|
|
if (BCM590XX_REG_IS_LDO(id))
|
|
|
|
return BCM590XX_RFLDOCTRL + id;
|
2014-04-24 07:21:32 +08:00
|
|
|
else if (BCM590XX_REG_IS_GPLDO(id))
|
|
|
|
return BCM590XX_GPLDO1CTRL + id;
|
2014-03-11 23:46:13 +08:00
|
|
|
else
|
|
|
|
return BCM590XX_CSRVOUT1 + (id - BCM590XX_REG_CSR) * 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm590xx_get_enable_register(int id)
|
|
|
|
{
|
|
|
|
int reg = 0;
|
|
|
|
|
|
|
|
if (BCM590XX_REG_IS_LDO(id))
|
|
|
|
reg = BCM590XX_RFLDOPMCTRL1 + id * 2;
|
2014-04-24 07:21:32 +08:00
|
|
|
else if (BCM590XX_REG_IS_GPLDO(id))
|
|
|
|
reg = BCM590XX_GPLDO1PMCTRL1 + id * 2;
|
2014-03-11 23:46:13 +08:00
|
|
|
else
|
|
|
|
switch (id) {
|
|
|
|
case BCM590XX_REG_CSR:
|
|
|
|
reg = BCM590XX_CSRPMCTRL1;
|
|
|
|
break;
|
|
|
|
case BCM590XX_REG_IOSR1:
|
|
|
|
reg = BCM590XX_IOSR1PMCTRL1;
|
|
|
|
break;
|
|
|
|
case BCM590XX_REG_IOSR2:
|
|
|
|
reg = BCM590XX_IOSR2PMCTRL1;
|
|
|
|
break;
|
|
|
|
case BCM590XX_REG_MSR:
|
|
|
|
reg = BCM590XX_MSRPMCTRL1;
|
|
|
|
break;
|
|
|
|
case BCM590XX_REG_SDSR1:
|
|
|
|
reg = BCM590XX_SDSR1PMCTRL1;
|
|
|
|
break;
|
|
|
|
case BCM590XX_REG_SDSR2:
|
|
|
|
reg = BCM590XX_SDSR2PMCTRL1;
|
|
|
|
break;
|
2019-01-05 11:28:17 +08:00
|
|
|
case BCM590XX_REG_VSR:
|
|
|
|
reg = BCM590XX_VSRPMCTRL1;
|
|
|
|
break;
|
2014-04-24 07:21:32 +08:00
|
|
|
case BCM590XX_REG_VBUS:
|
|
|
|
reg = BCM590XX_OTG_CTRL;
|
2019-01-05 11:28:17 +08:00
|
|
|
break;
|
2015-09-11 10:26:56 +08:00
|
|
|
}
|
2014-03-11 23:46:13 +08:00
|
|
|
|
2014-04-24 07:21:32 +08:00
|
|
|
|
2014-03-11 23:46:13 +08:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2017-01-28 22:00:24 +08:00
|
|
|
static const struct regulator_ops bcm590xx_ops_ldo = {
|
2014-03-11 23:46:13 +08:00
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
|
|
|
.list_voltage = regulator_list_voltage_table,
|
|
|
|
.map_voltage = regulator_map_voltage_iterate,
|
|
|
|
};
|
|
|
|
|
2017-01-28 22:00:24 +08:00
|
|
|
static const struct regulator_ops bcm590xx_ops_dcdc = {
|
2014-03-11 23:46:13 +08:00
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
|
|
|
.list_voltage = regulator_list_voltage_linear_range,
|
|
|
|
.map_voltage = regulator_map_voltage_linear_range,
|
|
|
|
};
|
|
|
|
|
2017-01-28 22:00:24 +08:00
|
|
|
static const struct regulator_ops bcm590xx_ops_vbus = {
|
2014-04-24 07:21:32 +08:00
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
|
|
|
};
|
|
|
|
|
2014-03-11 23:46:13 +08:00
|
|
|
static int bcm590xx_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct bcm590xx *bcm590xx = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
struct bcm590xx_reg *pmu;
|
|
|
|
struct regulator_config config = { };
|
|
|
|
struct bcm590xx_info *info;
|
|
|
|
struct regulator_dev *rdev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);
|
2014-06-02 14:27:21 +08:00
|
|
|
if (!pmu)
|
2014-03-11 23:46:13 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pmu->mfd = bcm590xx;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, pmu);
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
pmu->desc = devm_kcalloc(&pdev->dev,
|
|
|
|
BCM590XX_NUM_REGS,
|
|
|
|
sizeof(struct regulator_desc),
|
|
|
|
GFP_KERNEL);
|
2014-06-02 14:27:21 +08:00
|
|
|
if (!pmu->desc)
|
2014-03-11 23:46:13 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
info = bcm590xx_regs;
|
|
|
|
|
|
|
|
for (i = 0; i < BCM590XX_NUM_REGS; i++, info++) {
|
|
|
|
/* Register the regulators */
|
|
|
|
pmu->desc[i].name = info->name;
|
2019-04-01 22:42:36 +08:00
|
|
|
pmu->desc[i].of_match = of_match_ptr(info->name);
|
|
|
|
pmu->desc[i].regulators_node = of_match_ptr("regulators");
|
2014-03-11 23:46:13 +08:00
|
|
|
pmu->desc[i].supply_name = info->vin_name;
|
|
|
|
pmu->desc[i].id = i;
|
|
|
|
pmu->desc[i].volt_table = info->volt_table;
|
|
|
|
pmu->desc[i].n_voltages = info->n_voltages;
|
|
|
|
pmu->desc[i].linear_ranges = info->linear_ranges;
|
|
|
|
pmu->desc[i].n_linear_ranges = info->n_linear_ranges;
|
|
|
|
|
2014-04-24 07:21:32 +08:00
|
|
|
if ((BCM590XX_REG_IS_LDO(i)) || (BCM590XX_REG_IS_GPLDO(i))) {
|
2014-03-11 23:46:13 +08:00
|
|
|
pmu->desc[i].ops = &bcm590xx_ops_ldo;
|
|
|
|
pmu->desc[i].vsel_mask = BCM590XX_LDO_VSEL_MASK;
|
2014-04-24 07:21:32 +08:00
|
|
|
} else if (BCM590XX_REG_IS_VBUS(i))
|
|
|
|
pmu->desc[i].ops = &bcm590xx_ops_vbus;
|
|
|
|
else {
|
2014-03-11 23:46:13 +08:00
|
|
|
pmu->desc[i].ops = &bcm590xx_ops_dcdc;
|
|
|
|
pmu->desc[i].vsel_mask = BCM590XX_SR_VSEL_MASK;
|
|
|
|
}
|
|
|
|
|
2014-04-24 07:21:32 +08:00
|
|
|
if (BCM590XX_REG_IS_VBUS(i))
|
|
|
|
pmu->desc[i].enable_mask = BCM590XX_VBUS_ENABLE;
|
|
|
|
else {
|
|
|
|
pmu->desc[i].vsel_reg = bcm590xx_get_vsel_register(i);
|
|
|
|
pmu->desc[i].enable_is_inverted = true;
|
|
|
|
pmu->desc[i].enable_mask = BCM590XX_REG_ENABLE;
|
|
|
|
}
|
2014-03-11 23:46:13 +08:00
|
|
|
pmu->desc[i].enable_reg = bcm590xx_get_enable_register(i);
|
|
|
|
pmu->desc[i].type = REGULATOR_VOLTAGE;
|
|
|
|
pmu->desc[i].owner = THIS_MODULE;
|
|
|
|
|
|
|
|
config.dev = bcm590xx->dev;
|
|
|
|
config.driver_data = pmu;
|
2014-04-24 07:21:32 +08:00
|
|
|
if (BCM590XX_REG_IS_GPLDO(i) || BCM590XX_REG_IS_VBUS(i))
|
|
|
|
config.regmap = bcm590xx->regmap_sec;
|
|
|
|
else
|
|
|
|
config.regmap = bcm590xx->regmap_pri;
|
2014-03-11 23:46:13 +08:00
|
|
|
|
|
|
|
rdev = devm_regulator_register(&pdev->dev, &pmu->desc[i],
|
|
|
|
&config);
|
|
|
|
if (IS_ERR(rdev)) {
|
|
|
|
dev_err(bcm590xx->dev,
|
|
|
|
"failed to register %s regulator\n",
|
|
|
|
pdev->name);
|
|
|
|
return PTR_ERR(rdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver bcm590xx_regulator_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "bcm590xx-vregs",
|
|
|
|
},
|
|
|
|
.probe = bcm590xx_probe,
|
|
|
|
};
|
|
|
|
module_platform_driver(bcm590xx_regulator_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
|
|
|
|
MODULE_DESCRIPTION("BCM590xx voltage regulator driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
2014-03-14 09:57:54 +08:00
|
|
|
MODULE_ALIAS("platform:bcm590xx-vregs");
|