blob: b9dbe7949fab1bc81530d90943b9eb59540103b9 [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.
40 * @PINCFG_TYPE_PUD: Pull up/down configuration.
41 * @PINCFG_TYPE_DRV: Drive strength configuration.
42 * @PINCFG_TYPE_CON_PDN: Pin function in power down mode.
43 * @PINCFG_TYPE_PUD_PDN: Pull up/down configuration in power down mode.
44 */
45enum pincfg_type {
46 PINCFG_TYPE_PUD,
47 PINCFG_TYPE_DRV,
48 PINCFG_TYPE_CON_PDN,
49 PINCFG_TYPE_PUD_PDN,
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 Figaa04b07c2012-10-11 10:11:18 +020069 * @EINT_TYPE_WKUP_MUX: bank supports multiplexed external wakeup interrupts
Thomas Abraham30574f02012-09-07 06:07:19 +090070 *
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 */
78enum eint_type {
79 EINT_TYPE_NONE,
80 EINT_TYPE_GPIO,
81 EINT_TYPE_WKUP,
Tomasz Figaa04b07c2012-10-11 10:11:18 +020082 EINT_TYPE_WKUP_MUX,
Thomas Abraham30574f02012-09-07 06:07:19 +090083};
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
103struct samsung_pinctrl_drv_data;
104
105/**
106 * struct samsung_pin_bank: represent a controller pin-bank.
Sachin Kamat88f23242012-12-10 09:45:55 +0900107 * @pctl_offset: starting offset of the pin-bank registers.
Thomas Abraham30574f02012-09-07 06:07:19 +0900108 * @pin_base: starting pin number of the bank.
109 * @nr_pins: number of pins included in this bank.
110 * @func_width: width of the function selector bit field.
111 * @pud_width: width of the pin pull up/down selector bit field.
112 * @drv_width: width of the pin driver strength selector bit field.
113 * @conpdn_width: width of the sleep mode function selector bin field.
114 * @pudpdn_width: width of the sleep mode pull up/down selector bit field.
115 * @eint_type: type of the external interrupt supported by the bank.
Thomas Abraham30574f02012-09-07 06:07:19 +0900116 * @name: name to be prefixed for each pin in this pin bank.
Tomasz Figaab663782012-10-11 10:11:13 +0200117 * @of_node: OF node of the bank.
Tomasz Figa6defe9a2012-10-11 10:11:14 +0200118 * @drvdata: link to controller driver data
Tomasz Figa595be722012-10-11 10:11:16 +0200119 * @irq_domain: IRQ domain of the bank.
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200120 * @gpio_chip: GPIO chip of the bank.
121 * @grange: linux gpio pin range supported by this bank.
Tomasz Figa19846952013-03-18 22:31:50 +0100122 * @slock: spinlock protecting bank registers
Thomas Abraham30574f02012-09-07 06:07:19 +0900123 */
124struct samsung_pin_bank {
125 u32 pctl_offset;
126 u32 pin_base;
127 u8 nr_pins;
128 u8 func_width;
129 u8 pud_width;
130 u8 drv_width;
131 u8 conpdn_width;
132 u8 pudpdn_width;
133 enum eint_type eint_type;
Tomasz Figa1b6056d2012-10-11 10:11:15 +0200134 u32 eint_offset;
Thomas Abraham30574f02012-09-07 06:07:19 +0900135 char *name;
Tomasz Figaab663782012-10-11 10:11:13 +0200136 struct device_node *of_node;
Tomasz Figa6defe9a2012-10-11 10:11:14 +0200137 struct samsung_pinctrl_drv_data *drvdata;
Tomasz Figa595be722012-10-11 10:11:16 +0200138 struct irq_domain *irq_domain;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200139 struct gpio_chip gpio_chip;
140 struct pinctrl_gpio_range grange;
Tomasz Figa19846952013-03-18 22:31:50 +0100141 spinlock_t slock;
Thomas Abraham30574f02012-09-07 06:07:19 +0900142};
143
144/**
145 * struct samsung_pin_ctrl: represent a pin controller.
146 * @pin_banks: list of pin banks included in this controller.
147 * @nr_banks: number of pin banks.
148 * @base: starting system wide pin number.
149 * @nr_pins: number of pins supported by the controller.
Thomas Abraham30574f02012-09-07 06:07:19 +0900150 * @geint_con: offset of the ext-gpio controller registers.
151 * @geint_mask: offset of the ext-gpio interrupt mask registers.
152 * @geint_pend: offset of the ext-gpio interrupt pending registers.
153 * @weint_con: offset of the ext-wakeup controller registers.
154 * @weint_mask: offset of the ext-wakeup interrupt mask registers.
155 * @weint_pend: offset of the ext-wakeup interrupt pending registers.
156 * @svc: offset of the interrupt service register.
157 * @eint_gpio_init: platform specific callback to setup the external gpio
158 * interrupts for the controller.
159 * @eint_wkup_init: platform specific callback to setup the external wakeup
160 * interrupts for the controller.
161 * @label: for debug information.
162 */
163struct samsung_pin_ctrl {
164 struct samsung_pin_bank *pin_banks;
165 u32 nr_banks;
166
167 u32 base;
168 u32 nr_pins;
Thomas Abraham30574f02012-09-07 06:07:19 +0900169
170 u32 geint_con;
171 u32 geint_mask;
172 u32 geint_pend;
173
174 u32 weint_con;
175 u32 weint_mask;
176 u32 weint_pend;
177
178 u32 svc;
179
180 int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *);
181 int (*eint_wkup_init)(struct samsung_pinctrl_drv_data *);
182 char *label;
183};
184
185/**
186 * struct samsung_pinctrl_drv_data: wrapper for holding driver data together.
187 * @virt_base: register base address of the controller.
188 * @dev: device instance representing the controller.
189 * @irq: interrpt number used by the controller to notify gpio interrupts.
190 * @ctrl: pin controller instance managed by the driver.
191 * @pctl: pin controller descriptor registered with the pinctrl subsystem.
192 * @pctl_dev: cookie representing pinctrl device instance.
193 * @pin_groups: list of pin groups available to the driver.
194 * @nr_groups: number of such pin groups.
195 * @pmx_functions: list of pin functions available to the driver.
196 * @nr_function: number of such pin functions.
Thomas Abraham30574f02012-09-07 06:07:19 +0900197 */
198struct samsung_pinctrl_drv_data {
199 void __iomem *virt_base;
200 struct device *dev;
201 int irq;
202
203 struct samsung_pin_ctrl *ctrl;
204 struct pinctrl_desc pctl;
205 struct pinctrl_dev *pctl_dev;
206
207 const struct samsung_pin_group *pin_groups;
208 unsigned int nr_groups;
209 const struct samsung_pmx_func *pmx_functions;
210 unsigned int nr_functions;
Thomas Abraham30574f02012-09-07 06:07:19 +0900211};
212
213/**
214 * struct samsung_pin_group: represent group of pins of a pinmux function.
215 * @name: name of the pin group, used to lookup the group.
216 * @pins: the pins included in this group.
217 * @num_pins: number of pins included in this group.
218 * @func: the function number to be programmed when selected.
219 */
220struct samsung_pin_group {
221 const char *name;
222 const unsigned int *pins;
223 u8 num_pins;
224 u8 func;
225};
226
227/**
228 * struct samsung_pmx_func: represent a pin function.
229 * @name: name of the pin function, used to lookup the function.
230 * @groups: one or more names of pin groups that provide this function.
231 * @num_groups: number of groups included in @groups.
232 */
233struct samsung_pmx_func {
234 const char *name;
235 const char **groups;
236 u8 num_groups;
237};
238
239/* list of all exported SoC specific data */
240extern struct samsung_pin_ctrl exynos4210_pin_ctrl[];
Tomasz Figa6edc7942012-11-07 08:44:59 +0900241extern struct samsung_pin_ctrl exynos4x12_pin_ctrl[];
Thomas Abraham30574f02012-09-07 06:07:19 +0900242
243#endif /* __PINCTRL_SAMSUNG_H */