gpio-samsung.c 50 KB

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