Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | S3C2410 GPIO Control |
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 | ||
15 | ||
f47c32f3 BD |
16 | GPIOLIB |
17 | ------- | |
18 | ||
19 | With the event of the GPIOLIB in drivers/gpio, support for some | |
20 | of the GPIO functions such as reading and writing a pin will | |
21 | be removed in favour of this common access method. | |
22 | ||
23 | Once all the extant drivers have been converted, the functions | |
24 | listed below will be removed (they may be marked as __deprecated | |
25 | in the near future). | |
26 | ||
27 | - s3c2410_gpio_getpin | |
28 | - s3c2410_gpio_setpin | |
29 | ||
30 | ||
1da177e4 LT |
31 | Headers |
32 | ------- | |
33 | ||
a09e64fb | 34 | See arch/arm/mach-s3c2410/include/mach/regs-gpio.h for the list |
1da177e4 | 35 | of GPIO pins, and the configuration values for them. This |
a09e64fb | 36 | is included by using #include <mach/regs-gpio.h> |
1da177e4 LT |
37 | |
38 | The GPIO management functions are defined in the hardware | |
a09e64fb RK |
39 | header arch/arm/mach-s3c2410/include/mach/hardware.h which can be |
40 | included by #include <mach/hardware.h> | |
1da177e4 | 41 | |
3f6dee9b | 42 | A useful amount of documentation can be found in the hardware |
1da177e4 LT |
43 | header on how the GPIO functions (and others) work. |
44 | ||
45 | Whilst a number of these functions do make some checks on what | |
46 | is passed to them, for speed of use, they may not always ensure | |
47 | that the user supplied data to them is correct. | |
48 | ||
49 | ||
50 | PIN Numbers | |
51 | ----------- | |
52 | ||
53 | Each pin has an unique number associated with it in regs-gpio.h, | |
54 | eg S3C2410_GPA0 or S3C2410_GPF1. These defines are used to tell | |
55 | the GPIO functions which pin is to be used. | |
56 | ||
57 | ||
58 | Configuring a pin | |
59 | ----------------- | |
60 | ||
61 | The following function allows the configuration of a given pin to | |
62 | be changed. | |
63 | ||
64 | void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function); | |
65 | ||
66 | Eg: | |
67 | ||
68 | s3c2410_gpio_cfgpin(S3C2410_GPA0, S3C2410_GPA0_ADDR0); | |
69 | s3c2410_gpio_cfgpin(S3C2410_GPE8, S3C2410_GPE8_SDDAT1); | |
70 | ||
71 | which would turn GPA0 into the lowest Address line A0, and set | |
72 | GPE8 to be connected to the SDIO/MMC controller's SDDAT1 line. | |
73 | ||
74 | ||
75 | Reading the current configuration | |
76 | --------------------------------- | |
77 | ||
78 | The current configuration of a pin can be read by using: | |
79 | ||
80 | s3c2410_gpio_getcfg(unsigned int pin); | |
81 | ||
82 | The return value will be from the same set of values which can be | |
83 | passed to s3c2410_gpio_cfgpin(). | |
84 | ||
85 | ||
86 | Configuring a pull-up resistor | |
87 | ------------------------------ | |
88 | ||
89 | A large proportion of the GPIO pins on the S3C2410 can have weak | |
90 | pull-up resistors enabled. This can be configured by the following | |
91 | function: | |
92 | ||
93 | void s3c2410_gpio_pullup(unsigned int pin, unsigned int to); | |
94 | ||
95 | Where the to value is zero to set the pull-up off, and 1 to enable | |
96 | the specified pull-up. Any other values are currently undefined. | |
97 | ||
98 | ||
99 | Getting the state of a PIN | |
100 | -------------------------- | |
101 | ||
102 | The state of a pin can be read by using the function: | |
103 | ||
104 | unsigned int s3c2410_gpio_getpin(unsigned int pin); | |
105 | ||
106 | This will return either zero or non-zero. Do not count on this | |
107 | function returning 1 if the pin is set. | |
108 | ||
109 | ||
110 | Setting the state of a PIN | |
111 | -------------------------- | |
112 | ||
113 | The value an pin is outputing can be modified by using the following: | |
114 | ||
115 | void s3c2410_gpio_setpin(unsigned int pin, unsigned int to); | |
116 | ||
117 | Which sets the given pin to the value. Use 0 to write 0, and 1 to | |
118 | set the output to 1. | |
119 | ||
120 | ||
121 | Getting the IRQ number associated with a PIN | |
122 | -------------------------------------------- | |
123 | ||
124 | The following function can map the given pin number to an IRQ | |
125 | number to pass to the IRQ system. | |
126 | ||
127 | int s3c2410_gpio_getirq(unsigned int pin); | |
128 | ||
129 | Note, not all pins have an IRQ. | |
130 | ||
131 | ||
132 | Authour | |
133 | ------- | |
134 | ||
135 | ||
136 | Ben Dooks, 03 October 2004 | |
137 | (c) 2004 Ben Dooks, Simtec Electronics |