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. @@ -141,6 +141,13 @@ config GPIO_BRCMSTB
  74. help
  75. Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs.
  76. +config GPIO_AR2315
  77. + bool "AR2315 SoC GPIO support"
  78. + default y if SOC_AR2315
  79. + depends on SOC_AR2315
  80. + help
  81. + Say yes here to enable GPIO support for Atheros AR2315+ SoCs.
  82. +
  83. config GPIO_AR5312
  84. bool "AR5312 SoC GPIO support"
  85. default y if SOC_AR5312
  86. --- a/drivers/gpio/Makefile
  87. +++ b/drivers/gpio/Makefile
  88. @@ -21,6 +21,7 @@ obj-$(CONFIG_GPIO_ADP5588) += gpio-adp55
  89. obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o
  90. obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
  91. obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o
  92. +obj-$(CONFIG_GPIO_AR2315) += gpio-ar2315.o
  93. obj-$(CONFIG_GPIO_AR5312) += gpio-ar5312.o
  94. obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
  95. obj-$(CONFIG_ATH79) += gpio-ath79.o
  96. --- /dev/null
  97. +++ b/drivers/gpio/gpio-ar2315.c
  98. @@ -0,0 +1,233 @@
  99. +/*
  100. + * This file is subject to the terms and conditions of the GNU General Public
  101. + * License. See the file "COPYING" in the main directory of this archive
  102. + * for more details.
  103. + *
  104. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  105. + * Copyright (C) 2006 FON Technology, SL.
  106. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  107. + * Copyright (C) 2006 Felix Fietkau <nbd@nbd.name>
  108. + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
  109. + */
  110. +
  111. +#include <linux/kernel.h>
  112. +#include <linux/init.h>
  113. +#include <linux/platform_device.h>
  114. +#include <linux/gpio.h>
  115. +#include <linux/irq.h>
  116. +
  117. +#define DRIVER_NAME "ar2315-gpio"
  118. +
  119. +#define AR2315_GPIO_DI 0x0000
  120. +#define AR2315_GPIO_DO 0x0008
  121. +#define AR2315_GPIO_DIR 0x0010
  122. +#define AR2315_GPIO_INT 0x0018
  123. +
  124. +#define AR2315_GPIO_DIR_M(x) (1 << (x)) /* mask for i/o */
  125. +#define AR2315_GPIO_DIR_O(x) (1 << (x)) /* output */
  126. +#define AR2315_GPIO_DIR_I(x) (0) /* input */
  127. +
  128. +#define AR2315_GPIO_INT_NUM_M 0x3F /* mask for GPIO num */
  129. +#define AR2315_GPIO_INT_TRIG(x) ((x) << 6) /* interrupt trigger */
  130. +#define AR2315_GPIO_INT_TRIG_M (0x3 << 6) /* mask for int trig */
  131. +
  132. +#define AR2315_GPIO_INT_TRIG_OFF 0 /* Triggerring off */
  133. +#define AR2315_GPIO_INT_TRIG_LOW 1 /* Low Level Triggered */
  134. +#define AR2315_GPIO_INT_TRIG_HIGH 2 /* High Level Triggered */
  135. +#define AR2315_GPIO_INT_TRIG_EDGE 3 /* Edge Triggered */
  136. +
  137. +#define AR2315_GPIO_NUM 22
  138. +
  139. +static u32 ar2315_gpio_intmask;
  140. +static u32 ar2315_gpio_intval;
  141. +static unsigned ar2315_gpio_irq_base;
  142. +static void __iomem *ar2315_mem;
  143. +
  144. +static inline u32 ar2315_gpio_reg_read(unsigned reg)
  145. +{
  146. + return __raw_readl(ar2315_mem + reg);
  147. +}
  148. +
  149. +static inline void ar2315_gpio_reg_write(unsigned reg, u32 val)
  150. +{
  151. + __raw_writel(val, ar2315_mem + reg);
  152. +}
  153. +
  154. +static inline void ar2315_gpio_reg_mask(unsigned reg, u32 mask, u32 val)
  155. +{
  156. + ar2315_gpio_reg_write(reg, (ar2315_gpio_reg_read(reg) & ~mask) | val);
  157. +}
  158. +
  159. +static void ar2315_gpio_irq_handler(struct irq_desc *desc)
  160. +{
  161. + u32 pend;
  162. + int bit = -1;
  163. +
  164. + /* only do one gpio interrupt at a time */
  165. + pend = ar2315_gpio_reg_read(AR2315_GPIO_DI);
  166. + pend ^= ar2315_gpio_intval;
  167. + pend &= ar2315_gpio_intmask;
  168. +
  169. + if (pend) {
  170. + bit = fls(pend) - 1;
  171. + pend &= ~(1 << bit);
  172. + ar2315_gpio_intval ^= (1 << bit);
  173. + }
  174. +
  175. + /* Enable interrupt with edge detection */
  176. + if ((ar2315_gpio_reg_read(AR2315_GPIO_DIR) & AR2315_GPIO_DIR_M(bit)) !=
  177. + AR2315_GPIO_DIR_I(bit))
  178. + return;
  179. +
  180. + if (bit >= 0)
  181. + generic_handle_irq(ar2315_gpio_irq_base + bit);
  182. +}
  183. +
  184. +static void ar2315_gpio_int_setup(unsigned gpio, int trig)
  185. +{
  186. + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_INT);
  187. +
  188. + reg &= ~(AR2315_GPIO_INT_NUM_M | AR2315_GPIO_INT_TRIG_M);
  189. + reg |= gpio | AR2315_GPIO_INT_TRIG(trig);
  190. + ar2315_gpio_reg_write(AR2315_GPIO_INT, reg);
  191. +}
  192. +
  193. +static void ar2315_gpio_irq_unmask(struct irq_data *d)
  194. +{
  195. + unsigned gpio = d->irq - ar2315_gpio_irq_base;
  196. + u32 dir = ar2315_gpio_reg_read(AR2315_GPIO_DIR);
  197. +
  198. + /* Enable interrupt with edge detection */
  199. + if ((dir & AR2315_GPIO_DIR_M(gpio)) != AR2315_GPIO_DIR_I(gpio))
  200. + return;
  201. +
  202. + ar2315_gpio_intmask |= (1 << gpio);
  203. + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_EDGE);
  204. +}
  205. +
  206. +static void ar2315_gpio_irq_mask(struct irq_data *d)
  207. +{
  208. + unsigned gpio = d->irq - ar2315_gpio_irq_base;
  209. +
  210. + /* Disable interrupt */
  211. + ar2315_gpio_intmask &= ~(1 << gpio);
  212. + ar2315_gpio_int_setup(gpio, AR2315_GPIO_INT_TRIG_OFF);
  213. +}
  214. +
  215. +static struct irq_chip ar2315_gpio_irq_chip = {
  216. + .name = DRIVER_NAME,
  217. + .irq_unmask = ar2315_gpio_irq_unmask,
  218. + .irq_mask = ar2315_gpio_irq_mask,
  219. +};
  220. +
  221. +static void ar2315_gpio_irq_init(unsigned irq)
  222. +{
  223. + unsigned i;
  224. +
  225. + ar2315_gpio_intval = ar2315_gpio_reg_read(AR2315_GPIO_DI);
  226. + for (i = 0; i < AR2315_GPIO_NUM; i++) {
  227. + unsigned _irq = ar2315_gpio_irq_base + i;
  228. +
  229. + irq_set_chip_and_handler(_irq, &ar2315_gpio_irq_chip,
  230. + handle_level_irq);
  231. + }
  232. + irq_set_chained_handler(irq, ar2315_gpio_irq_handler);
  233. +}
  234. +
  235. +static int ar2315_gpio_get_val(struct gpio_chip *chip, unsigned gpio)
  236. +{
  237. + return (ar2315_gpio_reg_read(AR2315_GPIO_DI) >> gpio) & 1;
  238. +}
  239. +
  240. +static void ar2315_gpio_set_val(struct gpio_chip *chip, unsigned gpio, int val)
  241. +{
  242. + u32 reg = ar2315_gpio_reg_read(AR2315_GPIO_DO);
  243. +
  244. + reg = val ? reg | (1 << gpio) : reg & ~(1 << gpio);
  245. + ar2315_gpio_reg_write(AR2315_GPIO_DO, reg);
  246. +}
  247. +
  248. +static int ar2315_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
  249. +{
  250. + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 1 << gpio, 0);
  251. + return 0;
  252. +}
  253. +
  254. +static int ar2315_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, int val)
  255. +{
  256. + ar2315_gpio_reg_mask(AR2315_GPIO_DIR, 0, 1 << gpio);
  257. + ar2315_gpio_set_val(chip, gpio, val);
  258. + return 0;
  259. +}
  260. +
  261. +static int ar2315_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  262. +{
  263. + return ar2315_gpio_irq_base + gpio;
  264. +}
  265. +
  266. +static struct gpio_chip ar2315_gpio_chip = {
  267. + .label = DRIVER_NAME,
  268. + .direction_input = ar2315_gpio_dir_in,
  269. + .direction_output = ar2315_gpio_dir_out,
  270. + .set = ar2315_gpio_set_val,
  271. + .get = ar2315_gpio_get_val,
  272. + .to_irq = ar2315_gpio_to_irq,
  273. + .base = 0,
  274. + .ngpio = AR2315_GPIO_NUM,
  275. +};
  276. +
  277. +static int ar2315_gpio_probe(struct platform_device *pdev)
  278. +{
  279. + struct device *dev = &pdev->dev;
  280. + struct resource *res;
  281. + unsigned irq;
  282. + int ret;
  283. +
  284. + if (ar2315_mem)
  285. + return -EBUSY;
  286. +
  287. + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  288. + "ar2315-gpio-irq-base");
  289. + if (!res) {
  290. + dev_err(dev, "not found GPIO IRQ base\n");
  291. + return -ENXIO;
  292. + }
  293. + ar2315_gpio_irq_base = res->start;
  294. +
  295. + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, DRIVER_NAME);
  296. + if (!res) {
  297. + dev_err(dev, "not found IRQ number\n");
  298. + return -ENXIO;
  299. + }
  300. + irq = res->start;
  301. +
  302. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, DRIVER_NAME);
  303. + ar2315_mem = devm_ioremap_resource(dev, res);
  304. + if (IS_ERR(ar2315_mem))
  305. + return PTR_ERR(ar2315_mem);
  306. +
  307. + ar2315_gpio_chip.dev = dev;
  308. + ret = gpiochip_add(&ar2315_gpio_chip);
  309. + if (ret) {
  310. + dev_err(dev, "failed to add gpiochip\n");
  311. + return ret;
  312. + }
  313. +
  314. + ar2315_gpio_irq_init(irq);
  315. +
  316. + return 0;
  317. +}
  318. +
  319. +static struct platform_driver ar2315_gpio_driver = {
  320. + .probe = ar2315_gpio_probe,
  321. + .driver = {
  322. + .name = DRIVER_NAME,
  323. + .owner = THIS_MODULE,
  324. + }
  325. +};
  326. +
  327. +static int __init ar2315_gpio_init(void)
  328. +{
  329. + return platform_driver_register(&ar2315_gpio_driver);
  330. +}
  331. +subsys_initcall(ar2315_gpio_init);
  332. --- a/arch/mips/ath25/devices.h
  333. +++ b/arch/mips/ath25/devices.h
  334. @@ -3,6 +3,11 @@
  335. #include <linux/cpu.h>
  336. +#define AR231X_GPIO_IRQ_BASE 0x30
  337. +
  338. +/* GPIO number for AR2315/16 reset issue workaround */
  339. +#define AR2315_RESET_GPIO 5
  340. +
  341. #define ATH25_REG_MS(_val, _field) (((_val) & _field##_M) >> _field##_S)
  342. #define ATH25_IRQ_CPU_CLOCK (MIPS_CPU_IRQ_BASE + 7) /* C0_CAUSE: 0x8000 */
  343. --- a/arch/mips/ath25/ar2315_regs.h
  344. +++ b/arch/mips/ath25/ar2315_regs.h
  345. @@ -315,6 +315,9 @@
  346. #define AR2315_MEM_CFG_BANKADDR_BITS_M 0x00000018
  347. #define AR2315_MEM_CFG_BANKADDR_BITS_S 3
  348. +/* GPIO MMR base address */
  349. +#define AR2315_GPIO 0x0088
  350. +
  351. /*
  352. * Local Bus Interface Registers
  353. */