gpio-samsung.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240
  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_GPC4(0),
  2252. .ngpio = EXYNOS5_GPIO_C4_NR,
  2253. .label = "GPC4",
  2254. },
  2255. }, {
  2256. .chip = {
  2257. .base = EXYNOS5_GPD0(0),
  2258. .ngpio = EXYNOS5_GPIO_D0_NR,
  2259. .label = "GPD0",
  2260. },
  2261. }, {
  2262. .chip = {
  2263. .base = EXYNOS5_GPD1(0),
  2264. .ngpio = EXYNOS5_GPIO_D1_NR,
  2265. .label = "GPD1",
  2266. },
  2267. }, {
  2268. .chip = {
  2269. .base = EXYNOS5_GPY0(0),
  2270. .ngpio = EXYNOS5_GPIO_Y0_NR,
  2271. .label = "GPY0",
  2272. },
  2273. }, {
  2274. .chip = {
  2275. .base = EXYNOS5_GPY1(0),
  2276. .ngpio = EXYNOS5_GPIO_Y1_NR,
  2277. .label = "GPY1",
  2278. },
  2279. }, {
  2280. .chip = {
  2281. .base = EXYNOS5_GPY2(0),
  2282. .ngpio = EXYNOS5_GPIO_Y2_NR,
  2283. .label = "GPY2",
  2284. },
  2285. }, {
  2286. .chip = {
  2287. .base = EXYNOS5_GPY3(0),
  2288. .ngpio = EXYNOS5_GPIO_Y3_NR,
  2289. .label = "GPY3",
  2290. },
  2291. }, {
  2292. .chip = {
  2293. .base = EXYNOS5_GPY4(0),
  2294. .ngpio = EXYNOS5_GPIO_Y4_NR,
  2295. .label = "GPY4",
  2296. },
  2297. }, {
  2298. .chip = {
  2299. .base = EXYNOS5_GPY5(0),
  2300. .ngpio = EXYNOS5_GPIO_Y5_NR,
  2301. .label = "GPY5",
  2302. },
  2303. }, {
  2304. .chip = {
  2305. .base = EXYNOS5_GPY6(0),
  2306. .ngpio = EXYNOS5_GPIO_Y6_NR,
  2307. .label = "GPY6",
  2308. },
  2309. }, {
  2310. .config = &samsung_gpio_cfgs[9],
  2311. .irq_base = IRQ_EINT(0),
  2312. .chip = {
  2313. .base = EXYNOS5_GPX0(0),
  2314. .ngpio = EXYNOS5_GPIO_X0_NR,
  2315. .label = "GPX0",
  2316. .to_irq = samsung_gpiolib_to_irq,
  2317. },
  2318. }, {
  2319. .config = &samsung_gpio_cfgs[9],
  2320. .irq_base = IRQ_EINT(8),
  2321. .chip = {
  2322. .base = EXYNOS5_GPX1(0),
  2323. .ngpio = EXYNOS5_GPIO_X1_NR,
  2324. .label = "GPX1",
  2325. .to_irq = samsung_gpiolib_to_irq,
  2326. },
  2327. }, {
  2328. .config = &samsung_gpio_cfgs[9],
  2329. .irq_base = IRQ_EINT(16),
  2330. .chip = {
  2331. .base = EXYNOS5_GPX2(0),
  2332. .ngpio = EXYNOS5_GPIO_X2_NR,
  2333. .label = "GPX2",
  2334. .to_irq = samsung_gpiolib_to_irq,
  2335. },
  2336. }, {
  2337. .config = &samsung_gpio_cfgs[9],
  2338. .irq_base = IRQ_EINT(24),
  2339. .chip = {
  2340. .base = EXYNOS5_GPX3(0),
  2341. .ngpio = EXYNOS5_GPIO_X3_NR,
  2342. .label = "GPX3",
  2343. .to_irq = samsung_gpiolib_to_irq,
  2344. },
  2345. },
  2346. };
  2347. #endif
  2348. #ifdef CONFIG_ARCH_EXYNOS5
  2349. static struct samsung_gpio_chip exynos5_gpios_2[] = {
  2350. {
  2351. .chip = {
  2352. .base = EXYNOS5_GPE0(0),
  2353. .ngpio = EXYNOS5_GPIO_E0_NR,
  2354. .label = "GPE0",
  2355. },
  2356. }, {
  2357. .chip = {
  2358. .base = EXYNOS5_GPE1(0),
  2359. .ngpio = EXYNOS5_GPIO_E1_NR,
  2360. .label = "GPE1",
  2361. },
  2362. }, {
  2363. .chip = {
  2364. .base = EXYNOS5_GPF0(0),
  2365. .ngpio = EXYNOS5_GPIO_F0_NR,
  2366. .label = "GPF0",
  2367. },
  2368. }, {
  2369. .chip = {
  2370. .base = EXYNOS5_GPF1(0),
  2371. .ngpio = EXYNOS5_GPIO_F1_NR,
  2372. .label = "GPF1",
  2373. },
  2374. }, {
  2375. .chip = {
  2376. .base = EXYNOS5_GPG0(0),
  2377. .ngpio = EXYNOS5_GPIO_G0_NR,
  2378. .label = "GPG0",
  2379. },
  2380. }, {
  2381. .chip = {
  2382. .base = EXYNOS5_GPG1(0),
  2383. .ngpio = EXYNOS5_GPIO_G1_NR,
  2384. .label = "GPG1",
  2385. },
  2386. }, {
  2387. .chip = {
  2388. .base = EXYNOS5_GPG2(0),
  2389. .ngpio = EXYNOS5_GPIO_G2_NR,
  2390. .label = "GPG2",
  2391. },
  2392. }, {
  2393. .chip = {
  2394. .base = EXYNOS5_GPH0(0),
  2395. .ngpio = EXYNOS5_GPIO_H0_NR,
  2396. .label = "GPH0",
  2397. },
  2398. }, {
  2399. .chip = {
  2400. .base = EXYNOS5_GPH1(0),
  2401. .ngpio = EXYNOS5_GPIO_H1_NR,
  2402. .label = "GPH1",
  2403. },
  2404. },
  2405. };
  2406. #endif
  2407. #ifdef CONFIG_ARCH_EXYNOS5
  2408. static struct samsung_gpio_chip exynos5_gpios_3[] = {
  2409. {
  2410. .chip = {
  2411. .base = EXYNOS5_GPV0(0),
  2412. .ngpio = EXYNOS5_GPIO_V0_NR,
  2413. .label = "GPV0",
  2414. },
  2415. }, {
  2416. .chip = {
  2417. .base = EXYNOS5_GPV1(0),
  2418. .ngpio = EXYNOS5_GPIO_V1_NR,
  2419. .label = "GPV1",
  2420. },
  2421. }, {
  2422. .chip = {
  2423. .base = EXYNOS5_GPV2(0),
  2424. .ngpio = EXYNOS5_GPIO_V2_NR,
  2425. .label = "GPV2",
  2426. },
  2427. }, {
  2428. .chip = {
  2429. .base = EXYNOS5_GPV3(0),
  2430. .ngpio = EXYNOS5_GPIO_V3_NR,
  2431. .label = "GPV3",
  2432. },
  2433. }, {
  2434. .chip = {
  2435. .base = EXYNOS5_GPV4(0),
  2436. .ngpio = EXYNOS5_GPIO_V4_NR,
  2437. .label = "GPV4",
  2438. },
  2439. },
  2440. };
  2441. #endif
  2442. #ifdef CONFIG_ARCH_EXYNOS5
  2443. static struct samsung_gpio_chip exynos5_gpios_4[] = {
  2444. {
  2445. .chip = {
  2446. .base = EXYNOS5_GPZ(0),
  2447. .ngpio = EXYNOS5_GPIO_Z_NR,
  2448. .label = "GPZ",
  2449. },
  2450. },
  2451. };
  2452. #endif
  2453. #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
  2454. static int exynos_gpio_xlate(struct gpio_chip *gc,
  2455. const struct of_phandle_args *gpiospec, u32 *flags)
  2456. {
  2457. unsigned int pin;
  2458. if (WARN_ON(gc->of_gpio_n_cells < 4))
  2459. return -EINVAL;
  2460. if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
  2461. return -EINVAL;
  2462. if (gpiospec->args[0] > gc->ngpio)
  2463. return -EINVAL;
  2464. pin = gc->base + gpiospec->args[0];
  2465. if (s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(gpiospec->args[1])))
  2466. pr_warn("gpio_xlate: failed to set pin function\n");
  2467. if (s3c_gpio_setpull(pin, gpiospec->args[2] & 0xffff))
  2468. pr_warn("gpio_xlate: failed to set pin pull up/down\n");
  2469. if (s5p_gpio_set_drvstr(pin, gpiospec->args[3]))
  2470. pr_warn("gpio_xlate: failed to set pin drive strength\n");
  2471. if (flags)
  2472. *flags = gpiospec->args[2] >> 16;
  2473. return gpiospec->args[0];
  2474. }
  2475. static const struct of_device_id exynos_gpio_dt_match[] __initdata = {
  2476. { .compatible = "samsung,exynos4-gpio", },
  2477. {}
  2478. };
  2479. static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2480. u64 base, u64 offset)
  2481. {
  2482. struct gpio_chip *gc = &chip->chip;
  2483. u64 address;
  2484. if (!of_have_populated_dt())
  2485. return;
  2486. address = chip->base ? base + ((u32)chip->base & 0xfff) : base + offset;
  2487. gc->of_node = of_find_matching_node_by_address(NULL,
  2488. exynos_gpio_dt_match, address);
  2489. if (!gc->of_node) {
  2490. pr_info("gpio: device tree node not found for gpio controller"
  2491. " with base address %08llx\n", address);
  2492. return;
  2493. }
  2494. gc->of_gpio_n_cells = 4;
  2495. gc->of_xlate = exynos_gpio_xlate;
  2496. }
  2497. #elif defined(CONFIG_ARCH_EXYNOS)
  2498. static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2499. u64 base, u64 offset)
  2500. {
  2501. return;
  2502. }
  2503. #endif /* defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) */
  2504. static __init void exynos4_gpiolib_init(void)
  2505. {
  2506. #ifdef CONFIG_CPU_EXYNOS4210
  2507. struct samsung_gpio_chip *chip;
  2508. int i, nr_chips;
  2509. void __iomem *gpio_base1, *gpio_base2, *gpio_base3;
  2510. int group = 0;
  2511. void __iomem *gpx_base;
  2512. /* gpio part1 */
  2513. gpio_base1 = ioremap(EXYNOS4_PA_GPIO1, SZ_4K);
  2514. if (gpio_base1 == NULL) {
  2515. pr_err("unable to ioremap for gpio_base1\n");
  2516. goto err_ioremap1;
  2517. }
  2518. chip = exynos4_gpios_1;
  2519. nr_chips = ARRAY_SIZE(exynos4_gpios_1);
  2520. for (i = 0; i < nr_chips; i++, chip++) {
  2521. if (!chip->config) {
  2522. chip->config = &exynos_gpio_cfg;
  2523. chip->group = group++;
  2524. }
  2525. exynos_gpiolib_attach_ofnode(chip,
  2526. EXYNOS4_PA_GPIO1, i * 0x20);
  2527. }
  2528. samsung_gpiolib_add_4bit_chips(exynos4_gpios_1,
  2529. nr_chips, gpio_base1);
  2530. /* gpio part2 */
  2531. gpio_base2 = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  2532. if (gpio_base2 == NULL) {
  2533. pr_err("unable to ioremap for gpio_base2\n");
  2534. goto err_ioremap2;
  2535. }
  2536. /* need to set base address for gpx */
  2537. chip = &exynos4_gpios_2[16];
  2538. gpx_base = gpio_base2 + 0xC00;
  2539. for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
  2540. chip->base = gpx_base;
  2541. chip = exynos4_gpios_2;
  2542. nr_chips = ARRAY_SIZE(exynos4_gpios_2);
  2543. for (i = 0; i < nr_chips; i++, chip++) {
  2544. if (!chip->config) {
  2545. chip->config = &exynos_gpio_cfg;
  2546. chip->group = group++;
  2547. }
  2548. exynos_gpiolib_attach_ofnode(chip,
  2549. EXYNOS4_PA_GPIO2, i * 0x20);
  2550. }
  2551. samsung_gpiolib_add_4bit_chips(exynos4_gpios_2,
  2552. nr_chips, gpio_base2);
  2553. /* gpio part3 */
  2554. gpio_base3 = ioremap(EXYNOS4_PA_GPIO3, SZ_256);
  2555. if (gpio_base3 == NULL) {
  2556. pr_err("unable to ioremap for gpio_base3\n");
  2557. goto err_ioremap3;
  2558. }
  2559. chip = exynos4_gpios_3;
  2560. nr_chips = ARRAY_SIZE(exynos4_gpios_3);
  2561. for (i = 0; i < nr_chips; i++, chip++) {
  2562. if (!chip->config) {
  2563. chip->config = &exynos_gpio_cfg;
  2564. chip->group = group++;
  2565. }
  2566. exynos_gpiolib_attach_ofnode(chip,
  2567. EXYNOS4_PA_GPIO3, i * 0x20);
  2568. }
  2569. samsung_gpiolib_add_4bit_chips(exynos4_gpios_3,
  2570. nr_chips, gpio_base3);
  2571. #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
  2572. s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
  2573. s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
  2574. #endif
  2575. return;
  2576. err_ioremap3:
  2577. iounmap(gpio_base2);
  2578. err_ioremap2:
  2579. iounmap(gpio_base1);
  2580. err_ioremap1:
  2581. return;
  2582. #endif /* CONFIG_CPU_EXYNOS4210 */
  2583. }
  2584. static __init void exynos5_gpiolib_init(void)
  2585. {
  2586. #ifdef CONFIG_SOC_EXYNOS5250
  2587. struct samsung_gpio_chip *chip;
  2588. int i, nr_chips;
  2589. void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4;
  2590. int group = 0;
  2591. void __iomem *gpx_base;
  2592. /* gpio part1 */
  2593. gpio_base1 = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  2594. if (gpio_base1 == NULL) {
  2595. pr_err("unable to ioremap for gpio_base1\n");
  2596. goto err_ioremap1;
  2597. }
  2598. /* need to set base address for gpc4 */
  2599. exynos5_gpios_1[11].base = gpio_base1 + 0x2E0;
  2600. /* need to set base address for gpx */
  2601. chip = &exynos5_gpios_1[21];
  2602. gpx_base = gpio_base1 + 0xC00;
  2603. for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
  2604. chip->base = gpx_base;
  2605. chip = exynos5_gpios_1;
  2606. nr_chips = ARRAY_SIZE(exynos5_gpios_1);
  2607. for (i = 0; i < nr_chips; i++, chip++) {
  2608. if (!chip->config) {
  2609. chip->config = &exynos_gpio_cfg;
  2610. chip->group = group++;
  2611. }
  2612. exynos_gpiolib_attach_ofnode(chip,
  2613. EXYNOS5_PA_GPIO1, i * 0x20);
  2614. }
  2615. samsung_gpiolib_add_4bit_chips(exynos5_gpios_1,
  2616. nr_chips, gpio_base1);
  2617. /* gpio part2 */
  2618. gpio_base2 = ioremap(EXYNOS5_PA_GPIO2, SZ_4K);
  2619. if (gpio_base2 == NULL) {
  2620. pr_err("unable to ioremap for gpio_base2\n");
  2621. goto err_ioremap2;
  2622. }
  2623. chip = exynos5_gpios_2;
  2624. nr_chips = ARRAY_SIZE(exynos5_gpios_2);
  2625. for (i = 0; i < nr_chips; i++, chip++) {
  2626. if (!chip->config) {
  2627. chip->config = &exynos_gpio_cfg;
  2628. chip->group = group++;
  2629. }
  2630. exynos_gpiolib_attach_ofnode(chip,
  2631. EXYNOS5_PA_GPIO2, i * 0x20);
  2632. }
  2633. samsung_gpiolib_add_4bit_chips(exynos5_gpios_2,
  2634. nr_chips, gpio_base2);
  2635. /* gpio part3 */
  2636. gpio_base3 = ioremap(EXYNOS5_PA_GPIO3, SZ_4K);
  2637. if (gpio_base3 == NULL) {
  2638. pr_err("unable to ioremap for gpio_base3\n");
  2639. goto err_ioremap3;
  2640. }
  2641. /* need to set base address for gpv */
  2642. exynos5_gpios_3[0].base = gpio_base3;
  2643. exynos5_gpios_3[1].base = gpio_base3 + 0x20;
  2644. exynos5_gpios_3[2].base = gpio_base3 + 0x60;
  2645. exynos5_gpios_3[3].base = gpio_base3 + 0x80;
  2646. exynos5_gpios_3[4].base = gpio_base3 + 0xC0;
  2647. chip = exynos5_gpios_3;
  2648. nr_chips = ARRAY_SIZE(exynos5_gpios_3);
  2649. for (i = 0; i < nr_chips; i++, chip++) {
  2650. if (!chip->config) {
  2651. chip->config = &exynos_gpio_cfg;
  2652. chip->group = group++;
  2653. }
  2654. exynos_gpiolib_attach_ofnode(chip,
  2655. EXYNOS5_PA_GPIO3, i * 0x20);
  2656. }
  2657. samsung_gpiolib_add_4bit_chips(exynos5_gpios_3,
  2658. nr_chips, gpio_base3);
  2659. /* gpio part4 */
  2660. gpio_base4 = ioremap(EXYNOS5_PA_GPIO4, SZ_4K);
  2661. if (gpio_base4 == NULL) {
  2662. pr_err("unable to ioremap for gpio_base4\n");
  2663. goto err_ioremap4;
  2664. }
  2665. chip = exynos5_gpios_4;
  2666. nr_chips = ARRAY_SIZE(exynos5_gpios_4);
  2667. for (i = 0; i < nr_chips; i++, chip++) {
  2668. if (!chip->config) {
  2669. chip->config = &exynos_gpio_cfg;
  2670. chip->group = group++;
  2671. }
  2672. exynos_gpiolib_attach_ofnode(chip,
  2673. EXYNOS5_PA_GPIO4, i * 0x20);
  2674. }
  2675. samsung_gpiolib_add_4bit_chips(exynos5_gpios_4,
  2676. nr_chips, gpio_base4);
  2677. return;
  2678. err_ioremap4:
  2679. iounmap(gpio_base3);
  2680. err_ioremap3:
  2681. iounmap(gpio_base2);
  2682. err_ioremap2:
  2683. iounmap(gpio_base1);
  2684. err_ioremap1:
  2685. return;
  2686. #endif /* CONFIG_SOC_EXYNOS5250 */
  2687. }
  2688. /* TODO: cleanup soc_is_* */
  2689. static __init int samsung_gpiolib_init(void)
  2690. {
  2691. struct samsung_gpio_chip *chip;
  2692. int i, nr_chips;
  2693. int group = 0;
  2694. samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
  2695. if (soc_is_s3c24xx()) {
  2696. s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
  2697. ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
  2698. } else if (soc_is_s3c64xx()) {
  2699. samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
  2700. ARRAY_SIZE(s3c64xx_gpios_2bit),
  2701. S3C64XX_VA_GPIO + 0xE0, 0x20);
  2702. samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
  2703. ARRAY_SIZE(s3c64xx_gpios_4bit),
  2704. S3C64XX_VA_GPIO);
  2705. samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
  2706. ARRAY_SIZE(s3c64xx_gpios_4bit2));
  2707. } else if (soc_is_s5p6440()) {
  2708. samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
  2709. ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
  2710. samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
  2711. ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
  2712. samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
  2713. ARRAY_SIZE(s5p6440_gpios_4bit2));
  2714. s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
  2715. ARRAY_SIZE(s5p6440_gpios_rbank));
  2716. } else if (soc_is_s5p6450()) {
  2717. samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
  2718. ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
  2719. samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
  2720. ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
  2721. samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
  2722. ARRAY_SIZE(s5p6450_gpios_4bit2));
  2723. s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
  2724. ARRAY_SIZE(s5p6450_gpios_rbank));
  2725. } else if (soc_is_s5pc100()) {
  2726. group = 0;
  2727. chip = s5pc100_gpios_4bit;
  2728. nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
  2729. for (i = 0; i < nr_chips; i++, chip++) {
  2730. if (!chip->config) {
  2731. chip->config = &samsung_gpio_cfgs[3];
  2732. chip->group = group++;
  2733. }
  2734. }
  2735. samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2736. #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
  2737. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2738. #endif
  2739. } else if (soc_is_s5pv210()) {
  2740. group = 0;
  2741. chip = s5pv210_gpios_4bit;
  2742. nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
  2743. for (i = 0; i < nr_chips; i++, chip++) {
  2744. if (!chip->config) {
  2745. chip->config = &samsung_gpio_cfgs[3];
  2746. chip->group = group++;
  2747. }
  2748. }
  2749. samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2750. #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
  2751. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2752. #endif
  2753. } else if (soc_is_exynos4210()) {
  2754. exynos4_gpiolib_init();
  2755. } else if (soc_is_exynos5250()) {
  2756. exynos5_gpiolib_init();
  2757. } else {
  2758. WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
  2759. return -ENODEV;
  2760. }
  2761. return 0;
  2762. }
  2763. core_initcall(samsung_gpiolib_init);
  2764. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  2765. {
  2766. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2767. unsigned long flags;
  2768. int offset;
  2769. int ret;
  2770. if (!chip)
  2771. return -EINVAL;
  2772. offset = pin - chip->chip.base;
  2773. samsung_gpio_lock(chip, flags);
  2774. ret = samsung_gpio_do_setcfg(chip, offset, config);
  2775. samsung_gpio_unlock(chip, flags);
  2776. return ret;
  2777. }
  2778. EXPORT_SYMBOL(s3c_gpio_cfgpin);
  2779. int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  2780. unsigned int cfg)
  2781. {
  2782. int ret;
  2783. for (; nr > 0; nr--, start++) {
  2784. ret = s3c_gpio_cfgpin(start, cfg);
  2785. if (ret != 0)
  2786. return ret;
  2787. }
  2788. return 0;
  2789. }
  2790. EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
  2791. int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  2792. unsigned int cfg, samsung_gpio_pull_t pull)
  2793. {
  2794. int ret;
  2795. for (; nr > 0; nr--, start++) {
  2796. s3c_gpio_setpull(start, pull);
  2797. ret = s3c_gpio_cfgpin(start, cfg);
  2798. if (ret != 0)
  2799. return ret;
  2800. }
  2801. return 0;
  2802. }
  2803. EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
  2804. unsigned s3c_gpio_getcfg(unsigned int pin)
  2805. {
  2806. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2807. unsigned long flags;
  2808. unsigned ret = 0;
  2809. int offset;
  2810. if (chip) {
  2811. offset = pin - chip->chip.base;
  2812. samsung_gpio_lock(chip, flags);
  2813. ret = samsung_gpio_do_getcfg(chip, offset);
  2814. samsung_gpio_unlock(chip, flags);
  2815. }
  2816. return ret;
  2817. }
  2818. EXPORT_SYMBOL(s3c_gpio_getcfg);
  2819. int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
  2820. {
  2821. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2822. unsigned long flags;
  2823. int offset, ret;
  2824. if (!chip)
  2825. return -EINVAL;
  2826. offset = pin - chip->chip.base;
  2827. samsung_gpio_lock(chip, flags);
  2828. ret = samsung_gpio_do_setpull(chip, offset, pull);
  2829. samsung_gpio_unlock(chip, flags);
  2830. return ret;
  2831. }
  2832. EXPORT_SYMBOL(s3c_gpio_setpull);
  2833. samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
  2834. {
  2835. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2836. unsigned long flags;
  2837. int offset;
  2838. u32 pup = 0;
  2839. if (chip) {
  2840. offset = pin - chip->chip.base;
  2841. samsung_gpio_lock(chip, flags);
  2842. pup = samsung_gpio_do_getpull(chip, offset);
  2843. samsung_gpio_unlock(chip, flags);
  2844. }
  2845. return (__force samsung_gpio_pull_t)pup;
  2846. }
  2847. EXPORT_SYMBOL(s3c_gpio_getpull);
  2848. /* gpiolib wrappers until these are totally eliminated */
  2849. void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
  2850. {
  2851. int ret;
  2852. WARN_ON(to); /* should be none of these left */
  2853. if (!to) {
  2854. /* if pull is enabled, try first with up, and if that
  2855. * fails, try using down */
  2856. ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
  2857. if (ret)
  2858. s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
  2859. } else {
  2860. s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
  2861. }
  2862. }
  2863. EXPORT_SYMBOL(s3c2410_gpio_pullup);
  2864. void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
  2865. {
  2866. /* do this via gpiolib until all users removed */
  2867. gpio_request(pin, "temporary");
  2868. gpio_set_value(pin, to);
  2869. gpio_free(pin);
  2870. }
  2871. EXPORT_SYMBOL(s3c2410_gpio_setpin);
  2872. unsigned int s3c2410_gpio_getpin(unsigned int pin)
  2873. {
  2874. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2875. unsigned long offs = pin - chip->chip.base;
  2876. return __raw_readl(chip->base + 0x04) & (1 << offs);
  2877. }
  2878. EXPORT_SYMBOL(s3c2410_gpio_getpin);
  2879. #ifdef CONFIG_S5P_GPIO_DRVSTR
  2880. s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
  2881. {
  2882. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2883. unsigned int off;
  2884. void __iomem *reg;
  2885. int shift;
  2886. u32 drvstr;
  2887. if (!chip)
  2888. return -EINVAL;
  2889. off = pin - chip->chip.base;
  2890. shift = off * 2;
  2891. reg = chip->base + 0x0C;
  2892. drvstr = __raw_readl(reg);
  2893. drvstr = drvstr >> shift;
  2894. drvstr &= 0x3;
  2895. return (__force s5p_gpio_drvstr_t)drvstr;
  2896. }
  2897. EXPORT_SYMBOL(s5p_gpio_get_drvstr);
  2898. int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
  2899. {
  2900. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2901. unsigned int off;
  2902. void __iomem *reg;
  2903. int shift;
  2904. u32 tmp;
  2905. if (!chip)
  2906. return -EINVAL;
  2907. off = pin - chip->chip.base;
  2908. shift = off * 2;
  2909. reg = chip->base + 0x0C;
  2910. tmp = __raw_readl(reg);
  2911. tmp &= ~(0x3 << shift);
  2912. tmp |= drvstr << shift;
  2913. __raw_writel(tmp, reg);
  2914. return 0;
  2915. }
  2916. EXPORT_SYMBOL(s5p_gpio_set_drvstr);
  2917. #endif /* CONFIG_S5P_GPIO_DRVSTR */
  2918. #ifdef CONFIG_PLAT_S3C24XX
  2919. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  2920. {
  2921. unsigned long flags;
  2922. unsigned long misccr;
  2923. local_irq_save(flags);
  2924. misccr = __raw_readl(S3C24XX_MISCCR);
  2925. misccr &= ~clear;
  2926. misccr ^= change;
  2927. __raw_writel(misccr, S3C24XX_MISCCR);
  2928. local_irq_restore(flags);
  2929. return misccr;
  2930. }
  2931. EXPORT_SYMBOL(s3c2410_modify_misccr);
  2932. #endif