pinctrl-rockchip.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2024 Rockchip Electronics Co., Ltd.
  4. *
  5. * Copyright (c) 2013 MundoReader S.L.
  6. * Author: Heiko Stuebner <heiko@sntech.de>
  7. *
  8. * With some ideas taken from pinctrl-samsung:
  9. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  10. * http://www.samsung.com
  11. * Copyright (c) 2012 Linaro Ltd
  12. * https://www.linaro.org
  13. *
  14. * and pinctrl-at91:
  15. * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  16. */
  17. #ifndef _PINCTRL_ROCKCHIP_H
  18. #define _PINCTRL_ROCKCHIP_H
  19. #define RK_GPIO0_A0 0
  20. #define RK_GPIO0_A1 1
  21. #define RK_GPIO0_A2 2
  22. #define RK_GPIO0_A3 3
  23. #define RK_GPIO0_A4 4
  24. #define RK_GPIO0_A5 5
  25. #define RK_GPIO0_A6 6
  26. #define RK_GPIO0_A7 7
  27. #define RK_GPIO0_B0 8
  28. #define RK_GPIO0_B1 9
  29. #define RK_GPIO0_B2 10
  30. #define RK_GPIO0_B3 11
  31. #define RK_GPIO0_B4 12
  32. #define RK_GPIO0_B5 13
  33. #define RK_GPIO0_B6 14
  34. #define RK_GPIO0_B7 15
  35. #define RK_GPIO0_C0 16
  36. #define RK_GPIO0_C1 17
  37. #define RK_GPIO0_C2 18
  38. #define RK_GPIO0_C3 19
  39. #define RK_GPIO0_C4 20
  40. #define RK_GPIO0_C5 21
  41. #define RK_GPIO0_C6 22
  42. #define RK_GPIO0_C7 23
  43. #define RK_GPIO0_D0 24
  44. #define RK_GPIO0_D1 25
  45. #define RK_GPIO0_D2 26
  46. #define RK_GPIO0_D3 27
  47. #define RK_GPIO0_D4 28
  48. #define RK_GPIO0_D5 29
  49. #define RK_GPIO0_D6 30
  50. #define RK_GPIO0_D7 31
  51. #define RK_GPIO1_A0 32
  52. #define RK_GPIO1_A1 33
  53. #define RK_GPIO1_A2 34
  54. #define RK_GPIO1_A3 35
  55. #define RK_GPIO1_A4 36
  56. #define RK_GPIO1_A5 37
  57. #define RK_GPIO1_A6 38
  58. #define RK_GPIO1_A7 39
  59. #define RK_GPIO1_B0 40
  60. #define RK_GPIO1_B1 41
  61. #define RK_GPIO1_B2 42
  62. #define RK_GPIO1_B3 43
  63. #define RK_GPIO1_B4 44
  64. #define RK_GPIO1_B5 45
  65. #define RK_GPIO1_B6 46
  66. #define RK_GPIO1_B7 47
  67. #define RK_GPIO1_C0 48
  68. #define RK_GPIO1_C1 49
  69. #define RK_GPIO1_C2 50
  70. #define RK_GPIO1_C3 51
  71. #define RK_GPIO1_C4 52
  72. #define RK_GPIO1_C5 53
  73. #define RK_GPIO1_C6 54
  74. #define RK_GPIO1_C7 55
  75. #define RK_GPIO1_D0 56
  76. #define RK_GPIO1_D1 57
  77. #define RK_GPIO1_D2 58
  78. #define RK_GPIO1_D3 59
  79. #define RK_GPIO1_D4 60
  80. #define RK_GPIO1_D5 61
  81. #define RK_GPIO1_D6 62
  82. #define RK_GPIO1_D7 63
  83. #define RK_GPIO2_A0 64
  84. #define RK_GPIO2_A1 65
  85. #define RK_GPIO2_A2 66
  86. #define RK_GPIO2_A3 67
  87. #define RK_GPIO2_A4 68
  88. #define RK_GPIO2_A5 69
  89. #define RK_GPIO2_A6 70
  90. #define RK_GPIO2_A7 71
  91. #define RK_GPIO2_B0 72
  92. #define RK_GPIO2_B1 73
  93. #define RK_GPIO2_B2 74
  94. #define RK_GPIO2_B3 75
  95. #define RK_GPIO2_B4 76
  96. #define RK_GPIO2_B5 77
  97. #define RK_GPIO2_B6 78
  98. #define RK_GPIO2_B7 79
  99. #define RK_GPIO2_C0 80
  100. #define RK_GPIO2_C1 81
  101. #define RK_GPIO2_C2 82
  102. #define RK_GPIO2_C3 83
  103. #define RK_GPIO2_C4 84
  104. #define RK_GPIO2_C5 85
  105. #define RK_GPIO2_C6 86
  106. #define RK_GPIO2_C7 87
  107. #define RK_GPIO2_D0 88
  108. #define RK_GPIO2_D1 89
  109. #define RK_GPIO2_D2 90
  110. #define RK_GPIO2_D3 91
  111. #define RK_GPIO2_D4 92
  112. #define RK_GPIO2_D5 93
  113. #define RK_GPIO2_D6 94
  114. #define RK_GPIO2_D7 95
  115. #define RK_GPIO3_A0 96
  116. #define RK_GPIO3_A1 97
  117. #define RK_GPIO3_A2 98
  118. #define RK_GPIO3_A3 99
  119. #define RK_GPIO3_A4 100
  120. #define RK_GPIO3_A5 101
  121. #define RK_GPIO3_A6 102
  122. #define RK_GPIO3_A7 103
  123. #define RK_GPIO3_B0 104
  124. #define RK_GPIO3_B1 105
  125. #define RK_GPIO3_B2 106
  126. #define RK_GPIO3_B3 107
  127. #define RK_GPIO3_B4 108
  128. #define RK_GPIO3_B5 109
  129. #define RK_GPIO3_B6 110
  130. #define RK_GPIO3_B7 111
  131. #define RK_GPIO3_C0 112
  132. #define RK_GPIO3_C1 113
  133. #define RK_GPIO3_C2 114
  134. #define RK_GPIO3_C3 115
  135. #define RK_GPIO3_C4 116
  136. #define RK_GPIO3_C5 117
  137. #define RK_GPIO3_C6 118
  138. #define RK_GPIO3_C7 119
  139. #define RK_GPIO3_D0 120
  140. #define RK_GPIO3_D1 121
  141. #define RK_GPIO3_D2 122
  142. #define RK_GPIO3_D3 123
  143. #define RK_GPIO3_D4 124
  144. #define RK_GPIO3_D5 125
  145. #define RK_GPIO3_D6 126
  146. #define RK_GPIO3_D7 127
  147. #define RK_GPIO4_A0 128
  148. #define RK_GPIO4_A1 129
  149. #define RK_GPIO4_A2 130
  150. #define RK_GPIO4_A3 131
  151. #define RK_GPIO4_A4 132
  152. #define RK_GPIO4_A5 133
  153. #define RK_GPIO4_A6 134
  154. #define RK_GPIO4_A7 135
  155. #define RK_GPIO4_B0 136
  156. #define RK_GPIO4_B1 137
  157. #define RK_GPIO4_B2 138
  158. #define RK_GPIO4_B3 139
  159. #define RK_GPIO4_B4 140
  160. #define RK_GPIO4_B5 141
  161. #define RK_GPIO4_B6 142
  162. #define RK_GPIO4_B7 143
  163. #define RK_GPIO4_C0 144
  164. #define RK_GPIO4_C1 145
  165. #define RK_GPIO4_C2 146
  166. #define RK_GPIO4_C3 147
  167. #define RK_GPIO4_C4 148
  168. #define RK_GPIO4_C5 149
  169. #define RK_GPIO4_C6 150
  170. #define RK_GPIO4_C7 151
  171. #define RK_GPIO4_D0 152
  172. #define RK_GPIO4_D1 153
  173. #define RK_GPIO4_D2 154
  174. #define RK_GPIO4_D3 155
  175. #define RK_GPIO4_D4 156
  176. #define RK_GPIO4_D5 157
  177. #define RK_GPIO4_D6 158
  178. #define RK_GPIO4_D7 159
  179. enum rockchip_pinctrl_type {
  180. PX30,
  181. RV1108,
  182. RV1126,
  183. RK2928,
  184. RK3066B,
  185. RK3128,
  186. RK3188,
  187. RK3288,
  188. RK3308,
  189. RK3328,
  190. RK3368,
  191. RK3399,
  192. RK3506,
  193. RK3528,
  194. RK3562,
  195. RK3568,
  196. RK3576,
  197. RK3588,
  198. };
  199. /**
  200. * struct rockchip_gpio_regs
  201. * @port_dr: data register
  202. * @port_ddr: data direction register
  203. * @int_en: interrupt enable
  204. * @int_mask: interrupt mask
  205. * @int_type: interrupt trigger type, such as high, low, edge trriger type.
  206. * @int_polarity: interrupt polarity enable register
  207. * @int_bothedge: interrupt bothedge enable register
  208. * @int_status: interrupt status register
  209. * @int_rawstatus: int_status = int_rawstatus & int_mask
  210. * @debounce: enable debounce for interrupt signal
  211. * @dbclk_div_en: enable divider for debounce clock
  212. * @dbclk_div_con: setting for divider of debounce clock
  213. * @port_eoi: end of interrupt of the port
  214. * @ext_port: port data from external
  215. * @version_id: controller version register
  216. */
  217. struct rockchip_gpio_regs {
  218. u32 port_dr;
  219. u32 port_ddr;
  220. u32 int_en;
  221. u32 int_mask;
  222. u32 int_type;
  223. u32 int_polarity;
  224. u32 int_bothedge;
  225. u32 int_status;
  226. u32 int_rawstatus;
  227. u32 debounce;
  228. u32 dbclk_div_en;
  229. u32 dbclk_div_con;
  230. u32 port_eoi;
  231. u32 ext_port;
  232. u32 version_id;
  233. };
  234. /**
  235. * struct rockchip_iomux
  236. * @type: iomux variant using IOMUX_* constants
  237. * @offset: if initialized to -1 it will be autocalculated, by specifying
  238. * an initial offset value the relevant source offset can be reset
  239. * to a new value for autocalculating the following iomux registers.
  240. */
  241. struct rockchip_iomux {
  242. int type;
  243. int offset;
  244. };
  245. /*
  246. * enum type index corresponding to rockchip_perpin_drv_list arrays index.
  247. */
  248. enum rockchip_pin_drv_type {
  249. DRV_TYPE_IO_DEFAULT = 0,
  250. DRV_TYPE_IO_1V8_OR_3V0,
  251. DRV_TYPE_IO_1V8_ONLY,
  252. DRV_TYPE_IO_1V8_3V0_AUTO,
  253. DRV_TYPE_IO_3V3_ONLY,
  254. DRV_TYPE_IO_LEVEL_2_BIT,
  255. DRV_TYPE_IO_LEVEL_8_BIT,
  256. DRV_TYPE_MAX
  257. };
  258. /*
  259. * enum type index corresponding to rockchip_pull_list arrays index.
  260. */
  261. enum rockchip_pin_pull_type {
  262. PULL_TYPE_IO_DEFAULT = 0,
  263. PULL_TYPE_IO_1V8_ONLY,
  264. PULL_TYPE_MAX
  265. };
  266. /**
  267. * struct rockchip_drv
  268. * @drv_type: drive strength variant using rockchip_perpin_drv_type
  269. * @offset: if initialized to -1 it will be autocalculated, by specifying
  270. * an initial offset value the relevant source offset can be reset
  271. * to a new value for autocalculating the following drive strength
  272. * registers. if used chips own cal_drv func instead to calculate
  273. * registers offset, the variant could be ignored.
  274. */
  275. struct rockchip_drv {
  276. enum rockchip_pin_drv_type drv_type;
  277. int offset;
  278. };
  279. /**
  280. * struct rockchip_pin_bank
  281. * @dev: the pinctrl device bind to the bank
  282. * @reg_base: register base of the gpio bank
  283. * @regmap_pull: optional separate register for additional pull settings
  284. * @clk: clock of the gpio bank
  285. * @db_clk: clock of the gpio debounce
  286. * @irq: interrupt of the gpio bank
  287. * @saved_masks: Saved content of GPIO_INTEN at suspend time.
  288. * @pin_base: first pin number
  289. * @nr_pins: number of pins in this bank
  290. * @name: name of the bank
  291. * @bank_num: number of the bank, to account for holes
  292. * @iomux: array describing the 4 iomux sources of the bank
  293. * @drv: array describing the 4 drive strength sources of the bank
  294. * @pull_type: array describing the 4 pull type sources of the bank
  295. * @valid: is all necessary information present
  296. * @of_node: dt node of this bank
  297. * @drvdata: common pinctrl basedata
  298. * @domain: irqdomain of the gpio bank
  299. * @gpio_chip: gpiolib chip
  300. * @grange: gpio range
  301. * @slock: spinlock for the gpio bank
  302. * @toggle_edge_mode: bit mask to toggle (falling/rising) edge mode
  303. * @recalced_mask: bit mask to indicate a need to recalulate the mask
  304. * @route_mask: bits describing the routing pins of per bank
  305. * @deferred_output: gpio output settings to be done after gpio bank probed
  306. * @deferred_lock: mutex for the deferred_output shared btw gpio and pinctrl
  307. */
  308. struct rockchip_pin_bank {
  309. struct device *dev;
  310. void __iomem *reg_base;
  311. struct regmap *regmap_pull;
  312. struct clk *clk;
  313. struct clk *db_clk;
  314. int irq;
  315. u32 saved_masks;
  316. u32 pin_base;
  317. u8 nr_pins;
  318. char *name;
  319. u8 bank_num;
  320. struct rockchip_iomux iomux[4];
  321. struct rockchip_drv drv[4];
  322. enum rockchip_pin_pull_type pull_type[4];
  323. bool valid;
  324. struct device_node *of_node;
  325. struct rockchip_pinctrl *drvdata;
  326. struct irq_domain *domain;
  327. struct gpio_chip gpio_chip;
  328. struct pinctrl_gpio_range grange;
  329. raw_spinlock_t slock;
  330. const struct rockchip_gpio_regs *gpio_regs;
  331. u32 gpio_type;
  332. u32 toggle_edge_mode;
  333. u32 recalced_mask;
  334. u32 route_mask;
  335. struct list_head deferred_pins;
  336. struct mutex deferred_lock;
  337. };
  338. /**
  339. * struct rockchip_mux_recalced_data: represent a pin iomux data.
  340. * @num: bank number.
  341. * @pin: pin number.
  342. * @bit: index at register.
  343. * @reg: register offset.
  344. * @mask: mask bit
  345. */
  346. struct rockchip_mux_recalced_data {
  347. u8 num;
  348. u8 pin;
  349. u32 reg;
  350. u8 bit;
  351. u8 mask;
  352. };
  353. enum rockchip_mux_route_location {
  354. ROCKCHIP_ROUTE_SAME = 0,
  355. ROCKCHIP_ROUTE_PMU,
  356. ROCKCHIP_ROUTE_GRF,
  357. };
  358. /**
  359. * struct rockchip_mux_recalced_data: represent a pin iomux data.
  360. * @bank_num: bank number.
  361. * @pin: index at register or used to calc index.
  362. * @func: the min pin.
  363. * @route_location: the mux route location (same, pmu, grf).
  364. * @route_offset: the max pin.
  365. * @route_val: the register offset.
  366. */
  367. struct rockchip_mux_route_data {
  368. u8 bank_num;
  369. u8 pin;
  370. u8 func;
  371. enum rockchip_mux_route_location route_location;
  372. u32 route_offset;
  373. u32 route_val;
  374. };
  375. struct rockchip_pin_ctrl {
  376. struct rockchip_pin_bank *pin_banks;
  377. u32 nr_banks;
  378. u32 nr_pins;
  379. char *label;
  380. enum rockchip_pinctrl_type type;
  381. int grf_mux_offset;
  382. int pmu_mux_offset;
  383. int grf_drv_offset;
  384. int pmu_drv_offset;
  385. struct rockchip_mux_recalced_data *iomux_recalced;
  386. u32 niomux_recalced;
  387. struct rockchip_mux_route_data *iomux_routes;
  388. u32 niomux_routes;
  389. int (*pull_calc_reg)(struct rockchip_pin_bank *bank,
  390. int pin_num, struct regmap **regmap,
  391. int *reg, u8 *bit);
  392. int (*drv_calc_reg)(struct rockchip_pin_bank *bank,
  393. int pin_num, struct regmap **regmap,
  394. int *reg, u8 *bit);
  395. int (*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
  396. int pin_num, struct regmap **regmap,
  397. int *reg, u8 *bit);
  398. };
  399. struct rockchip_pin_config {
  400. unsigned int func;
  401. unsigned long *configs;
  402. unsigned int nconfigs;
  403. };
  404. enum pin_config_param;
  405. struct rockchip_pin_deferred {
  406. struct list_head head;
  407. unsigned int pin;
  408. enum pin_config_param param;
  409. u32 arg;
  410. };
  411. /**
  412. * struct rockchip_pin_group: represent group of pins of a pinmux function.
  413. * @name: name of the pin group, used to lookup the group.
  414. * @pins: the pins included in this group.
  415. * @npins: number of pins included in this group.
  416. * @data: local pin configuration
  417. */
  418. struct rockchip_pin_group {
  419. const char *name;
  420. unsigned int npins;
  421. unsigned int *pins;
  422. struct rockchip_pin_config *data;
  423. };
  424. /**
  425. * struct rockchip_pmx_func: represent a pin function.
  426. * @name: name of the pin function, used to lookup the function.
  427. * @groups: one or more names of pin groups that provide this function.
  428. * @ngroups: number of groups included in @groups.
  429. */
  430. struct rockchip_pmx_func {
  431. const char *name;
  432. const char **groups;
  433. u8 ngroups;
  434. };
  435. struct rockchip_pinctrl {
  436. struct regmap *regmap_base;
  437. int reg_size;
  438. struct regmap *regmap_pull;
  439. struct regmap *regmap_pmu;
  440. struct regmap *regmap_ioc1;
  441. struct device *dev;
  442. struct rockchip_pin_ctrl *ctrl;
  443. struct pinctrl_desc pctl;
  444. struct pinctrl_dev *pctl_dev;
  445. struct rockchip_pin_group *groups;
  446. unsigned int ngroups;
  447. struct rockchip_pmx_func *functions;
  448. unsigned int nfunctions;
  449. };
  450. #endif