blob: 21391faab068b5eb6bc027af7874f1e0defd8471 [file] [log] [blame]
Ben Dooks21b23662008-10-31 16:14:34 +00001/* linux/arch/arm/plat-s3c/include/plat/gpio-cfg.h
2 *
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * http://armlinux.simtec.co.uk/
6 * Ben Dooks <ben@simtec.co.uk>
7 *
8 * S3C Platform - GPIO pin configuration
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15/* This file contains the necessary definitions to get the basic gpio
16 * pin configuration done such as setting a pin to input or output or
17 * changing the pull-{up,down} configurations.
18 */
19
20/* Note, this interface is being added to the s3c64xx arch first and will
21 * be added to the s3c24xx systems later.
22 */
23
24#ifndef __PLAT_GPIO_CFG_H
25#define __PLAT_GPIO_CFG_H __FILE__
26
Paul Bolle6ac7d112012-06-06 14:17:46 +020027#include <linux/types.h>
Axel Lindc2c8352011-11-17 01:17:18 +090028
Kukjin Kim782d8a32011-08-30 20:47:32 +090029typedef unsigned int __bitwise__ samsung_gpio_pull_t;
Ben Dooks21b23662008-10-31 16:14:34 +000030
31/* forward declaration if gpio-core.h hasn't been included */
Kukjin Kim782d8a32011-08-30 20:47:32 +090032struct samsung_gpio_chip;
Ben Dooks21b23662008-10-31 16:14:34 +000033
34/**
Kukjin Kim782d8a32011-08-30 20:47:32 +090035 * struct samsung_gpio_cfg GPIO configuration
Ben Dooks21b23662008-10-31 16:14:34 +000036 * @cfg_eint: Configuration setting when used for external interrupt source
37 * @get_pull: Read the current pull configuration for the GPIO
Andrea Gelmini40b07542016-05-21 13:51:23 +020038 * @set_pull: Set the current pull configuration for the GPIO
Ben Dooks21b23662008-10-31 16:14:34 +000039 * @set_config: Set the current configuration for the GPIO
40 * @get_config: Read the current configuration for the GPIO
41 *
42 * Each chip can have more than one type of GPIO bank available and some
43 * have different capabilites even when they have the same control register
44 * layouts. Provide an point to vector control routine and provide any
45 * per-bank configuration information that other systems such as the
46 * external interrupt code will need.
Ben Dooks189e0442010-05-24 12:21:40 +090047 *
Kukjin Kim782d8a32011-08-30 20:47:32 +090048 * @sa samsung_gpio_cfgpin
Ben Dooks189e0442010-05-24 12:21:40 +090049 * @sa s3c_gpio_getcfg
50 * @sa s3c_gpio_setpull
51 * @sa s3c_gpio_getpull
Ben Dooks21b23662008-10-31 16:14:34 +000052 */
Kukjin Kim782d8a32011-08-30 20:47:32 +090053struct samsung_gpio_cfg {
Ben Dooks21b23662008-10-31 16:14:34 +000054 unsigned int cfg_eint;
55
Kukjin Kim782d8a32011-08-30 20:47:32 +090056 samsung_gpio_pull_t (*get_pull)(struct samsung_gpio_chip *chip, unsigned offs);
57 int (*set_pull)(struct samsung_gpio_chip *chip, unsigned offs,
58 samsung_gpio_pull_t pull);
Ben Dooks21b23662008-10-31 16:14:34 +000059
Kukjin Kim782d8a32011-08-30 20:47:32 +090060 unsigned (*get_config)(struct samsung_gpio_chip *chip, unsigned offs);
61 int (*set_config)(struct samsung_gpio_chip *chip, unsigned offs,
Ben Dooks21b23662008-10-31 16:14:34 +000062 unsigned config);
63};
64
65#define S3C_GPIO_SPECIAL_MARK (0xfffffff0)
66#define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))
67
68/* Defines for generic pin configurations */
69#define S3C_GPIO_INPUT (S3C_GPIO_SPECIAL(0))
70#define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))
71#define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))
72
Kukjin Kim782d8a32011-08-30 20:47:32 +090073#define samsung_gpio_is_cfg_special(_cfg) \
Ben Dooks21b23662008-10-31 16:14:34 +000074 (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)
75
76/**
77 * s3c_gpio_cfgpin() - Change the GPIO function of a pin.
78 * @pin pin The pin number to configure.
Ben Dooks94143922010-05-24 12:11:43 +090079 * @to to The configuration for the pin's function.
Ben Dooks21b23662008-10-31 16:14:34 +000080 *
81 * Configure which function is actually connected to the external
82 * pin, such as an gpio input, output or some form of special function
83 * connected to an internal peripheral block.
Ben Dooks189e0442010-05-24 12:21:40 +090084 *
85 * The @to parameter can be one of the generic S3C_GPIO_INPUT, S3C_GPIO_OUTPUT
86 * or S3C_GPIO_SFN() to indicate one of the possible values that the helper
87 * will then generate the correct bit mask and shift for the configuration.
88 *
89 * If a bank of GPIOs all needs to be set to special-function 2, then
90 * the following code will work:
91 *
92 * for (gpio = start; gpio < end; gpio++)
93 * s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
94 *
95 * The @to parameter can also be a specific value already shifted to the
96 * correct position in the control register, although these are discouraged
97 * in newer kernels and are only being kept for compatibility.
Ben Dooks21b23662008-10-31 16:14:34 +000098 */
99extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
100
Ben Dooks99338472010-05-06 10:50:42 +0900101/**
102 * s3c_gpio_getcfg - Read the current function for a GPIO pin
103 * @pin: The pin to read the configuration value for.
104 *
105 * Read the configuration state of the given @pin, returning a value that
106 * could be passed back to s3c_gpio_cfgpin().
107 *
108 * @sa s3c_gpio_cfgpin
109 */
110extern unsigned s3c_gpio_getcfg(unsigned int pin);
111
Ben Dooks4b46fbb2010-10-01 13:37:13 +0900112/**
113 * s3c_gpio_cfgpin_range() - Change the GPIO function for configuring pin range
114 * @start: The pin number to start at
115 * @nr: The number of pins to configure from @start.
116 * @cfg: The configuration for the pin's function
117 *
118 * Call s3c_gpio_cfgpin() for the @nr pins starting at @start.
119 *
120 * @sa s3c_gpio_cfgpin.
121 */
122extern int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
123 unsigned int cfg);
124
Ben Dooks21b23662008-10-31 16:14:34 +0000125/* Define values for the pull-{up,down} available for each gpio pin.
126 *
127 * These values control the state of the weak pull-{up,down} resistors
128 * available on most pins on the S3C series. Not all chips support both
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300129 * up or down settings, and it may be dependent on the chip that is being
Ben Dooks21b23662008-10-31 16:14:34 +0000130 * used to whether the particular mode is available.
131 */
Kukjin Kim782d8a32011-08-30 20:47:32 +0900132#define S3C_GPIO_PULL_NONE ((__force samsung_gpio_pull_t)0x00)
133#define S3C_GPIO_PULL_DOWN ((__force samsung_gpio_pull_t)0x01)
134#define S3C_GPIO_PULL_UP ((__force samsung_gpio_pull_t)0x02)
Ben Dooks21b23662008-10-31 16:14:34 +0000135
136/**
137 * s3c_gpio_setpull() - set the state of a gpio pin pull resistor
138 * @pin: The pin number to configure the pull resistor.
139 * @pull: The configuration for the pull resistor.
140 *
141 * This function sets the state of the pull-{up,down} resistor for the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300142 * specified pin. It will return 0 if successful, or a negative error
Ben Dooks21b23662008-10-31 16:14:34 +0000143 * code if the pin cannot support the requested pull setting.
Ben Dooks189e0442010-05-24 12:21:40 +0900144 *
145 * @pull is one of S3C_GPIO_PULL_NONE, S3C_GPIO_PULL_DOWN or S3C_GPIO_PULL_UP.
Ben Dooks21b23662008-10-31 16:14:34 +0000146*/
Kukjin Kim782d8a32011-08-30 20:47:32 +0900147extern int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull);
Ben Dooks21b23662008-10-31 16:14:34 +0000148
149/**
150 * s3c_gpio_getpull() - get the pull resistor state of a gpio pin
151 * @pin: The pin number to get the settings for
152 *
153 * Read the pull resistor value for the specified pin.
154*/
Kukjin Kim782d8a32011-08-30 20:47:32 +0900155extern samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin);
Ben Dooks21b23662008-10-31 16:14:34 +0000156
Ben Dooks54591482010-10-01 16:34:34 +0900157/* configure `all` aspects of an gpio */
158
159/**
160 * s3c_gpio_cfgall_range() - configure range of gpio functtion and pull.
161 * @start: The gpio number to start at.
162 * @nr: The number of gpio to configure from @start.
163 * @cfg: The configuration to use
164 * @pull: The pull setting to use.
165 *
166 * Run s3c_gpio_cfgpin() and s3c_gpio_setpull() over the gpio range starting
167 * @gpio and running for @size.
168 *
169 * @sa s3c_gpio_cfgpin
170 * @sa s3c_gpio_setpull
171 * @sa s3c_gpio_cfgpin_range
172 */
173extern int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
Kukjin Kim782d8a32011-08-30 20:47:32 +0900174 unsigned int cfg, samsung_gpio_pull_t pull);
Ben Dooks54591482010-10-01 16:34:34 +0900175
Ben Dookse594ea32010-10-01 19:07:28 +0900176static inline int s3c_gpio_cfgrange_nopull(unsigned int pin, unsigned int size,
177 unsigned int cfg)
178{
179 return s3c_gpio_cfgall_range(pin, size, cfg, S3C_GPIO_PULL_NONE);
180}
181
Ben Dooks21b23662008-10-31 16:14:34 +0000182#endif /* __PLAT_GPIO_CFG_H */