gpio-samsung.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230
  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/hardware.h>
  31. #include <mach/map.h>
  32. #include <mach/regs-gpio.h>
  33. #include <plat/cpu.h>
  34. #include <plat/gpio-core.h>
  35. #include <plat/gpio-cfg.h>
  36. #include <plat/gpio-cfg-helpers.h>
  37. #include <plat/pm.h>
  38. int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip,
  39. unsigned int off, samsung_gpio_pull_t pull)
  40. {
  41. void __iomem *reg = chip->base + 0x08;
  42. int shift = off * 2;
  43. u32 pup;
  44. pup = __raw_readl(reg);
  45. pup &= ~(3 << shift);
  46. pup |= pull << shift;
  47. __raw_writel(pup, reg);
  48. return 0;
  49. }
  50. samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip,
  51. unsigned int off)
  52. {
  53. void __iomem *reg = chip->base + 0x08;
  54. int shift = off * 2;
  55. u32 pup = __raw_readl(reg);
  56. pup >>= shift;
  57. pup &= 0x3;
  58. return (__force samsung_gpio_pull_t)pup;
  59. }
  60. int s3c2443_gpio_setpull(struct samsung_gpio_chip *chip,
  61. unsigned int off, samsung_gpio_pull_t pull)
  62. {
  63. switch (pull) {
  64. case S3C_GPIO_PULL_NONE:
  65. pull = 0x01;
  66. break;
  67. case S3C_GPIO_PULL_UP:
  68. pull = 0x00;
  69. break;
  70. case S3C_GPIO_PULL_DOWN:
  71. pull = 0x02;
  72. break;
  73. }
  74. return samsung_gpio_setpull_updown(chip, off, pull);
  75. }
  76. samsung_gpio_pull_t s3c2443_gpio_getpull(struct samsung_gpio_chip *chip,
  77. unsigned int off)
  78. {
  79. samsung_gpio_pull_t pull;
  80. pull = samsung_gpio_getpull_updown(chip, off);
  81. switch (pull) {
  82. case 0x00:
  83. pull = S3C_GPIO_PULL_UP;
  84. break;
  85. case 0x01:
  86. case 0x03:
  87. pull = S3C_GPIO_PULL_NONE;
  88. break;
  89. case 0x02:
  90. pull = S3C_GPIO_PULL_DOWN;
  91. break;
  92. }
  93. return pull;
  94. }
  95. static int s3c24xx_gpio_setpull_1(struct samsung_gpio_chip *chip,
  96. unsigned int off, samsung_gpio_pull_t pull,
  97. samsung_gpio_pull_t updown)
  98. {
  99. void __iomem *reg = chip->base + 0x08;
  100. u32 pup = __raw_readl(reg);
  101. if (pull == updown)
  102. pup &= ~(1 << off);
  103. else if (pull == S3C_GPIO_PULL_NONE)
  104. pup |= (1 << off);
  105. else
  106. return -EINVAL;
  107. __raw_writel(pup, reg);
  108. return 0;
  109. }
  110. static samsung_gpio_pull_t s3c24xx_gpio_getpull_1(struct samsung_gpio_chip *chip,
  111. unsigned int off,
  112. samsung_gpio_pull_t updown)
  113. {
  114. void __iomem *reg = chip->base + 0x08;
  115. u32 pup = __raw_readl(reg);
  116. pup &= (1 << off);
  117. return pup ? S3C_GPIO_PULL_NONE : updown;
  118. }
  119. samsung_gpio_pull_t s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip *chip,
  120. unsigned int off)
  121. {
  122. return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_UP);
  123. }
  124. int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip *chip,
  125. unsigned int off, samsung_gpio_pull_t pull)
  126. {
  127. return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_UP);
  128. }
  129. samsung_gpio_pull_t s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip *chip,
  130. unsigned int off)
  131. {
  132. return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_DOWN);
  133. }
  134. int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip *chip,
  135. unsigned int off, samsung_gpio_pull_t pull)
  136. {
  137. return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_DOWN);
  138. }
  139. static int exynos_gpio_setpull(struct samsung_gpio_chip *chip,
  140. unsigned int off, samsung_gpio_pull_t pull)
  141. {
  142. if (pull == S3C_GPIO_PULL_UP)
  143. pull = 3;
  144. return samsung_gpio_setpull_updown(chip, off, pull);
  145. }
  146. static samsung_gpio_pull_t exynos_gpio_getpull(struct samsung_gpio_chip *chip,
  147. unsigned int off)
  148. {
  149. samsung_gpio_pull_t pull;
  150. pull = samsung_gpio_getpull_updown(chip, off);
  151. if (pull == 3)
  152. pull = S3C_GPIO_PULL_UP;
  153. return pull;
  154. }
  155. /*
  156. * samsung_gpio_setcfg_2bit - Samsung 2bit style GPIO configuration.
  157. * @chip: The gpio chip that is being configured.
  158. * @off: The offset for the GPIO being configured.
  159. * @cfg: The configuration value to set.
  160. *
  161. * This helper deal with the GPIO cases where the control register
  162. * has two bits of configuration per gpio, which have the following
  163. * functions:
  164. * 00 = input
  165. * 01 = output
  166. * 1x = special function
  167. */
  168. static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip *chip,
  169. unsigned int off, unsigned int cfg)
  170. {
  171. void __iomem *reg = chip->base;
  172. unsigned int shift = off * 2;
  173. u32 con;
  174. if (samsung_gpio_is_cfg_special(cfg)) {
  175. cfg &= 0xf;
  176. if (cfg > 3)
  177. return -EINVAL;
  178. cfg <<= shift;
  179. }
  180. con = __raw_readl(reg);
  181. con &= ~(0x3 << shift);
  182. con |= cfg;
  183. __raw_writel(con, reg);
  184. return 0;
  185. }
  186. /*
  187. * samsung_gpio_getcfg_2bit - Samsung 2bit style GPIO configuration read.
  188. * @chip: The gpio chip that is being configured.
  189. * @off: The offset for the GPIO being configured.
  190. *
  191. * The reverse of samsung_gpio_setcfg_2bit(). Will return a value which
  192. * could be directly passed back to samsung_gpio_setcfg_2bit(), from the
  193. * S3C_GPIO_SPECIAL() macro.
  194. */
  195. static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip *chip,
  196. unsigned int off)
  197. {
  198. u32 con;
  199. con = __raw_readl(chip->base);
  200. con >>= off * 2;
  201. con &= 3;
  202. /* this conversion works for IN and OUT as well as special mode */
  203. return S3C_GPIO_SPECIAL(con);
  204. }
  205. /*
  206. * samsung_gpio_setcfg_4bit - Samsung 4bit single register GPIO config.
  207. * @chip: The gpio chip that is being configured.
  208. * @off: The offset for the GPIO being configured.
  209. * @cfg: The configuration value to set.
  210. *
  211. * This helper deal with the GPIO cases where the control register has 4 bits
  212. * of control per GPIO, generally in the form of:
  213. * 0000 = Input
  214. * 0001 = Output
  215. * others = Special functions (dependent on bank)
  216. *
  217. * Note, since the code to deal with the case where there are two control
  218. * registers instead of one, we do not have a separate set of functions for
  219. * each case.
  220. */
  221. static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip *chip,
  222. unsigned int off, unsigned int cfg)
  223. {
  224. void __iomem *reg = chip->base;
  225. unsigned int shift = (off & 7) * 4;
  226. u32 con;
  227. if (off < 8 && chip->chip.ngpio > 8)
  228. reg -= 4;
  229. if (samsung_gpio_is_cfg_special(cfg)) {
  230. cfg &= 0xf;
  231. cfg <<= shift;
  232. }
  233. con = __raw_readl(reg);
  234. con &= ~(0xf << shift);
  235. con |= cfg;
  236. __raw_writel(con, reg);
  237. return 0;
  238. }
  239. /*
  240. * samsung_gpio_getcfg_4bit - Samsung 4bit single register GPIO config read.
  241. * @chip: The gpio chip that is being configured.
  242. * @off: The offset for the GPIO being configured.
  243. *
  244. * The reverse of samsung_gpio_setcfg_4bit(), turning a gpio configuration
  245. * register setting into a value the software can use, such as could be passed
  246. * to samsung_gpio_setcfg_4bit().
  247. *
  248. * @sa samsung_gpio_getcfg_2bit
  249. */
  250. static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip *chip,
  251. unsigned int off)
  252. {
  253. void __iomem *reg = chip->base;
  254. unsigned int shift = (off & 7) * 4;
  255. u32 con;
  256. if (off < 8 && chip->chip.ngpio > 8)
  257. reg -= 4;
  258. con = __raw_readl(reg);
  259. con >>= shift;
  260. con &= 0xf;
  261. /* this conversion works for IN and OUT as well as special mode */
  262. return S3C_GPIO_SPECIAL(con);
  263. }
  264. #ifdef CONFIG_PLAT_S3C24XX
  265. /*
  266. * s3c24xx_gpio_setcfg_abank - S3C24XX style GPIO configuration (Bank A)
  267. * @chip: The gpio chip that is being configured.
  268. * @off: The offset for the GPIO being configured.
  269. * @cfg: The configuration value to set.
  270. *
  271. * This helper deal with the GPIO cases where the control register
  272. * has one bit of configuration for the gpio, where setting the bit
  273. * means the pin is in special function mode and unset means output.
  274. */
  275. static int s3c24xx_gpio_setcfg_abank(struct samsung_gpio_chip *chip,
  276. unsigned int off, unsigned int cfg)
  277. {
  278. void __iomem *reg = chip->base;
  279. unsigned int shift = off;
  280. u32 con;
  281. if (samsung_gpio_is_cfg_special(cfg)) {
  282. cfg &= 0xf;
  283. /* Map output to 0, and SFN2 to 1 */
  284. cfg -= 1;
  285. if (cfg > 1)
  286. return -EINVAL;
  287. cfg <<= shift;
  288. }
  289. con = __raw_readl(reg);
  290. con &= ~(0x1 << shift);
  291. con |= cfg;
  292. __raw_writel(con, reg);
  293. return 0;
  294. }
  295. /*
  296. * s3c24xx_gpio_getcfg_abank - S3C24XX style GPIO configuration read (Bank A)
  297. * @chip: The gpio chip that is being configured.
  298. * @off: The offset for the GPIO being configured.
  299. *
  300. * The reverse of s3c24xx_gpio_setcfg_abank() turning an GPIO into a usable
  301. * GPIO configuration value.
  302. *
  303. * @sa samsung_gpio_getcfg_2bit
  304. * @sa samsung_gpio_getcfg_4bit
  305. */
  306. static unsigned s3c24xx_gpio_getcfg_abank(struct samsung_gpio_chip *chip,
  307. unsigned int off)
  308. {
  309. u32 con;
  310. con = __raw_readl(chip->base);
  311. con >>= off;
  312. con &= 1;
  313. con++;
  314. return S3C_GPIO_SFN(con);
  315. }
  316. #endif
  317. #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
  318. static int s5p64x0_gpio_setcfg_rbank(struct samsung_gpio_chip *chip,
  319. unsigned int off, unsigned int cfg)
  320. {
  321. void __iomem *reg = chip->base;
  322. unsigned int shift;
  323. u32 con;
  324. switch (off) {
  325. case 0:
  326. case 1:
  327. case 2:
  328. case 3:
  329. case 4:
  330. case 5:
  331. shift = (off & 7) * 4;
  332. reg -= 4;
  333. break;
  334. case 6:
  335. shift = ((off + 1) & 7) * 4;
  336. reg -= 4;
  337. default:
  338. shift = ((off + 1) & 7) * 4;
  339. break;
  340. }
  341. if (samsung_gpio_is_cfg_special(cfg)) {
  342. cfg &= 0xf;
  343. cfg <<= shift;
  344. }
  345. con = __raw_readl(reg);
  346. con &= ~(0xf << shift);
  347. con |= cfg;
  348. __raw_writel(con, reg);
  349. return 0;
  350. }
  351. #endif
  352. static void __init samsung_gpiolib_set_cfg(struct samsung_gpio_cfg *chipcfg,
  353. int nr_chips)
  354. {
  355. for (; nr_chips > 0; nr_chips--, chipcfg++) {
  356. if (!chipcfg->set_config)
  357. chipcfg->set_config = samsung_gpio_setcfg_4bit;
  358. if (!chipcfg->get_config)
  359. chipcfg->get_config = samsung_gpio_getcfg_4bit;
  360. if (!chipcfg->set_pull)
  361. chipcfg->set_pull = samsung_gpio_setpull_updown;
  362. if (!chipcfg->get_pull)
  363. chipcfg->get_pull = samsung_gpio_getpull_updown;
  364. }
  365. }
  366. struct samsung_gpio_cfg s3c24xx_gpiocfg_default = {
  367. .set_config = samsung_gpio_setcfg_2bit,
  368. .get_config = samsung_gpio_getcfg_2bit,
  369. };
  370. #ifdef CONFIG_PLAT_S3C24XX
  371. static struct samsung_gpio_cfg s3c24xx_gpiocfg_banka = {
  372. .set_config = s3c24xx_gpio_setcfg_abank,
  373. .get_config = s3c24xx_gpio_getcfg_abank,
  374. };
  375. #endif
  376. #if defined(CONFIG_ARCH_EXYNOS4) || defined(CONFIG_SOC_EXYNOS5250)
  377. static struct samsung_gpio_cfg exynos_gpio_cfg = {
  378. .set_pull = exynos_gpio_setpull,
  379. .get_pull = exynos_gpio_getpull,
  380. .set_config = samsung_gpio_setcfg_4bit,
  381. .get_config = samsung_gpio_getcfg_4bit,
  382. };
  383. #endif
  384. #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
  385. static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = {
  386. .cfg_eint = 0x3,
  387. .set_config = s5p64x0_gpio_setcfg_rbank,
  388. .get_config = samsung_gpio_getcfg_4bit,
  389. .set_pull = samsung_gpio_setpull_updown,
  390. .get_pull = samsung_gpio_getpull_updown,
  391. };
  392. #endif
  393. static struct samsung_gpio_cfg samsung_gpio_cfgs[] = {
  394. [0] = {
  395. .cfg_eint = 0x0,
  396. },
  397. [1] = {
  398. .cfg_eint = 0x3,
  399. },
  400. [2] = {
  401. .cfg_eint = 0x7,
  402. },
  403. [3] = {
  404. .cfg_eint = 0xF,
  405. },
  406. [4] = {
  407. .cfg_eint = 0x0,
  408. .set_config = samsung_gpio_setcfg_2bit,
  409. .get_config = samsung_gpio_getcfg_2bit,
  410. },
  411. [5] = {
  412. .cfg_eint = 0x2,
  413. .set_config = samsung_gpio_setcfg_2bit,
  414. .get_config = samsung_gpio_getcfg_2bit,
  415. },
  416. [6] = {
  417. .cfg_eint = 0x3,
  418. .set_config = samsung_gpio_setcfg_2bit,
  419. .get_config = samsung_gpio_getcfg_2bit,
  420. },
  421. [7] = {
  422. .set_config = samsung_gpio_setcfg_2bit,
  423. .get_config = samsung_gpio_getcfg_2bit,
  424. },
  425. [8] = {
  426. .set_pull = exynos_gpio_setpull,
  427. .get_pull = exynos_gpio_getpull,
  428. },
  429. [9] = {
  430. .cfg_eint = 0x3,
  431. .set_pull = exynos_gpio_setpull,
  432. .get_pull = exynos_gpio_getpull,
  433. }
  434. };
  435. /*
  436. * Default routines for controlling GPIO, based on the original S3C24XX
  437. * GPIO functions which deal with the case where each gpio bank of the
  438. * chip is as following:
  439. *
  440. * base + 0x00: Control register, 2 bits per gpio
  441. * gpio n: 2 bits starting at (2*n)
  442. * 00 = input, 01 = output, others mean special-function
  443. * base + 0x04: Data register, 1 bit per gpio
  444. * bit n: data bit n
  445. */
  446. static int samsung_gpiolib_2bit_input(struct gpio_chip *chip, unsigned offset)
  447. {
  448. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  449. void __iomem *base = ourchip->base;
  450. unsigned long flags;
  451. unsigned long con;
  452. samsung_gpio_lock(ourchip, flags);
  453. con = __raw_readl(base + 0x00);
  454. con &= ~(3 << (offset * 2));
  455. __raw_writel(con, base + 0x00);
  456. samsung_gpio_unlock(ourchip, flags);
  457. return 0;
  458. }
  459. static int samsung_gpiolib_2bit_output(struct gpio_chip *chip,
  460. unsigned offset, int value)
  461. {
  462. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  463. void __iomem *base = ourchip->base;
  464. unsigned long flags;
  465. unsigned long dat;
  466. unsigned long con;
  467. samsung_gpio_lock(ourchip, flags);
  468. dat = __raw_readl(base + 0x04);
  469. dat &= ~(1 << offset);
  470. if (value)
  471. dat |= 1 << offset;
  472. __raw_writel(dat, base + 0x04);
  473. con = __raw_readl(base + 0x00);
  474. con &= ~(3 << (offset * 2));
  475. con |= 1 << (offset * 2);
  476. __raw_writel(con, base + 0x00);
  477. __raw_writel(dat, base + 0x04);
  478. samsung_gpio_unlock(ourchip, flags);
  479. return 0;
  480. }
  481. /*
  482. * The samsung_gpiolib_4bit routines are to control the gpio banks where
  483. * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
  484. * following example:
  485. *
  486. * base + 0x00: Control register, 4 bits per gpio
  487. * gpio n: 4 bits starting at (4*n)
  488. * 0000 = input, 0001 = output, others mean special-function
  489. * base + 0x04: Data register, 1 bit per gpio
  490. * bit n: data bit n
  491. *
  492. * Note, since the data register is one bit per gpio and is at base + 0x4
  493. * we can use samsung_gpiolib_get and samsung_gpiolib_set to change the
  494. * state of the output.
  495. */
  496. static int samsung_gpiolib_4bit_input(struct gpio_chip *chip,
  497. unsigned int offset)
  498. {
  499. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  500. void __iomem *base = ourchip->base;
  501. unsigned long con;
  502. con = __raw_readl(base + GPIOCON_OFF);
  503. if (ourchip->bitmap_gpio_int & BIT(offset))
  504. con |= 0xf << con_4bit_shift(offset);
  505. else
  506. con &= ~(0xf << con_4bit_shift(offset));
  507. __raw_writel(con, base + GPIOCON_OFF);
  508. pr_debug("%s: %p: CON now %08lx\n", __func__, base, con);
  509. return 0;
  510. }
  511. static int samsung_gpiolib_4bit_output(struct gpio_chip *chip,
  512. unsigned int offset, int value)
  513. {
  514. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  515. void __iomem *base = ourchip->base;
  516. unsigned long con;
  517. unsigned long dat;
  518. con = __raw_readl(base + GPIOCON_OFF);
  519. con &= ~(0xf << con_4bit_shift(offset));
  520. con |= 0x1 << con_4bit_shift(offset);
  521. dat = __raw_readl(base + GPIODAT_OFF);
  522. if (value)
  523. dat |= 1 << offset;
  524. else
  525. dat &= ~(1 << offset);
  526. __raw_writel(dat, base + GPIODAT_OFF);
  527. __raw_writel(con, base + GPIOCON_OFF);
  528. __raw_writel(dat, base + GPIODAT_OFF);
  529. pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
  530. return 0;
  531. }
  532. /*
  533. * The next set of routines are for the case where the GPIO configuration
  534. * registers are 4 bits per GPIO but there is more than one register (the
  535. * bank has more than 8 GPIOs.
  536. *
  537. * This case is the similar to the 4 bit case, but the registers are as
  538. * follows:
  539. *
  540. * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs)
  541. * gpio n: 4 bits starting at (4*n)
  542. * 0000 = input, 0001 = output, others mean special-function
  543. * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs)
  544. * gpio n: 4 bits starting at (4*n)
  545. * 0000 = input, 0001 = output, others mean special-function
  546. * base + 0x08: Data register, 1 bit per gpio
  547. * bit n: data bit n
  548. *
  549. * To allow us to use the samsung_gpiolib_get and samsung_gpiolib_set
  550. * routines we store the 'base + 0x4' address so that these routines see
  551. * the data register at ourchip->base + 0x04.
  552. */
  553. static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip,
  554. unsigned int offset)
  555. {
  556. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  557. void __iomem *base = ourchip->base;
  558. void __iomem *regcon = base;
  559. unsigned long con;
  560. if (offset > 7)
  561. offset -= 8;
  562. else
  563. regcon -= 4;
  564. con = __raw_readl(regcon);
  565. con &= ~(0xf << con_4bit_shift(offset));
  566. __raw_writel(con, regcon);
  567. pr_debug("%s: %p: CON %08lx\n", __func__, base, con);
  568. return 0;
  569. }
  570. static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip,
  571. unsigned int offset, int value)
  572. {
  573. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  574. void __iomem *base = ourchip->base;
  575. void __iomem *regcon = base;
  576. unsigned long con;
  577. unsigned long dat;
  578. unsigned con_offset = offset;
  579. if (con_offset > 7)
  580. con_offset -= 8;
  581. else
  582. regcon -= 4;
  583. con = __raw_readl(regcon);
  584. con &= ~(0xf << con_4bit_shift(con_offset));
  585. con |= 0x1 << con_4bit_shift(con_offset);
  586. dat = __raw_readl(base + GPIODAT_OFF);
  587. if (value)
  588. dat |= 1 << offset;
  589. else
  590. dat &= ~(1 << offset);
  591. __raw_writel(dat, base + GPIODAT_OFF);
  592. __raw_writel(con, regcon);
  593. __raw_writel(dat, base + GPIODAT_OFF);
  594. pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
  595. return 0;
  596. }
  597. #ifdef CONFIG_PLAT_S3C24XX
  598. /* The next set of routines are for the case of s3c24xx bank a */
  599. static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
  600. {
  601. return -EINVAL;
  602. }
  603. static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
  604. unsigned offset, int value)
  605. {
  606. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  607. void __iomem *base = ourchip->base;
  608. unsigned long flags;
  609. unsigned long dat;
  610. unsigned long con;
  611. local_irq_save(flags);
  612. con = __raw_readl(base + 0x00);
  613. dat = __raw_readl(base + 0x04);
  614. dat &= ~(1 << offset);
  615. if (value)
  616. dat |= 1 << offset;
  617. __raw_writel(dat, base + 0x04);
  618. con &= ~(1 << offset);
  619. __raw_writel(con, base + 0x00);
  620. __raw_writel(dat, base + 0x04);
  621. local_irq_restore(flags);
  622. return 0;
  623. }
  624. #endif
  625. /* The next set of routines are for the case of s5p64x0 bank r */
  626. static int s5p64x0_gpiolib_rbank_input(struct gpio_chip *chip,
  627. unsigned int offset)
  628. {
  629. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  630. void __iomem *base = ourchip->base;
  631. void __iomem *regcon = base;
  632. unsigned long con;
  633. unsigned long flags;
  634. switch (offset) {
  635. case 6:
  636. offset += 1;
  637. case 0:
  638. case 1:
  639. case 2:
  640. case 3:
  641. case 4:
  642. case 5:
  643. regcon -= 4;
  644. break;
  645. default:
  646. offset -= 7;
  647. break;
  648. }
  649. samsung_gpio_lock(ourchip, flags);
  650. con = __raw_readl(regcon);
  651. con &= ~(0xf << con_4bit_shift(offset));
  652. __raw_writel(con, regcon);
  653. samsung_gpio_unlock(ourchip, flags);
  654. return 0;
  655. }
  656. static int s5p64x0_gpiolib_rbank_output(struct gpio_chip *chip,
  657. unsigned int offset, int value)
  658. {
  659. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  660. void __iomem *base = ourchip->base;
  661. void __iomem *regcon = base;
  662. unsigned long con;
  663. unsigned long dat;
  664. unsigned long flags;
  665. unsigned con_offset = offset;
  666. switch (con_offset) {
  667. case 6:
  668. con_offset += 1;
  669. case 0:
  670. case 1:
  671. case 2:
  672. case 3:
  673. case 4:
  674. case 5:
  675. regcon -= 4;
  676. break;
  677. default:
  678. con_offset -= 7;
  679. break;
  680. }
  681. samsung_gpio_lock(ourchip, flags);
  682. con = __raw_readl(regcon);
  683. con &= ~(0xf << con_4bit_shift(con_offset));
  684. con |= 0x1 << con_4bit_shift(con_offset);
  685. dat = __raw_readl(base + GPIODAT_OFF);
  686. if (value)
  687. dat |= 1 << offset;
  688. else
  689. dat &= ~(1 << offset);
  690. __raw_writel(con, regcon);
  691. __raw_writel(dat, base + GPIODAT_OFF);
  692. samsung_gpio_unlock(ourchip, flags);
  693. return 0;
  694. }
  695. static void samsung_gpiolib_set(struct gpio_chip *chip,
  696. unsigned offset, int value)
  697. {
  698. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  699. void __iomem *base = ourchip->base;
  700. unsigned long flags;
  701. unsigned long dat;
  702. samsung_gpio_lock(ourchip, flags);
  703. dat = __raw_readl(base + 0x04);
  704. dat &= ~(1 << offset);
  705. if (value)
  706. dat |= 1 << offset;
  707. __raw_writel(dat, base + 0x04);
  708. samsung_gpio_unlock(ourchip, flags);
  709. }
  710. static int samsung_gpiolib_get(struct gpio_chip *chip, unsigned offset)
  711. {
  712. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  713. unsigned long val;
  714. val = __raw_readl(ourchip->base + 0x04);
  715. val >>= offset;
  716. val &= 1;
  717. return val;
  718. }
  719. /*
  720. * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
  721. * for use with the configuration calls, and other parts of the s3c gpiolib
  722. * support code.
  723. *
  724. * Not all s3c support code will need this, as some configurations of cpu
  725. * may only support one or two different configuration options and have an
  726. * easy gpio to samsung_gpio_chip mapping function. If this is the case, then
  727. * the machine support file should provide its own samsung_gpiolib_getchip()
  728. * and any other necessary functions.
  729. */
  730. #ifdef CONFIG_S3C_GPIO_TRACK
  731. struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
  732. static __init void s3c_gpiolib_track(struct samsung_gpio_chip *chip)
  733. {
  734. unsigned int gpn;
  735. int i;
  736. gpn = chip->chip.base;
  737. for (i = 0; i < chip->chip.ngpio; i++, gpn++) {
  738. BUG_ON(gpn >= ARRAY_SIZE(s3c_gpios));
  739. s3c_gpios[gpn] = chip;
  740. }
  741. }
  742. #endif /* CONFIG_S3C_GPIO_TRACK */
  743. /*
  744. * samsung_gpiolib_add() - add the Samsung gpio_chip.
  745. * @chip: The chip to register
  746. *
  747. * This is a wrapper to gpiochip_add() that takes our specific gpio chip
  748. * information and makes the necessary alterations for the platform and
  749. * notes the information for use with the configuration systems and any
  750. * other parts of the system.
  751. */
  752. static void __init samsung_gpiolib_add(struct samsung_gpio_chip *chip)
  753. {
  754. struct gpio_chip *gc = &chip->chip;
  755. int ret;
  756. BUG_ON(!chip->base);
  757. BUG_ON(!gc->label);
  758. BUG_ON(!gc->ngpio);
  759. spin_lock_init(&chip->lock);
  760. if (!gc->direction_input)
  761. gc->direction_input = samsung_gpiolib_2bit_input;
  762. if (!gc->direction_output)
  763. gc->direction_output = samsung_gpiolib_2bit_output;
  764. if (!gc->set)
  765. gc->set = samsung_gpiolib_set;
  766. if (!gc->get)
  767. gc->get = samsung_gpiolib_get;
  768. #ifdef CONFIG_PM
  769. if (chip->pm != NULL) {
  770. if (!chip->pm->save || !chip->pm->resume)
  771. pr_err("gpio: %s has missing PM functions\n",
  772. gc->label);
  773. } else
  774. pr_err("gpio: %s has no PM function\n", gc->label);
  775. #endif
  776. /* gpiochip_add() prints own failure message on error. */
  777. ret = gpiochip_add(gc);
  778. if (ret >= 0)
  779. s3c_gpiolib_track(chip);
  780. }
  781. static void __init s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip *chip,
  782. int nr_chips, void __iomem *base)
  783. {
  784. int i;
  785. struct gpio_chip *gc = &chip->chip;
  786. for (i = 0 ; i < nr_chips; i++, chip++) {
  787. /* skip banks not present on SoC */
  788. if (chip->chip.base >= S3C_GPIO_END)
  789. continue;
  790. if (!chip->config)
  791. chip->config = &s3c24xx_gpiocfg_default;
  792. if (!chip->pm)
  793. chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
  794. if ((base != NULL) && (chip->base == NULL))
  795. chip->base = base + ((i) * 0x10);
  796. if (!gc->direction_input)
  797. gc->direction_input = samsung_gpiolib_2bit_input;
  798. if (!gc->direction_output)
  799. gc->direction_output = samsung_gpiolib_2bit_output;
  800. samsung_gpiolib_add(chip);
  801. }
  802. }
  803. static void __init samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip *chip,
  804. int nr_chips, void __iomem *base,
  805. unsigned int offset)
  806. {
  807. int i;
  808. for (i = 0 ; i < nr_chips; i++, chip++) {
  809. chip->chip.direction_input = samsung_gpiolib_2bit_input;
  810. chip->chip.direction_output = samsung_gpiolib_2bit_output;
  811. if (!chip->config)
  812. chip->config = &samsung_gpio_cfgs[7];
  813. if (!chip->pm)
  814. chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
  815. if ((base != NULL) && (chip->base == NULL))
  816. chip->base = base + ((i) * offset);
  817. samsung_gpiolib_add(chip);
  818. }
  819. }
  820. /*
  821. * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
  822. * @chip: The gpio chip that is being configured.
  823. * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
  824. *
  825. * This helper deal with the GPIO cases where the control register has 4 bits
  826. * of control per GPIO, generally in the form of:
  827. * 0000 = Input
  828. * 0001 = Output
  829. * others = Special functions (dependent on bank)
  830. *
  831. * Note, since the code to deal with the case where there are two control
  832. * registers instead of one, we do not have a separate set of function
  833. * (samsung_gpiolib_add_4bit2_chips)for each case.
  834. */
  835. static void __init samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip *chip,
  836. int nr_chips, void __iomem *base)
  837. {
  838. int i;
  839. for (i = 0 ; i < nr_chips; i++, chip++) {
  840. chip->chip.direction_input = samsung_gpiolib_4bit_input;
  841. chip->chip.direction_output = samsung_gpiolib_4bit_output;
  842. if (!chip->config)
  843. chip->config = &samsung_gpio_cfgs[2];
  844. if (!chip->pm)
  845. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  846. if ((base != NULL) && (chip->base == NULL))
  847. chip->base = base + ((i) * 0x20);
  848. chip->bitmap_gpio_int = 0;
  849. samsung_gpiolib_add(chip);
  850. }
  851. }
  852. static void __init samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip *chip,
  853. int nr_chips)
  854. {
  855. for (; nr_chips > 0; nr_chips--, chip++) {
  856. chip->chip.direction_input = samsung_gpiolib_4bit2_input;
  857. chip->chip.direction_output = samsung_gpiolib_4bit2_output;
  858. if (!chip->config)
  859. chip->config = &samsung_gpio_cfgs[2];
  860. if (!chip->pm)
  861. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  862. samsung_gpiolib_add(chip);
  863. }
  864. }
  865. static void __init s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip *chip,
  866. int nr_chips)
  867. {
  868. for (; nr_chips > 0; nr_chips--, chip++) {
  869. chip->chip.direction_input = s5p64x0_gpiolib_rbank_input;
  870. chip->chip.direction_output = s5p64x0_gpiolib_rbank_output;
  871. if (!chip->pm)
  872. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  873. samsung_gpiolib_add(chip);
  874. }
  875. }
  876. int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
  877. {
  878. struct samsung_gpio_chip *samsung_chip = container_of(chip, struct samsung_gpio_chip, chip);
  879. return samsung_chip->irq_base + offset;
  880. }
  881. #ifdef CONFIG_PLAT_S3C24XX
  882. static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset)
  883. {
  884. if (offset < 4) {
  885. if (soc_is_s3c2412())
  886. return IRQ_EINT0_2412 + offset;
  887. else
  888. return IRQ_EINT0 + offset;
  889. }
  890. if (offset < 8)
  891. return IRQ_EINT4 + offset - 4;
  892. return -EINVAL;
  893. }
  894. #endif
  895. #ifdef CONFIG_PLAT_S3C64XX
  896. static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin)
  897. {
  898. return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
  899. }
  900. static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin)
  901. {
  902. return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
  903. }
  904. #endif
  905. struct samsung_gpio_chip s3c24xx_gpios[] = {
  906. #ifdef CONFIG_PLAT_S3C24XX
  907. {
  908. .config = &s3c24xx_gpiocfg_banka,
  909. .chip = {
  910. .base = S3C2410_GPA(0),
  911. .owner = THIS_MODULE,
  912. .label = "GPIOA",
  913. .ngpio = 24,
  914. .direction_input = s3c24xx_gpiolib_banka_input,
  915. .direction_output = s3c24xx_gpiolib_banka_output,
  916. },
  917. }, {
  918. .chip = {
  919. .base = S3C2410_GPB(0),
  920. .owner = THIS_MODULE,
  921. .label = "GPIOB",
  922. .ngpio = 16,
  923. },
  924. }, {
  925. .chip = {
  926. .base = S3C2410_GPC(0),
  927. .owner = THIS_MODULE,
  928. .label = "GPIOC",
  929. .ngpio = 16,
  930. },
  931. }, {
  932. .chip = {
  933. .base = S3C2410_GPD(0),
  934. .owner = THIS_MODULE,
  935. .label = "GPIOD",
  936. .ngpio = 16,
  937. },
  938. }, {
  939. .chip = {
  940. .base = S3C2410_GPE(0),
  941. .label = "GPIOE",
  942. .owner = THIS_MODULE,
  943. .ngpio = 16,
  944. },
  945. }, {
  946. .chip = {
  947. .base = S3C2410_GPF(0),
  948. .owner = THIS_MODULE,
  949. .label = "GPIOF",
  950. .ngpio = 8,
  951. .to_irq = s3c24xx_gpiolib_fbank_to_irq,
  952. },
  953. }, {
  954. .irq_base = IRQ_EINT8,
  955. .chip = {
  956. .base = S3C2410_GPG(0),
  957. .owner = THIS_MODULE,
  958. .label = "GPIOG",
  959. .ngpio = 16,
  960. .to_irq = samsung_gpiolib_to_irq,
  961. },
  962. }, {
  963. .chip = {
  964. .base = S3C2410_GPH(0),
  965. .owner = THIS_MODULE,
  966. .label = "GPIOH",
  967. .ngpio = 11,
  968. },
  969. },
  970. /* GPIOS for the S3C2443 and later devices. */
  971. {
  972. .base = S3C2440_GPJCON,
  973. .chip = {
  974. .base = S3C2410_GPJ(0),
  975. .owner = THIS_MODULE,
  976. .label = "GPIOJ",
  977. .ngpio = 16,
  978. },
  979. }, {
  980. .base = S3C2443_GPKCON,
  981. .chip = {
  982. .base = S3C2410_GPK(0),
  983. .owner = THIS_MODULE,
  984. .label = "GPIOK",
  985. .ngpio = 16,
  986. },
  987. }, {
  988. .base = S3C2443_GPLCON,
  989. .chip = {
  990. .base = S3C2410_GPL(0),
  991. .owner = THIS_MODULE,
  992. .label = "GPIOL",
  993. .ngpio = 15,
  994. },
  995. }, {
  996. .base = S3C2443_GPMCON,
  997. .chip = {
  998. .base = S3C2410_GPM(0),
  999. .owner = THIS_MODULE,
  1000. .label = "GPIOM",
  1001. .ngpio = 2,
  1002. },
  1003. },
  1004. #endif
  1005. };
  1006. /*
  1007. * GPIO bank summary:
  1008. *
  1009. * Bank GPIOs Style SlpCon ExtInt Group
  1010. * A 8 4Bit Yes 1
  1011. * B 7 4Bit Yes 1
  1012. * C 8 4Bit Yes 2
  1013. * D 5 4Bit Yes 3
  1014. * E 5 4Bit Yes None
  1015. * F 16 2Bit Yes 4 [1]
  1016. * G 7 4Bit Yes 5
  1017. * H 10 4Bit[2] Yes 6
  1018. * I 16 2Bit Yes None
  1019. * J 12 2Bit Yes None
  1020. * K 16 4Bit[2] No None
  1021. * L 15 4Bit[2] No None
  1022. * M 6 4Bit No IRQ_EINT
  1023. * N 16 2Bit No IRQ_EINT
  1024. * O 16 2Bit Yes 7
  1025. * P 15 2Bit Yes 8
  1026. * Q 9 2Bit Yes 9
  1027. *
  1028. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  1029. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  1030. */
  1031. static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = {
  1032. #ifdef CONFIG_PLAT_S3C64XX
  1033. {
  1034. .chip = {
  1035. .base = S3C64XX_GPA(0),
  1036. .ngpio = S3C64XX_GPIO_A_NR,
  1037. .label = "GPA",
  1038. },
  1039. }, {
  1040. .chip = {
  1041. .base = S3C64XX_GPB(0),
  1042. .ngpio = S3C64XX_GPIO_B_NR,
  1043. .label = "GPB",
  1044. },
  1045. }, {
  1046. .chip = {
  1047. .base = S3C64XX_GPC(0),
  1048. .ngpio = S3C64XX_GPIO_C_NR,
  1049. .label = "GPC",
  1050. },
  1051. }, {
  1052. .chip = {
  1053. .base = S3C64XX_GPD(0),
  1054. .ngpio = S3C64XX_GPIO_D_NR,
  1055. .label = "GPD",
  1056. },
  1057. }, {
  1058. .config = &samsung_gpio_cfgs[0],
  1059. .chip = {
  1060. .base = S3C64XX_GPE(0),
  1061. .ngpio = S3C64XX_GPIO_E_NR,
  1062. .label = "GPE",
  1063. },
  1064. }, {
  1065. .base = S3C64XX_GPG_BASE,
  1066. .chip = {
  1067. .base = S3C64XX_GPG(0),
  1068. .ngpio = S3C64XX_GPIO_G_NR,
  1069. .label = "GPG",
  1070. },
  1071. }, {
  1072. .base = S3C64XX_GPM_BASE,
  1073. .config = &samsung_gpio_cfgs[1],
  1074. .chip = {
  1075. .base = S3C64XX_GPM(0),
  1076. .ngpio = S3C64XX_GPIO_M_NR,
  1077. .label = "GPM",
  1078. .to_irq = s3c64xx_gpiolib_mbank_to_irq,
  1079. },
  1080. },
  1081. #endif
  1082. };
  1083. static struct samsung_gpio_chip s3c64xx_gpios_4bit2[] = {
  1084. #ifdef CONFIG_PLAT_S3C64XX
  1085. {
  1086. .base = S3C64XX_GPH_BASE + 0x4,
  1087. .chip = {
  1088. .base = S3C64XX_GPH(0),
  1089. .ngpio = S3C64XX_GPIO_H_NR,
  1090. .label = "GPH",
  1091. },
  1092. }, {
  1093. .base = S3C64XX_GPK_BASE + 0x4,
  1094. .config = &samsung_gpio_cfgs[0],
  1095. .chip = {
  1096. .base = S3C64XX_GPK(0),
  1097. .ngpio = S3C64XX_GPIO_K_NR,
  1098. .label = "GPK",
  1099. },
  1100. }, {
  1101. .base = S3C64XX_GPL_BASE + 0x4,
  1102. .config = &samsung_gpio_cfgs[1],
  1103. .chip = {
  1104. .base = S3C64XX_GPL(0),
  1105. .ngpio = S3C64XX_GPIO_L_NR,
  1106. .label = "GPL",
  1107. .to_irq = s3c64xx_gpiolib_lbank_to_irq,
  1108. },
  1109. },
  1110. #endif
  1111. };
  1112. static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = {
  1113. #ifdef CONFIG_PLAT_S3C64XX
  1114. {
  1115. .base = S3C64XX_GPF_BASE,
  1116. .config = &samsung_gpio_cfgs[6],
  1117. .chip = {
  1118. .base = S3C64XX_GPF(0),
  1119. .ngpio = S3C64XX_GPIO_F_NR,
  1120. .label = "GPF",
  1121. },
  1122. }, {
  1123. .config = &samsung_gpio_cfgs[7],
  1124. .chip = {
  1125. .base = S3C64XX_GPI(0),
  1126. .ngpio = S3C64XX_GPIO_I_NR,
  1127. .label = "GPI",
  1128. },
  1129. }, {
  1130. .config = &samsung_gpio_cfgs[7],
  1131. .chip = {
  1132. .base = S3C64XX_GPJ(0),
  1133. .ngpio = S3C64XX_GPIO_J_NR,
  1134. .label = "GPJ",
  1135. },
  1136. }, {
  1137. .config = &samsung_gpio_cfgs[6],
  1138. .chip = {
  1139. .base = S3C64XX_GPO(0),
  1140. .ngpio = S3C64XX_GPIO_O_NR,
  1141. .label = "GPO",
  1142. },
  1143. }, {
  1144. .config = &samsung_gpio_cfgs[6],
  1145. .chip = {
  1146. .base = S3C64XX_GPP(0),
  1147. .ngpio = S3C64XX_GPIO_P_NR,
  1148. .label = "GPP",
  1149. },
  1150. }, {
  1151. .config = &samsung_gpio_cfgs[6],
  1152. .chip = {
  1153. .base = S3C64XX_GPQ(0),
  1154. .ngpio = S3C64XX_GPIO_Q_NR,
  1155. .label = "GPQ",
  1156. },
  1157. }, {
  1158. .base = S3C64XX_GPN_BASE,
  1159. .irq_base = IRQ_EINT(0),
  1160. .config = &samsung_gpio_cfgs[5],
  1161. .chip = {
  1162. .base = S3C64XX_GPN(0),
  1163. .ngpio = S3C64XX_GPIO_N_NR,
  1164. .label = "GPN",
  1165. .to_irq = samsung_gpiolib_to_irq,
  1166. },
  1167. },
  1168. #endif
  1169. };
  1170. /*
  1171. * S5P6440 GPIO bank summary:
  1172. *
  1173. * Bank GPIOs Style SlpCon ExtInt Group
  1174. * A 6 4Bit Yes 1
  1175. * B 7 4Bit Yes 1
  1176. * C 8 4Bit Yes 2
  1177. * F 2 2Bit Yes 4 [1]
  1178. * G 7 4Bit Yes 5
  1179. * H 10 4Bit[2] Yes 6
  1180. * I 16 2Bit Yes None
  1181. * J 12 2Bit Yes None
  1182. * N 16 2Bit No IRQ_EINT
  1183. * P 8 2Bit Yes 8
  1184. * R 15 4Bit[2] Yes 8
  1185. */
  1186. static struct samsung_gpio_chip s5p6440_gpios_4bit[] = {
  1187. #ifdef CONFIG_CPU_S5P6440
  1188. {
  1189. .chip = {
  1190. .base = S5P6440_GPA(0),
  1191. .ngpio = S5P6440_GPIO_A_NR,
  1192. .label = "GPA",
  1193. },
  1194. }, {
  1195. .chip = {
  1196. .base = S5P6440_GPB(0),
  1197. .ngpio = S5P6440_GPIO_B_NR,
  1198. .label = "GPB",
  1199. },
  1200. }, {
  1201. .chip = {
  1202. .base = S5P6440_GPC(0),
  1203. .ngpio = S5P6440_GPIO_C_NR,
  1204. .label = "GPC",
  1205. },
  1206. }, {
  1207. .base = S5P64X0_GPG_BASE,
  1208. .chip = {
  1209. .base = S5P6440_GPG(0),
  1210. .ngpio = S5P6440_GPIO_G_NR,
  1211. .label = "GPG",
  1212. },
  1213. },
  1214. #endif
  1215. };
  1216. static struct samsung_gpio_chip s5p6440_gpios_4bit2[] = {
  1217. #ifdef CONFIG_CPU_S5P6440
  1218. {
  1219. .base = S5P64X0_GPH_BASE + 0x4,
  1220. .chip = {
  1221. .base = S5P6440_GPH(0),
  1222. .ngpio = S5P6440_GPIO_H_NR,
  1223. .label = "GPH",
  1224. },
  1225. },
  1226. #endif
  1227. };
  1228. static struct samsung_gpio_chip s5p6440_gpios_rbank[] = {
  1229. #ifdef CONFIG_CPU_S5P6440
  1230. {
  1231. .base = S5P64X0_GPR_BASE + 0x4,
  1232. .config = &s5p64x0_gpio_cfg_rbank,
  1233. .chip = {
  1234. .base = S5P6440_GPR(0),
  1235. .ngpio = S5P6440_GPIO_R_NR,
  1236. .label = "GPR",
  1237. },
  1238. },
  1239. #endif
  1240. };
  1241. static struct samsung_gpio_chip s5p6440_gpios_2bit[] = {
  1242. #ifdef CONFIG_CPU_S5P6440
  1243. {
  1244. .base = S5P64X0_GPF_BASE,
  1245. .config = &samsung_gpio_cfgs[6],
  1246. .chip = {
  1247. .base = S5P6440_GPF(0),
  1248. .ngpio = S5P6440_GPIO_F_NR,
  1249. .label = "GPF",
  1250. },
  1251. }, {
  1252. .base = S5P64X0_GPI_BASE,
  1253. .config = &samsung_gpio_cfgs[4],
  1254. .chip = {
  1255. .base = S5P6440_GPI(0),
  1256. .ngpio = S5P6440_GPIO_I_NR,
  1257. .label = "GPI",
  1258. },
  1259. }, {
  1260. .base = S5P64X0_GPJ_BASE,
  1261. .config = &samsung_gpio_cfgs[4],
  1262. .chip = {
  1263. .base = S5P6440_GPJ(0),
  1264. .ngpio = S5P6440_GPIO_J_NR,
  1265. .label = "GPJ",
  1266. },
  1267. }, {
  1268. .base = S5P64X0_GPN_BASE,
  1269. .config = &samsung_gpio_cfgs[5],
  1270. .chip = {
  1271. .base = S5P6440_GPN(0),
  1272. .ngpio = S5P6440_GPIO_N_NR,
  1273. .label = "GPN",
  1274. },
  1275. }, {
  1276. .base = S5P64X0_GPP_BASE,
  1277. .config = &samsung_gpio_cfgs[6],
  1278. .chip = {
  1279. .base = S5P6440_GPP(0),
  1280. .ngpio = S5P6440_GPIO_P_NR,
  1281. .label = "GPP",
  1282. },
  1283. },
  1284. #endif
  1285. };
  1286. /*
  1287. * S5P6450 GPIO bank summary:
  1288. *
  1289. * Bank GPIOs Style SlpCon ExtInt Group
  1290. * A 6 4Bit Yes 1
  1291. * B 7 4Bit Yes 1
  1292. * C 8 4Bit Yes 2
  1293. * D 8 4Bit Yes None
  1294. * F 2 2Bit Yes None
  1295. * G 14 4Bit[2] Yes 5
  1296. * H 10 4Bit[2] Yes 6
  1297. * I 16 2Bit Yes None
  1298. * J 12 2Bit Yes None
  1299. * K 5 4Bit Yes None
  1300. * N 16 2Bit No IRQ_EINT
  1301. * P 11 2Bit Yes 8
  1302. * Q 14 2Bit Yes None
  1303. * R 15 4Bit[2] Yes None
  1304. * S 8 2Bit Yes None
  1305. *
  1306. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  1307. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  1308. */
  1309. static struct samsung_gpio_chip s5p6450_gpios_4bit[] = {
  1310. #ifdef CONFIG_CPU_S5P6450
  1311. {
  1312. .chip = {
  1313. .base = S5P6450_GPA(0),
  1314. .ngpio = S5P6450_GPIO_A_NR,
  1315. .label = "GPA",
  1316. },
  1317. }, {
  1318. .chip = {
  1319. .base = S5P6450_GPB(0),
  1320. .ngpio = S5P6450_GPIO_B_NR,
  1321. .label = "GPB",
  1322. },
  1323. }, {
  1324. .chip = {
  1325. .base = S5P6450_GPC(0),
  1326. .ngpio = S5P6450_GPIO_C_NR,
  1327. .label = "GPC",
  1328. },
  1329. }, {
  1330. .chip = {
  1331. .base = S5P6450_GPD(0),
  1332. .ngpio = S5P6450_GPIO_D_NR,
  1333. .label = "GPD",
  1334. },
  1335. }, {
  1336. .base = S5P6450_GPK_BASE,
  1337. .chip = {
  1338. .base = S5P6450_GPK(0),
  1339. .ngpio = S5P6450_GPIO_K_NR,
  1340. .label = "GPK",
  1341. },
  1342. },
  1343. #endif
  1344. };
  1345. static struct samsung_gpio_chip s5p6450_gpios_4bit2[] = {
  1346. #ifdef CONFIG_CPU_S5P6450
  1347. {
  1348. .base = S5P64X0_GPG_BASE + 0x4,
  1349. .chip = {
  1350. .base = S5P6450_GPG(0),
  1351. .ngpio = S5P6450_GPIO_G_NR,
  1352. .label = "GPG",
  1353. },
  1354. }, {
  1355. .base = S5P64X0_GPH_BASE + 0x4,
  1356. .chip = {
  1357. .base = S5P6450_GPH(0),
  1358. .ngpio = S5P6450_GPIO_H_NR,
  1359. .label = "GPH",
  1360. },
  1361. },
  1362. #endif
  1363. };
  1364. static struct samsung_gpio_chip s5p6450_gpios_rbank[] = {
  1365. #ifdef CONFIG_CPU_S5P6450
  1366. {
  1367. .base = S5P64X0_GPR_BASE + 0x4,
  1368. .config = &s5p64x0_gpio_cfg_rbank,
  1369. .chip = {
  1370. .base = S5P6450_GPR(0),
  1371. .ngpio = S5P6450_GPIO_R_NR,
  1372. .label = "GPR",
  1373. },
  1374. },
  1375. #endif
  1376. };
  1377. static struct samsung_gpio_chip s5p6450_gpios_2bit[] = {
  1378. #ifdef CONFIG_CPU_S5P6450
  1379. {
  1380. .base = S5P64X0_GPF_BASE,
  1381. .config = &samsung_gpio_cfgs[6],
  1382. .chip = {
  1383. .base = S5P6450_GPF(0),
  1384. .ngpio = S5P6450_GPIO_F_NR,
  1385. .label = "GPF",
  1386. },
  1387. }, {
  1388. .base = S5P64X0_GPI_BASE,
  1389. .config = &samsung_gpio_cfgs[4],
  1390. .chip = {
  1391. .base = S5P6450_GPI(0),
  1392. .ngpio = S5P6450_GPIO_I_NR,
  1393. .label = "GPI",
  1394. },
  1395. }, {
  1396. .base = S5P64X0_GPJ_BASE,
  1397. .config = &samsung_gpio_cfgs[4],
  1398. .chip = {
  1399. .base = S5P6450_GPJ(0),
  1400. .ngpio = S5P6450_GPIO_J_NR,
  1401. .label = "GPJ",
  1402. },
  1403. }, {
  1404. .base = S5P64X0_GPN_BASE,
  1405. .config = &samsung_gpio_cfgs[5],
  1406. .chip = {
  1407. .base = S5P6450_GPN(0),
  1408. .ngpio = S5P6450_GPIO_N_NR,
  1409. .label = "GPN",
  1410. },
  1411. }, {
  1412. .base = S5P64X0_GPP_BASE,
  1413. .config = &samsung_gpio_cfgs[6],
  1414. .chip = {
  1415. .base = S5P6450_GPP(0),
  1416. .ngpio = S5P6450_GPIO_P_NR,
  1417. .label = "GPP",
  1418. },
  1419. }, {
  1420. .base = S5P6450_GPQ_BASE,
  1421. .config = &samsung_gpio_cfgs[5],
  1422. .chip = {
  1423. .base = S5P6450_GPQ(0),
  1424. .ngpio = S5P6450_GPIO_Q_NR,
  1425. .label = "GPQ",
  1426. },
  1427. }, {
  1428. .base = S5P6450_GPS_BASE,
  1429. .config = &samsung_gpio_cfgs[6],
  1430. .chip = {
  1431. .base = S5P6450_GPS(0),
  1432. .ngpio = S5P6450_GPIO_S_NR,
  1433. .label = "GPS",
  1434. },
  1435. },
  1436. #endif
  1437. };
  1438. /*
  1439. * S5PC100 GPIO bank summary:
  1440. *
  1441. * Bank GPIOs Style INT Type
  1442. * A0 8 4Bit GPIO_INT0
  1443. * A1 5 4Bit GPIO_INT1
  1444. * B 8 4Bit GPIO_INT2
  1445. * C 5 4Bit GPIO_INT3
  1446. * D 7 4Bit GPIO_INT4
  1447. * E0 8 4Bit GPIO_INT5
  1448. * E1 6 4Bit GPIO_INT6
  1449. * F0 8 4Bit GPIO_INT7
  1450. * F1 8 4Bit GPIO_INT8
  1451. * F2 8 4Bit GPIO_INT9
  1452. * F3 4 4Bit GPIO_INT10
  1453. * G0 8 4Bit GPIO_INT11
  1454. * G1 3 4Bit GPIO_INT12
  1455. * G2 7 4Bit GPIO_INT13
  1456. * G3 7 4Bit GPIO_INT14
  1457. * H0 8 4Bit WKUP_INT
  1458. * H1 8 4Bit WKUP_INT
  1459. * H2 8 4Bit WKUP_INT
  1460. * H3 8 4Bit WKUP_INT
  1461. * I 8 4Bit GPIO_INT15
  1462. * J0 8 4Bit GPIO_INT16
  1463. * J1 5 4Bit GPIO_INT17
  1464. * J2 8 4Bit GPIO_INT18
  1465. * J3 8 4Bit GPIO_INT19
  1466. * J4 4 4Bit GPIO_INT20
  1467. * K0 8 4Bit None
  1468. * K1 6 4Bit None
  1469. * K2 8 4Bit None
  1470. * K3 8 4Bit None
  1471. * L0 8 4Bit None
  1472. * L1 8 4Bit None
  1473. * L2 8 4Bit None
  1474. * L3 8 4Bit None
  1475. */
  1476. static struct samsung_gpio_chip s5pc100_gpios_4bit[] = {
  1477. #ifdef CONFIG_CPU_S5PC100
  1478. {
  1479. .chip = {
  1480. .base = S5PC100_GPA0(0),
  1481. .ngpio = S5PC100_GPIO_A0_NR,
  1482. .label = "GPA0",
  1483. },
  1484. }, {
  1485. .chip = {
  1486. .base = S5PC100_GPA1(0),
  1487. .ngpio = S5PC100_GPIO_A1_NR,
  1488. .label = "GPA1",
  1489. },
  1490. }, {
  1491. .chip = {
  1492. .base = S5PC100_GPB(0),
  1493. .ngpio = S5PC100_GPIO_B_NR,
  1494. .label = "GPB",
  1495. },
  1496. }, {
  1497. .chip = {
  1498. .base = S5PC100_GPC(0),
  1499. .ngpio = S5PC100_GPIO_C_NR,
  1500. .label = "GPC",
  1501. },
  1502. }, {
  1503. .chip = {
  1504. .base = S5PC100_GPD(0),
  1505. .ngpio = S5PC100_GPIO_D_NR,
  1506. .label = "GPD",
  1507. },
  1508. }, {
  1509. .chip = {
  1510. .base = S5PC100_GPE0(0),
  1511. .ngpio = S5PC100_GPIO_E0_NR,
  1512. .label = "GPE0",
  1513. },
  1514. }, {
  1515. .chip = {
  1516. .base = S5PC100_GPE1(0),
  1517. .ngpio = S5PC100_GPIO_E1_NR,
  1518. .label = "GPE1",
  1519. },
  1520. }, {
  1521. .chip = {
  1522. .base = S5PC100_GPF0(0),
  1523. .ngpio = S5PC100_GPIO_F0_NR,
  1524. .label = "GPF0",
  1525. },
  1526. }, {
  1527. .chip = {
  1528. .base = S5PC100_GPF1(0),
  1529. .ngpio = S5PC100_GPIO_F1_NR,
  1530. .label = "GPF1",
  1531. },
  1532. }, {
  1533. .chip = {
  1534. .base = S5PC100_GPF2(0),
  1535. .ngpio = S5PC100_GPIO_F2_NR,
  1536. .label = "GPF2",
  1537. },
  1538. }, {
  1539. .chip = {
  1540. .base = S5PC100_GPF3(0),
  1541. .ngpio = S5PC100_GPIO_F3_NR,
  1542. .label = "GPF3",
  1543. },
  1544. }, {
  1545. .chip = {
  1546. .base = S5PC100_GPG0(0),
  1547. .ngpio = S5PC100_GPIO_G0_NR,
  1548. .label = "GPG0",
  1549. },
  1550. }, {
  1551. .chip = {
  1552. .base = S5PC100_GPG1(0),
  1553. .ngpio = S5PC100_GPIO_G1_NR,
  1554. .label = "GPG1",
  1555. },
  1556. }, {
  1557. .chip = {
  1558. .base = S5PC100_GPG2(0),
  1559. .ngpio = S5PC100_GPIO_G2_NR,
  1560. .label = "GPG2",
  1561. },
  1562. }, {
  1563. .chip = {
  1564. .base = S5PC100_GPG3(0),
  1565. .ngpio = S5PC100_GPIO_G3_NR,
  1566. .label = "GPG3",
  1567. },
  1568. }, {
  1569. .chip = {
  1570. .base = S5PC100_GPI(0),
  1571. .ngpio = S5PC100_GPIO_I_NR,
  1572. .label = "GPI",
  1573. },
  1574. }, {
  1575. .chip = {
  1576. .base = S5PC100_GPJ0(0),
  1577. .ngpio = S5PC100_GPIO_J0_NR,
  1578. .label = "GPJ0",
  1579. },
  1580. }, {
  1581. .chip = {
  1582. .base = S5PC100_GPJ1(0),
  1583. .ngpio = S5PC100_GPIO_J1_NR,
  1584. .label = "GPJ1",
  1585. },
  1586. }, {
  1587. .chip = {
  1588. .base = S5PC100_GPJ2(0),
  1589. .ngpio = S5PC100_GPIO_J2_NR,
  1590. .label = "GPJ2",
  1591. },
  1592. }, {
  1593. .chip = {
  1594. .base = S5PC100_GPJ3(0),
  1595. .ngpio = S5PC100_GPIO_J3_NR,
  1596. .label = "GPJ3",
  1597. },
  1598. }, {
  1599. .chip = {
  1600. .base = S5PC100_GPJ4(0),
  1601. .ngpio = S5PC100_GPIO_J4_NR,
  1602. .label = "GPJ4",
  1603. },
  1604. }, {
  1605. .chip = {
  1606. .base = S5PC100_GPK0(0),
  1607. .ngpio = S5PC100_GPIO_K0_NR,
  1608. .label = "GPK0",
  1609. },
  1610. }, {
  1611. .chip = {
  1612. .base = S5PC100_GPK1(0),
  1613. .ngpio = S5PC100_GPIO_K1_NR,
  1614. .label = "GPK1",
  1615. },
  1616. }, {
  1617. .chip = {
  1618. .base = S5PC100_GPK2(0),
  1619. .ngpio = S5PC100_GPIO_K2_NR,
  1620. .label = "GPK2",
  1621. },
  1622. }, {
  1623. .chip = {
  1624. .base = S5PC100_GPK3(0),
  1625. .ngpio = S5PC100_GPIO_K3_NR,
  1626. .label = "GPK3",
  1627. },
  1628. }, {
  1629. .chip = {
  1630. .base = S5PC100_GPL0(0),
  1631. .ngpio = S5PC100_GPIO_L0_NR,
  1632. .label = "GPL0",
  1633. },
  1634. }, {
  1635. .chip = {
  1636. .base = S5PC100_GPL1(0),
  1637. .ngpio = S5PC100_GPIO_L1_NR,
  1638. .label = "GPL1",
  1639. },
  1640. }, {
  1641. .chip = {
  1642. .base = S5PC100_GPL2(0),
  1643. .ngpio = S5PC100_GPIO_L2_NR,
  1644. .label = "GPL2",
  1645. },
  1646. }, {
  1647. .chip = {
  1648. .base = S5PC100_GPL3(0),
  1649. .ngpio = S5PC100_GPIO_L3_NR,
  1650. .label = "GPL3",
  1651. },
  1652. }, {
  1653. .chip = {
  1654. .base = S5PC100_GPL4(0),
  1655. .ngpio = S5PC100_GPIO_L4_NR,
  1656. .label = "GPL4",
  1657. },
  1658. }, {
  1659. .base = (S5P_VA_GPIO + 0xC00),
  1660. .irq_base = IRQ_EINT(0),
  1661. .chip = {
  1662. .base = S5PC100_GPH0(0),
  1663. .ngpio = S5PC100_GPIO_H0_NR,
  1664. .label = "GPH0",
  1665. .to_irq = samsung_gpiolib_to_irq,
  1666. },
  1667. }, {
  1668. .base = (S5P_VA_GPIO + 0xC20),
  1669. .irq_base = IRQ_EINT(8),
  1670. .chip = {
  1671. .base = S5PC100_GPH1(0),
  1672. .ngpio = S5PC100_GPIO_H1_NR,
  1673. .label = "GPH1",
  1674. .to_irq = samsung_gpiolib_to_irq,
  1675. },
  1676. }, {
  1677. .base = (S5P_VA_GPIO + 0xC40),
  1678. .irq_base = IRQ_EINT(16),
  1679. .chip = {
  1680. .base = S5PC100_GPH2(0),
  1681. .ngpio = S5PC100_GPIO_H2_NR,
  1682. .label = "GPH2",
  1683. .to_irq = samsung_gpiolib_to_irq,
  1684. },
  1685. }, {
  1686. .base = (S5P_VA_GPIO + 0xC60),
  1687. .irq_base = IRQ_EINT(24),
  1688. .chip = {
  1689. .base = S5PC100_GPH3(0),
  1690. .ngpio = S5PC100_GPIO_H3_NR,
  1691. .label = "GPH3",
  1692. .to_irq = samsung_gpiolib_to_irq,
  1693. },
  1694. },
  1695. #endif
  1696. };
  1697. /*
  1698. * Followings are the gpio banks in S5PV210/S5PC110
  1699. *
  1700. * The 'config' member when left to NULL, is initialized to the default
  1701. * structure samsung_gpio_cfgs[3] in the init function below.
  1702. *
  1703. * The 'base' member is also initialized in the init function below.
  1704. * Note: The initialization of 'base' member of samsung_gpio_chip structure
  1705. * uses the above macro and depends on the banks being listed in order here.
  1706. */
  1707. static struct samsung_gpio_chip s5pv210_gpios_4bit[] = {
  1708. #ifdef CONFIG_CPU_S5PV210
  1709. {
  1710. .chip = {
  1711. .base = S5PV210_GPA0(0),
  1712. .ngpio = S5PV210_GPIO_A0_NR,
  1713. .label = "GPA0",
  1714. },
  1715. }, {
  1716. .chip = {
  1717. .base = S5PV210_GPA1(0),
  1718. .ngpio = S5PV210_GPIO_A1_NR,
  1719. .label = "GPA1",
  1720. },
  1721. }, {
  1722. .chip = {
  1723. .base = S5PV210_GPB(0),
  1724. .ngpio = S5PV210_GPIO_B_NR,
  1725. .label = "GPB",
  1726. },
  1727. }, {
  1728. .chip = {
  1729. .base = S5PV210_GPC0(0),
  1730. .ngpio = S5PV210_GPIO_C0_NR,
  1731. .label = "GPC0",
  1732. },
  1733. }, {
  1734. .chip = {
  1735. .base = S5PV210_GPC1(0),
  1736. .ngpio = S5PV210_GPIO_C1_NR,
  1737. .label = "GPC1",
  1738. },
  1739. }, {
  1740. .chip = {
  1741. .base = S5PV210_GPD0(0),
  1742. .ngpio = S5PV210_GPIO_D0_NR,
  1743. .label = "GPD0",
  1744. },
  1745. }, {
  1746. .chip = {
  1747. .base = S5PV210_GPD1(0),
  1748. .ngpio = S5PV210_GPIO_D1_NR,
  1749. .label = "GPD1",
  1750. },
  1751. }, {
  1752. .chip = {
  1753. .base = S5PV210_GPE0(0),
  1754. .ngpio = S5PV210_GPIO_E0_NR,
  1755. .label = "GPE0",
  1756. },
  1757. }, {
  1758. .chip = {
  1759. .base = S5PV210_GPE1(0),
  1760. .ngpio = S5PV210_GPIO_E1_NR,
  1761. .label = "GPE1",
  1762. },
  1763. }, {
  1764. .chip = {
  1765. .base = S5PV210_GPF0(0),
  1766. .ngpio = S5PV210_GPIO_F0_NR,
  1767. .label = "GPF0",
  1768. },
  1769. }, {
  1770. .chip = {
  1771. .base = S5PV210_GPF1(0),
  1772. .ngpio = S5PV210_GPIO_F1_NR,
  1773. .label = "GPF1",
  1774. },
  1775. }, {
  1776. .chip = {
  1777. .base = S5PV210_GPF2(0),
  1778. .ngpio = S5PV210_GPIO_F2_NR,
  1779. .label = "GPF2",
  1780. },
  1781. }, {
  1782. .chip = {
  1783. .base = S5PV210_GPF3(0),
  1784. .ngpio = S5PV210_GPIO_F3_NR,
  1785. .label = "GPF3",
  1786. },
  1787. }, {
  1788. .chip = {
  1789. .base = S5PV210_GPG0(0),
  1790. .ngpio = S5PV210_GPIO_G0_NR,
  1791. .label = "GPG0",
  1792. },
  1793. }, {
  1794. .chip = {
  1795. .base = S5PV210_GPG1(0),
  1796. .ngpio = S5PV210_GPIO_G1_NR,
  1797. .label = "GPG1",
  1798. },
  1799. }, {
  1800. .chip = {
  1801. .base = S5PV210_GPG2(0),
  1802. .ngpio = S5PV210_GPIO_G2_NR,
  1803. .label = "GPG2",
  1804. },
  1805. }, {
  1806. .chip = {
  1807. .base = S5PV210_GPG3(0),
  1808. .ngpio = S5PV210_GPIO_G3_NR,
  1809. .label = "GPG3",
  1810. },
  1811. }, {
  1812. .chip = {
  1813. .base = S5PV210_GPI(0),
  1814. .ngpio = S5PV210_GPIO_I_NR,
  1815. .label = "GPI",
  1816. },
  1817. }, {
  1818. .chip = {
  1819. .base = S5PV210_GPJ0(0),
  1820. .ngpio = S5PV210_GPIO_J0_NR,
  1821. .label = "GPJ0",
  1822. },
  1823. }, {
  1824. .chip = {
  1825. .base = S5PV210_GPJ1(0),
  1826. .ngpio = S5PV210_GPIO_J1_NR,
  1827. .label = "GPJ1",
  1828. },
  1829. }, {
  1830. .chip = {
  1831. .base = S5PV210_GPJ2(0),
  1832. .ngpio = S5PV210_GPIO_J2_NR,
  1833. .label = "GPJ2",
  1834. },
  1835. }, {
  1836. .chip = {
  1837. .base = S5PV210_GPJ3(0),
  1838. .ngpio = S5PV210_GPIO_J3_NR,
  1839. .label = "GPJ3",
  1840. },
  1841. }, {
  1842. .chip = {
  1843. .base = S5PV210_GPJ4(0),
  1844. .ngpio = S5PV210_GPIO_J4_NR,
  1845. .label = "GPJ4",
  1846. },
  1847. }, {
  1848. .chip = {
  1849. .base = S5PV210_MP01(0),
  1850. .ngpio = S5PV210_GPIO_MP01_NR,
  1851. .label = "MP01",
  1852. },
  1853. }, {
  1854. .chip = {
  1855. .base = S5PV210_MP02(0),
  1856. .ngpio = S5PV210_GPIO_MP02_NR,
  1857. .label = "MP02",
  1858. },
  1859. }, {
  1860. .chip = {
  1861. .base = S5PV210_MP03(0),
  1862. .ngpio = S5PV210_GPIO_MP03_NR,
  1863. .label = "MP03",
  1864. },
  1865. }, {
  1866. .chip = {
  1867. .base = S5PV210_MP04(0),
  1868. .ngpio = S5PV210_GPIO_MP04_NR,
  1869. .label = "MP04",
  1870. },
  1871. }, {
  1872. .chip = {
  1873. .base = S5PV210_MP05(0),
  1874. .ngpio = S5PV210_GPIO_MP05_NR,
  1875. .label = "MP05",
  1876. },
  1877. }, {
  1878. .base = (S5P_VA_GPIO + 0xC00),
  1879. .irq_base = IRQ_EINT(0),
  1880. .chip = {
  1881. .base = S5PV210_GPH0(0),
  1882. .ngpio = S5PV210_GPIO_H0_NR,
  1883. .label = "GPH0",
  1884. .to_irq = samsung_gpiolib_to_irq,
  1885. },
  1886. }, {
  1887. .base = (S5P_VA_GPIO + 0xC20),
  1888. .irq_base = IRQ_EINT(8),
  1889. .chip = {
  1890. .base = S5PV210_GPH1(0),
  1891. .ngpio = S5PV210_GPIO_H1_NR,
  1892. .label = "GPH1",
  1893. .to_irq = samsung_gpiolib_to_irq,
  1894. },
  1895. }, {
  1896. .base = (S5P_VA_GPIO + 0xC40),
  1897. .irq_base = IRQ_EINT(16),
  1898. .chip = {
  1899. .base = S5PV210_GPH2(0),
  1900. .ngpio = S5PV210_GPIO_H2_NR,
  1901. .label = "GPH2",
  1902. .to_irq = samsung_gpiolib_to_irq,
  1903. },
  1904. }, {
  1905. .base = (S5P_VA_GPIO + 0xC60),
  1906. .irq_base = IRQ_EINT(24),
  1907. .chip = {
  1908. .base = S5PV210_GPH3(0),
  1909. .ngpio = S5PV210_GPIO_H3_NR,
  1910. .label = "GPH3",
  1911. .to_irq = samsung_gpiolib_to_irq,
  1912. },
  1913. },
  1914. #endif
  1915. };
  1916. /*
  1917. * Followings are the gpio banks in EXYNOS SoCs
  1918. *
  1919. * The 'config' member when left to NULL, is initialized to the default
  1920. * structure exynos_gpio_cfg in the init function below.
  1921. *
  1922. * The 'base' member is also initialized in the init function below.
  1923. * Note: The initialization of 'base' member of samsung_gpio_chip structure
  1924. * uses the above macro and depends on the banks being listed in order here.
  1925. */
  1926. #ifdef CONFIG_ARCH_EXYNOS4
  1927. static struct samsung_gpio_chip exynos4_gpios_1[] = {
  1928. {
  1929. .chip = {
  1930. .base = EXYNOS4_GPA0(0),
  1931. .ngpio = EXYNOS4_GPIO_A0_NR,
  1932. .label = "GPA0",
  1933. },
  1934. }, {
  1935. .chip = {
  1936. .base = EXYNOS4_GPA1(0),
  1937. .ngpio = EXYNOS4_GPIO_A1_NR,
  1938. .label = "GPA1",
  1939. },
  1940. }, {
  1941. .chip = {
  1942. .base = EXYNOS4_GPB(0),
  1943. .ngpio = EXYNOS4_GPIO_B_NR,
  1944. .label = "GPB",
  1945. },
  1946. }, {
  1947. .chip = {
  1948. .base = EXYNOS4_GPC0(0),
  1949. .ngpio = EXYNOS4_GPIO_C0_NR,
  1950. .label = "GPC0",
  1951. },
  1952. }, {
  1953. .chip = {
  1954. .base = EXYNOS4_GPC1(0),
  1955. .ngpio = EXYNOS4_GPIO_C1_NR,
  1956. .label = "GPC1",
  1957. },
  1958. }, {
  1959. .chip = {
  1960. .base = EXYNOS4_GPD0(0),
  1961. .ngpio = EXYNOS4_GPIO_D0_NR,
  1962. .label = "GPD0",
  1963. },
  1964. }, {
  1965. .chip = {
  1966. .base = EXYNOS4_GPD1(0),
  1967. .ngpio = EXYNOS4_GPIO_D1_NR,
  1968. .label = "GPD1",
  1969. },
  1970. }, {
  1971. .chip = {
  1972. .base = EXYNOS4_GPE0(0),
  1973. .ngpio = EXYNOS4_GPIO_E0_NR,
  1974. .label = "GPE0",
  1975. },
  1976. }, {
  1977. .chip = {
  1978. .base = EXYNOS4_GPE1(0),
  1979. .ngpio = EXYNOS4_GPIO_E1_NR,
  1980. .label = "GPE1",
  1981. },
  1982. }, {
  1983. .chip = {
  1984. .base = EXYNOS4_GPE2(0),
  1985. .ngpio = EXYNOS4_GPIO_E2_NR,
  1986. .label = "GPE2",
  1987. },
  1988. }, {
  1989. .chip = {
  1990. .base = EXYNOS4_GPE3(0),
  1991. .ngpio = EXYNOS4_GPIO_E3_NR,
  1992. .label = "GPE3",
  1993. },
  1994. }, {
  1995. .chip = {
  1996. .base = EXYNOS4_GPE4(0),
  1997. .ngpio = EXYNOS4_GPIO_E4_NR,
  1998. .label = "GPE4",
  1999. },
  2000. }, {
  2001. .chip = {
  2002. .base = EXYNOS4_GPF0(0),
  2003. .ngpio = EXYNOS4_GPIO_F0_NR,
  2004. .label = "GPF0",
  2005. },
  2006. }, {
  2007. .chip = {
  2008. .base = EXYNOS4_GPF1(0),
  2009. .ngpio = EXYNOS4_GPIO_F1_NR,
  2010. .label = "GPF1",
  2011. },
  2012. }, {
  2013. .chip = {
  2014. .base = EXYNOS4_GPF2(0),
  2015. .ngpio = EXYNOS4_GPIO_F2_NR,
  2016. .label = "GPF2",
  2017. },
  2018. }, {
  2019. .chip = {
  2020. .base = EXYNOS4_GPF3(0),
  2021. .ngpio = EXYNOS4_GPIO_F3_NR,
  2022. .label = "GPF3",
  2023. },
  2024. },
  2025. };
  2026. #endif
  2027. #ifdef CONFIG_ARCH_EXYNOS4
  2028. static struct samsung_gpio_chip exynos4_gpios_2[] = {
  2029. {
  2030. .chip = {
  2031. .base = EXYNOS4_GPJ0(0),
  2032. .ngpio = EXYNOS4_GPIO_J0_NR,
  2033. .label = "GPJ0",
  2034. },
  2035. }, {
  2036. .chip = {
  2037. .base = EXYNOS4_GPJ1(0),
  2038. .ngpio = EXYNOS4_GPIO_J1_NR,
  2039. .label = "GPJ1",
  2040. },
  2041. }, {
  2042. .chip = {
  2043. .base = EXYNOS4_GPK0(0),
  2044. .ngpio = EXYNOS4_GPIO_K0_NR,
  2045. .label = "GPK0",
  2046. },
  2047. }, {
  2048. .chip = {
  2049. .base = EXYNOS4_GPK1(0),
  2050. .ngpio = EXYNOS4_GPIO_K1_NR,
  2051. .label = "GPK1",
  2052. },
  2053. }, {
  2054. .chip = {
  2055. .base = EXYNOS4_GPK2(0),
  2056. .ngpio = EXYNOS4_GPIO_K2_NR,
  2057. .label = "GPK2",
  2058. },
  2059. }, {
  2060. .chip = {
  2061. .base = EXYNOS4_GPK3(0),
  2062. .ngpio = EXYNOS4_GPIO_K3_NR,
  2063. .label = "GPK3",
  2064. },
  2065. }, {
  2066. .chip = {
  2067. .base = EXYNOS4_GPL0(0),
  2068. .ngpio = EXYNOS4_GPIO_L0_NR,
  2069. .label = "GPL0",
  2070. },
  2071. }, {
  2072. .chip = {
  2073. .base = EXYNOS4_GPL1(0),
  2074. .ngpio = EXYNOS4_GPIO_L1_NR,
  2075. .label = "GPL1",
  2076. },
  2077. }, {
  2078. .chip = {
  2079. .base = EXYNOS4_GPL2(0),
  2080. .ngpio = EXYNOS4_GPIO_L2_NR,
  2081. .label = "GPL2",
  2082. },
  2083. }, {
  2084. .config = &samsung_gpio_cfgs[8],
  2085. .chip = {
  2086. .base = EXYNOS4_GPY0(0),
  2087. .ngpio = EXYNOS4_GPIO_Y0_NR,
  2088. .label = "GPY0",
  2089. },
  2090. }, {
  2091. .config = &samsung_gpio_cfgs[8],
  2092. .chip = {
  2093. .base = EXYNOS4_GPY1(0),
  2094. .ngpio = EXYNOS4_GPIO_Y1_NR,
  2095. .label = "GPY1",
  2096. },
  2097. }, {
  2098. .config = &samsung_gpio_cfgs[8],
  2099. .chip = {
  2100. .base = EXYNOS4_GPY2(0),
  2101. .ngpio = EXYNOS4_GPIO_Y2_NR,
  2102. .label = "GPY2",
  2103. },
  2104. }, {
  2105. .config = &samsung_gpio_cfgs[8],
  2106. .chip = {
  2107. .base = EXYNOS4_GPY3(0),
  2108. .ngpio = EXYNOS4_GPIO_Y3_NR,
  2109. .label = "GPY3",
  2110. },
  2111. }, {
  2112. .config = &samsung_gpio_cfgs[8],
  2113. .chip = {
  2114. .base = EXYNOS4_GPY4(0),
  2115. .ngpio = EXYNOS4_GPIO_Y4_NR,
  2116. .label = "GPY4",
  2117. },
  2118. }, {
  2119. .config = &samsung_gpio_cfgs[8],
  2120. .chip = {
  2121. .base = EXYNOS4_GPY5(0),
  2122. .ngpio = EXYNOS4_GPIO_Y5_NR,
  2123. .label = "GPY5",
  2124. },
  2125. }, {
  2126. .config = &samsung_gpio_cfgs[8],
  2127. .chip = {
  2128. .base = EXYNOS4_GPY6(0),
  2129. .ngpio = EXYNOS4_GPIO_Y6_NR,
  2130. .label = "GPY6",
  2131. },
  2132. }, {
  2133. .config = &samsung_gpio_cfgs[9],
  2134. .irq_base = IRQ_EINT(0),
  2135. .chip = {
  2136. .base = EXYNOS4_GPX0(0),
  2137. .ngpio = EXYNOS4_GPIO_X0_NR,
  2138. .label = "GPX0",
  2139. .to_irq = samsung_gpiolib_to_irq,
  2140. },
  2141. }, {
  2142. .config = &samsung_gpio_cfgs[9],
  2143. .irq_base = IRQ_EINT(8),
  2144. .chip = {
  2145. .base = EXYNOS4_GPX1(0),
  2146. .ngpio = EXYNOS4_GPIO_X1_NR,
  2147. .label = "GPX1",
  2148. .to_irq = samsung_gpiolib_to_irq,
  2149. },
  2150. }, {
  2151. .config = &samsung_gpio_cfgs[9],
  2152. .irq_base = IRQ_EINT(16),
  2153. .chip = {
  2154. .base = EXYNOS4_GPX2(0),
  2155. .ngpio = EXYNOS4_GPIO_X2_NR,
  2156. .label = "GPX2",
  2157. .to_irq = samsung_gpiolib_to_irq,
  2158. },
  2159. }, {
  2160. .config = &samsung_gpio_cfgs[9],
  2161. .irq_base = IRQ_EINT(24),
  2162. .chip = {
  2163. .base = EXYNOS4_GPX3(0),
  2164. .ngpio = EXYNOS4_GPIO_X3_NR,
  2165. .label = "GPX3",
  2166. .to_irq = samsung_gpiolib_to_irq,
  2167. },
  2168. },
  2169. };
  2170. #endif
  2171. #ifdef CONFIG_ARCH_EXYNOS4
  2172. static struct samsung_gpio_chip exynos4_gpios_3[] = {
  2173. {
  2174. .chip = {
  2175. .base = EXYNOS4_GPZ(0),
  2176. .ngpio = EXYNOS4_GPIO_Z_NR,
  2177. .label = "GPZ",
  2178. },
  2179. },
  2180. };
  2181. #endif
  2182. #ifdef CONFIG_SOC_EXYNOS5250
  2183. static struct samsung_gpio_chip exynos5_gpios_1[] = {
  2184. {
  2185. .chip = {
  2186. .base = EXYNOS5_GPA0(0),
  2187. .ngpio = EXYNOS5_GPIO_A0_NR,
  2188. .label = "GPA0",
  2189. },
  2190. }, {
  2191. .chip = {
  2192. .base = EXYNOS5_GPA1(0),
  2193. .ngpio = EXYNOS5_GPIO_A1_NR,
  2194. .label = "GPA1",
  2195. },
  2196. }, {
  2197. .chip = {
  2198. .base = EXYNOS5_GPA2(0),
  2199. .ngpio = EXYNOS5_GPIO_A2_NR,
  2200. .label = "GPA2",
  2201. },
  2202. }, {
  2203. .chip = {
  2204. .base = EXYNOS5_GPB0(0),
  2205. .ngpio = EXYNOS5_GPIO_B0_NR,
  2206. .label = "GPB0",
  2207. },
  2208. }, {
  2209. .chip = {
  2210. .base = EXYNOS5_GPB1(0),
  2211. .ngpio = EXYNOS5_GPIO_B1_NR,
  2212. .label = "GPB1",
  2213. },
  2214. }, {
  2215. .chip = {
  2216. .base = EXYNOS5_GPB2(0),
  2217. .ngpio = EXYNOS5_GPIO_B2_NR,
  2218. .label = "GPB2",
  2219. },
  2220. }, {
  2221. .chip = {
  2222. .base = EXYNOS5_GPB3(0),
  2223. .ngpio = EXYNOS5_GPIO_B3_NR,
  2224. .label = "GPB3",
  2225. },
  2226. }, {
  2227. .chip = {
  2228. .base = EXYNOS5_GPC0(0),
  2229. .ngpio = EXYNOS5_GPIO_C0_NR,
  2230. .label = "GPC0",
  2231. },
  2232. }, {
  2233. .chip = {
  2234. .base = EXYNOS5_GPC1(0),
  2235. .ngpio = EXYNOS5_GPIO_C1_NR,
  2236. .label = "GPC1",
  2237. },
  2238. }, {
  2239. .chip = {
  2240. .base = EXYNOS5_GPC2(0),
  2241. .ngpio = EXYNOS5_GPIO_C2_NR,
  2242. .label = "GPC2",
  2243. },
  2244. }, {
  2245. .chip = {
  2246. .base = EXYNOS5_GPC3(0),
  2247. .ngpio = EXYNOS5_GPIO_C3_NR,
  2248. .label = "GPC3",
  2249. },
  2250. }, {
  2251. .chip = {
  2252. .base = EXYNOS5_GPD0(0),
  2253. .ngpio = EXYNOS5_GPIO_D0_NR,
  2254. .label = "GPD0",
  2255. },
  2256. }, {
  2257. .chip = {
  2258. .base = EXYNOS5_GPD1(0),
  2259. .ngpio = EXYNOS5_GPIO_D1_NR,
  2260. .label = "GPD1",
  2261. },
  2262. }, {
  2263. .chip = {
  2264. .base = EXYNOS5_GPY0(0),
  2265. .ngpio = EXYNOS5_GPIO_Y0_NR,
  2266. .label = "GPY0",
  2267. },
  2268. }, {
  2269. .chip = {
  2270. .base = EXYNOS5_GPY1(0),
  2271. .ngpio = EXYNOS5_GPIO_Y1_NR,
  2272. .label = "GPY1",
  2273. },
  2274. }, {
  2275. .chip = {
  2276. .base = EXYNOS5_GPY2(0),
  2277. .ngpio = EXYNOS5_GPIO_Y2_NR,
  2278. .label = "GPY2",
  2279. },
  2280. }, {
  2281. .chip = {
  2282. .base = EXYNOS5_GPY3(0),
  2283. .ngpio = EXYNOS5_GPIO_Y3_NR,
  2284. .label = "GPY3",
  2285. },
  2286. }, {
  2287. .chip = {
  2288. .base = EXYNOS5_GPY4(0),
  2289. .ngpio = EXYNOS5_GPIO_Y4_NR,
  2290. .label = "GPY4",
  2291. },
  2292. }, {
  2293. .chip = {
  2294. .base = EXYNOS5_GPY5(0),
  2295. .ngpio = EXYNOS5_GPIO_Y5_NR,
  2296. .label = "GPY5",
  2297. },
  2298. }, {
  2299. .chip = {
  2300. .base = EXYNOS5_GPY6(0),
  2301. .ngpio = EXYNOS5_GPIO_Y6_NR,
  2302. .label = "GPY6",
  2303. },
  2304. }, {
  2305. .chip = {
  2306. .base = EXYNOS5_GPC4(0),
  2307. .ngpio = EXYNOS5_GPIO_C4_NR,
  2308. .label = "GPC4",
  2309. },
  2310. }, {
  2311. .config = &samsung_gpio_cfgs[9],
  2312. .irq_base = IRQ_EINT(0),
  2313. .chip = {
  2314. .base = EXYNOS5_GPX0(0),
  2315. .ngpio = EXYNOS5_GPIO_X0_NR,
  2316. .label = "GPX0",
  2317. .to_irq = samsung_gpiolib_to_irq,
  2318. },
  2319. }, {
  2320. .config = &samsung_gpio_cfgs[9],
  2321. .irq_base = IRQ_EINT(8),
  2322. .chip = {
  2323. .base = EXYNOS5_GPX1(0),
  2324. .ngpio = EXYNOS5_GPIO_X1_NR,
  2325. .label = "GPX1",
  2326. .to_irq = samsung_gpiolib_to_irq,
  2327. },
  2328. }, {
  2329. .config = &samsung_gpio_cfgs[9],
  2330. .irq_base = IRQ_EINT(16),
  2331. .chip = {
  2332. .base = EXYNOS5_GPX2(0),
  2333. .ngpio = EXYNOS5_GPIO_X2_NR,
  2334. .label = "GPX2",
  2335. .to_irq = samsung_gpiolib_to_irq,
  2336. },
  2337. }, {
  2338. .config = &samsung_gpio_cfgs[9],
  2339. .irq_base = IRQ_EINT(24),
  2340. .chip = {
  2341. .base = EXYNOS5_GPX3(0),
  2342. .ngpio = EXYNOS5_GPIO_X3_NR,
  2343. .label = "GPX3",
  2344. .to_irq = samsung_gpiolib_to_irq,
  2345. },
  2346. },
  2347. };
  2348. #endif
  2349. #ifdef CONFIG_SOC_EXYNOS5250
  2350. static struct samsung_gpio_chip exynos5_gpios_2[] = {
  2351. {
  2352. .chip = {
  2353. .base = EXYNOS5_GPE0(0),
  2354. .ngpio = EXYNOS5_GPIO_E0_NR,
  2355. .label = "GPE0",
  2356. },
  2357. }, {
  2358. .chip = {
  2359. .base = EXYNOS5_GPE1(0),
  2360. .ngpio = EXYNOS5_GPIO_E1_NR,
  2361. .label = "GPE1",
  2362. },
  2363. }, {
  2364. .chip = {
  2365. .base = EXYNOS5_GPF0(0),
  2366. .ngpio = EXYNOS5_GPIO_F0_NR,
  2367. .label = "GPF0",
  2368. },
  2369. }, {
  2370. .chip = {
  2371. .base = EXYNOS5_GPF1(0),
  2372. .ngpio = EXYNOS5_GPIO_F1_NR,
  2373. .label = "GPF1",
  2374. },
  2375. }, {
  2376. .chip = {
  2377. .base = EXYNOS5_GPG0(0),
  2378. .ngpio = EXYNOS5_GPIO_G0_NR,
  2379. .label = "GPG0",
  2380. },
  2381. }, {
  2382. .chip = {
  2383. .base = EXYNOS5_GPG1(0),
  2384. .ngpio = EXYNOS5_GPIO_G1_NR,
  2385. .label = "GPG1",
  2386. },
  2387. }, {
  2388. .chip = {
  2389. .base = EXYNOS5_GPG2(0),
  2390. .ngpio = EXYNOS5_GPIO_G2_NR,
  2391. .label = "GPG2",
  2392. },
  2393. }, {
  2394. .chip = {
  2395. .base = EXYNOS5_GPH0(0),
  2396. .ngpio = EXYNOS5_GPIO_H0_NR,
  2397. .label = "GPH0",
  2398. },
  2399. }, {
  2400. .chip = {
  2401. .base = EXYNOS5_GPH1(0),
  2402. .ngpio = EXYNOS5_GPIO_H1_NR,
  2403. .label = "GPH1",
  2404. },
  2405. },
  2406. };
  2407. #endif
  2408. #ifdef CONFIG_SOC_EXYNOS5250
  2409. static struct samsung_gpio_chip exynos5_gpios_3[] = {
  2410. {
  2411. .chip = {
  2412. .base = EXYNOS5_GPV0(0),
  2413. .ngpio = EXYNOS5_GPIO_V0_NR,
  2414. .label = "GPV0",
  2415. },
  2416. }, {
  2417. .chip = {
  2418. .base = EXYNOS5_GPV1(0),
  2419. .ngpio = EXYNOS5_GPIO_V1_NR,
  2420. .label = "GPV1",
  2421. },
  2422. }, {
  2423. .chip = {
  2424. .base = EXYNOS5_GPV2(0),
  2425. .ngpio = EXYNOS5_GPIO_V2_NR,
  2426. .label = "GPV2",
  2427. },
  2428. }, {
  2429. .chip = {
  2430. .base = EXYNOS5_GPV3(0),
  2431. .ngpio = EXYNOS5_GPIO_V3_NR,
  2432. .label = "GPV3",
  2433. },
  2434. }, {
  2435. .chip = {
  2436. .base = EXYNOS5_GPV4(0),
  2437. .ngpio = EXYNOS5_GPIO_V4_NR,
  2438. .label = "GPV4",
  2439. },
  2440. },
  2441. };
  2442. #endif
  2443. #ifdef CONFIG_SOC_EXYNOS5250
  2444. static struct samsung_gpio_chip exynos5_gpios_4[] = {
  2445. {
  2446. .chip = {
  2447. .base = EXYNOS5_GPZ(0),
  2448. .ngpio = EXYNOS5_GPIO_Z_NR,
  2449. .label = "GPZ",
  2450. },
  2451. },
  2452. };
  2453. #endif
  2454. #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
  2455. static int exynos_gpio_xlate(struct gpio_chip *gc,
  2456. const struct of_phandle_args *gpiospec, u32 *flags)
  2457. {
  2458. unsigned int pin;
  2459. if (WARN_ON(gc->of_gpio_n_cells < 4))
  2460. return -EINVAL;
  2461. if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
  2462. return -EINVAL;
  2463. if (gpiospec->args[0] > gc->ngpio)
  2464. return -EINVAL;
  2465. pin = gc->base + gpiospec->args[0];
  2466. if (s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(gpiospec->args[1])))
  2467. pr_warn("gpio_xlate: failed to set pin function\n");
  2468. if (s3c_gpio_setpull(pin, gpiospec->args[2] & 0xffff))
  2469. pr_warn("gpio_xlate: failed to set pin pull up/down\n");
  2470. if (s5p_gpio_set_drvstr(pin, gpiospec->args[3]))
  2471. pr_warn("gpio_xlate: failed to set pin drive strength\n");
  2472. if (flags)
  2473. *flags = gpiospec->args[2] >> 16;
  2474. return gpiospec->args[0];
  2475. }
  2476. static const struct of_device_id exynos_gpio_dt_match[] __initdata = {
  2477. { .compatible = "samsung,exynos4-gpio", },
  2478. {}
  2479. };
  2480. static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2481. u64 base, u64 offset)
  2482. {
  2483. struct gpio_chip *gc = &chip->chip;
  2484. u64 address;
  2485. if (!of_have_populated_dt())
  2486. return;
  2487. address = chip->base ? base + ((u32)chip->base & 0xfff) : base + offset;
  2488. gc->of_node = of_find_matching_node_by_address(NULL,
  2489. exynos_gpio_dt_match, address);
  2490. if (!gc->of_node) {
  2491. pr_info("gpio: device tree node not found for gpio controller"
  2492. " with base address %08llx\n", address);
  2493. return;
  2494. }
  2495. gc->of_gpio_n_cells = 4;
  2496. gc->of_xlate = exynos_gpio_xlate;
  2497. }
  2498. #elif defined(CONFIG_ARCH_EXYNOS)
  2499. static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2500. u64 base, u64 offset)
  2501. {
  2502. return;
  2503. }
  2504. #endif /* defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) */
  2505. static __init void exynos4_gpiolib_init(void)
  2506. {
  2507. #ifdef CONFIG_CPU_EXYNOS4210
  2508. struct samsung_gpio_chip *chip;
  2509. int i, nr_chips;
  2510. void __iomem *gpio_base1, *gpio_base2, *gpio_base3;
  2511. int group = 0;
  2512. void __iomem *gpx_base;
  2513. /* gpio part1 */
  2514. gpio_base1 = ioremap(EXYNOS4_PA_GPIO1, SZ_4K);
  2515. if (gpio_base1 == NULL) {
  2516. pr_err("unable to ioremap for gpio_base1\n");
  2517. goto err_ioremap1;
  2518. }
  2519. chip = exynos4_gpios_1;
  2520. nr_chips = ARRAY_SIZE(exynos4_gpios_1);
  2521. for (i = 0; i < nr_chips; i++, chip++) {
  2522. if (!chip->config) {
  2523. chip->config = &exynos_gpio_cfg;
  2524. chip->group = group++;
  2525. }
  2526. exynos_gpiolib_attach_ofnode(chip,
  2527. EXYNOS4_PA_GPIO1, i * 0x20);
  2528. }
  2529. samsung_gpiolib_add_4bit_chips(exynos4_gpios_1,
  2530. nr_chips, gpio_base1);
  2531. /* gpio part2 */
  2532. gpio_base2 = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  2533. if (gpio_base2 == NULL) {
  2534. pr_err("unable to ioremap for gpio_base2\n");
  2535. goto err_ioremap2;
  2536. }
  2537. /* need to set base address for gpx */
  2538. chip = &exynos4_gpios_2[16];
  2539. gpx_base = gpio_base2 + 0xC00;
  2540. for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
  2541. chip->base = gpx_base;
  2542. chip = exynos4_gpios_2;
  2543. nr_chips = ARRAY_SIZE(exynos4_gpios_2);
  2544. for (i = 0; i < nr_chips; i++, chip++) {
  2545. if (!chip->config) {
  2546. chip->config = &exynos_gpio_cfg;
  2547. chip->group = group++;
  2548. }
  2549. exynos_gpiolib_attach_ofnode(chip,
  2550. EXYNOS4_PA_GPIO2, i * 0x20);
  2551. }
  2552. samsung_gpiolib_add_4bit_chips(exynos4_gpios_2,
  2553. nr_chips, gpio_base2);
  2554. /* gpio part3 */
  2555. gpio_base3 = ioremap(EXYNOS4_PA_GPIO3, SZ_256);
  2556. if (gpio_base3 == NULL) {
  2557. pr_err("unable to ioremap for gpio_base3\n");
  2558. goto err_ioremap3;
  2559. }
  2560. chip = exynos4_gpios_3;
  2561. nr_chips = ARRAY_SIZE(exynos4_gpios_3);
  2562. for (i = 0; i < nr_chips; i++, chip++) {
  2563. if (!chip->config) {
  2564. chip->config = &exynos_gpio_cfg;
  2565. chip->group = group++;
  2566. }
  2567. exynos_gpiolib_attach_ofnode(chip,
  2568. EXYNOS4_PA_GPIO3, i * 0x20);
  2569. }
  2570. samsung_gpiolib_add_4bit_chips(exynos4_gpios_3,
  2571. nr_chips, gpio_base3);
  2572. #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
  2573. s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
  2574. s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
  2575. #endif
  2576. return;
  2577. err_ioremap3:
  2578. iounmap(gpio_base2);
  2579. err_ioremap2:
  2580. iounmap(gpio_base1);
  2581. err_ioremap1:
  2582. return;
  2583. #endif /* CONFIG_CPU_EXYNOS4210 */
  2584. }
  2585. static __init void exynos5_gpiolib_init(void)
  2586. {
  2587. #ifdef CONFIG_SOC_EXYNOS5250
  2588. struct samsung_gpio_chip *chip;
  2589. int i, nr_chips;
  2590. void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4;
  2591. int group = 0;
  2592. void __iomem *gpx_base;
  2593. /* gpio part1 */
  2594. gpio_base1 = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  2595. if (gpio_base1 == NULL) {
  2596. pr_err("unable to ioremap for gpio_base1\n");
  2597. goto err_ioremap1;
  2598. }
  2599. /* need to set base address for gpc4 */
  2600. exynos5_gpios_1[20].base = gpio_base1 + 0x2E0;
  2601. /* need to set base address for gpx */
  2602. chip = &exynos5_gpios_1[21];
  2603. gpx_base = gpio_base1 + 0xC00;
  2604. for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
  2605. chip->base = gpx_base;
  2606. chip = exynos5_gpios_1;
  2607. nr_chips = ARRAY_SIZE(exynos5_gpios_1);
  2608. for (i = 0; i < nr_chips; i++, chip++) {
  2609. if (!chip->config) {
  2610. chip->config = &exynos_gpio_cfg;
  2611. chip->group = group++;
  2612. }
  2613. exynos_gpiolib_attach_ofnode(chip,
  2614. EXYNOS5_PA_GPIO1, i * 0x20);
  2615. }
  2616. samsung_gpiolib_add_4bit_chips(exynos5_gpios_1,
  2617. nr_chips, gpio_base1);
  2618. /* gpio part2 */
  2619. gpio_base2 = ioremap(EXYNOS5_PA_GPIO2, SZ_4K);
  2620. if (gpio_base2 == NULL) {
  2621. pr_err("unable to ioremap for gpio_base2\n");
  2622. goto err_ioremap2;
  2623. }
  2624. chip = exynos5_gpios_2;
  2625. nr_chips = ARRAY_SIZE(exynos5_gpios_2);
  2626. for (i = 0; i < nr_chips; i++, chip++) {
  2627. if (!chip->config) {
  2628. chip->config = &exynos_gpio_cfg;
  2629. chip->group = group++;
  2630. }
  2631. exynos_gpiolib_attach_ofnode(chip,
  2632. EXYNOS5_PA_GPIO2, i * 0x20);
  2633. }
  2634. samsung_gpiolib_add_4bit_chips(exynos5_gpios_2,
  2635. nr_chips, gpio_base2);
  2636. /* gpio part3 */
  2637. gpio_base3 = ioremap(EXYNOS5_PA_GPIO3, SZ_4K);
  2638. if (gpio_base3 == NULL) {
  2639. pr_err("unable to ioremap for gpio_base3\n");
  2640. goto err_ioremap3;
  2641. }
  2642. /* need to set base address for gpv */
  2643. exynos5_gpios_3[0].base = gpio_base3;
  2644. exynos5_gpios_3[1].base = gpio_base3 + 0x20;
  2645. exynos5_gpios_3[2].base = gpio_base3 + 0x60;
  2646. exynos5_gpios_3[3].base = gpio_base3 + 0x80;
  2647. exynos5_gpios_3[4].base = gpio_base3 + 0xC0;
  2648. chip = exynos5_gpios_3;
  2649. nr_chips = ARRAY_SIZE(exynos5_gpios_3);
  2650. for (i = 0; i < nr_chips; i++, chip++) {
  2651. if (!chip->config) {
  2652. chip->config = &exynos_gpio_cfg;
  2653. chip->group = group++;
  2654. }
  2655. exynos_gpiolib_attach_ofnode(chip,
  2656. EXYNOS5_PA_GPIO3, i * 0x20);
  2657. }
  2658. samsung_gpiolib_add_4bit_chips(exynos5_gpios_3,
  2659. nr_chips, gpio_base3);
  2660. /* gpio part4 */
  2661. gpio_base4 = ioremap(EXYNOS5_PA_GPIO4, SZ_4K);
  2662. if (gpio_base4 == NULL) {
  2663. pr_err("unable to ioremap for gpio_base4\n");
  2664. goto err_ioremap4;
  2665. }
  2666. chip = exynos5_gpios_4;
  2667. nr_chips = ARRAY_SIZE(exynos5_gpios_4);
  2668. for (i = 0; i < nr_chips; i++, chip++) {
  2669. if (!chip->config) {
  2670. chip->config = &exynos_gpio_cfg;
  2671. chip->group = group++;
  2672. }
  2673. exynos_gpiolib_attach_ofnode(chip,
  2674. EXYNOS5_PA_GPIO4, i * 0x20);
  2675. }
  2676. samsung_gpiolib_add_4bit_chips(exynos5_gpios_4,
  2677. nr_chips, gpio_base4);
  2678. return;
  2679. err_ioremap4:
  2680. iounmap(gpio_base3);
  2681. err_ioremap3:
  2682. iounmap(gpio_base2);
  2683. err_ioremap2:
  2684. iounmap(gpio_base1);
  2685. err_ioremap1:
  2686. return;
  2687. #endif /* CONFIG_SOC_EXYNOS5250 */
  2688. }
  2689. /* TODO: cleanup soc_is_* */
  2690. static __init int samsung_gpiolib_init(void)
  2691. {
  2692. struct samsung_gpio_chip *chip;
  2693. int i, nr_chips;
  2694. int group = 0;
  2695. #if defined(CONFIG_PINCTRL_EXYNOS) || defined(CONFIG_PINCTRL_EXYNOS5440)
  2696. /*
  2697. * This gpio driver includes support for device tree support and there
  2698. * are platforms using it. In order to maintain compatibility with those
  2699. * platforms, and to allow non-dt Exynos4210 platforms to use this
  2700. * gpiolib support, a check is added to find out if there is a active
  2701. * pin-controller driver support available. If it is available, this
  2702. * gpiolib support is ignored and the gpiolib support available in
  2703. * pin-controller driver is used. This is a temporary check and will go
  2704. * away when all of the Exynos4210 platforms have switched to using
  2705. * device tree and the pin-ctrl driver.
  2706. */
  2707. struct device_node *pctrl_np;
  2708. static const struct of_device_id exynos_pinctrl_ids[] = {
  2709. { .compatible = "samsung,s3c2412-pinctrl", },
  2710. { .compatible = "samsung,s3c2416-pinctrl", },
  2711. { .compatible = "samsung,s3c2440-pinctrl", },
  2712. { .compatible = "samsung,s3c2450-pinctrl", },
  2713. { .compatible = "samsung,exynos4210-pinctrl", },
  2714. { .compatible = "samsung,exynos4x12-pinctrl", },
  2715. { .compatible = "samsung,exynos5250-pinctrl", },
  2716. { .compatible = "samsung,exynos5440-pinctrl", },
  2717. { }
  2718. };
  2719. for_each_matching_node(pctrl_np, exynos_pinctrl_ids)
  2720. if (pctrl_np && of_device_is_available(pctrl_np))
  2721. return -ENODEV;
  2722. #endif
  2723. samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
  2724. if (soc_is_s3c24xx()) {
  2725. s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
  2726. ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
  2727. } else if (soc_is_s3c64xx()) {
  2728. samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
  2729. ARRAY_SIZE(s3c64xx_gpios_2bit),
  2730. S3C64XX_VA_GPIO + 0xE0, 0x20);
  2731. samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
  2732. ARRAY_SIZE(s3c64xx_gpios_4bit),
  2733. S3C64XX_VA_GPIO);
  2734. samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
  2735. ARRAY_SIZE(s3c64xx_gpios_4bit2));
  2736. } else if (soc_is_s5p6440()) {
  2737. samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
  2738. ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
  2739. samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
  2740. ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
  2741. samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
  2742. ARRAY_SIZE(s5p6440_gpios_4bit2));
  2743. s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
  2744. ARRAY_SIZE(s5p6440_gpios_rbank));
  2745. } else if (soc_is_s5p6450()) {
  2746. samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
  2747. ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
  2748. samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
  2749. ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
  2750. samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
  2751. ARRAY_SIZE(s5p6450_gpios_4bit2));
  2752. s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
  2753. ARRAY_SIZE(s5p6450_gpios_rbank));
  2754. } else if (soc_is_s5pc100()) {
  2755. group = 0;
  2756. chip = s5pc100_gpios_4bit;
  2757. nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
  2758. for (i = 0; i < nr_chips; i++, chip++) {
  2759. if (!chip->config) {
  2760. chip->config = &samsung_gpio_cfgs[3];
  2761. chip->group = group++;
  2762. }
  2763. }
  2764. samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2765. #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
  2766. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2767. #endif
  2768. } else if (soc_is_s5pv210()) {
  2769. group = 0;
  2770. chip = s5pv210_gpios_4bit;
  2771. nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
  2772. for (i = 0; i < nr_chips; i++, chip++) {
  2773. if (!chip->config) {
  2774. chip->config = &samsung_gpio_cfgs[3];
  2775. chip->group = group++;
  2776. }
  2777. }
  2778. samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2779. #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
  2780. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2781. #endif
  2782. } else if (soc_is_exynos4210()) {
  2783. exynos4_gpiolib_init();
  2784. } else if (soc_is_exynos5250()) {
  2785. exynos5_gpiolib_init();
  2786. } else {
  2787. WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
  2788. return -ENODEV;
  2789. }
  2790. return 0;
  2791. }
  2792. core_initcall(samsung_gpiolib_init);
  2793. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  2794. {
  2795. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2796. unsigned long flags;
  2797. int offset;
  2798. int ret;
  2799. if (!chip)
  2800. return -EINVAL;
  2801. offset = pin - chip->chip.base;
  2802. samsung_gpio_lock(chip, flags);
  2803. ret = samsung_gpio_do_setcfg(chip, offset, config);
  2804. samsung_gpio_unlock(chip, flags);
  2805. return ret;
  2806. }
  2807. EXPORT_SYMBOL(s3c_gpio_cfgpin);
  2808. int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  2809. unsigned int cfg)
  2810. {
  2811. int ret;
  2812. for (; nr > 0; nr--, start++) {
  2813. ret = s3c_gpio_cfgpin(start, cfg);
  2814. if (ret != 0)
  2815. return ret;
  2816. }
  2817. return 0;
  2818. }
  2819. EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
  2820. int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  2821. unsigned int cfg, samsung_gpio_pull_t pull)
  2822. {
  2823. int ret;
  2824. for (; nr > 0; nr--, start++) {
  2825. s3c_gpio_setpull(start, pull);
  2826. ret = s3c_gpio_cfgpin(start, cfg);
  2827. if (ret != 0)
  2828. return ret;
  2829. }
  2830. return 0;
  2831. }
  2832. EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
  2833. unsigned s3c_gpio_getcfg(unsigned int pin)
  2834. {
  2835. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2836. unsigned long flags;
  2837. unsigned ret = 0;
  2838. int offset;
  2839. if (chip) {
  2840. offset = pin - chip->chip.base;
  2841. samsung_gpio_lock(chip, flags);
  2842. ret = samsung_gpio_do_getcfg(chip, offset);
  2843. samsung_gpio_unlock(chip, flags);
  2844. }
  2845. return ret;
  2846. }
  2847. EXPORT_SYMBOL(s3c_gpio_getcfg);
  2848. int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
  2849. {
  2850. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2851. unsigned long flags;
  2852. int offset, ret;
  2853. if (!chip)
  2854. return -EINVAL;
  2855. offset = pin - chip->chip.base;
  2856. samsung_gpio_lock(chip, flags);
  2857. ret = samsung_gpio_do_setpull(chip, offset, pull);
  2858. samsung_gpio_unlock(chip, flags);
  2859. return ret;
  2860. }
  2861. EXPORT_SYMBOL(s3c_gpio_setpull);
  2862. samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
  2863. {
  2864. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2865. unsigned long flags;
  2866. int offset;
  2867. u32 pup = 0;
  2868. if (chip) {
  2869. offset = pin - chip->chip.base;
  2870. samsung_gpio_lock(chip, flags);
  2871. pup = samsung_gpio_do_getpull(chip, offset);
  2872. samsung_gpio_unlock(chip, flags);
  2873. }
  2874. return (__force samsung_gpio_pull_t)pup;
  2875. }
  2876. EXPORT_SYMBOL(s3c_gpio_getpull);
  2877. #ifdef CONFIG_S5P_GPIO_DRVSTR
  2878. s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
  2879. {
  2880. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2881. unsigned int off;
  2882. void __iomem *reg;
  2883. int shift;
  2884. u32 drvstr;
  2885. if (!chip)
  2886. return -EINVAL;
  2887. off = pin - chip->chip.base;
  2888. shift = off * 2;
  2889. reg = chip->base + 0x0C;
  2890. drvstr = __raw_readl(reg);
  2891. drvstr = drvstr >> shift;
  2892. drvstr &= 0x3;
  2893. return (__force s5p_gpio_drvstr_t)drvstr;
  2894. }
  2895. EXPORT_SYMBOL(s5p_gpio_get_drvstr);
  2896. int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
  2897. {
  2898. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2899. unsigned int off;
  2900. void __iomem *reg;
  2901. int shift;
  2902. u32 tmp;
  2903. if (!chip)
  2904. return -EINVAL;
  2905. off = pin - chip->chip.base;
  2906. shift = off * 2;
  2907. reg = chip->base + 0x0C;
  2908. tmp = __raw_readl(reg);
  2909. tmp &= ~(0x3 << shift);
  2910. tmp |= drvstr << shift;
  2911. __raw_writel(tmp, reg);
  2912. return 0;
  2913. }
  2914. EXPORT_SYMBOL(s5p_gpio_set_drvstr);
  2915. #endif /* CONFIG_S5P_GPIO_DRVSTR */
  2916. #ifdef CONFIG_PLAT_S3C24XX
  2917. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  2918. {
  2919. unsigned long flags;
  2920. unsigned long misccr;
  2921. local_irq_save(flags);
  2922. misccr = __raw_readl(S3C24XX_MISCCR);
  2923. misccr &= ~clear;
  2924. misccr ^= change;
  2925. __raw_writel(misccr, S3C24XX_MISCCR);
  2926. local_irq_restore(flags);
  2927. return misccr;
  2928. }
  2929. EXPORT_SYMBOL(s3c2410_modify_misccr);
  2930. #endif