pinctrl-samsung.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 <[email protected]>
  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. /**
  58. * enum eint_type - possible external interrupt types.
  59. * @EINT_TYPE_NONE: bank does not support external interrupts
  60. * @EINT_TYPE_GPIO: bank supportes external gpio interrupts
  61. * @EINT_TYPE_WKUP: bank supportes external wakeup interrupts
  62. * @EINT_TYPE_WKUP_MUX: bank supports multiplexed external wakeup interrupts
  63. *
  64. * Samsung GPIO controller groups all the available pins into banks. The pins
  65. * in a pin bank can support external gpio interrupts or external wakeup
  66. * interrupts or no interrupts at all. From a software perspective, the only
  67. * difference between external gpio and external wakeup interrupts is that
  68. * the wakeup interrupts can additionally wakeup the system if it is in
  69. * suspended state.
  70. */
  71. enum eint_type {
  72. EINT_TYPE_NONE,
  73. EINT_TYPE_GPIO,
  74. EINT_TYPE_WKUP,
  75. EINT_TYPE_WKUP_MUX,
  76. };
  77. /* maximum length of a pin in pin descriptor (example: "gpa0-0") */
  78. #define PIN_NAME_LENGTH 10
  79. #define PIN_GROUP(n, p, f) \
  80. { \
  81. .name = n, \
  82. .pins = p, \
  83. .num_pins = ARRAY_SIZE(p), \
  84. .func = f \
  85. }
  86. #define PMX_FUNC(n, g) \
  87. { \
  88. .name = n, \
  89. .groups = g, \
  90. .num_groups = ARRAY_SIZE(g), \
  91. }
  92. struct samsung_pinctrl_drv_data;
  93. /**
  94. * struct samsung_pin_bank_type: pin bank type description
  95. * @fld_width: widths of configuration bitfields (0 if unavailable)
  96. * @reg_offset: offsets of configuration registers (don't care of width is 0)
  97. */
  98. struct samsung_pin_bank_type {
  99. u8 fld_width[PINCFG_TYPE_NUM];
  100. u8 reg_offset[PINCFG_TYPE_NUM];
  101. };
  102. /**
  103. * struct samsung_pin_bank_data: represent a controller pin-bank (init data).
  104. * @type: type of the bank (register offsets and bitfield widths)
  105. * @pctl_offset: starting offset of the pin-bank registers.
  106. * @pctl_res_idx: index of base address for pin-bank registers.
  107. * @nr_pins: number of pins included in this bank.
  108. * @eint_func: function to set in CON register to configure pin as EINT.
  109. * @eint_type: type of the external interrupt supported by the bank.
  110. * @eint_mask: bit mask of pins which support EINT function.
  111. * @eint_offset: SoC-specific EINT register or interrupt offset of bank.
  112. * @name: name to be prefixed for each pin in this pin bank.
  113. */
  114. struct samsung_pin_bank_data {
  115. const struct samsung_pin_bank_type *type;
  116. u32 pctl_offset;
  117. u8 pctl_res_idx;
  118. u8 nr_pins;
  119. u8 eint_func;
  120. enum eint_type eint_type;
  121. u32 eint_mask;
  122. u32 eint_offset;
  123. const char *name;
  124. };
  125. /**
  126. * struct samsung_pin_bank: represent a controller pin-bank.
  127. * @type: type of the bank (register offsets and bitfield widths)
  128. * @pctl_base: base address of the pin-bank registers
  129. * @pctl_offset: starting offset of the pin-bank registers.
  130. * @nr_pins: number of pins included in this bank.
  131. * @eint_base: base address of the pin-bank EINT registers.
  132. * @eint_func: function to set in CON register to configure pin as EINT.
  133. * @eint_type: type of the external interrupt supported by the bank.
  134. * @eint_mask: bit mask of pins which support EINT function.
  135. * @eint_offset: SoC-specific EINT register or interrupt offset of bank.
  136. * @name: name to be prefixed for each pin in this pin bank.
  137. * @pin_base: starting pin number of the bank.
  138. * @soc_priv: per-bank private data for SoC-specific code.
  139. * @of_node: OF node of the bank.
  140. * @drvdata: link to controller driver data
  141. * @irq_domain: IRQ domain of the bank.
  142. * @gpio_chip: GPIO chip of the bank.
  143. * @grange: linux gpio pin range supported by this bank.
  144. * @irq_chip: link to irq chip for external gpio and wakeup interrupts.
  145. * @slock: spinlock protecting bank registers
  146. * @pm_save: saved register values during suspend
  147. */
  148. struct samsung_pin_bank {
  149. const struct samsung_pin_bank_type *type;
  150. void __iomem *pctl_base;
  151. u32 pctl_offset;
  152. u8 nr_pins;
  153. void __iomem *eint_base;
  154. u8 eint_func;
  155. enum eint_type eint_type;
  156. u32 eint_mask;
  157. u32 eint_offset;
  158. const char *name;
  159. u32 pin_base;
  160. void *soc_priv;
  161. struct fwnode_handle *fwnode;
  162. struct samsung_pinctrl_drv_data *drvdata;
  163. struct irq_domain *irq_domain;
  164. struct gpio_chip gpio_chip;
  165. struct pinctrl_gpio_range grange;
  166. struct exynos_irq_chip *irq_chip;
  167. raw_spinlock_t slock;
  168. u32 pm_save[PINCFG_TYPE_NUM + 1]; /* +1 to handle double CON registers*/
  169. };
  170. /**
  171. * struct samsung_retention_data: runtime pin-bank retention control data.
  172. * @regs: array of PMU registers to control pad retention.
  173. * @nr_regs: number of registers in @regs array.
  174. * @value: value to store to registers to turn off retention.
  175. * @refcnt: atomic counter if retention control affects more than one bank.
  176. * @priv: retention control code private data
  177. * @enable: platform specific callback to enter retention mode.
  178. * @disable: platform specific callback to exit retention mode.
  179. **/
  180. struct samsung_retention_ctrl {
  181. const u32 *regs;
  182. int nr_regs;
  183. u32 value;
  184. atomic_t *refcnt;
  185. void *priv;
  186. void (*enable)(struct samsung_pinctrl_drv_data *);
  187. void (*disable)(struct samsung_pinctrl_drv_data *);
  188. };
  189. /**
  190. * struct samsung_retention_data: represent a pin-bank retention control data.
  191. * @regs: array of PMU registers to control pad retention.
  192. * @nr_regs: number of registers in @regs array.
  193. * @value: value to store to registers to turn off retention.
  194. * @refcnt: atomic counter if retention control affects more than one bank.
  195. * @init: platform specific callback to initialize retention control.
  196. **/
  197. struct samsung_retention_data {
  198. const u32 *regs;
  199. int nr_regs;
  200. u32 value;
  201. atomic_t *refcnt;
  202. struct samsung_retention_ctrl *(*init)(struct samsung_pinctrl_drv_data *,
  203. const struct samsung_retention_data *);
  204. };
  205. /**
  206. * struct samsung_pin_ctrl: represent a pin controller.
  207. * @pin_banks: list of pin banks included in this controller.
  208. * @nr_banks: number of pin banks.
  209. * @nr_ext_resources: number of the extra base address for pin banks.
  210. * @retention_data: configuration data for retention control.
  211. * @eint_gpio_init: platform specific callback to setup the external gpio
  212. * interrupts for the controller.
  213. * @eint_wkup_init: platform specific callback to setup the external wakeup
  214. * interrupts for the controller.
  215. * @suspend: platform specific suspend callback, executed during pin controller
  216. * device suspend, see samsung_pinctrl_suspend()
  217. * @resume: platform specific resume callback, executed during pin controller
  218. * device suspend, see samsung_pinctrl_resume()
  219. *
  220. * External wakeup interrupts must define at least eint_wkup_init,
  221. * retention_data and suspend in order for proper suspend/resume to work.
  222. */
  223. struct samsung_pin_ctrl {
  224. const struct samsung_pin_bank_data *pin_banks;
  225. unsigned int nr_banks;
  226. unsigned int nr_ext_resources;
  227. const struct samsung_retention_data *retention_data;
  228. int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *);
  229. int (*eint_wkup_init)(struct samsung_pinctrl_drv_data *);
  230. void (*suspend)(struct samsung_pinctrl_drv_data *);
  231. void (*resume)(struct samsung_pinctrl_drv_data *);
  232. };
  233. /**
  234. * struct samsung_pinctrl_drv_data: wrapper for holding driver data together.
  235. * @node: global list node
  236. * @virt_base: register base address of the controller; this will be equal
  237. * to each bank samsung_pin_bank->pctl_base and used on legacy
  238. * platforms (like S3C24XX or S3C64XX) which has to access the base
  239. * through samsung_pinctrl_drv_data, not samsung_pin_bank).
  240. * @dev: device instance representing the controller.
  241. * @irq: interrpt number used by the controller to notify gpio interrupts.
  242. * @ctrl: pin controller instance managed by the driver.
  243. * @pctl: pin controller descriptor registered with the pinctrl subsystem.
  244. * @pctl_dev: cookie representing pinctrl device instance.
  245. * @pin_groups: list of pin groups available to the driver.
  246. * @nr_groups: number of such pin groups.
  247. * @pmx_functions: list of pin functions available to the driver.
  248. * @nr_function: number of such pin functions.
  249. * @pin_base: starting system wide pin number.
  250. * @nr_pins: number of pins supported by the controller.
  251. * @retention_ctrl: retention control runtime data.
  252. * @suspend: platform specific suspend callback, executed during pin controller
  253. * device suspend, see samsung_pinctrl_suspend()
  254. * @resume: platform specific resume callback, executed during pin controller
  255. * device suspend, see samsung_pinctrl_resume()
  256. */
  257. struct samsung_pinctrl_drv_data {
  258. struct list_head node;
  259. void __iomem *virt_base;
  260. struct device *dev;
  261. int irq;
  262. struct pinctrl_desc pctl;
  263. struct pinctrl_dev *pctl_dev;
  264. const struct samsung_pin_group *pin_groups;
  265. unsigned int nr_groups;
  266. const struct samsung_pmx_func *pmx_functions;
  267. unsigned int nr_functions;
  268. struct samsung_pin_bank *pin_banks;
  269. unsigned int nr_banks;
  270. unsigned int pin_base;
  271. unsigned int nr_pins;
  272. struct samsung_retention_ctrl *retention_ctrl;
  273. void (*suspend)(struct samsung_pinctrl_drv_data *);
  274. void (*resume)(struct samsung_pinctrl_drv_data *);
  275. };
  276. /**
  277. * struct samsung_pinctrl_of_match_data: OF match device specific configuration data.
  278. * @ctrl: array of pin controller data.
  279. * @num_ctrl: size of array @ctrl.
  280. */
  281. struct samsung_pinctrl_of_match_data {
  282. const struct samsung_pin_ctrl *ctrl;
  283. unsigned int num_ctrl;
  284. };
  285. /**
  286. * struct samsung_pin_group: represent group of pins of a pinmux function.
  287. * @name: name of the pin group, used to lookup the group.
  288. * @pins: the pins included in this group.
  289. * @num_pins: number of pins included in this group.
  290. * @func: the function number to be programmed when selected.
  291. */
  292. struct samsung_pin_group {
  293. const char *name;
  294. const unsigned int *pins;
  295. u8 num_pins;
  296. u8 func;
  297. };
  298. /**
  299. * struct samsung_pmx_func: represent a pin function.
  300. * @name: name of the pin function, used to lookup the function.
  301. * @groups: one or more names of pin groups that provide this function.
  302. * @num_groups: number of groups included in @groups.
  303. */
  304. struct samsung_pmx_func {
  305. const char *name;
  306. const char **groups;
  307. u8 num_groups;
  308. u32 val;
  309. };
  310. /* list of all exported SoC specific data */
  311. extern const struct samsung_pinctrl_of_match_data exynos3250_of_data;
  312. extern const struct samsung_pinctrl_of_match_data exynos4210_of_data;
  313. extern const struct samsung_pinctrl_of_match_data exynos4x12_of_data;
  314. extern const struct samsung_pinctrl_of_match_data exynos5250_of_data;
  315. extern const struct samsung_pinctrl_of_match_data exynos5260_of_data;
  316. extern const struct samsung_pinctrl_of_match_data exynos5410_of_data;
  317. extern const struct samsung_pinctrl_of_match_data exynos5420_of_data;
  318. extern const struct samsung_pinctrl_of_match_data exynos5433_of_data;
  319. extern const struct samsung_pinctrl_of_match_data exynos7_of_data;
  320. extern const struct samsung_pinctrl_of_match_data exynos7885_of_data;
  321. extern const struct samsung_pinctrl_of_match_data exynos850_of_data;
  322. extern const struct samsung_pinctrl_of_match_data exynosautov9_of_data;
  323. extern const struct samsung_pinctrl_of_match_data fsd_of_data;
  324. extern const struct samsung_pinctrl_of_match_data s3c64xx_of_data;
  325. extern const struct samsung_pinctrl_of_match_data s3c2412_of_data;
  326. extern const struct samsung_pinctrl_of_match_data s3c2416_of_data;
  327. extern const struct samsung_pinctrl_of_match_data s3c2440_of_data;
  328. extern const struct samsung_pinctrl_of_match_data s3c2450_of_data;
  329. extern const struct samsung_pinctrl_of_match_data s5pv210_of_data;
  330. #endif /* __PINCTRL_SAMSUNG_H */