Merge remote-tracking branch 'aosp/android-3.0' into develop-3.0-jb
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / hdmi / rk_hdmi_sysfs.c
1 #include <linux/ctype.h>
2 #include <linux/string.h>
3 #include <linux/display-sys.h>
4 #include <linux/interrupt.h>
5 #include "rk_hdmi.h"
6
7 static int hdmi_get_enable(struct rk_display_device *device)
8 {
9         struct hdmi *hdmi = device->priv_data;
10         int enable;
11         
12         mutex_lock(&hdmi->enable_mutex);
13         enable = hdmi->enable;
14         mutex_unlock(&hdmi->enable_mutex);
15         
16         return enable;
17 }
18
19 static int hdmi_set_enable(struct rk_display_device *device, int enable)
20 {
21         struct hdmi *hdmi = device->priv_data;
22         
23         mutex_lock(&hdmi->enable_mutex);
24         if(hdmi->enable == enable) {
25                 mutex_unlock(&hdmi->enable_mutex);
26                 return 0;
27         }
28         hdmi->enable = enable;
29         
30         if(hdmi->suspend ) {
31                 mutex_unlock(&hdmi->enable_mutex);
32                 return 0;
33         }
34         
35         if(enable == 0) {
36                 disable_irq(hdmi->irq);
37                 mutex_unlock(&hdmi->enable_mutex);
38                 hdmi->command = HDMI_CONFIG_ENABLE;
39                 queue_delayed_work(hdmi->workqueue, &hdmi->delay_work, 0);
40         }
41         else {
42                 enable_irq(hdmi->irq);
43                 mutex_unlock(&hdmi->enable_mutex);
44         }
45         return 0;
46 }
47
48 static int hdmi_get_status(struct rk_display_device *device)
49 {
50         struct hdmi *hdmi = device->priv_data;
51         if(hdmi->hotplug == HDMI_HPD_ACTIVED)
52                 return 1;
53         else
54                 return 0;
55 }
56
57 static int hdmi_get_modelist(struct rk_display_device *device, struct list_head **modelist)
58 {
59         struct hdmi *hdmi = device->priv_data;
60         if(!hdmi->hotplug)
61                 return -1;
62         *modelist = &hdmi->edid.modelist;
63         return 0;
64 }
65
66 static int hdmi_set_mode(struct rk_display_device *device, struct fb_videomode *mode)
67 {
68         struct hdmi *hdmi = device->priv_data;
69         int vic = hdmi_videomode_to_vic(mode);
70         
71         if(!hdmi->hotplug)
72                 return -1;
73         hdmi->autoconfig = HDMI_DISABLE;
74         if(vic && hdmi->vic != vic)
75         {
76                 hdmi->vic = vic;
77                 hdmi->command = HDMI_CONFIG_VIDEO;
78                 init_completion(&hdmi->complete);
79                 hdmi->wait = 1;
80                 queue_delayed_work(hdmi->workqueue, &hdmi->delay_work, 0);
81                 wait_for_completion_interruptible_timeout(&hdmi->complete,
82                                                                 msecs_to_jiffies(10000));
83         }
84         return 0;
85 }
86
87 static int hdmi_get_mode(struct rk_display_device *device, struct fb_videomode *mode)
88 {
89         struct hdmi *hdmi = device->priv_data;
90         struct fb_videomode *vmode;
91         
92         if(!hdmi->hotplug)
93                 return -1;
94                 
95         vmode = (struct fb_videomode*) hdmi_vic_to_videomode(hdmi->vic);
96         if(unlikely(vmode == NULL))
97                 return -1;
98         *mode = *vmode;
99         return 0;
100 }
101
102 static int hdmi_set_scale(struct rk_display_device *device, int direction, int value)
103 {
104         struct hdmi *hdmi = device->priv_data;
105         
106         if(!hdmi || value < 0 || value > 100)
107                 return -1;
108                         
109         if(direction == DISPLAY_SCALE_X)
110                 hdmi->xscale = value;
111         else if(direction == DISPLAY_SCALE_Y)
112                 hdmi->yscale = value;
113         else
114                 return -1;
115         rk_fb_disp_scale(hdmi->xscale, hdmi->yscale, HDMI_SOURCE_DEFAULT);
116         return 0;
117 }
118
119 static int hdmi_get_scale(struct rk_display_device *device, int direction)
120 {
121         struct hdmi *hdmi = device->priv_data;
122         
123         if(!hdmi)
124                 return -1;
125                 
126         if(direction == DISPLAY_SCALE_X)
127                 return hdmi->xscale;
128         else if(direction == DISPLAY_SCALE_Y)
129                 return hdmi->yscale;
130         else
131                 return -1;
132 }
133
134 struct rk_display_ops hdmi_display_ops = {
135         .setenable = hdmi_set_enable,
136         .getenable = hdmi_get_enable,
137         .getstatus = hdmi_get_status,
138         .getmodelist = hdmi_get_modelist,
139         .setmode = hdmi_set_mode,
140         .getmode = hdmi_get_mode,
141         .setscale = hdmi_set_scale,
142         .getscale = hdmi_get_scale,
143 };
144
145 #if 1
146 static int hdmi_display_probe(struct rk_display_device *device, void *devdata)
147 {
148         device->owner = THIS_MODULE;
149         strcpy(device->type, "HDMI");
150         device->priority = DISPLAY_PRIORITY_HDMI;
151 //      device->name = kmalloc(strlen(name), GFP_KERNEL);
152 //      if(device->name)
153 //      {
154 //              strcpy(device->name, name);
155 //      }
156         device->priv_data = devdata;
157         device->ops = &hdmi_display_ops;
158         return 1;
159 }
160
161 static struct rk_display_driver display_hdmi = {
162         .probe = hdmi_display_probe,
163 };
164
165 static struct rk_display_device *display_device_hdmi = NULL;
166
167 void hdmi_register_display_sysfs(struct hdmi *hdmi, struct device *parent)
168 {
169         display_device_hdmi = rk_display_device_register(&display_hdmi, parent, hdmi);
170 }
171
172 void hdmi_unregister_display_sysfs(struct hdmi *hdmi)
173 {
174         if(display_device_hdmi)
175                 rk_display_device_unregister(display_device_hdmi);
176 }
177 #endif