2 * Copyright (C) 2015-2016 Wills Wang <wills.wang@live.com>
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <dm/pinctrl.h>
12 #include <mach/ar71xx_regs.h>
14 DECLARE_GLOBAL_DATA_PTR;
22 struct ar933x_pinctrl_priv {
26 static void pinctrl_ar933x_spi_config(struct ar933x_pinctrl_priv *priv, int cs)
30 clrsetbits_be32(priv->regs + AR71XX_GPIO_REG_OE,
31 AR933X_GPIO(4), AR933X_GPIO(3) |
32 AR933X_GPIO(5) | AR933X_GPIO(2));
33 setbits_be32(priv->regs + AR71XX_GPIO_REG_FUNC,
34 AR933X_GPIO_FUNC_SPI_EN |
35 AR933X_GPIO_FUNC_RES_TRUE);
40 static void pinctrl_ar933x_uart_config(struct ar933x_pinctrl_priv *priv, int uart_id)
44 clrsetbits_be32(priv->regs + AR71XX_GPIO_REG_OE,
45 AR933X_GPIO(9), AR933X_GPIO(10));
46 setbits_be32(priv->regs + AR71XX_GPIO_REG_FUNC,
47 AR933X_GPIO_FUNC_UART_EN |
48 AR933X_GPIO_FUNC_RES_TRUE);
53 static int ar933x_pinctrl_request(struct udevice *dev, int func, int flags)
55 struct ar933x_pinctrl_priv *priv = dev_get_priv(dev);
57 debug("%s: func=%x, flags=%x\n", __func__, func, flags);
60 pinctrl_ar933x_spi_config(priv, flags);
63 pinctrl_ar933x_uart_config(priv, func);
72 static int ar933x_pinctrl_get_periph_id(struct udevice *dev,
73 struct udevice *periph)
78 ret = fdtdec_get_int_array(gd->fdt_blob, periph->of_offset,
79 "interrupts", cell, ARRAY_SIZE(cell));
85 return PERIPH_ID_UART0;
87 return PERIPH_ID_SPI0;
92 static int ar933x_pinctrl_set_state_simple(struct udevice *dev,
93 struct udevice *periph)
97 func = ar933x_pinctrl_get_periph_id(dev, periph);
100 return ar933x_pinctrl_request(dev, func, 0);
103 static struct pinctrl_ops ar933x_pinctrl_ops = {
104 .set_state_simple = ar933x_pinctrl_set_state_simple,
105 .request = ar933x_pinctrl_request,
106 .get_periph_id = ar933x_pinctrl_get_periph_id,
109 static int ar933x_pinctrl_probe(struct udevice *dev)
111 struct ar933x_pinctrl_priv *priv = dev_get_priv(dev);
114 addr = dev_get_addr(dev);
115 if (addr == FDT_ADDR_T_NONE)
118 priv->regs = map_physmem(addr,
124 static const struct udevice_id ar933x_pinctrl_ids[] = {
125 { .compatible = "qca,ar933x-pinctrl" },
129 U_BOOT_DRIVER(pinctrl_ar933x) = {
130 .name = "pinctrl_ar933x",
131 .id = UCLASS_PINCTRL,
132 .of_match = ar933x_pinctrl_ids,
133 .priv_auto_alloc_size = sizeof(struct ar933x_pinctrl_priv),
134 .ops = &ar933x_pinctrl_ops,
135 .probe = ar933x_pinctrl_probe,