1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Microsemi SoCs pinctrl driver
6 * License: Dual MIT/GPL
7 * Copyright (c) 2018 Microsemi Corporation
11 #include <asm-generic/gpio.h>
26 static const int pinmap[] = { 0, 5, 6, 7, 8, 10, 12 };
28 #define SW_SPI_CSn_OE 0x1E /* bits 1 to 4 */
29 #define SW_SPI_CS0_OE BIT(1)
30 #define SW_SPI_SDO_OE BIT(9)
31 #define SW_SPI_SCK_OE BIT(11)
32 #define SW_PIN_CTRL_MODE BIT(13)
34 struct mscc_bb_spi_gpio {
39 static int mscc_bb_spi_gpio_set(struct udevice *dev, unsigned oft, int val)
41 struct mscc_bb_spi_gpio *gpio = dev_get_priv(dev);
44 gpio->cache_val |= BIT(pinmap[oft]);
46 gpio->cache_val &= ~BIT(pinmap[oft]);
48 writel(gpio->cache_val, gpio->regs);
53 static int mscc_bb_spi_gpio_direction_output(struct udevice *dev, unsigned oft,
57 pr_err("SW_SPI_DSI can't be used as output\n");
61 mscc_bb_spi_gpio_set(dev, oft, val);
66 static int mscc_bb_spi_gpio_direction_input(struct udevice *dev, unsigned oft)
71 static int mscc_bb_spi_gpio_get(struct udevice *dev, unsigned int oft)
73 struct mscc_bb_spi_gpio *gpio = dev_get_priv(dev);
74 u32 val = readl(gpio->regs);
76 return !!(val & BIT(pinmap[oft]));
79 static const struct dm_gpio_ops mscc_bb_spi_gpio_ops = {
80 .direction_output = mscc_bb_spi_gpio_direction_output,
81 .direction_input = mscc_bb_spi_gpio_direction_input,
82 .set_value = mscc_bb_spi_gpio_set,
83 .get_value = mscc_bb_spi_gpio_get,
86 static int mscc_bb_spi_gpio_probe(struct udevice *dev)
88 struct mscc_bb_spi_gpio *gpio = dev_get_priv(dev);
89 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
91 gpio->regs = dev_remap_addr(dev);
95 uc_priv->bank_name = dev->name;
96 uc_priv->gpio_count = ARRAY_SIZE(pinmap);
98 * Enable software mode to control the SPI pin, enables the
99 * output mode for most of the pin and initialize the cache
100 * value in the same time
103 gpio->cache_val = SW_PIN_CTRL_MODE | SW_SPI_SCK_OE | SW_SPI_SDO_OE |
105 writel(gpio->cache_val, gpio->regs);
110 static const struct udevice_id mscc_bb_spi_gpio_ids[] = {
111 {.compatible = "mscc,spi-bitbang-gpio"},
115 U_BOOT_DRIVER(gpio_mscc_bb_spi) = {
116 .name = "gpio-mscc-spi-bitbang",
118 .ops = &mscc_bb_spi_gpio_ops,
119 .probe = mscc_bb_spi_gpio_probe,
120 .of_match = of_match_ptr(mscc_bb_spi_gpio_ids),
121 .priv_auto_alloc_size = sizeof(struct mscc_bb_spi_gpio),