gpio-samsung.c 68 KB

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