gpio-samsung.c 60 KB

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