Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 1 | /* linux/arch/arm/plat-s3c/include/plat/gpio-cfg-helper.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 helper definitions |
| 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 is meant for core cpu support, machine or other driver files |
| 16 | * should not be including this header. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __PLAT_GPIO_CFG_HELPERS_H |
| 20 | #define __PLAT_GPIO_CFG_HELPERS_H __FILE__ |
| 21 | |
| 22 | /* As a note, all gpio configuration functions are entered exclusively, either |
| 23 | * with the relevant lock held or the system prevented from doing anything else |
| 24 | * by disabling interrupts. |
| 25 | */ |
| 26 | |
| 27 | static inline int s3c_gpio_do_setcfg(struct s3c_gpio_chip *chip, |
| 28 | unsigned int off, unsigned int config) |
| 29 | { |
| 30 | return (chip->config->set_config)(chip, off, config); |
| 31 | } |
| 32 | |
Ben Dooks | 9933847 | 2010-05-06 10:50:42 +0900 | [diff] [blame] | 33 | static inline unsigned s3c_gpio_do_getcfg(struct s3c_gpio_chip *chip, |
| 34 | unsigned int off) |
| 35 | { |
| 36 | return (chip->config->get_config)(chip, off); |
| 37 | } |
| 38 | |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 39 | static inline int s3c_gpio_do_setpull(struct s3c_gpio_chip *chip, |
| 40 | unsigned int off, s3c_gpio_pull_t pull) |
| 41 | { |
| 42 | return (chip->config->set_pull)(chip, off, pull); |
| 43 | } |
| 44 | |
Daein Moon | a6149c0 | 2010-10-26 08:40:08 +0900 | [diff] [blame] | 45 | static inline s3c_gpio_pull_t s3c_gpio_do_getpull(struct s3c_gpio_chip *chip, |
| 46 | unsigned int off) |
| 47 | { |
| 48 | return chip->config->get_pull(chip, off); |
| 49 | } |
| 50 | |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 51 | /** |
| 52 | * s3c_gpio_setcfg_s3c24xx - S3C24XX style GPIO configuration. |
| 53 | * @chip: The gpio chip that is being configured. |
| 54 | * @off: The offset for the GPIO being configured. |
| 55 | * @cfg: The configuration value to set. |
| 56 | * |
| 57 | * This helper deal with the GPIO cases where the control register |
| 58 | * has two bits of configuration per gpio, which have the following |
| 59 | * functions: |
| 60 | * 00 = input |
| 61 | * 01 = output |
| 62 | * 1x = special function |
| 63 | */ |
| 64 | extern int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip, |
| 65 | unsigned int off, unsigned int cfg); |
| 66 | |
| 67 | /** |
Ben Dooks | 97a3399 | 2010-05-06 10:27:16 +0900 | [diff] [blame] | 68 | * s3c_gpio_getcfg_s3c24xx - S3C24XX style GPIO configuration read. |
| 69 | * @chip: The gpio chip that is being configured. |
| 70 | * @off: The offset for the GPIO being configured. |
| 71 | * |
| 72 | * The reverse of s3c_gpio_setcfg_s3c24xx(). Will return a value whicg |
| 73 | * could be directly passed back to s3c_gpio_setcfg_s3c24xx(), from the |
| 74 | * S3C_GPIO_SPECIAL() macro. |
| 75 | */ |
| 76 | unsigned int s3c_gpio_getcfg_s3c24xx(struct s3c_gpio_chip *chip, |
| 77 | unsigned int off); |
| 78 | |
| 79 | /** |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 80 | * s3c_gpio_setcfg_s3c24xx_a - S3C24XX style GPIO configuration (Bank A) |
| 81 | * @chip: The gpio chip that is being configured. |
| 82 | * @off: The offset for the GPIO being configured. |
| 83 | * @cfg: The configuration value to set. |
| 84 | * |
| 85 | * This helper deal with the GPIO cases where the control register |
| 86 | * has one bit of configuration for the gpio, where setting the bit |
| 87 | * means the pin is in special function mode and unset means output. |
| 88 | */ |
| 89 | extern int s3c_gpio_setcfg_s3c24xx_a(struct s3c_gpio_chip *chip, |
| 90 | unsigned int off, unsigned int cfg); |
| 91 | |
Ben Dooks | 97a3399 | 2010-05-06 10:27:16 +0900 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * s3c_gpio_getcfg_s3c24xx_a - S3C24XX style GPIO configuration read (Bank A) |
| 95 | * @chip: The gpio chip that is being configured. |
| 96 | * @off: The offset for the GPIO being configured. |
| 97 | * |
| 98 | * The reverse of s3c_gpio_setcfg_s3c24xx_a() turning an GPIO into a usable |
| 99 | * GPIO configuration value. |
| 100 | * |
| 101 | * @sa s3c_gpio_getcfg_s3c24xx |
| 102 | * @sa s3c_gpio_getcfg_s3c64xx_4bit |
| 103 | */ |
| 104 | extern unsigned s3c_gpio_getcfg_s3c24xx_a(struct s3c_gpio_chip *chip, |
| 105 | unsigned int off); |
| 106 | |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 107 | /** |
| 108 | * s3c_gpio_setcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config. |
| 109 | * @chip: The gpio chip that is being configured. |
| 110 | * @off: The offset for the GPIO being configured. |
| 111 | * @cfg: The configuration value to set. |
| 112 | * |
| 113 | * This helper deal with the GPIO cases where the control register has 4 bits |
| 114 | * of control per GPIO, generally in the form of: |
| 115 | * 0000 = Input |
| 116 | * 0001 = Output |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 117 | * others = Special functions (dependent on bank) |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 118 | * |
| 119 | * Note, since the code to deal with the case where there are two control |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 120 | * registers instead of one, we do not have a separate set of functions for |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 121 | * each case. |
| 122 | */ |
| 123 | extern int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip, |
| 124 | unsigned int off, unsigned int cfg); |
| 125 | |
| 126 | |
Ben Dooks | 97a3399 | 2010-05-06 10:27:16 +0900 | [diff] [blame] | 127 | /** |
| 128 | * s3c_gpio_getcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config read. |
| 129 | * @chip: The gpio chip that is being configured. |
| 130 | * @off: The offset for the GPIO being configured. |
| 131 | * |
| 132 | * The reverse of s3c_gpio_setcfg_s3c64xx_4bit(), turning a gpio configuration |
| 133 | * register setting into a value the software can use, such as could be passed |
| 134 | * to s3c_gpio_setcfg_s3c64xx_4bit(). |
| 135 | * |
| 136 | * @sa s3c_gpio_getcfg_s3c24xx |
| 137 | */ |
| 138 | extern unsigned s3c_gpio_getcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip, |
| 139 | unsigned int off); |
| 140 | |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 141 | /* Pull-{up,down} resistor controls. |
| 142 | * |
| 143 | * S3C2410,S3C2440,S3C24A0 = Pull-UP, |
| 144 | * S3C2412,S3C2413 = Pull-Down |
| 145 | * S3C6400,S3C6410 = Pull-Both [None,Down,Up,Undef] |
| 146 | * S3C2443 = Pull-Both [not same as S3C6400] |
| 147 | */ |
| 148 | |
| 149 | /** |
| 150 | * s3c_gpio_setpull_1up() - Pull configuration for choice of up or none. |
| 151 | * @chip: The gpio chip that is being configured. |
| 152 | * @off: The offset for the GPIO being configured. |
| 153 | * @param: pull: The pull mode being requested. |
| 154 | * |
| 155 | * This is a helper function for the case where we have GPIOs with one |
| 156 | * bit configuring the presence of a pull-up resistor. |
| 157 | */ |
| 158 | extern int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip, |
| 159 | unsigned int off, s3c_gpio_pull_t pull); |
| 160 | |
| 161 | /** |
| 162 | * s3c_gpio_setpull_1down() - Pull configuration for choice of down or none |
| 163 | * @chip: The gpio chip that is being configured |
| 164 | * @off: The offset for the GPIO being configured |
| 165 | * @param: pull: The pull mode being requested |
| 166 | * |
| 167 | * This is a helper function for the case where we have GPIOs with one |
| 168 | * bit configuring the presence of a pull-down resistor. |
| 169 | */ |
| 170 | extern int s3c_gpio_setpull_1down(struct s3c_gpio_chip *chip, |
| 171 | unsigned int off, s3c_gpio_pull_t pull); |
| 172 | |
| 173 | /** |
| 174 | * s3c_gpio_setpull_upown() - Pull configuration for choice of up, down or none |
| 175 | * @chip: The gpio chip that is being configured. |
| 176 | * @off: The offset for the GPIO being configured. |
| 177 | * @param: pull: The pull mode being requested. |
| 178 | * |
| 179 | * This is a helper function for the case where we have GPIOs with two |
| 180 | * bits configuring the presence of a pull resistor, in the following |
| 181 | * order: |
| 182 | * 00 = No pull resistor connected |
| 183 | * 01 = Pull-up resistor connected |
| 184 | * 10 = Pull-down resistor connected |
| 185 | */ |
| 186 | extern int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip, |
| 187 | unsigned int off, s3c_gpio_pull_t pull); |
| 188 | |
| 189 | |
| 190 | /** |
| 191 | * s3c_gpio_getpull_updown() - Get configuration for choice of up, down or none |
| 192 | * @chip: The gpio chip that the GPIO pin belongs to |
| 193 | * @off: The offset to the pin to get the configuration of. |
| 194 | * |
| 195 | * This helper function reads the state of the pull-{up,down} resistor for the |
| 196 | * given GPIO in the same case as s3c_gpio_setpull_upown. |
| 197 | */ |
| 198 | extern s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip, |
| 199 | unsigned int off); |
| 200 | |
| 201 | /** |
Ben Dooks | 1ec7269 | 2010-05-03 14:39:45 +0900 | [diff] [blame] | 202 | * s3c_gpio_getpull_1up() - Get configuration for choice of up or none |
| 203 | * @chip: The gpio chip that the GPIO pin belongs to |
| 204 | * @off: The offset to the pin to get the configuration of. |
| 205 | * |
| 206 | * This helper function reads the state of the pull-up resistor for the |
| 207 | * given GPIO in the same case as s3c_gpio_setpull_1up. |
| 208 | */ |
| 209 | extern s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip, |
| 210 | unsigned int off); |
| 211 | |
| 212 | /** |
Vasily Khoruzhick | 812c4e4 | 2010-12-01 08:29:23 +0200 | [diff] [blame] | 213 | * s3c_gpio_getpull_1down() - Get configuration for choice of down or none |
| 214 | * @chip: The gpio chip that the GPIO pin belongs to |
| 215 | * @off: The offset to the pin to get the configuration of. |
| 216 | * |
| 217 | * This helper function reads the state of the pull-down resistor for the |
| 218 | * given GPIO in the same case as s3c_gpio_setpull_1down. |
| 219 | */ |
| 220 | extern s3c_gpio_pull_t s3c_gpio_getpull_1down(struct s3c_gpio_chip *chip, |
| 221 | unsigned int off); |
| 222 | |
| 223 | /** |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 224 | * s3c_gpio_setpull_s3c2443() - Pull configuration for s3c2443. |
| 225 | * @chip: The gpio chip that is being configured. |
| 226 | * @off: The offset for the GPIO being configured. |
| 227 | * @param: pull: The pull mode being requested. |
| 228 | * |
| 229 | * This is a helper function for the case where we have GPIOs with two |
| 230 | * bits configuring the presence of a pull resistor, in the following |
| 231 | * order: |
| 232 | * 00 = Pull-up resistor connected |
| 233 | * 10 = Pull-down resistor connected |
| 234 | * x1 = No pull up resistor |
| 235 | */ |
| 236 | extern int s3c_gpio_setpull_s3c2443(struct s3c_gpio_chip *chip, |
| 237 | unsigned int off, s3c_gpio_pull_t pull); |
| 238 | |
| 239 | /** |
| 240 | * s3c_gpio_getpull_s3c2443() - Get configuration for s3c2443 pull resistors |
| 241 | * @chip: The gpio chip that the GPIO pin belongs to. |
| 242 | * @off: The offset to the pin to get the configuration of. |
| 243 | * |
| 244 | * This helper function reads the state of the pull-{up,down} resistor for the |
| 245 | * given GPIO in the same case as s3c_gpio_setpull_upown. |
| 246 | */ |
Yauhen Kharuzhy | 0536d0d | 2011-01-06 13:04:33 +0900 | [diff] [blame] | 247 | extern s3c_gpio_pull_t s3c_gpio_getpull_s3c2443(struct s3c_gpio_chip *chip, |
Ben Dooks | 21b2366 | 2008-10-31 16:14:34 +0000 | [diff] [blame] | 248 | unsigned int off); |
| 249 | |
| 250 | #endif /* __PLAT_GPIO_CFG_HELPERS_H */ |
| 251 | |