pinctrl-tz1090.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. /*
  2. * Pinctrl driver for the Toumaz Xenif TZ1090 SoC
  3. *
  4. * Copyright (c) 2013, Imagination Technologies Ltd.
  5. *
  6. * Derived from Tegra code:
  7. * Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
  8. *
  9. * Derived from code:
  10. * Copyright (C) 2010 Google, Inc.
  11. * Copyright (C) 2010 NVIDIA Corporation
  12. * Copyright (C) 2009-2011 ST-Ericsson AB
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms and conditions of the GNU General Public License,
  16. * version 2, as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope it will be useful, but WITHOUT
  19. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  20. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  21. * more details.
  22. */
  23. #include <linux/bitops.h>
  24. #include <linux/io.h>
  25. #include <linux/module.h>
  26. #include <linux/of.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/pinctrl/machine.h>
  29. #include <linux/pinctrl/pinconf-generic.h>
  30. #include <linux/pinctrl/pinctrl.h>
  31. #include <linux/pinctrl/pinmux.h>
  32. #include <linux/slab.h>
  33. #include <linux/spinlock.h>
  34. /*
  35. * The registers may be shared with other threads/cores, so we need to use the
  36. * metag global lock2 for atomicity.
  37. */
  38. #include <asm/global_lock.h>
  39. #include "core.h"
  40. #include "pinconf.h"
  41. /* Register offsets from bank base address */
  42. #define REG_PINCTRL_SELECT 0x10
  43. #define REG_PINCTRL_SCHMITT 0x90
  44. #define REG_PINCTRL_PU_PD 0xa0
  45. #define REG_PINCTRL_SR 0xc0
  46. #define REG_PINCTRL_DR 0xd0
  47. #define REG_PINCTRL_IF_CTL 0xe0
  48. /* REG_PINCTRL_PU_PD field values */
  49. #define REG_PU_PD_TRISTATE 0
  50. #define REG_PU_PD_UP 1
  51. #define REG_PU_PD_DOWN 2
  52. #define REG_PU_PD_REPEATER 3
  53. /* REG_PINCTRL_DR field values */
  54. #define REG_DR_2mA 0
  55. #define REG_DR_4mA 1
  56. #define REG_DR_8mA 2
  57. #define REG_DR_12mA 3
  58. /**
  59. * struct tz1090_function - TZ1090 pinctrl mux function
  60. * @name: The name of the function, exported to pinctrl core.
  61. * @groups: An array of pin groups that may select this function.
  62. * @ngroups: The number of entries in @groups.
  63. */
  64. struct tz1090_function {
  65. const char *name;
  66. const char * const *groups;
  67. unsigned int ngroups;
  68. };
  69. /**
  70. * struct tz1090_muxdesc - TZ1090 individual mux description
  71. * @funcs: Function for each mux value.
  72. * @reg: Mux register offset. 0 if unsupported.
  73. * @bit: Mux register bit. 0 if unsupported.
  74. * @width: Mux field width. 0 if unsupported.
  75. *
  76. * A representation of a group of signals (possibly just one signal) in the
  77. * TZ1090 which can be muxed to a set of functions or sub muxes.
  78. */
  79. struct tz1090_muxdesc {
  80. int funcs[5];
  81. u16 reg;
  82. u8 bit;
  83. u8 width;
  84. };
  85. /**
  86. * struct tz1090_pingroup - TZ1090 pin group
  87. * @name: Name of pin group.
  88. * @pins: Array of pin numbers in this pin group.
  89. * @npins: Number of pins in this pin group.
  90. * @mux: Top level mux.
  91. * @drv: Drive control supported, 0 if unsupported.
  92. * This means Schmitt, Slew, and Drive strength.
  93. * @slw_bit: Slew register bit. 0 if unsupported.
  94. * The same bit is used for Schmitt, and Drive (*2).
  95. * @func: Currently muxed function.
  96. * @func_count: Number of pins using current mux function.
  97. *
  98. * A representation of a group of pins (possibly just one pin) in the TZ1090
  99. * pin controller. Each group allows some parameter or parameters to be
  100. * configured. The most common is mux function selection.
  101. */
  102. struct tz1090_pingroup {
  103. const char *name;
  104. const unsigned int *pins;
  105. unsigned int npins;
  106. struct tz1090_muxdesc mux;
  107. bool drv;
  108. u8 slw_bit;
  109. int func;
  110. unsigned int func_count;
  111. };
  112. /*
  113. * Most pins affected by the pinmux can also be GPIOs. Define these first.
  114. * These must match how the GPIO driver names/numbers its pins.
  115. */
  116. enum tz1090_pin {
  117. /* GPIO pins */
  118. TZ1090_PIN_SDIO_CLK,
  119. TZ1090_PIN_SDIO_CMD,
  120. TZ1090_PIN_SDIO_D0,
  121. TZ1090_PIN_SDIO_D1,
  122. TZ1090_PIN_SDIO_D2,
  123. TZ1090_PIN_SDIO_D3,
  124. TZ1090_PIN_SDH_CD,
  125. TZ1090_PIN_SDH_WP,
  126. TZ1090_PIN_SPI0_MCLK,
  127. TZ1090_PIN_SPI0_CS0,
  128. TZ1090_PIN_SPI0_CS1,
  129. TZ1090_PIN_SPI0_CS2,
  130. TZ1090_PIN_SPI0_DOUT,
  131. TZ1090_PIN_SPI0_DIN,
  132. TZ1090_PIN_SPI1_MCLK,
  133. TZ1090_PIN_SPI1_CS0,
  134. TZ1090_PIN_SPI1_CS1,
  135. TZ1090_PIN_SPI1_CS2,
  136. TZ1090_PIN_SPI1_DOUT,
  137. TZ1090_PIN_SPI1_DIN,
  138. TZ1090_PIN_UART0_RXD,
  139. TZ1090_PIN_UART0_TXD,
  140. TZ1090_PIN_UART0_CTS,
  141. TZ1090_PIN_UART0_RTS,
  142. TZ1090_PIN_UART1_RXD,
  143. TZ1090_PIN_UART1_TXD,
  144. TZ1090_PIN_SCB0_SDAT,
  145. TZ1090_PIN_SCB0_SCLK,
  146. TZ1090_PIN_SCB1_SDAT,
  147. TZ1090_PIN_SCB1_SCLK,
  148. TZ1090_PIN_SCB2_SDAT,
  149. TZ1090_PIN_SCB2_SCLK,
  150. TZ1090_PIN_I2S_MCLK,
  151. TZ1090_PIN_I2S_BCLK_OUT,
  152. TZ1090_PIN_I2S_LRCLK_OUT,
  153. TZ1090_PIN_I2S_DOUT0,
  154. TZ1090_PIN_I2S_DOUT1,
  155. TZ1090_PIN_I2S_DOUT2,
  156. TZ1090_PIN_I2S_DIN,
  157. TZ1090_PIN_PDM_A,
  158. TZ1090_PIN_PDM_B,
  159. TZ1090_PIN_PDM_C,
  160. TZ1090_PIN_PDM_D,
  161. TZ1090_PIN_TFT_RED0,
  162. TZ1090_PIN_TFT_RED1,
  163. TZ1090_PIN_TFT_RED2,
  164. TZ1090_PIN_TFT_RED3,
  165. TZ1090_PIN_TFT_RED4,
  166. TZ1090_PIN_TFT_RED5,
  167. TZ1090_PIN_TFT_RED6,
  168. TZ1090_PIN_TFT_RED7,
  169. TZ1090_PIN_TFT_GREEN0,
  170. TZ1090_PIN_TFT_GREEN1,
  171. TZ1090_PIN_TFT_GREEN2,
  172. TZ1090_PIN_TFT_GREEN3,
  173. TZ1090_PIN_TFT_GREEN4,
  174. TZ1090_PIN_TFT_GREEN5,
  175. TZ1090_PIN_TFT_GREEN6,
  176. TZ1090_PIN_TFT_GREEN7,
  177. TZ1090_PIN_TFT_BLUE0,
  178. TZ1090_PIN_TFT_BLUE1,
  179. TZ1090_PIN_TFT_BLUE2,
  180. TZ1090_PIN_TFT_BLUE3,
  181. TZ1090_PIN_TFT_BLUE4,
  182. TZ1090_PIN_TFT_BLUE5,
  183. TZ1090_PIN_TFT_BLUE6,
  184. TZ1090_PIN_TFT_BLUE7,
  185. TZ1090_PIN_TFT_VDDEN_GD,
  186. TZ1090_PIN_TFT_PANELCLK,
  187. TZ1090_PIN_TFT_BLANK_LS,
  188. TZ1090_PIN_TFT_VSYNC_NS,
  189. TZ1090_PIN_TFT_HSYNC_NR,
  190. TZ1090_PIN_TFT_VD12ACB,
  191. TZ1090_PIN_TFT_PWRSAVE,
  192. TZ1090_PIN_TX_ON,
  193. TZ1090_PIN_RX_ON,
  194. TZ1090_PIN_PLL_ON,
  195. TZ1090_PIN_PA_ON,
  196. TZ1090_PIN_RX_HP,
  197. TZ1090_PIN_GAIN0,
  198. TZ1090_PIN_GAIN1,
  199. TZ1090_PIN_GAIN2,
  200. TZ1090_PIN_GAIN3,
  201. TZ1090_PIN_GAIN4,
  202. TZ1090_PIN_GAIN5,
  203. TZ1090_PIN_GAIN6,
  204. TZ1090_PIN_GAIN7,
  205. TZ1090_PIN_ANT_SEL0,
  206. TZ1090_PIN_ANT_SEL1,
  207. TZ1090_PIN_SDH_CLK_IN,
  208. /* Non-GPIO pins */
  209. TZ1090_PIN_TCK,
  210. TZ1090_PIN_TRST,
  211. TZ1090_PIN_TDI,
  212. TZ1090_PIN_TDO,
  213. TZ1090_PIN_TMS,
  214. TZ1090_PIN_CLK_OUT0,
  215. TZ1090_PIN_CLK_OUT1,
  216. NUM_GPIOS = TZ1090_PIN_TCK,
  217. };
  218. /* Pin names */
  219. static const struct pinctrl_pin_desc tz1090_pins[] = {
  220. /* GPIO pins */
  221. PINCTRL_PIN(TZ1090_PIN_SDIO_CLK, "sdio_clk"),
  222. PINCTRL_PIN(TZ1090_PIN_SDIO_CMD, "sdio_cmd"),
  223. PINCTRL_PIN(TZ1090_PIN_SDIO_D0, "sdio_d0"),
  224. PINCTRL_PIN(TZ1090_PIN_SDIO_D1, "sdio_d1"),
  225. PINCTRL_PIN(TZ1090_PIN_SDIO_D2, "sdio_d2"),
  226. PINCTRL_PIN(TZ1090_PIN_SDIO_D3, "sdio_d3"),
  227. PINCTRL_PIN(TZ1090_PIN_SDH_CD, "sdh_cd"),
  228. PINCTRL_PIN(TZ1090_PIN_SDH_WP, "sdh_wp"),
  229. PINCTRL_PIN(TZ1090_PIN_SPI0_MCLK, "spi0_mclk"),
  230. PINCTRL_PIN(TZ1090_PIN_SPI0_CS0, "spi0_cs0"),
  231. PINCTRL_PIN(TZ1090_PIN_SPI0_CS1, "spi0_cs1"),
  232. PINCTRL_PIN(TZ1090_PIN_SPI0_CS2, "spi0_cs2"),
  233. PINCTRL_PIN(TZ1090_PIN_SPI0_DOUT, "spi0_dout"),
  234. PINCTRL_PIN(TZ1090_PIN_SPI0_DIN, "spi0_din"),
  235. PINCTRL_PIN(TZ1090_PIN_SPI1_MCLK, "spi1_mclk"),
  236. PINCTRL_PIN(TZ1090_PIN_SPI1_CS0, "spi1_cs0"),
  237. PINCTRL_PIN(TZ1090_PIN_SPI1_CS1, "spi1_cs1"),
  238. PINCTRL_PIN(TZ1090_PIN_SPI1_CS2, "spi1_cs2"),
  239. PINCTRL_PIN(TZ1090_PIN_SPI1_DOUT, "spi1_dout"),
  240. PINCTRL_PIN(TZ1090_PIN_SPI1_DIN, "spi1_din"),
  241. PINCTRL_PIN(TZ1090_PIN_UART0_RXD, "uart0_rxd"),
  242. PINCTRL_PIN(TZ1090_PIN_UART0_TXD, "uart0_txd"),
  243. PINCTRL_PIN(TZ1090_PIN_UART0_CTS, "uart0_cts"),
  244. PINCTRL_PIN(TZ1090_PIN_UART0_RTS, "uart0_rts"),
  245. PINCTRL_PIN(TZ1090_PIN_UART1_RXD, "uart1_rxd"),
  246. PINCTRL_PIN(TZ1090_PIN_UART1_TXD, "uart1_txd"),
  247. PINCTRL_PIN(TZ1090_PIN_SCB0_SDAT, "scb0_sdat"),
  248. PINCTRL_PIN(TZ1090_PIN_SCB0_SCLK, "scb0_sclk"),
  249. PINCTRL_PIN(TZ1090_PIN_SCB1_SDAT, "scb1_sdat"),
  250. PINCTRL_PIN(TZ1090_PIN_SCB1_SCLK, "scb1_sclk"),
  251. PINCTRL_PIN(TZ1090_PIN_SCB2_SDAT, "scb2_sdat"),
  252. PINCTRL_PIN(TZ1090_PIN_SCB2_SCLK, "scb2_sclk"),
  253. PINCTRL_PIN(TZ1090_PIN_I2S_MCLK, "i2s_mclk"),
  254. PINCTRL_PIN(TZ1090_PIN_I2S_BCLK_OUT, "i2s_bclk_out"),
  255. PINCTRL_PIN(TZ1090_PIN_I2S_LRCLK_OUT, "i2s_lrclk_out"),
  256. PINCTRL_PIN(TZ1090_PIN_I2S_DOUT0, "i2s_dout0"),
  257. PINCTRL_PIN(TZ1090_PIN_I2S_DOUT1, "i2s_dout1"),
  258. PINCTRL_PIN(TZ1090_PIN_I2S_DOUT2, "i2s_dout2"),
  259. PINCTRL_PIN(TZ1090_PIN_I2S_DIN, "i2s_din"),
  260. PINCTRL_PIN(TZ1090_PIN_PDM_A, "pdm_a"),
  261. PINCTRL_PIN(TZ1090_PIN_PDM_B, "pdm_b"),
  262. PINCTRL_PIN(TZ1090_PIN_PDM_C, "pdm_c"),
  263. PINCTRL_PIN(TZ1090_PIN_PDM_D, "pdm_d"),
  264. PINCTRL_PIN(TZ1090_PIN_TFT_RED0, "tft_red0"),
  265. PINCTRL_PIN(TZ1090_PIN_TFT_RED1, "tft_red1"),
  266. PINCTRL_PIN(TZ1090_PIN_TFT_RED2, "tft_red2"),
  267. PINCTRL_PIN(TZ1090_PIN_TFT_RED3, "tft_red3"),
  268. PINCTRL_PIN(TZ1090_PIN_TFT_RED4, "tft_red4"),
  269. PINCTRL_PIN(TZ1090_PIN_TFT_RED5, "tft_red5"),
  270. PINCTRL_PIN(TZ1090_PIN_TFT_RED6, "tft_red6"),
  271. PINCTRL_PIN(TZ1090_PIN_TFT_RED7, "tft_red7"),
  272. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN0, "tft_green0"),
  273. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN1, "tft_green1"),
  274. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN2, "tft_green2"),
  275. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN3, "tft_green3"),
  276. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN4, "tft_green4"),
  277. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN5, "tft_green5"),
  278. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN6, "tft_green6"),
  279. PINCTRL_PIN(TZ1090_PIN_TFT_GREEN7, "tft_green7"),
  280. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE0, "tft_blue0"),
  281. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE1, "tft_blue1"),
  282. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE2, "tft_blue2"),
  283. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE3, "tft_blue3"),
  284. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE4, "tft_blue4"),
  285. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE5, "tft_blue5"),
  286. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE6, "tft_blue6"),
  287. PINCTRL_PIN(TZ1090_PIN_TFT_BLUE7, "tft_blue7"),
  288. PINCTRL_PIN(TZ1090_PIN_TFT_VDDEN_GD, "tft_vdden_gd"),
  289. PINCTRL_PIN(TZ1090_PIN_TFT_PANELCLK, "tft_panelclk"),
  290. PINCTRL_PIN(TZ1090_PIN_TFT_BLANK_LS, "tft_blank_ls"),
  291. PINCTRL_PIN(TZ1090_PIN_TFT_VSYNC_NS, "tft_vsync_ns"),
  292. PINCTRL_PIN(TZ1090_PIN_TFT_HSYNC_NR, "tft_hsync_nr"),
  293. PINCTRL_PIN(TZ1090_PIN_TFT_VD12ACB, "tft_vd12acb"),
  294. PINCTRL_PIN(TZ1090_PIN_TFT_PWRSAVE, "tft_pwrsave"),
  295. PINCTRL_PIN(TZ1090_PIN_TX_ON, "tx_on"),
  296. PINCTRL_PIN(TZ1090_PIN_RX_ON, "rx_on"),
  297. PINCTRL_PIN(TZ1090_PIN_PLL_ON, "pll_on"),
  298. PINCTRL_PIN(TZ1090_PIN_PA_ON, "pa_on"),
  299. PINCTRL_PIN(TZ1090_PIN_RX_HP, "rx_hp"),
  300. PINCTRL_PIN(TZ1090_PIN_GAIN0, "gain0"),
  301. PINCTRL_PIN(TZ1090_PIN_GAIN1, "gain1"),
  302. PINCTRL_PIN(TZ1090_PIN_GAIN2, "gain2"),
  303. PINCTRL_PIN(TZ1090_PIN_GAIN3, "gain3"),
  304. PINCTRL_PIN(TZ1090_PIN_GAIN4, "gain4"),
  305. PINCTRL_PIN(TZ1090_PIN_GAIN5, "gain5"),
  306. PINCTRL_PIN(TZ1090_PIN_GAIN6, "gain6"),
  307. PINCTRL_PIN(TZ1090_PIN_GAIN7, "gain7"),
  308. PINCTRL_PIN(TZ1090_PIN_ANT_SEL0, "ant_sel0"),
  309. PINCTRL_PIN(TZ1090_PIN_ANT_SEL1, "ant_sel1"),
  310. PINCTRL_PIN(TZ1090_PIN_SDH_CLK_IN, "sdh_clk_in"),
  311. /* Non-GPIO pins */
  312. PINCTRL_PIN(TZ1090_PIN_TCK, "tck"),
  313. PINCTRL_PIN(TZ1090_PIN_TRST, "trst"),
  314. PINCTRL_PIN(TZ1090_PIN_TDI, "tdi"),
  315. PINCTRL_PIN(TZ1090_PIN_TDO, "tdo"),
  316. PINCTRL_PIN(TZ1090_PIN_TMS, "tms"),
  317. PINCTRL_PIN(TZ1090_PIN_CLK_OUT0, "clk_out0"),
  318. PINCTRL_PIN(TZ1090_PIN_CLK_OUT1, "clk_out1"),
  319. };
  320. /* Pins in each pin group */
  321. static const unsigned int spi1_cs2_pins[] = {
  322. TZ1090_PIN_SPI1_CS2,
  323. };
  324. static const unsigned int pdm_d_pins[] = {
  325. TZ1090_PIN_PDM_D,
  326. };
  327. static const unsigned int tft_pins[] = {
  328. TZ1090_PIN_TFT_RED0,
  329. TZ1090_PIN_TFT_RED1,
  330. TZ1090_PIN_TFT_RED2,
  331. TZ1090_PIN_TFT_RED3,
  332. TZ1090_PIN_TFT_RED4,
  333. TZ1090_PIN_TFT_RED5,
  334. TZ1090_PIN_TFT_RED6,
  335. TZ1090_PIN_TFT_RED7,
  336. TZ1090_PIN_TFT_GREEN0,
  337. TZ1090_PIN_TFT_GREEN1,
  338. TZ1090_PIN_TFT_GREEN2,
  339. TZ1090_PIN_TFT_GREEN3,
  340. TZ1090_PIN_TFT_GREEN4,
  341. TZ1090_PIN_TFT_GREEN5,
  342. TZ1090_PIN_TFT_GREEN6,
  343. TZ1090_PIN_TFT_GREEN7,
  344. TZ1090_PIN_TFT_BLUE0,
  345. TZ1090_PIN_TFT_BLUE1,
  346. TZ1090_PIN_TFT_BLUE2,
  347. TZ1090_PIN_TFT_BLUE3,
  348. TZ1090_PIN_TFT_BLUE4,
  349. TZ1090_PIN_TFT_BLUE5,
  350. TZ1090_PIN_TFT_BLUE6,
  351. TZ1090_PIN_TFT_BLUE7,
  352. TZ1090_PIN_TFT_VDDEN_GD,
  353. TZ1090_PIN_TFT_PANELCLK,
  354. TZ1090_PIN_TFT_BLANK_LS,
  355. TZ1090_PIN_TFT_VSYNC_NS,
  356. TZ1090_PIN_TFT_HSYNC_NR,
  357. TZ1090_PIN_TFT_VD12ACB,
  358. TZ1090_PIN_TFT_PWRSAVE,
  359. };
  360. static const unsigned int afe_pins[] = {
  361. TZ1090_PIN_TX_ON,
  362. TZ1090_PIN_RX_ON,
  363. TZ1090_PIN_PLL_ON,
  364. TZ1090_PIN_PA_ON,
  365. TZ1090_PIN_RX_HP,
  366. TZ1090_PIN_ANT_SEL0,
  367. TZ1090_PIN_ANT_SEL1,
  368. TZ1090_PIN_GAIN0,
  369. TZ1090_PIN_GAIN1,
  370. TZ1090_PIN_GAIN2,
  371. TZ1090_PIN_GAIN3,
  372. TZ1090_PIN_GAIN4,
  373. TZ1090_PIN_GAIN5,
  374. TZ1090_PIN_GAIN6,
  375. TZ1090_PIN_GAIN7,
  376. };
  377. static const unsigned int sdio_pins[] = {
  378. TZ1090_PIN_SDIO_CLK,
  379. TZ1090_PIN_SDIO_CMD,
  380. TZ1090_PIN_SDIO_D0,
  381. TZ1090_PIN_SDIO_D1,
  382. TZ1090_PIN_SDIO_D2,
  383. TZ1090_PIN_SDIO_D3,
  384. };
  385. static const unsigned int sdh_pins[] = {
  386. TZ1090_PIN_SDH_CD,
  387. TZ1090_PIN_SDH_WP,
  388. TZ1090_PIN_SDH_CLK_IN,
  389. };
  390. static const unsigned int spi0_pins[] = {
  391. TZ1090_PIN_SPI0_MCLK,
  392. TZ1090_PIN_SPI0_CS0,
  393. TZ1090_PIN_SPI0_CS1,
  394. TZ1090_PIN_SPI0_CS2,
  395. TZ1090_PIN_SPI0_DOUT,
  396. TZ1090_PIN_SPI0_DIN,
  397. };
  398. static const unsigned int spi1_pins[] = {
  399. TZ1090_PIN_SPI1_MCLK,
  400. TZ1090_PIN_SPI1_CS0,
  401. TZ1090_PIN_SPI1_CS1,
  402. TZ1090_PIN_SPI1_CS2,
  403. TZ1090_PIN_SPI1_DOUT,
  404. TZ1090_PIN_SPI1_DIN,
  405. };
  406. static const unsigned int uart0_pins[] = {
  407. TZ1090_PIN_UART0_RTS,
  408. TZ1090_PIN_UART0_CTS,
  409. TZ1090_PIN_UART0_TXD,
  410. TZ1090_PIN_UART0_RXD,
  411. };
  412. static const unsigned int uart1_pins[] = {
  413. TZ1090_PIN_UART1_TXD,
  414. TZ1090_PIN_UART1_RXD,
  415. };
  416. static const unsigned int uart_pins[] = {
  417. TZ1090_PIN_UART1_TXD,
  418. TZ1090_PIN_UART1_RXD,
  419. TZ1090_PIN_UART0_RTS,
  420. TZ1090_PIN_UART0_CTS,
  421. TZ1090_PIN_UART0_TXD,
  422. TZ1090_PIN_UART0_RXD,
  423. };
  424. static const unsigned int scb0_pins[] = {
  425. TZ1090_PIN_SCB0_SDAT,
  426. TZ1090_PIN_SCB0_SCLK,
  427. };
  428. static const unsigned int scb1_pins[] = {
  429. TZ1090_PIN_SCB1_SDAT,
  430. TZ1090_PIN_SCB1_SCLK,
  431. };
  432. static const unsigned int scb2_pins[] = {
  433. TZ1090_PIN_SCB2_SDAT,
  434. TZ1090_PIN_SCB2_SCLK,
  435. };
  436. static const unsigned int i2s_pins[] = {
  437. TZ1090_PIN_I2S_MCLK,
  438. TZ1090_PIN_I2S_BCLK_OUT,
  439. TZ1090_PIN_I2S_LRCLK_OUT,
  440. TZ1090_PIN_I2S_DOUT0,
  441. TZ1090_PIN_I2S_DOUT1,
  442. TZ1090_PIN_I2S_DOUT2,
  443. TZ1090_PIN_I2S_DIN,
  444. };
  445. static const unsigned int jtag_pins[] = {
  446. TZ1090_PIN_TCK,
  447. TZ1090_PIN_TRST,
  448. TZ1090_PIN_TDI,
  449. TZ1090_PIN_TDO,
  450. TZ1090_PIN_TMS,
  451. };
  452. /* Pins in each drive pin group */
  453. static const unsigned int drive_sdio_pins[] = {
  454. TZ1090_PIN_SDIO_CLK,
  455. TZ1090_PIN_SDIO_CMD,
  456. TZ1090_PIN_SDIO_D0,
  457. TZ1090_PIN_SDIO_D1,
  458. TZ1090_PIN_SDIO_D2,
  459. TZ1090_PIN_SDIO_D3,
  460. TZ1090_PIN_SDH_WP,
  461. TZ1090_PIN_SDH_CD,
  462. TZ1090_PIN_SDH_CLK_IN,
  463. };
  464. static const unsigned int drive_i2s_pins[] = {
  465. TZ1090_PIN_CLK_OUT1,
  466. TZ1090_PIN_I2S_DIN,
  467. TZ1090_PIN_I2S_DOUT0,
  468. TZ1090_PIN_I2S_DOUT1,
  469. TZ1090_PIN_I2S_DOUT2,
  470. TZ1090_PIN_I2S_LRCLK_OUT,
  471. TZ1090_PIN_I2S_BCLK_OUT,
  472. TZ1090_PIN_I2S_MCLK,
  473. };
  474. static const unsigned int drive_scb0_pins[] = {
  475. TZ1090_PIN_SCB0_SCLK,
  476. TZ1090_PIN_SCB0_SDAT,
  477. TZ1090_PIN_PDM_D,
  478. TZ1090_PIN_PDM_C,
  479. };
  480. static const unsigned int drive_pdm_pins[] = {
  481. TZ1090_PIN_CLK_OUT0,
  482. TZ1090_PIN_PDM_B,
  483. TZ1090_PIN_PDM_A,
  484. };
  485. /* Pin groups each function can be muxed to */
  486. /*
  487. * The magic "perip" function allows otherwise non-muxing pins to be enabled in
  488. * peripheral mode.
  489. */
  490. static const char * const perip_groups[] = {
  491. /* non-muxing convenient gpio pingroups */
  492. "uart",
  493. "uart0",
  494. "uart1",
  495. "spi0",
  496. "spi1",
  497. "scb0",
  498. "scb1",
  499. "scb2",
  500. "i2s",
  501. /* individual pins not part of a pin mux group */
  502. "spi0_mclk",
  503. "spi0_cs0",
  504. "spi0_cs1",
  505. "spi0_cs2",
  506. "spi0_dout",
  507. "spi0_din",
  508. "spi1_mclk",
  509. "spi1_cs0",
  510. "spi1_cs1",
  511. "spi1_dout",
  512. "spi1_din",
  513. "uart0_rxd",
  514. "uart0_txd",
  515. "uart0_cts",
  516. "uart0_rts",
  517. "uart1_rxd",
  518. "uart1_txd",
  519. "scb0_sdat",
  520. "scb0_sclk",
  521. "scb1_sdat",
  522. "scb1_sclk",
  523. "scb2_sdat",
  524. "scb2_sclk",
  525. "i2s_mclk",
  526. "i2s_bclk_out",
  527. "i2s_lrclk_out",
  528. "i2s_dout0",
  529. "i2s_dout1",
  530. "i2s_dout2",
  531. "i2s_din",
  532. "pdm_a",
  533. "pdm_b",
  534. "pdm_c",
  535. };
  536. static const char * const sdh_sdio_groups[] = {
  537. "sdh",
  538. "sdio",
  539. /* sdh pins */
  540. "sdh_cd",
  541. "sdh_wp",
  542. "sdh_clk_in",
  543. /* sdio pins */
  544. "sdio_clk",
  545. "sdio_cmd",
  546. "sdio_d0",
  547. "sdio_d1",
  548. "sdio_d2",
  549. "sdio_d3",
  550. };
  551. static const char * const spi1_cs2_groups[] = {
  552. "spi1_cs2",
  553. };
  554. static const char * const pdm_dac_groups[] = {
  555. "pdm_d",
  556. };
  557. static const char * const usb_vbus_groups[] = {
  558. "spi1_cs2",
  559. "pdm_d",
  560. };
  561. static const char * const afe_groups[] = {
  562. "afe",
  563. /* afe pins */
  564. "tx_on",
  565. "rx_on",
  566. "pll_on",
  567. "pa_on",
  568. "rx_hp",
  569. "ant_sel0",
  570. "ant_sel1",
  571. "gain0",
  572. "gain1",
  573. "gain2",
  574. "gain3",
  575. "gain4",
  576. "gain5",
  577. "gain6",
  578. "gain7",
  579. };
  580. static const char * const tft_groups[] = {
  581. "tft",
  582. /* tft pins */
  583. "tft_red0",
  584. "tft_red1",
  585. "tft_red2",
  586. "tft_red3",
  587. "tft_red4",
  588. "tft_red5",
  589. "tft_red6",
  590. "tft_red7",
  591. "tft_green0",
  592. "tft_green1",
  593. "tft_green2",
  594. "tft_green3",
  595. "tft_green4",
  596. "tft_green5",
  597. "tft_green6",
  598. "tft_green7",
  599. "tft_blue0",
  600. "tft_blue1",
  601. "tft_blue2",
  602. "tft_blue3",
  603. "tft_blue4",
  604. "tft_blue5",
  605. "tft_blue6",
  606. "tft_blue7",
  607. "tft_vdden_gd",
  608. "tft_panelclk",
  609. "tft_blank_ls",
  610. "tft_vsync_ns",
  611. "tft_hsync_nr",
  612. "tft_vd12acb",
  613. "tft_pwrsave",
  614. };
  615. /* Mux functions that can be used by a mux */
  616. enum tz1090_mux {
  617. /* internal placeholder */
  618. TZ1090_MUX_NA = -1,
  619. /* magic per-non-muxing-GPIO-pin peripheral mode mux */
  620. TZ1090_MUX_PERIP,
  621. /* SDH/SDIO mux */
  622. TZ1090_MUX_SDH,
  623. TZ1090_MUX_SDIO,
  624. /* USB_VBUS muxes */
  625. TZ1090_MUX_SPI1_CS2,
  626. TZ1090_MUX_PDM_DAC,
  627. TZ1090_MUX_USB_VBUS,
  628. /* AFE mux */
  629. TZ1090_MUX_AFE,
  630. TZ1090_MUX_TS_OUT_0,
  631. /* EXT_DAC mux */
  632. TZ1090_MUX_DAC,
  633. TZ1090_MUX_NOT_IQADC_STB,
  634. TZ1090_MUX_IQDAC_STB,
  635. /* TFT mux */
  636. TZ1090_MUX_TFT,
  637. TZ1090_MUX_EXT_DAC,
  638. TZ1090_MUX_TS_OUT_1,
  639. TZ1090_MUX_LCD_TRACE,
  640. TZ1090_MUX_PHY_RINGOSC,
  641. };
  642. #define FUNCTION(mux, fname, group) \
  643. [(TZ1090_MUX_ ## mux)] = { \
  644. .name = #fname, \
  645. .groups = group##_groups, \
  646. .ngroups = ARRAY_SIZE(group##_groups), \
  647. }
  648. /* For intermediate functions with submuxes */
  649. #define NULL_FUNCTION(mux, fname) \
  650. [(TZ1090_MUX_ ## mux)] = { \
  651. .name = #fname, \
  652. }
  653. /* Must correlate with enum tz1090_mux */
  654. static const struct tz1090_function tz1090_functions[] = {
  655. /* FUNCTION function name pingroups */
  656. FUNCTION(PERIP, perip, perip),
  657. FUNCTION(SDH, sdh, sdh_sdio),
  658. FUNCTION(SDIO, sdio, sdh_sdio),
  659. FUNCTION(SPI1_CS2, spi1_cs2, spi1_cs2),
  660. FUNCTION(PDM_DAC, pdm_dac, pdm_dac),
  661. FUNCTION(USB_VBUS, usb_vbus, usb_vbus),
  662. FUNCTION(AFE, afe, afe),
  663. FUNCTION(TS_OUT_0, ts_out_0, afe),
  664. FUNCTION(DAC, ext_dac, tft),
  665. FUNCTION(NOT_IQADC_STB, not_iqadc_stb, tft),
  666. FUNCTION(IQDAC_STB, iqdac_stb, tft),
  667. FUNCTION(TFT, tft, tft),
  668. NULL_FUNCTION(EXT_DAC, _ext_dac),
  669. FUNCTION(TS_OUT_1, ts_out_1, tft),
  670. FUNCTION(LCD_TRACE, lcd_trace, tft),
  671. FUNCTION(PHY_RINGOSC, phy_ringosc, tft),
  672. };
  673. /* Sub muxes */
  674. /**
  675. * MUX() - Initialise a mux description.
  676. * @f0: Function 0 (TZ1090_MUX_ is prepended, NA for none)
  677. * @f1: Function 1 (TZ1090_MUX_ is prepended, NA for none)
  678. * @f2: Function 2 (TZ1090_MUX_ is prepended, NA for none)
  679. * @f3: Function 3 (TZ1090_MUX_ is prepended, NA for none)
  680. * @f4: Function 4 (TZ1090_MUX_ is prepended, NA for none)
  681. * @mux_r: Mux register (REG_PINCTRL_ is prepended)
  682. * @mux_b: Bit number in register that the mux field begins
  683. * @mux_w: Width of mux field in register
  684. */
  685. #define MUX(f0, f1, f2, f3, f4, mux_r, mux_b, mux_w) \
  686. { \
  687. .funcs = { \
  688. TZ1090_MUX_ ## f0, \
  689. TZ1090_MUX_ ## f1, \
  690. TZ1090_MUX_ ## f2, \
  691. TZ1090_MUX_ ## f3, \
  692. TZ1090_MUX_ ## f4, \
  693. }, \
  694. .reg = (REG_PINCTRL_ ## mux_r), \
  695. .bit = (mux_b), \
  696. .width = (mux_w), \
  697. }
  698. /**
  699. * DEFINE_SUBMUX() - Defines a submux description separate from a pin group.
  700. * @mux: Mux name (_submux is appended)
  701. * @f0: Function 0 (TZ1090_MUX_ is prepended, NA for none)
  702. * @f1: Function 1 (TZ1090_MUX_ is prepended, NA for none)
  703. * @f2: Function 2 (TZ1090_MUX_ is prepended, NA for none)
  704. * @f3: Function 3 (TZ1090_MUX_ is prepended, NA for none)
  705. * @f4: Function 4 (TZ1090_MUX_ is prepended, NA for none)
  706. * @mux_r: Mux register (REG_PINCTRL_ is prepended)
  707. * @mux_b: Bit number in register that the mux field begins
  708. * @mux_w: Width of mux field in register
  709. *
  710. * A sub mux is a nested mux that can be bound to a magic function number used
  711. * by another mux description. For example value 4 of the top level mux might
  712. * correspond to a function which has a submux pointed to in tz1090_submux[].
  713. * The outer mux can then take on any function in the top level mux or the
  714. * submux, and if a submux function is chosen both muxes are updated to route
  715. * the signal from the submux.
  716. *
  717. * The submux can be defined with DEFINE_SUBMUX and pointed to from
  718. * tz1090_submux[] using SUBMUX.
  719. */
  720. #define DEFINE_SUBMUX(mux, f0, f1, f2, f3, f4, mux_r, mux_b, mux_w) \
  721. static struct tz1090_muxdesc mux ## _submux = \
  722. MUX(f0, f1, f2, f3, f4, mux_r, mux_b, mux_w)
  723. /**
  724. * SUBMUX() - Link a submux to a function number.
  725. * @f: Function name (TZ1090_MUX_ is prepended)
  726. * @submux: Submux name (_submux is appended)
  727. *
  728. * For use in tz1090_submux[] initialisation to link an intermediate function
  729. * number to a particular submux description. It indicates that when the
  730. * function is chosen the signal is connected to the submux.
  731. */
  732. #define SUBMUX(f, submux) [(TZ1090_MUX_ ## f)] = &(submux ## _submux)
  733. /**
  734. * MUX_PG() - Initialise a pin group with mux control
  735. * @pg_name: Pin group name (stringified, _pins appended to get pins array)
  736. * @f0: Function 0 (TZ1090_MUX_ is prepended, NA for none)
  737. * @f1: Function 1 (TZ1090_MUX_ is prepended, NA for none)
  738. * @f2: Function 2 (TZ1090_MUX_ is prepended, NA for none)
  739. * @f3: Function 3 (TZ1090_MUX_ is prepended, NA for none)
  740. * @f4: Function 4 (TZ1090_MUX_ is prepended, NA for none)
  741. * @mux_r: Mux register (REG_PINCTRL_ is prepended)
  742. * @mux_b: Bit number in register that the mux field begins
  743. * @mux_w: Width of mux field in register
  744. */
  745. #define MUX_PG(pg_name, f0, f1, f2, f3, f4, \
  746. mux_r, mux_b, mux_w) \
  747. { \
  748. .name = #pg_name, \
  749. .pins = pg_name##_pins, \
  750. .npins = ARRAY_SIZE(pg_name##_pins), \
  751. .mux = MUX(f0, f1, f2, f3, f4, \
  752. mux_r, mux_b, mux_w), \
  753. }
  754. /**
  755. * SIMPLE_PG() - Initialise a simple convenience pin group
  756. * @pg_name: Pin group name (stringified, _pins appended to get pins array)
  757. *
  758. * A simple pin group is simply used for binding pins together so they can be
  759. * referred to by a single name instead of having to list every pin
  760. * individually.
  761. */
  762. #define SIMPLE_PG(pg_name) \
  763. { \
  764. .name = #pg_name, \
  765. .pins = pg_name##_pins, \
  766. .npins = ARRAY_SIZE(pg_name##_pins), \
  767. }
  768. /**
  769. * DRV_PG() - Initialise a pin group with drive control
  770. * @pg_name: Pin group name (stringified, _pins appended to get pins array)
  771. * @slw_b: Slew register bit.
  772. * The same bit is used for Schmitt, and Drive (*2).
  773. */
  774. #define DRV_PG(pg_name, slw_b) \
  775. { \
  776. .name = #pg_name, \
  777. .pins = pg_name##_pins, \
  778. .npins = ARRAY_SIZE(pg_name##_pins), \
  779. .drv = true, \
  780. .slw_bit = (slw_b), \
  781. }
  782. /*
  783. * Define main muxing pin groups
  784. */
  785. /* submuxes */
  786. /* name f0, f1, f2, f3, f4, mux r/b/w */
  787. DEFINE_SUBMUX(ext_dac, DAC, NOT_IQADC_STB, IQDAC_STB, NA, NA, IF_CTL, 6, 2);
  788. /* bind submuxes to internal functions */
  789. static struct tz1090_muxdesc *tz1090_submux[] = {
  790. SUBMUX(EXT_DAC, ext_dac),
  791. };
  792. /*
  793. * These are the pin mux groups. Pin muxing can be enabled and disabled for each
  794. * pin individually so these groups are internal. The mapping of pins to pin mux
  795. * group is below (tz1090_mux_pins).
  796. */
  797. static struct tz1090_pingroup tz1090_mux_groups[] = {
  798. /* Muxing pin groups */
  799. /* pg_name, f0, f1, f2, f3, f4, mux r/b/w */
  800. MUX_PG(sdh, SDH, SDIO, NA, NA, NA, IF_CTL, 20, 2),
  801. MUX_PG(sdio, SDIO, SDH, NA, NA, NA, IF_CTL, 16, 2),
  802. MUX_PG(spi1_cs2, SPI1_CS2, USB_VBUS, NA, NA, NA, IF_CTL, 10, 2),
  803. MUX_PG(pdm_d, PDM_DAC, USB_VBUS, NA, NA, NA, IF_CTL, 8, 2),
  804. MUX_PG(afe, AFE, TS_OUT_0, NA, NA, NA, IF_CTL, 4, 2),
  805. MUX_PG(tft, TFT, EXT_DAC, TS_OUT_1, LCD_TRACE, PHY_RINGOSC, IF_CTL, 0, 3),
  806. };
  807. /*
  808. * This is the mapping from GPIO pins to pin mux groups in tz1090_mux_groups[].
  809. * Pins which aren't muxable to multiple peripherals are set to
  810. * TZ1090_MUX_GROUP_MAX to enable the "perip" function to enable/disable
  811. * peripheral control of the pin.
  812. *
  813. * This array is initialised in tz1090_init_mux_pins().
  814. */
  815. static u8 tz1090_mux_pins[NUM_GPIOS];
  816. /* TZ1090_MUX_GROUP_MAX is used in tz1090_mux_pins[] for non-muxing pins */
  817. #define TZ1090_MUX_GROUP_MAX ARRAY_SIZE(tz1090_mux_groups)
  818. /**
  819. * tz1090_init_mux_pins() - Initialise GPIO pin to mux group mapping.
  820. *
  821. * Initialises the tz1090_mux_pins[] array to be the inverse of the pin lists in
  822. * each pin mux group in tz1090_mux_groups[].
  823. *
  824. * It is assumed that no pin mux groups overlap (share pins).
  825. */
  826. static void __init tz1090_init_mux_pins(void)
  827. {
  828. unsigned int g, p;
  829. const struct tz1090_pingroup *grp;
  830. const unsigned int *pin;
  831. for (p = 0; p < NUM_GPIOS; ++p)
  832. tz1090_mux_pins[p] = TZ1090_MUX_GROUP_MAX;
  833. grp = tz1090_mux_groups;
  834. for (g = 0, grp = tz1090_mux_groups;
  835. g < ARRAY_SIZE(tz1090_mux_groups); ++g, ++grp)
  836. for (pin = grp->pins, p = 0; p < grp->npins; ++p, ++pin)
  837. tz1090_mux_pins[*pin] = g;
  838. }
  839. /*
  840. * These are the externally visible pin groups. Some of them allow group control
  841. * of drive configuration. Some are just simple convenience pingroups. All the
  842. * internal pin mux groups in tz1090_mux_groups[] are mirrored here with the
  843. * same pins.
  844. * Pseudo pin groups follow in the group numbers after this array for each GPIO
  845. * pin. Any group used for muxing must have all pins belonging to the same pin
  846. * mux group.
  847. */
  848. static struct tz1090_pingroup tz1090_groups[] = {
  849. /* Pin groups with drive control (with no out of place pins) */
  850. /* pg_name, slw/schmitt/drv b */
  851. DRV_PG(jtag, 11 /* 11, 22 */),
  852. DRV_PG(tft, 10 /* 10, 20 */),
  853. DRV_PG(scb2, 9 /* 9, 18 */),
  854. DRV_PG(spi0, 7 /* 7, 14 */),
  855. DRV_PG(uart, 5 /* 5, 10 */),
  856. DRV_PG(scb1, 4 /* 4, 8 */),
  857. DRV_PG(spi1, 3 /* 3, 6 */),
  858. DRV_PG(afe, 0 /* 0, 0 */),
  859. /*
  860. * Drive specific pin groups (with odd combinations of pins which makes
  861. * the pin group naming somewhat arbitrary)
  862. */
  863. /* pg_name, slw/schmitt/drv b */
  864. DRV_PG(drive_sdio, 8 /* 8, 16 */), /* sdio_* + sdh_* */
  865. DRV_PG(drive_i2s, 6 /* 6, 12 */), /* i2s_* + clk_out1 */
  866. DRV_PG(drive_scb0, 2 /* 2, 4 */), /* scb0_* + pdm_{c,d} */
  867. DRV_PG(drive_pdm, 1 /* 1, 2 */), /* pdm_{a,b} + clk_out0 */
  868. /* Convenience pin groups */
  869. /* pg_name */
  870. SIMPLE_PG(uart0),
  871. SIMPLE_PG(uart1),
  872. SIMPLE_PG(scb0),
  873. SIMPLE_PG(i2s),
  874. SIMPLE_PG(sdh),
  875. SIMPLE_PG(sdio),
  876. /* pseudo-pingroups for each GPIO pin follow */
  877. };
  878. /**
  879. * struct tz1090_pmx - Private pinctrl data
  880. * @dev: Platform device
  881. * @pctl: Pin control device
  882. * @regs: Register region
  883. * @lock: Lock protecting coherency of pin_en, gpio_en, and SELECT regs
  884. * @pin_en: Pins that have been enabled (32 pins packed into each element)
  885. * @gpio_en: GPIOs that have been enabled (32 pins packed into each element)
  886. */
  887. struct tz1090_pmx {
  888. struct device *dev;
  889. struct pinctrl_dev *pctl;
  890. void __iomem *regs;
  891. spinlock_t lock;
  892. u32 pin_en[3];
  893. u32 gpio_en[3];
  894. };
  895. static inline u32 pmx_read(struct tz1090_pmx *pmx, u32 reg)
  896. {
  897. return ioread32(pmx->regs + reg);
  898. }
  899. static inline void pmx_write(struct tz1090_pmx *pmx, u32 val, u32 reg)
  900. {
  901. iowrite32(val, pmx->regs + reg);
  902. }
  903. /*
  904. * Pin control operations
  905. */
  906. /* each GPIO pin has it's own pseudo pingroup containing only itself */
  907. static int tz1090_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  908. {
  909. return ARRAY_SIZE(tz1090_groups) + NUM_GPIOS;
  910. }
  911. static const char *tz1090_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  912. unsigned int group)
  913. {
  914. if (group < ARRAY_SIZE(tz1090_groups)) {
  915. /* normal pingroup */
  916. return tz1090_groups[group].name;
  917. } else {
  918. /* individual gpio pin pseudo-pingroup */
  919. unsigned int pin = group - ARRAY_SIZE(tz1090_groups);
  920. return tz1090_pins[pin].name;
  921. }
  922. }
  923. static int tz1090_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  924. unsigned int group,
  925. const unsigned int **pins,
  926. unsigned int *num_pins)
  927. {
  928. if (group < ARRAY_SIZE(tz1090_groups)) {
  929. /* normal pingroup */
  930. *pins = tz1090_groups[group].pins;
  931. *num_pins = tz1090_groups[group].npins;
  932. } else {
  933. /* individual gpio pin pseudo-pingroup */
  934. unsigned int pin = group - ARRAY_SIZE(tz1090_groups);
  935. *pins = &tz1090_pins[pin].number;
  936. *num_pins = 1;
  937. }
  938. return 0;
  939. }
  940. #ifdef CONFIG_DEBUG_FS
  941. static void tz1090_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,
  942. struct seq_file *s,
  943. unsigned int offset)
  944. {
  945. seq_printf(s, " %s", dev_name(pctldev->dev));
  946. }
  947. #endif
  948. static int reserve_map(struct device *dev, struct pinctrl_map **map,
  949. unsigned int *reserved_maps, unsigned int *num_maps,
  950. unsigned int reserve)
  951. {
  952. unsigned int old_num = *reserved_maps;
  953. unsigned int new_num = *num_maps + reserve;
  954. struct pinctrl_map *new_map;
  955. if (old_num >= new_num)
  956. return 0;
  957. new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
  958. if (!new_map) {
  959. dev_err(dev, "krealloc(map) failed\n");
  960. return -ENOMEM;
  961. }
  962. memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
  963. *map = new_map;
  964. *reserved_maps = new_num;
  965. return 0;
  966. }
  967. static int add_map_mux(struct pinctrl_map **map, unsigned int *reserved_maps,
  968. unsigned int *num_maps, const char *group,
  969. const char *function)
  970. {
  971. if (WARN_ON(*num_maps == *reserved_maps))
  972. return -ENOSPC;
  973. (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
  974. (*map)[*num_maps].data.mux.group = group;
  975. (*map)[*num_maps].data.mux.function = function;
  976. (*num_maps)++;
  977. return 0;
  978. }
  979. static int add_map_configs(struct device *dev,
  980. struct pinctrl_map **map,
  981. unsigned int *reserved_maps, unsigned int *num_maps,
  982. const char *group, unsigned long *configs,
  983. unsigned int num_configs)
  984. {
  985. unsigned long *dup_configs;
  986. if (WARN_ON(*num_maps == *reserved_maps))
  987. return -ENOSPC;
  988. dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
  989. GFP_KERNEL);
  990. if (!dup_configs) {
  991. dev_err(dev, "kmemdup(configs) failed\n");
  992. return -ENOMEM;
  993. }
  994. (*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
  995. (*map)[*num_maps].data.configs.group_or_pin = group;
  996. (*map)[*num_maps].data.configs.configs = dup_configs;
  997. (*map)[*num_maps].data.configs.num_configs = num_configs;
  998. (*num_maps)++;
  999. return 0;
  1000. }
  1001. static void tz1090_pinctrl_dt_free_map(struct pinctrl_dev *pctldev,
  1002. struct pinctrl_map *map,
  1003. unsigned int num_maps)
  1004. {
  1005. int i;
  1006. for (i = 0; i < num_maps; i++)
  1007. if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
  1008. kfree(map[i].data.configs.configs);
  1009. kfree(map);
  1010. }
  1011. static int tz1090_pinctrl_dt_subnode_to_map(struct device *dev,
  1012. struct device_node *np,
  1013. struct pinctrl_map **map,
  1014. unsigned int *reserved_maps,
  1015. unsigned int *num_maps)
  1016. {
  1017. int ret;
  1018. const char *function;
  1019. unsigned long *configs = NULL;
  1020. unsigned int num_configs = 0;
  1021. unsigned int reserve;
  1022. struct property *prop;
  1023. const char *group;
  1024. ret = of_property_read_string(np, "tz1090,function", &function);
  1025. if (ret < 0) {
  1026. /* EINVAL=missing, which is fine since it's optional */
  1027. if (ret != -EINVAL)
  1028. dev_err(dev, "could not parse property function\n");
  1029. function = NULL;
  1030. }
  1031. ret = pinconf_generic_parse_dt_config(np, NULL, &configs, &num_configs);
  1032. if (ret)
  1033. return ret;
  1034. reserve = 0;
  1035. if (function != NULL)
  1036. reserve++;
  1037. if (num_configs)
  1038. reserve++;
  1039. ret = of_property_count_strings(np, "tz1090,pins");
  1040. if (ret < 0) {
  1041. dev_err(dev, "could not parse property pins\n");
  1042. goto exit;
  1043. }
  1044. reserve *= ret;
  1045. ret = reserve_map(dev, map, reserved_maps, num_maps, reserve);
  1046. if (ret < 0)
  1047. goto exit;
  1048. of_property_for_each_string(np, "tz1090,pins", prop, group) {
  1049. if (function) {
  1050. ret = add_map_mux(map, reserved_maps, num_maps,
  1051. group, function);
  1052. if (ret < 0)
  1053. goto exit;
  1054. }
  1055. if (num_configs) {
  1056. ret = add_map_configs(dev, map, reserved_maps,
  1057. num_maps, group, configs,
  1058. num_configs);
  1059. if (ret < 0)
  1060. goto exit;
  1061. }
  1062. }
  1063. ret = 0;
  1064. exit:
  1065. kfree(configs);
  1066. return ret;
  1067. }
  1068. static int tz1090_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
  1069. struct device_node *np_config,
  1070. struct pinctrl_map **map,
  1071. unsigned int *num_maps)
  1072. {
  1073. unsigned int reserved_maps;
  1074. struct device_node *np;
  1075. int ret;
  1076. reserved_maps = 0;
  1077. *map = NULL;
  1078. *num_maps = 0;
  1079. for_each_child_of_node(np_config, np) {
  1080. ret = tz1090_pinctrl_dt_subnode_to_map(pctldev->dev, np, map,
  1081. &reserved_maps,
  1082. num_maps);
  1083. if (ret < 0) {
  1084. tz1090_pinctrl_dt_free_map(pctldev, *map, *num_maps);
  1085. return ret;
  1086. }
  1087. }
  1088. return 0;
  1089. }
  1090. static struct pinctrl_ops tz1090_pinctrl_ops = {
  1091. .get_groups_count = tz1090_pinctrl_get_groups_count,
  1092. .get_group_name = tz1090_pinctrl_get_group_name,
  1093. .get_group_pins = tz1090_pinctrl_get_group_pins,
  1094. #ifdef CONFIG_DEBUG_FS
  1095. .pin_dbg_show = tz1090_pinctrl_pin_dbg_show,
  1096. #endif
  1097. .dt_node_to_map = tz1090_pinctrl_dt_node_to_map,
  1098. .dt_free_map = tz1090_pinctrl_dt_free_map,
  1099. };
  1100. /*
  1101. * Pin mux operations
  1102. */
  1103. static int tz1090_pinctrl_get_funcs_count(struct pinctrl_dev *pctldev)
  1104. {
  1105. return ARRAY_SIZE(tz1090_functions);
  1106. }
  1107. static const char *tz1090_pinctrl_get_func_name(struct pinctrl_dev *pctldev,
  1108. unsigned int function)
  1109. {
  1110. return tz1090_functions[function].name;
  1111. }
  1112. static int tz1090_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,
  1113. unsigned int function,
  1114. const char * const **groups,
  1115. unsigned int * const num_groups)
  1116. {
  1117. /* pingroup functions */
  1118. *groups = tz1090_functions[function].groups;
  1119. *num_groups = tz1090_functions[function].ngroups;
  1120. return 0;
  1121. }
  1122. /**
  1123. * tz1090_pinctrl_select() - update bit in SELECT register
  1124. * @pmx: Pinmux data
  1125. * @pin: Pin number (must be within GPIO range)
  1126. */
  1127. static void tz1090_pinctrl_select(struct tz1090_pmx *pmx,
  1128. unsigned int pin)
  1129. {
  1130. u32 reg, reg_shift, select, val;
  1131. unsigned int pmx_index, pmx_shift;
  1132. unsigned long flags;
  1133. /* uses base 32 instead of base 30 */
  1134. pmx_index = pin >> 5;
  1135. pmx_shift = pin & 0x1f;
  1136. /* select = !perip || gpio */
  1137. select = ((~pmx->pin_en[pmx_index] |
  1138. pmx->gpio_en[pmx_index]) >> pmx_shift) & 1;
  1139. /* find register and bit offset (base 30) */
  1140. reg = REG_PINCTRL_SELECT + 4*(pin / 30);
  1141. reg_shift = pin % 30;
  1142. /* modify gpio select bit */
  1143. __global_lock2(flags);
  1144. val = pmx_read(pmx, reg);
  1145. val &= ~BIT(reg_shift);
  1146. val |= select << reg_shift;
  1147. pmx_write(pmx, val, reg);
  1148. __global_unlock2(flags);
  1149. }
  1150. /**
  1151. * tz1090_pinctrl_gpio_select() - enable/disable GPIO usage for a pin
  1152. * @pmx: Pinmux data
  1153. * @pin: Pin number
  1154. * @gpio_select: true to enable pin as GPIO,
  1155. * false to leave control to whatever function is enabled
  1156. *
  1157. * Records that GPIO usage is enabled/disabled so that enabling a function
  1158. * doesn't override the SELECT register bit.
  1159. */
  1160. static void tz1090_pinctrl_gpio_select(struct tz1090_pmx *pmx,
  1161. unsigned int pin,
  1162. bool gpio_select)
  1163. {
  1164. unsigned int index, shift;
  1165. u32 gpio_en;
  1166. if (pin >= NUM_GPIOS)
  1167. return;
  1168. /* uses base 32 instead of base 30 */
  1169. index = pin >> 5;
  1170. shift = pin & 0x1f;
  1171. spin_lock(&pmx->lock);
  1172. /* keep a record whether gpio is selected */
  1173. gpio_en = pmx->gpio_en[index];
  1174. gpio_en &= ~BIT(shift);
  1175. if (gpio_select)
  1176. gpio_en |= BIT(shift);
  1177. pmx->gpio_en[index] = gpio_en;
  1178. /* update the select bit */
  1179. tz1090_pinctrl_select(pmx, pin);
  1180. spin_unlock(&pmx->lock);
  1181. }
  1182. /**
  1183. * tz1090_pinctrl_perip_select() - enable/disable peripheral interface for a pin
  1184. * @pmx: Pinmux data
  1185. * @pin: Pin number
  1186. * @perip_select: true to enable peripheral interface when not GPIO,
  1187. * false to leave pin in GPIO mode
  1188. *
  1189. * Records that peripheral usage is enabled/disabled so that SELECT register can
  1190. * be set appropriately when GPIO is disabled.
  1191. */
  1192. static void tz1090_pinctrl_perip_select(struct tz1090_pmx *pmx,
  1193. unsigned int pin,
  1194. bool perip_select)
  1195. {
  1196. unsigned int index, shift;
  1197. u32 pin_en;
  1198. if (pin >= NUM_GPIOS)
  1199. return;
  1200. /* uses base 32 instead of base 30 */
  1201. index = pin >> 5;
  1202. shift = pin & 0x1f;
  1203. spin_lock(&pmx->lock);
  1204. /* keep a record whether peripheral is selected */
  1205. pin_en = pmx->pin_en[index];
  1206. pin_en &= ~BIT(shift);
  1207. if (perip_select)
  1208. pin_en |= BIT(shift);
  1209. pmx->pin_en[index] = pin_en;
  1210. /* update the select bit */
  1211. tz1090_pinctrl_select(pmx, pin);
  1212. spin_unlock(&pmx->lock);
  1213. }
  1214. /**
  1215. * tz1090_pinctrl_enable_mux() - Switch a pin mux group to a function.
  1216. * @pmx: Pinmux data
  1217. * @desc: Pinmux description
  1218. * @function: Function to switch to
  1219. *
  1220. * Enable a particular function on a pin mux group. Since pin mux descriptions
  1221. * are nested this function is recursive.
  1222. */
  1223. static int tz1090_pinctrl_enable_mux(struct tz1090_pmx *pmx,
  1224. const struct tz1090_muxdesc *desc,
  1225. unsigned int function)
  1226. {
  1227. const int *fit;
  1228. unsigned long flags;
  1229. int mux;
  1230. unsigned int func, ret;
  1231. u32 reg, mask;
  1232. /* find the mux value for this function, searching recursively */
  1233. for (mux = 0, fit = desc->funcs;
  1234. mux < ARRAY_SIZE(desc->funcs); ++mux, ++fit) {
  1235. func = *fit;
  1236. if (func == function)
  1237. goto found_mux;
  1238. /* maybe it's a sub-mux */
  1239. if (func < ARRAY_SIZE(tz1090_submux) && tz1090_submux[func]) {
  1240. ret = tz1090_pinctrl_enable_mux(pmx,
  1241. tz1090_submux[func],
  1242. function);
  1243. if (!ret)
  1244. goto found_mux;
  1245. }
  1246. }
  1247. return -EINVAL;
  1248. found_mux:
  1249. /* Set up the mux */
  1250. if (desc->width) {
  1251. mask = (BIT(desc->width) - 1) << desc->bit;
  1252. __global_lock2(flags);
  1253. reg = pmx_read(pmx, desc->reg);
  1254. reg &= ~mask;
  1255. reg |= (mux << desc->bit) & mask;
  1256. pmx_write(pmx, reg, desc->reg);
  1257. __global_unlock2(flags);
  1258. }
  1259. return 0;
  1260. }
  1261. /**
  1262. * tz1090_pinctrl_enable() - Enable a function on a pin group.
  1263. * @pctldev: Pin control data
  1264. * @function: Function index to enable
  1265. * @group: Group index to enable
  1266. *
  1267. * Enable a particular function on a group of pins. The per GPIO pin pseudo pin
  1268. * groups can be used (in which case the pin will be enabled in peripheral mode
  1269. * and if it belongs to a pin mux group the mux will be switched if it isn't
  1270. * already in use. Some convenience pin groups can also be used in which case
  1271. * the effect is the same as enabling the function on each individual pin in the
  1272. * group.
  1273. */
  1274. static int tz1090_pinctrl_set_mux(struct pinctrl_dev *pctldev,
  1275. unsigned int function, unsigned int group)
  1276. {
  1277. struct tz1090_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  1278. struct tz1090_pingroup *grp;
  1279. int ret;
  1280. unsigned int pin_num, mux_group, i, npins;
  1281. const unsigned int *pins;
  1282. /* group of pins? */
  1283. if (group < ARRAY_SIZE(tz1090_groups)) {
  1284. grp = &tz1090_groups[group];
  1285. npins = grp->npins;
  1286. pins = grp->pins;
  1287. /*
  1288. * All pins in the group must belong to the same mux group,
  1289. * which allows us to just use the mux group of the first pin.
  1290. * By explicitly listing permitted pingroups for each function
  1291. * the pinmux core should ensure this is always the case.
  1292. */
  1293. } else {
  1294. pin_num = group - ARRAY_SIZE(tz1090_groups);
  1295. npins = 1;
  1296. pins = &pin_num;
  1297. }
  1298. mux_group = tz1090_mux_pins[*pins];
  1299. /* no mux group, but can still be individually muxed to peripheral */
  1300. if (mux_group >= TZ1090_MUX_GROUP_MAX) {
  1301. if (function == TZ1090_MUX_PERIP)
  1302. goto mux_pins;
  1303. return -EINVAL;
  1304. }
  1305. /* mux group already set to a different function? */
  1306. grp = &tz1090_mux_groups[mux_group];
  1307. if (grp->func_count && grp->func != function) {
  1308. dev_err(pctldev->dev,
  1309. "%s: can't mux pin(s) to '%s', group already muxed to '%s'\n",
  1310. __func__, tz1090_functions[function].name,
  1311. tz1090_functions[grp->func].name);
  1312. return -EBUSY;
  1313. }
  1314. dev_dbg(pctldev->dev, "%s: muxing %u pin(s) in '%s' to '%s'\n",
  1315. __func__, npins, grp->name, tz1090_functions[function].name);
  1316. /* if first pin in mux group to be enabled, enable the group mux */
  1317. if (!grp->func_count) {
  1318. grp->func = function;
  1319. ret = tz1090_pinctrl_enable_mux(pmx, &grp->mux, function);
  1320. if (ret)
  1321. return ret;
  1322. }
  1323. /* add pins to ref count and mux individually to peripheral */
  1324. grp->func_count += npins;
  1325. mux_pins:
  1326. for (i = 0; i < npins; ++i)
  1327. tz1090_pinctrl_perip_select(pmx, pins[i], true);
  1328. return 0;
  1329. }
  1330. /**
  1331. * tz1090_pinctrl_gpio_request_enable() - Put pin in GPIO mode.
  1332. * @pctldev: Pin control data
  1333. * @range: GPIO range
  1334. * @pin: Pin number
  1335. *
  1336. * Puts a particular pin into GPIO mode, disabling peripheral control until it's
  1337. * disabled again.
  1338. */
  1339. static int tz1090_pinctrl_gpio_request_enable(struct pinctrl_dev *pctldev,
  1340. struct pinctrl_gpio_range *range,
  1341. unsigned int pin)
  1342. {
  1343. struct tz1090_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  1344. tz1090_pinctrl_gpio_select(pmx, pin, true);
  1345. return 0;
  1346. }
  1347. /**
  1348. * tz1090_pinctrl_gpio_disable_free() - Take pin out of GPIO mode.
  1349. * @pctldev: Pin control data
  1350. * @range: GPIO range
  1351. * @pin: Pin number
  1352. *
  1353. * Take a particular pin out of GPIO mode. If the pin is enabled for a
  1354. * peripheral it will return to peripheral mode.
  1355. */
  1356. static void tz1090_pinctrl_gpio_disable_free(struct pinctrl_dev *pctldev,
  1357. struct pinctrl_gpio_range *range,
  1358. unsigned int pin)
  1359. {
  1360. struct tz1090_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  1361. tz1090_pinctrl_gpio_select(pmx, pin, false);
  1362. }
  1363. static struct pinmux_ops tz1090_pinmux_ops = {
  1364. .get_functions_count = tz1090_pinctrl_get_funcs_count,
  1365. .get_function_name = tz1090_pinctrl_get_func_name,
  1366. .get_function_groups = tz1090_pinctrl_get_func_groups,
  1367. .set_mux = tz1090_pinctrl_set_mux,
  1368. .gpio_request_enable = tz1090_pinctrl_gpio_request_enable,
  1369. .gpio_disable_free = tz1090_pinctrl_gpio_disable_free,
  1370. };
  1371. /*
  1372. * Pin config operations
  1373. */
  1374. struct tz1090_pinconf_pullup {
  1375. unsigned char index;
  1376. unsigned char shift;
  1377. };
  1378. /* The mapping of pin to pull up/down register index and shift */
  1379. static struct tz1090_pinconf_pullup tz1090_pinconf_pullup[] = {
  1380. {5, 22}, /* 0 - TZ1090_PIN_SDIO_CLK */
  1381. {0, 14}, /* 1 - TZ1090_PIN_SDIO_CMD */
  1382. {0, 6}, /* 2 - TZ1090_PIN_SDIO_D0 */
  1383. {0, 8}, /* 3 - TZ1090_PIN_SDIO_D1 */
  1384. {0, 10}, /* 4 - TZ1090_PIN_SDIO_D2 */
  1385. {0, 12}, /* 5 - TZ1090_PIN_SDIO_D3 */
  1386. {0, 2}, /* 6 - TZ1090_PIN_SDH_CD */
  1387. {0, 4}, /* 7 - TZ1090_PIN_SDH_WP */
  1388. {0, 16}, /* 8 - TZ1090_PIN_SPI0_MCLK */
  1389. {0, 18}, /* 9 - TZ1090_PIN_SPI0_CS0 */
  1390. {0, 20}, /* 10 - TZ1090_PIN_SPI0_CS1 */
  1391. {0, 22}, /* 11 - TZ1090_PIN_SPI0_CS2 */
  1392. {0, 24}, /* 12 - TZ1090_PIN_SPI0_DOUT */
  1393. {0, 26}, /* 13 - TZ1090_PIN_SPI0_DIN */
  1394. {0, 28}, /* 14 - TZ1090_PIN_SPI1_MCLK */
  1395. {0, 30}, /* 15 - TZ1090_PIN_SPI1_CS0 */
  1396. {1, 0}, /* 16 - TZ1090_PIN_SPI1_CS1 */
  1397. {1, 2}, /* 17 - TZ1090_PIN_SPI1_CS2 */
  1398. {1, 4}, /* 18 - TZ1090_PIN_SPI1_DOUT */
  1399. {1, 6}, /* 19 - TZ1090_PIN_SPI1_DIN */
  1400. {1, 8}, /* 20 - TZ1090_PIN_UART0_RXD */
  1401. {1, 10}, /* 21 - TZ1090_PIN_UART0_TXD */
  1402. {1, 12}, /* 22 - TZ1090_PIN_UART0_CTS */
  1403. {1, 14}, /* 23 - TZ1090_PIN_UART0_RTS */
  1404. {1, 16}, /* 24 - TZ1090_PIN_UART1_RXD */
  1405. {1, 18}, /* 25 - TZ1090_PIN_UART1_TXD */
  1406. {1, 20}, /* 26 - TZ1090_PIN_SCB0_SDAT */
  1407. {1, 22}, /* 27 - TZ1090_PIN_SCB0_SCLK */
  1408. {1, 24}, /* 28 - TZ1090_PIN_SCB1_SDAT */
  1409. {1, 26}, /* 29 - TZ1090_PIN_SCB1_SCLK */
  1410. {1, 28}, /* 30 - TZ1090_PIN_SCB2_SDAT */
  1411. {1, 30}, /* 31 - TZ1090_PIN_SCB2_SCLK */
  1412. {2, 0}, /* 32 - TZ1090_PIN_I2S_MCLK */
  1413. {2, 2}, /* 33 - TZ1090_PIN_I2S_BCLK_OUT */
  1414. {2, 4}, /* 34 - TZ1090_PIN_I2S_LRCLK_OUT */
  1415. {2, 6}, /* 35 - TZ1090_PIN_I2S_DOUT0 */
  1416. {2, 8}, /* 36 - TZ1090_PIN_I2S_DOUT1 */
  1417. {2, 10}, /* 37 - TZ1090_PIN_I2S_DOUT2 */
  1418. {2, 12}, /* 38 - TZ1090_PIN_I2S_DIN */
  1419. {4, 12}, /* 39 - TZ1090_PIN_PDM_A */
  1420. {4, 14}, /* 40 - TZ1090_PIN_PDM_B */
  1421. {4, 18}, /* 41 - TZ1090_PIN_PDM_C */
  1422. {4, 20}, /* 42 - TZ1090_PIN_PDM_D */
  1423. {2, 14}, /* 43 - TZ1090_PIN_TFT_RED0 */
  1424. {2, 16}, /* 44 - TZ1090_PIN_TFT_RED1 */
  1425. {2, 18}, /* 45 - TZ1090_PIN_TFT_RED2 */
  1426. {2, 20}, /* 46 - TZ1090_PIN_TFT_RED3 */
  1427. {2, 22}, /* 47 - TZ1090_PIN_TFT_RED4 */
  1428. {2, 24}, /* 48 - TZ1090_PIN_TFT_RED5 */
  1429. {2, 26}, /* 49 - TZ1090_PIN_TFT_RED6 */
  1430. {2, 28}, /* 50 - TZ1090_PIN_TFT_RED7 */
  1431. {2, 30}, /* 51 - TZ1090_PIN_TFT_GREEN0 */
  1432. {3, 0}, /* 52 - TZ1090_PIN_TFT_GREEN1 */
  1433. {3, 2}, /* 53 - TZ1090_PIN_TFT_GREEN2 */
  1434. {3, 4}, /* 54 - TZ1090_PIN_TFT_GREEN3 */
  1435. {3, 6}, /* 55 - TZ1090_PIN_TFT_GREEN4 */
  1436. {3, 8}, /* 56 - TZ1090_PIN_TFT_GREEN5 */
  1437. {3, 10}, /* 57 - TZ1090_PIN_TFT_GREEN6 */
  1438. {3, 12}, /* 58 - TZ1090_PIN_TFT_GREEN7 */
  1439. {3, 14}, /* 59 - TZ1090_PIN_TFT_BLUE0 */
  1440. {3, 16}, /* 60 - TZ1090_PIN_TFT_BLUE1 */
  1441. {3, 18}, /* 61 - TZ1090_PIN_TFT_BLUE2 */
  1442. {3, 20}, /* 62 - TZ1090_PIN_TFT_BLUE3 */
  1443. {3, 22}, /* 63 - TZ1090_PIN_TFT_BLUE4 */
  1444. {3, 24}, /* 64 - TZ1090_PIN_TFT_BLUE5 */
  1445. {3, 26}, /* 65 - TZ1090_PIN_TFT_BLUE6 */
  1446. {3, 28}, /* 66 - TZ1090_PIN_TFT_BLUE7 */
  1447. {3, 30}, /* 67 - TZ1090_PIN_TFT_VDDEN_GD */
  1448. {4, 0}, /* 68 - TZ1090_PIN_TFT_PANELCLK */
  1449. {4, 2}, /* 69 - TZ1090_PIN_TFT_BLANK_LS */
  1450. {4, 4}, /* 70 - TZ1090_PIN_TFT_VSYNC_NS */
  1451. {4, 6}, /* 71 - TZ1090_PIN_TFT_HSYNC_NR */
  1452. {4, 8}, /* 72 - TZ1090_PIN_TFT_VD12ACB */
  1453. {4, 10}, /* 73 - TZ1090_PIN_TFT_PWRSAVE */
  1454. {4, 24}, /* 74 - TZ1090_PIN_TX_ON */
  1455. {4, 26}, /* 75 - TZ1090_PIN_RX_ON */
  1456. {4, 28}, /* 76 - TZ1090_PIN_PLL_ON */
  1457. {4, 30}, /* 77 - TZ1090_PIN_PA_ON */
  1458. {5, 0}, /* 78 - TZ1090_PIN_RX_HP */
  1459. {5, 6}, /* 79 - TZ1090_PIN_GAIN0 */
  1460. {5, 8}, /* 80 - TZ1090_PIN_GAIN1 */
  1461. {5, 10}, /* 81 - TZ1090_PIN_GAIN2 */
  1462. {5, 12}, /* 82 - TZ1090_PIN_GAIN3 */
  1463. {5, 14}, /* 83 - TZ1090_PIN_GAIN4 */
  1464. {5, 16}, /* 84 - TZ1090_PIN_GAIN5 */
  1465. {5, 18}, /* 85 - TZ1090_PIN_GAIN6 */
  1466. {5, 20}, /* 86 - TZ1090_PIN_GAIN7 */
  1467. {5, 2}, /* 87 - TZ1090_PIN_ANT_SEL0 */
  1468. {5, 4}, /* 88 - TZ1090_PIN_ANT_SEL1 */
  1469. {0, 0}, /* 89 - TZ1090_PIN_SDH_CLK_IN */
  1470. {5, 24}, /* 90 - TZ1090_PIN_TCK */
  1471. {5, 26}, /* 91 - TZ1090_PIN_TRST */
  1472. {5, 28}, /* 92 - TZ1090_PIN_TDI */
  1473. {5, 30}, /* 93 - TZ1090_PIN_TDO */
  1474. {6, 0}, /* 94 - TZ1090_PIN_TMS */
  1475. {4, 16}, /* 95 - TZ1090_PIN_CLK_OUT0 */
  1476. {4, 22}, /* 96 - TZ1090_PIN_CLK_OUT1 */
  1477. };
  1478. static int tz1090_pinconf_reg(struct pinctrl_dev *pctldev,
  1479. unsigned int pin,
  1480. enum pin_config_param param,
  1481. bool report_err,
  1482. u32 *reg, u32 *width, u32 *mask, u32 *shift,
  1483. u32 *val)
  1484. {
  1485. struct tz1090_pinconf_pullup *pu;
  1486. /* All supported pins have controllable input bias */
  1487. switch (param) {
  1488. case PIN_CONFIG_BIAS_DISABLE:
  1489. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
  1490. *val = REG_PU_PD_TRISTATE;
  1491. break;
  1492. case PIN_CONFIG_BIAS_PULL_UP:
  1493. *val = REG_PU_PD_UP;
  1494. break;
  1495. case PIN_CONFIG_BIAS_PULL_DOWN:
  1496. *val = REG_PU_PD_DOWN;
  1497. break;
  1498. case PIN_CONFIG_BIAS_BUS_HOLD:
  1499. *val = REG_PU_PD_REPEATER;
  1500. break;
  1501. default:
  1502. return -ENOTSUPP;
  1503. }
  1504. /* Only input bias parameters supported */
  1505. pu = &tz1090_pinconf_pullup[pin];
  1506. *reg = REG_PINCTRL_PU_PD + 4*pu->index;
  1507. *shift = pu->shift;
  1508. *width = 2;
  1509. /* Calculate field information */
  1510. *mask = (BIT(*width) - 1) << *shift;
  1511. return 0;
  1512. }
  1513. static int tz1090_pinconf_get(struct pinctrl_dev *pctldev,
  1514. unsigned int pin, unsigned long *config)
  1515. {
  1516. struct tz1090_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  1517. enum pin_config_param param = pinconf_to_config_param(*config);
  1518. int ret;
  1519. u32 reg, width, mask, shift, val, tmp, arg;
  1520. /* Get register information */
  1521. ret = tz1090_pinconf_reg(pctldev, pin, param, true,
  1522. &reg, &width, &mask, &shift, &val);
  1523. if (ret < 0)
  1524. return ret;
  1525. /* Extract field from register */
  1526. tmp = pmx_read(pmx, reg);
  1527. arg = ((tmp & mask) >> shift) == val;
  1528. /* Config not active */
  1529. if (!arg)
  1530. return -EINVAL;
  1531. /* And pack config */
  1532. *config = pinconf_to_config_packed(param, arg);
  1533. return 0;
  1534. }
  1535. static int tz1090_pinconf_set(struct pinctrl_dev *pctldev,
  1536. unsigned int pin, unsigned long *configs,
  1537. unsigned num_configs)
  1538. {
  1539. struct tz1090_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  1540. enum pin_config_param param;
  1541. unsigned int arg;
  1542. int ret;
  1543. u32 reg, width, mask, shift, val, tmp;
  1544. unsigned long flags;
  1545. int i;
  1546. for (i = 0; i < num_configs; i++) {
  1547. param = pinconf_to_config_param(configs[i]);
  1548. arg = pinconf_to_config_argument(configs[i]);
  1549. dev_dbg(pctldev->dev, "%s(pin=%s, config=%#lx)\n",
  1550. __func__, tz1090_pins[pin].name, configs[i]);
  1551. /* Get register information */
  1552. ret = tz1090_pinconf_reg(pctldev, pin, param, true,
  1553. &reg, &width, &mask, &shift, &val);
  1554. if (ret < 0)
  1555. return ret;
  1556. /* Unpack argument and range check it */
  1557. if (arg > 1) {
  1558. dev_dbg(pctldev->dev, "%s: arg %u out of range\n",
  1559. __func__, arg);
  1560. return -EINVAL;
  1561. }
  1562. /* Write register field */
  1563. __global_lock2(flags);
  1564. tmp = pmx_read(pmx, reg);
  1565. tmp &= ~mask;
  1566. if (arg)
  1567. tmp |= val << shift;
  1568. pmx_write(pmx, tmp, reg);
  1569. __global_unlock2(flags);
  1570. } /* for each config */
  1571. return 0;
  1572. }
  1573. static const int tz1090_boolean_map[] = {
  1574. [0] = -EINVAL,
  1575. [1] = 1,
  1576. };
  1577. static const int tz1090_dr_map[] = {
  1578. [REG_DR_2mA] = 2,
  1579. [REG_DR_4mA] = 4,
  1580. [REG_DR_8mA] = 8,
  1581. [REG_DR_12mA] = 12,
  1582. };
  1583. static int tz1090_pinconf_group_reg(struct pinctrl_dev *pctldev,
  1584. const struct tz1090_pingroup *g,
  1585. enum pin_config_param param,
  1586. bool report_err,
  1587. u32 *reg, u32 *width, u32 *mask, u32 *shift,
  1588. const int **map)
  1589. {
  1590. /* Drive configuration applies in groups, but not to all groups. */
  1591. if (!g->drv) {
  1592. if (report_err)
  1593. dev_dbg(pctldev->dev,
  1594. "%s: group %s has no drive control\n",
  1595. __func__, g->name);
  1596. return -ENOTSUPP;
  1597. }
  1598. /* Find information about drive parameter's register */
  1599. switch (param) {
  1600. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  1601. *reg = REG_PINCTRL_SCHMITT;
  1602. *width = 1;
  1603. *map = tz1090_boolean_map;
  1604. break;
  1605. case PIN_CONFIG_DRIVE_STRENGTH:
  1606. *reg = REG_PINCTRL_DR;
  1607. *width = 2;
  1608. *map = tz1090_dr_map;
  1609. break;
  1610. default:
  1611. return -ENOTSUPP;
  1612. }
  1613. /* Calculate field information */
  1614. *shift = g->slw_bit * *width;
  1615. *mask = (BIT(*width) - 1) << *shift;
  1616. return 0;
  1617. }
  1618. static int tz1090_pinconf_group_get(struct pinctrl_dev *pctldev,
  1619. unsigned int group,
  1620. unsigned long *config)
  1621. {
  1622. struct tz1090_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  1623. const struct tz1090_pingroup *g;
  1624. enum pin_config_param param = pinconf_to_config_param(*config);
  1625. int ret, arg;
  1626. unsigned int pin;
  1627. u32 reg, width, mask, shift, val;
  1628. const int *map;
  1629. if (group >= ARRAY_SIZE(tz1090_groups)) {
  1630. pin = group - ARRAY_SIZE(tz1090_groups);
  1631. return tz1090_pinconf_get(pctldev, pin, config);
  1632. }
  1633. g = &tz1090_groups[group];
  1634. if (g->npins == 1) {
  1635. pin = g->pins[0];
  1636. ret = tz1090_pinconf_get(pctldev, pin, config);
  1637. if (ret != -ENOTSUPP)
  1638. return ret;
  1639. }
  1640. /* Get register information */
  1641. ret = tz1090_pinconf_group_reg(pctldev, g, param, true,
  1642. &reg, &width, &mask, &shift, &map);
  1643. if (ret < 0)
  1644. return ret;
  1645. /* Extract field from register */
  1646. val = pmx_read(pmx, reg);
  1647. arg = map[(val & mask) >> shift];
  1648. if (arg < 0)
  1649. return arg;
  1650. /* And pack config */
  1651. *config = pinconf_to_config_packed(param, arg);
  1652. return 0;
  1653. }
  1654. static int tz1090_pinconf_group_set(struct pinctrl_dev *pctldev,
  1655. unsigned int group, unsigned long *configs,
  1656. unsigned num_configs)
  1657. {
  1658. struct tz1090_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  1659. const struct tz1090_pingroup *g;
  1660. enum pin_config_param param;
  1661. unsigned int arg, pin, i;
  1662. const unsigned int *pit;
  1663. int ret;
  1664. u32 reg, width, mask, shift, val;
  1665. unsigned long flags;
  1666. const int *map;
  1667. int j;
  1668. if (group >= ARRAY_SIZE(tz1090_groups)) {
  1669. pin = group - ARRAY_SIZE(tz1090_groups);
  1670. return tz1090_pinconf_set(pctldev, pin, configs, num_configs);
  1671. }
  1672. g = &tz1090_groups[group];
  1673. if (g->npins == 1) {
  1674. pin = g->pins[0];
  1675. ret = tz1090_pinconf_set(pctldev, pin, configs, num_configs);
  1676. if (ret != -ENOTSUPP)
  1677. return ret;
  1678. }
  1679. for (j = 0; j < num_configs; j++) {
  1680. param = pinconf_to_config_param(configs[j]);
  1681. dev_dbg(pctldev->dev, "%s(group=%s, config=%#lx)\n",
  1682. __func__, g->name, configs[j]);
  1683. /* Get register information */
  1684. ret = tz1090_pinconf_group_reg(pctldev, g, param, true, &reg,
  1685. &width, &mask, &shift, &map);
  1686. if (ret < 0) {
  1687. /*
  1688. * Maybe we're trying to set a per-pin configuration
  1689. * of a group, so do the pins one by one. This is
  1690. * mainly as a convenience.
  1691. */
  1692. for (i = 0, pit = g->pins; i < g->npins; ++i, ++pit) {
  1693. ret = tz1090_pinconf_set(pctldev, *pit, configs,
  1694. num_configs);
  1695. if (ret)
  1696. return ret;
  1697. }
  1698. return 0;
  1699. }
  1700. /* Unpack argument and map it to register value */
  1701. arg = pinconf_to_config_argument(configs[j]);
  1702. for (i = 0; i < BIT(width); ++i) {
  1703. if (map[i] == arg || (map[i] == -EINVAL && !arg)) {
  1704. /* Write register field */
  1705. __global_lock2(flags);
  1706. val = pmx_read(pmx, reg);
  1707. val &= ~mask;
  1708. val |= i << shift;
  1709. pmx_write(pmx, val, reg);
  1710. __global_unlock2(flags);
  1711. goto next_config;
  1712. }
  1713. }
  1714. dev_dbg(pctldev->dev, "%s: arg %u not supported\n",
  1715. __func__, arg);
  1716. return -EINVAL;
  1717. next_config:
  1718. ;
  1719. } /* for each config */
  1720. return 0;
  1721. }
  1722. static struct pinconf_ops tz1090_pinconf_ops = {
  1723. .is_generic = true,
  1724. .pin_config_get = tz1090_pinconf_get,
  1725. .pin_config_set = tz1090_pinconf_set,
  1726. .pin_config_group_get = tz1090_pinconf_group_get,
  1727. .pin_config_group_set = tz1090_pinconf_group_set,
  1728. .pin_config_config_dbg_show = pinconf_generic_dump_config,
  1729. };
  1730. /*
  1731. * Pin control driver setup
  1732. */
  1733. static struct pinctrl_desc tz1090_pinctrl_desc = {
  1734. .pctlops = &tz1090_pinctrl_ops,
  1735. .pmxops = &tz1090_pinmux_ops,
  1736. .confops = &tz1090_pinconf_ops,
  1737. .owner = THIS_MODULE,
  1738. };
  1739. static int tz1090_pinctrl_probe(struct platform_device *pdev)
  1740. {
  1741. struct tz1090_pmx *pmx;
  1742. struct resource *res;
  1743. pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL);
  1744. if (!pmx) {
  1745. dev_err(&pdev->dev, "Can't alloc tz1090_pmx\n");
  1746. return -ENOMEM;
  1747. }
  1748. pmx->dev = &pdev->dev;
  1749. spin_lock_init(&pmx->lock);
  1750. tz1090_pinctrl_desc.name = dev_name(&pdev->dev);
  1751. tz1090_pinctrl_desc.pins = tz1090_pins;
  1752. tz1090_pinctrl_desc.npins = ARRAY_SIZE(tz1090_pins);
  1753. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1754. pmx->regs = devm_ioremap_resource(&pdev->dev, res);
  1755. if (IS_ERR(pmx->regs))
  1756. return PTR_ERR(pmx->regs);
  1757. pmx->pctl = pinctrl_register(&tz1090_pinctrl_desc, &pdev->dev, pmx);
  1758. if (IS_ERR(pmx->pctl)) {
  1759. dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
  1760. return PTR_ERR(pmx->pctl);
  1761. }
  1762. platform_set_drvdata(pdev, pmx);
  1763. dev_info(&pdev->dev, "TZ1090 pinctrl driver initialised\n");
  1764. return 0;
  1765. }
  1766. static int tz1090_pinctrl_remove(struct platform_device *pdev)
  1767. {
  1768. struct tz1090_pmx *pmx = platform_get_drvdata(pdev);
  1769. pinctrl_unregister(pmx->pctl);
  1770. return 0;
  1771. }
  1772. static const struct of_device_id tz1090_pinctrl_of_match[] = {
  1773. { .compatible = "img,tz1090-pinctrl", },
  1774. { },
  1775. };
  1776. static struct platform_driver tz1090_pinctrl_driver = {
  1777. .driver = {
  1778. .name = "tz1090-pinctrl",
  1779. .of_match_table = tz1090_pinctrl_of_match,
  1780. },
  1781. .probe = tz1090_pinctrl_probe,
  1782. .remove = tz1090_pinctrl_remove,
  1783. };
  1784. static int __init tz1090_pinctrl_init(void)
  1785. {
  1786. tz1090_init_mux_pins();
  1787. return platform_driver_register(&tz1090_pinctrl_driver);
  1788. }
  1789. arch_initcall(tz1090_pinctrl_init);
  1790. static void __exit tz1090_pinctrl_exit(void)
  1791. {
  1792. platform_driver_unregister(&tz1090_pinctrl_driver);
  1793. }
  1794. module_exit(tz1090_pinctrl_exit);
  1795. MODULE_AUTHOR("Imagination Technologies Ltd.");
  1796. MODULE_DESCRIPTION("Toumaz Xenif TZ1090 pinctrl driver");
  1797. MODULE_LICENSE("GPL v2");
  1798. MODULE_DEVICE_TABLE(of, tz1090_pinctrl_of_match);