9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
20 #include <linux/types.h>
23 #include <linux/sched.h>
25 #include <linux/device.h>
28 #include <linux/i2c.h>
31 #include <linux/slab.h>
42 #define MAX_BRIGHENESS 95
43 #define MIN_BRIGHENESS 5
44 #define NBR_PALETTE 256
46 static const unsigned short ppi_pins[] = {
53 static unsigned char *fb_buffer;
54 static unsigned long *dma_desc_table;
55 static int t_conf_done, lq035_open_cnt;
61 "LANDSCAPE use 320x240 instead of Native 240x320 Resolution");
66 "BGR use 16-bit BGR-565 instead of RGB-565");
68 static int nocursor = 1;
72 static unsigned long current_brightness;
75 static unsigned char vcomm_value = 150;
78 static void set_vcomm(
void)
87 pr_err(
"i2c_smbus_write_byte_data fail: %d\n", nr);
94 if (!i2c_check_functionality(client->
adapter,
96 dev_err(&client->
dev,
"SMBUS Byte Data not Supported\n");
102 dev_err(&client->
dev,
"write fail: %d\n", ret);
113 ad5280_client =
NULL;
118 {
"bf537-lq035-ad5280", 0},
126 .name =
"bf537-lq035-ad5280",
128 .probe = ad5280_probe,
130 .id_table = ad5280_id,
134 #define MOD GPIO_PH13
136 #define bfin_write_TIMER_LP_CONFIG bfin_write_TIMER0_CONFIG
137 #define bfin_write_TIMER_LP_WIDTH bfin_write_TIMER0_WIDTH
138 #define bfin_write_TIMER_LP_PERIOD bfin_write_TIMER0_PERIOD
139 #define bfin_read_TIMER_LP_COUNTER bfin_read_TIMER0_COUNTER
140 #define TIMDIS_LP TIMDIS0
141 #define TIMEN_LP TIMEN0
143 #define bfin_write_TIMER_SPS_CONFIG bfin_write_TIMER1_CONFIG
144 #define bfin_write_TIMER_SPS_WIDTH bfin_write_TIMER1_WIDTH
145 #define bfin_write_TIMER_SPS_PERIOD bfin_write_TIMER1_PERIOD
146 #define TIMDIS_SPS TIMDIS1
147 #define TIMEN_SPS TIMEN1
149 #define bfin_write_TIMER_SP_CONFIG bfin_write_TIMER5_CONFIG
150 #define bfin_write_TIMER_SP_WIDTH bfin_write_TIMER5_WIDTH
151 #define bfin_write_TIMER_SP_PERIOD bfin_write_TIMER5_PERIOD
152 #define TIMDIS_SP TIMDIS5
153 #define TIMEN_SP TIMEN5
155 #define bfin_write_TIMER_PS_CLS_CONFIG bfin_write_TIMER2_CONFIG
156 #define bfin_write_TIMER_PS_CLS_WIDTH bfin_write_TIMER2_WIDTH
157 #define bfin_write_TIMER_PS_CLS_PERIOD bfin_write_TIMER2_PERIOD
158 #define TIMDIS_PS_CLS TIMDIS2
159 #define TIMEN_PS_CLS TIMEN2
161 #define bfin_write_TIMER_REV_CONFIG bfin_write_TIMER3_CONFIG
162 #define bfin_write_TIMER_REV_WIDTH bfin_write_TIMER3_WIDTH
163 #define bfin_write_TIMER_REV_PERIOD bfin_write_TIMER3_PERIOD
164 #define TIMDIS_REV TIMDIS3
165 #define TIMEN_REV TIMEN3
166 #define bfin_read_TIMER_REV_COUNTER bfin_read_TIMER3_COUNTER
168 #define FREQ_PPI_CLK (5*1024*1024)
170 #define TIMERS {P_TMR0, P_TMR1, P_TMR2, P_TMR3, P_TMR5, 0}
175 #define MOD GPIO_PF10
176 #define LBR GPIO_PF14
178 #define bfin_write_TIMER_LP_CONFIG bfin_write_TIMER6_CONFIG
179 #define bfin_write_TIMER_LP_WIDTH bfin_write_TIMER6_WIDTH
180 #define bfin_write_TIMER_LP_PERIOD bfin_write_TIMER6_PERIOD
181 #define bfin_read_TIMER_LP_COUNTER bfin_read_TIMER6_COUNTER
182 #define TIMDIS_LP TIMDIS6
183 #define TIMEN_LP TIMEN6
185 #define bfin_write_TIMER_SPS_CONFIG bfin_write_TIMER1_CONFIG
186 #define bfin_write_TIMER_SPS_WIDTH bfin_write_TIMER1_WIDTH
187 #define bfin_write_TIMER_SPS_PERIOD bfin_write_TIMER1_PERIOD
188 #define TIMDIS_SPS TIMDIS1
189 #define TIMEN_SPS TIMEN1
191 #define bfin_write_TIMER_SP_CONFIG bfin_write_TIMER0_CONFIG
192 #define bfin_write_TIMER_SP_WIDTH bfin_write_TIMER0_WIDTH
193 #define bfin_write_TIMER_SP_PERIOD bfin_write_TIMER0_PERIOD
194 #define TIMDIS_SP TIMDIS0
195 #define TIMEN_SP TIMEN0
197 #define bfin_write_TIMER_PS_CLS_CONFIG bfin_write_TIMER7_CONFIG
198 #define bfin_write_TIMER_PS_CLS_WIDTH bfin_write_TIMER7_WIDTH
199 #define bfin_write_TIMER_PS_CLS_PERIOD bfin_write_TIMER7_PERIOD
200 #define TIMDIS_PS_CLS TIMDIS7
201 #define TIMEN_PS_CLS TIMEN7
203 #define bfin_write_TIMER_REV_CONFIG bfin_write_TIMER5_CONFIG
204 #define bfin_write_TIMER_REV_WIDTH bfin_write_TIMER5_WIDTH
205 #define bfin_write_TIMER_REV_PERIOD bfin_write_TIMER5_PERIOD
206 #define TIMDIS_REV TIMDIS5
207 #define TIMEN_REV TIMEN5
208 #define bfin_read_TIMER_REV_COUNTER bfin_read_TIMER5_COUNTER
210 #define FREQ_PPI_CLK (6*1000*1000)
211 #define TIMERS {P_TMR0, P_TMR1, P_TMR5, P_TMR6, P_TMR7, 0}
215 #define LCD_X_RES 240
216 #define LCD_Y_RES 320
225 #define START_LINES 8
228 #define FRAMES_PER_SEC (60)
230 #define DCLKS_PER_FRAME (FREQ_PPI_CLK/FRAMES_PER_SEC)
231 #define DCLKS_PER_LINE (DCLKS_PER_FRAME/(LCD_Y_RES+U_LINES))
233 #define PPI_CONFIG_VALUE (PORT_DIR|XFR_TYPE|DLEN_16|POLS)
234 #define PPI_DELAY_VALUE (0)
235 #define TIMER_CONFIG (PWM_OUT|PERIOD_CNT|TIN_SEL|CLK_SEL)
237 #define ACTIVE_VIDEO_MEM_OFFSET (LCD_X_RES*START_LINES*(LCD_BBP/8))
238 #define ACTIVE_VIDEO_MEM_SIZE (LCD_Y_RES*LCD_X_RES*(LCD_BBP/8))
239 #define TOTAL_VIDEO_MEM_SIZE ((LCD_Y_RES+U_LINES)*LCD_X_RES*(LCD_BBP/8))
240 #define TOTAL_DMA_DESC_SIZE (2 * sizeof(u32) * (LCD_Y_RES + U_LINES))
242 static void start_timers(
void)
264 static void config_timers(
void)
308 static void config_ppi(
void)
316 static int config_dma(
void)
324 dma_desc_table[2*
i] = (
unsigned long)&dma_desc_table[2*i+2];
325 dma_desc_table[2*i+1] = (
unsigned long)fb_buffer;
328 for (i = U_LINES; i < U_LINES +
LCD_Y_RES; ++
i) {
330 dma_desc_table[2*
i] = (
unsigned long)&dma_desc_table[2*i+2];
331 dma_desc_table[2*i+1] = (
unsigned long)fb_buffer +
332 (LCD_Y_RES+U_LINES-1-i)*2;
336 dma_desc_table[2*(LCD_Y_RES+U_LINES-1)] = (
unsigned long)&dma_desc_table[0];
340 set_dma_y_count(
CH_PPI, 0);
341 set_dma_y_modify(
CH_PPI, 0);
342 set_dma_next_desc_addr(
CH_PPI, (
void *)dma_desc_table[0]);
355 set_dma_y_count(
CH_PPI, LCD_Y_RES+U_LINES);
357 set_dma_start_addr(
CH_PPI, (
unsigned long) fb_buffer);
375 pr_err(
"requesting PPI peripheral failed\n");
381 pr_err(
"requesting timer peripheral failed\n");
385 #if (defined(UD) && defined(LBR))
387 pr_err(
"requesting GPIO %d failed\n",
UD);
392 pr_err(
"requesting GPIO %d failed\n",
LBR);
399 pr_err(
"requesting GPIO %d failed\n",
MOD);
400 #if (defined(UD) && defined(LBR))
411 static void free_ports(
void)
418 #if defined(UD) && defined(LBR)
425 static struct fb_info bfin_lq035_fb;
447 .id = KBUILD_MODNAME,
464 spin_unlock_irqrestore(&bfin_lq035_lock, flags);
466 if (lq035_open_cnt <= 1) {
490 static int bfin_lq035_fb_release(
struct fb_info *info,
int user)
496 spin_unlock_irqrestore(&bfin_lq035_lock, flags);
499 if (lq035_open_cnt <= 0) {
516 var->
red.offset = info->
var.red.offset;
517 var->
green.offset = info->
var.green.offset;
518 var->
blue.offset = info->
var.blue.offset;
519 var->
red.length = info->
var.red.length;
520 var->
green.length = info->
var.green.length;
521 var->
blue.length = info->
var.blue.length;
524 var->
transp.msb_right = 0;
525 var->
red.msb_right = 0;
526 var->
green.msb_right = 0;
527 var->
blue.msb_right = 0;
530 pr_debug(
"%s: depth not supported: %u BPP\n", __func__,
535 if (info->
var.xres != var->
xres ||
539 pr_debug(
"%s: Resolution not supported: X%u x Y%u\n",
549 pr_debug(
"%s: Memory Limit requested yres_virtual = %u\n",
561 static void bfin_lq035_fb_rotate(
struct fb_info *fbi,
int angle)
563 pr_debug(
"%s: %p %d", __func__, fbi, angle);
564 #if (defined(UD) && defined(LBR))
579 static int bfin_lq035_fb_cursor(
struct fb_info *info,
struct fb_cursor *cursor)
594 if (info->
var.grayscale)
596 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
605 red >>= (16 - info->
var.red.length);
606 green >>= (16 - info->
var.green.length);
607 blue >>= (16 - info->
var.blue.length);
609 value = (red << info->
var.red.offset) |
610 (green << info->
var.green.offset)|
611 (blue << info->
var.blue.offset);
621 static struct fb_ops bfin_lq035_fb_ops = {
623 .fb_open = bfin_lq035_fb_open,
624 .fb_release = bfin_lq035_fb_release,
625 .fb_check_var = bfin_lq035_fb_check_var,
626 .fb_rotate = bfin_lq035_fb_rotate,
630 .fb_cursor = bfin_lq035_fb_cursor,
631 .fb_setcolreg = bfin_lq035_fb_setcolreg,
636 return current_brightness;
640 .get_brightness = bl_get_brightness,
650 static int bfin_lcd_set_power(
struct lcd_device *
dev,
int power)
657 return (
int)vcomm_value;
667 vcomm_value = (
unsigned char)contrast;
674 if (!fi || (fi == &bfin_lq035_fb))
679 static struct lcd_ops bfin_lcd_ops = {
680 .get_power = bfin_lcd_get_power,
681 .set_power = bfin_lcd_set_power,
682 .get_contrast = bfin_lcd_get_contrast,
683 .set_contrast = bfin_lcd_set_contrast,
684 .check_fb = bfin_lcd_check_fb,
696 pr_err(
"couldn't request PPI DMA\n");
700 if (request_ports()) {
701 pr_err(
"couldn't request gpio port\n");
708 if (fb_buffer ==
NULL) {
709 pr_err(
"couldn't allocate dma buffer\n");
711 goto out_dma_coherent;
720 if (dma_desc_table ==
NULL) {
721 pr_err(
"couldn't allocate dma descriptor\n");
726 bfin_lq035_fb.screen_base = (
void *)fb_buffer;
727 bfin_lq035_fb_fix.smem_start = (
int)fb_buffer;
734 bfin_lq035_fb_fix.line_length = LCD_Y_RES*(
LCD_BBP/8);
740 bfin_lq035_fb_defined.
green.msb_right = 0;
741 bfin_lq035_fb_defined.
red.msb_right = 0;
742 bfin_lq035_fb_defined.
blue.msb_right = 0;
743 bfin_lq035_fb_defined.
green.offset = 5;
744 bfin_lq035_fb_defined.
green.length = 6;
745 bfin_lq035_fb_defined.
red.length = 5;
746 bfin_lq035_fb_defined.
blue.length = 5;
749 bfin_lq035_fb_defined.
red.offset = 0;
750 bfin_lq035_fb_defined.
blue.offset = 11;
752 bfin_lq035_fb_defined.
red.offset = 11;
753 bfin_lq035_fb_defined.
blue.offset = 0;
756 bfin_lq035_fb.fbops = &bfin_lq035_fb_ops;
757 bfin_lq035_fb.var = bfin_lq035_fb_defined;
759 bfin_lq035_fb.fix = bfin_lq035_fb_fix;
766 if (bfin_lq035_fb.pseudo_palette ==
NULL) {
767 pr_err(
"failed to allocate pseudo_palette\n");
773 pr_err(
"failed to allocate colormap (%d entries)\n",
780 pr_err(
"unable to register framebuffer\n");
785 i2c_add_driver(&ad5280_driver);
787 memset(&props, 0,
sizeof(props));
791 &bfin_lq035fb_bl_ops, &props);
795 if (IS_ERR(lcd_dev)) {
796 pr_err(
"unable to register lcd\n");
797 ret = PTR_ERR(lcd_dev);
800 lcd_dev->
props.max_contrast = 255,
821 if (fb_buffer !=
NULL)
847 pr_info(
"unregistered LCD driver\n");
855 if (lq035_open_cnt > 0) {
866 if (lq035_open_cnt > 0) {
886 # define bfin_lq035_suspend NULL
887 # define bfin_lq035_resume NULL
891 .probe = bfin_lq035_probe,
896 .name = KBUILD_MODNAME,
901 static int __init bfin_lq035_driver_init(
void)
903 request_module(
"i2c-bfin-twi");
908 static void __exit bfin_lq035_driver_cleanup(
void)