Merge tag 'v4.4-rc1'
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / rk_camsys / camsys_gpio.h
1 #ifndef __RKCAMSYS_GPIO_H__
2 #define __RKCAMSYS_GPIO_H__
3
4 #if defined(CONFIG_ARCH_ROCKCHIP)
5 #define RK30_PIN0_PA0 (0)
6 #define NUM_GROUP (32)
7 #define GPIO_BANKS (9)
8 #endif
9
10 static inline unsigned int camsys_gpio_group_pin(unsigned char *io_name)
11 {
12         unsigned char *pin_char;
13         unsigned char pin;
14
15         if (strstr(io_name, "PA")) {
16                 pin_char = strstr(io_name, "PA");
17                 pin_char += 2;
18                 pin = *pin_char - 0x30;
19         } else if (strstr(io_name, "PB")) {
20                 pin_char = strstr(io_name, "PB");
21                 pin_char += 2;
22                 pin = *pin_char - 0x30;
23                 pin += 8;
24         } else if (strstr(io_name, "PC")) {
25                 pin_char = strstr(io_name, "PC");
26                 pin_char += 2;
27                 pin = *pin_char - 0x30;
28                 pin += 16;
29         } else if (strstr(io_name, "PD")) {
30                 pin_char = strstr(io_name, "PD");
31                 pin_char += 2;
32                 pin = *pin_char - 0x30;
33                 pin += 24;
34         }
35         return pin;
36 }
37
38 static inline unsigned int camsys_gpio_group(unsigned char *io_name)
39 {
40         unsigned int group;
41
42         if (strstr(io_name, "PIN0"))
43                 group = 0;
44         else if (strstr(io_name, "PIN1"))
45                 group = 1;
46         else if (strstr(io_name, "PIN2"))
47                 group = 2;
48         else if (strstr(io_name, "PIN3"))
49                 group = 3;
50         else if (strstr(io_name, "PIN4"))
51                 group = 4;
52         else if (strstr(io_name, "PIN5"))
53                 group = 5;
54         else if (strstr(io_name, "PIN6"))
55                 group = 6;
56         else if (strstr(io_name, "PIN7"))
57                 group = 7;
58         else if (strstr(io_name, "PIN8"))
59                 group = 8;
60         return group;
61 }
62
63 static inline unsigned int camsys_gpio_get(unsigned char *io_name)
64 {
65         unsigned int gpio;
66         unsigned int group;
67         unsigned int group_pin;
68 #if (defined(CONFIG_ARCH_RK3066B) || defined(CONFIG_ARCH_RK3188) ||\
69                 defined(CONFIG_ARCH_RK319X) || defined(CONFIG_ARCH_ROCKCHIP))
70         if (strstr(io_name, "RK30_")) {
71                 gpio = RK30_PIN0_PA0;
72                 group = camsys_gpio_group(io_name);
73                 group_pin = camsys_gpio_group_pin(io_name);
74                 if (group >= GPIO_BANKS) {
75                         gpio = 0xffffffff;
76                 } else {
77                         if (cpu_is_rk3288()) {
78                                 /* bank 0 only has 24 pins ,not 32 pins */
79                                 if (group > 0) {
80                                         gpio += 24 + (group - 1) * NUM_GROUP
81                                                         + group_pin;
82                                 } else {
83                                         gpio += group_pin;
84                                 }
85                         } else {
86                                 gpio += group * NUM_GROUP + group_pin;
87                         }
88                 }
89         }
90 #endif
91         return gpio;
92 }
93
94 #endif
95