The s3c6410 Gpio pin is relatively much, and most of the pins have multi-function, how to use the simplest way to control the Gpio on Linux we need to look at the underlying code, in fact, there are many ways, Since the control of Gpio on the operating system side is not the same as controlling a traditional microcontroller.
Here I'll mention a way to tell, and this is the simplest way I've ever seen.
First we open Linux-3.0.1\arch\arm\plat-samsung\include\plat under Gpio-cfg.h This header file, and after a closer look, we can use the function:
1. Setting up a single IO port
int s3c_gpio_cfgpin (unsigned int pin, unsigned int to);
There are two parameters, the first pin is the choice of which pin, the second parameter has three definitions
Set to output mode #define S3C_GPIO_INPUT (s3c_gpio_special (0))
Set into input mode #define S3C_GPIO_OUTPUT (s3c_gpio_special (1))
Multiplexing function Selection #define S3C_GPIO_SFN (x) (S3c_gpio_special (x))
In fact, according to my use of the situation 1th, 22 definitions is a chicken, only the 3rd S3C_GPIO_SFN (x) is the most useful, for example:
The Ds18b20 interface of the Ok6410 Development Board, the device is connected to the GPE0, and the GPE has the following multiplexing function
The parameter x is the corresponding function of the table, when x=0 is input function, X=1 is output function ... I guess I don't need to say that everyone understands.
This example S3c_gpio_cfgpin (S3C64XX_GPE (0), S3C_GPIO_SFN (1)), stating that the GPE0 port is configured as output mode.
1. Get the configuration of the IO port
unsigned s3c_gpio_getcfg (unsigned int pin); This function is the opposite of the one mentioned above, is to read the configuration of the current IO port, the pin parameter is to obtain the pin configuration, the function will return a corresponding value
2. Set up a set of IO
int s3c_gpio_cfgpin_range (unsigned int start, unsigned int nr, unsigned int cfg);
The first parameter start is the start pin, the second NR is from start to the first, note that the configured IO must be the same set of Io, the third CFG is the configuration state
3. Setting the pull-up resistor for single IO
int s3c_gpio_setpull (unsigned int pin, s3c_gpio_pull_t pull);
Set the single IO to a different pull-up mode, respectively
S3c_gpio_pull_none
S3c_gpio_pull_down
S3c_gpio_pull_up
5. Get the pull-up resistor configuration for the IO port
s3c_gpio_pull_t s3c_gpio_getpull (unsigned int pin);
Gets the pull-up configuration state of a single IO and returns a configuration mode
6. Set up a set of Io (including pull-up resistors)
int s3c_gpio_cfgall_range (unsigned int start, unsigned int nr, unsigned int cfg, s3c_gpio_pull_t pull);
So much to see the last function not to speak should also be able to see exactly how to configure it
The configuration of so many IO ports to see how to configure the level state of the output.
Open the Linux-3.0.1\include\linux under the gpio.h of the header file, found that there are a lot of pin functions of which the most important is the words
1. Set the level state of a PIN
static inline void Gpio_set_value (unsigned gpio, int value)
The first parameter gpio is the specified pin, the second parameter value is the high and low level to set
2. Get the level status of a PIN
static inline int gpio_get_value (unsigned gpio)
The first parameter is a GPIO for the specified PIN, which returns a level state
Speaking of the above we basically can control an IO, and now I am introducing a method, this method can only input and output can not be multiplexed configuration of IO
1.io output
static inline int gpio_direction_output (unsigned gpio, int value)
The first parameter gpio is the specified pin, the second parameter is level state
2.io input
static inline int gpio_direction_input (unsigned gpio)
The first parameter gpio is the specified pin and returns a level state
Out of the above method we can also directly to the GPIO address access, Linux has prepared such interface functions for us
#define __RAW_READL (a) (__chk_io_ptr (a), * (volatile unsigned int __force *) (a))
#define __raw_writel (V,a) (__chk_io_ptr (a), * (volatile unsigned int __force *) (a) = (v))
Where the A value is
S3c64xx_gpmcon
S3c64xx_gpmpud
S3c64xx_gpmdat
The above definitions are already in the reg-gpio.h.
V is the specific value.
"Grooming"--arm Gpio overview