2 * linux/drivers/video/rockchip/rkfb-sysfs.c
4 * Copyright (C) 2012 Rockchip Corporation
5 * Author: yxj<yxj@rock-chips.com>
7 * Some code and ideas taken from
8 *drivers/video/omap2/omapfb/omapfb-sys.c
9 *driver by Tomi Valkeinen.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published by
14 * the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * You should have received a copy of the GNU General Public License along with
22 * this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <linux/sysfs.h>
27 #include <linux/device.h>
28 #include <linux/uaccess.h>
29 #include <linux/platform_device.h>
30 #include <linux/kernel.h>
32 #include <asm/div64.h>
33 #include <linux/rk_screen.h>
34 #include <linux/rk_fb.h>
36 static ssize_t show_screen_info(struct device *dev,
37 struct device_attribute *attr, char *buf)
39 struct fb_info *fbi = dev_get_drvdata(dev);
40 struct rk_lcdc_driver *dev_drv = (struct rk_lcdc_driver *)fbi->par;
41 struct rk_screen *screen = dev_drv->screen0;
43 u32 x = (screen->mode.left_margin + screen->mode.right_margin + screen->mode.xres + screen->mode.hsync_len);
44 u32 y = (screen->mode.upper_margin + screen->mode.lower_margin + screen->mode.yres + screen->mode.vsync_len);
45 u64 ft = (u64)x * y * (dev_drv->pixclock); // one frame time ,(pico seconds)
46 fps = div64_u64(1000000000000llu, ft);
47 return snprintf(buf, PAGE_SIZE, "xres:%d\nyres:%d\nfps:%d\n",
48 screen->mode.xres, screen->mode.yres, fps);
51 static ssize_t show_disp_info(struct device *dev,
52 struct device_attribute *attr, char *buf)
54 struct fb_info *fbi = dev_get_drvdata(dev);
55 struct rk_lcdc_driver *dev_drv = (struct rk_lcdc_driver *)fbi->par;
56 int win_id = dev_drv->ops->fb_get_win_id(dev_drv, fbi->fix.id);
57 if (dev_drv->ops->get_disp_info)
58 return dev_drv->ops->get_disp_info(dev_drv, buf, win_id);
63 static ssize_t show_phys(struct device *dev,
64 struct device_attribute *attr, char *buf)
66 struct fb_info *fbi = dev_get_drvdata(dev);
67 return snprintf(buf, PAGE_SIZE, "0x%lx-----0x%x\n",
68 fbi->fix.smem_start, fbi->fix.smem_len);
71 static ssize_t show_virt(struct device *dev,
72 struct device_attribute *attr, char *buf)
74 struct fb_info *fbi = dev_get_drvdata(dev);
76 return snprintf(buf, PAGE_SIZE, "0x%p-----0x%x\n",
77 fbi->screen_base, fbi->fix.smem_len);
80 static ssize_t show_fb_state(struct device *dev,
81 struct device_attribute *attr, char *buf)
83 struct fb_info *fbi = dev_get_drvdata(dev);
84 struct rk_lcdc_driver *dev_drv =
85 (struct rk_lcdc_driver *)fbi->par;
86 int win_id = dev_drv->ops->fb_get_win_id(dev_drv, fbi->fix.id);
87 int state = dev_drv->ops->get_win_state(dev_drv, win_id);
88 return snprintf(buf, PAGE_SIZE, "%s\n", state ? "enabled" : "disabled");
92 static ssize_t show_dual_mode(struct device *dev,
93 struct device_attribute *attr, char *buf)
95 struct fb_info *fbi = dev_get_drvdata(dev);
96 struct rk_fb *rk_fb = dev_get_drvdata(fbi->device);
97 int mode= rk_fb->disp_mode;
98 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
102 static ssize_t set_fb_state(struct device *dev, struct device_attribute *attr,
103 const char *buf, size_t count)
105 struct fb_info *fbi = dev_get_drvdata(dev);
106 struct rk_lcdc_driver *dev_drv =
107 (struct rk_lcdc_driver *)fbi->par;
108 int win_id = dev_drv->ops->fb_get_win_id(dev_drv, fbi->fix.id);
111 ret = kstrtoint(buf, 0, &state);
115 dev_drv->ops->open(dev_drv, win_id, state);
119 static ssize_t show_overlay(struct device *dev,
120 struct device_attribute *attr, char *buf)
122 struct fb_info *fbi = dev_get_drvdata(dev);
123 struct rk_lcdc_driver *dev_drv =
124 (struct rk_lcdc_driver *)fbi->par;
126 ovl = dev_drv->ops->ovl_mgr(dev_drv, 0, 0);
131 return snprintf(buf, PAGE_SIZE, "%s\n",
132 ovl ? "win0 on the top of win1" :
133 "win1 on the top of win0");
137 static ssize_t set_overlay(struct device *dev, struct device_attribute *attr,
138 const char *buf, size_t count)
140 struct fb_info *fbi = dev_get_drvdata(dev);
141 struct rk_lcdc_driver *dev_drv =
142 (struct rk_lcdc_driver *)fbi->par;
145 ret = kstrtoint(buf, 0, &ovl);
149 ret = dev_drv->ops->ovl_mgr(dev_drv, ovl, 1);
157 static ssize_t show_fps(struct device *dev,
158 struct device_attribute *attr, char *buf)
160 struct fb_info *fbi = dev_get_drvdata(dev);
161 struct rk_lcdc_driver *dev_drv =
162 (struct rk_lcdc_driver *)fbi->par;
164 fps = dev_drv->ops->fps_mgr(dev_drv, 0, 0);
169 return snprintf(buf, PAGE_SIZE, "fps:%d\n", fps);
173 static ssize_t set_fps(struct device *dev, struct device_attribute *attr,
174 const char *buf, size_t count)
176 struct fb_info *fbi = dev_get_drvdata(dev);
177 struct rk_lcdc_driver *dev_drv =
178 (struct rk_lcdc_driver *)fbi->par;
181 ret = kstrtoint(buf, 0, &fps);
185 ret = dev_drv->ops->fps_mgr(dev_drv, fps, 1);
193 static ssize_t show_fb_win_map(struct device *dev,
194 struct device_attribute *attr, char *buf)
197 struct fb_info *fbi = dev_get_drvdata(dev);
198 struct rk_lcdc_driver *dev_drv =
199 (struct rk_lcdc_driver *)fbi->par;
201 mutex_lock(&dev_drv->fb_win_id_mutex);
203 snprintf(buf, PAGE_SIZE, "fb0:win%d\nfb1:win%d\nfb2:win%d\n",
204 dev_drv->fb0_win_id, dev_drv->fb1_win_id,
205 dev_drv->fb2_win_id);
206 mutex_unlock(&dev_drv->fb_win_id_mutex);
212 static ssize_t set_fb_win_map(struct device *dev, struct device_attribute *attr,
213 const char *buf, size_t count)
215 struct fb_info *fbi = dev_get_drvdata(dev);
216 struct rk_lcdc_driver *dev_drv =
217 (struct rk_lcdc_driver *)fbi->par;
220 ret = kstrtoint(buf, 0, &order);
221 if ((order != FB0_WIN2_FB1_WIN1_FB2_WIN0)
222 && (order != FB0_WIN1_FB1_WIN2_FB2_WIN0)
223 && (order != FB0_WIN2_FB1_WIN0_FB2_WIN1)
224 && (order != FB0_WIN0_FB1_WIN2_FB2_WIN1)
225 && (order != FB0_WIN0_FB1_WIN1_FB2_WIN2)
226 && (order != FB0_WIN1_FB1_WIN0_FB2_WIN2)) {
227 printk(KERN_ERR "un supported map\n"
228 "you can use the following order:\n" "201:\n"
229 "fb0-win1\n" "fb1-win0\n" "fb2-win2\n" "210:\n"
230 "fb0-win0\n" "fb1-win1\n" "fb2-win2\n" "120:\n"
231 "fb0-win0\n" "fb1-win2\n" "fb2-win1\n" "102:\n"
232 "fb0-win2\n" "fb1-win0\n" "fb2-win1\n" "021:\n"
233 "fb0-win1\n" "fb1-win2\n" "fb2-win0\n" "012:\n"
234 "fb0-win2\n" "fb1-win1\n" "fb2-win0\n");
237 dev_drv->ops->fb_win_remap(dev_drv, order);
244 static ssize_t show_dsp_lut(struct device *dev,
245 struct device_attribute *attr, char *buf)
251 static ssize_t set_dsp_lut(struct device *dev, struct device_attribute *attr,
252 const char *buf, size_t count)
255 const char *start = buf;
259 struct fb_info *fbi = dev_get_drvdata(dev);
260 struct rk_lcdc_driver *dev_drv =
261 (struct rk_lcdc_driver *)fbi->par;
263 for (i = 0; i < 256; i++) {
265 dsp_lut[i] = temp + (temp << 8) + (temp << 16); //init by default value
267 //printk("count:%d\n>>%s\n\n",count,start);
268 for (i = 0; i < 256; i++) {
269 space_max = 10; //max space number 10;
270 temp = simple_strtoul(start, NULL, 10);
275 } while ((*start != ' ') && space_max);
283 for (i = 0; i < 16; i++) {
284 for (j = 0; j < 16; j++)
285 printk("0x%08x ", dsp_lut[i * 16 + j]);
289 dev_drv->ops->set_dsp_lut(dev_drv, dsp_lut);
294 static ssize_t show_dsp_cabc(struct device *dev,
295 struct device_attribute *attr, char *buf)
301 static ssize_t set_dsp_cabc(struct device *dev, struct device_attribute *attr,
302 const char *buf, size_t count)
304 struct fb_info *fbi = dev_get_drvdata(dev);
305 struct rk_lcdc_driver *dev_drv =
306 (struct rk_lcdc_driver *)fbi->par;
309 ret = kstrtoint(buf, 0, &mode);
313 ret = dev_drv->ops->set_dsp_cabc(dev_drv, mode);
322 static ssize_t show_hue(struct device *dev,
323 struct device_attribute *attr, char *buf)
329 static ssize_t set_hue(struct device *dev, struct device_attribute *attr,
330 const char *buf, size_t count)
332 struct fb_info *fbi = dev_get_drvdata(dev);
333 struct rk_lcdc_driver *dev_drv =
334 (struct rk_lcdc_driver *)fbi->par;
337 ret = kstrtoint(buf, 0, &hue);
341 ret = dev_drv->ops->set_dsp_hue(dev_drv, hue);
348 static ssize_t show_dsp_bcs(struct device *dev,
349 struct device_attribute *attr, char *buf)
355 static ssize_t set_dsp_bcs(struct device *dev, struct device_attribute *attr,
356 const char *buf, size_t count)
358 struct fb_info *fbi = dev_get_drvdata(dev);
359 struct rk_lcdc_driver *dev_drv =
360 (struct rk_lcdc_driver *)fbi->par;
363 ret = kstrtoint(buf, 0, &bri);
367 ret = dev_drv->ops->set_dsp_bcsh_bcs(dev_drv, bri,con,sat);
374 static struct device_attribute rkfb_attrs[] = {
375 __ATTR(phys_addr, S_IRUGO, show_phys, NULL),
376 __ATTR(virt_addr, S_IRUGO, show_virt, NULL),
377 __ATTR(disp_info, S_IRUGO, show_disp_info, NULL),
378 __ATTR(screen_info, S_IRUGO, show_screen_info, NULL),
379 __ATTR(dual_mode, S_IRUGO, show_dual_mode, NULL),
380 __ATTR(enable, S_IRUGO | S_IWUSR, show_fb_state, set_fb_state),
381 __ATTR(overlay, S_IRUGO | S_IWUSR, show_overlay, set_overlay),
382 __ATTR(fps, S_IRUGO | S_IWUSR, show_fps, set_fps),
383 __ATTR(map, S_IRUGO | S_IWUSR, show_fb_win_map, set_fb_win_map),
384 __ATTR(dsp_lut, S_IRUGO | S_IWUSR, show_dsp_lut, set_dsp_lut),
385 __ATTR(cabc, S_IRUGO | S_IWUSR, show_dsp_cabc, set_dsp_cabc),
386 __ATTR(hue, S_IRUGO | S_IWUSR, show_hue, set_hue),
387 __ATTR(bcs, S_IRUGO | S_IWUSR, show_dsp_bcs, set_dsp_bcs),
390 int rkfb_create_sysfs(struct fb_info *fbi)
394 for (t = 0; t < ARRAY_SIZE(rkfb_attrs); t++) {
395 r = device_create_file(fbi->dev, &rkfb_attrs[t]);
397 dev_err(fbi->dev, "failed to create sysfs " "file\n");
405 void rkfb_remove_sysfs(struct rk_fb *rk_fb)
409 for (i = 0; i < rk_fb->num_fb; i++) {
410 for (t = 0; t < ARRAY_SIZE(rkfb_attrs); t++)
411 device_remove_file(rk_fb->fb[i]->dev, &rkfb_attrs[t]);