bfin-lq035q1-fb.c 21 KB

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