Skip to content

Commit 72758f9

Browse files
xakep-amatopcarlescufi
authored andcommitted
drivers: pinctrl: pfc_rcar: add support of voltage control to pfc driver
Add support of voltage control to Renesas PFC driver. Voltage register mappings have been added to r8a77951 and r8a77961 SoCs. Allow 'power-source' property for 'renesas,rcar-pfc' node. This property will be used for configuring IO voltage on appropriate pin. For now it is possible to have only two voltages: 1.8 and 3.3. Note: it is possible to change voltage only for SD/MMC pins on r8a77951 and r8a77961 SoCs. Signed-off-by: Mykola Kvach <[email protected]>
1 parent b8008c4 commit 72758f9

File tree

6 files changed

+139
-0
lines changed

6 files changed

+139
-0
lines changed

drivers/pinctrl/Kconfig.rcar

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ config PINCTRL_RCAR_PFC
77
depends on DT_HAS_RENESAS_RCAR_PFC_ENABLED
88
help
99
Enable pin controller driver for Renesas RCar SoC
10+
11+
config PINCTRL_RCAR_VOLTAGE_CONTROL
12+
bool "Voltage control functionality of Renesas R-Car PFC driver"
13+
default y if SOC_SERIES_RCAR_GEN3
14+
depends on PINCTRL_RCAR_PFC

drivers/pinctrl/pfc_rcar.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ static const uintptr_t reg_base[] = {
3535
#error Unsupported SoC Series
3636
#endif
3737

38+
#ifdef CONFIG_PINCTRL_RCAR_VOLTAGE_CONTROL
39+
/* POC Control Register can control IO voltage level that is supplied to the pin */
40+
struct pfc_pocctrl_reg {
41+
uint32_t offset;
42+
const uint16_t pins[32];
43+
};
44+
#endif /* CONFIG_PINCTRL_RCAR_VOLTAGE_CONTROL */
45+
3846
/*
3947
* Each drive step is either encoded in 2 or 3 bits.
4048
* So based on a 24 mA maximum value each step is either
@@ -189,6 +197,110 @@ int pfc_rcar_set_bias(uintptr_t pfc_base, uint16_t pin, uint16_t flags)
189197
return 0;
190198
}
191199

200+
#ifdef CONFIG_PINCTRL_RCAR_VOLTAGE_CONTROL
201+
202+
const struct pfc_pocctrl_reg pfc_r8a77951_r8a77961_volt_regs[] = {
203+
{
204+
.offset = 0x0380,
205+
.pins = {
206+
[0] = RCAR_GP_PIN(3, 0), /* SD0_CLK */
207+
[1] = RCAR_GP_PIN(3, 1), /* SD0_CMD */
208+
[2] = RCAR_GP_PIN(3, 2), /* SD0_DAT0 */
209+
[3] = RCAR_GP_PIN(3, 3), /* SD0_DAT1 */
210+
[4] = RCAR_GP_PIN(3, 4), /* SD0_DAT2 */
211+
[5] = RCAR_GP_PIN(3, 5), /* SD0_DAT3 */
212+
[6] = RCAR_GP_PIN(3, 6), /* SD1_CLK */
213+
[7] = RCAR_GP_PIN(3, 7), /* SD1_CMD */
214+
[8] = RCAR_GP_PIN(3, 8), /* SD1_DAT0 */
215+
[9] = RCAR_GP_PIN(3, 9), /* SD1_DAT1 */
216+
[10] = RCAR_GP_PIN(3, 10), /* SD1_DAT2 */
217+
[11] = RCAR_GP_PIN(3, 11), /* SD1_DAT3 */
218+
[12] = RCAR_GP_PIN(4, 0), /* SD2_CLK */
219+
[13] = RCAR_GP_PIN(4, 1), /* SD2_CMD */
220+
[14] = RCAR_GP_PIN(4, 2), /* SD2_DAT0 */
221+
[15] = RCAR_GP_PIN(4, 3), /* SD2_DAT1 */
222+
[16] = RCAR_GP_PIN(4, 4), /* SD2_DAT2 */
223+
[17] = RCAR_GP_PIN(4, 5), /* SD2_DAT3 */
224+
[18] = RCAR_GP_PIN(4, 6), /* SD2_DS */
225+
[19] = RCAR_GP_PIN(4, 7), /* SD3_CLK */
226+
[20] = RCAR_GP_PIN(4, 8), /* SD3_CMD */
227+
[21] = RCAR_GP_PIN(4, 9), /* SD3_DAT0 */
228+
[22] = RCAR_GP_PIN(4, 10), /* SD3_DAT1 */
229+
[23] = RCAR_GP_PIN(4, 11), /* SD3_DAT2 */
230+
[24] = RCAR_GP_PIN(4, 12), /* SD3_DAT3 */
231+
[25] = RCAR_GP_PIN(4, 13), /* SD3_DAT4 */
232+
[26] = RCAR_GP_PIN(4, 14), /* SD3_DAT5 */
233+
[27] = RCAR_GP_PIN(4, 15), /* SD3_DAT6 */
234+
[28] = RCAR_GP_PIN(4, 16), /* SD3_DAT7 */
235+
[29] = RCAR_GP_PIN(4, 17), /* SD3_DS */
236+
[30] = -1,
237+
[31] = -1,
238+
}
239+
},
240+
{ /* sentinel */ },
241+
};
242+
243+
static const struct pfc_pocctrl_reg *pfc_rcar_get_io_voltage_regs(void)
244+
{
245+
return pfc_r8a77951_r8a77961_volt_regs;
246+
}
247+
248+
static const struct pfc_pocctrl_reg *pfc_rcar_get_pocctrl_reg(uint16_t pin, uint8_t *bit)
249+
{
250+
const struct pfc_pocctrl_reg *voltage_regs = pfc_rcar_get_io_voltage_regs();
251+
252+
BUILD_ASSERT(ARRAY_SIZE(voltage_regs->pins) < UINT8_MAX);
253+
254+
/* Loop around all the registers to find the bit for a given pin */
255+
while (voltage_regs && voltage_regs->offset) {
256+
uint8_t i;
257+
258+
for (i = 0U; i < ARRAY_SIZE(voltage_regs->pins); i++) {
259+
if (voltage_regs->pins[i] == pin) {
260+
*bit = i;
261+
return voltage_regs;
262+
}
263+
}
264+
voltage_regs++;
265+
}
266+
267+
return NULL;
268+
}
269+
270+
static void pfc_rcar_set_voltage(uintptr_t pfc_base, uint16_t pin, uint16_t voltage)
271+
{
272+
uint32_t val;
273+
uint8_t bit;
274+
const struct pfc_pocctrl_reg *voltage_reg;
275+
276+
voltage_reg = pfc_rcar_get_pocctrl_reg(pin, &bit);
277+
if (!voltage_reg) {
278+
return;
279+
}
280+
281+
val = sys_read32(pfc_base + voltage_reg->offset);
282+
283+
switch (voltage) {
284+
case PIN_VOLTAGE_1P8V:
285+
if (!(val & BIT(bit))) {
286+
return;
287+
}
288+
val &= ~BIT(bit);
289+
break;
290+
case PIN_VOLTAGE_3P3V:
291+
if (val & BIT(bit)) {
292+
return;
293+
}
294+
val |= BIT(bit);
295+
break;
296+
default:
297+
break;
298+
}
299+
300+
pfc_rcar_write(pfc_base, voltage_reg->offset, val);
301+
}
302+
#endif /* CONFIG_PINCTRL_RCAR_VOLTAGE_CONTROL */
303+
192304
int pinctrl_configure_pin(const pinctrl_soc_pin_t *pin)
193305
{
194306
int ret = 0;
@@ -214,6 +326,12 @@ int pinctrl_configure_pin(const pinctrl_soc_pin_t *pin)
214326
return -EINVAL;
215327
}
216328

