bf54x-lq043fb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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 Framebufer 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(disp, 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. gpio_direction_output(disp, 1);
  213. return 0;
  214. }
  215. static void free_ports(struct bfin_bf54xfb_info *fbi)
  216. {
  217. u16 eppi_req_18[] = EPPI0_18;
  218. gpio_free(fbi->mach_info->disp);
  219. peripheral_free_list(eppi_req_18);
  220. if (!outp_rgb666) {
  221. u16 eppi_req_24[] = EPPI0_24;
  222. peripheral_free_list(eppi_req_24);
  223. }
  224. }
  225. static int bfin_bf54x_fb_open(struct fb_info *info, int user)
  226. {
  227. struct bfin_bf54xfb_info *fbi = info->par;
  228. spin_lock(&fbi->lock);
  229. fbi->lq043_open_cnt++;
  230. if (fbi->lq043_open_cnt <= 1) {
  231. bfin_write_EPPI0_CONTROL(0);
  232. SSYNC();
  233. config_dma(fbi);
  234. config_ppi(fbi);
  235. /* start dma */
  236. enable_dma(CH_EPPI0);
  237. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  238. }
  239. spin_unlock(&fbi->lock);
  240. return 0;
  241. }
  242. static int bfin_bf54x_fb_release(struct fb_info *info, int user)
  243. {
  244. struct bfin_bf54xfb_info *fbi = info->par;
  245. spin_lock(&fbi->lock);
  246. fbi->lq043_open_cnt--;
  247. if (fbi->lq043_open_cnt <= 0) {
  248. bfin_write_EPPI0_CONTROL(0);
  249. SSYNC();
  250. disable_dma(CH_EPPI0);
  251. }
  252. spin_unlock(&fbi->lock);
  253. return 0;
  254. }
  255. static int bfin_bf54x_fb_check_var(struct fb_var_screeninfo *var,
  256. struct fb_info *info)
  257. {
  258. switch (var->bits_per_pixel) {
  259. case 24:/* TRUECOLOUR, 16m */
  260. var->red.offset = 16;
  261. var->green.offset = 8;
  262. var->blue.offset = 0;
  263. var->red.length = var->green.length = var->blue.length = 8;
  264. var->transp.offset = 0;
  265. var->transp.length = 0;
  266. var->transp.msb_right = 0;
  267. var->red.msb_right = 0;
  268. var->green.msb_right = 0;
  269. var->blue.msb_right = 0;
  270. break;
  271. default:
  272. pr_debug("%s: depth not supported: %u BPP\n", __func__,
  273. var->bits_per_pixel);
  274. return -EINVAL;
  275. }
  276. if (info->var.xres != var->xres || info->var.yres != var->yres ||
  277. info->var.xres_virtual != var->xres_virtual ||
  278. info->var.yres_virtual != var->yres_virtual) {
  279. pr_debug("%s: Resolution not supported: X%u x Y%u \n",
  280. __func__, var->xres, var->yres);
  281. return -EINVAL;
  282. }
  283. /*
  284. * Memory limit
  285. */
  286. if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) {
  287. pr_debug("%s: Memory Limit requested yres_virtual = %u\n",
  288. __func__, var->yres_virtual);
  289. return -ENOMEM;
  290. }
  291. return 0;
  292. }
  293. int bfin_bf54x_fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  294. {
  295. if (nocursor)
  296. return 0;
  297. else
  298. return -EINVAL; /* just to force soft_cursor() call */
  299. }
  300. static int bfin_bf54x_fb_setcolreg(u_int regno, u_int red, u_int green,
  301. u_int blue, u_int transp,
  302. struct fb_info *info)
  303. {
  304. if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES)
  305. return -EINVAL;
  306. if (info->var.grayscale) {
  307. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  308. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  309. }
  310. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  311. u32 value;
  312. /* Place color in the pseudopalette */
  313. if (regno > 16)
  314. return -EINVAL;
  315. red >>= (16 - info->var.red.length);
  316. green >>= (16 - info->var.green.length);
  317. blue >>= (16 - info->var.blue.length);
  318. value = (red << info->var.red.offset) |
  319. (green << info->var.green.offset) |
  320. (blue << info->var.blue.offset);
  321. value &= 0xFFFFFF;
  322. ((u32 *) (info->pseudo_palette))[regno] = value;
  323. }
  324. return 0;
  325. }
  326. static struct fb_ops bfin_bf54x_fb_ops = {
  327. .owner = THIS_MODULE,
  328. .fb_open = bfin_bf54x_fb_open,
  329. .fb_release = bfin_bf54x_fb_release,
  330. .fb_check_var = bfin_bf54x_fb_check_var,
  331. .fb_fillrect = cfb_fillrect,
  332. .fb_copyarea = cfb_copyarea,
  333. .fb_imageblit = cfb_imageblit,
  334. .fb_cursor = bfin_bf54x_fb_cursor,
  335. .fb_setcolreg = bfin_bf54x_fb_setcolreg,
  336. };
  337. #ifndef NO_BL_SUPPORT
  338. static int bl_get_brightness(struct backlight_device *bd)
  339. {
  340. return 0;
  341. }
  342. static const struct backlight_ops bfin_lq043fb_bl_ops = {
  343. .get_brightness = bl_get_brightness,
  344. };
  345. static struct backlight_device *bl_dev;
  346. static int bfin_lcd_get_power(struct lcd_device *dev)
  347. {
  348. return 0;
  349. }
  350. static int bfin_lcd_set_power(struct lcd_device *dev, int power)
  351. {
  352. return 0;
  353. }
  354. static int bfin_lcd_get_contrast(struct lcd_device *dev)
  355. {
  356. return 0;
  357. }
  358. static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast)
  359. {
  360. return 0;
  361. }
  362. static int bfin_lcd_check_fb(struct lcd_device *dev, struct fb_info *fi)
  363. {
  364. if (!fi || (fi == &bfin_bf54x_fb))
  365. return 1;
  366. return 0;
  367. }
  368. static struct lcd_ops bfin_lcd_ops = {
  369. .get_power = bfin_lcd_get_power,
  370. .set_power = bfin_lcd_set_power,
  371. .get_contrast = bfin_lcd_get_contrast,
  372. .set_contrast = bfin_lcd_set_contrast,
  373. .check_fb = bfin_lcd_check_fb,
  374. };
  375. static struct lcd_device *lcd_dev;
  376. #endif
  377. static irqreturn_t bfin_bf54x_irq_error(int irq, void *dev_id)
  378. {
  379. /*struct bfin_bf54xfb_info *info = dev_id;*/
  380. u16 status = bfin_read_EPPI0_STATUS();
  381. bfin_write_EPPI0_STATUS(0xFFFF);
  382. if (status) {
  383. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);
  384. disable_dma(CH_EPPI0);
  385. /* start dma */
  386. enable_dma(CH_EPPI0);
  387. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  388. bfin_write_EPPI0_STATUS(0xFFFF);
  389. }
  390. return IRQ_HANDLED;
  391. }
  392. static int __devinit bfin_bf54x_probe(struct platform_device *pdev)
  393. {
  394. #ifndef NO_BL_SUPPORT
  395. struct backlight_properties props;
  396. #endif
  397. struct bfin_bf54xfb_info *info;
  398. struct fb_info *fbinfo;
  399. int ret;
  400. printk(KERN_INFO DRIVER_NAME ": FrameBuffer initializing...\n");
  401. if (request_dma(CH_EPPI0, "CH_EPPI0") < 0) {
  402. printk(KERN_ERR DRIVER_NAME
  403. ": couldn't request CH_EPPI0 DMA\n");
  404. ret = -EFAULT;
  405. goto out1;
  406. }
  407. fbinfo =
  408. framebuffer_alloc(sizeof(struct bfin_bf54xfb_info), &pdev->dev);
  409. if (!fbinfo) {
  410. ret = -ENOMEM;
  411. goto out2;
  412. }
  413. info = fbinfo->par;
  414. info->fb = fbinfo;
  415. info->dev = &pdev->dev;
  416. platform_set_drvdata(pdev, fbinfo);
  417. strcpy(fbinfo->fix.id, driver_name);
  418. info->mach_info = pdev->dev.platform_data;
  419. if (info->mach_info == NULL) {
  420. dev_err(&pdev->dev,
  421. "no platform data for lcd, cannot attach\n");
  422. ret = -EINVAL;
  423. goto out3;
  424. }
  425. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  426. fbinfo->fix.type_aux = 0;
  427. fbinfo->fix.xpanstep = 0;
  428. fbinfo->fix.ypanstep = 0;
  429. fbinfo->fix.ywrapstep = 0;
  430. fbinfo->fix.accel = FB_ACCEL_NONE;
  431. fbinfo->fix.visual = FB_VISUAL_TRUECOLOR;
  432. fbinfo->var.nonstd = 0;
  433. fbinfo->var.activate = FB_ACTIVATE_NOW;
  434. fbinfo->var.height = info->mach_info->height;
  435. fbinfo->var.width = info->mach_info->width;
  436. fbinfo->var.accel_flags = 0;
  437. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  438. fbinfo->fbops = &bfin_bf54x_fb_ops;
  439. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  440. fbinfo->var.xres = info->mach_info->xres.defval;
  441. fbinfo->var.xres_virtual = info->mach_info->xres.defval;
  442. fbinfo->var.yres = info->mach_info->yres.defval;
  443. fbinfo->var.yres_virtual = info->mach_info->yres.defval;
  444. fbinfo->var.bits_per_pixel = info->mach_info->bpp.defval;
  445. fbinfo->var.upper_margin = 0;
  446. fbinfo->var.lower_margin = 0;
  447. fbinfo->var.vsync_len = 0;
  448. fbinfo->var.left_margin = 0;
  449. fbinfo->var.right_margin = 0;
  450. fbinfo->var.hsync_len = 0;
  451. fbinfo->var.red.offset = 16;
  452. fbinfo->var.green.offset = 8;
  453. fbinfo->var.blue.offset = 0;
  454. fbinfo->var.transp.offset = 0;
  455. fbinfo->var.red.length = 8;
  456. fbinfo->var.green.length = 8;
  457. fbinfo->var.blue.length = 8;
  458. fbinfo->var.transp.length = 0;
  459. fbinfo->fix.smem_len = info->mach_info->xres.max *
  460. info->mach_info->yres.max * info->mach_info->bpp.max / 8;
  461. fbinfo->fix.line_length = fbinfo->var.xres_virtual *
  462. fbinfo->var.bits_per_pixel / 8;
  463. info->fb_buffer =
  464. dma_alloc_coherent(NULL, fbinfo->fix.smem_len, &info->dma_handle,
  465. GFP_KERNEL);
  466. if (NULL == info->fb_buffer) {
  467. printk(KERN_ERR DRIVER_NAME
  468. ": couldn't allocate dma buffer.\n");
  469. ret = -ENOMEM;
  470. goto out3;
  471. }
  472. fbinfo->screen_base = (void *)info->fb_buffer;
  473. fbinfo->fix.smem_start = (int)info->fb_buffer;
  474. fbinfo->fbops = &bfin_bf54x_fb_ops;
  475. fbinfo->pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
  476. if (!fbinfo->pseudo_palette) {
  477. printk(KERN_ERR DRIVER_NAME
  478. "Fail to allocate pseudo_palette\n");
  479. ret = -ENOMEM;
  480. goto out4;
  481. }
  482. if (fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0)
  483. < 0) {
  484. printk(KERN_ERR DRIVER_NAME
  485. "Fail to allocate colormap (%d entries)\n",
  486. BFIN_LCD_NBR_PALETTE_ENTRIES);
  487. ret = -EFAULT;
  488. goto out5;
  489. }
  490. if (request_ports(info)) {
  491. printk(KERN_ERR DRIVER_NAME ": couldn't request gpio port.\n");
  492. ret = -EFAULT;
  493. goto out6;
  494. }
  495. info->irq = platform_get_irq(pdev, 0);
  496. if (info->irq < 0) {
  497. ret = -EINVAL;
  498. goto out7;
  499. }
  500. if (request_irq(info->irq, bfin_bf54x_irq_error, IRQF_DISABLED,
  501. "PPI ERROR", info) < 0) {
  502. printk(KERN_ERR DRIVER_NAME
  503. ": unable to request PPI ERROR IRQ\n");
  504. ret = -EFAULT;
  505. goto out7;
  506. }
  507. if (register_framebuffer(fbinfo) < 0) {
  508. printk(KERN_ERR DRIVER_NAME
  509. ": unable to register framebuffer.\n");
  510. ret = -EINVAL;
  511. goto out8;
  512. }
  513. #ifndef NO_BL_SUPPORT
  514. memset(&props, 0, sizeof(struct backlight_properties));
  515. props.type = BACKLIGHT_RAW;
  516. props.max_brightness = 255;
  517. bl_dev = backlight_device_register("bf54x-bl", NULL, NULL,
  518. &bfin_lq043fb_bl_ops, &props);
  519. if (IS_ERR(bl_dev)) {
  520. printk(KERN_ERR DRIVER_NAME
  521. ": unable to register backlight.\n");
  522. ret = -EINVAL;
  523. unregister_framebuffer(fbinfo);
  524. goto out8;
  525. }
  526. lcd_dev = lcd_device_register(DRIVER_NAME, &pdev->dev, NULL, &bfin_lcd_ops);
  527. lcd_dev->props.max_contrast = 255, printk(KERN_INFO "Done.\n");
  528. #endif
  529. return 0;
  530. out8:
  531. free_irq(info->irq, info);
  532. out7:
  533. free_ports(info);
  534. out6:
  535. fb_dealloc_cmap(&fbinfo->cmap);
  536. out5:
  537. kfree(fbinfo->pseudo_palette);
  538. out4:
  539. dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
  540. info->dma_handle);
  541. out3:
  542. framebuffer_release(fbinfo);
  543. out2:
  544. free_dma(CH_EPPI0);
  545. out1:
  546. platform_set_drvdata(pdev, NULL);
  547. return ret;
  548. }
  549. static int __devexit bfin_bf54x_remove(struct platform_device *pdev)
  550. {
  551. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  552. struct bfin_bf54xfb_info *info = fbinfo->par;
  553. free_dma(CH_EPPI0);
  554. free_irq(info->irq, info);
  555. if (info->fb_buffer != NULL)
  556. dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
  557. info->dma_handle);
  558. kfree(fbinfo->pseudo_palette);
  559. fb_dealloc_cmap(&fbinfo->cmap);
  560. #ifndef NO_BL_SUPPORT
  561. lcd_device_unregister(lcd_dev);
  562. backlight_device_unregister(bl_dev);
  563. #endif
  564. unregister_framebuffer(fbinfo);
  565. free_ports(info);
  566. printk(KERN_INFO DRIVER_NAME ": Unregister LCD driver.\n");
  567. return 0;
  568. }
  569. #ifdef CONFIG_PM
  570. static int bfin_bf54x_suspend(struct platform_device *pdev, pm_message_t state)
  571. {
  572. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  573. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);
  574. disable_dma(CH_EPPI0);
  575. bfin_write_EPPI0_STATUS(0xFFFF);
  576. return 0;
  577. }
  578. static int bfin_bf54x_resume(struct platform_device *pdev)
  579. {
  580. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  581. struct bfin_bf54xfb_info *info = fbinfo->par;
  582. if (info->lq043_open_cnt) {
  583. bfin_write_EPPI0_CONTROL(0);
  584. SSYNC();
  585. config_dma(info);
  586. config_ppi(info);
  587. /* start dma */
  588. enable_dma(CH_EPPI0);
  589. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  590. }
  591. return 0;
  592. }
  593. #else
  594. #define bfin_bf54x_suspend NULL
  595. #define bfin_bf54x_resume NULL
  596. #endif
  597. static struct platform_driver bfin_bf54x_driver = {
  598. .probe = bfin_bf54x_probe,
  599. .remove = __devexit_p(bfin_bf54x_remove),
  600. .suspend = bfin_bf54x_suspend,
  601. .resume = bfin_bf54x_resume,
  602. .driver = {
  603. .name = DRIVER_NAME,
  604. .owner = THIS_MODULE,
  605. },
  606. };
  607. static int __init bfin_bf54x_driver_init(void)
  608. {
  609. return platform_driver_register(&bfin_bf54x_driver);
  610. }
  611. static void __exit bfin_bf54x_driver_cleanup(void)
  612. {
  613. platform_driver_unregister(&bfin_bf54x_driver);
  614. }
  615. MODULE_DESCRIPTION("Blackfin BF54x TFT LCD Driver");
  616. MODULE_LICENSE("GPL");
  617. module_init(bfin_bf54x_driver_init);
  618. module_exit(bfin_bf54x_driver_cleanup);