gpio-samsung.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283
  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. return IRQ_EINT0 + offset;
  936. if (offset < 8)
  937. return IRQ_EINT4 + offset - 4;
  938. return -EINVAL;
  939. }
  940. #endif
  941. #ifdef CONFIG_PLAT_S3C64XX
  942. static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin)
  943. {
  944. return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
  945. }
  946. static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin)
  947. {
  948. return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
  949. }
  950. #endif
  951. struct samsung_gpio_chip s3c24xx_gpios[] = {
  952. #ifdef CONFIG_PLAT_S3C24XX
  953. {
  954. .config = &s3c24xx_gpiocfg_banka,
  955. .chip = {
  956. .base = S3C2410_GPA(0),
  957. .owner = THIS_MODULE,
  958. .label = "GPIOA",
  959. .ngpio = 24,
  960. .direction_input = s3c24xx_gpiolib_banka_input,
  961. .direction_output = s3c24xx_gpiolib_banka_output,
  962. },
  963. }, {
  964. .chip = {
  965. .base = S3C2410_GPB(0),
  966. .owner = THIS_MODULE,
  967. .label = "GPIOB",
  968. .ngpio = 16,
  969. },
  970. }, {
  971. .chip = {
  972. .base = S3C2410_GPC(0),
  973. .owner = THIS_MODULE,
  974. .label = "GPIOC",
  975. .ngpio = 16,
  976. },
  977. }, {
  978. .chip = {
  979. .base = S3C2410_GPD(0),
  980. .owner = THIS_MODULE,
  981. .label = "GPIOD",
  982. .ngpio = 16,
  983. },
  984. }, {
  985. .chip = {
  986. .base = S3C2410_GPE(0),
  987. .label = "GPIOE",
  988. .owner = THIS_MODULE,
  989. .ngpio = 16,
  990. },
  991. }, {
  992. .chip = {
  993. .base = S3C2410_GPF(0),
  994. .owner = THIS_MODULE,
  995. .label = "GPIOF",
  996. .ngpio = 8,
  997. .to_irq = s3c24xx_gpiolib_fbank_to_irq,
  998. },
  999. }, {
  1000. .irq_base = IRQ_EINT8,
  1001. .chip = {
  1002. .base = S3C2410_GPG(0),
  1003. .owner = THIS_MODULE,
  1004. .label = "GPIOG",
  1005. .ngpio = 16,
  1006. .to_irq = samsung_gpiolib_to_irq,
  1007. },
  1008. }, {
  1009. .chip = {
  1010. .base = S3C2410_GPH(0),
  1011. .owner = THIS_MODULE,
  1012. .label = "GPIOH",
  1013. .ngpio = 11,
  1014. },
  1015. },
  1016. /* GPIOS for the S3C2443 and later devices. */
  1017. {
  1018. .base = S3C2440_GPJCON,
  1019. .chip = {
  1020. .base = S3C2410_GPJ(0),
  1021. .owner = THIS_MODULE,
  1022. .label = "GPIOJ",
  1023. .ngpio = 16,
  1024. },
  1025. }, {
  1026. .base = S3C2443_GPKCON,
  1027. .chip = {
  1028. .base = S3C2410_GPK(0),
  1029. .owner = THIS_MODULE,
  1030. .label = "GPIOK",
  1031. .ngpio = 16,
  1032. },
  1033. }, {
  1034. .base = S3C2443_GPLCON,
  1035. .chip = {
  1036. .base = S3C2410_GPL(0),
  1037. .owner = THIS_MODULE,
  1038. .label = "GPIOL",
  1039. .ngpio = 15,
  1040. },
  1041. }, {
  1042. .base = S3C2443_GPMCON,
  1043. .chip = {
  1044. .base = S3C2410_GPM(0),
  1045. .owner = THIS_MODULE,
  1046. .label = "GPIOM",
  1047. .ngpio = 2,
  1048. },
  1049. },
  1050. #endif
  1051. };
  1052. /*
  1053. * GPIO bank summary:
  1054. *
  1055. * Bank GPIOs Style SlpCon ExtInt Group
  1056. * A 8 4Bit Yes 1
  1057. * B 7 4Bit Yes 1
  1058. * C 8 4Bit Yes 2
  1059. * D 5 4Bit Yes 3
  1060. * E 5 4Bit Yes None
  1061. * F 16 2Bit Yes 4 [1]
  1062. * G 7 4Bit Yes 5
  1063. * H 10 4Bit[2] Yes 6
  1064. * I 16 2Bit Yes None
  1065. * J 12 2Bit Yes None
  1066. * K 16 4Bit[2] No None
  1067. * L 15 4Bit[2] No None
  1068. * M 6 4Bit No IRQ_EINT
  1069. * N 16 2Bit No IRQ_EINT
  1070. * O 16 2Bit Yes 7
  1071. * P 15 2Bit Yes 8
  1072. * Q 9 2Bit Yes 9
  1073. *
  1074. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  1075. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  1076. */
  1077. static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = {
  1078. #ifdef CONFIG_PLAT_S3C64XX
  1079. {
  1080. .chip = {
  1081. .base = S3C64XX_GPA(0),
  1082. .ngpio = S3C64XX_GPIO_A_NR,
  1083. .label = "GPA",
  1084. },
  1085. }, {
  1086. .chip = {
  1087. .base = S3C64XX_GPB(0),
  1088. .ngpio = S3C64XX_GPIO_B_NR,
  1089. .label = "GPB",
  1090. },
  1091. }, {
  1092. .chip = {
  1093. .base = S3C64XX_GPC(0),
  1094. .ngpio = S3C64XX_GPIO_C_NR,
  1095. .label = "GPC",
  1096. },
  1097. }, {
  1098. .chip = {
  1099. .base = S3C64XX_GPD(0),
  1100. .ngpio = S3C64XX_GPIO_D_NR,
  1101. .label = "GPD",
  1102. },
  1103. }, {
  1104. .config = &samsung_gpio_cfgs[0],
  1105. .chip = {
  1106. .base = S3C64XX_GPE(0),
  1107. .ngpio = S3C64XX_GPIO_E_NR,
  1108. .label = "GPE",
  1109. },
  1110. }, {
  1111. .base = S3C64XX_GPG_BASE,
  1112. .chip = {
  1113. .base = S3C64XX_GPG(0),
  1114. .ngpio = S3C64XX_GPIO_G_NR,
  1115. .label = "GPG",
  1116. },
  1117. }, {
  1118. .base = S3C64XX_GPM_BASE,
  1119. .config = &samsung_gpio_cfgs[1],
  1120. .chip = {
  1121. .base = S3C64XX_GPM(0),
  1122. .ngpio = S3C64XX_GPIO_M_NR,
  1123. .label = "GPM",
  1124. .to_irq = s3c64xx_gpiolib_mbank_to_irq,
  1125. },
  1126. },
  1127. #endif
  1128. };
  1129. static struct samsung_gpio_chip s3c64xx_gpios_4bit2[] = {
  1130. #ifdef CONFIG_PLAT_S3C64XX
  1131. {
  1132. .base = S3C64XX_GPH_BASE + 0x4,
  1133. .chip = {
  1134. .base = S3C64XX_GPH(0),
  1135. .ngpio = S3C64XX_GPIO_H_NR,
  1136. .label = "GPH",
  1137. },
  1138. }, {
  1139. .base = S3C64XX_GPK_BASE + 0x4,
  1140. .config = &samsung_gpio_cfgs[0],
  1141. .chip = {
  1142. .base = S3C64XX_GPK(0),
  1143. .ngpio = S3C64XX_GPIO_K_NR,
  1144. .label = "GPK",
  1145. },
  1146. }, {
  1147. .base = S3C64XX_GPL_BASE + 0x4,
  1148. .config = &samsung_gpio_cfgs[1],
  1149. .chip = {
  1150. .base = S3C64XX_GPL(0),
  1151. .ngpio = S3C64XX_GPIO_L_NR,
  1152. .label = "GPL",
  1153. .to_irq = s3c64xx_gpiolib_lbank_to_irq,
  1154. },
  1155. },
  1156. #endif
  1157. };
  1158. static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = {
  1159. #ifdef CONFIG_PLAT_S3C64XX
  1160. {
  1161. .base = S3C64XX_GPF_BASE,
  1162. .config = &samsung_gpio_cfgs[6],
  1163. .chip = {
  1164. .base = S3C64XX_GPF(0),
  1165. .ngpio = S3C64XX_GPIO_F_NR,
  1166. .label = "GPF",
  1167. },
  1168. }, {
  1169. .config = &samsung_gpio_cfgs[7],
  1170. .chip = {
  1171. .base = S3C64XX_GPI(0),
  1172. .ngpio = S3C64XX_GPIO_I_NR,
  1173. .label = "GPI",
  1174. },
  1175. }, {
  1176. .config = &samsung_gpio_cfgs[7],
  1177. .chip = {
  1178. .base = S3C64XX_GPJ(0),
  1179. .ngpio = S3C64XX_GPIO_J_NR,
  1180. .label = "GPJ",
  1181. },
  1182. }, {
  1183. .config = &samsung_gpio_cfgs[6],
  1184. .chip = {
  1185. .base = S3C64XX_GPO(0),
  1186. .ngpio = S3C64XX_GPIO_O_NR,
  1187. .label = "GPO",
  1188. },
  1189. }, {
  1190. .config = &samsung_gpio_cfgs[6],
  1191. .chip = {
  1192. .base = S3C64XX_GPP(0),
  1193. .ngpio = S3C64XX_GPIO_P_NR,
  1194. .label = "GPP",
  1195. },
  1196. }, {
  1197. .config = &samsung_gpio_cfgs[6],
  1198. .chip = {
  1199. .base = S3C64XX_GPQ(0),
  1200. .ngpio = S3C64XX_GPIO_Q_NR,
  1201. .label = "GPQ",
  1202. },
  1203. }, {
  1204. .base = S3C64XX_GPN_BASE,
  1205. .irq_base = IRQ_EINT(0),
  1206. .config = &samsung_gpio_cfgs[5],
  1207. .chip = {
  1208. .base = S3C64XX_GPN(0),
  1209. .ngpio = S3C64XX_GPIO_N_NR,
  1210. .label = "GPN",
  1211. .to_irq = samsung_gpiolib_to_irq,
  1212. },
  1213. },
  1214. #endif
  1215. };
  1216. /*
  1217. * S5P6440 GPIO bank summary:
  1218. *
  1219. * Bank GPIOs Style SlpCon ExtInt Group
  1220. * A 6 4Bit Yes 1
  1221. * B 7 4Bit Yes 1
  1222. * C 8 4Bit Yes 2
  1223. * F 2 2Bit Yes 4 [1]
  1224. * G 7 4Bit Yes 5
  1225. * H 10 4Bit[2] Yes 6
  1226. * I 16 2Bit Yes None
  1227. * J 12 2Bit Yes None
  1228. * N 16 2Bit No IRQ_EINT
  1229. * P 8 2Bit Yes 8
  1230. * R 15 4Bit[2] Yes 8
  1231. */
  1232. static struct samsung_gpio_chip s5p6440_gpios_4bit[] = {
  1233. #ifdef CONFIG_CPU_S5P6440
  1234. {
  1235. .chip = {
  1236. .base = S5P6440_GPA(0),
  1237. .ngpio = S5P6440_GPIO_A_NR,
  1238. .label = "GPA",
  1239. },
  1240. }, {
  1241. .chip = {
  1242. .base = S5P6440_GPB(0),
  1243. .ngpio = S5P6440_GPIO_B_NR,
  1244. .label = "GPB",
  1245. },
  1246. }, {
  1247. .chip = {
  1248. .base = S5P6440_GPC(0),
  1249. .ngpio = S5P6440_GPIO_C_NR,
  1250. .label = "GPC",
  1251. },
  1252. }, {
  1253. .base = S5P64X0_GPG_BASE,
  1254. .chip = {
  1255. .base = S5P6440_GPG(0),
  1256. .ngpio = S5P6440_GPIO_G_NR,
  1257. .label = "GPG",
  1258. },
  1259. },
  1260. #endif
  1261. };
  1262. static struct samsung_gpio_chip s5p6440_gpios_4bit2[] = {
  1263. #ifdef CONFIG_CPU_S5P6440
  1264. {
  1265. .base = S5P64X0_GPH_BASE + 0x4,
  1266. .chip = {
  1267. .base = S5P6440_GPH(0),
  1268. .ngpio = S5P6440_GPIO_H_NR,
  1269. .label = "GPH",
  1270. },
  1271. },
  1272. #endif
  1273. };
  1274. static struct samsung_gpio_chip s5p6440_gpios_rbank[] = {
  1275. #ifdef CONFIG_CPU_S5P6440
  1276. {
  1277. .base = S5P64X0_GPR_BASE + 0x4,
  1278. .config = &s5p64x0_gpio_cfg_rbank,
  1279. .chip = {
  1280. .base = S5P6440_GPR(0),
  1281. .ngpio = S5P6440_GPIO_R_NR,
  1282. .label = "GPR",
  1283. },
  1284. },
  1285. #endif
  1286. };
  1287. static struct samsung_gpio_chip s5p6440_gpios_2bit[] = {
  1288. #ifdef CONFIG_CPU_S5P6440
  1289. {
  1290. .base = S5P64X0_GPF_BASE,
  1291. .config = &samsung_gpio_cfgs[6],
  1292. .chip = {
  1293. .base = S5P6440_GPF(0),
  1294. .ngpio = S5P6440_GPIO_F_NR,
  1295. .label = "GPF",
  1296. },
  1297. }, {
  1298. .base = S5P64X0_GPI_BASE,
  1299. .config = &samsung_gpio_cfgs[4],
  1300. .chip = {
  1301. .base = S5P6440_GPI(0),
  1302. .ngpio = S5P6440_GPIO_I_NR,
  1303. .label = "GPI",
  1304. },
  1305. }, {
  1306. .base = S5P64X0_GPJ_BASE,
  1307. .config = &samsung_gpio_cfgs[4],
  1308. .chip = {
  1309. .base = S5P6440_GPJ(0),
  1310. .ngpio = S5P6440_GPIO_J_NR,
  1311. .label = "GPJ",
  1312. },
  1313. }, {
  1314. .base = S5P64X0_GPN_BASE,
  1315. .config = &samsung_gpio_cfgs[5],
  1316. .chip = {
  1317. .base = S5P6440_GPN(0),
  1318. .ngpio = S5P6440_GPIO_N_NR,
  1319. .label = "GPN",
  1320. },
  1321. }, {
  1322. .base = S5P64X0_GPP_BASE,
  1323. .config = &samsung_gpio_cfgs[6],
  1324. .chip = {
  1325. .base = S5P6440_GPP(0),
  1326. .ngpio = S5P6440_GPIO_P_NR,
  1327. .label = "GPP",
  1328. },
  1329. },
  1330. #endif
  1331. };
  1332. /*
  1333. * S5P6450 GPIO bank summary:
  1334. *
  1335. * Bank GPIOs Style SlpCon ExtInt Group
  1336. * A 6 4Bit Yes 1
  1337. * B 7 4Bit Yes 1
  1338. * C 8 4Bit Yes 2
  1339. * D 8 4Bit Yes None
  1340. * F 2 2Bit Yes None
  1341. * G 14 4Bit[2] Yes 5
  1342. * H 10 4Bit[2] Yes 6
  1343. * I 16 2Bit Yes None
  1344. * J 12 2Bit Yes None
  1345. * K 5 4Bit Yes None
  1346. * N 16 2Bit No IRQ_EINT
  1347. * P 11 2Bit Yes 8
  1348. * Q 14 2Bit Yes None
  1349. * R 15 4Bit[2] Yes None
  1350. * S 8 2Bit Yes None
  1351. *
  1352. * [1] BANKF pins 14,15 do not form part of the external interrupt sources
  1353. * [2] BANK has two control registers, GPxCON0 and GPxCON1
  1354. */
  1355. static struct samsung_gpio_chip s5p6450_gpios_4bit[] = {
  1356. #ifdef CONFIG_CPU_S5P6450
  1357. {
  1358. .chip = {
  1359. .base = S5P6450_GPA(0),
  1360. .ngpio = S5P6450_GPIO_A_NR,
  1361. .label = "GPA",
  1362. },
  1363. }, {
  1364. .chip = {
  1365. .base = S5P6450_GPB(0),
  1366. .ngpio = S5P6450_GPIO_B_NR,
  1367. .label = "GPB",
  1368. },
  1369. }, {
  1370. .chip = {
  1371. .base = S5P6450_GPC(0),
  1372. .ngpio = S5P6450_GPIO_C_NR,
  1373. .label = "GPC",
  1374. },
  1375. }, {
  1376. .chip = {
  1377. .base = S5P6450_GPD(0),
  1378. .ngpio = S5P6450_GPIO_D_NR,
  1379. .label = "GPD",
  1380. },
  1381. }, {
  1382. .base = S5P6450_GPK_BASE,
  1383. .chip = {
  1384. .base = S5P6450_GPK(0),
  1385. .ngpio = S5P6450_GPIO_K_NR,
  1386. .label = "GPK",
  1387. },
  1388. },
  1389. #endif
  1390. };
  1391. static struct samsung_gpio_chip s5p6450_gpios_4bit2[] = {
  1392. #ifdef CONFIG_CPU_S5P6450
  1393. {
  1394. .base = S5P64X0_GPG_BASE + 0x4,
  1395. .chip = {
  1396. .base = S5P6450_GPG(0),
  1397. .ngpio = S5P6450_GPIO_G_NR,
  1398. .label = "GPG",
  1399. },
  1400. }, {
  1401. .base = S5P64X0_GPH_BASE + 0x4,
  1402. .chip = {
  1403. .base = S5P6450_GPH(0),
  1404. .ngpio = S5P6450_GPIO_H_NR,
  1405. .label = "GPH",
  1406. },
  1407. },
  1408. #endif
  1409. };
  1410. static struct samsung_gpio_chip s5p6450_gpios_rbank[] = {
  1411. #ifdef CONFIG_CPU_S5P6450
  1412. {
  1413. .base = S5P64X0_GPR_BASE + 0x4,
  1414. .config = &s5p64x0_gpio_cfg_rbank,
  1415. .chip = {
  1416. .base = S5P6450_GPR(0),
  1417. .ngpio = S5P6450_GPIO_R_NR,
  1418. .label = "GPR",
  1419. },
  1420. },
  1421. #endif
  1422. };
  1423. static struct samsung_gpio_chip s5p6450_gpios_2bit[] = {
  1424. #ifdef CONFIG_CPU_S5P6450
  1425. {
  1426. .base = S5P64X0_GPF_BASE,
  1427. .config = &samsung_gpio_cfgs[6],
  1428. .chip = {
  1429. .base = S5P6450_GPF(0),
  1430. .ngpio = S5P6450_GPIO_F_NR,
  1431. .label = "GPF",
  1432. },
  1433. }, {
  1434. .base = S5P64X0_GPI_BASE,
  1435. .config = &samsung_gpio_cfgs[4],
  1436. .chip = {
  1437. .base = S5P6450_GPI(0),
  1438. .ngpio = S5P6450_GPIO_I_NR,
  1439. .label = "GPI",
  1440. },
  1441. }, {
  1442. .base = S5P64X0_GPJ_BASE,
  1443. .config = &samsung_gpio_cfgs[4],
  1444. .chip = {
  1445. .base = S5P6450_GPJ(0),
  1446. .ngpio = S5P6450_GPIO_J_NR,
  1447. .label = "GPJ",
  1448. },
  1449. }, {
  1450. .base = S5P64X0_GPN_BASE,
  1451. .config = &samsung_gpio_cfgs[5],
  1452. .chip = {
  1453. .base = S5P6450_GPN(0),
  1454. .ngpio = S5P6450_GPIO_N_NR,
  1455. .label = "GPN",
  1456. },
  1457. }, {
  1458. .base = S5P64X0_GPP_BASE,
  1459. .config = &samsung_gpio_cfgs[6],
  1460. .chip = {
  1461. .base = S5P6450_GPP(0),
  1462. .ngpio = S5P6450_GPIO_P_NR,
  1463. .label = "GPP",
  1464. },
  1465. }, {
  1466. .base = S5P6450_GPQ_BASE,
  1467. .config = &samsung_gpio_cfgs[5],
  1468. .chip = {
  1469. .base = S5P6450_GPQ(0),
  1470. .ngpio = S5P6450_GPIO_Q_NR,
  1471. .label = "GPQ",
  1472. },
  1473. }, {
  1474. .base = S5P6450_GPS_BASE,
  1475. .config = &samsung_gpio_cfgs[6],
  1476. .chip = {
  1477. .base = S5P6450_GPS(0),
  1478. .ngpio = S5P6450_GPIO_S_NR,
  1479. .label = "GPS",
  1480. },
  1481. },
  1482. #endif
  1483. };
  1484. /*
  1485. * S5PC100 GPIO bank summary:
  1486. *
  1487. * Bank GPIOs Style INT Type
  1488. * A0 8 4Bit GPIO_INT0
  1489. * A1 5 4Bit GPIO_INT1
  1490. * B 8 4Bit GPIO_INT2
  1491. * C 5 4Bit GPIO_INT3
  1492. * D 7 4Bit GPIO_INT4
  1493. * E0 8 4Bit GPIO_INT5
  1494. * E1 6 4Bit GPIO_INT6
  1495. * F0 8 4Bit GPIO_INT7
  1496. * F1 8 4Bit GPIO_INT8
  1497. * F2 8 4Bit GPIO_INT9
  1498. * F3 4 4Bit GPIO_INT10
  1499. * G0 8 4Bit GPIO_INT11
  1500. * G1 3 4Bit GPIO_INT12
  1501. * G2 7 4Bit GPIO_INT13
  1502. * G3 7 4Bit GPIO_INT14
  1503. * H0 8 4Bit WKUP_INT
  1504. * H1 8 4Bit WKUP_INT
  1505. * H2 8 4Bit WKUP_INT
  1506. * H3 8 4Bit WKUP_INT
  1507. * I 8 4Bit GPIO_INT15
  1508. * J0 8 4Bit GPIO_INT16
  1509. * J1 5 4Bit GPIO_INT17
  1510. * J2 8 4Bit GPIO_INT18
  1511. * J3 8 4Bit GPIO_INT19
  1512. * J4 4 4Bit GPIO_INT20
  1513. * K0 8 4Bit None
  1514. * K1 6 4Bit None
  1515. * K2 8 4Bit None
  1516. * K3 8 4Bit None
  1517. * L0 8 4Bit None
  1518. * L1 8 4Bit None
  1519. * L2 8 4Bit None
  1520. * L3 8 4Bit None
  1521. */
  1522. static struct samsung_gpio_chip s5pc100_gpios_4bit[] = {
  1523. #ifdef CONFIG_CPU_S5PC100
  1524. {
  1525. .chip = {
  1526. .base = S5PC100_GPA0(0),
  1527. .ngpio = S5PC100_GPIO_A0_NR,
  1528. .label = "GPA0",
  1529. },
  1530. }, {
  1531. .chip = {
  1532. .base = S5PC100_GPA1(0),
  1533. .ngpio = S5PC100_GPIO_A1_NR,
  1534. .label = "GPA1",
  1535. },
  1536. }, {
  1537. .chip = {
  1538. .base = S5PC100_GPB(0),
  1539. .ngpio = S5PC100_GPIO_B_NR,
  1540. .label = "GPB",
  1541. },
  1542. }, {
  1543. .chip = {
  1544. .base = S5PC100_GPC(0),
  1545. .ngpio = S5PC100_GPIO_C_NR,
  1546. .label = "GPC",
  1547. },
  1548. }, {
  1549. .chip = {
  1550. .base = S5PC100_GPD(0),
  1551. .ngpio = S5PC100_GPIO_D_NR,
  1552. .label = "GPD",
  1553. },
  1554. }, {
  1555. .chip = {
  1556. .base = S5PC100_GPE0(0),
  1557. .ngpio = S5PC100_GPIO_E0_NR,
  1558. .label = "GPE0",
  1559. },
  1560. }, {
  1561. .chip = {
  1562. .base = S5PC100_GPE1(0),
  1563. .ngpio = S5PC100_GPIO_E1_NR,
  1564. .label = "GPE1",
  1565. },
  1566. }, {
  1567. .chip = {
  1568. .base = S5PC100_GPF0(0),
  1569. .ngpio = S5PC100_GPIO_F0_NR,
  1570. .label = "GPF0",
  1571. },
  1572. }, {
  1573. .chip = {
  1574. .base = S5PC100_GPF1(0),
  1575. .ngpio = S5PC100_GPIO_F1_NR,
  1576. .label = "GPF1",
  1577. },
  1578. }, {
  1579. .chip = {
  1580. .base = S5PC100_GPF2(0),
  1581. .ngpio = S5PC100_GPIO_F2_NR,
  1582. .label = "GPF2",
  1583. },
  1584. }, {
  1585. .chip = {
  1586. .base = S5PC100_GPF3(0),
  1587. .ngpio = S5PC100_GPIO_F3_NR,
  1588. .label = "GPF3",
  1589. },
  1590. }, {
  1591. .chip = {
  1592. .base = S5PC100_GPG0(0),
  1593. .ngpio = S5PC100_GPIO_G0_NR,
  1594. .label = "GPG0",
  1595. },
  1596. }, {
  1597. .chip = {
  1598. .base = S5PC100_GPG1(0),
  1599. .ngpio = S5PC100_GPIO_G1_NR,
  1600. .label = "GPG1",
  1601. },
  1602. }, {
  1603. .chip = {
  1604. .base = S5PC100_GPG2(0),
  1605. .ngpio = S5PC100_GPIO_G2_NR,
  1606. .label = "GPG2",
  1607. },
  1608. }, {
  1609. .chip = {
  1610. .base = S5PC100_GPG3(0),
  1611. .ngpio = S5PC100_GPIO_G3_NR,
  1612. .label = "GPG3",
  1613. },
  1614. }, {
  1615. .chip = {
  1616. .base = S5PC100_GPI(0),
  1617. .ngpio = S5PC100_GPIO_I_NR,
  1618. .label = "GPI",
  1619. },
  1620. }, {
  1621. .chip = {
  1622. .base = S5PC100_GPJ0(0),
  1623. .ngpio = S5PC100_GPIO_J0_NR,
  1624. .label = "GPJ0",
  1625. },
  1626. }, {
  1627. .chip = {
  1628. .base = S5PC100_GPJ1(0),
  1629. .ngpio = S5PC100_GPIO_J1_NR,
  1630. .label = "GPJ1",
  1631. },
  1632. }, {
  1633. .chip = {
  1634. .base = S5PC100_GPJ2(0),
  1635. .ngpio = S5PC100_GPIO_J2_NR,
  1636. .label = "GPJ2",
  1637. },
  1638. }, {
  1639. .chip = {
  1640. .base = S5PC100_GPJ3(0),
  1641. .ngpio = S5PC100_GPIO_J3_NR,
  1642. .label = "GPJ3",
  1643. },
  1644. }, {
  1645. .chip = {
  1646. .base = S5PC100_GPJ4(0),
  1647. .ngpio = S5PC100_GPIO_J4_NR,
  1648. .label = "GPJ4",
  1649. },
  1650. }, {
  1651. .chip = {
  1652. .base = S5PC100_GPK0(0),
  1653. .ngpio = S5PC100_GPIO_K0_NR,
  1654. .label = "GPK0",
  1655. },
  1656. }, {
  1657. .chip = {
  1658. .base = S5PC100_GPK1(0),
  1659. .ngpio = S5PC100_GPIO_K1_NR,
  1660. .label = "GPK1",
  1661. },
  1662. }, {
  1663. .chip = {
  1664. .base = S5PC100_GPK2(0),
  1665. .ngpio = S5PC100_GPIO_K2_NR,
  1666. .label = "GPK2",
  1667. },
  1668. }, {
  1669. .chip = {
  1670. .base = S5PC100_GPK3(0),
  1671. .ngpio = S5PC100_GPIO_K3_NR,
  1672. .label = "GPK3",
  1673. },
  1674. }, {
  1675. .chip = {
  1676. .base = S5PC100_GPL0(0),
  1677. .ngpio = S5PC100_GPIO_L0_NR,
  1678. .label = "GPL0",
  1679. },
  1680. }, {
  1681. .chip = {
  1682. .base = S5PC100_GPL1(0),
  1683. .ngpio = S5PC100_GPIO_L1_NR,
  1684. .label = "GPL1",
  1685. },
  1686. }, {
  1687. .chip = {
  1688. .base = S5PC100_GPL2(0),
  1689. .ngpio = S5PC100_GPIO_L2_NR,
  1690. .label = "GPL2",
  1691. },
  1692. }, {
  1693. .chip = {
  1694. .base = S5PC100_GPL3(0),
  1695. .ngpio = S5PC100_GPIO_L3_NR,
  1696. .label = "GPL3",
  1697. },
  1698. }, {
  1699. .chip = {
  1700. .base = S5PC100_GPL4(0),
  1701. .ngpio = S5PC100_GPIO_L4_NR,
  1702. .label = "GPL4",
  1703. },
  1704. }, {
  1705. .base = (S5P_VA_GPIO + 0xC00),
  1706. .irq_base = IRQ_EINT(0),
  1707. .chip = {
  1708. .base = S5PC100_GPH0(0),
  1709. .ngpio = S5PC100_GPIO_H0_NR,
  1710. .label = "GPH0",
  1711. .to_irq = samsung_gpiolib_to_irq,
  1712. },
  1713. }, {
  1714. .base = (S5P_VA_GPIO + 0xC20),
  1715. .irq_base = IRQ_EINT(8),
  1716. .chip = {
  1717. .base = S5PC100_GPH1(0),
  1718. .ngpio = S5PC100_GPIO_H1_NR,
  1719. .label = "GPH1",
  1720. .to_irq = samsung_gpiolib_to_irq,
  1721. },
  1722. }, {
  1723. .base = (S5P_VA_GPIO + 0xC40),
  1724. .irq_base = IRQ_EINT(16),
  1725. .chip = {
  1726. .base = S5PC100_GPH2(0),
  1727. .ngpio = S5PC100_GPIO_H2_NR,
  1728. .label = "GPH2",
  1729. .to_irq = samsung_gpiolib_to_irq,
  1730. },
  1731. }, {
  1732. .base = (S5P_VA_GPIO + 0xC60),
  1733. .irq_base = IRQ_EINT(24),
  1734. .chip = {
  1735. .base = S5PC100_GPH3(0),
  1736. .ngpio = S5PC100_GPIO_H3_NR,
  1737. .label = "GPH3",
  1738. .to_irq = samsung_gpiolib_to_irq,
  1739. },
  1740. },
  1741. #endif
  1742. };
  1743. /*
  1744. * Followings are the gpio banks in S5PV210/S5PC110
  1745. *
  1746. * The 'config' member when left to NULL, is initialized to the default
  1747. * structure samsung_gpio_cfgs[3] in the init function below.
  1748. *
  1749. * The 'base' member is also initialized in the init function below.
  1750. * Note: The initialization of 'base' member of samsung_gpio_chip structure
  1751. * uses the above macro and depends on the banks being listed in order here.
  1752. */
  1753. static struct samsung_gpio_chip s5pv210_gpios_4bit[] = {
  1754. #ifdef CONFIG_CPU_S5PV210
  1755. {
  1756. .chip = {
  1757. .base = S5PV210_GPA0(0),
  1758. .ngpio = S5PV210_GPIO_A0_NR,
  1759. .label = "GPA0",
  1760. },
  1761. }, {
  1762. .chip = {
  1763. .base = S5PV210_GPA1(0),
  1764. .ngpio = S5PV210_GPIO_A1_NR,
  1765. .label = "GPA1",
  1766. },
  1767. }, {
  1768. .chip = {
  1769. .base = S5PV210_GPB(0),
  1770. .ngpio = S5PV210_GPIO_B_NR,
  1771. .label = "GPB",
  1772. },
  1773. }, {
  1774. .chip = {
  1775. .base = S5PV210_GPC0(0),
  1776. .ngpio = S5PV210_GPIO_C0_NR,
  1777. .label = "GPC0",
  1778. },
  1779. }, {
  1780. .chip = {
  1781. .base = S5PV210_GPC1(0),
  1782. .ngpio = S5PV210_GPIO_C1_NR,
  1783. .label = "GPC1",
  1784. },
  1785. }, {
  1786. .chip = {
  1787. .base = S5PV210_GPD0(0),
  1788. .ngpio = S5PV210_GPIO_D0_NR,
  1789. .label = "GPD0",
  1790. },
  1791. }, {
  1792. .chip = {
  1793. .base = S5PV210_GPD1(0),
  1794. .ngpio = S5PV210_GPIO_D1_NR,
  1795. .label = "GPD1",
  1796. },
  1797. }, {
  1798. .chip = {
  1799. .base = S5PV210_GPE0(0),
  1800. .ngpio = S5PV210_GPIO_E0_NR,
  1801. .label = "GPE0",
  1802. },
  1803. }, {
  1804. .chip = {
  1805. .base = S5PV210_GPE1(0),
  1806. .ngpio = S5PV210_GPIO_E1_NR,
  1807. .label = "GPE1",
  1808. },
  1809. }, {
  1810. .chip = {
  1811. .base = S5PV210_GPF0(0),
  1812. .ngpio = S5PV210_GPIO_F0_NR,
  1813. .label = "GPF0",
  1814. },
  1815. }, {
  1816. .chip = {
  1817. .base = S5PV210_GPF1(0),
  1818. .ngpio = S5PV210_GPIO_F1_NR,
  1819. .label = "GPF1",
  1820. },
  1821. }, {
  1822. .chip = {
  1823. .base = S5PV210_GPF2(0),
  1824. .ngpio = S5PV210_GPIO_F2_NR,
  1825. .label = "GPF2",
  1826. },
  1827. }, {
  1828. .chip = {
  1829. .base = S5PV210_GPF3(0),
  1830. .ngpio = S5PV210_GPIO_F3_NR,
  1831. .label = "GPF3",
  1832. },
  1833. }, {
  1834. .chip = {
  1835. .base = S5PV210_GPG0(0),
  1836. .ngpio = S5PV210_GPIO_G0_NR,
  1837. .label = "GPG0",
  1838. },
  1839. }, {
  1840. .chip = {
  1841. .base = S5PV210_GPG1(0),
  1842. .ngpio = S5PV210_GPIO_G1_NR,
  1843. .label = "GPG1",
  1844. },
  1845. }, {
  1846. .chip = {
  1847. .base = S5PV210_GPG2(0),
  1848. .ngpio = S5PV210_GPIO_G2_NR,
  1849. .label = "GPG2",
  1850. },
  1851. }, {
  1852. .chip = {
  1853. .base = S5PV210_GPG3(0),
  1854. .ngpio = S5PV210_GPIO_G3_NR,
  1855. .label = "GPG3",
  1856. },
  1857. }, {
  1858. .chip = {
  1859. .base = S5PV210_GPI(0),
  1860. .ngpio = S5PV210_GPIO_I_NR,
  1861. .label = "GPI",
  1862. },
  1863. }, {
  1864. .chip = {
  1865. .base = S5PV210_GPJ0(0),
  1866. .ngpio = S5PV210_GPIO_J0_NR,
  1867. .label = "GPJ0",
  1868. },
  1869. }, {
  1870. .chip = {
  1871. .base = S5PV210_GPJ1(0),
  1872. .ngpio = S5PV210_GPIO_J1_NR,
  1873. .label = "GPJ1",
  1874. },
  1875. }, {
  1876. .chip = {
  1877. .base = S5PV210_GPJ2(0),
  1878. .ngpio = S5PV210_GPIO_J2_NR,
  1879. .label = "GPJ2",
  1880. },
  1881. }, {
  1882. .chip = {
  1883. .base = S5PV210_GPJ3(0),
  1884. .ngpio = S5PV210_GPIO_J3_NR,
  1885. .label = "GPJ3",
  1886. },
  1887. }, {
  1888. .chip = {
  1889. .base = S5PV210_GPJ4(0),
  1890. .ngpio = S5PV210_GPIO_J4_NR,
  1891. .label = "GPJ4",
  1892. },
  1893. }, {
  1894. .chip = {
  1895. .base = S5PV210_MP01(0),
  1896. .ngpio = S5PV210_GPIO_MP01_NR,
  1897. .label = "MP01",
  1898. },
  1899. }, {
  1900. .chip = {
  1901. .base = S5PV210_MP02(0),
  1902. .ngpio = S5PV210_GPIO_MP02_NR,
  1903. .label = "MP02",
  1904. },
  1905. }, {
  1906. .chip = {
  1907. .base = S5PV210_MP03(0),
  1908. .ngpio = S5PV210_GPIO_MP03_NR,
  1909. .label = "MP03",
  1910. },
  1911. }, {
  1912. .chip = {
  1913. .base = S5PV210_MP04(0),
  1914. .ngpio = S5PV210_GPIO_MP04_NR,
  1915. .label = "MP04",
  1916. },
  1917. }, {
  1918. .chip = {
  1919. .base = S5PV210_MP05(0),
  1920. .ngpio = S5PV210_GPIO_MP05_NR,
  1921. .label = "MP05",
  1922. },
  1923. }, {
  1924. .base = (S5P_VA_GPIO + 0xC00),
  1925. .irq_base = IRQ_EINT(0),
  1926. .chip = {
  1927. .base = S5PV210_GPH0(0),
  1928. .ngpio = S5PV210_GPIO_H0_NR,
  1929. .label = "GPH0",
  1930. .to_irq = samsung_gpiolib_to_irq,
  1931. },
  1932. }, {
  1933. .base = (S5P_VA_GPIO + 0xC20),
  1934. .irq_base = IRQ_EINT(8),
  1935. .chip = {
  1936. .base = S5PV210_GPH1(0),
  1937. .ngpio = S5PV210_GPIO_H1_NR,
  1938. .label = "GPH1",
  1939. .to_irq = samsung_gpiolib_to_irq,
  1940. },
  1941. }, {
  1942. .base = (S5P_VA_GPIO + 0xC40),
  1943. .irq_base = IRQ_EINT(16),
  1944. .chip = {
  1945. .base = S5PV210_GPH2(0),
  1946. .ngpio = S5PV210_GPIO_H2_NR,
  1947. .label = "GPH2",
  1948. .to_irq = samsung_gpiolib_to_irq,
  1949. },
  1950. }, {
  1951. .base = (S5P_VA_GPIO + 0xC60),
  1952. .irq_base = IRQ_EINT(24),
  1953. .chip = {
  1954. .base = S5PV210_GPH3(0),
  1955. .ngpio = S5PV210_GPIO_H3_NR,
  1956. .label = "GPH3",
  1957. .to_irq = samsung_gpiolib_to_irq,
  1958. },
  1959. },
  1960. #endif
  1961. };
  1962. /*
  1963. * Followings are the gpio banks in EXYNOS SoCs
  1964. *
  1965. * The 'config' member when left to NULL, is initialized to the default
  1966. * structure exynos_gpio_cfg in the init function below.
  1967. *
  1968. * The 'base' member is also initialized in the init function below.
  1969. * Note: The initialization of 'base' member of samsung_gpio_chip structure
  1970. * uses the above macro and depends on the banks being listed in order here.
  1971. */
  1972. #ifdef CONFIG_ARCH_EXYNOS4
  1973. static struct samsung_gpio_chip exynos4_gpios_1[] = {
  1974. {
  1975. .chip = {
  1976. .base = EXYNOS4_GPA0(0),
  1977. .ngpio = EXYNOS4_GPIO_A0_NR,
  1978. .label = "GPA0",
  1979. },
  1980. }, {
  1981. .chip = {
  1982. .base = EXYNOS4_GPA1(0),
  1983. .ngpio = EXYNOS4_GPIO_A1_NR,
  1984. .label = "GPA1",
  1985. },
  1986. }, {
  1987. .chip = {
  1988. .base = EXYNOS4_GPB(0),
  1989. .ngpio = EXYNOS4_GPIO_B_NR,
  1990. .label = "GPB",
  1991. },
  1992. }, {
  1993. .chip = {
  1994. .base = EXYNOS4_GPC0(0),
  1995. .ngpio = EXYNOS4_GPIO_C0_NR,
  1996. .label = "GPC0",
  1997. },
  1998. }, {
  1999. .chip = {
  2000. .base = EXYNOS4_GPC1(0),
  2001. .ngpio = EXYNOS4_GPIO_C1_NR,
  2002. .label = "GPC1",
  2003. },
  2004. }, {
  2005. .chip = {
  2006. .base = EXYNOS4_GPD0(0),
  2007. .ngpio = EXYNOS4_GPIO_D0_NR,
  2008. .label = "GPD0",
  2009. },
  2010. }, {
  2011. .chip = {
  2012. .base = EXYNOS4_GPD1(0),
  2013. .ngpio = EXYNOS4_GPIO_D1_NR,
  2014. .label = "GPD1",
  2015. },
  2016. }, {
  2017. .chip = {
  2018. .base = EXYNOS4_GPE0(0),
  2019. .ngpio = EXYNOS4_GPIO_E0_NR,
  2020. .label = "GPE0",
  2021. },
  2022. }, {
  2023. .chip = {
  2024. .base = EXYNOS4_GPE1(0),
  2025. .ngpio = EXYNOS4_GPIO_E1_NR,
  2026. .label = "GPE1",
  2027. },
  2028. }, {
  2029. .chip = {
  2030. .base = EXYNOS4_GPE2(0),
  2031. .ngpio = EXYNOS4_GPIO_E2_NR,
  2032. .label = "GPE2",
  2033. },
  2034. }, {
  2035. .chip = {
  2036. .base = EXYNOS4_GPE3(0),
  2037. .ngpio = EXYNOS4_GPIO_E3_NR,
  2038. .label = "GPE3",
  2039. },
  2040. }, {
  2041. .chip = {
  2042. .base = EXYNOS4_GPE4(0),
  2043. .ngpio = EXYNOS4_GPIO_E4_NR,
  2044. .label = "GPE4",
  2045. },
  2046. }, {
  2047. .chip = {
  2048. .base = EXYNOS4_GPF0(0),
  2049. .ngpio = EXYNOS4_GPIO_F0_NR,
  2050. .label = "GPF0",
  2051. },
  2052. }, {
  2053. .chip = {
  2054. .base = EXYNOS4_GPF1(0),
  2055. .ngpio = EXYNOS4_GPIO_F1_NR,
  2056. .label = "GPF1",
  2057. },
  2058. }, {
  2059. .chip = {
  2060. .base = EXYNOS4_GPF2(0),
  2061. .ngpio = EXYNOS4_GPIO_F2_NR,
  2062. .label = "GPF2",
  2063. },
  2064. }, {
  2065. .chip = {
  2066. .base = EXYNOS4_GPF3(0),
  2067. .ngpio = EXYNOS4_GPIO_F3_NR,
  2068. .label = "GPF3",
  2069. },
  2070. },
  2071. };
  2072. #endif
  2073. #ifdef CONFIG_ARCH_EXYNOS4
  2074. static struct samsung_gpio_chip exynos4_gpios_2[] = {
  2075. {
  2076. .chip = {
  2077. .base = EXYNOS4_GPJ0(0),
  2078. .ngpio = EXYNOS4_GPIO_J0_NR,
  2079. .label = "GPJ0",
  2080. },
  2081. }, {
  2082. .chip = {
  2083. .base = EXYNOS4_GPJ1(0),
  2084. .ngpio = EXYNOS4_GPIO_J1_NR,
  2085. .label = "GPJ1",
  2086. },
  2087. }, {
  2088. .chip = {
  2089. .base = EXYNOS4_GPK0(0),
  2090. .ngpio = EXYNOS4_GPIO_K0_NR,
  2091. .label = "GPK0",
  2092. },
  2093. }, {
  2094. .chip = {
  2095. .base = EXYNOS4_GPK1(0),
  2096. .ngpio = EXYNOS4_GPIO_K1_NR,
  2097. .label = "GPK1",
  2098. },
  2099. }, {
  2100. .chip = {
  2101. .base = EXYNOS4_GPK2(0),
  2102. .ngpio = EXYNOS4_GPIO_K2_NR,
  2103. .label = "GPK2",
  2104. },
  2105. }, {
  2106. .chip = {
  2107. .base = EXYNOS4_GPK3(0),
  2108. .ngpio = EXYNOS4_GPIO_K3_NR,
  2109. .label = "GPK3",
  2110. },
  2111. }, {
  2112. .chip = {
  2113. .base = EXYNOS4_GPL0(0),
  2114. .ngpio = EXYNOS4_GPIO_L0_NR,
  2115. .label = "GPL0",
  2116. },
  2117. }, {
  2118. .chip = {
  2119. .base = EXYNOS4_GPL1(0),
  2120. .ngpio = EXYNOS4_GPIO_L1_NR,
  2121. .label = "GPL1",
  2122. },
  2123. }, {
  2124. .chip = {
  2125. .base = EXYNOS4_GPL2(0),
  2126. .ngpio = EXYNOS4_GPIO_L2_NR,
  2127. .label = "GPL2",
  2128. },
  2129. }, {
  2130. .config = &samsung_gpio_cfgs[8],
  2131. .chip = {
  2132. .base = EXYNOS4_GPY0(0),
  2133. .ngpio = EXYNOS4_GPIO_Y0_NR,
  2134. .label = "GPY0",
  2135. },
  2136. }, {
  2137. .config = &samsung_gpio_cfgs[8],
  2138. .chip = {
  2139. .base = EXYNOS4_GPY1(0),
  2140. .ngpio = EXYNOS4_GPIO_Y1_NR,
  2141. .label = "GPY1",
  2142. },
  2143. }, {
  2144. .config = &samsung_gpio_cfgs[8],
  2145. .chip = {
  2146. .base = EXYNOS4_GPY2(0),
  2147. .ngpio = EXYNOS4_GPIO_Y2_NR,
  2148. .label = "GPY2",
  2149. },
  2150. }, {
  2151. .config = &samsung_gpio_cfgs[8],
  2152. .chip = {
  2153. .base = EXYNOS4_GPY3(0),
  2154. .ngpio = EXYNOS4_GPIO_Y3_NR,
  2155. .label = "GPY3",
  2156. },
  2157. }, {
  2158. .config = &samsung_gpio_cfgs[8],
  2159. .chip = {
  2160. .base = EXYNOS4_GPY4(0),
  2161. .ngpio = EXYNOS4_GPIO_Y4_NR,
  2162. .label = "GPY4",
  2163. },
  2164. }, {
  2165. .config = &samsung_gpio_cfgs[8],
  2166. .chip = {
  2167. .base = EXYNOS4_GPY5(0),
  2168. .ngpio = EXYNOS4_GPIO_Y5_NR,
  2169. .label = "GPY5",
  2170. },
  2171. }, {
  2172. .config = &samsung_gpio_cfgs[8],
  2173. .chip = {
  2174. .base = EXYNOS4_GPY6(0),
  2175. .ngpio = EXYNOS4_GPIO_Y6_NR,
  2176. .label = "GPY6",
  2177. },
  2178. }, {
  2179. .config = &samsung_gpio_cfgs[9],
  2180. .irq_base = IRQ_EINT(0),
  2181. .chip = {
  2182. .base = EXYNOS4_GPX0(0),
  2183. .ngpio = EXYNOS4_GPIO_X0_NR,
  2184. .label = "GPX0",
  2185. .to_irq = samsung_gpiolib_to_irq,
  2186. },
  2187. }, {
  2188. .config = &samsung_gpio_cfgs[9],
  2189. .irq_base = IRQ_EINT(8),
  2190. .chip = {
  2191. .base = EXYNOS4_GPX1(0),
  2192. .ngpio = EXYNOS4_GPIO_X1_NR,
  2193. .label = "GPX1",
  2194. .to_irq = samsung_gpiolib_to_irq,
  2195. },
  2196. }, {
  2197. .config = &samsung_gpio_cfgs[9],
  2198. .irq_base = IRQ_EINT(16),
  2199. .chip = {
  2200. .base = EXYNOS4_GPX2(0),
  2201. .ngpio = EXYNOS4_GPIO_X2_NR,
  2202. .label = "GPX2",
  2203. .to_irq = samsung_gpiolib_to_irq,
  2204. },
  2205. }, {
  2206. .config = &samsung_gpio_cfgs[9],
  2207. .irq_base = IRQ_EINT(24),
  2208. .chip = {
  2209. .base = EXYNOS4_GPX3(0),
  2210. .ngpio = EXYNOS4_GPIO_X3_NR,
  2211. .label = "GPX3",
  2212. .to_irq = samsung_gpiolib_to_irq,
  2213. },
  2214. },
  2215. };
  2216. #endif
  2217. #ifdef CONFIG_ARCH_EXYNOS4
  2218. static struct samsung_gpio_chip exynos4_gpios_3[] = {
  2219. {
  2220. .chip = {
  2221. .base = EXYNOS4_GPZ(0),
  2222. .ngpio = EXYNOS4_GPIO_Z_NR,
  2223. .label = "GPZ",
  2224. },
  2225. },
  2226. };
  2227. #endif
  2228. #ifdef CONFIG_SOC_EXYNOS5250
  2229. static struct samsung_gpio_chip exynos5_gpios_1[] = {
  2230. {
  2231. .chip = {
  2232. .base = EXYNOS5_GPA0(0),
  2233. .ngpio = EXYNOS5_GPIO_A0_NR,
  2234. .label = "GPA0",
  2235. },
  2236. }, {
  2237. .chip = {
  2238. .base = EXYNOS5_GPA1(0),
  2239. .ngpio = EXYNOS5_GPIO_A1_NR,
  2240. .label = "GPA1",
  2241. },
  2242. }, {
  2243. .chip = {
  2244. .base = EXYNOS5_GPA2(0),
  2245. .ngpio = EXYNOS5_GPIO_A2_NR,
  2246. .label = "GPA2",
  2247. },
  2248. }, {
  2249. .chip = {
  2250. .base = EXYNOS5_GPB0(0),
  2251. .ngpio = EXYNOS5_GPIO_B0_NR,
  2252. .label = "GPB0",
  2253. },
  2254. }, {
  2255. .chip = {
  2256. .base = EXYNOS5_GPB1(0),
  2257. .ngpio = EXYNOS5_GPIO_B1_NR,
  2258. .label = "GPB1",
  2259. },
  2260. }, {
  2261. .chip = {
  2262. .base = EXYNOS5_GPB2(0),
  2263. .ngpio = EXYNOS5_GPIO_B2_NR,
  2264. .label = "GPB2",
  2265. },
  2266. }, {
  2267. .chip = {
  2268. .base = EXYNOS5_GPB3(0),
  2269. .ngpio = EXYNOS5_GPIO_B3_NR,
  2270. .label = "GPB3",
  2271. },
  2272. }, {
  2273. .chip = {
  2274. .base = EXYNOS5_GPC0(0),
  2275. .ngpio = EXYNOS5_GPIO_C0_NR,
  2276. .label = "GPC0",
  2277. },
  2278. }, {
  2279. .chip = {
  2280. .base = EXYNOS5_GPC1(0),
  2281. .ngpio = EXYNOS5_GPIO_C1_NR,
  2282. .label = "GPC1",
  2283. },
  2284. }, {
  2285. .chip = {
  2286. .base = EXYNOS5_GPC2(0),
  2287. .ngpio = EXYNOS5_GPIO_C2_NR,
  2288. .label = "GPC2",
  2289. },
  2290. }, {
  2291. .chip = {
  2292. .base = EXYNOS5_GPC3(0),
  2293. .ngpio = EXYNOS5_GPIO_C3_NR,
  2294. .label = "GPC3",
  2295. },
  2296. }, {
  2297. .chip = {
  2298. .base = EXYNOS5_GPD0(0),
  2299. .ngpio = EXYNOS5_GPIO_D0_NR,
  2300. .label = "GPD0",
  2301. },
  2302. }, {
  2303. .chip = {
  2304. .base = EXYNOS5_GPD1(0),
  2305. .ngpio = EXYNOS5_GPIO_D1_NR,
  2306. .label = "GPD1",
  2307. },
  2308. }, {
  2309. .chip = {
  2310. .base = EXYNOS5_GPY0(0),
  2311. .ngpio = EXYNOS5_GPIO_Y0_NR,
  2312. .label = "GPY0",
  2313. },
  2314. }, {
  2315. .chip = {
  2316. .base = EXYNOS5_GPY1(0),
  2317. .ngpio = EXYNOS5_GPIO_Y1_NR,
  2318. .label = "GPY1",
  2319. },
  2320. }, {
  2321. .chip = {
  2322. .base = EXYNOS5_GPY2(0),
  2323. .ngpio = EXYNOS5_GPIO_Y2_NR,
  2324. .label = "GPY2",
  2325. },
  2326. }, {
  2327. .chip = {
  2328. .base = EXYNOS5_GPY3(0),
  2329. .ngpio = EXYNOS5_GPIO_Y3_NR,
  2330. .label = "GPY3",
  2331. },
  2332. }, {
  2333. .chip = {
  2334. .base = EXYNOS5_GPY4(0),
  2335. .ngpio = EXYNOS5_GPIO_Y4_NR,
  2336. .label = "GPY4",
  2337. },
  2338. }, {
  2339. .chip = {
  2340. .base = EXYNOS5_GPY5(0),
  2341. .ngpio = EXYNOS5_GPIO_Y5_NR,
  2342. .label = "GPY5",
  2343. },
  2344. }, {
  2345. .chip = {
  2346. .base = EXYNOS5_GPY6(0),
  2347. .ngpio = EXYNOS5_GPIO_Y6_NR,
  2348. .label = "GPY6",
  2349. },
  2350. }, {
  2351. .chip = {
  2352. .base = EXYNOS5_GPC4(0),
  2353. .ngpio = EXYNOS5_GPIO_C4_NR,
  2354. .label = "GPC4",
  2355. },
  2356. }, {
  2357. .config = &samsung_gpio_cfgs[9],
  2358. .irq_base = IRQ_EINT(0),
  2359. .chip = {
  2360. .base = EXYNOS5_GPX0(0),
  2361. .ngpio = EXYNOS5_GPIO_X0_NR,
  2362. .label = "GPX0",
  2363. .to_irq = samsung_gpiolib_to_irq,
  2364. },
  2365. }, {
  2366. .config = &samsung_gpio_cfgs[9],
  2367. .irq_base = IRQ_EINT(8),
  2368. .chip = {
  2369. .base = EXYNOS5_GPX1(0),
  2370. .ngpio = EXYNOS5_GPIO_X1_NR,
  2371. .label = "GPX1",
  2372. .to_irq = samsung_gpiolib_to_irq,
  2373. },
  2374. }, {
  2375. .config = &samsung_gpio_cfgs[9],
  2376. .irq_base = IRQ_EINT(16),
  2377. .chip = {
  2378. .base = EXYNOS5_GPX2(0),
  2379. .ngpio = EXYNOS5_GPIO_X2_NR,
  2380. .label = "GPX2",
  2381. .to_irq = samsung_gpiolib_to_irq,
  2382. },
  2383. }, {
  2384. .config = &samsung_gpio_cfgs[9],
  2385. .irq_base = IRQ_EINT(24),
  2386. .chip = {
  2387. .base = EXYNOS5_GPX3(0),
  2388. .ngpio = EXYNOS5_GPIO_X3_NR,
  2389. .label = "GPX3",
  2390. .to_irq = samsung_gpiolib_to_irq,
  2391. },
  2392. },
  2393. };
  2394. #endif
  2395. #ifdef CONFIG_SOC_EXYNOS5250
  2396. static struct samsung_gpio_chip exynos5_gpios_2[] = {
  2397. {
  2398. .chip = {
  2399. .base = EXYNOS5_GPE0(0),
  2400. .ngpio = EXYNOS5_GPIO_E0_NR,
  2401. .label = "GPE0",
  2402. },
  2403. }, {
  2404. .chip = {
  2405. .base = EXYNOS5_GPE1(0),
  2406. .ngpio = EXYNOS5_GPIO_E1_NR,
  2407. .label = "GPE1",
  2408. },
  2409. }, {
  2410. .chip = {
  2411. .base = EXYNOS5_GPF0(0),
  2412. .ngpio = EXYNOS5_GPIO_F0_NR,
  2413. .label = "GPF0",
  2414. },
  2415. }, {
  2416. .chip = {
  2417. .base = EXYNOS5_GPF1(0),
  2418. .ngpio = EXYNOS5_GPIO_F1_NR,
  2419. .label = "GPF1",
  2420. },
  2421. }, {
  2422. .chip = {
  2423. .base = EXYNOS5_GPG0(0),
  2424. .ngpio = EXYNOS5_GPIO_G0_NR,
  2425. .label = "GPG0",
  2426. },
  2427. }, {
  2428. .chip = {
  2429. .base = EXYNOS5_GPG1(0),
  2430. .ngpio = EXYNOS5_GPIO_G1_NR,
  2431. .label = "GPG1",
  2432. },
  2433. }, {
  2434. .chip = {
  2435. .base = EXYNOS5_GPG2(0),
  2436. .ngpio = EXYNOS5_GPIO_G2_NR,
  2437. .label = "GPG2",
  2438. },
  2439. }, {
  2440. .chip = {
  2441. .base = EXYNOS5_GPH0(0),
  2442. .ngpio = EXYNOS5_GPIO_H0_NR,
  2443. .label = "GPH0",
  2444. },
  2445. }, {
  2446. .chip = {
  2447. .base = EXYNOS5_GPH1(0),
  2448. .ngpio = EXYNOS5_GPIO_H1_NR,
  2449. .label = "GPH1",
  2450. },
  2451. },
  2452. };
  2453. #endif
  2454. #ifdef CONFIG_SOC_EXYNOS5250
  2455. static struct samsung_gpio_chip exynos5_gpios_3[] = {
  2456. {
  2457. .chip = {
  2458. .base = EXYNOS5_GPV0(0),
  2459. .ngpio = EXYNOS5_GPIO_V0_NR,
  2460. .label = "GPV0",
  2461. },
  2462. }, {
  2463. .chip = {
  2464. .base = EXYNOS5_GPV1(0),
  2465. .ngpio = EXYNOS5_GPIO_V1_NR,
  2466. .label = "GPV1",
  2467. },
  2468. }, {
  2469. .chip = {
  2470. .base = EXYNOS5_GPV2(0),
  2471. .ngpio = EXYNOS5_GPIO_V2_NR,
  2472. .label = "GPV2",
  2473. },
  2474. }, {
  2475. .chip = {
  2476. .base = EXYNOS5_GPV3(0),
  2477. .ngpio = EXYNOS5_GPIO_V3_NR,
  2478. .label = "GPV3",
  2479. },
  2480. }, {
  2481. .chip = {
  2482. .base = EXYNOS5_GPV4(0),
  2483. .ngpio = EXYNOS5_GPIO_V4_NR,
  2484. .label = "GPV4",
  2485. },
  2486. },
  2487. };
  2488. #endif
  2489. #ifdef CONFIG_SOC_EXYNOS5250
  2490. static struct samsung_gpio_chip exynos5_gpios_4[] = {
  2491. {
  2492. .chip = {
  2493. .base = EXYNOS5_GPZ(0),
  2494. .ngpio = EXYNOS5_GPIO_Z_NR,
  2495. .label = "GPZ",
  2496. },
  2497. },
  2498. };
  2499. #endif
  2500. #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
  2501. static int exynos_gpio_xlate(struct gpio_chip *gc,
  2502. const struct of_phandle_args *gpiospec, u32 *flags)
  2503. {
  2504. unsigned int pin;
  2505. if (WARN_ON(gc->of_gpio_n_cells < 4))
  2506. return -EINVAL;
  2507. if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
  2508. return -EINVAL;
  2509. if (gpiospec->args[0] > gc->ngpio)
  2510. return -EINVAL;
  2511. pin = gc->base + gpiospec->args[0];
  2512. if (s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(gpiospec->args[1])))
  2513. pr_warn("gpio_xlate: failed to set pin function\n");
  2514. if (s3c_gpio_setpull(pin, gpiospec->args[2] & 0xffff))
  2515. pr_warn("gpio_xlate: failed to set pin pull up/down\n");
  2516. if (s5p_gpio_set_drvstr(pin, gpiospec->args[3]))
  2517. pr_warn("gpio_xlate: failed to set pin drive strength\n");
  2518. if (flags)
  2519. *flags = gpiospec->args[2] >> 16;
  2520. return gpiospec->args[0];
  2521. }
  2522. static const struct of_device_id exynos_gpio_dt_match[] __initdata = {
  2523. { .compatible = "samsung,exynos4-gpio", },
  2524. {}
  2525. };
  2526. static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2527. u64 base, u64 offset)
  2528. {
  2529. struct gpio_chip *gc = &chip->chip;
  2530. u64 address;
  2531. if (!of_have_populated_dt())
  2532. return;
  2533. address = chip->base ? base + ((u32)chip->base & 0xfff) : base + offset;
  2534. gc->of_node = of_find_matching_node_by_address(NULL,
  2535. exynos_gpio_dt_match, address);
  2536. if (!gc->of_node) {
  2537. pr_info("gpio: device tree node not found for gpio controller"
  2538. " with base address %08llx\n", address);
  2539. return;
  2540. }
  2541. gc->of_gpio_n_cells = 4;
  2542. gc->of_xlate = exynos_gpio_xlate;
  2543. }
  2544. #elif defined(CONFIG_ARCH_EXYNOS)
  2545. static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
  2546. u64 base, u64 offset)
  2547. {
  2548. return;
  2549. }
  2550. #endif /* defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) */
  2551. static __init void exynos4_gpiolib_init(void)
  2552. {
  2553. #ifdef CONFIG_CPU_EXYNOS4210
  2554. struct samsung_gpio_chip *chip;
  2555. int i, nr_chips;
  2556. void __iomem *gpio_base1, *gpio_base2, *gpio_base3;
  2557. int group = 0;
  2558. void __iomem *gpx_base;
  2559. /* gpio part1 */
  2560. gpio_base1 = ioremap(EXYNOS4_PA_GPIO1, SZ_4K);
  2561. if (gpio_base1 == NULL) {
  2562. pr_err("unable to ioremap for gpio_base1\n");
  2563. goto err_ioremap1;
  2564. }
  2565. chip = exynos4_gpios_1;
  2566. nr_chips = ARRAY_SIZE(exynos4_gpios_1);
  2567. for (i = 0; i < nr_chips; i++, chip++) {
  2568. if (!chip->config) {
  2569. chip->config = &exynos_gpio_cfg;
  2570. chip->group = group++;
  2571. }
  2572. exynos_gpiolib_attach_ofnode(chip,
  2573. EXYNOS4_PA_GPIO1, i * 0x20);
  2574. }
  2575. samsung_gpiolib_add_4bit_chips(exynos4_gpios_1,
  2576. nr_chips, gpio_base1);
  2577. /* gpio part2 */
  2578. gpio_base2 = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  2579. if (gpio_base2 == NULL) {
  2580. pr_err("unable to ioremap for gpio_base2\n");
  2581. goto err_ioremap2;
  2582. }
  2583. /* need to set base address for gpx */
  2584. chip = &exynos4_gpios_2[16];
  2585. gpx_base = gpio_base2 + 0xC00;
  2586. for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
  2587. chip->base = gpx_base;
  2588. chip = exynos4_gpios_2;
  2589. nr_chips = ARRAY_SIZE(exynos4_gpios_2);
  2590. for (i = 0; i < nr_chips; i++, chip++) {
  2591. if (!chip->config) {
  2592. chip->config = &exynos_gpio_cfg;
  2593. chip->group = group++;
  2594. }
  2595. exynos_gpiolib_attach_ofnode(chip,
  2596. EXYNOS4_PA_GPIO2, i * 0x20);
  2597. }
  2598. samsung_gpiolib_add_4bit_chips(exynos4_gpios_2,
  2599. nr_chips, gpio_base2);
  2600. /* gpio part3 */
  2601. gpio_base3 = ioremap(EXYNOS4_PA_GPIO3, SZ_256);
  2602. if (gpio_base3 == NULL) {
  2603. pr_err("unable to ioremap for gpio_base3\n");
  2604. goto err_ioremap3;
  2605. }
  2606. chip = exynos4_gpios_3;
  2607. nr_chips = ARRAY_SIZE(exynos4_gpios_3);
  2608. for (i = 0; i < nr_chips; i++, chip++) {
  2609. if (!chip->config) {
  2610. chip->config = &exynos_gpio_cfg;
  2611. chip->group = group++;
  2612. }
  2613. exynos_gpiolib_attach_ofnode(chip,
  2614. EXYNOS4_PA_GPIO3, i * 0x20);
  2615. }
  2616. samsung_gpiolib_add_4bit_chips(exynos4_gpios_3,
  2617. nr_chips, gpio_base3);
  2618. #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
  2619. s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
  2620. s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
  2621. #endif
  2622. return;
  2623. err_ioremap3:
  2624. iounmap(gpio_base2);
  2625. err_ioremap2:
  2626. iounmap(gpio_base1);
  2627. err_ioremap1:
  2628. return;
  2629. #endif /* CONFIG_CPU_EXYNOS4210 */
  2630. }
  2631. static __init void exynos5_gpiolib_init(void)
  2632. {
  2633. #ifdef CONFIG_SOC_EXYNOS5250
  2634. struct samsung_gpio_chip *chip;
  2635. int i, nr_chips;
  2636. void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4;
  2637. int group = 0;
  2638. void __iomem *gpx_base;
  2639. /* gpio part1 */
  2640. gpio_base1 = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  2641. if (gpio_base1 == NULL) {
  2642. pr_err("unable to ioremap for gpio_base1\n");
  2643. goto err_ioremap1;
  2644. }
  2645. /* need to set base address for gpc4 */
  2646. exynos5_gpios_1[20].base = gpio_base1 + 0x2E0;
  2647. /* need to set base address for gpx */
  2648. chip = &exynos5_gpios_1[21];
  2649. gpx_base = gpio_base1 + 0xC00;
  2650. for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
  2651. chip->base = gpx_base;
  2652. chip = exynos5_gpios_1;
  2653. nr_chips = ARRAY_SIZE(exynos5_gpios_1);
  2654. for (i = 0; i < nr_chips; i++, chip++) {
  2655. if (!chip->config) {
  2656. chip->config = &exynos_gpio_cfg;
  2657. chip->group = group++;
  2658. }
  2659. exynos_gpiolib_attach_ofnode(chip,
  2660. EXYNOS5_PA_GPIO1, i * 0x20);
  2661. }
  2662. samsung_gpiolib_add_4bit_chips(exynos5_gpios_1,
  2663. nr_chips, gpio_base1);
  2664. /* gpio part2 */
  2665. gpio_base2 = ioremap(EXYNOS5_PA_GPIO2, SZ_4K);
  2666. if (gpio_base2 == NULL) {
  2667. pr_err("unable to ioremap for gpio_base2\n");
  2668. goto err_ioremap2;
  2669. }
  2670. chip = exynos5_gpios_2;
  2671. nr_chips = ARRAY_SIZE(exynos5_gpios_2);
  2672. for (i = 0; i < nr_chips; i++, chip++) {
  2673. if (!chip->config) {
  2674. chip->config = &exynos_gpio_cfg;
  2675. chip->group = group++;
  2676. }
  2677. exynos_gpiolib_attach_ofnode(chip,
  2678. EXYNOS5_PA_GPIO2, i * 0x20);
  2679. }
  2680. samsung_gpiolib_add_4bit_chips(exynos5_gpios_2,
  2681. nr_chips, gpio_base2);
  2682. /* gpio part3 */
  2683. gpio_base3 = ioremap(EXYNOS5_PA_GPIO3, SZ_4K);
  2684. if (gpio_base3 == NULL) {
  2685. pr_err("unable to ioremap for gpio_base3\n");
  2686. goto err_ioremap3;
  2687. }
  2688. /* need to set base address for gpv */
  2689. exynos5_gpios_3[0].base = gpio_base3;
  2690. exynos5_gpios_3[1].base = gpio_base3 + 0x20;
  2691. exynos5_gpios_3[2].base = gpio_base3 + 0x60;
  2692. exynos5_gpios_3[3].base = gpio_base3 + 0x80;
  2693. exynos5_gpios_3[4].base = gpio_base3 + 0xC0;
  2694. chip = exynos5_gpios_3;
  2695. nr_chips = ARRAY_SIZE(exynos5_gpios_3);
  2696. for (i = 0; i < nr_chips; i++, chip++) {
  2697. if (!chip->config) {
  2698. chip->config = &exynos_gpio_cfg;
  2699. chip->group = group++;
  2700. }
  2701. exynos_gpiolib_attach_ofnode(chip,
  2702. EXYNOS5_PA_GPIO3, i * 0x20);
  2703. }
  2704. samsung_gpiolib_add_4bit_chips(exynos5_gpios_3,
  2705. nr_chips, gpio_base3);
  2706. /* gpio part4 */
  2707. gpio_base4 = ioremap(EXYNOS5_PA_GPIO4, SZ_4K);
  2708. if (gpio_base4 == NULL) {
  2709. pr_err("unable to ioremap for gpio_base4\n");
  2710. goto err_ioremap4;
  2711. }
  2712. chip = exynos5_gpios_4;
  2713. nr_chips = ARRAY_SIZE(exynos5_gpios_4);
  2714. for (i = 0; i < nr_chips; i++, chip++) {
  2715. if (!chip->config) {
  2716. chip->config = &exynos_gpio_cfg;
  2717. chip->group = group++;
  2718. }
  2719. exynos_gpiolib_attach_ofnode(chip,
  2720. EXYNOS5_PA_GPIO4, i * 0x20);
  2721. }
  2722. samsung_gpiolib_add_4bit_chips(exynos5_gpios_4,
  2723. nr_chips, gpio_base4);
  2724. return;
  2725. err_ioremap4:
  2726. iounmap(gpio_base3);
  2727. err_ioremap3:
  2728. iounmap(gpio_base2);
  2729. err_ioremap2:
  2730. iounmap(gpio_base1);
  2731. err_ioremap1:
  2732. return;
  2733. #endif /* CONFIG_SOC_EXYNOS5250 */
  2734. }
  2735. /* TODO: cleanup soc_is_* */
  2736. static __init int samsung_gpiolib_init(void)
  2737. {
  2738. struct samsung_gpio_chip *chip;
  2739. int i, nr_chips;
  2740. int group = 0;
  2741. #if defined(CONFIG_PINCTRL_EXYNOS) || defined(CONFIG_PINCTRL_EXYNOS5440)
  2742. /*
  2743. * This gpio driver includes support for device tree support and there
  2744. * are platforms using it. In order to maintain compatibility with those
  2745. * platforms, and to allow non-dt Exynos4210 platforms to use this
  2746. * gpiolib support, a check is added to find out if there is a active
  2747. * pin-controller driver support available. If it is available, this
  2748. * gpiolib support is ignored and the gpiolib support available in
  2749. * pin-controller driver is used. This is a temporary check and will go
  2750. * away when all of the Exynos4210 platforms have switched to using
  2751. * device tree and the pin-ctrl driver.
  2752. */
  2753. struct device_node *pctrl_np;
  2754. static const struct of_device_id exynos_pinctrl_ids[] = {
  2755. { .compatible = "samsung,exynos4210-pinctrl", },
  2756. { .compatible = "samsung,exynos4x12-pinctrl", },
  2757. { .compatible = "samsung,exynos5440-pinctrl", },
  2758. };
  2759. for_each_matching_node(pctrl_np, exynos_pinctrl_ids)
  2760. if (pctrl_np && of_device_is_available(pctrl_np))
  2761. return -ENODEV;
  2762. #endif
  2763. samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
  2764. if (soc_is_s3c24xx()) {
  2765. s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
  2766. ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
  2767. } else if (soc_is_s3c64xx()) {
  2768. samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
  2769. ARRAY_SIZE(s3c64xx_gpios_2bit),
  2770. S3C64XX_VA_GPIO + 0xE0, 0x20);
  2771. samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
  2772. ARRAY_SIZE(s3c64xx_gpios_4bit),
  2773. S3C64XX_VA_GPIO);
  2774. samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
  2775. ARRAY_SIZE(s3c64xx_gpios_4bit2));
  2776. } else if (soc_is_s5p6440()) {
  2777. samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
  2778. ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
  2779. samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
  2780. ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
  2781. samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
  2782. ARRAY_SIZE(s5p6440_gpios_4bit2));
  2783. s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
  2784. ARRAY_SIZE(s5p6440_gpios_rbank));
  2785. } else if (soc_is_s5p6450()) {
  2786. samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
  2787. ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
  2788. samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
  2789. ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
  2790. samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
  2791. ARRAY_SIZE(s5p6450_gpios_4bit2));
  2792. s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
  2793. ARRAY_SIZE(s5p6450_gpios_rbank));
  2794. } else if (soc_is_s5pc100()) {
  2795. group = 0;
  2796. chip = s5pc100_gpios_4bit;
  2797. nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
  2798. for (i = 0; i < nr_chips; i++, chip++) {
  2799. if (!chip->config) {
  2800. chip->config = &samsung_gpio_cfgs[3];
  2801. chip->group = group++;
  2802. }
  2803. }
  2804. samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2805. #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
  2806. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2807. #endif
  2808. } else if (soc_is_s5pv210()) {
  2809. group = 0;
  2810. chip = s5pv210_gpios_4bit;
  2811. nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
  2812. for (i = 0; i < nr_chips; i++, chip++) {
  2813. if (!chip->config) {
  2814. chip->config = &samsung_gpio_cfgs[3];
  2815. chip->group = group++;
  2816. }
  2817. }
  2818. samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
  2819. #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
  2820. s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
  2821. #endif
  2822. } else if (soc_is_exynos4210()) {
  2823. exynos4_gpiolib_init();
  2824. } else if (soc_is_exynos5250()) {
  2825. exynos5_gpiolib_init();
  2826. } else {
  2827. WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
  2828. return -ENODEV;
  2829. }
  2830. return 0;
  2831. }
  2832. core_initcall(samsung_gpiolib_init);
  2833. int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
  2834. {
  2835. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2836. unsigned long flags;
  2837. int offset;
  2838. int ret;
  2839. if (!chip)
  2840. return -EINVAL;
  2841. offset = pin - chip->chip.base;
  2842. samsung_gpio_lock(chip, flags);
  2843. ret = samsung_gpio_do_setcfg(chip, offset, config);
  2844. samsung_gpio_unlock(chip, flags);
  2845. return ret;
  2846. }
  2847. EXPORT_SYMBOL(s3c_gpio_cfgpin);
  2848. int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
  2849. unsigned int cfg)
  2850. {
  2851. int ret;
  2852. for (; nr > 0; nr--, start++) {
  2853. ret = s3c_gpio_cfgpin(start, cfg);
  2854. if (ret != 0)
  2855. return ret;
  2856. }
  2857. return 0;
  2858. }
  2859. EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
  2860. int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
  2861. unsigned int cfg, samsung_gpio_pull_t pull)
  2862. {
  2863. int ret;
  2864. for (; nr > 0; nr--, start++) {
  2865. s3c_gpio_setpull(start, pull);
  2866. ret = s3c_gpio_cfgpin(start, cfg);
  2867. if (ret != 0)
  2868. return ret;
  2869. }
  2870. return 0;
  2871. }
  2872. EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
  2873. unsigned s3c_gpio_getcfg(unsigned int pin)
  2874. {
  2875. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2876. unsigned long flags;
  2877. unsigned ret = 0;
  2878. int offset;
  2879. if (chip) {
  2880. offset = pin - chip->chip.base;
  2881. samsung_gpio_lock(chip, flags);
  2882. ret = samsung_gpio_do_getcfg(chip, offset);
  2883. samsung_gpio_unlock(chip, flags);
  2884. }
  2885. return ret;
  2886. }
  2887. EXPORT_SYMBOL(s3c_gpio_getcfg);
  2888. int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
  2889. {
  2890. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2891. unsigned long flags;
  2892. int offset, ret;
  2893. if (!chip)
  2894. return -EINVAL;
  2895. offset = pin - chip->chip.base;
  2896. samsung_gpio_lock(chip, flags);
  2897. ret = samsung_gpio_do_setpull(chip, offset, pull);
  2898. samsung_gpio_unlock(chip, flags);
  2899. return ret;
  2900. }
  2901. EXPORT_SYMBOL(s3c_gpio_setpull);
  2902. samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
  2903. {
  2904. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2905. unsigned long flags;
  2906. int offset;
  2907. u32 pup = 0;
  2908. if (chip) {
  2909. offset = pin - chip->chip.base;
  2910. samsung_gpio_lock(chip, flags);
  2911. pup = samsung_gpio_do_getpull(chip, offset);
  2912. samsung_gpio_unlock(chip, flags);
  2913. }
  2914. return (__force samsung_gpio_pull_t)pup;
  2915. }
  2916. EXPORT_SYMBOL(s3c_gpio_getpull);
  2917. #ifdef CONFIG_S5P_GPIO_DRVSTR
  2918. s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
  2919. {
  2920. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2921. unsigned int off;
  2922. void __iomem *reg;
  2923. int shift;
  2924. u32 drvstr;
  2925. if (!chip)
  2926. return -EINVAL;
  2927. off = pin - chip->chip.base;
  2928. shift = off * 2;
  2929. reg = chip->base + 0x0C;
  2930. drvstr = __raw_readl(reg);
  2931. drvstr = drvstr >> shift;
  2932. drvstr &= 0x3;
  2933. return (__force s5p_gpio_drvstr_t)drvstr;
  2934. }
  2935. EXPORT_SYMBOL(s5p_gpio_get_drvstr);
  2936. int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
  2937. {
  2938. struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
  2939. unsigned int off;
  2940. void __iomem *reg;
  2941. int shift;
  2942. u32 tmp;
  2943. if (!chip)
  2944. return -EINVAL;
  2945. off = pin - chip->chip.base;
  2946. shift = off * 2;
  2947. reg = chip->base + 0x0C;
  2948. tmp = __raw_readl(reg);
  2949. tmp &= ~(0x3 << shift);
  2950. tmp |= drvstr << shift;
  2951. __raw_writel(tmp, reg);
  2952. return 0;
  2953. }
  2954. EXPORT_SYMBOL(s5p_gpio_set_drvstr);
  2955. #endif /* CONFIG_S5P_GPIO_DRVSTR */
  2956. #ifdef CONFIG_PLAT_S3C24XX
  2957. unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
  2958. {
  2959. unsigned long flags;
  2960. unsigned long misccr;
  2961. local_irq_save(flags);
  2962. misccr = __raw_readl(S3C24XX_MISCCR);
  2963. misccr &= ~clear;
  2964. misccr ^= change;
  2965. __raw_writel(misccr, S3C24XX_MISCCR);
  2966. local_irq_restore(flags);
  2967. return misccr;
  2968. }
  2969. EXPORT_SYMBOL(s3c2410_modify_misccr);
  2970. #endif