pinctrl-nomadik.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  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. * Copyright (C) 2011 Linus Walleij <linus.walleij@linaro.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/io.h>
  19. #include <linux/clk.h>
  20. #include <linux/err.h>
  21. #include <linux/gpio.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/irqdomain.h>
  26. #include <linux/slab.h>
  27. #include <linux/pinctrl/pinctrl.h>
  28. #include <linux/pinctrl/pinmux.h>
  29. #include <linux/pinctrl/pinconf.h>
  30. /* Since we request GPIOs from ourself */
  31. #include <linux/pinctrl/consumer.h>
  32. #include <asm/mach/irq.h>
  33. #include <plat/pincfg.h>
  34. #include <plat/gpio-nomadik.h>
  35. #include "pinctrl-nomadik.h"
  36. /*
  37. * The GPIO module in the Nomadik family of Systems-on-Chip is an
  38. * AMBA device, managing 32 pins and alternate functions. The logic block
  39. * is currently used in the Nomadik and ux500.
  40. *
  41. * Symbols in this file are called "nmk_gpio" for "nomadik gpio"
  42. */
  43. #define NMK_GPIO_PER_CHIP 32
  44. struct nmk_gpio_chip {
  45. struct gpio_chip chip;
  46. struct irq_domain *domain;
  47. void __iomem *addr;
  48. struct clk *clk;
  49. unsigned int bank;
  50. unsigned int parent_irq;
  51. int secondary_parent_irq;
  52. u32 (*get_secondary_status)(unsigned int bank);
  53. void (*set_ioforce)(bool enable);
  54. spinlock_t lock;
  55. bool sleepmode;
  56. /* Keep track of configured edges */
  57. u32 edge_rising;
  58. u32 edge_falling;
  59. u32 real_wake;
  60. u32 rwimsc;
  61. u32 fwimsc;
  62. u32 rimsc;
  63. u32 fimsc;
  64. u32 pull_up;
  65. u32 lowemi;
  66. };
  67. struct nmk_pinctrl {
  68. struct device *dev;
  69. struct pinctrl_dev *pctl;
  70. const struct nmk_pinctrl_soc_data *soc;
  71. };
  72. static struct nmk_gpio_chip *
  73. nmk_gpio_chips[DIV_ROUND_UP(ARCH_NR_GPIOS, NMK_GPIO_PER_CHIP)];
  74. static DEFINE_SPINLOCK(nmk_gpio_slpm_lock);
  75. #define NUM_BANKS ARRAY_SIZE(nmk_gpio_chips)
  76. static void __nmk_gpio_set_mode(struct nmk_gpio_chip *nmk_chip,
  77. unsigned offset, int gpio_mode)
  78. {
  79. u32 bit = 1 << offset;
  80. u32 afunc, bfunc;
  81. afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit;
  82. bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit;
  83. if (gpio_mode & NMK_GPIO_ALT_A)
  84. afunc |= bit;
  85. if (gpio_mode & NMK_GPIO_ALT_B)
  86. bfunc |= bit;
  87. writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA);
  88. writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB);
  89. }
  90. static void __nmk_gpio_set_slpm(struct nmk_gpio_chip *nmk_chip,
  91. unsigned offset, enum nmk_gpio_slpm mode)
  92. {
  93. u32 bit = 1 << offset;
  94. u32 slpm;
  95. slpm = readl(nmk_chip->addr + NMK_GPIO_SLPC);
  96. if (mode == NMK_GPIO_SLPM_NOCHANGE)
  97. slpm |= bit;
  98. else
  99. slpm &= ~bit;
  100. writel(slpm, nmk_chip->addr + NMK_GPIO_SLPC);
  101. }
  102. static void __nmk_gpio_set_pull(struct nmk_gpio_chip *nmk_chip,
  103. unsigned offset, enum nmk_gpio_pull pull)
  104. {
  105. u32 bit = 1 << offset;
  106. u32 pdis;
  107. pdis = readl(nmk_chip->addr + NMK_GPIO_PDIS);
  108. if (pull == NMK_GPIO_PULL_NONE) {
  109. pdis |= bit;
  110. nmk_chip->pull_up &= ~bit;
  111. } else {
  112. pdis &= ~bit;
  113. }
  114. writel(pdis, nmk_chip->addr + NMK_GPIO_PDIS);
  115. if (pull == NMK_GPIO_PULL_UP) {
  116. nmk_chip->pull_up |= bit;
  117. writel(bit, nmk_chip->addr + NMK_GPIO_DATS);
  118. } else if (pull == NMK_GPIO_PULL_DOWN) {
  119. nmk_chip->pull_up &= ~bit;
  120. writel(bit, nmk_chip->addr + NMK_GPIO_DATC);
  121. }
  122. }
  123. static void __nmk_gpio_set_lowemi(struct nmk_gpio_chip *nmk_chip,
  124. unsigned offset, bool lowemi)
  125. {
  126. u32 bit = BIT(offset);
  127. bool enabled = nmk_chip->lowemi & bit;
  128. if (lowemi == enabled)
  129. return;
  130. if (lowemi)
  131. nmk_chip->lowemi |= bit;
  132. else
  133. nmk_chip->lowemi &= ~bit;
  134. writel_relaxed(nmk_chip->lowemi,
  135. nmk_chip->addr + NMK_GPIO_LOWEMI);
  136. }
  137. static void __nmk_gpio_make_input(struct nmk_gpio_chip *nmk_chip,
  138. unsigned offset)
  139. {
  140. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
  141. }
  142. static void __nmk_gpio_set_output(struct nmk_gpio_chip *nmk_chip,
  143. unsigned offset, int val)
  144. {
  145. if (val)
  146. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATS);
  147. else
  148. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATC);
  149. }
  150. static void __nmk_gpio_make_output(struct nmk_gpio_chip *nmk_chip,
  151. unsigned offset, int val)
  152. {
  153. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS);
  154. __nmk_gpio_set_output(nmk_chip, offset, val);
  155. }
  156. static void __nmk_gpio_set_mode_safe(struct nmk_gpio_chip *nmk_chip,
  157. unsigned offset, int gpio_mode,
  158. bool glitch)
  159. {
  160. u32 rwimsc = nmk_chip->rwimsc;
  161. u32 fwimsc = nmk_chip->fwimsc;
  162. if (glitch && nmk_chip->set_ioforce) {
  163. u32 bit = BIT(offset);
  164. /* Prevent spurious wakeups */
  165. writel(rwimsc & ~bit, nmk_chip->addr + NMK_GPIO_RWIMSC);
  166. writel(fwimsc & ~bit, nmk_chip->addr + NMK_GPIO_FWIMSC);
  167. nmk_chip->set_ioforce(true);
  168. }
  169. __nmk_gpio_set_mode(nmk_chip, offset, gpio_mode);
  170. if (glitch && nmk_chip->set_ioforce) {
  171. nmk_chip->set_ioforce(false);
  172. writel(rwimsc, nmk_chip->addr + NMK_GPIO_RWIMSC);
  173. writel(fwimsc, nmk_chip->addr + NMK_GPIO_FWIMSC);
  174. }
  175. }
  176. static void
  177. nmk_gpio_disable_lazy_irq(struct nmk_gpio_chip *nmk_chip, unsigned offset)
  178. {
  179. u32 falling = nmk_chip->fimsc & BIT(offset);
  180. u32 rising = nmk_chip->rimsc & BIT(offset);
  181. int gpio = nmk_chip->chip.base + offset;
  182. int irq = NOMADIK_GPIO_TO_IRQ(gpio);
  183. struct irq_data *d = irq_get_irq_data(irq);
  184. if (!rising && !falling)
  185. return;
  186. if (!d || !irqd_irq_disabled(d))
  187. return;
  188. if (rising) {
  189. nmk_chip->rimsc &= ~BIT(offset);
  190. writel_relaxed(nmk_chip->rimsc,
  191. nmk_chip->addr + NMK_GPIO_RIMSC);
  192. }
  193. if (falling) {
  194. nmk_chip->fimsc &= ~BIT(offset);
  195. writel_relaxed(nmk_chip->fimsc,
  196. nmk_chip->addr + NMK_GPIO_FIMSC);
  197. }
  198. dev_dbg(nmk_chip->chip.dev, "%d: clearing interrupt mask\n", gpio);
  199. }
  200. static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset,
  201. pin_cfg_t cfg, bool sleep, unsigned int *slpmregs)
  202. {
  203. static const char *afnames[] = {
  204. [NMK_GPIO_ALT_GPIO] = "GPIO",
  205. [NMK_GPIO_ALT_A] = "A",
  206. [NMK_GPIO_ALT_B] = "B",
  207. [NMK_GPIO_ALT_C] = "C"
  208. };
  209. static const char *pullnames[] = {
  210. [NMK_GPIO_PULL_NONE] = "none",
  211. [NMK_GPIO_PULL_UP] = "up",
  212. [NMK_GPIO_PULL_DOWN] = "down",
  213. [3] /* illegal */ = "??"
  214. };
  215. static const char *slpmnames[] = {
  216. [NMK_GPIO_SLPM_INPUT] = "input/wakeup",
  217. [NMK_GPIO_SLPM_NOCHANGE] = "no-change/no-wakeup",
  218. };
  219. int pin = PIN_NUM(cfg);
  220. int pull = PIN_PULL(cfg);
  221. int af = PIN_ALT(cfg);
  222. int slpm = PIN_SLPM(cfg);
  223. int output = PIN_DIR(cfg);
  224. int val = PIN_VAL(cfg);
  225. bool glitch = af == NMK_GPIO_ALT_C;
  226. dev_dbg(nmk_chip->chip.dev, "pin %d [%#lx]: af %s, pull %s, slpm %s (%s%s)\n",
  227. pin, cfg, afnames[af], pullnames[pull], slpmnames[slpm],
  228. output ? "output " : "input",
  229. output ? (val ? "high" : "low") : "");
  230. if (sleep) {
  231. int slpm_pull = PIN_SLPM_PULL(cfg);
  232. int slpm_output = PIN_SLPM_DIR(cfg);
  233. int slpm_val = PIN_SLPM_VAL(cfg);
  234. af = NMK_GPIO_ALT_GPIO;
  235. /*
  236. * The SLPM_* values are normal values + 1 to allow zero to
  237. * mean "same as normal".
  238. */
  239. if (slpm_pull)
  240. pull = slpm_pull - 1;
  241. if (slpm_output)
  242. output = slpm_output - 1;
  243. if (slpm_val)
  244. val = slpm_val - 1;
  245. dev_dbg(nmk_chip->chip.dev, "pin %d: sleep pull %s, dir %s, val %s\n",
  246. pin,
  247. slpm_pull ? pullnames[pull] : "same",
  248. slpm_output ? (output ? "output" : "input") : "same",
  249. slpm_val ? (val ? "high" : "low") : "same");
  250. }
  251. if (output)
  252. __nmk_gpio_make_output(nmk_chip, offset, val);
  253. else {
  254. __nmk_gpio_make_input(nmk_chip, offset);
  255. __nmk_gpio_set_pull(nmk_chip, offset, pull);
  256. }
  257. __nmk_gpio_set_lowemi(nmk_chip, offset, PIN_LOWEMI(cfg));
  258. /*
  259. * If the pin is switching to altfunc, and there was an interrupt
  260. * installed on it which has been lazy disabled, actually mask the
  261. * interrupt to prevent spurious interrupts that would occur while the
  262. * pin is under control of the peripheral. Only SKE does this.
  263. */
  264. if (af != NMK_GPIO_ALT_GPIO)
  265. nmk_gpio_disable_lazy_irq(nmk_chip, offset);
  266. /*
  267. * If we've backed up the SLPM registers (glitch workaround), modify
  268. * the backups since they will be restored.
  269. */
  270. if (slpmregs) {
  271. if (slpm == NMK_GPIO_SLPM_NOCHANGE)
  272. slpmregs[nmk_chip->bank] |= BIT(offset);
  273. else
  274. slpmregs[nmk_chip->bank] &= ~BIT(offset);
  275. } else
  276. __nmk_gpio_set_slpm(nmk_chip, offset, slpm);
  277. __nmk_gpio_set_mode_safe(nmk_chip, offset, af, glitch);
  278. }
  279. /*
  280. * Safe sequence used to switch IOs between GPIO and Alternate-C mode:
  281. * - Save SLPM registers
  282. * - Set SLPM=0 for the IOs you want to switch and others to 1
  283. * - Configure the GPIO registers for the IOs that are being switched
  284. * - Set IOFORCE=1
  285. * - Modify the AFLSA/B registers for the IOs that are being switched
  286. * - Set IOFORCE=0
  287. * - Restore SLPM registers
  288. * - Any spurious wake up event during switch sequence to be ignored and
  289. * cleared
  290. */
  291. static void nmk_gpio_glitch_slpm_init(unsigned int *slpm)
  292. {
  293. int i;
  294. for (i = 0; i < NUM_BANKS; i++) {
  295. struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
  296. unsigned int temp = slpm[i];
  297. if (!chip)
  298. break;
  299. clk_enable(chip->clk);
  300. slpm[i] = readl(chip->addr + NMK_GPIO_SLPC);
  301. writel(temp, chip->addr + NMK_GPIO_SLPC);
  302. }
  303. }
  304. static void nmk_gpio_glitch_slpm_restore(unsigned int *slpm)
  305. {
  306. int i;
  307. for (i = 0; i < NUM_BANKS; i++) {
  308. struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
  309. if (!chip)
  310. break;
  311. writel(slpm[i], chip->addr + NMK_GPIO_SLPC);
  312. clk_disable(chip->clk);
  313. }
  314. }
  315. static int __nmk_config_pins(pin_cfg_t *cfgs, int num, bool sleep)
  316. {
  317. static unsigned int slpm[NUM_BANKS];
  318. unsigned long flags;
  319. bool glitch = false;
  320. int ret = 0;
  321. int i;
  322. for (i = 0; i < num; i++) {
  323. if (PIN_ALT(cfgs[i]) == NMK_GPIO_ALT_C) {
  324. glitch = true;
  325. break;
  326. }
  327. }
  328. spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
  329. if (glitch) {
  330. memset(slpm, 0xff, sizeof(slpm));
  331. for (i = 0; i < num; i++) {
  332. int pin = PIN_NUM(cfgs[i]);
  333. int offset = pin % NMK_GPIO_PER_CHIP;
  334. if (PIN_ALT(cfgs[i]) == NMK_GPIO_ALT_C)
  335. slpm[pin / NMK_GPIO_PER_CHIP] &= ~BIT(offset);
  336. }
  337. nmk_gpio_glitch_slpm_init(slpm);
  338. }
  339. for (i = 0; i < num; i++) {
  340. struct nmk_gpio_chip *nmk_chip;
  341. int pin = PIN_NUM(cfgs[i]);
  342. nmk_chip = nmk_gpio_chips[pin / NMK_GPIO_PER_CHIP];
  343. if (!nmk_chip) {
  344. ret = -EINVAL;
  345. break;
  346. }
  347. clk_enable(nmk_chip->clk);
  348. spin_lock(&nmk_chip->lock);
  349. __nmk_config_pin(nmk_chip, pin % NMK_GPIO_PER_CHIP,
  350. cfgs[i], sleep, glitch ? slpm : NULL);
  351. spin_unlock(&nmk_chip->lock);
  352. clk_disable(nmk_chip->clk);
  353. }
  354. if (glitch)
  355. nmk_gpio_glitch_slpm_restore(slpm);
  356. spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
  357. return ret;
  358. }
  359. /**
  360. * nmk_config_pin - configure a pin's mux attributes
  361. * @cfg: pin confguration
  362. *
  363. * Configures a pin's mode (alternate function or GPIO), its pull up status,
  364. * and its sleep mode based on the specified configuration. The @cfg is
  365. * usually one of the SoC specific macros defined in mach/<soc>-pins.h. These
  366. * are constructed using, and can be further enhanced with, the macros in
  367. * plat/pincfg.h.
  368. *
  369. * If a pin's mode is set to GPIO, it is configured as an input to avoid
  370. * side-effects. The gpio can be manipulated later using standard GPIO API
  371. * calls.
  372. */
  373. int nmk_config_pin(pin_cfg_t cfg, bool sleep)
  374. {
  375. return __nmk_config_pins(&cfg, 1, sleep);
  376. }
  377. EXPORT_SYMBOL(nmk_config_pin);
  378. /**
  379. * nmk_config_pins - configure several pins at once
  380. * @cfgs: array of pin configurations
  381. * @num: number of elments in the array
  382. *
  383. * Configures several pins using nmk_config_pin(). Refer to that function for
  384. * further information.
  385. */
  386. int nmk_config_pins(pin_cfg_t *cfgs, int num)
  387. {
  388. return __nmk_config_pins(cfgs, num, false);
  389. }
  390. EXPORT_SYMBOL(nmk_config_pins);
  391. int nmk_config_pins_sleep(pin_cfg_t *cfgs, int num)
  392. {
  393. return __nmk_config_pins(cfgs, num, true);
  394. }
  395. EXPORT_SYMBOL(nmk_config_pins_sleep);
  396. /**
  397. * nmk_gpio_set_slpm() - configure the sleep mode of a pin
  398. * @gpio: pin number
  399. * @mode: NMK_GPIO_SLPM_INPUT or NMK_GPIO_SLPM_NOCHANGE,
  400. *
  401. * This register is actually in the pinmux layer, not the GPIO block itself.
  402. * The GPIO1B_SLPM register defines the GPIO mode when SLEEP/DEEP-SLEEP
  403. * mode is entered (i.e. when signal IOFORCE is HIGH by the platform code).
  404. * Each GPIO can be configured to be forced into GPIO mode when IOFORCE is
  405. * HIGH, overriding the normal setting defined by GPIO_AFSELx registers.
  406. * When IOFORCE returns LOW (by software, after SLEEP/DEEP-SLEEP exit),
  407. * the GPIOs return to the normal setting defined by GPIO_AFSELx registers.
  408. *
  409. * If @mode is NMK_GPIO_SLPM_INPUT, the corresponding GPIO is switched to GPIO
  410. * mode when signal IOFORCE is HIGH (i.e. when SLEEP/DEEP-SLEEP mode is
  411. * entered) regardless of the altfunction selected. Also wake-up detection is
  412. * ENABLED.
  413. *
  414. * If @mode is NMK_GPIO_SLPM_NOCHANGE, the corresponding GPIO remains
  415. * controlled by NMK_GPIO_DATC, NMK_GPIO_DATS, NMK_GPIO_DIR, NMK_GPIO_PDIS
  416. * (for altfunction GPIO) or respective on-chip peripherals (for other
  417. * altfuncs) when IOFORCE is HIGH. Also wake-up detection DISABLED.
  418. *
  419. * Note that enable_irq_wake() will automatically enable wakeup detection.
  420. */
  421. int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
  422. {
  423. struct nmk_gpio_chip *nmk_chip;
  424. unsigned long flags;
  425. nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
  426. if (!nmk_chip)
  427. return -EINVAL;
  428. clk_enable(nmk_chip->clk);
  429. spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
  430. spin_lock(&nmk_chip->lock);
  431. __nmk_gpio_set_slpm(nmk_chip, gpio % NMK_GPIO_PER_CHIP, mode);
  432. spin_unlock(&nmk_chip->lock);
  433. spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
  434. clk_disable(nmk_chip->clk);
  435. return 0;
  436. }
  437. /**
  438. * nmk_gpio_set_pull() - enable/disable pull up/down on a gpio
  439. * @gpio: pin number
  440. * @pull: one of NMK_GPIO_PULL_DOWN, NMK_GPIO_PULL_UP, and NMK_GPIO_PULL_NONE
  441. *
  442. * Enables/disables pull up/down on a specified pin. This only takes effect if
  443. * the pin is configured as an input (either explicitly or by the alternate
  444. * function).
  445. *
  446. * NOTE: If enabling the pull up/down, the caller must ensure that the GPIO is
  447. * configured as an input. Otherwise, due to the way the controller registers
  448. * work, this function will change the value output on the pin.
  449. */
  450. int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull)
  451. {
  452. struct nmk_gpio_chip *nmk_chip;
  453. unsigned long flags;
  454. nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
  455. if (!nmk_chip)
  456. return -EINVAL;
  457. clk_enable(nmk_chip->clk);
  458. spin_lock_irqsave(&nmk_chip->lock, flags);
  459. __nmk_gpio_set_pull(nmk_chip, gpio % NMK_GPIO_PER_CHIP, pull);
  460. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  461. clk_disable(nmk_chip->clk);
  462. return 0;
  463. }
  464. /* Mode functions */
  465. /**
  466. * nmk_gpio_set_mode() - set the mux mode of a gpio pin
  467. * @gpio: pin number
  468. * @gpio_mode: one of NMK_GPIO_ALT_GPIO, NMK_GPIO_ALT_A,
  469. * NMK_GPIO_ALT_B, and NMK_GPIO_ALT_C
  470. *
  471. * Sets the mode of the specified pin to one of the alternate functions or
  472. * plain GPIO.
  473. */
  474. int nmk_gpio_set_mode(int gpio, int gpio_mode)
  475. {
  476. struct nmk_gpio_chip *nmk_chip;
  477. unsigned long flags;
  478. nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
  479. if (!nmk_chip)
  480. return -EINVAL;
  481. clk_enable(nmk_chip->clk);
  482. spin_lock_irqsave(&nmk_chip->lock, flags);
  483. __nmk_gpio_set_mode(nmk_chip, gpio % NMK_GPIO_PER_CHIP, gpio_mode);
  484. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  485. clk_disable(nmk_chip->clk);
  486. return 0;
  487. }
  488. EXPORT_SYMBOL(nmk_gpio_set_mode);
  489. int nmk_gpio_get_mode(int gpio)
  490. {
  491. struct nmk_gpio_chip *nmk_chip;
  492. u32 afunc, bfunc, bit;
  493. nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
  494. if (!nmk_chip)
  495. return -EINVAL;
  496. bit = 1 << (gpio % NMK_GPIO_PER_CHIP);
  497. clk_enable(nmk_chip->clk);
  498. afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit;
  499. bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit;
  500. clk_disable(nmk_chip->clk);
  501. return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0);
  502. }
  503. EXPORT_SYMBOL(nmk_gpio_get_mode);
  504. /* IRQ functions */
  505. static inline int nmk_gpio_get_bitmask(int gpio)
  506. {
  507. return 1 << (gpio % NMK_GPIO_PER_CHIP);
  508. }
  509. static void nmk_gpio_irq_ack(struct irq_data *d)
  510. {
  511. struct nmk_gpio_chip *nmk_chip;
  512. nmk_chip = irq_data_get_irq_chip_data(d);
  513. if (!nmk_chip)
  514. return;
  515. clk_enable(nmk_chip->clk);
  516. writel(nmk_gpio_get_bitmask(d->hwirq), nmk_chip->addr + NMK_GPIO_IC);
  517. clk_disable(nmk_chip->clk);
  518. }
  519. enum nmk_gpio_irq_type {
  520. NORMAL,
  521. WAKE,
  522. };
  523. static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip,
  524. int gpio, enum nmk_gpio_irq_type which,
  525. bool enable)
  526. {
  527. u32 bitmask = nmk_gpio_get_bitmask(gpio);
  528. u32 *rimscval;
  529. u32 *fimscval;
  530. u32 rimscreg;
  531. u32 fimscreg;
  532. if (which == NORMAL) {
  533. rimscreg = NMK_GPIO_RIMSC;
  534. fimscreg = NMK_GPIO_FIMSC;
  535. rimscval = &nmk_chip->rimsc;
  536. fimscval = &nmk_chip->fimsc;
  537. } else {
  538. rimscreg = NMK_GPIO_RWIMSC;
  539. fimscreg = NMK_GPIO_FWIMSC;
  540. rimscval = &nmk_chip->rwimsc;
  541. fimscval = &nmk_chip->fwimsc;
  542. }
  543. /* we must individually set/clear the two edges */
  544. if (nmk_chip->edge_rising & bitmask) {
  545. if (enable)
  546. *rimscval |= bitmask;
  547. else
  548. *rimscval &= ~bitmask;
  549. writel(*rimscval, nmk_chip->addr + rimscreg);
  550. }
  551. if (nmk_chip->edge_falling & bitmask) {
  552. if (enable)
  553. *fimscval |= bitmask;
  554. else
  555. *fimscval &= ~bitmask;
  556. writel(*fimscval, nmk_chip->addr + fimscreg);
  557. }
  558. }
  559. static void __nmk_gpio_set_wake(struct nmk_gpio_chip *nmk_chip,
  560. int gpio, bool on)
  561. {
  562. /*
  563. * Ensure WAKEUP_ENABLE is on. No need to disable it if wakeup is
  564. * disabled, since setting SLPM to 1 increases power consumption, and
  565. * wakeup is anyhow controlled by the RIMSC and FIMSC registers.
  566. */
  567. if (nmk_chip->sleepmode && on) {
  568. __nmk_gpio_set_slpm(nmk_chip, gpio % nmk_chip->chip.base,
  569. NMK_GPIO_SLPM_WAKEUP_ENABLE);
  570. }
  571. __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, on);
  572. }
  573. static int nmk_gpio_irq_maskunmask(struct irq_data *d, bool enable)
  574. {
  575. struct nmk_gpio_chip *nmk_chip;
  576. unsigned long flags;
  577. u32 bitmask;
  578. nmk_chip = irq_data_get_irq_chip_data(d);
  579. bitmask = nmk_gpio_get_bitmask(d->hwirq);
  580. if (!nmk_chip)
  581. return -EINVAL;
  582. clk_enable(nmk_chip->clk);
  583. spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
  584. spin_lock(&nmk_chip->lock);
  585. __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, enable);
  586. if (!(nmk_chip->real_wake & bitmask))
  587. __nmk_gpio_set_wake(nmk_chip, d->hwirq, enable);
  588. spin_unlock(&nmk_chip->lock);
  589. spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
  590. clk_disable(nmk_chip->clk);
  591. return 0;
  592. }
  593. static void nmk_gpio_irq_mask(struct irq_data *d)
  594. {
  595. nmk_gpio_irq_maskunmask(d, false);
  596. }
  597. static void nmk_gpio_irq_unmask(struct irq_data *d)
  598. {
  599. nmk_gpio_irq_maskunmask(d, true);
  600. }
  601. static int nmk_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
  602. {
  603. struct nmk_gpio_chip *nmk_chip;
  604. unsigned long flags;
  605. u32 bitmask;
  606. nmk_chip = irq_data_get_irq_chip_data(d);
  607. if (!nmk_chip)
  608. return -EINVAL;
  609. bitmask = nmk_gpio_get_bitmask(d->hwirq);
  610. clk_enable(nmk_chip->clk);
  611. spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
  612. spin_lock(&nmk_chip->lock);
  613. if (irqd_irq_disabled(d))
  614. __nmk_gpio_set_wake(nmk_chip, d->hwirq, on);
  615. if (on)
  616. nmk_chip->real_wake |= bitmask;
  617. else
  618. nmk_chip->real_wake &= ~bitmask;
  619. spin_unlock(&nmk_chip->lock);
  620. spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
  621. clk_disable(nmk_chip->clk);
  622. return 0;
  623. }
  624. static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
  625. {
  626. bool enabled = !irqd_irq_disabled(d);
  627. bool wake = irqd_is_wakeup_set(d);
  628. struct nmk_gpio_chip *nmk_chip;
  629. unsigned long flags;
  630. u32 bitmask;
  631. nmk_chip = irq_data_get_irq_chip_data(d);
  632. bitmask = nmk_gpio_get_bitmask(d->hwirq);
  633. if (!nmk_chip)
  634. return -EINVAL;
  635. if (type & IRQ_TYPE_LEVEL_HIGH)
  636. return -EINVAL;
  637. if (type & IRQ_TYPE_LEVEL_LOW)
  638. return -EINVAL;
  639. clk_enable(nmk_chip->clk);
  640. spin_lock_irqsave(&nmk_chip->lock, flags);
  641. if (enabled)
  642. __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, false);
  643. if (enabled || wake)
  644. __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, false);
  645. nmk_chip->edge_rising &= ~bitmask;
  646. if (type & IRQ_TYPE_EDGE_RISING)
  647. nmk_chip->edge_rising |= bitmask;
  648. nmk_chip->edge_falling &= ~bitmask;
  649. if (type & IRQ_TYPE_EDGE_FALLING)
  650. nmk_chip->edge_falling |= bitmask;
  651. if (enabled)
  652. __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, true);
  653. if (enabled || wake)
  654. __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, true);
  655. spin_unlock_irqrestore(&nmk_chip->lock, flags);
  656. clk_disable(nmk_chip->clk);
  657. return 0;
  658. }
  659. static unsigned int nmk_gpio_irq_startup(struct irq_data *d)
  660. {
  661. struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d);
  662. clk_enable(nmk_chip->clk);
  663. nmk_gpio_irq_unmask(d);
  664. return 0;
  665. }
  666. static void nmk_gpio_irq_shutdown(struct irq_data *d)
  667. {
  668. struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d);
  669. nmk_gpio_irq_mask(d);
  670. clk_disable(nmk_chip->clk);
  671. }
  672. static struct irq_chip nmk_gpio_irq_chip = {
  673. .name = "Nomadik-GPIO",
  674. .irq_ack = nmk_gpio_irq_ack,
  675. .irq_mask = nmk_gpio_irq_mask,
  676. .irq_unmask = nmk_gpio_irq_unmask,
  677. .irq_set_type = nmk_gpio_irq_set_type,
  678. .irq_set_wake = nmk_gpio_irq_set_wake,
  679. .irq_startup = nmk_gpio_irq_startup,
  680. .irq_shutdown = nmk_gpio_irq_shutdown,
  681. };
  682. static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc,
  683. u32 status)
  684. {
  685. struct nmk_gpio_chip *nmk_chip;
  686. struct irq_chip *host_chip = irq_get_chip(irq);
  687. unsigned int first_irq;
  688. chained_irq_enter(host_chip, desc);
  689. nmk_chip = irq_get_handler_data(irq);
  690. first_irq = nmk_chip->domain->revmap_data.legacy.first_irq;
  691. while (status) {
  692. int bit = __ffs(status);
  693. generic_handle_irq(first_irq + bit);
  694. status &= ~BIT(bit);
  695. }
  696. chained_irq_exit(host_chip, desc);
  697. }
  698. static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
  699. {
  700. struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq);
  701. u32 status;
  702. clk_enable(nmk_chip->clk);
  703. status = readl(nmk_chip->addr + NMK_GPIO_IS);
  704. clk_disable(nmk_chip->clk);
  705. __nmk_gpio_irq_handler(irq, desc, status);
  706. }
  707. static void nmk_gpio_secondary_irq_handler(unsigned int irq,
  708. struct irq_desc *desc)
  709. {
  710. struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq);
  711. u32 status = nmk_chip->get_secondary_status(nmk_chip->bank);
  712. __nmk_gpio_irq_handler(irq, desc, status);
  713. }
  714. static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip)
  715. {
  716. irq_set_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler);
  717. irq_set_handler_data(nmk_chip->parent_irq, nmk_chip);
  718. if (nmk_chip->secondary_parent_irq >= 0) {
  719. irq_set_chained_handler(nmk_chip->secondary_parent_irq,
  720. nmk_gpio_secondary_irq_handler);
  721. irq_set_handler_data(nmk_chip->secondary_parent_irq, nmk_chip);
  722. }
  723. return 0;
  724. }
  725. /* I/O Functions */
  726. static int nmk_gpio_request(struct gpio_chip *chip, unsigned offset)
  727. {
  728. /*
  729. * Map back to global GPIO space and request muxing, the direction
  730. * parameter does not matter for this controller.
  731. */
  732. int gpio = chip->base + offset;
  733. return pinctrl_request_gpio(gpio);
  734. }
  735. static void nmk_gpio_free(struct gpio_chip *chip, unsigned offset)
  736. {
  737. int gpio = chip->base + offset;
  738. pinctrl_free_gpio(gpio);
  739. }
  740. static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset)
  741. {
  742. struct nmk_gpio_chip *nmk_chip =
  743. container_of(chip, struct nmk_gpio_chip, chip);
  744. clk_enable(nmk_chip->clk);
  745. writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
  746. clk_disable(nmk_chip->clk);
  747. return 0;
  748. }
  749. static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset)
  750. {
  751. struct nmk_gpio_chip *nmk_chip =
  752. container_of(chip, struct nmk_gpio_chip, chip);
  753. u32 bit = 1 << offset;
  754. int value;
  755. clk_enable(nmk_chip->clk);
  756. value = (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0;
  757. clk_disable(nmk_chip->clk);
  758. return value;
  759. }
  760. static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset,
  761. int val)
  762. {
  763. struct nmk_gpio_chip *nmk_chip =
  764. container_of(chip, struct nmk_gpio_chip, chip);
  765. clk_enable(nmk_chip->clk);
  766. __nmk_gpio_set_output(nmk_chip, offset, val);
  767. clk_disable(nmk_chip->clk);
  768. }
  769. static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
  770. int val)
  771. {
  772. struct nmk_gpio_chip *nmk_chip =
  773. container_of(chip, struct nmk_gpio_chip, chip);
  774. clk_enable(nmk_chip->clk);
  775. __nmk_gpio_make_output(nmk_chip, offset, val);
  776. clk_disable(nmk_chip->clk);
  777. return 0;
  778. }
  779. static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  780. {
  781. struct nmk_gpio_chip *nmk_chip =
  782. container_of(chip, struct nmk_gpio_chip, chip);
  783. return irq_find_mapping(nmk_chip->domain, offset);
  784. }
  785. #ifdef CONFIG_DEBUG_FS
  786. #include <linux/seq_file.h>
  787. static void nmk_gpio_dbg_show_one(struct seq_file *s, struct gpio_chip *chip,
  788. unsigned offset, unsigned gpio)
  789. {
  790. const char *label = gpiochip_is_requested(chip, offset);
  791. struct nmk_gpio_chip *nmk_chip =
  792. container_of(chip, struct nmk_gpio_chip, chip);
  793. int mode;
  794. bool is_out;
  795. bool pull;
  796. u32 bit = 1 << offset;
  797. const char *modes[] = {
  798. [NMK_GPIO_ALT_GPIO] = "gpio",
  799. [NMK_GPIO_ALT_A] = "altA",
  800. [NMK_GPIO_ALT_B] = "altB",
  801. [NMK_GPIO_ALT_C] = "altC",
  802. };
  803. clk_enable(nmk_chip->clk);
  804. is_out = !!(readl(nmk_chip->addr + NMK_GPIO_DIR) & bit);
  805. pull = !(readl(nmk_chip->addr + NMK_GPIO_PDIS) & bit);
  806. mode = nmk_gpio_get_mode(gpio);
  807. seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s %s",
  808. gpio, label ?: "(none)",
  809. is_out ? "out" : "in ",
  810. chip->get
  811. ? (chip->get(chip, offset) ? "hi" : "lo")
  812. : "? ",
  813. (mode < 0) ? "unknown" : modes[mode],
  814. pull ? "pull" : "none");
  815. if (label && !is_out) {
  816. int irq = gpio_to_irq(gpio);
  817. struct irq_desc *desc = irq_to_desc(irq);
  818. /* This races with request_irq(), set_irq_type(),
  819. * and set_irq_wake() ... but those are "rare".
  820. */
  821. if (irq >= 0 && desc->action) {
  822. char *trigger;
  823. u32 bitmask = nmk_gpio_get_bitmask(gpio);
  824. if (nmk_chip->edge_rising & bitmask)
  825. trigger = "edge-rising";
  826. else if (nmk_chip->edge_falling & bitmask)
  827. trigger = "edge-falling";
  828. else
  829. trigger = "edge-undefined";
  830. seq_printf(s, " irq-%d %s%s",
  831. irq, trigger,
  832. irqd_is_wakeup_set(&desc->irq_data)
  833. ? " wakeup" : "");
  834. }
  835. }
  836. clk_disable(nmk_chip->clk);
  837. }
  838. static void nmk_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  839. {
  840. unsigned i;
  841. unsigned gpio = chip->base;
  842. for (i = 0; i < chip->ngpio; i++, gpio++) {
  843. nmk_gpio_dbg_show_one(s, chip, i, gpio);
  844. seq_printf(s, "\n");
  845. }
  846. }
  847. #else
  848. static inline void nmk_gpio_dbg_show_one(struct seq_file *s,
  849. struct gpio_chip *chip,
  850. unsigned offset, unsigned gpio)
  851. {
  852. }
  853. #define nmk_gpio_dbg_show NULL
  854. #endif
  855. /* This structure is replicated for each GPIO block allocated at probe time */
  856. static struct gpio_chip nmk_gpio_template = {
  857. .request = nmk_gpio_request,
  858. .free = nmk_gpio_free,
  859. .direction_input = nmk_gpio_make_input,
  860. .get = nmk_gpio_get_input,
  861. .direction_output = nmk_gpio_make_output,
  862. .set = nmk_gpio_set_output,
  863. .to_irq = nmk_gpio_to_irq,
  864. .dbg_show = nmk_gpio_dbg_show,
  865. .can_sleep = 0,
  866. };
  867. void nmk_gpio_clocks_enable(void)
  868. {
  869. int i;
  870. for (i = 0; i < NUM_BANKS; i++) {
  871. struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
  872. if (!chip)
  873. continue;
  874. clk_enable(chip->clk);
  875. }
  876. }
  877. void nmk_gpio_clocks_disable(void)
  878. {
  879. int i;
  880. for (i = 0; i < NUM_BANKS; i++) {
  881. struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
  882. if (!chip)
  883. continue;
  884. clk_disable(chip->clk);
  885. }
  886. }
  887. /*
  888. * Called from the suspend/resume path to only keep the real wakeup interrupts
  889. * (those that have had set_irq_wake() called on them) as wakeup interrupts,
  890. * and not the rest of the interrupts which we needed to have as wakeups for
  891. * cpuidle.
  892. *
  893. * PM ops are not used since this needs to be done at the end, after all the
  894. * other drivers are done with their suspend callbacks.
  895. */
  896. void nmk_gpio_wakeups_suspend(void)
  897. {
  898. int i;
  899. for (i = 0; i < NUM_BANKS; i++) {
  900. struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
  901. if (!chip)
  902. break;
  903. clk_enable(chip->clk);
  904. writel(chip->rwimsc & chip->real_wake,
  905. chip->addr + NMK_GPIO_RWIMSC);
  906. writel(chip->fwimsc & chip->real_wake,
  907. chip->addr + NMK_GPIO_FWIMSC);
  908. clk_disable(chip->clk);
  909. }
  910. }
  911. void nmk_gpio_wakeups_resume(void)
  912. {
  913. int i;
  914. for (i = 0; i < NUM_BANKS; i++) {
  915. struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
  916. if (!chip)
  917. break;
  918. clk_enable(chip->clk);
  919. writel(chip->rwimsc, chip->addr + NMK_GPIO_RWIMSC);
  920. writel(chip->fwimsc, chip->addr + NMK_GPIO_FWIMSC);
  921. clk_disable(chip->clk);
  922. }
  923. }
  924. /*
  925. * Read the pull up/pull down status.
  926. * A bit set in 'pull_up' means that pull up
  927. * is selected if pull is enabled in PDIS register.
  928. * Note: only pull up/down set via this driver can
  929. * be detected due to HW limitations.
  930. */
  931. void nmk_gpio_read_pull(int gpio_bank, u32 *pull_up)
  932. {
  933. if (gpio_bank < NUM_BANKS) {
  934. struct nmk_gpio_chip *chip = nmk_gpio_chips[gpio_bank];
  935. if (!chip)
  936. return;
  937. *pull_up = chip->pull_up;
  938. }
  939. }
  940. int nmk_gpio_irq_map(struct irq_domain *d, unsigned int irq,
  941. irq_hw_number_t hwirq)
  942. {
  943. struct nmk_gpio_chip *nmk_chip = d->host_data;
  944. if (!nmk_chip)
  945. return -EINVAL;
  946. irq_set_chip_and_handler(irq, &nmk_gpio_irq_chip, handle_edge_irq);
  947. set_irq_flags(irq, IRQF_VALID);
  948. irq_set_chip_data(irq, nmk_chip);
  949. irq_set_irq_type(irq, IRQ_TYPE_EDGE_FALLING);
  950. return 0;
  951. }
  952. const struct irq_domain_ops nmk_gpio_irq_simple_ops = {
  953. .map = nmk_gpio_irq_map,
  954. .xlate = irq_domain_xlate_twocell,
  955. };
  956. static int __devinit nmk_gpio_probe(struct platform_device *dev)
  957. {
  958. struct nmk_gpio_platform_data *pdata = dev->dev.platform_data;
  959. struct device_node *np = dev->dev.of_node;
  960. struct nmk_gpio_chip *nmk_chip;
  961. struct gpio_chip *chip;
  962. struct resource *res;
  963. struct clk *clk;
  964. int secondary_irq;
  965. void __iomem *base;
  966. int irq;
  967. int ret;
  968. if (!pdata && !np) {
  969. dev_err(&dev->dev, "No platform data or device tree found\n");
  970. return -ENODEV;
  971. }
  972. if (np) {
  973. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  974. if (!pdata)
  975. return -ENOMEM;
  976. if (of_get_property(np, "supports-sleepmode", NULL))
  977. pdata->supports_sleepmode = true;
  978. if (of_property_read_u32(np, "gpio-bank", &dev->id)) {
  979. dev_err(&dev->dev, "gpio-bank property not found\n");
  980. ret = -EINVAL;
  981. goto out;
  982. }
  983. pdata->first_gpio = dev->id * NMK_GPIO_PER_CHIP;
  984. pdata->num_gpio = NMK_GPIO_PER_CHIP;
  985. }
  986. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  987. if (!res) {
  988. ret = -ENOENT;
  989. goto out;
  990. }
  991. irq = platform_get_irq(dev, 0);
  992. if (irq < 0) {
  993. ret = irq;
  994. goto out;
  995. }
  996. secondary_irq = platform_get_irq(dev, 1);
  997. if (secondary_irq >= 0 && !pdata->get_secondary_status) {
  998. ret = -EINVAL;
  999. goto out;
  1000. }
  1001. if (request_mem_region(res->start, resource_size(res),
  1002. dev_name(&dev->dev)) == NULL) {
  1003. ret = -EBUSY;
  1004. goto out;
  1005. }
  1006. base = ioremap(res->start, resource_size(res));
  1007. if (!base) {
  1008. ret = -ENOMEM;
  1009. goto out_release;
  1010. }
  1011. clk = clk_get(&dev->dev, NULL);
  1012. if (IS_ERR(clk)) {
  1013. ret = PTR_ERR(clk);
  1014. goto out_unmap;
  1015. }
  1016. nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL);
  1017. if (!nmk_chip) {
  1018. ret = -ENOMEM;
  1019. goto out_clk;
  1020. }
  1021. /*
  1022. * The virt address in nmk_chip->addr is in the nomadik register space,
  1023. * so we can simply convert the resource address, without remapping
  1024. */
  1025. nmk_chip->bank = dev->id;
  1026. nmk_chip->clk = clk;
  1027. nmk_chip->addr = base;
  1028. nmk_chip->chip = nmk_gpio_template;
  1029. nmk_chip->parent_irq = irq;
  1030. nmk_chip->secondary_parent_irq = secondary_irq;
  1031. nmk_chip->get_secondary_status = pdata->get_secondary_status;
  1032. nmk_chip->set_ioforce = pdata->set_ioforce;
  1033. nmk_chip->sleepmode = pdata->supports_sleepmode;
  1034. spin_lock_init(&nmk_chip->lock);
  1035. chip = &nmk_chip->chip;
  1036. chip->base = pdata->first_gpio;
  1037. chip->ngpio = pdata->num_gpio;
  1038. chip->label = pdata->name ?: dev_name(&dev->dev);
  1039. chip->dev = &dev->dev;
  1040. chip->owner = THIS_MODULE;
  1041. clk_enable(nmk_chip->clk);
  1042. nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI);
  1043. clk_disable(nmk_chip->clk);
  1044. #ifdef CONFIG_OF_GPIO
  1045. chip->of_node = np;
  1046. #endif
  1047. ret = gpiochip_add(&nmk_chip->chip);
  1048. if (ret)
  1049. goto out_free;
  1050. BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));
  1051. nmk_gpio_chips[nmk_chip->bank] = nmk_chip;
  1052. platform_set_drvdata(dev, nmk_chip);
  1053. nmk_chip->domain = irq_domain_add_legacy(np, NMK_GPIO_PER_CHIP,
  1054. NOMADIK_GPIO_TO_IRQ(pdata->first_gpio),
  1055. 0, &nmk_gpio_irq_simple_ops, nmk_chip);
  1056. if (!nmk_chip->domain) {
  1057. pr_err("%s: Failed to create irqdomain\n", np->full_name);
  1058. ret = -ENOSYS;
  1059. goto out_free;
  1060. }
  1061. nmk_gpio_init_irq(nmk_chip);
  1062. dev_info(&dev->dev, "at address %p\n", nmk_chip->addr);
  1063. return 0;
  1064. out_free:
  1065. kfree(nmk_chip);
  1066. out_clk:
  1067. clk_disable(clk);
  1068. clk_put(clk);
  1069. out_unmap:
  1070. iounmap(base);
  1071. out_release:
  1072. release_mem_region(res->start, resource_size(res));
  1073. out:
  1074. dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret,
  1075. pdata->first_gpio, pdata->first_gpio+31);
  1076. if (np)
  1077. kfree(pdata);
  1078. return ret;
  1079. }
  1080. static int nmk_get_groups_cnt(struct pinctrl_dev *pctldev)
  1081. {
  1082. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1083. return npct->soc->ngroups;
  1084. }
  1085. static const char *nmk_get_group_name(struct pinctrl_dev *pctldev,
  1086. unsigned selector)
  1087. {
  1088. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1089. return npct->soc->groups[selector].name;
  1090. }
  1091. static int nmk_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
  1092. const unsigned **pins,
  1093. unsigned *num_pins)
  1094. {
  1095. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1096. *pins = npct->soc->groups[selector].pins;
  1097. *num_pins = npct->soc->groups[selector].npins;
  1098. return 0;
  1099. }
  1100. static struct pinctrl_gpio_range *
  1101. nmk_match_gpio_range(struct pinctrl_dev *pctldev, unsigned offset)
  1102. {
  1103. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1104. int i;
  1105. for (i = 0; i < npct->soc->gpio_num_ranges; i++) {
  1106. struct pinctrl_gpio_range *range;
  1107. range = &npct->soc->gpio_ranges[i];
  1108. if (offset >= range->pin_base &&
  1109. offset <= (range->pin_base + range->npins - 1))
  1110. return range;
  1111. }
  1112. return NULL;
  1113. }
  1114. static void nmk_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  1115. unsigned offset)
  1116. {
  1117. struct pinctrl_gpio_range *range;
  1118. struct gpio_chip *chip;
  1119. range = nmk_match_gpio_range(pctldev, offset);
  1120. if (!range || !range->gc) {
  1121. seq_printf(s, "invalid pin offset");
  1122. return;
  1123. }
  1124. chip = range->gc;
  1125. nmk_gpio_dbg_show_one(s, chip, offset - chip->base, offset);
  1126. }
  1127. static struct pinctrl_ops nmk_pinctrl_ops = {
  1128. .get_groups_count = nmk_get_groups_cnt,
  1129. .get_group_name = nmk_get_group_name,
  1130. .get_group_pins = nmk_get_group_pins,
  1131. .pin_dbg_show = nmk_pin_dbg_show,
  1132. };
  1133. static int nmk_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
  1134. {
  1135. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1136. return npct->soc->nfunctions;
  1137. }
  1138. static const char *nmk_pmx_get_func_name(struct pinctrl_dev *pctldev,
  1139. unsigned function)
  1140. {
  1141. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1142. return npct->soc->functions[function].name;
  1143. }
  1144. static int nmk_pmx_get_func_groups(struct pinctrl_dev *pctldev,
  1145. unsigned function,
  1146. const char * const **groups,
  1147. unsigned * const num_groups)
  1148. {
  1149. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1150. *groups = npct->soc->functions[function].groups;
  1151. *num_groups = npct->soc->functions[function].ngroups;
  1152. return 0;
  1153. }
  1154. static int nmk_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
  1155. unsigned group)
  1156. {
  1157. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1158. const struct nmk_pingroup *g;
  1159. static unsigned int slpm[NUM_BANKS];
  1160. unsigned long flags;
  1161. bool glitch;
  1162. int ret = -EINVAL;
  1163. int i;
  1164. g = &npct->soc->groups[group];
  1165. if (g->altsetting < 0)
  1166. return -EINVAL;
  1167. dev_dbg(npct->dev, "enable group %s, %u pins\n", g->name, g->npins);
  1168. /* Handle this special glitch on altfunction C */
  1169. glitch = (g->altsetting == NMK_GPIO_ALT_C);
  1170. if (glitch) {
  1171. spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
  1172. /* Initially don't put any pins to sleep when switching */
  1173. memset(slpm, 0xff, sizeof(slpm));
  1174. /*
  1175. * Then mask the pins that need to be sleeping now when we're
  1176. * switching to the ALT C function.
  1177. */
  1178. for (i = 0; i < g->npins; i++)
  1179. slpm[g->pins[i] / NMK_GPIO_PER_CHIP] &= ~BIT(g->pins[i]);
  1180. nmk_gpio_glitch_slpm_init(slpm);
  1181. }
  1182. for (i = 0; i < g->npins; i++) {
  1183. struct pinctrl_gpio_range *range;
  1184. struct nmk_gpio_chip *nmk_chip;
  1185. struct gpio_chip *chip;
  1186. unsigned bit;
  1187. range = nmk_match_gpio_range(pctldev, g->pins[i]);
  1188. if (!range) {
  1189. dev_err(npct->dev,
  1190. "invalid pin offset %d in group %s at index %d\n",
  1191. g->pins[i], g->name, i);
  1192. goto out_glitch;
  1193. }
  1194. if (!range->gc) {
  1195. dev_err(npct->dev, "GPIO chip missing in range for pin offset %d in group %s at index %d\n",
  1196. g->pins[i], g->name, i);
  1197. goto out_glitch;
  1198. }
  1199. chip = range->gc;
  1200. nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
  1201. dev_dbg(npct->dev, "setting pin %d to altsetting %d\n", g->pins[i], g->altsetting);
  1202. clk_enable(nmk_chip->clk);
  1203. bit = g->pins[i] % NMK_GPIO_PER_CHIP;
  1204. /*
  1205. * If the pin is switching to altfunc, and there was an
  1206. * interrupt installed on it which has been lazy disabled,
  1207. * actually mask the interrupt to prevent spurious interrupts
  1208. * that would occur while the pin is under control of the
  1209. * peripheral. Only SKE does this.
  1210. */
  1211. nmk_gpio_disable_lazy_irq(nmk_chip, bit);
  1212. __nmk_gpio_set_mode_safe(nmk_chip, bit, g->altsetting, glitch);
  1213. clk_disable(nmk_chip->clk);
  1214. }
  1215. /* When all pins are successfully reconfigured we get here */
  1216. ret = 0;
  1217. out_glitch:
  1218. if (glitch) {
  1219. nmk_gpio_glitch_slpm_restore(slpm);
  1220. spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
  1221. }
  1222. return ret;
  1223. }
  1224. static void nmk_pmx_disable(struct pinctrl_dev *pctldev,
  1225. unsigned function, unsigned group)
  1226. {
  1227. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1228. const struct nmk_pingroup *g;
  1229. g = &npct->soc->groups[group];
  1230. if (g->altsetting < 0)
  1231. return;
  1232. /* Poke out the mux, set the pin to some default state? */
  1233. dev_dbg(npct->dev, "disable group %s, %u pins\n", g->name, g->npins);
  1234. }
  1235. int nmk_gpio_request_enable(struct pinctrl_dev *pctldev,
  1236. struct pinctrl_gpio_range *range,
  1237. unsigned offset)
  1238. {
  1239. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1240. struct nmk_gpio_chip *nmk_chip;
  1241. struct gpio_chip *chip;
  1242. unsigned bit;
  1243. if (!range) {
  1244. dev_err(npct->dev, "invalid range\n");
  1245. return -EINVAL;
  1246. }
  1247. if (!range->gc) {
  1248. dev_err(npct->dev, "missing GPIO chip in range\n");
  1249. return -EINVAL;
  1250. }
  1251. chip = range->gc;
  1252. nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
  1253. dev_dbg(npct->dev, "enable pin %u as GPIO\n", offset);
  1254. clk_enable(nmk_chip->clk);
  1255. bit = offset % NMK_GPIO_PER_CHIP;
  1256. /* There is no glitch when converting any pin to GPIO */
  1257. __nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);
  1258. clk_disable(nmk_chip->clk);
  1259. return 0;
  1260. }
  1261. void nmk_gpio_disable_free(struct pinctrl_dev *pctldev,
  1262. struct pinctrl_gpio_range *range,
  1263. unsigned offset)
  1264. {
  1265. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1266. dev_dbg(npct->dev, "disable pin %u as GPIO\n", offset);
  1267. /* Set the pin to some default state, GPIO is usually default */
  1268. }
  1269. static struct pinmux_ops nmk_pinmux_ops = {
  1270. .get_functions_count = nmk_pmx_get_funcs_cnt,
  1271. .get_function_name = nmk_pmx_get_func_name,
  1272. .get_function_groups = nmk_pmx_get_func_groups,
  1273. .enable = nmk_pmx_enable,
  1274. .disable = nmk_pmx_disable,
  1275. .gpio_request_enable = nmk_gpio_request_enable,
  1276. .gpio_disable_free = nmk_gpio_disable_free,
  1277. };
  1278. int nmk_pin_config_get(struct pinctrl_dev *pctldev,
  1279. unsigned pin,
  1280. unsigned long *config)
  1281. {
  1282. /* Not implemented */
  1283. return -EINVAL;
  1284. }
  1285. int nmk_pin_config_set(struct pinctrl_dev *pctldev,
  1286. unsigned pin,
  1287. unsigned long config)
  1288. {
  1289. static const char *pullnames[] = {
  1290. [NMK_GPIO_PULL_NONE] = "none",
  1291. [NMK_GPIO_PULL_UP] = "up",
  1292. [NMK_GPIO_PULL_DOWN] = "down",
  1293. [3] /* illegal */ = "??"
  1294. };
  1295. static const char *slpmnames[] = {
  1296. [NMK_GPIO_SLPM_INPUT] = "input/wakeup",
  1297. [NMK_GPIO_SLPM_NOCHANGE] = "no-change/no-wakeup",
  1298. };
  1299. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1300. struct nmk_gpio_chip *nmk_chip;
  1301. struct pinctrl_gpio_range *range;
  1302. struct gpio_chip *chip;
  1303. unsigned bit;
  1304. /*
  1305. * The pin config contains pin number and altfunction fields, here
  1306. * we just ignore that part. It's being handled by the framework and
  1307. * pinmux callback respectively.
  1308. */
  1309. pin_cfg_t cfg = (pin_cfg_t) config;
  1310. int pull = PIN_PULL(cfg);
  1311. int slpm = PIN_SLPM(cfg);
  1312. int output = PIN_DIR(cfg);
  1313. int val = PIN_VAL(cfg);
  1314. bool lowemi = PIN_LOWEMI(cfg);
  1315. bool gpiomode = PIN_GPIOMODE(cfg);
  1316. bool sleep = PIN_SLEEPMODE(cfg);
  1317. range = nmk_match_gpio_range(pctldev, pin);
  1318. if (!range) {
  1319. dev_err(npct->dev, "invalid pin offset %d\n", pin);
  1320. return -EINVAL;
  1321. }
  1322. if (!range->gc) {
  1323. dev_err(npct->dev, "GPIO chip missing in range for pin %d\n",
  1324. pin);
  1325. return -EINVAL;
  1326. }
  1327. chip = range->gc;
  1328. nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
  1329. if (sleep) {
  1330. int slpm_pull = PIN_SLPM_PULL(cfg);
  1331. int slpm_output = PIN_SLPM_DIR(cfg);
  1332. int slpm_val = PIN_SLPM_VAL(cfg);
  1333. /* All pins go into GPIO mode at sleep */
  1334. gpiomode = true;
  1335. /*
  1336. * The SLPM_* values are normal values + 1 to allow zero to
  1337. * mean "same as normal".
  1338. */
  1339. if (slpm_pull)
  1340. pull = slpm_pull - 1;
  1341. if (slpm_output)
  1342. output = slpm_output - 1;
  1343. if (slpm_val)
  1344. val = slpm_val - 1;
  1345. dev_dbg(nmk_chip->chip.dev, "pin %d: sleep pull %s, dir %s, val %s\n",
  1346. pin,
  1347. slpm_pull ? pullnames[pull] : "same",
  1348. slpm_output ? (output ? "output" : "input") : "same",
  1349. slpm_val ? (val ? "high" : "low") : "same");
  1350. }
  1351. dev_dbg(nmk_chip->chip.dev, "pin %d [%#lx]: pull %s, slpm %s (%s%s), lowemi %s\n",
  1352. pin, cfg, pullnames[pull], slpmnames[slpm],
  1353. output ? "output " : "input",
  1354. output ? (val ? "high" : "low") : "",
  1355. lowemi ? "on" : "off" );
  1356. clk_enable(nmk_chip->clk);
  1357. bit = pin % NMK_GPIO_PER_CHIP;
  1358. if (gpiomode)
  1359. /* No glitch when going to GPIO mode */
  1360. __nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);
  1361. if (output)
  1362. __nmk_gpio_make_output(nmk_chip, bit, val);
  1363. else {
  1364. __nmk_gpio_make_input(nmk_chip, bit);
  1365. __nmk_gpio_set_pull(nmk_chip, bit, pull);
  1366. }
  1367. /* TODO: isn't this only applicable on output pins? */
  1368. __nmk_gpio_set_lowemi(nmk_chip, bit, lowemi);
  1369. __nmk_gpio_set_slpm(nmk_chip, bit, slpm);
  1370. clk_disable(nmk_chip->clk);
  1371. return 0;
  1372. }
  1373. static struct pinconf_ops nmk_pinconf_ops = {
  1374. .pin_config_get = nmk_pin_config_get,
  1375. .pin_config_set = nmk_pin_config_set,
  1376. };
  1377. static struct pinctrl_desc nmk_pinctrl_desc = {
  1378. .name = "pinctrl-nomadik",
  1379. .pctlops = &nmk_pinctrl_ops,
  1380. .pmxops = &nmk_pinmux_ops,
  1381. .confops = &nmk_pinconf_ops,
  1382. .owner = THIS_MODULE,
  1383. };
  1384. static int __devinit nmk_pinctrl_probe(struct platform_device *pdev)
  1385. {
  1386. const struct platform_device_id *platid = platform_get_device_id(pdev);
  1387. struct nmk_pinctrl *npct;
  1388. int i;
  1389. npct = devm_kzalloc(&pdev->dev, sizeof(*npct), GFP_KERNEL);
  1390. if (!npct)
  1391. return -ENOMEM;
  1392. /* Poke in other ASIC variants here */
  1393. if (platid->driver_data == PINCTRL_NMK_DB8500)
  1394. nmk_pinctrl_db8500_init(&npct->soc);
  1395. /*
  1396. * We need all the GPIO drivers to probe FIRST, or we will not be able
  1397. * to obtain references to the struct gpio_chip * for them, and we
  1398. * need this to proceed.
  1399. */
  1400. for (i = 0; i < npct->soc->gpio_num_ranges; i++) {
  1401. if (!nmk_gpio_chips[i]) {
  1402. dev_warn(&pdev->dev, "GPIO chip %d not registered yet\n", i);
  1403. devm_kfree(&pdev->dev, npct);
  1404. return -EPROBE_DEFER;
  1405. }
  1406. npct->soc->gpio_ranges[i].gc = &nmk_gpio_chips[i]->chip;
  1407. }
  1408. nmk_pinctrl_desc.pins = npct->soc->pins;
  1409. nmk_pinctrl_desc.npins = npct->soc->npins;
  1410. npct->dev = &pdev->dev;
  1411. npct->pctl = pinctrl_register(&nmk_pinctrl_desc, &pdev->dev, npct);
  1412. if (!npct->pctl) {
  1413. dev_err(&pdev->dev, "could not register Nomadik pinctrl driver\n");
  1414. return -EINVAL;
  1415. }
  1416. /* We will handle a range of GPIO pins */
  1417. for (i = 0; i < npct->soc->gpio_num_ranges; i++)
  1418. pinctrl_add_gpio_range(npct->pctl, &npct->soc->gpio_ranges[i]);
  1419. platform_set_drvdata(pdev, npct);
  1420. dev_info(&pdev->dev, "initialized Nomadik pin control driver\n");
  1421. return 0;
  1422. }
  1423. static const struct of_device_id nmk_gpio_match[] = {
  1424. { .compatible = "st,nomadik-gpio", },
  1425. {}
  1426. };
  1427. static struct platform_driver nmk_gpio_driver = {
  1428. .driver = {
  1429. .owner = THIS_MODULE,
  1430. .name = "gpio",
  1431. .of_match_table = nmk_gpio_match,
  1432. },
  1433. .probe = nmk_gpio_probe,
  1434. };
  1435. static const struct platform_device_id nmk_pinctrl_id[] = {
  1436. { "pinctrl-stn8815", PINCTRL_NMK_STN8815 },
  1437. { "pinctrl-db8500", PINCTRL_NMK_DB8500 },
  1438. };
  1439. static struct platform_driver nmk_pinctrl_driver = {
  1440. .driver = {
  1441. .owner = THIS_MODULE,
  1442. .name = "pinctrl-nomadik",
  1443. },
  1444. .probe = nmk_pinctrl_probe,
  1445. .id_table = nmk_pinctrl_id,
  1446. };
  1447. static int __init nmk_gpio_init(void)
  1448. {
  1449. int ret;
  1450. ret = platform_driver_register(&nmk_gpio_driver);
  1451. if (ret)
  1452. return ret;
  1453. return platform_driver_register(&nmk_pinctrl_driver);
  1454. }
  1455. core_initcall(nmk_gpio_init);
  1456. MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini");
  1457. MODULE_DESCRIPTION("Nomadik GPIO Driver");
  1458. MODULE_LICENSE("GPL");