0001 ====================
0002 S3C24XX GPIO Control
0003 ====================
0004
0005 Introduction
0006 ------------
0007
0008 The s3c2410 kernel provides an interface to configure and
0009 manipulate the state of the GPIO pins, and find out other
0010 information about them.
0011
0012 There are a number of conditions attached to the configuration
0013 of the s3c2410 GPIO system, please read the Samsung provided
0014 data-sheet/users manual to find out the complete list.
0015
0016 See Documentation/arm/samsung/gpio.rst for the core implementation.
0017
0018
0019 GPIOLIB
0020 -------
0021
0022 With the event of the GPIOLIB in drivers/gpio, support for some
0023 of the GPIO functions such as reading and writing a pin will
0024 be removed in favour of this common access method.
0025
0026 Once all the extant drivers have been converted, the functions
0027 listed below will be removed (they may be marked as __deprecated
0028 in the near future).
0029
0030 The following functions now either have a `s3c_` specific variant
0031 or are merged into gpiolib. See the definitions in
0032 arch/arm/mach-s3c/gpio-cfg.h:
0033
0034 - s3c2410_gpio_setpin() gpio_set_value() or gpio_direction_output()
0035 - s3c2410_gpio_getpin() gpio_get_value() or gpio_direction_input()
0036 - s3c2410_gpio_getirq() gpio_to_irq()
0037 - s3c2410_gpio_cfgpin() s3c_gpio_cfgpin()
0038 - s3c2410_gpio_getcfg() s3c_gpio_getcfg()
0039 - s3c2410_gpio_pullup() s3c_gpio_setpull()
0040
0041
0042 GPIOLIB conversion
0043 ------------------
0044
0045 If you need to convert your board or driver to use gpiolib from the phased
0046 out s3c2410 API, then here are some notes on the process.
0047
0048 1) If your board is exclusively using an GPIO, say to control peripheral
0049 power, then it will require to claim the gpio with gpio_request() before
0050 it can use it.
0051
0052 It is recommended to check the return value, with at least WARN_ON()
0053 during initialisation.
0054
0055 2) The s3c2410_gpio_cfgpin() can be directly replaced with s3c_gpio_cfgpin()
0056 as they have the same arguments, and can either take the pin specific
0057 values, or the more generic special-function-number arguments.
0058
0059 3) s3c2410_gpio_pullup() changes have the problem that while the
0060 s3c2410_gpio_pullup(x, 1) can be easily translated to the
0061 s3c_gpio_setpull(x, S3C_GPIO_PULL_NONE), the s3c2410_gpio_pullup(x, 0)
0062 are not so easy.
0063
0064 The s3c2410_gpio_pullup(x, 0) case enables the pull-up (or in the case
0065 of some of the devices, a pull-down) and as such the new API distinguishes
0066 between the UP and DOWN case. There is currently no 'just turn on' setting
0067 which may be required if this becomes a problem.
0068
0069 4) s3c2410_gpio_setpin() can be replaced by gpio_set_value(), the old call
0070 does not implicitly configure the relevant gpio to output. The gpio
0071 direction should be changed before using gpio_set_value().
0072
0073 5) s3c2410_gpio_getpin() is replaceable by gpio_get_value() if the pin
0074 has been set to input. It is currently unknown what the behaviour is
0075 when using gpio_get_value() on an output pin (s3c2410_gpio_getpin
0076 would return the value the pin is supposed to be outputting).
0077
0078 6) s3c2410_gpio_getirq() should be directly replaceable with the
0079 gpio_to_irq() call.
0080
0081 The s3c2410_gpio and `gpio_` calls have always operated on the same gpio
0082 numberspace, so there is no problem with converting the gpio numbering
0083 between the calls.
0084
0085
0086 Headers
0087 -------
0088
0089 See arch/arm/mach-s3c/regs-gpio-s3c24xx.h for the list
0090 of GPIO pins, and the configuration values for them. This
0091 is included by using #include <mach/regs-gpio.h>
0092
0093
0094 PIN Numbers
0095 -----------
0096
0097 Each pin has an unique number associated with it in regs-gpio.h,
0098 e.g. S3C2410_GPA(0) or S3C2410_GPF(1). These defines are used to tell
0099 the GPIO functions which pin is to be used.
0100
0101 With the conversion to gpiolib, there is no longer a direct conversion
0102 from gpio pin number to register base address as in earlier kernels. This
0103 is due to the number space required for newer SoCs where the later
0104 GPIOs are not contiguous.
0105
0106
0107 Configuring a pin
0108 -----------------
0109
0110 The following function allows the configuration of a given pin to
0111 be changed.
0112
0113 void s3c_gpio_cfgpin(unsigned int pin, unsigned int function);
0114
0115 e.g.:
0116
0117 s3c_gpio_cfgpin(S3C2410_GPA(0), S3C_GPIO_SFN(1));
0118 s3c_gpio_cfgpin(S3C2410_GPE(8), S3C_GPIO_SFN(2));
0119
0120 which would turn GPA(0) into the lowest Address line A0, and set
0121 GPE(8) to be connected to the SDIO/MMC controller's SDDAT1 line.
0122
0123
0124 Reading the current configuration
0125 ---------------------------------
0126
0127 The current configuration of a pin can be read by using standard
0128 gpiolib function:
0129
0130 s3c_gpio_getcfg(unsigned int pin);
0131
0132 The return value will be from the same set of values which can be
0133 passed to s3c_gpio_cfgpin().
0134
0135
0136 Configuring a pull-up resistor
0137 ------------------------------
0138
0139 A large proportion of the GPIO pins on the S3C2410 can have weak
0140 pull-up resistors enabled. This can be configured by the following
0141 function:
0142
0143 void s3c_gpio_setpull(unsigned int pin, unsigned int to);
0144
0145 Where the to value is S3C_GPIO_PULL_NONE to set the pull-up off,
0146 and S3C_GPIO_PULL_UP to enable the specified pull-up. Any other
0147 values are currently undefined.
0148
0149
0150 Getting and setting the state of a PIN
0151 --------------------------------------
0152
0153 These calls are now implemented by the relevant gpiolib calls, convert
0154 your board or driver to use gpiolib.
0155
0156
0157 Getting the IRQ number associated with a PIN
0158 --------------------------------------------
0159
0160 A standard gpiolib function can map the given pin number to an IRQ
0161 number to pass to the IRQ system.
0162
0163 int gpio_to_irq(unsigned int pin);
0164
0165 Note, not all pins have an IRQ.
0166
0167
0168 Author
0169 -------
0170
0171 Ben Dooks, 03 October 2004
0172 Copyright 2004 Ben Dooks, Simtec Electronics