gpio-samsung.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359
  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/hardware.h>
  31. #include <mach/map.h>
  32. #include <mach/regs-gpio.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_PLAT_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 = 24,
  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 = 16,
  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 = 11,
  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_PLAT_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_PLAT_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_PLAT_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. #if defined(CONFIG_PINCTRL_EXYNOS) || defined(CONFIG_PINCTRL_EXYNOS5440)
  1890. /*
  1891. * This gpio driver includes support for device tree support and there
  1892. * are platforms using it. In order to maintain compatibility with those
  1893. * platforms, and to allow non-dt Exynos4210 platforms to use this
  1894. * gpiolib support, a check is added to find out if there is a active
  1895. * pin-controller driver support available. If it is available, this
  1896. * gpiolib support is ignored and the gpiolib support available in
  1897. * pin-controller driver is used. This is a temporary check and will go
  1898. * away when all of the Exynos4210 platforms have switched to using
  1899. * device tree and the pin-ctrl driver.
  1900. */
  1901. struct device_node *pctrl_np;
  1902. static const struct of_device_id exynos_pinctrl_ids[] = {
  1903. { .compatible = "samsung,s3c2412-pinctrl", },
  1904. { .compatible = "samsung,s3c2416-pinctrl", },
  1905. { .compatible = "samsung,s3c2440-pinctrl", },
  1906. { .compatible = "samsung,s3c2450-pinctrl", },
  1907. { .compatible = "samsung,exynos4210-pinctrl", },
  1908. { .compatible = "samsung,exynos4x12-pinctrl", },
  1909. { .compatible = "samsung,exynos5250-pinctrl", },
  1910. { .compatible = "samsung,exynos5440-pinctrl", },
  1911. { }
  1912. };
  1913. for_each_matching_node(pctrl_np, exynos_pinctrl_ids)
  1914. if (pctrl_np && of_device_is_available(pctrl_np))
  1915. return -ENODEV;
  1916. #endif
  1917. samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
  1918. if (soc_is_s3c24xx()) {
  1919. s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
  1920. ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
  1921. } else if (soc_is_s3c64xx()) {
  1922. samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
  1923. ARRAY_SIZE(s3c64xx_gpios_2bit),
  1924. S3C64XX_VA_GPIO + 0xE0, 0x20);
  1925. samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
  1926. ARRAY_SIZE(s3c64xx_gpios_4bit),
  1927. S3C64XX_VA_GPIO);
  1928. samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
  1929. ARRAY_SIZE(s3c64xx_gpios_4bit2));
  1930. } else if (soc_is_s5p6440()) {
  1931. samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
  1932. ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
  1933. samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
  1934. ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
  1935. samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
  1936. ARRAY_SIZE(s5p6440_gpios_4bit2));
  1937. s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
  1938. ARRAY_SIZE(s5p6440_gpios_rbank));
  1939. } else if (soc_is_s5p6450()) {
  1940. samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
  1941. ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
  1942. samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
  1943. ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
  1944. samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
  1945. ARRAY_SIZE(s5p6450_gpios_4bit2));
  1946. s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
  1947. ARRAY_SIZE(s5p6450_gpios_rbank));
  1948. } else if (soc_is_s5pc100()) {
  1949. group = 0;
  1950. chip = s5pc100_gpios_4bit;
  1951. nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
  1952. for (i = 0; i < nr_chips; i++, chip++) {
  1953. if (!chip->config) {
  1954. chip->config = &samsung_gpio_cfgs[3];
  1955. chip->group = group++;
  1956. }
  1957. }
  1958. samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
  1959. #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
  1960. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  1961. #endif
  1962. } else if (soc_is_s5pv210()) {
  1963. group = 0;
  1964. chip = s5pv210_gpios_4bit;
  1965. nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
  1966. for (i = 0; i < nr_chips; i++, chip++) {
  1967. if (!chip->config) {
  1968. chip->config = &samsung_gpio_cfgs[3];
  1969. chip->group = group++;
  1970. }
  1971. }
  1972. samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
  1973. #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
  1974. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  1975. #endif
  1976. } else {
  1977. WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
  1978. return -ENODEV;
  1979. }
  1980. return 0;
  1981. }
  1982. core_initcall(samsung_gpiolib_init);
  1983. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  1984. {
  1985. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  1986. unsigned long flags;
  1987. int offset;
  1988. int ret;
  1989. if (!chip)
  1990. return -EINVAL;
  1991. offset = pin - chip->chip.base;
  1992. samsung_gpio_lock(chip, flags);
  1993. ret = samsung_gpio_do_setcfg(chip, offset, config);
  1994. samsung_gpio_unlock(chip, flags);
  1995. return ret;
  1996. }
  1997. EXPORT_SYMBOL(s3c_gpio_cfgpin);
  1998. int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  1999. unsigned int cfg)
  2000. {
  2001. int ret;
  2002. for (; nr > 0; nr--, start++) {
  2003. ret = s3c_gpio_cfgpin(start, cfg);
  2004. if (ret != 0)
  2005. return ret;
  2006. }
  2007. return 0;
  2008. }
  2009. EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
  2010. int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  2011. unsigned int cfg, samsung_gpio_pull_t pull)
  2012. {
  2013. int ret;
  2014. for (; nr > 0; nr--, start++) {
  2015. s3c_gpio_setpull(start, pull);
  2016. ret = s3c_gpio_cfgpin(start, cfg);
  2017. if (ret != 0)
  2018. return ret;
  2019. }
  2020. return 0;
  2021. }
  2022. EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
  2023. unsigned s3c_gpio_getcfg(unsigned int pin)
  2024. {
  2025. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2026. unsigned long flags;
  2027. unsigned ret = 0;
  2028. int offset;
  2029. if (chip) {
  2030. offset = pin - chip->chip.base;
  2031. samsung_gpio_lock(chip, flags);
  2032. ret = samsung_gpio_do_getcfg(chip, offset);
  2033. samsung_gpio_unlock(chip, flags);
  2034. }
  2035. return ret;
  2036. }
  2037. EXPORT_SYMBOL(s3c_gpio_getcfg);
  2038. int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
  2039. {
  2040. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2041. unsigned long flags;
  2042. int offset, ret;
  2043. if (!chip)
  2044. return -EINVAL;
  2045. offset = pin - chip->chip.base;
  2046. samsung_gpio_lock(chip, flags);
  2047. ret = samsung_gpio_do_setpull(chip, offset, pull);
  2048. samsung_gpio_unlock(chip, flags);
  2049. return ret;
  2050. }
  2051. EXPORT_SYMBOL(s3c_gpio_setpull);
  2052. samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
  2053. {
  2054. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2055. unsigned long flags;
  2056. int offset;
  2057. u32 pup = 0;
  2058. if (chip) {
  2059. offset = pin - chip->chip.base;
  2060. samsung_gpio_lock(chip, flags);
  2061. pup = samsung_gpio_do_getpull(chip, offset);
  2062. samsung_gpio_unlock(chip, flags);
  2063. }
  2064. return (__force samsung_gpio_pull_t)pup;
  2065. }
  2066. EXPORT_SYMBOL(s3c_gpio_getpull);
  2067. #ifdef CONFIG_S5P_GPIO_DRVSTR
  2068. s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
  2069. {
  2070. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2071. unsigned int off;
  2072. void __iomem *reg;
  2073. int shift;
  2074. u32 drvstr;
  2075. if (!chip)
  2076. return -EINVAL;
  2077. off = pin - chip->chip.base;
  2078. shift = off * 2;
  2079. reg = chip->base + 0x0C;
  2080. drvstr = __raw_readl(reg);
  2081. drvstr = drvstr >> shift;
  2082. drvstr &= 0x3;
  2083. return (__force s5p_gpio_drvstr_t)drvstr;
  2084. }
  2085. EXPORT_SYMBOL(s5p_gpio_get_drvstr);
  2086. int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
  2087. {
  2088. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2089. unsigned int off;
  2090. void __iomem *reg;
  2091. int shift;
  2092. u32 tmp;
  2093. if (!chip)
  2094. return -EINVAL;
  2095. off = pin - chip->chip.base;
  2096. shift = off * 2;
  2097. reg = chip->base + 0x0C;
  2098. tmp = __raw_readl(reg);
  2099. tmp &= ~(0x3 << shift);
  2100. tmp |= drvstr << shift;
  2101. __raw_writel(tmp, reg);
  2102. return 0;
  2103. }
  2104. EXPORT_SYMBOL(s5p_gpio_set_drvstr);
  2105. #endif /* CONFIG_S5P_GPIO_DRVSTR */
  2106. #ifdef CONFIG_PLAT_S3C24XX
  2107. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  2108. {
  2109. unsigned long flags;
  2110. unsigned long misccr;
  2111. local_irq_save(flags);
  2112. misccr = __raw_readl(S3C24XX_MISCCR);
  2113. misccr &= ~clear;
  2114. misccr ^= change;
  2115. __raw_writel(misccr, S3C24XX_MISCCR);
  2116. local_irq_restore(flags);
  2117. return misccr;
  2118. }
  2119. EXPORT_SYMBOL(s3c2410_modify_misccr);
  2120. #endif