gpio.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
  3. * JZ4740 platform GPIO support
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * You should have received a copy of the GNU General Public License along
  11. * with this program; if not, write to the Free Software Foundation, Inc.,
  12. * 675 Mass Ave, Cambridge, MA 02139, USA.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/sysdev.h>
  20. #include <linux/io.h>
  21. #include <linux/gpio.h>
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/bitops.h>
  25. #include <linux/debugfs.h>
  26. #include <linux/seq_file.h>
  27. #include <asm/mach-jz4740/base.h>
  28. #define JZ4740_GPIO_BASE_A (32*0)
  29. #define JZ4740_GPIO_BASE_B (32*1)
  30. #define JZ4740_GPIO_BASE_C (32*2)
  31. #define JZ4740_GPIO_BASE_D (32*3)
  32. #define JZ4740_GPIO_NUM_A 32
  33. #define JZ4740_GPIO_NUM_B 32
  34. #define JZ4740_GPIO_NUM_C 31
  35. #define JZ4740_GPIO_NUM_D 32
  36. #define JZ4740_IRQ_GPIO_BASE_A (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_A)
  37. #define JZ4740_IRQ_GPIO_BASE_B (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_B)
  38. #define JZ4740_IRQ_GPIO_BASE_C (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_C)
  39. #define JZ4740_IRQ_GPIO_BASE_D (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_D)
  40. #define JZ_REG_GPIO_PIN 0x00
  41. #define JZ_REG_GPIO_DATA 0x10
  42. #define JZ_REG_GPIO_DATA_SET 0x14
  43. #define JZ_REG_GPIO_DATA_CLEAR 0x18
  44. #define JZ_REG_GPIO_MASK 0x20
  45. #define JZ_REG_GPIO_MASK_SET 0x24
  46. #define JZ_REG_GPIO_MASK_CLEAR 0x28
  47. #define JZ_REG_GPIO_PULL 0x30
  48. #define JZ_REG_GPIO_PULL_SET 0x34
  49. #define JZ_REG_GPIO_PULL_CLEAR 0x38
  50. #define JZ_REG_GPIO_FUNC 0x40
  51. #define JZ_REG_GPIO_FUNC_SET 0x44
  52. #define JZ_REG_GPIO_FUNC_CLEAR 0x48
  53. #define JZ_REG_GPIO_SELECT 0x50
  54. #define JZ_REG_GPIO_SELECT_SET 0x54
  55. #define JZ_REG_GPIO_SELECT_CLEAR 0x58
  56. #define JZ_REG_GPIO_DIRECTION 0x60
  57. #define JZ_REG_GPIO_DIRECTION_SET 0x64
  58. #define JZ_REG_GPIO_DIRECTION_CLEAR 0x68
  59. #define JZ_REG_GPIO_TRIGGER 0x70
  60. #define JZ_REG_GPIO_TRIGGER_SET 0x74
  61. #define JZ_REG_GPIO_TRIGGER_CLEAR 0x78
  62. #define JZ_REG_GPIO_FLAG 0x80
  63. #define JZ_REG_GPIO_FLAG_CLEAR 0x14
  64. #define GPIO_TO_BIT(gpio) BIT(gpio & 0x1f)
  65. #define GPIO_TO_REG(gpio, reg) (gpio_to_jz_gpio_chip(gpio)->base + (reg))
  66. #define CHIP_TO_REG(chip, reg) (gpio_chip_to_jz_gpio_chip(chip)->base + (reg))
  67. struct jz_gpio_chip {
  68. unsigned int irq;
  69. unsigned int irq_base;
  70. uint32_t wakeup;
  71. uint32_t suspend_mask;
  72. uint32_t edge_trigger_both;
  73. void __iomem *base;
  74. spinlock_t lock;
  75. struct gpio_chip gpio_chip;
  76. struct irq_chip irq_chip;
  77. struct sys_device sysdev;
  78. };
  79. static struct jz_gpio_chip jz4740_gpio_chips[];
  80. static inline struct jz_gpio_chip *gpio_to_jz_gpio_chip(unsigned int gpio)
  81. {
  82. return &jz4740_gpio_chips[gpio >> 5];
  83. }
  84. static inline struct jz_gpio_chip *gpio_chip_to_jz_gpio_chip(struct gpio_chip *gpio_chip)
  85. {
  86. return container_of(gpio_chip, struct jz_gpio_chip, gpio_chip);
  87. }
  88. static inline struct jz_gpio_chip *irq_to_jz_gpio_chip(unsigned int irq)
  89. {
  90. return get_irq_chip_data(irq);
  91. }
  92. static inline void jz_gpio_write_bit(unsigned int gpio, unsigned int reg)
  93. {
  94. writel(GPIO_TO_BIT(gpio), GPIO_TO_REG(gpio, reg));
  95. }
  96. int jz_gpio_set_function(int gpio, enum jz_gpio_function function)
  97. {
  98. if (function == JZ_GPIO_FUNC_NONE) {
  99. jz_gpio_write_bit(gpio, JZ_REG_GPIO_FUNC_CLEAR);
  100. jz_gpio_write_bit(gpio, JZ_REG_GPIO_SELECT_CLEAR);
  101. jz_gpio_write_bit(gpio, JZ_REG_GPIO_TRIGGER_CLEAR);
  102. } else {
  103. jz_gpio_write_bit(gpio, JZ_REG_GPIO_FUNC_SET);
  104. jz_gpio_write_bit(gpio, JZ_REG_GPIO_TRIGGER_CLEAR);
  105. switch (function) {
  106. case JZ_GPIO_FUNC1:
  107. jz_gpio_write_bit(gpio, JZ_REG_GPIO_SELECT_CLEAR);
  108. break;
  109. case JZ_GPIO_FUNC3:
  110. jz_gpio_write_bit(gpio, JZ_REG_GPIO_TRIGGER_SET);
  111. case JZ_GPIO_FUNC2: /* Falltrough */
  112. jz_gpio_write_bit(gpio, JZ_REG_GPIO_SELECT_SET);
  113. break;
  114. default:
  115. BUG();
  116. break;
  117. }
  118. }
  119. return 0;
  120. }
  121. EXPORT_SYMBOL_GPL(jz_gpio_set_function);
  122. int jz_gpio_bulk_request(const struct jz_gpio_bulk_request *request, size_t num)
  123. {
  124. size_t i;
  125. int ret;
  126. for (i = 0; i < num; ++i, ++request) {
  127. ret = gpio_request(request->gpio, request->name);
  128. if (ret)
  129. goto err;
  130. jz_gpio_set_function(request->gpio, request->function);
  131. }
  132. return 0;
  133. err:
  134. for (--request; i > 0; --i, --request) {
  135. gpio_free(request->gpio);
  136. jz_gpio_set_function(request->gpio, JZ_GPIO_FUNC_NONE);
  137. }
  138. return ret;
  139. }
  140. EXPORT_SYMBOL_GPL(jz_gpio_bulk_request);
  141. void jz_gpio_bulk_free(const struct jz_gpio_bulk_request *request, size_t num)
  142. {
  143. size_t i;
  144. for (i = 0; i < num; ++i, ++request) {
  145. gpio_free(request->gpio);
  146. jz_gpio_set_function(request->gpio, JZ_GPIO_FUNC_NONE);
  147. }
  148. }
  149. EXPORT_SYMBOL_GPL(jz_gpio_bulk_free);
  150. void jz_gpio_bulk_suspend(const struct jz_gpio_bulk_request *request, size_t num)
  151. {
  152. size_t i;
  153. for (i = 0; i < num; ++i, ++request) {
  154. jz_gpio_set_function(request->gpio, JZ_GPIO_FUNC_NONE);
  155. jz_gpio_write_bit(request->gpio, JZ_REG_GPIO_DIRECTION_CLEAR);
  156. jz_gpio_write_bit(request->gpio, JZ_REG_GPIO_PULL_SET);
  157. }
  158. }
  159. EXPORT_SYMBOL_GPL(jz_gpio_bulk_suspend);
  160. void jz_gpio_bulk_resume(const struct jz_gpio_bulk_request *request, size_t num)
  161. {
  162. size_t i;
  163. for (i = 0; i < num; ++i, ++request)
  164. jz_gpio_set_function(request->gpio, request->function);
  165. }
  166. EXPORT_SYMBOL_GPL(jz_gpio_bulk_resume);
  167. void jz_gpio_enable_pullup(unsigned gpio)
  168. {
  169. jz_gpio_write_bit(gpio, JZ_REG_GPIO_PULL_CLEAR);
  170. }
  171. EXPORT_SYMBOL_GPL(jz_gpio_enable_pullup);
  172. void jz_gpio_disable_pullup(unsigned gpio)
  173. {
  174. jz_gpio_write_bit(gpio, JZ_REG_GPIO_PULL_SET);
  175. }
  176. EXPORT_SYMBOL_GPL(jz_gpio_disable_pullup);
  177. static int jz_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
  178. {
  179. return !!(readl(CHIP_TO_REG(chip, JZ_REG_GPIO_PIN)) & BIT(gpio));
  180. }
  181. static void jz_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
  182. {
  183. uint32_t __iomem *reg = CHIP_TO_REG(chip, JZ_REG_GPIO_DATA_SET);
  184. reg += !value;
  185. writel(BIT(gpio), reg);
  186. }
  187. static int jz_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
  188. int value)
  189. {
  190. writel(BIT(gpio), CHIP_TO_REG(chip, JZ_REG_GPIO_DIRECTION_SET));
  191. jz_gpio_set_value(chip, gpio, value);
  192. return 0;
  193. }
  194. static int jz_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  195. {
  196. writel(BIT(gpio), CHIP_TO_REG(chip, JZ_REG_GPIO_DIRECTION_CLEAR));
  197. return 0;
  198. }
  199. int jz_gpio_port_direction_input(int port, uint32_t mask)
  200. {
  201. writel(mask, GPIO_TO_REG(port, JZ_REG_GPIO_DIRECTION_CLEAR));
  202. return 0;
  203. }
  204. EXPORT_SYMBOL(jz_gpio_port_direction_input);
  205. int jz_gpio_port_direction_output(int port, uint32_t mask)
  206. {
  207. writel(mask, GPIO_TO_REG(port, JZ_REG_GPIO_DIRECTION_SET));
  208. return 0;
  209. }
  210. EXPORT_SYMBOL(jz_gpio_port_direction_output);
  211. void jz_gpio_port_set_value(int port, uint32_t value, uint32_t mask)
  212. {
  213. writel(~value & mask, GPIO_TO_REG(port, JZ_REG_GPIO_DATA_CLEAR));
  214. writel(value & mask, GPIO_TO_REG(port, JZ_REG_GPIO_DATA_SET));
  215. }
  216. EXPORT_SYMBOL(jz_gpio_port_set_value);
  217. uint32_t jz_gpio_port_get_value(int port, uint32_t mask)
  218. {
  219. uint32_t value = readl(GPIO_TO_REG(port, JZ_REG_GPIO_PIN));
  220. return value & mask;
  221. }
  222. EXPORT_SYMBOL(jz_gpio_port_get_value);
  223. int gpio_to_irq(unsigned gpio)
  224. {
  225. return JZ4740_IRQ_GPIO(0) + gpio;
  226. }
  227. EXPORT_SYMBOL_GPL(gpio_to_irq);
  228. int irq_to_gpio(unsigned irq)
  229. {
  230. return irq - JZ4740_IRQ_GPIO(0);
  231. }
  232. EXPORT_SYMBOL_GPL(irq_to_gpio);
  233. #define IRQ_TO_BIT(irq) BIT(irq_to_gpio(irq) & 0x1f)
  234. static void jz_gpio_check_trigger_both(struct jz_gpio_chip *chip, unsigned int irq)
  235. {
  236. uint32_t value;
  237. void __iomem *reg;
  238. uint32_t mask = IRQ_TO_BIT(irq);
  239. if (!(chip->edge_trigger_both & mask))
  240. return;
  241. reg = chip->base;
  242. value = readl(chip->base + JZ_REG_GPIO_PIN);
  243. if (value & mask)
  244. reg += JZ_REG_GPIO_DIRECTION_CLEAR;
  245. else
  246. reg += JZ_REG_GPIO_DIRECTION_SET;
  247. writel(mask, reg);
  248. }
  249. static void jz_gpio_irq_demux_handler(unsigned int irq, struct irq_desc *desc)
  250. {
  251. uint32_t flag;
  252. unsigned int gpio_irq;
  253. unsigned int gpio_bank;
  254. struct jz_gpio_chip *chip = get_irq_desc_data(desc);
  255. gpio_bank = JZ4740_IRQ_GPIO0 - irq;
  256. flag = readl(chip->base + JZ_REG_GPIO_FLAG);
  257. if (!flag)
  258. return;
  259. gpio_irq = __fls(flag);
  260. jz_gpio_check_trigger_both(chip, irq);
  261. gpio_irq += (gpio_bank << 5) + JZ4740_IRQ_GPIO(0);
  262. generic_handle_irq(gpio_irq);
  263. };
  264. static inline void jz_gpio_set_irq_bit(unsigned int irq, unsigned int reg)
  265. {
  266. struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq);
  267. writel(IRQ_TO_BIT(irq), chip->base + reg);
  268. }
  269. static void jz_gpio_irq_mask(unsigned int irq)
  270. {
  271. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_MASK_SET);
  272. };
  273. static void jz_gpio_irq_unmask(unsigned int irq)
  274. {
  275. struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq);
  276. jz_gpio_check_trigger_both(chip, irq);
  277. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_MASK_CLEAR);
  278. };
  279. /* TODO: Check if function is gpio */
  280. static unsigned int jz_gpio_irq_startup(unsigned int irq)
  281. {
  282. struct irq_desc *desc = irq_to_desc(irq);
  283. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_SELECT_SET);
  284. desc->status &= ~IRQ_MASKED;
  285. jz_gpio_irq_unmask(irq);
  286. return 0;
  287. }
  288. static void jz_gpio_irq_shutdown(unsigned int irq)
  289. {
  290. struct irq_desc *desc = irq_to_desc(irq);
  291. jz_gpio_irq_mask(irq);
  292. desc->status |= IRQ_MASKED;
  293. /* Set direction to input */
  294. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR);
  295. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_SELECT_CLEAR);
  296. }
  297. static void jz_gpio_irq_ack(unsigned int irq)
  298. {
  299. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_FLAG_CLEAR);
  300. };
  301. static int jz_gpio_irq_set_type(unsigned int irq, unsigned int flow_type)
  302. {
  303. struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq);
  304. struct irq_desc *desc = irq_to_desc(irq);
  305. jz_gpio_irq_mask(irq);
  306. if (flow_type == IRQ_TYPE_EDGE_BOTH) {
  307. uint32_t value = readl(chip->base + JZ_REG_GPIO_PIN);
  308. if (value & IRQ_TO_BIT(irq))
  309. flow_type = IRQ_TYPE_EDGE_FALLING;
  310. else
  311. flow_type = IRQ_TYPE_EDGE_RISING;
  312. chip->edge_trigger_both |= IRQ_TO_BIT(irq);
  313. } else {
  314. chip->edge_trigger_both &= ~IRQ_TO_BIT(irq);
  315. }
  316. switch (flow_type) {
  317. case IRQ_TYPE_EDGE_RISING:
  318. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_SET);
  319. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_SET);
  320. break;
  321. case IRQ_TYPE_EDGE_FALLING:
  322. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR);
  323. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_SET);
  324. break;
  325. case IRQ_TYPE_LEVEL_HIGH:
  326. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_SET);
  327. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_CLEAR);
  328. break;
  329. case IRQ_TYPE_LEVEL_LOW:
  330. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR);
  331. jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_CLEAR);
  332. break;
  333. default:
  334. return -EINVAL;
  335. }
  336. if (!(desc->status & IRQ_MASKED))
  337. jz_gpio_irq_unmask(irq);
  338. return 0;
  339. }
  340. static int jz_gpio_irq_set_wake(unsigned int irq, unsigned int on)
  341. {
  342. struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq);
  343. spin_lock(&chip->lock);
  344. if (on)
  345. chip->wakeup |= IRQ_TO_BIT(irq);
  346. else
  347. chip->wakeup &= ~IRQ_TO_BIT(irq);
  348. spin_unlock(&chip->lock);
  349. set_irq_wake(chip->irq, on);
  350. return 0;
  351. }
  352. /*
  353. * This lock class tells lockdep that GPIO irqs are in a different
  354. * category than their parents, so it won't report false recursion.
  355. */
  356. static struct lock_class_key gpio_lock_class;
  357. #define JZ4740_GPIO_CHIP(_bank) { \
  358. .irq_base = JZ4740_IRQ_GPIO_BASE_ ## _bank, \
  359. .gpio_chip = { \
  360. .label = "Bank " # _bank, \
  361. .owner = THIS_MODULE, \
  362. .set = jz_gpio_set_value, \
  363. .get = jz_gpio_get_value, \
  364. .direction_output = jz_gpio_direction_output, \
  365. .direction_input = jz_gpio_direction_input, \
  366. .base = JZ4740_GPIO_BASE_ ## _bank, \
  367. .ngpio = JZ4740_GPIO_NUM_ ## _bank, \
  368. }, \
  369. .irq_chip = { \
  370. .name = "GPIO Bank " # _bank, \
  371. .mask = jz_gpio_irq_mask, \
  372. .unmask = jz_gpio_irq_unmask, \
  373. .ack = jz_gpio_irq_ack, \
  374. .startup = jz_gpio_irq_startup, \
  375. .shutdown = jz_gpio_irq_shutdown, \
  376. .set_type = jz_gpio_irq_set_type, \
  377. .set_wake = jz_gpio_irq_set_wake, \
  378. }, \
  379. }
  380. static struct jz_gpio_chip jz4740_gpio_chips[] = {
  381. JZ4740_GPIO_CHIP(A),
  382. JZ4740_GPIO_CHIP(B),
  383. JZ4740_GPIO_CHIP(C),
  384. JZ4740_GPIO_CHIP(D),
  385. };
  386. static inline struct jz_gpio_chip *sysdev_to_chip(struct sys_device *dev)
  387. {
  388. return container_of(dev, struct jz_gpio_chip, sysdev);
  389. }
  390. static int jz4740_gpio_suspend(struct sys_device *dev, pm_message_t state)
  391. {
  392. struct jz_gpio_chip *chip = sysdev_to_chip(dev);
  393. chip->suspend_mask = readl(chip->base + JZ_REG_GPIO_MASK);
  394. writel(~(chip->wakeup), chip->base + JZ_REG_GPIO_MASK_SET);
  395. writel(chip->wakeup, chip->base + JZ_REG_GPIO_MASK_CLEAR);
  396. return 0;
  397. }
  398. static int jz4740_gpio_resume(struct sys_device *dev)
  399. {
  400. struct jz_gpio_chip *chip = sysdev_to_chip(dev);
  401. uint32_t mask = chip->suspend_mask;
  402. writel(~mask, chip->base + JZ_REG_GPIO_MASK_CLEAR);
  403. writel(mask, chip->base + JZ_REG_GPIO_MASK_SET);
  404. return 0;
  405. }
  406. static struct sysdev_class jz4740_gpio_sysdev_class = {
  407. .name = "gpio",
  408. .suspend = jz4740_gpio_suspend,
  409. .resume = jz4740_gpio_resume,
  410. };
  411. static int jz4740_gpio_chip_init(struct jz_gpio_chip *chip, unsigned int id)
  412. {
  413. int ret, irq;
  414. chip->sysdev.id = id;
  415. chip->sysdev.cls = &jz4740_gpio_sysdev_class;
  416. ret = sysdev_register(&chip->sysdev);
  417. if (ret)
  418. return ret;
  419. spin_lock_init(&chip->lock);
  420. chip->base = ioremap(JZ4740_GPIO_BASE_ADDR + (id * 0x100), 0x100);
  421. gpiochip_add(&chip->gpio_chip);
  422. chip->irq = JZ4740_IRQ_INTC_GPIO(id);
  423. set_irq_data(chip->irq, chip);
  424. set_irq_chained_handler(chip->irq, jz_gpio_irq_demux_handler);
  425. for (irq = chip->irq_base; irq < chip->irq_base + chip->gpio_chip.ngpio; ++irq) {
  426. lockdep_set_class(&irq_desc[irq].lock, &gpio_lock_class);
  427. set_irq_chip_data(irq, chip);
  428. set_irq_chip_and_handler(irq, &chip->irq_chip, handle_level_irq);
  429. }
  430. return 0;
  431. }
  432. static int __init jz4740_gpio_init(void)
  433. {
  434. unsigned int i;
  435. int ret;
  436. ret = sysdev_class_register(&jz4740_gpio_sysdev_class);
  437. if (ret)
  438. return ret;
  439. for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i)
  440. jz4740_gpio_chip_init(&jz4740_gpio_chips[i], i);
  441. printk(KERN_INFO "JZ4740 GPIO initalized\n");
  442. return 0;
  443. }
  444. arch_initcall(jz4740_gpio_init);
  445. #ifdef CONFIG_DEBUG_FS
  446. static inline void gpio_seq_reg(struct seq_file *s, struct jz_gpio_chip *chip,
  447. const char *name, unsigned int reg)
  448. {
  449. seq_printf(s, "\t%s: %08x\n", name, readl(chip->base + reg));
  450. }
  451. static int gpio_regs_show(struct seq_file *s, void *unused)
  452. {
  453. struct jz_gpio_chip *chip = jz4740_gpio_chips;
  454. int i;
  455. for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i, ++chip) {
  456. seq_printf(s, "==GPIO %d==\n", i);
  457. gpio_seq_reg(s, chip, "Pin", JZ_REG_GPIO_PIN);
  458. gpio_seq_reg(s, chip, "Data", JZ_REG_GPIO_DATA);
  459. gpio_seq_reg(s, chip, "Mask", JZ_REG_GPIO_MASK);
  460. gpio_seq_reg(s, chip, "Pull", JZ_REG_GPIO_PULL);
  461. gpio_seq_reg(s, chip, "Func", JZ_REG_GPIO_FUNC);
  462. gpio_seq_reg(s, chip, "Select", JZ_REG_GPIO_SELECT);
  463. gpio_seq_reg(s, chip, "Direction", JZ_REG_GPIO_DIRECTION);
  464. gpio_seq_reg(s, chip, "Trigger", JZ_REG_GPIO_TRIGGER);
  465. gpio_seq_reg(s, chip, "Flag", JZ_REG_GPIO_FLAG);
  466. }
  467. return 0;
  468. }
  469. static int gpio_regs_open(struct inode *inode, struct file *file)
  470. {
  471. return single_open(file, gpio_regs_show, NULL);
  472. }
  473. static const struct file_operations gpio_regs_operations = {
  474. .open = gpio_regs_open,
  475. .read = seq_read,
  476. .llseek = seq_lseek,
  477. .release = single_release,
  478. };
  479. static int __init gpio_debugfs_init(void)
  480. {
  481. (void) debugfs_create_file("jz_regs_gpio", S_IFREG | S_IRUGO,
  482. NULL, NULL, &gpio_regs_operations);
  483. return 0;
  484. }
  485. subsys_initcall(gpio_debugfs_init);
  486. #endif