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