gpio-samsung.c 50 KB

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