bf54x-lq043fb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * File: drivers/video/bf54x-lq043.c
  3. * Based on:
  4. * Author: Michael Hennerich <hennerich@blackfin.uclinux.org>
  5. *
  6. * Created:
  7. * Description: ADSP-BF54x Framebuffer driver
  8. *
  9. *
  10. * Modified:
  11. * Copyright 2007-2008 Analog Devices Inc.
  12. *
  13. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, see the file COPYING, or write
  27. * to the Free Software Foundation, Inc.,
  28. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #include <linux/module.h>
  31. #include <linux/kernel.h>
  32. #include <linux/errno.h>
  33. #include <linux/string.h>
  34. #include <linux/mm.h>
  35. #include <linux/tty.h>
  36. #include <linux/slab.h>
  37. #include <linux/delay.h>
  38. #include <linux/fb.h>
  39. #include <linux/ioport.h>
  40. #include <linux/init.h>
  41. #include <linux/types.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/sched.h>
  44. #include <linux/timer.h>
  45. #include <linux/device.h>
  46. #include <linux/backlight.h>
  47. #include <linux/lcd.h>
  48. #include <linux/spinlock.h>
  49. #include <linux/dma-mapping.h>
  50. #include <linux/platform_device.h>
  51. #include <asm/blackfin.h>
  52. #include <asm/irq.h>
  53. #include <asm/dpmc.h>
  54. #include <asm/dma-mapping.h>
  55. #include <asm/dma.h>
  56. #include <asm/gpio.h>
  57. #include <asm/portmux.h>
  58. #include <mach/bf54x-lq043.h>
  59. #define NO_BL_SUPPORT
  60. #define DRIVER_NAME "bf54x-lq043"
  61. static char driver_name[] = DRIVER_NAME;
  62. #define BFIN_LCD_NBR_PALETTE_ENTRIES 256
  63. #define EPPI0_18 {P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2, P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, P_PPI0_D3, \
  64. P_PPI0_D4, P_PPI0_D5, P_PPI0_D6, P_PPI0_D7, P_PPI0_D8, P_PPI0_D9, P_PPI0_D10, \
  65. P_PPI0_D11, P_PPI0_D12, P_PPI0_D13, P_PPI0_D14, P_PPI0_D15, P_PPI0_D16, P_PPI0_D17, 0}
  66. #define EPPI0_24 {P_PPI0_D18, P_PPI0_D19, P_PPI0_D20, P_PPI0_D21, P_PPI0_D22, P_PPI0_D23, 0}
  67. struct bfin_bf54xfb_info {
  68. struct fb_info *fb;
  69. struct device *dev;
  70. struct bfin_bf54xfb_mach_info *mach_info;
  71. unsigned char *fb_buffer; /* RGB Buffer */
  72. dma_addr_t dma_handle;
  73. int lq043_open_cnt;
  74. int irq;
  75. spinlock_t lock; /* lock */
  76. };
  77. static int nocursor;
  78. module_param(nocursor, int, 0644);
  79. MODULE_PARM_DESC(nocursor, "cursor enable/disable");
  80. static int outp_rgb666;
  81. module_param(outp_rgb666, int, 0);
  82. MODULE_PARM_DESC(outp_rgb666, "Output 18-bit RGB666");
  83. #define LCD_X_RES 480 /*Horizontal Resolution */
  84. #define LCD_Y_RES 272 /* Vertical Resolution */
  85. #define LCD_BPP 24 /* Bit Per Pixel */
  86. #define DMA_BUS_SIZE 32
  87. /* -- Horizontal synchronizing --
  88. *
  89. * Timing characteristics taken from the SHARP LQ043T1DG01 datasheet
  90. * (LCY-W-06602A Page 9 of 22)
  91. *
  92. * Clock Frequency 1/Tc Min 7.83 Typ 9.00 Max 9.26 MHz
  93. *
  94. * Period TH - 525 - Clock
  95. * Pulse width THp - 41 - Clock
  96. * Horizontal period THd - 480 - Clock
  97. * Back porch THb - 2 - Clock
  98. * Front porch THf - 2 - Clock
  99. *
  100. * -- Vertical synchronizing --
  101. * Period TV - 286 - Line
  102. * Pulse width TVp - 10 - Line
  103. * Vertical period TVd - 272 - Line
  104. * Back porch TVb - 2 - Line
  105. * Front porch TVf - 2 - Line
  106. */
  107. #define LCD_CLK (8*1000*1000) /* 8MHz */
  108. /* # active data to transfer after Horizontal Delay clock */
  109. #define EPPI_HCOUNT LCD_X_RES
  110. /* # active lines to transfer after Vertical Delay clock */
  111. #define EPPI_VCOUNT LCD_Y_RES
  112. /* Samples per Line = 480 (active data) + 45 (padding) */
  113. #define EPPI_LINE 525
  114. /* Lines per Frame = 272 (active data) + 14 (padding) */
  115. #define EPPI_FRAME 286
  116. /* FS1 (Hsync) Width (Typical)*/
  117. #define EPPI_FS1W_HBL 41
  118. /* FS1 (Hsync) Period (Typical) */
  119. #define EPPI_FS1P_AVPL EPPI_LINE
  120. /* Horizontal Delay clock after assertion of Hsync (Typical) */
  121. #define EPPI_HDELAY 43
  122. /* FS2 (Vsync) Width = FS1 (Hsync) Period * 10 */
  123. #define EPPI_FS2W_LVB (EPPI_LINE * 10)
  124. /* FS2 (Vsync) Period = FS1 (Hsync) Period * Lines per Frame */
  125. #define EPPI_FS2P_LAVF (EPPI_LINE * EPPI_FRAME)
  126. /* Vertical Delay after assertion of Vsync (2 Lines) */
  127. #define EPPI_VDELAY 12
  128. #define EPPI_CLIP 0xFF00FF00
  129. /* EPPI Control register configuration value for RGB out
  130. * - EPPI as Output
  131. * GP 2 frame sync mode,
  132. * Internal Clock generation disabled, Internal FS generation enabled,
  133. * Receives samples on EPPI_CLK raising edge, Transmits samples on EPPI_CLK falling edge,
  134. * FS1 & FS2 are active high,
  135. * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
  136. * DMA Unpacking disabled when RGB Formating is enabled, otherwise DMA unpacking enabled
  137. * Swapping Enabled,
  138. * One (DMA) Channel Mode,
  139. * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
  140. * Regular watermark - when FIFO is 100% full,
  141. * Urgent watermark - when FIFO is 75% full
  142. */
  143. #define EPPI_CONTROL (0x20136E2E | SWAPEN)
  144. static inline u16 get_eppi_clkdiv(u32 target_ppi_clk)
  145. {
  146. u32 sclk = get_sclk();
  147. /* EPPI_CLK = (SCLK) / (2 * (EPPI_CLKDIV[15:0] + 1)) */
  148. return (((sclk / target_ppi_clk) / 2) - 1);
  149. }
  150. static void config_ppi(struct bfin_bf54xfb_info *fbi)
  151. {
  152. u16 eppi_clkdiv = get_eppi_clkdiv(LCD_CLK);
  153. bfin_write_EPPI0_FS1W_HBL(EPPI_FS1W_HBL);
  154. bfin_write_EPPI0_FS1P_AVPL(EPPI_FS1P_AVPL);
  155. bfin_write_EPPI0_FS2W_LVB(EPPI_FS2W_LVB);
  156. bfin_write_EPPI0_FS2P_LAVF(EPPI_FS2P_LAVF);
  157. bfin_write_EPPI0_CLIP(EPPI_CLIP);
  158. bfin_write_EPPI0_FRAME(EPPI_FRAME);
  159. bfin_write_EPPI0_LINE(EPPI_LINE);
  160. bfin_write_EPPI0_HCOUNT(EPPI_HCOUNT);
  161. bfin_write_EPPI0_HDELAY(EPPI_HDELAY);
  162. bfin_write_EPPI0_VCOUNT(EPPI_VCOUNT);
  163. bfin_write_EPPI0_VDELAY(EPPI_VDELAY);
  164. bfin_write_EPPI0_CLKDIV(eppi_clkdiv);
  165. /*
  166. * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
  167. * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
  168. */
  169. if (outp_rgb666)
  170. bfin_write_EPPI0_CONTROL((EPPI_CONTROL & ~DLENGTH) | DLEN_18 |
  171. RGB_FMT_EN);
  172. else
  173. bfin_write_EPPI0_CONTROL(((EPPI_CONTROL & ~DLENGTH) | DLEN_24) &
  174. ~RGB_FMT_EN);
  175. }
  176. static int config_dma(struct bfin_bf54xfb_info *fbi)
  177. {
  178. set_dma_config(CH_EPPI0,
  179. set_bfin_dma_config(DIR_READ, DMA_FLOW_AUTO,
  180. INTR_DISABLE, DIMENSION_2D,
  181. DATA_SIZE_32,
  182. DMA_NOSYNC_KEEP_DMA_BUF));
  183. set_dma_x_count(CH_EPPI0, (LCD_X_RES * LCD_BPP) / DMA_BUS_SIZE);
  184. set_dma_x_modify(CH_EPPI0, DMA_BUS_SIZE / 8);
  185. set_dma_y_count(CH_EPPI0, LCD_Y_RES);
  186. set_dma_y_modify(CH_EPPI0, DMA_BUS_SIZE / 8);
  187. set_dma_start_addr(CH_EPPI0, (unsigned long)fbi->fb_buffer);
  188. return 0;
  189. }
  190. static int request_ports(struct bfin_bf54xfb_info *fbi)
  191. {
  192. u16 eppi_req_18[] = EPPI0_18;
  193. u16 disp = fbi->mach_info->disp;
  194. if (gpio_request_one(disp, GPIOF_OUT_INIT_HIGH, DRIVER_NAME)) {
  195. printk(KERN_ERR "Requesting GPIO %d failed\n", disp);
  196. return -EFAULT;
  197. }
  198. if (peripheral_request_list(eppi_req_18, DRIVER_NAME)) {
  199. printk(KERN_ERR "Requesting Peripherals failed\n");
  200. gpio_free(disp);
  201. return -EFAULT;
  202. }
  203. if (!outp_rgb666) {
  204. u16 eppi_req_24[] = EPPI0_24;
  205. if (peripheral_request_list(eppi_req_24, DRIVER_NAME)) {
  206. printk(KERN_ERR "Requesting Peripherals failed\n");
  207. peripheral_free_list(eppi_req_18);
  208. gpio_free(disp);
  209. return -EFAULT;
  210. }
  211. }
  212. return 0;
  213. }
  214. static void free_ports(struct bfin_bf54xfb_info *fbi)
  215. {
  216. u16 eppi_req_18[] = EPPI0_18;
  217. gpio_free(fbi->mach_info->disp);
  218. peripheral_free_list(eppi_req_18);
  219. if (!outp_rgb666) {
  220. u16 eppi_req_24[] = EPPI0_24;
  221. peripheral_free_list(eppi_req_24);
  222. }
  223. }
  224. static int bfin_bf54x_fb_open(struct fb_info *info, int user)
  225. {
  226. struct bfin_bf54xfb_info *fbi = info->par;
  227. spin_lock(&fbi->lock);
  228. fbi->lq043_open_cnt++;
  229. if (fbi->lq043_open_cnt <= 1) {
  230. bfin_write_EPPI0_CONTROL(0);
  231. SSYNC();
  232. config_dma(fbi);
  233. config_ppi(fbi);
  234. /* start dma */
  235. enable_dma(CH_EPPI0);
  236. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  237. }
  238. spin_unlock(&fbi->lock);
  239. return 0;
  240. }
  241. static int bfin_bf54x_fb_release(struct fb_info *info, int user)
  242. {
  243. struct bfin_bf54xfb_info *fbi = info->par;
  244. spin_lock(&fbi->lock);
  245. fbi->lq043_open_cnt--;
  246. if (fbi->lq043_open_cnt <= 0) {
  247. bfin_write_EPPI0_CONTROL(0);
  248. SSYNC();
  249. disable_dma(CH_EPPI0);
  250. }
  251. spin_unlock(&fbi->lock);
  252. return 0;
  253. }
  254. static int bfin_bf54x_fb_check_var(struct fb_var_screeninfo *var,
  255. struct fb_info *info)
  256. {
  257. switch (var->bits_per_pixel) {
  258. case 24:/* TRUECOLOUR, 16m */
  259. var->red.offset = 16;
  260. var->green.offset = 8;
  261. var->blue.offset = 0;
  262. var->red.length = var->green.length = var->blue.length = 8;
  263. var->transp.offset = 0;
  264. var->transp.length = 0;
  265. var->transp.msb_right = 0;
  266. var->red.msb_right = 0;
  267. var->green.msb_right = 0;
  268. var->blue.msb_right = 0;
  269. break;
  270. default:
  271. pr_debug("%s: depth not supported: %u BPP\n", __func__,
  272. var->bits_per_pixel);
  273. return -EINVAL;
  274. }
  275. if (info->var.xres != var->xres || info->var.yres != var->yres ||
  276. info->var.xres_virtual != var->xres_virtual ||
  277. info->var.yres_virtual != var->yres_virtual) {
  278. pr_debug("%s: Resolution not supported: X%u x Y%u \n",
  279. __func__, var->xres, var->yres);
  280. return -EINVAL;
  281. }
  282. /*
  283. * Memory limit
  284. */
  285. if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) {
  286. pr_debug("%s: Memory Limit requested yres_virtual = %u\n",
  287. __func__, var->yres_virtual);
  288. return -ENOMEM;
  289. }
  290. return 0;
  291. }
  292. int bfin_bf54x_fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  293. {
  294. if (nocursor)
  295. return 0;
  296. else
  297. return -EINVAL; /* just to force soft_cursor() call */
  298. }
  299. static int bfin_bf54x_fb_setcolreg(u_int regno, u_int red, u_int green,
  300. u_int blue, u_int transp,
  301. struct fb_info *info)
  302. {
  303. if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES)
  304. return -EINVAL;
  305. if (info->var.grayscale) {
  306. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  307. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  308. }
  309. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  310. u32 value;
  311. /* Place color in the pseudopalette */
  312. if (regno > 16)
  313. return -EINVAL;
  314. red >>= (16 - info->var.red.length);
  315. green >>= (16 - info->var.green.length);
  316. blue >>= (16 - info->var.blue.length);
  317. value = (red << info->var.red.offset) |
  318. (green << info->var.green.offset) |
  319. (blue << info->var.blue.offset);
  320. value &= 0xFFFFFF;
  321. ((u32 *) (info->pseudo_palette))[regno] = value;
  322. }
  323. return 0;
  324. }
  325. static struct fb_ops bfin_bf54x_fb_ops = {
  326. .owner = THIS_MODULE,
  327. .fb_open = bfin_bf54x_fb_open,
  328. .fb_release = bfin_bf54x_fb_release,
  329. .fb_check_var = bfin_bf54x_fb_check_var,
  330. .fb_fillrect = cfb_fillrect,
  331. .fb_copyarea = cfb_copyarea,
  332. .fb_imageblit = cfb_imageblit,
  333. .fb_cursor = bfin_bf54x_fb_cursor,
  334. .fb_setcolreg = bfin_bf54x_fb_setcolreg,
  335. };
  336. #ifndef NO_BL_SUPPORT
  337. static int bl_get_brightness(struct backlight_device *bd)
  338. {
  339. return 0;
  340. }
  341. static const struct backlight_ops bfin_lq043fb_bl_ops = {
  342. .get_brightness = bl_get_brightness,
  343. };
  344. static struct backlight_device *bl_dev;
  345. static int bfin_lcd_get_power(struct lcd_device *dev)
  346. {
  347. return 0;
  348. }
  349. static int bfin_lcd_set_power(struct lcd_device *dev, int power)
  350. {
  351. return 0;
  352. }
  353. static int bfin_lcd_get_contrast(struct lcd_device *dev)
  354. {
  355. return 0;
  356. }
  357. static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast)
  358. {
  359. return 0;
  360. }
  361. static int bfin_lcd_check_fb(struct lcd_device *dev, struct fb_info *fi)
  362. {
  363. if (!fi || (fi == &bfin_bf54x_fb))
  364. return 1;
  365. return 0;
  366. }
  367. static struct lcd_ops bfin_lcd_ops = {
  368. .get_power = bfin_lcd_get_power,
  369. .set_power = bfin_lcd_set_power,
  370. .get_contrast = bfin_lcd_get_contrast,
  371. .set_contrast = bfin_lcd_set_contrast,
  372. .check_fb = bfin_lcd_check_fb,
  373. };
  374. static struct lcd_device *lcd_dev;
  375. #endif
  376. static irqreturn_t bfin_bf54x_irq_error(int irq, void *dev_id)
  377. {
  378. /*struct bfin_bf54xfb_info *info = dev_id;*/
  379. u16 status = bfin_read_EPPI0_STATUS();
  380. bfin_write_EPPI0_STATUS(0xFFFF);
  381. if (status) {
  382. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);
  383. disable_dma(CH_EPPI0);
  384. /* start dma */
  385. enable_dma(CH_EPPI0);
  386. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  387. bfin_write_EPPI0_STATUS(0xFFFF);
  388. }
  389. return IRQ_HANDLED;
  390. }
  391. static int __devinit bfin_bf54x_probe(struct platform_device *pdev)
  392. {
  393. #ifndef NO_BL_SUPPORT
  394. struct backlight_properties props;
  395. #endif
  396. struct bfin_bf54xfb_info *info;
  397. struct fb_info *fbinfo;
  398. int ret;
  399. printk(KERN_INFO DRIVER_NAME ": FrameBuffer initializing...\n");
  400. if (request_dma(CH_EPPI0, "CH_EPPI0") < 0) {
  401. printk(KERN_ERR DRIVER_NAME
  402. ": couldn't request CH_EPPI0 DMA\n");
  403. ret = -EFAULT;
  404. goto out1;
  405. }
  406. fbinfo =
  407. framebuffer_alloc(sizeof(struct bfin_bf54xfb_info), &pdev->dev);
  408. if (!fbinfo) {
  409. ret = -ENOMEM;
  410. goto out2;
  411. }
  412. info = fbinfo->par;
  413. info->fb = fbinfo;
  414. info->dev = &pdev->dev;
  415. platform_set_drvdata(pdev, fbinfo);
  416. strcpy(fbinfo->fix.id, driver_name);
  417. info->mach_info = pdev->dev.platform_data;
  418. if (info->mach_info == NULL) {
  419. dev_err(&pdev->dev,
  420. "no platform data for lcd, cannot attach\n");
  421. ret = -EINVAL;
  422. goto out3;
  423. }
  424. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  425. fbinfo->fix.type_aux = 0;
  426. fbinfo->fix.xpanstep = 0;
  427. fbinfo->fix.ypanstep = 0;
  428. fbinfo->fix.ywrapstep = 0;
  429. fbinfo->fix.accel = FB_ACCEL_NONE;
  430. fbinfo->fix.visual = FB_VISUAL_TRUECOLOR;
  431. fbinfo->var.nonstd = 0;
  432. fbinfo->var.activate = FB_ACTIVATE_NOW;
  433. fbinfo->var.height = info->mach_info->height;
  434. fbinfo->var.width = info->mach_info->width;
  435. fbinfo->var.accel_flags = 0;
  436. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  437. fbinfo->fbops = &bfin_bf54x_fb_ops;
  438. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  439. fbinfo->var.xres = info->mach_info->xres.defval;
  440. fbinfo->var.xres_virtual = info->mach_info->xres.defval;
  441. fbinfo->var.yres = info->mach_info->yres.defval;
  442. fbinfo->var.yres_virtual = info->mach_info->yres.defval;
  443. fbinfo->var.bits_per_pixel = info->mach_info->bpp.defval;
  444. fbinfo->var.upper_margin = 0;
  445. fbinfo->var.lower_margin = 0;
  446. fbinfo->var.vsync_len = 0;
  447. fbinfo->var.left_margin = 0;
  448. fbinfo->var.right_margin = 0;
  449. fbinfo->var.hsync_len = 0;
  450. fbinfo->var.red.offset = 16;
  451. fbinfo->var.green.offset = 8;
  452. fbinfo->var.blue.offset = 0;
  453. fbinfo->var.transp.offset = 0;
  454. fbinfo->var.red.length = 8;
  455. fbinfo->var.green.length = 8;
  456. fbinfo->var.blue.length = 8;
  457. fbinfo->var.transp.length = 0;
  458. fbinfo->fix.smem_len = info->mach_info->xres.max *
  459. info->mach_info->yres.max * info->mach_info->bpp.max / 8;
  460. fbinfo->fix.line_length = fbinfo->var.xres_virtual *
  461. fbinfo->var.bits_per_pixel / 8;
  462. info->fb_buffer =
  463. dma_alloc_coherent(NULL, fbinfo->fix.smem_len, &info->dma_handle,
  464. GFP_KERNEL);
  465. if (NULL == info->fb_buffer) {
  466. printk(KERN_ERR DRIVER_NAME
  467. ": couldn't allocate dma buffer.\n");
  468. ret = -ENOMEM;
  469. goto out3;
  470. }
  471. fbinfo->screen_base = (void *)info->fb_buffer;
  472. fbinfo->fix.smem_start = (int)info->fb_buffer;
  473. fbinfo->fbops = &bfin_bf54x_fb_ops;
  474. fbinfo->pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
  475. if (!fbinfo->pseudo_palette) {
  476. printk(KERN_ERR DRIVER_NAME
  477. "Fail to allocate pseudo_palette\n");
  478. ret = -ENOMEM;
  479. goto out4;
  480. }
  481. if (fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0)
  482. < 0) {
  483. printk(KERN_ERR DRIVER_NAME
  484. "Fail to allocate colormap (%d entries)\n",
  485. BFIN_LCD_NBR_PALETTE_ENTRIES);
  486. ret = -EFAULT;
  487. goto out5;
  488. }
  489. if (request_ports(info)) {
  490. printk(KERN_ERR DRIVER_NAME ": couldn't request gpio port.\n");
  491. ret = -EFAULT;
  492. goto out6;
  493. }
  494. info->irq = platform_get_irq(pdev, 0);
  495. if (info->irq < 0) {
  496. ret = -EINVAL;
  497. goto out7;
  498. }
  499. if (request_irq(info->irq, bfin_bf54x_irq_error, 0,
  500. "PPI ERROR", info) < 0) {
  501. printk(KERN_ERR DRIVER_NAME
  502. ": unable to request PPI ERROR IRQ\n");
  503. ret = -EFAULT;
  504. goto out7;
  505. }
  506. if (register_framebuffer(fbinfo) < 0) {
  507. printk(KERN_ERR DRIVER_NAME
  508. ": unable to register framebuffer.\n");
  509. ret = -EINVAL;
  510. goto out8;
  511. }
  512. #ifndef NO_BL_SUPPORT
  513. memset(&props, 0, sizeof(struct backlight_properties));
  514. props.type = BACKLIGHT_RAW;
  515. props.max_brightness = 255;
  516. bl_dev = backlight_device_register("bf54x-bl", NULL, NULL,
  517. &bfin_lq043fb_bl_ops, &props);
  518. if (IS_ERR(bl_dev)) {
  519. printk(KERN_ERR DRIVER_NAME
  520. ": unable to register backlight.\n");
  521. ret = -EINVAL;
  522. unregister_framebuffer(fbinfo);
  523. goto out8;
  524. }
  525. lcd_dev = lcd_device_register(DRIVER_NAME, &pdev->dev, NULL, &bfin_lcd_ops);
  526. lcd_dev->props.max_contrast = 255, printk(KERN_INFO "Done.\n");
  527. #endif
  528. return 0;
  529. out8:
  530. free_irq(info->irq, info);
  531. out7:
  532. free_ports(info);
  533. out6:
  534. fb_dealloc_cmap(&fbinfo->cmap);
  535. out5:
  536. kfree(fbinfo->pseudo_palette);
  537. out4:
  538. dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
  539. info->dma_handle);
  540. out3:
  541. framebuffer_release(fbinfo);
  542. out2:
  543. free_dma(CH_EPPI0);
  544. out1:
  545. platform_set_drvdata(pdev, NULL);
  546. return ret;
  547. }
  548. static int __devexit bfin_bf54x_remove(struct platform_device *pdev)
  549. {
  550. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  551. struct bfin_bf54xfb_info *info = fbinfo->par;
  552. free_dma(CH_EPPI0);
  553. free_irq(info->irq, info);
  554. if (info->fb_buffer != NULL)
  555. dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
  556. info->dma_handle);
  557. kfree(fbinfo->pseudo_palette);
  558. fb_dealloc_cmap(&fbinfo->cmap);
  559. #ifndef NO_BL_SUPPORT
  560. lcd_device_unregister(lcd_dev);
  561. backlight_device_unregister(bl_dev);
  562. #endif
  563. unregister_framebuffer(fbinfo);
  564. free_ports(info);
  565. printk(KERN_INFO DRIVER_NAME ": Unregister LCD driver.\n");
  566. return 0;
  567. }
  568. #ifdef CONFIG_PM
  569. static int bfin_bf54x_suspend(struct platform_device *pdev, pm_message_t state)
  570. {
  571. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  572. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);
  573. disable_dma(CH_EPPI0);
  574. bfin_write_EPPI0_STATUS(0xFFFF);
  575. return 0;
  576. }
  577. static int bfin_bf54x_resume(struct platform_device *pdev)
  578. {
  579. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  580. struct bfin_bf54xfb_info *info = fbinfo->par;
  581. if (info->lq043_open_cnt) {
  582. bfin_write_EPPI0_CONTROL(0);
  583. SSYNC();
  584. config_dma(info);
  585. config_ppi(info);
  586. /* start dma */
  587. enable_dma(CH_EPPI0);
  588. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  589. }
  590. return 0;
  591. }
  592. #else
  593. #define bfin_bf54x_suspend NULL
  594. #define bfin_bf54x_resume NULL
  595. #endif
  596. static struct platform_driver bfin_bf54x_driver = {
  597. .probe = bfin_bf54x_probe,
  598. .remove = __devexit_p(bfin_bf54x_remove),
  599. .suspend = bfin_bf54x_suspend,
  600. .resume = bfin_bf54x_resume,
  601. .driver = {
  602. .name = DRIVER_NAME,
  603. .owner = THIS_MODULE,
  604. },
  605. };
  606. static int __init bfin_bf54x_driver_init(void)
  607. {
  608. return platform_driver_register(&bfin_bf54x_driver);
  609. }
  610. static void __exit bfin_bf54x_driver_cleanup(void)
  611. {
  612. platform_driver_unregister(&bfin_bf54x_driver);
  613. }
  614. MODULE_DESCRIPTION("Blackfin BF54x TFT LCD Driver");
  615. MODULE_LICENSE("GPL");
  616. module_init(bfin_bf54x_driver_init);
  617. module_exit(bfin_bf54x_driver_cleanup);