pinctrl-nomadik.c 45 KB

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