1 #include <linux/ctype.h>
\r
2 #include <linux/hdmi.h>
\r
3 #include <linux/string.h>
\r
6 static ssize_t hdmi_show_state_attrs(struct device *dev,
\r
7 struct device_attribute *attr,
\r
10 struct hdmi *hdmi = dev_get_drvdata(dev);
\r
12 return sprintf(buf, "display_on=%d\n"
\r
22 "--------------------------\n"
\r
23 "resolution support:\n"
\r
24 "HDMI_1920x1080p_50Hz 0\n"
\r
25 "HDMI_1920x1080p_60Hz 1\n"
\r
26 "HDMI_1280x720p_50Hz 2\n"
\r
27 "HDMI_1280x720p_60Hz 3\n"
\r
28 "HDMI_720x576p_50Hz_4x3 4\n"
\r
29 "HDMI_720x576p_50Hz_16x9 5\n"
\r
30 "HDMI_720x480p_60Hz_4x3 6\n"
\r
31 "HDMI_720x480p_60Hz_16x9 7\n"
\r
32 "--------------------------\n",
\r
33 hdmi->display_on,hdmi->ops->hdmi_precent(hdmi),
\r
34 hdmi->dual_disp,fb_get_video_mode(), hdmi->mode, hdmi->hdcp_on,
\r
35 hdmi->audio_fs, (hdmi->ops->hdmi_precent(hdmi) && hdmi->display_on)?hdmi->scale:100,
\r
39 static ssize_t hdmi_restore_state_attrs(struct device *dev,
\r
40 struct device_attribute *attr,
\r
41 const char *buf, size_t size)
\r
44 struct hdmi *hdmi = dev_get_drvdata(dev);
\r
47 int set_param = 0, tmp = 0;
\r
49 if(hdmi->mode == DISP_ON_LCD)
\r
51 dev_err(dev, "display on lcd, do not set parameter!\n");
\r
59 if((p = strstr(q, "mode=")) != NULL)
\r
63 if((sscanf(q, "%d", &tmp) == 1) && (tmp >= 0 && tmp <= 3))
\r
65 if(tmp != hdmi->mode)
\r
73 dev_err(dev, "failed to set hdmi configuration\n");
\r
80 else if((p = strstr(q, "hdcp_on=")) != NULL)
\r
84 if((sscanf(q, "%d", &tmp) == 1) && (tmp == 0 || tmp ==1))
\r
86 if(tmp != hdmi->hdcp_on)
\r
89 hdmi->hdcp_on = tmp;
\r
94 dev_err(dev, "failed to set hdmi configuration\n");
\r
102 else if((p = strstr(q, "scale_set=")) != NULL)
\r
105 if((sscanf(q, "%d", &tmp) == 1) && (tmp >=MIN_SCALE && tmp <= 100))
\r
107 hdmi->scale_set = tmp;
\r
108 hdmi_dbg(dev, "set scale = %d\n", tmp);
\r
113 dev_err(dev, "failed to set hdmi configuration\n");
\r
118 else if((p = strstr(q, "resolution=")) != NULL)
\r
121 if((sscanf(q, "%d", &tmp) == 1) && (tmp >= 0))
\r
123 if(hdmi->resolution != tmp)
\r
126 hdmi_dbg(dev, "set resolution = %d\n", tmp);
\r
127 hdmi->resolution = tmp;
\r
132 dev_err(dev, "failed to set hdmi configuration\n");
\r
141 if(hdmi->ops->set_param && set_param != 0)
\r
143 mutex_lock(&hdmi->lock);
\r
144 ret = hdmi->ops->set_param(hdmi);
\r
145 mutex_unlock(&hdmi->lock);
\r
149 dev_err(dev, "hdmi_restore_state_attrs err\n");
\r
153 static ssize_t hdmi_show_switch_attrs(struct device *dev,
\r
154 struct device_attribute *attr,
\r
157 struct hdmi *hdmi = dev_get_drvdata(dev);
\r
159 return sprintf(buf, "%d\n", hdmi->display_on);
\r
161 static ssize_t hdmi_restore_switch_attrs(struct device *dev,
\r
162 struct device_attribute *attr,
\r
163 const char *buf, size_t size)
\r
165 int display_on = 0;
\r
166 struct hdmi *hdmi = dev_get_drvdata(dev);
\r
168 sscanf(buf, "%d", &display_on);
\r
169 hdmi_dbg(dev, "hdmi %s\n", (display_on)?"enable":"disable");
\r
170 if(display_on ^ hdmi->display_on)
\r
172 hdmi->display_on = display_on;
\r
173 hdmi_changed(hdmi, 1);
\r
177 static ssize_t hdmi_show_debug_attrs(struct device *dev,
\r
178 struct device_attribute *attr,
\r
181 return sprintf(buf, "%d\n", debug_en);
\r
183 static ssize_t hdmi_restore_debug_attrs(struct device *dev,
\r
184 struct device_attribute *attr,
\r
185 const char *buf, size_t size)
\r
189 sscanf(buf, "%d", &tmp);
\r
191 if(tmp != 0 && tmp != 1)
\r
192 dev_err(dev, "hdmi_restore_debug_attrs err\n");
\r
197 static ssize_t hdmi_restore_init_attrs(struct device *dev,
\r
198 struct device_attribute *attr,
\r
199 const char *buf, size_t size)
\r
201 int enable = HDMI_DISABLE, scale = 100, resolution = HDMI_DEFAULT_RESOLUTION;
\r
202 struct hdmi *hdmi = dev_get_drvdata(dev);
\r
204 sscanf(buf, "%d %d %d\n", &enable, &scale, &resolution);
\r
206 hdmi_dbg(dev, "hdmi init, set param: enable = %d, scale = %d, resolution = %d\n",
\r
207 enable, scale, resolution);
\r
209 hdmi->display_on = enable;
\r
210 hdmi->resolution = resolution;
\r
211 hdmi->scale_set = scale;
\r
213 if(hdmi->ops->hdmi_precent(hdmi) && hdmi->display_on)
\r
214 hdmi->scale = scale;
\r
216 if(hdmi->ops->init)
\r
217 hdmi->ops->init(hdmi);
\r
220 static struct device_attribute hdmi_attrs[] = {
\r
221 __ATTR(state, 0777, hdmi_show_state_attrs, hdmi_restore_state_attrs),
\r
222 __ATTR(enable, 0777, hdmi_show_switch_attrs, hdmi_restore_switch_attrs),
\r
223 __ATTR(debug, 0777, hdmi_show_debug_attrs, hdmi_restore_debug_attrs),
\r
224 __ATTR(init, 0777, NULL, hdmi_restore_init_attrs),
\r
227 int hdmi_create_attrs(struct hdmi *hdmi)
\r
232 for (i = 0; i < ARRAY_SIZE(hdmi_attrs); i++) {
\r
233 rc = device_create_file(hdmi->dev, &hdmi_attrs[i]);
\r
235 goto create_failed;
\r
242 device_remove_file(hdmi->dev, &hdmi_attrs[i]);
\r
247 void hdmi_remove_attrs(struct hdmi *hdmi)
\r
251 for (i = 0; i < ARRAY_SIZE(hdmi_attrs); i++)
\r
252 device_remove_file(hdmi->dev, &hdmi_attrs[i]);
\r