1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2016 Marvell International Ltd.
4 * https://spdx.org/licenses
12 #include <dm/pinctrl.h>
14 #include <asm/system.h>
16 #include <asm/arch-armada8k/soc-info.h>
17 #include "pinctrl-mvebu.h"
19 #define AP_EMMC_PHY_CTRL_REG 0x100
20 #define CP_EMMC_PHY_CTRL_REG 0x424
21 #define EMMC_PHY_CTRL_SDPHY_EN BIT(0)
23 #define AP806_EMMC_CLK_PIN_ID 0
24 #define AP806_EMMC_CLK_FUNC 0x1
25 #define CP110_EMMC_CLK_PIN_ID 56
26 #define CP110_EMMC_CLK_FUNC 0xe
28 DECLARE_GLOBAL_DATA_PTR;
30 /* mvebu_pinctl_emmc_set_mux: configure sd/mmc PHY mux
31 * To enable SDIO/eMMC in Armada-APN806/CP110, need to configure PHY mux.
32 * eMMC/SD PHY register responsible for muxing between MPPs and SD/eMMC
34 * - Bit0 enabled SDIO/eMMC PHY is used as a MPP muxltiplexer,
35 * - Bit0 disabled SDIO/eMMC PHY is connected to SDIO/eMMC controller
36 * If pin function is set to eMMC/SD, then configure the eMMC/SD PHY
37 * muxltiplexer register to be on SDIO/eMMC controller
39 void mvebu_pinctl_emmc_set_mux(struct udevice *dev, u32 pin, u32 func)
41 const void *blob = gd->fdt_blob;
42 int node = dev_of_offset(dev);
43 struct mvebu_pinctrl_priv *priv = dev_get_priv(dev);
45 if (!fdt_node_check_compatible(blob, node, "marvell,ap806-pinctrl")) {
46 if ((pin == AP806_EMMC_CLK_PIN_ID) &&
47 (func == AP806_EMMC_CLK_FUNC)) {
48 clrbits_le32(priv->base_reg + AP_EMMC_PHY_CTRL_REG,
49 EMMC_PHY_CTRL_SDPHY_EN);
51 } else if (!fdt_node_check_compatible(blob, node,
52 "marvell,armada-8k-cpm-pinctrl")) {
53 if ((pin == CP110_EMMC_CLK_PIN_ID) &&
54 (func == CP110_EMMC_CLK_FUNC)) {
55 clrbits_le32(priv->base_reg + CP_EMMC_PHY_CTRL_REG,
56 EMMC_PHY_CTRL_SDPHY_EN);
62 * mvebu_pinctrl_set_state: configure pin functions.
63 * @dev: the pinctrl device to be configured.
64 * @config: the state to be configured.
65 * @return: 0 in success
67 int mvebu_pinctrl_set_state(struct udevice *dev, struct udevice *config)
69 const void *blob = gd->fdt_blob;
70 int node = dev_of_offset(config);
71 struct mvebu_pinctrl_priv *priv;
72 u32 pin_arr[MVEBU_MAX_PINS_PER_BANK];
76 priv = dev_get_priv(dev);
78 pin_count = fdtdec_get_int_array_count(blob, node,
81 MVEBU_MAX_PINS_PER_BANK);
83 debug("Failed reading pins array for pinconfig %s (%d)\n",
84 config->name, pin_count);
88 function = fdtdec_get_int(blob, node, "marvell,function", 0xff);
91 * Check if setup of PHY mux is needed for this pins group.
92 * Only the first pin id in array is tested, all the rest use the same
95 mvebu_pinctl_emmc_set_mux(dev, pin_arr[0], function);
97 for (i = 0; i < pin_count; i++) {
100 int pin = pin_arr[i];
102 if (function > priv->max_func) {
103 debug("Illegal function %d for pinconfig %s\n",
104 function, config->name);
108 /* Calculate register address and bit in register */
109 reg_offset = priv->reg_direction * 4 *
110 (pin >> (PIN_REG_SHIFT));
111 field_offset = (BITS_PER_PIN) * (pin & PIN_FIELD_MASK);
113 clrsetbits_le32(priv->base_reg + reg_offset,
114 PIN_FUNC_MASK << field_offset,
115 (function & PIN_FUNC_MASK) << field_offset);
122 * mvebu_pinctrl_set_state_all: configure the entire bank pin functions.
123 * @dev: the pinctrl device to be configured.
124 * @config: the state to be configured.
125 * @return: 0 in success
127 static int mvebu_pinctrl_set_state_all(struct udevice *dev,
128 struct udevice *config)
130 const void *blob = gd->fdt_blob;
131 int node = dev_of_offset(config);
132 struct mvebu_pinctrl_priv *priv;
133 u32 func_arr[MVEBU_MAX_PINS_PER_BANK];
136 priv = dev_get_priv(dev);
138 err = fdtdec_get_int_array(blob, node, "pin-func",
139 func_arr, priv->pin_cnt);
141 debug("Failed reading pin functions for bank %s\n",
146 /* Check if setup of PHY mux is needed for this pins group. */
147 if (priv->pin_cnt < CP110_EMMC_CLK_PIN_ID)
148 mvebu_pinctl_emmc_set_mux(dev, AP806_EMMC_CLK_PIN_ID,
149 func_arr[AP806_EMMC_CLK_PIN_ID]);
151 mvebu_pinctl_emmc_set_mux(dev, CP110_EMMC_CLK_PIN_ID,
152 func_arr[CP110_EMMC_CLK_PIN_ID]);
154 for (pin = 0; pin < priv->pin_cnt; pin++) {
157 u32 func = func_arr[pin];
159 /* Bypass pins with function 0xFF */
161 debug("Warning: pin %d value is not modified ", pin);
162 debug("(kept as default)\n");
164 } else if (func > priv->max_func) {
165 debug("Illegal function %d for pin %d\n", func, pin);
169 /* Calculate register address and bit in register */
170 reg_offset = priv->reg_direction * 4 *
171 (pin >> (PIN_REG_SHIFT));
172 field_offset = (BITS_PER_PIN) * (pin & PIN_FIELD_MASK);
174 clrsetbits_le32(priv->base_reg + reg_offset,
175 PIN_FUNC_MASK << field_offset,
176 (func & PIN_FUNC_MASK) << field_offset);
182 int mvebu_pinctl_probe(struct udevice *dev)
184 const void *blob = gd->fdt_blob;
185 int node = dev_of_offset(dev);
186 struct mvebu_pinctrl_priv *priv;
188 priv = dev_get_priv(dev);
190 debug("%s: Failed to get private\n", __func__);
194 priv->base_reg = devfdt_get_addr_ptr(dev);
195 if (priv->base_reg == (void *)FDT_ADDR_T_NONE) {
196 debug("%s: Failed to get base address\n", __func__);
200 priv->pin_cnt = fdtdec_get_int(blob, node, "pin-count",
201 MVEBU_MAX_PINS_PER_BANK);
202 priv->max_func = fdtdec_get_int(blob, node, "max-func",
204 priv->bank_name = fdt_getprop(blob, node, "bank-name", NULL);
206 priv->reg_direction = 1;
207 if (fdtdec_get_bool(blob, node, "reverse-reg"))
208 priv->reg_direction = -1;
210 return mvebu_pinctrl_set_state_all(dev, dev);
213 static struct pinctrl_ops mvebu_pinctrl_ops = {
214 .set_state = mvebu_pinctrl_set_state
217 static const struct udevice_id mvebu_pinctrl_ids[] = {
218 { .compatible = "marvell,mvebu-pinctrl" },
219 { .compatible = "marvell,ap806-pinctrl" },
220 { .compatible = "marvell,armada-7k-pinctrl" },
221 { .compatible = "marvell,armada-8k-cpm-pinctrl" },
222 { .compatible = "marvell,armada-8k-cps-pinctrl" },
226 U_BOOT_DRIVER(pinctrl_mvebu) = {
227 .name = "mvebu_pinctrl",
228 .id = UCLASS_PINCTRL,
229 .of_match = mvebu_pinctrl_ids,
230 .priv_auto_alloc_size = sizeof(struct mvebu_pinctrl_priv),
231 .ops = &mvebu_pinctrl_ops,
232 .probe = mvebu_pinctl_probe