bfin_adv7393fb.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. /*
  2. * Frame buffer driver for ADV7393/2 video encoder
  3. *
  4. * Copyright 2006-2009 Analog Devices Inc.
  5. * Licensed under the GPL-2 or late.
  6. */
  7. /*
  8. * TODO: Remove Globals
  9. * TODO: Code Cleanup
  10. */
  11. #define pr_fmt(fmt) DRIVER_NAME ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/string.h>
  16. #include <linux/mm.h>
  17. #include <linux/tty.h>
  18. #include <linux/slab.h>
  19. #include <linux/delay.h>
  20. #include <linux/fb.h>
  21. #include <linux/ioport.h>
  22. #include <linux/init.h>
  23. #include <linux/types.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/sched.h>
  26. #include <asm/blackfin.h>
  27. #include <asm/irq.h>
  28. #include <asm/dma.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/gpio.h>
  31. #include <asm/portmux.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/proc_fs.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/i2c.h>
  36. #include <linux/i2c-dev.h>
  37. #include "bfin_adv7393fb.h"
  38. static int mode = VMODE;
  39. static int mem = VMEM;
  40. static int nocursor = 1;
  41. static const unsigned short ppi_pins[] = {
  42. P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2,
  43. P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, P_PPI0_D3,
  44. P_PPI0_D4, P_PPI0_D5, P_PPI0_D6, P_PPI0_D7,
  45. P_PPI0_D8, P_PPI0_D9, P_PPI0_D10, P_PPI0_D11,
  46. P_PPI0_D12, P_PPI0_D13, P_PPI0_D14, P_PPI0_D15,
  47. 0
  48. };
  49. /*
  50. * card parameters
  51. */
  52. static struct bfin_adv7393_fb_par {
  53. /* structure holding blackfin / adv7393 paramters when
  54. screen is blanked */
  55. struct {
  56. u8 Mode; /* ntsc/pal/? */
  57. } vga_state;
  58. atomic_t ref_count;
  59. } bfin_par;
  60. /* --------------------------------------------------------------------- */
  61. static struct fb_var_screeninfo bfin_adv7393_fb_defined = {
  62. .xres = 720,
  63. .yres = 480,
  64. .xres_virtual = 720,
  65. .yres_virtual = 480,
  66. .bits_per_pixel = 16,
  67. .activate = FB_ACTIVATE_TEST,
  68. .height = -1,
  69. .width = -1,
  70. .left_margin = 0,
  71. .right_margin = 0,
  72. .upper_margin = 0,
  73. .lower_margin = 0,
  74. .vmode = FB_VMODE_INTERLACED,
  75. .red = {11, 5, 0},
  76. .green = {5, 6, 0},
  77. .blue = {0, 5, 0},
  78. .transp = {0, 0, 0},
  79. };
  80. static struct fb_fix_screeninfo bfin_adv7393_fb_fix __devinitdata = {
  81. .id = "BFIN ADV7393",
  82. .smem_len = 720 * 480 * 2,
  83. .type = FB_TYPE_PACKED_PIXELS,
  84. .visual = FB_VISUAL_TRUECOLOR,
  85. .xpanstep = 0,
  86. .ypanstep = 0,
  87. .line_length = 720 * 2,
  88. .accel = FB_ACCEL_NONE
  89. };
  90. static struct fb_ops bfin_adv7393_fb_ops = {
  91. .owner = THIS_MODULE,
  92. .fb_open = bfin_adv7393_fb_open,
  93. .fb_release = bfin_adv7393_fb_release,
  94. .fb_check_var = bfin_adv7393_fb_check_var,
  95. .fb_pan_display = bfin_adv7393_fb_pan_display,
  96. .fb_blank = bfin_adv7393_fb_blank,
  97. .fb_fillrect = cfb_fillrect,
  98. .fb_copyarea = cfb_copyarea,
  99. .fb_imageblit = cfb_imageblit,
  100. .fb_cursor = bfin_adv7393_fb_cursor,
  101. .fb_setcolreg = bfin_adv7393_fb_setcolreg,
  102. };
  103. static int dma_desc_list(struct adv7393fb_device *fbdev, u16 arg)
  104. {
  105. if (arg == BUILD) { /* Build */
  106. fbdev->vb1 = l1_data_sram_zalloc(sizeof(struct dmasg));
  107. if (fbdev->vb1 == NULL)
  108. goto error;
  109. fbdev->av1 = l1_data_sram_zalloc(sizeof(struct dmasg));
  110. if (fbdev->av1 == NULL)
  111. goto error;
  112. fbdev->vb2 = l1_data_sram_zalloc(sizeof(struct dmasg));
  113. if (fbdev->vb2 == NULL)
  114. goto error;
  115. fbdev->av2 = l1_data_sram_zalloc(sizeof(struct dmasg));
  116. if (fbdev->av2 == NULL)
  117. goto error;
  118. /* Build linked DMA descriptor list */
  119. fbdev->vb1->next_desc_addr = fbdev->av1;
  120. fbdev->av1->next_desc_addr = fbdev->vb2;
  121. fbdev->vb2->next_desc_addr = fbdev->av2;
  122. fbdev->av2->next_desc_addr = fbdev->vb1;
  123. /* Save list head */
  124. fbdev->descriptor_list_head = fbdev->av2;
  125. /* Vertical Blanking Field 1 */
  126. fbdev->vb1->start_addr = VB_DUMMY_MEMORY_SOURCE;
  127. fbdev->vb1->cfg = DMA_CFG_VAL;
  128. fbdev->vb1->x_count =
  129. fbdev->modes[mode].xres + fbdev->modes[mode].boeft_blank;
  130. fbdev->vb1->x_modify = 0;
  131. fbdev->vb1->y_count = fbdev->modes[mode].vb1_lines;
  132. fbdev->vb1->y_modify = 0;
  133. /* Active Video Field 1 */
  134. fbdev->av1->start_addr = (unsigned long)fbdev->fb_mem;
  135. fbdev->av1->cfg = DMA_CFG_VAL;
  136. fbdev->av1->x_count =
  137. fbdev->modes[mode].xres + fbdev->modes[mode].boeft_blank;
  138. fbdev->av1->x_modify = fbdev->modes[mode].bpp / 8;
  139. fbdev->av1->y_count = fbdev->modes[mode].a_lines;
  140. fbdev->av1->y_modify =
  141. (fbdev->modes[mode].xres - fbdev->modes[mode].boeft_blank +
  142. 1) * (fbdev->modes[mode].bpp / 8);
  143. /* Vertical Blanking Field 2 */
  144. fbdev->vb2->start_addr = VB_DUMMY_MEMORY_SOURCE;
  145. fbdev->vb2->cfg = DMA_CFG_VAL;
  146. fbdev->vb2->x_count =
  147. fbdev->modes[mode].xres + fbdev->modes[mode].boeft_blank;
  148. fbdev->vb2->x_modify = 0;
  149. fbdev->vb2->y_count = fbdev->modes[mode].vb2_lines;
  150. fbdev->vb2->y_modify = 0;
  151. /* Active Video Field 2 */
  152. fbdev->av2->start_addr =
  153. (unsigned long)fbdev->fb_mem + fbdev->line_len;
  154. fbdev->av2->cfg = DMA_CFG_VAL;
  155. fbdev->av2->x_count =
  156. fbdev->modes[mode].xres + fbdev->modes[mode].boeft_blank;
  157. fbdev->av2->x_modify = (fbdev->modes[mode].bpp / 8);
  158. fbdev->av2->y_count = fbdev->modes[mode].a_lines;
  159. fbdev->av2->y_modify =
  160. (fbdev->modes[mode].xres - fbdev->modes[mode].boeft_blank +
  161. 1) * (fbdev->modes[mode].bpp / 8);
  162. return 1;
  163. }
  164. error:
  165. l1_data_sram_free(fbdev->vb1);
  166. l1_data_sram_free(fbdev->av1);
  167. l1_data_sram_free(fbdev->vb2);
  168. l1_data_sram_free(fbdev->av2);
  169. return 0;
  170. }
  171. static int bfin_config_dma(struct adv7393fb_device *fbdev)
  172. {
  173. BUG_ON(!(fbdev->fb_mem));
  174. set_dma_x_count(CH_PPI, fbdev->descriptor_list_head->x_count);
  175. set_dma_x_modify(CH_PPI, fbdev->descriptor_list_head->x_modify);
  176. set_dma_y_count(CH_PPI, fbdev->descriptor_list_head->y_count);
  177. set_dma_y_modify(CH_PPI, fbdev->descriptor_list_head->y_modify);
  178. set_dma_start_addr(CH_PPI, fbdev->descriptor_list_head->start_addr);
  179. set_dma_next_desc_addr(CH_PPI,
  180. fbdev->descriptor_list_head->next_desc_addr);
  181. set_dma_config(CH_PPI, fbdev->descriptor_list_head->cfg);
  182. return 1;
  183. }
  184. static void bfin_disable_dma(void)
  185. {
  186. bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() & ~DMAEN);
  187. }
  188. static void bfin_config_ppi(struct adv7393fb_device *fbdev)
  189. {
  190. if (ANOMALY_05000183) {
  191. bfin_write_TIMER2_CONFIG(WDTH_CAP);
  192. bfin_write_TIMER_ENABLE(TIMEN2);
  193. }
  194. bfin_write_PPI_CONTROL(0x381E);
  195. bfin_write_PPI_FRAME(fbdev->modes[mode].tot_lines);
  196. bfin_write_PPI_COUNT(fbdev->modes[mode].xres +
  197. fbdev->modes[mode].boeft_blank - 1);
  198. bfin_write_PPI_DELAY(fbdev->modes[mode].aoeft_blank - 1);
  199. }
  200. static void bfin_enable_ppi(void)
  201. {
  202. bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN);
  203. }
  204. static void bfin_disable_ppi(void)
  205. {
  206. bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN);
  207. }
  208. static inline int adv7393_write(struct i2c_client *client, u8 reg, u8 value)
  209. {
  210. return i2c_smbus_write_byte_data(client, reg, value);
  211. }
  212. static inline int adv7393_read(struct i2c_client *client, u8 reg)
  213. {
  214. return i2c_smbus_read_byte_data(client, reg);
  215. }
  216. static int
  217. adv7393_write_block(struct i2c_client *client,
  218. const u8 *data, unsigned int len)
  219. {
  220. int ret = -1;
  221. u8 reg;
  222. while (len >= 2) {
  223. reg = *data++;
  224. ret = adv7393_write(client, reg, *data++);
  225. if (ret < 0)
  226. break;
  227. len -= 2;
  228. }
  229. return ret;
  230. }
  231. static int adv7393_mode(struct i2c_client *client, u16 mode)
  232. {
  233. switch (mode) {
  234. case POWER_ON: /* ADV7393 Sleep mode OFF */
  235. adv7393_write(client, 0x00, 0x1E);
  236. break;
  237. case POWER_DOWN: /* ADV7393 Sleep mode ON */
  238. adv7393_write(client, 0x00, 0x1F);
  239. break;
  240. case BLANK_OFF: /* Pixel Data Valid */
  241. adv7393_write(client, 0x82, 0xCB);
  242. break;
  243. case BLANK_ON: /* Pixel Data Invalid */
  244. adv7393_write(client, 0x82, 0x8B);
  245. break;
  246. default:
  247. return -EINVAL;
  248. break;
  249. }
  250. return 0;
  251. }
  252. static irqreturn_t ppi_irq_error(int irq, void *dev_id)
  253. {
  254. struct adv7393fb_device *fbdev = (struct adv7393fb_device *)dev_id;
  255. u16 status = bfin_read_PPI_STATUS();
  256. pr_debug("%s: PPI Status = 0x%X\n", __func__, status);
  257. if (status) {
  258. bfin_disable_dma(); /* TODO: Check Sequence */
  259. bfin_disable_ppi();
  260. bfin_clear_PPI_STATUS();
  261. bfin_config_dma(fbdev);
  262. bfin_enable_ppi();
  263. }
  264. return IRQ_HANDLED;
  265. }
  266. static int proc_output(char *buf)
  267. {
  268. char *p = buf;
  269. p += sprintf(p,
  270. "Usage:\n"
  271. "echo 0x[REG][Value] > adv7393\n"
  272. "example: echo 0x1234 >adv7393\n"
  273. "writes 0x34 into Register 0x12\n");
  274. return p - buf;
  275. }
  276. static int
  277. adv7393_read_proc(char *page, char **start, off_t off,
  278. int count, int *eof, void *data)
  279. {
  280. int len;
  281. len = proc_output(page);
  282. if (len <= off + count)
  283. *eof = 1;
  284. *start = page + off;
  285. len -= off;
  286. if (len > count)
  287. len = count;
  288. if (len < 0)
  289. len = 0;
  290. return len;
  291. }
  292. static int
  293. adv7393_write_proc(struct file *file, const char __user * buffer,
  294. unsigned long count, void *data)
  295. {
  296. struct adv7393fb_device *fbdev = data;
  297. char line[8];
  298. unsigned int val;
  299. int ret;
  300. ret = copy_from_user(line, buffer, count);
  301. if (ret)
  302. return -EFAULT;
  303. val = simple_strtoul(line, NULL, 0);
  304. adv7393_write(fbdev->client, val >> 8, val & 0xff);
  305. return count;
  306. }
  307. static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
  308. const struct i2c_device_id *id)
  309. {
  310. int ret = 0;
  311. struct proc_dir_entry *entry;
  312. int num_modes = ARRAY_SIZE(known_modes);
  313. struct adv7393fb_device *fbdev = NULL;
  314. if (mem > 2) {
  315. dev_err(&client->dev, "mem out of allowed range [1;2]\n");
  316. return -EINVAL;
  317. }
  318. if (mode > num_modes) {
  319. dev_err(&client->dev, "mode %d: not supported", mode);
  320. return -EFAULT;
  321. }
  322. fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
  323. if (!fbdev) {
  324. dev_err(&client->dev, "failed to allocate device private record");
  325. return -ENOMEM;
  326. }
  327. i2c_set_clientdata(client, fbdev);
  328. fbdev->modes = known_modes;
  329. fbdev->client = client;
  330. fbdev->fb_len =
  331. mem * fbdev->modes[mode].xres * fbdev->modes[mode].xres *
  332. (fbdev->modes[mode].bpp / 8);
  333. fbdev->line_len =
  334. fbdev->modes[mode].xres * (fbdev->modes[mode].bpp / 8);
  335. /* Workaround "PPI Does Not Start Properly In Specific Mode" */
  336. if (ANOMALY_05000400) {
  337. if (gpio_request(P_IDENT(P_PPI0_FS3), "PPI0_FS3")) {
  338. dev_err(&client->dev, "PPI0_FS3 GPIO request failed\n");
  339. ret = -EBUSY;
  340. goto out_8;
  341. }
  342. gpio_direction_output(P_IDENT(P_PPI0_FS3), 0);
  343. }
  344. if (peripheral_request_list(ppi_pins, DRIVER_NAME)) {
  345. dev_err(&client->dev, "requesting PPI peripheral failed\n");
  346. ret = -EFAULT;
  347. goto out_8;
  348. }
  349. fbdev->fb_mem =
  350. dma_alloc_coherent(NULL, fbdev->fb_len, &fbdev->dma_handle,
  351. GFP_KERNEL);
  352. if (NULL == fbdev->fb_mem) {
  353. dev_err(&client->dev, "couldn't allocate dma buffer (%d bytes)\n",
  354. (u32) fbdev->fb_len);
  355. ret = -ENOMEM;
  356. goto out_7;
  357. }
  358. fbdev->info.screen_base = (void *)fbdev->fb_mem;
  359. bfin_adv7393_fb_fix.smem_start = (int)fbdev->fb_mem;
  360. bfin_adv7393_fb_fix.smem_len = fbdev->fb_len;
  361. bfin_adv7393_fb_fix.line_length = fbdev->line_len;
  362. if (mem > 1)
  363. bfin_adv7393_fb_fix.ypanstep = 1;
  364. bfin_adv7393_fb_defined.red.length = 5;
  365. bfin_adv7393_fb_defined.green.length = 6;
  366. bfin_adv7393_fb_defined.blue.length = 5;
  367. bfin_adv7393_fb_defined.xres = fbdev->modes[mode].xres;
  368. bfin_adv7393_fb_defined.yres = fbdev->modes[mode].yres;
  369. bfin_adv7393_fb_defined.xres_virtual = fbdev->modes[mode].xres;
  370. bfin_adv7393_fb_defined.yres_virtual = mem * fbdev->modes[mode].yres;
  371. bfin_adv7393_fb_defined.bits_per_pixel = fbdev->modes[mode].bpp;
  372. fbdev->info.fbops = &bfin_adv7393_fb_ops;
  373. fbdev->info.var = bfin_adv7393_fb_defined;
  374. fbdev->info.fix = bfin_adv7393_fb_fix;
  375. fbdev->info.par = &bfin_par;
  376. fbdev->info.flags = FBINFO_DEFAULT;
  377. fbdev->info.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
  378. if (!fbdev->info.pseudo_palette) {
  379. dev_err(&client->dev, "failed to allocate pseudo_palette\n");
  380. ret = -ENOMEM;
  381. goto out_6;
  382. }
  383. if (fb_alloc_cmap(&fbdev->info.cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
  384. dev_err(&client->dev, "failed to allocate colormap (%d entries)\n",
  385. BFIN_LCD_NBR_PALETTE_ENTRIES);
  386. ret = -EFAULT;
  387. goto out_5;
  388. }
  389. if (request_dma(CH_PPI, "BF5xx_PPI_DMA") < 0) {
  390. dev_err(&client->dev, "unable to request PPI DMA\n");
  391. ret = -EFAULT;
  392. goto out_4;
  393. }
  394. if (request_irq(IRQ_PPI_ERROR, ppi_irq_error, IRQF_DISABLED,
  395. "PPI ERROR", fbdev) < 0) {
  396. dev_err(&client->dev, "unable to request PPI ERROR IRQ\n");
  397. ret = -EFAULT;
  398. goto out_3;
  399. }
  400. fbdev->open = 0;
  401. ret = adv7393_write_block(client, fbdev->modes[mode].adv7393_i2c_initd,
  402. fbdev->modes[mode].adv7393_i2c_initd_len);
  403. if (ret) {
  404. dev_err(&client->dev, "i2c attach: init error\n");
  405. goto out_1;
  406. }
  407. if (register_framebuffer(&fbdev->info) < 0) {
  408. dev_err(&client->dev, "unable to register framebuffer\n");
  409. ret = -EFAULT;
  410. goto out_1;
  411. }
  412. dev_info(&client->dev, "fb%d: %s frame buffer device\n",
  413. fbdev->info.node, fbdev->info.fix.id);
  414. dev_info(&client->dev, "fb memory address : 0x%p\n", fbdev->fb_mem);
  415. entry = create_proc_entry("driver/adv7393", 0, NULL);
  416. if (!entry) {
  417. dev_err(&client->dev, "unable to create /proc entry\n");
  418. ret = -EFAULT;
  419. goto out_0;
  420. }
  421. entry->read_proc = adv7393_read_proc;
  422. entry->write_proc = adv7393_write_proc;
  423. entry->data = fbdev;
  424. return 0;
  425. out_0:
  426. unregister_framebuffer(&fbdev->info);
  427. out_1:
  428. free_irq(IRQ_PPI_ERROR, fbdev);
  429. out_3:
  430. free_dma(CH_PPI);
  431. out_4:
  432. dma_free_coherent(NULL, fbdev->fb_len, fbdev->fb_mem,
  433. fbdev->dma_handle);
  434. out_5:
  435. fb_dealloc_cmap(&fbdev->info.cmap);
  436. out_6:
  437. kfree(fbdev->info.pseudo_palette);
  438. out_7:
  439. peripheral_free_list(ppi_pins);
  440. out_8:
  441. kfree(fbdev);
  442. return ret;
  443. }
  444. static int bfin_adv7393_fb_open(struct fb_info *info, int user)
  445. {
  446. struct adv7393fb_device *fbdev = to_adv7393fb_device(info);
  447. fbdev->info.screen_base = (void *)fbdev->fb_mem;
  448. if (!fbdev->info.screen_base) {
  449. dev_err(&fbdev->client->dev, "unable to map device\n");
  450. return -ENOMEM;
  451. }
  452. fbdev->open = 1;
  453. dma_desc_list(fbdev, BUILD);
  454. adv7393_mode(fbdev->client, BLANK_OFF);
  455. bfin_config_ppi(fbdev);
  456. bfin_config_dma(fbdev);
  457. bfin_enable_ppi();
  458. return 0;
  459. }
  460. static int bfin_adv7393_fb_release(struct fb_info *info, int user)
  461. {
  462. struct adv7393fb_device *fbdev = to_adv7393fb_device(info);
  463. adv7393_mode(fbdev->client, BLANK_ON);
  464. bfin_disable_dma();
  465. bfin_disable_ppi();
  466. dma_desc_list(fbdev, DESTRUCT);
  467. fbdev->open = 0;
  468. return 0;
  469. }
  470. static int
  471. bfin_adv7393_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  472. {
  473. switch (var->bits_per_pixel) {
  474. case 16:/* DIRECTCOLOUR, 64k */
  475. var->red.offset = info->var.red.offset;
  476. var->green.offset = info->var.green.offset;
  477. var->blue.offset = info->var.blue.offset;
  478. var->red.length = info->var.red.length;
  479. var->green.length = info->var.green.length;
  480. var->blue.length = info->var.blue.length;
  481. var->transp.offset = 0;
  482. var->transp.length = 0;
  483. var->transp.msb_right = 0;
  484. var->red.msb_right = 0;
  485. var->green.msb_right = 0;
  486. var->blue.msb_right = 0;
  487. break;
  488. default:
  489. pr_debug("%s: depth not supported: %u BPP\n", __func__,
  490. var->bits_per_pixel);
  491. return -EINVAL;
  492. }
  493. if (info->var.xres != var->xres ||
  494. info->var.yres != var->yres ||
  495. info->var.xres_virtual != var->xres_virtual ||
  496. info->var.yres_virtual != var->yres_virtual) {
  497. pr_debug("%s: Resolution not supported: X%u x Y%u\n",
  498. __func__, var->xres, var->yres);
  499. return -EINVAL;
  500. }
  501. /*
  502. * Memory limit
  503. */
  504. if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) {
  505. pr_debug("%s: Memory Limit requested yres_virtual = %u\n",
  506. __func__, var->yres_virtual);
  507. return -ENOMEM;
  508. }
  509. return 0;
  510. }
  511. static int
  512. bfin_adv7393_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  513. {
  514. int dy;
  515. u32 dmaaddr;
  516. struct adv7393fb_device *fbdev = to_adv7393fb_device(info);
  517. if (!var || !info)
  518. return -EINVAL;
  519. if (var->xoffset - info->var.xoffset) {
  520. /* No support for X panning for now! */
  521. return -EINVAL;
  522. }
  523. dy = var->yoffset - info->var.yoffset;
  524. if (dy) {
  525. pr_debug("%s: Panning screen of %d lines\n", __func__, dy);
  526. dmaaddr = fbdev->av1->start_addr;
  527. dmaaddr += (info->fix.line_length * dy);
  528. /* TODO: Wait for current frame to finished */
  529. fbdev->av1->start_addr = (unsigned long)dmaaddr;
  530. fbdev->av2->start_addr = (unsigned long)dmaaddr + fbdev->line_len;
  531. }
  532. return 0;
  533. }
  534. /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
  535. static int bfin_adv7393_fb_blank(int blank, struct fb_info *info)
  536. {
  537. struct adv7393fb_device *fbdev = to_adv7393fb_device(info);
  538. switch (blank) {
  539. case VESA_NO_BLANKING:
  540. /* Turn on panel */
  541. adv7393_mode(fbdev->client, BLANK_OFF);
  542. break;
  543. case VESA_VSYNC_SUSPEND:
  544. case VESA_HSYNC_SUSPEND:
  545. case VESA_POWERDOWN:
  546. /* Turn off panel */
  547. adv7393_mode(fbdev->client, BLANK_ON);
  548. break;
  549. default:
  550. return -EINVAL;
  551. break;
  552. }
  553. return 0;
  554. }
  555. int bfin_adv7393_fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  556. {
  557. if (nocursor)
  558. return 0;
  559. else
  560. return -EINVAL; /* just to force soft_cursor() call */
  561. }
  562. static int bfin_adv7393_fb_setcolreg(u_int regno, u_int red, u_int green,
  563. u_int blue, u_int transp,
  564. struct fb_info *info)
  565. {
  566. if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES)
  567. return -EINVAL;
  568. if (info->var.grayscale)
  569. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  570. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  571. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  572. u32 value;
  573. /* Place color in the pseudopalette */
  574. if (regno > 16)
  575. return -EINVAL;
  576. red >>= (16 - info->var.red.length);
  577. green >>= (16 - info->var.green.length);
  578. blue >>= (16 - info->var.blue.length);
  579. value = (red << info->var.red.offset) |
  580. (green << info->var.green.offset)|
  581. (blue << info->var.blue.offset);
  582. value &= 0xFFFF;
  583. ((u32 *) (info->pseudo_palette))[regno] = value;
  584. }
  585. return 0;
  586. }
  587. static int __devexit bfin_adv7393_fb_remove(struct i2c_client *client)
  588. {
  589. struct adv7393fb_device *fbdev = i2c_get_clientdata(client);
  590. adv7393_mode(client, POWER_DOWN);
  591. if (fbdev->fb_mem)
  592. dma_free_coherent(NULL, fbdev->fb_len, fbdev->fb_mem, fbdev->dma_handle);
  593. free_dma(CH_PPI);
  594. free_irq(IRQ_PPI_ERROR, fbdev);
  595. unregister_framebuffer(&fbdev->info);
  596. remove_proc_entry("driver/adv7393", NULL);
  597. fb_dealloc_cmap(&fbdev->info.cmap);
  598. kfree(fbdev->info.pseudo_palette);
  599. if (ANOMALY_05000400)
  600. gpio_free(P_IDENT(P_PPI0_FS3)); /* FS3 */
  601. peripheral_free_list(ppi_pins);
  602. kfree(fbdev);
  603. return 0;
  604. }
  605. #ifdef CONFIG_PM
  606. static int bfin_adv7393_fb_suspend(struct device *dev)
  607. {
  608. struct adv7393fb_device *fbdev = dev_get_drvdata(dev);
  609. if (fbdev->open) {
  610. bfin_disable_dma();
  611. bfin_disable_ppi();
  612. dma_desc_list(fbdev, DESTRUCT);
  613. }
  614. adv7393_mode(fbdev->client, POWER_DOWN);
  615. return 0;
  616. }
  617. static int bfin_adv7393_fb_resume(struct device *dev)
  618. {
  619. struct adv7393fb_device *fbdev = dev_get_drvdata(dev);
  620. adv7393_mode(fbdev->client, POWER_ON);
  621. if (fbdev->open) {
  622. dma_desc_list(fbdev, BUILD);
  623. bfin_config_ppi(fbdev);
  624. bfin_config_dma(fbdev);
  625. bfin_enable_ppi();
  626. }
  627. return 0;
  628. }
  629. static const struct dev_pm_ops bfin_adv7393_dev_pm_ops = {
  630. .suspend = bfin_adv7393_fb_suspend,
  631. .resume = bfin_adv7393_fb_resume,
  632. };
  633. #endif
  634. static const struct i2c_device_id bfin_adv7393_id[] = {
  635. {DRIVER_NAME, 0},
  636. {}
  637. };
  638. MODULE_DEVICE_TABLE(i2c, bfin_adv7393_id);
  639. static struct i2c_driver bfin_adv7393_fb_driver = {
  640. .driver = {
  641. .name = DRIVER_NAME,
  642. #ifdef CONFIG_PM
  643. .pm = &bfin_adv7393_dev_pm_ops,
  644. #endif
  645. },
  646. .probe = bfin_adv7393_fb_probe,
  647. .remove = __devexit_p(bfin_adv7393_fb_remove),
  648. .id_table = bfin_adv7393_id,
  649. };
  650. static int __init bfin_adv7393_fb_driver_init(void)
  651. {
  652. #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
  653. request_module("i2c-bfin-twi");
  654. #else
  655. request_module("i2c-gpio");
  656. #endif
  657. return i2c_add_driver(&bfin_adv7393_fb_driver);
  658. }
  659. module_init(bfin_adv7393_fb_driver_init);
  660. static void __exit bfin_adv7393_fb_driver_cleanup(void)
  661. {
  662. i2c_del_driver(&bfin_adv7393_fb_driver);
  663. }
  664. module_exit(bfin_adv7393_fb_driver_cleanup);
  665. MODULE_LICENSE("GPL");
  666. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  667. MODULE_DESCRIPTION("Frame buffer driver for ADV7393/2 Video Encoder");
  668. module_param(mode, int, 0);
  669. MODULE_PARM_DESC(mode,
  670. "Video Mode (0=NTSC,1=PAL,2=NTSC 640x480,3=PAL 640x480,4=NTSC YCbCr input,5=PAL YCbCr input)");
  671. module_param(mem, int, 0);
  672. MODULE_PARM_DESC(mem,
  673. "Size of frame buffer memory 1=Single 2=Double Size (allows y-panning / frame stacking)");
  674. module_param(nocursor, int, 0644);
  675. MODULE_PARM_DESC(nocursor, "cursor enable/disable");