pinctrl-mt8135.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: Hongzhou.Yang <hongzhou.yang@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/of.h>
  17. #include <linux/of_device.h>
  18. #include <linux/pinctrl/pinctrl.h>
  19. #include <linux/regmap.h>
  20. #include <dt-bindings/pinctrl/mt65xx.h>
  21. #include "pinctrl-mtk-common.h"
  22. #include "pinctrl-mtk-mt8135.h"
  23. #define DRV_BASE1 0x500
  24. #define DRV_BASE2 0x510
  25. #define PUPD_BASE1 0x400
  26. #define PUPD_BASE2 0x450
  27. #define R0_BASE1 0x4d0
  28. #define R1_BASE1 0x200
  29. #define R1_BASE2 0x250
  30. struct mtk_spec_pull_set {
  31. unsigned char pin;
  32. unsigned char pupd_bit;
  33. unsigned short pupd_offset;
  34. unsigned short r0_offset;
  35. unsigned short r1_offset;
  36. unsigned char r0_bit;
  37. unsigned char r1_bit;
  38. };
  39. #define SPEC_PULL(_pin, _pupd_offset, _pupd_bit, _r0_offset, \
  40. _r0_bit, _r1_offset, _r1_bit) \
  41. { \
  42. .pin = _pin, \
  43. .pupd_offset = _pupd_offset, \
  44. .pupd_bit = _pupd_bit, \
  45. .r0_offset = _r0_offset, \
  46. .r0_bit = _r0_bit, \
  47. .r1_offset = _r1_offset, \
  48. .r1_bit = _r1_bit, \
  49. }
  50. static const struct mtk_drv_group_desc mt8135_drv_grp[] = {
  51. /* E8E4E2 2/4/6/8/10/12/14/16 */
  52. MTK_DRV_GRP(2, 16, 0, 2, 2),
  53. /* E8E4 4/8/12/16 */
  54. MTK_DRV_GRP(4, 16, 1, 2, 4),
  55. /* E4E2 2/4/6/8 */
  56. MTK_DRV_GRP(2, 8, 0, 1, 2),
  57. /* E16E8E4 4/8/12/16/20/24/28/32 */
  58. MTK_DRV_GRP(4, 32, 0, 2, 4)
  59. };
  60. static const struct mtk_pin_drv_grp mt8135_pin_drv[] = {
  61. MTK_PIN_DRV_GRP(0, DRV_BASE1, 0, 0),
  62. MTK_PIN_DRV_GRP(1, DRV_BASE1, 0, 0),
  63. MTK_PIN_DRV_GRP(2, DRV_BASE1, 0, 0),
  64. MTK_PIN_DRV_GRP(3, DRV_BASE1, 0, 0),
  65. MTK_PIN_DRV_GRP(4, DRV_BASE1, 4, 0),
  66. MTK_PIN_DRV_GRP(5, DRV_BASE1, 8, 0),
  67. MTK_PIN_DRV_GRP(6, DRV_BASE1, 0, 0),
  68. MTK_PIN_DRV_GRP(7, DRV_BASE1, 0, 0),
  69. MTK_PIN_DRV_GRP(8, DRV_BASE1, 0, 0),
  70. MTK_PIN_DRV_GRP(9, DRV_BASE1, 0, 0),
  71. MTK_PIN_DRV_GRP(10, DRV_BASE1, 12, 1),
  72. MTK_PIN_DRV_GRP(11, DRV_BASE1, 12, 1),
  73. MTK_PIN_DRV_GRP(12, DRV_BASE1, 12, 1),
  74. MTK_PIN_DRV_GRP(13, DRV_BASE1, 12, 1),
  75. MTK_PIN_DRV_GRP(14, DRV_BASE1, 12, 1),
  76. MTK_PIN_DRV_GRP(15, DRV_BASE1, 12, 1),
  77. MTK_PIN_DRV_GRP(16, DRV_BASE1, 12, 1),
  78. MTK_PIN_DRV_GRP(17, DRV_BASE1, 16, 1),
  79. MTK_PIN_DRV_GRP(18, DRV_BASE1, 16, 1),
  80. MTK_PIN_DRV_GRP(19, DRV_BASE1, 16, 1),
  81. MTK_PIN_DRV_GRP(20, DRV_BASE1, 16, 1),
  82. MTK_PIN_DRV_GRP(21, DRV_BASE1, 16, 1),
  83. MTK_PIN_DRV_GRP(22, DRV_BASE1, 16, 1),
  84. MTK_PIN_DRV_GRP(23, DRV_BASE1, 16, 1),
  85. MTK_PIN_DRV_GRP(24, DRV_BASE1, 16, 1),
  86. MTK_PIN_DRV_GRP(33, DRV_BASE1, 24, 1),
  87. MTK_PIN_DRV_GRP(34, DRV_BASE2, 12, 2),
  88. MTK_PIN_DRV_GRP(37, DRV_BASE2, 20, 1),
  89. MTK_PIN_DRV_GRP(38, DRV_BASE2, 20, 1),
  90. MTK_PIN_DRV_GRP(39, DRV_BASE2, 20, 1),
  91. MTK_PIN_DRV_GRP(40, DRV_BASE2, 24, 1),
  92. MTK_PIN_DRV_GRP(41, DRV_BASE2, 24, 1),
  93. MTK_PIN_DRV_GRP(42, DRV_BASE2, 24, 1),
  94. MTK_PIN_DRV_GRP(43, DRV_BASE2, 28, 1),
  95. MTK_PIN_DRV_GRP(44, DRV_BASE2, 28, 1),
  96. MTK_PIN_DRV_GRP(45, DRV_BASE2, 28, 1),
  97. MTK_PIN_DRV_GRP(46, DRV_BASE2, 28, 1),
  98. MTK_PIN_DRV_GRP(47, DRV_BASE2, 28, 1),
  99. MTK_PIN_DRV_GRP(49, DRV_BASE2+0x10, 0, 1),
  100. MTK_PIN_DRV_GRP(50, DRV_BASE2+0x10, 4, 1),
  101. MTK_PIN_DRV_GRP(51, DRV_BASE2+0x10, 8, 1),
  102. MTK_PIN_DRV_GRP(52, DRV_BASE2+0x10, 12, 2),
  103. MTK_PIN_DRV_GRP(53, DRV_BASE2+0x10, 16, 1),
  104. MTK_PIN_DRV_GRP(54, DRV_BASE2+0x10, 20, 1),
  105. MTK_PIN_DRV_GRP(55, DRV_BASE2+0x10, 24, 1),
  106. MTK_PIN_DRV_GRP(56, DRV_BASE2+0x10, 28, 1),
  107. MTK_PIN_DRV_GRP(57, DRV_BASE2+0x20, 0, 1),
  108. MTK_PIN_DRV_GRP(58, DRV_BASE2+0x20, 0, 1),
  109. MTK_PIN_DRV_GRP(59, DRV_BASE2+0x20, 0, 1),
  110. MTK_PIN_DRV_GRP(60, DRV_BASE2+0x20, 0, 1),
  111. MTK_PIN_DRV_GRP(61, DRV_BASE2+0x20, 0, 1),
  112. MTK_PIN_DRV_GRP(62, DRV_BASE2+0x20, 0, 1),
  113. MTK_PIN_DRV_GRP(63, DRV_BASE2+0x20, 4, 1),
  114. MTK_PIN_DRV_GRP(64, DRV_BASE2+0x20, 8, 1),
  115. MTK_PIN_DRV_GRP(65, DRV_BASE2+0x20, 12, 1),
  116. MTK_PIN_DRV_GRP(66, DRV_BASE2+0x20, 16, 1),
  117. MTK_PIN_DRV_GRP(67, DRV_BASE2+0x20, 20, 1),
  118. MTK_PIN_DRV_GRP(68, DRV_BASE2+0x20, 24, 1),
  119. MTK_PIN_DRV_GRP(69, DRV_BASE2+0x20, 28, 1),
  120. MTK_PIN_DRV_GRP(70, DRV_BASE2+0x30, 0, 1),
  121. MTK_PIN_DRV_GRP(71, DRV_BASE2+0x30, 4, 1),
  122. MTK_PIN_DRV_GRP(72, DRV_BASE2+0x30, 8, 1),
  123. MTK_PIN_DRV_GRP(73, DRV_BASE2+0x30, 12, 1),
  124. MTK_PIN_DRV_GRP(74, DRV_BASE2+0x30, 16, 1),
  125. MTK_PIN_DRV_GRP(75, DRV_BASE2+0x30, 20, 1),
  126. MTK_PIN_DRV_GRP(76, DRV_BASE2+0x30, 24, 1),
  127. MTK_PIN_DRV_GRP(77, DRV_BASE2+0x30, 28, 3),
  128. MTK_PIN_DRV_GRP(78, DRV_BASE2+0x30, 28, 3),
  129. MTK_PIN_DRV_GRP(79, DRV_BASE2+0x40, 0, 3),
  130. MTK_PIN_DRV_GRP(80, DRV_BASE2+0x40, 4, 3),
  131. MTK_PIN_DRV_GRP(81, DRV_BASE2+0x30, 28, 3),
  132. MTK_PIN_DRV_GRP(82, DRV_BASE2+0x30, 28, 3),
  133. MTK_PIN_DRV_GRP(83, DRV_BASE2+0x40, 8, 3),
  134. MTK_PIN_DRV_GRP(84, DRV_BASE2+0x40, 8, 3),
  135. MTK_PIN_DRV_GRP(85, DRV_BASE2+0x40, 12, 3),
  136. MTK_PIN_DRV_GRP(86, DRV_BASE2+0x40, 16, 3),
  137. MTK_PIN_DRV_GRP(87, DRV_BASE2+0x40, 8, 3),
  138. MTK_PIN_DRV_GRP(88, DRV_BASE2+0x40, 8, 3),
  139. MTK_PIN_DRV_GRP(89, DRV_BASE2+0x50, 12, 0),
  140. MTK_PIN_DRV_GRP(90, DRV_BASE2+0x50, 12, 0),
  141. MTK_PIN_DRV_GRP(91, DRV_BASE2+0x50, 12, 0),
  142. MTK_PIN_DRV_GRP(92, DRV_BASE2+0x50, 12, 0),
  143. MTK_PIN_DRV_GRP(93, DRV_BASE2+0x50, 12, 0),
  144. MTK_PIN_DRV_GRP(94, DRV_BASE2+0x50, 12, 0),
  145. MTK_PIN_DRV_GRP(95, DRV_BASE2+0x50, 12, 0),
  146. MTK_PIN_DRV_GRP(96, DRV_BASE1+0xb0, 28, 0),
  147. MTK_PIN_DRV_GRP(97, DRV_BASE2+0x50, 12, 0),
  148. MTK_PIN_DRV_GRP(98, DRV_BASE2+0x50, 16, 0),
  149. MTK_PIN_DRV_GRP(99, DRV_BASE2+0x50, 20, 1),
  150. MTK_PIN_DRV_GRP(102, DRV_BASE2+0x50, 24, 1),
  151. MTK_PIN_DRV_GRP(103, DRV_BASE2+0x50, 28, 1),
  152. MTK_PIN_DRV_GRP(104, DRV_BASE2+0x60, 0, 1),
  153. MTK_PIN_DRV_GRP(105, DRV_BASE2+0x60, 4, 1),
  154. MTK_PIN_DRV_GRP(106, DRV_BASE2+0x60, 4, 1),
  155. MTK_PIN_DRV_GRP(107, DRV_BASE2+0x60, 4, 1),
  156. MTK_PIN_DRV_GRP(108, DRV_BASE2+0x60, 4, 1),
  157. MTK_PIN_DRV_GRP(109, DRV_BASE2+0x60, 8, 2),
  158. MTK_PIN_DRV_GRP(110, DRV_BASE2+0x60, 12, 2),
  159. MTK_PIN_DRV_GRP(111, DRV_BASE2+0x60, 16, 2),
  160. MTK_PIN_DRV_GRP(112, DRV_BASE2+0x60, 20, 2),
  161. MTK_PIN_DRV_GRP(113, DRV_BASE2+0x60, 24, 2),
  162. MTK_PIN_DRV_GRP(114, DRV_BASE2+0x60, 28, 2),
  163. MTK_PIN_DRV_GRP(115, DRV_BASE2+0x70, 0, 2),
  164. MTK_PIN_DRV_GRP(116, DRV_BASE2+0x70, 4, 2),
  165. MTK_PIN_DRV_GRP(117, DRV_BASE2+0x70, 8, 2),
  166. MTK_PIN_DRV_GRP(118, DRV_BASE2+0x70, 12, 2),
  167. MTK_PIN_DRV_GRP(119, DRV_BASE2+0x70, 16, 2),
  168. MTK_PIN_DRV_GRP(120, DRV_BASE2+0x70, 20, 2),
  169. MTK_PIN_DRV_GRP(181, DRV_BASE1+0xa0, 12, 1),
  170. MTK_PIN_DRV_GRP(182, DRV_BASE1+0xa0, 16, 1),
  171. MTK_PIN_DRV_GRP(183, DRV_BASE1+0xa0, 20, 1),
  172. MTK_PIN_DRV_GRP(184, DRV_BASE1+0xa0, 24, 1),
  173. MTK_PIN_DRV_GRP(185, DRV_BASE1+0xa0, 28, 1),
  174. MTK_PIN_DRV_GRP(186, DRV_BASE1+0xb0, 0, 2),
  175. MTK_PIN_DRV_GRP(187, DRV_BASE1+0xb0, 0, 2),
  176. MTK_PIN_DRV_GRP(188, DRV_BASE1+0xb0, 0, 2),
  177. MTK_PIN_DRV_GRP(189, DRV_BASE1+0xb0, 0, 2),
  178. MTK_PIN_DRV_GRP(190, DRV_BASE1+0xb0, 4, 1),
  179. MTK_PIN_DRV_GRP(191, DRV_BASE1+0xb0, 8, 1),
  180. MTK_PIN_DRV_GRP(192, DRV_BASE1+0xb0, 12, 1),
  181. MTK_PIN_DRV_GRP(197, DRV_BASE1+0xb0, 16, 0),
  182. MTK_PIN_DRV_GRP(198, DRV_BASE1+0xb0, 16, 0),
  183. MTK_PIN_DRV_GRP(199, DRV_BASE1+0xb0, 20, 0),
  184. MTK_PIN_DRV_GRP(200, DRV_BASE1+0xb0, 24, 0),
  185. MTK_PIN_DRV_GRP(201, DRV_BASE1+0xb0, 16, 0),
  186. MTK_PIN_DRV_GRP(202, DRV_BASE1+0xb0, 16, 0)
  187. };
  188. static const struct mtk_spec_pull_set spec_pupd[] = {
  189. SPEC_PULL(0, PUPD_BASE1, 0, R0_BASE1, 9, R1_BASE1, 0),
  190. SPEC_PULL(1, PUPD_BASE1, 1, R0_BASE1, 8, R1_BASE1, 1),
  191. SPEC_PULL(2, PUPD_BASE1, 2, R0_BASE1, 7, R1_BASE1, 2),
  192. SPEC_PULL(3, PUPD_BASE1, 3, R0_BASE1, 6, R1_BASE1, 3),
  193. SPEC_PULL(4, PUPD_BASE1, 4, R0_BASE1, 1, R1_BASE1, 4),
  194. SPEC_PULL(5, PUPD_BASE1, 5, R0_BASE1, 0, R1_BASE1, 5),
  195. SPEC_PULL(6, PUPD_BASE1, 6, R0_BASE1, 5, R1_BASE1, 6),
  196. SPEC_PULL(7, PUPD_BASE1, 7, R0_BASE1, 4, R1_BASE1, 7),
  197. SPEC_PULL(8, PUPD_BASE1, 8, R0_BASE1, 3, R1_BASE1, 8),
  198. SPEC_PULL(9, PUPD_BASE1, 9, R0_BASE1, 2, R1_BASE1, 9),
  199. SPEC_PULL(89, PUPD_BASE2, 9, R0_BASE1, 18, R1_BASE2, 9),
  200. SPEC_PULL(90, PUPD_BASE2, 10, R0_BASE1, 19, R1_BASE2, 10),
  201. SPEC_PULL(91, PUPD_BASE2, 11, R0_BASE1, 23, R1_BASE2, 11),
  202. SPEC_PULL(92, PUPD_BASE2, 12, R0_BASE1, 24, R1_BASE2, 12),
  203. SPEC_PULL(93, PUPD_BASE2, 13, R0_BASE1, 25, R1_BASE2, 13),
  204. SPEC_PULL(94, PUPD_BASE2, 14, R0_BASE1, 22, R1_BASE2, 14),
  205. SPEC_PULL(95, PUPD_BASE2, 15, R0_BASE1, 20, R1_BASE2, 15),
  206. SPEC_PULL(96, PUPD_BASE2+0x10, 0, R0_BASE1, 16, R1_BASE2+0x10, 0),
  207. SPEC_PULL(97, PUPD_BASE2+0x10, 1, R0_BASE1, 21, R1_BASE2+0x10, 1),
  208. SPEC_PULL(98, PUPD_BASE2+0x10, 2, R0_BASE1, 17, R1_BASE2+0x10, 2),
  209. SPEC_PULL(197, PUPD_BASE1+0xc0, 5, R0_BASE1, 13, R1_BASE2+0xc0, 5),
  210. SPEC_PULL(198, PUPD_BASE2+0xc0, 6, R0_BASE1, 14, R1_BASE2+0xc0, 6),
  211. SPEC_PULL(199, PUPD_BASE2+0xc0, 7, R0_BASE1, 11, R1_BASE2+0xc0, 7),
  212. SPEC_PULL(200, PUPD_BASE2+0xc0, 8, R0_BASE1, 10, R1_BASE2+0xc0, 8),
  213. SPEC_PULL(201, PUPD_BASE2+0xc0, 9, R0_BASE1, 13, R1_BASE2+0xc0, 9),
  214. SPEC_PULL(202, PUPD_BASE2+0xc0, 10, R0_BASE1, 12, R1_BASE2+0xc0, 10)
  215. };
  216. static int spec_pull_set(struct regmap *regmap, unsigned int pin,
  217. unsigned char align, bool isup, unsigned int r1r0)
  218. {
  219. unsigned int i;
  220. unsigned int reg_pupd, reg_set_r0, reg_set_r1;
  221. unsigned int reg_rst_r0, reg_rst_r1;
  222. bool find = false;
  223. for (i = 0; i < ARRAY_SIZE(spec_pupd); i++) {
  224. if (pin == spec_pupd[i].pin) {
  225. find = true;
  226. break;
  227. }
  228. }
  229. if (!find)
  230. return -EINVAL;
  231. if (isup)
  232. reg_pupd = spec_pupd[i].pupd_offset + align;
  233. else
  234. reg_pupd = spec_pupd[i].pupd_offset + (align << 1);
  235. regmap_write(regmap, reg_pupd, spec_pupd[i].pupd_bit);
  236. reg_set_r0 = spec_pupd[i].r0_offset + align;
  237. reg_rst_r0 = spec_pupd[i].r0_offset + (align << 1);
  238. reg_set_r1 = spec_pupd[i].r1_offset + align;
  239. reg_rst_r1 = spec_pupd[i].r1_offset + (align << 1);
  240. switch (r1r0) {
  241. case MTK_PUPD_SET_R1R0_00:
  242. regmap_write(regmap, reg_rst_r0, spec_pupd[i].r0_bit);
  243. regmap_write(regmap, reg_rst_r1, spec_pupd[i].r1_bit);
  244. break;
  245. case MTK_PUPD_SET_R1R0_01:
  246. regmap_write(regmap, reg_set_r0, spec_pupd[i].r0_bit);
  247. regmap_write(regmap, reg_rst_r1, spec_pupd[i].r1_bit);
  248. break;
  249. case MTK_PUPD_SET_R1R0_10:
  250. regmap_write(regmap, reg_rst_r0, spec_pupd[i].r0_bit);
  251. regmap_write(regmap, reg_set_r1, spec_pupd[i].r1_bit);
  252. break;
  253. case MTK_PUPD_SET_R1R0_11:
  254. regmap_write(regmap, reg_set_r0, spec_pupd[i].r0_bit);
  255. regmap_write(regmap, reg_set_r1, spec_pupd[i].r1_bit);
  256. break;
  257. default:
  258. return -EINVAL;
  259. }
  260. return 0;
  261. }
  262. static const struct mtk_pinctrl_devdata mt8135_pinctrl_data = {
  263. .pins = mtk_pins_mt8135,
  264. .npins = ARRAY_SIZE(mtk_pins_mt8135),
  265. .grp_desc = mt8135_drv_grp,
  266. .n_grp_cls = ARRAY_SIZE(mt8135_drv_grp),
  267. .pin_drv_grp = mt8135_pin_drv,
  268. .n_pin_drv_grps = ARRAY_SIZE(mt8135_pin_drv),
  269. .spec_pull_set = spec_pull_set,
  270. .dir_offset = 0x0000,
  271. .ies_offset = 0x0100,
  272. .pullen_offset = 0x0200,
  273. .smt_offset = 0x0300,
  274. .pullsel_offset = 0x0400,
  275. .dout_offset = 0x0800,
  276. .din_offset = 0x0A00,
  277. .pinmux_offset = 0x0C00,
  278. .type1_start = 34,
  279. .type1_end = 149,
  280. .port_shf = 4,
  281. .port_mask = 0xf,
  282. .port_align = 4,
  283. .eint_offsets = {
  284. .name = "mt8135_eint",
  285. .stat = 0x000,
  286. .ack = 0x040,
  287. .mask = 0x080,
  288. .mask_set = 0x0c0,
  289. .mask_clr = 0x100,
  290. .sens = 0x140,
  291. .sens_set = 0x180,
  292. .sens_clr = 0x1c0,
  293. .soft = 0x200,
  294. .soft_set = 0x240,
  295. .soft_clr = 0x280,
  296. .pol = 0x300,
  297. .pol_set = 0x340,
  298. .pol_clr = 0x380,
  299. .dom_en = 0x400,
  300. .dbnc_ctrl = 0x500,
  301. .dbnc_set = 0x600,
  302. .dbnc_clr = 0x700,
  303. .port_mask = 7,
  304. .ports = 6,
  305. },
  306. .ap_num = 192,
  307. .db_cnt = 16,
  308. };
  309. static int mt8135_pinctrl_probe(struct platform_device *pdev)
  310. {
  311. return mtk_pctrl_init(pdev, &mt8135_pinctrl_data, NULL);
  312. }
  313. static const struct of_device_id mt8135_pctrl_match[] = {
  314. {
  315. .compatible = "mediatek,mt8135-pinctrl",
  316. },
  317. { }
  318. };
  319. MODULE_DEVICE_TABLE(of, mt8135_pctrl_match);
  320. static struct platform_driver mtk_pinctrl_driver = {
  321. .probe = mt8135_pinctrl_probe,
  322. .driver = {
  323. .name = "mediatek-mt8135-pinctrl",
  324. .of_match_table = mt8135_pctrl_match,
  325. },
  326. };
  327. static int __init mtk_pinctrl_init(void)
  328. {
  329. return platform_driver_register(&mtk_pinctrl_driver);
  330. }
  331. module_init(mtk_pinctrl_init);
  332. MODULE_LICENSE("GPL");
  333. MODULE_DESCRIPTION("MediaTek Pinctrl Driver");
  334. MODULE_AUTHOR("Hongzhou Yang <hongzhou.yang@mediatek.com>");