gpio-samsung.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
  1. /*
  2. * Copyright (c) 2009-2011 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com/
  4. *
  5. * Copyright 2008 Openmoko, Inc.
  6. * Copyright 2008 Simtec Electronics
  7. * Ben Dooks <ben@simtec.co.uk>
  8. * http://armlinux.simtec.co.uk/
  9. *
  10. * SAMSUNG - GPIOlib support
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/irq.h>
  18. #include <linux/io.h>
  19. #include <linux/gpio.h>
  20. #include <linux/init.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/module.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/device.h>
  25. #include <linux/ioport.h>
  26. #include <linux/of.h>
  27. #include <linux/slab.h>
  28. #include <linux/of_address.h>
  29. #include <asm/irq.h>
  30. #include <mach/map.h>
  31. #include <mach/regs-gpio.h>
  32. #if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
  33. #include <mach/gpio-samsung.h>
  34. #endif
  35. #include <plat/cpu.h>
  36. #include <plat/gpio-core.h>
  37. #include <plat/gpio-cfg.h>
  38. #include <plat/gpio-cfg-helpers.h>
  39. #include <plat/pm.h>
  40. int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip,
  41. unsigned int off, samsung_gpio_pull_t pull)
  42. {
  43. void __iomem *reg = chip->base + 0x08;
  44. int shift = off * 2;
  45. u32 pup;
  46. pup = __raw_readl(reg);
  47. pup &= ~(3 << shift);
  48. pup |= pull << shift;
  49. __raw_writel(pup, reg);
  50. return 0;
  51. }
  52. samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip,
  53. unsigned int off)
  54. {
  55. void __iomem *reg = chip->base + 0x08;
  56. int shift = off * 2;
  57. u32 pup = __raw_readl(reg);
  58. pup >>= shift;
  59. pup &= 0x3;
  60. return (__force samsung_gpio_pull_t)pup;
  61. }
  62. int s3c2443_gpio_setpull(struct samsung_gpio_chip *chip,
  63. unsigned int off, samsung_gpio_pull_t pull)
  64. {
  65. switch (pull) {
  66. case S3C_GPIO_PULL_NONE:
  67. pull = 0x01;
  68. break;
  69. case S3C_GPIO_PULL_UP:
  70. pull = 0x00;
  71. break;
  72. case S3C_GPIO_PULL_DOWN:
  73. pull = 0x02;
  74. break;
  75. }
  76. return samsung_gpio_setpull_updown(chip, off, pull);
  77. }
  78. samsung_gpio_pull_t s3c2443_gpio_getpull(struct samsung_gpio_chip *chip,
  79. unsigned int off)
  80. {
  81. samsung_gpio_pull_t pull;
  82. pull = samsung_gpio_getpull_updown(chip, off);
  83. switch (pull) {
  84. case 0x00:
  85. pull = S3C_GPIO_PULL_UP;
  86. break;
  87. case 0x01:
  88. case 0x03:
  89. pull = S3C_GPIO_PULL_NONE;
  90. break;
  91. case 0x02:
  92. pull = S3C_GPIO_PULL_DOWN;
  93. break;
  94. }
  95. return pull;
  96. }
  97. static int s3c24xx_gpio_setpull_1(struct samsung_gpio_chip *chip,
  98. unsigned int off, samsung_gpio_pull_t pull,
  99. samsung_gpio_pull_t updown)
  100. {
  101. void __iomem *reg = chip->base + 0x08;
  102. u32 pup = __raw_readl(reg);
  103. if (pull == updown)
  104. pup &= ~(1 << off);
  105. else if (pull == S3C_GPIO_PULL_NONE)
  106. pup |= (1 << off);
  107. else
  108. return -EINVAL;
  109. __raw_writel(pup, reg);
  110. return 0;
  111. }
  112. static samsung_gpio_pull_t s3c24xx_gpio_getpull_1(struct samsung_gpio_chip *chip,
  113. unsigned int off,
  114. samsung_gpio_pull_t updown)
  115. {
  116. void __iomem *reg = chip->base + 0x08;
  117. u32 pup = __raw_readl(reg);
  118. pup &= (1 << off);
  119. return pup ? S3C_GPIO_PULL_NONE : updown;
  120. }
  121. samsung_gpio_pull_t s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip *chip,
  122. unsigned int off)
  123. {
  124. return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_UP);
  125. }
  126. int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip *chip,
  127. unsigned int off, samsung_gpio_pull_t pull)
  128. {
  129. return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_UP);
  130. }
  131. samsung_gpio_pull_t s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip *chip,
  132. unsigned int off)
  133. {
  134. return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_DOWN);
  135. }
  136. int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip *chip,
  137. unsigned int off, samsung_gpio_pull_t pull)
  138. {
  139. return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_DOWN);
  140. }
  141. /*
  142. * samsung_gpio_setcfg_2bit - Samsung 2bit style GPIO configuration.
  143. * @chip: The gpio chip that is being configured.
  144. * @off: The offset for the GPIO being configured.
  145. * @cfg: The configuration value to set.
  146. *
  147. * This helper deal with the GPIO cases where the control register
  148. * has two bits of configuration per gpio, which have the following
  149. * functions:
  150. * 00 = input
  151. * 01 = output
  152. * 1x = special function
  153. */
  154. static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip *chip,
  155. unsigned int off, unsigned int cfg)
  156. {
  157. void __iomem *reg = chip->base;
  158. unsigned int shift = off * 2;
  159. u32 con;
  160. if (samsung_gpio_is_cfg_special(cfg)) {
  161. cfg &= 0xf;
  162. if (cfg > 3)
  163. return -EINVAL;
  164. cfg <<= shift;
  165. }
  166. con = __raw_readl(reg);
  167. con &= ~(0x3 << shift);
  168. con |= cfg;
  169. __raw_writel(con, reg);
  170. return 0;
  171. }
  172. /*
  173. * samsung_gpio_getcfg_2bit - Samsung 2bit style GPIO configuration read.
  174. * @chip: The gpio chip that is being configured.
  175. * @off: The offset for the GPIO being configured.
  176. *
  177. * The reverse of samsung_gpio_setcfg_2bit(). Will return a value which
  178. * could be directly passed back to samsung_gpio_setcfg_2bit(), from the
  179. * S3C_GPIO_SPECIAL() macro.
  180. */
  181. static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip *chip,
  182. unsigned int off)
  183. {
  184. u32 con;
  185. con = __raw_readl(chip->base);
  186. con >>= off * 2;
  187. con &= 3;
  188. /* this conversion works for IN and OUT as well as special mode */
  189. return S3C_GPIO_SPECIAL(con);
  190. }
  191. /*
  192. * samsung_gpio_setcfg_4bit - Samsung 4bit single register GPIO config.
  193. * @chip: The gpio chip that is being configured.
  194. * @off: The offset for the GPIO being configured.
  195. * @cfg: The configuration value to set.
  196. *
  197. * This helper deal with the GPIO cases where the control register has 4 bits
  198. * of control per GPIO, generally in the form of:
  199. * 0000 = Input
  200. * 0001 = Output
  201. * others = Special functions (dependent on bank)
  202. *
  203. * Note, since the code to deal with the case where there are two control
  204. * registers instead of one, we do not have a separate set of functions for
  205. * each case.
  206. */
  207. static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip *chip,
  208. unsigned int off, unsigned int cfg)
  209. {
  210. void __iomem *reg = chip->base;
  211. unsigned int shift = (off & 7) * 4;
  212. u32 con;
  213. if (off < 8 && chip->chip.ngpio > 8)
  214. reg -= 4;
  215. if (samsung_gpio_is_cfg_special(cfg)) {
  216. cfg &= 0xf;
  217. cfg <<= shift;
  218. }
  219. con = __raw_readl(reg);
  220. con &= ~(0xf << shift);
  221. con |= cfg;
  222. __raw_writel(con, reg);
  223. return 0;
  224. }
  225. /*
  226. * samsung_gpio_getcfg_4bit - Samsung 4bit single register GPIO config read.
  227. * @chip: The gpio chip that is being configured.
  228. * @off: The offset for the GPIO being configured.
  229. *
  230. * The reverse of samsung_gpio_setcfg_4bit(), turning a gpio configuration
  231. * register setting into a value the software can use, such as could be passed
  232. * to samsung_gpio_setcfg_4bit().
  233. *
  234. * @sa samsung_gpio_getcfg_2bit
  235. */
  236. static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip *chip,
  237. unsigned int off)
  238. {
  239. void __iomem *reg = chip->base;
  240. unsigned int shift = (off & 7) * 4;
  241. u32 con;
  242. if (off < 8 && chip->chip.ngpio > 8)
  243. reg -= 4;
  244. con = __raw_readl(reg);
  245. con >>= shift;
  246. con &= 0xf;
  247. /* this conversion works for IN and OUT as well as special mode */
  248. return S3C_GPIO_SPECIAL(con);
  249. }
  250. #ifdef CONFIG_PLAT_S3C24XX
  251. /*
  252. * s3c24xx_gpio_setcfg_abank - S3C24XX style GPIO configuration (Bank A)
  253. * @chip: The gpio chip that is being configured.
  254. * @off: The offset for the GPIO being configured.
  255. * @cfg: The configuration value to set.
  256. *
  257. * This helper deal with the GPIO cases where the control register
  258. * has one bit of configuration for the gpio, where setting the bit
  259. * means the pin is in special function mode and unset means output.
  260. */
  261. static int s3c24xx_gpio_setcfg_abank(struct samsung_gpio_chip *chip,
  262. unsigned int off, unsigned int cfg)
  263. {
  264. void __iomem *reg = chip->base;
  265. unsigned int shift = off;
  266. u32 con;
  267. if (samsung_gpio_is_cfg_special(cfg)) {
  268. cfg &= 0xf;
  269. /* Map output to 0, and SFN2 to 1 */
  270. cfg -= 1;
  271. if (cfg > 1)
  272. return -EINVAL;
  273. cfg <<= shift;
  274. }
  275. con = __raw_readl(reg);
  276. con &= ~(0x1 << shift);
  277. con |= cfg;
  278. __raw_writel(con, reg);
  279. return 0;
  280. }
  281. /*
  282. * s3c24xx_gpio_getcfg_abank - S3C24XX style GPIO configuration read (Bank A)
  283. * @chip: The gpio chip that is being configured.
  284. * @off: The offset for the GPIO being configured.
  285. *
  286. * The reverse of s3c24xx_gpio_setcfg_abank() turning an GPIO into a usable
  287. * GPIO configuration value.
  288. *
  289. * @sa samsung_gpio_getcfg_2bit
  290. * @sa samsung_gpio_getcfg_4bit
  291. */
  292. static unsigned s3c24xx_gpio_getcfg_abank(struct samsung_gpio_chip *chip,
  293. unsigned int off)
  294. {
  295. u32 con;
  296. con = __raw_readl(chip->base);
  297. con >>= off;
  298. con &= 1;
  299. con++;
  300. return S3C_GPIO_SFN(con);
  301. }
  302. #endif
  303. #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
  304. static int s5p64x0_gpio_setcfg_rbank(struct samsung_gpio_chip *chip,
  305. unsigned int off, unsigned int cfg)
  306. {
  307. void __iomem *reg = chip->base;
  308. unsigned int shift;
  309. u32 con;
  310. switch (off) {
  311. case 0:
  312. case 1:
  313. case 2:
  314. case 3:
  315. case 4:
  316. case 5:
  317. shift = (off & 7) * 4;
  318. reg -= 4;
  319. break;
  320. case 6:
  321. shift = ((off + 1) & 7) * 4;
  322. reg -= 4;
  323. default:
  324. shift = ((off + 1) & 7) * 4;
  325. break;
  326. }
  327. if (samsung_gpio_is_cfg_special(cfg)) {
  328. cfg &= 0xf;
  329. cfg <<= shift;
  330. }
  331. con = __raw_readl(reg);
  332. con &= ~(0xf << shift);
  333. con |= cfg;
  334. __raw_writel(con, reg);
  335. return 0;
  336. }
  337. #endif
  338. static void __init samsung_gpiolib_set_cfg(struct samsung_gpio_cfg *chipcfg,
  339. int nr_chips)
  340. {
  341. for (; nr_chips > 0; nr_chips--, chipcfg++) {
  342. if (!chipcfg->set_config)
  343. chipcfg->set_config = samsung_gpio_setcfg_4bit;
  344. if (!chipcfg->get_config)
  345. chipcfg->get_config = samsung_gpio_getcfg_4bit;
  346. if (!chipcfg->set_pull)
  347. chipcfg->set_pull = samsung_gpio_setpull_updown;
  348. if (!chipcfg->get_pull)
  349. chipcfg->get_pull = samsung_gpio_getpull_updown;
  350. }
  351. }
  352. struct samsung_gpio_cfg s3c24xx_gpiocfg_default = {
  353. .set_config = samsung_gpio_setcfg_2bit,
  354. .get_config = samsung_gpio_getcfg_2bit,
  355. };
  356. #ifdef CONFIG_PLAT_S3C24XX
  357. static struct samsung_gpio_cfg s3c24xx_gpiocfg_banka = {
  358. .set_config = s3c24xx_gpio_setcfg_abank,
  359. .get_config = s3c24xx_gpio_getcfg_abank,
  360. };
  361. #endif
  362. #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
  363. static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = {
  364. .cfg_eint = 0x3,
  365. .set_config = s5p64x0_gpio_setcfg_rbank,
  366. .get_config = samsung_gpio_getcfg_4bit,
  367. .set_pull = samsung_gpio_setpull_updown,
  368. .get_pull = samsung_gpio_getpull_updown,
  369. };
  370. #endif
  371. static struct samsung_gpio_cfg samsung_gpio_cfgs[] = {
  372. [0] = {
  373. .cfg_eint = 0x0,
  374. },
  375. [1] = {
  376. .cfg_eint = 0x3,
  377. },
  378. [2] = {
  379. .cfg_eint = 0x7,
  380. },
  381. [3] = {
  382. .cfg_eint = 0xF,
  383. },
  384. [4] = {
  385. .cfg_eint = 0x0,
  386. .set_config = samsung_gpio_setcfg_2bit,
  387. .get_config = samsung_gpio_getcfg_2bit,
  388. },
  389. [5] = {
  390. .cfg_eint = 0x2,
  391. .set_config = samsung_gpio_setcfg_2bit,
  392. .get_config = samsung_gpio_getcfg_2bit,
  393. },
  394. [6] = {
  395. .cfg_eint = 0x3,
  396. .set_config = samsung_gpio_setcfg_2bit,
  397. .get_config = samsung_gpio_getcfg_2bit,
  398. },
  399. [7] = {
  400. .set_config = samsung_gpio_setcfg_2bit,
  401. .get_config = samsung_gpio_getcfg_2bit,
  402. },
  403. };
  404. /*
  405. * Default routines for controlling GPIO, based on the original S3C24XX
  406. * GPIO functions which deal with the case where each gpio bank of the
  407. * chip is as following:
  408. *
  409. * base + 0x00: Control register, 2 bits per gpio
  410. * gpio n: 2 bits starting at (2*n)
  411. * 00 = input, 01 = output, others mean special-function
  412. * base + 0x04: Data register, 1 bit per gpio
  413. * bit n: data bit n
  414. */
  415. static int samsung_gpiolib_2bit_input(struct gpio_chip *chip, unsigned offset)
  416. {
  417. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  418. void __iomem *base = ourchip->base;
  419. unsigned long flags;
  420. unsigned long con;
  421. samsung_gpio_lock(ourchip, flags);
  422. con = __raw_readl(base + 0x00);
  423. con &= ~(3 << (offset * 2));
  424. __raw_writel(con, base + 0x00);
  425. samsung_gpio_unlock(ourchip, flags);
  426. return 0;
  427. }
  428. static int samsung_gpiolib_2bit_output(struct gpio_chip *chip,
  429. unsigned offset, int value)
  430. {
  431. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  432. void __iomem *base = ourchip->base;
  433. unsigned long flags;
  434. unsigned long dat;
  435. unsigned long con;
  436. samsung_gpio_lock(ourchip, flags);
  437. dat = __raw_readl(base + 0x04);
  438. dat &= ~(1 << offset);
  439. if (value)
  440. dat |= 1 << offset;
  441. __raw_writel(dat, base + 0x04);
  442. con = __raw_readl(base + 0x00);
  443. con &= ~(3 << (offset * 2));
  444. con |= 1 << (offset * 2);
  445. __raw_writel(con, base + 0x00);
  446. __raw_writel(dat, base + 0x04);
  447. samsung_gpio_unlock(ourchip, flags);
  448. return 0;
  449. }
  450. /*
  451. * The samsung_gpiolib_4bit routines are to control the gpio banks where
  452. * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
  453. * following example:
  454. *
  455. * base + 0x00: Control register, 4 bits per gpio
  456. * gpio n: 4 bits starting at (4*n)
  457. * 0000 = input, 0001 = output, others mean special-function
  458. * base + 0x04: Data register, 1 bit per gpio
  459. * bit n: data bit n
  460. *
  461. * Note, since the data register is one bit per gpio and is at base + 0x4
  462. * we can use samsung_gpiolib_get and samsung_gpiolib_set to change the
  463. * state of the output.
  464. */
  465. static int samsung_gpiolib_4bit_input(struct gpio_chip *chip,
  466. unsigned int offset)
  467. {
  468. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  469. void __iomem *base = ourchip->base;
  470. unsigned long con;
  471. con = __raw_readl(base + GPIOCON_OFF);
  472. if (ourchip->bitmap_gpio_int & BIT(offset))
  473. con |= 0xf << con_4bit_shift(offset);
  474. else
  475. con &= ~(0xf << con_4bit_shift(offset));
  476. __raw_writel(con, base + GPIOCON_OFF);
  477. pr_debug("%s: %p: CON now %08lx\n", __func__, base, con);
  478. return 0;
  479. }
  480. static int samsung_gpiolib_4bit_output(struct gpio_chip *chip,
  481. unsigned int offset, int value)
  482. {
  483. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  484. void __iomem *base = ourchip->base;
  485. unsigned long con;
  486. unsigned long dat;
  487. con = __raw_readl(base + GPIOCON_OFF);
  488. con &= ~(0xf << con_4bit_shift(offset));
  489. con |= 0x1 << con_4bit_shift(offset);
  490. dat = __raw_readl(base + GPIODAT_OFF);
  491. if (value)
  492. dat |= 1 << offset;
  493. else
  494. dat &= ~(1 << offset);
  495. __raw_writel(dat, base + GPIODAT_OFF);
  496. __raw_writel(con, base + GPIOCON_OFF);
  497. __raw_writel(dat, base + GPIODAT_OFF);
  498. pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
  499. return 0;
  500. }
  501. /*
  502. * The next set of routines are for the case where the GPIO configuration
  503. * registers are 4 bits per GPIO but there is more than one register (the
  504. * bank has more than 8 GPIOs.
  505. *
  506. * This case is the similar to the 4 bit case, but the registers are as
  507. * follows:
  508. *
  509. * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs)
  510. * gpio n: 4 bits starting at (4*n)
  511. * 0000 = input, 0001 = output, others mean special-function
  512. * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs)
  513. * gpio n: 4 bits starting at (4*n)
  514. * 0000 = input, 0001 = output, others mean special-function
  515. * base + 0x08: Data register, 1 bit per gpio
  516. * bit n: data bit n
  517. *
  518. * To allow us to use the samsung_gpiolib_get and samsung_gpiolib_set
  519. * routines we store the 'base + 0x4' address so that these routines see
  520. * the data register at ourchip->base + 0x04.
  521. */
  522. static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip,
  523. unsigned int offset)
  524. {
  525. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  526. void __iomem *base = ourchip->base;
  527. void __iomem *regcon = base;
  528. unsigned long con;
  529. if (offset > 7)
  530. offset -= 8;
  531. else
  532. regcon -= 4;
  533. con = __raw_readl(regcon);
  534. con &= ~(0xf << con_4bit_shift(offset));
  535. __raw_writel(con, regcon);
  536. pr_debug("%s: %p: CON %08lx\n", __func__, base, con);
  537. return 0;
  538. }
  539. static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip,
  540. unsigned int offset, int value)
  541. {
  542. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  543. void __iomem *base = ourchip->base;
  544. void __iomem *regcon = base;
  545. unsigned long con;
  546. unsigned long dat;
  547. unsigned con_offset = offset;
  548. if (con_offset > 7)
  549. con_offset -= 8;
  550. else
  551. regcon -= 4;
  552. con = __raw_readl(regcon);
  553. con &= ~(0xf << con_4bit_shift(con_offset));
  554. con |= 0x1 << con_4bit_shift(con_offset);
  555. dat = __raw_readl(base + GPIODAT_OFF);
  556. if (value)
  557. dat |= 1 << offset;
  558. else
  559. dat &= ~(1 << offset);
  560. __raw_writel(dat, base + GPIODAT_OFF);
  561. __raw_writel(con, regcon);
  562. __raw_writel(dat, base + GPIODAT_OFF);
  563. pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
  564. return 0;
  565. }
  566. #ifdef CONFIG_PLAT_S3C24XX
  567. /* The next set of routines are for the case of s3c24xx bank a */
  568. static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
  569. {
  570. return -EINVAL;
  571. }
  572. static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
  573. unsigned offset, int value)
  574. {
  575. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  576. void __iomem *base = ourchip->base;
  577. unsigned long flags;
  578. unsigned long dat;
  579. unsigned long con;
  580. local_irq_save(flags);
  581. con = __raw_readl(base + 0x00);
  582. dat = __raw_readl(base + 0x04);
  583. dat &= ~(1 << offset);
  584. if (value)
  585. dat |= 1 << offset;
  586. __raw_writel(dat, base + 0x04);
  587. con &= ~(1 << offset);
  588. __raw_writel(con, base + 0x00);
  589. __raw_writel(dat, base + 0x04);
  590. local_irq_restore(flags);
  591. return 0;
  592. }
  593. #endif
  594. /* The next set of routines are for the case of s5p64x0 bank r */
  595. static int s5p64x0_gpiolib_rbank_input(struct gpio_chip *chip,
  596. unsigned int offset)
  597. {
  598. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  599. void __iomem *base = ourchip->base;
  600. void __iomem *regcon = base;
  601. unsigned long con;
  602. unsigned long flags;
  603. switch (offset) {
  604. case 6:
  605. offset += 1;
  606. case 0:
  607. case 1:
  608. case 2:
  609. case 3:
  610. case 4:
  611. case 5:
  612. regcon -= 4;
  613. break;
  614. default:
  615. offset -= 7;
  616. break;
  617. }
  618. samsung_gpio_lock(ourchip, flags);
  619. con = __raw_readl(regcon);
  620. con &= ~(0xf << con_4bit_shift(offset));
  621. __raw_writel(con, regcon);
  622. samsung_gpio_unlock(ourchip, flags);
  623. return 0;
  624. }
  625. static int s5p64x0_gpiolib_rbank_output(struct gpio_chip *chip,
  626. unsigned int offset, int value)
  627. {
  628. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  629. void __iomem *base = ourchip->base;
  630. void __iomem *regcon = base;
  631. unsigned long con;
  632. unsigned long dat;
  633. unsigned long flags;
  634. unsigned con_offset = offset;
  635. switch (con_offset) {
  636. case 6:
  637. con_offset += 1;
  638. case 0:
  639. case 1:
  640. case 2:
  641. case 3:
  642. case 4:
  643. case 5:
  644. regcon -= 4;
  645. break;
  646. default:
  647. con_offset -= 7;
  648. break;
  649. }
  650. samsung_gpio_lock(ourchip, flags);
  651. con = __raw_readl(regcon);
  652. con &= ~(0xf << con_4bit_shift(con_offset));
  653. con |= 0x1 << con_4bit_shift(con_offset);
  654. dat = __raw_readl(base + GPIODAT_OFF);
  655. if (value)
  656. dat |= 1 << offset;
  657. else
  658. dat &= ~(1 << offset);
  659. __raw_writel(con, regcon);
  660. __raw_writel(dat, base + GPIODAT_OFF);
  661. samsung_gpio_unlock(ourchip, flags);
  662. return 0;
  663. }
  664. static void samsung_gpiolib_set(struct gpio_chip *chip,
  665. unsigned offset, int value)
  666. {
  667. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  668. void __iomem *base = ourchip->base;
  669. unsigned long flags;
  670. unsigned long dat;
  671. samsung_gpio_lock(ourchip, flags);
  672. dat = __raw_readl(base + 0x04);
  673. dat &= ~(1 << offset);
  674. if (value)
  675. dat |= 1 << offset;
  676. __raw_writel(dat, base + 0x04);
  677. samsung_gpio_unlock(ourchip, flags);
  678. }
  679. static int samsung_gpiolib_get(struct gpio_chip *chip, unsigned offset)
  680. {
  681. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  682. unsigned long val;
  683. val = __raw_readl(ourchip->base + 0x04);
  684. val >>= offset;
  685. val &= 1;
  686. return val;
  687. }
  688. /*
  689. * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
  690. * for use with the configuration calls, and other parts of the s3c gpiolib
  691. * support code.
  692. *
  693. * Not all s3c support code will need this, as some configurations of cpu
  694. * may only support one or two different configuration options and have an
  695. * easy gpio to samsung_gpio_chip mapping function. If this is the case, then
  696. * the machine support file should provide its own samsung_gpiolib_getchip()
  697. * and any other necessary functions.
  698. */
  699. #ifdef CONFIG_S3C_GPIO_TRACK
  700. struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
  701. static __init void s3c_gpiolib_track(struct samsung_gpio_chip *chip)
  702. {
  703. unsigned int gpn;
  704. int i;
  705. gpn = chip->chip.base;
  706. for (i = 0; i < chip->chip.ngpio; i++, gpn++) {
  707. BUG_ON(gpn >= ARRAY_SIZE(s3c_gpios));
  708. s3c_gpios[gpn] = chip;
  709. }
  710. }
  711. #endif /* CONFIG_S3C_GPIO_TRACK */
  712. /*
  713. * samsung_gpiolib_add() - add the Samsung gpio_chip.
  714. * @chip: The chip to register
  715. *
  716. * This is a wrapper to gpiochip_add() that takes our specific gpio chip
  717. * information and makes the necessary alterations for the platform and
  718. * notes the information for use with the configuration systems and any
  719. * other parts of the system.
  720. */
  721. static void __init samsung_gpiolib_add(struct samsung_gpio_chip *chip)
  722. {
  723. struct gpio_chip *gc = &chip->chip;
  724. int ret;
  725. BUG_ON(!chip->base);
  726. BUG_ON(!gc->label);
  727. BUG_ON(!gc->ngpio);
  728. spin_lock_init(&chip->lock);
  729. if (!gc->direction_input)
  730. gc->direction_input = samsung_gpiolib_2bit_input;
  731. if (!gc->direction_output)
  732. gc->direction_output = samsung_gpiolib_2bit_output;
  733. if (!gc->set)
  734. gc->set = samsung_gpiolib_set;
  735. if (!gc->get)
  736. gc->get = samsung_gpiolib_get;
  737. #ifdef CONFIG_PM
  738. if (chip->pm != NULL) {
  739. if (!chip->pm->save || !chip->pm->resume)
  740. pr_err("gpio: %s has missing PM functions\n",
  741. gc->label);
  742. } else
  743. pr_err("gpio: %s has no PM function\n", gc->label);
  744. #endif
  745. /* gpiochip_add() prints own failure message on error. */
  746. ret = gpiochip_add(gc);
  747. if (ret >= 0)
  748. s3c_gpiolib_track(chip);
  749. }
  750. static void __init s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip *chip,
  751. int nr_chips, void __iomem *base)
  752. {
  753. int i;
  754. struct gpio_chip *gc = &chip->chip;
  755. for (i = 0 ; i < nr_chips; i++, chip++) {
  756. /* skip banks not present on SoC */
  757. if (chip->chip.base >= S3C_GPIO_END)
  758. continue;
  759. if (!chip->config)
  760. chip->config = &s3c24xx_gpiocfg_default;
  761. if (!chip->pm)
  762. chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
  763. if ((base != NULL) && (chip->base == NULL))
  764. chip->base = base + ((i) * 0x10);
  765. if (!gc->direction_input)
  766. gc->direction_input = samsung_gpiolib_2bit_input;
  767. if (!gc->direction_output)
  768. gc->direction_output = samsung_gpiolib_2bit_output;
  769. samsung_gpiolib_add(chip);
  770. }
  771. }
  772. static void __init samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip *chip,
  773. int nr_chips, void __iomem *base,
  774. unsigned int offset)
  775. {
  776. int i;
  777. for (i = 0 ; i < nr_chips; i++, chip++) {
  778. chip->chip.direction_input = samsung_gpiolib_2bit_input;
  779. chip->chip.direction_output = samsung_gpiolib_2bit_output;
  780. if (!chip->config)
  781. chip->config = &samsung_gpio_cfgs[7];
  782. if (!chip->pm)
  783. chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
  784. if ((base != NULL) && (chip->base == NULL))
  785. chip->base = base + ((i) * offset);
  786. samsung_gpiolib_add(chip);
  787. }
  788. }
  789. /*
  790. * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
  791. * @chip: The gpio chip that is being configured.
  792. * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
  793. *
  794. * This helper deal with the GPIO cases where the control register has 4 bits
  795. * of control per GPIO, generally in the form of:
  796. * 0000 = Input
  797. * 0001 = Output
  798. * others = Special functions (dependent on bank)
  799. *
  800. * Note, since the code to deal with the case where there are two control
  801. * registers instead of one, we do not have a separate set of function
  802. * (samsung_gpiolib_add_4bit2_chips)for each case.
  803. */
  804. static void __init samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip *chip,
  805. int nr_chips, void __iomem *base)
  806. {
  807. int i;
  808. for (i = 0 ; i < nr_chips; i++, chip++) {
  809. chip->chip.direction_input = samsung_gpiolib_4bit_input;
  810. chip->chip.direction_output = samsung_gpiolib_4bit_output;
  811. if (!chip->config)
  812. chip->config = &samsung_gpio_cfgs[2];
  813. if (!chip->pm)
  814. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  815. if ((base != NULL) && (chip->base == NULL))
  816. chip->base = base + ((i) * 0x20);
  817. chip->bitmap_gpio_int = 0;
  818. samsung_gpiolib_add(chip);
  819. }
  820. }
  821. static void __init samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip *chip,
  822. int nr_chips)
  823. {
  824. for (; nr_chips > 0; nr_chips--, chip++) {
  825. chip->chip.direction_input = samsung_gpiolib_4bit2_input;
  826. chip->chip.direction_output = samsung_gpiolib_4bit2_output;
  827. if (!chip->config)
  828. chip->config = &samsung_gpio_cfgs[2];
  829. if (!chip->pm)
  830. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  831. samsung_gpiolib_add(chip);
  832. }
  833. }
  834. static void __init s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip *chip,
  835. int nr_chips)
  836. {
  837. for (; nr_chips > 0; nr_chips--, chip++) {
  838. chip->chip.direction_input = s5p64x0_gpiolib_rbank_input;
  839. chip->chip.direction_output = s5p64x0_gpiolib_rbank_output;
  840. if (!chip->pm)
  841. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  842. samsung_gpiolib_add(chip);
  843. }
  844. }
  845. int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
  846. {
  847. struct samsung_gpio_chip *samsung_chip = container_of(chip, struct samsung_gpio_chip, chip);
  848. return samsung_chip->irq_base + offset;
  849. }
  850. #ifdef CONFIG_PLAT_S3C24XX
  851. static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset)
  852. {
  853. if (offset < 4) {
  854. if (soc_is_s3c2412())
  855. return IRQ_EINT0_2412 + offset;
  856. else
  857. return IRQ_EINT0 + offset;
  858. }
  859. if (offset < 8)
  860. return IRQ_EINT4 + offset - 4;
  861. return -EINVAL;
  862. }
  863. #endif
  864. #ifdef CONFIG_ARCH_S3C64XX
  865. static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin)
  866. {
  867. return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
  868. }
  869. static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin)
  870. {
  871. return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
  872. }
  873. #endif
  874. struct samsung_gpio_chip s3c24xx_gpios[] = {
  875. #ifdef CONFIG_PLAT_S3C24XX
  876. {
  877. .config = &s3c24xx_gpiocfg_banka,
  878. .chip = {
  879. .base = S3C2410_GPA(0),
  880. .owner = THIS_MODULE,
  881. .label = "GPIOA",
  882. .ngpio = 27,
  883. .direction_input = s3c24xx_gpiolib_banka_input,
  884. .direction_output = s3c24xx_gpiolib_banka_output,
  885. },
  886. }, {
  887. .chip = {
  888. .base = S3C2410_GPB(0),
  889. .owner = THIS_MODULE,
  890. .label = "GPIOB",
  891. .ngpio = 11,
  892. },
  893. }, {
  894. .chip = {
  895. .base = S3C2410_GPC(0),
  896. .owner = THIS_MODULE,
  897. .label = "GPIOC",
  898. .ngpio = 16,
  899. },
  900. }, {
  901. .chip = {
  902. .base = S3C2410_GPD(0),
  903. .owner = THIS_MODULE,
  904. .label = "GPIOD",
  905. .ngpio = 16,
  906. },
  907. }, {
  908. .chip = {
  909. .base = S3C2410_GPE(0),
  910. .label = "GPIOE",
  911. .owner = THIS_MODULE,
  912. .ngpio = 16,
  913. },
  914. }, {
  915. .chip = {
  916. .base = S3C2410_GPF(0),
  917. .owner = THIS_MODULE,
  918. .label = "GPIOF",
  919. .ngpio = 8,
  920. .to_irq = s3c24xx_gpiolib_fbank_to_irq,
  921. },
  922. }, {
  923. .irq_base = IRQ_EINT8,
  924. .chip = {
  925. .base = S3C2410_GPG(0),
  926. .owner = THIS_MODULE,
  927. .label = "GPIOG",
  928. .ngpio = 16,
  929. .to_irq = samsung_gpiolib_to_irq,
  930. },
  931. }, {
  932. .chip = {
  933. .base = S3C2410_GPH(0),
  934. .owner = THIS_MODULE,
  935. .label = "GPIOH",
  936. .ngpio = 15,
  937. },
  938. },
  939. /* GPIOS for the S3C2443 and later devices. */
  940. {
  941. .base = S3C2440_GPJCON,
  942. .chip = {
  943. .base = S3C2410_GPJ(0),
  944. .owner = THIS_MODULE,
  945. .label = "GPIOJ",
  946. .ngpio = 16,
  947. },
  948. }, {
  949. .base = S3C2443_GPKCON,
  950. .chip = {
  951. .base = S3C2410_GPK(0),
  952. .owner = THIS_MODULE,
  953. .label = "GPIOK",
  954. .ngpio = 16,
  955. },
  956. }, {
  957. .base = S3C2443_GPLCON,
  958. .chip = {
  959. .base = S3C2410_GPL(0),
  960. .owner = THIS_MODULE,
  961. .label = "GPIOL",
  962. .ngpio = 15,
  963. },
  964. }, {
  965. .base = S3C2443_GPMCON,
  966. .chip = {
  967. .base = S3C2410_GPM(0),
  968. .owner = THIS_MODULE,
  969. .label = "GPIOM",
  970. .ngpio = 2,
  971. },
  972. },
  973. #endif
  974. };
  975. /*
  976. * GPIO bank summary:
  977. *
  978. * Bank GPIOs Style SlpCon ExtInt Group
  979. * A 8 4Bit Yes 1
  980. * B 7 4Bit Yes 1
  981. * C 8 4Bit Yes 2
  982. * D 5 4Bit Yes 3
  983. * E 5 4Bit Yes None
  984. * F 16 2Bit Yes 4 [1]
  985. * G 7 4Bit Yes 5
  986. * H 10 4Bit[2] Yes 6
  987. * I 16 2Bit Yes None
  988. * J 12 2Bit Yes None
  989. * K 16 4Bit[2] No None
  990. * L 15 4Bit[2] No None
  991. * M 6 4Bit No IRQ_EINT
  992. * N 16 2Bit No IRQ_EINT
  993. * O 16 2Bit Yes 7
  994. * P 15 2Bit Yes 8
  995. * Q 9 2Bit Yes 9
  996. *
  997. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  998. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  999. */
  1000. static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = {
  1001. #ifdef CONFIG_ARCH_S3C64XX
  1002. {
  1003. .chip = {
  1004. .base = S3C64XX_GPA(0),
  1005. .ngpio = S3C64XX_GPIO_A_NR,
  1006. .label = "GPA",
  1007. },
  1008. }, {
  1009. .chip = {
  1010. .base = S3C64XX_GPB(0),
  1011. .ngpio = S3C64XX_GPIO_B_NR,
  1012. .label = "GPB",
  1013. },
  1014. }, {
  1015. .chip = {
  1016. .base = S3C64XX_GPC(0),
  1017. .ngpio = S3C64XX_GPIO_C_NR,
  1018. .label = "GPC",
  1019. },
  1020. }, {
  1021. .chip = {
  1022. .base = S3C64XX_GPD(0),
  1023. .ngpio = S3C64XX_GPIO_D_NR,
  1024. .label = "GPD",
  1025. },
  1026. }, {
  1027. .config = &samsung_gpio_cfgs[0],
  1028. .chip = {
  1029. .base = S3C64XX_GPE(0),
  1030. .ngpio = S3C64XX_GPIO_E_NR,
  1031. .label = "GPE",
  1032. },
  1033. }, {
  1034. .base = S3C64XX_GPG_BASE,
  1035. .chip = {
  1036. .base = S3C64XX_GPG(0),
  1037. .ngpio = S3C64XX_GPIO_G_NR,
  1038. .label = "GPG",
  1039. },
  1040. }, {
  1041. .base = S3C64XX_GPM_BASE,
  1042. .config = &samsung_gpio_cfgs[1],
  1043. .chip = {
  1044. .base = S3C64XX_GPM(0),
  1045. .ngpio = S3C64XX_GPIO_M_NR,
  1046. .label = "GPM",
  1047. .to_irq = s3c64xx_gpiolib_mbank_to_irq,
  1048. },
  1049. },
  1050. #endif
  1051. };
  1052. static struct samsung_gpio_chip s3c64xx_gpios_4bit2[] = {
  1053. #ifdef CONFIG_ARCH_S3C64XX
  1054. {
  1055. .base = S3C64XX_GPH_BASE + 0x4,
  1056. .chip = {
  1057. .base = S3C64XX_GPH(0),
  1058. .ngpio = S3C64XX_GPIO_H_NR,
  1059. .label = "GPH",
  1060. },
  1061. }, {
  1062. .base = S3C64XX_GPK_BASE + 0x4,
  1063. .config = &samsung_gpio_cfgs[0],
  1064. .chip = {
  1065. .base = S3C64XX_GPK(0),
  1066. .ngpio = S3C64XX_GPIO_K_NR,
  1067. .label = "GPK",
  1068. },
  1069. }, {
  1070. .base = S3C64XX_GPL_BASE + 0x4,
  1071. .config = &samsung_gpio_cfgs[1],
  1072. .chip = {
  1073. .base = S3C64XX_GPL(0),
  1074. .ngpio = S3C64XX_GPIO_L_NR,
  1075. .label = "GPL",
  1076. .to_irq = s3c64xx_gpiolib_lbank_to_irq,
  1077. },
  1078. },
  1079. #endif
  1080. };
  1081. static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = {
  1082. #ifdef CONFIG_ARCH_S3C64XX
  1083. {
  1084. .base = S3C64XX_GPF_BASE,
  1085. .config = &samsung_gpio_cfgs[6],
  1086. .chip = {
  1087. .base = S3C64XX_GPF(0),
  1088. .ngpio = S3C64XX_GPIO_F_NR,
  1089. .label = "GPF",
  1090. },
  1091. }, {
  1092. .config = &samsung_gpio_cfgs[7],
  1093. .chip = {
  1094. .base = S3C64XX_GPI(0),
  1095. .ngpio = S3C64XX_GPIO_I_NR,
  1096. .label = "GPI",
  1097. },
  1098. }, {
  1099. .config = &samsung_gpio_cfgs[7],
  1100. .chip = {
  1101. .base = S3C64XX_GPJ(0),
  1102. .ngpio = S3C64XX_GPIO_J_NR,
  1103. .label = "GPJ",
  1104. },
  1105. }, {
  1106. .config = &samsung_gpio_cfgs[6],
  1107. .chip = {
  1108. .base = S3C64XX_GPO(0),
  1109. .ngpio = S3C64XX_GPIO_O_NR,
  1110. .label = "GPO",
  1111. },
  1112. }, {
  1113. .config = &samsung_gpio_cfgs[6],
  1114. .chip = {
  1115. .base = S3C64XX_GPP(0),
  1116. .ngpio = S3C64XX_GPIO_P_NR,
  1117. .label = "GPP",
  1118. },
  1119. }, {
  1120. .config = &samsung_gpio_cfgs[6],
  1121. .chip = {
  1122. .base = S3C64XX_GPQ(0),
  1123. .ngpio = S3C64XX_GPIO_Q_NR,
  1124. .label = "GPQ",
  1125. },
  1126. }, {
  1127. .base = S3C64XX_GPN_BASE,
  1128. .irq_base = IRQ_EINT(0),
  1129. .config = &samsung_gpio_cfgs[5],
  1130. .chip = {
  1131. .base = S3C64XX_GPN(0),
  1132. .ngpio = S3C64XX_GPIO_N_NR,
  1133. .label = "GPN",
  1134. .to_irq = samsung_gpiolib_to_irq,
  1135. },
  1136. },
  1137. #endif
  1138. };
  1139. /*
  1140. * S5P6440 GPIO bank summary:
  1141. *
  1142. * Bank GPIOs Style SlpCon ExtInt Group
  1143. * A 6 4Bit Yes 1
  1144. * B 7 4Bit Yes 1
  1145. * C 8 4Bit Yes 2
  1146. * F 2 2Bit Yes 4 [1]
  1147. * G 7 4Bit Yes 5
  1148. * H 10 4Bit[2] Yes 6
  1149. * I 16 2Bit Yes None
  1150. * J 12 2Bit Yes None
  1151. * N 16 2Bit No IRQ_EINT
  1152. * P 8 2Bit Yes 8
  1153. * R 15 4Bit[2] Yes 8
  1154. */
  1155. static struct samsung_gpio_chip s5p6440_gpios_4bit[] = {
  1156. #ifdef CONFIG_CPU_S5P6440
  1157. {
  1158. .chip = {
  1159. .base = S5P6440_GPA(0),
  1160. .ngpio = S5P6440_GPIO_A_NR,
  1161. .label = "GPA",
  1162. },
  1163. }, {
  1164. .chip = {
  1165. .base = S5P6440_GPB(0),
  1166. .ngpio = S5P6440_GPIO_B_NR,
  1167. .label = "GPB",
  1168. },
  1169. }, {
  1170. .chip = {
  1171. .base = S5P6440_GPC(0),
  1172. .ngpio = S5P6440_GPIO_C_NR,
  1173. .label = "GPC",
  1174. },
  1175. }, {
  1176. .base = S5P64X0_GPG_BASE,
  1177. .chip = {
  1178. .base = S5P6440_GPG(0),
  1179. .ngpio = S5P6440_GPIO_G_NR,
  1180. .label = "GPG",
  1181. },
  1182. },
  1183. #endif
  1184. };
  1185. static struct samsung_gpio_chip s5p6440_gpios_4bit2[] = {
  1186. #ifdef CONFIG_CPU_S5P6440
  1187. {
  1188. .base = S5P64X0_GPH_BASE + 0x4,
  1189. .chip = {
  1190. .base = S5P6440_GPH(0),
  1191. .ngpio = S5P6440_GPIO_H_NR,
  1192. .label = "GPH",
  1193. },
  1194. },
  1195. #endif
  1196. };
  1197. static struct samsung_gpio_chip s5p6440_gpios_rbank[] = {
  1198. #ifdef CONFIG_CPU_S5P6440
  1199. {
  1200. .base = S5P64X0_GPR_BASE + 0x4,
  1201. .config = &s5p64x0_gpio_cfg_rbank,
  1202. .chip = {
  1203. .base = S5P6440_GPR(0),
  1204. .ngpio = S5P6440_GPIO_R_NR,
  1205. .label = "GPR",
  1206. },
  1207. },
  1208. #endif
  1209. };
  1210. static struct samsung_gpio_chip s5p6440_gpios_2bit[] = {
  1211. #ifdef CONFIG_CPU_S5P6440
  1212. {
  1213. .base = S5P64X0_GPF_BASE,
  1214. .config = &samsung_gpio_cfgs[6],
  1215. .chip = {
  1216. .base = S5P6440_GPF(0),
  1217. .ngpio = S5P6440_GPIO_F_NR,
  1218. .label = "GPF",
  1219. },
  1220. }, {
  1221. .base = S5P64X0_GPI_BASE,
  1222. .config = &samsung_gpio_cfgs[4],
  1223. .chip = {
  1224. .base = S5P6440_GPI(0),
  1225. .ngpio = S5P6440_GPIO_I_NR,
  1226. .label = "GPI",
  1227. },
  1228. }, {
  1229. .base = S5P64X0_GPJ_BASE,
  1230. .config = &samsung_gpio_cfgs[4],
  1231. .chip = {
  1232. .base = S5P6440_GPJ(0),
  1233. .ngpio = S5P6440_GPIO_J_NR,
  1234. .label = "GPJ",
  1235. },
  1236. }, {
  1237. .base = S5P64X0_GPN_BASE,
  1238. .config = &samsung_gpio_cfgs[5],
  1239. .chip = {
  1240. .base = S5P6440_GPN(0),
  1241. .ngpio = S5P6440_GPIO_N_NR,
  1242. .label = "GPN",
  1243. },
  1244. }, {
  1245. .base = S5P64X0_GPP_BASE,
  1246. .config = &samsung_gpio_cfgs[6],
  1247. .chip = {
  1248. .base = S5P6440_GPP(0),
  1249. .ngpio = S5P6440_GPIO_P_NR,
  1250. .label = "GPP",
  1251. },
  1252. },
  1253. #endif
  1254. };
  1255. /*
  1256. * S5P6450 GPIO bank summary:
  1257. *
  1258. * Bank GPIOs Style SlpCon ExtInt Group
  1259. * A 6 4Bit Yes 1
  1260. * B 7 4Bit Yes 1
  1261. * C 8 4Bit Yes 2
  1262. * D 8 4Bit Yes None
  1263. * F 2 2Bit Yes None
  1264. * G 14 4Bit[2] Yes 5
  1265. * H 10 4Bit[2] Yes 6
  1266. * I 16 2Bit Yes None
  1267. * J 12 2Bit Yes None
  1268. * K 5 4Bit Yes None
  1269. * N 16 2Bit No IRQ_EINT
  1270. * P 11 2Bit Yes 8
  1271. * Q 14 2Bit Yes None
  1272. * R 15 4Bit[2] Yes None
  1273. * S 8 2Bit Yes None
  1274. *
  1275. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  1276. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  1277. */
  1278. static struct samsung_gpio_chip s5p6450_gpios_4bit[] = {
  1279. #ifdef CONFIG_CPU_S5P6450
  1280. {
  1281. .chip = {
  1282. .base = S5P6450_GPA(0),
  1283. .ngpio = S5P6450_GPIO_A_NR,
  1284. .label = "GPA",
  1285. },
  1286. }, {
  1287. .chip = {
  1288. .base = S5P6450_GPB(0),
  1289. .ngpio = S5P6450_GPIO_B_NR,
  1290. .label = "GPB",
  1291. },
  1292. }, {
  1293. .chip = {
  1294. .base = S5P6450_GPC(0),
  1295. .ngpio = S5P6450_GPIO_C_NR,
  1296. .label = "GPC",
  1297. },
  1298. }, {
  1299. .chip = {
  1300. .base = S5P6450_GPD(0),
  1301. .ngpio = S5P6450_GPIO_D_NR,
  1302. .label = "GPD",
  1303. },
  1304. }, {
  1305. .base = S5P6450_GPK_BASE,
  1306. .chip = {
  1307. .base = S5P6450_GPK(0),
  1308. .ngpio = S5P6450_GPIO_K_NR,
  1309. .label = "GPK",
  1310. },
  1311. },
  1312. #endif
  1313. };
  1314. static struct samsung_gpio_chip s5p6450_gpios_4bit2[] = {
  1315. #ifdef CONFIG_CPU_S5P6450
  1316. {
  1317. .base = S5P64X0_GPG_BASE + 0x4,
  1318. .chip = {
  1319. .base = S5P6450_GPG(0),
  1320. .ngpio = S5P6450_GPIO_G_NR,
  1321. .label = "GPG",
  1322. },
  1323. }, {
  1324. .base = S5P64X0_GPH_BASE + 0x4,
  1325. .chip = {
  1326. .base = S5P6450_GPH(0),
  1327. .ngpio = S5P6450_GPIO_H_NR,
  1328. .label = "GPH",
  1329. },
  1330. },
  1331. #endif
  1332. };
  1333. static struct samsung_gpio_chip s5p6450_gpios_rbank[] = {
  1334. #ifdef CONFIG_CPU_S5P6450
  1335. {
  1336. .base = S5P64X0_GPR_BASE + 0x4,
  1337. .config = &s5p64x0_gpio_cfg_rbank,
  1338. .chip = {
  1339. .base = S5P6450_GPR(0),
  1340. .ngpio = S5P6450_GPIO_R_NR,
  1341. .label = "GPR",
  1342. },
  1343. },
  1344. #endif
  1345. };
  1346. static struct samsung_gpio_chip s5p6450_gpios_2bit[] = {
  1347. #ifdef CONFIG_CPU_S5P6450
  1348. {
  1349. .base = S5P64X0_GPF_BASE,
  1350. .config = &samsung_gpio_cfgs[6],
  1351. .chip = {
  1352. .base = S5P6450_GPF(0),
  1353. .ngpio = S5P6450_GPIO_F_NR,
  1354. .label = "GPF",
  1355. },
  1356. }, {
  1357. .base = S5P64X0_GPI_BASE,
  1358. .config = &samsung_gpio_cfgs[4],
  1359. .chip = {
  1360. .base = S5P6450_GPI(0),
  1361. .ngpio = S5P6450_GPIO_I_NR,
  1362. .label = "GPI",
  1363. },
  1364. }, {
  1365. .base = S5P64X0_GPJ_BASE,
  1366. .config = &samsung_gpio_cfgs[4],
  1367. .chip = {
  1368. .base = S5P6450_GPJ(0),
  1369. .ngpio = S5P6450_GPIO_J_NR,
  1370. .label = "GPJ",
  1371. },
  1372. }, {
  1373. .base = S5P64X0_GPN_BASE,
  1374. .config = &samsung_gpio_cfgs[5],
  1375. .chip = {
  1376. .base = S5P6450_GPN(0),
  1377. .ngpio = S5P6450_GPIO_N_NR,
  1378. .label = "GPN",
  1379. },
  1380. }, {
  1381. .base = S5P64X0_GPP_BASE,
  1382. .config = &samsung_gpio_cfgs[6],
  1383. .chip = {
  1384. .base = S5P6450_GPP(0),
  1385. .ngpio = S5P6450_GPIO_P_NR,
  1386. .label = "GPP",
  1387. },
  1388. }, {
  1389. .base = S5P6450_GPQ_BASE,
  1390. .config = &samsung_gpio_cfgs[5],
  1391. .chip = {
  1392. .base = S5P6450_GPQ(0),
  1393. .ngpio = S5P6450_GPIO_Q_NR,
  1394. .label = "GPQ",
  1395. },
  1396. }, {
  1397. .base = S5P6450_GPS_BASE,
  1398. .config = &samsung_gpio_cfgs[6],
  1399. .chip = {
  1400. .base = S5P6450_GPS(0),
  1401. .ngpio = S5P6450_GPIO_S_NR,
  1402. .label = "GPS",
  1403. },
  1404. },
  1405. #endif
  1406. };
  1407. /*
  1408. * S5PC100 GPIO bank summary:
  1409. *
  1410. * Bank GPIOs Style INT Type
  1411. * A0 8 4Bit GPIO_INT0
  1412. * A1 5 4Bit GPIO_INT1
  1413. * B 8 4Bit GPIO_INT2
  1414. * C 5 4Bit GPIO_INT3
  1415. * D 7 4Bit GPIO_INT4
  1416. * E0 8 4Bit GPIO_INT5
  1417. * E1 6 4Bit GPIO_INT6
  1418. * F0 8 4Bit GPIO_INT7
  1419. * F1 8 4Bit GPIO_INT8
  1420. * F2 8 4Bit GPIO_INT9
  1421. * F3 4 4Bit GPIO_INT10
  1422. * G0 8 4Bit GPIO_INT11
  1423. * G1 3 4Bit GPIO_INT12
  1424. * G2 7 4Bit GPIO_INT13
  1425. * G3 7 4Bit GPIO_INT14
  1426. * H0 8 4Bit WKUP_INT
  1427. * H1 8 4Bit WKUP_INT
  1428. * H2 8 4Bit WKUP_INT
  1429. * H3 8 4Bit WKUP_INT
  1430. * I 8 4Bit GPIO_INT15
  1431. * J0 8 4Bit GPIO_INT16
  1432. * J1 5 4Bit GPIO_INT17
  1433. * J2 8 4Bit GPIO_INT18
  1434. * J3 8 4Bit GPIO_INT19
  1435. * J4 4 4Bit GPIO_INT20
  1436. * K0 8 4Bit None
  1437. * K1 6 4Bit None
  1438. * K2 8 4Bit None
  1439. * K3 8 4Bit None
  1440. * L0 8 4Bit None
  1441. * L1 8 4Bit None
  1442. * L2 8 4Bit None
  1443. * L3 8 4Bit None
  1444. */
  1445. static struct samsung_gpio_chip s5pc100_gpios_4bit[] = {
  1446. #ifdef CONFIG_CPU_S5PC100
  1447. {
  1448. .chip = {
  1449. .base = S5PC100_GPA0(0),
  1450. .ngpio = S5PC100_GPIO_A0_NR,
  1451. .label = "GPA0",
  1452. },
  1453. }, {
  1454. .chip = {
  1455. .base = S5PC100_GPA1(0),
  1456. .ngpio = S5PC100_GPIO_A1_NR,
  1457. .label = "GPA1",
  1458. },
  1459. }, {
  1460. .chip = {
  1461. .base = S5PC100_GPB(0),
  1462. .ngpio = S5PC100_GPIO_B_NR,
  1463. .label = "GPB",
  1464. },
  1465. }, {
  1466. .chip = {
  1467. .base = S5PC100_GPC(0),
  1468. .ngpio = S5PC100_GPIO_C_NR,
  1469. .label = "GPC",
  1470. },
  1471. }, {
  1472. .chip = {
  1473. .base = S5PC100_GPD(0),
  1474. .ngpio = S5PC100_GPIO_D_NR,
  1475. .label = "GPD",
  1476. },
  1477. }, {
  1478. .chip = {
  1479. .base = S5PC100_GPE0(0),
  1480. .ngpio = S5PC100_GPIO_E0_NR,
  1481. .label = "GPE0",
  1482. },
  1483. }, {
  1484. .chip = {
  1485. .base = S5PC100_GPE1(0),
  1486. .ngpio = S5PC100_GPIO_E1_NR,
  1487. .label = "GPE1",
  1488. },
  1489. }, {
  1490. .chip = {
  1491. .base = S5PC100_GPF0(0),
  1492. .ngpio = S5PC100_GPIO_F0_NR,
  1493. .label = "GPF0",
  1494. },
  1495. }, {
  1496. .chip = {
  1497. .base = S5PC100_GPF1(0),
  1498. .ngpio = S5PC100_GPIO_F1_NR,
  1499. .label = "GPF1",
  1500. },
  1501. }, {
  1502. .chip = {
  1503. .base = S5PC100_GPF2(0),
  1504. .ngpio = S5PC100_GPIO_F2_NR,
  1505. .label = "GPF2",
  1506. },
  1507. }, {
  1508. .chip = {
  1509. .base = S5PC100_GPF3(0),
  1510. .ngpio = S5PC100_GPIO_F3_NR,
  1511. .label = "GPF3",
  1512. },
  1513. }, {
  1514. .chip = {
  1515. .base = S5PC100_GPG0(0),
  1516. .ngpio = S5PC100_GPIO_G0_NR,
  1517. .label = "GPG0",
  1518. },
  1519. }, {
  1520. .chip = {
  1521. .base = S5PC100_GPG1(0),
  1522. .ngpio = S5PC100_GPIO_G1_NR,
  1523. .label = "GPG1",
  1524. },
  1525. }, {
  1526. .chip = {
  1527. .base = S5PC100_GPG2(0),
  1528. .ngpio = S5PC100_GPIO_G2_NR,
  1529. .label = "GPG2",
  1530. },
  1531. }, {
  1532. .chip = {
  1533. .base = S5PC100_GPG3(0),
  1534. .ngpio = S5PC100_GPIO_G3_NR,
  1535. .label = "GPG3",
  1536. },
  1537. }, {
  1538. .chip = {
  1539. .base = S5PC100_GPI(0),
  1540. .ngpio = S5PC100_GPIO_I_NR,
  1541. .label = "GPI",
  1542. },
  1543. }, {
  1544. .chip = {
  1545. .base = S5PC100_GPJ0(0),
  1546. .ngpio = S5PC100_GPIO_J0_NR,
  1547. .label = "GPJ0",
  1548. },
  1549. }, {
  1550. .chip = {
  1551. .base = S5PC100_GPJ1(0),
  1552. .ngpio = S5PC100_GPIO_J1_NR,
  1553. .label = "GPJ1",
  1554. },
  1555. }, {
  1556. .chip = {
  1557. .base = S5PC100_GPJ2(0),
  1558. .ngpio = S5PC100_GPIO_J2_NR,
  1559. .label = "GPJ2",
  1560. },
  1561. }, {
  1562. .chip = {
  1563. .base = S5PC100_GPJ3(0),
  1564. .ngpio = S5PC100_GPIO_J3_NR,
  1565. .label = "GPJ3",
  1566. },
  1567. }, {
  1568. .chip = {
  1569. .base = S5PC100_GPJ4(0),
  1570. .ngpio = S5PC100_GPIO_J4_NR,
  1571. .label = "GPJ4",
  1572. },
  1573. }, {
  1574. .chip = {
  1575. .base = S5PC100_GPK0(0),
  1576. .ngpio = S5PC100_GPIO_K0_NR,
  1577. .label = "GPK0",
  1578. },
  1579. }, {
  1580. .chip = {
  1581. .base = S5PC100_GPK1(0),
  1582. .ngpio = S5PC100_GPIO_K1_NR,
  1583. .label = "GPK1",
  1584. },
  1585. }, {
  1586. .chip = {
  1587. .base = S5PC100_GPK2(0),
  1588. .ngpio = S5PC100_GPIO_K2_NR,
  1589. .label = "GPK2",
  1590. },
  1591. }, {
  1592. .chip = {
  1593. .base = S5PC100_GPK3(0),
  1594. .ngpio = S5PC100_GPIO_K3_NR,
  1595. .label = "GPK3",
  1596. },
  1597. }, {
  1598. .chip = {
  1599. .base = S5PC100_GPL0(0),
  1600. .ngpio = S5PC100_GPIO_L0_NR,
  1601. .label = "GPL0",
  1602. },
  1603. }, {
  1604. .chip = {
  1605. .base = S5PC100_GPL1(0),
  1606. .ngpio = S5PC100_GPIO_L1_NR,
  1607. .label = "GPL1",
  1608. },
  1609. }, {
  1610. .chip = {
  1611. .base = S5PC100_GPL2(0),
  1612. .ngpio = S5PC100_GPIO_L2_NR,
  1613. .label = "GPL2",
  1614. },
  1615. }, {
  1616. .chip = {
  1617. .base = S5PC100_GPL3(0),
  1618. .ngpio = S5PC100_GPIO_L3_NR,
  1619. .label = "GPL3",
  1620. },
  1621. }, {
  1622. .chip = {
  1623. .base = S5PC100_GPL4(0),
  1624. .ngpio = S5PC100_GPIO_L4_NR,
  1625. .label = "GPL4",
  1626. },
  1627. }, {
  1628. .base = (S5P_VA_GPIO + 0xC00),
  1629. .irq_base = IRQ_EINT(0),
  1630. .chip = {
  1631. .base = S5PC100_GPH0(0),
  1632. .ngpio = S5PC100_GPIO_H0_NR,
  1633. .label = "GPH0",
  1634. .to_irq = samsung_gpiolib_to_irq,
  1635. },
  1636. }, {
  1637. .base = (S5P_VA_GPIO + 0xC20),
  1638. .irq_base = IRQ_EINT(8),
  1639. .chip = {
  1640. .base = S5PC100_GPH1(0),
  1641. .ngpio = S5PC100_GPIO_H1_NR,
  1642. .label = "GPH1",
  1643. .to_irq = samsung_gpiolib_to_irq,
  1644. },
  1645. }, {
  1646. .base = (S5P_VA_GPIO + 0xC40),
  1647. .irq_base = IRQ_EINT(16),
  1648. .chip = {
  1649. .base = S5PC100_GPH2(0),
  1650. .ngpio = S5PC100_GPIO_H2_NR,
  1651. .label = "GPH2",
  1652. .to_irq = samsung_gpiolib_to_irq,
  1653. },
  1654. }, {
  1655. .base = (S5P_VA_GPIO + 0xC60),
  1656. .irq_base = IRQ_EINT(24),
  1657. .chip = {
  1658. .base = S5PC100_GPH3(0),
  1659. .ngpio = S5PC100_GPIO_H3_NR,
  1660. .label = "GPH3",
  1661. .to_irq = samsung_gpiolib_to_irq,
  1662. },
  1663. },
  1664. #endif
  1665. };
  1666. /*
  1667. * Followings are the gpio banks in S5PV210/S5PC110
  1668. *
  1669. * The 'config' member when left to NULL, is initialized to the default
  1670. * structure samsung_gpio_cfgs[3] in the init function below.
  1671. *
  1672. * The 'base' member is also initialized in the init function below.
  1673. * Note: The initialization of 'base' member of samsung_gpio_chip structure
  1674. * uses the above macro and depends on the banks being listed in order here.
  1675. */
  1676. static struct samsung_gpio_chip s5pv210_gpios_4bit[] = {
  1677. #ifdef CONFIG_CPU_S5PV210
  1678. {
  1679. .chip = {
  1680. .base = S5PV210_GPA0(0),
  1681. .ngpio = S5PV210_GPIO_A0_NR,
  1682. .label = "GPA0",
  1683. },
  1684. }, {
  1685. .chip = {
  1686. .base = S5PV210_GPA1(0),
  1687. .ngpio = S5PV210_GPIO_A1_NR,
  1688. .label = "GPA1",
  1689. },
  1690. }, {
  1691. .chip = {
  1692. .base = S5PV210_GPB(0),
  1693. .ngpio = S5PV210_GPIO_B_NR,
  1694. .label = "GPB",
  1695. },
  1696. }, {
  1697. .chip = {
  1698. .base = S5PV210_GPC0(0),
  1699. .ngpio = S5PV210_GPIO_C0_NR,
  1700. .label = "GPC0",
  1701. },
  1702. }, {
  1703. .chip = {
  1704. .base = S5PV210_GPC1(0),
  1705. .ngpio = S5PV210_GPIO_C1_NR,
  1706. .label = "GPC1",
  1707. },
  1708. }, {
  1709. .chip = {
  1710. .base = S5PV210_GPD0(0),
  1711. .ngpio = S5PV210_GPIO_D0_NR,
  1712. .label = "GPD0",
  1713. },
  1714. }, {
  1715. .chip = {
  1716. .base = S5PV210_GPD1(0),
  1717. .ngpio = S5PV210_GPIO_D1_NR,
  1718. .label = "GPD1",
  1719. },
  1720. }, {
  1721. .chip = {
  1722. .base = S5PV210_GPE0(0),
  1723. .ngpio = S5PV210_GPIO_E0_NR,
  1724. .label = "GPE0",
  1725. },
  1726. }, {
  1727. .chip = {
  1728. .base = S5PV210_GPE1(0),
  1729. .ngpio = S5PV210_GPIO_E1_NR,
  1730. .label = "GPE1",
  1731. },
  1732. }, {
  1733. .chip = {
  1734. .base = S5PV210_GPF0(0),
  1735. .ngpio = S5PV210_GPIO_F0_NR,
  1736. .label = "GPF0",
  1737. },
  1738. }, {
  1739. .chip = {
  1740. .base = S5PV210_GPF1(0),
  1741. .ngpio = S5PV210_GPIO_F1_NR,
  1742. .label = "GPF1",
  1743. },
  1744. }, {
  1745. .chip = {
  1746. .base = S5PV210_GPF2(0),
  1747. .ngpio = S5PV210_GPIO_F2_NR,
  1748. .label = "GPF2",
  1749. },
  1750. }, {
  1751. .chip = {
  1752. .base = S5PV210_GPF3(0),
  1753. .ngpio = S5PV210_GPIO_F3_NR,
  1754. .label = "GPF3",
  1755. },
  1756. }, {
  1757. .chip = {
  1758. .base = S5PV210_GPG0(0),
  1759. .ngpio = S5PV210_GPIO_G0_NR,
  1760. .label = "GPG0",
  1761. },
  1762. }, {
  1763. .chip = {
  1764. .base = S5PV210_GPG1(0),
  1765. .ngpio = S5PV210_GPIO_G1_NR,
  1766. .label = "GPG1",
  1767. },
  1768. }, {
  1769. .chip = {
  1770. .base = S5PV210_GPG2(0),
  1771. .ngpio = S5PV210_GPIO_G2_NR,
  1772. .label = "GPG2",
  1773. },
  1774. }, {
  1775. .chip = {
  1776. .base = S5PV210_GPG3(0),
  1777. .ngpio = S5PV210_GPIO_G3_NR,
  1778. .label = "GPG3",
  1779. },
  1780. }, {
  1781. .chip = {
  1782. .base = S5PV210_GPI(0),
  1783. .ngpio = S5PV210_GPIO_I_NR,
  1784. .label = "GPI",
  1785. },
  1786. }, {
  1787. .chip = {
  1788. .base = S5PV210_GPJ0(0),
  1789. .ngpio = S5PV210_GPIO_J0_NR,
  1790. .label = "GPJ0",
  1791. },
  1792. }, {
  1793. .chip = {
  1794. .base = S5PV210_GPJ1(0),
  1795. .ngpio = S5PV210_GPIO_J1_NR,
  1796. .label = "GPJ1",
  1797. },
  1798. }, {
  1799. .chip = {
  1800. .base = S5PV210_GPJ2(0),
  1801. .ngpio = S5PV210_GPIO_J2_NR,
  1802. .label = "GPJ2",
  1803. },
  1804. }, {
  1805. .chip = {
  1806. .base = S5PV210_GPJ3(0),
  1807. .ngpio = S5PV210_GPIO_J3_NR,
  1808. .label = "GPJ3",
  1809. },
  1810. }, {
  1811. .chip = {
  1812. .base = S5PV210_GPJ4(0),
  1813. .ngpio = S5PV210_GPIO_J4_NR,
  1814. .label = "GPJ4",
  1815. },
  1816. }, {
  1817. .chip = {
  1818. .base = S5PV210_MP01(0),
  1819. .ngpio = S5PV210_GPIO_MP01_NR,
  1820. .label = "MP01",
  1821. },
  1822. }, {
  1823. .chip = {
  1824. .base = S5PV210_MP02(0),
  1825. .ngpio = S5PV210_GPIO_MP02_NR,
  1826. .label = "MP02",
  1827. },
  1828. }, {
  1829. .chip = {
  1830. .base = S5PV210_MP03(0),
  1831. .ngpio = S5PV210_GPIO_MP03_NR,
  1832. .label = "MP03",
  1833. },
  1834. }, {
  1835. .chip = {
  1836. .base = S5PV210_MP04(0),
  1837. .ngpio = S5PV210_GPIO_MP04_NR,
  1838. .label = "MP04",
  1839. },
  1840. }, {
  1841. .chip = {
  1842. .base = S5PV210_MP05(0),
  1843. .ngpio = S5PV210_GPIO_MP05_NR,
  1844. .label = "MP05",
  1845. },
  1846. }, {
  1847. .base = (S5P_VA_GPIO + 0xC00),
  1848. .irq_base = IRQ_EINT(0),
  1849. .chip = {
  1850. .base = S5PV210_GPH0(0),
  1851. .ngpio = S5PV210_GPIO_H0_NR,
  1852. .label = "GPH0",
  1853. .to_irq = samsung_gpiolib_to_irq,
  1854. },
  1855. }, {
  1856. .base = (S5P_VA_GPIO + 0xC20),
  1857. .irq_base = IRQ_EINT(8),
  1858. .chip = {
  1859. .base = S5PV210_GPH1(0),
  1860. .ngpio = S5PV210_GPIO_H1_NR,
  1861. .label = "GPH1",
  1862. .to_irq = samsung_gpiolib_to_irq,
  1863. },
  1864. }, {
  1865. .base = (S5P_VA_GPIO + 0xC40),
  1866. .irq_base = IRQ_EINT(16),
  1867. .chip = {
  1868. .base = S5PV210_GPH2(0),
  1869. .ngpio = S5PV210_GPIO_H2_NR,
  1870. .label = "GPH2",
  1871. .to_irq = samsung_gpiolib_to_irq,
  1872. },
  1873. }, {
  1874. .base = (S5P_VA_GPIO + 0xC60),
  1875. .irq_base = IRQ_EINT(24),
  1876. .chip = {
  1877. .base = S5PV210_GPH3(0),
  1878. .ngpio = S5PV210_GPIO_H3_NR,
  1879. .label = "GPH3",
  1880. .to_irq = samsung_gpiolib_to_irq,
  1881. },
  1882. },
  1883. #endif
  1884. };
  1885. /* TODO: cleanup soc_is_* */
  1886. static __init int samsung_gpiolib_init(void)
  1887. {
  1888. struct samsung_gpio_chip *chip;
  1889. int i, nr_chips;
  1890. int group = 0;
  1891. /*
  1892. * Currently there are two drivers that can provide GPIO support for
  1893. * Samsung SoCs. For device tree enabled platforms, the new
  1894. * pinctrl-samsung driver is used, providing both GPIO and pin control
  1895. * interfaces. For legacy (non-DT) platforms this driver is used.
  1896. */
  1897. if (of_have_populated_dt())
  1898. return -ENODEV;
  1899. samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
  1900. if (soc_is_s3c24xx()) {
  1901. s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
  1902. ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
  1903. } else if (soc_is_s3c64xx()) {
  1904. samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
  1905. ARRAY_SIZE(s3c64xx_gpios_2bit),
  1906. S3C64XX_VA_GPIO + 0xE0, 0x20);
  1907. samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
  1908. ARRAY_SIZE(s3c64xx_gpios_4bit),
  1909. S3C64XX_VA_GPIO);
  1910. samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
  1911. ARRAY_SIZE(s3c64xx_gpios_4bit2));
  1912. } else if (soc_is_s5p6440()) {
  1913. samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
  1914. ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
  1915. samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
  1916. ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
  1917. samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
  1918. ARRAY_SIZE(s5p6440_gpios_4bit2));
  1919. s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
  1920. ARRAY_SIZE(s5p6440_gpios_rbank));
  1921. } else if (soc_is_s5p6450()) {
  1922. samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
  1923. ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
  1924. samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
  1925. ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
  1926. samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
  1927. ARRAY_SIZE(s5p6450_gpios_4bit2));
  1928. s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
  1929. ARRAY_SIZE(s5p6450_gpios_rbank));
  1930. } else if (soc_is_s5pc100()) {
  1931. group = 0;
  1932. chip = s5pc100_gpios_4bit;
  1933. nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
  1934. for (i = 0; i < nr_chips; i++, chip++) {
  1935. if (!chip->config) {
  1936. chip->config = &samsung_gpio_cfgs[3];
  1937. chip->group = group++;
  1938. }
  1939. }
  1940. samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
  1941. #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
  1942. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  1943. #endif
  1944. } else if (soc_is_s5pv210()) {
  1945. group = 0;
  1946. chip = s5pv210_gpios_4bit;
  1947. nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
  1948. for (i = 0; i < nr_chips; i++, chip++) {
  1949. if (!chip->config) {
  1950. chip->config = &samsung_gpio_cfgs[3];
  1951. chip->group = group++;
  1952. }
  1953. }
  1954. samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
  1955. #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
  1956. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  1957. #endif
  1958. } else {
  1959. WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
  1960. return -ENODEV;
  1961. }
  1962. return 0;
  1963. }
  1964. core_initcall(samsung_gpiolib_init);
  1965. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  1966. {
  1967. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  1968. unsigned long flags;
  1969. int offset;
  1970. int ret;
  1971. if (!chip)
  1972. return -EINVAL;
  1973. offset = pin - chip->chip.base;
  1974. samsung_gpio_lock(chip, flags);
  1975. ret = samsung_gpio_do_setcfg(chip, offset, config);
  1976. samsung_gpio_unlock(chip, flags);
  1977. return ret;
  1978. }
  1979. EXPORT_SYMBOL(s3c_gpio_cfgpin);
  1980. int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  1981. unsigned int cfg)
  1982. {
  1983. int ret;
  1984. for (; nr > 0; nr--, start++) {
  1985. ret = s3c_gpio_cfgpin(start, cfg);
  1986. if (ret != 0)
  1987. return ret;
  1988. }
  1989. return 0;
  1990. }
  1991. EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
  1992. int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  1993. unsigned int cfg, samsung_gpio_pull_t pull)
  1994. {
  1995. int ret;
  1996. for (; nr > 0; nr--, start++) {
  1997. s3c_gpio_setpull(start, pull);
  1998. ret = s3c_gpio_cfgpin(start, cfg);
  1999. if (ret != 0)
  2000. return ret;
  2001. }
  2002. return 0;
  2003. }
  2004. EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
  2005. unsigned s3c_gpio_getcfg(unsigned int pin)
  2006. {
  2007. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2008. unsigned long flags;
  2009. unsigned ret = 0;
  2010. int offset;
  2011. if (chip) {
  2012. offset = pin - chip->chip.base;
  2013. samsung_gpio_lock(chip, flags);
  2014. ret = samsung_gpio_do_getcfg(chip, offset);
  2015. samsung_gpio_unlock(chip, flags);
  2016. }
  2017. return ret;
  2018. }
  2019. EXPORT_SYMBOL(s3c_gpio_getcfg);
  2020. int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
  2021. {
  2022. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2023. unsigned long flags;
  2024. int offset, ret;
  2025. if (!chip)
  2026. return -EINVAL;
  2027. offset = pin - chip->chip.base;
  2028. samsung_gpio_lock(chip, flags);
  2029. ret = samsung_gpio_do_setpull(chip, offset, pull);
  2030. samsung_gpio_unlock(chip, flags);
  2031. return ret;
  2032. }
  2033. EXPORT_SYMBOL(s3c_gpio_setpull);
  2034. samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
  2035. {
  2036. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2037. unsigned long flags;
  2038. int offset;
  2039. u32 pup = 0;
  2040. if (chip) {
  2041. offset = pin - chip->chip.base;
  2042. samsung_gpio_lock(chip, flags);
  2043. pup = samsung_gpio_do_getpull(chip, offset);
  2044. samsung_gpio_unlock(chip, flags);
  2045. }
  2046. return (__force samsung_gpio_pull_t)pup;
  2047. }
  2048. EXPORT_SYMBOL(s3c_gpio_getpull);
  2049. #ifdef CONFIG_S5P_GPIO_DRVSTR
  2050. s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
  2051. {
  2052. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2053. unsigned int off;
  2054. void __iomem *reg;
  2055. int shift;
  2056. u32 drvstr;
  2057. if (!chip)
  2058. return -EINVAL;
  2059. off = pin - chip->chip.base;
  2060. shift = off * 2;
  2061. reg = chip->base + 0x0C;
  2062. drvstr = __raw_readl(reg);
  2063. drvstr = drvstr >> shift;
  2064. drvstr &= 0x3;
  2065. return (__force s5p_gpio_drvstr_t)drvstr;
  2066. }
  2067. EXPORT_SYMBOL(s5p_gpio_get_drvstr);
  2068. int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
  2069. {
  2070. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2071. unsigned int off;
  2072. void __iomem *reg;
  2073. int shift;
  2074. u32 tmp;
  2075. if (!chip)
  2076. return -EINVAL;
  2077. off = pin - chip->chip.base;
  2078. shift = off * 2;
  2079. reg = chip->base + 0x0C;
  2080. tmp = __raw_readl(reg);
  2081. tmp &= ~(0x3 << shift);
  2082. tmp |= drvstr << shift;
  2083. __raw_writel(tmp, reg);
  2084. return 0;
  2085. }
  2086. EXPORT_SYMBOL(s5p_gpio_set_drvstr);
  2087. #endif /* CONFIG_S5P_GPIO_DRVSTR */
  2088. #ifdef CONFIG_PLAT_S3C24XX
  2089. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  2090. {
  2091. unsigned long flags;
  2092. unsigned long misccr;
  2093. local_irq_save(flags);
  2094. misccr = __raw_readl(S3C24XX_MISCCR);
  2095. misccr &= ~clear;
  2096. misccr ^= change;
  2097. __raw_writel(misccr, S3C24XX_MISCCR);
  2098. local_irq_restore(flags);
  2099. return misccr;
  2100. }
  2101. EXPORT_SYMBOL(s3c2410_modify_misccr);
  2102. #endif