gpio-samsung.c 70 KB

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