gpio.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Generic GPIO driver for logic cells found in the Nomadik SoC
  3. *
  4. * Copyright (C) 2008,2009 STMicroelectronics
  5. * Copyright (C) 2009 Alessandro Rubini <rubini@unipv.it>
  6. * Rewritten based on work by Prafulla WADASKAR <prafulla.wadaskar@st.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/device.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/io.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/gpio.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/slab.h>
  25. #include <plat/pincfg.h>
  26. #include <mach/hardware.h>
  27. #include <mach/gpio.h>
  28. /*
  29. * The GPIO module in the Nomadik family of Systems-on-Chip is an
  30. * AMBA device, managing 32 pins and alternate functions. The logic block
  31. * is currently only used in the Nomadik.
  32. *
  33. * Symbols in this file are called "nmk_gpio" for "nomadik gpio"
  34. */
  35. #define NMK_GPIO_PER_CHIP 32
  36. struct nmk_gpio_chip {
  37. struct gpio_chip chip;
  38. void __iomem *addr;
  39. struct clk *clk;
  40. unsigned int parent_irq;
  41. spinlock_t lock;
  42. /* Keep track of configured edges */
  43. u32 edge_rising;
  44. u32 edge_falling;
  45. };
  46. static void __nmk_gpio_set_mode(struct nmk_gpio_chip *nmk_chip,
  47. unsigned offset, int gpio_mode)
  48. {
  49. u32 bit = 1 << offset;
  50. u32 afunc, bfunc;
  51. afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit;
  52. bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit;
  53. if (gpio_mode & NMK_GPIO_ALT_A)
  54. afunc |= bit;
  55. if (gpio_mode & NMK_GPIO_ALT_B)
  56. bfunc |= bit;
  57. writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA);
  58. writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB);
  59. }
  60. static void __nmk_gpio_set_slpm(struct nmk_gpio_chip *nmk_chip,
  61. unsigned offset, enum nmk_gpio_slpm mode)
  62. {
  63. u32 bit = 1 << offset;
  64. u32 slpm;
  65. slpm = readl(nmk_chip->addr + NMK_GPIO_SLPC);
  66. if (mode == NMK_GPIO_SLPM_NOCHANGE)
  67. slpm |= bit;
  68. else
  69. slpm &= ~bit;
  70. writel(slpm, nmk_chip->addr + NMK_GPIO_SLPC);
  71. }
  72. static void __nmk_gpio_set_pull(struct nmk_gpio_chip *nmk_chip,
  73. unsigned offset, enum nmk_gpio_pull pull)
  74. {
  75. u32 bit = 1 << offset;
  76. u32 pdis;
  77. pdis = readl(nmk_chip->addr + NMK_GPIO_PDIS);
  78. if (pull == NMK_GPIO_PULL_NONE)
  79. pdis |= bit;
  80. else
  81. pdis &= ~bit;
  82. writel(pdis, nmk_chip->addr + NMK_GPIO_PDIS);
  83. if (pull == NMK_GPIO_PULL_UP)
  84. writel(bit, nmk_chip->addr + NMK_GPIO_DATS);
  85. else if (pull == NMK_GPIO_PULL_DOWN)
  86. writel(bit, nmk_chip->addr + NMK_GPIO_DATC);
  87. }
  88. static void __nmk_gpio_make_input(struct nmk_gpio_chip *nmk_chip,
  89. unsigned offset)
  90. {
  91. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
  92. }
  93. static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset,
  94. pin_cfg_t cfg)
  95. {
  96. static const char *afnames[] = {
  97. [NMK_GPIO_ALT_GPIO] = "GPIO",
  98. [NMK_GPIO_ALT_A] = "A",
  99. [NMK_GPIO_ALT_B] = "B",
  100. [NMK_GPIO_ALT_C] = "C"
  101. };
  102. static const char *pullnames[] = {
  103. [NMK_GPIO_PULL_NONE] = "none",
  104. [NMK_GPIO_PULL_UP] = "up",
  105. [NMK_GPIO_PULL_DOWN] = "down",
  106. [3] /* illegal */ = "??"
  107. };
  108. static const char *slpmnames[] = {
  109. [NMK_GPIO_SLPM_INPUT] = "input",
  110. [NMK_GPIO_SLPM_NOCHANGE] = "no-change",
  111. };
  112. int pin = PIN_NUM(cfg);
  113. int pull = PIN_PULL(cfg);
  114. int af = PIN_ALT(cfg);
  115. int slpm = PIN_SLPM(cfg);
  116. dev_dbg(nmk_chip->chip.dev, "pin %d: af %s, pull %s, slpm %s\n",
  117. pin, afnames[af], pullnames[pull], slpmnames[slpm]);
  118. __nmk_gpio_make_input(nmk_chip, offset);
  119. __nmk_gpio_set_pull(nmk_chip, offset, pull);
  120. __nmk_gpio_set_slpm(nmk_chip, offset, slpm);
  121. __nmk_gpio_set_mode(nmk_chip, offset, af);
  122. }
  123. /**
  124. * nmk_config_pin - configure a pin's mux attributes
  125. * @cfg: pin confguration
  126. *
  127. * Configures a pin's mode (alternate function or GPIO), its pull up status,
  128. * and its sleep mode based on the specified configuration. The @cfg is
  129. * usually one of the SoC specific macros defined in mach/<soc>-pins.h. These
  130. * are constructed using, and can be further enhanced with, the macros in
  131. * plat/pincfg.h.
  132. *
  133. * If a pin's mode is set to GPIO, it is configured as an input to avoid
  134. * side-effects. The gpio can be manipulated later using standard GPIO API
  135. * calls.
  136. */
  137. int nmk_config_pin(pin_cfg_t cfg)
  138. {
  139. struct nmk_gpio_chip *nmk_chip;
  140. int gpio = PIN_NUM(cfg);
  141. unsigned long flags;
  142. nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
  143. if (!nmk_chip)
  144. return -EINVAL;
  145. spin_lock_irqsave(&nmk_chip->lock, flags);
  146. __nmk_config_pin(nmk_chip, gpio - nmk_chip->chip.base, cfg);
  147. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  148. return 0;
  149. }
  150. EXPORT_SYMBOL(nmk_config_pin);
  151. /**
  152. * nmk_config_pins - configure several pins at once
  153. * @cfgs: array of pin configurations
  154. * @num: number of elments in the array
  155. *
  156. * Configures several pins using nmk_config_pin(). Refer to that function for
  157. * further information.
  158. */
  159. int nmk_config_pins(pin_cfg_t *cfgs, int num)
  160. {
  161. int ret = 0;
  162. int i;
  163. for (i = 0; i < num; i++) {
  164. int ret = nmk_config_pin(cfgs[i]);
  165. if (ret)
  166. break;
  167. }
  168. return ret;
  169. }
  170. EXPORT_SYMBOL(nmk_config_pins);
  171. /**
  172. * nmk_gpio_set_slpm() - configure the sleep mode of a pin
  173. * @gpio: pin number
  174. * @mode: NMK_GPIO_SLPM_INPUT or NMK_GPIO_SLPM_NOCHANGE,
  175. *
  176. * Sets the sleep mode of a pin. If @mode is NMK_GPIO_SLPM_INPUT, the pin is
  177. * changed to an input (with pullup/down enabled) in sleep and deep sleep. If
  178. * @mode is NMK_GPIO_SLPM_NOCHANGE, the pin remains in the state it was
  179. * configured even when in sleep and deep sleep.
  180. */
  181. int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
  182. {
  183. struct nmk_gpio_chip *nmk_chip;
  184. unsigned long flags;
  185. nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
  186. if (!nmk_chip)
  187. return -EINVAL;
  188. spin_lock_irqsave(&nmk_chip->lock, flags);
  189. __nmk_gpio_set_slpm(nmk_chip, gpio - nmk_chip->chip.base, mode);
  190. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  191. return 0;
  192. }
  193. /**
  194. * nmk_gpio_set_pull() - enable/disable pull up/down on a gpio
  195. * @gpio: pin number
  196. * @pull: one of NMK_GPIO_PULL_DOWN, NMK_GPIO_PULL_UP, and NMK_GPIO_PULL_NONE
  197. *
  198. * Enables/disables pull up/down on a specified pin. This only takes effect if
  199. * the pin is configured as an input (either explicitly or by the alternate
  200. * function).
  201. *
  202. * NOTE: If enabling the pull up/down, the caller must ensure that the GPIO is
  203. * configured as an input. Otherwise, due to the way the controller registers
  204. * work, this function will change the value output on the pin.
  205. */
  206. int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull)
  207. {
  208. struct nmk_gpio_chip *nmk_chip;
  209. unsigned long flags;
  210. nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
  211. if (!nmk_chip)
  212. return -EINVAL;
  213. spin_lock_irqsave(&nmk_chip->lock, flags);
  214. __nmk_gpio_set_pull(nmk_chip, gpio - nmk_chip->chip.base, pull);
  215. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  216. return 0;
  217. }
  218. /* Mode functions */
  219. int nmk_gpio_set_mode(int gpio, int gpio_mode)
  220. {
  221. struct nmk_gpio_chip *nmk_chip;
  222. unsigned long flags;
  223. nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
  224. if (!nmk_chip)
  225. return -EINVAL;
  226. spin_lock_irqsave(&nmk_chip->lock, flags);
  227. __nmk_gpio_set_mode(nmk_chip, gpio - nmk_chip->chip.base, gpio_mode);
  228. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  229. return 0;
  230. }
  231. EXPORT_SYMBOL(nmk_gpio_set_mode);
  232. int nmk_gpio_get_mode(int gpio)
  233. {
  234. struct nmk_gpio_chip *nmk_chip;
  235. u32 afunc, bfunc, bit;
  236. nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
  237. if (!nmk_chip)
  238. return -EINVAL;
  239. bit = 1 << (gpio - nmk_chip->chip.base);
  240. afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit;
  241. bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit;
  242. return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0);
  243. }
  244. EXPORT_SYMBOL(nmk_gpio_get_mode);
  245. /* IRQ functions */
  246. static inline int nmk_gpio_get_bitmask(int gpio)
  247. {
  248. return 1 << (gpio % 32);
  249. }
  250. static void nmk_gpio_irq_ack(unsigned int irq)
  251. {
  252. int gpio;
  253. struct nmk_gpio_chip *nmk_chip;
  254. gpio = NOMADIK_IRQ_TO_GPIO(irq);
  255. nmk_chip = get_irq_chip_data(irq);
  256. if (!nmk_chip)
  257. return;
  258. writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC);
  259. }
  260. enum nmk_gpio_irq_type {
  261. NORMAL,
  262. WAKE,
  263. };
  264. static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip,
  265. int gpio, enum nmk_gpio_irq_type which,
  266. bool enable)
  267. {
  268. u32 rimsc = which == WAKE ? NMK_GPIO_RWIMSC : NMK_GPIO_RIMSC;
  269. u32 fimsc = which == WAKE ? NMK_GPIO_FWIMSC : NMK_GPIO_FIMSC;
  270. u32 bitmask = nmk_gpio_get_bitmask(gpio);
  271. u32 reg;
  272. /* we must individually set/clear the two edges */
  273. if (nmk_chip->edge_rising & bitmask) {
  274. reg = readl(nmk_chip->addr + rimsc);
  275. if (enable)
  276. reg |= bitmask;
  277. else
  278. reg &= ~bitmask;
  279. writel(reg, nmk_chip->addr + rimsc);
  280. }
  281. if (nmk_chip->edge_falling & bitmask) {
  282. reg = readl(nmk_chip->addr + fimsc);
  283. if (enable)
  284. reg |= bitmask;
  285. else
  286. reg &= ~bitmask;
  287. writel(reg, nmk_chip->addr + fimsc);
  288. }
  289. }
  290. static int nmk_gpio_irq_modify(unsigned int irq, enum nmk_gpio_irq_type which,
  291. bool enable)
  292. {
  293. int gpio;
  294. struct nmk_gpio_chip *nmk_chip;
  295. unsigned long flags;
  296. u32 bitmask;
  297. gpio = NOMADIK_IRQ_TO_GPIO(irq);
  298. nmk_chip = get_irq_chip_data(irq);
  299. bitmask = nmk_gpio_get_bitmask(gpio);
  300. if (!nmk_chip)
  301. return -EINVAL;
  302. spin_lock_irqsave(&nmk_chip->lock, flags);
  303. __nmk_gpio_irq_modify(nmk_chip, gpio, which, enable);
  304. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  305. return 0;
  306. }
  307. static void nmk_gpio_irq_mask(unsigned int irq)
  308. {
  309. nmk_gpio_irq_modify(irq, NORMAL, false);
  310. }
  311. static void nmk_gpio_irq_unmask(unsigned int irq)
  312. {
  313. nmk_gpio_irq_modify(irq, NORMAL, true);
  314. }
  315. static int nmk_gpio_irq_set_wake(unsigned int irq, unsigned int on)
  316. {
  317. return nmk_gpio_irq_modify(irq, WAKE, on);
  318. }
  319. static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type)
  320. {
  321. struct irq_desc *desc = irq_to_desc(irq);
  322. bool enabled = !(desc->status & IRQ_DISABLED);
  323. bool wake = desc->wake_depth;
  324. int gpio;
  325. struct nmk_gpio_chip *nmk_chip;
  326. unsigned long flags;
  327. u32 bitmask;
  328. gpio = NOMADIK_IRQ_TO_GPIO(irq);
  329. nmk_chip = get_irq_chip_data(irq);
  330. bitmask = nmk_gpio_get_bitmask(gpio);
  331. if (!nmk_chip)
  332. return -EINVAL;
  333. if (type & IRQ_TYPE_LEVEL_HIGH)
  334. return -EINVAL;
  335. if (type & IRQ_TYPE_LEVEL_LOW)
  336. return -EINVAL;
  337. spin_lock_irqsave(&nmk_chip->lock, flags);
  338. if (enabled)
  339. __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, false);
  340. if (wake)
  341. __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, false);
  342. nmk_chip->edge_rising &= ~bitmask;
  343. if (type & IRQ_TYPE_EDGE_RISING)
  344. nmk_chip->edge_rising |= bitmask;
  345. nmk_chip->edge_falling &= ~bitmask;
  346. if (type & IRQ_TYPE_EDGE_FALLING)
  347. nmk_chip->edge_falling |= bitmask;
  348. if (enabled)
  349. __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, true);
  350. if (wake)
  351. __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, true);
  352. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  353. return 0;
  354. }
  355. static struct irq_chip nmk_gpio_irq_chip = {
  356. .name = "Nomadik-GPIO",
  357. .ack = nmk_gpio_irq_ack,
  358. .mask = nmk_gpio_irq_mask,
  359. .unmask = nmk_gpio_irq_unmask,
  360. .set_type = nmk_gpio_irq_set_type,
  361. .set_wake = nmk_gpio_irq_set_wake,
  362. };
  363. static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
  364. {
  365. struct nmk_gpio_chip *nmk_chip;
  366. struct irq_chip *host_chip = get_irq_chip(irq);
  367. unsigned int gpio_irq;
  368. u32 pending;
  369. unsigned int first_irq;
  370. if (host_chip->mask_ack)
  371. host_chip->mask_ack(irq);
  372. else {
  373. host_chip->mask(irq);
  374. if (host_chip->ack)
  375. host_chip->ack(irq);
  376. }
  377. nmk_chip = get_irq_data(irq);
  378. first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base);
  379. while ( (pending = readl(nmk_chip->addr + NMK_GPIO_IS)) ) {
  380. gpio_irq = first_irq + __ffs(pending);
  381. generic_handle_irq(gpio_irq);
  382. }
  383. host_chip->unmask(irq);
  384. }
  385. static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip)
  386. {
  387. unsigned int first_irq;
  388. int i;
  389. first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base);
  390. for (i = first_irq; i < first_irq + NMK_GPIO_PER_CHIP; i++) {
  391. set_irq_chip(i, &nmk_gpio_irq_chip);
  392. set_irq_handler(i, handle_edge_irq);
  393. set_irq_flags(i, IRQF_VALID);
  394. set_irq_chip_data(i, nmk_chip);
  395. set_irq_type(i, IRQ_TYPE_EDGE_FALLING);
  396. }
  397. set_irq_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler);
  398. set_irq_data(nmk_chip->parent_irq, nmk_chip);
  399. return 0;
  400. }
  401. /* I/O Functions */
  402. static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset)
  403. {
  404. struct nmk_gpio_chip *nmk_chip =
  405. container_of(chip, struct nmk_gpio_chip, chip);
  406. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
  407. return 0;
  408. }
  409. static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset)
  410. {
  411. struct nmk_gpio_chip *nmk_chip =
  412. container_of(chip, struct nmk_gpio_chip, chip);
  413. u32 bit = 1 << offset;
  414. return (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0;
  415. }
  416. static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset,
  417. int val)
  418. {
  419. struct nmk_gpio_chip *nmk_chip =
  420. container_of(chip, struct nmk_gpio_chip, chip);
  421. u32 bit = 1 << offset;
  422. if (val)
  423. writel(bit, nmk_chip->addr + NMK_GPIO_DATS);
  424. else
  425. writel(bit, nmk_chip->addr + NMK_GPIO_DATC);
  426. }
  427. static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
  428. int val)
  429. {
  430. struct nmk_gpio_chip *nmk_chip =
  431. container_of(chip, struct nmk_gpio_chip, chip);
  432. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS);
  433. nmk_gpio_set_output(chip, offset, val);
  434. return 0;
  435. }
  436. static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  437. {
  438. struct nmk_gpio_chip *nmk_chip =
  439. container_of(chip, struct nmk_gpio_chip, chip);
  440. return NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base) + offset;
  441. }
  442. /* This structure is replicated for each GPIO block allocated at probe time */
  443. static struct gpio_chip nmk_gpio_template = {
  444. .direction_input = nmk_gpio_make_input,
  445. .get = nmk_gpio_get_input,
  446. .direction_output = nmk_gpio_make_output,
  447. .set = nmk_gpio_set_output,
  448. .to_irq = nmk_gpio_to_irq,
  449. .ngpio = NMK_GPIO_PER_CHIP,
  450. .can_sleep = 0,
  451. };
  452. static int __init nmk_gpio_probe(struct platform_device *dev)
  453. {
  454. struct nmk_gpio_platform_data *pdata = dev->dev.platform_data;
  455. struct nmk_gpio_chip *nmk_chip;
  456. struct gpio_chip *chip;
  457. struct resource *res;
  458. struct clk *clk;
  459. int irq;
  460. int ret;
  461. if (!pdata)
  462. return -ENODEV;
  463. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  464. if (!res) {
  465. ret = -ENOENT;
  466. goto out;
  467. }
  468. irq = platform_get_irq(dev, 0);
  469. if (irq < 0) {
  470. ret = irq;
  471. goto out;
  472. }
  473. if (request_mem_region(res->start, resource_size(res),
  474. dev_name(&dev->dev)) == NULL) {
  475. ret = -EBUSY;
  476. goto out;
  477. }
  478. clk = clk_get(&dev->dev, NULL);
  479. if (IS_ERR(clk)) {
  480. ret = PTR_ERR(clk);
  481. goto out_release;
  482. }
  483. clk_enable(clk);
  484. nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL);
  485. if (!nmk_chip) {
  486. ret = -ENOMEM;
  487. goto out_clk;
  488. }
  489. /*
  490. * The virt address in nmk_chip->addr is in the nomadik register space,
  491. * so we can simply convert the resource address, without remapping
  492. */
  493. nmk_chip->clk = clk;
  494. nmk_chip->addr = io_p2v(res->start);
  495. nmk_chip->chip = nmk_gpio_template;
  496. nmk_chip->parent_irq = irq;
  497. spin_lock_init(&nmk_chip->lock);
  498. chip = &nmk_chip->chip;
  499. chip->base = pdata->first_gpio;
  500. chip->label = pdata->name;
  501. chip->dev = &dev->dev;
  502. chip->owner = THIS_MODULE;
  503. ret = gpiochip_add(&nmk_chip->chip);
  504. if (ret)
  505. goto out_free;
  506. platform_set_drvdata(dev, nmk_chip);
  507. nmk_gpio_init_irq(nmk_chip);
  508. dev_info(&dev->dev, "Bits %i-%i at address %p\n",
  509. nmk_chip->chip.base, nmk_chip->chip.base+31, nmk_chip->addr);
  510. return 0;
  511. out_free:
  512. kfree(nmk_chip);
  513. out_clk:
  514. clk_disable(clk);
  515. clk_put(clk);
  516. out_release:
  517. release_mem_region(res->start, resource_size(res));
  518. out:
  519. dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret,
  520. pdata->first_gpio, pdata->first_gpio+31);
  521. return ret;
  522. }
  523. static struct platform_driver nmk_gpio_driver = {
  524. .driver = {
  525. .owner = THIS_MODULE,
  526. .name = "gpio",
  527. },
  528. .probe = nmk_gpio_probe,
  529. .suspend = NULL, /* to be done */
  530. .resume = NULL,
  531. };
  532. static int __init nmk_gpio_init(void)
  533. {
  534. return platform_driver_register(&nmk_gpio_driver);
  535. }
  536. core_initcall(nmk_gpio_init);
  537. MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini");
  538. MODULE_DESCRIPTION("Nomadik GPIO Driver");
  539. MODULE_LICENSE("GPL");