gpio-samsung.c 58 KB

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