Advertisement
P3T3

ILI9327 framebuffer driver

May 21st, 2013
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 19.43 KB | None | 0 0
  1. /*
  2.  * ZTE U733 Framebuffer
  3.  *
  4.  *
  5.  * Original: Copyright (c) 2009 Jean-Christian de Rivaz
  6.  *
  7.  * SPI mods, console support, 400x240 instead of 240x320:
  8.  * Copyright (c) 2012 Jeroen Domburg <jeroen@spritesmods.com>
  9.  *
  10.  * Bits and pieces borrowed from the fsl-zteu733.c:
  11.  * Copyright (C) 2010-2011 Freescale Semiconductor, Inc. All Rights Reserved.
  12.  * Author: Alison Wang <b18965@freescale.com>
  13.  *         Jason Jin <Jason.jin@freescale.com>
  14.  *
  15.  * This file is subject to the terms and conditions of the GNU General Public
  16.  * License.  See the file "COPYING" in the main directory of this archive
  17.  * for more details.
  18.  *
  19.  * The Solomon Systech ZTEU733 chip drive TFT screen up to 240x400.
  20.  *
  21.  * This driver uses only SPI mode:
  22.  *
  23.  * A SPI port with modalias 'zteu733' should exist. The LCD should be in 16-bit
  24.  * mode (which they usually are hardwired to be...) and connected to three
  25.  * CD4094s and a CD4020. For schematic, check out
  26.  * http://spritesmods.com/?art=spitft
  27.  *
  28.  * LCDs in their own, native SPI mode aren't supported yet, mostly because I
  29.  * can't get my hands on a cheap one.
  30.  */
  31. #define DEBUG
  32.  
  33. #include <linux/kernel.h>
  34. #include <linux/device.h>
  35. #include <linux/module.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/mm.h>
  38. #include <linux/vmalloc.h>
  39. #include <linux/fb.h>
  40. #include <asm/io.h>
  41. #include <linux/spi/spi.h>
  42. #include <linux/delay.h>
  43.  
  44. #define ZTEU733_REG_SLEEP_MODE      0x10
  45. #define ZTEU733_REG_SET_COLUMN_ADDR     0x2A
  46. #define ZTEU733_REG_SET_PAGE_ADDR       0x2B
  47. #define ZTEU733_REG_SET_WRMEM_START     0x2C
  48.  
  49. struct zteu733_page {
  50.     unsigned short x;
  51.     unsigned short y;
  52.     unsigned short *buffer;
  53.     unsigned short len;
  54.     int must_update;
  55. };
  56.  
  57. struct zteu733 {
  58.     struct device *dev;
  59.     struct spi_device *spidev;
  60.     struct fb_info *info;
  61.     unsigned int pages_count;
  62.     struct zteu733_page *pages;
  63.     unsigned long pseudo_palette[17];
  64.     int backlight;
  65. };
  66.  
  67. /*
  68. These two routines will write to the SPI-port, shifting data into the 4094 shift
  69. registers.
  70. */
  71. #define CD4094_RD (1<<0)
  72. #define CD4094_WR (1<<1)
  73. #define CD4094_BCNT (1<<2)
  74. #define CD4094_RST (1<<3)
  75. #define CD4094_DC (1<<4)
  76. #define CD4094_INVERT (CD4094_RD|CD4094_WR|CD4094_RST)
  77.  
  78. /*
  79. This routine will write a single 16-bit value, either as data or as a command
  80. (depends on isdata). The LCD will clock this in because the SPIs /CS goes high.
  81. */
  82. static int zteu733_spi_write(struct zteu733 *item, unsigned short value,
  83.                 unsigned int isdata)
  84. {
  85.     u8 buf[3];
  86.     buf[0]=((isdata?CD4094_DC:0)|CD4094_WR|(item->backlight?CD4094_BCNT:0))^CD4094_INVERT;
  87.     buf[1]=(value>>8)&0xff;
  88.     buf[2]=(value)&0xff;
  89.     spi_write(item->spidev, buf, 3);
  90.     return 0;
  91. }
  92.  
  93. #define BLOCKLEN (4096)
  94. static u8 zteu733_spiblock[BLOCKLEN*4];
  95.  
  96. /*
  97. This routine will clock in len words of data. The LCD will clock this in every 4th byte written
  98. because a 4020 will pull down the /cs at that moment.
  99. */
  100. static int zteu733_spi_write_datablock(struct zteu733 *item,
  101.                     unsigned short *block, int len)
  102. {
  103.     int x;
  104.     unsigned short value;
  105.  
  106.     //ToDo: send in parts if needed
  107.     if (len>BLOCKLEN) {
  108.         dev_err(item->dev, "%s: len > blocklen (%i > %i)\n",
  109.             __func__, len, BLOCKLEN);
  110.         len=BLOCKLEN;
  111.     }
  112.  
  113.     for (x=0; x<len; x++) {
  114.         value=block[x];
  115.         zteu733_spiblock[(x*4)]=0; //dummy
  116.         zteu733_spiblock[(x*4)+1]=(CD4094_DC|CD4094_WR|(item->backlight?CD4094_BCNT:0))^CD4094_INVERT;
  117.         zteu733_spiblock[(x*4)+2]=(value>>8)&0xff;
  118.         zteu733_spiblock[(x*4)+3]=(value)&0xff;
  119.     }
  120.     spi_write(item->spidev, zteu733_spiblock, len*4);
  121.     return 0;
  122. }
  123.  
  124. static inline void zteu733_write_reg(struct zteu733 *item, unsigned char reg)
  125. {
  126.     dev_dbg(item->dev, "%s: Register 0x%02x \n", __func__, reg);
  127.     zteu733_spi_write(item, reg&0xff, 0);
  128. }
  129.  
  130.  
  131.  
  132. static inline void zteu733_reg_set(struct zteu733 *item, unsigned char reg,
  133.                    unsigned short value)
  134. {
  135.     dev_dbg(item->dev, "%s: Register 0x%02x = 0x%04x \n", __func__, reg, value);
  136.     zteu733_spi_write(item, reg&0xff, 0);
  137.     zteu733_spi_write(item, value, 1);
  138. }
  139.  
  140. static void zteu733_copy(struct zteu733 *item, unsigned int index)
  141. {
  142.     unsigned short x;
  143.     unsigned short y;
  144.     unsigned short *buffer;
  145.     unsigned int len;
  146.     x = item->pages[index].x;
  147.     y = item->pages[index].y;
  148.     buffer = item->pages[index].buffer;
  149.     len = item->pages[index].len;
  150.     dev_dbg(item->dev,
  151.         "%s: page[%u]: x=%3hu y=%3hu buffer=0x%p len=%3hu\n",
  152.         __func__, index, x, y, buffer, len);
  153.  
  154.     zteu733_reg_set(item, ZTEU733_REG_SET_COLUMN_ADDR, (item->info->var.yres - 1)-y);
  155.     zteu733_reg_set(item, ZTEU733_REG_SET_PAGE_ADDR, x);
  156.  
  157. //  zteu733_reg_set(item, ZTEU733_REG_GDDRAM_X_ADDR, (item->info->var.yres - 1)-y);
  158. //  zteu733_reg_set(item, ZTEU733_REG_GDDRAM_Y_ADDR, x);
  159.     zteu733_spi_write(item, ZTEU733_REG_SET_WRMEM_START, 0);
  160.  
  161. //  zteu733_spi_write(item, ZTEU733_REG_GDDRAM_DATA, 0);
  162.  
  163.     zteu733_spi_write_datablock(item, buffer, len);
  164. /*
  165. //The write_datablock can also be exchanged with this code, which is slower but
  166. //doesn't require the CD4020 counter IC.
  167.     for (count = 0; count < len; count++) {
  168.         zteu733_spi_write(item, buffer[count], 1);
  169.     }
  170. */
  171. }
  172.  
  173. static void zteu733_update_all(struct zteu733 *item)
  174. {
  175.     unsigned short i;
  176.     struct fb_deferred_io *fbdefio = item->info->fbdefio;
  177.     for (i = 0; i < item->pages_count; i++) {
  178.         item->pages[i].must_update=1;
  179.     }
  180.     schedule_delayed_work(&item->info->deferred_work, fbdefio->delay);
  181. }
  182.  
  183. static void zteu733_update(struct fb_info *info, struct list_head *pagelist)
  184. {
  185.     struct zteu733 *item = (struct zteu733 *)info->par;
  186.     struct page *page;
  187.     int i;
  188.  
  189.     //We can be called because of pagefaults (mmap'ed framebuffer, pages
  190.     //returned in *pagelist) or because of kernel activity
  191.     //(pages[i]/must_update!=0). Add the former to the list of the latter.
  192.     list_for_each_entry(page, pagelist, lru) {
  193.         item->pages[page->index].must_update=1;
  194.     }
  195.  
  196.     //Copy changed pages.
  197.     for (i=0; i<item->pages_count; i++) {
  198.         //ToDo: Small race here between checking and setting must_update,
  199.         //maybe lock?
  200.         if (item->pages[i].must_update) {
  201.             item->pages[i].must_update=0;
  202.             zteu733_copy(item, i);
  203.         }
  204.     }
  205.  
  206. }
  207.  
  208.  
  209. static void __init zteu733_setup(struct zteu733 *item)
  210. {
  211.     dev_dbg(item->dev, "%s: item=0x%p\n", __func__, (void *)item);
  212.     dev_dbg(item->dev, "%s: ------------------------------------------------------------------", __func__);
  213.  
  214. zteu733_write_reg(item, 0xE9);  // LSI Test Register
  215. zteu733_spi_write(item, 0x20, 1);
  216. mdelay(20);
  217.  
  218. zteu733_write_reg(item, 0x01);  // Sotf Reset
  219. mdelay(150);
  220.  
  221. zteu733_write_reg(item, 0x11);  // Exit Sleep mode
  222. mdelay(500);
  223.  
  224. zteu733_write_reg(item, 0x53);  // Write CTRL Display, Display Dimming = 1, Backlight = ON
  225. zteu733_spi_write(item, 0x08, 1);
  226. zteu733_write_reg(item, 0x51);  // Write Display Brightness = 0x80
  227. zteu733_spi_write(item, 0xFF, 1);
  228. mdelay(1000);
  229.  
  230. zteu733_write_reg(item, 0xD1);
  231. zteu733_spi_write(item, 0x00, 1);
  232. zteu733_spi_write(item, 0x71, 1);
  233. zteu733_spi_write(item, 0x19, 1);
  234.  
  235. zteu733_write_reg(item, 0xD0);
  236. zteu733_spi_write(item, 0x07, 1);
  237. zteu733_spi_write(item, 0x01, 1);
  238. zteu733_spi_write(item, 0x08, 1);
  239.  
  240. zteu733_write_reg(item, 0x36);      // Set Address Mode
  241. zteu733_spi_write(item, 0x00, 1);
  242.  
  243. zteu733_write_reg(item, 0x3A);      // Set Pixel Format : 0x11 = 8bpp, 0x55 = 16bpp, 0x66 = 18bpp
  244. zteu733_spi_write(item, 0x55, 1);
  245.  
  246. zteu733_write_reg(item, 0xC1);
  247. zteu733_spi_write(item, 0x10, 1);
  248. zteu733_spi_write(item, 0x10, 1);
  249. zteu733_spi_write(item, 0x02, 1);
  250. zteu733_spi_write(item, 0x02, 1);
  251.  
  252. zteu733_write_reg(item, 0xC0);
  253. zteu733_spi_write(item, 0x00, 1);
  254. zteu733_spi_write(item, 0x35, 1);
  255. zteu733_spi_write(item, 0x00, 1);
  256. zteu733_spi_write(item, 0x00, 1);
  257. zteu733_spi_write(item, 0x01, 1);
  258. zteu733_spi_write(item, 0x02, 1);
  259.  
  260. zteu733_write_reg(item, 0xC5);
  261. zteu733_spi_write(item, 0x04, 1);
  262.  
  263. zteu733_write_reg(item, 0xC5);
  264. zteu733_spi_write(item, 0x04, 1);
  265.  
  266. zteu733_write_reg(item, 0xD2);
  267. zteu733_spi_write(item, 0x01, 1);
  268. zteu733_spi_write(item, 0x44, 1);
  269.  
  270. // GAMA TODO
  271.  
  272. zteu733_write_reg(item, 0x2A);
  273. zteu733_spi_write(item, 0x00, 1);
  274. zteu733_spi_write(item, 0x00, 1);
  275. zteu733_spi_write(item, 0x00, 1);
  276. zteu733_spi_write(item, 0xEF, 1);
  277.  
  278. zteu733_write_reg(item, 0x2B);
  279. zteu733_spi_write(item, 0x00, 1);
  280. zteu733_spi_write(item, 0x00, 1);
  281. zteu733_spi_write(item, 0x01, 1);
  282. zteu733_spi_write(item, 0x8F, 1);
  283.  
  284. zteu733_write_reg(item, 0x29);  // Display ON
  285. zteu733_write_reg(item, 0x20);  //Exit Invert Mode
  286. // zteu733_write_reg(item, 0x2c);   //Exit Invert Mode
  287.  
  288.     dev_dbg(item->dev, "%s: ------------------------------------------------------------------", __func__);
  289.  
  290. }
  291.  
  292. //This routine will allocate the buffer for the complete framebuffer. This
  293. //is one continuous chunk of 16-bit pixel values; userspace programs
  294. //will write here.
  295. static int __init zteu733_video_alloc(struct zteu733 *item)
  296. {
  297.     unsigned int frame_size;
  298.  
  299.     dev_dbg(item->dev, "%s: item=0x%p\n", __func__, (void *)item);
  300.  
  301.     frame_size = item->info->fix.line_length * item->info->var.yres;
  302.     dev_dbg(item->dev, "%s: item=0x%p frame_size=%u\n",
  303.         __func__, (void *)item, frame_size);
  304.  
  305.     item->pages_count = frame_size / PAGE_SIZE;
  306.     if ((item->pages_count * PAGE_SIZE) < frame_size) {
  307.         item->pages_count++;
  308.     }
  309.     dev_dbg(item->dev, "%s: item=0x%p pages_count=%u\n",
  310.         __func__, (void *)item, item->pages_count);
  311.  
  312.     item->info->fix.smem_len = item->pages_count * PAGE_SIZE;
  313.     item->info->fix.smem_start =
  314.         (unsigned long)vmalloc(item->info->fix.smem_len);
  315.     if (!item->info->fix.smem_start) {
  316.         dev_err(item->dev, "%s: unable to vmalloc\n", __func__);
  317.         return -ENOMEM;
  318.     }
  319.     memset((void *)item->info->fix.smem_start, 0, item->info->fix.smem_len);
  320.  
  321.     return 0;
  322. }
  323.  
  324. static void zteu733_video_free(struct zteu733 *item)
  325. {
  326.     dev_dbg(item->dev, "%s: item=0x%p\n", __func__, (void *)item);
  327.     vfree((void *)item->info->fix.smem_start);
  328. }
  329.  
  330. //This routine will allocate a zteu733_page struct for each vm page in the
  331. //main framebuffer memory. Each struct will contain a pointer to the page
  332. //start, an x- and y-offset, and the length of the pagebuffer which is in the framebuffer.
  333. static int __init zteu733_pages_alloc(struct zteu733 *item)
  334. {
  335.     unsigned short pixels_per_page;
  336.     unsigned short yoffset_per_page;
  337.     unsigned short xoffset_per_page;
  338.     unsigned short index;
  339.     unsigned short x = 0;
  340.     unsigned short y = 0;
  341.     unsigned short *buffer;
  342.     unsigned int len;
  343.  
  344.     dev_dbg(item->dev, "%s: item=0x%p\n", __func__, (void *)item);
  345.  
  346.     item->pages = kmalloc(item->pages_count * sizeof(struct zteu733_page),
  347.                   GFP_KERNEL);
  348.     if (!item->pages) {
  349.         dev_err(item->dev, "%s: unable to kmalloc for zteu733_page\n",
  350.             __func__);
  351.         return -ENOMEM;
  352.     }
  353.  
  354.     pixels_per_page = PAGE_SIZE / (item->info->var.bits_per_pixel / 8);
  355.     yoffset_per_page = pixels_per_page / item->info->var.xres;
  356.     xoffset_per_page = pixels_per_page -
  357.         (yoffset_per_page * item->info->var.xres);
  358.     dev_dbg(item->dev, "%s: item=0x%p pixels_per_page=%hu "
  359.         "yoffset_per_page=%hu xoffset_per_page=%hu\n",
  360.         __func__, (void *)item, pixels_per_page,
  361.         yoffset_per_page, xoffset_per_page);
  362.  
  363.     buffer = (unsigned short *)item->info->fix.smem_start;
  364.     for (index = 0; index < item->pages_count; index++) {
  365.         len = (item->info->var.xres * item->info->var.yres) -
  366.             (index * pixels_per_page);
  367.         if (len > pixels_per_page) {
  368.             len = pixels_per_page;
  369.         }
  370.         dev_dbg(item->dev,
  371.             "%s: page[%d]: x=%3hu y=%3hu buffer=0x%p len=%3hu\n",
  372.             __func__, index, x, y, buffer, len);
  373.         item->pages[index].x = x;
  374.         item->pages[index].y = y;
  375.         item->pages[index].buffer = buffer;
  376.         item->pages[index].len = len;
  377.  
  378.         x += xoffset_per_page;
  379.         if (x >= item->info->var.xres) {
  380.             y++;
  381.             x -= item->info->var.xres;
  382.         }
  383.         y += yoffset_per_page;
  384.         buffer += pixels_per_page;
  385.     }
  386.  
  387.     return 0;
  388. }
  389.  
  390. static void zteu733_pages_free(struct zteu733 *item)
  391. {
  392.     dev_dbg(item->dev, "%s: item=0x%p\n", __func__, (void *)item);
  393.  
  394.     kfree(item->pages);
  395. }
  396.  
  397. static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
  398. {
  399.     return ((val<<width) + 0x7FFF - val)>>16;
  400. }
  401.  
  402. //This routine is needed because the console driver won't work without it.
  403. static int zteu733_setcolreg(unsigned regno,
  404.                    unsigned red, unsigned green, unsigned blue,
  405.                    unsigned transp, struct fb_info *info)
  406. {
  407.     int ret = 1;
  408.  
  409.     /*
  410.      * If greyscale is true, then we convert the RGB value
  411.      * to greyscale no matter what visual we are using.
  412.      */
  413.     if (info->var.grayscale)
  414.         red = green = blue = (19595 * red + 38470 * green +
  415.                       7471 * blue) >> 16;
  416.     switch (info->fix.visual) {
  417.     case FB_VISUAL_TRUECOLOR:
  418.         if (regno < 16) {
  419.             u32 *pal = info->pseudo_palette;
  420.             u32 value;
  421.  
  422.             red = CNVT_TOHW(red, info->var.red.length);
  423.             green = CNVT_TOHW(green, info->var.green.length);
  424.             blue = CNVT_TOHW(blue, info->var.blue.length);
  425.             transp = CNVT_TOHW(transp, info->var.transp.length);
  426.  
  427.             value = (red << info->var.red.offset) |
  428.                 (green << info->var.green.offset) |
  429.                 (blue << info->var.blue.offset) |
  430.                 (transp << info->var.transp.offset);
  431.  
  432.             pal[regno] = value;
  433.             ret = 0;
  434.         }
  435.         break;
  436.     case FB_VISUAL_STATIC_PSEUDOCOLOR:
  437.     case FB_VISUAL_PSEUDOCOLOR:
  438.         break;
  439.     }
  440.     return ret;
  441. }
  442.  
  443. static int zteu733_blank(int blank_mode, struct fb_info *info)
  444. {
  445.     struct zteu733 *item = (struct zteu733 *)info->par;
  446.     if (blank_mode == FB_BLANK_UNBLANK)
  447.         item->backlight=1;
  448.     else
  449.         item->backlight=0;
  450.     //Item->backlight won't take effect until the LCD is written to. Force that
  451.     //by dirty'ing a page.
  452.     item->pages[0].must_update=1;
  453.     schedule_delayed_work(&info->deferred_work, 0);
  454.     return 0;
  455. }
  456.  
  457. static void zteu733_touch(struct fb_info *info, int x, int y, int w, int h)
  458. {
  459.     struct fb_deferred_io *fbdefio = info->fbdefio;
  460.     struct zteu733 *item = (struct zteu733 *)info->par;
  461.     int i, ystart, yend;
  462.     if (fbdefio) {
  463.         //Touch the pages the y-range hits, so the deferred io will update them.
  464.         for (i=0; i<item->pages_count; i++) {
  465.             ystart=item->pages[i].y;
  466.             yend=item->pages[i].y+(item->pages[i].len/info->fix.line_length)+1;
  467.             if (!((y+h)<ystart || y>yend)) {
  468.                 item->pages[i].must_update=1;
  469.             }
  470.         }
  471.         //Schedule the deferred IO to kick in after a delay.
  472.         schedule_delayed_work(&info->deferred_work, fbdefio->delay);
  473.     }
  474. }
  475.  
  476. static void zteu733_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
  477. {
  478.     sys_fillrect(p, rect);
  479.     zteu733_touch(p, rect->dx, rect->dy, rect->width, rect->height);
  480. }
  481.  
  482. static void zteu733_imageblit(struct fb_info *p, const struct fb_image *image)
  483. {
  484.     sys_imageblit(p, image);
  485.     zteu733_touch(p, image->dx, image->dy, image->width, image->height);
  486. }
  487.  
  488. static void zteu733_copyarea(struct fb_info *p, const struct fb_copyarea *area)
  489. {
  490.     sys_copyarea(p, area);
  491.     zteu733_touch(p, area->dx, area->dy, area->width, area->height);
  492. }
  493.  
  494. static ssize_t zteu733_write(struct fb_info *p, const char __user *buf,
  495.                 size_t count, loff_t *ppos)
  496. {
  497.     ssize_t res;
  498.     res = fb_sys_write(p, buf, count, ppos);
  499.     zteu733_touch(p, 0, 0, p->var.xres, p->var.yres);
  500.     return res;
  501. }
  502.  
  503. static struct fb_ops zteu733_fbops = {
  504.     .owner        = THIS_MODULE,
  505.     .fb_read      = fb_sys_read,
  506.     .fb_write     = zteu733_write,
  507.     .fb_fillrect  = zteu733_fillrect,
  508.     .fb_copyarea  = zteu733_copyarea,
  509.     .fb_imageblit = zteu733_imageblit,
  510.     .fb_setcolreg   = zteu733_setcolreg,
  511.     .fb_blank   = zteu733_blank,
  512. };
  513.  
  514. static struct fb_fix_screeninfo zteu733_fix __initdata = {
  515.     .id          = "ZTEU733",
  516.     .type        = FB_TYPE_PACKED_PIXELS,
  517.     .visual      = FB_VISUAL_TRUECOLOR,
  518.     .accel       = FB_ACCEL_NONE,
  519.     .line_length = 400 * 2,
  520. };
  521.  
  522. static struct fb_var_screeninfo zteu733_var __initdata = {
  523.     .xres       = 400,
  524.     .yres       = 240,
  525.     .xres_virtual   = 400,
  526.     .yres_virtual   = 240,
  527.     .width      = 400,
  528.     .height     = 240,
  529.     .bits_per_pixel = 16,
  530.     .red        = {11, 5, 0},
  531.     .green      = {5, 6, 0},
  532.     .blue       = {0, 5, 0},
  533.     .activate   = FB_ACTIVATE_NOW,
  534.     .vmode      = FB_VMODE_NONINTERLACED,
  535. };
  536.  
  537. static struct fb_deferred_io zteu733_defio = {
  538.         .delay          = HZ / 20,
  539.         .deferred_io    = &zteu733_update,
  540. };
  541.  
  542. static int __devinit zteu733_probe(struct spi_device *dev)
  543. {
  544.     int ret = 0;
  545.     struct zteu733 *item;
  546.     struct fb_info *info;
  547.  
  548.     dev_dbg(&dev->dev, "%s\n", __func__);
  549.  
  550.     item = kzalloc(sizeof(struct zteu733), GFP_KERNEL);
  551.     if (!item) {
  552.         dev_err(&dev->dev,
  553.             "%s: unable to kzalloc for zteu733\n", __func__);
  554.         ret = -ENOMEM;
  555.         goto out;
  556.     }
  557.     item->dev = &dev->dev;
  558.     dev_set_drvdata(&dev->dev, item);
  559.     item->backlight=1;
  560.  
  561.     item->spidev=dev;
  562.     item->dev=&dev->dev;
  563.     dev_set_drvdata(&dev->dev, item);
  564.     dev_info(&dev->dev, "spi registered, item=0x%p\n", (void *)item);
  565.  
  566.     info = framebuffer_alloc(sizeof(struct zteu733), &dev->dev);
  567.     if (!info) {
  568.         ret = -ENOMEM;
  569.         dev_err(&dev->dev,
  570.             "%s: unable to framebuffer_alloc\n", __func__);
  571.         goto out_item;
  572.     }
  573.     info->pseudo_palette = &item->pseudo_palette;
  574.     item->info = info;
  575.     info->par = item;
  576.     info->dev = &dev->dev;
  577.     info->fbops = &zteu733_fbops;
  578.     info->flags = FBINFO_FLAG_DEFAULT|FBINFO_VIRTFB;
  579.     info->fix = zteu733_fix;
  580.     info->var = zteu733_var;
  581.  
  582.     ret = zteu733_video_alloc(item);
  583.     if (ret) {
  584.         dev_err(&dev->dev,
  585.             "%s: unable to zteu733_video_alloc\n", __func__);
  586.         goto out_info;
  587.     }
  588.     info->screen_base = (char __iomem *)item->info->fix.smem_start;
  589.  
  590.     ret = zteu733_pages_alloc(item);
  591.     if (ret < 0) {
  592.         dev_err(&dev->dev,
  593.             "%s: unable to zteu733_pages_init\n", __func__);
  594.         goto out_video;
  595.     }
  596.  
  597.     info->fbdefio = &zteu733_defio;
  598.     fb_deferred_io_init(info);
  599.  
  600.     ret = register_framebuffer(info);
  601.     if (ret < 0) {
  602.         dev_err(&dev->dev,
  603.             "%s: unable to register_frambuffer\n", __func__);
  604.         goto out_pages;
  605.     }
  606.  
  607.  
  608.     zteu733_setup(item);
  609.     zteu733_update_all(item);
  610.  
  611.     return ret;
  612.  
  613. out_pages:
  614.     zteu733_pages_free(item);
  615. out_video:
  616.     zteu733_video_free(item);
  617. out_info:
  618.     framebuffer_release(info);
  619. out_item:
  620.     kfree(item);
  621. out:
  622.     return ret;
  623. }
  624.  
  625.     static int __devexit zteu733_remove(struct spi_device *dev)
  626. {
  627.     struct zteu733 *item = dev_get_drvdata(&dev->dev);
  628.     struct fb_info *info;
  629.  
  630.     dev_dbg(&dev->dev, "%s\n", __func__);
  631.  
  632.     dev_set_drvdata(&dev->dev, NULL);
  633.     if (item) {
  634.         info = item->info;
  635.         if (info)
  636.         unregister_framebuffer(info);
  637.         zteu733_pages_free(item);
  638.         zteu733_video_free(item);
  639.         kfree(item);
  640.         if (info)
  641.         framebuffer_release(info);
  642.     }
  643.     return 0;
  644. }
  645.  
  646. #ifdef CONFIG_PM
  647. static int zteu733_suspend(struct spi_device *spi, pm_message_t state)
  648. {
  649.     struct fb_info *info = dev_get_drvdata(&spi->dev);
  650.     struct zteu733 *item = (struct zteu733 *)info->par;
  651.     /* enter into sleep mode */
  652.     zteu733_reg_set(item, ZTEU733_REG_SLEEP_MODE, 0x0001);
  653.     return 0;
  654. }
  655.  
  656. static int zteu733_resume(struct spi_device *spi)
  657. {
  658.     struct fb_info *info = dev_get_drvdata(&spi->dev);
  659.     struct zteu733 *item = (struct zteu733 *)info->par;
  660.     /* leave sleep mode */
  661.     zteu733_reg_set(item, ZTEU733_REG_SLEEP_MODE, 0x0000);
  662.     return 0;
  663. }
  664. #else
  665. #define zteu733_suspend NULL
  666. #define zteu733_resume NULL
  667. #endif
  668.  
  669. static struct spi_driver spi_zteu733_driver = {
  670.     .driver = {
  671.         .name   = "spi-zteu733",
  672.         .bus    = &spi_bus_type,
  673.         .owner  = THIS_MODULE,
  674.     },
  675.     .probe = zteu733_probe,
  676.     .remove = zteu733_remove,
  677.     .suspend = zteu733_suspend,
  678.     .resume = zteu733_resume,
  679. };
  680.  
  681. static int __init zteu733_init(void)
  682. {
  683.     int ret = 0;
  684.  
  685.     pr_debug("%s\n", __func__);
  686.  
  687.     ret = spi_register_driver(&spi_zteu733_driver);
  688.     if (ret) {
  689.         pr_err("%s: unable to platform_driver_register\n", __func__);
  690.     }
  691.  
  692.     return ret;
  693. }
  694.  
  695. static void __exit zteu733_exit(void)
  696.     {
  697.            pr_debug("%s\n", __func__);
  698.  
  699.            spi_unregister_driver(&spi_zteu733_driver);
  700.     }
  701.    
  702.  
  703. module_init(zteu733_init);
  704. module_exit(zteu733_exit);
  705.  
  706. MODULE_DESCRIPTION("ZTEU733 LCD Driver");
  707. MODULE_AUTHOR("Jeroen Domburg <jeroen@spritesmods.com>");
  708. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement