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. @@ -113,6 +113,13 @@ config GPIO_MAX730X
  52. comment "Memory mapped GPIO drivers:"
  53. +config GPIO_AR5312
  54. + bool "AR5312 SoC GPIO support"
  55. + default y if SOC_AR5312
  56. + depends on SOC_AR5312
  57. + help
  58. + Say yes here to enable GPIO support for Atheros AR5312/AR2312+ SoCs.
  59. +
  60. config GPIO_CLPS711X
  61. tristate "CLPS711X GPIO support"
  62. depends on ARCH_CLPS711X || COMPILE_TEST
  63. --- a/drivers/gpio/Makefile
  64. +++ b/drivers/gpio/Makefile
  65. @@ -17,6 +17,7 @@ obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
  66. obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
  67. obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o
  68. obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
  69. +obj-$(CONFIG_GPIO_AR5312) += gpio-ar5312.o
  70. obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
  71. obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
  72. obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
  73. --- /dev/null
  74. +++ b/drivers/gpio/gpio-ar5312.c
  75. @@ -0,0 +1,121 @@
  76. +/*
  77. + * This file is subject to the terms and conditions of the GNU General Public
  78. + * License. See the file "COPYING" in the main directory of this archive
  79. + * for more details.
  80. + *
  81. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  82. + * Copyright (C) 2006 FON Technology, SL.
  83. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  84. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  85. + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
  86. + */
  87. +
  88. +#include <linux/kernel.h>
  89. +#include <linux/init.h>
  90. +#include <linux/platform_device.h>
  91. +#include <linux/gpio.h>
  92. +
  93. +#define DRIVER_NAME "ar5312-gpio"
  94. +
  95. +#define AR5312_GPIO_DO 0x00 /* output register */
  96. +#define AR5312_GPIO_DI 0x04 /* intput register */
  97. +#define AR5312_GPIO_CR 0x08 /* control register */
  98. +
  99. +#define AR5312_GPIO_CR_M(x) (1 << (x)) /* mask for i/o */
  100. +#define AR5312_GPIO_CR_O(x) (0 << (x)) /* mask for output */
  101. +#define AR5312_GPIO_CR_I(x) (1 << (x)) /* mask for input */
  102. +#define AR5312_GPIO_CR_INT(x) (1 << ((x)+8)) /* mask for interrupt */
  103. +#define AR5312_GPIO_CR_UART(x) (1 << ((x)+16)) /* uart multiplex */
  104. +
  105. +#define AR5312_GPIO_NUM 8
  106. +
  107. +static void __iomem *ar5312_mem;
  108. +
  109. +static inline u32 ar5312_gpio_reg_read(unsigned reg)
  110. +{
  111. + return __raw_readl(ar5312_mem + reg);
  112. +}
  113. +
  114. +static inline void ar5312_gpio_reg_write(unsigned reg, u32 val)
  115. +{
  116. + __raw_writel(val, ar5312_mem + reg);
  117. +}
  118. +
  119. +static inline void ar5312_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
  120. +{
  121. + ar5312_gpio_reg_write(reg, (ar5312_gpio_reg_read(reg) & ~mask) | val);
  122. +}
  123. +
  124. +static int ar5312_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
  125. +{
  126. + return (ar5312_gpio_reg_read(AR5312_GPIO_DI) >> gpio) & 1;
  127. +}
  128. +
  129. +static void ar5312_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
  130. +{
  131. + u32 reg = ar5312_gpio_reg_read(AR5312_GPIO_DO);
  132. +
  133. + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
  134. + ar5312_gpio_reg_write(AR5312_GPIO_DO, reg);
  135. +}
  136. +
  137. +static int ar5312_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
  138. +{
  139. + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 0, 1 << gpio);
  140. + return 0;
  141. +}
  142. +
  143. +static int ar5312_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
  144. +{
  145. + ar5312_gpio_reg_mask(AR5312_GPIO_CR, 1 << gpio, 0);
  146. + ar5312_gpio_set_val(chip, gpio, val);
  147. + return 0;
  148. +}
  149. +
  150. +static struct gpio_chip ar5312_gpio_chip = {
  151. + .label = DRIVER_NAME,
  152. + .direction_input = ar5312_gpio_dir_in,
  153. + .direction_output = ar5312_gpio_dir_out,
  154. + .set = ar5312_gpio_set_val,
  155. + .get = ar5312_gpio_get_val,
  156. + .base = 0,
  157. + .ngpio = AR5312_GPIO_NUM,
  158. +};
  159. +
  160. +static int ar5312_gpio_probe(struct platform_device *pdev)
  161. +{
  162. + struct device *dev = &pdev->dev;
  163. + struct resource *res;
  164. + int ret;
  165. +
  166. + if (ar5312_mem)
  167. + return -EBUSY;
  168. +
  169. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  170. + ar5312_mem = devm_ioremap_resource(dev, res);
  171. + if (IS_ERR(ar5312_mem))
  172. + return PTR_ERR(ar5312_mem);
  173. +
  174. + ar5312_gpio_chip.dev = dev;
  175. + ret = gpiochip_add(&ar5312_gpio_chip);
  176. + if (ret) {
  177. + dev_err(dev, "failed to add gpiochip\n");
  178. + return ret;
  179. + }
  180. +
  181. + return 0;
  182. +}
  183. +
  184. +static struct platform_driver ar5312_gpio_driver = {
  185. + .probe = ar5312_gpio_probe,
  186. + .driver = {
  187. + .name = DRIVER_NAME,
  188. + .owner = THIS_MODULE,
  189. + }
  190. +};
  191. +
  192. +static int __init ar5312_gpio_init(void)
  193. +{
  194. + return platform_driver_register(&ar5312_gpio_driver);
  195. +}
  196. +subsys_initcall(ar5312_gpio_init);
  197. --- a/arch/mips/Kconfig
  198. +++ b/arch/mips/Kconfig
  199. @@ -107,6 +107,7 @@ config ATH25
  200. select SYS_SUPPORTS_BIG_ENDIAN
  201. select SYS_SUPPORTS_32BIT_KERNEL
  202. select SYS_HAS_EARLY_PRINTK
  203. + select ARCH_REQUIRE_GPIOLIB
  204. help
  205. Support for Atheros AR231x and Atheros AR531x based boards