/* LCD init */ void lcd_init_device(void) { #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) corelock_init(&cl); #endif #ifdef IPOD_MINI2G /* serial LCD hookup */ lcd_wait_write(); LCD1_CONTROL = 0x01730084; /* fastest setting */ #elif defined(IPOD_1G2G) || defined(IPOD_3G) LCD1_CONTROL = (LCD1_CONTROL & 0x0002) | 0x0084; /* fastest setting, keep backlight bit */ #else LCD1_CONTROL = 0x0084; /* fastest setting */ #endif lcd_cmd_and_data(R_DRV_WAVEFORM_CONTROL, 0x48); /* C waveform, no EOR, 9 lines inversion */ lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0xc); lcd_cmd_and_data(R_DISPLAY_CONTROL, 0x0019); lcd_set_contrast(DEFAULT_CONTRAST); #ifdef HAVE_BACKLIGHT_INVERSION invert_display(); #endif lcd_set_flip(false); lcd_cmd_and_data(R_ENTRY_MODE, 0x0000); }
static void set_backlight(int on) { int lcd_state = inl(IPOD_LCD_BASE); if (on) { lcd_state = lcd_state | 0x2; outl(lcd_state, IPOD_LCD_BASE); /* display control (1 00 0 1) */ /* GSH=01 -> 2/3 level grayscale control */ /* GSL=00 -> 1/4 level grayscale control */ /* REV=0 -> don't reverse */ /* D=1 -> display on */ lcd_cmd_and_data(0x7, 0x0, 0x11 /* | 0x2 */); } else { lcd_state = lcd_state & ~0x2; outl(lcd_state, IPOD_LCD_BASE); /* display control (10 0 1) */ /* GSL=10 -> 2/4 level grayscale control */ /* REV=0 -> don't reverse */ /* D=1 -> display on */ lcd_cmd_and_data(0x7, 0x0, 0x9 /* | 0x2 */); } }
/* turn the display upside down (call lcd_update() afterwards) */ void lcd_set_flip(bool yesno) { #if defined(IPOD_MINI) || defined(IPOD_MINI2G) if (yesno) { /* 168x112, inverse COM order */ lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x020d); lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x8316); /* 22..131 */ addr_offset = (22 << 5) | (20 - 4); pix_offset = -2; } else { /* 168x112, inverse SEG order */ lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x010d); lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x6d00); /* 0..109 */ addr_offset = 20; pix_offset = 0; } #else if (yesno) { /* 168x128, inverse SEG & COM order */ lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x030f); lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x8304); /* 4..131 */ addr_offset = (4 << 5) | (20 - 1); } else { /* 168x128 */ lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x000f); lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x7f00); /* 0..127 */ addr_offset = 20; } #endif }
void lcd_update_rect(int x, int y, int width, int height) { int xmax, ymax; if (x + width > LCD_WIDTH) width = LCD_WIDTH - x; if (width <= 0) return; ymax = y + height - 1; if (ymax >= LCD_HEIGHT) ymax = LCD_HEIGHT - 1; #if defined(IPOD_MINI) || defined(IPOD_MINI2G) x += pix_offset; #endif /* writing is done in 16-bit units (8 pixels) */ xmax = (x + width - 1) >> 3; x >>= 3; width = xmax - x + 1; for (; y <= ymax; y++) { lcd_cmd_and_data(R_RAM_ADDR_SET, (y << 5) + addr_offset - x); lcd_prepare_cmd(R_RAM_DATA); #if defined(IPOD_MINI) || defined(IPOD_MINI2G) if (pix_offset == -2) lcd_write_data_shifted(&lcd_framebuffer[y][2*x], width); else #endif lcd_write_data(&lcd_framebuffer[y][2*x], width); } }
/* Rockbox stores the contrast as 0..63 - we add 64 to it */ void lcd_set_contrast(int val) { if (val < 0) val = 0; else if (val > 63) val = 63; lcd_cmd_and_data(R_CONTRAST_CONTROL, CONTRAST_REG_H | (val + 64)); }
static void set_contrast(int contrast) { if (ipod_hw_ver < 0x6 || ipod_hw_ver == 0x7) { lcd_cmd_and_data(0x4, 0x4, contrast); lcd_contrast = contrast; } }
void lcd_enable(bool on) { if (on) { lcd_cmd_and_data(R_START_OSC, 1); /* start oscillation */ sleep(HZ/10); /* wait 10ms */ lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H); /*clear standby mode */ lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0xc); /* enable opamp & booster */ } else { lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H); /* switch off opamp & booster */ lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x1); /* enter standby mode */ } }
static void invert_display(void) { static bool last_invert = false; bool new_invert = lcd_inverted ^ lcd_backlit; if (new_invert != last_invert) { int oldlevel = disable_irq_save(); #if NUM_CORES > 1 corelock_lock(&cl); lcd_cmd_and_data(R_DISPLAY_CONTROL, new_invert? 0x0027 : 0x0019); corelock_unlock(&cl); #else lcd_cmd_and_data(R_DISPLAY_CONTROL, new_invert? 0x0027 : 0x0019); #endif restore_irq(oldlevel); last_invert = new_invert; } }
/* initialise the LCD */ static void init_lcd(void) { if ( read_controller_id() != HD66753_ID ) { printk(KERN_ERR "Unknown LCD controller ID: 0x%x id?\n", read_controller_id()); } /* driver output control - 168x128 -> we use 160x128 */ /* CMS=0, SGS=1 */ lcd_cmd_and_data(0x1, 0x1, 0xf); /* ID=1 -> auto decrement address counter */ /* AM=00 -> data is continuously written in parallel */ /* LG=00 -> no logical operation */ lcd_cmd_and_data(0x5, 0x0, 0x10); /* backlight off & set grayscale */ set_backlight(0); }
void contrast_down(void) { int contrast = get_contrast(); if ( contrast > 0 ) { contrast--; lcd_cmd_and_data(0x4, 0x4, contrast); #if 0 printk("ctrst=0x%x\n", get_contrast()); #endif } }
void contrast_up(void) { int contrast = get_contrast(); if ( contrast < 0xff ) { contrast++; lcd_cmd_and_data(0x4, 0x4, contrast); #if 0 printk("ctrst=0x%x\n", get_contrast()); #endif } }
static int ipod_blank(int blank_mode, const struct fb_info *info) { static int backlight_on = -1; switch (blank_mode) { case VESA_NO_BLANKING: /* printk(KERN_ERR "VESA_NO_BLANKING\n"); */ /* start oscillation * wait 10ms * cancel standby * turn on LCD power */ lcd_cmd_and_data(0x0, 0x0, 0x1); udelay(10000); lcd_cmd_and_data(0x3, 0x15, 0x0); lcd_cmd_and_data(0x3, 0x15, 0xc); if (backlight_on != -1) { set_backlight(backlight_on); } backlight_on = -1; break; case VESA_VSYNC_SUSPEND: case VESA_HSYNC_SUSPEND: /* printk(KERN_ERR "VESA_XSYNC_BLANKING\n"); */ if (backlight_on == -1) { backlight_on = get_backlight(); set_backlight(0); } /* go to SLP = 1 */ /* 10101 00001100 */ lcd_cmd_and_data(0x3, 0x15, 0x0); lcd_cmd_and_data(0x3, 0x15, 0x2); break; case VESA_POWERDOWN: /* printk(KERN_ERR "VESA_POWERDOWN\n"); */ if (backlight_on == -1) { backlight_on = get_backlight(); set_backlight(0); } /* got to standby */ lcd_cmd_and_data(0x3, 0x15, 0x1); break; default: /* printk(KERN_ERR "unknown blank value %d\n", blank_mode); */ return -EINVAL; } return 0; }
/* Performance function that works with an external buffer note that x, bwidtht and stride are in 8-pixel units! */ void lcd_blit_mono(const unsigned char *data, int bx, int y, int bwidth, int height, int stride) { #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) corelock_lock(&cl); #endif while (height--) { lcd_cmd_and_data(R_RAM_ADDR_SET, (y++ << 5) + addr_offset - bx); lcd_prepare_cmd(R_RAM_DATA); lcd_mono_data(data, bwidth); data += stride; } #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) corelock_unlock(&cl); #endif }
/* Performance function that works with an external buffer note that bx and bwidth are in 8-pixel units! */ void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, int bx, int y, int bwidth, int height, int stride) { #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) corelock_lock(&cl); #endif while (height--) { lcd_cmd_and_data(R_RAM_ADDR_SET, (y++ << 5) + addr_offset - bx); lcd_prepare_cmd(R_RAM_DATA); lcd_grey_data(values, phases, bwidth); values += stride; phases += stride; } #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) corelock_unlock(&cl); #endif }
void lcd_set_invert_display(bool yesno) { lcd_cmd_and_data(R_DISPLAY_CONTROL, yesno ? 0x0027 : 0x0019); }
/* LCD powerdown */ void lcd_shutdown(void) { lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x00); /* Turn off op amp power */ lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x02); /* Put LCD driver in standby */ }
static void set_contrast(int contrast) { lcd_cmd_and_data(0x4, 0x4, contrast); }