pinctrl-samsung.h 12 KB

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