gpio-samsung.c 70 KB

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