gpio-samsung.c 58 KB

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