Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 1 | S3C24XX GPIO Control |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | ==================== |
| 3 | |
| 4 | Introduction |
| 5 | ------------ |
| 6 | |
| 7 | The s3c2410 kernel provides an interface to configure and |
| 8 | manipulate the state of the GPIO pins, and find out other |
| 9 | information about them. |
| 10 | |
| 11 | There are a number of conditions attached to the configuration |
| 12 | of the s3c2410 GPIO system, please read the Samsung provided |
| 13 | data-sheet/users manual to find out the complete list. |
| 14 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 15 | See Documentation/arm/Samsung/GPIO.txt for the core implementation. |
Ben Dooks | d192bae | 2010-05-24 12:13:30 +0900 | [diff] [blame] | 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Ben Dooks | f47c32f | 2008-08-08 21:22:40 +0100 | [diff] [blame] | 18 | GPIOLIB |
| 19 | ------- |
| 20 | |
| 21 | With the event of the GPIOLIB in drivers/gpio, support for some |
| 22 | of the GPIO functions such as reading and writing a pin will |
| 23 | be removed in favour of this common access method. |
| 24 | |
| 25 | Once all the extant drivers have been converted, the functions |
| 26 | listed below will be removed (they may be marked as __deprecated |
| 27 | in the near future). |
| 28 | |
Ben Dooks | 70f5c9a | 2010-05-24 11:11:50 +0900 | [diff] [blame] | 29 | The following functions now either have a s3c_ specific variant |
| 30 | or are merged into gpiolib. See the definitions in |
| 31 | arch/arm/plat-samsung/include/plat/gpio-cfg.h: |
| 32 | |
| 33 | s3c2410_gpio_setpin() gpio_set_value() or gpio_direction_output() |
| 34 | s3c2410_gpio_getpin() gpio_get_value() or gpio_direction_input() |
| 35 | s3c2410_gpio_getirq() gpio_to_irq() |
| 36 | s3c2410_gpio_cfgpin() s3c_gpio_cfgpin() |
| 37 | s3c2410_gpio_getcfg() s3c_gpio_getcfg() |
| 38 | s3c2410_gpio_pullup() s3c_gpio_setpull() |
Ben Dooks | f47c32f | 2008-08-08 21:22:40 +0100 | [diff] [blame] | 39 | |
| 40 | |
Ben Dooks | 0639b93 | 2010-05-24 11:23:53 +0900 | [diff] [blame] | 41 | GPIOLIB conversion |
| 42 | ------------------ |
| 43 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 44 | If you need to convert your board or driver to use gpiolib from the phased |
| 45 | out s3c2410 API, then here are some notes on the process. |
Ben Dooks | 0639b93 | 2010-05-24 11:23:53 +0900 | [diff] [blame] | 46 | |
| 47 | 1) If your board is exclusively using an GPIO, say to control peripheral |
| 48 | power, then it will require to claim the gpio with gpio_request() before |
| 49 | it can use it. |
| 50 | |
| 51 | It is recommended to check the return value, with at least WARN_ON() |
| 52 | during initialisation. |
| 53 | |
| 54 | 2) The s3c2410_gpio_cfgpin() can be directly replaced with s3c_gpio_cfgpin() |
| 55 | as they have the same arguments, and can either take the pin specific |
| 56 | values, or the more generic special-function-number arguments. |
| 57 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 58 | 3) s3c2410_gpio_pullup() changes have the problem that whilst the |
Ben Dooks | 0639b93 | 2010-05-24 11:23:53 +0900 | [diff] [blame] | 59 | s3c2410_gpio_pullup(x, 1) can be easily translated to the |
| 60 | s3c_gpio_setpull(x, S3C_GPIO_PULL_NONE), the s3c2410_gpio_pullup(x, 0) |
| 61 | are not so easy. |
| 62 | |
| 63 | The s3c2410_gpio_pullup(x, 0) case enables the pull-up (or in the case |
| 64 | of some of the devices, a pull-down) and as such the new API distinguishes |
| 65 | between the UP and DOWN case. There is currently no 'just turn on' setting |
| 66 | which may be required if this becomes a problem. |
| 67 | |
| 68 | 4) s3c2410_gpio_setpin() can be replaced by gpio_set_value(), the old call |
| 69 | does not implicitly configure the relevant gpio to output. The gpio |
| 70 | direction should be changed before using gpio_set_value(). |
| 71 | |
| 72 | 5) s3c2410_gpio_getpin() is replaceable by gpio_get_value() if the pin |
| 73 | has been set to input. It is currently unknown what the behaviour is |
| 74 | when using gpio_get_value() on an output pin (s3c2410_gpio_getpin |
| 75 | would return the value the pin is supposed to be outputting). |
| 76 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 77 | 6) s3c2410_gpio_getirq() should be directly replaceable with the |
Ben Dooks | 0639b93 | 2010-05-24 11:23:53 +0900 | [diff] [blame] | 78 | gpio_to_irq() call. |
| 79 | |
| 80 | The s3c2410_gpio and gpio_ calls have always operated on the same gpio |
| 81 | numberspace, so there is no problem with converting the gpio numbering |
| 82 | between the calls. |
| 83 | |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | Headers |
| 86 | ------- |
| 87 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 88 | See arch/arm/mach-s3c2410/include/mach/regs-gpio.h for the list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | of GPIO pins, and the configuration values for them. This |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 90 | is included by using #include <mach/regs-gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | The GPIO management functions are defined in the hardware |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 93 | header arch/arm/mach-s3c2410/include/mach/hardware.h which can be |
| 94 | included by #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Matt LaPlante | 3f6dee9 | 2006-10-03 22:45:33 +0200 | [diff] [blame] | 96 | A useful amount of documentation can be found in the hardware |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | header on how the GPIO functions (and others) work. |
| 98 | |
| 99 | Whilst a number of these functions do make some checks on what |
| 100 | is passed to them, for speed of use, they may not always ensure |
| 101 | that the user supplied data to them is correct. |
| 102 | |
| 103 | |
| 104 | PIN Numbers |
| 105 | ----------- |
| 106 | |
| 107 | Each pin has an unique number associated with it in regs-gpio.h, |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 108 | e.g. S3C2410_GPA(0) or S3C2410_GPF(1). These defines are used to tell |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | the GPIO functions which pin is to be used. |
| 110 | |
Ben Dooks | 70f5c9a | 2010-05-24 11:11:50 +0900 | [diff] [blame] | 111 | With the conversion to gpiolib, there is no longer a direct conversion |
| 112 | from gpio pin number to register base address as in earlier kernels. This |
| 113 | is due to the number space required for newer SoCs where the later |
| 114 | GPIOs are not contiguous. |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | Configuring a pin |
| 118 | ----------------- |
| 119 | |
| 120 | The following function allows the configuration of a given pin to |
| 121 | be changed. |
| 122 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 123 | void s3c_gpio_cfgpin(unsigned int pin, unsigned int function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 125 | e.g.: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 127 | s3c_gpio_cfgpin(S3C2410_GPA(0), S3C_GPIO_SFN(1)); |
| 128 | s3c_gpio_cfgpin(S3C2410_GPE(8), S3C_GPIO_SFN(2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 130 | which would turn GPA(0) into the lowest Address line A0, and set |
| 131 | GPE(8) to be connected to the SDIO/MMC controller's SDDAT1 line. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | |
| 134 | Reading the current configuration |
| 135 | --------------------------------- |
| 136 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 137 | The current configuration of a pin can be read by using standard |
| 138 | gpiolib function: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 140 | s3c_gpio_getcfg(unsigned int pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | The return value will be from the same set of values which can be |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 143 | passed to s3c_gpio_cfgpin(). |
Ben Dooks | 70f5c9a | 2010-05-24 11:11:50 +0900 | [diff] [blame] | 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | Configuring a pull-up resistor |
| 147 | ------------------------------ |
| 148 | |
| 149 | A large proportion of the GPIO pins on the S3C2410 can have weak |
| 150 | pull-up resistors enabled. This can be configured by the following |
| 151 | function: |
| 152 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 153 | void s3c_gpio_setpull(unsigned int pin, unsigned int to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 155 | Where the to value is S3C_GPIO_PULL_NONE to set the pull-up off, |
| 156 | and S3C_GPIO_PULL_UP to enable the specified pull-up. Any other |
| 157 | values are currently undefined. |
Ben Dooks | 70f5c9a | 2010-05-24 11:11:50 +0900 | [diff] [blame] | 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 160 | Getting and setting the state of a PIN |
| 161 | -------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 163 | These calls are now implemented by the relevant gpiolib calls, convert |
Ben Dooks | 70f5c9a | 2010-05-24 11:11:50 +0900 | [diff] [blame] | 164 | your board or driver to use gpiolib. |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | Getting the IRQ number associated with a PIN |
| 168 | -------------------------------------------- |
| 169 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 170 | A standard gpiolib function can map the given pin number to an IRQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | number to pass to the IRQ system. |
| 172 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 173 | int gpio_to_irq(unsigned int pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | Note, not all pins have an IRQ. |
| 176 | |
Ben Dooks | 70f5c9a | 2010-05-24 11:11:50 +0900 | [diff] [blame] | 177 | |
Sylwester Nawrocki | 98025c8 | 2012-09-07 06:40:29 +0900 | [diff] [blame] | 178 | Author |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | ------- |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | Ben Dooks, 03 October 2004 |
Ben Dooks | 50f430e | 2009-11-13 22:54:12 +0000 | [diff] [blame] | 182 | Copyright 2004 Ben Dooks, Simtec Electronics |