pinctrl-nomadik.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805
  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. .flags = IRQCHIP_MASK_ON_SUSPEND,
  683. };
  684. static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc,
  685. u32 status)
  686. {
  687. struct nmk_gpio_chip *nmk_chip;
  688. struct irq_chip *host_chip = irq_get_chip(irq);
  689. chained_irq_enter(host_chip, desc);
  690. nmk_chip = irq_get_handler_data(irq);
  691. while (status) {
  692. int bit = __ffs(status);
  693. generic_handle_irq(irq_find_mapping(nmk_chip->domain, 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 = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL);
  974. if (!pdata)
  975. return -ENOMEM;
  976. if (of_get_property(np, "st,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. base = devm_request_and_ioremap(&dev->dev, res);
  1002. if (!base) {
  1003. ret = -ENOMEM;
  1004. goto out;
  1005. }
  1006. clk = devm_clk_get(&dev->dev, NULL);
  1007. if (IS_ERR(clk)) {
  1008. ret = PTR_ERR(clk);
  1009. goto out;
  1010. }
  1011. clk_prepare(clk);
  1012. nmk_chip = devm_kzalloc(&dev->dev, sizeof(*nmk_chip), GFP_KERNEL);
  1013. if (!nmk_chip) {
  1014. ret = -ENOMEM;
  1015. goto out;
  1016. }
  1017. /*
  1018. * The virt address in nmk_chip->addr is in the nomadik register space,
  1019. * so we can simply convert the resource address, without remapping
  1020. */
  1021. nmk_chip->bank = dev->id;
  1022. nmk_chip->clk = clk;
  1023. nmk_chip->addr = base;
  1024. nmk_chip->chip = nmk_gpio_template;
  1025. nmk_chip->parent_irq = irq;
  1026. nmk_chip->secondary_parent_irq = secondary_irq;
  1027. nmk_chip->get_secondary_status = pdata->get_secondary_status;
  1028. nmk_chip->set_ioforce = pdata->set_ioforce;
  1029. nmk_chip->sleepmode = pdata->supports_sleepmode;
  1030. spin_lock_init(&nmk_chip->lock);
  1031. chip = &nmk_chip->chip;
  1032. chip->base = pdata->first_gpio;
  1033. chip->ngpio = pdata->num_gpio;
  1034. chip->label = pdata->name ?: dev_name(&dev->dev);
  1035. chip->dev = &dev->dev;
  1036. chip->owner = THIS_MODULE;
  1037. clk_enable(nmk_chip->clk);
  1038. nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI);
  1039. clk_disable(nmk_chip->clk);
  1040. #ifdef CONFIG_OF_GPIO
  1041. chip->of_node = np;
  1042. #endif
  1043. ret = gpiochip_add(&nmk_chip->chip);
  1044. if (ret)
  1045. goto out;
  1046. BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));
  1047. nmk_gpio_chips[nmk_chip->bank] = nmk_chip;
  1048. platform_set_drvdata(dev, nmk_chip);
  1049. nmk_chip->domain = irq_domain_add_legacy(np, NMK_GPIO_PER_CHIP,
  1050. NOMADIK_GPIO_TO_IRQ(pdata->first_gpio),
  1051. 0, &nmk_gpio_irq_simple_ops, nmk_chip);
  1052. if (!nmk_chip->domain) {
  1053. dev_err(&dev->dev, "failed to create irqdomain\n");
  1054. ret = -ENOSYS;
  1055. goto out;
  1056. }
  1057. nmk_gpio_init_irq(nmk_chip);
  1058. dev_info(&dev->dev, "at address %p\n", nmk_chip->addr);
  1059. return 0;
  1060. out:
  1061. dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret,
  1062. pdata->first_gpio, pdata->first_gpio+31);
  1063. return ret;
  1064. }
  1065. static int nmk_get_groups_cnt(struct pinctrl_dev *pctldev)
  1066. {
  1067. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1068. return npct->soc->ngroups;
  1069. }
  1070. static const char *nmk_get_group_name(struct pinctrl_dev *pctldev,
  1071. unsigned selector)
  1072. {
  1073. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1074. return npct->soc->groups[selector].name;
  1075. }
  1076. static int nmk_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
  1077. const unsigned **pins,
  1078. unsigned *num_pins)
  1079. {
  1080. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1081. *pins = npct->soc->groups[selector].pins;
  1082. *num_pins = npct->soc->groups[selector].npins;
  1083. return 0;
  1084. }
  1085. static struct pinctrl_gpio_range *
  1086. nmk_match_gpio_range(struct pinctrl_dev *pctldev, unsigned offset)
  1087. {
  1088. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1089. int i;
  1090. for (i = 0; i < npct->soc->gpio_num_ranges; i++) {
  1091. struct pinctrl_gpio_range *range;
  1092. range = &npct->soc->gpio_ranges[i];
  1093. if (offset >= range->pin_base &&
  1094. offset <= (range->pin_base + range->npins - 1))
  1095. return range;
  1096. }
  1097. return NULL;
  1098. }
  1099. static void nmk_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  1100. unsigned offset)
  1101. {
  1102. struct pinctrl_gpio_range *range;
  1103. struct gpio_chip *chip;
  1104. range = nmk_match_gpio_range(pctldev, offset);
  1105. if (!range || !range->gc) {
  1106. seq_printf(s, "invalid pin offset");
  1107. return;
  1108. }
  1109. chip = range->gc;
  1110. nmk_gpio_dbg_show_one(s, chip, offset - chip->base, offset);
  1111. }
  1112. static struct pinctrl_ops nmk_pinctrl_ops = {
  1113. .get_groups_count = nmk_get_groups_cnt,
  1114. .get_group_name = nmk_get_group_name,
  1115. .get_group_pins = nmk_get_group_pins,
  1116. .pin_dbg_show = nmk_pin_dbg_show,
  1117. };
  1118. static int nmk_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
  1119. {
  1120. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1121. return npct->soc->nfunctions;
  1122. }
  1123. static const char *nmk_pmx_get_func_name(struct pinctrl_dev *pctldev,
  1124. unsigned function)
  1125. {
  1126. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1127. return npct->soc->functions[function].name;
  1128. }
  1129. static int nmk_pmx_get_func_groups(struct pinctrl_dev *pctldev,
  1130. unsigned function,
  1131. const char * const **groups,
  1132. unsigned * const num_groups)
  1133. {
  1134. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1135. *groups = npct->soc->functions[function].groups;
  1136. *num_groups = npct->soc->functions[function].ngroups;
  1137. return 0;
  1138. }
  1139. static int nmk_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
  1140. unsigned group)
  1141. {
  1142. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1143. const struct nmk_pingroup *g;
  1144. static unsigned int slpm[NUM_BANKS];
  1145. unsigned long flags;
  1146. bool glitch;
  1147. int ret = -EINVAL;
  1148. int i;
  1149. g = &npct->soc->groups[group];
  1150. if (g->altsetting < 0)
  1151. return -EINVAL;
  1152. dev_dbg(npct->dev, "enable group %s, %u pins\n", g->name, g->npins);
  1153. /*
  1154. * If we're setting altfunc C by setting both AFSLA and AFSLB to 1,
  1155. * we may pass through an undesired state. In this case we take
  1156. * some extra care.
  1157. *
  1158. * Safe sequence used to switch IOs between GPIO and Alternate-C mode:
  1159. * - Save SLPM registers (since we have a shadow register in the
  1160. * nmk_chip we're using that as backup)
  1161. * - Set SLPM=0 for the IOs you want to switch and others to 1
  1162. * - Configure the GPIO registers for the IOs that are being switched
  1163. * - Set IOFORCE=1
  1164. * - Modify the AFLSA/B registers for the IOs that are being switched
  1165. * - Set IOFORCE=0
  1166. * - Restore SLPM registers
  1167. * - Any spurious wake up event during switch sequence to be ignored
  1168. * and cleared
  1169. *
  1170. * We REALLY need to save ALL slpm registers, because the external
  1171. * IOFORCE will switch *all* ports to their sleepmode setting to as
  1172. * to avoid glitches. (Not just one port!)
  1173. */
  1174. glitch = (g->altsetting == NMK_GPIO_ALT_C);
  1175. if (glitch) {
  1176. spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
  1177. /* Initially don't put any pins to sleep when switching */
  1178. memset(slpm, 0xff, sizeof(slpm));
  1179. /*
  1180. * Then mask the pins that need to be sleeping now when we're
  1181. * switching to the ALT C function.
  1182. */
  1183. for (i = 0; i < g->npins; i++)
  1184. slpm[g->pins[i] / NMK_GPIO_PER_CHIP] &= ~BIT(g->pins[i]);
  1185. nmk_gpio_glitch_slpm_init(slpm);
  1186. }
  1187. for (i = 0; i < g->npins; i++) {
  1188. struct pinctrl_gpio_range *range;
  1189. struct nmk_gpio_chip *nmk_chip;
  1190. struct gpio_chip *chip;
  1191. unsigned bit;
  1192. range = nmk_match_gpio_range(pctldev, g->pins[i]);
  1193. if (!range) {
  1194. dev_err(npct->dev,
  1195. "invalid pin offset %d in group %s at index %d\n",
  1196. g->pins[i], g->name, i);
  1197. goto out_glitch;
  1198. }
  1199. if (!range->gc) {
  1200. dev_err(npct->dev, "GPIO chip missing in range for pin offset %d in group %s at index %d\n",
  1201. g->pins[i], g->name, i);
  1202. goto out_glitch;
  1203. }
  1204. chip = range->gc;
  1205. nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
  1206. dev_dbg(npct->dev, "setting pin %d to altsetting %d\n", g->pins[i], g->altsetting);
  1207. clk_enable(nmk_chip->clk);
  1208. bit = g->pins[i] % NMK_GPIO_PER_CHIP;
  1209. /*
  1210. * If the pin is switching to altfunc, and there was an
  1211. * interrupt installed on it which has been lazy disabled,
  1212. * actually mask the interrupt to prevent spurious interrupts
  1213. * that would occur while the pin is under control of the
  1214. * peripheral. Only SKE does this.
  1215. */
  1216. nmk_gpio_disable_lazy_irq(nmk_chip, bit);
  1217. __nmk_gpio_set_mode_safe(nmk_chip, bit, g->altsetting, glitch);
  1218. clk_disable(nmk_chip->clk);
  1219. }
  1220. /* When all pins are successfully reconfigured we get here */
  1221. ret = 0;
  1222. out_glitch:
  1223. if (glitch) {
  1224. nmk_gpio_glitch_slpm_restore(slpm);
  1225. spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
  1226. }
  1227. return ret;
  1228. }
  1229. static void nmk_pmx_disable(struct pinctrl_dev *pctldev,
  1230. unsigned function, unsigned group)
  1231. {
  1232. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1233. const struct nmk_pingroup *g;
  1234. g = &npct->soc->groups[group];
  1235. if (g->altsetting < 0)
  1236. return;
  1237. /* Poke out the mux, set the pin to some default state? */
  1238. dev_dbg(npct->dev, "disable group %s, %u pins\n", g->name, g->npins);
  1239. }
  1240. int nmk_gpio_request_enable(struct pinctrl_dev *pctldev,
  1241. struct pinctrl_gpio_range *range,
  1242. unsigned offset)
  1243. {
  1244. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1245. struct nmk_gpio_chip *nmk_chip;
  1246. struct gpio_chip *chip;
  1247. unsigned bit;
  1248. if (!range) {
  1249. dev_err(npct->dev, "invalid range\n");
  1250. return -EINVAL;
  1251. }
  1252. if (!range->gc) {
  1253. dev_err(npct->dev, "missing GPIO chip in range\n");
  1254. return -EINVAL;
  1255. }
  1256. chip = range->gc;
  1257. nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
  1258. dev_dbg(npct->dev, "enable pin %u as GPIO\n", offset);
  1259. clk_enable(nmk_chip->clk);
  1260. bit = offset % NMK_GPIO_PER_CHIP;
  1261. /* There is no glitch when converting any pin to GPIO */
  1262. __nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);
  1263. clk_disable(nmk_chip->clk);
  1264. return 0;
  1265. }
  1266. void nmk_gpio_disable_free(struct pinctrl_dev *pctldev,
  1267. struct pinctrl_gpio_range *range,
  1268. unsigned offset)
  1269. {
  1270. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1271. dev_dbg(npct->dev, "disable pin %u as GPIO\n", offset);
  1272. /* Set the pin to some default state, GPIO is usually default */
  1273. }
  1274. static struct pinmux_ops nmk_pinmux_ops = {
  1275. .get_functions_count = nmk_pmx_get_funcs_cnt,
  1276. .get_function_name = nmk_pmx_get_func_name,
  1277. .get_function_groups = nmk_pmx_get_func_groups,
  1278. .enable = nmk_pmx_enable,
  1279. .disable = nmk_pmx_disable,
  1280. .gpio_request_enable = nmk_gpio_request_enable,
  1281. .gpio_disable_free = nmk_gpio_disable_free,
  1282. };
  1283. int nmk_pin_config_get(struct pinctrl_dev *pctldev,
  1284. unsigned pin,
  1285. unsigned long *config)
  1286. {
  1287. /* Not implemented */
  1288. return -EINVAL;
  1289. }
  1290. int nmk_pin_config_set(struct pinctrl_dev *pctldev,
  1291. unsigned pin,
  1292. unsigned long config)
  1293. {
  1294. static const char *pullnames[] = {
  1295. [NMK_GPIO_PULL_NONE] = "none",
  1296. [NMK_GPIO_PULL_UP] = "up",
  1297. [NMK_GPIO_PULL_DOWN] = "down",
  1298. [3] /* illegal */ = "??"
  1299. };
  1300. static const char *slpmnames[] = {
  1301. [NMK_GPIO_SLPM_INPUT] = "input/wakeup",
  1302. [NMK_GPIO_SLPM_NOCHANGE] = "no-change/no-wakeup",
  1303. };
  1304. struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  1305. struct nmk_gpio_chip *nmk_chip;
  1306. struct pinctrl_gpio_range *range;
  1307. struct gpio_chip *chip;
  1308. unsigned bit;
  1309. /*
  1310. * The pin config contains pin number and altfunction fields, here
  1311. * we just ignore that part. It's being handled by the framework and
  1312. * pinmux callback respectively.
  1313. */
  1314. pin_cfg_t cfg = (pin_cfg_t) config;
  1315. int pull = PIN_PULL(cfg);
  1316. int slpm = PIN_SLPM(cfg);
  1317. int output = PIN_DIR(cfg);
  1318. int val = PIN_VAL(cfg);
  1319. bool lowemi = PIN_LOWEMI(cfg);
  1320. bool gpiomode = PIN_GPIOMODE(cfg);
  1321. bool sleep = PIN_SLEEPMODE(cfg);
  1322. range = nmk_match_gpio_range(pctldev, pin);
  1323. if (!range) {
  1324. dev_err(npct->dev, "invalid pin offset %d\n", pin);
  1325. return -EINVAL;
  1326. }
  1327. if (!range->gc) {
  1328. dev_err(npct->dev, "GPIO chip missing in range for pin %d\n",
  1329. pin);
  1330. return -EINVAL;
  1331. }
  1332. chip = range->gc;
  1333. nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
  1334. if (sleep) {
  1335. int slpm_pull = PIN_SLPM_PULL(cfg);
  1336. int slpm_output = PIN_SLPM_DIR(cfg);
  1337. int slpm_val = PIN_SLPM_VAL(cfg);
  1338. /* All pins go into GPIO mode at sleep */
  1339. gpiomode = true;
  1340. /*
  1341. * The SLPM_* values are normal values + 1 to allow zero to
  1342. * mean "same as normal".
  1343. */
  1344. if (slpm_pull)
  1345. pull = slpm_pull - 1;
  1346. if (slpm_output)
  1347. output = slpm_output - 1;
  1348. if (slpm_val)
  1349. val = slpm_val - 1;
  1350. dev_dbg(nmk_chip->chip.dev, "pin %d: sleep pull %s, dir %s, val %s\n",
  1351. pin,
  1352. slpm_pull ? pullnames[pull] : "same",
  1353. slpm_output ? (output ? "output" : "input") : "same",
  1354. slpm_val ? (val ? "high" : "low") : "same");
  1355. }
  1356. dev_dbg(nmk_chip->chip.dev, "pin %d [%#lx]: pull %s, slpm %s (%s%s), lowemi %s\n",
  1357. pin, cfg, pullnames[pull], slpmnames[slpm],
  1358. output ? "output " : "input",
  1359. output ? (val ? "high" : "low") : "",
  1360. lowemi ? "on" : "off" );
  1361. clk_enable(nmk_chip->clk);
  1362. bit = pin % NMK_GPIO_PER_CHIP;
  1363. if (gpiomode)
  1364. /* No glitch when going to GPIO mode */
  1365. __nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);
  1366. if (output)
  1367. __nmk_gpio_make_output(nmk_chip, bit, val);
  1368. else {
  1369. __nmk_gpio_make_input(nmk_chip, bit);
  1370. __nmk_gpio_set_pull(nmk_chip, bit, pull);
  1371. }
  1372. /* TODO: isn't this only applicable on output pins? */
  1373. __nmk_gpio_set_lowemi(nmk_chip, bit, lowemi);
  1374. __nmk_gpio_set_slpm(nmk_chip, bit, slpm);
  1375. clk_disable(nmk_chip->clk);
  1376. return 0;
  1377. }
  1378. static struct pinconf_ops nmk_pinconf_ops = {
  1379. .pin_config_get = nmk_pin_config_get,
  1380. .pin_config_set = nmk_pin_config_set,
  1381. };
  1382. static struct pinctrl_desc nmk_pinctrl_desc = {
  1383. .name = "pinctrl-nomadik",
  1384. .pctlops = &nmk_pinctrl_ops,
  1385. .pmxops = &nmk_pinmux_ops,
  1386. .confops = &nmk_pinconf_ops,
  1387. .owner = THIS_MODULE,
  1388. };
  1389. static const struct of_device_id nmk_pinctrl_match[] = {
  1390. {
  1391. .compatible = "stericsson,nmk_pinctrl",
  1392. .data = (void *)PINCTRL_NMK_DB8500,
  1393. },
  1394. {},
  1395. };
  1396. static int __devinit nmk_pinctrl_probe(struct platform_device *pdev)
  1397. {
  1398. const struct platform_device_id *platid = platform_get_device_id(pdev);
  1399. struct device_node *np = pdev->dev.of_node;
  1400. struct nmk_pinctrl *npct;
  1401. unsigned int version = 0;
  1402. int i;
  1403. npct = devm_kzalloc(&pdev->dev, sizeof(*npct), GFP_KERNEL);
  1404. if (!npct)
  1405. return -ENOMEM;
  1406. if (platid)
  1407. version = platid->driver_data;
  1408. else if (np)
  1409. version = (unsigned int)
  1410. of_match_device(nmk_pinctrl_match, &pdev->dev)->data;
  1411. /* Poke in other ASIC variants here */
  1412. if (version == PINCTRL_NMK_STN8815)
  1413. nmk_pinctrl_stn8815_init(&npct->soc);
  1414. if (version == PINCTRL_NMK_DB8500)
  1415. nmk_pinctrl_db8500_init(&npct->soc);
  1416. if (version == PINCTRL_NMK_DB8540)
  1417. nmk_pinctrl_db8540_init(&npct->soc);
  1418. /*
  1419. * We need all the GPIO drivers to probe FIRST, or we will not be able
  1420. * to obtain references to the struct gpio_chip * for them, and we
  1421. * need this to proceed.
  1422. */
  1423. for (i = 0; i < npct->soc->gpio_num_ranges; i++) {
  1424. if (!nmk_gpio_chips[i]) {
  1425. dev_warn(&pdev->dev, "GPIO chip %d not registered yet\n", i);
  1426. return -EPROBE_DEFER;
  1427. }
  1428. npct->soc->gpio_ranges[i].gc = &nmk_gpio_chips[i]->chip;
  1429. }
  1430. nmk_pinctrl_desc.pins = npct->soc->pins;
  1431. nmk_pinctrl_desc.npins = npct->soc->npins;
  1432. npct->dev = &pdev->dev;
  1433. npct->pctl = pinctrl_register(&nmk_pinctrl_desc, &pdev->dev, npct);
  1434. if (!npct->pctl) {
  1435. dev_err(&pdev->dev, "could not register Nomadik pinctrl driver\n");
  1436. return -EINVAL;
  1437. }
  1438. /* We will handle a range of GPIO pins */
  1439. for (i = 0; i < npct->soc->gpio_num_ranges; i++)
  1440. pinctrl_add_gpio_range(npct->pctl, &npct->soc->gpio_ranges[i]);
  1441. platform_set_drvdata(pdev, npct);
  1442. dev_info(&pdev->dev, "initialized Nomadik pin control driver\n");
  1443. return 0;
  1444. }
  1445. static const struct of_device_id nmk_gpio_match[] = {
  1446. { .compatible = "st,nomadik-gpio", },
  1447. {}
  1448. };
  1449. static struct platform_driver nmk_gpio_driver = {
  1450. .driver = {
  1451. .owner = THIS_MODULE,
  1452. .name = "gpio",
  1453. .of_match_table = nmk_gpio_match,
  1454. },
  1455. .probe = nmk_gpio_probe,
  1456. };
  1457. static const struct platform_device_id nmk_pinctrl_id[] = {
  1458. { "pinctrl-stn8815", PINCTRL_NMK_STN8815 },
  1459. { "pinctrl-db8500", PINCTRL_NMK_DB8500 },
  1460. { "pinctrl-db8540", PINCTRL_NMK_DB8540 },
  1461. };
  1462. static struct platform_driver nmk_pinctrl_driver = {
  1463. .driver = {
  1464. .owner = THIS_MODULE,
  1465. .name = "pinctrl-nomadik",
  1466. .of_match_table = nmk_pinctrl_match,
  1467. },
  1468. .probe = nmk_pinctrl_probe,
  1469. .id_table = nmk_pinctrl_id,
  1470. };
  1471. static int __init nmk_gpio_init(void)
  1472. {
  1473. int ret;
  1474. ret = platform_driver_register(&nmk_gpio_driver);
  1475. if (ret)
  1476. return ret;
  1477. return platform_driver_register(&nmk_pinctrl_driver);
  1478. }
  1479. core_initcall(nmk_gpio_init);
  1480. MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini");
  1481. MODULE_DESCRIPTION("Nomadik GPIO Driver");
  1482. MODULE_LICENSE("GPL");