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