pinctrl-samsung.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * pin-controller/pin-mux/pin-config/gpio-driver for Samsung's SoC's.
  4. *
  5. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  6. * http://www.samsung.com
  7. * Copyright (c) 2012 Linaro Ltd
  8. * http://www.linaro.org
  9. *
  10. * Author: Thomas Abraham <thomas.ab@samsung.com>
  11. */
  12. #ifndef __PINCTRL_SAMSUNG_H
  13. #define __PINCTRL_SAMSUNG_H
  14. #include <linux/pinctrl/pinctrl.h>
  15. #include <linux/pinctrl/pinmux.h>
  16. #include <linux/pinctrl/pinconf.h>
  17. #include <linux/pinctrl/consumer.h>
  18. #include <linux/pinctrl/machine.h>
  19. #include <linux/gpio/driver.h>
  20. /**
  21. * enum pincfg_type - possible pin configuration types supported.
  22. * @PINCFG_TYPE_FUNC: Function configuration.
  23. * @PINCFG_TYPE_DAT: Pin value configuration.
  24. * @PINCFG_TYPE_PUD: Pull up/down configuration.
  25. * @PINCFG_TYPE_DRV: Drive strength configuration.
  26. * @PINCFG_TYPE_CON_PDN: Pin function in power down mode.
  27. * @PINCFG_TYPE_PUD_PDN: Pull up/down configuration in power down mode.
  28. */
  29. enum pincfg_type {
  30. PINCFG_TYPE_FUNC,
  31. PINCFG_TYPE_DAT,
  32. PINCFG_TYPE_PUD,
  33. PINCFG_TYPE_DRV,
  34. PINCFG_TYPE_CON_PDN,
  35. PINCFG_TYPE_PUD_PDN,
  36. PINCFG_TYPE_NUM
  37. };
  38. /*
  39. * pin configuration (pull up/down and drive strength) type and its value are
  40. * packed together into a 16-bits. The upper 8-bits represent the configuration
  41. * type and the lower 8-bits hold the value of the configuration type.
  42. */
  43. #define PINCFG_TYPE_MASK 0xFF
  44. #define PINCFG_VALUE_SHIFT 8
  45. #define PINCFG_VALUE_MASK (0xFF << PINCFG_VALUE_SHIFT)
  46. #define PINCFG_PACK(type, value) (((value) << PINCFG_VALUE_SHIFT) | type)
  47. #define PINCFG_UNPACK_TYPE(cfg) ((cfg) & PINCFG_TYPE_MASK)
  48. #define PINCFG_UNPACK_VALUE(cfg) (((cfg) & PINCFG_VALUE_MASK) >> \
  49. PINCFG_VALUE_SHIFT)
  50. /*
  51. * Values for the pin CON register, choosing pin function.
  52. * The basic set (input and output) are same between: S3C24xx, S3C64xx, S5PV210,
  53. * Exynos ARMv7, Exynos ARMv8, Tesla FSD.
  54. */
  55. #define PIN_CON_FUNC_INPUT 0x0
  56. #define PIN_CON_FUNC_OUTPUT 0x1
  57. /* Values for the pin PUD register */
  58. #define EXYNOS_PIN_PUD_PULL_DISABLE 0x0
  59. #define EXYNOS_PIN_PID_PULL_DOWN 0x1
  60. #define EXYNOS_PIN_PID_PULL_UP 0x3
  61. /*
  62. * enum pud_index - Possible index values to access the pud_val array.
  63. * @PUD_PULL_DISABLE: Index for the value of pud disable
  64. * @PUD_PULL_DOWN: Index for the value of pull down enable
  65. * @PUD_PULL_UP: Index for the value of pull up enable
  66. * @PUD_MAX: Maximum value of the index
  67. */
  68. enum pud_index {
  69. PUD_PULL_DISABLE,
  70. PUD_PULL_DOWN,
  71. PUD_PULL_UP,
  72. PUD_MAX,
  73. };
  74. /**
  75. * enum eint_type - possible external interrupt types.
  76. * @EINT_TYPE_NONE: bank does not support external interrupts
  77. * @EINT_TYPE_GPIO: bank supportes external gpio interrupts
  78. * @EINT_TYPE_WKUP: bank supportes external wakeup interrupts
  79. * @EINT_TYPE_WKUP_MUX: bank supports multiplexed external wakeup interrupts
  80. *
  81. * Samsung GPIO controller groups all the available pins into banks. The pins
  82. * in a pin bank can support external gpio interrupts or external wakeup
  83. * interrupts or no interrupts at all. From a software perspective, the only
  84. * difference between external gpio and external wakeup interrupts is that
  85. * the wakeup interrupts can additionally wakeup the system if it is in
  86. * suspended state.
  87. */
  88. enum eint_type {
  89. EINT_TYPE_NONE,
  90. EINT_TYPE_GPIO,
  91. EINT_TYPE_WKUP,
  92. EINT_TYPE_WKUP_MUX,
  93. };
  94. /* maximum length of a pin in pin descriptor (example: "gpa0-0") */
  95. #define PIN_NAME_LENGTH 10
  96. #define PIN_GROUP(n, p, f) \
  97. { \
  98. .name = n, \
  99. .pins = p, \
  100. .num_pins = ARRAY_SIZE(p), \
  101. .func = f \
  102. }
  103. #define PMX_FUNC(n, g) \
  104. { \
  105. .name = n, \
  106. .groups = g, \
  107. .num_groups = ARRAY_SIZE(g), \
  108. }
  109. struct samsung_pinctrl_drv_data;
  110. /**
  111. * struct samsung_pin_bank_type: pin bank type description
  112. * @fld_width: widths of configuration bitfields (0 if unavailable)
  113. * @reg_offset: offsets of configuration registers (don't care of width is 0)
  114. */
  115. struct samsung_pin_bank_type {
  116. u8 fld_width[PINCFG_TYPE_NUM];
  117. u8 reg_offset[PINCFG_TYPE_NUM];
  118. };
  119. /**
  120. * struct samsung_pin_bank_data: represent a controller pin-bank (init data).
  121. * @type: type of the bank (register offsets and bitfield widths)
  122. * @pctl_offset: starting offset of the pin-bank registers.
  123. * @pctl_res_idx: index of base address for pin-bank registers.
  124. * @nr_pins: number of pins included in this bank.
  125. * @eint_func: function to set in CON register to configure pin as EINT.
  126. * @eint_type: type of the external interrupt supported by the bank.
  127. * @eint_mask: bit mask of pins which support EINT function.
  128. * @eint_offset: SoC-specific EINT register or interrupt offset of bank.
  129. * @eint_con_offset: ExynosAuto SoC-specific EINT control register offset of bank.
  130. * @eint_mask_offset: ExynosAuto SoC-specific EINT mask register offset of bank.
  131. * @eint_pend_offset: ExynosAuto SoC-specific EINT pend register offset of bank.
  132. * @eint_fltcon_offset: GS101 SoC-specific EINT filter config register offset.
  133. * @name: name to be prefixed for each pin in this pin bank.
  134. */
  135. struct samsung_pin_bank_data {
  136. const struct samsung_pin_bank_type *type;
  137. u32 pctl_offset;
  138. u8 pctl_res_idx;
  139. u8 nr_pins;
  140. u8 eint_func;
  141. enum eint_type eint_type;
  142. u32 eint_mask;
  143. u32 eint_offset;
  144. u32 eint_con_offset;
  145. u32 eint_mask_offset;
  146. u32 eint_pend_offset;
  147. u32 eint_fltcon_offset;
  148. const char *name;
  149. };
  150. /**
  151. * struct samsung_pin_bank: represent a controller pin-bank.
  152. * @type: type of the bank (register offsets and bitfield widths)
  153. * @pctl_base: base address of the pin-bank registers
  154. * @pctl_offset: starting offset of the pin-bank registers.
  155. * @nr_pins: number of pins included in this bank.
  156. * @eint_base: base address of the pin-bank EINT registers.
  157. * @eint_func: function to set in CON register to configure pin as EINT.
  158. * @eint_type: type of the external interrupt supported by the bank.
  159. * @eint_mask: bit mask of pins which support EINT function.
  160. * @eint_offset: SoC-specific EINT register or interrupt offset of bank.
  161. * @eint_con_offset: ExynosAuto SoC-specific EINT register or interrupt offset of bank.
  162. * @eint_mask_offset: ExynosAuto SoC-specific EINT mask register offset of bank.
  163. * @eint_pend_offset: ExynosAuto SoC-specific EINT pend register offset of bank.
  164. * @eint_fltcon_offset: GS101 SoC-specific EINT filter config register offset.
  165. * @name: name to be prefixed for each pin in this pin bank.
  166. * @id: id of the bank, propagated to the pin range.
  167. * @pin_base: starting pin number of the bank.
  168. * @soc_priv: per-bank private data for SoC-specific code.
  169. * @of_node: OF node of the bank.
  170. * @drvdata: link to controller driver data
  171. * @irq_domain: IRQ domain of the bank.
  172. * @gpio_chip: GPIO chip of the bank.
  173. * @grange: linux gpio pin range supported by this bank.
  174. * @irq_chip: link to irq chip for external gpio and wakeup interrupts.
  175. * @slock: spinlock protecting bank registers
  176. * @pm_save: saved register values during suspend
  177. */
  178. struct samsung_pin_bank {
  179. const struct samsung_pin_bank_type *type;
  180. void __iomem *pctl_base;
  181. u32 pctl_offset;
  182. u8 nr_pins;
  183. void __iomem *eint_base;
  184. u8 eint_func;
  185. enum eint_type eint_type;
  186. u32 eint_mask;
  187. u32 eint_offset;
  188. u32 eint_con_offset;
  189. u32 eint_mask_offset;
  190. u32 eint_pend_offset;
  191. u32 eint_fltcon_offset;
  192. const char *name;
  193. u32 id;
  194. u32 pin_base;
  195. void *soc_priv;
  196. struct fwnode_handle *fwnode;
  197. struct samsung_pinctrl_drv_data *drvdata;
  198. struct irq_domain *irq_domain;
  199. struct gpio_chip gpio_chip;
  200. struct pinctrl_gpio_range grange;
  201. struct exynos_irq_chip *irq_chip;
  202. raw_spinlock_t slock;
  203. u32 pm_save[PINCFG_TYPE_NUM + 1]; /* +1 to handle double CON registers*/
  204. };
  205. /**
  206. * struct samsung_retention_data: runtime pin-bank retention control data.
  207. * @regs: array of PMU registers to control pad retention.
  208. * @nr_regs: number of registers in @regs array.
  209. * @value: value to store to registers to turn off retention.
  210. * @refcnt: atomic counter if retention control affects more than one bank.
  211. * @priv: retention control code private data
  212. * @enable: platform specific callback to enter retention mode.
  213. * @disable: platform specific callback to exit retention mode.
  214. **/
  215. struct samsung_retention_ctrl {
  216. const u32 *regs;
  217. int nr_regs;
  218. u32 value;
  219. atomic_t *refcnt;
  220. void *priv;
  221. void (*enable)(struct samsung_pinctrl_drv_data *);
  222. void (*disable)(struct samsung_pinctrl_drv_data *);
  223. };
  224. /**
  225. * struct samsung_retention_data: represent a pin-bank retention control data.
  226. * @regs: array of PMU registers to control pad retention.
  227. * @nr_regs: number of registers in @regs array.
  228. * @value: value to store to registers to turn off retention.
  229. * @refcnt: atomic counter if retention control affects more than one bank.
  230. * @init: platform specific callback to initialize retention control.
  231. **/
  232. struct samsung_retention_data {
  233. const u32 *regs;
  234. int nr_regs;
  235. u32 value;
  236. atomic_t *refcnt;
  237. struct samsung_retention_ctrl *(*init)(struct samsung_pinctrl_drv_data *,
  238. const struct samsung_retention_data *);
  239. };
  240. /**
  241. * struct samsung_pin_ctrl: represent a pin controller.
  242. * @pin_banks: list of pin banks included in this controller.
  243. * @nr_banks: number of pin banks.
  244. * @nr_ext_resources: number of the extra base address for pin banks.
  245. * @retention_data: configuration data for retention control.
  246. * @eint_gpio_init: platform specific callback to setup the external gpio
  247. * interrupts for the controller.
  248. * @eint_wkup_init: platform specific callback to setup the external wakeup
  249. * interrupts for the controller.
  250. * @suspend: platform specific suspend callback, executed during pin controller
  251. * device suspend, see samsung_pinctrl_suspend()
  252. * @resume: platform specific resume callback, executed during pin controller
  253. * device suspend, see samsung_pinctrl_resume()
  254. *
  255. * External wakeup interrupts must define at least eint_wkup_init,
  256. * retention_data and suspend in order for proper suspend/resume to work.
  257. */
  258. struct samsung_pin_ctrl {
  259. const struct samsung_pin_bank_data *pin_banks;
  260. unsigned int nr_banks;
  261. unsigned int nr_ext_resources;
  262. const struct samsung_retention_data *retention_data;
  263. int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *);
  264. int (*eint_wkup_init)(struct samsung_pinctrl_drv_data *);
  265. void (*pud_value_init)(struct samsung_pinctrl_drv_data *drvdata);
  266. void (*suspend)(struct samsung_pin_bank *bank);
  267. void (*resume)(struct samsung_pin_bank *bank);
  268. };
  269. /**
  270. * struct samsung_pinctrl_drv_data: wrapper for holding driver data together.
  271. * @node: global list node
  272. * @virt_base: register base address of the controller; this will be equal
  273. * to each bank samsung_pin_bank->pctl_base and used on legacy
  274. * platforms (like S3C24XX or S3C64XX) which has to access the base
  275. * through samsung_pinctrl_drv_data, not samsung_pin_bank).
  276. * @dev: device instance representing the controller.
  277. * @irq: interrpt number used by the controller to notify gpio interrupts.
  278. * @pclk: optional bus clock if required for accessing registers
  279. * @ctrl: pin controller instance managed by the driver.
  280. * @pctl: pin controller descriptor registered with the pinctrl subsystem.
  281. * @pctl_dev: cookie representing pinctrl device instance.
  282. * @pin_groups: list of pin groups available to the driver.
  283. * @nr_groups: number of such pin groups.
  284. * @pmx_functions: list of pin functions available to the driver.
  285. * @nr_function: number of such pin functions.
  286. * @nr_pins: number of pins supported by the controller.
  287. * @retention_ctrl: retention control runtime data.
  288. * @suspend: platform specific suspend callback, executed during pin controller
  289. * device suspend, see samsung_pinctrl_suspend()
  290. * @resume: platform specific resume callback, executed during pin controller
  291. * device suspend, see samsung_pinctrl_resume()
  292. */
  293. struct samsung_pinctrl_drv_data {
  294. struct list_head node;
  295. void __iomem *virt_base;
  296. struct device *dev;
  297. int irq;
  298. struct clk *pclk;
  299. struct pinctrl_desc pctl;
  300. struct pinctrl_dev *pctl_dev;
  301. const struct samsung_pin_group *pin_groups;
  302. unsigned int nr_groups;
  303. const struct samsung_pmx_func *pmx_functions;
  304. unsigned int nr_functions;
  305. struct samsung_pin_bank *pin_banks;
  306. unsigned int nr_banks;
  307. unsigned int nr_pins;
  308. unsigned int pud_val[PUD_MAX];
  309. struct samsung_retention_ctrl *retention_ctrl;
  310. void (*suspend)(struct samsung_pin_bank *bank);
  311. void (*resume)(struct samsung_pin_bank *bank);
  312. };
  313. /**
  314. * struct samsung_pinctrl_of_match_data: OF match device specific configuration data.
  315. * @ctrl: array of pin controller data.
  316. * @num_ctrl: size of array @ctrl.
  317. */
  318. struct samsung_pinctrl_of_match_data {
  319. const struct samsung_pin_ctrl *ctrl;
  320. unsigned int num_ctrl;
  321. };
  322. /**
  323. * struct samsung_pin_group: represent group of pins of a pinmux function.
  324. * @name: name of the pin group, used to lookup the group.
  325. * @pins: the pins included in this group.
  326. * @num_pins: number of pins included in this group.
  327. * @func: the function number to be programmed when selected.
  328. */
  329. struct samsung_pin_group {
  330. const char *name;
  331. const unsigned int *pins;
  332. u8 num_pins;
  333. u8 func;
  334. };
  335. /**
  336. * struct samsung_pmx_func: represent a pin function.
  337. * @name: name of the pin function, used to lookup the function.
  338. * @groups: one or more names of pin groups that provide this function.
  339. * @num_groups: number of groups included in @groups.
  340. */
  341. struct samsung_pmx_func {
  342. const char *name;
  343. const char **groups;
  344. u8 num_groups;
  345. u32 val;
  346. };
  347. /* list of all exported SoC specific data */
  348. extern const struct samsung_pinctrl_of_match_data exynos3250_of_data;
  349. extern const struct samsung_pinctrl_of_match_data exynos4210_of_data;
  350. extern const struct samsung_pinctrl_of_match_data exynos4x12_of_data;
  351. extern const struct samsung_pinctrl_of_match_data exynos5250_of_data;
  352. extern const struct samsung_pinctrl_of_match_data exynos5260_of_data;
  353. extern const struct samsung_pinctrl_of_match_data exynos5410_of_data;
  354. extern const struct samsung_pinctrl_of_match_data exynos5420_of_data;
  355. extern const struct samsung_pinctrl_of_match_data exynos5433_of_data;
  356. extern const struct samsung_pinctrl_of_match_data exynos7_of_data;
  357. extern const struct samsung_pinctrl_of_match_data exynos7885_of_data;
  358. extern const struct samsung_pinctrl_of_match_data exynos850_of_data;
  359. extern const struct samsung_pinctrl_of_match_data exynosautov9_of_data;
  360. extern const struct samsung_pinctrl_of_match_data exynosautov920_of_data;
  361. extern const struct samsung_pinctrl_of_match_data fsd_of_data;
  362. extern const struct samsung_pinctrl_of_match_data gs101_of_data;
  363. extern const struct samsung_pinctrl_of_match_data s3c64xx_of_data;
  364. extern const struct samsung_pinctrl_of_match_data s5pv210_of_data;
  365. #endif /* __PINCTRL_SAMSUNG_H */