pinctrl-samsung.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * pin-controller/pin-mux/pin-config/gpio-driver for Samsung's SoC's.
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. * Copyright (c) 2012 Linaro Ltd
  7. * http://www.linaro.org
  8. *
  9. * Author: Thomas Abraham <thomas.ab@samsung.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. #ifndef __PINCTRL_SAMSUNG_H
  17. #define __PINCTRL_SAMSUNG_H
  18. #include <linux/pinctrl/pinctrl.h>
  19. #include <linux/pinctrl/pinmux.h>
  20. #include <linux/pinctrl/pinconf.h>
  21. #include <linux/pinctrl/consumer.h>
  22. #include <linux/pinctrl/machine.h>
  23. #include <linux/gpio.h>
  24. /* pinmux function number for pin as gpio output line */
  25. #define FUNC_INPUT 0x0
  26. #define FUNC_OUTPUT 0x1
  27. /**
  28. * enum pincfg_type - possible pin configuration types supported.
  29. * @PINCFG_TYPE_FUNC: Function configuration.
  30. * @PINCFG_TYPE_DAT: Pin value configuration.
  31. * @PINCFG_TYPE_PUD: Pull up/down configuration.
  32. * @PINCFG_TYPE_DRV: Drive strength configuration.
  33. * @PINCFG_TYPE_CON_PDN: Pin function in power down mode.
  34. * @PINCFG_TYPE_PUD_PDN: Pull up/down configuration in power down mode.
  35. */
  36. enum pincfg_type {
  37. PINCFG_TYPE_FUNC,
  38. PINCFG_TYPE_DAT,
  39. PINCFG_TYPE_PUD,
  40. PINCFG_TYPE_DRV,
  41. PINCFG_TYPE_CON_PDN,
  42. PINCFG_TYPE_PUD_PDN,
  43. PINCFG_TYPE_NUM
  44. };
  45. /*
  46. * pin configuration (pull up/down and drive strength) type and its value are
  47. * packed together into a 16-bits. The upper 8-bits represent the configuration
  48. * type and the lower 8-bits hold the value of the configuration type.
  49. */
  50. #define PINCFG_TYPE_MASK 0xFF
  51. #define PINCFG_VALUE_SHIFT 8
  52. #define PINCFG_VALUE_MASK (0xFF << PINCFG_VALUE_SHIFT)
  53. #define PINCFG_PACK(type, value) (((value) << PINCFG_VALUE_SHIFT) | type)
  54. #define PINCFG_UNPACK_TYPE(cfg) ((cfg) & PINCFG_TYPE_MASK)
  55. #define PINCFG_UNPACK_VALUE(cfg) (((cfg) & PINCFG_VALUE_MASK) >> \
  56. PINCFG_VALUE_SHIFT)
  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. * @nr_pins: number of pins included in this bank.
  107. * @eint_func: function to set in CON register to configure pin as EINT.
  108. * @eint_type: type of the external interrupt supported by the bank.
  109. * @eint_mask: bit mask of pins which support EINT function.
  110. * @eint_offset: SoC-specific EINT register or interrupt offset of bank.
  111. * @name: name to be prefixed for each pin in this pin bank.
  112. */
  113. struct samsung_pin_bank_data {
  114. const struct samsung_pin_bank_type *type;
  115. u32 pctl_offset;
  116. u8 nr_pins;
  117. u8 eint_func;
  118. enum eint_type eint_type;
  119. u32 eint_mask;
  120. u32 eint_offset;
  121. const char *name;
  122. };
  123. /**
  124. * struct samsung_pin_bank: represent a controller pin-bank.
  125. * @type: type of the bank (register offsets and bitfield widths)
  126. * @pctl_offset: starting offset of the pin-bank registers.
  127. * @nr_pins: number of pins included in this bank.
  128. * @eint_func: function to set in CON register to configure pin as EINT.
  129. * @eint_type: type of the external interrupt supported by the bank.
  130. * @eint_mask: bit mask of pins which support EINT function.
  131. * @eint_offset: SoC-specific EINT register or interrupt offset of bank.
  132. * @name: name to be prefixed for each pin in this pin bank.
  133. * @pin_base: starting pin number of the bank.
  134. * @soc_priv: per-bank private data for SoC-specific code.
  135. * @of_node: OF node of the bank.
  136. * @drvdata: link to controller driver data
  137. * @irq_domain: IRQ domain of the bank.
  138. * @gpio_chip: GPIO chip of the bank.
  139. * @grange: linux gpio pin range supported by this bank.
  140. * @irq_chip: link to irq chip for external gpio and wakeup interrupts.
  141. * @slock: spinlock protecting bank registers
  142. * @pm_save: saved register values during suspend
  143. */
  144. struct samsung_pin_bank {
  145. const struct samsung_pin_bank_type *type;
  146. u32 pctl_offset;
  147. u8 nr_pins;
  148. u8 eint_func;
  149. enum eint_type eint_type;
  150. u32 eint_mask;
  151. u32 eint_offset;
  152. const char *name;
  153. u32 pin_base;
  154. void *soc_priv;
  155. struct device_node *of_node;
  156. struct samsung_pinctrl_drv_data *drvdata;
  157. struct irq_domain *irq_domain;
  158. struct gpio_chip gpio_chip;
  159. struct pinctrl_gpio_range grange;
  160. struct exynos_irq_chip *irq_chip;
  161. spinlock_t slock;
  162. u32 pm_save[PINCFG_TYPE_NUM + 1]; /* +1 to handle double CON registers*/
  163. };
  164. /**
  165. * struct samsung_pin_ctrl: represent a pin controller.
  166. * @pin_banks: list of pin banks included in this controller.
  167. * @nr_banks: number of pin banks.
  168. * @eint_gpio_init: platform specific callback to setup the external gpio
  169. * interrupts for the controller.
  170. * @eint_wkup_init: platform specific callback to setup the external wakeup
  171. * interrupts for the controller.
  172. */
  173. struct samsung_pin_ctrl {
  174. const struct samsung_pin_bank_data *pin_banks;
  175. u32 nr_banks;
  176. int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *);
  177. int (*eint_wkup_init)(struct samsung_pinctrl_drv_data *);
  178. void (*suspend)(struct samsung_pinctrl_drv_data *);
  179. void (*resume)(struct samsung_pinctrl_drv_data *);
  180. };
  181. /**
  182. * struct samsung_pinctrl_drv_data: wrapper for holding driver data together.
  183. * @node: global list node
  184. * @virt_base: register base address of the controller.
  185. * @dev: device instance representing the controller.
  186. * @irq: interrpt number used by the controller to notify gpio interrupts.
  187. * @ctrl: pin controller instance managed by the driver.
  188. * @pctl: pin controller descriptor registered with the pinctrl subsystem.
  189. * @pctl_dev: cookie representing pinctrl device instance.
  190. * @pin_groups: list of pin groups available to the driver.
  191. * @nr_groups: number of such pin groups.
  192. * @pmx_functions: list of pin functions available to the driver.
  193. * @nr_function: number of such pin functions.
  194. * @pin_base: starting system wide pin number.
  195. * @nr_pins: number of pins supported by the controller.
  196. */
  197. struct samsung_pinctrl_drv_data {
  198. struct list_head node;
  199. void __iomem *virt_base;
  200. struct device *dev;
  201. int irq;
  202. struct pinctrl_desc pctl;
  203. struct pinctrl_dev *pctl_dev;
  204. const struct samsung_pin_group *pin_groups;
  205. unsigned int nr_groups;
  206. const struct samsung_pmx_func *pmx_functions;
  207. unsigned int nr_functions;
  208. struct samsung_pin_bank *pin_banks;
  209. u32 nr_banks;
  210. unsigned int pin_base;
  211. unsigned int nr_pins;
  212. void (*suspend)(struct samsung_pinctrl_drv_data *);
  213. void (*resume)(struct samsung_pinctrl_drv_data *);
  214. };
  215. /**
  216. * struct samsung_pin_group: represent group of pins of a pinmux function.
  217. * @name: name of the pin group, used to lookup the group.
  218. * @pins: the pins included in this group.
  219. * @num_pins: number of pins included in this group.
  220. * @func: the function number to be programmed when selected.
  221. */
  222. struct samsung_pin_group {
  223. const char *name;
  224. const unsigned int *pins;
  225. u8 num_pins;
  226. u8 func;
  227. };
  228. /**
  229. * struct samsung_pmx_func: represent a pin function.
  230. * @name: name of the pin function, used to lookup the function.
  231. * @groups: one or more names of pin groups that provide this function.
  232. * @num_groups: number of groups included in @groups.
  233. */
  234. struct samsung_pmx_func {
  235. const char *name;
  236. const char **groups;
  237. u8 num_groups;
  238. u32 val;
  239. };
  240. /* list of all exported SoC specific data */
  241. extern const struct samsung_pin_ctrl exynos3250_pin_ctrl[];
  242. extern const struct samsung_pin_ctrl exynos4210_pin_ctrl[];
  243. extern const struct samsung_pin_ctrl exynos4x12_pin_ctrl[];
  244. extern const struct samsung_pin_ctrl exynos4415_pin_ctrl[];
  245. extern const struct samsung_pin_ctrl exynos5250_pin_ctrl[];
  246. extern const struct samsung_pin_ctrl exynos5260_pin_ctrl[];
  247. extern const struct samsung_pin_ctrl exynos5410_pin_ctrl[];
  248. extern const struct samsung_pin_ctrl exynos5420_pin_ctrl[];
  249. extern const struct samsung_pin_ctrl exynos5433_pin_ctrl[];
  250. extern const struct samsung_pin_ctrl exynos7_pin_ctrl[];
  251. extern const struct samsung_pin_ctrl s3c64xx_pin_ctrl[];
  252. extern const struct samsung_pin_ctrl s3c2412_pin_ctrl[];
  253. extern const struct samsung_pin_ctrl s3c2416_pin_ctrl[];
  254. extern const struct samsung_pin_ctrl s3c2440_pin_ctrl[];
  255. extern const struct samsung_pin_ctrl s3c2450_pin_ctrl[];
  256. extern const struct samsung_pin_ctrl s5pv210_pin_ctrl[];
  257. #endif /* __PINCTRL_SAMSUNG_H */