blob: 1c590f7e95dd869b96c1b568c221e32b25c263ab [file] [log] [blame]
Thomas Abraham30574f02012-09-07 06:07:19 +09001/*
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 Figad3a7b9e2012-10-11 10:11:17 +020026#include <linux/gpio.h>
27
Thomas Abraham30574f02012-09-07 06:07:19 +090028/* register offsets within a pin bank */
29#define DAT_REG 0x4
30#define PUD_REG 0x8
31#define DRV_REG 0xC
32#define CONPDN_REG 0x10
33#define PUDPDN_REG 0x14
34
35/* pinmux function number for pin as gpio output line */
36#define FUNC_OUTPUT 0x1
37
38/**
39 * enum pincfg_type - possible pin configuration types supported.
Tomasz Figa499147c2013-03-18 22:31:52 +010040 * @PINCFG_TYPE_FUNC: Function configuration.
41 * @PINCFG_TYPE_DAT: Pin value configuration.
Thomas Abraham30574f02012-09-07 06:07:19 +090042 * @PINCFG_TYPE_PUD: Pull up/down configuration.
43 * @PINCFG_TYPE_DRV: Drive strength configuration.
44 * @PINCFG_TYPE_CON_PDN: Pin function in power down mode.
45 * @PINCFG_TYPE_PUD_PDN: Pull up/down configuration in power down mode.
46 */
47enum pincfg_type {
Tomasz Figa499147c2013-03-18 22:31:52 +010048 PINCFG_TYPE_FUNC,
49 PINCFG_TYPE_DAT,
Thomas Abraham30574f02012-09-07 06:07:19 +090050 PINCFG_TYPE_PUD,
51 PINCFG_TYPE_DRV,
52 PINCFG_TYPE_CON_PDN,
53 PINCFG_TYPE_PUD_PDN,
Tomasz Figa499147c2013-03-18 22:31:52 +010054
55 PINCFG_TYPE_NUM
Thomas Abraham30574f02012-09-07 06:07:19 +090056};
57
58/*
59 * pin configuration (pull up/down and drive strength) type and its value are
60 * packed together into a 16-bits. The upper 8-bits represent the configuration
61 * type and the lower 8-bits hold the value of the configuration type.
62 */
63#define PINCFG_TYPE_MASK 0xFF
64#define PINCFG_VALUE_SHIFT 8
65#define PINCFG_VALUE_MASK (0xFF << PINCFG_VALUE_SHIFT)
66#define PINCFG_PACK(type, value) (((value) << PINCFG_VALUE_SHIFT) | type)
67#define PINCFG_UNPACK_TYPE(cfg) ((cfg) & PINCFG_TYPE_MASK)
68#define PINCFG_UNPACK_VALUE(cfg) (((cfg) & PINCFG_VALUE_MASK) >> \
69 PINCFG_VALUE_SHIFT)
70/**
71 * enum eint_type - possible external interrupt types.
72 * @EINT_TYPE_NONE: bank does not support external interrupts
73 * @EINT_TYPE_GPIO: bank supportes external gpio interrupts
74 * @EINT_TYPE_WKUP: bank supportes external wakeup interrupts
Tomasz Figaa04b07c2012-10-11 10:11:18 +020075 * @EINT_TYPE_WKUP_MUX: bank supports multiplexed external wakeup interrupts
Thomas Abraham30574f02012-09-07 06:07:19 +090076 *
77 * Samsung GPIO controller groups all the available pins into banks. The pins
78 * in a pin bank can support external gpio interrupts or external wakeup
79 * interrupts or no interrupts at all. From a software perspective, the only
80 * difference between external gpio and external wakeup interrupts is that
81 * the wakeup interrupts can additionally wakeup the system if it is in
82 * suspended state.
83 */
84enum eint_type {
85 EINT_TYPE_NONE,
86 EINT_TYPE_GPIO,
87 EINT_TYPE_WKUP,
Tomasz Figaa04b07c2012-10-11 10:11:18 +020088 EINT_TYPE_WKUP_MUX,
Thomas Abraham30574f02012-09-07 06:07:19 +090089};
90
91/* maximum length of a pin in pin descriptor (example: "gpa0-0") */
92#define PIN_NAME_LENGTH 10
93
94#define PIN_GROUP(n, p, f) \
95 { \
96 .name = n, \
97 .pins = p, \
98 .num_pins = ARRAY_SIZE(p), \
99 .func = f \
100 }
101
102#define PMX_FUNC(n, g) \
103 { \
104 .name = n, \
105 .groups = g, \
106 .num_groups = ARRAY_SIZE(g), \
107 }
108
109struct samsung_pinctrl_drv_data;
110
111/**
Tomasz Figa499147c2013-03-18 22:31:52 +0100112 * struct samsung_pin_bank_type: pin bank type description
113 * @fld_width: widths of configuration bitfields (0 if unavailable)
114 */
115struct samsung_pin_bank_type {
116 u8 fld_width[PINCFG_TYPE_NUM];
117};
118
119/**
Thomas Abraham30574f02012-09-07 06:07:19 +0900120 * struct samsung_pin_bank: represent a controller pin-bank.
Tomasz Figa499147c2013-03-18 22:31:52 +0100121 * @type: type of the bank (register offsets and bitfield widths)
Sachin Kamat88f23242012-12-10 09:45:55 +0900122 * @pctl_offset: starting offset of the pin-bank registers.
Thomas Abraham30574f02012-09-07 06:07:19 +0900123 * @pin_base: starting pin number of the bank.
124 * @nr_pins: number of pins included in this bank.
Thomas Abraham30574f02012-09-07 06:07:19 +0900125 * @eint_type: type of the external interrupt supported by the bank.
Thomas Abraham30574f02012-09-07 06:07:19 +0900126 * @name: name to be prefixed for each pin in this pin bank.
Tomasz Figaab663782012-10-11 10:11:13 +0200127 * @of_node: OF node of the bank.
Tomasz Figa6defe9a2012-10-11 10:11:14 +0200128 * @drvdata: link to controller driver data
Tomasz Figa595be722012-10-11 10:11:16 +0200129 * @irq_domain: IRQ domain of the bank.
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200130 * @gpio_chip: GPIO chip of the bank.
131 * @grange: linux gpio pin range supported by this bank.
Tomasz Figa19846952013-03-18 22:31:50 +0100132 * @slock: spinlock protecting bank registers
Thomas Abraham30574f02012-09-07 06:07:19 +0900133 */
134struct samsung_pin_bank {
Tomasz Figa499147c2013-03-18 22:31:52 +0100135 struct samsung_pin_bank_type *type;
Thomas Abraham30574f02012-09-07 06:07:19 +0900136 u32 pctl_offset;
137 u32 pin_base;
138 u8 nr_pins;
Thomas Abraham30574f02012-09-07 06:07:19 +0900139 enum eint_type eint_type;
Tomasz Figa1b6056d2012-10-11 10:11:15 +0200140 u32 eint_offset;
Thomas Abraham30574f02012-09-07 06:07:19 +0900141 char *name;
Tomasz Figaab663782012-10-11 10:11:13 +0200142 struct device_node *of_node;
Tomasz Figa6defe9a2012-10-11 10:11:14 +0200143 struct samsung_pinctrl_drv_data *drvdata;
Tomasz Figa595be722012-10-11 10:11:16 +0200144 struct irq_domain *irq_domain;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200145 struct gpio_chip gpio_chip;
146 struct pinctrl_gpio_range grange;
Tomasz Figa19846952013-03-18 22:31:50 +0100147 spinlock_t slock;
Thomas Abraham30574f02012-09-07 06:07:19 +0900148};
149
150/**
151 * struct samsung_pin_ctrl: represent a pin controller.
152 * @pin_banks: list of pin banks included in this controller.
153 * @nr_banks: number of pin banks.
154 * @base: starting system wide pin number.
155 * @nr_pins: number of pins supported by the controller.
Thomas Abraham30574f02012-09-07 06:07:19 +0900156 * @geint_con: offset of the ext-gpio controller registers.
157 * @geint_mask: offset of the ext-gpio interrupt mask registers.
158 * @geint_pend: offset of the ext-gpio interrupt pending registers.
159 * @weint_con: offset of the ext-wakeup controller registers.
160 * @weint_mask: offset of the ext-wakeup interrupt mask registers.
161 * @weint_pend: offset of the ext-wakeup interrupt pending registers.
162 * @svc: offset of the interrupt service register.
163 * @eint_gpio_init: platform specific callback to setup the external gpio
164 * interrupts for the controller.
165 * @eint_wkup_init: platform specific callback to setup the external wakeup
166 * interrupts for the controller.
167 * @label: for debug information.
168 */
169struct samsung_pin_ctrl {
170 struct samsung_pin_bank *pin_banks;
171 u32 nr_banks;
172
173 u32 base;
174 u32 nr_pins;
Thomas Abraham30574f02012-09-07 06:07:19 +0900175
176 u32 geint_con;
177 u32 geint_mask;
178 u32 geint_pend;
179
180 u32 weint_con;
181 u32 weint_mask;
182 u32 weint_pend;
183
184 u32 svc;
185
186 int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *);
187 int (*eint_wkup_init)(struct samsung_pinctrl_drv_data *);
188 char *label;
189};
190
191/**
192 * struct samsung_pinctrl_drv_data: wrapper for holding driver data together.
193 * @virt_base: register base address of the controller.
194 * @dev: device instance representing the controller.
195 * @irq: interrpt number used by the controller to notify gpio interrupts.
196 * @ctrl: pin controller instance managed by the driver.
197 * @pctl: pin controller descriptor registered with the pinctrl subsystem.
198 * @pctl_dev: cookie representing pinctrl device instance.
199 * @pin_groups: list of pin groups available to the driver.
200 * @nr_groups: number of such pin groups.
201 * @pmx_functions: list of pin functions available to the driver.
202 * @nr_function: number of such pin functions.
Thomas Abraham30574f02012-09-07 06:07:19 +0900203 */
204struct samsung_pinctrl_drv_data {
205 void __iomem *virt_base;
206 struct device *dev;
207 int irq;
208
209 struct samsung_pin_ctrl *ctrl;
210 struct pinctrl_desc pctl;
211 struct pinctrl_dev *pctl_dev;
212
213 const struct samsung_pin_group *pin_groups;
214 unsigned int nr_groups;
215 const struct samsung_pmx_func *pmx_functions;
216 unsigned int nr_functions;
Thomas Abraham30574f02012-09-07 06:07:19 +0900217};
218
219/**
220 * struct samsung_pin_group: represent group of pins of a pinmux function.
221 * @name: name of the pin group, used to lookup the group.
222 * @pins: the pins included in this group.
223 * @num_pins: number of pins included in this group.
224 * @func: the function number to be programmed when selected.
225 */
226struct samsung_pin_group {
227 const char *name;
228 const unsigned int *pins;
229 u8 num_pins;
230 u8 func;
231};
232
233/**
234 * struct samsung_pmx_func: represent a pin function.
235 * @name: name of the pin function, used to lookup the function.
236 * @groups: one or more names of pin groups that provide this function.
237 * @num_groups: number of groups included in @groups.
238 */
239struct samsung_pmx_func {
240 const char *name;
241 const char **groups;
242 u8 num_groups;
243};
244
245/* list of all exported SoC specific data */
246extern struct samsung_pin_ctrl exynos4210_pin_ctrl[];
Tomasz Figa6edc7942012-11-07 08:44:59 +0900247extern struct samsung_pin_ctrl exynos4x12_pin_ctrl[];
Thomas Abraham30574f02012-09-07 06:07:19 +0900248
249#endif /* __PINCTRL_SAMSUNG_H */