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