gpio-samsung.c 57 KB

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