gpio.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182
  1. /*
  2. * linux/arch/arm/plat-omap/gpio.c
  3. *
  4. * Support functions for OMAP GPIO
  5. *
  6. * Copyright (C) 2003-2005 Nokia Corporation
  7. * Written by Juha Yrjölä <juha.yrjola@nokia.com>
  8. *
  9. * Copyright (C) 2009 Texas Instruments
  10. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  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/init.h>
  17. #include <linux/module.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/sysdev.h>
  20. #include <linux/err.h>
  21. #include <linux/clk.h>
  22. #include <linux/io.h>
  23. #include <mach/hardware.h>
  24. #include <asm/irq.h>
  25. #include <mach/irqs.h>
  26. #include <mach/gpio.h>
  27. #include <asm/mach/irq.h>
  28. /*
  29. * OMAP1510 GPIO registers
  30. */
  31. #define OMAP1510_GPIO_BASE 0xfffce000
  32. #define OMAP1510_GPIO_DATA_INPUT 0x00
  33. #define OMAP1510_GPIO_DATA_OUTPUT 0x04
  34. #define OMAP1510_GPIO_DIR_CONTROL 0x08
  35. #define OMAP1510_GPIO_INT_CONTROL 0x0c
  36. #define OMAP1510_GPIO_INT_MASK 0x10
  37. #define OMAP1510_GPIO_INT_STATUS 0x14
  38. #define OMAP1510_GPIO_PIN_CONTROL 0x18
  39. #define OMAP1510_IH_GPIO_BASE 64
  40. /*
  41. * OMAP1610 specific GPIO registers
  42. */
  43. #define OMAP1610_GPIO1_BASE 0xfffbe400
  44. #define OMAP1610_GPIO2_BASE 0xfffbec00
  45. #define OMAP1610_GPIO3_BASE 0xfffbb400
  46. #define OMAP1610_GPIO4_BASE 0xfffbbc00
  47. #define OMAP1610_GPIO_REVISION 0x0000
  48. #define OMAP1610_GPIO_SYSCONFIG 0x0010
  49. #define OMAP1610_GPIO_SYSSTATUS 0x0014
  50. #define OMAP1610_GPIO_IRQSTATUS1 0x0018
  51. #define OMAP1610_GPIO_IRQENABLE1 0x001c
  52. #define OMAP1610_GPIO_WAKEUPENABLE 0x0028
  53. #define OMAP1610_GPIO_DATAIN 0x002c
  54. #define OMAP1610_GPIO_DATAOUT 0x0030
  55. #define OMAP1610_GPIO_DIRECTION 0x0034
  56. #define OMAP1610_GPIO_EDGE_CTRL1 0x0038
  57. #define OMAP1610_GPIO_EDGE_CTRL2 0x003c
  58. #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
  59. #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
  60. #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
  61. #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
  62. #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
  63. #define OMAP1610_GPIO_SET_DATAOUT 0x00f0
  64. /*
  65. * OMAP7XX specific GPIO registers
  66. */
  67. #define OMAP7XX_GPIO1_BASE 0xfffbc000
  68. #define OMAP7XX_GPIO2_BASE 0xfffbc800
  69. #define OMAP7XX_GPIO3_BASE 0xfffbd000
  70. #define OMAP7XX_GPIO4_BASE 0xfffbd800
  71. #define OMAP7XX_GPIO5_BASE 0xfffbe000
  72. #define OMAP7XX_GPIO6_BASE 0xfffbe800
  73. #define OMAP7XX_GPIO_DATA_INPUT 0x00
  74. #define OMAP7XX_GPIO_DATA_OUTPUT 0x04
  75. #define OMAP7XX_GPIO_DIR_CONTROL 0x08
  76. #define OMAP7XX_GPIO_INT_CONTROL 0x0c
  77. #define OMAP7XX_GPIO_INT_MASK 0x10
  78. #define OMAP7XX_GPIO_INT_STATUS 0x14
  79. #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
  80. /*
  81. * omap24xx specific GPIO registers
  82. */
  83. #define OMAP242X_GPIO1_BASE 0x48018000
  84. #define OMAP242X_GPIO2_BASE 0x4801a000
  85. #define OMAP242X_GPIO3_BASE 0x4801c000
  86. #define OMAP242X_GPIO4_BASE 0x4801e000
  87. #define OMAP243X_GPIO1_BASE 0x4900C000
  88. #define OMAP243X_GPIO2_BASE 0x4900E000
  89. #define OMAP243X_GPIO3_BASE 0x49010000
  90. #define OMAP243X_GPIO4_BASE 0x49012000
  91. #define OMAP243X_GPIO5_BASE 0x480B6000
  92. #define OMAP24XX_GPIO_REVISION 0x0000
  93. #define OMAP24XX_GPIO_SYSCONFIG 0x0010
  94. #define OMAP24XX_GPIO_SYSSTATUS 0x0014
  95. #define OMAP24XX_GPIO_IRQSTATUS1 0x0018
  96. #define OMAP24XX_GPIO_IRQSTATUS2 0x0028
  97. #define OMAP24XX_GPIO_IRQENABLE2 0x002c
  98. #define OMAP24XX_GPIO_IRQENABLE1 0x001c
  99. #define OMAP24XX_GPIO_WAKE_EN 0x0020
  100. #define OMAP24XX_GPIO_CTRL 0x0030
  101. #define OMAP24XX_GPIO_OE 0x0034
  102. #define OMAP24XX_GPIO_DATAIN 0x0038
  103. #define OMAP24XX_GPIO_DATAOUT 0x003c
  104. #define OMAP24XX_GPIO_LEVELDETECT0 0x0040
  105. #define OMAP24XX_GPIO_LEVELDETECT1 0x0044
  106. #define OMAP24XX_GPIO_RISINGDETECT 0x0048
  107. #define OMAP24XX_GPIO_FALLINGDETECT 0x004c
  108. #define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
  109. #define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
  110. #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
  111. #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
  112. #define OMAP24XX_GPIO_CLEARWKUENA 0x0080
  113. #define OMAP24XX_GPIO_SETWKUENA 0x0084
  114. #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
  115. #define OMAP24XX_GPIO_SETDATAOUT 0x0094
  116. #define OMAP4_GPIO_REVISION 0x0000
  117. #define OMAP4_GPIO_SYSCONFIG 0x0010
  118. #define OMAP4_GPIO_EOI 0x0020
  119. #define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
  120. #define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
  121. #define OMAP4_GPIO_IRQSTATUS0 0x002c
  122. #define OMAP4_GPIO_IRQSTATUS1 0x0030
  123. #define OMAP4_GPIO_IRQSTATUSSET0 0x0034
  124. #define OMAP4_GPIO_IRQSTATUSSET1 0x0038
  125. #define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
  126. #define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
  127. #define OMAP4_GPIO_IRQWAKEN0 0x0044
  128. #define OMAP4_GPIO_IRQWAKEN1 0x0048
  129. #define OMAP4_GPIO_SYSSTATUS 0x0104
  130. #define OMAP4_GPIO_CTRL 0x0130
  131. #define OMAP4_GPIO_OE 0x0134
  132. #define OMAP4_GPIO_DATAIN 0x0138
  133. #define OMAP4_GPIO_DATAOUT 0x013c
  134. #define OMAP4_GPIO_LEVELDETECT0 0x0140
  135. #define OMAP4_GPIO_LEVELDETECT1 0x0144
  136. #define OMAP4_GPIO_RISINGDETECT 0x0148
  137. #define OMAP4_GPIO_FALLINGDETECT 0x014c
  138. #define OMAP4_GPIO_DEBOUNCENABLE 0x0150
  139. #define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
  140. #define OMAP4_GPIO_CLEARDATAOUT 0x0190
  141. #define OMAP4_GPIO_SETDATAOUT 0x0194
  142. /*
  143. * omap34xx specific GPIO registers
  144. */
  145. #define OMAP34XX_GPIO1_BASE 0x48310000
  146. #define OMAP34XX_GPIO2_BASE 0x49050000
  147. #define OMAP34XX_GPIO3_BASE 0x49052000
  148. #define OMAP34XX_GPIO4_BASE 0x49054000
  149. #define OMAP34XX_GPIO5_BASE 0x49056000
  150. #define OMAP34XX_GPIO6_BASE 0x49058000
  151. /*
  152. * OMAP44XX specific GPIO registers
  153. */
  154. #define OMAP44XX_GPIO1_BASE 0x4a310000
  155. #define OMAP44XX_GPIO2_BASE 0x48055000
  156. #define OMAP44XX_GPIO3_BASE 0x48057000
  157. #define OMAP44XX_GPIO4_BASE 0x48059000
  158. #define OMAP44XX_GPIO5_BASE 0x4805B000
  159. #define OMAP44XX_GPIO6_BASE 0x4805D000
  160. struct gpio_bank {
  161. unsigned long pbase;
  162. void __iomem *base;
  163. u16 irq;
  164. u16 virtual_irq_start;
  165. int method;
  166. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
  167. defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
  168. u32 suspend_wakeup;
  169. u32 saved_wakeup;
  170. #endif
  171. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  172. defined(CONFIG_ARCH_OMAP4)
  173. u32 non_wakeup_gpios;
  174. u32 enabled_non_wakeup_gpios;
  175. u32 saved_datain;
  176. u32 saved_fallingdetect;
  177. u32 saved_risingdetect;
  178. #endif
  179. u32 level_mask;
  180. spinlock_t lock;
  181. struct gpio_chip chip;
  182. struct clk *dbck;
  183. };
  184. #define METHOD_MPUIO 0
  185. #define METHOD_GPIO_1510 1
  186. #define METHOD_GPIO_1610 2
  187. #define METHOD_GPIO_7XX 3
  188. #define METHOD_GPIO_24XX 5
  189. #ifdef CONFIG_ARCH_OMAP16XX
  190. static struct gpio_bank gpio_bank_1610[5] = {
  191. { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
  192. METHOD_MPUIO },
  193. { OMAP1610_GPIO1_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
  194. METHOD_GPIO_1610 },
  195. { OMAP1610_GPIO2_BASE, NULL, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16,
  196. METHOD_GPIO_1610 },
  197. { OMAP1610_GPIO3_BASE, NULL, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32,
  198. METHOD_GPIO_1610 },
  199. { OMAP1610_GPIO4_BASE, NULL, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48,
  200. METHOD_GPIO_1610 },
  201. };
  202. #endif
  203. #ifdef CONFIG_ARCH_OMAP15XX
  204. static struct gpio_bank gpio_bank_1510[2] = {
  205. { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
  206. METHOD_MPUIO },
  207. { OMAP1510_GPIO_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
  208. METHOD_GPIO_1510 }
  209. };
  210. #endif
  211. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  212. static struct gpio_bank gpio_bank_7xx[7] = {
  213. { OMAP1_MPUIO_VBASE, NULL, INT_7XX_MPUIO, IH_MPUIO_BASE,
  214. METHOD_MPUIO },
  215. { OMAP7XX_GPIO1_BASE, NULL, INT_7XX_GPIO_BANK1, IH_GPIO_BASE,
  216. METHOD_GPIO_7XX },
  217. { OMAP7XX_GPIO2_BASE, NULL, INT_7XX_GPIO_BANK2, IH_GPIO_BASE + 32,
  218. METHOD_GPIO_7XX },
  219. { OMAP7XX_GPIO3_BASE, NULL, INT_7XX_GPIO_BANK3, IH_GPIO_BASE + 64,
  220. METHOD_GPIO_7XX },
  221. { OMAP7XX_GPIO4_BASE, NULL, INT_7XX_GPIO_BANK4, IH_GPIO_BASE + 96,
  222. METHOD_GPIO_7XX },
  223. { OMAP7XX_GPIO5_BASE, NULL, INT_7XX_GPIO_BANK5, IH_GPIO_BASE + 128,
  224. METHOD_GPIO_7XX },
  225. { OMAP7XX_GPIO6_BASE, NULL, INT_7XX_GPIO_BANK6, IH_GPIO_BASE + 160,
  226. METHOD_GPIO_7XX },
  227. };
  228. #endif
  229. #ifdef CONFIG_ARCH_OMAP24XX
  230. static struct gpio_bank gpio_bank_242x[4] = {
  231. { OMAP242X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
  232. METHOD_GPIO_24XX },
  233. { OMAP242X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
  234. METHOD_GPIO_24XX },
  235. { OMAP242X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
  236. METHOD_GPIO_24XX },
  237. { OMAP242X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
  238. METHOD_GPIO_24XX },
  239. };
  240. static struct gpio_bank gpio_bank_243x[5] = {
  241. { OMAP243X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
  242. METHOD_GPIO_24XX },
  243. { OMAP243X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
  244. METHOD_GPIO_24XX },
  245. { OMAP243X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
  246. METHOD_GPIO_24XX },
  247. { OMAP243X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
  248. METHOD_GPIO_24XX },
  249. { OMAP243X_GPIO5_BASE, NULL, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128,
  250. METHOD_GPIO_24XX },
  251. };
  252. #endif
  253. #ifdef CONFIG_ARCH_OMAP34XX
  254. static struct gpio_bank gpio_bank_34xx[6] = {
  255. { OMAP34XX_GPIO1_BASE, NULL, INT_34XX_GPIO_BANK1, IH_GPIO_BASE,
  256. METHOD_GPIO_24XX },
  257. { OMAP34XX_GPIO2_BASE, NULL, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32,
  258. METHOD_GPIO_24XX },
  259. { OMAP34XX_GPIO3_BASE, NULL, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64,
  260. METHOD_GPIO_24XX },
  261. { OMAP34XX_GPIO4_BASE, NULL, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96,
  262. METHOD_GPIO_24XX },
  263. { OMAP34XX_GPIO5_BASE, NULL, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128,
  264. METHOD_GPIO_24XX },
  265. { OMAP34XX_GPIO6_BASE, NULL, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160,
  266. METHOD_GPIO_24XX },
  267. };
  268. #endif
  269. #ifdef CONFIG_ARCH_OMAP4
  270. static struct gpio_bank gpio_bank_44xx[6] = {
  271. { OMAP44XX_GPIO1_BASE, NULL, INT_44XX_GPIO_BANK1, IH_GPIO_BASE,
  272. METHOD_GPIO_24XX },
  273. { OMAP44XX_GPIO2_BASE, NULL, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32,
  274. METHOD_GPIO_24XX },
  275. { OMAP44XX_GPIO3_BASE, NULL, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64,
  276. METHOD_GPIO_24XX },
  277. { OMAP44XX_GPIO4_BASE, NULL, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96,
  278. METHOD_GPIO_24XX },
  279. { OMAP44XX_GPIO5_BASE, NULL, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128,
  280. METHOD_GPIO_24XX },
  281. { OMAP44XX_GPIO6_BASE, NULL, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160,
  282. METHOD_GPIO_24XX },
  283. };
  284. #endif
  285. static struct gpio_bank *gpio_bank;
  286. static int gpio_bank_count;
  287. static inline struct gpio_bank *get_gpio_bank(int gpio)
  288. {
  289. if (cpu_is_omap15xx()) {
  290. if (OMAP_GPIO_IS_MPUIO(gpio))
  291. return &gpio_bank[0];
  292. return &gpio_bank[1];
  293. }
  294. if (cpu_is_omap16xx()) {
  295. if (OMAP_GPIO_IS_MPUIO(gpio))
  296. return &gpio_bank[0];
  297. return &gpio_bank[1 + (gpio >> 4)];
  298. }
  299. if (cpu_is_omap7xx()) {
  300. if (OMAP_GPIO_IS_MPUIO(gpio))
  301. return &gpio_bank[0];
  302. return &gpio_bank[1 + (gpio >> 5)];
  303. }
  304. if (cpu_is_omap24xx())
  305. return &gpio_bank[gpio >> 5];
  306. if (cpu_is_omap34xx() || cpu_is_omap44xx())
  307. return &gpio_bank[gpio >> 5];
  308. BUG();
  309. return NULL;
  310. }
  311. static inline int get_gpio_index(int gpio)
  312. {
  313. if (cpu_is_omap7xx())
  314. return gpio & 0x1f;
  315. if (cpu_is_omap24xx())
  316. return gpio & 0x1f;
  317. if (cpu_is_omap34xx() || cpu_is_omap44xx())
  318. return gpio & 0x1f;
  319. return gpio & 0x0f;
  320. }
  321. static inline int gpio_valid(int gpio)
  322. {
  323. if (gpio < 0)
  324. return -1;
  325. if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
  326. if (gpio >= OMAP_MAX_GPIO_LINES + 16)
  327. return -1;
  328. return 0;
  329. }
  330. if (cpu_is_omap15xx() && gpio < 16)
  331. return 0;
  332. if ((cpu_is_omap16xx()) && gpio < 64)
  333. return 0;
  334. if (cpu_is_omap7xx() && gpio < 192)
  335. return 0;
  336. if (cpu_is_omap24xx() && gpio < 128)
  337. return 0;
  338. if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
  339. return 0;
  340. return -1;
  341. }
  342. static int check_gpio(int gpio)
  343. {
  344. if (unlikely(gpio_valid(gpio)) < 0) {
  345. printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
  346. dump_stack();
  347. return -1;
  348. }
  349. return 0;
  350. }
  351. static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
  352. {
  353. void __iomem *reg = bank->base;
  354. u32 l;
  355. switch (bank->method) {
  356. #ifdef CONFIG_ARCH_OMAP1
  357. case METHOD_MPUIO:
  358. reg += OMAP_MPUIO_IO_CNTL;
  359. break;
  360. #endif
  361. #ifdef CONFIG_ARCH_OMAP15XX
  362. case METHOD_GPIO_1510:
  363. reg += OMAP1510_GPIO_DIR_CONTROL;
  364. break;
  365. #endif
  366. #ifdef CONFIG_ARCH_OMAP16XX
  367. case METHOD_GPIO_1610:
  368. reg += OMAP1610_GPIO_DIRECTION;
  369. break;
  370. #endif
  371. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  372. case METHOD_GPIO_7XX:
  373. reg += OMAP7XX_GPIO_DIR_CONTROL;
  374. break;
  375. #endif
  376. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  377. case METHOD_GPIO_24XX:
  378. reg += OMAP24XX_GPIO_OE;
  379. break;
  380. #endif
  381. #if defined(CONFIG_ARCH_OMAP4)
  382. case METHOD_GPIO_24XX:
  383. reg += OMAP4_GPIO_OE;
  384. break;
  385. #endif
  386. default:
  387. WARN_ON(1);
  388. return;
  389. }
  390. l = __raw_readl(reg);
  391. if (is_input)
  392. l |= 1 << gpio;
  393. else
  394. l &= ~(1 << gpio);
  395. __raw_writel(l, reg);
  396. }
  397. static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
  398. {
  399. void __iomem *reg = bank->base;
  400. u32 l = 0;
  401. switch (bank->method) {
  402. #ifdef CONFIG_ARCH_OMAP1
  403. case METHOD_MPUIO:
  404. reg += OMAP_MPUIO_OUTPUT;
  405. l = __raw_readl(reg);
  406. if (enable)
  407. l |= 1 << gpio;
  408. else
  409. l &= ~(1 << gpio);
  410. break;
  411. #endif
  412. #ifdef CONFIG_ARCH_OMAP15XX
  413. case METHOD_GPIO_1510:
  414. reg += OMAP1510_GPIO_DATA_OUTPUT;
  415. l = __raw_readl(reg);
  416. if (enable)
  417. l |= 1 << gpio;
  418. else
  419. l &= ~(1 << gpio);
  420. break;
  421. #endif
  422. #ifdef CONFIG_ARCH_OMAP16XX
  423. case METHOD_GPIO_1610:
  424. if (enable)
  425. reg += OMAP1610_GPIO_SET_DATAOUT;
  426. else
  427. reg += OMAP1610_GPIO_CLEAR_DATAOUT;
  428. l = 1 << gpio;
  429. break;
  430. #endif
  431. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  432. case METHOD_GPIO_7XX:
  433. reg += OMAP7XX_GPIO_DATA_OUTPUT;
  434. l = __raw_readl(reg);
  435. if (enable)
  436. l |= 1 << gpio;
  437. else
  438. l &= ~(1 << gpio);
  439. break;
  440. #endif
  441. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  442. case METHOD_GPIO_24XX:
  443. if (enable)
  444. reg += OMAP24XX_GPIO_SETDATAOUT;
  445. else
  446. reg += OMAP24XX_GPIO_CLEARDATAOUT;
  447. l = 1 << gpio;
  448. break;
  449. #endif
  450. #ifdef CONFIG_ARCH_OMAP4
  451. case METHOD_GPIO_24XX:
  452. if (enable)
  453. reg += OMAP4_GPIO_SETDATAOUT;
  454. else
  455. reg += OMAP4_GPIO_CLEARDATAOUT;
  456. l = 1 << gpio;
  457. break;
  458. #endif
  459. default:
  460. WARN_ON(1);
  461. return;
  462. }
  463. __raw_writel(l, reg);
  464. }
  465. static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
  466. {
  467. void __iomem *reg;
  468. if (check_gpio(gpio) < 0)
  469. return -EINVAL;
  470. reg = bank->base;
  471. switch (bank->method) {
  472. #ifdef CONFIG_ARCH_OMAP1
  473. case METHOD_MPUIO:
  474. reg += OMAP_MPUIO_INPUT_LATCH;
  475. break;
  476. #endif
  477. #ifdef CONFIG_ARCH_OMAP15XX
  478. case METHOD_GPIO_1510:
  479. reg += OMAP1510_GPIO_DATA_INPUT;
  480. break;
  481. #endif
  482. #ifdef CONFIG_ARCH_OMAP16XX
  483. case METHOD_GPIO_1610:
  484. reg += OMAP1610_GPIO_DATAIN;
  485. break;
  486. #endif
  487. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  488. case METHOD_GPIO_7XX:
  489. reg += OMAP7XX_GPIO_DATA_INPUT;
  490. break;
  491. #endif
  492. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  493. case METHOD_GPIO_24XX:
  494. reg += OMAP24XX_GPIO_DATAIN;
  495. break;
  496. #endif
  497. #ifdef CONFIG_ARCH_OMAP4
  498. case METHOD_GPIO_24XX:
  499. reg += OMAP4_GPIO_DATAIN;
  500. break;
  501. #endif
  502. default:
  503. return -EINVAL;
  504. }
  505. return (__raw_readl(reg)
  506. & (1 << get_gpio_index(gpio))) != 0;
  507. }
  508. static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
  509. {
  510. void __iomem *reg;
  511. if (check_gpio(gpio) < 0)
  512. return -EINVAL;
  513. reg = bank->base;
  514. switch (bank->method) {
  515. #ifdef CONFIG_ARCH_OMAP1
  516. case METHOD_MPUIO:
  517. reg += OMAP_MPUIO_OUTPUT;
  518. break;
  519. #endif
  520. #ifdef CONFIG_ARCH_OMAP15XX
  521. case METHOD_GPIO_1510:
  522. reg += OMAP1510_GPIO_DATA_OUTPUT;
  523. break;
  524. #endif
  525. #ifdef CONFIG_ARCH_OMAP16XX
  526. case METHOD_GPIO_1610:
  527. reg += OMAP1610_GPIO_DATAOUT;
  528. break;
  529. #endif
  530. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  531. case METHOD_GPIO_7XX:
  532. reg += OMAP7XX_GPIO_DATA_OUTPUT;
  533. break;
  534. #endif
  535. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  536. defined(CONFIG_ARCH_OMAP4)
  537. case METHOD_GPIO_24XX:
  538. reg += OMAP24XX_GPIO_DATAOUT;
  539. break;
  540. #endif
  541. default:
  542. return -EINVAL;
  543. }
  544. return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
  545. }
  546. #define MOD_REG_BIT(reg, bit_mask, set) \
  547. do { \
  548. int l = __raw_readl(base + reg); \
  549. if (set) l |= bit_mask; \
  550. else l &= ~bit_mask; \
  551. __raw_writel(l, base + reg); \
  552. } while(0)
  553. void omap_set_gpio_debounce(int gpio, int enable)
  554. {
  555. struct gpio_bank *bank;
  556. void __iomem *reg;
  557. unsigned long flags;
  558. u32 val, l = 1 << get_gpio_index(gpio);
  559. if (cpu_class_is_omap1())
  560. return;
  561. bank = get_gpio_bank(gpio);
  562. reg = bank->base;
  563. #ifdef CONFIG_ARCH_OMAP4
  564. reg += OMAP4_GPIO_DEBOUNCENABLE;
  565. #else
  566. reg += OMAP24XX_GPIO_DEBOUNCE_EN;
  567. #endif
  568. spin_lock_irqsave(&bank->lock, flags);
  569. val = __raw_readl(reg);
  570. if (enable && !(val & l))
  571. val |= l;
  572. else if (!enable && (val & l))
  573. val &= ~l;
  574. else
  575. goto done;
  576. if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
  577. if (enable)
  578. clk_enable(bank->dbck);
  579. else
  580. clk_disable(bank->dbck);
  581. }
  582. __raw_writel(val, reg);
  583. done:
  584. spin_unlock_irqrestore(&bank->lock, flags);
  585. }
  586. EXPORT_SYMBOL(omap_set_gpio_debounce);
  587. void omap_set_gpio_debounce_time(int gpio, int enc_time)
  588. {
  589. struct gpio_bank *bank;
  590. void __iomem *reg;
  591. if (cpu_class_is_omap1())
  592. return;
  593. bank = get_gpio_bank(gpio);
  594. reg = bank->base;
  595. enc_time &= 0xff;
  596. #ifdef CONFIG_ARCH_OMAP4
  597. reg += OMAP4_GPIO_DEBOUNCINGTIME;
  598. #else
  599. reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
  600. #endif
  601. __raw_writel(enc_time, reg);
  602. }
  603. EXPORT_SYMBOL(omap_set_gpio_debounce_time);
  604. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  605. defined(CONFIG_ARCH_OMAP4)
  606. static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
  607. int trigger)
  608. {
  609. void __iomem *base = bank->base;
  610. u32 gpio_bit = 1 << gpio;
  611. u32 val;
  612. if (cpu_is_omap44xx()) {
  613. MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
  614. trigger & IRQ_TYPE_LEVEL_LOW);
  615. MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
  616. trigger & IRQ_TYPE_LEVEL_HIGH);
  617. MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
  618. trigger & IRQ_TYPE_EDGE_RISING);
  619. MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
  620. trigger & IRQ_TYPE_EDGE_FALLING);
  621. } else {
  622. MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
  623. trigger & IRQ_TYPE_LEVEL_LOW);
  624. MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
  625. trigger & IRQ_TYPE_LEVEL_HIGH);
  626. MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
  627. trigger & IRQ_TYPE_EDGE_RISING);
  628. MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
  629. trigger & IRQ_TYPE_EDGE_FALLING);
  630. }
  631. if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
  632. if (cpu_is_omap44xx()) {
  633. if (trigger != 0)
  634. __raw_writel(1 << gpio, bank->base+
  635. OMAP4_GPIO_IRQWAKEN0);
  636. else {
  637. val = __raw_readl(bank->base +
  638. OMAP4_GPIO_IRQWAKEN0);
  639. __raw_writel(val & (~(1 << gpio)), bank->base +
  640. OMAP4_GPIO_IRQWAKEN0);
  641. }
  642. } else {
  643. if (trigger != 0)
  644. __raw_writel(1 << gpio, bank->base
  645. + OMAP24XX_GPIO_SETWKUENA);
  646. else
  647. __raw_writel(1 << gpio, bank->base
  648. + OMAP24XX_GPIO_CLEARWKUENA);
  649. }
  650. } else {
  651. if (trigger != 0)
  652. bank->enabled_non_wakeup_gpios |= gpio_bit;
  653. else
  654. bank->enabled_non_wakeup_gpios &= ~gpio_bit;
  655. }
  656. if (cpu_is_omap44xx()) {
  657. bank->level_mask =
  658. __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
  659. __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
  660. } else {
  661. bank->level_mask =
  662. __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
  663. __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
  664. }
  665. }
  666. #endif
  667. static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
  668. {
  669. void __iomem *reg = bank->base;
  670. u32 l = 0;
  671. switch (bank->method) {
  672. #ifdef CONFIG_ARCH_OMAP1
  673. case METHOD_MPUIO:
  674. reg += OMAP_MPUIO_GPIO_INT_EDGE;
  675. l = __raw_readl(reg);
  676. if (trigger & IRQ_TYPE_EDGE_RISING)
  677. l |= 1 << gpio;
  678. else if (trigger & IRQ_TYPE_EDGE_FALLING)
  679. l &= ~(1 << gpio);
  680. else
  681. goto bad;
  682. break;
  683. #endif
  684. #ifdef CONFIG_ARCH_OMAP15XX
  685. case METHOD_GPIO_1510:
  686. reg += OMAP1510_GPIO_INT_CONTROL;
  687. l = __raw_readl(reg);
  688. if (trigger & IRQ_TYPE_EDGE_RISING)
  689. l |= 1 << gpio;
  690. else if (trigger & IRQ_TYPE_EDGE_FALLING)
  691. l &= ~(1 << gpio);
  692. else
  693. goto bad;
  694. break;
  695. #endif
  696. #ifdef CONFIG_ARCH_OMAP16XX
  697. case METHOD_GPIO_1610:
  698. if (gpio & 0x08)
  699. reg += OMAP1610_GPIO_EDGE_CTRL2;
  700. else
  701. reg += OMAP1610_GPIO_EDGE_CTRL1;
  702. gpio &= 0x07;
  703. l = __raw_readl(reg);
  704. l &= ~(3 << (gpio << 1));
  705. if (trigger & IRQ_TYPE_EDGE_RISING)
  706. l |= 2 << (gpio << 1);
  707. if (trigger & IRQ_TYPE_EDGE_FALLING)
  708. l |= 1 << (gpio << 1);
  709. if (trigger)
  710. /* Enable wake-up during idle for dynamic tick */
  711. __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
  712. else
  713. __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
  714. break;
  715. #endif
  716. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  717. case METHOD_GPIO_7XX:
  718. reg += OMAP7XX_GPIO_INT_CONTROL;
  719. l = __raw_readl(reg);
  720. if (trigger & IRQ_TYPE_EDGE_RISING)
  721. l |= 1 << gpio;
  722. else if (trigger & IRQ_TYPE_EDGE_FALLING)
  723. l &= ~(1 << gpio);
  724. else
  725. goto bad;
  726. break;
  727. #endif
  728. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  729. defined(CONFIG_ARCH_OMAP4)
  730. case METHOD_GPIO_24XX:
  731. set_24xx_gpio_triggering(bank, gpio, trigger);
  732. break;
  733. #endif
  734. default:
  735. goto bad;
  736. }
  737. __raw_writel(l, reg);
  738. return 0;
  739. bad:
  740. return -EINVAL;
  741. }
  742. static int gpio_irq_type(unsigned irq, unsigned type)
  743. {
  744. struct gpio_bank *bank;
  745. unsigned gpio;
  746. int retval;
  747. unsigned long flags;
  748. if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
  749. gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
  750. else
  751. gpio = irq - IH_GPIO_BASE;
  752. if (check_gpio(gpio) < 0)
  753. return -EINVAL;
  754. if (type & ~IRQ_TYPE_SENSE_MASK)
  755. return -EINVAL;
  756. /* OMAP1 allows only only edge triggering */
  757. if (!cpu_class_is_omap2()
  758. && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
  759. return -EINVAL;
  760. bank = get_irq_chip_data(irq);
  761. spin_lock_irqsave(&bank->lock, flags);
  762. retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
  763. if (retval == 0) {
  764. irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
  765. irq_desc[irq].status |= type;
  766. }
  767. spin_unlock_irqrestore(&bank->lock, flags);
  768. if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  769. __set_irq_handler_unlocked(irq, handle_level_irq);
  770. else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
  771. __set_irq_handler_unlocked(irq, handle_edge_irq);
  772. return retval;
  773. }
  774. static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
  775. {
  776. void __iomem *reg = bank->base;
  777. switch (bank->method) {
  778. #ifdef CONFIG_ARCH_OMAP1
  779. case METHOD_MPUIO:
  780. /* MPUIO irqstatus is reset by reading the status register,
  781. * so do nothing here */
  782. return;
  783. #endif
  784. #ifdef CONFIG_ARCH_OMAP15XX
  785. case METHOD_GPIO_1510:
  786. reg += OMAP1510_GPIO_INT_STATUS;
  787. break;
  788. #endif
  789. #ifdef CONFIG_ARCH_OMAP16XX
  790. case METHOD_GPIO_1610:
  791. reg += OMAP1610_GPIO_IRQSTATUS1;
  792. break;
  793. #endif
  794. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  795. case METHOD_GPIO_7XX:
  796. reg += OMAP7XX_GPIO_INT_STATUS;
  797. break;
  798. #endif
  799. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  800. case METHOD_GPIO_24XX:
  801. reg += OMAP24XX_GPIO_IRQSTATUS1;
  802. break;
  803. #endif
  804. #if defined(CONFIG_ARCH_OMAP4)
  805. case METHOD_GPIO_24XX:
  806. reg += OMAP4_GPIO_IRQSTATUS0;
  807. break;
  808. #endif
  809. default:
  810. WARN_ON(1);
  811. return;
  812. }
  813. __raw_writel(gpio_mask, reg);
  814. /* Workaround for clearing DSP GPIO interrupts to allow retention */
  815. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  816. reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
  817. #endif
  818. #if defined(CONFIG_ARCH_OMAP4)
  819. reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
  820. #endif
  821. if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
  822. __raw_writel(gpio_mask, reg);
  823. /* Flush posted write for the irq status to avoid spurious interrupts */
  824. __raw_readl(reg);
  825. }
  826. }
  827. static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
  828. {
  829. _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
  830. }
  831. static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
  832. {
  833. void __iomem *reg = bank->base;
  834. int inv = 0;
  835. u32 l;
  836. u32 mask;
  837. switch (bank->method) {
  838. #ifdef CONFIG_ARCH_OMAP1
  839. case METHOD_MPUIO:
  840. reg += OMAP_MPUIO_GPIO_MASKIT;
  841. mask = 0xffff;
  842. inv = 1;
  843. break;
  844. #endif
  845. #ifdef CONFIG_ARCH_OMAP15XX
  846. case METHOD_GPIO_1510:
  847. reg += OMAP1510_GPIO_INT_MASK;
  848. mask = 0xffff;
  849. inv = 1;
  850. break;
  851. #endif
  852. #ifdef CONFIG_ARCH_OMAP16XX
  853. case METHOD_GPIO_1610:
  854. reg += OMAP1610_GPIO_IRQENABLE1;
  855. mask = 0xffff;
  856. break;
  857. #endif
  858. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  859. case METHOD_GPIO_7XX:
  860. reg += OMAP7XX_GPIO_INT_MASK;
  861. mask = 0xffffffff;
  862. inv = 1;
  863. break;
  864. #endif
  865. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  866. case METHOD_GPIO_24XX:
  867. reg += OMAP24XX_GPIO_IRQENABLE1;
  868. mask = 0xffffffff;
  869. break;
  870. #endif
  871. #if defined(CONFIG_ARCH_OMAP4)
  872. case METHOD_GPIO_24XX:
  873. reg += OMAP4_GPIO_IRQSTATUSSET0;
  874. mask = 0xffffffff;
  875. break;
  876. #endif
  877. default:
  878. WARN_ON(1);
  879. return 0;
  880. }
  881. l = __raw_readl(reg);
  882. if (inv)
  883. l = ~l;
  884. l &= mask;
  885. return l;
  886. }
  887. static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
  888. {
  889. void __iomem *reg = bank->base;
  890. u32 l;
  891. switch (bank->method) {
  892. #ifdef CONFIG_ARCH_OMAP1
  893. case METHOD_MPUIO:
  894. reg += OMAP_MPUIO_GPIO_MASKIT;
  895. l = __raw_readl(reg);
  896. if (enable)
  897. l &= ~(gpio_mask);
  898. else
  899. l |= gpio_mask;
  900. break;
  901. #endif
  902. #ifdef CONFIG_ARCH_OMAP15XX
  903. case METHOD_GPIO_1510:
  904. reg += OMAP1510_GPIO_INT_MASK;
  905. l = __raw_readl(reg);
  906. if (enable)
  907. l &= ~(gpio_mask);
  908. else
  909. l |= gpio_mask;
  910. break;
  911. #endif
  912. #ifdef CONFIG_ARCH_OMAP16XX
  913. case METHOD_GPIO_1610:
  914. if (enable)
  915. reg += OMAP1610_GPIO_SET_IRQENABLE1;
  916. else
  917. reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
  918. l = gpio_mask;
  919. break;
  920. #endif
  921. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  922. case METHOD_GPIO_7XX:
  923. reg += OMAP7XX_GPIO_INT_MASK;
  924. l = __raw_readl(reg);
  925. if (enable)
  926. l &= ~(gpio_mask);
  927. else
  928. l |= gpio_mask;
  929. break;
  930. #endif
  931. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  932. case METHOD_GPIO_24XX:
  933. if (enable)
  934. reg += OMAP24XX_GPIO_SETIRQENABLE1;
  935. else
  936. reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
  937. l = gpio_mask;
  938. break;
  939. #endif
  940. #ifdef CONFIG_ARCH_OMAP4
  941. case METHOD_GPIO_24XX:
  942. if (enable)
  943. reg += OMAP4_GPIO_IRQSTATUSSET0;
  944. else
  945. reg += OMAP4_GPIO_IRQSTATUSCLR0;
  946. l = gpio_mask;
  947. break;
  948. #endif
  949. default:
  950. WARN_ON(1);
  951. return;
  952. }
  953. __raw_writel(l, reg);
  954. }
  955. static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
  956. {
  957. _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
  958. }
  959. /*
  960. * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
  961. * 1510 does not seem to have a wake-up register. If JTAG is connected
  962. * to the target, system will wake up always on GPIO events. While
  963. * system is running all registered GPIO interrupts need to have wake-up
  964. * enabled. When system is suspended, only selected GPIO interrupts need
  965. * to have wake-up enabled.
  966. */
  967. static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
  968. {
  969. unsigned long flags;
  970. switch (bank->method) {
  971. #ifdef CONFIG_ARCH_OMAP16XX
  972. case METHOD_MPUIO:
  973. case METHOD_GPIO_1610:
  974. spin_lock_irqsave(&bank->lock, flags);
  975. if (enable)
  976. bank->suspend_wakeup |= (1 << gpio);
  977. else
  978. bank->suspend_wakeup &= ~(1 << gpio);
  979. spin_unlock_irqrestore(&bank->lock, flags);
  980. return 0;
  981. #endif
  982. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  983. defined(CONFIG_ARCH_OMAP4)
  984. case METHOD_GPIO_24XX:
  985. if (bank->non_wakeup_gpios & (1 << gpio)) {
  986. printk(KERN_ERR "Unable to modify wakeup on "
  987. "non-wakeup GPIO%d\n",
  988. (bank - gpio_bank) * 32 + gpio);
  989. return -EINVAL;
  990. }
  991. spin_lock_irqsave(&bank->lock, flags);
  992. if (enable)
  993. bank->suspend_wakeup |= (1 << gpio);
  994. else
  995. bank->suspend_wakeup &= ~(1 << gpio);
  996. spin_unlock_irqrestore(&bank->lock, flags);
  997. return 0;
  998. #endif
  999. default:
  1000. printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
  1001. bank->method);
  1002. return -EINVAL;
  1003. }
  1004. }
  1005. static void _reset_gpio(struct gpio_bank *bank, int gpio)
  1006. {
  1007. _set_gpio_direction(bank, get_gpio_index(gpio), 1);
  1008. _set_gpio_irqenable(bank, gpio, 0);
  1009. _clear_gpio_irqstatus(bank, gpio);
  1010. _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
  1011. }
  1012. /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
  1013. static int gpio_wake_enable(unsigned int irq, unsigned int enable)
  1014. {
  1015. unsigned int gpio = irq - IH_GPIO_BASE;
  1016. struct gpio_bank *bank;
  1017. int retval;
  1018. if (check_gpio(gpio) < 0)
  1019. return -ENODEV;
  1020. bank = get_irq_chip_data(irq);
  1021. retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
  1022. return retval;
  1023. }
  1024. static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
  1025. {
  1026. struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
  1027. unsigned long flags;
  1028. spin_lock_irqsave(&bank->lock, flags);
  1029. /* Set trigger to none. You need to enable the desired trigger with
  1030. * request_irq() or set_irq_type().
  1031. */
  1032. _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
  1033. #ifdef CONFIG_ARCH_OMAP15XX
  1034. if (bank->method == METHOD_GPIO_1510) {
  1035. void __iomem *reg;
  1036. /* Claim the pin for MPU */
  1037. reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
  1038. __raw_writel(__raw_readl(reg) | (1 << offset), reg);
  1039. }
  1040. #endif
  1041. spin_unlock_irqrestore(&bank->lock, flags);
  1042. return 0;
  1043. }
  1044. static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
  1045. {
  1046. struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
  1047. unsigned long flags;
  1048. spin_lock_irqsave(&bank->lock, flags);
  1049. #ifdef CONFIG_ARCH_OMAP16XX
  1050. if (bank->method == METHOD_GPIO_1610) {
  1051. /* Disable wake-up during idle for dynamic tick */
  1052. void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
  1053. __raw_writel(1 << offset, reg);
  1054. }
  1055. #endif
  1056. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  1057. defined(CONFIG_ARCH_OMAP4)
  1058. if (bank->method == METHOD_GPIO_24XX) {
  1059. /* Disable wake-up during idle for dynamic tick */
  1060. void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
  1061. __raw_writel(1 << offset, reg);
  1062. }
  1063. #endif
  1064. _reset_gpio(bank, bank->chip.base + offset);
  1065. spin_unlock_irqrestore(&bank->lock, flags);
  1066. }
  1067. /*
  1068. * We need to unmask the GPIO bank interrupt as soon as possible to
  1069. * avoid missing GPIO interrupts for other lines in the bank.
  1070. * Then we need to mask-read-clear-unmask the triggered GPIO lines
  1071. * in the bank to avoid missing nested interrupts for a GPIO line.
  1072. * If we wait to unmask individual GPIO lines in the bank after the
  1073. * line's interrupt handler has been run, we may miss some nested
  1074. * interrupts.
  1075. */
  1076. static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
  1077. {
  1078. void __iomem *isr_reg = NULL;
  1079. u32 isr;
  1080. unsigned int gpio_irq;
  1081. struct gpio_bank *bank;
  1082. u32 retrigger = 0;
  1083. int unmasked = 0;
  1084. desc->chip->ack(irq);
  1085. bank = get_irq_data(irq);
  1086. #ifdef CONFIG_ARCH_OMAP1
  1087. if (bank->method == METHOD_MPUIO)
  1088. isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
  1089. #endif
  1090. #ifdef CONFIG_ARCH_OMAP15XX
  1091. if (bank->method == METHOD_GPIO_1510)
  1092. isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
  1093. #endif
  1094. #if defined(CONFIG_ARCH_OMAP16XX)
  1095. if (bank->method == METHOD_GPIO_1610)
  1096. isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
  1097. #endif
  1098. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  1099. if (bank->method == METHOD_GPIO_7XX)
  1100. isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
  1101. #endif
  1102. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  1103. if (bank->method == METHOD_GPIO_24XX)
  1104. isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
  1105. #endif
  1106. #if defined(CONFIG_ARCH_OMAP4)
  1107. if (bank->method == METHOD_GPIO_24XX)
  1108. isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
  1109. #endif
  1110. while(1) {
  1111. u32 isr_saved, level_mask = 0;
  1112. u32 enabled;
  1113. enabled = _get_gpio_irqbank_mask(bank);
  1114. isr_saved = isr = __raw_readl(isr_reg) & enabled;
  1115. if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
  1116. isr &= 0x0000ffff;
  1117. if (cpu_class_is_omap2()) {
  1118. level_mask = bank->level_mask & enabled;
  1119. }
  1120. /* clear edge sensitive interrupts before handler(s) are
  1121. called so that we don't miss any interrupt occurred while
  1122. executing them */
  1123. _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
  1124. _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
  1125. _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
  1126. /* if there is only edge sensitive GPIO pin interrupts
  1127. configured, we could unmask GPIO bank interrupt immediately */
  1128. if (!level_mask && !unmasked) {
  1129. unmasked = 1;
  1130. desc->chip->unmask(irq);
  1131. }
  1132. isr |= retrigger;
  1133. retrigger = 0;
  1134. if (!isr)
  1135. break;
  1136. gpio_irq = bank->virtual_irq_start;
  1137. for (; isr != 0; isr >>= 1, gpio_irq++) {
  1138. if (!(isr & 1))
  1139. continue;
  1140. generic_handle_irq(gpio_irq);
  1141. }
  1142. }
  1143. /* if bank has any level sensitive GPIO pin interrupt
  1144. configured, we must unmask the bank interrupt only after
  1145. handler(s) are executed in order to avoid spurious bank
  1146. interrupt */
  1147. if (!unmasked)
  1148. desc->chip->unmask(irq);
  1149. }
  1150. static void gpio_irq_shutdown(unsigned int irq)
  1151. {
  1152. unsigned int gpio = irq - IH_GPIO_BASE;
  1153. struct gpio_bank *bank = get_irq_chip_data(irq);
  1154. _reset_gpio(bank, gpio);
  1155. }
  1156. static void gpio_ack_irq(unsigned int irq)
  1157. {
  1158. unsigned int gpio = irq - IH_GPIO_BASE;
  1159. struct gpio_bank *bank = get_irq_chip_data(irq);
  1160. _clear_gpio_irqstatus(bank, gpio);
  1161. }
  1162. static void gpio_mask_irq(unsigned int irq)
  1163. {
  1164. unsigned int gpio = irq - IH_GPIO_BASE;
  1165. struct gpio_bank *bank = get_irq_chip_data(irq);
  1166. _set_gpio_irqenable(bank, gpio, 0);
  1167. _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
  1168. }
  1169. static void gpio_unmask_irq(unsigned int irq)
  1170. {
  1171. unsigned int gpio = irq - IH_GPIO_BASE;
  1172. struct gpio_bank *bank = get_irq_chip_data(irq);
  1173. unsigned int irq_mask = 1 << get_gpio_index(gpio);
  1174. struct irq_desc *desc = irq_to_desc(irq);
  1175. u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
  1176. if (trigger)
  1177. _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
  1178. /* For level-triggered GPIOs, the clearing must be done after
  1179. * the HW source is cleared, thus after the handler has run */
  1180. if (bank->level_mask & irq_mask) {
  1181. _set_gpio_irqenable(bank, gpio, 0);
  1182. _clear_gpio_irqstatus(bank, gpio);
  1183. }
  1184. _set_gpio_irqenable(bank, gpio, 1);
  1185. }
  1186. static struct irq_chip gpio_irq_chip = {
  1187. .name = "GPIO",
  1188. .shutdown = gpio_irq_shutdown,
  1189. .ack = gpio_ack_irq,
  1190. .mask = gpio_mask_irq,
  1191. .unmask = gpio_unmask_irq,
  1192. .set_type = gpio_irq_type,
  1193. .set_wake = gpio_wake_enable,
  1194. };
  1195. /*---------------------------------------------------------------------*/
  1196. #ifdef CONFIG_ARCH_OMAP1
  1197. /* MPUIO uses the always-on 32k clock */
  1198. static void mpuio_ack_irq(unsigned int irq)
  1199. {
  1200. /* The ISR is reset automatically, so do nothing here. */
  1201. }
  1202. static void mpuio_mask_irq(unsigned int irq)
  1203. {
  1204. unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
  1205. struct gpio_bank *bank = get_irq_chip_data(irq);
  1206. _set_gpio_irqenable(bank, gpio, 0);
  1207. }
  1208. static void mpuio_unmask_irq(unsigned int irq)
  1209. {
  1210. unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
  1211. struct gpio_bank *bank = get_irq_chip_data(irq);
  1212. _set_gpio_irqenable(bank, gpio, 1);
  1213. }
  1214. static struct irq_chip mpuio_irq_chip = {
  1215. .name = "MPUIO",
  1216. .ack = mpuio_ack_irq,
  1217. .mask = mpuio_mask_irq,
  1218. .unmask = mpuio_unmask_irq,
  1219. .set_type = gpio_irq_type,
  1220. #ifdef CONFIG_ARCH_OMAP16XX
  1221. /* REVISIT: assuming only 16xx supports MPUIO wake events */
  1222. .set_wake = gpio_wake_enable,
  1223. #endif
  1224. };
  1225. #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
  1226. #ifdef CONFIG_ARCH_OMAP16XX
  1227. #include <linux/platform_device.h>
  1228. static int omap_mpuio_suspend_noirq(struct device *dev)
  1229. {
  1230. struct platform_device *pdev = to_platform_device(dev);
  1231. struct gpio_bank *bank = platform_get_drvdata(pdev);
  1232. void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
  1233. unsigned long flags;
  1234. spin_lock_irqsave(&bank->lock, flags);
  1235. bank->saved_wakeup = __raw_readl(mask_reg);
  1236. __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
  1237. spin_unlock_irqrestore(&bank->lock, flags);
  1238. return 0;
  1239. }
  1240. static int omap_mpuio_resume_noirq(struct device *dev)
  1241. {
  1242. struct platform_device *pdev = to_platform_device(dev);
  1243. struct gpio_bank *bank = platform_get_drvdata(pdev);
  1244. void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
  1245. unsigned long flags;
  1246. spin_lock_irqsave(&bank->lock, flags);
  1247. __raw_writel(bank->saved_wakeup, mask_reg);
  1248. spin_unlock_irqrestore(&bank->lock, flags);
  1249. return 0;
  1250. }
  1251. static struct dev_pm_ops omap_mpuio_dev_pm_ops = {
  1252. .suspend_noirq = omap_mpuio_suspend_noirq,
  1253. .resume_noirq = omap_mpuio_resume_noirq,
  1254. };
  1255. /* use platform_driver for this, now that there's no longer any
  1256. * point to sys_device (other than not disturbing old code).
  1257. */
  1258. static struct platform_driver omap_mpuio_driver = {
  1259. .driver = {
  1260. .name = "mpuio",
  1261. .pm = &omap_mpuio_dev_pm_ops,
  1262. },
  1263. };
  1264. static struct platform_device omap_mpuio_device = {
  1265. .name = "mpuio",
  1266. .id = -1,
  1267. .dev = {
  1268. .driver = &omap_mpuio_driver.driver,
  1269. }
  1270. /* could list the /proc/iomem resources */
  1271. };
  1272. static inline void mpuio_init(void)
  1273. {
  1274. platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
  1275. if (platform_driver_register(&omap_mpuio_driver) == 0)
  1276. (void) platform_device_register(&omap_mpuio_device);
  1277. }
  1278. #else
  1279. static inline void mpuio_init(void) {}
  1280. #endif /* 16xx */
  1281. #else
  1282. extern struct irq_chip mpuio_irq_chip;
  1283. #define bank_is_mpuio(bank) 0
  1284. static inline void mpuio_init(void) {}
  1285. #endif
  1286. /*---------------------------------------------------------------------*/
  1287. /* REVISIT these are stupid implementations! replace by ones that
  1288. * don't switch on METHOD_* and which mostly avoid spinlocks
  1289. */
  1290. static int gpio_input(struct gpio_chip *chip, unsigned offset)
  1291. {
  1292. struct gpio_bank *bank;
  1293. unsigned long flags;
  1294. bank = container_of(chip, struct gpio_bank, chip);
  1295. spin_lock_irqsave(&bank->lock, flags);
  1296. _set_gpio_direction(bank, offset, 1);
  1297. spin_unlock_irqrestore(&bank->lock, flags);
  1298. return 0;
  1299. }
  1300. static int gpio_is_input(struct gpio_bank *bank, int mask)
  1301. {
  1302. void __iomem *reg = bank->base;
  1303. switch (bank->method) {
  1304. case METHOD_MPUIO:
  1305. reg += OMAP_MPUIO_IO_CNTL;
  1306. break;
  1307. case METHOD_GPIO_1510:
  1308. reg += OMAP1510_GPIO_DIR_CONTROL;
  1309. break;
  1310. case METHOD_GPIO_1610:
  1311. reg += OMAP1610_GPIO_DIRECTION;
  1312. break;
  1313. case METHOD_GPIO_7XX:
  1314. reg += OMAP7XX_GPIO_DIR_CONTROL;
  1315. break;
  1316. case METHOD_GPIO_24XX:
  1317. reg += OMAP24XX_GPIO_OE;
  1318. break;
  1319. }
  1320. return __raw_readl(reg) & mask;
  1321. }
  1322. static int gpio_get(struct gpio_chip *chip, unsigned offset)
  1323. {
  1324. struct gpio_bank *bank;
  1325. void __iomem *reg;
  1326. int gpio;
  1327. u32 mask;
  1328. gpio = chip->base + offset;
  1329. bank = get_gpio_bank(gpio);
  1330. reg = bank->base;
  1331. mask = 1 << get_gpio_index(gpio);
  1332. if (gpio_is_input(bank, mask))
  1333. return _get_gpio_datain(bank, gpio);
  1334. else
  1335. return _get_gpio_dataout(bank, gpio);
  1336. }
  1337. static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
  1338. {
  1339. struct gpio_bank *bank;
  1340. unsigned long flags;
  1341. bank = container_of(chip, struct gpio_bank, chip);
  1342. spin_lock_irqsave(&bank->lock, flags);
  1343. _set_gpio_dataout(bank, offset, value);
  1344. _set_gpio_direction(bank, offset, 0);
  1345. spin_unlock_irqrestore(&bank->lock, flags);
  1346. return 0;
  1347. }
  1348. static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  1349. {
  1350. struct gpio_bank *bank;
  1351. unsigned long flags;
  1352. bank = container_of(chip, struct gpio_bank, chip);
  1353. spin_lock_irqsave(&bank->lock, flags);
  1354. _set_gpio_dataout(bank, offset, value);
  1355. spin_unlock_irqrestore(&bank->lock, flags);
  1356. }
  1357. static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
  1358. {
  1359. struct gpio_bank *bank;
  1360. bank = container_of(chip, struct gpio_bank, chip);
  1361. return bank->virtual_irq_start + offset;
  1362. }
  1363. /*---------------------------------------------------------------------*/
  1364. static int initialized;
  1365. #if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
  1366. static struct clk * gpio_ick;
  1367. #endif
  1368. #if defined(CONFIG_ARCH_OMAP2)
  1369. static struct clk * gpio_fck;
  1370. #endif
  1371. #if defined(CONFIG_ARCH_OMAP2430)
  1372. static struct clk * gpio5_ick;
  1373. static struct clk * gpio5_fck;
  1374. #endif
  1375. #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
  1376. static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
  1377. #endif
  1378. static void __init omap_gpio_show_rev(void)
  1379. {
  1380. u32 rev;
  1381. if (cpu_is_omap16xx())
  1382. rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
  1383. else if (cpu_is_omap24xx() || cpu_is_omap34xx())
  1384. rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
  1385. else if (cpu_is_omap44xx())
  1386. rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
  1387. else
  1388. return;
  1389. printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
  1390. (rev >> 4) & 0x0f, rev & 0x0f);
  1391. }
  1392. /* This lock class tells lockdep that GPIO irqs are in a different
  1393. * category than their parents, so it won't report false recursion.
  1394. */
  1395. static struct lock_class_key gpio_lock_class;
  1396. static int __init _omap_gpio_init(void)
  1397. {
  1398. int i;
  1399. int gpio = 0;
  1400. struct gpio_bank *bank;
  1401. int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
  1402. char clk_name[11];
  1403. initialized = 1;
  1404. #if defined(CONFIG_ARCH_OMAP1)
  1405. if (cpu_is_omap15xx()) {
  1406. gpio_ick = clk_get(NULL, "arm_gpio_ck");
  1407. if (IS_ERR(gpio_ick))
  1408. printk("Could not get arm_gpio_ck\n");
  1409. else
  1410. clk_enable(gpio_ick);
  1411. }
  1412. #endif
  1413. #if defined(CONFIG_ARCH_OMAP2)
  1414. if (cpu_class_is_omap2()) {
  1415. gpio_ick = clk_get(NULL, "gpios_ick");
  1416. if (IS_ERR(gpio_ick))
  1417. printk("Could not get gpios_ick\n");
  1418. else
  1419. clk_enable(gpio_ick);
  1420. gpio_fck = clk_get(NULL, "gpios_fck");
  1421. if (IS_ERR(gpio_fck))
  1422. printk("Could not get gpios_fck\n");
  1423. else
  1424. clk_enable(gpio_fck);
  1425. /*
  1426. * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
  1427. */
  1428. #if defined(CONFIG_ARCH_OMAP2430)
  1429. if (cpu_is_omap2430()) {
  1430. gpio5_ick = clk_get(NULL, "gpio5_ick");
  1431. if (IS_ERR(gpio5_ick))
  1432. printk("Could not get gpio5_ick\n");
  1433. else
  1434. clk_enable(gpio5_ick);
  1435. gpio5_fck = clk_get(NULL, "gpio5_fck");
  1436. if (IS_ERR(gpio5_fck))
  1437. printk("Could not get gpio5_fck\n");
  1438. else
  1439. clk_enable(gpio5_fck);
  1440. }
  1441. #endif
  1442. }
  1443. #endif
  1444. #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
  1445. if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
  1446. for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
  1447. sprintf(clk_name, "gpio%d_ick", i + 1);
  1448. gpio_iclks[i] = clk_get(NULL, clk_name);
  1449. if (IS_ERR(gpio_iclks[i]))
  1450. printk(KERN_ERR "Could not get %s\n", clk_name);
  1451. else
  1452. clk_enable(gpio_iclks[i]);
  1453. }
  1454. }
  1455. #endif
  1456. #ifdef CONFIG_ARCH_OMAP15XX
  1457. if (cpu_is_omap15xx()) {
  1458. gpio_bank_count = 2;
  1459. gpio_bank = gpio_bank_1510;
  1460. bank_size = SZ_2K;
  1461. }
  1462. #endif
  1463. #if defined(CONFIG_ARCH_OMAP16XX)
  1464. if (cpu_is_omap16xx()) {
  1465. gpio_bank_count = 5;
  1466. gpio_bank = gpio_bank_1610;
  1467. bank_size = SZ_2K;
  1468. }
  1469. #endif
  1470. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  1471. if (cpu_is_omap7xx()) {
  1472. gpio_bank_count = 7;
  1473. gpio_bank = gpio_bank_7xx;
  1474. bank_size = SZ_2K;
  1475. }
  1476. #endif
  1477. #ifdef CONFIG_ARCH_OMAP24XX
  1478. if (cpu_is_omap242x()) {
  1479. gpio_bank_count = 4;
  1480. gpio_bank = gpio_bank_242x;
  1481. }
  1482. if (cpu_is_omap243x()) {
  1483. gpio_bank_count = 5;
  1484. gpio_bank = gpio_bank_243x;
  1485. }
  1486. #endif
  1487. #ifdef CONFIG_ARCH_OMAP34XX
  1488. if (cpu_is_omap34xx()) {
  1489. gpio_bank_count = OMAP34XX_NR_GPIOS;
  1490. gpio_bank = gpio_bank_34xx;
  1491. }
  1492. #endif
  1493. #ifdef CONFIG_ARCH_OMAP4
  1494. if (cpu_is_omap44xx()) {
  1495. gpio_bank_count = OMAP34XX_NR_GPIOS;
  1496. gpio_bank = gpio_bank_44xx;
  1497. }
  1498. #endif
  1499. for (i = 0; i < gpio_bank_count; i++) {
  1500. int j, gpio_count = 16;
  1501. bank = &gpio_bank[i];
  1502. spin_lock_init(&bank->lock);
  1503. /* Static mapping, never released */
  1504. bank->base = ioremap(bank->pbase, bank_size);
  1505. if (!bank->base) {
  1506. printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
  1507. continue;
  1508. }
  1509. if (bank_is_mpuio(bank))
  1510. __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
  1511. if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
  1512. __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
  1513. __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
  1514. }
  1515. if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
  1516. __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
  1517. __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
  1518. __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
  1519. }
  1520. if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
  1521. __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
  1522. __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
  1523. gpio_count = 32; /* 7xx has 32-bit GPIOs */
  1524. }
  1525. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  1526. defined(CONFIG_ARCH_OMAP4)
  1527. if (bank->method == METHOD_GPIO_24XX) {
  1528. static const u32 non_wakeup_gpios[] = {
  1529. 0xe203ffc0, 0x08700040
  1530. };
  1531. if (cpu_is_omap44xx()) {
  1532. __raw_writel(0xffffffff, bank->base +
  1533. OMAP4_GPIO_IRQSTATUSCLR0);
  1534. __raw_writew(0x0015, bank->base +
  1535. OMAP4_GPIO_SYSCONFIG);
  1536. __raw_writel(0x00000000, bank->base +
  1537. OMAP4_GPIO_DEBOUNCENABLE);
  1538. /* Initialize interface clock ungated, module enabled */
  1539. __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
  1540. } else {
  1541. __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
  1542. __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
  1543. __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
  1544. __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
  1545. /* Initialize interface clock ungated, module enabled */
  1546. __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
  1547. }
  1548. if (i < ARRAY_SIZE(non_wakeup_gpios))
  1549. bank->non_wakeup_gpios = non_wakeup_gpios[i];
  1550. gpio_count = 32;
  1551. }
  1552. #endif
  1553. /* REVISIT eventually switch from OMAP-specific gpio structs
  1554. * over to the generic ones
  1555. */
  1556. bank->chip.request = omap_gpio_request;
  1557. bank->chip.free = omap_gpio_free;
  1558. bank->chip.direction_input = gpio_input;
  1559. bank->chip.get = gpio_get;
  1560. bank->chip.direction_output = gpio_output;
  1561. bank->chip.set = gpio_set;
  1562. bank->chip.to_irq = gpio_2irq;
  1563. if (bank_is_mpuio(bank)) {
  1564. bank->chip.label = "mpuio";
  1565. #ifdef CONFIG_ARCH_OMAP16XX
  1566. bank->chip.dev = &omap_mpuio_device.dev;
  1567. #endif
  1568. bank->chip.base = OMAP_MPUIO(0);
  1569. } else {
  1570. bank->chip.label = "gpio";
  1571. bank->chip.base = gpio;
  1572. gpio += gpio_count;
  1573. }
  1574. bank->chip.ngpio = gpio_count;
  1575. gpiochip_add(&bank->chip);
  1576. for (j = bank->virtual_irq_start;
  1577. j < bank->virtual_irq_start + gpio_count; j++) {
  1578. lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
  1579. set_irq_chip_data(j, bank);
  1580. if (bank_is_mpuio(bank))
  1581. set_irq_chip(j, &mpuio_irq_chip);
  1582. else
  1583. set_irq_chip(j, &gpio_irq_chip);
  1584. set_irq_handler(j, handle_simple_irq);
  1585. set_irq_flags(j, IRQF_VALID);
  1586. }
  1587. set_irq_chained_handler(bank->irq, gpio_irq_handler);
  1588. set_irq_data(bank->irq, bank);
  1589. if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
  1590. sprintf(clk_name, "gpio%d_dbck", i + 1);
  1591. bank->dbck = clk_get(NULL, clk_name);
  1592. if (IS_ERR(bank->dbck))
  1593. printk(KERN_ERR "Could not get %s\n", clk_name);
  1594. }
  1595. }
  1596. /* Enable system clock for GPIO module.
  1597. * The CAM_CLK_CTRL *is* really the right place. */
  1598. if (cpu_is_omap16xx())
  1599. omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
  1600. /* Enable autoidle for the OCP interface */
  1601. if (cpu_is_omap24xx())
  1602. omap_writel(1 << 0, 0x48019010);
  1603. if (cpu_is_omap34xx())
  1604. omap_writel(1 << 0, 0x48306814);
  1605. omap_gpio_show_rev();
  1606. return 0;
  1607. }
  1608. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
  1609. defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
  1610. static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
  1611. {
  1612. int i;
  1613. if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
  1614. return 0;
  1615. for (i = 0; i < gpio_bank_count; i++) {
  1616. struct gpio_bank *bank = &gpio_bank[i];
  1617. void __iomem *wake_status;
  1618. void __iomem *wake_clear;
  1619. void __iomem *wake_set;
  1620. unsigned long flags;
  1621. switch (bank->method) {
  1622. #ifdef CONFIG_ARCH_OMAP16XX
  1623. case METHOD_GPIO_1610:
  1624. wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
  1625. wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
  1626. wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
  1627. break;
  1628. #endif
  1629. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  1630. case METHOD_GPIO_24XX:
  1631. wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
  1632. wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
  1633. wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
  1634. break;
  1635. #endif
  1636. #ifdef CONFIG_ARCH_OMAP4
  1637. case METHOD_GPIO_24XX:
  1638. wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
  1639. wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
  1640. wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
  1641. break;
  1642. #endif
  1643. default:
  1644. continue;
  1645. }
  1646. spin_lock_irqsave(&bank->lock, flags);
  1647. bank->saved_wakeup = __raw_readl(wake_status);
  1648. __raw_writel(0xffffffff, wake_clear);
  1649. __raw_writel(bank->suspend_wakeup, wake_set);
  1650. spin_unlock_irqrestore(&bank->lock, flags);
  1651. }
  1652. return 0;
  1653. }
  1654. static int omap_gpio_resume(struct sys_device *dev)
  1655. {
  1656. int i;
  1657. if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
  1658. return 0;
  1659. for (i = 0; i < gpio_bank_count; i++) {
  1660. struct gpio_bank *bank = &gpio_bank[i];
  1661. void __iomem *wake_clear;
  1662. void __iomem *wake_set;
  1663. unsigned long flags;
  1664. switch (bank->method) {
  1665. #ifdef CONFIG_ARCH_OMAP16XX
  1666. case METHOD_GPIO_1610:
  1667. wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
  1668. wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
  1669. break;
  1670. #endif
  1671. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  1672. case METHOD_GPIO_24XX:
  1673. wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
  1674. wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
  1675. break;
  1676. #endif
  1677. #ifdef CONFIG_ARCH_OMAP4
  1678. case METHOD_GPIO_24XX:
  1679. wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
  1680. wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
  1681. break;
  1682. #endif
  1683. default:
  1684. continue;
  1685. }
  1686. spin_lock_irqsave(&bank->lock, flags);
  1687. __raw_writel(0xffffffff, wake_clear);
  1688. __raw_writel(bank->saved_wakeup, wake_set);
  1689. spin_unlock_irqrestore(&bank->lock, flags);
  1690. }
  1691. return 0;
  1692. }
  1693. static struct sysdev_class omap_gpio_sysclass = {
  1694. .name = "gpio",
  1695. .suspend = omap_gpio_suspend,
  1696. .resume = omap_gpio_resume,
  1697. };
  1698. static struct sys_device omap_gpio_device = {
  1699. .id = 0,
  1700. .cls = &omap_gpio_sysclass,
  1701. };
  1702. #endif
  1703. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
  1704. defined(CONFIG_ARCH_OMAP4)
  1705. static int workaround_enabled;
  1706. void omap2_gpio_prepare_for_retention(void)
  1707. {
  1708. int i, c = 0;
  1709. /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
  1710. * IRQs will be generated. See OMAP2420 Errata item 1.101. */
  1711. for (i = 0; i < gpio_bank_count; i++) {
  1712. struct gpio_bank *bank = &gpio_bank[i];
  1713. u32 l1, l2;
  1714. if (!(bank->enabled_non_wakeup_gpios))
  1715. continue;
  1716. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  1717. bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
  1718. l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
  1719. l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
  1720. #endif
  1721. #ifdef CONFIG_ARCH_OMAP4
  1722. bank->saved_datain = __raw_readl(bank->base +
  1723. OMAP4_GPIO_DATAIN);
  1724. l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
  1725. l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
  1726. #endif
  1727. bank->saved_fallingdetect = l1;
  1728. bank->saved_risingdetect = l2;
  1729. l1 &= ~bank->enabled_non_wakeup_gpios;
  1730. l2 &= ~bank->enabled_non_wakeup_gpios;
  1731. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  1732. __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
  1733. __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
  1734. #endif
  1735. #ifdef CONFIG_ARCH_OMAP4
  1736. __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
  1737. __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
  1738. #endif
  1739. c++;
  1740. }
  1741. if (!c) {
  1742. workaround_enabled = 0;
  1743. return;
  1744. }
  1745. workaround_enabled = 1;
  1746. }
  1747. void omap2_gpio_resume_after_retention(void)
  1748. {
  1749. int i;
  1750. if (!workaround_enabled)
  1751. return;
  1752. for (i = 0; i < gpio_bank_count; i++) {
  1753. struct gpio_bank *bank = &gpio_bank[i];
  1754. u32 l, gen, gen0, gen1;
  1755. if (!(bank->enabled_non_wakeup_gpios))
  1756. continue;
  1757. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  1758. __raw_writel(bank->saved_fallingdetect,
  1759. bank->base + OMAP24XX_GPIO_FALLINGDETECT);
  1760. __raw_writel(bank->saved_risingdetect,
  1761. bank->base + OMAP24XX_GPIO_RISINGDETECT);
  1762. l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
  1763. #endif
  1764. #ifdef CONFIG_ARCH_OMAP4
  1765. __raw_writel(bank->saved_fallingdetect,
  1766. bank->base + OMAP4_GPIO_FALLINGDETECT);
  1767. __raw_writel(bank->saved_risingdetect,
  1768. bank->base + OMAP4_GPIO_RISINGDETECT);
  1769. l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
  1770. #endif
  1771. /* Check if any of the non-wakeup interrupt GPIOs have changed
  1772. * state. If so, generate an IRQ by software. This is
  1773. * horribly racy, but it's the best we can do to work around
  1774. * this silicon bug. */
  1775. l ^= bank->saved_datain;
  1776. l &= bank->non_wakeup_gpios;
  1777. /*
  1778. * No need to generate IRQs for the rising edge for gpio IRQs
  1779. * configured with falling edge only; and vice versa.
  1780. */
  1781. gen0 = l & bank->saved_fallingdetect;
  1782. gen0 &= bank->saved_datain;
  1783. gen1 = l & bank->saved_risingdetect;
  1784. gen1 &= ~(bank->saved_datain);
  1785. /* FIXME: Consider GPIO IRQs with level detections properly! */
  1786. gen = l & (~(bank->saved_fallingdetect) &
  1787. ~(bank->saved_risingdetect));
  1788. /* Consider all GPIO IRQs needed to be updated */
  1789. gen |= gen0 | gen1;
  1790. if (gen) {
  1791. u32 old0, old1;
  1792. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  1793. old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
  1794. old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
  1795. __raw_writel(old0 | gen, bank->base +
  1796. OMAP24XX_GPIO_LEVELDETECT0);
  1797. __raw_writel(old1 | gen, bank->base +
  1798. OMAP24XX_GPIO_LEVELDETECT1);
  1799. __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
  1800. __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
  1801. #endif
  1802. #ifdef CONFIG_ARCH_OMAP4
  1803. old0 = __raw_readl(bank->base +
  1804. OMAP4_GPIO_LEVELDETECT0);
  1805. old1 = __raw_readl(bank->base +
  1806. OMAP4_GPIO_LEVELDETECT1);
  1807. __raw_writel(old0 | l, bank->base +
  1808. OMAP4_GPIO_LEVELDETECT0);
  1809. __raw_writel(old1 | l, bank->base +
  1810. OMAP4_GPIO_LEVELDETECT1);
  1811. __raw_writel(old0, bank->base +
  1812. OMAP4_GPIO_LEVELDETECT0);
  1813. __raw_writel(old1, bank->base +
  1814. OMAP4_GPIO_LEVELDETECT1);
  1815. #endif
  1816. }
  1817. }
  1818. }
  1819. #endif
  1820. /*
  1821. * This may get called early from board specific init
  1822. * for boards that have interrupts routed via FPGA.
  1823. */
  1824. int __init omap_gpio_init(void)
  1825. {
  1826. if (!initialized)
  1827. return _omap_gpio_init();
  1828. else
  1829. return 0;
  1830. }
  1831. static int __init omap_gpio_sysinit(void)
  1832. {
  1833. int ret = 0;
  1834. if (!initialized)
  1835. ret = _omap_gpio_init();
  1836. mpuio_init();
  1837. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
  1838. defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
  1839. if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
  1840. if (ret == 0) {
  1841. ret = sysdev_class_register(&omap_gpio_sysclass);
  1842. if (ret == 0)
  1843. ret = sysdev_register(&omap_gpio_device);
  1844. }
  1845. }
  1846. #endif
  1847. return ret;
  1848. }
  1849. arch_initcall(omap_gpio_sysinit);
  1850. #ifdef CONFIG_DEBUG_FS
  1851. #include <linux/debugfs.h>
  1852. #include <linux/seq_file.h>
  1853. static int dbg_gpio_show(struct seq_file *s, void *unused)
  1854. {
  1855. unsigned i, j, gpio;
  1856. for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
  1857. struct gpio_bank *bank = gpio_bank + i;
  1858. unsigned bankwidth = 16;
  1859. u32 mask = 1;
  1860. if (bank_is_mpuio(bank))
  1861. gpio = OMAP_MPUIO(0);
  1862. else if (cpu_class_is_omap2() || cpu_is_omap7xx())
  1863. bankwidth = 32;
  1864. for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
  1865. unsigned irq, value, is_in, irqstat;
  1866. const char *label;
  1867. label = gpiochip_is_requested(&bank->chip, j);
  1868. if (!label)
  1869. continue;
  1870. irq = bank->virtual_irq_start + j;
  1871. value = gpio_get_value(gpio);
  1872. is_in = gpio_is_input(bank, mask);
  1873. if (bank_is_mpuio(bank))
  1874. seq_printf(s, "MPUIO %2d ", j);
  1875. else
  1876. seq_printf(s, "GPIO %3d ", gpio);
  1877. seq_printf(s, "(%-20.20s): %s %s",
  1878. label,
  1879. is_in ? "in " : "out",
  1880. value ? "hi" : "lo");
  1881. /* FIXME for at least omap2, show pullup/pulldown state */
  1882. irqstat = irq_desc[irq].status;
  1883. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
  1884. defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
  1885. if (is_in && ((bank->suspend_wakeup & mask)
  1886. || irqstat & IRQ_TYPE_SENSE_MASK)) {
  1887. char *trigger = NULL;
  1888. switch (irqstat & IRQ_TYPE_SENSE_MASK) {
  1889. case IRQ_TYPE_EDGE_FALLING:
  1890. trigger = "falling";
  1891. break;
  1892. case IRQ_TYPE_EDGE_RISING:
  1893. trigger = "rising";
  1894. break;
  1895. case IRQ_TYPE_EDGE_BOTH:
  1896. trigger = "bothedge";
  1897. break;
  1898. case IRQ_TYPE_LEVEL_LOW:
  1899. trigger = "low";
  1900. break;
  1901. case IRQ_TYPE_LEVEL_HIGH:
  1902. trigger = "high";
  1903. break;
  1904. case IRQ_TYPE_NONE:
  1905. trigger = "(?)";
  1906. break;
  1907. }
  1908. seq_printf(s, ", irq-%d %-8s%s",
  1909. irq, trigger,
  1910. (bank->suspend_wakeup & mask)
  1911. ? " wakeup" : "");
  1912. }
  1913. #endif
  1914. seq_printf(s, "\n");
  1915. }
  1916. if (bank_is_mpuio(bank)) {
  1917. seq_printf(s, "\n");
  1918. gpio = 0;
  1919. }
  1920. }
  1921. return 0;
  1922. }
  1923. static int dbg_gpio_open(struct inode *inode, struct file *file)
  1924. {
  1925. return single_open(file, dbg_gpio_show, &inode->i_private);
  1926. }
  1927. static const struct file_operations debug_fops = {
  1928. .open = dbg_gpio_open,
  1929. .read = seq_read,
  1930. .llseek = seq_lseek,
  1931. .release = single_release,
  1932. };
  1933. static int __init omap_gpio_debuginit(void)
  1934. {
  1935. (void) debugfs_create_file("omap_gpio", S_IRUGO,
  1936. NULL, NULL, &debug_fops);
  1937. return 0;
  1938. }
  1939. late_initcall(omap_gpio_debuginit);
  1940. #endif