bfin-lq035q1-fb.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. /*
  2. * Blackfin LCD Framebuffer driver SHARP LQ035Q1DH02
  3. *
  4. * Copyright 2008-2009 Analog Devices Inc.
  5. * Licensed under the GPL-2 or later.
  6. */
  7. #define DRIVER_NAME "bfin-lq035q1"
  8. #define pr_fmt(fmt) DRIVER_NAME ": " fmt
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/string.h>
  13. #include <linux/fb.h>
  14. #include <linux/init.h>
  15. #include <linux/types.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/device.h>
  18. #include <linux/backlight.h>
  19. #include <linux/lcd.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/spi/spi.h>
  23. #include <asm/blackfin.h>
  24. #include <asm/irq.h>
  25. #include <asm/dma.h>
  26. #include <asm/portmux.h>
  27. #include <asm/gptimers.h>
  28. #include <asm/bfin-lq035q1.h>
  29. #if defined(BF533_FAMILY) || defined(BF538_FAMILY)
  30. #define TIMER_HSYNC_id TIMER1_id
  31. #define TIMER_HSYNCbit TIMER1bit
  32. #define TIMER_HSYNC_STATUS_TRUN TIMER_STATUS_TRUN1
  33. #define TIMER_HSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL1
  34. #define TIMER_HSYNC_STATUS_TOVF TIMER_STATUS_TOVF1
  35. #define TIMER_VSYNC_id TIMER2_id
  36. #define TIMER_VSYNCbit TIMER2bit
  37. #define TIMER_VSYNC_STATUS_TRUN TIMER_STATUS_TRUN2
  38. #define TIMER_VSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL2
  39. #define TIMER_VSYNC_STATUS_TOVF TIMER_STATUS_TOVF2
  40. #else
  41. #define TIMER_HSYNC_id TIMER0_id
  42. #define TIMER_HSYNCbit TIMER0bit
  43. #define TIMER_HSYNC_STATUS_TRUN TIMER_STATUS_TRUN0
  44. #define TIMER_HSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL0
  45. #define TIMER_HSYNC_STATUS_TOVF TIMER_STATUS_TOVF0
  46. #define TIMER_VSYNC_id TIMER1_id
  47. #define TIMER_VSYNCbit TIMER1bit
  48. #define TIMER_VSYNC_STATUS_TRUN TIMER_STATUS_TRUN1
  49. #define TIMER_VSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL1
  50. #define TIMER_VSYNC_STATUS_TOVF TIMER_STATUS_TOVF1
  51. #endif
  52. #define LCD_X_RES 320 /* Horizontal Resolution */
  53. #define LCD_Y_RES 240 /* Vertical Resolution */
  54. #define DMA_BUS_SIZE 16
  55. #define USE_RGB565_16_BIT_PPI
  56. #ifdef USE_RGB565_16_BIT_PPI
  57. #define LCD_BPP 16 /* Bit Per Pixel */
  58. #define CLOCKS_PER_PIX 1
  59. #define CPLD_PIPELINE_DELAY_COR 0 /* NO CPLB */
  60. #endif
  61. /* Interface 16/18-bit TFT over an 8-bit wide PPI using a small Programmable Logic Device (CPLD)
  62. * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
  63. */
  64. #ifdef USE_RGB565_8_BIT_PPI
  65. #define LCD_BPP 16 /* Bit Per Pixel */
  66. #define CLOCKS_PER_PIX 2
  67. #define CPLD_PIPELINE_DELAY_COR 3 /* RGB565 */
  68. #endif
  69. #ifdef USE_RGB888_8_BIT_PPI
  70. #define LCD_BPP 24 /* Bit Per Pixel */
  71. #define CLOCKS_PER_PIX 3
  72. #define CPLD_PIPELINE_DELAY_COR 5 /* RGB888 */
  73. #endif
  74. /*
  75. * HS and VS timing parameters (all in number of PPI clk ticks)
  76. */
  77. #define U_LINE 4 /* Blanking Lines */
  78. #define H_ACTPIX (LCD_X_RES * CLOCKS_PER_PIX) /* active horizontal pixel */
  79. #define H_PERIOD (336 * CLOCKS_PER_PIX) /* HS period */
  80. #define H_PULSE (2 * CLOCKS_PER_PIX) /* HS pulse width */
  81. #define H_START (7 * CLOCKS_PER_PIX + CPLD_PIPELINE_DELAY_COR) /* first valid pixel */
  82. #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
  83. #define V_PULSE (2 * CLOCKS_PER_PIX) /* VS pulse width (1-5 H_PERIODs) */
  84. #define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
  85. #define ACTIVE_VIDEO_MEM_OFFSET ((U_LINE / 2) * LCD_X_RES * (LCD_BPP / 8))
  86. #define BFIN_LCD_NBR_PALETTE_ENTRIES 256
  87. #define PPI_TX_MODE 0x2
  88. #define PPI_XFER_TYPE_11 0xC
  89. #define PPI_PORT_CFG_01 0x10
  90. #define PPI_POLS_1 0x8000
  91. #if (CLOCKS_PER_PIX > 1)
  92. #define PPI_PMODE (DLEN_8 | PACK_EN)
  93. #else
  94. #define PPI_PMODE (DLEN_16)
  95. #endif
  96. #define LQ035_INDEX 0x74
  97. #define LQ035_DATA 0x76
  98. #define LQ035_DRIVER_OUTPUT_CTL 0x1
  99. #define LQ035_SHUT_CTL 0x11
  100. #define LQ035_DRIVER_OUTPUT_MASK (LQ035_LR | LQ035_TB | LQ035_BGR | LQ035_REV)
  101. #define LQ035_DRIVER_OUTPUT_DEFAULT (0x2AEF & ~LQ035_DRIVER_OUTPUT_MASK)
  102. #define LQ035_SHUT (1 << 0) /* Shutdown */
  103. #define LQ035_ON (0 << 0) /* Shutdown */
  104. struct bfin_lq035q1fb_info {
  105. struct fb_info *fb;
  106. struct device *dev;
  107. struct spi_driver spidrv;
  108. struct bfin_lq035q1fb_disp_info *disp_info;
  109. unsigned char *fb_buffer; /* RGB Buffer */
  110. dma_addr_t dma_handle;
  111. int lq035_open_cnt;
  112. int irq;
  113. spinlock_t lock; /* lock */
  114. u32 pseudo_pal[16];
  115. };
  116. static int nocursor;
  117. module_param(nocursor, int, 0644);
  118. MODULE_PARM_DESC(nocursor, "cursor enable/disable");
  119. struct spi_control {
  120. unsigned short mode;
  121. };
  122. static int lq035q1_control(struct spi_device *spi, unsigned char reg, unsigned short value)
  123. {
  124. int ret;
  125. u8 regs[3] = { LQ035_INDEX, 0, 0 };
  126. u8 dat[3] = { LQ035_DATA, 0, 0 };
  127. if (!spi)
  128. return -ENODEV;
  129. regs[2] = reg;
  130. dat[1] = value >> 8;
  131. dat[2] = value & 0xFF;
  132. ret = spi_write(spi, regs, ARRAY_SIZE(regs));
  133. ret |= spi_write(spi, dat, ARRAY_SIZE(dat));
  134. return ret;
  135. }
  136. static int __devinit lq035q1_spidev_probe(struct spi_device *spi)
  137. {
  138. int ret;
  139. struct spi_control *ctl;
  140. struct bfin_lq035q1fb_info *info = container_of(spi->dev.driver,
  141. struct bfin_lq035q1fb_info,
  142. spidrv.driver);
  143. ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
  144. if (!ctl)
  145. return -ENOMEM;
  146. ctl->mode = (info->disp_info->mode &
  147. LQ035_DRIVER_OUTPUT_MASK) | LQ035_DRIVER_OUTPUT_DEFAULT;
  148. ret = lq035q1_control(spi, LQ035_SHUT_CTL, LQ035_ON);
  149. ret |= lq035q1_control(spi, LQ035_DRIVER_OUTPUT_CTL, ctl->mode);
  150. if (ret)
  151. return ret;
  152. spi_set_drvdata(spi, ctl);
  153. return 0;
  154. }
  155. static int lq035q1_spidev_remove(struct spi_device *spi)
  156. {
  157. return lq035q1_control(spi, LQ035_SHUT_CTL, LQ035_SHUT);
  158. }
  159. #ifdef CONFIG_PM
  160. static int lq035q1_spidev_suspend(struct spi_device *spi, pm_message_t state)
  161. {
  162. return lq035q1_control(spi, LQ035_SHUT_CTL, LQ035_SHUT);
  163. }
  164. static int lq035q1_spidev_resume(struct spi_device *spi)
  165. {
  166. int ret;
  167. struct spi_control *ctl = spi_get_drvdata(spi);
  168. ret = lq035q1_control(spi, LQ035_DRIVER_OUTPUT_CTL, ctl->mode);
  169. if (ret)
  170. return ret;
  171. return lq035q1_control(spi, LQ035_SHUT_CTL, LQ035_ON);
  172. }
  173. #else
  174. # define lq035q1_spidev_suspend NULL
  175. # define lq035q1_spidev_resume NULL
  176. #endif
  177. /* Power down all displays on reboot, poweroff or halt */
  178. static void lq035q1_spidev_shutdown(struct spi_device *spi)
  179. {
  180. lq035q1_control(spi, LQ035_SHUT_CTL, LQ035_SHUT);
  181. }
  182. static int lq035q1_backlight(struct bfin_lq035q1fb_info *info, unsigned arg)
  183. {
  184. if (info->disp_info->use_bl)
  185. gpio_set_value(info->disp_info->gpio_bl, arg);
  186. return 0;
  187. }
  188. static void bfin_lq035q1_config_ppi(struct bfin_lq035q1fb_info *fbi)
  189. {
  190. bfin_write_PPI_DELAY(H_START);
  191. bfin_write_PPI_COUNT(H_ACTPIX - 1);
  192. bfin_write_PPI_FRAME(V_LINES);
  193. bfin_write_PPI_CONTROL(PPI_TX_MODE | /* output mode , PORT_DIR */
  194. PPI_XFER_TYPE_11 | /* sync mode XFR_TYPE */
  195. PPI_PORT_CFG_01 | /* two frame sync PORT_CFG */
  196. PPI_PMODE | /* 8/16 bit data length / PACK_EN? */
  197. PPI_POLS_1); /* faling edge syncs POLS */
  198. }
  199. static inline void bfin_lq035q1_disable_ppi(void)
  200. {
  201. bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN);
  202. }
  203. static inline void bfin_lq035q1_enable_ppi(void)
  204. {
  205. bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN);
  206. }
  207. static void bfin_lq035q1_start_timers(void)
  208. {
  209. enable_gptimers(TIMER_VSYNCbit | TIMER_HSYNCbit);
  210. }
  211. static void bfin_lq035q1_stop_timers(void)
  212. {
  213. disable_gptimers(TIMER_HSYNCbit | TIMER_VSYNCbit);
  214. set_gptimer_status(0, TIMER_HSYNC_STATUS_TRUN | TIMER_VSYNC_STATUS_TRUN |
  215. TIMER_HSYNC_STATUS_TIMIL | TIMER_VSYNC_STATUS_TIMIL |
  216. TIMER_HSYNC_STATUS_TOVF | TIMER_VSYNC_STATUS_TOVF);
  217. }
  218. static void bfin_lq035q1_init_timers(void)
  219. {
  220. bfin_lq035q1_stop_timers();
  221. set_gptimer_period(TIMER_HSYNC_id, H_PERIOD);
  222. set_gptimer_pwidth(TIMER_HSYNC_id, H_PULSE);
  223. set_gptimer_config(TIMER_HSYNC_id, TIMER_MODE_PWM | TIMER_PERIOD_CNT |
  224. TIMER_TIN_SEL | TIMER_CLK_SEL|
  225. TIMER_EMU_RUN);
  226. set_gptimer_period(TIMER_VSYNC_id, V_PERIOD);
  227. set_gptimer_pwidth(TIMER_VSYNC_id, V_PULSE);
  228. set_gptimer_config(TIMER_VSYNC_id, TIMER_MODE_PWM | TIMER_PERIOD_CNT |
  229. TIMER_TIN_SEL | TIMER_CLK_SEL |
  230. TIMER_EMU_RUN);
  231. }
  232. static void bfin_lq035q1_config_dma(struct bfin_lq035q1fb_info *fbi)
  233. {
  234. set_dma_config(CH_PPI,
  235. set_bfin_dma_config(DIR_READ, DMA_FLOW_AUTO,
  236. INTR_DISABLE, DIMENSION_2D,
  237. DATA_SIZE_16,
  238. DMA_NOSYNC_KEEP_DMA_BUF));
  239. set_dma_x_count(CH_PPI, (LCD_X_RES * LCD_BPP) / DMA_BUS_SIZE);
  240. set_dma_x_modify(CH_PPI, DMA_BUS_SIZE / 8);
  241. set_dma_y_count(CH_PPI, V_LINES);
  242. set_dma_y_modify(CH_PPI, DMA_BUS_SIZE / 8);
  243. set_dma_start_addr(CH_PPI, (unsigned long)fbi->fb_buffer);
  244. }
  245. #if (CLOCKS_PER_PIX == 1)
  246. static const u16 ppi0_req_16[] = {P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2,
  247. P_PPI0_D0, P_PPI0_D1, P_PPI0_D2,
  248. P_PPI0_D3, P_PPI0_D4, P_PPI0_D5,
  249. P_PPI0_D6, P_PPI0_D7, P_PPI0_D8,
  250. P_PPI0_D9, P_PPI0_D10, P_PPI0_D11,
  251. P_PPI0_D12, P_PPI0_D13, P_PPI0_D14,
  252. P_PPI0_D15, 0};
  253. #else
  254. static const u16 ppi0_req_16[] = {P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2,
  255. P_PPI0_D0, P_PPI0_D1, P_PPI0_D2,
  256. P_PPI0_D3, P_PPI0_D4, P_PPI0_D5,
  257. P_PPI0_D6, P_PPI0_D7, 0};
  258. #endif
  259. static inline void bfin_lq035q1_free_ports(void)
  260. {
  261. peripheral_free_list(ppi0_req_16);
  262. if (ANOMALY_05000400)
  263. gpio_free(P_IDENT(P_PPI0_FS3));
  264. }
  265. static int __devinit bfin_lq035q1_request_ports(struct platform_device *pdev)
  266. {
  267. /* ANOMALY_05000400 - PPI Does Not Start Properly In Specific Mode:
  268. * Drive PPI_FS3 Low
  269. */
  270. if (ANOMALY_05000400) {
  271. int ret = gpio_request(P_IDENT(P_PPI0_FS3), "PPI_FS3");
  272. if (ret)
  273. return ret;
  274. gpio_direction_output(P_IDENT(P_PPI0_FS3), 0);
  275. }
  276. if (peripheral_request_list(ppi0_req_16, DRIVER_NAME)) {
  277. dev_err(&pdev->dev, "requesting peripherals failed\n");
  278. return -EFAULT;
  279. }
  280. return 0;
  281. }
  282. static int bfin_lq035q1_fb_open(struct fb_info *info, int user)
  283. {
  284. struct bfin_lq035q1fb_info *fbi = info->par;
  285. spin_lock(&fbi->lock);
  286. fbi->lq035_open_cnt++;
  287. if (fbi->lq035_open_cnt <= 1) {
  288. bfin_lq035q1_disable_ppi();
  289. SSYNC();
  290. bfin_lq035q1_config_dma(fbi);
  291. bfin_lq035q1_config_ppi(fbi);
  292. bfin_lq035q1_init_timers();
  293. /* start dma */
  294. enable_dma(CH_PPI);
  295. bfin_lq035q1_enable_ppi();
  296. bfin_lq035q1_start_timers();
  297. lq035q1_backlight(fbi, 1);
  298. }
  299. spin_unlock(&fbi->lock);
  300. return 0;
  301. }
  302. static int bfin_lq035q1_fb_release(struct fb_info *info, int user)
  303. {
  304. struct bfin_lq035q1fb_info *fbi = info->par;
  305. spin_lock(&fbi->lock);
  306. fbi->lq035_open_cnt--;
  307. if (fbi->lq035_open_cnt <= 0) {
  308. lq035q1_backlight(fbi, 0);
  309. bfin_lq035q1_disable_ppi();
  310. SSYNC();
  311. disable_dma(CH_PPI);
  312. bfin_lq035q1_stop_timers();
  313. }
  314. spin_unlock(&fbi->lock);
  315. return 0;
  316. }
  317. static int bfin_lq035q1_fb_check_var(struct fb_var_screeninfo *var,
  318. struct fb_info *info)
  319. {
  320. switch (var->bits_per_pixel) {
  321. #if (LCD_BPP == 24)
  322. case 24:/* TRUECOLOUR, 16m */
  323. #else
  324. case 16:/* DIRECTCOLOUR, 64k */
  325. #endif
  326. var->red.offset = info->var.red.offset;
  327. var->green.offset = info->var.green.offset;
  328. var->blue.offset = info->var.blue.offset;
  329. var->red.length = info->var.red.length;
  330. var->green.length = info->var.green.length;
  331. var->blue.length = info->var.blue.length;
  332. var->transp.offset = 0;
  333. var->transp.length = 0;
  334. var->transp.msb_right = 0;
  335. var->red.msb_right = 0;
  336. var->green.msb_right = 0;
  337. var->blue.msb_right = 0;
  338. break;
  339. default:
  340. pr_debug("%s: depth not supported: %u BPP\n", __func__,
  341. var->bits_per_pixel);
  342. return -EINVAL;
  343. }
  344. if (info->var.xres != var->xres || info->var.yres != var->yres ||
  345. info->var.xres_virtual != var->xres_virtual ||
  346. info->var.yres_virtual != var->yres_virtual) {
  347. pr_debug("%s: Resolution not supported: X%u x Y%u \n",
  348. __func__, var->xres, var->yres);
  349. return -EINVAL;
  350. }
  351. /*
  352. * Memory limit
  353. */
  354. if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) {
  355. pr_debug("%s: Memory Limit requested yres_virtual = %u\n",
  356. __func__, var->yres_virtual);
  357. return -ENOMEM;
  358. }
  359. return 0;
  360. }
  361. int bfin_lq035q1_fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  362. {
  363. if (nocursor)
  364. return 0;
  365. else
  366. return -EINVAL; /* just to force soft_cursor() call */
  367. }
  368. static int bfin_lq035q1_fb_setcolreg(u_int regno, u_int red, u_int green,
  369. u_int blue, u_int transp,
  370. struct fb_info *info)
  371. {
  372. if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES)
  373. return -EINVAL;
  374. if (info->var.grayscale) {
  375. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  376. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  377. }
  378. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  379. u32 value;
  380. /* Place color in the pseudopalette */
  381. if (regno > 16)
  382. return -EINVAL;
  383. red >>= (16 - info->var.red.length);
  384. green >>= (16 - info->var.green.length);
  385. blue >>= (16 - info->var.blue.length);
  386. value = (red << info->var.red.offset) |
  387. (green << info->var.green.offset) |
  388. (blue << info->var.blue.offset);
  389. value &= 0xFFFFFF;
  390. ((u32 *) (info->pseudo_palette))[regno] = value;
  391. }
  392. return 0;
  393. }
  394. static struct fb_ops bfin_lq035q1_fb_ops = {
  395. .owner = THIS_MODULE,
  396. .fb_open = bfin_lq035q1_fb_open,
  397. .fb_release = bfin_lq035q1_fb_release,
  398. .fb_check_var = bfin_lq035q1_fb_check_var,
  399. .fb_fillrect = cfb_fillrect,
  400. .fb_copyarea = cfb_copyarea,
  401. .fb_imageblit = cfb_imageblit,
  402. .fb_cursor = bfin_lq035q1_fb_cursor,
  403. .fb_setcolreg = bfin_lq035q1_fb_setcolreg,
  404. };
  405. static irqreturn_t bfin_lq035q1_irq_error(int irq, void *dev_id)
  406. {
  407. /*struct bfin_lq035q1fb_info *info = (struct bfin_lq035q1fb_info *)dev_id;*/
  408. u16 status = bfin_read_PPI_STATUS();
  409. bfin_write_PPI_STATUS(-1);
  410. if (status) {
  411. bfin_lq035q1_disable_ppi();
  412. disable_dma(CH_PPI);
  413. /* start dma */
  414. enable_dma(CH_PPI);
  415. bfin_lq035q1_enable_ppi();
  416. bfin_write_PPI_STATUS(-1);
  417. }
  418. return IRQ_HANDLED;
  419. }
  420. static int __devinit bfin_lq035q1_probe(struct platform_device *pdev)
  421. {
  422. struct bfin_lq035q1fb_info *info;
  423. struct fb_info *fbinfo;
  424. int ret;
  425. ret = request_dma(CH_PPI, DRIVER_NAME"_CH_PPI");
  426. if (ret < 0) {
  427. dev_err(&pdev->dev, "PPI DMA unavailable\n");
  428. goto out1;
  429. }
  430. fbinfo = framebuffer_alloc(sizeof(*info), &pdev->dev);
  431. if (!fbinfo) {
  432. ret = -ENOMEM;
  433. goto out2;
  434. }
  435. info = fbinfo->par;
  436. info->fb = fbinfo;
  437. info->dev = &pdev->dev;
  438. info->disp_info = pdev->dev.platform_data;
  439. platform_set_drvdata(pdev, fbinfo);
  440. strcpy(fbinfo->fix.id, DRIVER_NAME);
  441. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  442. fbinfo->fix.type_aux = 0;
  443. fbinfo->fix.xpanstep = 0;
  444. fbinfo->fix.ypanstep = 0;
  445. fbinfo->fix.ywrapstep = 0;
  446. fbinfo->fix.accel = FB_ACCEL_NONE;
  447. fbinfo->fix.visual = FB_VISUAL_TRUECOLOR;
  448. fbinfo->var.nonstd = 0;
  449. fbinfo->var.activate = FB_ACTIVATE_NOW;
  450. fbinfo->var.height = -1;
  451. fbinfo->var.width = -1;
  452. fbinfo->var.accel_flags = 0;
  453. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  454. fbinfo->var.xres = LCD_X_RES;
  455. fbinfo->var.xres_virtual = LCD_X_RES;
  456. fbinfo->var.yres = LCD_Y_RES;
  457. fbinfo->var.yres_virtual = LCD_Y_RES;
  458. fbinfo->var.bits_per_pixel = LCD_BPP;
  459. if (info->disp_info->mode & LQ035_BGR) {
  460. #if (LCD_BPP == 24)
  461. fbinfo->var.red.offset = 0;
  462. fbinfo->var.green.offset = 8;
  463. fbinfo->var.blue.offset = 16;
  464. #else
  465. fbinfo->var.red.offset = 0;
  466. fbinfo->var.green.offset = 5;
  467. fbinfo->var.blue.offset = 11;
  468. #endif
  469. } else {
  470. #if (LCD_BPP == 24)
  471. fbinfo->var.red.offset = 16;
  472. fbinfo->var.green.offset = 8;
  473. fbinfo->var.blue.offset = 0;
  474. #else
  475. fbinfo->var.red.offset = 11;
  476. fbinfo->var.green.offset = 5;
  477. fbinfo->var.blue.offset = 0;
  478. #endif
  479. }
  480. fbinfo->var.transp.offset = 0;
  481. #if (LCD_BPP == 24)
  482. fbinfo->var.red.length = 8;
  483. fbinfo->var.green.length = 8;
  484. fbinfo->var.blue.length = 8;
  485. #else
  486. fbinfo->var.red.length = 5;
  487. fbinfo->var.green.length = 6;
  488. fbinfo->var.blue.length = 5;
  489. #endif
  490. fbinfo->var.transp.length = 0;
  491. fbinfo->fix.smem_len = LCD_X_RES * LCD_Y_RES * LCD_BPP / 8
  492. + ACTIVE_VIDEO_MEM_OFFSET;
  493. fbinfo->fix.line_length = fbinfo->var.xres_virtual *
  494. fbinfo->var.bits_per_pixel / 8;
  495. fbinfo->fbops = &bfin_lq035q1_fb_ops;
  496. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  497. info->fb_buffer =
  498. dma_alloc_coherent(NULL, fbinfo->fix.smem_len, &info->dma_handle,
  499. GFP_KERNEL);
  500. if (NULL == info->fb_buffer) {
  501. dev_err(&pdev->dev, "couldn't allocate dma buffer\n");
  502. ret = -ENOMEM;
  503. goto out3;
  504. }
  505. fbinfo->screen_base = (void *)info->fb_buffer + ACTIVE_VIDEO_MEM_OFFSET;
  506. fbinfo->fix.smem_start = (int)info->fb_buffer + ACTIVE_VIDEO_MEM_OFFSET;
  507. fbinfo->fbops = &bfin_lq035q1_fb_ops;
  508. fbinfo->pseudo_palette = &info->pseudo_pal;
  509. ret = fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0);
  510. if (ret < 0) {
  511. dev_err(&pdev->dev, "failed to allocate colormap (%d entries)\n",
  512. BFIN_LCD_NBR_PALETTE_ENTRIES);
  513. goto out4;
  514. }
  515. ret = bfin_lq035q1_request_ports(pdev);
  516. if (ret) {
  517. dev_err(&pdev->dev, "couldn't request gpio port\n");
  518. goto out6;
  519. }
  520. info->irq = platform_get_irq(pdev, 0);
  521. if (info->irq < 0) {
  522. ret = -EINVAL;
  523. goto out7;
  524. }
  525. ret = request_irq(info->irq, bfin_lq035q1_irq_error, IRQF_DISABLED,
  526. DRIVER_NAME" PPI ERROR", info);
  527. if (ret < 0) {
  528. dev_err(&pdev->dev, "unable to request PPI ERROR IRQ\n");
  529. goto out7;
  530. }
  531. info->spidrv.driver.name = DRIVER_NAME"-spi";
  532. info->spidrv.probe = lq035q1_spidev_probe;
  533. info->spidrv.remove = __devexit_p(lq035q1_spidev_remove);
  534. info->spidrv.shutdown = lq035q1_spidev_shutdown;
  535. info->spidrv.suspend = lq035q1_spidev_suspend;
  536. info->spidrv.resume = lq035q1_spidev_resume;
  537. ret = spi_register_driver(&info->spidrv);
  538. if (ret < 0) {
  539. dev_err(&pdev->dev, "couldn't register SPI Interface\n");
  540. goto out8;
  541. }
  542. if (info->disp_info->use_bl) {
  543. ret = gpio_request(info->disp_info->gpio_bl, "LQ035 Backlight");
  544. if (ret) {
  545. dev_err(&pdev->dev, "failed to request GPIO %d\n",
  546. info->disp_info->gpio_bl);
  547. goto out9;
  548. }
  549. gpio_direction_output(info->disp_info->gpio_bl, 0);
  550. }
  551. ret = register_framebuffer(fbinfo);
  552. if (ret < 0) {
  553. dev_err(&pdev->dev, "unable to register framebuffer\n");
  554. goto out10;
  555. }
  556. dev_info(&pdev->dev, "%dx%d %d-bit RGB FrameBuffer initialized\n",
  557. LCD_X_RES, LCD_Y_RES, LCD_BPP);
  558. return 0;
  559. out10:
  560. if (info->disp_info->use_bl)
  561. gpio_free(info->disp_info->gpio_bl);
  562. out9:
  563. spi_unregister_driver(&info->spidrv);
  564. out8:
  565. free_irq(info->irq, info);
  566. out7:
  567. bfin_lq035q1_free_ports();
  568. out6:
  569. fb_dealloc_cmap(&fbinfo->cmap);
  570. out4:
  571. dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
  572. info->dma_handle);
  573. out3:
  574. framebuffer_release(fbinfo);
  575. out2:
  576. free_dma(CH_PPI);
  577. out1:
  578. platform_set_drvdata(pdev, NULL);
  579. return ret;
  580. }
  581. static int __devexit bfin_lq035q1_remove(struct platform_device *pdev)
  582. {
  583. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  584. struct bfin_lq035q1fb_info *info = fbinfo->par;
  585. if (info->disp_info->use_bl)
  586. gpio_free(info->disp_info->gpio_bl);
  587. spi_unregister_driver(&info->spidrv);
  588. unregister_framebuffer(fbinfo);
  589. free_dma(CH_PPI);
  590. free_irq(info->irq, info);
  591. if (info->fb_buffer != NULL)
  592. dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
  593. info->dma_handle);
  594. fb_dealloc_cmap(&fbinfo->cmap);
  595. bfin_lq035q1_free_ports();
  596. platform_set_drvdata(pdev, NULL);
  597. framebuffer_release(fbinfo);
  598. dev_info(&pdev->dev, "unregistered LCD driver\n");
  599. return 0;
  600. }
  601. #ifdef CONFIG_PM
  602. static int bfin_lq035q1_suspend(struct device *dev)
  603. {
  604. struct fb_info *fbinfo = dev_get_drvdata(dev);
  605. struct bfin_lq035q1fb_info *info = fbinfo->par;
  606. if (info->lq035_open_cnt) {
  607. lq035q1_backlight(info, 0);
  608. bfin_lq035q1_disable_ppi();
  609. SSYNC();
  610. disable_dma(CH_PPI);
  611. bfin_lq035q1_stop_timers();
  612. bfin_write_PPI_STATUS(-1);
  613. }
  614. return 0;
  615. }
  616. static int bfin_lq035q1_resume(struct device *dev)
  617. {
  618. struct fb_info *fbinfo = dev_get_drvdata(dev);
  619. struct bfin_lq035q1fb_info *info = fbinfo->par;
  620. if (info->lq035_open_cnt) {
  621. bfin_lq035q1_disable_ppi();
  622. SSYNC();
  623. bfin_lq035q1_config_dma(info);
  624. bfin_lq035q1_config_ppi(info);
  625. bfin_lq035q1_init_timers();
  626. /* start dma */
  627. enable_dma(CH_PPI);
  628. bfin_lq035q1_enable_ppi();
  629. bfin_lq035q1_start_timers();
  630. lq035q1_backlight(info, 1);
  631. }
  632. return 0;
  633. }
  634. static struct dev_pm_ops bfin_lq035q1_dev_pm_ops = {
  635. .suspend = bfin_lq035q1_suspend,
  636. .resume = bfin_lq035q1_resume,
  637. };
  638. #endif
  639. static struct platform_driver bfin_lq035q1_driver = {
  640. .probe = bfin_lq035q1_probe,
  641. .remove = __devexit_p(bfin_lq035q1_remove),
  642. .driver = {
  643. .name = DRIVER_NAME,
  644. #ifdef CONFIG_PM
  645. .pm = &bfin_lq035q1_dev_pm_ops,
  646. #endif
  647. },
  648. };
  649. static int __init bfin_lq035q1_driver_init(void)
  650. {
  651. return platform_driver_register(&bfin_lq035q1_driver);
  652. }
  653. module_init(bfin_lq035q1_driver_init);
  654. static void __exit bfin_lq035q1_driver_cleanup(void)
  655. {
  656. platform_driver_unregister(&bfin_lq035q1_driver);
  657. }
  658. module_exit(bfin_lq035q1_driver_cleanup);
  659. MODULE_DESCRIPTION("Blackfin TFT LCD Driver");
  660. MODULE_LICENSE("GPL");