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)
297 struct fb_info *fbi = dev_get_drvdata(dev);
298 struct rk_lcdc_driver *dev_drv =
299 (struct rk_lcdc_driver *)fbi->par;
301 return snprintf(buf, PAGE_SIZE, "cabc mode=%d\n",
306 static ssize_t set_dsp_cabc(struct device *dev, struct device_attribute *attr,
307 const char *buf, size_t count)
309 struct fb_info *fbi = dev_get_drvdata(dev);
310 struct rk_lcdc_driver *dev_drv =
311 (struct rk_lcdc_driver *)fbi->par;
314 ret = kstrtoint(buf, 0, &mode);
318 ret = dev_drv->ops->set_dsp_cabc(dev_drv, mode);
326 static ssize_t show_dsp_bcsh(struct device *dev,
327 struct device_attribute *attr, char *buf)
329 struct fb_info *fbi = dev_get_drvdata(dev);
330 struct rk_lcdc_driver *dev_drv =
331 (struct rk_lcdc_driver *)fbi->par;
332 int brightness, contrast, sat_con, sin_hue, cos_hue;
333 if(dev_drv->ops->get_dsp_bcsh_bcs) {
334 brightness = dev_drv->ops->get_dsp_bcsh_bcs(dev_drv, BRIGHTNESS);
335 contrast = dev_drv->ops->get_dsp_bcsh_bcs(dev_drv, CONTRAST);
336 sat_con = dev_drv->ops->get_dsp_bcsh_bcs(dev_drv, SAT_CON);
338 if(dev_drv->ops->get_dsp_bcsh_hue) {
339 sin_hue = dev_drv->ops->get_dsp_bcsh_hue(dev_drv,H_SIN);
340 cos_hue = dev_drv->ops->get_dsp_bcsh_hue(dev_drv,H_COS);
342 snprintf(buf, PAGE_SIZE, "brightness:%4d,contrast:%4d,sat_con:%4d,"
343 "sin_hue:%4d,cos_hue:%4d\n",
344 brightness, contrast,sat_con,sin_hue,cos_hue);
348 static ssize_t set_dsp_bcsh(struct device *dev, struct device_attribute *attr,
349 const char *buf, size_t count)
351 struct fb_info *fbi = dev_get_drvdata(dev);
352 struct rk_lcdc_driver *dev_drv =
353 (struct rk_lcdc_driver *)fbi->par;
354 int brightness, contrast, sat_con, ret, sin_hue, cos_hue;
356 if (!strncmp(buf, "open", 4)) {
357 if(dev_drv->ops->open_bcsh)
358 ret = dev_drv->ops->open_bcsh(dev_drv, 1);
361 } else if (!strncmp(buf, "close", 5)) {
362 if(dev_drv->ops->open_bcsh)
363 ret = dev_drv->ops->open_bcsh(dev_drv, 0);
366 } else if (!strncmp(buf, "brightness", 10)) {
367 sscanf(buf, "brightness %d", &brightness);
368 if (unlikely(brightness > 255)) {
369 dev_err(fbi->dev,"brightness should be [0:255],now=%d\n\n",brightness);
372 if(dev_drv->ops->set_dsp_bcsh_bcs)
373 ret = dev_drv->ops->set_dsp_bcsh_bcs(dev_drv, BRIGHTNESS,brightness);
376 } else if (!strncmp(buf, "contrast", 8)) {
377 sscanf(buf, "contrast %d", &contrast);
378 if (unlikely(contrast > 510)) {
379 dev_err(fbi->dev,"contrast should be [0:510],now=%d\n",contrast);
382 if(dev_drv->ops->set_dsp_bcsh_bcs)
383 ret = dev_drv->ops->set_dsp_bcsh_bcs(dev_drv, CONTRAST,contrast);
386 } else if (!strncmp(buf, "sat_con", 7)) {
387 sscanf(buf, "sat_con %d", &sat_con);
388 if (unlikely(sat_con > 1015)) {
389 dev_err(fbi->dev,"sat_con should be [0:1015],now=%d\n",sat_con);
392 if(dev_drv->ops->set_dsp_bcsh_bcs)
393 ret = dev_drv->ops->set_dsp_bcsh_bcs(dev_drv, SAT_CON,sat_con);
396 } else if (!strncmp(buf, "hue", 3)) {
397 sscanf(buf, "hue %d %d", &sin_hue,&cos_hue);
398 if (unlikely(sin_hue > 511 || cos_hue > 511)) {
399 dev_err(fbi->dev,"sin_hue=%d,cos_hue=%d\n",sin_hue,cos_hue);
401 if(dev_drv->ops->set_dsp_bcsh_hue)
402 ret = dev_drv->ops->set_dsp_bcsh_hue(dev_drv,sin_hue,cos_hue);
406 printk("format error\n");
415 static ssize_t show_scale(struct device *dev,
416 struct device_attribute *attr, char *buf)
418 struct fb_info *fbi = dev_get_drvdata(dev);
419 struct rk_lcdc_driver *dev_drv =
420 (struct rk_lcdc_driver *)fbi->par;
421 struct rk_screen *screen = dev_drv->cur_screen;
422 return snprintf(buf, PAGE_SIZE, "xscale=%d yscale=%d\nleft=%d top=%d right=%d bottom=%d\n",
423 (screen->overscan.left + screen->overscan.right)/2,
424 (screen->overscan.top + screen->overscan.bottom)/2,
425 screen->overscan.left, screen->overscan.top,
426 screen->overscan.right, screen->overscan.bottom);
429 static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
430 const char *buf, size_t count)
432 struct fb_info *fbi = dev_get_drvdata(dev);
433 struct rk_lcdc_driver *dev_drv =
434 (struct rk_lcdc_driver *)fbi->par;
435 struct rk_screen *screen = dev_drv->cur_screen;
436 u32 left, top, right, bottom;
438 if (!strncmp(buf, "overscan", 8)) {
439 sscanf(buf, "overscan %d,%d,%d,%d", &left, &top, &right, &bottom);
440 if (left > 0 && left <= 100)
441 screen->overscan.left = left;
442 if (top > 0 && top <= 100)
443 screen->overscan.top = top;
444 if (right > 0 && right <= 100)
445 screen->overscan.right = right;
446 if (bottom > 0 && bottom <= 100)
447 screen->overscan.bottom = bottom;
448 } else if (!strncmp(buf, "left", 4)) {
449 sscanf(buf, "left=%d", &left);
450 if (left > 0 && left <= 100)
451 screen->overscan.left = left;
452 } else if (!strncmp(buf, "top", 3)) {
453 sscanf(buf, "top=%d", &top);
454 if (top > 0 && top <= 100)
455 screen->overscan.top = top;
456 } else if (!strncmp(buf, "right", 5)) {
457 sscanf(buf, "right=%d", &right);
458 if (right > 0 && right <= 100)
459 screen->overscan.right = right;
460 } else if (!strncmp(buf, "bottom", 6)) {
461 sscanf(buf, "bottom=%d", &bottom);
462 if (bottom > 0 && bottom <= 100)
463 screen->overscan.bottom = bottom;
464 } else if (!strncmp(buf, "xscale", 6)) {
465 sscanf(buf, "xscale=%d", &left);
466 if (left > 0 && left <= 100) {
467 screen->overscan.left = left;
468 screen->overscan.right = left;
470 } else if (!strncmp(buf, "yscale", 6)) {
471 sscanf(buf, "yscale=%d", &left);
472 if (left > 0 && left <= 100) {
473 screen->overscan.top = left;
474 screen->overscan.bottom = left;
477 sscanf(buf, "%d", &left);
478 if (left > 0 && left <= 100) {
479 screen->overscan.left = left;
480 screen->overscan.right = left;
481 screen->overscan.top = left;
482 screen->overscan.bottom = left;
485 // printk("%d %d %d %d\n", dev_drv->overscan.left, dev_drv->overscan.top, dev_drv->overscan.right, dev_drv->overscan.bottom);
486 dev_drv->ops->load_screen(dev_drv, 1);
487 dev_drv->ops->cfg_done(dev_drv);
491 static struct device_attribute rkfb_attrs[] = {
492 __ATTR(phys_addr, S_IRUGO, show_phys, NULL),
493 __ATTR(virt_addr, S_IRUGO, show_virt, NULL),
494 __ATTR(disp_info, S_IRUGO, show_disp_info, NULL),
495 __ATTR(screen_info, S_IRUGO, show_screen_info, NULL),
496 __ATTR(dual_mode, S_IRUGO, show_dual_mode, NULL),
497 __ATTR(enable, S_IRUGO | S_IWUSR, show_fb_state, set_fb_state),
498 __ATTR(overlay, S_IRUGO | S_IWUSR, show_overlay, set_overlay),
499 __ATTR(fps, S_IRUGO | S_IWUSR, show_fps, set_fps),
500 __ATTR(map, S_IRUGO | S_IWUSR, show_fb_win_map, set_fb_win_map),
501 __ATTR(dsp_lut, S_IRUGO | S_IWUSR, show_dsp_lut, set_dsp_lut),
502 __ATTR(cabc, S_IRUGO | S_IWUSR, show_dsp_cabc, set_dsp_cabc),
503 __ATTR(bcsh, S_IRUGO | S_IWUSR, show_dsp_bcsh, set_dsp_bcsh),
504 __ATTR(scale, S_IRUGO | S_IWUSR, show_scale, set_scale),
507 int rkfb_create_sysfs(struct fb_info *fbi)
511 for (t = 0; t < ARRAY_SIZE(rkfb_attrs); t++) {
512 r = device_create_file(fbi->dev, &rkfb_attrs[t]);
514 dev_err(fbi->dev, "failed to create sysfs " "file\n");
522 void rkfb_remove_sysfs(struct rk_fb *rk_fb)
526 for (i = 0; i < rk_fb->num_fb; i++) {
527 for (t = 0; t < ARRAY_SIZE(rkfb_attrs); t++)
528 device_remove_file(rk_fb->fb[i]->dev, &rkfb_attrs[t]);