1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| struct fb_ops st7789_fbops = { .owner = THIS_MODULE, .fb_read = st7789_buf_read, .fb_write = st7789_buf_write, .fb_pan_display = st7789_pan_disp, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit, }; static void st7789_deferred_io(struct fb_info *info, struct list_head *pagelist); static int st7789_pan_disp(struct fb_var_screeninfo *var, struct fb_info *info); static int st7789_fbdev_init(struct st7789_spi *screen);
static struct st7789_spi ins= {0};
static ssize_t st7789_buf_read(struct fb_info *info, char __user *buf, size_t count, loff_t *ppos) { struct st7789_spi *ins = info->par; if(*ppos + count > ins->buffer_size) return -EINVAL; if(copy_to_user(buf, ins->tx_buf + *ppos, count) != 0) return -EFAULT; return count; }
static ssize_t st7789_buf_write(struct fb_info *info, const char __user *buf, size_t count, loff_t *ppos) { struct st7789_spi *ins = info->par; if(*ppos + count > ins->buffer_size) return -EINVAL; if(copy_from_user(ins->tx_buf + *ppos, buf, count) != 0) return -EFAULT; return count; } static void st7789_deferred_io(struct fb_info *info, struct list_head *pagelist) { struct st7789_spi *scr = info->par; struct rect area = { {0, 0}, {scr->scr.width - 1, scr->scr.height - 1} }; st7789_disp_buf_at(&area, scr->tx_buf); }
static int st7789_pan_disp(struct fb_var_screeninfo *var, struct fb_info *info) { st7789_deferred_io(info, NULL); return 0; } static int st7789_fbdev_init(struct st7789_spi *screen) { struct st7789 *scr = &screen->scr; struct fb_info *info; struct fb_deferred_io *defio; if(ins.tx_buf_dma == 0){ ins.buffer_size = scr->width*scr->height*2+100; #if 0 ins.tx_buf = devm_kmalloc(&screen->spi->dev, ins.buffer_size, GFP_KERNEL); #endif ins.tx_buf = vzalloc(ins.buffer_size); if(ins.tx_buf == NULL) return -ENOMEM; } ins.info = devm_kzalloc(&screen->spi->dev,sizeof(struct fb_info), GFP_KERNEL); defio = devm_kzalloc(&screen->spi->dev, sizeof(struct fb_deferred_io), GFP_KERNEL); info = ins.info; defio->delay = HZ; defio->deferred_io = st7789_deferred_io;
info->screen_buffer = ins.tx_buf; info->fbops = &st7789_fbops; info->fbdefio = defio; fb_deferred_io_init(info);
info->fix.type = FB_TYPE_PACKED_PIXELS; info->fix.visual = FB_VISUAL_TRUECOLOR; info->fix.xpanstep = 0; info->fix.ypanstep = 0; info->fix.ywrapstep = 0; info->fix.line_length = scr->width * 2; info->fix.accel = FB_ACCEL_NONE; info->fix.smem_len = ins.buffer_size;
info->var.rotate = 0; info->var.xres = scr->width; info->var.yres = scr->height; info->var.xres_virtual = info->var.xres; info->var.yres_virtual = info->var.yres; info->var.bits_per_pixel = 16; info->var.nonstd = 1;
info->var.red.offset = 11; info->var.red.length = 5; info->var.green.offset = 5; info->var.green.length = 6; info->var.blue.offset = 0; info->var.blue.length = 5; info->var.transp.offset = 0; info->var.transp.length = 0; info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB; info->par = &ins; return register_framebuffer(info); }
|