pinctrl-mt6735.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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-mt6735.h"
  23. /**
  24. * struct mtk_pin_spec_pupd_set - For special pins' pull up/down setting.
  25. * @pin: The pin number.
  26. * @offset: The offset of special pull up/down setting register.
  27. * @pupd_bit: The pull up/down bit in this register.
  28. * @r0_bit: The r0 bit of pull resistor.
  29. * @r1_bit: The r1 bit of pull resistor.
  30. */
  31. struct mtk_pin_spec_pupd_set {
  32. unsigned int pin;
  33. unsigned int offset;
  34. unsigned char pupd_bit;
  35. unsigned char r1_bit;
  36. unsigned char r0_bit;
  37. };
  38. #define MTK_PIN_PUPD_SPEC(_pin, _offset, _pupd, _r1, _r0) \
  39. { \
  40. .pin = _pin, \
  41. .offset = _offset, \
  42. .pupd_bit = _pupd, \
  43. .r1_bit = _r1, \
  44. .r0_bit = _r0, \
  45. }
  46. static const struct mtk_pin_spec_pupd_set mt6735_spec_pupd[] = {
  47. MTK_PIN_PUPD_SPEC(45, 0x980, 2, 1, 0),
  48. MTK_PIN_PUPD_SPEC(46, 0x980, 6, 5, 4),
  49. MTK_PIN_PUPD_SPEC(81, 0xA80, 2, 1, 0),
  50. MTK_PIN_PUPD_SPEC(82, 0xA80, 6, 5, 4),
  51. MTK_PIN_PUPD_SPEC(83, 0xA80, 10, 9, 8),
  52. MTK_PIN_PUPD_SPEC(84, 0xA80, 18, 17, 16),
  53. MTK_PIN_PUPD_SPEC(85, 0xA80, 22, 21, 20),
  54. MTK_PIN_PUPD_SPEC(86, 0xA80, 26, 25, 24),
  55. MTK_PIN_PUPD_SPEC(160, 0xC90, 3, 2, 1),
  56. MTK_PIN_PUPD_SPEC(161, 0xC90, 7, 6, 5),
  57. MTK_PIN_PUPD_SPEC(162, 0xC90, 11, 10, 9),
  58. MTK_PIN_PUPD_SPEC(163, 0xC90, 19, 18, 17),
  59. MTK_PIN_PUPD_SPEC(164, 0xC90, 23, 22, 21),
  60. MTK_PIN_PUPD_SPEC(165, 0xC90, 27, 26, 25),
  61. MTK_PIN_PUPD_SPEC(166, 0xC80, 2, 1, 0),
  62. MTK_PIN_PUPD_SPEC(167, 0xC80, 6, 5, 4),
  63. MTK_PIN_PUPD_SPEC(168, 0xC80, 10, 9, 8),
  64. MTK_PIN_PUPD_SPEC(169, 0xC80, 14, 13, 12),
  65. MTK_PIN_PUPD_SPEC(170, 0xC80, 18, 17, 16),
  66. MTK_PIN_PUPD_SPEC(171, 0xC80, 22, 21, 20),
  67. MTK_PIN_PUPD_SPEC(172, 0xD80, 2, 1, 0),
  68. MTK_PIN_PUPD_SPEC(173, 0xD80, 10, 9, 8),
  69. MTK_PIN_PUPD_SPEC(174, 0xD80, 6, 5, 4),
  70. MTK_PIN_PUPD_SPEC(175, 0xD80, 14, 13, 12),
  71. MTK_PIN_PUPD_SPEC(176, 0xD80, 18, 17, 16),
  72. MTK_PIN_PUPD_SPEC(177, 0xD80, 22, 21, 20),
  73. MTK_PIN_PUPD_SPEC(178, 0xD80, 26, 25, 24),
  74. MTK_PIN_PUPD_SPEC(179, 0xD80, 30, 29, 28),
  75. MTK_PIN_PUPD_SPEC(180, 0xD90, 2, 1, 0),
  76. MTK_PIN_PUPD_SPEC(181, 0xD90, 6, 5, 4),
  77. MTK_PIN_PUPD_SPEC(182, 0xD90, 10, 9, 8),
  78. MTK_PIN_PUPD_SPEC(183, 0xD90, 14, 13, 12),
  79. MTK_PIN_PUPD_SPEC(198, 0x880, 2, 1, 0),
  80. MTK_PIN_PUPD_SPEC(199, 0x880, 6, 5, 4),
  81. MTK_PIN_PUPD_SPEC(200, 0x880, 10, 9, 8),
  82. MTK_PIN_PUPD_SPEC(201, 0x880, 14, 13, 12),
  83. MTK_PIN_PUPD_SPEC(202, 0x880, 18, 17, 16),
  84. MTK_PIN_PUPD_SPEC(203, 0x880, 22, 21, 20),
  85. MTK_PIN_PUPD_SPEC(45, 0x980, 2, 1, 0),
  86. MTK_PIN_PUPD_SPEC(46, 0x980, 6, 5, 4),
  87. MTK_PIN_PUPD_SPEC(81, 0xA80, 2, 1, 0),
  88. MTK_PIN_PUPD_SPEC(82, 0xA80, 6, 5, 4),
  89. MTK_PIN_PUPD_SPEC(83, 0xA80, 10, 9, 8),
  90. MTK_PIN_PUPD_SPEC(84, 0xA80, 18, 17, 16),
  91. MTK_PIN_PUPD_SPEC(85, 0xA80, 22, 21, 20),
  92. MTK_PIN_PUPD_SPEC(86, 0xA80, 26, 25, 24),
  93. /* MTK_PIN_PUPD_SPEC(160,0xC90,3,2,1), */
  94. /* MTK_PIN_PUPD_SPEC(161,0xC90,7,6,5), */
  95. /* MTK_PIN_PUPD_SPEC(162,0xC90,11,10,9), */
  96. /* MTK_PIN_PUPD_SPEC(163,0xC90,19,18,17), */
  97. /* MTK_PIN_PUPD_SPEC(164,0xC90,23,22,21), */
  98. /* MTK_PIN_PUPD_SPEC(165,0xC90,27,26,25), */
  99. MTK_PIN_PUPD_SPEC(166, 0xC80, 2, 1, 0),
  100. MTK_PIN_PUPD_SPEC(167, 0xC80, 6, 5, 4),
  101. MTK_PIN_PUPD_SPEC(168, 0xC80, 10, 9, 8),
  102. MTK_PIN_PUPD_SPEC(169, 0xC80, 14, 13, 12),
  103. MTK_PIN_PUPD_SPEC(170, 0xC80, 18, 17, 16),
  104. MTK_PIN_PUPD_SPEC(171, 0xC80, 22, 21, 20),
  105. MTK_PIN_PUPD_SPEC(172, 0xD80, 2, 1, 0),
  106. MTK_PIN_PUPD_SPEC(173, 0xD80, 10, 9, 8),
  107. MTK_PIN_PUPD_SPEC(174, 0xD80, 6, 5, 4),
  108. MTK_PIN_PUPD_SPEC(175, 0xD80, 14, 13, 12),
  109. MTK_PIN_PUPD_SPEC(176, 0xD80, 18, 17, 16),
  110. MTK_PIN_PUPD_SPEC(177, 0xD80, 22, 21, 20),
  111. MTK_PIN_PUPD_SPEC(178, 0xD80, 26, 25, 24),
  112. MTK_PIN_PUPD_SPEC(179, 0xD80, 30, 29, 28),
  113. MTK_PIN_PUPD_SPEC(180, 0xD90, 2, 1, 0),
  114. MTK_PIN_PUPD_SPEC(181, 0xD90, 6, 5, 4),
  115. MTK_PIN_PUPD_SPEC(182, 0xD90, 10, 9, 8),
  116. MTK_PIN_PUPD_SPEC(183, 0xD90, 14, 13, 12),
  117. MTK_PIN_PUPD_SPEC(198, 0x880, 2, 1, 0),
  118. MTK_PIN_PUPD_SPEC(199, 0x880, 6, 5, 4),
  119. MTK_PIN_PUPD_SPEC(200, 0x880, 10, 9, 8),
  120. MTK_PIN_PUPD_SPEC(201, 0x880, 14, 13, 12),
  121. MTK_PIN_PUPD_SPEC(202, 0x880, 18, 17, 16),
  122. MTK_PIN_PUPD_SPEC(203, 0x880, 22, 21, 20),
  123. };
  124. static int spec_pull_set(struct regmap *regmap, unsigned int pin,
  125. unsigned char align, bool isup, unsigned int r1r0)
  126. {
  127. unsigned int i;
  128. unsigned int reg_pupd, reg_set, reg_rst;
  129. unsigned int bit_pupd, bit_r0, bit_r1;
  130. const struct mtk_pin_spec_pupd_set *spec_pupd_pin;
  131. bool find = false;
  132. for (i = 0; i < ARRAY_SIZE(mt6735_spec_pupd); i++) {
  133. if (pin == mt6735_spec_pupd[i].pin) {
  134. find = true;
  135. break;
  136. }
  137. }
  138. if (!find)
  139. return -EINVAL;
  140. spec_pupd_pin = mt6735_spec_pupd + i;
  141. reg_set = spec_pupd_pin->offset + align;
  142. reg_rst = spec_pupd_pin->offset + (align << 1);
  143. if (isup)
  144. reg_pupd = reg_rst;
  145. else
  146. reg_pupd = reg_set;
  147. bit_pupd = BIT(spec_pupd_pin->pupd_bit);
  148. regmap_write(regmap, reg_pupd, bit_pupd);
  149. bit_r0 = BIT(spec_pupd_pin->r0_bit);
  150. bit_r1 = BIT(spec_pupd_pin->r1_bit);
  151. switch (r1r0) {
  152. case MTK_PUPD_SET_R1R0_00:
  153. regmap_write(regmap, reg_rst, bit_r0);
  154. regmap_write(regmap, reg_rst, bit_r1);
  155. break;
  156. case MTK_PUPD_SET_R1R0_01:
  157. regmap_write(regmap, reg_set, bit_r0);
  158. regmap_write(regmap, reg_rst, bit_r1);
  159. break;
  160. case MTK_PUPD_SET_R1R0_10:
  161. regmap_write(regmap, reg_rst, bit_r0);
  162. regmap_write(regmap, reg_set, bit_r1);
  163. break;
  164. case MTK_PUPD_SET_R1R0_11:
  165. regmap_write(regmap, reg_set, bit_r0);
  166. regmap_write(regmap, reg_set, bit_r1);
  167. break;
  168. default:
  169. return -EINVAL;
  170. }
  171. return 0;
  172. }
  173. /*
  174. static const struct mtk_pin_ies_smt_set mt6735_ies_smt_set[] = {
  175. MTK_PIN_IES_SMT_SET(0, 4, 0x930, 1),
  176. MTK_PIN_IES_SMT_SET(5, 9, 0x930, 2),
  177. MTK_PIN_IES_SMT_SET(10, 13, 0x930, 10),
  178. MTK_PIN_IES_SMT_SET(14, 15, 0x940, 10),
  179. MTK_PIN_IES_SMT_SET(16, 16, 0x930, 0),
  180. MTK_PIN_IES_SMT_SET(17, 17, 0x950, 2),
  181. MTK_PIN_IES_SMT_SET(18, 21, 0x940, 3),
  182. MTK_PIN_IES_SMT_SET(29, 32, 0x930, 3),
  183. MTK_PIN_IES_SMT_SET(33, 33, 0x930, 4),
  184. MTK_PIN_IES_SMT_SET(34, 36, 0x930, 5),
  185. MTK_PIN_IES_SMT_SET(37, 38, 0x930, 6),
  186. MTK_PIN_IES_SMT_SET(39, 39, 0x930, 7),
  187. MTK_PIN_IES_SMT_SET(40, 41, 0x930, 9),
  188. MTK_PIN_IES_SMT_SET(42, 42, 0x940, 0),
  189. MTK_PIN_IES_SMT_SET(43, 44, 0x930, 11),
  190. MTK_PIN_IES_SMT_SET(45, 46, 0x930, 12),
  191. MTK_PIN_IES_SMT_SET(57, 64, 0xc20, 13),
  192. MTK_PIN_IES_SMT_SET(65, 65, 0xc10, 13),
  193. MTK_PIN_IES_SMT_SET(66, 66, 0xc00, 13),
  194. MTK_PIN_IES_SMT_SET(67, 67, 0xd10, 13),
  195. MTK_PIN_IES_SMT_SET(68, 68, 0xd00, 13),
  196. MTK_PIN_IES_SMT_SET(69, 72, 0x940, 14),
  197. MTK_PIN_IES_SMT_SET(73, 76, 0xc60, 13),
  198. MTK_PIN_IES_SMT_SET(77, 77, 0xc40, 13),
  199. MTK_PIN_IES_SMT_SET(78, 78, 0xc50, 13),
  200. MTK_PIN_IES_SMT_SET(79, 82, 0x940, 15),
  201. MTK_PIN_IES_SMT_SET(83, 83, 0x950, 0),
  202. MTK_PIN_IES_SMT_SET(84, 85, 0x950, 1),
  203. MTK_PIN_IES_SMT_SET(86, 91, 0x950, 2),
  204. MTK_PIN_IES_SMT_SET(92, 92, 0x930, 13),
  205. MTK_PIN_IES_SMT_SET(93, 95, 0x930, 14),
  206. MTK_PIN_IES_SMT_SET(96, 99, 0x930, 15),
  207. MTK_PIN_IES_SMT_SET(100, 103, 0xca0, 13),
  208. MTK_PIN_IES_SMT_SET(104, 104, 0xc80, 13),
  209. MTK_PIN_IES_SMT_SET(105, 105, 0xc90, 13),
  210. MTK_PIN_IES_SMT_SET(106, 107, 0x940, 4),
  211. MTK_PIN_IES_SMT_SET(108, 112, 0x940, 1),
  212. MTK_PIN_IES_SMT_SET(113, 116, 0x940, 2),
  213. MTK_PIN_IES_SMT_SET(117, 118, 0x940, 5),
  214. MTK_PIN_IES_SMT_SET(119, 124, 0x940, 6),
  215. MTK_PIN_IES_SMT_SET(125, 126, 0x940, 7),
  216. MTK_PIN_IES_SMT_SET(127, 127, 0x940, 0),
  217. MTK_PIN_IES_SMT_SET(128, 128, 0x950, 8),
  218. MTK_PIN_IES_SMT_SET(129, 130, 0x950, 9),
  219. MTK_PIN_IES_SMT_SET(131, 132, 0x950, 8),
  220. MTK_PIN_IES_SMT_SET(133, 134, 0x910, 8)
  221. };
  222. int spec_ies_smt_set(struct regmap *regmap, unsigned int pin,
  223. unsigned char align, int value)
  224. {
  225. unsigned int i, reg_addr, bit;
  226. bool find = false;
  227. for (i = 0; i < ARRAY_SIZE(mt6735_ies_smt_set); i++) {
  228. if (pin >= mt6735_ies_smt_set[i].start &&
  229. pin <= mt6735_ies_smt_set[i].end) {
  230. find = true;
  231. break;
  232. }
  233. }
  234. if (!find)
  235. return -EINVAL;
  236. if (value)
  237. reg_addr = mt6735_ies_smt_set[i].offset + align;
  238. else
  239. reg_addr = mt6735_ies_smt_set[i].offset + (align << 1);
  240. bit = BIT(mt6735_ies_smt_set[i].bit);
  241. regmap_write(regmap, reg_addr, bit);
  242. return 0;
  243. }
  244. */
  245. static const struct mtk_pinctrl_devdata mt6735_pinctrl_data = {
  246. .pins = mtk_pins_mt6735,
  247. .npins = ARRAY_SIZE(mtk_pins_mt6735),
  248. .grp_desc = NULL,
  249. .n_grp_cls = 0,
  250. .pin_drv_grp = NULL,
  251. .n_pin_drv_grps = 0,
  252. .spec_pull_set = spec_pull_set,
  253. /*.spec_ies_smt_set = spec_ies_smt_set,*/
  254. .spec_set_gpio_mode = mt_set_gpio_mode,
  255. .mt_set_gpio_dir = mt_set_gpio_dir,
  256. .mt_get_gpio_dir = mt_get_gpio_dir,
  257. .mt_get_gpio_out = mt_get_gpio_out,
  258. .mt_set_gpio_out = mt_set_gpio_out,
  259. .mt_set_gpio_ies = mt_set_gpio_ies,
  260. .mt_set_gpio_smt = mt_set_gpio_smt,
  261. .mt_set_gpio_pull_enable = mt_set_gpio_pull_enable,
  262. .mt_set_gpio_pull_select = mt_set_gpio_pull_select,
  263. .mt_get_gpio_in = mt_get_gpio_in,
  264. /* .dir_offset = 0x0000, */
  265. /* .pullen_offset = 0x0100, */
  266. /* .pullsel_offset = 0x0200, */
  267. /* .dout_offset = 0x0100, */
  268. /* .din_offset = 0x0200, */
  269. /* .pinmux_offset = 0x300, */
  270. .type1_start = 204,
  271. .type1_end = 204,
  272. .port_shf = 4,
  273. .port_mask = 0xf,
  274. .port_align = 4,
  275. .chip_type = MTK_CHIP_TYPE_BASE,
  276. /*
  277. .eint_offsets = {
  278. .name = "mt6735_eint",
  279. .stat = 0x000,
  280. .ack = 0x040,
  281. .mask = 0x080,
  282. .mask_set = 0x0c0,
  283. .mask_clr = 0x100,
  284. .sens = 0x140,
  285. .sens_set = 0x180,
  286. .sens_clr = 0x1c0,
  287. .soft = 0x200,
  288. .soft_set = 0x240,
  289. .soft_clr = 0x280,
  290. .pol = 0x300,
  291. .pol_set = 0x340,
  292. .pol_clr = 0x380,
  293. .dom_en = 0x400,
  294. .dbnc_ctrl = 0x500,
  295. .dbnc_set = 0x600,
  296. .dbnc_clr = 0x700,
  297. .port_mask = 7,
  298. .ports = 6,
  299. },
  300. .ap_num = 224,
  301. .db_cnt = 16,
  302. */
  303. };
  304. static int mt6735_pinctrl_probe(struct platform_device *pdev)
  305. {
  306. pr_warn("mt6735 pinctrl probe\n");
  307. return mtk_pctrl_init(pdev, &mt6735_pinctrl_data, NULL);
  308. }
  309. static struct of_device_id mt6735_pctrl_match[] = {
  310. {
  311. .compatible = "mediatek,mt6735-pinctrl",
  312. }, {
  313. }
  314. };
  315. MODULE_DEVICE_TABLE(of, mt6735_pctrl_match);
  316. static struct platform_driver mtk_pinctrl_driver = {
  317. .probe = mt6735_pinctrl_probe,
  318. .driver = {
  319. .name = "mediatek-mt6735-pinctrl",
  320. .owner = THIS_MODULE,
  321. .of_match_table = mt6735_pctrl_match,
  322. },
  323. };
  324. static int __init mtk_pinctrl_init(void)
  325. {
  326. return platform_driver_register(&mtk_pinctrl_driver);
  327. }
  328. /* module_init(mtk_pinctrl_init); */
  329. postcore_initcall(mtk_pinctrl_init);
  330. MODULE_LICENSE("GPL");
  331. MODULE_DESCRIPTION("MediaTek Pinctrl Driver");
  332. MODULE_AUTHOR("Hongzhou Yang <hongzhou.yang@mediatek.com>");