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