gpio-samsung.c 68 KB

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