329+
#ifdef CONFIG_PINCTRL_RCAR_VOLTAGE_CONTROL
330+
if (pin->voltage != PIN_VOLTAGE_NONE) {
331+
pfc_rcar_set_voltage(pfc_base, pin->pin, pin->voltage);
332+
}
333+
#endif
334+
217335
/* Select function for pin */
218336
if ((pin->flags & RCAR_PIN_FLAGS_FUNC_SET) != 0U) {
219337
pfc_rcar_set_ipsr(pfc_base, &pin->func);

dts/bindings/pinctrl/renesas,rcar-pfc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ description: |
5151
- bias-pull-down
5252
- bias-pull-up
5353
- drive-strength
54+
- power-source
5455
5556
To link pin configurations with a device, use a pinctrl-N property for some
5657
number N, like this example you could place in your board's DTS file:
@@ -82,6 +83,7 @@ child-binding:
8283
- bias-pull-down
8384
- bias-pull-up
8485
- drive-strength
86+
- power-source
8587

8688
properties:
8789
pin:

include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-rcar-common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@
7272
#define IP2SR5(shift, func) IPnSR(2, 5, shift, func)
7373
#define IP3SR5(shift, func) IPnSR(3, 5, shift, func)
7474

75+
#define PIN_VOLTAGE_NONE 0
76+
#define PIN_VOLTAGE_1P8V 1
77+
#define PIN_VOLTAGE_3P3V 2
78+
7579
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_RCAR_COMMON_H_ */

soc/arm/renesas_rcar/common/pinctrl_rcar.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef struct pinctrl_soc_pin {
3838
struct rcar_pin_func func;
3939
uint8_t flags;
4040
uint8_t drive_strength;
41+
uint8_t voltage;
4142
} pinctrl_soc_pin_t;
4243

4344
#define RCAR_IPSR(node_id) DT_PROP_BY_IDX(node_id, pin, 1)
@@ -66,6 +67,10 @@ typedef struct pinctrl_soc_pin {
6667
.drive_strength = \
6768
COND_CODE_1(DT_NODE_HAS_PROP(node_id, drive_strength), \
6869
(DT_PROP(node_id, drive_strength)), (0)), \
70+
.voltage = COND_CODE_1(DT_NODE_HAS_PROP(node_id, \
71+
power_source), \
72+
(DT_PROP(node_id, power_source)), \
73+
(PIN_VOLTAGE_NONE)), \
6974
},
7075

7176
/**

soc/arm64/renesas_rcar/gen3/pinctrl_soc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct pinctrl_soc_pin {
3737
struct rcar_pin_func func;
3838
uint8_t flags;
3939
uint8_t drive_strength;
40+
uint8_t voltage;
4041
} pinctrl_soc_pin_t;
4142

4243
#define RCAR_IPSR(node_id) DT_PROP_BY_IDX(node_id, pin, 1)
@@ -65,6 +66,10 @@ typedef struct pinctrl_soc_pin {
6566
.drive_strength = \
6667
COND_CODE_1(DT_NODE_HAS_PROP(node_id, drive_strength), \
6768
(DT_PROP(node_id, drive_strength)), (0)), \
69+
.voltage = COND_CODE_1(DT_NODE_HAS_PROP(node_id, \
70+
power_source), \
71+
(DT_PROP(node_id, power_source)), \
72+
(PIN_VOLTAGE_NONE)), \
6873
},
6974

7075
/**

0 commit comments

Comments
 (0)