pinctrl-rockchip.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021 Rockchip Electronics Co. Ltd.
  4. *
  5. * Copyright (c) 2013 MundoReader S.L.
  6. * Author: Heiko Stuebner <[email protected]>
  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 <[email protected]>
  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. RK3368,
  190. RK3399,
  191. RK3568,
  192. RK3588,
  193. };
  194. /**
  195. * struct rockchip_gpio_regs
  196. * @port_dr: data register
  197. * @port_ddr: data direction register
  198. * @int_en: interrupt enable
  199. * @int_mask: interrupt mask
  200. * @int_type: interrupt trigger type, such as high, low, edge trriger type.
  201. * @int_polarity: interrupt polarity enable register
  202. * @int_bothedge: interrupt bothedge enable register
  203. * @int_status: interrupt status register
  204. * @int_rawstatus: int_status = int_rawstatus & int_mask
  205. * @debounce: enable debounce for interrupt signal
  206. * @dbclk_div_en: enable divider for debounce clock
  207. * @dbclk_div_con: setting for divider of debounce clock
  208. * @port_eoi: end of interrupt of the port
  209. * @ext_port: port data from external
  210. * @version_id: controller version register
  211. */
  212. struct rockchip_gpio_regs {
  213. u32 port_dr;
  214. u32 port_ddr;
  215. u32 int_en;
  216. u32 int_mask;
  217. u32 int_type;
  218. u32 int_polarity;
  219. u32 int_bothedge;
  220. u32 int_status;
  221. u32 int_rawstatus;
  222. u32 debounce;
  223. u32 dbclk_div_en;
  224. u32 dbclk_div_con;
  225. u32 port_eoi;
  226. u32 ext_port;
  227. u32 version_id;
  228. };
  229. /**
  230. * struct rockchip_iomux
  231. * @type: iomux variant using IOMUX_* constants
  232. * @offset: if initialized to -1 it will be autocalculated, by specifying
  233. * an initial offset value the relevant source offset can be reset
  234. * to a new value for autocalculating the following iomux registers.
  235. */
  236. struct rockchip_iomux {
  237. int type;
  238. int offset;
  239. };
  240. /*
  241. * enum type index corresponding to rockchip_perpin_drv_list arrays index.
  242. */
  243. enum rockchip_pin_drv_type {
  244. DRV_TYPE_IO_DEFAULT = 0,
  245. DRV_TYPE_IO_1V8_OR_3V0,
  246. DRV_TYPE_IO_1V8_ONLY,
  247. DRV_TYPE_IO_1V8_3V0_AUTO,
  248. DRV_TYPE_IO_3V3_ONLY,
  249. DRV_TYPE_MAX
  250. };
  251. /*
  252. * enum type index corresponding to rockchip_pull_list arrays index.
  253. */
  254. enum rockchip_pin_pull_type {
  255. PULL_TYPE_IO_DEFAULT = 0,
  256. PULL_TYPE_IO_1V8_ONLY,
  257. PULL_TYPE_MAX
  258. };
  259. /**
  260. * struct rockchip_drv
  261. * @drv_type: drive strength variant using rockchip_perpin_drv_type
  262. * @offset: if initialized to -1 it will be autocalculated, by specifying
  263. * an initial offset value the relevant source offset can be reset
  264. * to a new value for autocalculating the following drive strength
  265. * registers. if used chips own cal_drv func instead to calculate
  266. * registers offset, the variant could be ignored.
  267. */
  268. struct rockchip_drv {
  269. enum rockchip_pin_drv_type drv_type;
  270. int offset;
  271. };
  272. /**
  273. * struct rockchip_pin_bank
  274. * @dev: the pinctrl device bind to the bank
  275. * @reg_base: register base of the gpio bank
  276. * @regmap_pull: optional separate register for additional pull settings
  277. * @clk: clock of the gpio bank
  278. * @db_clk: clock of the gpio debounce
  279. * @irq: interrupt of the gpio bank
  280. * @saved_masks: Saved content of GPIO_INTEN at suspend time.
  281. * @pin_base: first pin number
  282. * @nr_pins: number of pins in this bank
  283. * @name: name of the bank
  284. * @bank_num: number of the bank, to account for holes
  285. * @iomux: array describing the 4 iomux sources of the bank
  286. * @drv: array describing the 4 drive strength sources of the bank
  287. * @pull_type: array describing the 4 pull type sources of the bank
  288. * @valid: is all necessary information present
  289. * @of_node: dt node of this bank
  290. * @drvdata: common pinctrl basedata
  291. * @domain: irqdomain of the gpio bank
  292. * @gpio_chip: gpiolib chip
  293. * @grange: gpio range
  294. * @slock: spinlock for the gpio bank
  295. * @toggle_edge_mode: bit mask to toggle (falling/rising) edge mode
  296. * @recalced_mask: bit mask to indicate a need to recalulate the mask
  297. * @route_mask: bits describing the routing pins of per bank
  298. * @deferred_output: gpio output settings to be done after gpio bank probed
  299. * @deferred_lock: mutex for the deferred_output shared btw gpio and pinctrl
  300. */
  301. struct rockchip_pin_bank {
  302. struct device *dev;
  303. void __iomem *reg_base;
  304. struct regmap *regmap_pull;
  305. struct clk *clk;
  306. struct clk *db_clk;
  307. int irq;
  308. u32 saved_masks;
  309. u32 pin_base;
  310. u8 nr_pins;
  311. char *name;
  312. u8 bank_num;
  313. struct rockchip_iomux iomux[4];
  314. struct rockchip_drv drv[4];
  315. enum rockchip_pin_pull_type pull_type[4];
  316. bool valid;
  317. struct device_node *of_node;
  318. struct rockchip_pinctrl *drvdata;
  319. struct irq_domain *domain;
  320. struct gpio_chip gpio_chip;
  321. struct pinctrl_gpio_range grange;
  322. raw_spinlock_t slock;
  323. const struct rockchip_gpio_regs *gpio_regs;
  324. u32 gpio_type;
  325. u32 toggle_edge_mode;
  326. u32 recalced_mask;
  327. u32 route_mask;
  328. struct list_head deferred_pins;
  329. struct mutex deferred_lock;
  330. };
  331. /**
  332. * struct rockchip_mux_recalced_data: represent a pin iomux data.
  333. * @num: bank number.
  334. * @pin: pin number.
  335. * @bit: index at register.
  336. * @reg: register offset.
  337. * @mask: mask bit
  338. */
  339. struct rockchip_mux_recalced_data {
  340. u8 num;
  341. u8 pin;
  342. u32 reg;
  343. u8 bit;
  344. u8 mask;
  345. };
  346. enum rockchip_mux_route_location {
  347. ROCKCHIP_ROUTE_SAME = 0,
  348. ROCKCHIP_ROUTE_PMU,
  349. ROCKCHIP_ROUTE_GRF,
  350. };
  351. /**
  352. * struct rockchip_mux_recalced_data: represent a pin iomux data.
  353. * @bank_num: bank number.
  354. * @pin: index at register or used to calc index.
  355. * @func: the min pin.
  356. * @route_location: the mux route location (same, pmu, grf).
  357. * @route_offset: the max pin.
  358. * @route_val: the register offset.
  359. */
  360. struct rockchip_mux_route_data {
  361. u8 bank_num;
  362. u8 pin;
  363. u8 func;
  364. enum rockchip_mux_route_location route_location;
  365. u32 route_offset;
  366. u32 route_val;
  367. };
  368. struct rockchip_pin_ctrl {
  369. struct rockchip_pin_bank *pin_banks;
  370. u32 nr_banks;
  371. u32 nr_pins;
  372. char *label;
  373. enum rockchip_pinctrl_type type;
  374. int grf_mux_offset;
  375. int pmu_mux_offset;
  376. int grf_drv_offset;
  377. int pmu_drv_offset;
  378. struct rockchip_mux_recalced_data *iomux_recalced;
  379. u32 niomux_recalced;
  380. struct rockchip_mux_route_data *iomux_routes;
  381. u32 niomux_routes;
  382. int (*pull_calc_reg)(struct rockchip_pin_bank *bank,
  383. int pin_num, struct regmap **regmap,
  384. int *reg, u8 *bit);
  385. int (*drv_calc_reg)(struct rockchip_pin_bank *bank,
  386. int pin_num, struct regmap **regmap,
  387. int *reg, u8 *bit);
  388. int (*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
  389. int pin_num, struct regmap **regmap,
  390. int *reg, u8 *bit);
  391. };
  392. struct rockchip_pin_config {
  393. unsigned int func;
  394. unsigned long *configs;
  395. unsigned int nconfigs;
  396. };
  397. enum pin_config_param;
  398. struct rockchip_pin_deferred {
  399. struct list_head head;
  400. unsigned int pin;
  401. enum pin_config_param param;
  402. u32 arg;
  403. };
  404. /**
  405. * struct rockchip_pin_group: represent group of pins of a pinmux function.
  406. * @name: name of the pin group, used to lookup the group.
  407. * @pins: the pins included in this group.
  408. * @npins: number of pins included in this group.
  409. * @data: local pin configuration
  410. */
  411. struct rockchip_pin_group {
  412. const char *name;
  413. unsigned int npins;
  414. unsigned int *pins;
  415. struct rockchip_pin_config *data;
  416. };
  417. /**
  418. * struct rockchip_pmx_func: represent a pin function.
  419. * @name: name of the pin function, used to lookup the function.
  420. * @groups: one or more names of pin groups that provide this function.
  421. * @ngroups: number of groups included in @groups.
  422. */
  423. struct rockchip_pmx_func {
  424. const char *name;
  425. const char **groups;
  426. u8 ngroups;
  427. };
  428. struct rockchip_pinctrl {
  429. struct regmap *regmap_base;
  430. int reg_size;
  431. struct regmap *regmap_pull;
  432. struct regmap *regmap_pmu;
  433. struct device *dev;
  434. struct rockchip_pin_ctrl *ctrl;
  435. struct pinctrl_desc pctl;
  436. struct pinctrl_dev *pctl_dev;
  437. struct rockchip_pin_group *groups;
  438. unsigned int ngroups;
  439. struct rockchip_pmx_func *functions;
  440. unsigned int nfunctions;
  441. };
  442. #endif