Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 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 | |
| 17 | #ifndef __PINCTRL_SAMSUNG_H |
| 18 | #define __PINCTRL_SAMSUNG_H |
| 19 | |
| 20 | #include <linux/pinctrl/pinctrl.h> |
| 21 | #include <linux/pinctrl/pinmux.h> |
| 22 | #include <linux/pinctrl/pinconf.h> |
| 23 | #include <linux/pinctrl/consumer.h> |
| 24 | #include <linux/pinctrl/machine.h> |
| 25 | |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 26 | #include <linux/gpio.h> |
| 27 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 28 | /* pinmux function number for pin as gpio output line */ |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame^] | 29 | #define FUNC_INPUT 0x0 |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 30 | #define FUNC_OUTPUT 0x1 |
| 31 | |
| 32 | /** |
| 33 | * enum pincfg_type - possible pin configuration types supported. |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 34 | * @PINCFG_TYPE_FUNC: Function configuration. |
| 35 | * @PINCFG_TYPE_DAT: Pin value configuration. |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 36 | * @PINCFG_TYPE_PUD: Pull up/down configuration. |
| 37 | * @PINCFG_TYPE_DRV: Drive strength configuration. |
| 38 | * @PINCFG_TYPE_CON_PDN: Pin function in power down mode. |
| 39 | * @PINCFG_TYPE_PUD_PDN: Pull up/down configuration in power down mode. |
| 40 | */ |
| 41 | enum pincfg_type { |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 42 | PINCFG_TYPE_FUNC, |
| 43 | PINCFG_TYPE_DAT, |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 44 | PINCFG_TYPE_PUD, |
| 45 | PINCFG_TYPE_DRV, |
| 46 | PINCFG_TYPE_CON_PDN, |
| 47 | PINCFG_TYPE_PUD_PDN, |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 48 | |
| 49 | PINCFG_TYPE_NUM |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /* |
| 53 | * pin configuration (pull up/down and drive strength) type and its value are |
| 54 | * packed together into a 16-bits. The upper 8-bits represent the configuration |
| 55 | * type and the lower 8-bits hold the value of the configuration type. |
| 56 | */ |
| 57 | #define PINCFG_TYPE_MASK 0xFF |
| 58 | #define PINCFG_VALUE_SHIFT 8 |
| 59 | #define PINCFG_VALUE_MASK (0xFF << PINCFG_VALUE_SHIFT) |
| 60 | #define PINCFG_PACK(type, value) (((value) << PINCFG_VALUE_SHIFT) | type) |
| 61 | #define PINCFG_UNPACK_TYPE(cfg) ((cfg) & PINCFG_TYPE_MASK) |
| 62 | #define PINCFG_UNPACK_VALUE(cfg) (((cfg) & PINCFG_VALUE_MASK) >> \ |
| 63 | PINCFG_VALUE_SHIFT) |
| 64 | /** |
| 65 | * enum eint_type - possible external interrupt types. |
| 66 | * @EINT_TYPE_NONE: bank does not support external interrupts |
| 67 | * @EINT_TYPE_GPIO: bank supportes external gpio interrupts |
| 68 | * @EINT_TYPE_WKUP: bank supportes external wakeup interrupts |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 69 | * @EINT_TYPE_WKUP_MUX: bank supports multiplexed external wakeup interrupts |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 70 | * |
| 71 | * Samsung GPIO controller groups all the available pins into banks. The pins |
| 72 | * in a pin bank can support external gpio interrupts or external wakeup |
| 73 | * interrupts or no interrupts at all. From a software perspective, the only |
| 74 | * difference between external gpio and external wakeup interrupts is that |
| 75 | * the wakeup interrupts can additionally wakeup the system if it is in |
| 76 | * suspended state. |
| 77 | */ |
| 78 | enum eint_type { |
| 79 | EINT_TYPE_NONE, |
| 80 | EINT_TYPE_GPIO, |
| 81 | EINT_TYPE_WKUP, |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 82 | EINT_TYPE_WKUP_MUX, |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /* maximum length of a pin in pin descriptor (example: "gpa0-0") */ |
| 86 | #define PIN_NAME_LENGTH 10 |
| 87 | |
| 88 | #define PIN_GROUP(n, p, f) \ |
| 89 | { \ |
| 90 | .name = n, \ |
| 91 | .pins = p, \ |
| 92 | .num_pins = ARRAY_SIZE(p), \ |
| 93 | .func = f \ |
| 94 | } |
| 95 | |
| 96 | #define PMX_FUNC(n, g) \ |
| 97 | { \ |
| 98 | .name = n, \ |
| 99 | .groups = g, \ |
| 100 | .num_groups = ARRAY_SIZE(g), \ |
| 101 | } |
| 102 | |
| 103 | struct samsung_pinctrl_drv_data; |
| 104 | |
| 105 | /** |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 106 | * struct samsung_pin_bank_type: pin bank type description |
| 107 | * @fld_width: widths of configuration bitfields (0 if unavailable) |
Tomasz Figa | 43fc9e7 | 2013-03-18 22:31:53 +0100 | [diff] [blame] | 108 | * @reg_offset: offsets of configuration registers (don't care of width is 0) |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 109 | */ |
| 110 | struct samsung_pin_bank_type { |
| 111 | u8 fld_width[PINCFG_TYPE_NUM]; |
Tomasz Figa | 43fc9e7 | 2013-03-18 22:31:53 +0100 | [diff] [blame] | 112 | u8 reg_offset[PINCFG_TYPE_NUM]; |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /** |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 116 | * struct samsung_pin_bank: represent a controller pin-bank. |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 117 | * @type: type of the bank (register offsets and bitfield widths) |
Sachin Kamat | 88f2324 | 2012-12-10 09:45:55 +0900 | [diff] [blame] | 118 | * @pctl_offset: starting offset of the pin-bank registers. |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 119 | * @pin_base: starting pin number of the bank. |
| 120 | * @nr_pins: number of pins included in this bank. |
Tomasz Figa | 61dd726 | 2013-03-18 22:31:55 +0100 | [diff] [blame] | 121 | * @eint_func: function to set in CON register to configure pin as EINT. |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 122 | * @eint_type: type of the external interrupt supported by the bank. |
Tomasz Figa | 61dd726 | 2013-03-18 22:31:55 +0100 | [diff] [blame] | 123 | * @eint_mask: bit mask of pins which support EINT function. |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 124 | * @name: name to be prefixed for each pin in this pin bank. |
Tomasz Figa | ab66378 | 2012-10-11 10:11:13 +0200 | [diff] [blame] | 125 | * @of_node: OF node of the bank. |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 126 | * @drvdata: link to controller driver data |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 127 | * @irq_domain: IRQ domain of the bank. |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 128 | * @gpio_chip: GPIO chip of the bank. |
| 129 | * @grange: linux gpio pin range supported by this bank. |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 130 | * @slock: spinlock protecting bank registers |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 131 | * @pm_save: saved register values during suspend |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 132 | */ |
| 133 | struct samsung_pin_bank { |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 134 | struct samsung_pin_bank_type *type; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 135 | u32 pctl_offset; |
| 136 | u32 pin_base; |
| 137 | u8 nr_pins; |
Tomasz Figa | 61dd726 | 2013-03-18 22:31:55 +0100 | [diff] [blame] | 138 | u8 eint_func; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 139 | enum eint_type eint_type; |
Tomasz Figa | 61dd726 | 2013-03-18 22:31:55 +0100 | [diff] [blame] | 140 | u32 eint_mask; |
Tomasz Figa | 1b6056d | 2012-10-11 10:11:15 +0200 | [diff] [blame] | 141 | u32 eint_offset; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 142 | char *name; |
Tomasz Figa | 3385474 | 2013-05-17 18:24:31 +0200 | [diff] [blame] | 143 | void *soc_priv; |
Tomasz Figa | ab66378 | 2012-10-11 10:11:13 +0200 | [diff] [blame] | 144 | struct device_node *of_node; |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 145 | struct samsung_pinctrl_drv_data *drvdata; |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 146 | struct irq_domain *irq_domain; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 147 | struct gpio_chip gpio_chip; |
| 148 | struct pinctrl_gpio_range grange; |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 149 | spinlock_t slock; |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 150 | |
| 151 | u32 pm_save[PINCFG_TYPE_NUM + 1]; /* +1 to handle double CON registers*/ |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | /** |
| 155 | * struct samsung_pin_ctrl: represent a pin controller. |
| 156 | * @pin_banks: list of pin banks included in this controller. |
| 157 | * @nr_banks: number of pin banks. |
| 158 | * @base: starting system wide pin number. |
| 159 | * @nr_pins: number of pins supported by the controller. |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 160 | * @eint_gpio_init: platform specific callback to setup the external gpio |
| 161 | * interrupts for the controller. |
| 162 | * @eint_wkup_init: platform specific callback to setup the external wakeup |
| 163 | * interrupts for the controller. |
| 164 | * @label: for debug information. |
| 165 | */ |
| 166 | struct samsung_pin_ctrl { |
| 167 | struct samsung_pin_bank *pin_banks; |
| 168 | u32 nr_banks; |
| 169 | |
| 170 | u32 base; |
| 171 | u32 nr_pins; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 172 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 173 | int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *); |
| 174 | int (*eint_wkup_init)(struct samsung_pinctrl_drv_data *); |
Tomasz Figa | 21c2199 | 2013-05-17 18:24:30 +0200 | [diff] [blame] | 175 | void (*suspend)(struct samsung_pinctrl_drv_data *); |
| 176 | void (*resume)(struct samsung_pinctrl_drv_data *); |
| 177 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 178 | char *label; |
| 179 | }; |
| 180 | |
| 181 | /** |
| 182 | * struct samsung_pinctrl_drv_data: wrapper for holding driver data together. |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 183 | * @node: global list node |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 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. |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 194 | */ |
| 195 | struct samsung_pinctrl_drv_data { |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 196 | struct list_head node; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 197 | void __iomem *virt_base; |
| 198 | struct device *dev; |
| 199 | int irq; |
| 200 | |
| 201 | struct samsung_pin_ctrl *ctrl; |
| 202 | struct pinctrl_desc pctl; |
| 203 | struct pinctrl_dev *pctl_dev; |
| 204 | |
| 205 | const struct samsung_pin_group *pin_groups; |
| 206 | unsigned int nr_groups; |
| 207 | const struct samsung_pmx_func *pmx_functions; |
| 208 | unsigned int nr_functions; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | /** |
| 212 | * struct samsung_pin_group: represent group of pins of a pinmux function. |
| 213 | * @name: name of the pin group, used to lookup the group. |
| 214 | * @pins: the pins included in this group. |
| 215 | * @num_pins: number of pins included in this group. |
| 216 | * @func: the function number to be programmed when selected. |
| 217 | */ |
| 218 | struct samsung_pin_group { |
| 219 | const char *name; |
| 220 | const unsigned int *pins; |
| 221 | u8 num_pins; |
| 222 | u8 func; |
| 223 | }; |
| 224 | |
| 225 | /** |
| 226 | * struct samsung_pmx_func: represent a pin function. |
| 227 | * @name: name of the pin function, used to lookup the function. |
| 228 | * @groups: one or more names of pin groups that provide this function. |
| 229 | * @num_groups: number of groups included in @groups. |
| 230 | */ |
| 231 | struct samsung_pmx_func { |
| 232 | const char *name; |
| 233 | const char **groups; |
| 234 | u8 num_groups; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 235 | u32 val; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | /* list of all exported SoC specific data */ |
Tomasz Figa | d97f5b9 | 2014-04-14 10:45:47 +0900 | [diff] [blame] | 239 | extern struct samsung_pin_ctrl exynos3250_pin_ctrl[]; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 240 | extern struct samsung_pin_ctrl exynos4210_pin_ctrl[]; |
Tomasz Figa | 6edc794 | 2012-11-07 08:44:59 +0900 | [diff] [blame] | 241 | extern struct samsung_pin_ctrl exynos4x12_pin_ctrl[]; |
Thomas Abraham | f67faf4 | 2012-12-28 10:37:27 -0800 | [diff] [blame] | 242 | extern struct samsung_pin_ctrl exynos5250_pin_ctrl[]; |
Young-Gun Jang | 9a8b607 | 2014-02-05 11:51:28 +0530 | [diff] [blame] | 243 | extern struct samsung_pin_ctrl exynos5260_pin_ctrl[]; |
Leela Krishna Amudala | 983dbeb | 2013-06-19 22:16:26 +0900 | [diff] [blame] | 244 | extern struct samsung_pin_ctrl exynos5420_pin_ctrl[]; |
Tomasz Figa | 61dd726 | 2013-03-18 22:31:55 +0100 | [diff] [blame] | 245 | extern struct samsung_pin_ctrl s3c64xx_pin_ctrl[]; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 246 | extern struct samsung_pin_ctrl s3c2412_pin_ctrl[]; |
| 247 | extern struct samsung_pin_ctrl s3c2416_pin_ctrl[]; |
| 248 | extern struct samsung_pin_ctrl s3c2440_pin_ctrl[]; |
| 249 | extern struct samsung_pin_ctrl s3c2450_pin_ctrl[]; |
Mateusz Krawczuk | 608a26a | 2013-08-27 15:08:10 +0200 | [diff] [blame] | 250 | extern struct samsung_pin_ctrl s5pv210_pin_ctrl[]; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 251 | |
| 252 | #endif /* __PINCTRL_SAMSUNG_H */ |