ARM: rockchip: rk3228: add grf definition
[firefly-linux-kernel-4.4.55.git] / include / linux / scaler-core.h
1 #ifndef __SCALER_CORE_H__
2 #define __SCALER_CORE_H__
3 #include <linux/platform_device.h>
4 #include <linux/i2c.h>
5 #include <linux/cdev.h>
6 #include <linux/file.h>
7 #include <linux/list.h>
8 #include <linux/fb.h>
9
10 struct scaler_platform_data;
11
12 struct display_edid {
13         char *data;
14         char *ext_data;
15 };
16
17 enum scaler_output_type {
18         SCALER_OUT_INVALID = 0,
19         SCALER_OUT_LVDS,
20         SCALER_OUT_VGA,
21         SCALER_OUT_RGB,
22         SCALER_OUT_HDMI,
23         SCALER_OUT_DP,
24         SCALER_OUT_NUMS,
25 };
26
27 enum scaler_input_type {
28         SCALER_IN_INVALID = 0,
29         SCALER_IN_VGA,
30         SCALER_IN_RGB,
31         SCALER_IN_HDMI,
32         SCALER_IN_DP,
33         SCALER_IN_DVI,
34         SCALER_IN_YPBPR,
35         SCALER_IN_YCBCR,
36         SCALER_IN_MYDP,
37         SCALER_IN_IDP,
38         SCALER_IN_NUMS,
39 };
40
41 enum scaler_bus_type {
42         SCALER_BUS_TYPE_INVALID = 0,
43         SCALER_BUS_TYPE_UART,
44         SCALER_BUS_TYPE_I2C,
45         SCALER_BUS_TYPE_SPI,
46         SCALER_BUS_TYPE_NUMS,
47 };
48
49 /*
50  * the function of scaler, for example convertor or switch 
51 */
52 enum scaler_function_type {
53         SCALER_FUNC_INVALID = 0,
54         SCALER_FUNC_CONVERTOR,   //转换器
55         SCALER_FUNC_SWITCH,      //切换开关多选一输出 
56         SCALER_FUNC_FULL,        //全功能
57         SCALER_FUNC_NUMS,
58 };
59
60 struct scaler_output_port {
61         int id;
62         int max_hres;
63         int max_vres;
64         int freq;
65         int led_gpio;   //working led
66         enum scaler_output_type type;
67         struct list_head next; 
68 };
69
70 struct scaler_input_port {
71         int id;
72         int max_hres;
73         int max_vres;
74         int freq;       //HZ
75         int led_gpio;   //working led
76         enum scaler_input_type type;
77         struct list_head next; 
78 };
79
80 struct scaler_chip_dev {
81         char id;
82         char name[I2C_NAME_SIZE];
83         struct i2c_client *client;
84         
85         struct scaler_platform_data *pdata;
86
87         enum scaler_function_type func_type;
88         struct list_head iports; 
89         struct list_head oports; 
90         enum scaler_input_type cur_in_type;
91         enum scaler_output_type cur_out_type;
92         int cur_inport_id;
93         int cur_outport_id;
94
95         //enable chip to process image
96         void (*start)(void);
97         //disable chip to process image
98         void (*stop)(void);
99         void (*reset)(char active);
100         void (*suspend)(void);
101         void (*resume)(void);
102
103         //
104         int (*read)(unsigned short reg, int bytes, void *dest);
105         int (*write)(unsigned short reg, int bytes, void *src);
106         int (*parse_cmd)(unsigned int cmd, unsigned long arg);
107         int (*update_firmware)(void *data);
108
109         //scaler chip dev list
110         struct list_head next;
111 };
112
113 struct scaler_platform_data {
114         int int_gpio;
115         int reset_gpio;
116         int status_gpio; //check chip if work on lower power mode or normal mode.
117
118         int power_gpio;
119         int power_level;
120         int vga5v_gpio;
121         int vga5v_level;
122         int ddc_sel_gpio;
123         int ddc_sel_level; //ddc dev default select by defined the first input port in iports
124         int vga_hsync_gpio; //detect vga-in v\hsync clk by gpio
125         int vga_vsync_gpio;
126
127         char *firmware; 
128         //function type
129         enum scaler_function_type func_type;
130
131         //config in and out 
132         struct scaler_input_port  *iports;
133         struct scaler_output_port *oports;
134         int iport_size;
135         int oport_size;
136
137         int (*init_hw)(void);
138         int (*exit_hw)(void);
139 };
140
141 struct scaler_device {
142         struct class *class;
143         struct device *dev;
144         struct cdev *cdev;
145         dev_t devno;
146
147         struct display_edid edid;
148
149         struct list_head chips;
150 };
151
152 //scaler core
153 int scaler_init_platform(struct scaler_platform_data *pdata);
154 struct scaler_chip_dev *alloc_scaler_chip(void);
155 //free chip memory and port memory
156 void free_scaler_chip(struct scaler_chip_dev *chip);
157 int init_scaler_chip(struct scaler_chip_dev *chip, struct scaler_platform_data *pdata);
158 int register_scaler_chip(struct scaler_chip_dev *chip);
159 int unregister_scaler_chip(struct scaler_chip_dev *chip);
160
161 //edid
162 int scaler_switch_default_screen(void);
163 struct fb_videmode *scaler_get_cmode(void);
164
165 //fs ioctl
166 #define SCALER_IOCTL_MAGIC 'a'
167 #define SCALER_IOCTL_POWER _IOW(SCALER_IOCTL_MAGIC, 0x00, char)
168 #define SCALER_IOCTL_GET_CUR_INPUT _IOR(SCALER_IOCTL_MAGIC, 0x01, int)
169 #define SCALER_IOCTL_SET_CUR_INPUT _IOW(SCALER_IOCTL_MAGIC, 0x02, int)
170
171 #endif