xref: /openbmc/linux/arch/arm/mach-s3c/gpio-cfg.h (revision 0d297df0)
1c6ff132dSArnd Bergmann /* SPDX-License-Identifier: GPL-2.0 */
2c6ff132dSArnd Bergmann /*
3c6ff132dSArnd Bergmann  * Copyright 2008 Openmoko, Inc.
4c6ff132dSArnd Bergmann  * Copyright 2008 Simtec Electronics
5c6ff132dSArnd Bergmann  *	http://armlinux.simtec.co.uk/
6c6ff132dSArnd Bergmann  *	Ben Dooks <ben@simtec.co.uk>
7c6ff132dSArnd Bergmann  *
8c6ff132dSArnd Bergmann  * S3C Platform - GPIO pin configuration
9c6ff132dSArnd Bergmann  */
10c6ff132dSArnd Bergmann 
11c6ff132dSArnd Bergmann /* This file contains the necessary definitions to get the basic gpio
12c6ff132dSArnd Bergmann  * pin configuration done such as setting a pin to input or output or
13c6ff132dSArnd Bergmann  * changing the pull-{up,down} configurations.
14c6ff132dSArnd Bergmann  */
15c6ff132dSArnd Bergmann 
16c6ff132dSArnd Bergmann /* Note, this interface is being added to the s3c64xx arch first and will
17c6ff132dSArnd Bergmann  * be added to the s3c24xx systems later.
18c6ff132dSArnd Bergmann  */
19c6ff132dSArnd Bergmann 
20c6ff132dSArnd Bergmann #ifndef __PLAT_GPIO_CFG_H
21c6ff132dSArnd Bergmann #define __PLAT_GPIO_CFG_H __FILE__
22c6ff132dSArnd Bergmann 
23c6ff132dSArnd Bergmann #include <linux/types.h>
24c6ff132dSArnd Bergmann 
25c6ff132dSArnd Bergmann typedef unsigned int __bitwise samsung_gpio_pull_t;
26c6ff132dSArnd Bergmann 
27c6ff132dSArnd Bergmann /* forward declaration if gpio-core.h hasn't been included */
28c6ff132dSArnd Bergmann struct samsung_gpio_chip;
29c6ff132dSArnd Bergmann 
30c6ff132dSArnd Bergmann /**
31c6ff132dSArnd Bergmann  * struct samsung_gpio_cfg GPIO configuration
32c6ff132dSArnd Bergmann  * @cfg_eint: Configuration setting when used for external interrupt source
33c6ff132dSArnd Bergmann  * @get_pull: Read the current pull configuration for the GPIO
34c6ff132dSArnd Bergmann  * @set_pull: Set the current pull configuration for the GPIO
35c6ff132dSArnd Bergmann  * @set_config: Set the current configuration for the GPIO
36c6ff132dSArnd Bergmann  * @get_config: Read the current configuration for the GPIO
37c6ff132dSArnd Bergmann  *
38c6ff132dSArnd Bergmann  * Each chip can have more than one type of GPIO bank available and some
39c6ff132dSArnd Bergmann  * have different capabilites even when they have the same control register
40c6ff132dSArnd Bergmann  * layouts. Provide an point to vector control routine and provide any
41c6ff132dSArnd Bergmann  * per-bank configuration information that other systems such as the
42c6ff132dSArnd Bergmann  * external interrupt code will need.
43c6ff132dSArnd Bergmann  *
44c6ff132dSArnd Bergmann  * @sa samsung_gpio_cfgpin
45c6ff132dSArnd Bergmann  * @sa s3c_gpio_getcfg
46c6ff132dSArnd Bergmann  * @sa s3c_gpio_setpull
47c6ff132dSArnd Bergmann  * @sa s3c_gpio_getpull
48c6ff132dSArnd Bergmann  */
49c6ff132dSArnd Bergmann struct samsung_gpio_cfg {
50c6ff132dSArnd Bergmann 	unsigned int	cfg_eint;
51c6ff132dSArnd Bergmann 
52c6ff132dSArnd Bergmann 	samsung_gpio_pull_t	(*get_pull)(struct samsung_gpio_chip *chip, unsigned offs);
53c6ff132dSArnd Bergmann 	int		(*set_pull)(struct samsung_gpio_chip *chip, unsigned offs,
54c6ff132dSArnd Bergmann 				    samsung_gpio_pull_t pull);
55c6ff132dSArnd Bergmann 
56c6ff132dSArnd Bergmann 	unsigned (*get_config)(struct samsung_gpio_chip *chip, unsigned offs);
57c6ff132dSArnd Bergmann 	int	 (*set_config)(struct samsung_gpio_chip *chip, unsigned offs,
58c6ff132dSArnd Bergmann 			       unsigned config);
59c6ff132dSArnd Bergmann };
60c6ff132dSArnd Bergmann 
61c6ff132dSArnd Bergmann #define S3C_GPIO_SPECIAL_MARK	(0xfffffff0)
62c6ff132dSArnd Bergmann #define S3C_GPIO_SPECIAL(x)	(S3C_GPIO_SPECIAL_MARK | (x))
63c6ff132dSArnd Bergmann 
64c6ff132dSArnd Bergmann /* Defines for generic pin configurations */
65c6ff132dSArnd Bergmann #define S3C_GPIO_INPUT	(S3C_GPIO_SPECIAL(0))
66c6ff132dSArnd Bergmann #define S3C_GPIO_OUTPUT	(S3C_GPIO_SPECIAL(1))
67c6ff132dSArnd Bergmann #define S3C_GPIO_SFN(x)	(S3C_GPIO_SPECIAL(x))
68c6ff132dSArnd Bergmann 
69c6ff132dSArnd Bergmann #define samsung_gpio_is_cfg_special(_cfg) \
70c6ff132dSArnd Bergmann 	(((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)
71c6ff132dSArnd Bergmann 
72c6ff132dSArnd Bergmann /**
73c6ff132dSArnd Bergmann  * s3c_gpio_cfgpin() - Change the GPIO function of a pin.
74c6ff132dSArnd Bergmann  * @pin pin The pin number to configure.
75c6ff132dSArnd Bergmann  * @to to The configuration for the pin's function.
76c6ff132dSArnd Bergmann  *
77c6ff132dSArnd Bergmann  * Configure which function is actually connected to the external
78c6ff132dSArnd Bergmann  * pin, such as an gpio input, output or some form of special function
79c6ff132dSArnd Bergmann  * connected to an internal peripheral block.
80c6ff132dSArnd Bergmann  *
81c6ff132dSArnd Bergmann  * The @to parameter can be one of the generic S3C_GPIO_INPUT, S3C_GPIO_OUTPUT
82c6ff132dSArnd Bergmann  * or S3C_GPIO_SFN() to indicate one of the possible values that the helper
83c6ff132dSArnd Bergmann  * will then generate the correct bit mask and shift for the configuration.
84c6ff132dSArnd Bergmann  *
85c6ff132dSArnd Bergmann  * If a bank of GPIOs all needs to be set to special-function 2, then
86c6ff132dSArnd Bergmann  * the following code will work:
87c6ff132dSArnd Bergmann  *
88c6ff132dSArnd Bergmann  *	for (gpio = start; gpio < end; gpio++)
89c6ff132dSArnd Bergmann  *		s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
90c6ff132dSArnd Bergmann  *
91c6ff132dSArnd Bergmann  * The @to parameter can also be a specific value already shifted to the
92c6ff132dSArnd Bergmann  * correct position in the control register, although these are discouraged
93c6ff132dSArnd Bergmann  * in newer kernels and are only being kept for compatibility.
94c6ff132dSArnd Bergmann  */
95c6ff132dSArnd Bergmann extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
96c6ff132dSArnd Bergmann 
97c6ff132dSArnd Bergmann /**
98c6ff132dSArnd Bergmann  * s3c_gpio_cfgpin_range() - Change the GPIO function for configuring pin range
99c6ff132dSArnd Bergmann  * @start: The pin number to start at
100c6ff132dSArnd Bergmann  * @nr: The number of pins to configure from @start.
101c6ff132dSArnd Bergmann  * @cfg: The configuration for the pin's function
102c6ff132dSArnd Bergmann  *
103c6ff132dSArnd Bergmann  * Call s3c_gpio_cfgpin() for the @nr pins starting at @start.
104c6ff132dSArnd Bergmann  *
105c6ff132dSArnd Bergmann  * @sa s3c_gpio_cfgpin.
106c6ff132dSArnd Bergmann  */
107c6ff132dSArnd Bergmann extern int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
108c6ff132dSArnd Bergmann 				 unsigned int cfg);
109c6ff132dSArnd Bergmann 
110c6ff132dSArnd Bergmann /* Define values for the pull-{up,down} available for each gpio pin.
111c6ff132dSArnd Bergmann  *
112c6ff132dSArnd Bergmann  * These values control the state of the weak pull-{up,down} resistors
113c6ff132dSArnd Bergmann  * available on most pins on the S3C series. Not all chips support both
114c6ff132dSArnd Bergmann  * up or down settings, and it may be dependent on the chip that is being
115c6ff132dSArnd Bergmann  * used to whether the particular mode is available.
116c6ff132dSArnd Bergmann  */
117c6ff132dSArnd Bergmann #define S3C_GPIO_PULL_NONE	((__force samsung_gpio_pull_t)0x00)
118c6ff132dSArnd Bergmann #define S3C_GPIO_PULL_DOWN	((__force samsung_gpio_pull_t)0x01)
119c6ff132dSArnd Bergmann #define S3C_GPIO_PULL_UP	((__force samsung_gpio_pull_t)0x02)
120c6ff132dSArnd Bergmann 
121c6ff132dSArnd Bergmann /**
122c6ff132dSArnd Bergmann  * s3c_gpio_setpull() - set the state of a gpio pin pull resistor
123c6ff132dSArnd Bergmann  * @pin: The pin number to configure the pull resistor.
124c6ff132dSArnd Bergmann  * @pull: The configuration for the pull resistor.
125c6ff132dSArnd Bergmann  *
126c6ff132dSArnd Bergmann  * This function sets the state of the pull-{up,down} resistor for the
127c6ff132dSArnd Bergmann  * specified pin. It will return 0 if successful, or a negative error
128c6ff132dSArnd Bergmann  * code if the pin cannot support the requested pull setting.
129c6ff132dSArnd Bergmann  *
130c6ff132dSArnd Bergmann  * @pull is one of S3C_GPIO_PULL_NONE, S3C_GPIO_PULL_DOWN or S3C_GPIO_PULL_UP.
131c6ff132dSArnd Bergmann */
132c6ff132dSArnd Bergmann extern int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull);
133c6ff132dSArnd Bergmann 
134c6ff132dSArnd Bergmann /* configure `all` aspects of an gpio */
135c6ff132dSArnd Bergmann 
136c6ff132dSArnd Bergmann /**
137c6ff132dSArnd Bergmann  * s3c_gpio_cfgall_range() - configure range of gpio functtion and pull.
138c6ff132dSArnd Bergmann  * @start: The gpio number to start at.
139c6ff132dSArnd Bergmann  * @nr: The number of gpio to configure from @start.
140c6ff132dSArnd Bergmann  * @cfg: The configuration to use
141c6ff132dSArnd Bergmann  * @pull: The pull setting to use.
142c6ff132dSArnd Bergmann  *
143c6ff132dSArnd Bergmann  * Run s3c_gpio_cfgpin() and s3c_gpio_setpull() over the gpio range starting
144c6ff132dSArnd Bergmann  * @gpio and running for @size.
145c6ff132dSArnd Bergmann  *
146c6ff132dSArnd Bergmann  * @sa s3c_gpio_cfgpin
147c6ff132dSArnd Bergmann  * @sa s3c_gpio_setpull
148c6ff132dSArnd Bergmann  * @sa s3c_gpio_cfgpin_range
149c6ff132dSArnd Bergmann  */
150c6ff132dSArnd Bergmann extern int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
151c6ff132dSArnd Bergmann 				 unsigned int cfg, samsung_gpio_pull_t pull);
152c6ff132dSArnd Bergmann 
s3c_gpio_cfgrange_nopull(unsigned int pin,unsigned int size,unsigned int cfg)153c6ff132dSArnd Bergmann static inline int s3c_gpio_cfgrange_nopull(unsigned int pin, unsigned int size,
154c6ff132dSArnd Bergmann 					   unsigned int cfg)
155c6ff132dSArnd Bergmann {
156c6ff132dSArnd Bergmann 	return s3c_gpio_cfgall_range(pin, size, cfg, S3C_GPIO_PULL_NONE);
157c6ff132dSArnd Bergmann }
158c6ff132dSArnd Bergmann 
159c6ff132dSArnd Bergmann #endif /* __PLAT_GPIO_CFG_H */
160