gpio-samsung.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796
  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 exynos4_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 exynos4_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. static struct samsung_gpio_cfg exynos4_gpio_cfg = {
  384. .set_pull = exynos4_gpio_setpull,
  385. .get_pull = exynos4_gpio_getpull,
  386. .set_config = samsung_gpio_setcfg_4bit,
  387. .get_config = samsung_gpio_getcfg_4bit,
  388. };
  389. #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
  390. static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = {
  391. .cfg_eint = 0x3,
  392. .set_config = s5p64x0_gpio_setcfg_rbank,
  393. .get_config = samsung_gpio_getcfg_4bit,
  394. .set_pull = samsung_gpio_setpull_updown,
  395. .get_pull = samsung_gpio_getpull_updown,
  396. };
  397. #endif
  398. static struct samsung_gpio_cfg samsung_gpio_cfgs[] = {
  399. [0] = {
  400. .cfg_eint = 0x0,
  401. },
  402. [1] = {
  403. .cfg_eint = 0x3,
  404. },
  405. [2] = {
  406. .cfg_eint = 0x7,
  407. },
  408. [3] = {
  409. .cfg_eint = 0xF,
  410. },
  411. [4] = {
  412. .cfg_eint = 0x0,
  413. .set_config = samsung_gpio_setcfg_2bit,
  414. .get_config = samsung_gpio_getcfg_2bit,
  415. },
  416. [5] = {
  417. .cfg_eint = 0x2,
  418. .set_config = samsung_gpio_setcfg_2bit,
  419. .get_config = samsung_gpio_getcfg_2bit,
  420. },
  421. [6] = {
  422. .cfg_eint = 0x3,
  423. .set_config = samsung_gpio_setcfg_2bit,
  424. .get_config = samsung_gpio_getcfg_2bit,
  425. },
  426. [7] = {
  427. .set_config = samsung_gpio_setcfg_2bit,
  428. .get_config = samsung_gpio_getcfg_2bit,
  429. },
  430. [8] = {
  431. .set_pull = exynos4_gpio_setpull,
  432. .get_pull = exynos4_gpio_getpull,
  433. },
  434. [9] = {
  435. .cfg_eint = 0x3,
  436. .set_pull = exynos4_gpio_setpull,
  437. .get_pull = exynos4_gpio_getpull,
  438. }
  439. };
  440. /*
  441. * Default routines for controlling GPIO, based on the original S3C24XX
  442. * GPIO functions which deal with the case where each gpio bank of the
  443. * chip is as following:
  444. *
  445. * base + 0x00: Control register, 2 bits per gpio
  446. * gpio n: 2 bits starting at (2*n)
  447. * 00 = input, 01 = output, others mean special-function
  448. * base + 0x04: Data register, 1 bit per gpio
  449. * bit n: data bit n
  450. */
  451. static int samsung_gpiolib_2bit_input(struct gpio_chip *chip, unsigned offset)
  452. {
  453. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  454. void __iomem *base = ourchip->base;
  455. unsigned long flags;
  456. unsigned long con;
  457. samsung_gpio_lock(ourchip, flags);
  458. con = __raw_readl(base + 0x00);
  459. con &= ~(3 << (offset * 2));
  460. __raw_writel(con, base + 0x00);
  461. samsung_gpio_unlock(ourchip, flags);
  462. return 0;
  463. }
  464. static int samsung_gpiolib_2bit_output(struct gpio_chip *chip,
  465. unsigned offset, int value)
  466. {
  467. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  468. void __iomem *base = ourchip->base;
  469. unsigned long flags;
  470. unsigned long dat;
  471. unsigned long con;
  472. samsung_gpio_lock(ourchip, flags);
  473. dat = __raw_readl(base + 0x04);
  474. dat &= ~(1 << offset);
  475. if (value)
  476. dat |= 1 << offset;
  477. __raw_writel(dat, base + 0x04);
  478. con = __raw_readl(base + 0x00);
  479. con &= ~(3 << (offset * 2));
  480. con |= 1 << (offset * 2);
  481. __raw_writel(con, base + 0x00);
  482. __raw_writel(dat, base + 0x04);
  483. samsung_gpio_unlock(ourchip, flags);
  484. return 0;
  485. }
  486. /*
  487. * The samsung_gpiolib_4bit routines are to control the gpio banks where
  488. * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
  489. * following example:
  490. *
  491. * base + 0x00: Control register, 4 bits per gpio
  492. * gpio n: 4 bits starting at (4*n)
  493. * 0000 = input, 0001 = output, others mean special-function
  494. * base + 0x04: Data register, 1 bit per gpio
  495. * bit n: data bit n
  496. *
  497. * Note, since the data register is one bit per gpio and is at base + 0x4
  498. * we can use samsung_gpiolib_get and samsung_gpiolib_set to change the
  499. * state of the output.
  500. */
  501. static int samsung_gpiolib_4bit_input(struct gpio_chip *chip,
  502. unsigned int offset)
  503. {
  504. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  505. void __iomem *base = ourchip->base;
  506. unsigned long con;
  507. con = __raw_readl(base + GPIOCON_OFF);
  508. con &= ~(0xf << con_4bit_shift(offset));
  509. __raw_writel(con, base + GPIOCON_OFF);
  510. gpio_dbg("%s: %p: CON now %08lx\n", __func__, base, con);
  511. return 0;
  512. }
  513. static int samsung_gpiolib_4bit_output(struct gpio_chip *chip,
  514. unsigned int offset, int value)
  515. {
  516. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  517. void __iomem *base = ourchip->base;
  518. unsigned long con;
  519. unsigned long dat;
  520. con = __raw_readl(base + GPIOCON_OFF);
  521. con &= ~(0xf << con_4bit_shift(offset));
  522. con |= 0x1 << con_4bit_shift(offset);
  523. dat = __raw_readl(base + GPIODAT_OFF);
  524. if (value)
  525. dat |= 1 << offset;
  526. else
  527. dat &= ~(1 << offset);
  528. __raw_writel(dat, base + GPIODAT_OFF);
  529. __raw_writel(con, base + GPIOCON_OFF);
  530. __raw_writel(dat, base + GPIODAT_OFF);
  531. gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
  532. return 0;
  533. }
  534. /*
  535. * The next set of routines are for the case where the GPIO configuration
  536. * registers are 4 bits per GPIO but there is more than one register (the
  537. * bank has more than 8 GPIOs.
  538. *
  539. * This case is the similar to the 4 bit case, but the registers are as
  540. * follows:
  541. *
  542. * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs)
  543. * gpio n: 4 bits starting at (4*n)
  544. * 0000 = input, 0001 = output, others mean special-function
  545. * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs)
  546. * gpio n: 4 bits starting at (4*n)
  547. * 0000 = input, 0001 = output, others mean special-function
  548. * base + 0x08: Data register, 1 bit per gpio
  549. * bit n: data bit n
  550. *
  551. * To allow us to use the samsung_gpiolib_get and samsung_gpiolib_set
  552. * routines we store the 'base + 0x4' address so that these routines see
  553. * the data register at ourchip->base + 0x04.
  554. */
  555. static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip,
  556. unsigned int offset)
  557. {
  558. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  559. void __iomem *base = ourchip->base;
  560. void __iomem *regcon = base;
  561. unsigned long con;
  562. if (offset > 7)
  563. offset -= 8;
  564. else
  565. regcon -= 4;
  566. con = __raw_readl(regcon);
  567. con &= ~(0xf << con_4bit_shift(offset));
  568. __raw_writel(con, regcon);
  569. gpio_dbg("%s: %p: CON %08lx\n", __func__, base, con);
  570. return 0;
  571. }
  572. static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip,
  573. unsigned int offset, int value)
  574. {
  575. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  576. void __iomem *base = ourchip->base;
  577. void __iomem *regcon = base;
  578. unsigned long con;
  579. unsigned long dat;
  580. unsigned con_offset = offset;
  581. if (con_offset > 7)
  582. con_offset -= 8;
  583. else
  584. regcon -= 4;
  585. con = __raw_readl(regcon);
  586. con &= ~(0xf << con_4bit_shift(con_offset));
  587. con |= 0x1 << con_4bit_shift(con_offset);
  588. dat = __raw_readl(base + GPIODAT_OFF);
  589. if (value)
  590. dat |= 1 << offset;
  591. else
  592. dat &= ~(1 << offset);
  593. __raw_writel(dat, base + GPIODAT_OFF);
  594. __raw_writel(con, regcon);
  595. __raw_writel(dat, base + GPIODAT_OFF);
  596. gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
  597. return 0;
  598. }
  599. #ifdef CONFIG_PLAT_S3C24XX
  600. /* The next set of routines are for the case of s3c24xx bank a */
  601. static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
  602. {
  603. return -EINVAL;
  604. }
  605. static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
  606. unsigned offset, int value)
  607. {
  608. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  609. void __iomem *base = ourchip->base;
  610. unsigned long flags;
  611. unsigned long dat;
  612. unsigned long con;
  613. local_irq_save(flags);
  614. con = __raw_readl(base + 0x00);
  615. dat = __raw_readl(base + 0x04);
  616. dat &= ~(1 << offset);
  617. if (value)
  618. dat |= 1 << offset;
  619. __raw_writel(dat, base + 0x04);
  620. con &= ~(1 << offset);
  621. __raw_writel(con, base + 0x00);
  622. __raw_writel(dat, base + 0x04);
  623. local_irq_restore(flags);
  624. return 0;
  625. }
  626. #endif
  627. /* The next set of routines are for the case of s5p64x0 bank r */
  628. static int s5p64x0_gpiolib_rbank_input(struct gpio_chip *chip,
  629. unsigned int offset)
  630. {
  631. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  632. void __iomem *base = ourchip->base;
  633. void __iomem *regcon = base;
  634. unsigned long con;
  635. unsigned long flags;
  636. switch (offset) {
  637. case 6:
  638. offset += 1;
  639. case 0:
  640. case 1:
  641. case 2:
  642. case 3:
  643. case 4:
  644. case 5:
  645. regcon -= 4;
  646. break;
  647. default:
  648. offset -= 7;
  649. break;
  650. }
  651. samsung_gpio_lock(ourchip, flags);
  652. con = __raw_readl(regcon);
  653. con &= ~(0xf << con_4bit_shift(offset));
  654. __raw_writel(con, regcon);
  655. samsung_gpio_unlock(ourchip, flags);
  656. return 0;
  657. }
  658. static int s5p64x0_gpiolib_rbank_output(struct gpio_chip *chip,
  659. unsigned int offset, int value)
  660. {
  661. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  662. void __iomem *base = ourchip->base;
  663. void __iomem *regcon = base;
  664. unsigned long con;
  665. unsigned long dat;
  666. unsigned long flags;
  667. unsigned con_offset = offset;
  668. switch (con_offset) {
  669. case 6:
  670. con_offset += 1;
  671. case 0:
  672. case 1:
  673. case 2:
  674. case 3:
  675. case 4:
  676. case 5:
  677. regcon -= 4;
  678. break;
  679. default:
  680. con_offset -= 7;
  681. break;
  682. }
  683. samsung_gpio_lock(ourchip, flags);
  684. con = __raw_readl(regcon);
  685. con &= ~(0xf << con_4bit_shift(con_offset));
  686. con |= 0x1 << con_4bit_shift(con_offset);
  687. dat = __raw_readl(base + GPIODAT_OFF);
  688. if (value)
  689. dat |= 1 << offset;
  690. else
  691. dat &= ~(1 << offset);
  692. __raw_writel(con, regcon);
  693. __raw_writel(dat, base + GPIODAT_OFF);
  694. samsung_gpio_unlock(ourchip, flags);
  695. return 0;
  696. }
  697. static void samsung_gpiolib_set(struct gpio_chip *chip,
  698. unsigned offset, int value)
  699. {
  700. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  701. void __iomem *base = ourchip->base;
  702. unsigned long flags;
  703. unsigned long dat;
  704. samsung_gpio_lock(ourchip, flags);
  705. dat = __raw_readl(base + 0x04);
  706. dat &= ~(1 << offset);
  707. if (value)
  708. dat |= 1 << offset;
  709. __raw_writel(dat, base + 0x04);
  710. samsung_gpio_unlock(ourchip, flags);
  711. }
  712. static int samsung_gpiolib_get(struct gpio_chip *chip, unsigned offset)
  713. {
  714. struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
  715. unsigned long val;
  716. val = __raw_readl(ourchip->base + 0x04);
  717. val >>= offset;
  718. val &= 1;
  719. return val;
  720. }
  721. /*
  722. * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
  723. * for use with the configuration calls, and other parts of the s3c gpiolib
  724. * support code.
  725. *
  726. * Not all s3c support code will need this, as some configurations of cpu
  727. * may only support one or two different configuration options and have an
  728. * easy gpio to samsung_gpio_chip mapping function. If this is the case, then
  729. * the machine support file should provide its own samsung_gpiolib_getchip()
  730. * and any other necessary functions.
  731. */
  732. #ifdef CONFIG_S3C_GPIO_TRACK
  733. struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
  734. static __init void s3c_gpiolib_track(struct samsung_gpio_chip *chip)
  735. {
  736. unsigned int gpn;
  737. int i;
  738. gpn = chip->chip.base;
  739. for (i = 0; i < chip->chip.ngpio; i++, gpn++) {
  740. BUG_ON(gpn >= ARRAY_SIZE(s3c_gpios));
  741. s3c_gpios[gpn] = chip;
  742. }
  743. }
  744. #endif /* CONFIG_S3C_GPIO_TRACK */
  745. /*
  746. * samsung_gpiolib_add() - add the Samsung gpio_chip.
  747. * @chip: The chip to register
  748. *
  749. * This is a wrapper to gpiochip_add() that takes our specific gpio chip
  750. * information and makes the necessary alterations for the platform and
  751. * notes the information for use with the configuration systems and any
  752. * other parts of the system.
  753. */
  754. static void __init samsung_gpiolib_add(struct samsung_gpio_chip *chip)
  755. {
  756. struct gpio_chip *gc = &chip->chip;
  757. int ret;
  758. BUG_ON(!chip->base);
  759. BUG_ON(!gc->label);
  760. BUG_ON(!gc->ngpio);
  761. spin_lock_init(&chip->lock);
  762. if (!gc->direction_input)
  763. gc->direction_input = samsung_gpiolib_2bit_input;
  764. if (!gc->direction_output)
  765. gc->direction_output = samsung_gpiolib_2bit_output;
  766. if (!gc->set)
  767. gc->set = samsung_gpiolib_set;
  768. if (!gc->get)
  769. gc->get = samsung_gpiolib_get;
  770. #ifdef CONFIG_PM
  771. if (chip->pm != NULL) {
  772. if (!chip->pm->save || !chip->pm->resume)
  773. printk(KERN_ERR "gpio: %s has missing PM functions\n",
  774. gc->label);
  775. } else
  776. printk(KERN_ERR "gpio: %s has no PM function\n", gc->label);
  777. #endif
  778. /* gpiochip_add() prints own failure message on error. */
  779. ret = gpiochip_add(gc);
  780. if (ret >= 0)
  781. s3c_gpiolib_track(chip);
  782. }
  783. static void __init s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip *chip,
  784. int nr_chips, void __iomem *base)
  785. {
  786. int i;
  787. struct gpio_chip *gc = &chip->chip;
  788. for (i = 0 ; i < nr_chips; i++, chip++) {
  789. /* skip banks not present on SoC */
  790. if (chip->chip.base >= S3C_GPIO_END)
  791. continue;
  792. if (!chip->config)
  793. chip->config = &s3c24xx_gpiocfg_default;
  794. if (!chip->pm)
  795. chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
  796. if ((base != NULL) && (chip->base == NULL))
  797. chip->base = base + ((i) * 0x10);
  798. if (!gc->direction_input)
  799. gc->direction_input = samsung_gpiolib_2bit_input;
  800. if (!gc->direction_output)
  801. gc->direction_output = samsung_gpiolib_2bit_output;
  802. samsung_gpiolib_add(chip);
  803. }
  804. }
  805. static void __init samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip *chip,
  806. int nr_chips, void __iomem *base,
  807. unsigned int offset)
  808. {
  809. int i;
  810. for (i = 0 ; i < nr_chips; i++, chip++) {
  811. chip->chip.direction_input = samsung_gpiolib_2bit_input;
  812. chip->chip.direction_output = samsung_gpiolib_2bit_output;
  813. if (!chip->config)
  814. chip->config = &samsung_gpio_cfgs[7];
  815. if (!chip->pm)
  816. chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
  817. if ((base != NULL) && (chip->base == NULL))
  818. chip->base = base + ((i) * offset);
  819. samsung_gpiolib_add(chip);
  820. }
  821. }
  822. /*
  823. * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
  824. * @chip: The gpio chip that is being configured.
  825. * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
  826. *
  827. * This helper deal with the GPIO cases where the control register has 4 bits
  828. * of control per GPIO, generally in the form of:
  829. * 0000 = Input
  830. * 0001 = Output
  831. * others = Special functions (dependent on bank)
  832. *
  833. * Note, since the code to deal with the case where there are two control
  834. * registers instead of one, we do not have a separate set of function
  835. * (samsung_gpiolib_add_4bit2_chips)for each case.
  836. */
  837. static void __init samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip *chip,
  838. int nr_chips, void __iomem *base)
  839. {
  840. int i;
  841. for (i = 0 ; i < nr_chips; i++, chip++) {
  842. chip->chip.direction_input = samsung_gpiolib_4bit_input;
  843. chip->chip.direction_output = samsung_gpiolib_4bit_output;
  844. if (!chip->config)
  845. chip->config = &samsung_gpio_cfgs[2];
  846. if (!chip->pm)
  847. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  848. if ((base != NULL) && (chip->base == NULL))
  849. chip->base = base + ((i) * 0x20);
  850. samsung_gpiolib_add(chip);
  851. }
  852. }
  853. static void __init samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip *chip,
  854. int nr_chips)
  855. {
  856. for (; nr_chips > 0; nr_chips--, chip++) {
  857. chip->chip.direction_input = samsung_gpiolib_4bit2_input;
  858. chip->chip.direction_output = samsung_gpiolib_4bit2_output;
  859. if (!chip->config)
  860. chip->config = &samsung_gpio_cfgs[2];
  861. if (!chip->pm)
  862. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  863. samsung_gpiolib_add(chip);
  864. }
  865. }
  866. static void __init s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip *chip,
  867. int nr_chips)
  868. {
  869. for (; nr_chips > 0; nr_chips--, chip++) {
  870. chip->chip.direction_input = s5p64x0_gpiolib_rbank_input;
  871. chip->chip.direction_output = s5p64x0_gpiolib_rbank_output;
  872. if (!chip->pm)
  873. chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
  874. samsung_gpiolib_add(chip);
  875. }
  876. }
  877. int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
  878. {
  879. struct samsung_gpio_chip *samsung_chip = container_of(chip, struct samsung_gpio_chip, chip);
  880. return samsung_chip->irq_base + offset;
  881. }
  882. #ifdef CONFIG_PLAT_S3C24XX
  883. static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset)
  884. {
  885. if (offset < 4)
  886. return IRQ_EINT0 + offset;
  887. if (offset < 8)
  888. return IRQ_EINT4 + offset - 4;
  889. return -EINVAL;
  890. }
  891. #endif
  892. #ifdef CONFIG_PLAT_S3C64XX
  893. static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin)
  894. {
  895. return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
  896. }
  897. static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin)
  898. {
  899. return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
  900. }
  901. #endif
  902. struct samsung_gpio_chip s3c24xx_gpios[] = {
  903. #ifdef CONFIG_PLAT_S3C24XX
  904. {
  905. .config = &s3c24xx_gpiocfg_banka,
  906. .chip = {
  907. .base = S3C2410_GPA(0),
  908. .owner = THIS_MODULE,
  909. .label = "GPIOA",
  910. .ngpio = 24,
  911. .direction_input = s3c24xx_gpiolib_banka_input,
  912. .direction_output = s3c24xx_gpiolib_banka_output,
  913. },
  914. }, {
  915. .chip = {
  916. .base = S3C2410_GPB(0),
  917. .owner = THIS_MODULE,
  918. .label = "GPIOB",
  919. .ngpio = 16,
  920. },
  921. }, {
  922. .chip = {
  923. .base = S3C2410_GPC(0),
  924. .owner = THIS_MODULE,
  925. .label = "GPIOC",
  926. .ngpio = 16,
  927. },
  928. }, {
  929. .chip = {
  930. .base = S3C2410_GPD(0),
  931. .owner = THIS_MODULE,
  932. .label = "GPIOD",
  933. .ngpio = 16,
  934. },
  935. }, {
  936. .chip = {
  937. .base = S3C2410_GPE(0),
  938. .label = "GPIOE",
  939. .owner = THIS_MODULE,
  940. .ngpio = 16,
  941. },
  942. }, {
  943. .chip = {
  944. .base = S3C2410_GPF(0),
  945. .owner = THIS_MODULE,
  946. .label = "GPIOF",
  947. .ngpio = 8,
  948. .to_irq = s3c24xx_gpiolib_fbank_to_irq,
  949. },
  950. }, {
  951. .irq_base = IRQ_EINT8,
  952. .chip = {
  953. .base = S3C2410_GPG(0),
  954. .owner = THIS_MODULE,
  955. .label = "GPIOG",
  956. .ngpio = 16,
  957. .to_irq = samsung_gpiolib_to_irq,
  958. },
  959. }, {
  960. .chip = {
  961. .base = S3C2410_GPH(0),
  962. .owner = THIS_MODULE,
  963. .label = "GPIOH",
  964. .ngpio = 11,
  965. },
  966. },
  967. /* GPIOS for the S3C2443 and later devices. */
  968. {
  969. .base = S3C2440_GPJCON,
  970. .chip = {
  971. .base = S3C2410_GPJ(0),
  972. .owner = THIS_MODULE,
  973. .label = "GPIOJ",
  974. .ngpio = 16,
  975. },
  976. }, {
  977. .base = S3C2443_GPKCON,
  978. .chip = {
  979. .base = S3C2410_GPK(0),
  980. .owner = THIS_MODULE,
  981. .label = "GPIOK",
  982. .ngpio = 16,
  983. },
  984. }, {
  985. .base = S3C2443_GPLCON,
  986. .chip = {
  987. .base = S3C2410_GPL(0),
  988. .owner = THIS_MODULE,
  989. .label = "GPIOL",
  990. .ngpio = 15,
  991. },
  992. }, {
  993. .base = S3C2443_GPMCON,
  994. .chip = {
  995. .base = S3C2410_GPM(0),
  996. .owner = THIS_MODULE,
  997. .label = "GPIOM",
  998. .ngpio = 2,
  999. },
  1000. },
  1001. #endif
  1002. };
  1003. /*
  1004. * GPIO bank summary:
  1005. *
  1006. * Bank GPIOs Style SlpCon ExtInt Group
  1007. * A 8 4Bit Yes 1
  1008. * B 7 4Bit Yes 1
  1009. * C 8 4Bit Yes 2
  1010. * D 5 4Bit Yes 3
  1011. * E 5 4Bit Yes None
  1012. * F 16 2Bit Yes 4 [1]
  1013. * G 7 4Bit Yes 5
  1014. * H 10 4Bit[2] Yes 6
  1015. * I 16 2Bit Yes None
  1016. * J 12 2Bit Yes None
  1017. * K 16 4Bit[2] No None
  1018. * L 15 4Bit[2] No None
  1019. * M 6 4Bit No IRQ_EINT
  1020. * N 16 2Bit No IRQ_EINT
  1021. * O 16 2Bit Yes 7
  1022. * P 15 2Bit Yes 8
  1023. * Q 9 2Bit Yes 9
  1024. *
  1025. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  1026. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  1027. */
  1028. static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = {
  1029. #ifdef CONFIG_PLAT_S3C64XX
  1030. {
  1031. .chip = {
  1032. .base = S3C64XX_GPA(0),
  1033. .ngpio = S3C64XX_GPIO_A_NR,
  1034. .label = "GPA",
  1035. },
  1036. }, {
  1037. .chip = {
  1038. .base = S3C64XX_GPB(0),
  1039. .ngpio = S3C64XX_GPIO_B_NR,
  1040. .label = "GPB",
  1041. },
  1042. }, {
  1043. .chip = {
  1044. .base = S3C64XX_GPC(0),
  1045. .ngpio = S3C64XX_GPIO_C_NR,
  1046. .label = "GPC",
  1047. },
  1048. }, {
  1049. .chip = {
  1050. .base = S3C64XX_GPD(0),
  1051. .ngpio = S3C64XX_GPIO_D_NR,
  1052. .label = "GPD",
  1053. },
  1054. }, {
  1055. .config = &samsung_gpio_cfgs[0],
  1056. .chip = {
  1057. .base = S3C64XX_GPE(0),
  1058. .ngpio = S3C64XX_GPIO_E_NR,
  1059. .label = "GPE",
  1060. },
  1061. }, {
  1062. .base = S3C64XX_GPG_BASE,
  1063. .chip = {
  1064. .base = S3C64XX_GPG(0),
  1065. .ngpio = S3C64XX_GPIO_G_NR,
  1066. .label = "GPG",
  1067. },
  1068. }, {
  1069. .base = S3C64XX_GPM_BASE,
  1070. .config = &samsung_gpio_cfgs[1],
  1071. .chip = {
  1072. .base = S3C64XX_GPM(0),
  1073. .ngpio = S3C64XX_GPIO_M_NR,
  1074. .label = "GPM",
  1075. .to_irq = s3c64xx_gpiolib_mbank_to_irq,
  1076. },
  1077. },
  1078. #endif
  1079. };
  1080. static struct samsung_gpio_chip s3c64xx_gpios_4bit2[] = {
  1081. #ifdef CONFIG_PLAT_S3C64XX
  1082. {
  1083. .base = S3C64XX_GPH_BASE + 0x4,
  1084. .chip = {
  1085. .base = S3C64XX_GPH(0),
  1086. .ngpio = S3C64XX_GPIO_H_NR,
  1087. .label = "GPH",
  1088. },
  1089. }, {
  1090. .base = S3C64XX_GPK_BASE + 0x4,
  1091. .config = &samsung_gpio_cfgs[0],
  1092. .chip = {
  1093. .base = S3C64XX_GPK(0),
  1094. .ngpio = S3C64XX_GPIO_K_NR,
  1095. .label = "GPK",
  1096. },
  1097. }, {
  1098. .base = S3C64XX_GPL_BASE + 0x4,
  1099. .config = &samsung_gpio_cfgs[1],
  1100. .chip = {
  1101. .base = S3C64XX_GPL(0),
  1102. .ngpio = S3C64XX_GPIO_L_NR,
  1103. .label = "GPL",
  1104. .to_irq = s3c64xx_gpiolib_lbank_to_irq,
  1105. },
  1106. },
  1107. #endif
  1108. };
  1109. static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = {
  1110. #ifdef CONFIG_PLAT_S3C64XX
  1111. {
  1112. .base = S3C64XX_GPF_BASE,
  1113. .config = &samsung_gpio_cfgs[6],
  1114. .chip = {
  1115. .base = S3C64XX_GPF(0),
  1116. .ngpio = S3C64XX_GPIO_F_NR,
  1117. .label = "GPF",
  1118. },
  1119. }, {
  1120. .config = &samsung_gpio_cfgs[7],
  1121. .chip = {
  1122. .base = S3C64XX_GPI(0),
  1123. .ngpio = S3C64XX_GPIO_I_NR,
  1124. .label = "GPI",
  1125. },
  1126. }, {
  1127. .config = &samsung_gpio_cfgs[7],
  1128. .chip = {
  1129. .base = S3C64XX_GPJ(0),
  1130. .ngpio = S3C64XX_GPIO_J_NR,
  1131. .label = "GPJ",
  1132. },
  1133. }, {
  1134. .config = &samsung_gpio_cfgs[6],
  1135. .chip = {
  1136. .base = S3C64XX_GPO(0),
  1137. .ngpio = S3C64XX_GPIO_O_NR,
  1138. .label = "GPO",
  1139. },
  1140. }, {
  1141. .config = &samsung_gpio_cfgs[6],
  1142. .chip = {
  1143. .base = S3C64XX_GPP(0),
  1144. .ngpio = S3C64XX_GPIO_P_NR,
  1145. .label = "GPP",
  1146. },
  1147. }, {
  1148. .config = &samsung_gpio_cfgs[6],
  1149. .chip = {
  1150. .base = S3C64XX_GPQ(0),
  1151. .ngpio = S3C64XX_GPIO_Q_NR,
  1152. .label = "GPQ",
  1153. },
  1154. }, {
  1155. .base = S3C64XX_GPN_BASE,
  1156. .irq_base = IRQ_EINT(0),
  1157. .config = &samsung_gpio_cfgs[5],
  1158. .chip = {
  1159. .base = S3C64XX_GPN(0),
  1160. .ngpio = S3C64XX_GPIO_N_NR,
  1161. .label = "GPN",
  1162. .to_irq = samsung_gpiolib_to_irq,
  1163. },
  1164. },
  1165. #endif
  1166. };
  1167. /*
  1168. * S5P6440 GPIO bank summary:
  1169. *
  1170. * Bank GPIOs Style SlpCon ExtInt Group
  1171. * A 6 4Bit Yes 1
  1172. * B 7 4Bit Yes 1
  1173. * C 8 4Bit Yes 2
  1174. * F 2 2Bit Yes 4 [1]
  1175. * G 7 4Bit Yes 5
  1176. * H 10 4Bit[2] Yes 6
  1177. * I 16 2Bit Yes None
  1178. * J 12 2Bit Yes None
  1179. * N 16 2Bit No IRQ_EINT
  1180. * P 8 2Bit Yes 8
  1181. * R 15 4Bit[2] Yes 8
  1182. */
  1183. static struct samsung_gpio_chip s5p6440_gpios_4bit[] = {
  1184. #ifdef CONFIG_CPU_S5P6440
  1185. {
  1186. .chip = {
  1187. .base = S5P6440_GPA(0),
  1188. .ngpio = S5P6440_GPIO_A_NR,
  1189. .label = "GPA",
  1190. },
  1191. }, {
  1192. .chip = {
  1193. .base = S5P6440_GPB(0),
  1194. .ngpio = S5P6440_GPIO_B_NR,
  1195. .label = "GPB",
  1196. },
  1197. }, {
  1198. .chip = {
  1199. .base = S5P6440_GPC(0),
  1200. .ngpio = S5P6440_GPIO_C_NR,
  1201. .label = "GPC",
  1202. },
  1203. }, {
  1204. .base = S5P64X0_GPG_BASE,
  1205. .chip = {
  1206. .base = S5P6440_GPG(0),
  1207. .ngpio = S5P6440_GPIO_G_NR,
  1208. .label = "GPG",
  1209. },
  1210. },
  1211. #endif
  1212. };
  1213. static struct samsung_gpio_chip s5p6440_gpios_4bit2[] = {
  1214. #ifdef CONFIG_CPU_S5P6440
  1215. {
  1216. .base = S5P64X0_GPH_BASE + 0x4,
  1217. .chip = {
  1218. .base = S5P6440_GPH(0),
  1219. .ngpio = S5P6440_GPIO_H_NR,
  1220. .label = "GPH",
  1221. },
  1222. },
  1223. #endif
  1224. };
  1225. static struct samsung_gpio_chip s5p6440_gpios_rbank[] = {
  1226. #ifdef CONFIG_CPU_S5P6440
  1227. {
  1228. .base = S5P64X0_GPR_BASE + 0x4,
  1229. .config = &s5p64x0_gpio_cfg_rbank,
  1230. .chip = {
  1231. .base = S5P6440_GPR(0),
  1232. .ngpio = S5P6440_GPIO_R_NR,
  1233. .label = "GPR",
  1234. },
  1235. },
  1236. #endif
  1237. };
  1238. static struct samsung_gpio_chip s5p6440_gpios_2bit[] = {
  1239. #ifdef CONFIG_CPU_S5P6440
  1240. {
  1241. .base = S5P64X0_GPF_BASE,
  1242. .config = &samsung_gpio_cfgs[6],
  1243. .chip = {
  1244. .base = S5P6440_GPF(0),
  1245. .ngpio = S5P6440_GPIO_F_NR,
  1246. .label = "GPF",
  1247. },
  1248. }, {
  1249. .base = S5P64X0_GPI_BASE,
  1250. .config = &samsung_gpio_cfgs[4],
  1251. .chip = {
  1252. .base = S5P6440_GPI(0),
  1253. .ngpio = S5P6440_GPIO_I_NR,
  1254. .label = "GPI",
  1255. },
  1256. }, {
  1257. .base = S5P64X0_GPJ_BASE,
  1258. .config = &samsung_gpio_cfgs[4],
  1259. .chip = {
  1260. .base = S5P6440_GPJ(0),
  1261. .ngpio = S5P6440_GPIO_J_NR,
  1262. .label = "GPJ",
  1263. },
  1264. }, {
  1265. .base = S5P64X0_GPN_BASE,
  1266. .config = &samsung_gpio_cfgs[5],
  1267. .chip = {
  1268. .base = S5P6440_GPN(0),
  1269. .ngpio = S5P6440_GPIO_N_NR,
  1270. .label = "GPN",
  1271. },
  1272. }, {
  1273. .base = S5P64X0_GPP_BASE,
  1274. .config = &samsung_gpio_cfgs[6],
  1275. .chip = {
  1276. .base = S5P6440_GPP(0),
  1277. .ngpio = S5P6440_GPIO_P_NR,
  1278. .label = "GPP",
  1279. },
  1280. },
  1281. #endif
  1282. };
  1283. /*
  1284. * S5P6450 GPIO bank summary:
  1285. *
  1286. * Bank GPIOs Style SlpCon ExtInt Group
  1287. * A 6 4Bit Yes 1
  1288. * B 7 4Bit Yes 1
  1289. * C 8 4Bit Yes 2
  1290. * D 8 4Bit Yes None
  1291. * F 2 2Bit Yes None
  1292. * G 14 4Bit[2] Yes 5
  1293. * H 10 4Bit[2] Yes 6
  1294. * I 16 2Bit Yes None
  1295. * J 12 2Bit Yes None
  1296. * K 5 4Bit Yes None
  1297. * N 16 2Bit No IRQ_EINT
  1298. * P 11 2Bit Yes 8
  1299. * Q 14 2Bit Yes None
  1300. * R 15 4Bit[2] Yes None
  1301. * S 8 2Bit Yes None
  1302. *
  1303. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  1304. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  1305. */
  1306. static struct samsung_gpio_chip s5p6450_gpios_4bit[] = {
  1307. #ifdef CONFIG_CPU_S5P6450
  1308. {
  1309. .chip = {
  1310. .base = S5P6450_GPA(0),
  1311. .ngpio = S5P6450_GPIO_A_NR,
  1312. .label = "GPA",
  1313. },
  1314. }, {
  1315. .chip = {
  1316. .base = S5P6450_GPB(0),
  1317. .ngpio = S5P6450_GPIO_B_NR,
  1318. .label = "GPB",
  1319. },
  1320. }, {
  1321. .chip = {
  1322. .base = S5P6450_GPC(0),
  1323. .ngpio = S5P6450_GPIO_C_NR,
  1324. .label = "GPC",
  1325. },
  1326. }, {
  1327. .chip = {
  1328. .base = S5P6450_GPD(0),
  1329. .ngpio = S5P6450_GPIO_D_NR,
  1330. .label = "GPD",
  1331. },
  1332. }, {
  1333. .base = S5P6450_GPK_BASE,
  1334. .chip = {
  1335. .base = S5P6450_GPK(0),
  1336. .ngpio = S5P6450_GPIO_K_NR,
  1337. .label = "GPK",
  1338. },
  1339. },
  1340. #endif
  1341. };
  1342. static struct samsung_gpio_chip s5p6450_gpios_4bit2[] = {
  1343. #ifdef CONFIG_CPU_S5P6450
  1344. {
  1345. .base = S5P64X0_GPG_BASE + 0x4,
  1346. .chip = {
  1347. .base = S5P6450_GPG(0),
  1348. .ngpio = S5P6450_GPIO_G_NR,
  1349. .label = "GPG",
  1350. },
  1351. }, {
  1352. .base = S5P64X0_GPH_BASE + 0x4,
  1353. .chip = {
  1354. .base = S5P6450_GPH(0),
  1355. .ngpio = S5P6450_GPIO_H_NR,
  1356. .label = "GPH",
  1357. },
  1358. },
  1359. #endif
  1360. };
  1361. static struct samsung_gpio_chip s5p6450_gpios_rbank[] = {
  1362. #ifdef CONFIG_CPU_S5P6450
  1363. {
  1364. .base = S5P64X0_GPR_BASE + 0x4,
  1365. .config = &s5p64x0_gpio_cfg_rbank,
  1366. .chip = {
  1367. .base = S5P6450_GPR(0),
  1368. .ngpio = S5P6450_GPIO_R_NR,
  1369. .label = "GPR",
  1370. },
  1371. },
  1372. #endif
  1373. };
  1374. static struct samsung_gpio_chip s5p6450_gpios_2bit[] = {
  1375. #ifdef CONFIG_CPU_S5P6450
  1376. {
  1377. .base = S5P64X0_GPF_BASE,
  1378. .config = &samsung_gpio_cfgs[6],
  1379. .chip = {
  1380. .base = S5P6450_GPF(0),
  1381. .ngpio = S5P6450_GPIO_F_NR,
  1382. .label = "GPF",
  1383. },
  1384. }, {
  1385. .base = S5P64X0_GPI_BASE,
  1386. .config = &samsung_gpio_cfgs[4],
  1387. .chip = {
  1388. .base = S5P6450_GPI(0),
  1389. .ngpio = S5P6450_GPIO_I_NR,
  1390. .label = "GPI",
  1391. },
  1392. }, {
  1393. .base = S5P64X0_GPJ_BASE,
  1394. .config = &samsung_gpio_cfgs[4],
  1395. .chip = {
  1396. .base = S5P6450_GPJ(0),
  1397. .ngpio = S5P6450_GPIO_J_NR,
  1398. .label = "GPJ",
  1399. },
  1400. }, {
  1401. .base = S5P64X0_GPN_BASE,
  1402. .config = &samsung_gpio_cfgs[5],
  1403. .chip = {
  1404. .base = S5P6450_GPN(0),
  1405. .ngpio = S5P6450_GPIO_N_NR,
  1406. .label = "GPN",
  1407. },
  1408. }, {
  1409. .base = S5P64X0_GPP_BASE,
  1410. .config = &samsung_gpio_cfgs[6],
  1411. .chip = {
  1412. .base = S5P6450_GPP(0),
  1413. .ngpio = S5P6450_GPIO_P_NR,
  1414. .label = "GPP",
  1415. },
  1416. }, {
  1417. .base = S5P6450_GPQ_BASE,
  1418. .config = &samsung_gpio_cfgs[5],
  1419. .chip = {
  1420. .base = S5P6450_GPQ(0),
  1421. .ngpio = S5P6450_GPIO_Q_NR,
  1422. .label = "GPQ",
  1423. },
  1424. }, {
  1425. .base = S5P6450_GPS_BASE,
  1426. .config = &samsung_gpio_cfgs[6],
  1427. .chip = {
  1428. .base = S5P6450_GPS(0),
  1429. .ngpio = S5P6450_GPIO_S_NR,
  1430. .label = "GPS",
  1431. },
  1432. },
  1433. #endif
  1434. };
  1435. /*
  1436. * S5PC100 GPIO bank summary:
  1437. *
  1438. * Bank GPIOs Style INT Type
  1439. * A0 8 4Bit GPIO_INT0
  1440. * A1 5 4Bit GPIO_INT1
  1441. * B 8 4Bit GPIO_INT2
  1442. * C 5 4Bit GPIO_INT3
  1443. * D 7 4Bit GPIO_INT4
  1444. * E0 8 4Bit GPIO_INT5
  1445. * E1 6 4Bit GPIO_INT6
  1446. * F0 8 4Bit GPIO_INT7
  1447. * F1 8 4Bit GPIO_INT8
  1448. * F2 8 4Bit GPIO_INT9
  1449. * F3 4 4Bit GPIO_INT10
  1450. * G0 8 4Bit GPIO_INT11
  1451. * G1 3 4Bit GPIO_INT12
  1452. * G2 7 4Bit GPIO_INT13
  1453. * G3 7 4Bit GPIO_INT14
  1454. * H0 8 4Bit WKUP_INT
  1455. * H1 8 4Bit WKUP_INT
  1456. * H2 8 4Bit WKUP_INT
  1457. * H3 8 4Bit WKUP_INT
  1458. * I 8 4Bit GPIO_INT15
  1459. * J0 8 4Bit GPIO_INT16
  1460. * J1 5 4Bit GPIO_INT17
  1461. * J2 8 4Bit GPIO_INT18
  1462. * J3 8 4Bit GPIO_INT19
  1463. * J4 4 4Bit GPIO_INT20
  1464. * K0 8 4Bit None
  1465. * K1 6 4Bit None
  1466. * K2 8 4Bit None
  1467. * K3 8 4Bit None
  1468. * L0 8 4Bit None
  1469. * L1 8 4Bit None
  1470. * L2 8 4Bit None
  1471. * L3 8 4Bit None
  1472. */
  1473. static struct samsung_gpio_chip s5pc100_gpios_4bit[] = {
  1474. #ifdef CONFIG_CPU_S5PC100
  1475. {
  1476. .chip = {
  1477. .base = S5PC100_GPA0(0),
  1478. .ngpio = S5PC100_GPIO_A0_NR,
  1479. .label = "GPA0",
  1480. },
  1481. }, {
  1482. .chip = {
  1483. .base = S5PC100_GPA1(0),
  1484. .ngpio = S5PC100_GPIO_A1_NR,
  1485. .label = "GPA1",
  1486. },
  1487. }, {
  1488. .chip = {
  1489. .base = S5PC100_GPB(0),
  1490. .ngpio = S5PC100_GPIO_B_NR,
  1491. .label = "GPB",
  1492. },
  1493. }, {
  1494. .chip = {
  1495. .base = S5PC100_GPC(0),
  1496. .ngpio = S5PC100_GPIO_C_NR,
  1497. .label = "GPC",
  1498. },
  1499. }, {
  1500. .chip = {
  1501. .base = S5PC100_GPD(0),
  1502. .ngpio = S5PC100_GPIO_D_NR,
  1503. .label = "GPD",
  1504. },
  1505. }, {
  1506. .chip = {
  1507. .base = S5PC100_GPE0(0),
  1508. .ngpio = S5PC100_GPIO_E0_NR,
  1509. .label = "GPE0",
  1510. },
  1511. }, {
  1512. .chip = {
  1513. .base = S5PC100_GPE1(0),
  1514. .ngpio = S5PC100_GPIO_E1_NR,
  1515. .label = "GPE1",
  1516. },
  1517. }, {
  1518. .chip = {
  1519. .base = S5PC100_GPF0(0),
  1520. .ngpio = S5PC100_GPIO_F0_NR,
  1521. .label = "GPF0",
  1522. },
  1523. }, {
  1524. .chip = {
  1525. .base = S5PC100_GPF1(0),
  1526. .ngpio = S5PC100_GPIO_F1_NR,
  1527. .label = "GPF1",
  1528. },
  1529. }, {
  1530. .chip = {
  1531. .base = S5PC100_GPF2(0),
  1532. .ngpio = S5PC100_GPIO_F2_NR,
  1533. .label = "GPF2",
  1534. },
  1535. }, {
  1536. .chip = {
  1537. .base = S5PC100_GPF3(0),
  1538. .ngpio = S5PC100_GPIO_F3_NR,
  1539. .label = "GPF3",
  1540. },
  1541. }, {
  1542. .chip = {
  1543. .base = S5PC100_GPG0(0),
  1544. .ngpio = S5PC100_GPIO_G0_NR,
  1545. .label = "GPG0",
  1546. },
  1547. }, {
  1548. .chip = {
  1549. .base = S5PC100_GPG1(0),
  1550. .ngpio = S5PC100_GPIO_G1_NR,
  1551. .label = "GPG1",
  1552. },
  1553. }, {
  1554. .chip = {
  1555. .base = S5PC100_GPG2(0),
  1556. .ngpio = S5PC100_GPIO_G2_NR,
  1557. .label = "GPG2",
  1558. },
  1559. }, {
  1560. .chip = {
  1561. .base = S5PC100_GPG3(0),
  1562. .ngpio = S5PC100_GPIO_G3_NR,
  1563. .label = "GPG3",
  1564. },
  1565. }, {
  1566. .chip = {
  1567. .base = S5PC100_GPI(0),
  1568. .ngpio = S5PC100_GPIO_I_NR,
  1569. .label = "GPI",
  1570. },
  1571. }, {
  1572. .chip = {
  1573. .base = S5PC100_GPJ0(0),
  1574. .ngpio = S5PC100_GPIO_J0_NR,
  1575. .label = "GPJ0",
  1576. },
  1577. }, {
  1578. .chip = {
  1579. .base = S5PC100_GPJ1(0),
  1580. .ngpio = S5PC100_GPIO_J1_NR,
  1581. .label = "GPJ1",
  1582. },
  1583. }, {
  1584. .chip = {
  1585. .base = S5PC100_GPJ2(0),
  1586. .ngpio = S5PC100_GPIO_J2_NR,
  1587. .label = "GPJ2",
  1588. },
  1589. }, {
  1590. .chip = {
  1591. .base = S5PC100_GPJ3(0),
  1592. .ngpio = S5PC100_GPIO_J3_NR,
  1593. .label = "GPJ3",
  1594. },
  1595. }, {
  1596. .chip = {
  1597. .base = S5PC100_GPJ4(0),
  1598. .ngpio = S5PC100_GPIO_J4_NR,
  1599. .label = "GPJ4",
  1600. },
  1601. }, {
  1602. .chip = {
  1603. .base = S5PC100_GPK0(0),
  1604. .ngpio = S5PC100_GPIO_K0_NR,
  1605. .label = "GPK0",
  1606. },
  1607. }, {
  1608. .chip = {
  1609. .base = S5PC100_GPK1(0),
  1610. .ngpio = S5PC100_GPIO_K1_NR,
  1611. .label = "GPK1",
  1612. },
  1613. }, {
  1614. .chip = {
  1615. .base = S5PC100_GPK2(0),
  1616. .ngpio = S5PC100_GPIO_K2_NR,
  1617. .label = "GPK2",
  1618. },
  1619. }, {
  1620. .chip = {
  1621. .base = S5PC100_GPK3(0),
  1622. .ngpio = S5PC100_GPIO_K3_NR,
  1623. .label = "GPK3",
  1624. },
  1625. }, {
  1626. .chip = {
  1627. .base = S5PC100_GPL0(0),
  1628. .ngpio = S5PC100_GPIO_L0_NR,
  1629. .label = "GPL0",
  1630. },
  1631. }, {
  1632. .chip = {
  1633. .base = S5PC100_GPL1(0),
  1634. .ngpio = S5PC100_GPIO_L1_NR,
  1635. .label = "GPL1",
  1636. },
  1637. }, {
  1638. .chip = {
  1639. .base = S5PC100_GPL2(0),
  1640. .ngpio = S5PC100_GPIO_L2_NR,
  1641. .label = "GPL2",
  1642. },
  1643. }, {
  1644. .chip = {
  1645. .base = S5PC100_GPL3(0),
  1646. .ngpio = S5PC100_GPIO_L3_NR,
  1647. .label = "GPL3",
  1648. },
  1649. }, {
  1650. .chip = {
  1651. .base = S5PC100_GPL4(0),
  1652. .ngpio = S5PC100_GPIO_L4_NR,
  1653. .label = "GPL4",
  1654. },
  1655. }, {
  1656. .base = (S5P_VA_GPIO + 0xC00),
  1657. .irq_base = IRQ_EINT(0),
  1658. .chip = {
  1659. .base = S5PC100_GPH0(0),
  1660. .ngpio = S5PC100_GPIO_H0_NR,
  1661. .label = "GPH0",
  1662. .to_irq = samsung_gpiolib_to_irq,
  1663. },
  1664. }, {
  1665. .base = (S5P_VA_GPIO + 0xC20),
  1666. .irq_base = IRQ_EINT(8),
  1667. .chip = {
  1668. .base = S5PC100_GPH1(0),
  1669. .ngpio = S5PC100_GPIO_H1_NR,
  1670. .label = "GPH1",
  1671. .to_irq = samsung_gpiolib_to_irq,
  1672. },
  1673. }, {
  1674. .base = (S5P_VA_GPIO + 0xC40),
  1675. .irq_base = IRQ_EINT(16),
  1676. .chip = {
  1677. .base = S5PC100_GPH2(0),
  1678. .ngpio = S5PC100_GPIO_H2_NR,
  1679. .label = "GPH2",
  1680. .to_irq = samsung_gpiolib_to_irq,
  1681. },
  1682. }, {
  1683. .base = (S5P_VA_GPIO + 0xC60),
  1684. .irq_base = IRQ_EINT(24),
  1685. .chip = {
  1686. .base = S5PC100_GPH3(0),
  1687. .ngpio = S5PC100_GPIO_H3_NR,
  1688. .label = "GPH3",
  1689. .to_irq = samsung_gpiolib_to_irq,
  1690. },
  1691. },
  1692. #endif
  1693. };
  1694. /*
  1695. * Followings are the gpio banks in S5PV210/S5PC110
  1696. *
  1697. * The 'config' member when left to NULL, is initialized to the default
  1698. * structure samsung_gpio_cfgs[3] in the init function below.
  1699. *
  1700. * The 'base' member is also initialized in the init function below.
  1701. * Note: The initialization of 'base' member of samsung_gpio_chip structure
  1702. * uses the above macro and depends on the banks being listed in order here.
  1703. */
  1704. static struct samsung_gpio_chip s5pv210_gpios_4bit[] = {
  1705. #ifdef CONFIG_CPU_S5PV210
  1706. {
  1707. .chip = {
  1708. .base = S5PV210_GPA0(0),
  1709. .ngpio = S5PV210_GPIO_A0_NR,
  1710. .label = "GPA0",
  1711. },
  1712. }, {
  1713. .chip = {
  1714. .base = S5PV210_GPA1(0),
  1715. .ngpio = S5PV210_GPIO_A1_NR,
  1716. .label = "GPA1",
  1717. },
  1718. }, {
  1719. .chip = {
  1720. .base = S5PV210_GPB(0),
  1721. .ngpio = S5PV210_GPIO_B_NR,
  1722. .label = "GPB",
  1723. },
  1724. }, {
  1725. .chip = {
  1726. .base = S5PV210_GPC0(0),
  1727. .ngpio = S5PV210_GPIO_C0_NR,
  1728. .label = "GPC0",
  1729. },
  1730. }, {
  1731. .chip = {
  1732. .base = S5PV210_GPC1(0),
  1733. .ngpio = S5PV210_GPIO_C1_NR,
  1734. .label = "GPC1",
  1735. },
  1736. }, {
  1737. .chip = {
  1738. .base = S5PV210_GPD0(0),
  1739. .ngpio = S5PV210_GPIO_D0_NR,
  1740. .label = "GPD0",
  1741. },
  1742. }, {
  1743. .chip = {
  1744. .base = S5PV210_GPD1(0),
  1745. .ngpio = S5PV210_GPIO_D1_NR,
  1746. .label = "GPD1",
  1747. },
  1748. }, {
  1749. .chip = {
  1750. .base = S5PV210_GPE0(0),
  1751. .ngpio = S5PV210_GPIO_E0_NR,
  1752. .label = "GPE0",
  1753. },
  1754. }, {
  1755. .chip = {
  1756. .base = S5PV210_GPE1(0),
  1757. .ngpio = S5PV210_GPIO_E1_NR,
  1758. .label = "GPE1",
  1759. },
  1760. }, {
  1761. .chip = {
  1762. .base = S5PV210_GPF0(0),
  1763. .ngpio = S5PV210_GPIO_F0_NR,
  1764. .label = "GPF0",
  1765. },
  1766. }, {
  1767. .chip = {
  1768. .base = S5PV210_GPF1(0),
  1769. .ngpio = S5PV210_GPIO_F1_NR,
  1770. .label = "GPF1",
  1771. },
  1772. }, {
  1773. .chip = {
  1774. .base = S5PV210_GPF2(0),
  1775. .ngpio = S5PV210_GPIO_F2_NR,
  1776. .label = "GPF2",
  1777. },
  1778. }, {
  1779. .chip = {
  1780. .base = S5PV210_GPF3(0),
  1781. .ngpio = S5PV210_GPIO_F3_NR,
  1782. .label = "GPF3",
  1783. },
  1784. }, {
  1785. .chip = {
  1786. .base = S5PV210_GPG0(0),
  1787. .ngpio = S5PV210_GPIO_G0_NR,
  1788. .label = "GPG0",
  1789. },
  1790. }, {
  1791. .chip = {
  1792. .base = S5PV210_GPG1(0),
  1793. .ngpio = S5PV210_GPIO_G1_NR,
  1794. .label = "GPG1",
  1795. },
  1796. }, {
  1797. .chip = {
  1798. .base = S5PV210_GPG2(0),
  1799. .ngpio = S5PV210_GPIO_G2_NR,
  1800. .label = "GPG2",
  1801. },
  1802. }, {
  1803. .chip = {
  1804. .base = S5PV210_GPG3(0),
  1805. .ngpio = S5PV210_GPIO_G3_NR,
  1806. .label = "GPG3",
  1807. },
  1808. }, {
  1809. .chip = {
  1810. .base = S5PV210_GPI(0),
  1811. .ngpio = S5PV210_GPIO_I_NR,
  1812. .label = "GPI",
  1813. },
  1814. }, {
  1815. .chip = {
  1816. .base = S5PV210_GPJ0(0),
  1817. .ngpio = S5PV210_GPIO_J0_NR,
  1818. .label = "GPJ0",
  1819. },
  1820. }, {
  1821. .chip = {
  1822. .base = S5PV210_GPJ1(0),
  1823. .ngpio = S5PV210_GPIO_J1_NR,
  1824. .label = "GPJ1",
  1825. },
  1826. }, {
  1827. .chip = {
  1828. .base = S5PV210_GPJ2(0),
  1829. .ngpio = S5PV210_GPIO_J2_NR,
  1830. .label = "GPJ2",
  1831. },
  1832. }, {
  1833. .chip = {
  1834. .base = S5PV210_GPJ3(0),
  1835. .ngpio = S5PV210_GPIO_J3_NR,
  1836. .label = "GPJ3",
  1837. },
  1838. }, {
  1839. .chip = {
  1840. .base = S5PV210_GPJ4(0),
  1841. .ngpio = S5PV210_GPIO_J4_NR,
  1842. .label = "GPJ4",
  1843. },
  1844. }, {
  1845. .chip = {
  1846. .base = S5PV210_MP01(0),
  1847. .ngpio = S5PV210_GPIO_MP01_NR,
  1848. .label = "MP01",
  1849. },
  1850. }, {
  1851. .chip = {
  1852. .base = S5PV210_MP02(0),
  1853. .ngpio = S5PV210_GPIO_MP02_NR,
  1854. .label = "MP02",
  1855. },
  1856. }, {
  1857. .chip = {
  1858. .base = S5PV210_MP03(0),
  1859. .ngpio = S5PV210_GPIO_MP03_NR,
  1860. .label = "MP03",
  1861. },
  1862. }, {
  1863. .chip = {
  1864. .base = S5PV210_MP04(0),
  1865. .ngpio = S5PV210_GPIO_MP04_NR,
  1866. .label = "MP04",
  1867. },
  1868. }, {
  1869. .chip = {
  1870. .base = S5PV210_MP05(0),
  1871. .ngpio = S5PV210_GPIO_MP05_NR,
  1872. .label = "MP05",
  1873. },
  1874. }, {
  1875. .base = (S5P_VA_GPIO + 0xC00),
  1876. .irq_base = IRQ_EINT(0),
  1877. .chip = {
  1878. .base = S5PV210_GPH0(0),
  1879. .ngpio = S5PV210_GPIO_H0_NR,
  1880. .label = "GPH0",
  1881. .to_irq = samsung_gpiolib_to_irq,
  1882. },
  1883. }, {
  1884. .base = (S5P_VA_GPIO + 0xC20),
  1885. .irq_base = IRQ_EINT(8),
  1886. .chip = {
  1887. .base = S5PV210_GPH1(0),
  1888. .ngpio = S5PV210_GPIO_H1_NR,
  1889. .label = "GPH1",
  1890. .to_irq = samsung_gpiolib_to_irq,
  1891. },
  1892. }, {
  1893. .base = (S5P_VA_GPIO + 0xC40),
  1894. .irq_base = IRQ_EINT(16),
  1895. .chip = {
  1896. .base = S5PV210_GPH2(0),
  1897. .ngpio = S5PV210_GPIO_H2_NR,
  1898. .label = "GPH2",
  1899. .to_irq = samsung_gpiolib_to_irq,
  1900. },
  1901. }, {
  1902. .base = (S5P_VA_GPIO + 0xC60),
  1903. .irq_base = IRQ_EINT(24),
  1904. .chip = {
  1905. .base = S5PV210_GPH3(0),
  1906. .ngpio = S5PV210_GPIO_H3_NR,
  1907. .label = "GPH3",
  1908. .to_irq = samsung_gpiolib_to_irq,
  1909. },
  1910. },
  1911. #endif
  1912. };
  1913. /*
  1914. * Followings are the gpio banks in EXYNOS4210
  1915. *
  1916. * The 'config' member when left to NULL, is initialized to the default
  1917. * structure samsung_gpio_cfgs[3] in the init function below.
  1918. *
  1919. * The 'base' member is also initialized in the init function below.
  1920. * Note: The initialization of 'base' member of samsung_gpio_chip structure
  1921. * uses the above macro and depends on the banks being listed in order here.
  1922. */
  1923. static struct samsung_gpio_chip exynos4_gpios_1[] = {
  1924. #ifdef CONFIG_ARCH_EXYNOS4
  1925. {
  1926. .chip = {
  1927. .base = EXYNOS4_GPA0(0),
  1928. .ngpio = EXYNOS4_GPIO_A0_NR,
  1929. .label = "GPA0",
  1930. },
  1931. }, {
  1932. .chip = {
  1933. .base = EXYNOS4_GPA1(0),
  1934. .ngpio = EXYNOS4_GPIO_A1_NR,
  1935. .label = "GPA1",
  1936. },
  1937. }, {
  1938. .chip = {
  1939. .base = EXYNOS4_GPB(0),
  1940. .ngpio = EXYNOS4_GPIO_B_NR,
  1941. .label = "GPB",
  1942. },
  1943. }, {
  1944. .chip = {
  1945. .base = EXYNOS4_GPC0(0),
  1946. .ngpio = EXYNOS4_GPIO_C0_NR,
  1947. .label = "GPC0",
  1948. },
  1949. }, {
  1950. .chip = {
  1951. .base = EXYNOS4_GPC1(0),
  1952. .ngpio = EXYNOS4_GPIO_C1_NR,
  1953. .label = "GPC1",
  1954. },
  1955. }, {
  1956. .chip = {
  1957. .base = EXYNOS4_GPD0(0),
  1958. .ngpio = EXYNOS4_GPIO_D0_NR,
  1959. .label = "GPD0",
  1960. },
  1961. }, {
  1962. .chip = {
  1963. .base = EXYNOS4_GPD1(0),
  1964. .ngpio = EXYNOS4_GPIO_D1_NR,
  1965. .label = "GPD1",
  1966. },
  1967. }, {
  1968. .chip = {
  1969. .base = EXYNOS4_GPE0(0),
  1970. .ngpio = EXYNOS4_GPIO_E0_NR,
  1971. .label = "GPE0",
  1972. },
  1973. }, {
  1974. .chip = {
  1975. .base = EXYNOS4_GPE1(0),
  1976. .ngpio = EXYNOS4_GPIO_E1_NR,
  1977. .label = "GPE1",
  1978. },
  1979. }, {
  1980. .chip = {
  1981. .base = EXYNOS4_GPE2(0),
  1982. .ngpio = EXYNOS4_GPIO_E2_NR,
  1983. .label = "GPE2",
  1984. },
  1985. }, {
  1986. .chip = {
  1987. .base = EXYNOS4_GPE3(0),
  1988. .ngpio = EXYNOS4_GPIO_E3_NR,
  1989. .label = "GPE3",
  1990. },
  1991. }, {
  1992. .chip = {
  1993. .base = EXYNOS4_GPE4(0),
  1994. .ngpio = EXYNOS4_GPIO_E4_NR,
  1995. .label = "GPE4",
  1996. },
  1997. }, {
  1998. .chip = {
  1999. .base = EXYNOS4_GPF0(0),
  2000. .ngpio = EXYNOS4_GPIO_F0_NR,
  2001. .label = "GPF0",
  2002. },
  2003. }, {
  2004. .chip = {
  2005. .base = EXYNOS4_GPF1(0),
  2006. .ngpio = EXYNOS4_GPIO_F1_NR,
  2007. .label = "GPF1",
  2008. },
  2009. }, {
  2010. .chip = {
  2011. .base = EXYNOS4_GPF2(0),
  2012. .ngpio = EXYNOS4_GPIO_F2_NR,
  2013. .label = "GPF2",
  2014. },
  2015. }, {
  2016. .chip = {
  2017. .base = EXYNOS4_GPF3(0),
  2018. .ngpio = EXYNOS4_GPIO_F3_NR,
  2019. .label = "GPF3",
  2020. },
  2021. },
  2022. #endif
  2023. };
  2024. static struct samsung_gpio_chip exynos4_gpios_2[] = {
  2025. #ifdef CONFIG_ARCH_EXYNOS4
  2026. {
  2027. .chip = {
  2028. .base = EXYNOS4_GPJ0(0),
  2029. .ngpio = EXYNOS4_GPIO_J0_NR,
  2030. .label = "GPJ0",
  2031. },
  2032. }, {
  2033. .chip = {
  2034. .base = EXYNOS4_GPJ1(0),
  2035. .ngpio = EXYNOS4_GPIO_J1_NR,
  2036. .label = "GPJ1",
  2037. },
  2038. }, {
  2039. .chip = {
  2040. .base = EXYNOS4_GPK0(0),
  2041. .ngpio = EXYNOS4_GPIO_K0_NR,
  2042. .label = "GPK0",
  2043. },
  2044. }, {
  2045. .chip = {
  2046. .base = EXYNOS4_GPK1(0),
  2047. .ngpio = EXYNOS4_GPIO_K1_NR,
  2048. .label = "GPK1",
  2049. },
  2050. }, {
  2051. .chip = {
  2052. .base = EXYNOS4_GPK2(0),
  2053. .ngpio = EXYNOS4_GPIO_K2_NR,
  2054. .label = "GPK2",
  2055. },
  2056. }, {
  2057. .chip = {
  2058. .base = EXYNOS4_GPK3(0),
  2059. .ngpio = EXYNOS4_GPIO_K3_NR,
  2060. .label = "GPK3",
  2061. },
  2062. }, {
  2063. .chip = {
  2064. .base = EXYNOS4_GPL0(0),
  2065. .ngpio = EXYNOS4_GPIO_L0_NR,
  2066. .label = "GPL0",
  2067. },
  2068. }, {
  2069. .chip = {
  2070. .base = EXYNOS4_GPL1(0),
  2071. .ngpio = EXYNOS4_GPIO_L1_NR,
  2072. .label = "GPL1",
  2073. },
  2074. }, {
  2075. .chip = {
  2076. .base = EXYNOS4_GPL2(0),
  2077. .ngpio = EXYNOS4_GPIO_L2_NR,
  2078. .label = "GPL2",
  2079. },
  2080. }, {
  2081. .config = &samsung_gpio_cfgs[8],
  2082. .chip = {
  2083. .base = EXYNOS4_GPY0(0),
  2084. .ngpio = EXYNOS4_GPIO_Y0_NR,
  2085. .label = "GPY0",
  2086. },
  2087. }, {
  2088. .config = &samsung_gpio_cfgs[8],
  2089. .chip = {
  2090. .base = EXYNOS4_GPY1(0),
  2091. .ngpio = EXYNOS4_GPIO_Y1_NR,
  2092. .label = "GPY1",
  2093. },
  2094. }, {
  2095. .config = &samsung_gpio_cfgs[8],
  2096. .chip = {
  2097. .base = EXYNOS4_GPY2(0),
  2098. .ngpio = EXYNOS4_GPIO_Y2_NR,
  2099. .label = "GPY2",
  2100. },
  2101. }, {
  2102. .config = &samsung_gpio_cfgs[8],
  2103. .chip = {
  2104. .base = EXYNOS4_GPY3(0),
  2105. .ngpio = EXYNOS4_GPIO_Y3_NR,
  2106. .label = "GPY3",
  2107. },
  2108. }, {
  2109. .config = &samsung_gpio_cfgs[8],
  2110. .chip = {
  2111. .base = EXYNOS4_GPY4(0),
  2112. .ngpio = EXYNOS4_GPIO_Y4_NR,
  2113. .label = "GPY4",
  2114. },
  2115. }, {
  2116. .config = &samsung_gpio_cfgs[8],
  2117. .chip = {
  2118. .base = EXYNOS4_GPY5(0),
  2119. .ngpio = EXYNOS4_GPIO_Y5_NR,
  2120. .label = "GPY5",
  2121. },
  2122. }, {
  2123. .config = &samsung_gpio_cfgs[8],
  2124. .chip = {
  2125. .base = EXYNOS4_GPY6(0),
  2126. .ngpio = EXYNOS4_GPIO_Y6_NR,
  2127. .label = "GPY6",
  2128. },
  2129. }, {
  2130. .base = (S5P_VA_GPIO2 + 0xC00),
  2131. .config = &samsung_gpio_cfgs[9],
  2132. .irq_base = IRQ_EINT(0),
  2133. .chip = {
  2134. .base = EXYNOS4_GPX0(0),
  2135. .ngpio = EXYNOS4_GPIO_X0_NR,
  2136. .label = "GPX0",
  2137. .to_irq = samsung_gpiolib_to_irq,
  2138. },
  2139. }, {
  2140. .base = (S5P_VA_GPIO2 + 0xC20),
  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. .base = (S5P_VA_GPIO2 + 0xC40),
  2151. .config = &samsung_gpio_cfgs[9],
  2152. .irq_base = IRQ_EINT(16),
  2153. .chip = {
  2154. .base = EXYNOS4_GPX2(0),
  2155. .ngpio = EXYNOS4_GPIO_X2_NR,
  2156. .label = "GPX2",
  2157. .to_irq = samsung_gpiolib_to_irq,
  2158. },
  2159. }, {
  2160. .base = (S5P_VA_GPIO2 + 0xC60),
  2161. .config = &samsung_gpio_cfgs[9],
  2162. .irq_base = IRQ_EINT(24),
  2163. .chip = {
  2164. .base = EXYNOS4_GPX3(0),
  2165. .ngpio = EXYNOS4_GPIO_X3_NR,
  2166. .label = "GPX3",
  2167. .to_irq = samsung_gpiolib_to_irq,
  2168. },
  2169. },
  2170. #endif
  2171. };
  2172. static struct samsung_gpio_chip exynos4_gpios_3[] = {
  2173. #ifdef CONFIG_ARCH_EXYNOS4
  2174. {
  2175. .chip = {
  2176. .base = EXYNOS4_GPZ(0),
  2177. .ngpio = EXYNOS4_GPIO_Z_NR,
  2178. .label = "GPZ",
  2179. },
  2180. },
  2181. #endif
  2182. };
  2183. #if defined(CONFIG_ARCH_EXYNOS4) && defined(CONFIG_OF)
  2184. static int exynos4_gpio_xlate(struct gpio_chip *gc,
  2185. const struct of_phandle_args *gpiospec, u32 *flags)
  2186. {
  2187. unsigned int pin;
  2188. if (WARN_ON(gc->of_gpio_n_cells < 4))
  2189. return -EINVAL;
  2190. if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
  2191. return -EINVAL;
  2192. if (gpiospec->args[0] > gc->ngpio)
  2193. return -EINVAL;
  2194. pin = gc->base + gpiospec->args[0];
  2195. if (s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(gpiospec->args[1])))
  2196. pr_warn("gpio_xlate: failed to set pin function\n");
  2197. if (s3c_gpio_setpull(pin, gpiospec->args[2]))
  2198. pr_warn("gpio_xlate: failed to set pin pull up/down\n");
  2199. if (s5p_gpio_set_drvstr(pin, gpiospec->args[3]))
  2200. pr_warn("gpio_xlate: failed to set pin drive strength\n");
  2201. return gpiospec->args[0];
  2202. }
  2203. static const struct of_device_id exynos4_gpio_dt_match[] __initdata = {
  2204. { .compatible = "samsung,exynos4-gpio", },
  2205. {}
  2206. };
  2207. static __init void exynos4_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2208. u64 base, u64 offset)
  2209. {
  2210. struct gpio_chip *gc = &chip->chip;
  2211. u64 address;
  2212. if (!of_have_populated_dt())
  2213. return;
  2214. address = chip->base ? base + ((u32)chip->base & 0xfff) : base + offset;
  2215. gc->of_node = of_find_matching_node_by_address(NULL,
  2216. exynos4_gpio_dt_match, address);
  2217. if (!gc->of_node) {
  2218. pr_info("gpio: device tree node not found for gpio controller"
  2219. " with base address %08llx\n", address);
  2220. return;
  2221. }
  2222. gc->of_gpio_n_cells = 4;
  2223. gc->of_xlate = exynos4_gpio_xlate;
  2224. }
  2225. #elif defined(CONFIG_ARCH_EXYNOS4)
  2226. static __init void exynos4_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2227. u64 base, u64 offset)
  2228. {
  2229. return;
  2230. }
  2231. #endif /* defined(CONFIG_ARCH_EXYNOS4) && defined(CONFIG_OF) */
  2232. /* TODO: cleanup soc_is_* */
  2233. static __init int samsung_gpiolib_init(void)
  2234. {
  2235. struct samsung_gpio_chip *chip;
  2236. int i, nr_chips;
  2237. int group = 0;
  2238. samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
  2239. if (soc_is_s3c24xx()) {
  2240. s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
  2241. ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
  2242. } else if (soc_is_s3c64xx()) {
  2243. samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
  2244. ARRAY_SIZE(s3c64xx_gpios_2bit),
  2245. S3C64XX_VA_GPIO + 0xE0, 0x20);
  2246. samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
  2247. ARRAY_SIZE(s3c64xx_gpios_4bit),
  2248. S3C64XX_VA_GPIO);
  2249. samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
  2250. ARRAY_SIZE(s3c64xx_gpios_4bit2));
  2251. } else if (soc_is_s5p6440()) {
  2252. samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
  2253. ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
  2254. samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
  2255. ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
  2256. samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
  2257. ARRAY_SIZE(s5p6440_gpios_4bit2));
  2258. s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
  2259. ARRAY_SIZE(s5p6440_gpios_rbank));
  2260. } else if (soc_is_s5p6450()) {
  2261. samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
  2262. ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
  2263. samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
  2264. ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
  2265. samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
  2266. ARRAY_SIZE(s5p6450_gpios_4bit2));
  2267. s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
  2268. ARRAY_SIZE(s5p6450_gpios_rbank));
  2269. } else if (soc_is_s5pc100()) {
  2270. group = 0;
  2271. chip = s5pc100_gpios_4bit;
  2272. nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
  2273. for (i = 0; i < nr_chips; i++, chip++) {
  2274. if (!chip->config) {
  2275. chip->config = &samsung_gpio_cfgs[3];
  2276. chip->group = group++;
  2277. }
  2278. }
  2279. samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2280. #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
  2281. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2282. #endif
  2283. } else if (soc_is_s5pv210()) {
  2284. group = 0;
  2285. chip = s5pv210_gpios_4bit;
  2286. nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
  2287. for (i = 0; i < nr_chips; i++, chip++) {
  2288. if (!chip->config) {
  2289. chip->config = &samsung_gpio_cfgs[3];
  2290. chip->group = group++;
  2291. }
  2292. }
  2293. samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2294. #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
  2295. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2296. #endif
  2297. } else if (soc_is_exynos4210()) {
  2298. group = 0;
  2299. /* gpio part1 */
  2300. chip = exynos4_gpios_1;
  2301. nr_chips = ARRAY_SIZE(exynos4_gpios_1);
  2302. for (i = 0; i < nr_chips; i++, chip++) {
  2303. if (!chip->config) {
  2304. chip->config = &exynos4_gpio_cfg;
  2305. chip->group = group++;
  2306. }
  2307. #ifdef CONFIG_CPU_EXYNOS4210
  2308. exynos4_gpiolib_attach_ofnode(chip,
  2309. EXYNOS4_PA_GPIO1, i * 0x20);
  2310. #endif
  2311. }
  2312. samsung_gpiolib_add_4bit_chips(exynos4_gpios_1, nr_chips, S5P_VA_GPIO1);
  2313. /* gpio part2 */
  2314. chip = exynos4_gpios_2;
  2315. nr_chips = ARRAY_SIZE(exynos4_gpios_2);
  2316. for (i = 0; i < nr_chips; i++, chip++) {
  2317. if (!chip->config) {
  2318. chip->config = &exynos4_gpio_cfg;
  2319. chip->group = group++;
  2320. }
  2321. #ifdef CONFIG_CPU_EXYNOS4210
  2322. exynos4_gpiolib_attach_ofnode(chip,
  2323. EXYNOS4_PA_GPIO2, i * 0x20);
  2324. #endif
  2325. }
  2326. samsung_gpiolib_add_4bit_chips(exynos4_gpios_2, nr_chips, S5P_VA_GPIO2);
  2327. /* gpio part3 */
  2328. chip = exynos4_gpios_3;
  2329. nr_chips = ARRAY_SIZE(exynos4_gpios_3);
  2330. for (i = 0; i < nr_chips; i++, chip++) {
  2331. if (!chip->config) {
  2332. chip->config = &exynos4_gpio_cfg;
  2333. chip->group = group++;
  2334. }
  2335. #ifdef CONFIG_CPU_EXYNOS4210
  2336. exynos4_gpiolib_attach_ofnode(chip,
  2337. EXYNOS4_PA_GPIO3, i * 0x20);
  2338. #endif
  2339. }
  2340. samsung_gpiolib_add_4bit_chips(exynos4_gpios_3, nr_chips, S5P_VA_GPIO3);
  2341. #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
  2342. s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
  2343. s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
  2344. #endif
  2345. } else {
  2346. WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
  2347. return -ENODEV;
  2348. }
  2349. return 0;
  2350. }
  2351. core_initcall(samsung_gpiolib_init);
  2352. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  2353. {
  2354. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2355. unsigned long flags;
  2356. int offset;
  2357. int ret;
  2358. if (!chip)
  2359. return -EINVAL;
  2360. offset = pin - chip->chip.base;
  2361. samsung_gpio_lock(chip, flags);
  2362. ret = samsung_gpio_do_setcfg(chip, offset, config);
  2363. samsung_gpio_unlock(chip, flags);
  2364. return ret;
  2365. }
  2366. EXPORT_SYMBOL(s3c_gpio_cfgpin);
  2367. int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  2368. unsigned int cfg)
  2369. {
  2370. int ret;
  2371. for (; nr > 0; nr--, start++) {
  2372. ret = s3c_gpio_cfgpin(start, cfg);
  2373. if (ret != 0)
  2374. return ret;
  2375. }
  2376. return 0;
  2377. }
  2378. EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
  2379. int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  2380. unsigned int cfg, samsung_gpio_pull_t pull)
  2381. {
  2382. int ret;
  2383. for (; nr > 0; nr--, start++) {
  2384. s3c_gpio_setpull(start, pull);
  2385. ret = s3c_gpio_cfgpin(start, cfg);
  2386. if (ret != 0)
  2387. return ret;
  2388. }
  2389. return 0;
  2390. }
  2391. EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
  2392. unsigned s3c_gpio_getcfg(unsigned int pin)
  2393. {
  2394. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2395. unsigned long flags;
  2396. unsigned ret = 0;
  2397. int offset;
  2398. if (chip) {
  2399. offset = pin - chip->chip.base;
  2400. samsung_gpio_lock(chip, flags);
  2401. ret = samsung_gpio_do_getcfg(chip, offset);
  2402. samsung_gpio_unlock(chip, flags);
  2403. }
  2404. return ret;
  2405. }
  2406. EXPORT_SYMBOL(s3c_gpio_getcfg);
  2407. int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
  2408. {
  2409. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2410. unsigned long flags;
  2411. int offset, ret;
  2412. if (!chip)
  2413. return -EINVAL;
  2414. offset = pin - chip->chip.base;
  2415. samsung_gpio_lock(chip, flags);
  2416. ret = samsung_gpio_do_setpull(chip, offset, pull);
  2417. samsung_gpio_unlock(chip, flags);
  2418. return ret;
  2419. }
  2420. EXPORT_SYMBOL(s3c_gpio_setpull);
  2421. samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
  2422. {
  2423. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2424. unsigned long flags;
  2425. int offset;
  2426. u32 pup = 0;
  2427. if (chip) {
  2428. offset = pin - chip->chip.base;
  2429. samsung_gpio_lock(chip, flags);
  2430. pup = samsung_gpio_do_getpull(chip, offset);
  2431. samsung_gpio_unlock(chip, flags);
  2432. }
  2433. return (__force samsung_gpio_pull_t)pup;
  2434. }
  2435. EXPORT_SYMBOL(s3c_gpio_getpull);
  2436. /* gpiolib wrappers until these are totally eliminated */
  2437. void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
  2438. {
  2439. int ret;
  2440. WARN_ON(to); /* should be none of these left */
  2441. if (!to) {
  2442. /* if pull is enabled, try first with up, and if that
  2443. * fails, try using down */
  2444. ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
  2445. if (ret)
  2446. s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
  2447. } else {
  2448. s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
  2449. }
  2450. }
  2451. EXPORT_SYMBOL(s3c2410_gpio_pullup);
  2452. void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
  2453. {
  2454. /* do this via gpiolib until all users removed */
  2455. gpio_request(pin, "temporary");
  2456. gpio_set_value(pin, to);
  2457. gpio_free(pin);
  2458. }
  2459. EXPORT_SYMBOL(s3c2410_gpio_setpin);
  2460. unsigned int s3c2410_gpio_getpin(unsigned int pin)
  2461. {
  2462. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2463. unsigned long offs = pin - chip->chip.base;
  2464. return __raw_readl(chip->base + 0x04) & (1 << offs);
  2465. }
  2466. EXPORT_SYMBOL(s3c2410_gpio_getpin);
  2467. #ifdef CONFIG_S5P_GPIO_DRVSTR
  2468. s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
  2469. {
  2470. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2471. unsigned int off;
  2472. void __iomem *reg;
  2473. int shift;
  2474. u32 drvstr;
  2475. if (!chip)
  2476. return -EINVAL;
  2477. off = pin - chip->chip.base;
  2478. shift = off * 2;
  2479. reg = chip->base + 0x0C;
  2480. drvstr = __raw_readl(reg);
  2481. drvstr = drvstr >> shift;
  2482. drvstr &= 0x3;
  2483. return (__force s5p_gpio_drvstr_t)drvstr;
  2484. }
  2485. EXPORT_SYMBOL(s5p_gpio_get_drvstr);
  2486. int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
  2487. {
  2488. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2489. unsigned int off;
  2490. void __iomem *reg;
  2491. int shift;
  2492. u32 tmp;
  2493. if (!chip)
  2494. return -EINVAL;
  2495. off = pin - chip->chip.base;
  2496. shift = off * 2;
  2497. reg = chip->base + 0x0C;
  2498. tmp = __raw_readl(reg);
  2499. tmp &= ~(0x3 << shift);
  2500. tmp |= drvstr << shift;
  2501. __raw_writel(tmp, reg);
  2502. return 0;
  2503. }
  2504. EXPORT_SYMBOL(s5p_gpio_set_drvstr);
  2505. #endif /* CONFIG_S5P_GPIO_DRVSTR */
  2506. #ifdef CONFIG_PLAT_S3C24XX
  2507. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  2508. {
  2509. unsigned long flags;
  2510. unsigned long misccr;
  2511. local_irq_save(flags);
  2512. misccr = __raw_readl(S3C24XX_MISCCR);
  2513. misccr &= ~clear;
  2514. misccr ^= change;
  2515. __raw_writel(misccr, S3C24XX_MISCCR);
  2516. local_irq_restore(flags);
  2517. return misccr;
  2518. }
  2519. EXPORT_SYMBOL(s3c2410_modify_misccr);
  2520. #endif