107-ar5312_gpio.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. --- a/arch/mips/ath25/Kconfig
  2. +++ b/arch/mips/ath25/Kconfig
  3. @@ -1,6 +1,7 @@
  4. config SOC_AR5312
  5. bool "Atheros AR5312/AR2312+ SoC support"
  6. depends on ATH25
  7. + select GPIO_AR5312
  8. default y
  9. config SOC_AR2315
  10. --- a/arch/mips/ath25/ar5312.c
  11. +++ b/arch/mips/ath25/ar5312.c
  12. @@ -22,6 +22,7 @@
  13. #include <linux/platform_device.h>
  14. #include <linux/mtd/physmap.h>
  15. #include <linux/reboot.h>
  16. +#include <linux/gpio.h>
  17. #include <asm/bootinfo.h>
  18. #include <asm/reboot.h>
  19. #include <asm/time.h>
  20. @@ -180,6 +181,22 @@ static struct platform_device ar5312_phy
  21. .num_resources = 1,
  22. };
  23. +static struct resource ar5312_gpio_res[] = {
  24. + {
  25. + .name = "ar5312-gpio",
  26. + .flags = IORESOURCE_MEM,
  27. + .start = AR5312_GPIO_BASE,
  28. + .end = AR5312_GPIO_BASE + AR5312_GPIO_SIZE - 1,
  29. + },
  30. +};
  31. +
  32. +static struct platform_device ar5312_gpio = {
  33. + .name = "ar5312-gpio",
  34. + .id = -1,
  35. + .resource = ar5312_gpio_res,
  36. + .num_resources = ARRAY_SIZE(ar5312_gpio_res),
  37. +};
  38. +
  39. static void __init ar5312_flash_init(void)
  40. {
  41. void __iomem *flashctl_base;
  42. @@ -247,6 +264,8 @@ void __init ar5312_init_devices(void)
  43. platform_device_register(&ar5312_physmap_flash);
  44. + platform_device_register(&ar5312_gpio);
  45. +
  46. switch (ath25_soc) {
  47. case ATH25_SOC_AR5312:
  48. if (!ath25_board.radio)
  49. --- a/drivers/gpio/Kconfig
  50. +++ b/drivers/gpio/Kconfig
  51. @@ -141,6 +141,13 @@ config GPIO_BRCMSTB
  52. help
  53. Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs.
  54. +config GPIO_AR5312
  55. + bool "AR5312 SoC GPIO support"
  56. + default y if SOC_AR5312
  57. + depends on SOC_AR5312
  58. + help
  59. + Say yes here to enable GPIO support for Atheros AR5312/AR2312+ SoCs.
  60. +
  61. config GPIO_CLPS711X
  62. tristate "CLPS711X GPIO support"
  63. depends on ARCH_CLPS711X || COMPILE_TEST
  64. --- a/drivers/gpio/Makefile
  65. +++ b/drivers/gpio/Makefile
  66. @@ -21,6 +21,7 @@ obj-$(CONFIG_GPIO_ADP5588) += gpio-adp55
  67. obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o
  68. obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
  69. obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o
  70. +obj-$(CONFIG_GPIO_AR5312) += gpio-ar5312.o
  71. obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
  72. obj-$(CONFIG_ATH79) += gpio-ath79.o
  73. obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
  74. --- /dev/null
  75. +++ b/drivers/gpio/gpio-ar5312.c
  76. @@ -0,0 +1,121 @@
  77. +/*
  78. + * This file is subject to the terms and conditions of the GNU General Public
  79. + * License. See the file "COPYING" in the main directory of this archive
  80. + * for more details.
  81. + *
  82. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  83. + * Copyright (C) 2006 FON Technology, SL.
  84. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  85. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@nbd.name>
  86. + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
  87. + */
  88. +
  89. +#include <linux/kernel.h>
  90. +#include <linux/init.h>
  91. +#include <linux/platform_device.h>
  92. +#include <linux/gpio.h>
  93. +
  94. +#define DRIVER_NAME "ar5312-gpio"
  95. +
  96. +#define AR5312_GPIO_DO 0x00 /* output register */
  97. +#define AR5312_GPIO_DI 0x04 /* intput register */
  98. +#define AR5312_GPIO_CR 0x08 /* control register */
  99. +
  100. +#define AR5312_GPIO_CR_M(x) (1 << (x)) /* mask for i/o */
  101. +#define AR5312_GPIO_CR_O(x) (0 << (x)) /* mask for output */
  102. +#define AR5312_GPIO_CR_I(x) (1 << (x)) /* mask for input */
  103. +#define AR5312_GPIO_CR_INT(x) (1 << ((x)+8)) /* mask for interrupt */
  104. +#define AR5312_GPIO_CR_UART(x) (1 << ((x)+16)) /* uart multiplex */
  105. +
  106. +#define AR5312_GPIO_NUM 8
  107. +
  108. +static void __iomem *ar5312_mem;
  109. +
  110. +static inline u32 ar5312_gpio_reg_read(unsigned reg)
  111. +{
  112. + return __raw_readl(ar5312_mem + reg);
  113. +}
  114. +
  115. +static inline void ar5312_gpio_reg_write(unsigned reg, u32 val)
  116. +{
  117. + __raw_writel(val, ar5312_mem + reg);
  118. +}
  119. +
  120. +static inline void ar5312_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
  121. +{
  122. + ar5312_gpio_reg_write(reg, (ar5312_gpio_reg_read(reg) & ~mask) | val);
  123. +}
  124. +
  125. +static int ar5312_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
  126. +{
  127. + return (ar5312_gpio_reg_read(AR5312_GPIO_DI) >> gpio) & 1;
  128. +}
  129. +
  130. +static void ar5312_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
  131. +{
  132. + u32 reg = ar5312_gpio_reg_read(AR5312_GPIO_DO);
  133. +
  134. + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
  135. + ar5312_gpio_reg_write(AR5312_GPIO_DO, reg);
  136. +}
  137. +
  138. +static int ar5312_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
  139. +{
  140. + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 0, 1 << gpio);
  141. + return 0;
  142. +}
  143. +
  144. +static int ar5312_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
  145. +{
  146. + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 1 << gpio, 0);
  147. + ar5312_gpio_set_val(chip, gpio, val);
  148. + return 0;
  149. +}
  150. +
  151. +static struct gpio_chip ar5312_gpio_chip = {
  152. + .label = DRIVER_NAME,
  153. + .direction_input = ar5312_gpio_dir_in,
  154. + .direction_output = ar5312_gpio_dir_out,
  155. + .set = ar5312_gpio_set_val,
  156. + .get = ar5312_gpio_get_val,
  157. + .base = 0,
  158. + .ngpio = AR5312_GPIO_NUM,
  159. +};
  160. +
  161. +static int ar5312_gpio_probe(struct platform_device *pdev)
  162. +{
  163. + struct device *dev = &pdev->dev;
  164. + struct resource *res;
  165. + int ret;
  166. +
  167. + if (ar5312_mem)
  168. + return -EBUSY;
  169. +
  170. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  171. + ar5312_mem = devm_ioremap_resource(dev, res);
  172. + if (IS_ERR(ar5312_mem))
  173. + return PTR_ERR(ar5312_mem);
  174. +
  175. + ar5312_gpio_chip.dev = dev;
  176. + ret = gpiochip_add(&ar5312_gpio_chip);
  177. + if (ret) {
  178. + dev_err(dev, "failed to add gpiochip\n");
  179. + return ret;
  180. + }
  181. +
  182. + return 0;
  183. +}
  184. +
  185. +static struct platform_driver ar5312_gpio_driver = {
  186. + .probe = ar5312_gpio_probe,
  187. + .driver = {
  188. + .name = DRIVER_NAME,
  189. + .owner = THIS_MODULE,
  190. + }
  191. +};
  192. +
  193. +static int __init ar5312_gpio_init(void)
  194. +{
  195. + return platform_driver_register(&ar5312_gpio_driver);
  196. +}
  197. +subsys_initcall(ar5312_gpio_init);
  198. --- a/arch/mips/Kconfig
  199. +++ b/arch/mips/Kconfig
  200. @@ -117,6 +117,7 @@ config ATH25
  201. select SYS_SUPPORTS_BIG_ENDIAN
  202. select SYS_SUPPORTS_32BIT_KERNEL
  203. select SYS_HAS_EARLY_PRINTK
  204. + select ARCH_REQUIRE_GPIOLIB
  205. help
  206. Support for Atheros AR231x and Atheros AR531x based boards