pinctrl-baytrail.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Pinctrl GPIO driver for Intel Baytrail
  4. *
  5. * Copyright (c) 2012-2013, Intel Corporation
  6. * Author: Mathias Nyman <mathias.nyman@linux.intel.com>
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/array_size.h>
  10. #include <linux/bitops.h>
  11. #include <linux/cleanup.h>
  12. #include <linux/gpio/driver.h>
  13. #include <linux/init.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/io.h>
  16. #include <linux/module.h>
  17. #include <linux/types.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/pm.h>
  20. #include <linux/property.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/string_helpers.h>
  23. #include <linux/pinctrl/pinctrl.h>
  24. #include <linux/pinctrl/pinmux.h>
  25. #include <linux/pinctrl/pinconf.h>
  26. #include <linux/pinctrl/pinconf-generic.h>
  27. #include "pinctrl-intel.h"
  28. /* memory mapped register offsets */
  29. #define BYT_CONF0_REG 0x000
  30. #define BYT_CONF1_REG 0x004
  31. #define BYT_VAL_REG 0x008
  32. #define BYT_DFT_REG 0x00c
  33. #define BYT_INT_STAT_REG 0x800
  34. #define BYT_DIRECT_IRQ_REG 0x980
  35. #define BYT_DEBOUNCE_REG 0x9d0
  36. /* BYT_CONF0_REG register bits */
  37. #define BYT_IODEN BIT(31)
  38. #define BYT_DIRECT_IRQ_EN BIT(27)
  39. #define BYT_TRIG_MASK GENMASK(26, 24)
  40. #define BYT_TRIG_NEG BIT(26)
  41. #define BYT_TRIG_POS BIT(25)
  42. #define BYT_TRIG_LVL BIT(24)
  43. #define BYT_DEBOUNCE_EN BIT(20)
  44. #define BYT_GLITCH_FILTER_EN BIT(19)
  45. #define BYT_GLITCH_F_SLOW_CLK BIT(17)
  46. #define BYT_GLITCH_F_FAST_CLK BIT(16)
  47. #define BYT_PULL_STR_SHIFT 9
  48. #define BYT_PULL_STR_MASK GENMASK(10, 9)
  49. #define BYT_PULL_STR_2K (0 << BYT_PULL_STR_SHIFT)
  50. #define BYT_PULL_STR_10K (1 << BYT_PULL_STR_SHIFT)
  51. #define BYT_PULL_STR_20K (2 << BYT_PULL_STR_SHIFT)
  52. #define BYT_PULL_STR_40K (3 << BYT_PULL_STR_SHIFT)
  53. #define BYT_PULL_ASSIGN_MASK GENMASK(8, 7)
  54. #define BYT_PULL_ASSIGN_DOWN BIT(8)
  55. #define BYT_PULL_ASSIGN_UP BIT(7)
  56. #define BYT_PIN_MUX GENMASK(2, 0)
  57. /* BYT_VAL_REG register bits */
  58. #define BYT_DIR_MASK GENMASK(2, 1)
  59. #define BYT_INPUT_EN BIT(2) /* 0: input enabled (active low)*/
  60. #define BYT_OUTPUT_EN BIT(1) /* 0: output enabled (active low)*/
  61. #define BYT_LEVEL BIT(0)
  62. #define BYT_CONF0_RESTORE_MASK (BYT_DIRECT_IRQ_EN | BYT_TRIG_MASK | BYT_PIN_MUX)
  63. #define BYT_VAL_RESTORE_MASK (BYT_DIR_MASK | BYT_LEVEL)
  64. /* BYT_DEBOUNCE_REG bits */
  65. #define BYT_DEBOUNCE_PULSE_MASK GENMASK(2, 0)
  66. #define BYT_DEBOUNCE_PULSE_375US 1
  67. #define BYT_DEBOUNCE_PULSE_750US 2
  68. #define BYT_DEBOUNCE_PULSE_1500US 3
  69. #define BYT_DEBOUNCE_PULSE_3MS 4
  70. #define BYT_DEBOUNCE_PULSE_6MS 5
  71. #define BYT_DEBOUNCE_PULSE_12MS 6
  72. #define BYT_DEBOUNCE_PULSE_24MS 7
  73. #define BYT_NGPIO_SCORE 102
  74. #define BYT_NGPIO_NCORE 28
  75. #define BYT_NGPIO_SUS 44
  76. #define BYT_SCORE_ACPI_UID "1"
  77. #define BYT_NCORE_ACPI_UID "2"
  78. #define BYT_SUS_ACPI_UID "3"
  79. /*
  80. * This is the function value most pins have for GPIO muxing. If the value
  81. * differs from the default one, it must be explicitly mentioned. Otherwise, the
  82. * pin control implementation will set the muxing value to default GPIO if it
  83. * does not find a match for the requested function.
  84. */
  85. #define BYT_DEFAULT_GPIO_MUX 0
  86. #define BYT_ALTER_GPIO_MUX 1
  87. struct intel_pad_context {
  88. u32 conf0;
  89. u32 val;
  90. };
  91. #define COMMUNITY(p, n, map) \
  92. { \
  93. .pin_base = (p), \
  94. .npins = (n), \
  95. .pad_map = (map),\
  96. }
  97. /* SCORE pins, aka GPIOC_<pin_no> or GPIO_S0_SC[<pin_no>] */
  98. static const struct pinctrl_pin_desc byt_score_pins[] = {
  99. PINCTRL_PIN(0, "SATA_GP0"),
  100. PINCTRL_PIN(1, "SATA_GP1"),
  101. PINCTRL_PIN(2, "SATA_LED#"),
  102. PINCTRL_PIN(3, "PCIE_CLKREQ0"),
  103. PINCTRL_PIN(4, "PCIE_CLKREQ1"),
  104. PINCTRL_PIN(5, "PCIE_CLKREQ2"),
  105. PINCTRL_PIN(6, "PCIE_CLKREQ3"),
  106. PINCTRL_PIN(7, "SD3_WP"),
  107. PINCTRL_PIN(8, "HDA_RST"),
  108. PINCTRL_PIN(9, "HDA_SYNC"),
  109. PINCTRL_PIN(10, "HDA_CLK"),
  110. PINCTRL_PIN(11, "HDA_SDO"),
  111. PINCTRL_PIN(12, "HDA_SDI0"),
  112. PINCTRL_PIN(13, "HDA_SDI1"),
  113. PINCTRL_PIN(14, "GPIO_S0_SC14"),
  114. PINCTRL_PIN(15, "GPIO_S0_SC15"),
  115. PINCTRL_PIN(16, "MMC1_CLK"),
  116. PINCTRL_PIN(17, "MMC1_D0"),
  117. PINCTRL_PIN(18, "MMC1_D1"),
  118. PINCTRL_PIN(19, "MMC1_D2"),
  119. PINCTRL_PIN(20, "MMC1_D3"),
  120. PINCTRL_PIN(21, "MMC1_D4"),
  121. PINCTRL_PIN(22, "MMC1_D5"),
  122. PINCTRL_PIN(23, "MMC1_D6"),
  123. PINCTRL_PIN(24, "MMC1_D7"),
  124. PINCTRL_PIN(25, "MMC1_CMD"),
  125. PINCTRL_PIN(26, "MMC1_RST"),
  126. PINCTRL_PIN(27, "SD2_CLK"),
  127. PINCTRL_PIN(28, "SD2_D0"),
  128. PINCTRL_PIN(29, "SD2_D1"),
  129. PINCTRL_PIN(30, "SD2_D2"),
  130. PINCTRL_PIN(31, "SD2_D3_CD"),
  131. PINCTRL_PIN(32, "SD2_CMD"),
  132. PINCTRL_PIN(33, "SD3_CLK"),
  133. PINCTRL_PIN(34, "SD3_D0"),
  134. PINCTRL_PIN(35, "SD3_D1"),
  135. PINCTRL_PIN(36, "SD3_D2"),
  136. PINCTRL_PIN(37, "SD3_D3"),
  137. PINCTRL_PIN(38, "SD3_CD"),
  138. PINCTRL_PIN(39, "SD3_CMD"),
  139. PINCTRL_PIN(40, "SD3_1P8EN"),
  140. PINCTRL_PIN(41, "SD3_PWREN#"),
  141. PINCTRL_PIN(42, "ILB_LPC_AD0"),
  142. PINCTRL_PIN(43, "ILB_LPC_AD1"),
  143. PINCTRL_PIN(44, "ILB_LPC_AD2"),
  144. PINCTRL_PIN(45, "ILB_LPC_AD3"),
  145. PINCTRL_PIN(46, "ILB_LPC_FRAME"),
  146. PINCTRL_PIN(47, "ILB_LPC_CLK0"),
  147. PINCTRL_PIN(48, "ILB_LPC_CLK1"),
  148. PINCTRL_PIN(49, "ILB_LPC_CLKRUN"),
  149. PINCTRL_PIN(50, "ILB_LPC_SERIRQ"),
  150. PINCTRL_PIN(51, "PCU_SMB_DATA"),
  151. PINCTRL_PIN(52, "PCU_SMB_CLK"),
  152. PINCTRL_PIN(53, "PCU_SMB_ALERT"),
  153. PINCTRL_PIN(54, "ILB_8254_SPKR"),
  154. PINCTRL_PIN(55, "GPIO_S0_SC55"),
  155. PINCTRL_PIN(56, "GPIO_S0_SC56"),
  156. PINCTRL_PIN(57, "GPIO_S0_SC57"),
  157. PINCTRL_PIN(58, "GPIO_S0_SC58"),
  158. PINCTRL_PIN(59, "GPIO_S0_SC59"),
  159. PINCTRL_PIN(60, "GPIO_S0_SC60"),
  160. PINCTRL_PIN(61, "GPIO_S0_SC61"),
  161. PINCTRL_PIN(62, "LPE_I2S2_CLK"),
  162. PINCTRL_PIN(63, "LPE_I2S2_FRM"),
  163. PINCTRL_PIN(64, "LPE_I2S2_DATAIN"),
  164. PINCTRL_PIN(65, "LPE_I2S2_DATAOUT"),
  165. PINCTRL_PIN(66, "SIO_SPI_CS"),
  166. PINCTRL_PIN(67, "SIO_SPI_MISO"),
  167. PINCTRL_PIN(68, "SIO_SPI_MOSI"),
  168. PINCTRL_PIN(69, "SIO_SPI_CLK"),
  169. PINCTRL_PIN(70, "SIO_UART1_RXD"),
  170. PINCTRL_PIN(71, "SIO_UART1_TXD"),
  171. PINCTRL_PIN(72, "SIO_UART1_RTS"),
  172. PINCTRL_PIN(73, "SIO_UART1_CTS"),
  173. PINCTRL_PIN(74, "SIO_UART2_RXD"),
  174. PINCTRL_PIN(75, "SIO_UART2_TXD"),
  175. PINCTRL_PIN(76, "SIO_UART2_RTS"),
  176. PINCTRL_PIN(77, "SIO_UART2_CTS"),
  177. PINCTRL_PIN(78, "SIO_I2C0_DATA"),
  178. PINCTRL_PIN(79, "SIO_I2C0_CLK"),
  179. PINCTRL_PIN(80, "SIO_I2C1_DATA"),
  180. PINCTRL_PIN(81, "SIO_I2C1_CLK"),
  181. PINCTRL_PIN(82, "SIO_I2C2_DATA"),
  182. PINCTRL_PIN(83, "SIO_I2C2_CLK"),
  183. PINCTRL_PIN(84, "SIO_I2C3_DATA"),
  184. PINCTRL_PIN(85, "SIO_I2C3_CLK"),
  185. PINCTRL_PIN(86, "SIO_I2C4_DATA"),
  186. PINCTRL_PIN(87, "SIO_I2C4_CLK"),
  187. PINCTRL_PIN(88, "SIO_I2C5_DATA"),
  188. PINCTRL_PIN(89, "SIO_I2C5_CLK"),
  189. PINCTRL_PIN(90, "SIO_I2C6_DATA"),
  190. PINCTRL_PIN(91, "SIO_I2C6_CLK"),
  191. PINCTRL_PIN(92, "GPIO_S0_SC92"),
  192. PINCTRL_PIN(93, "GPIO_S0_SC93"),
  193. PINCTRL_PIN(94, "SIO_PWM0"),
  194. PINCTRL_PIN(95, "SIO_PWM1"),
  195. PINCTRL_PIN(96, "PMC_PLT_CLK0"),
  196. PINCTRL_PIN(97, "PMC_PLT_CLK1"),
  197. PINCTRL_PIN(98, "PMC_PLT_CLK2"),
  198. PINCTRL_PIN(99, "PMC_PLT_CLK3"),
  199. PINCTRL_PIN(100, "PMC_PLT_CLK4"),
  200. PINCTRL_PIN(101, "PMC_PLT_CLK5"),
  201. };
  202. static const unsigned int byt_score_pins_map[BYT_NGPIO_SCORE] = {
  203. 85, 89, 93, 96, 99, 102, 98, 101, 34, 37,
  204. 36, 38, 39, 35, 40, 84, 62, 61, 64, 59,
  205. 54, 56, 60, 55, 63, 57, 51, 50, 53, 47,
  206. 52, 49, 48, 43, 46, 41, 45, 42, 58, 44,
  207. 95, 105, 70, 68, 67, 66, 69, 71, 65, 72,
  208. 86, 90, 88, 92, 103, 77, 79, 83, 78, 81,
  209. 80, 82, 13, 12, 15, 14, 17, 18, 19, 16,
  210. 2, 1, 0, 4, 6, 7, 9, 8, 33, 32,
  211. 31, 30, 29, 27, 25, 28, 26, 23, 21, 20,
  212. 24, 22, 5, 3, 10, 11, 106, 87, 91, 104,
  213. 97, 100,
  214. };
  215. /* SCORE groups */
  216. static const unsigned int byt_score_uart1_pins[] = { 70, 71, 72, 73 };
  217. static const unsigned int byt_score_uart2_pins[] = { 74, 75, 76, 77 };
  218. static const unsigned int byt_score_uart3_pins[] = { 57, 61 };
  219. static const unsigned int byt_score_pwm0_pins[] = { 94 };
  220. static const unsigned int byt_score_pwm1_pins[] = { 95 };
  221. static const unsigned int byt_score_sio_spi_pins[] = { 66, 67, 68, 69 };
  222. static const unsigned int byt_score_i2c5_pins[] = { 88, 89 };
  223. static const unsigned int byt_score_i2c6_pins[] = { 90, 91 };
  224. static const unsigned int byt_score_i2c4_pins[] = { 86, 87 };
  225. static const unsigned int byt_score_i2c3_pins[] = { 84, 85 };
  226. static const unsigned int byt_score_i2c2_pins[] = { 82, 83 };
  227. static const unsigned int byt_score_i2c1_pins[] = { 80, 81 };
  228. static const unsigned int byt_score_i2c0_pins[] = { 78, 79 };
  229. static const unsigned int byt_score_ssp0_pins[] = { 8, 9, 10, 11 };
  230. static const unsigned int byt_score_ssp1_pins[] = { 12, 13, 14, 15 };
  231. static const unsigned int byt_score_ssp2_pins[] = { 62, 63, 64, 65 };
  232. static const unsigned int byt_score_sdcard_pins[] = {
  233. 7, 33, 34, 35, 36, 37, 38, 39, 40, 41,
  234. };
  235. static const unsigned int byt_score_sdcard_mux_values[] = {
  236. 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  237. };
  238. static const unsigned int byt_score_sdio_pins[] = { 27, 28, 29, 30, 31, 32 };
  239. static const unsigned int byt_score_emmc_pins[] = {
  240. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
  241. };
  242. static const unsigned int byt_score_ilb_lpc_pins[] = {
  243. 42, 43, 44, 45, 46, 47, 48, 49, 50,
  244. };
  245. static const unsigned int byt_score_sata_pins[] = { 0, 1, 2 };
  246. static const unsigned int byt_score_plt_clk0_pins[] = { 96 };
  247. static const unsigned int byt_score_plt_clk1_pins[] = { 97 };
  248. static const unsigned int byt_score_plt_clk2_pins[] = { 98 };
  249. static const unsigned int byt_score_plt_clk3_pins[] = { 99 };
  250. static const unsigned int byt_score_plt_clk4_pins[] = { 100 };
  251. static const unsigned int byt_score_plt_clk5_pins[] = { 101 };
  252. static const unsigned int byt_score_smbus_pins[] = { 51, 52, 53 };
  253. static const struct intel_pingroup byt_score_groups[] = {
  254. PIN_GROUP_GPIO("uart1_grp", byt_score_uart1_pins, 1),
  255. PIN_GROUP_GPIO("uart2_grp", byt_score_uart2_pins, 1),
  256. PIN_GROUP_GPIO("uart3_grp", byt_score_uart3_pins, 1),
  257. PIN_GROUP_GPIO("pwm0_grp", byt_score_pwm0_pins, 1),
  258. PIN_GROUP_GPIO("pwm1_grp", byt_score_pwm1_pins, 1),
  259. PIN_GROUP_GPIO("ssp2_grp", byt_score_ssp2_pins, 1),
  260. PIN_GROUP_GPIO("sio_spi_grp", byt_score_sio_spi_pins, 1),
  261. PIN_GROUP_GPIO("i2c5_grp", byt_score_i2c5_pins, 1),
  262. PIN_GROUP_GPIO("i2c6_grp", byt_score_i2c6_pins, 1),
  263. PIN_GROUP_GPIO("i2c4_grp", byt_score_i2c4_pins, 1),
  264. PIN_GROUP_GPIO("i2c3_grp", byt_score_i2c3_pins, 1),
  265. PIN_GROUP_GPIO("i2c2_grp", byt_score_i2c2_pins, 1),
  266. PIN_GROUP_GPIO("i2c1_grp", byt_score_i2c1_pins, 1),
  267. PIN_GROUP_GPIO("i2c0_grp", byt_score_i2c0_pins, 1),
  268. PIN_GROUP_GPIO("ssp0_grp", byt_score_ssp0_pins, 1),
  269. PIN_GROUP_GPIO("ssp1_grp", byt_score_ssp1_pins, 1),
  270. PIN_GROUP_GPIO("sdcard_grp", byt_score_sdcard_pins, byt_score_sdcard_mux_values),
  271. PIN_GROUP_GPIO("sdio_grp", byt_score_sdio_pins, 1),
  272. PIN_GROUP_GPIO("emmc_grp", byt_score_emmc_pins, 1),
  273. PIN_GROUP_GPIO("lpc_grp", byt_score_ilb_lpc_pins, 1),
  274. PIN_GROUP_GPIO("sata_grp", byt_score_sata_pins, 1),
  275. PIN_GROUP_GPIO("plt_clk0_grp", byt_score_plt_clk0_pins, 1),
  276. PIN_GROUP_GPIO("plt_clk1_grp", byt_score_plt_clk1_pins, 1),
  277. PIN_GROUP_GPIO("plt_clk2_grp", byt_score_plt_clk2_pins, 1),
  278. PIN_GROUP_GPIO("plt_clk3_grp", byt_score_plt_clk3_pins, 1),
  279. PIN_GROUP_GPIO("plt_clk4_grp", byt_score_plt_clk4_pins, 1),
  280. PIN_GROUP_GPIO("plt_clk5_grp", byt_score_plt_clk5_pins, 1),
  281. PIN_GROUP_GPIO("smbus_grp", byt_score_smbus_pins, 1),
  282. };
  283. static const char * const byt_score_uart_groups[] = {
  284. "uart1_grp", "uart2_grp", "uart3_grp",
  285. };
  286. static const char * const byt_score_pwm_groups[] = {
  287. "pwm0_grp", "pwm1_grp",
  288. };
  289. static const char * const byt_score_ssp_groups[] = {
  290. "ssp0_grp", "ssp1_grp", "ssp2_grp",
  291. };
  292. static const char * const byt_score_spi_groups[] = { "sio_spi_grp" };
  293. static const char * const byt_score_i2c_groups[] = {
  294. "i2c0_grp", "i2c1_grp", "i2c2_grp", "i2c3_grp", "i2c4_grp", "i2c5_grp",
  295. "i2c6_grp",
  296. };
  297. static const char * const byt_score_sdcard_groups[] = { "sdcard_grp" };
  298. static const char * const byt_score_sdio_groups[] = { "sdio_grp" };
  299. static const char * const byt_score_emmc_groups[] = { "emmc_grp" };
  300. static const char * const byt_score_lpc_groups[] = { "lpc_grp" };
  301. static const char * const byt_score_sata_groups[] = { "sata_grp" };
  302. static const char * const byt_score_plt_clk_groups[] = {
  303. "plt_clk0_grp", "plt_clk1_grp", "plt_clk2_grp", "plt_clk3_grp",
  304. "plt_clk4_grp", "plt_clk5_grp",
  305. };
  306. static const char * const byt_score_smbus_groups[] = { "smbus_grp" };
  307. static const char * const byt_score_gpio_groups[] = {
  308. "uart1_grp_gpio", "uart2_grp_gpio", "uart3_grp_gpio", "pwm0_grp_gpio",
  309. "pwm1_grp_gpio", "ssp0_grp_gpio", "ssp1_grp_gpio", "ssp2_grp_gpio",
  310. "sio_spi_grp_gpio", "i2c0_grp_gpio", "i2c1_grp_gpio", "i2c2_grp_gpio",
  311. "i2c3_grp_gpio", "i2c4_grp_gpio", "i2c5_grp_gpio", "i2c6_grp_gpio",
  312. "sdcard_grp_gpio", "sdio_grp_gpio", "emmc_grp_gpio", "lpc_grp_gpio",
  313. "sata_grp_gpio", "plt_clk0_grp_gpio", "plt_clk1_grp_gpio",
  314. "plt_clk2_grp_gpio", "plt_clk3_grp_gpio", "plt_clk4_grp_gpio",
  315. "plt_clk5_grp_gpio", "smbus_grp_gpio",
  316. };
  317. static const struct intel_function byt_score_functions[] = {
  318. FUNCTION("uart", byt_score_uart_groups),
  319. FUNCTION("pwm", byt_score_pwm_groups),
  320. FUNCTION("ssp", byt_score_ssp_groups),
  321. FUNCTION("spi", byt_score_spi_groups),
  322. FUNCTION("i2c", byt_score_i2c_groups),
  323. FUNCTION("sdcard", byt_score_sdcard_groups),
  324. FUNCTION("sdio", byt_score_sdio_groups),
  325. FUNCTION("emmc", byt_score_emmc_groups),
  326. FUNCTION("lpc", byt_score_lpc_groups),
  327. FUNCTION("sata", byt_score_sata_groups),
  328. FUNCTION("plt_clk", byt_score_plt_clk_groups),
  329. FUNCTION("smbus", byt_score_smbus_groups),
  330. FUNCTION("gpio", byt_score_gpio_groups),
  331. };
  332. static const struct intel_community byt_score_communities[] = {
  333. COMMUNITY(0, BYT_NGPIO_SCORE, byt_score_pins_map),
  334. };
  335. static const struct intel_pinctrl_soc_data byt_score_soc_data = {
  336. .uid = BYT_SCORE_ACPI_UID,
  337. .pins = byt_score_pins,
  338. .npins = ARRAY_SIZE(byt_score_pins),
  339. .groups = byt_score_groups,
  340. .ngroups = ARRAY_SIZE(byt_score_groups),
  341. .functions = byt_score_functions,
  342. .nfunctions = ARRAY_SIZE(byt_score_functions),
  343. .communities = byt_score_communities,
  344. .ncommunities = ARRAY_SIZE(byt_score_communities),
  345. };
  346. /* SUS pins, aka GPIOS_<pin_no> or GPIO_S5[<pin_no>] */
  347. static const struct pinctrl_pin_desc byt_sus_pins[] = {
  348. PINCTRL_PIN(0, "GPIO_S50"),
  349. PINCTRL_PIN(1, "GPIO_S51"),
  350. PINCTRL_PIN(2, "GPIO_S52"),
  351. PINCTRL_PIN(3, "GPIO_S53"),
  352. PINCTRL_PIN(4, "GPIO_S54"),
  353. PINCTRL_PIN(5, "GPIO_S55"),
  354. PINCTRL_PIN(6, "GPIO_S56"),
  355. PINCTRL_PIN(7, "GPIO_S57"),
  356. PINCTRL_PIN(8, "GPIO_S58"),
  357. PINCTRL_PIN(9, "GPIO_S59"),
  358. PINCTRL_PIN(10, "GPIO_S510"),
  359. PINCTRL_PIN(11, "PMC_SUSPWRDNACK"),
  360. PINCTRL_PIN(12, "PMC_SUSCLK0"),
  361. PINCTRL_PIN(13, "GPIO_S513"),
  362. PINCTRL_PIN(14, "USB_ULPI_RST"),
  363. PINCTRL_PIN(15, "PMC_WAKE_PCIE0#"),
  364. PINCTRL_PIN(16, "PMC_PWRBTN"),
  365. PINCTRL_PIN(17, "GPIO_S517"),
  366. PINCTRL_PIN(18, "PMC_SUS_STAT"),
  367. PINCTRL_PIN(19, "USB_OC0"),
  368. PINCTRL_PIN(20, "USB_OC1"),
  369. PINCTRL_PIN(21, "PCU_SPI_CS1"),
  370. PINCTRL_PIN(22, "GPIO_S522"),
  371. PINCTRL_PIN(23, "GPIO_S523"),
  372. PINCTRL_PIN(24, "GPIO_S524"),
  373. PINCTRL_PIN(25, "GPIO_S525"),
  374. PINCTRL_PIN(26, "GPIO_S526"),
  375. PINCTRL_PIN(27, "GPIO_S527"),
  376. PINCTRL_PIN(28, "GPIO_S528"),
  377. PINCTRL_PIN(29, "GPIO_S529"),
  378. PINCTRL_PIN(30, "GPIO_S530"),
  379. PINCTRL_PIN(31, "USB_ULPI_CLK"),
  380. PINCTRL_PIN(32, "USB_ULPI_DATA0"),
  381. PINCTRL_PIN(33, "USB_ULPI_DATA1"),
  382. PINCTRL_PIN(34, "USB_ULPI_DATA2"),
  383. PINCTRL_PIN(35, "USB_ULPI_DATA3"),
  384. PINCTRL_PIN(36, "USB_ULPI_DATA4"),
  385. PINCTRL_PIN(37, "USB_ULPI_DATA5"),
  386. PINCTRL_PIN(38, "USB_ULPI_DATA6"),
  387. PINCTRL_PIN(39, "USB_ULPI_DATA7"),
  388. PINCTRL_PIN(40, "USB_ULPI_DIR"),
  389. PINCTRL_PIN(41, "USB_ULPI_NXT"),
  390. PINCTRL_PIN(42, "USB_ULPI_STP"),
  391. PINCTRL_PIN(43, "USB_ULPI_REFCLK"),
  392. };
  393. static const unsigned int byt_sus_pins_map[BYT_NGPIO_SUS] = {
  394. 29, 33, 30, 31, 32, 34, 36, 35, 38, 37,
  395. 18, 7, 11, 20, 17, 1, 8, 10, 19, 12,
  396. 0, 2, 23, 39, 28, 27, 22, 21, 24, 25,
  397. 26, 51, 56, 54, 49, 55, 48, 57, 50, 58,
  398. 52, 53, 59, 40,
  399. };
  400. static const unsigned int byt_sus_usb_over_current_pins[] = { 19, 20 };
  401. static const unsigned int byt_sus_usb_over_current_mode_values[] = { 0, 0 };
  402. static const unsigned int byt_sus_usb_over_current_gpio_mode_values[] = { 1, 1 };
  403. static const unsigned int byt_sus_usb_ulpi_pins[] = {
  404. 14, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
  405. };
  406. static const unsigned int byt_sus_usb_ulpi_mode_values[] = {
  407. 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  408. };
  409. static const unsigned int byt_sus_usb_ulpi_gpio_mode_values[] = {
  410. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  411. };
  412. static const unsigned int byt_sus_pcu_spi_pins[] = { 21 };
  413. static const unsigned int byt_sus_pcu_spi_mode_values[] = { 0 };
  414. static const unsigned int byt_sus_pcu_spi_gpio_mode_values[] = { 1 };
  415. static const unsigned int byt_sus_pmu_clk1_pins[] = { 5 };
  416. static const unsigned int byt_sus_pmu_clk2_pins[] = { 6 };
  417. static const struct intel_pingroup byt_sus_groups[] = {
  418. PIN_GROUP("usb_oc_grp", byt_sus_usb_over_current_pins, byt_sus_usb_over_current_mode_values),
  419. PIN_GROUP("usb_ulpi_grp", byt_sus_usb_ulpi_pins, byt_sus_usb_ulpi_mode_values),
  420. PIN_GROUP("pcu_spi_grp", byt_sus_pcu_spi_pins, byt_sus_pcu_spi_mode_values),
  421. PIN_GROUP("usb_oc_grp_gpio", byt_sus_usb_over_current_pins, byt_sus_usb_over_current_gpio_mode_values),
  422. PIN_GROUP("usb_ulpi_grp_gpio", byt_sus_usb_ulpi_pins, byt_sus_usb_ulpi_gpio_mode_values),
  423. PIN_GROUP("pcu_spi_grp_gpio", byt_sus_pcu_spi_pins, byt_sus_pcu_spi_gpio_mode_values),
  424. PIN_GROUP_GPIO("pmu_clk1_grp", byt_sus_pmu_clk1_pins, 1),
  425. PIN_GROUP_GPIO("pmu_clk2_grp", byt_sus_pmu_clk2_pins, 1),
  426. };
  427. static const char * const byt_sus_usb_groups[] = {
  428. "usb_oc_grp", "usb_ulpi_grp",
  429. };
  430. static const char * const byt_sus_spi_groups[] = { "pcu_spi_grp" };
  431. static const char * const byt_sus_pmu_clk_groups[] = {
  432. "pmu_clk1_grp", "pmu_clk2_grp",
  433. };
  434. static const char * const byt_sus_gpio_groups[] = {
  435. "usb_oc_grp_gpio", "usb_ulpi_grp_gpio", "pcu_spi_grp_gpio",
  436. "pmu_clk1_grp_gpio", "pmu_clk2_grp_gpio",
  437. };
  438. static const struct intel_function byt_sus_functions[] = {
  439. FUNCTION("usb", byt_sus_usb_groups),
  440. FUNCTION("spi", byt_sus_spi_groups),
  441. FUNCTION("gpio", byt_sus_gpio_groups),
  442. FUNCTION("pmu_clk", byt_sus_pmu_clk_groups),
  443. };
  444. static const struct intel_community byt_sus_communities[] = {
  445. COMMUNITY(0, BYT_NGPIO_SUS, byt_sus_pins_map),
  446. };
  447. static const struct intel_pinctrl_soc_data byt_sus_soc_data = {
  448. .uid = BYT_SUS_ACPI_UID,
  449. .pins = byt_sus_pins,
  450. .npins = ARRAY_SIZE(byt_sus_pins),
  451. .groups = byt_sus_groups,
  452. .ngroups = ARRAY_SIZE(byt_sus_groups),
  453. .functions = byt_sus_functions,
  454. .nfunctions = ARRAY_SIZE(byt_sus_functions),
  455. .communities = byt_sus_communities,
  456. .ncommunities = ARRAY_SIZE(byt_sus_communities),
  457. };
  458. static const struct pinctrl_pin_desc byt_ncore_pins[] = {
  459. PINCTRL_PIN(0, "HV_DDI0_HPD"),
  460. PINCTRL_PIN(1, "HV_DDI0_DDC_SDA"),
  461. PINCTRL_PIN(2, "HV_DDI0_DDC_SCL"),
  462. PINCTRL_PIN(3, "PANEL0_VDDEN"),
  463. PINCTRL_PIN(4, "PANEL0_BKLTEN"),
  464. PINCTRL_PIN(5, "PANEL0_BKLTCTL"),
  465. PINCTRL_PIN(6, "HV_DDI1_HPD"),
  466. PINCTRL_PIN(7, "HV_DDI1_DDC_SDA"),
  467. PINCTRL_PIN(8, "HV_DDI1_DDC_SCL"),
  468. PINCTRL_PIN(9, "PANEL1_VDDEN"),
  469. PINCTRL_PIN(10, "PANEL1_BKLTEN"),
  470. PINCTRL_PIN(11, "PANEL1_BKLTCTL"),
  471. PINCTRL_PIN(12, "GP_INTD_DSI_TE1"),
  472. PINCTRL_PIN(13, "HV_DDI2_DDC_SDA"),
  473. PINCTRL_PIN(14, "HV_DDI2_DDC_SCL"),
  474. PINCTRL_PIN(15, "GP_CAMERASB00"),
  475. PINCTRL_PIN(16, "GP_CAMERASB01"),
  476. PINCTRL_PIN(17, "GP_CAMERASB02"),
  477. PINCTRL_PIN(18, "GP_CAMERASB03"),
  478. PINCTRL_PIN(19, "GP_CAMERASB04"),
  479. PINCTRL_PIN(20, "GP_CAMERASB05"),
  480. PINCTRL_PIN(21, "GP_CAMERASB06"),
  481. PINCTRL_PIN(22, "GP_CAMERASB07"),
  482. PINCTRL_PIN(23, "GP_CAMERASB08"),
  483. PINCTRL_PIN(24, "GP_CAMERASB09"),
  484. PINCTRL_PIN(25, "GP_CAMERASB10"),
  485. PINCTRL_PIN(26, "GP_CAMERASB11"),
  486. PINCTRL_PIN(27, "GP_INTD_DSI_TE2"),
  487. };
  488. static const unsigned int byt_ncore_pins_map[BYT_NGPIO_NCORE] = {
  489. 19, 18, 17, 20, 21, 22, 24, 25, 23, 16,
  490. 14, 15, 12, 26, 27, 1, 4, 8, 11, 0,
  491. 3, 6, 10, 13, 2, 5, 9, 7,
  492. };
  493. static const struct intel_community byt_ncore_communities[] = {
  494. COMMUNITY(0, BYT_NGPIO_NCORE, byt_ncore_pins_map),
  495. };
  496. static const struct intel_pinctrl_soc_data byt_ncore_soc_data = {
  497. .uid = BYT_NCORE_ACPI_UID,
  498. .pins = byt_ncore_pins,
  499. .npins = ARRAY_SIZE(byt_ncore_pins),
  500. .communities = byt_ncore_communities,
  501. .ncommunities = ARRAY_SIZE(byt_ncore_communities),
  502. };
  503. static const struct intel_pinctrl_soc_data *byt_soc_data[] = {
  504. &byt_score_soc_data,
  505. &byt_sus_soc_data,
  506. &byt_ncore_soc_data,
  507. NULL
  508. };
  509. static DEFINE_RAW_SPINLOCK(byt_lock);
  510. static void __iomem *byt_gpio_reg(struct intel_pinctrl *vg, unsigned int offset,
  511. int reg)
  512. {
  513. const struct intel_community *comm;
  514. u32 reg_offset;
  515. comm = intel_get_community(vg, offset);
  516. if (!comm)
  517. return NULL;
  518. offset -= comm->pin_base;
  519. switch (reg) {
  520. case BYT_INT_STAT_REG:
  521. reg_offset = (offset / 32) * 4;
  522. break;
  523. case BYT_DEBOUNCE_REG:
  524. reg_offset = 0;
  525. break;
  526. default:
  527. reg_offset = comm->pad_map[offset] * 16;
  528. break;
  529. }
  530. return comm->pad_regs + reg_offset + reg;
  531. }
  532. static const struct pinctrl_ops byt_pinctrl_ops = {
  533. .get_groups_count = intel_get_groups_count,
  534. .get_group_name = intel_get_group_name,
  535. .get_group_pins = intel_get_group_pins,
  536. };
  537. static void byt_set_group_simple_mux(struct intel_pinctrl *vg,
  538. const struct intel_pingroup group,
  539. unsigned int func)
  540. {
  541. int i;
  542. guard(raw_spinlock_irqsave)(&byt_lock);
  543. for (i = 0; i < group.grp.npins; i++) {
  544. void __iomem *padcfg0;
  545. u32 value;
  546. padcfg0 = byt_gpio_reg(vg, group.grp.pins[i], BYT_CONF0_REG);
  547. if (!padcfg0) {
  548. dev_warn(vg->dev, "Group %s, pin %i not muxed (can't retrieve CONF0)\n",
  549. group.grp.name, i);
  550. continue;
  551. }
  552. value = readl(padcfg0);
  553. value &= ~BYT_PIN_MUX;
  554. value |= func;
  555. writel(value, padcfg0);
  556. }
  557. }
  558. static void byt_set_group_mixed_mux(struct intel_pinctrl *vg,
  559. const struct intel_pingroup group,
  560. const unsigned int *func)
  561. {
  562. int i;
  563. guard(raw_spinlock_irqsave)(&byt_lock);
  564. for (i = 0; i < group.grp.npins; i++) {
  565. void __iomem *padcfg0;
  566. u32 value;
  567. padcfg0 = byt_gpio_reg(vg, group.grp.pins[i], BYT_CONF0_REG);
  568. if (!padcfg0) {
  569. dev_warn(vg->dev, "Group %s, pin %i not muxed (can't retrieve CONF0)\n",
  570. group.grp.name, i);
  571. continue;
  572. }
  573. value = readl(padcfg0);
  574. value &= ~BYT_PIN_MUX;
  575. value |= func[i];
  576. writel(value, padcfg0);
  577. }
  578. }
  579. static int byt_set_mux(struct pinctrl_dev *pctldev, unsigned int func_selector,
  580. unsigned int group_selector)
  581. {
  582. struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctldev);
  583. const struct intel_function func = vg->soc->functions[func_selector];
  584. const struct intel_pingroup group = vg->soc->groups[group_selector];
  585. if (group.modes)
  586. byt_set_group_mixed_mux(vg, group, group.modes);
  587. else if (!strcmp(func.func.name, "gpio"))
  588. byt_set_group_simple_mux(vg, group, BYT_DEFAULT_GPIO_MUX);
  589. else
  590. byt_set_group_simple_mux(vg, group, group.mode);
  591. return 0;
  592. }
  593. static u32 byt_get_gpio_mux(struct intel_pinctrl *vg, unsigned int offset)
  594. {
  595. /* SCORE pin 92-93 */
  596. if (!strcmp(vg->soc->uid, BYT_SCORE_ACPI_UID) &&
  597. offset >= 92 && offset <= 93)
  598. return BYT_ALTER_GPIO_MUX;
  599. /* SUS pin 11-21 */
  600. if (!strcmp(vg->soc->uid, BYT_SUS_ACPI_UID) &&
  601. offset >= 11 && offset <= 21)
  602. return BYT_ALTER_GPIO_MUX;
  603. return BYT_DEFAULT_GPIO_MUX;
  604. }
  605. static void byt_gpio_clear_triggering(struct intel_pinctrl *vg, unsigned int offset)
  606. {
  607. void __iomem *reg = byt_gpio_reg(vg, offset, BYT_CONF0_REG);
  608. u32 value;
  609. guard(raw_spinlock_irqsave)(&byt_lock);
  610. value = readl(reg);
  611. /* Do not clear direct-irq enabled IRQs (from gpio_disable_free) */
  612. if (!(value & BYT_DIRECT_IRQ_EN))
  613. value &= ~(BYT_TRIG_POS | BYT_TRIG_NEG | BYT_TRIG_LVL);
  614. writel(value, reg);
  615. }
  616. static int byt_gpio_request_enable(struct pinctrl_dev *pctl_dev,
  617. struct pinctrl_gpio_range *range,
  618. unsigned int offset)
  619. {
  620. struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctl_dev);
  621. void __iomem *reg = byt_gpio_reg(vg, offset, BYT_CONF0_REG);
  622. u32 value, gpio_mux;
  623. guard(raw_spinlock_irqsave)(&byt_lock);
  624. /*
  625. * In most cases, func pin mux 000 means GPIO function.
  626. * But, some pins may have func pin mux 001 represents
  627. * GPIO function.
  628. *
  629. * Because there are devices out there where some pins were not
  630. * configured correctly we allow changing the mux value from
  631. * request (but print out warning about that).
  632. */
  633. value = readl(reg) & BYT_PIN_MUX;
  634. gpio_mux = byt_get_gpio_mux(vg, offset);
  635. if (gpio_mux == value)
  636. return 0;
  637. value = readl(reg) & ~BYT_PIN_MUX;
  638. value |= gpio_mux;
  639. writel(value, reg);
  640. dev_warn(vg->dev, FW_BUG "Pin %i: forcibly re-configured as GPIO\n", offset);
  641. return 0;
  642. }
  643. static void byt_gpio_disable_free(struct pinctrl_dev *pctl_dev,
  644. struct pinctrl_gpio_range *range,
  645. unsigned int offset)
  646. {
  647. struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctl_dev);
  648. byt_gpio_clear_triggering(vg, offset);
  649. }
  650. static void byt_gpio_direct_irq_check(struct intel_pinctrl *vg,
  651. unsigned int offset)
  652. {
  653. void __iomem *conf_reg = byt_gpio_reg(vg, offset, BYT_CONF0_REG);
  654. /*
  655. * Before making any direction modifications, do a check if gpio is set
  656. * for direct IRQ. On Bay Trail, setting GPIO to output does not make
  657. * sense, so let's at least inform the caller before they shoot
  658. * themselves in the foot.
  659. */
  660. if (readl(conf_reg) & BYT_DIRECT_IRQ_EN)
  661. dev_info_once(vg->dev,
  662. "Potential Error: Pin %i: forcibly set GPIO with DIRECT_IRQ_EN to output\n",
  663. offset);
  664. }
  665. static int byt_gpio_set_direction(struct pinctrl_dev *pctl_dev,
  666. struct pinctrl_gpio_range *range,
  667. unsigned int offset,
  668. bool input)
  669. {
  670. struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctl_dev);
  671. void __iomem *val_reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  672. u32 value;
  673. guard(raw_spinlock_irqsave)(&byt_lock);
  674. value = readl(val_reg);
  675. value &= ~BYT_DIR_MASK;
  676. if (input)
  677. value |= BYT_OUTPUT_EN;
  678. else
  679. byt_gpio_direct_irq_check(vg, offset);
  680. writel(value, val_reg);
  681. return 0;
  682. }
  683. static const struct pinmux_ops byt_pinmux_ops = {
  684. .get_functions_count = intel_get_functions_count,
  685. .get_function_name = intel_get_function_name,
  686. .get_function_groups = intel_get_function_groups,
  687. .set_mux = byt_set_mux,
  688. .gpio_request_enable = byt_gpio_request_enable,
  689. .gpio_disable_free = byt_gpio_disable_free,
  690. .gpio_set_direction = byt_gpio_set_direction,
  691. };
  692. static void byt_get_pull_strength(u32 reg, u16 *strength)
  693. {
  694. switch (reg & BYT_PULL_STR_MASK) {
  695. case BYT_PULL_STR_2K:
  696. *strength = 2000;
  697. break;
  698. case BYT_PULL_STR_10K:
  699. *strength = 10000;
  700. break;
  701. case BYT_PULL_STR_20K:
  702. *strength = 20000;
  703. break;
  704. case BYT_PULL_STR_40K:
  705. *strength = 40000;
  706. break;
  707. }
  708. }
  709. static int byt_set_pull_strength(u32 *reg, u16 strength)
  710. {
  711. *reg &= ~BYT_PULL_STR_MASK;
  712. switch (strength) {
  713. case 1: /* Set default strength value in case none is given */
  714. case 2000:
  715. *reg |= BYT_PULL_STR_2K;
  716. break;
  717. case 10000:
  718. *reg |= BYT_PULL_STR_10K;
  719. break;
  720. case 20000:
  721. *reg |= BYT_PULL_STR_20K;
  722. break;
  723. case 40000:
  724. *reg |= BYT_PULL_STR_40K;
  725. break;
  726. default:
  727. return -EINVAL;
  728. }
  729. return 0;
  730. }
  731. static void byt_gpio_force_input_mode(struct intel_pinctrl *vg, unsigned int offset)
  732. {
  733. void __iomem *reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  734. u32 value;
  735. value = readl(reg);
  736. if (!(value & BYT_INPUT_EN))
  737. return;
  738. /*
  739. * Pull assignment is only applicable in input mode. If
  740. * chip is not in input mode, set it and warn about it.
  741. */
  742. value &= ~BYT_INPUT_EN;
  743. writel(value, reg);
  744. dev_warn(vg->dev, "Pin %i: forcibly set to input mode\n", offset);
  745. }
  746. static int byt_pin_config_get(struct pinctrl_dev *pctl_dev, unsigned int offset,
  747. unsigned long *config)
  748. {
  749. struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctl_dev);
  750. enum pin_config_param param = pinconf_to_config_param(*config);
  751. void __iomem *conf_reg = byt_gpio_reg(vg, offset, BYT_CONF0_REG);
  752. void __iomem *val_reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  753. void __iomem *db_reg = byt_gpio_reg(vg, offset, BYT_DEBOUNCE_REG);
  754. u32 conf, pull, val, debounce;
  755. u16 arg = 0;
  756. scoped_guard(raw_spinlock_irqsave, &byt_lock) {
  757. conf = readl(conf_reg);
  758. val = readl(val_reg);
  759. }
  760. pull = conf & BYT_PULL_ASSIGN_MASK;
  761. switch (param) {
  762. case PIN_CONFIG_BIAS_DISABLE:
  763. if (pull)
  764. return -EINVAL;
  765. break;
  766. case PIN_CONFIG_BIAS_PULL_DOWN:
  767. /* Pull assignment is only applicable in input mode */
  768. if ((val & BYT_INPUT_EN) || pull != BYT_PULL_ASSIGN_DOWN)
  769. return -EINVAL;
  770. byt_get_pull_strength(conf, &arg);
  771. break;
  772. case PIN_CONFIG_BIAS_PULL_UP:
  773. /* Pull assignment is only applicable in input mode */
  774. if ((val & BYT_INPUT_EN) || pull != BYT_PULL_ASSIGN_UP)
  775. return -EINVAL;
  776. byt_get_pull_strength(conf, &arg);
  777. break;
  778. case PIN_CONFIG_INPUT_DEBOUNCE:
  779. if (!(conf & BYT_DEBOUNCE_EN))
  780. return -EINVAL;
  781. scoped_guard(raw_spinlock_irqsave, &byt_lock)
  782. debounce = readl(db_reg);
  783. switch (debounce & BYT_DEBOUNCE_PULSE_MASK) {
  784. case BYT_DEBOUNCE_PULSE_375US:
  785. arg = 375;
  786. break;
  787. case BYT_DEBOUNCE_PULSE_750US:
  788. arg = 750;
  789. break;
  790. case BYT_DEBOUNCE_PULSE_1500US:
  791. arg = 1500;
  792. break;
  793. case BYT_DEBOUNCE_PULSE_3MS:
  794. arg = 3000;
  795. break;
  796. case BYT_DEBOUNCE_PULSE_6MS:
  797. arg = 6000;
  798. break;
  799. case BYT_DEBOUNCE_PULSE_12MS:
  800. arg = 12000;
  801. break;
  802. case BYT_DEBOUNCE_PULSE_24MS:
  803. arg = 24000;
  804. break;
  805. default:
  806. return -EINVAL;
  807. }
  808. break;
  809. default:
  810. return -ENOTSUPP;
  811. }
  812. *config = pinconf_to_config_packed(param, arg);
  813. return 0;
  814. }
  815. static int byt_pin_config_set(struct pinctrl_dev *pctl_dev,
  816. unsigned int offset,
  817. unsigned long *configs,
  818. unsigned int num_configs)
  819. {
  820. struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctl_dev);
  821. void __iomem *conf_reg = byt_gpio_reg(vg, offset, BYT_CONF0_REG);
  822. void __iomem *db_reg = byt_gpio_reg(vg, offset, BYT_DEBOUNCE_REG);
  823. u32 conf, db_pulse, debounce;
  824. enum pin_config_param param;
  825. int i, ret;
  826. u32 arg;
  827. guard(raw_spinlock_irqsave)(&byt_lock);
  828. conf = readl(conf_reg);
  829. for (i = 0; i < num_configs; i++) {
  830. param = pinconf_to_config_param(configs[i]);
  831. arg = pinconf_to_config_argument(configs[i]);
  832. switch (param) {
  833. case PIN_CONFIG_BIAS_DISABLE:
  834. conf &= ~BYT_PULL_ASSIGN_MASK;
  835. break;
  836. case PIN_CONFIG_BIAS_PULL_DOWN:
  837. byt_gpio_force_input_mode(vg, offset);
  838. conf &= ~BYT_PULL_ASSIGN_MASK;
  839. conf |= BYT_PULL_ASSIGN_DOWN;
  840. ret = byt_set_pull_strength(&conf, arg);
  841. if (ret)
  842. return ret;
  843. break;
  844. case PIN_CONFIG_BIAS_PULL_UP:
  845. byt_gpio_force_input_mode(vg, offset);
  846. conf &= ~BYT_PULL_ASSIGN_MASK;
  847. conf |= BYT_PULL_ASSIGN_UP;
  848. ret = byt_set_pull_strength(&conf, arg);
  849. if (ret)
  850. return ret;
  851. break;
  852. case PIN_CONFIG_INPUT_DEBOUNCE:
  853. switch (arg) {
  854. case 0:
  855. db_pulse = 0;
  856. break;
  857. case 375:
  858. db_pulse = BYT_DEBOUNCE_PULSE_375US;
  859. break;
  860. case 750:
  861. db_pulse = BYT_DEBOUNCE_PULSE_750US;
  862. break;
  863. case 1500:
  864. db_pulse = BYT_DEBOUNCE_PULSE_1500US;
  865. break;
  866. case 3000:
  867. db_pulse = BYT_DEBOUNCE_PULSE_3MS;
  868. break;
  869. case 6000:
  870. db_pulse = BYT_DEBOUNCE_PULSE_6MS;
  871. break;
  872. case 12000:
  873. db_pulse = BYT_DEBOUNCE_PULSE_12MS;
  874. break;
  875. case 24000:
  876. db_pulse = BYT_DEBOUNCE_PULSE_24MS;
  877. break;
  878. default:
  879. return -EINVAL;
  880. }
  881. if (db_pulse) {
  882. debounce = readl(db_reg);
  883. debounce = (debounce & ~BYT_DEBOUNCE_PULSE_MASK) | db_pulse;
  884. writel(debounce, db_reg);
  885. conf |= BYT_DEBOUNCE_EN;
  886. } else {
  887. conf &= ~BYT_DEBOUNCE_EN;
  888. }
  889. break;
  890. default:
  891. return -ENOTSUPP;
  892. }
  893. }
  894. writel(conf, conf_reg);
  895. return 0;
  896. }
  897. static const struct pinconf_ops byt_pinconf_ops = {
  898. .is_generic = true,
  899. .pin_config_get = byt_pin_config_get,
  900. .pin_config_set = byt_pin_config_set,
  901. };
  902. static const struct pinctrl_desc byt_pinctrl_desc = {
  903. .pctlops = &byt_pinctrl_ops,
  904. .pmxops = &byt_pinmux_ops,
  905. .confops = &byt_pinconf_ops,
  906. .owner = THIS_MODULE,
  907. };
  908. static int byt_gpio_get(struct gpio_chip *chip, unsigned int offset)
  909. {
  910. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  911. void __iomem *reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  912. u32 val;
  913. scoped_guard(raw_spinlock_irqsave, &byt_lock)
  914. val = readl(reg);
  915. return !!(val & BYT_LEVEL);
  916. }
  917. static void byt_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
  918. {
  919. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  920. void __iomem *reg;
  921. u32 old_val;
  922. reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  923. if (!reg)
  924. return;
  925. guard(raw_spinlock_irqsave)(&byt_lock);
  926. old_val = readl(reg);
  927. if (value)
  928. writel(old_val | BYT_LEVEL, reg);
  929. else
  930. writel(old_val & ~BYT_LEVEL, reg);
  931. }
  932. static int byt_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
  933. {
  934. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  935. void __iomem *reg;
  936. u32 value;
  937. reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  938. if (!reg)
  939. return -EINVAL;
  940. scoped_guard(raw_spinlock_irqsave, &byt_lock)
  941. value = readl(reg);
  942. if (!(value & BYT_OUTPUT_EN))
  943. return GPIO_LINE_DIRECTION_OUT;
  944. if (!(value & BYT_INPUT_EN))
  945. return GPIO_LINE_DIRECTION_IN;
  946. return -EINVAL;
  947. }
  948. static int byt_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
  949. {
  950. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  951. void __iomem *val_reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  952. u32 reg;
  953. guard(raw_spinlock_irqsave)(&byt_lock);
  954. reg = readl(val_reg);
  955. reg &= ~BYT_DIR_MASK;
  956. reg |= BYT_OUTPUT_EN;
  957. writel(reg, val_reg);
  958. return 0;
  959. }
  960. /*
  961. * Note despite the temptation this MUST NOT be converted into a call to
  962. * pinctrl_gpio_direction_output() + byt_gpio_set() that does not work this
  963. * MUST be done as a single BYT_VAL_REG register write.
  964. * See the commit message of the commit adding this comment for details.
  965. */
  966. static int byt_gpio_direction_output(struct gpio_chip *chip,
  967. unsigned int offset, int value)
  968. {
  969. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  970. void __iomem *val_reg = byt_gpio_reg(vg, offset, BYT_VAL_REG);
  971. u32 reg;
  972. guard(raw_spinlock_irqsave)(&byt_lock);
  973. byt_gpio_direct_irq_check(vg, offset);
  974. reg = readl(val_reg);
  975. reg &= ~BYT_DIR_MASK;
  976. if (value)
  977. reg |= BYT_LEVEL;
  978. else
  979. reg &= ~BYT_LEVEL;
  980. writel(reg, val_reg);
  981. return 0;
  982. }
  983. static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  984. {
  985. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  986. int i;
  987. u32 conf0, val;
  988. for (i = 0; i < vg->soc->npins; i++) {
  989. const struct intel_community *comm;
  990. void __iomem *conf_reg, *val_reg;
  991. const char *pull_str = NULL;
  992. const char *pull = NULL;
  993. unsigned int pin;
  994. pin = vg->soc->pins[i].number;
  995. conf_reg = byt_gpio_reg(vg, pin, BYT_CONF0_REG);
  996. if (!conf_reg) {
  997. seq_printf(s, "Pin %i: can't retrieve CONF0\n", pin);
  998. continue;
  999. }
  1000. val_reg = byt_gpio_reg(vg, pin, BYT_VAL_REG);
  1001. if (!val_reg) {
  1002. seq_printf(s, "Pin %i: can't retrieve VAL\n", pin);
  1003. continue;
  1004. }
  1005. scoped_guard(raw_spinlock_irqsave, &byt_lock) {
  1006. conf0 = readl(conf_reg);
  1007. val = readl(val_reg);
  1008. }
  1009. comm = intel_get_community(vg, pin);
  1010. if (!comm) {
  1011. seq_printf(s, "Pin %i: can't retrieve community\n", pin);
  1012. continue;
  1013. }
  1014. char *label __free(kfree) = gpiochip_dup_line_label(chip, i);
  1015. if (IS_ERR(label))
  1016. continue;
  1017. switch (conf0 & BYT_PULL_ASSIGN_MASK) {
  1018. case BYT_PULL_ASSIGN_UP:
  1019. pull = "up";
  1020. break;
  1021. case BYT_PULL_ASSIGN_DOWN:
  1022. pull = "down";
  1023. break;
  1024. }
  1025. switch (conf0 & BYT_PULL_STR_MASK) {
  1026. case BYT_PULL_STR_2K:
  1027. pull_str = "2k";
  1028. break;
  1029. case BYT_PULL_STR_10K:
  1030. pull_str = "10k";
  1031. break;
  1032. case BYT_PULL_STR_20K:
  1033. pull_str = "20k";
  1034. break;
  1035. case BYT_PULL_STR_40K:
  1036. pull_str = "40k";
  1037. break;
  1038. }
  1039. seq_printf(s,
  1040. " gpio-%-3d (%-20.20s) %s %s %s pad-%-3d offset:0x%03x mux:%d %s%s%s",
  1041. pin,
  1042. label ?: "Unrequested",
  1043. val & BYT_INPUT_EN ? " " : "in",
  1044. val & BYT_OUTPUT_EN ? " " : "out",
  1045. str_hi_lo(val & BYT_LEVEL),
  1046. comm->pad_map[i], comm->pad_map[i] * 16,
  1047. conf0 & 0x7,
  1048. conf0 & BYT_TRIG_NEG ? " fall" : " ",
  1049. conf0 & BYT_TRIG_POS ? " rise" : " ",
  1050. conf0 & BYT_TRIG_LVL ? " level" : " ");
  1051. if (pull && pull_str)
  1052. seq_printf(s, " %-4s %-3s", pull, pull_str);
  1053. else
  1054. seq_puts(s, " ");
  1055. if (conf0 & BYT_IODEN)
  1056. seq_puts(s, " open-drain");
  1057. seq_puts(s, "\n");
  1058. }
  1059. }
  1060. static const struct gpio_chip byt_gpio_chip = {
  1061. .owner = THIS_MODULE,
  1062. .request = gpiochip_generic_request,
  1063. .free = gpiochip_generic_free,
  1064. .get_direction = byt_gpio_get_direction,
  1065. .direction_input = byt_gpio_direction_input,
  1066. .direction_output = byt_gpio_direction_output,
  1067. .get = byt_gpio_get,
  1068. .set = byt_gpio_set,
  1069. .set_config = gpiochip_generic_config,
  1070. .dbg_show = byt_gpio_dbg_show,
  1071. };
  1072. static void byt_irq_ack(struct irq_data *d)
  1073. {
  1074. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  1075. struct intel_pinctrl *vg = gpiochip_get_data(gc);
  1076. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1077. void __iomem *reg;
  1078. reg = byt_gpio_reg(vg, hwirq, BYT_INT_STAT_REG);
  1079. if (!reg)
  1080. return;
  1081. guard(raw_spinlock)(&byt_lock);
  1082. writel(BIT(hwirq % 32), reg);
  1083. }
  1084. static void byt_irq_mask(struct irq_data *d)
  1085. {
  1086. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  1087. struct intel_pinctrl *vg = gpiochip_get_data(gc);
  1088. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1089. byt_gpio_clear_triggering(vg, hwirq);
  1090. gpiochip_disable_irq(gc, hwirq);
  1091. }
  1092. static void byt_irq_unmask(struct irq_data *d)
  1093. {
  1094. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  1095. struct intel_pinctrl *vg = gpiochip_get_data(gc);
  1096. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1097. void __iomem *reg;
  1098. u32 value;
  1099. gpiochip_enable_irq(gc, hwirq);
  1100. reg = byt_gpio_reg(vg, hwirq, BYT_CONF0_REG);
  1101. if (!reg)
  1102. return;
  1103. guard(raw_spinlock_irqsave)(&byt_lock);
  1104. value = readl(reg);
  1105. switch (irqd_get_trigger_type(d)) {
  1106. case IRQ_TYPE_LEVEL_HIGH:
  1107. value |= BYT_TRIG_LVL;
  1108. fallthrough;
  1109. case IRQ_TYPE_EDGE_RISING:
  1110. value |= BYT_TRIG_POS;
  1111. break;
  1112. case IRQ_TYPE_LEVEL_LOW:
  1113. value |= BYT_TRIG_LVL;
  1114. fallthrough;
  1115. case IRQ_TYPE_EDGE_FALLING:
  1116. value |= BYT_TRIG_NEG;
  1117. break;
  1118. case IRQ_TYPE_EDGE_BOTH:
  1119. value |= (BYT_TRIG_NEG | BYT_TRIG_POS);
  1120. break;
  1121. }
  1122. writel(value, reg);
  1123. }
  1124. static int byt_irq_type(struct irq_data *d, unsigned int type)
  1125. {
  1126. struct intel_pinctrl *vg = gpiochip_get_data(irq_data_get_irq_chip_data(d));
  1127. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1128. void __iomem *reg;
  1129. u32 value;
  1130. reg = byt_gpio_reg(vg, hwirq, BYT_CONF0_REG);
  1131. if (!reg)
  1132. return -EINVAL;
  1133. guard(raw_spinlock_irqsave)(&byt_lock);
  1134. value = readl(reg);
  1135. WARN(value & BYT_DIRECT_IRQ_EN,
  1136. "Bad pad config for IO mode, force DIRECT_IRQ_EN bit clearing");
  1137. /* For level trigges the BYT_TRIG_POS and BYT_TRIG_NEG bits
  1138. * are used to indicate high and low level triggering
  1139. */
  1140. value &= ~(BYT_DIRECT_IRQ_EN | BYT_TRIG_POS | BYT_TRIG_NEG |
  1141. BYT_TRIG_LVL);
  1142. /* Enable glitch filtering */
  1143. value |= BYT_GLITCH_FILTER_EN | BYT_GLITCH_F_SLOW_CLK |
  1144. BYT_GLITCH_F_FAST_CLK;
  1145. writel(value, reg);
  1146. if (type & IRQ_TYPE_EDGE_BOTH)
  1147. irq_set_handler_locked(d, handle_edge_irq);
  1148. else if (type & IRQ_TYPE_LEVEL_MASK)
  1149. irq_set_handler_locked(d, handle_level_irq);
  1150. return 0;
  1151. }
  1152. static const struct irq_chip byt_gpio_irq_chip = {
  1153. .name = "BYT-GPIO",
  1154. .irq_ack = byt_irq_ack,
  1155. .irq_mask = byt_irq_mask,
  1156. .irq_unmask = byt_irq_unmask,
  1157. .irq_set_type = byt_irq_type,
  1158. .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED | IRQCHIP_IMMUTABLE,
  1159. GPIOCHIP_IRQ_RESOURCE_HELPERS,
  1160. };
  1161. static void byt_gpio_irq_handler(struct irq_desc *desc)
  1162. {
  1163. struct irq_data *data = irq_desc_get_irq_data(desc);
  1164. struct intel_pinctrl *vg = gpiochip_get_data(irq_desc_get_handler_data(desc));
  1165. struct irq_chip *chip = irq_data_get_irq_chip(data);
  1166. u32 base, pin;
  1167. void __iomem *reg;
  1168. unsigned long pending;
  1169. /* check from GPIO controller which pin triggered the interrupt */
  1170. for (base = 0; base < vg->chip.ngpio; base += 32) {
  1171. reg = byt_gpio_reg(vg, base, BYT_INT_STAT_REG);
  1172. if (!reg) {
  1173. dev_warn(vg->dev, "Pin %i: can't retrieve INT_STAT%u\n", base / 32, base);
  1174. continue;
  1175. }
  1176. scoped_guard(raw_spinlock, &byt_lock)
  1177. pending = readl(reg);
  1178. for_each_set_bit(pin, &pending, 32)
  1179. generic_handle_domain_irq(vg->chip.irq.domain, base + pin);
  1180. }
  1181. chip->irq_eoi(data);
  1182. }
  1183. static bool byt_direct_irq_sanity_check(struct intel_pinctrl *vg, int pin, u32 conf0)
  1184. {
  1185. int direct_irq, ioapic_direct_irq_base;
  1186. u8 *match, direct_irq_mux[16];
  1187. u32 trig;
  1188. memcpy_fromio(direct_irq_mux, vg->communities->pad_regs + BYT_DIRECT_IRQ_REG,
  1189. sizeof(direct_irq_mux));
  1190. match = memchr(direct_irq_mux, pin, sizeof(direct_irq_mux));
  1191. if (!match) {
  1192. dev_warn(vg->dev, FW_BUG "Pin %i: DIRECT_IRQ_EN set but no IRQ assigned, clearing\n", pin);
  1193. return false;
  1194. }
  1195. direct_irq = match - direct_irq_mux;
  1196. /* Base IO-APIC pin numbers come from atom-e3800-family-datasheet.pdf */
  1197. ioapic_direct_irq_base = (vg->communities->npins == BYT_NGPIO_SCORE) ? 51 : 67;
  1198. dev_dbg(vg->dev, "Pin %i: uses direct IRQ %d (IO-APIC %d)\n", pin,
  1199. direct_irq, direct_irq + ioapic_direct_irq_base);
  1200. /*
  1201. * Testing has shown that the way direct IRQs work is that the combination of the
  1202. * direct-irq-en flag and the direct IRQ mux connect the output of the GPIO's IRQ
  1203. * trigger block, which normally sets the status flag in the IRQ status reg at
  1204. * 0x800, to one of the IO-APIC pins according to the mux registers.
  1205. *
  1206. * This means that:
  1207. * 1. The TRIG_MASK bits must be set to configure the GPIO's IRQ trigger block
  1208. * 2. The TRIG_LVL bit *must* be set, so that the GPIO's input value is directly
  1209. * passed (1:1 or inverted) to the IO-APIC pin, if TRIG_LVL is not set,
  1210. * selecting edge mode operation then on the first edge the IO-APIC pin goes
  1211. * high, but since no write-to-clear write will be done to the IRQ status reg
  1212. * at 0x800, the detected edge condition will never get cleared.
  1213. */
  1214. trig = conf0 & BYT_TRIG_MASK;
  1215. if (trig != (BYT_TRIG_POS | BYT_TRIG_LVL) &&
  1216. trig != (BYT_TRIG_NEG | BYT_TRIG_LVL)) {
  1217. dev_warn(vg->dev,
  1218. FW_BUG "Pin %i: DIRECT_IRQ_EN set without trigger (CONF0: %#08x), clearing\n",
  1219. pin, conf0);
  1220. return false;
  1221. }
  1222. return true;
  1223. }
  1224. static void byt_init_irq_valid_mask(struct gpio_chip *chip,
  1225. unsigned long *valid_mask,
  1226. unsigned int ngpios)
  1227. {
  1228. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  1229. void __iomem *reg;
  1230. u32 value;
  1231. int i;
  1232. /*
  1233. * Clear interrupt triggers for all pins that are GPIOs and
  1234. * do not use direct IRQ mode. This will prevent spurious
  1235. * interrupts from misconfigured pins.
  1236. */
  1237. for (i = 0; i < vg->soc->npins; i++) {
  1238. unsigned int pin = vg->soc->pins[i].number;
  1239. reg = byt_gpio_reg(vg, pin, BYT_CONF0_REG);
  1240. if (!reg) {
  1241. dev_warn(vg->dev, "Pin %i: could not retrieve CONF0\n", i);
  1242. continue;
  1243. }
  1244. value = readl(reg);
  1245. if (value & BYT_DIRECT_IRQ_EN) {
  1246. if (byt_direct_irq_sanity_check(vg, i, value)) {
  1247. clear_bit(i, valid_mask);
  1248. } else {
  1249. value &= ~(BYT_DIRECT_IRQ_EN | BYT_TRIG_POS |
  1250. BYT_TRIG_NEG | BYT_TRIG_LVL);
  1251. writel(value, reg);
  1252. }
  1253. } else if ((value & BYT_PIN_MUX) == byt_get_gpio_mux(vg, i)) {
  1254. byt_gpio_clear_triggering(vg, i);
  1255. dev_dbg(vg->dev, "disabling GPIO %d\n", i);
  1256. }
  1257. }
  1258. }
  1259. static int byt_gpio_irq_init_hw(struct gpio_chip *chip)
  1260. {
  1261. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  1262. void __iomem *reg;
  1263. u32 base, value;
  1264. /* clear interrupt status trigger registers */
  1265. for (base = 0; base < vg->soc->npins; base += 32) {
  1266. reg = byt_gpio_reg(vg, base, BYT_INT_STAT_REG);
  1267. if (!reg) {
  1268. dev_warn(vg->dev, "Pin %i: can't retrieve INT_STAT%u\n", base / 32, base);
  1269. continue;
  1270. }
  1271. writel(0xffffffff, reg);
  1272. /* make sure trigger bits are cleared, if not then a pin
  1273. might be misconfigured in bios */
  1274. value = readl(reg);
  1275. if (value)
  1276. dev_err(vg->dev,
  1277. "GPIO interrupt error, pins misconfigured. INT_STAT%u: %#08x\n",
  1278. base / 32, value);
  1279. }
  1280. return 0;
  1281. }
  1282. static int byt_gpio_add_pin_ranges(struct gpio_chip *chip)
  1283. {
  1284. struct intel_pinctrl *vg = gpiochip_get_data(chip);
  1285. struct device *dev = vg->dev;
  1286. int ret;
  1287. ret = gpiochip_add_pin_range(chip, dev_name(dev), 0, 0, vg->soc->npins);
  1288. if (ret)
  1289. dev_err(dev, "failed to add GPIO pin range\n");
  1290. return ret;
  1291. }
  1292. static int byt_gpio_probe(struct intel_pinctrl *vg)
  1293. {
  1294. struct platform_device *pdev = to_platform_device(vg->dev);
  1295. struct gpio_chip *gc;
  1296. int irq, ret;
  1297. /* Set up gpio chip */
  1298. vg->chip = byt_gpio_chip;
  1299. gc = &vg->chip;
  1300. gc->label = dev_name(vg->dev);
  1301. gc->base = -1;
  1302. gc->can_sleep = false;
  1303. gc->add_pin_ranges = byt_gpio_add_pin_ranges;
  1304. gc->parent = vg->dev;
  1305. gc->ngpio = vg->soc->npins;
  1306. #ifdef CONFIG_PM_SLEEP
  1307. vg->context.pads = devm_kcalloc(vg->dev, gc->ngpio, sizeof(*vg->context.pads),
  1308. GFP_KERNEL);
  1309. if (!vg->context.pads)
  1310. return -ENOMEM;
  1311. #endif
  1312. /* set up interrupts */
  1313. irq = platform_get_irq_optional(pdev, 0);
  1314. if (irq > 0) {
  1315. struct gpio_irq_chip *girq;
  1316. girq = &gc->irq;
  1317. gpio_irq_chip_set_chip(girq, &byt_gpio_irq_chip);
  1318. girq->init_hw = byt_gpio_irq_init_hw;
  1319. girq->init_valid_mask = byt_init_irq_valid_mask;
  1320. girq->parent_handler = byt_gpio_irq_handler;
  1321. girq->num_parents = 1;
  1322. girq->parents = devm_kcalloc(vg->dev, girq->num_parents,
  1323. sizeof(*girq->parents), GFP_KERNEL);
  1324. if (!girq->parents)
  1325. return -ENOMEM;
  1326. girq->parents[0] = irq;
  1327. girq->default_type = IRQ_TYPE_NONE;
  1328. girq->handler = handle_bad_irq;
  1329. }
  1330. ret = devm_gpiochip_add_data(vg->dev, gc, vg);
  1331. if (ret)
  1332. dev_err(vg->dev, "failed adding byt-gpio chip\n");
  1333. return ret;
  1334. }
  1335. static int byt_set_soc_data(struct intel_pinctrl *vg,
  1336. const struct intel_pinctrl_soc_data *soc)
  1337. {
  1338. struct platform_device *pdev = to_platform_device(vg->dev);
  1339. int i;
  1340. vg->soc = soc;
  1341. vg->ncommunities = vg->soc->ncommunities;
  1342. vg->communities = devm_kcalloc(vg->dev, vg->ncommunities,
  1343. sizeof(*vg->communities), GFP_KERNEL);
  1344. if (!vg->communities)
  1345. return -ENOMEM;
  1346. for (i = 0; i < vg->soc->ncommunities; i++) {
  1347. struct intel_community *comm = vg->communities + i;
  1348. *comm = vg->soc->communities[i];
  1349. comm->pad_regs = devm_platform_ioremap_resource(pdev, 0);
  1350. if (IS_ERR(comm->pad_regs))
  1351. return PTR_ERR(comm->pad_regs);
  1352. }
  1353. return 0;
  1354. }
  1355. static const struct acpi_device_id byt_gpio_acpi_match[] = {
  1356. { "INT33B2", (kernel_ulong_t)byt_soc_data },
  1357. { "INT33FC", (kernel_ulong_t)byt_soc_data },
  1358. { }
  1359. };
  1360. static int byt_pinctrl_probe(struct platform_device *pdev)
  1361. {
  1362. const struct intel_pinctrl_soc_data *soc_data;
  1363. struct device *dev = &pdev->dev;
  1364. struct intel_pinctrl *vg;
  1365. int ret;
  1366. soc_data = intel_pinctrl_get_soc_data(pdev);
  1367. if (IS_ERR(soc_data))
  1368. return PTR_ERR(soc_data);
  1369. vg = devm_kzalloc(dev, sizeof(*vg), GFP_KERNEL);
  1370. if (!vg)
  1371. return -ENOMEM;
  1372. vg->dev = dev;
  1373. ret = byt_set_soc_data(vg, soc_data);
  1374. if (ret) {
  1375. dev_err(dev, "failed to set soc data\n");
  1376. return ret;
  1377. }
  1378. vg->pctldesc = byt_pinctrl_desc;
  1379. vg->pctldesc.name = dev_name(dev);
  1380. vg->pctldesc.pins = vg->soc->pins;
  1381. vg->pctldesc.npins = vg->soc->npins;
  1382. vg->pctldev = devm_pinctrl_register(dev, &vg->pctldesc, vg);
  1383. if (IS_ERR(vg->pctldev)) {
  1384. dev_err(dev, "failed to register pinctrl driver\n");
  1385. return PTR_ERR(vg->pctldev);
  1386. }
  1387. ret = byt_gpio_probe(vg);
  1388. if (ret)
  1389. return ret;
  1390. platform_set_drvdata(pdev, vg);
  1391. return 0;
  1392. }
  1393. static int byt_gpio_suspend(struct device *dev)
  1394. {
  1395. struct intel_pinctrl *vg = dev_get_drvdata(dev);
  1396. int i;
  1397. guard(raw_spinlock_irqsave)(&byt_lock);
  1398. for (i = 0; i < vg->soc->npins; i++) {
  1399. void __iomem *reg;
  1400. u32 value;
  1401. unsigned int pin = vg->soc->pins[i].number;
  1402. reg = byt_gpio_reg(vg, pin, BYT_CONF0_REG);
  1403. if (!reg) {
  1404. dev_warn(vg->dev, "Pin %i: can't retrieve CONF0\n", i);
  1405. continue;
  1406. }
  1407. value = readl(reg) & BYT_CONF0_RESTORE_MASK;
  1408. vg->context.pads[i].conf0 = value;
  1409. reg = byt_gpio_reg(vg, pin, BYT_VAL_REG);
  1410. if (!reg) {
  1411. dev_warn(vg->dev, "Pin %i: can't retrieve VAL\n", i);
  1412. continue;
  1413. }
  1414. value = readl(reg) & BYT_VAL_RESTORE_MASK;
  1415. vg->context.pads[i].val = value;
  1416. }
  1417. return 0;
  1418. }
  1419. static int byt_gpio_resume(struct device *dev)
  1420. {
  1421. struct intel_pinctrl *vg = dev_get_drvdata(dev);
  1422. int i;
  1423. guard(raw_spinlock_irqsave)(&byt_lock);
  1424. for (i = 0; i < vg->soc->npins; i++) {
  1425. void __iomem *reg;
  1426. u32 value;
  1427. unsigned int pin = vg->soc->pins[i].number;
  1428. reg = byt_gpio_reg(vg, pin, BYT_CONF0_REG);
  1429. if (!reg) {
  1430. dev_warn(vg->dev, "Pin %i: can't retrieve CONF0\n", i);
  1431. continue;
  1432. }
  1433. value = readl(reg);
  1434. if ((value & BYT_CONF0_RESTORE_MASK) !=
  1435. vg->context.pads[i].conf0) {
  1436. value &= ~BYT_CONF0_RESTORE_MASK;
  1437. value |= vg->context.pads[i].conf0;
  1438. writel(value, reg);
  1439. dev_info(dev, "restored pin %d CONF0 %#08x", i, value);
  1440. }
  1441. reg = byt_gpio_reg(vg, pin, BYT_VAL_REG);
  1442. if (!reg) {
  1443. dev_warn(vg->dev, "Pin %i: can't retrieve VAL\n", i);
  1444. continue;
  1445. }
  1446. value = readl(reg);
  1447. if ((value & BYT_VAL_RESTORE_MASK) !=
  1448. vg->context.pads[i].val) {
  1449. u32 v;
  1450. v = value & ~BYT_VAL_RESTORE_MASK;
  1451. v |= vg->context.pads[i].val;
  1452. if (v != value) {
  1453. writel(v, reg);
  1454. dev_dbg(dev, "restored pin %d VAL %#08x\n", i, v);
  1455. }
  1456. }
  1457. }
  1458. return 0;
  1459. }
  1460. static const struct dev_pm_ops byt_gpio_pm_ops = {
  1461. LATE_SYSTEM_SLEEP_PM_OPS(byt_gpio_suspend, byt_gpio_resume)
  1462. };
  1463. static struct platform_driver byt_gpio_driver = {
  1464. .probe = byt_pinctrl_probe,
  1465. .driver = {
  1466. .name = "byt_gpio",
  1467. .pm = pm_sleep_ptr(&byt_gpio_pm_ops),
  1468. .acpi_match_table = byt_gpio_acpi_match,
  1469. .suppress_bind_attrs = true,
  1470. },
  1471. };
  1472. static int __init byt_gpio_init(void)
  1473. {
  1474. return platform_driver_register(&byt_gpio_driver);
  1475. }
  1476. subsys_initcall(byt_gpio_init);
  1477. MODULE_IMPORT_NS(PINCTRL_INTEL);