Skip to content

Commit 3dacdda

Browse files
committed
regulator: da91xx: Allow caching of buck registers when no GPIO input control is configured
André Svensson <andre.svensson@axis.com> says: This series introduces a boolean DT property, dlg,no-gpio-control, for the DA91xx regulators. Use this property to indicate that GPIO control is not configured with the functions DVC/RELOAD/EN, allowing buck registers to be cached. The DA9121 driver checks dlg,no-gpio-control and updates regmap_config's volatile_table if the property is present. Buck registers are removed from the volatile_table if the property is present, enabling caching of the registers, which removes I2C reads when performing an I2C write to the buck registers. Link: https://patch.msgid.link/20260320-no-gpio-control-v2-0-dbc938e462cb@axis.com Signed-off-by: Mark Brown <broonie@kernel.org>
2 parents 57fca3a + 6c2505e commit 3dacdda

2 files changed

Lines changed: 85 additions & 7 deletions

File tree

Documentation/devicetree/bindings/regulator/dlg,da9121.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ properties:
8181
Specify the polling period, measured in milliseconds, between interrupt status
8282
update checks. Range 1000-10000 ms.
8383
84+
dlg,no-gpio-control:
85+
type: boolean
86+
description: |
87+
Available GPIO input pins of the regulator are strapped to fixed levels, therefore
88+
GPIO configurable input functions, DVC/RELOAD/EN, cannot dynamically update BUCK
89+
registers. GPIO pins connected as output pins are not required to be strapped to a
90+
fixed level. Not allowed together with enable-gpios.
91+
8492
regulators:
8593
type: object
8694
additionalProperties: false
@@ -134,6 +142,17 @@ allOf:
134142
properties:
135143
buck2: false
136144

145+
- if:
146+
required:
147+
- dlg,no-gpio-control
148+
then:
149+
properties:
150+
regulators:
151+
patternProperties:
152+
"^buck([1-2])$":
153+
properties:
154+
enable-gpios: false
155+
137156
additionalProperties: false
138157

139158
examples:
@@ -168,6 +187,36 @@ examples:
168187
};
169188
};
170189
190+
- |
191+
#include <dt-bindings/interrupt-controller/irq.h>
192+
#include <dt-bindings/regulator/dlg,da9121-regulator.h>
193+
i2c {
194+
#address-cells = <1>;
195+
#size-cells = <0>;
196+
pmic@68 {
197+
compatible = "dlg,da9121";
198+
reg = <0x68>;
199+
200+
interrupt-parent = <&gpio6>;
201+
interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
202+
203+
dlg,irq-polling-delay-passive-ms = <2000>;
204+
dlg,no-gpio-control;
205+
206+
regulators {
207+
DA9121_BUCK: buck1 {
208+
regulator-name = "BUCK1";
209+
regulator-min-microvolt = <300000>;
210+
regulator-max-microvolt = <1900000>;
211+
regulator-min-microamp = <7000000>;
212+
regulator-max-microamp = <20000000>;
213+
regulator-boot-on;
214+
regulator-initial-mode = <DA9121_BUCK_MODE_AUTO>;
215+
};
216+
};
217+
};
218+
};
219+
171220
- |
172221
#include <dt-bindings/gpio/gpio.h>
173222
#include <dt-bindings/interrupt-controller/irq.h>

drivers/regulator/da9121-regulator.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,14 @@ static int da9121_of_parse_cb(struct device_node *np,
400400
GPIOD_OUT_HIGH |
401401
GPIOD_FLAGS_BIT_NONEXCLUSIVE,
402402
"da9121-enable");
403-
if (!IS_ERR(ena_gpiod))
403+
if (!IS_ERR(ena_gpiod)) {
404+
if (of_property_read_bool(chip->dev->of_node, "dlg,no-gpio-control")) {
405+
gpiod_put(ena_gpiod);
406+
dev_err(chip->dev, "dlg,no-gpio-control conflicts with enable-gpios\n");
407+
return -EINVAL;
408+
}
404409
config->ena_gpiod = ena_gpiod;
410+
}
405411

