rk2928 hdmi: fix hdmi switch status
[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         if(!hdmi->hotplug)
77                 return -1;
78         hdmi->autoconfig = HDMI_DISABLE;
79         if(vic && hdmi->vic != vic)
80         {
81                 hdmi->vic = vic;
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(direction == DISPLAY_SCALE_X)
115                 hdmi->xscale = value;
116         else if(direction == DISPLAY_SCALE_Y)
117                 hdmi->yscale = value;
118         else
119                 return -1;
120         rk_fb_disp_scale(hdmi->xscale, hdmi->yscale, hdmi->lcdc->id);
121         return 0;
122 }
123
124 static int hdmi_get_scale(struct rk_display_device *device, int direction)
125 {
126         struct hdmi *hdmi = device->priv_data;
127         
128         if(!hdmi)
129                 return -1;
130                 
131         if(direction == DISPLAY_SCALE_X)
132                 return hdmi->xscale;
133         else if(direction == DISPLAY_SCALE_Y)
134                 return hdmi->yscale;
135         else
136                 return -1;
137 }
138
139 struct rk_display_ops hdmi_display_ops = {
140         .setenable = hdmi_set_enable,
141         .getenable = hdmi_get_enable,
142         .getstatus = hdmi_get_status,
143         .getmodelist = hdmi_get_modelist,
144         .setmode = hdmi_set_mode,
145         .getmode = hdmi_get_mode,
146         .setscale = hdmi_set_scale,
147         .getscale = hdmi_get_scale,
148 };
149
150 #if 1
151 static int hdmi_display_probe(struct rk_display_device *device, void *devdata)
152 {
153         device->owner = THIS_MODULE;
154         strcpy(device->type, "HDMI");
155         device->priority = DISPLAY_PRIORITY_HDMI;
156 //      device->name = kmalloc(strlen(name), GFP_KERNEL);
157 //      if(device->name)
158 //      {
159 //              strcpy(device->name, name);
160 //      }
161         device->priv_data = devdata;
162         device->ops = &hdmi_display_ops;
163         return 1;
164 }
165
166 static struct rk_display_driver display_hdmi = {
167         .probe = hdmi_display_probe,
168 };
169
170 static struct rk_display_device *display_device_hdmi = NULL;
171
172 void hdmi_register_display_sysfs(struct hdmi *hdmi, struct device *parent)
173 {
174         display_device_hdmi = rk_display_device_register(&display_hdmi, parent, hdmi);
175 }
176
177 void hdmi_unregister_display_sysfs(struct hdmi *hdmi)
178 {
179         if(display_device_hdmi)
180                 rk_display_device_unregister(display_device_hdmi);
181 }
182 #endif