gpio-samsung.c 70 KB

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