406412
if (variant_parameters[chip->variant_id].num_bucks == 2) {
407413
uint32_t ripple_cancel;
@@ -864,6 +870,21 @@ static const struct regmap_access_table da9121_volatile_table = {
864870
.n_yes_ranges = ARRAY_SIZE(da9121_volatile_ranges),
865871
};
866872

873+
/*
874+
* When GPIO functions DVC/RELOAD/EN are not used, the registers in the range
875+
* DA9121_REG_BUCK_BUCK1_0 to DA9121_REG_BUCK_BUCK1_6 need not be volatile
876+
* because register writes to these registers can only be performed via I2C.
877+
*/
878+
static const struct regmap_range da9121_volatile_ranges_no_gpio_ctrl[] = {
879+
regmap_reg_range(DA9121_REG_SYS_STATUS_0, DA9121_REG_SYS_EVENT_2),
880+
regmap_reg_range(DA9121_REG_SYS_GPIO0_0, DA9121_REG_SYS_GPIO2_1),
881+
};
882+
883+
static const struct regmap_access_table da9121_volatile_table_no_gpio_ctrl = {
884+
.yes_ranges = da9121_volatile_ranges_no_gpio_ctrl,
885+
.n_yes_ranges = ARRAY_SIZE(da9121_volatile_ranges_no_gpio_ctrl),
886+
};
887+
867888
/* DA9121 regmap config for 1 channel variants */
868889
static const struct regmap_config da9121_1ch_regmap_config = {
869890
.reg_bits = 8,
@@ -994,40 +1015,48 @@ static int da9121_assign_chip_model(struct i2c_client *i2c,
9941015
struct da9121 *chip)
9951016
{
9961017
const struct regmap_config *regmap;
1018+
struct regmap_config regmap_config_1ch = da9121_1ch_regmap_config;
1019+
struct regmap_config regmap_config_2ch = da9121_2ch_regmap_config;
1020+
9971021
int ret = 0;
9981022

9991023
chip->dev = &i2c->dev;
10001024

1025+
if (of_property_read_bool(i2c->dev.of_node, "dlg,no-gpio-control")) {
1026+
regmap_config_1ch.volatile_table = &da9121_volatile_table_no_gpio_ctrl;
1027+
regmap_config_2ch.volatile_table = &da9121_volatile_table_no_gpio_ctrl;
1028+
}
1029+
10011030
/* Use configured subtype to select the regulator descriptor index and
10021031
* register map, common to both consumer and automotive grade variants
10031032
*/
10041033
switch (chip->subvariant_id) {
10051034
case DA9121_SUBTYPE_DA9121:
10061035
case DA9121_SUBTYPE_DA9130:
10071036
chip->variant_id = DA9121_TYPE_DA9121_DA9130;
1008-
regmap = &da9121_1ch_regmap_config;
1037+
regmap = &regmap_config_1ch;
10091038
break;
10101039
case DA9121_SUBTYPE_DA9217:
10111040
chip->variant_id = DA9121_TYPE_DA9217;
1012-
regmap = &da9121_1ch_regmap_config;
1041+
regmap = &regmap_config_1ch;
10131042
break;
10141043
case DA9121_SUBTYPE_DA9122:
10151044
case DA9121_SUBTYPE_DA9131:
10161045
chip->variant_id = DA9121_TYPE_DA9122_DA9131;
1017-
regmap = &da9121_2ch_regmap_config;
1046+
regmap = &regmap_config_2ch;
10181047
break;
10191048
case DA9121_SUBTYPE_DA9220:
10201049
case DA9121_SUBTYPE_DA9132:
10211050
chip->variant_id = DA9121_TYPE_DA9220_DA9132;
1022-
regmap = &da9121_2ch_regmap_config;
1051+
regmap = &regmap_config_2ch;
10231052
break;
10241053
case DA9121_SUBTYPE_DA9141:
10251054
chip->variant_id = DA9121_TYPE_DA9141;
1026-
regmap = &da9121_1ch_regmap_config;
1055+
regmap = &regmap_config_1ch;
10271056
break;
10281057
case DA9121_SUBTYPE_DA9142:
10291058
chip->variant_id = DA9121_TYPE_DA9142;
1030-
regmap = &da9121_2ch_regmap_config;
1059+
regmap = &regmap_config_2ch;
10311060
break;
10321061
default:
10331062
return -EINVAL;

0 commit comments

Comments
 (0)