bfin-lq035q1-fb.c 21 KB

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