Path: blob/master/arch/sh/boards/mach-migor/lcd_qvga.c
15126 views
/*1* Support for SuperH MigoR Quarter VGA LCD Panel2*3* Copyright (C) 2008 Magnus Damm4*5* Based on lcd_powertip.c from Kenati Technologies Pvt Ltd.6* Copyright (c) 2007 Ujjwal Pande <[email protected]>,7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License version 2 as10* published by the Free Software Foundation.11*/1213#include <linux/delay.h>14#include <linux/err.h>15#include <linux/fb.h>16#include <linux/init.h>17#include <linux/kernel.h>18#include <linux/module.h>19#include <linux/gpio.h>20#include <video/sh_mobile_lcdc.h>21#include <cpu/sh7722.h>22#include <mach/migor.h>2324/* LCD Module is a PH240320T according to board schematics. This module25* is made up of a 240x320 LCD hooked up to a R61505U (or HX8347-A01?)26* Driver IC. This IC is connected to the SH7722 built-in LCDC using a27* SYS-80 interface configured in 16 bit mode.28*29* Index 0: "Device Code Read" returns 0x1505.30*/3132static void reset_lcd_module(void)33{34gpio_set_value(GPIO_PTH2, 0);35mdelay(2);36gpio_set_value(GPIO_PTH2, 1);37mdelay(1);38}3940/* DB0-DB7 are connected to D1-D8, and DB8-DB15 to D10-D17 */4142static unsigned long adjust_reg18(unsigned short data)43{44unsigned long tmp1, tmp2;4546tmp1 = (data<<1 | 0x00000001) & 0x000001FF;47tmp2 = (data<<2 | 0x00000200) & 0x0003FE00;48return tmp1 | tmp2;49}5051static void write_reg(void *sys_ops_handle,52struct sh_mobile_lcdc_sys_bus_ops *sys_ops,53unsigned short reg, unsigned short data)54{55sys_ops->write_index(sys_ops_handle, adjust_reg18(reg << 8 | data));56}5758static void write_reg16(void *sys_ops_handle,59struct sh_mobile_lcdc_sys_bus_ops *sys_ops,60unsigned short reg, unsigned short data)61{62sys_ops->write_index(sys_ops_handle, adjust_reg18(reg));63sys_ops->write_data(sys_ops_handle, adjust_reg18(data));64}6566static unsigned long read_reg16(void *sys_ops_handle,67struct sh_mobile_lcdc_sys_bus_ops *sys_ops,68unsigned short reg)69{70unsigned long data;7172sys_ops->write_index(sys_ops_handle, adjust_reg18(reg));73data = sys_ops->read_data(sys_ops_handle);74return ((data >> 1) & 0xff) | ((data >> 2) & 0xff00);75}7677static void migor_lcd_qvga_seq(void *sys_ops_handle,78struct sh_mobile_lcdc_sys_bus_ops *sys_ops,79unsigned short const *data, int no_data)80{81int i;8283for (i = 0; i < no_data; i += 2)84write_reg16(sys_ops_handle, sys_ops, data[i], data[i + 1]);85}8687static const unsigned short sync_data[] = {880x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,89};9091static const unsigned short magic0_data[] = {920x0060, 0x2700, 0x0008, 0x0808, 0x0090, 0x001A, 0x0007, 0x0001,930x0017, 0x0001, 0x0019, 0x0000, 0x0010, 0x17B0, 0x0011, 0x0116,940x0012, 0x0198, 0x0013, 0x1400, 0x0029, 0x000C, 0x0012, 0x01B8,95};9697static const unsigned short magic1_data[] = {980x0030, 0x0307, 0x0031, 0x0303, 0x0032, 0x0603, 0x0033, 0x0202,990x0034, 0x0202, 0x0035, 0x0202, 0x0036, 0x1F1F, 0x0037, 0x0303,1000x0038, 0x0303, 0x0039, 0x0603, 0x003A, 0x0202, 0x003B, 0x0102,1010x003C, 0x0204, 0x003D, 0x0000, 0x0001, 0x0100, 0x0002, 0x0300,1020x0003, 0x5028, 0x0020, 0x00ef, 0x0021, 0x0000, 0x0004, 0x0000,1030x0009, 0x0000, 0x000A, 0x0008, 0x000C, 0x0000, 0x000D, 0x0000,1040x0015, 0x8000,105};106107static const unsigned short magic2_data[] = {1080x0061, 0x0001, 0x0092, 0x0100, 0x0093, 0x0001, 0x0007, 0x0021,109};110111static const unsigned short magic3_data[] = {1120x0010, 0x16B0, 0x0011, 0x0111, 0x0007, 0x0061,113};114115int migor_lcd_qvga_setup(void *board_data, void *sohandle,116struct sh_mobile_lcdc_sys_bus_ops *so)117{118unsigned long xres = 320;119unsigned long yres = 240;120int k;121122reset_lcd_module();123migor_lcd_qvga_seq(sohandle, so, sync_data, ARRAY_SIZE(sync_data));124125if (read_reg16(sohandle, so, 0) != 0x1505)126return -ENODEV;127128pr_info("Migo-R QVGA LCD Module detected.\n");129130migor_lcd_qvga_seq(sohandle, so, sync_data, ARRAY_SIZE(sync_data));131write_reg16(sohandle, so, 0x00A4, 0x0001);132mdelay(10);133134migor_lcd_qvga_seq(sohandle, so, magic0_data, ARRAY_SIZE(magic0_data));135mdelay(100);136137migor_lcd_qvga_seq(sohandle, so, magic1_data, ARRAY_SIZE(magic1_data));138write_reg16(sohandle, so, 0x0050, 0xef - (yres - 1));139write_reg16(sohandle, so, 0x0051, 0x00ef);140write_reg16(sohandle, so, 0x0052, 0x0000);141write_reg16(sohandle, so, 0x0053, xres - 1);142143migor_lcd_qvga_seq(sohandle, so, magic2_data, ARRAY_SIZE(magic2_data));144mdelay(10);145146migor_lcd_qvga_seq(sohandle, so, magic3_data, ARRAY_SIZE(magic3_data));147mdelay(40);148149/* clear GRAM to avoid displaying garbage */150151write_reg16(sohandle, so, 0x0020, 0x0000); /* horiz addr */152write_reg16(sohandle, so, 0x0021, 0x0000); /* vert addr */153154for (k = 0; k < (xres * 256); k++) /* yes, 256 words per line */155write_reg16(sohandle, so, 0x0022, 0x0000);156157write_reg16(sohandle, so, 0x0020, 0x0000); /* reset horiz addr */158write_reg16(sohandle, so, 0x0021, 0x0000); /* reset vert addr */159write_reg16(sohandle, so, 0x0007, 0x0173);160mdelay(40);161162/* enable display */163write_reg(sohandle, so, 0x00, 0x22);164mdelay(100);165return 0;166}167168169