blob: 585d45868c4e4b747234c1b804f410fa2704d621 [file] [log] [blame]
Viktor Křivák68bce382012-08-08 13:42:19 +02001The U-Boot Driver Model Project
2===============================
3GPIO analysis
4=============
5Viktor Krivak <viktor.krivak@gmail.com>
62012-02-24
7
8I) Overview
9-----------
10
11 At this moment U-Boot provides standard API that consists of 7 functions.
12
13 int gpio_request(unsigned gpio, const char *label)
14 int gpio_free(unsigned gpio)
15 int gpio_direction_input(unsigned gpio)
16 int gpio_direction_output(unsigned gpio, int value)
17 int gpio_get_value(unsigned gpio)
18 void gpio_set_value(unsigned gpio, int value)
19
20 Methods "gpio_request()" and "gpio_free()" are used for claiming and releasing
21 GPIOs. First one should check if the desired pin exists and if the pin wasn't
22 requested already elsewhere. The method also has a label argument that can be
23 used for debug purposes. The label argument should be copied into the internal
24 memory, but only if the DEBUG macro is set. The "gpio_free()" is the exact
25 opposite. It releases the particular pin. Other methods are used for setting
26 input or output direction and obtaining or setting values of the pins.
27
28II) Approach
29------------
30
31 1) Request and free GPIO
32 ------------------------
33
34 The "gpio_request()" implementation is basically the same for all boards.
35 The function checks if the particular GPIO is correct and checks if the
36 GPIO pin is still free. If the conditions are met, the method marks the
37 GPIO claimed in it's internal structure. If macro DEBUG is defined, the
38 function also copies the label argument to the structure. If the pin is
39 already locked, the function returns -1 and if DEBUG is defined, certain
40 debug output is generated, including the contents of the label argument.
41 The "gpio_free()" function releases the lock and eventually deallocates
42 data used by the copied label argument.
43
44 2) Internal data
45 ----------------
46
47 Internal data are driver specific. They have to contain some mechanism to
48 realise the locking though. This can be done for example using a bit field.
49
50 3) Operations provided by the driver
51 ------------------------------------
52
53 The driver operations basically meet API that is already defined and used.
54 Except for "gpio_request()" and "gpio_free()", all methods can be converted in
55 a simple manner. The driver provides the following structure:
56
57 struct gpio_driver_ops {
58 int (*gpio_request)(struct instance *i, unsigned gpio,
Wolfgang Denk93e14592013-10-04 17:43:24 +020059 const char *label);
Viktor Křivák68bce382012-08-08 13:42:19 +020060 int (*gpio_free)(struct instance *i, unsigned gpio);
61 int (*gpio_direction_input)(struct instance *i, unsigned gpio);
62 int (*gpio_direction_output)(struct instance *i, unsigned gpio,
Wolfgang Denk93e14592013-10-04 17:43:24 +020063 int value);
Viktor Křivák68bce382012-08-08 13:42:19 +020064 int (*gpio_get_value)(struct instance *i, unsigned gpio);
65 void (*gpio_set_value)(struct instance *i, unsigned gpio, int value);
66 }
67
68III) Analysis of in-tree drivers
69--------------------------------
70
Masahiro Yamada566c6e42013-09-24 10:32:04 +090071 altera_pio.c
72 ------------
Viktor Křivák68bce382012-08-08 13:42:19 +020073 Meets standard API. Implements gpio_request() properly. Simple conversion
74 possible.
75
Masahiro Yamada566c6e42013-09-24 10:32:04 +090076 at91_gpio.c
77 -----------
Viktor Křivák68bce382012-08-08 13:42:19 +020078 Don't meet standard API. Need some other methods to implement.
79
Masahiro Yamada566c6e42013-09-24 10:32:04 +090080 da8xx_gpio.c
81 ------------
Viktor Křivák68bce382012-08-08 13:42:19 +020082 Meets standard API. Implements gpio_request() properly. Simple conversion
83 possible.
84
Masahiro Yamada566c6e42013-09-24 10:32:04 +090085 kw_gpio.c
86 ---------
Viktor Křivák68bce382012-08-08 13:42:19 +020087 Doesn't meet standard API. Needs some other methods to implement and move some
88 methods to another file.
89
Masahiro Yamada566c6e42013-09-24 10:32:04 +090090 mpc83xx_gpio.c
91 --------------
Viktor Křivák68bce382012-08-08 13:42:19 +020092 Meets standard API. Doesn't implement gpio_request() properly (only checks
93 if the pin is valid). Simple conversion possible.
94
Masahiro Yamada566c6e42013-09-24 10:32:04 +090095 mvgpio.c
96 --------
Viktor Křivák68bce382012-08-08 13:42:19 +020097 Meets standard API. Doesn't implement gpio_request() properly (only checks
98 if the pin is valid). Simple conversion possible.
99
Masahiro Yamada566c6e42013-09-24 10:32:04 +0900100 mvgpio.h
101 --------
Viktor Křivák68bce382012-08-08 13:42:19 +0200102 Wrong placement. Will be moved to another location.
103
Masahiro Yamada566c6e42013-09-24 10:32:04 +0900104 mvmfp.c
105 -------
Viktor Křivák68bce382012-08-08 13:42:19 +0200106 Wrong placement. Will be moved to another location.