pinctrl-samsung.h 12 KB

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