bfin-lq035q1-fb.c 21 KB

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