diff options
| -rw-r--r-- | Documentation/devicetree/bindings/gpio/spear_spics.txt | 50 | ||||
| -rw-r--r-- | arch/arm/plat-spear/Kconfig | 1 | ||||
| -rw-r--r-- | drivers/gpio/Kconfig | 7 | ||||
| -rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
| -rw-r--r-- | drivers/gpio/gpio-spear-spics.c | 217 |
5 files changed, 276 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/gpio/spear_spics.txt b/Documentation/devicetree/bindings/gpio/spear_spics.txt new file mode 100644 index 000000000000..96c37eb15075 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/spear_spics.txt | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | === ST Microelectronics SPEAr SPI CS Driver === | ||
| 2 | |||
| 3 | SPEAr platform provides a provision to control chipselects of ARM PL022 Prime | ||
| 4 | Cell spi controller through its system registers, which otherwise remains under | ||
| 5 | PL022 control. If chipselect remain under PL022 control then they would be | ||
| 6 | released as soon as transfer is over and TxFIFO becomes empty. This is not | ||
| 7 | desired by some of the device protocols above spi which expect (multiple) | ||
| 8 | transfers without releasing their chipselects. | ||
| 9 | |||
| 10 | Chipselects can be controlled by software by turning them as GPIOs. SPEAr | ||
| 11 | provides another interface through system registers through which software can | ||
| 12 | directly control each PL022 chipselect. Hence, it is natural for SPEAr to export | ||
| 13 | the control of this interface as gpio. | ||
| 14 | |||
| 15 | Required properties: | ||
| 16 | |||
| 17 | * compatible: should be defined as "st,spear-spics-gpio" | ||
| 18 | * reg: mentioning address range of spics controller | ||
| 19 | * st-spics,peripcfg-reg: peripheral configuration register offset | ||
| 20 | * st-spics,sw-enable-bit: bit offset to enable sw control | ||
| 21 | * st-spics,cs-value-bit: bit offset to drive chipselect low or high | ||
| 22 | * st-spics,cs-enable-mask: chip select number bit mask | ||
| 23 | * st-spics,cs-enable-shift: chip select number program offset | ||
| 24 | * gpio-controller: Marks the device node as gpio controller | ||
| 25 | * #gpio-cells: should be 1 and will mention chip select number | ||
| 26 | |||
| 27 | All the above bit offsets are within peripcfg register. | ||
| 28 | |||
| 29 | Example: | ||
| 30 | ------- | ||
| 31 | spics: spics@e0700000{ | ||
| 32 | compatible = "st,spear-spics-gpio"; | ||
| 33 | reg = <0xe0700000 0x1000>; | ||
| 34 | st-spics,peripcfg-reg = <0x3b0>; | ||
| 35 | st-spics,sw-enable-bit = <12>; | ||
| 36 | st-spics,cs-value-bit = <11>; | ||
| 37 | st-spics,cs-enable-mask = <3>; | ||
| 38 | st-spics,cs-enable-shift = <8>; | ||
| 39 | gpio-controller; | ||
| 40 | #gpio-cells = <2>; | ||
| 41 | }; | ||
| 42 | |||
| 43 | |||
| 44 | spi0: spi@e0100000 { | ||
| 45 | status = "okay"; | ||
| 46 | num-cs = <3>; | ||
| 47 | cs-gpios = <&gpio1 7 0>, <&spics 0>, | ||
| 48 | <&spics 1>; | ||
| 49 | ... | ||
| 50 | } | ||
diff --git a/arch/arm/plat-spear/Kconfig b/arch/arm/plat-spear/Kconfig index f8db7b2deb36..87dbd81bdf51 100644 --- a/arch/arm/plat-spear/Kconfig +++ b/arch/arm/plat-spear/Kconfig | |||
| @@ -12,6 +12,7 @@ config ARCH_SPEAR13XX | |||
| 12 | bool "ST SPEAr13xx with Device Tree" | 12 | bool "ST SPEAr13xx with Device Tree" |
| 13 | select ARM_GIC | 13 | select ARM_GIC |
| 14 | select CPU_V7 | 14 | select CPU_V7 |
| 15 | select GPIO_SPEAR_SPICS | ||
| 15 | select HAVE_SMP | 16 | select HAVE_SMP |
| 16 | select MIGHT_HAVE_CACHE_L2X0 | 17 | select MIGHT_HAVE_CACHE_L2X0 |
| 17 | select PINCTRL | 18 | select PINCTRL |
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 9e3fb3438718..4f592c615990 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
| @@ -196,6 +196,13 @@ config GPIO_PXA | |||
| 196 | help | 196 | help |
| 197 | Say yes here to support the PXA GPIO device | 197 | Say yes here to support the PXA GPIO device |
| 198 | 198 | ||
| 199 | config GPIO_SPEAR_SPICS | ||
| 200 | bool "ST SPEAr13xx SPI Chip Select as GPIO support" | ||
| 201 | depends on PLAT_SPEAR | ||
| 202 | select GENERIC_IRQ_CHIP | ||
| 203 | help | ||
| 204 | Say yes here to support ST SPEAr SPI Chip Select as GPIO device | ||
| 205 | |||
| 199 | config GPIO_STA2X11 | 206 | config GPIO_STA2X11 |
| 200 | bool "STA2x11/ConneXt GPIO support" | 207 | bool "STA2x11/ConneXt GPIO support" |
| 201 | depends on MFD_STA2X11 | 208 | depends on MFD_STA2X11 |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 1c1b63fcaeb3..a268d99f4e43 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
| @@ -59,6 +59,7 @@ obj-$(CONFIG_PLAT_SAMSUNG) += gpio-samsung.o | |||
| 59 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o | 59 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o |
| 60 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o | 60 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o |
| 61 | obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o | 61 | obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o |
| 62 | obj-$(CONFIG_GPIO_SPEAR_SPICS) += gpio-spear-spics.o | ||
| 62 | obj-$(CONFIG_GPIO_STA2X11) += gpio-sta2x11.o | 63 | obj-$(CONFIG_GPIO_STA2X11) += gpio-sta2x11.o |
| 63 | obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o | 64 | obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o |
| 64 | obj-$(CONFIG_GPIO_STP_XWAY) += gpio-stp-xway.o | 65 | obj-$(CONFIG_GPIO_STP_XWAY) += gpio-stp-xway.o |
diff --git a/drivers/gpio/gpio-spear-spics.c b/drivers/gpio/gpio-spear-spics.c new file mode 100644 index 000000000000..5f45fc4ed5d1 --- /dev/null +++ b/drivers/gpio/gpio-spear-spics.c | |||
| @@ -0,0 +1,217 @@ | |||
| 1 | /* | ||
| 2 | * SPEAr platform SPI chipselect abstraction over gpiolib | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 ST Microelectronics | ||
| 5 | * Shiraz Hashim <shiraz.hashim@st.com> | ||
| 6 | * | ||
| 7 | * This file is licensed under the terms of the GNU General Public | ||
| 8 | * License version 2. This program is licensed "as is" without any | ||
| 9 | * warranty of any kind, whether express or implied. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include <linux/err.h> | ||
| 13 | #include <linux/gpio.h> | ||
| 14 | #include <linux/io.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/of.h> | ||
| 17 | #include <linux/platform_device.h> | ||
| 18 | #include <linux/types.h> | ||
| 19 | |||
| 20 | /* maximum chipselects */ | ||
| 21 | #define NUM_OF_GPIO 4 | ||
| 22 | |||
| 23 | /* | ||
| 24 | * Provision is available on some SPEAr SoCs to control ARM PL022 spi cs | ||
| 25 | * through system registers. This register lies outside spi (pl022) | ||
| 26 | * address space into system registers. | ||
| 27 | * | ||
| 28 | * It provides control for spi chip select lines so that any chipselect | ||
| 29 | * (out of 4 possible chipselects in pl022) can be made low to select | ||
| 30 | * the particular slave. | ||
| 31 | */ | ||
| 32 | |||
| 33 | /** | ||
| 34 | * struct spear_spics - represents spi chip select control | ||
| 35 | * @base: base address | ||
| 36 | * @perip_cfg: configuration register | ||
| 37 | * @sw_enable_bit: bit to enable s/w control over chipselects | ||
| 38 | * @cs_value_bit: bit to program high or low chipselect | ||
| 39 | * @cs_enable_mask: mask to select bits required to select chipselect | ||
| 40 | * @cs_enable_shift: bit pos of cs_enable_mask | ||
| 41 | * @use_count: use count of a spi controller cs lines | ||
| 42 | * @last_off: stores last offset caller of set_value() | ||
| 43 | * @chip: gpio_chip abstraction | ||
| 44 | */ | ||
| 45 | struct spear_spics { | ||
| 46 | void __iomem *base; | ||
| 47 | u32 perip_cfg; | ||
| 48 | u32 sw_enable_bit; | ||
| 49 | u32 cs_value_bit; | ||
| 50 | u32 cs_enable_mask; | ||
| 51 | u32 cs_enable_shift; | ||
| 52 | unsigned long use_count; | ||
| 53 | int last_off; | ||
| 54 | struct gpio_chip chip; | ||
| 55 | }; | ||
| 56 | |||
| 57 | /* gpio framework specific routines */ | ||
| 58 | static int spics_get_value(struct gpio_chip *chip, unsigned offset) | ||
| 59 | { | ||
| 60 | return -ENXIO; | ||
| 61 | } | ||
| 62 | |||
| 63 | static void spics_set_value(struct gpio_chip *chip, unsigned offset, int value) | ||
| 64 | { | ||
| 65 | struct spear_spics *spics = container_of(chip, struct spear_spics, | ||
| 66 | chip); | ||
| 67 | u32 tmp; | ||
| 68 | |||
| 69 | /* select chip select from register */ | ||
| 70 | tmp = readl_relaxed(spics->base + spics->perip_cfg); | ||
| 71 | if (spics->last_off != offset) { | ||
| 72 | spics->last_off = offset; | ||
| 73 | tmp &= ~(spics->cs_enable_mask << spics->cs_enable_shift); | ||
| 74 | tmp |= offset << spics->cs_enable_shift; | ||
| 75 | } | ||
| 76 | |||
| 77 | /* toggle chip select line */ | ||
| 78 | tmp &= ~(0x1 << spics->cs_value_bit); | ||
| 79 | tmp |= value << spics->cs_value_bit; | ||
| 80 | writel_relaxed(tmp, spics->base + spics->perip_cfg); | ||
| 81 | } | ||
| 82 | |||
| 83 | static int spics_direction_input(struct gpio_chip *chip, unsigned offset) | ||
| 84 | { | ||
| 85 | return -ENXIO; | ||
| 86 | } | ||
| 87 | |||
| 88 | static int spics_direction_output(struct gpio_chip *chip, unsigned offset, | ||
| 89 | int value) | ||
| 90 | { | ||
| 91 | spics_set_value(chip, offset, value); | ||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | static int spics_request(struct gpio_chip *chip, unsigned offset) | ||
| 96 | { | ||
| 97 | struct spear_spics *spics = container_of(chip, struct spear_spics, | ||
| 98 | chip); | ||
| 99 | u32 tmp; | ||
| 100 | |||
| 101 | if (!spics->use_count++) { | ||
| 102 | tmp = readl_relaxed(spics->base + spics->perip_cfg); | ||
| 103 | tmp |= 0x1 << spics->sw_enable_bit; | ||
| 104 | tmp |= 0x1 << spics->cs_value_bit; | ||
| 105 | writel_relaxed(tmp, spics->base + spics->perip_cfg); | ||
| 106 | } | ||
| 107 | |||
| 108 | return 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | static void spics_free(struct gpio_chip *chip, unsigned offset) | ||
| 112 | { | ||
| 113 | struct spear_spics *spics = container_of(chip, struct spear_spics, | ||
| 114 | chip); | ||
| 115 | u32 tmp; | ||
| 116 | |||
| 117 | if (!--spics->use_count) { | ||
| 118 | tmp = readl_relaxed(spics->base + spics->perip_cfg); | ||
| 119 | tmp &= ~(0x1 << spics->sw_enable_bit); | ||
| 120 | writel_relaxed(tmp, spics->base + spics->perip_cfg); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | static int spics_gpio_probe(struct platform_device *pdev) | ||
| 125 | { | ||
| 126 | struct device_node *np = pdev->dev.of_node; | ||
| 127 | struct spear_spics *spics; | ||
| 128 | struct resource *res; | ||
| 129 | int ret; | ||
| 130 | |||
| 131 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 132 | if (!res) { | ||
| 133 | dev_err(&pdev->dev, "invalid IORESOURCE_MEM\n"); | ||
| 134 | return -EBUSY; | ||
| 135 | } | ||
| 136 | |||
| 137 | spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); | ||
| 138 | if (!spics) { | ||
| 139 | dev_err(&pdev->dev, "memory allocation fail\n"); | ||
| 140 | return -ENOMEM; | ||
| 141 | } | ||
| 142 | |||
| 143 | spics->base = devm_request_and_ioremap(&pdev->dev, res); | ||
| 144 | if (!spics->base) { | ||
| 145 | dev_err(&pdev->dev, "request and ioremap fail\n"); | ||
| 146 | return -ENOMEM; | ||
| 147 | } | ||
| 148 | |||
| 149 | if (of_property_read_u32(np, "st-spics,peripcfg-reg", | ||
| 150 | &spics->perip_cfg)) | ||
| 151 | goto err_dt_data; | ||
| 152 | if (of_property_read_u32(np, "st-spics,sw-enable-bit", | ||
| 153 | &spics->sw_enable_bit)) | ||
| 154 | goto err_dt_data; | ||
| 155 | if (of_property_read_u32(np, "st-spics,cs-value-bit", | ||
| 156 | &spics->cs_value_bit)) | ||
| 157 | goto err_dt_data; | ||
| 158 | if (of_property_read_u32(np, "st-spics,cs-enable-mask", | ||
| 159 | &spics->cs_enable_mask)) | ||
| 160 | goto err_dt_data; | ||
| 161 | if (of_property_read_u32(np, "st-spics,cs-enable-shift", | ||
| 162 | &spics->cs_enable_shift)) | ||
| 163 | goto err_dt_data; | ||
| 164 | |||
| 165 | platform_set_drvdata(pdev, spics); | ||
| 166 | |||
| 167 | spics->chip.ngpio = NUM_OF_GPIO; | ||
| 168 | spics->chip.base = -1; | ||
| 169 | spics->chip.request = spics_request; | ||
| 170 | spics->chip.free = spics_free; | ||
| 171 | spics->chip.direction_input = spics_direction_input; | ||
| 172 | spics->chip.direction_output = spics_direction_output; | ||
| 173 | spics->chip.get = spics_get_value; | ||
| 174 | spics->chip.set = spics_set_value; | ||
| 175 | spics->chip.label = dev_name(&pdev->dev); | ||
| 176 | spics->chip.dev = &pdev->dev; | ||
| 177 | spics->chip.owner = THIS_MODULE; | ||
| 178 | spics->last_off = -1; | ||
| 179 | |||
| 180 | ret = gpiochip_add(&spics->chip); | ||
| 181 | if (ret) { | ||
| 182 | dev_err(&pdev->dev, "unable to add gpio chip\n"); | ||
| 183 | return ret; | ||
| 184 | } | ||
| 185 | |||
| 186 | dev_info(&pdev->dev, "spear spics registered\n"); | ||
| 187 | return 0; | ||
| 188 | |||
| 189 | err_dt_data: | ||
| 190 | dev_err(&pdev->dev, "DT probe failed\n"); | ||
| 191 | return -EINVAL; | ||
| 192 | } | ||
| 193 | |||
| 194 | static const struct of_device_id spics_gpio_of_match[] = { | ||
| 195 | { .compatible = "st,spear-spics-gpio" }, | ||
| 196 | {} | ||
| 197 | }; | ||
| 198 | MODULE_DEVICE_TABLE(of, spics_gpio_of_match); | ||
| 199 | |||
| 200 | static struct platform_driver spics_gpio_driver = { | ||
| 201 | .probe = spics_gpio_probe, | ||
| 202 | .driver = { | ||
| 203 | .owner = THIS_MODULE, | ||
| 204 | .name = "spear-spics-gpio", | ||
| 205 | .of_match_table = spics_gpio_of_match, | ||
| 206 | }, | ||
| 207 | }; | ||
| 208 | |||
| 209 | static int __init spics_gpio_init(void) | ||
| 210 | { | ||
| 211 | return platform_driver_register(&spics_gpio_driver); | ||
| 212 | } | ||
| 213 | subsys_initcall(spics_gpio_init); | ||
| 214 | |||
| 215 | MODULE_AUTHOR("Shiraz Hashim <shiraz.hashim@st.com>"); | ||
| 216 | MODULE_DESCRIPTION("ST Microlectronics SPEAr SPI Chip Select Abstraction"); | ||
| 217 | MODULE_LICENSE("GPL"); | ||
