gpio.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * arch/arm/plat-orion/gpio.c
  3. *
  4. * Marvell Orion SoC GPIO handling.
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #define DEBUG
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqdomain.h>
  15. #include <linux/module.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/bitops.h>
  18. #include <linux/io.h>
  19. #include <linux/gpio.h>
  20. #include <linux/leds.h>
  21. #include <linux/of.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/of_address.h>
  24. #include <plat/orion-gpio.h>
  25. /*
  26. * GPIO unit register offsets.
  27. */
  28. #define GPIO_OUT_OFF 0x0000
  29. #define GPIO_IO_CONF_OFF 0x0004
  30. #define GPIO_BLINK_EN_OFF 0x0008
  31. #define GPIO_IN_POL_OFF 0x000c
  32. #define GPIO_DATA_IN_OFF 0x0010
  33. #define GPIO_EDGE_CAUSE_OFF 0x0014
  34. #define GPIO_EDGE_MASK_OFF 0x0018
  35. #define GPIO_LEVEL_MASK_OFF 0x001c
  36. struct orion_gpio_chip {
  37. struct gpio_chip chip;
  38. spinlock_t lock;
  39. void __iomem *base;
  40. unsigned long valid_input;
  41. unsigned long valid_output;
  42. int mask_offset;
  43. int secondary_irq_base;
  44. struct irq_domain *domain;
  45. };
  46. static void __iomem *GPIO_OUT(struct orion_gpio_chip *ochip)
  47. {
  48. return ochip->base + GPIO_OUT_OFF;
  49. }
  50. static void __iomem *GPIO_IO_CONF(struct orion_gpio_chip *ochip)
  51. {
  52. return ochip->base + GPIO_IO_CONF_OFF;
  53. }
  54. static void __iomem *GPIO_BLINK_EN(struct orion_gpio_chip *ochip)
  55. {
  56. return ochip->base + GPIO_BLINK_EN_OFF;
  57. }
  58. static void __iomem *GPIO_IN_POL(struct orion_gpio_chip *ochip)
  59. {
  60. return ochip->base + GPIO_IN_POL_OFF;
  61. }
  62. static void __iomem *GPIO_DATA_IN(struct orion_gpio_chip *ochip)
  63. {
  64. return ochip->base + GPIO_DATA_IN_OFF;
  65. }
  66. static void __iomem *GPIO_EDGE_CAUSE(struct orion_gpio_chip *ochip)
  67. {
  68. return ochip->base + GPIO_EDGE_CAUSE_OFF;
  69. }
  70. static void __iomem *GPIO_EDGE_MASK(struct orion_gpio_chip *ochip)
  71. {
  72. return ochip->base + ochip->mask_offset + GPIO_EDGE_MASK_OFF;
  73. }
  74. static void __iomem *GPIO_LEVEL_MASK(struct orion_gpio_chip *ochip)
  75. {
  76. return ochip->base + ochip->mask_offset + GPIO_LEVEL_MASK_OFF;
  77. }
  78. static struct orion_gpio_chip orion_gpio_chips[2];
  79. static int orion_gpio_chip_count;
  80. static inline void
  81. __set_direction(struct orion_gpio_chip *ochip, unsigned pin, int input)
  82. {
  83. u32 u;
  84. u = readl(GPIO_IO_CONF(ochip));
  85. if (input)
  86. u |= 1 << pin;
  87. else
  88. u &= ~(1 << pin);
  89. writel(u, GPIO_IO_CONF(ochip));
  90. }
  91. static void __set_level(struct orion_gpio_chip *ochip, unsigned pin, int high)
  92. {
  93. u32 u;
  94. u = readl(GPIO_OUT(ochip));
  95. if (high)
  96. u |= 1 << pin;
  97. else
  98. u &= ~(1 << pin);
  99. writel(u, GPIO_OUT(ochip));
  100. }
  101. static inline void
  102. __set_blinking(struct orion_gpio_chip *ochip, unsigned pin, int blink)
  103. {
  104. u32 u;
  105. u = readl(GPIO_BLINK_EN(ochip));
  106. if (blink)
  107. u |= 1 << pin;
  108. else
  109. u &= ~(1 << pin);
  110. writel(u, GPIO_BLINK_EN(ochip));
  111. }
  112. static inline int
  113. orion_gpio_is_valid(struct orion_gpio_chip *ochip, unsigned pin, int mode)
  114. {
  115. if (pin >= ochip->chip.ngpio)
  116. goto err_out;
  117. if ((mode & GPIO_INPUT_OK) && !test_bit(pin, &ochip->valid_input))
  118. goto err_out;
  119. if ((mode & GPIO_OUTPUT_OK) && !test_bit(pin, &ochip->valid_output))
  120. goto err_out;
  121. return 1;
  122. err_out:
  123. pr_debug("%s: invalid GPIO %d\n", __func__, pin);
  124. return false;
  125. }
  126. /*
  127. * GPIO primitives.
  128. */
  129. static int orion_gpio_request(struct gpio_chip *chip, unsigned pin)
  130. {
  131. struct orion_gpio_chip *ochip =
  132. container_of(chip, struct orion_gpio_chip, chip);
  133. if (orion_gpio_is_valid(ochip, pin, GPIO_INPUT_OK) ||
  134. orion_gpio_is_valid(ochip, pin, GPIO_OUTPUT_OK))
  135. return 0;
  136. return -EINVAL;
  137. }
  138. static int orion_gpio_direction_input(struct gpio_chip *chip, unsigned pin)
  139. {
  140. struct orion_gpio_chip *ochip =
  141. container_of(chip, struct orion_gpio_chip, chip);
  142. unsigned long flags;
  143. if (!orion_gpio_is_valid(ochip, pin, GPIO_INPUT_OK))
  144. return -EINVAL;
  145. spin_lock_irqsave(&ochip->lock, flags);
  146. __set_direction(ochip, pin, 1);
  147. spin_unlock_irqrestore(&ochip->lock, flags);
  148. return 0;
  149. }
  150. static int orion_gpio_get(struct gpio_chip *chip, unsigned pin)
  151. {
  152. struct orion_gpio_chip *ochip =
  153. container_of(chip, struct orion_gpio_chip, chip);
  154. int val;
  155. if (readl(GPIO_IO_CONF(ochip)) & (1 << pin)) {
  156. val = readl(GPIO_DATA_IN(ochip)) ^ readl(GPIO_IN_POL(ochip));
  157. } else {
  158. val = readl(GPIO_OUT(ochip));
  159. }
  160. return (val >> pin) & 1;
  161. }
  162. static int
  163. orion_gpio_direction_output(struct gpio_chip *chip, unsigned pin, int value)
  164. {
  165. struct orion_gpio_chip *ochip =
  166. container_of(chip, struct orion_gpio_chip, chip);
  167. unsigned long flags;
  168. if (!orion_gpio_is_valid(ochip, pin, GPIO_OUTPUT_OK))
  169. return -EINVAL;
  170. spin_lock_irqsave(&ochip->lock, flags);
  171. __set_blinking(ochip, pin, 0);
  172. __set_level(ochip, pin, value);
  173. __set_direction(ochip, pin, 0);
  174. spin_unlock_irqrestore(&ochip->lock, flags);
  175. return 0;
  176. }
  177. static void orion_gpio_set(struct gpio_chip *chip, unsigned pin, int value)
  178. {
  179. struct orion_gpio_chip *ochip =
  180. container_of(chip, struct orion_gpio_chip, chip);
  181. unsigned long flags;
  182. spin_lock_irqsave(&ochip->lock, flags);
  183. __set_level(ochip, pin, value);
  184. spin_unlock_irqrestore(&ochip->lock, flags);
  185. }
  186. static int orion_gpio_to_irq(struct gpio_chip *chip, unsigned pin)
  187. {
  188. struct orion_gpio_chip *ochip =
  189. container_of(chip, struct orion_gpio_chip, chip);
  190. return irq_create_mapping(ochip->domain,
  191. ochip->secondary_irq_base + pin);
  192. }
  193. /*
  194. * Orion-specific GPIO API extensions.
  195. */
  196. static struct orion_gpio_chip *orion_gpio_chip_find(int pin)
  197. {
  198. int i;
  199. for (i = 0; i < orion_gpio_chip_count; i++) {
  200. struct orion_gpio_chip *ochip = orion_gpio_chips + i;
  201. struct gpio_chip *chip = &ochip->chip;
  202. if (pin >= chip->base && pin < chip->base + chip->ngpio)
  203. return ochip;
  204. }
  205. return NULL;
  206. }
  207. void __init orion_gpio_set_unused(unsigned pin)
  208. {
  209. struct orion_gpio_chip *ochip = orion_gpio_chip_find(pin);
  210. if (ochip == NULL)
  211. return;
  212. pin -= ochip->chip.base;
  213. /* Configure as output, drive low. */
  214. __set_level(ochip, pin, 0);
  215. __set_direction(ochip, pin, 0);
  216. }
  217. void __init orion_gpio_set_valid(unsigned pin, int mode)
  218. {
  219. struct orion_gpio_chip *ochip = orion_gpio_chip_find(pin);
  220. if (ochip == NULL)
  221. return;
  222. pin -= ochip->chip.base;
  223. if (mode == 1)
  224. mode = GPIO_INPUT_OK | GPIO_OUTPUT_OK;
  225. if (mode & GPIO_INPUT_OK)
  226. __set_bit(pin, &ochip->valid_input);
  227. else
  228. __clear_bit(pin, &ochip->valid_input);
  229. if (mode & GPIO_OUTPUT_OK)
  230. __set_bit(pin, &ochip->valid_output);
  231. else
  232. __clear_bit(pin, &ochip->valid_output);
  233. }
  234. void orion_gpio_set_blink(unsigned pin, int blink)
  235. {
  236. struct orion_gpio_chip *ochip = orion_gpio_chip_find(pin);
  237. unsigned long flags;
  238. if (ochip == NULL)
  239. return;
  240. spin_lock_irqsave(&ochip->lock, flags);
  241. __set_level(ochip, pin & 31, 0);
  242. __set_blinking(ochip, pin & 31, blink);
  243. spin_unlock_irqrestore(&ochip->lock, flags);
  244. }
  245. EXPORT_SYMBOL(orion_gpio_set_blink);
  246. #define ORION_BLINK_HALF_PERIOD 100 /* ms */
  247. int orion_gpio_led_blink_set(unsigned gpio, int state,
  248. unsigned long *delay_on, unsigned long *delay_off)
  249. {
  250. if (delay_on && delay_off && !*delay_on && !*delay_off)
  251. *delay_on = *delay_off = ORION_BLINK_HALF_PERIOD;
  252. switch (state) {
  253. case GPIO_LED_NO_BLINK_LOW:
  254. case GPIO_LED_NO_BLINK_HIGH:
  255. orion_gpio_set_blink(gpio, 0);
  256. gpio_set_value(gpio, state);
  257. break;
  258. case GPIO_LED_BLINK:
  259. orion_gpio_set_blink(gpio, 1);
  260. }
  261. return 0;
  262. }
  263. EXPORT_SYMBOL_GPL(orion_gpio_led_blink_set);
  264. /*****************************************************************************
  265. * Orion GPIO IRQ
  266. *
  267. * GPIO_IN_POL register controls whether GPIO_DATA_IN will hold the same
  268. * value of the line or the opposite value.
  269. *
  270. * Level IRQ handlers: DATA_IN is used directly as cause register.
  271. * Interrupt are masked by LEVEL_MASK registers.
  272. * Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE.
  273. * Interrupt are masked by EDGE_MASK registers.
  274. * Both-edge handlers: Similar to regular Edge handlers, but also swaps
  275. * the polarity to catch the next line transaction.
  276. * This is a race condition that might not perfectly
  277. * work on some use cases.
  278. *
  279. * Every eight GPIO lines are grouped (OR'ed) before going up to main
  280. * cause register.
  281. *
  282. * EDGE cause mask
  283. * data-in /--------| |-----| |----\
  284. * -----| |----- ---- to main cause reg
  285. * X \----------------| |----/
  286. * polarity LEVEL mask
  287. *
  288. ****************************************************************************/
  289. static int gpio_irq_set_type(struct irq_data *d, u32 type)
  290. {
  291. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  292. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  293. struct orion_gpio_chip *ochip = gc->private;
  294. int pin;
  295. u32 u;
  296. pin = d->hwirq - ochip->secondary_irq_base;
  297. u = readl(GPIO_IO_CONF(ochip)) & (1 << pin);
  298. if (!u) {
  299. return -EINVAL;
  300. }
  301. type &= IRQ_TYPE_SENSE_MASK;
  302. if (type == IRQ_TYPE_NONE)
  303. return -EINVAL;
  304. /* Check if we need to change chip and handler */
  305. if (!(ct->type & type))
  306. if (irq_setup_alt_chip(d, type))
  307. return -EINVAL;
  308. /*
  309. * Configure interrupt polarity.
  310. */
  311. if (type == IRQ_TYPE_EDGE_RISING || type == IRQ_TYPE_LEVEL_HIGH) {
  312. u = readl(GPIO_IN_POL(ochip));
  313. u &= ~(1 << pin);
  314. writel(u, GPIO_IN_POL(ochip));
  315. } else if (type == IRQ_TYPE_EDGE_FALLING || type == IRQ_TYPE_LEVEL_LOW) {
  316. u = readl(GPIO_IN_POL(ochip));
  317. u |= 1 << pin;
  318. writel(u, GPIO_IN_POL(ochip));
  319. } else if (type == IRQ_TYPE_EDGE_BOTH) {
  320. u32 v;
  321. v = readl(GPIO_IN_POL(ochip)) ^ readl(GPIO_DATA_IN(ochip));
  322. /*
  323. * set initial polarity based on current input level
  324. */
  325. u = readl(GPIO_IN_POL(ochip));
  326. if (v & (1 << pin))
  327. u |= 1 << pin; /* falling */
  328. else
  329. u &= ~(1 << pin); /* rising */
  330. writel(u, GPIO_IN_POL(ochip));
  331. }
  332. return 0;
  333. }
  334. static void gpio_irq_handler(unsigned irq, struct irq_desc *desc)
  335. {
  336. struct orion_gpio_chip *ochip = irq_get_handler_data(irq);
  337. u32 cause, type;
  338. int i;
  339. if (ochip == NULL)
  340. return;
  341. cause = readl(GPIO_DATA_IN(ochip)) & readl(GPIO_LEVEL_MASK(ochip));
  342. cause |= readl(GPIO_EDGE_CAUSE(ochip)) & readl(GPIO_EDGE_MASK(ochip));
  343. for (i = 0; i < ochip->chip.ngpio; i++) {
  344. int irq;
  345. irq = ochip->secondary_irq_base + i;
  346. if (!(cause & (1 << i)))
  347. continue;
  348. type = irq_get_trigger_type(irq);
  349. if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  350. /* Swap polarity (race with GPIO line) */
  351. u32 polarity;
  352. polarity = readl(GPIO_IN_POL(ochip));
  353. polarity ^= 1 << i;
  354. writel(polarity, GPIO_IN_POL(ochip));
  355. }
  356. generic_handle_irq(irq);
  357. }
  358. }
  359. #ifdef CONFIG_DEBUG_FS
  360. #include <linux/seq_file.h>
  361. static void orion_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  362. {
  363. struct orion_gpio_chip *ochip =
  364. container_of(chip, struct orion_gpio_chip, chip);
  365. u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
  366. int i;
  367. out = readl_relaxed(GPIO_OUT(ochip));
  368. io_conf = readl_relaxed(GPIO_IO_CONF(ochip));
  369. blink = readl_relaxed(GPIO_BLINK_EN(ochip));
  370. in_pol = readl_relaxed(GPIO_IN_POL(ochip));
  371. data_in = readl_relaxed(GPIO_DATA_IN(ochip));
  372. cause = readl_relaxed(GPIO_EDGE_CAUSE(ochip));
  373. edg_msk = readl_relaxed(GPIO_EDGE_MASK(ochip));
  374. lvl_msk = readl_relaxed(GPIO_LEVEL_MASK(ochip));
  375. for (i = 0; i < chip->ngpio; i++) {
  376. const char *label;
  377. u32 msk;
  378. bool is_out;
  379. label = gpiochip_is_requested(chip, i);
  380. if (!label)
  381. continue;
  382. msk = 1 << i;
  383. is_out = !(io_conf & msk);
  384. seq_printf(s, " gpio-%-3d (%-20.20s)", chip->base + i, label);
  385. if (is_out) {
  386. seq_printf(s, " out %s %s\n",
  387. out & msk ? "hi" : "lo",
  388. blink & msk ? "(blink )" : "");
  389. continue;
  390. }
  391. seq_printf(s, " in %s (act %s) - IRQ",
  392. (data_in ^ in_pol) & msk ? "hi" : "lo",
  393. in_pol & msk ? "lo" : "hi");
  394. if (!((edg_msk | lvl_msk) & msk)) {
  395. seq_printf(s, " disabled\n");
  396. continue;
  397. }
  398. if (edg_msk & msk)
  399. seq_printf(s, " edge ");
  400. if (lvl_msk & msk)
  401. seq_printf(s, " level");
  402. seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear ");
  403. }
  404. }
  405. #else
  406. #define orion_gpio_dbg_show NULL
  407. #endif
  408. void __init orion_gpio_init(struct device_node *np,
  409. int gpio_base, int ngpio,
  410. void __iomem *base, int mask_offset,
  411. int secondary_irq_base,
  412. int irqs[4])
  413. {
  414. struct orion_gpio_chip *ochip;
  415. struct irq_chip_generic *gc;
  416. struct irq_chip_type *ct;
  417. char gc_label[16];
  418. int i;
  419. if (orion_gpio_chip_count == ARRAY_SIZE(orion_gpio_chips))
  420. return;
  421. snprintf(gc_label, sizeof(gc_label), "orion_gpio%d",
  422. orion_gpio_chip_count);
  423. ochip = orion_gpio_chips + orion_gpio_chip_count;
  424. ochip->chip.label = kstrdup(gc_label, GFP_KERNEL);
  425. ochip->chip.request = orion_gpio_request;
  426. ochip->chip.direction_input = orion_gpio_direction_input;
  427. ochip->chip.get = orion_gpio_get;
  428. ochip->chip.direction_output = orion_gpio_direction_output;
  429. ochip->chip.set = orion_gpio_set;
  430. ochip->chip.to_irq = orion_gpio_to_irq;
  431. ochip->chip.base = gpio_base;
  432. ochip->chip.ngpio = ngpio;
  433. ochip->chip.can_sleep = 0;
  434. #ifdef CONFIG_OF
  435. ochip->chip.of_node = np;
  436. #endif
  437. ochip->chip.dbg_show = orion_gpio_dbg_show;
  438. spin_lock_init(&ochip->lock);
  439. ochip->base = (void __iomem *)base;
  440. ochip->valid_input = 0;
  441. ochip->valid_output = 0;
  442. ochip->mask_offset = mask_offset;
  443. ochip->secondary_irq_base = secondary_irq_base;
  444. gpiochip_add(&ochip->chip);
  445. /*
  446. * Mask and clear GPIO interrupts.
  447. */
  448. writel(0, GPIO_EDGE_CAUSE(ochip));
  449. writel(0, GPIO_EDGE_MASK(ochip));
  450. writel(0, GPIO_LEVEL_MASK(ochip));
  451. /* Setup the interrupt handlers. Each chip can have up to 4
  452. * interrupt handlers, with each handler dealing with 8 GPIO
  453. * pins. */
  454. for (i = 0; i < 4; i++) {
  455. if (irqs[i]) {
  456. irq_set_handler_data(irqs[i], ochip);
  457. irq_set_chained_handler(irqs[i], gpio_irq_handler);
  458. }
  459. }
  460. gc = irq_alloc_generic_chip("orion_gpio_irq", 2,
  461. secondary_irq_base,
  462. ochip->base, handle_level_irq);
  463. gc->private = ochip;
  464. ct = gc->chip_types;
  465. ct->regs.mask = ochip->mask_offset + GPIO_LEVEL_MASK_OFF;
  466. ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW;
  467. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  468. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  469. ct->chip.irq_set_type = gpio_irq_set_type;
  470. ct->chip.name = ochip->chip.label;
  471. ct++;
  472. ct->regs.mask = ochip->mask_offset + GPIO_EDGE_MASK_OFF;
  473. ct->regs.ack = GPIO_EDGE_CAUSE_OFF;
  474. ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  475. ct->chip.irq_ack = irq_gc_ack_clr_bit;
  476. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  477. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  478. ct->chip.irq_set_type = gpio_irq_set_type;
  479. ct->handler = handle_edge_irq;
  480. ct->chip.name = ochip->chip.label;
  481. irq_setup_generic_chip(gc, IRQ_MSK(ngpio), IRQ_GC_INIT_MASK_CACHE,
  482. IRQ_NOREQUEST, IRQ_LEVEL | IRQ_NOPROBE);
  483. /* Setup irq domain on top of the generic chip. */
  484. ochip->domain = irq_domain_add_legacy(np,
  485. ochip->chip.ngpio,
  486. ochip->secondary_irq_base,
  487. ochip->secondary_irq_base,
  488. &irq_domain_simple_ops,
  489. ochip);
  490. if (!ochip->domain)
  491. panic("%s: couldn't allocate irq domain (DT).\n",
  492. ochip->chip.label);
  493. orion_gpio_chip_count++;
  494. }
  495. #ifdef CONFIG_OF
  496. static void __init orion_gpio_of_init_one(struct device_node *np,
  497. int irq_gpio_base)
  498. {
  499. int ngpio, gpio_base, mask_offset;
  500. void __iomem *base;
  501. int ret, i;
  502. int irqs[4];
  503. int secondary_irq_base;
  504. ret = of_property_read_u32(np, "ngpio", &ngpio);
  505. if (ret)
  506. goto out;
  507. ret = of_property_read_u32(np, "mask-offset", &mask_offset);
  508. if (ret == -EINVAL)
  509. mask_offset = 0;
  510. else
  511. goto out;
  512. base = of_iomap(np, 0);
  513. if (!base)
  514. goto out;
  515. secondary_irq_base = irq_gpio_base + (32 * orion_gpio_chip_count);
  516. gpio_base = 32 * orion_gpio_chip_count;
  517. /* Get the interrupt numbers. Each chip can have up to 4
  518. * interrupt handlers, with each handler dealing with 8 GPIO
  519. * pins. */
  520. for (i = 0; i < 4; i++)
  521. irqs[i] = irq_of_parse_and_map(np, i);
  522. orion_gpio_init(np, gpio_base, ngpio, base, mask_offset,
  523. secondary_irq_base, irqs);
  524. return;
  525. out:
  526. pr_err("%s: %s: missing mandatory property\n", __func__, np->name);
  527. }
  528. void __init orion_gpio_of_init(int irq_gpio_base)
  529. {
  530. struct device_node *np;
  531. for_each_compatible_node(np, NULL, "marvell,orion-gpio")
  532. orion_gpio_of_init_one(np, irq_gpio_base);
  533. }
  534. #endif