1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015-2016 Wills Wang <wills.wang@live.com>
10 #include <dm/pinctrl.h>
11 #include <mach/ar71xx_regs.h>
13 DECLARE_GLOBAL_DATA_PTR;
21 struct ar933x_pinctrl_priv {
25 static void pinctrl_ar933x_spi_config(struct ar933x_pinctrl_priv *priv, int cs)
29 clrsetbits_be32(priv->regs + AR71XX_GPIO_REG_OE,
30 AR933X_GPIO(4), AR933X_GPIO(3) |
31 AR933X_GPIO(5) | AR933X_GPIO(2));
32 setbits_be32(priv->regs + AR71XX_GPIO_REG_FUNC,
33 AR933X_GPIO_FUNC_SPI_EN |
34 AR933X_GPIO_FUNC_RES_TRUE);
39 static void pinctrl_ar933x_uart_config(struct ar933x_pinctrl_priv *priv, int uart_id)
43 clrsetbits_be32(priv->regs + AR71XX_GPIO_REG_OE,
44 AR933X_GPIO(9), AR933X_GPIO(10));
45 setbits_be32(priv->regs + AR71XX_GPIO_REG_FUNC,
46 AR933X_GPIO_FUNC_UART_EN |
47 AR933X_GPIO_FUNC_RES_TRUE);
52 static int ar933x_pinctrl_request(struct udevice *dev, int func, int flags)
54 struct ar933x_pinctrl_priv *priv = dev_get_priv(dev);
56 debug("%s: func=%x, flags=%x\n", __func__, func, flags);
59 pinctrl_ar933x_spi_config(priv, flags);
62 pinctrl_ar933x_uart_config(priv, func);
71 static int ar933x_pinctrl_get_periph_id(struct udevice *dev,
72 struct udevice *periph)
77 ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(periph),
78 "interrupts", cell, ARRAY_SIZE(cell));
84 return PERIPH_ID_UART0;
86 return PERIPH_ID_SPI0;
91 static int ar933x_pinctrl_set_state_simple(struct udevice *dev,
92 struct udevice *periph)
96 func = ar933x_pinctrl_get_periph_id(dev, periph);
99 return ar933x_pinctrl_request(dev, func, 0);
102 static struct pinctrl_ops ar933x_pinctrl_ops = {
103 .set_state_simple = ar933x_pinctrl_set_state_simple,
104 .request = ar933x_pinctrl_request,
105 .get_periph_id = ar933x_pinctrl_get_periph_id,
108 static int ar933x_pinctrl_probe(struct udevice *dev)
110 struct ar933x_pinctrl_priv *priv = dev_get_priv(dev);
113 addr = devfdt_get_addr(dev);
114 if (addr == FDT_ADDR_T_NONE)
117 priv->regs = map_physmem(addr,
123 static const struct udevice_id ar933x_pinctrl_ids[] = {
124 { .compatible = "qca,ar933x-pinctrl" },
128 U_BOOT_DRIVER(pinctrl_ar933x) = {
129 .name = "pinctrl_ar933x",
130 .id = UCLASS_PINCTRL,
131 .of_match = ar933x_pinctrl_ids,
132 .priv_auto_alloc_size = sizeof(struct ar933x_pinctrl_priv),
133 .ops = &ar933x_pinctrl_ops,
134 .probe = ar933x_pinctrl_probe,