Krzysztof Kozlowski | 4490e3c | 2017-12-25 20:54:35 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 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 |
Krzysztof Kozlowski | 4490e3c | 2017-12-25 20:54:35 +0100 | [diff] [blame] | 9 | */ |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 10 | |
| 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. |
| 14 | */ |
| 15 | |
| 16 | /* Note, this interface is being added to the s3c64xx arch first and will |
| 17 | * be added to the s3c24xx systems later. |
| 18 | */ |
| 19 | |
| 20 | #ifndef __PLAT_GPIO_CFG_H |
| 21 | #define __PLAT_GPIO_CFG_H __FILE__ |
| 22 | |
Paul Bolle | 6ac7d11 | 2012-06-06 14:17:46 +0200 | [diff] [blame] | 23 | #include <linux/types.h> |
Axel Lin | dc2c835 | 2011-11-17 01:17:18 +0900 | [diff] [blame] | 24 | |
Michael S. Tsirkin | 9efecca | 2016-12-11 06:34:53 +0200 | [diff] [blame] | 25 | typedef unsigned int __bitwise samsung_gpio_pull_t; |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 26 | |
| 27 | /* forward declaration if gpio-core.h hasn't been included */ |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 28 | struct samsung_gpio_chip; |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 29 | |
| 30 | /** |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 31 | * struct samsung_gpio_cfg GPIO configuration |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 32 | * @cfg_eint: Configuration setting when used for external interrupt source |
| 33 | * @get_pull: Read the current pull configuration for the GPIO |
Andrea Gelmini | 40b0754 | 2016-05-21 13:51:23 +0200 | [diff] [blame] | 34 | * @set_pull: Set the current pull configuration for the GPIO |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 35 | * @set_config: Set the current configuration for the GPIO |
| 36 | * @get_config: Read the current configuration for the GPIO |
| 37 | * |
| 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. |
Ben Dooks | 189e044 | 2010-05-24 12:21:40 +0900 | [diff] [blame] | 43 | * |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 44 | * @sa samsung_gpio_cfgpin |
Ben Dooks | 189e044 | 2010-05-24 12:21:40 +0900 | [diff] [blame] | 45 | * @sa s3c_gpio_getcfg |
| 46 | * @sa s3c_gpio_setpull |
| 47 | * @sa s3c_gpio_getpull |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 48 | */ |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 49 | struct samsung_gpio_cfg { |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 50 | unsigned int cfg_eint; |
| 51 | |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 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); |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 55 | |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 56 | unsigned (*get_config)(struct samsung_gpio_chip *chip, unsigned offs); |
| 57 | int (*set_config)(struct samsung_gpio_chip *chip, unsigned offs, |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 58 | unsigned config); |
| 59 | }; |
| 60 | |
| 61 | #define S3C_GPIO_SPECIAL_MARK (0xfffffff0) |
| 62 | #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x)) |
| 63 | |
| 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)) |
| 68 | |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 69 | #define samsung_gpio_is_cfg_special(_cfg) \ |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 70 | (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK) |
| 71 | |
| 72 | /** |
| 73 | * s3c_gpio_cfgpin() - Change the GPIO function of a pin. |
| 74 | * @pin pin The pin number to configure. |
Ben Dooks | 9414392 | 2010-05-24 12:11:43 +0900 | [diff] [blame] | 75 | * @to to The configuration for the pin's function. |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 76 | * |
| 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. |
Ben Dooks | 189e044 | 2010-05-24 12:21:40 +0900 | [diff] [blame] | 80 | * |
| 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. |
| 84 | * |
| 85 | * If a bank of GPIOs all needs to be set to special-function 2, then |
| 86 | * the following code will work: |
| 87 | * |
| 88 | * for (gpio = start; gpio < end; gpio++) |
| 89 | * s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2)); |
| 90 | * |
| 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. |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 94 | */ |
| 95 | extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to); |
| 96 | |
Ben Dooks | 9933847 | 2010-05-06 10:50:42 +0900 | [diff] [blame] | 97 | /** |
| 98 | * s3c_gpio_getcfg - Read the current function for a GPIO pin |
| 99 | * @pin: The pin to read the configuration value for. |
| 100 | * |
| 101 | * Read the configuration state of the given @pin, returning a value that |
| 102 | * could be passed back to s3c_gpio_cfgpin(). |
| 103 | * |
| 104 | * @sa s3c_gpio_cfgpin |
| 105 | */ |
| 106 | extern unsigned s3c_gpio_getcfg(unsigned int pin); |
| 107 | |
Ben Dooks | 4b46fbb | 2010-10-01 13:37:13 +0900 | [diff] [blame] | 108 | /** |
| 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 |
| 113 | * |
| 114 | * Call s3c_gpio_cfgpin() for the @nr pins starting at @start. |
| 115 | * |
| 116 | * @sa s3c_gpio_cfgpin. |
| 117 | */ |
| 118 | extern int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr, |
| 119 | unsigned int cfg); |
| 120 | |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 121 | /* Define values for the pull-{up,down} available for each gpio pin. |
| 122 | * |
| 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 |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 125 | * up or down settings, and it may be dependent on the chip that is being |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 126 | * used to whether the particular mode is available. |
| 127 | */ |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 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) |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 131 | |
| 132 | /** |
| 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. |
| 136 | * |
| 137 | * This function sets the state of the pull-{up,down} resistor for the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 138 | * specified pin. It will return 0 if successful, or a negative error |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 139 | * code if the pin cannot support the requested pull setting. |
Ben Dooks | 189e044 | 2010-05-24 12:21:40 +0900 | [diff] [blame] | 140 | * |
| 141 | * @pull is one of S3C_GPIO_PULL_NONE, S3C_GPIO_PULL_DOWN or S3C_GPIO_PULL_UP. |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 142 | */ |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 143 | extern int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull); |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * s3c_gpio_getpull() - get the pull resistor state of a gpio pin |
| 147 | * @pin: The pin number to get the settings for |
| 148 | * |
| 149 | * Read the pull resistor value for the specified pin. |
| 150 | */ |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 151 | extern samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin); |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 152 | |
Ben Dooks | 5459148 | 2010-10-01 16:34:34 +0900 | [diff] [blame] | 153 | /* configure `all` aspects of an gpio */ |
| 154 | |
| 155 | /** |
| 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. |
| 161 | * |
| 162 | * Run s3c_gpio_cfgpin() and s3c_gpio_setpull() over the gpio range starting |
| 163 | * @gpio and running for @size. |
| 164 | * |
| 165 | * @sa s3c_gpio_cfgpin |
| 166 | * @sa s3c_gpio_setpull |
| 167 | * @sa s3c_gpio_cfgpin_range |
| 168 | */ |
| 169 | extern int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr, |
Kukjin Kim | 782d8a3 | 2011-08-30 20:47:32 +0900 | [diff] [blame] | 170 | unsigned int cfg, samsung_gpio_pull_t pull); |
Ben Dooks | 5459148 | 2010-10-01 16:34:34 +0900 | [diff] [blame] | 171 | |
Ben Dooks | e594ea3 | 2010-10-01 19:07:28 +0900 | [diff] [blame] | 172 | static inline int s3c_gpio_cfgrange_nopull(unsigned int pin, unsigned int size, |
| 173 | unsigned int cfg) |
| 174 | { |
| 175 | return s3c_gpio_cfgall_range(pin, size, cfg, S3C_GPIO_PULL_NONE); |
| 176 | } |
| 177 | |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 178 | #endif /* __PLAT_GPIO_CFG_H */ |