video: rockchip: sysfs: fixup dump_buf node
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / rkfb_sysfs.c
1 /*
2  * linux/drivers/video/rockchip/rkfb-sysfs.c
3  *
4  * Copyright (C) 2012 Rockchip Corporation
5  * Author: yxj<yxj@rock-chips.com>
6  *
7  * Some code and ideas taken from
8  *drivers/video/omap2/omapfb/omapfb-sys.c
9  *driver by Tomi Valkeinen.
10  *
11  *
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.
15  *
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
19  * more details.
20  *
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/>.
23  */
24
25 #include <linux/fb.h>
26 #include <linux/namei.h>
27 #include <linux/sysfs.h>
28 #include <linux/device.h>
29 #include <linux/uaccess.h>
30 #include <linux/platform_device.h>
31 #include <linux/kernel.h>
32 #include <linux/mm.h>
33 #include <linux/vmalloc.h>
34 #include <asm/div64.h>
35 #include <linux/rk_screen.h>
36 #include <linux/rk_fb.h>
37 #if defined(CONFIG_ION_ROCKCHIP)
38 #include <linux/rockchip_ion.h>
39 #endif
40 #include "bmp_helper.h"
41 #include <linux/delay.h>
42 struct rkfb_sys_trace {
43         int num_frames;
44         int count_frame;
45         int mask_win;
46         int mask_area;
47         bool is_bmp;
48         bool is_append;
49 };
50 #define DUMP_BUF_PATH           "/data/dmp_buf"
51
52 static char *get_format_str(enum data_format format)
53 {
54         switch (format) {
55         case ARGB888:
56                 return "ARGB888";
57         case RGB888:
58                 return "RGB888";
59         case RGB565:
60                 return "RGB565";
61         case YUV420:
62         case YUV420_NV21:
63                 return "YUV420";
64         case YUV422:
65                 return "YUV422";
66         case YUV444:
67                 return "YUV444";
68         case YUV420_A:
69                 return "YUV420_A";
70         case YUV422_A:
71                 return "YUV422_A";
72         case YUV444_A:
73                 return "YUV444_A";
74         case XRGB888:
75                 return "XRGB888";
76         case XBGR888:
77                 return "XBGR888";
78         case ABGR888:
79                 return "ABGR888";
80         case FBDC_RGB_565:
81                 return "FBDC_RGB_565";
82         case FBDC_ARGB_888:
83                 return "FBDC_ARGB_888";
84         case FBDC_RGBX_888:
85                 return "FBDC_RGBX_888";
86         default:
87                 return "invalid";
88         }
89 }
90
91 static ssize_t show_screen_info(struct device *dev,
92                                 struct device_attribute *attr, char *buf)
93 {
94         struct fb_info *fbi = dev_get_drvdata(dev);
95         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
96         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
97         struct rk_screen *screen = dev_drv->cur_screen;
98         int fps = 0;
99         u32 x = screen->mode.left_margin + screen->mode.right_margin +
100                 screen->mode.xres + screen->mode.hsync_len;
101         u32 y = screen->mode.upper_margin + screen->mode.lower_margin +
102                 screen->mode.yres + screen->mode.vsync_len;
103         u64 ft = (u64)x * y * (dev_drv->pixclock);
104
105         if (ft > 0)
106                 fps = div64_u64(1000000000000llu, ft);
107         return snprintf(buf, PAGE_SIZE,
108                         "xres:%d\nyres:%d\nfps:%d\ntype:%d\ninterlace:%d\n",
109                         screen->mode.xres, screen->mode.yres,
110                         fps, screen->type, screen->mode.vmode);
111 }
112
113 static ssize_t show_disp_info(struct device *dev,
114                               struct device_attribute *attr, char *buf)
115 {
116         struct fb_info *fbi = dev_get_drvdata(dev);
117         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
118         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
119         int win_id = dev_drv->ops->fb_get_win_id(dev_drv, fbi->fix.id);
120
121         if (dev_drv->ops->get_disp_info)
122                 return dev_drv->ops->get_disp_info(dev_drv, buf, win_id);
123
124         return 0;
125 }
126
127 static void fill_buffer(void *handle, void *vaddr, int size)
128 {
129         struct file *filp = handle;
130
131         if (filp)
132                 vfs_write(filp, vaddr, size, &filp->f_pos);
133 }
134
135 static void read_buffer(void *handle, void *vaddr, int size, loff_t pos)
136 {
137         struct file *filp = handle;
138
139         if (filp)
140                 vfs_read(filp, vaddr, size, &pos);
141 }
142
143 static int dump_win(struct ion_client *ion_client,
144                     struct ion_handle *ion_handle, phys_addr_t phys_addr,
145                     int width, int height, u8 data_format, uint32_t frameid,
146                     int win_id, int area_id, bool is_bmp, bool is_append)
147 {
148         void __iomem *vaddr = NULL;
149         struct file *filp;
150         mm_segment_t old_fs;
151         char name[100];
152         int flags;
153         int bits;
154
155         switch (data_format) {
156         case XRGB888:
157         case XBGR888:
158         case ARGB888:
159         case ABGR888:
160         case FBDC_RGBX_888:
161                 bits = 32;
162                 break;
163         case YUV444_A:
164         case YUV444:
165         case RGB888:
166         case FBDC_ARGB_888:
167                 bits = 24;
168                 break;
169         case RGB565:
170         case FBDC_RGB_565:
171         case YUV422:
172         case YUV422_A:
173                 bits = 16;
174                 break;
175         case YUV420_A:
176         case YUV420:
177         case YUV420_NV21:
178                 bits = 12;
179                 break;
180         default:
181                 return 0;
182         }
183
184         if (ion_handle) {
185                 vaddr = ion_map_kernel(ion_client, ion_handle);
186         } else if (phys_addr) {
187                 unsigned long start;
188                 unsigned int nr_pages;
189                 struct page **pages;
190                 int i = 0;
191
192                 start = phys_addr;
193                 nr_pages = roundup(width * height * (bits >> 3), PAGE_SIZE);
194                 nr_pages /= PAGE_SIZE;
195                 pages = kzalloc(sizeof(struct page) * nr_pages, GFP_KERNEL);
196                 while (i < nr_pages) {
197                         pages[i] = phys_to_page(start);
198                         start += PAGE_SIZE;
199                         i++;
200                 }
201                 vaddr = vmap(pages, nr_pages, VM_MAP,
202                              pgprot_writecombine(PAGE_KERNEL));
203                 if (!vaddr) {
204                         pr_err("failed to vmap phy addr %lx\n",
205                                start);
206                         return -1;
207                 }
208         } else {
209                 return 0;
210         }
211
212         flags = O_RDWR | O_CREAT | O_NONBLOCK;
213         if (is_append) {
214                 snprintf(name, 100, "%s/append_win%d_%d_%dx%d_%s.%s",
215                          DUMP_BUF_PATH, win_id, area_id, width, height,
216                          get_format_str(data_format), is_bmp ? "bmp" : "bin");
217                 flags |= O_APPEND;
218         } else {
219                 snprintf(name, 100, "%s/frame%d_win%d_%d_%dx%d_%s.%s",
220                          DUMP_BUF_PATH, frameid, win_id, area_id, width, height,
221                          get_format_str(data_format), is_bmp ? "bmp" : "bin");
222         }
223
224         pr_info("dump win == > %s\n", name);
225         filp = filp_open(name, flags, 0x600);
226         if (!filp)
227                 printk("fail to create %s\n", name);
228
229         old_fs = get_fs();
230         set_fs(KERNEL_DS);
231
232         if (is_bmp)
233                 bmpencoder(vaddr, width, height,
234                            data_format, filp, fill_buffer);
235         else
236                 fill_buffer(filp, vaddr, width * height * bits >> 3);
237
238         set_fs(old_fs);
239
240         if (ion_handle)
241                 ion_unmap_kernel(ion_client, ion_handle);
242         else if (vaddr)
243                 vunmap(vaddr);
244
245         filp_close(filp, NULL);
246
247         return 0;
248 }
249
250 static ssize_t show_dump_buffer(struct device *dev,
251                               struct device_attribute *attr, char *buf)
252 {
253         ssize_t size;
254
255         size = snprintf(buf, PAGE_SIZE,
256                         "bmp       -- dump buffer to bmp image\n"
257                         "             can't support dump to single file\n"
258                         "bin       -- dump buffer to bin image\n"
259                         "multi     -- each dump will create new file\n"
260                         "             only works on trace context\n"
261                         "win=num   -- mask win to dump, default mask all\n"
262                         "             win=1, will dump win1 buffer\n"
263                         "             win=23, will dump win2 area3 buffer\n"
264                         "trace=num -- trace num frames buffer dump\n"
265                         "             this option will block buffer switch\n"
266                         "             so recommend use with bin and win=xx\n"
267                         "\nExample:\n"
268                         "echo bmp > dump_buf; -- dump current buf to bmp file\n"
269                         "echo bin > dump_buf; -- dump current buf to bin file\n"
270                         "echo trace=50:win=1:win=23 > dump_buf\n"
271                         "         -- dump 50 frames, dump win1 and win2 area3\n"
272                         "         -- dump all buffer to single file\n"
273                         "You can found dump files at %s\n"
274                         , DUMP_BUF_PATH);
275
276         return size;
277 }
278
279 void trace_buffer_dump(struct device *dev, struct rk_lcdc_driver *dev_drv)
280 {
281         struct rk_fb *rk_fb = dev_get_drvdata(dev);
282         struct rk_fb_reg_data *front_regs;
283         struct rk_fb_reg_win_data *win_data;
284         struct rk_fb_reg_area_data *area_data;
285         struct rkfb_sys_trace *trace = dev_drv->trace_buf;
286         int i, j;
287
288         if (!trace)
289                 return;
290         if (trace->num_frames <= trace->count_frame)
291                 return;
292
293         if (!dev_drv->front_regs)
294                 return;
295         front_regs = dev_drv->front_regs;
296
297         for (i = 0; i < front_regs->win_num; i++) {
298                 if (trace->mask_win && !(trace->mask_win & (1 << i)))
299                         continue;
300                 for (j = 0; j < RK_WIN_MAX_AREA; j++) {
301                         win_data = &front_regs->reg_win_data[i];
302                         area_data = &win_data->reg_area_data[j];
303                         if (trace->mask_area && !(trace->mask_area & (1 << j)))
304                                 continue;
305
306                         dump_win(rk_fb->ion_client, area_data->ion_handle,
307                                  area_data->smem_start,
308                                  area_data->xvir, area_data->yvir,
309                                  area_data->data_format, trace->count_frame,
310                                  i, j, trace->is_bmp, trace->is_append);
311                 }
312         }
313         trace->count_frame++;
314 }
315
316 static ssize_t set_dump_buffer(struct device *dev,
317                                struct device_attribute *attr,
318                                const char *buf, size_t count)
319 {
320         struct fb_info *fbi = dev_get_drvdata(dev);
321         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
322         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
323         struct rk_fb *rk_fb = dev_get_drvdata(fbi->device);
324         struct rk_fb_reg_data *front_regs;
325         struct rk_fb_reg_win_data *win_data;
326         struct rk_fb_reg_area_data *area_data;
327         struct rkfb_sys_trace *trace;
328         struct dentry *dentry;
329         struct path path;
330         int err = 0;
331         int num_frames = 0;
332         int mask_win = 0;
333         int mask_area = 0;
334         bool is_bmp = false;
335         bool is_append = true;
336         char *p;
337         int i, j;
338
339         if (!rk_fb->ion_client)
340                 return 0;
341
342         if (!dev_drv->trace_buf) {
343                 dev_drv->trace_buf = devm_kmalloc(dev_drv->dev,
344                                                   sizeof(struct rkfb_sys_trace),
345                                                   GFP_KERNEL);
346                 if (!dev_drv->trace_buf)
347                         return -ENOMEM;
348         }
349         trace = dev_drv->trace_buf;
350         /*
351          * Stop buffer trace.
352          */
353         trace->num_frames = 0;
354
355         while ((p = strsep((char **)&buf, ":")) != NULL) {
356                 if (!*p)
357                         continue;
358                 if (!strncmp(p, "trace=", 6)) {
359                         if (kstrtoint(p + 6, 0, &num_frames))
360                                 dev_err(dev, "can't found trace frames\n");
361                         continue;
362                 }
363                 if (!strncmp(p, "win=", 4)) {
364                         int win;
365
366                         if (kstrtoint(p + 4, 0, &win))
367                                 dev_err(dev, "can't found trace frames\n");
368                         if (win < 10) {
369                                mask_win |= 1 << win;
370                         } else {
371                                 mask_win |= 1 << (win / 10);
372                                 mask_area |= 1 << (win % 10);
373                         }
374
375                         continue;
376                 }
377                 if (!strncmp(p, "bmp", 3)) {
378                         is_bmp = true;
379                         is_append = false;
380                         continue;
381                 }
382                 if (!strncmp(p, "bin", 3)) {
383                         is_bmp = false;
384                         continue;
385                 }
386                 if (!strncmp(p, "multi", 5)) {
387                         is_append = false;
388                         continue;
389                 }
390
391                 dev_err(dev, "unknown option %s\n", p);
392         }
393
394         dentry = kern_path_create(AT_FDCWD, DUMP_BUF_PATH, &path,
395                                   LOOKUP_DIRECTORY);
396         if (!IS_ERR(dentry)) {
397                 err = vfs_mkdir(path.dentry->d_inode, dentry, 700);
398                 if (err)
399                         dev_err(dev, "can't create %s err%d\n",
400                                 DUMP_BUF_PATH, err);
401                 done_path_create(&path, dentry);
402         } else if (PTR_ERR(dentry) != -EEXIST) {
403                 dev_err(dev, "can't create PATH %s err%d\n",
404                                 DUMP_BUF_PATH, err);
405                 return PTR_ERR(dentry);
406         }
407
408         if (!num_frames) {
409                 mutex_lock(&dev_drv->front_lock);
410
411                 if (!dev_drv->front_regs) {
412                         u16 xact, yact;
413                         int data_format;
414                         u32 dsp_addr;
415                         int ymirror;
416
417                         mutex_unlock(&dev_drv->front_lock);
418
419                         if (dev_drv->ops->get_dspbuf_info)
420                                 dev_drv->ops->get_dspbuf_info(dev_drv, &xact,
421                                                 &yact, &data_format, &dsp_addr,
422                                                 &ymirror);
423
424                         dump_win(NULL, NULL, dsp_addr, xact, yact, data_format,
425                                  0, 0, 0, is_bmp, false);
426                         goto out;
427                 }
428                 front_regs = kmalloc(sizeof(*front_regs), GFP_KERNEL);
429                 if (!front_regs)
430                         return -ENOMEM;
431                 memcpy(front_regs, dev_drv->front_regs, sizeof(*front_regs));
432
433                 for (i = 0; i < front_regs->win_num; i++) {
434                         if (mask_win && !(mask_win & (1 << i)))
435                                 continue;
436                         for (j = 0; j < RK_WIN_MAX_AREA; j++) {
437                                 if (mask_area && !(mask_area & (1 << j)))
438                                         continue;
439                                 win_data = &front_regs->reg_win_data[i];
440                                 area_data = &win_data->reg_area_data[j];
441                                 if (area_data->ion_handle)
442                                         ion_handle_get(area_data->ion_handle);
443                         }
444                 }
445
446                 for (i = 0; i < front_regs->win_num; i++) {
447                         if (mask_win && !(mask_win & (1 << i)))
448                                 continue;
449                         for (j = 0; j < RK_WIN_MAX_AREA; j++) {
450                                 if (mask_area && !(mask_area & (1 << j)))
451                                         continue;
452
453                                 win_data = &front_regs->reg_win_data[i];
454                                 area_data = &win_data->reg_area_data[j];
455
456                                 dump_win(rk_fb->ion_client,
457                                          area_data->ion_handle,
458                                          area_data->smem_start,
459                                          area_data->xvir, area_data->yvir,
460                                          area_data->data_format,
461                                          0, i, j, is_bmp, false);
462                                 if (area_data->ion_handle)
463                                         ion_handle_put(area_data->ion_handle);
464                         }
465                 }
466
467                 kfree(front_regs);
468
469                 mutex_unlock(&dev_drv->front_lock);
470         } else {
471                 trace->num_frames = num_frames;
472                 trace->count_frame = 0;
473                 trace->is_bmp = is_bmp;
474                 trace->is_append = is_append;
475                 trace->mask_win = mask_win;
476                 trace->mask_area = mask_area;
477         }
478 out:
479
480         return count;
481 }
482
483 static ssize_t show_dsp_buffer(struct device *dev,
484                                struct device_attribute *attr, char *buf)
485 {
486         ssize_t size;
487
488         size = snprintf(buf, PAGE_SIZE,
489                         "you can display a picture store in "
490                         "/data/fb0.bin use the following cmd:\n"
491                         "echo n xsize ysize format > dsp_buf\n"
492                         "n: picture number"
493                         "xsize: picture horizontal size\n"
494                         "ysize: picture vertical size\n"
495                         "format:\n"
496                         "    RGBA=1,RGBX=2,RGB=3,YUV420SP=17");
497
498         return size;
499 }
500 extern int __close_fd(struct files_struct *files, unsigned fd);
501
502 static ssize_t set_dsp_buffer(struct device *dev,
503                                struct device_attribute *attr,
504                                const char *buf, size_t count)
505 {
506         struct fb_info *fbi = dev_get_drvdata(dev);
507         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
508         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
509         struct rk_fb *rk_fb = dev_get_drvdata(fbi->device);
510         struct file *filp;
511         mm_segment_t old_fs;
512         int width, height, frame_num;
513         int i, j, flags, fd;
514         const char *start = buf;
515         struct ion_handle *handle = NULL;
516         char __iomem *screen_base;
517         struct rk_fb_win_cfg_data win_config;
518         struct rk_screen *screen = dev_drv->cur_screen;
519         int space_max = 10;
520         int format;
521         size_t mem_size = 0;
522         char *name = "/data/fb0.bin";
523         struct sync_fence *acq_fence;
524         struct files_struct *files = current->files;
525
526         frame_num = simple_strtoul(start, NULL, 10);
527         do {
528                 start++;
529                 space_max--;
530         } while ((*start != ' ') && space_max);
531         start++;
532         width = simple_strtoul(start, NULL, 10);
533         do {
534                 start++;
535                 space_max--;
536         } while ((*start != ' ') && space_max);
537         start++;
538         height = simple_strtoul(start, NULL, 10);
539
540         do {
541                 start++;
542                 space_max--;
543         } while ((*start != ' ') && space_max);
544         start++;
545         format = simple_strtoul(start, NULL, 10);
546
547         pr_info("frame_num=%d,w=%d,h=%d,file=%s,format=%d\n",
548                 frame_num, width, height, name, format);
549         flags = O_RDWR | O_CREAT | O_NONBLOCK;
550         filp = filp_open(name, flags, 0x600);
551         if (!filp)
552                 pr_err("fail to create %s\n", name);
553
554         old_fs = get_fs();
555         set_fs(KERNEL_DS);
556
557         mem_size = width * height * 4 * frame_num;
558         if (dev_drv->iommu_enabled)
559                 handle = ion_alloc(rk_fb->ion_client, mem_size, 0,
560                                    ION_HEAP_SYSTEM_MASK, 0);
561         else
562                 handle = ion_alloc(rk_fb->ion_client, mem_size, 0,
563                                    ION_HEAP_TYPE_DMA_MASK, 0);
564         if (IS_ERR(handle)) {
565                 pr_err("failed to ion_alloc:%ld\n", PTR_ERR(handle));
566                 return -ENOMEM;
567         }
568         fd = ion_share_dma_buf_fd(rk_fb->ion_client, handle);
569         if (fd < 0) {
570                 pr_err("ion_share_dma_buf_fd failed, fd=%d\n", fd);
571                 return fd;
572         }
573         screen_base = ion_map_kernel(rk_fb->ion_client, handle);
574         read_buffer(filp, screen_base, mem_size, 0);
575
576         memset(&win_config, 0, sizeof(win_config));
577         win_config.wait_fs = 0;
578         win_config.win_par[0].win_id = 0;
579         win_config.win_par[0].z_order = 0;
580         win_config.win_par[0].area_par[0].data_format = format;
581         win_config.win_par[0].area_par[0].ion_fd = fd;
582         win_config.win_par[0].area_par[0].x_offset = 0;
583         win_config.win_par[0].area_par[0].y_offset = 0;
584         win_config.win_par[0].area_par[0].xpos = 0;
585         win_config.win_par[0].area_par[0].ypos = 0;
586         win_config.win_par[0].area_par[0].xsize = screen->mode.xres;
587         win_config.win_par[0].area_par[0].ysize = screen->mode.yres;
588         win_config.win_par[0].area_par[0].xact = width;
589         win_config.win_par[0].area_par[0].yact = height;
590         win_config.win_par[0].area_par[0].xvir = width;
591         win_config.win_par[0].area_par[0].yvir = height;
592
593         for (i = 0; i < frame_num; i++) {
594                 win_config.win_par[0].area_par[0].y_offset = height * i;
595                 fbi->fbops->fb_ioctl(fbi, RK_FBIOSET_CONFIG_DONE,
596                                      (unsigned long)(&win_config));
597                 for (j = 0; j < RK_MAX_BUF_NUM; j++) {
598                         if (win_config.rel_fence_fd[j] > 0) {
599                                 acq_fence =
600                                 sync_fence_fdget(win_config.rel_fence_fd[j]);
601                                 sync_fence_put(acq_fence);
602                         }
603                 }
604
605                 if (win_config.ret_fence_fd > 0) {
606                         acq_fence =
607                         sync_fence_fdget(win_config.ret_fence_fd);
608                         sync_fence_put(acq_fence);
609                 }
610         }
611
612         ion_unmap_kernel(rk_fb->ion_client, handle);
613         ion_free(rk_fb->ion_client, handle);
614         __close_fd(files, fd);
615
616         set_fs(old_fs);
617         filp_close(filp, NULL);
618
619         return count;
620 }
621
622 static ssize_t show_phys(struct device *dev,
623                          struct device_attribute *attr, char *buf)
624 {
625         struct fb_info *fbi = dev_get_drvdata(dev);
626
627         return snprintf(buf, PAGE_SIZE, "0x%lx-----0x%x\n",
628                         fbi->fix.smem_start, fbi->fix.smem_len);
629 }
630
631 static ssize_t show_virt(struct device *dev,
632                          struct device_attribute *attr, char *buf)
633 {
634         struct fb_info *fbi = dev_get_drvdata(dev);
635
636         return snprintf(buf, PAGE_SIZE, "0x%p-----0x%x\n",
637                         fbi->screen_base, fbi->fix.smem_len);
638 }
639
640 static ssize_t show_fb_state(struct device *dev,
641                              struct device_attribute *attr, char *buf)
642 {
643         struct fb_info *fbi = dev_get_drvdata(dev);
644         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
645         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
646
647         int win_id = dev_drv->ops->fb_get_win_id(dev_drv, fbi->fix.id);
648         int state = dev_drv->ops->get_win_state(dev_drv, win_id, 0);
649
650         return snprintf(buf, PAGE_SIZE, "%s\n", state ? "enabled" : "disabled");
651 }
652
653 static ssize_t show_dual_mode(struct device *dev,
654                               struct device_attribute *attr, char *buf)
655 {
656         struct fb_info *fbi = dev_get_drvdata(dev);
657         struct rk_fb *rk_fb = dev_get_drvdata(fbi->device);
658         int mode = rk_fb->disp_mode;
659
660         return snprintf(buf, PAGE_SIZE, "%d\n", mode);
661 }
662
663 static ssize_t set_fb_state(struct device *dev, struct device_attribute *attr,
664                             const char *buf, size_t count)
665 {
666         struct fb_info *fbi = dev_get_drvdata(dev);
667         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
668         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
669         int win_id = dev_drv->ops->fb_get_win_id(dev_drv, fbi->fix.id);
670         int state;
671         int ret;
672
673         ret = kstrtoint(buf, 0, &state);
674         if (ret)
675                 return ret;
676         dev_drv->ops->open(dev_drv, win_id, state);
677         if (state) {
678                 dev_drv->ops->set_par(dev_drv, win_id);
679                 dev_drv->ops->pan_display(dev_drv, win_id);
680                 dev_drv->ops->cfg_done(dev_drv);
681         }
682         return count;
683 }
684
685 static ssize_t show_overlay(struct device *dev,
686                             struct device_attribute *attr, char *buf)
687 {
688         struct fb_info *fbi = dev_get_drvdata(dev);
689         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
690         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
691         int ovl = 0;
692
693         if (dev_drv->ops->ovl_mgr)
694                 ovl = dev_drv->ops->ovl_mgr(dev_drv, 0, 0);
695
696         if (ovl < 0)
697                 return ovl;
698
699         return snprintf(buf, PAGE_SIZE, "%s\n",
700                         ovl ? "win0 on the top of win1" :
701                         "win1 on the top of win0");
702 }
703
704 static ssize_t set_overlay(struct device *dev, struct device_attribute *attr,
705                            const char *buf, size_t count)
706 {
707         struct fb_info *fbi = dev_get_drvdata(dev);
708         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
709         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
710         u32 ovl;
711         int ret;
712
713         ret = kstrtou32(buf, 0, &ovl);
714         if (ret)
715                 return ret;
716         if (dev_drv->ops->ovl_mgr)
717                 ret = dev_drv->ops->ovl_mgr(dev_drv, ovl, 1);
718         if (ret < 0)
719                 return ret;
720
721         return count;
722 }
723
724 static ssize_t show_fps(struct device *dev,
725                         struct device_attribute *attr, char *buf)
726 {
727         struct fb_info *fbi = dev_get_drvdata(dev);
728         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
729         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
730         int fps = 0;
731
732         if (dev_drv->ops->fps_mgr)
733                 fps = dev_drv->ops->fps_mgr(dev_drv, 0, 0);
734         if (fps < 0)
735                 return fps;
736
737         return snprintf(buf, PAGE_SIZE, "fps:%d\n", fps);
738 }
739
740 static ssize_t set_fps(struct device *dev, struct device_attribute *attr,
741                        const char *buf, size_t count)
742 {
743         struct fb_info *fbi = dev_get_drvdata(dev);
744         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
745         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
746         struct rk_screen *screen = dev_drv->cur_screen;
747         u32 fps, origin_fps;
748         int ret;
749
750         ret = kstrtou32(buf, 0, &fps);
751         if (ret)
752                 return ret;
753
754         origin_fps = rk_fb_calc_fps(screen, dev_drv->pixclock);
755
756         /*
757          * use too low or too high fps would make screen abnormal,
758          * and maybe can't recovery, so limit the fps.
759          */
760         if (fps <= 40 || fps > origin_fps)
761                 fps = origin_fps;
762
763         if (dev_drv->ops->fps_mgr)
764                 ret = dev_drv->ops->fps_mgr(dev_drv, fps, 1);
765         if (ret < 0)
766                 return ret;
767
768         return count;
769 }
770
771 static ssize_t show_fb_win_map(struct device *dev,
772                                struct device_attribute *attr, char *buf)
773 {
774         int ret;
775         struct fb_info *fbi = dev_get_drvdata(dev);
776         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
777         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
778
779         mutex_lock(&dev_drv->fb_win_id_mutex);
780         ret =
781             snprintf(buf, PAGE_SIZE, "fb0:win%d\nfb1:win%d\nfb2:win%d\n",
782                      dev_drv->fb0_win_id, dev_drv->fb1_win_id,
783                      dev_drv->fb2_win_id);
784         mutex_unlock(&dev_drv->fb_win_id_mutex);
785
786         return ret;
787 }
788
789 static ssize_t set_fb_win_map(struct device *dev, struct device_attribute *attr,
790                               const char *buf, size_t count)
791 {
792         struct fb_info *fbi = dev_get_drvdata(dev);
793         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
794         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
795         u32 order;
796         int ret;
797
798         ret = kstrtou32(buf, 0, &order);
799         if ((order != FB0_WIN2_FB1_WIN1_FB2_WIN0) &&
800             (order != FB0_WIN1_FB1_WIN2_FB2_WIN0) &&
801             (order != FB0_WIN2_FB1_WIN0_FB2_WIN1) &&
802             (order != FB0_WIN0_FB1_WIN2_FB2_WIN1) &&
803             (order != FB0_WIN0_FB1_WIN1_FB2_WIN2) &&
804             (order != FB0_WIN1_FB1_WIN0_FB2_WIN2)) {
805                 dev_info(dev, "un supported map\n"
806                        "you can use the following order:\n" "201:\n"
807                        "fb0-win1\n" "fb1-win0\n" "fb2-win2\n" "210:\n"
808                        "fb0-win0\n" "fb1-win1\n" "fb2-win2\n" "120:\n"
809                        "fb0-win0\n" "fb1-win2\n" "fb2-win1\n" "102:\n"
810                        "fb0-win2\n" "fb1-win0\n" "fb2-win1\n" "021:\n"
811                        "fb0-win1\n" "fb1-win2\n" "fb2-win0\n" "012:\n"
812                        "fb0-win2\n" "fb1-win1\n" "fb2-win0\n");
813                 return count;
814         } else {
815                 if (dev_drv->ops->fb_win_remap)
816                         dev_drv->ops->fb_win_remap(dev_drv, order);
817         }
818
819         return count;
820 }
821
822 static ssize_t show_hwc_lut(struct device *dev,
823                             struct device_attribute *attr, char *buf)
824 {
825         return 0;
826 }
827
828 static ssize_t set_hwc_lut(struct device *dev, struct device_attribute *attr,
829                            const char *buf, size_t count)
830 {
831         int hwc_lut[256];
832         const char *start = buf;
833         int i = 256, temp;
834         int space_max;
835
836         struct fb_info *fbi = dev_get_drvdata(dev);
837         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
838         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
839
840         /*printk("count:%d\n>>%s\n\n",count,start);*/
841         for (i = 0; i < 256; i++) {
842                 space_max = 15; /*max space number 15*/
843                 temp = simple_strtoul(start, NULL, 16);
844                 hwc_lut[i] = temp;
845                 do {
846                         start++;
847                         space_max--;
848                 } while ((*start != ' ') && space_max);
849
850                 if (!space_max)
851                         break;
852                 else
853                         start++;
854         }
855         if (dev_drv->ops->set_hwc_lut)
856                 dev_drv->ops->set_hwc_lut(dev_drv, hwc_lut, 1);
857
858         return count;
859 }
860
861 static ssize_t show_cabc_lut(struct device *dev,
862                              struct device_attribute *attr, char *buf)
863 {
864         return 0;
865 }
866
867 static ssize_t set_cabc_lut(struct device *dev, struct device_attribute *attr,
868                             const char *buf, size_t count)
869 {
870         int cabc_lut[256];
871         const char *start = buf;
872         int i = 256, temp;
873         int space_max = 10;
874
875         struct fb_info *fbi = dev_get_drvdata(dev);
876         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
877         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
878
879         for (i = 0; i < 256; i++) {
880                 temp = i;
881                 /*init by default value*/
882                 cabc_lut[i] = temp + (temp << 8) + (temp << 16);
883         }
884         for (i = 0; i < 256; i++) {
885                 space_max = 10; /*max space number 10*/
886                 temp = simple_strtoul(start, NULL, 10);
887                 cabc_lut[i] = temp;
888                 do {
889                         start++;
890                         space_max--;
891                 } while ((*start != ' ') && space_max);
892
893                 if (!space_max)
894                         break;
895                 else
896                         start++;
897         }
898         if (dev_drv->ops->set_cabc_lut)
899                 dev_drv->ops->set_cabc_lut(dev_drv, cabc_lut);
900
901         return count;
902 }
903
904 static ssize_t show_dsp_lut(struct device *dev,
905                             struct device_attribute *attr, char *buf)
906 {
907         return 0;
908 }
909
910 static ssize_t set_dsp_lut(struct device *dev, struct device_attribute *attr,
911                            const char *buf, size_t count)
912 {
913         int dsp_lut[256];
914         const char *start = buf;
915         int i = 256, temp;
916         int space_max = 10;
917
918         struct fb_info *fbi = dev_get_drvdata(dev);
919         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
920         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
921
922         for (i = 0; i < 256; i++) {
923                 temp = i;
924                 /*init by default value*/
925                 dsp_lut[i] = temp + (temp << 8) + (temp << 16);
926         }
927         /*printk("count:%d\n>>%s\n\n",count,start);*/
928         for (i = 0; i < 256; i++) {
929                 space_max = 10; /*max space number 10*/
930                 temp = simple_strtoul(start, NULL, 10);
931                 dsp_lut[i] = temp;
932                 do {
933                         start++;
934                         space_max--;
935                 } while ((*start != ' ') && space_max);
936
937                 if (!space_max)
938                         break;
939                 else
940                         start++;
941         }
942         if (dev_drv->ops->set_dsp_lut)
943                 dev_drv->ops->set_dsp_lut(dev_drv, dsp_lut);
944
945         return count;
946 }
947
948 static ssize_t show_dsp_cabc(struct device *dev,
949                              struct device_attribute *attr, char *buf)
950 {
951         struct fb_info *fbi = dev_get_drvdata(dev);
952         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
953         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
954
955         return snprintf(buf, PAGE_SIZE, "cabc mode=%d\n",
956                 dev_drv->cabc_mode);
957         return 0;
958 }
959
960 static ssize_t set_dsp_cabc(struct device *dev, struct device_attribute *attr,
961                             const char *buf, size_t count)
962 {
963         struct fb_info *fbi = dev_get_drvdata(dev);
964         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
965         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
966         int space_max, ret = 0, mode = 0, calc = 0, up = 0, down = 0, global = 0;
967         const char *start = buf;
968
969         space_max = 10; /*max space number 10*/
970         mode = simple_strtoul(start, NULL, 10);
971         do {
972                 start++;
973                 space_max--;
974         } while ((*start != ' ') && space_max);
975         start++;
976         calc = simple_strtoul(start, NULL, 10);
977
978         do {
979                 start++;
980                 space_max--;
981         } while ((*start != ' ') && space_max);
982         start++;
983         up  = simple_strtoul(start, NULL, 10);
984
985         do {
986                 start++;
987                 space_max--;
988         } while ((*start != ' ') && space_max);
989         start++;
990         down = simple_strtoul(start, NULL, 10);
991
992         do {
993                 start++;
994                 space_max--;
995         } while ((*start != ' ') && space_max);
996         start++;
997         global = simple_strtoul(start, NULL, 10);
998
999     if (dev_drv->ops->set_dsp_cabc)
1000                 ret = dev_drv->ops->set_dsp_cabc(dev_drv, mode, calc, up, down, global);
1001         if (ret < 0)
1002                 return ret;
1003
1004         return count;
1005 }
1006
1007 static ssize_t show_dsp_bcsh(struct device *dev,
1008                              struct device_attribute *attr, char *buf)
1009 {
1010         struct fb_info *fbi = dev_get_drvdata(dev);
1011         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1012         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1013         int brightness = 0, contrast = 0, sat_con = 0, sin_hue = 0, cos_hue = 0;
1014
1015         if (dev_drv->ops->get_dsp_bcsh_bcs) {
1016                 brightness = dev_drv->ops->get_dsp_bcsh_bcs(dev_drv,
1017                                                             BRIGHTNESS);
1018                 contrast = dev_drv->ops->get_dsp_bcsh_bcs(dev_drv, CONTRAST);
1019                 sat_con = dev_drv->ops->get_dsp_bcsh_bcs(dev_drv, SAT_CON);
1020         }
1021         if (dev_drv->ops->get_dsp_bcsh_hue) {
1022                 sin_hue = dev_drv->ops->get_dsp_bcsh_hue(dev_drv, H_SIN);
1023                 cos_hue = dev_drv->ops->get_dsp_bcsh_hue(dev_drv, H_COS);
1024         }
1025         return snprintf(buf, PAGE_SIZE,
1026                         "brightness:%4d,contrast:%4d,sat_con:%4d,"
1027                         "sin_hue:%4d,cos_hue:%4d\n",
1028                         brightness, contrast, sat_con, sin_hue, cos_hue);
1029 }
1030
1031 static ssize_t set_dsp_bcsh(struct device *dev, struct device_attribute *attr,
1032                             const char *buf, size_t count)
1033 {
1034         struct fb_info *fbi = dev_get_drvdata(dev);
1035         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1036         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1037         int brightness, contrast, sat_con, ret = 0, sin_hue, cos_hue;
1038
1039         if (!strncmp(buf, "open", 4)) {
1040                 if (dev_drv->ops->open_bcsh)
1041                         ret = dev_drv->ops->open_bcsh(dev_drv, 1);
1042                 else
1043                         ret = -1;
1044         } else if (!strncmp(buf, "close", 5)) {
1045                 if (dev_drv->ops->open_bcsh)
1046                         ret = dev_drv->ops->open_bcsh(dev_drv, 0);
1047                 else
1048                         ret = -1;
1049         } else if (!strncmp(buf, "brightness", 10)) {
1050                 sscanf(buf, "brightness %d", &brightness);
1051                 if (unlikely(brightness > 255)) {
1052                         dev_err(fbi->dev,
1053                                 "brightness should be [0:255],now=%d\n\n",
1054                                 brightness);
1055                         brightness = 255;
1056                 }
1057                 if (dev_drv->ops->set_dsp_bcsh_bcs)
1058                         ret = dev_drv->ops->set_dsp_bcsh_bcs(dev_drv,
1059                                                              BRIGHTNESS,
1060                                                              brightness);
1061                 else
1062                         ret = -1;
1063         } else if (!strncmp(buf, "contrast", 8)) {
1064                 sscanf(buf, "contrast %d", &contrast);
1065                 if (unlikely(contrast > 510)) {
1066                         dev_err(fbi->dev,
1067                                 "contrast should be [0:510],now=%d\n",
1068                                 contrast);
1069                         contrast = 510;
1070                 }
1071                 if (dev_drv->ops->set_dsp_bcsh_bcs)
1072                         ret = dev_drv->ops->set_dsp_bcsh_bcs(dev_drv,
1073                                                              CONTRAST,
1074                                                              contrast);
1075                 else
1076                         ret = -1;
1077         } else if (!strncmp(buf, "sat_con", 7)) {
1078                 sscanf(buf, "sat_con %d", &sat_con);
1079                 if (unlikely(sat_con > 1015)) {
1080                         dev_err(fbi->dev,
1081                                 "sat_con should be [0:1015],now=%d\n",
1082                                 sat_con);
1083                         sat_con = 1015;
1084                 }
1085                 if (dev_drv->ops->set_dsp_bcsh_bcs)
1086                         ret = dev_drv->ops->set_dsp_bcsh_bcs(dev_drv,
1087                                                              SAT_CON,
1088                                                              sat_con);
1089                 else
1090                         ret = -1;
1091         } else if (!strncmp(buf, "hue", 3)) {
1092                 sscanf(buf, "hue %d %d", &sin_hue, &cos_hue);
1093                 if (unlikely(sin_hue > 511 || cos_hue > 511)) {
1094                         dev_err(fbi->dev, "sin_hue=%d,cos_hue=%d\n",
1095                                 sin_hue, cos_hue);
1096                 }
1097                 if (dev_drv->ops->set_dsp_bcsh_hue)
1098                         ret = dev_drv->ops->set_dsp_bcsh_hue(dev_drv,
1099                                                              sin_hue,
1100                                                              cos_hue);
1101                 else
1102                         ret = -1;
1103         } else {
1104                 dev_info(dev, "format error\n");
1105         }
1106
1107         if (ret < 0)
1108                 return ret;
1109
1110         return count;
1111 }
1112
1113 static ssize_t show_scale(struct device *dev,
1114                           struct device_attribute *attr, char *buf)
1115 {
1116         struct fb_info *fbi = dev_get_drvdata(dev);
1117         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1118         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1119
1120         return snprintf(buf, PAGE_SIZE,
1121                 "xscale=%d yscale=%d\nleft=%d top=%d right=%d bottom=%d\n",
1122                 (dev_drv->overscan.left + dev_drv->overscan.right) / 2,
1123                 (dev_drv->overscan.top + dev_drv->overscan.bottom) / 2,
1124                 dev_drv->overscan.left, dev_drv->overscan.top,
1125                 dev_drv->overscan.right, dev_drv->overscan.bottom);
1126 }
1127
1128 static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
1129                          const char *buf, size_t count)
1130 {
1131         struct fb_info *fbi = dev_get_drvdata(dev);
1132         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1133         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1134         u32 left, top, right, bottom;
1135
1136         if (!strncmp(buf, "overscan", 8)) {
1137                 sscanf(buf,
1138                        "overscan %d,%d,%d,%d", &left, &top, &right, &bottom);
1139                 if (left > 0 && left <= 100)
1140                         dev_drv->overscan.left = left;
1141                 if (top > 0 && top <= 100)
1142                         dev_drv->overscan.top = top;
1143                 if (right > 0 && right <= 100)
1144                         dev_drv->overscan.right = right;
1145                 if (bottom > 0 && bottom <= 100)
1146                         dev_drv->overscan.bottom = bottom;
1147         } else if (!strncmp(buf, "left", 4)) {
1148                 sscanf(buf, "left=%d", &left);
1149                 if (left > 0 && left <= 100)
1150                         dev_drv->overscan.left = left;
1151         } else if (!strncmp(buf, "top", 3)) {
1152                 sscanf(buf, "top=%d", &top);
1153                 if (top > 0 && top <= 100)
1154                         dev_drv->overscan.top = top;
1155         } else if (!strncmp(buf, "right", 5)) {
1156                 sscanf(buf, "right=%d", &right);
1157                 if (right > 0 && right <= 100)
1158                         dev_drv->overscan.right = right;
1159         } else if (!strncmp(buf, "bottom", 6)) {
1160                 sscanf(buf, "bottom=%d", &bottom);
1161                 if (bottom > 0 && bottom <= 100)
1162                         dev_drv->overscan.bottom = bottom;
1163         } else if (!strncmp(buf, "xscale", 6)) {
1164                 sscanf(buf, "xscale=%d", &left);
1165                 if (left > 0 && left <= 100) {
1166                         dev_drv->overscan.left = left;
1167                         dev_drv->overscan.right = left;
1168                 }
1169         } else if (!strncmp(buf, "yscale", 6)) {
1170                 sscanf(buf, "yscale=%d", &left);
1171                 if (left > 0 && left <= 100) {
1172                         dev_drv->overscan.top = left;
1173                         dev_drv->overscan.bottom = left;
1174                 }
1175         } else {
1176                 sscanf(buf, "%d", &left);
1177                 if (left > 0 && left <= 100) {
1178                         dev_drv->overscan.left = left;
1179                         dev_drv->overscan.right = left;
1180                         dev_drv->overscan.top = left;
1181                         dev_drv->overscan.bottom = left;
1182                 }
1183         }
1184
1185         if (dev_drv->ops->set_overscan)
1186                 dev_drv->ops->set_overscan(dev_drv, &dev_drv->overscan);
1187
1188         return count;
1189 }
1190
1191 static ssize_t show_lcdc_id(struct device *dev,
1192                             struct device_attribute *attr,
1193                             char *buf)
1194 {
1195         struct fb_info *fbi = dev_get_drvdata(dev);
1196         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1197         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1198
1199         return snprintf(buf, PAGE_SIZE, "%d\n", dev_drv->id);
1200 }
1201
1202 static ssize_t show_dsp_mode(struct device *dev,
1203                             struct device_attribute *attr,
1204                             char *buf)
1205 {
1206         struct fb_info *fbi = dev_get_drvdata(dev);
1207         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1208         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1209
1210         return snprintf(buf, PAGE_SIZE, "%d\n", dev_drv->dsp_mode);
1211 }
1212
1213 static ssize_t show_hot_plug_state(struct device *dev,
1214                             struct device_attribute *attr,
1215                             char *buf)
1216 {
1217         struct fb_info *fbi = dev_get_drvdata(dev);
1218         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1219         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1220
1221         return snprintf(buf, PAGE_SIZE, "%d\n", dev_drv->hot_plug_state);
1222 }
1223
1224 static ssize_t show_win_property(struct device *dev,
1225                             struct device_attribute *attr,
1226                             char *buf)
1227 {
1228         struct fb_info *fbi = dev_get_drvdata(dev);
1229         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1230         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1231         int win_id = 0;
1232
1233         win_id = dev_drv->ops->fb_get_win_id(dev_drv, fbi->fix.id);
1234         return snprintf(buf, PAGE_SIZE,
1235                         "feature: %d, max_input_x: %d, max_input_y: %d\n",
1236                         dev_drv->win[win_id]->property.feature,
1237                         dev_drv->win[win_id]->property.max_input_x,
1238                         dev_drv->win[win_id]->property.max_input_y);
1239 }
1240
1241 static ssize_t set_car_reverse(struct device *dev,
1242                                struct device_attribute *attr,
1243                                const char *buf, size_t count)
1244 {
1245         struct fb_info *fbi = dev_get_drvdata(dev);
1246         struct rk_fb_par *fb_par = (struct rk_fb_par *)fbi->par;
1247         struct rk_lcdc_driver *dev_drv = fb_par->lcdc_drv;
1248         u32 status;
1249         int ret;
1250
1251         ret = kstrtou32(buf, 0, &status);
1252         if (ret)
1253                 return ret;
1254         rk_fb_set_car_reverse_status(dev_drv, status);
1255
1256         return count;
1257 }
1258
1259 static struct device_attribute rkfb_attrs[] = {
1260         __ATTR(phys_addr, S_IRUGO, show_phys, NULL),
1261         __ATTR(virt_addr, S_IRUGO, show_virt, NULL),
1262         __ATTR(disp_info, S_IRUGO, show_disp_info, NULL),
1263         __ATTR(dump_buf, S_IRUGO | S_IWUSR, show_dump_buffer, set_dump_buffer),
1264         __ATTR(dsp_buf, S_IRUGO | S_IWUSR, show_dsp_buffer, set_dsp_buffer),
1265         __ATTR(screen_info, S_IRUGO, show_screen_info, NULL),
1266         __ATTR(dual_mode, S_IRUGO, show_dual_mode, NULL),
1267         __ATTR(enable, S_IRUGO | S_IWUSR, show_fb_state, set_fb_state),
1268         __ATTR(overlay, S_IRUGO | S_IWUSR, show_overlay, set_overlay),
1269         __ATTR(fps, S_IRUGO | S_IWUSR, show_fps, set_fps),
1270         __ATTR(map, S_IRUGO | S_IWUSR, show_fb_win_map, set_fb_win_map),
1271         __ATTR(dsp_lut, S_IRUGO | S_IWUSR, show_dsp_lut, set_dsp_lut),
1272         __ATTR(cabc_lut, S_IRUGO | S_IWUSR, show_cabc_lut, set_cabc_lut),
1273         __ATTR(hwc_lut, S_IRUGO | S_IWUSR, show_hwc_lut, set_hwc_lut),
1274         __ATTR(cabc, S_IRUGO | S_IWUSR, show_dsp_cabc, set_dsp_cabc),
1275         __ATTR(bcsh, S_IRUGO | S_IWUSR, show_dsp_bcsh, set_dsp_bcsh),
1276         __ATTR(scale, S_IRUGO | S_IWUSR, show_scale, set_scale),
1277         __ATTR(lcdcid, S_IRUGO, show_lcdc_id, NULL),
1278         __ATTR(win_property, S_IRUGO, show_win_property, NULL),
1279         __ATTR(car_reverse, S_IWUSR, NULL, set_car_reverse),
1280         __ATTR(dsp_mode, S_IRUGO, show_dsp_mode, NULL),
1281         __ATTR(hot_plug_state, S_IRUGO, show_hot_plug_state, NULL),
1282 };
1283
1284 int rkfb_create_sysfs(struct fb_info *fbi)
1285 {
1286         int r, t;
1287
1288         for (t = 0; t < ARRAY_SIZE(rkfb_attrs); t++) {
1289                 r = device_create_file(fbi->dev, &rkfb_attrs[t]);
1290                 if (r) {
1291                         dev_err(fbi->dev, "failed to create sysfs " "file\n");
1292                         return r;
1293                 }
1294         }
1295
1296         return 0;
1297 }
1298
1299 void rkfb_remove_sysfs(struct rk_fb *rk_fb)
1300 {
1301         int i, t;
1302
1303         for (i = 0; i < rk_fb->num_fb; i++) {
1304                 for (t = 0; t < ARRAY_SIZE(rkfb_attrs); t++)
1305                         device_remove_file(rk_fb->fb[i]->dev, &rkfb_attrs[t]);
1306         }
1307 }