13 #define pr_fmt(fmt) DRIVER_NAME ": " fmt
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
20 #include <linux/tty.h>
21 #include <linux/slab.h>
26 #include <linux/types.h>
28 #include <linux/sched.h>
39 #include <linux/i2c.h>
45 static int nocursor = 1;
47 static const unsigned short ppi_pins[] = {
60 static struct bfin_adv7393_fb_par {
93 .smem_len = 720 * 480 * 2,
98 .line_length = 720 * 2,
102 static struct fb_ops bfin_adv7393_fb_ops = {
104 .fb_open = bfin_adv7393_fb_open,
105 .fb_release = bfin_adv7393_fb_release,
106 .fb_check_var = bfin_adv7393_fb_check_var,
107 .fb_pan_display = bfin_adv7393_fb_pan_display,
108 .fb_blank = bfin_adv7393_fb_blank,
113 .fb_setcolreg = bfin_adv7393_fb_setcolreg,
136 fbdev->
vb1->next_desc_addr = fbdev->
av1;
137 fbdev->
av1->next_desc_addr = fbdev->
vb2;
138 fbdev->
vb2->next_desc_addr = fbdev->
av2;
139 fbdev->
av2->next_desc_addr = fbdev->
vb1;
148 fbdev->
vb1->x_count =
151 fbdev->
vb1->x_modify = 0;
153 fbdev->
vb1->y_modify = 0;
159 fbdev->
av1->x_count =
163 fbdev->
av1->y_modify =
171 fbdev->
vb2->x_count =
174 fbdev->
vb2->x_modify = 0;
176 fbdev->
vb2->y_modify = 0;
180 fbdev->
av2->start_addr =
185 fbdev->
av2->x_count =
191 fbdev->
av2->y_modify =
216 set_dma_next_desc_addr(
CH_PPI,
223 static void bfin_disable_dma(
void)
242 static void bfin_enable_ppi(
void)
247 static void bfin_disable_ppi(
void)
264 const u8 *
data,
unsigned int len)
271 ret = adv7393_write(client, reg, *data++);
284 adv7393_write(client, 0x00, 0x1E);
287 adv7393_write(client, 0x00, 0x1F);
290 adv7393_write(client, 0x82, 0xCB);
293 adv7393_write(client, 0x82, 0x8B);
309 pr_debug(
"%s: PPI Status = 0x%X\n", __func__, status);
315 bfin_config_dma(fbdev);
323 static int proc_output(
char *
buf)
329 "echo 0x[REG][Value] > adv7393\n"
330 "example: echo 0x1234 >adv7393\n"
331 "writes 0x34 into Register 0x12\n");
338 int count,
int *eof,
void *data)
342 len = proc_output(page);
343 if (len <= off + count)
356 size_t count,
void *data)
366 adv7393_write(fbdev->
client, val >> 8, val & 0xff);
381 dev_err(&client->
dev,
"mem out of allowed range [1;2]\n");
385 if (mode > num_modes) {
386 dev_err(&client->
dev,
"mode %d: not supported", mode);
392 dev_err(&client->
dev,
"failed to allocate device private record");
396 i2c_set_clientdata(client, fbdev);
398 fbdev->
modes = known_modes;
413 dev_err(&client->
dev,
"PPI0_FS3 GPIO request failed\n");
420 dev_err(&client->
dev,
"requesting PPI peripheral failed\n");
430 dev_err(&client->
dev,
"couldn't allocate dma buffer (%d bytes)\n",
436 fbdev->
info.screen_base = (
void *)fbdev->
fb_mem;
437 bfin_adv7393_fb_fix.smem_start = (
int)fbdev->
fb_mem;
439 bfin_adv7393_fb_fix.smem_len = fbdev->
fb_len;
440 bfin_adv7393_fb_fix.line_length = fbdev->
line_len;
443 bfin_adv7393_fb_fix.ypanstep = 1;
445 bfin_adv7393_fb_defined.
red.length = 5;
446 bfin_adv7393_fb_defined.
green.length = 6;
447 bfin_adv7393_fb_defined.
blue.length = 5;
455 fbdev->
info.fbops = &bfin_adv7393_fb_ops;
456 fbdev->
info.var = bfin_adv7393_fb_defined;
457 fbdev->
info.fix = bfin_adv7393_fb_fix;
458 fbdev->
info.par = &bfin_par;
462 if (!fbdev->
info.pseudo_palette) {
463 dev_err(&client->
dev,
"failed to allocate pseudo_palette\n");
469 dev_err(&client->
dev,
"failed to allocate colormap (%d entries)\n",
476 dev_err(&client->
dev,
"unable to request PPI DMA\n");
482 "PPI ERROR", fbdev) < 0) {
483 dev_err(&client->
dev,
"unable to request PPI ERROR IRQ\n");
490 ret = adv7393_write_block(client, fbdev->
modes[mode].adv7393_i2c_initd,
491 fbdev->
modes[mode].adv7393_i2c_initd_len);
494 dev_err(&client->
dev,
"i2c attach: init error\n");
500 dev_err(&client->
dev,
"unable to register framebuffer\n");
505 dev_info(&client->
dev,
"fb%d: %s frame buffer device\n",
506 fbdev->
info.node, fbdev->
info.fix.id);
511 dev_err(&client->
dev,
"unable to create /proc entry\n");
550 fbdev->
info.screen_base = (
void *)fbdev->
fb_mem;
551 if (!fbdev->
info.screen_base) {
557 dma_desc_list(fbdev,
BUILD);
559 bfin_config_ppi(fbdev);
560 bfin_config_dma(fbdev);
566 static int bfin_adv7393_fb_release(
struct fb_info *info,
int user)
584 var->
red.offset = info->
var.red.offset;
585 var->
green.offset = info->
var.green.offset;
586 var->
blue.offset = info->
var.blue.offset;
587 var->
red.length = info->
var.red.length;
588 var->
green.length = info->
var.green.length;
589 var->
blue.length = info->
var.blue.length;
592 var->
transp.msb_right = 0;
593 var->
red.msb_right = 0;
594 var->
green.msb_right = 0;
595 var->
blue.msb_right = 0;
598 pr_debug(
"%s: depth not supported: %u BPP\n", __func__,
603 if (info->
var.xres != var->
xres ||
607 pr_debug(
"%s: Resolution not supported: X%u x Y%u\n",
617 pr_debug(
"%s: Memory Limit requested yres_virtual = %u\n",
642 pr_debug(
"%s: Panning screen of %d lines\n", __func__, dy);
644 dmaaddr = fbdev->
av1->start_addr;
645 dmaaddr += (info->
fix.line_length * dy);
648 fbdev->
av1->start_addr = (
unsigned long)dmaaddr;
657 static int bfin_adv7393_fb_blank(
int blank,
struct fb_info *info)
697 if (info->
var.grayscale)
699 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
707 red >>= (16 - info->
var.red.length);
708 green >>= (16 - info->
var.green.length);
709 blue >>= (16 - info->
var.blue.length);
711 value = (red << info->
var.red.offset) |
712 (green << info->
var.green.offset)|
713 (blue << info->
var.blue.offset);
746 static int bfin_adv7393_fb_suspend(
struct device *
dev)
760 static int bfin_adv7393_fb_resume(
struct device *dev)
767 dma_desc_list(fbdev,
BUILD);
768 bfin_config_ppi(fbdev);
769 bfin_config_dma(fbdev);
776 static const struct dev_pm_ops bfin_adv7393_dev_pm_ops = {
777 .
suspend = bfin_adv7393_fb_suspend,
778 .resume = bfin_adv7393_fb_resume,
789 static struct i2c_driver bfin_adv7393_fb_driver = {
793 .pm = &bfin_adv7393_dev_pm_ops,
796 .probe = bfin_adv7393_fb_probe,
798 .id_table = bfin_adv7393_id,
801 static int __init bfin_adv7393_fb_driver_init(
void)
803 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
804 request_module(
"i2c-bfin-twi");
806 request_module(
"i2c-gpio");
809 return i2c_add_driver(&bfin_adv7393_fb_driver);
813 static void __exit bfin_adv7393_fb_driver_cleanup(
void)
825 "Video Mode (0=NTSC,1=PAL,2=NTSC 640x480,3=PAL 640x480,4=NTSC YCbCr input,5=PAL YCbCr input)");
829 "Size of frame buffer memory 1=Single 2=Double Size (allows y-panning / frame stacking)");