108-ar2315_gpio.patch 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. --- a/arch/mips/ath25/Kconfig
  2. +++ b/arch/mips/ath25/Kconfig
  3. @@ -7,6 +7,7 @@ config SOC_AR5312
  4. config SOC_AR2315
  5. bool "Atheros AR2315+ SoC support"
  6. depends on ATH25
  7. + select GPIO_AR2315
  8. default y
  9. config PCI_AR2315
  10. --- a/arch/mips/ath25/ar2315.c
  11. +++ b/arch/mips/ath25/ar2315.c
  12. @@ -21,6 +21,8 @@
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/reboot.h>
  16. +#include <linux/delay.h>
  17. +#include <linux/gpio.h>
  18. #include <asm/bootinfo.h>
  19. #include <asm/reboot.h>
  20. #include <asm/time.h>
  21. @@ -167,11 +169,42 @@ void __init ar2315_arch_init_irq(void)
  22. ar2315_misc_irq_domain = domain;
  23. }
  24. +static struct resource ar2315_gpio_res[] = {
  25. + {
  26. + .name = "ar2315-gpio",
  27. + .flags = IORESOURCE_MEM,
  28. + .start = AR2315_RST_BASE + AR2315_GPIO,
  29. + .end = AR2315_RST_BASE + AR2315_GPIO + 0x10 - 1,
  30. + },
  31. + {
  32. + .name = "ar2315-gpio",
  33. + .flags = IORESOURCE_IRQ,
  34. + },
  35. + {
  36. + .name = "ar2315-gpio-irq-base",
  37. + .flags = IORESOURCE_IRQ,
  38. + .start = AR231X_GPIO_IRQ_BASE,
  39. + .end = AR231X_GPIO_IRQ_BASE,
  40. + }
  41. +};
  42. +
  43. +static struct platform_device ar2315_gpio = {
  44. + .id = -1,
  45. + .name = "ar2315-gpio",
  46. + .resource = ar2315_gpio_res,
  47. + .num_resources = ARRAY_SIZE(ar2315_gpio_res)
  48. +};
  49. +
  50. void __init ar2315_init_devices(void)
  51. {
  52. /* Find board configuration */
  53. ath25_find_config(AR2315_SPI_READ_BASE, AR2315_SPI_READ_SIZE);
  54. + ar2315_gpio_res[1].start = irq_create_mapping(ar2315_misc_irq_domain,
  55. + AR2315_MISC_IRQ_GPIO);
  56. + ar2315_gpio_res[1].end = ar2315_gpio_res[1].start;
  57. + platform_device_register(&ar2315_gpio);
  58. +
  59. ath25_add_wmac(0, AR2315_WLAN0_BASE, AR2315_IRQ_WLAN0);
  60. }
  61. @@ -187,8 +220,8 @@ static void ar2315_restart(char *command
  62. /* Cold reset does not work on the AR2315/6, use the GPIO reset bits
  63. * a workaround. Give it some time to attempt a gpio based hardware
  64. * reset (atheros reference design workaround) */
  65. -
  66. - /* TODO: implement the GPIO reset workaround */
  67. + gpio_request_one(AR2315_RESET_GPIO, GPIOF_OUT_INIT_LOW, "Reset");
  68. + mdelay(100);
  69. /* Some boards (e.g. Senao EOC-2610) don't implement the reset logic
  70. * workaround. Attempt to jump to the mips reset location -
  71. --- a/drivers/gpio/Kconfig
  72. +++ b/drivers/gpio/Kconfig
  73. @@ -113,6 +113,13 @@ config GPIO_MAX730X
  74. comment "Memory mapped GPIO drivers:"
  75. +config GPIO_AR2315
  76. + bool "AR2315 SoC GPIO support"
  77. + default y if SOC_AR2315
  78. + depends on SOC_AR2315
  79. + help
  80. + Say yes here to enable GPIO support for Atheros AR2315+ SoCs.
  81. +
  82. config GPIO_AR5312
  83. bool "AR5312 SoC GPIO support"
  84. default y if SOC_AR5312
  85. --- a/drivers/gpio/Makefile
  86. +++ b/drivers/gpio/Makefile
  87. @@ -17,6 +17,7 @@ obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
  88. obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
  89. obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o
  90. obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
  91. +obj-$(CONFIG_GPIO_AR2315) += gpio-ar2315.o
  92. obj-$(CONFIG_GPIO_AR5312) += gpio-ar5312.o
  93. obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
  94. obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
  95. --- /dev/null
  96. +++ b/drivers/gpio/gpio-ar2315.c
  97. @@ -0,0 +1,233 @@
  98. +/*
  99. + * This file is subject to the terms and conditions of the GNU General Public
  100. + * License. See the file "COPYING" in the main directory of this archive
  101. + * for more details.
  102. + *
  103. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  104. + * Copyright (C) 2006 FON Technology, SL.
  105. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  106. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  107. + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
  108. + */
  109. +
  110. +#include <linux/kernel.h>
  111. +#include <linux/init.h>
  112. +#include <linux/platform_device.h>
  113. +#include <linux/gpio.h>
  114. +#include <linux/irq.h>
  115. +
  116. +#define DRIVER_NAME "ar2315-gpio"
  117. +
  118. +#define AR2315_GPIO_DI 0x0000
  119. +#define AR2315_GPIO_DO 0x0008
  120. +#define AR2315_GPIO_DIR 0x0010
  121. +#define AR2315_GPIO_INT 0x0018
  122. +
  123. +#define AR2315_GPIO_DIR_M(x) (1 << (x)) /* mask for i/o */
  124. +#define AR2315_GPIO_DIR_O(x) (1 << (x)) /* output */
  125. +#define AR2315_GPIO_DIR_I(x) (0) /* input */
  126. +
  127. +#define AR2315_GPIO_INT_NUM_M 0x3F /* mask for GPIO num */
  128. +#define AR2315_GPIO_INT_TRIG(x) ((x) << 6) /* interrupt trigger */
  129. +#define AR2315_GPIO_INT_TRIG_M (0x3 << 6) /* mask for int trig */
  130. +
  131. +#define AR2315_GPIO_INT_TRIG_OFF 0 /* Triggerring off */
  132. +#define AR2315_GPIO_INT_TRIG_LOW 1 /* Low Level Triggered */
  133. +#define AR2315_GPIO_INT_TRIG_HIGH 2 /* High Level Triggered */
  134. +#define AR2315_GPIO_INT_TRIG_EDGE 3 /* Edge Triggered */
  135. +
  136. +#define AR2315_GPIO_NUM 22
  137. +
  138. +static u32 ar2315_gpio_intmask;
  139. +static u32 ar2315_gpio_intval;
  140. +static unsigned ar2315_gpio_irq_base;
  141. +static void __iomem *ar2315_mem;
  142. +
  143. +static inline u32 ar2315_gpio_reg_read(unsigned reg)
  144. +{
  145. + return __raw_readl(ar2315_mem + reg);
  146. +}
  147. +
  148. +static inline void ar2315_gpio_reg_write(unsigned reg, u32 val)
  149. +{
  150. + __raw_writel(val, ar2315_mem + reg);
  151. +}
  152. +
  153. +static inline void ar2315_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
  154. +{
  155. + ar2315_gpio_reg_write(reg, (ar2315_gpio_reg_read(reg) & ~mask) | val);
  156. +}
  157. +
  158. +static void ar2315_gpio_irq_handler(unsigned irq, struct irq_desc *desc)
  159. +{
  160. + u32 pend;
  161. + int bit = -1;
  162. +
  163. + /* only do one gpio interrupt at a time */
  164. + pend = ar2315_gpio_reg_read(AR2315_GPIO_DI);
  165. + pend ^= ar2315_gpio_intval;
  166. + pend &= ar2315_gpio_intmask;
  167. +
  168. + if (pend) {
  169. + bit = fls(pend) - 1;
  170. + pend &= ~(1 << bit);
  171. + ar2315_gpio_intval ^= (1 << bit);
  172. + }
  173. +
  174. + /* Enable interrupt with edge detection */
  175. + if ((ar2315_gpio_reg_read(AR2315_GPIO_DIR) & AR2315_GPIO_DIR_M(bit)) !=
  176. + AR2315_GPIO_DIR_I(bit))
  177. + return;
  178. +
  179. + if (bit >= 0)
  180. + generic_handle_irq(ar2315_gpio_irq_base + bit);
  181. +}
  182. +
  183. +static void ar2315_gpio_int_setup(unsigned gpio, int trig)
  184. +{
  185. + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_INT);
  186. +
  187. + reg &= ~(AR2315_GPIO_INT_NUM_M | AR2315_GPIO_INT_TRIG_M);
  188. + reg |= gpio | AR2315_GPIO_INT_TRIG(trig);
  189. + ar2315_gpio_reg_write(AR2315_GPIO_INT, reg);
  190. +}
  191. +
  192. +static void ar2315_gpio_irq_unmask(struct irq_data *d)
  193. +{
  194. + unsigned gpio = d->irq - ar2315_gpio_irq_base;
  195. + u32 dir = ar2315_gpio_reg_read(AR2315_GPIO_DIR);
  196. +
  197. + /* Enable interrupt with edge detection */
  198. + if ((dir & AR2315_GPIO_DIR_M(gpio)) != AR2315_GPIO_DIR_I(gpio))
  199. + return;
  200. +
  201. + ar2315_gpio_intmask |= (1 << gpio);
  202. + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_EDGE);
  203. +}
  204. +
  205. +static void ar2315_gpio_irq_mask(struct irq_data *d)
  206. +{
  207. + unsigned gpio = d->irq - ar2315_gpio_irq_base;
  208. +
  209. + /* Disable interrupt */
  210. + ar2315_gpio_intmask &= ~(1 << gpio);
  211. + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_OFF);
  212. +}
  213. +
  214. +static struct irq_chip ar2315_gpio_irq_chip = {
  215. + .name = DRIVER_NAME,
  216. + .irq_unmask = ar2315_gpio_irq_unmask,
  217. + .irq_mask = ar2315_gpio_irq_mask,
  218. +};
  219. +
  220. +static void ar2315_gpio_irq_init(unsigned irq)
  221. +{
  222. + unsigned i;
  223. +
  224. + ar2315_gpio_intval = ar2315_gpio_reg_read(AR2315_GPIO_DI);
  225. + for (i = 0; i < AR2315_GPIO_NUM; i++) {
  226. + unsigned _irq = ar2315_gpio_irq_base + i;
  227. +
  228. + irq_set_chip_and_handler(_irq, &ar2315_gpio_irq_chip,
  229. + handle_level_irq);
  230. + }
  231. + irq_set_chained_handler(irq, ar2315_gpio_irq_handler);
  232. +}
  233. +
  234. +static int ar2315_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
  235. +{
  236. + return (ar2315_gpio_reg_read(AR2315_GPIO_DI) >> gpio) & 1;
  237. +}
  238. +
  239. +static void ar2315_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
  240. +{
  241. + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_DO);
  242. +
  243. + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
  244. + ar2315_gpio_reg_write(AR2315_GPIO_DO, reg);
  245. +}
  246. +
  247. +static int ar2315_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
  248. +{
  249. + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 1 << gpio, 0);
  250. + return 0;
  251. +}
  252. +
  253. +static int ar2315_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
  254. +{
  255. + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 0, 1 << gpio);
  256. + ar2315_gpio_set_val(chip, gpio, val);
  257. + return 0;
  258. +}
  259. +
  260. +static int ar2315_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  261. +{
  262. + return ar2315_gpio_irq_base + gpio;
  263. +}
  264. +
  265. +static struct gpio_chip ar2315_gpio_chip = {
  266. + .label = DRIVER_NAME,
  267. + .direction_input = ar2315_gpio_dir_in,
  268. + .direction_output = ar2315_gpio_dir_out,
  269. + .set = ar2315_gpio_set_val,
  270. + .get = ar2315_gpio_get_val,
  271. + .to_irq = ar2315_gpio_to_irq,
  272. + .base = 0,
  273. + .ngpio = AR2315_GPIO_NUM,
  274. +};
  275. +
  276. +static int ar2315_gpio_probe(struct platform_device *pdev)
  277. +{
  278. + struct device *dev = &pdev->dev;
  279. + struct resource *res;
  280. + unsigned irq;
  281. + int ret;
  282. +
  283. + if (ar2315_mem)
  284. + return -EBUSY;
  285. +
  286. + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  287. + "ar2315-gpio-irq-base");
  288. + if (!res) {
  289. + dev_err(dev, "not found GPIO IRQ base\n");
  290. + return -ENXIO;
  291. + }
  292. + ar2315_gpio_irq_base = res->start;
  293. +
  294. + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, DRIVER_NAME);
  295. + if (!res) {
  296. + dev_err(dev, "not found IRQ number\n");
  297. + return -ENXIO;
  298. + }
  299. + irq = res->start;
  300. +
  301. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, DRIVER_NAME);
  302. + ar2315_mem = devm_ioremap_resource(dev, res);
  303. + if (IS_ERR(ar2315_mem))
  304. + return PTR_ERR(ar2315_mem);
  305. +
  306. + ar2315_gpio_chip.dev = dev;
  307. + ret = gpiochip_add(&ar2315_gpio_chip);
  308. + if (ret) {
  309. + dev_err(dev, "failed to add gpiochip\n");
  310. + return ret;
  311. + }
  312. +
  313. + ar2315_gpio_irq_init(irq);
  314. +
  315. + return 0;
  316. +}
  317. +
  318. +static struct platform_driver ar2315_gpio_driver = {
  319. + .probe = ar2315_gpio_probe,
  320. + .driver = {
  321. + .name = DRIVER_NAME,
  322. + .owner = THIS_MODULE,
  323. + }
  324. +};
  325. +
  326. +static int __init ar2315_gpio_init(void)
  327. +{
  328. + return platform_driver_register(&ar2315_gpio_driver);
  329. +}
  330. +subsys_initcall(ar2315_gpio_init);
  331. --- a/arch/mips/ath25/devices.h
  332. +++ b/arch/mips/ath25/devices.h
  333. @@ -3,6 +3,11 @@
  334. #include <linux/cpu.h>
  335. +#define AR231X_GPIO_IRQ_BASE 0x30
  336. +
  337. +/* GPIO number for AR2315/16 reset issue workaround */
  338. +#define AR2315_RESET_GPIO 5
  339. +
  340. #define ATH25_REG_MS(_val, _field) (((_val) & _field##_M) >> _field##_S)
  341. #define ATH25_IRQ_CPU_CLOCK (MIPS_CPU_IRQ_BASE + 7) /* C0_CAUSE: 0x8000 */
  342. --- a/arch/mips/ath25/ar2315_regs.h
  343. +++ b/arch/mips/ath25/ar2315_regs.h
  344. @@ -315,6 +315,9 @@
  345. #define AR2315_MEM_CFG_BANKADDR_BITS_M 0x00000018
  346. #define AR2315_MEM_CFG_BANKADDR_BITS_S 3
  347. +/* GPIO MMR base address */
  348. +#define AR2315_GPIO 0x0088
  349. +
  350. /*
  351. * Local Bus Interface Registers
  352. */