Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0
[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                 if(hdmi->irq)
37                         disable_irq(hdmi->irq);
38                 mutex_unlock(&hdmi->enable_mutex);
39                 hdmi->command = HDMI_CONFIG_ENABLE;
40                 queue_delayed_work(hdmi->workqueue, &hdmi->delay_work, 0);
41         }
42         else {
43                 if(hdmi->irq)
44                         enable_irq(hdmi->irq);
45                 #if defined(CONFIG_HDMI_RK610) || defined(CONFIG_HDMI_RK2928)
46                         queue_delayed_work(hdmi->workqueue, &hdmi->delay_work, 0);
47                 #endif
48                 mutex_unlock(&hdmi->enable_mutex);
49         }
50         return 0;
51 }
52
53 static int hdmi_get_status(struct rk_display_device *device)
54 {
55         struct hdmi *hdmi = device->priv_data;
56         if(hdmi->hotplug == HDMI_HPD_ACTIVED)
57                 return 1;
58         else
59                 return 0;
60 }
61
62 static int hdmi_get_modelist(struct rk_display_device *device, struct list_head **modelist)
63 {
64         struct hdmi *hdmi = device->priv_data;
65         if(!hdmi->hotplug)
66                 return -1;
67         *modelist = &hdmi->edid.modelist;
68         return 0;
69 }
70
71 static int hdmi_set_mode(struct rk_display_device *device, struct fb_videomode *mode)
72 {
73         struct hdmi *hdmi = device->priv_data;
74         int vic = hdmi_videomode_to_vic(mode);
75         
76         hdmi->autoconfig = HDMI_DISABLE;
77         if(vic && hdmi->vic != vic)
78         {
79                 hdmi->vic = vic;
80                 if(!hdmi->hotplug)
81                         return 0;
82                 hdmi->command = HDMI_CONFIG_VIDEO;
83                 init_completion(&hdmi->complete);
84                 hdmi->wait = 1;
85                 queue_delayed_work(hdmi->workqueue, &hdmi->delay_work, 0);
86                 wait_for_completion_interruptible_timeout(&hdmi->complete,
87                                                                 msecs_to_jiffies(10000));
88         }
89         return 0;
90 }
91
92 static int hdmi_get_mode(struct rk_display_device *device, struct fb_videomode *mode)
93 {
94         struct hdmi *hdmi = device->priv_data;
95         struct fb_videomode *vmode;
96         
97         if(!hdmi->hotplug)
98                 return -1;
99                 
100         vmode = (struct fb_videomode*) hdmi_vic_to_videomode(hdmi->vic);
101         if(unlikely(vmode == NULL))
102                 return -1;
103         *mode = *vmode;
104         return 0;
105 }
106
107 static int hdmi_set_scale(struct rk_display_device *device, int direction, int value)
108 {
109         struct hdmi *hdmi = device->priv_data;
110         
111         if(!hdmi || value < 0 || value > 100)
112                 return -1;
113
114         if(!hdmi->hotplug)
115                return 0;
116                 
117         if(direction == DISPLAY_SCALE_X)
118                 hdmi->xscale = value;
119         else if(direction == DISPLAY_SCALE_Y)
120                 hdmi->yscale = value;
121         else
122                 return -1;
123         rk_fb_disp_scale(hdmi->xscale, hdmi->yscale, hdmi->lcdc->id);
124         return 0;
125 }
126
127 static int hdmi_get_scale(struct rk_display_device *device, int direction)
128 {
129         struct hdmi *hdmi = device->priv_data;
130         
131         if(!hdmi)
132                 return -1;
133                 
134         if(direction == DISPLAY_SCALE_X)
135                 return hdmi->xscale;
136         else if(direction == DISPLAY_SCALE_Y)
137                 return hdmi->yscale;
138         else
139                 return -1;
140 }
141
142 struct rk_display_ops hdmi_display_ops = {
143         .setenable = hdmi_set_enable,
144         .getenable = hdmi_get_enable,
145         .getstatus = hdmi_get_status,
146         .getmodelist = hdmi_get_modelist,
147         .setmode = hdmi_set_mode,
148         .getmode = hdmi_get_mode,
149         .setscale = hdmi_set_scale,
150         .getscale = hdmi_get_scale,
151 };
152
153 #if 1
154 static int hdmi_display_probe(struct rk_display_device *device, void *devdata)
155 {
156         device->owner = THIS_MODULE;
157         strcpy(device->type, "HDMI");
158         device->priority = DISPLAY_PRIORITY_HDMI;
159 //      device->name = kmalloc(strlen(name), GFP_KERNEL);
160 //      if(device->name)
161 //      {
162 //              strcpy(device->name, name);
163 //      }
164         device->priv_data = devdata;
165         device->ops = &hdmi_display_ops;
166         return 1;
167 }
168
169 static struct rk_display_driver display_hdmi = {
170         .probe = hdmi_display_probe,
171 };
172
173 static struct rk_display_device *display_device_hdmi = NULL;
174
175 void hdmi_register_display_sysfs(struct hdmi *hdmi, struct device *parent)
176 {
177         display_device_hdmi = rk_display_device_register(&display_hdmi, parent, hdmi);
178 }
179
180 void hdmi_unregister_display_sysfs(struct hdmi *hdmi)
181 {
182         if(display_device_hdmi)
183                 rk_display_device_unregister(display_device_hdmi);
184 }
185 #endif