|
楼主 |
发表于 2014-8-21 16:48:27
|
显示全部楼层
来自 广东省深圳市
- #ifndef BUILD_LK
- #include <linux/string.h>
- #endif
- #ifdef BUILD_LK
- #include <platform/mt_gpio.h>
- #include <platform/mt_pmic.h>
- #elif (defined BUILD_UBOOT)
- #include <asm/arch/mt6577_gpio.h>
- #else
- #include <mach/mt_gpio.h>
- #include <mach/mt_pm_ldo.h>
- #endif
- #include "lcm_drv.h"
- // ---------------------------------------------------------------------------
- // Local Constants
- // ---------------------------------------------------------------------------
- #define FRAME_WIDTH (240)
- #define FRAME_HEIGHT (320)
- // ---------------------------------------------------------------------------
- // Local Variables
- // ---------------------------------------------------------------------------
- static LCM_UTIL_FUNCS lcm_util = {0};
- #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
- #define UDELAY(n) (lcm_util.udelay(n))
- #define MDELAY(n) (lcm_util.mdelay(n))
- // ---------------------------------------------------------------------------
- // Local Functions
- // ---------------------------------------------------------------------------
- //cs gpio110
- //sda gpio111
- //scl gpio59
- #define SPI_CS(flag) (lcm_util.set_gpio_out(GPIO110,flag))
- #define SPI_SDA(flag) (lcm_util.set_gpio_out(GPIO111,flag))
- #define SPI_SCL(flag) (lcm_util.set_gpio_out(GPIO59,flag))
- static int SPI_Gpio_init(void){
- lcm_util.set_gpio_mode(GPIO140, GPIO_MODE_00);
- lcm_util.set_gpio_dir(GPIO140, GPIO_DIR_OUT);
- lcm_util.set_gpio_out(GPIO140, GPIO_OUT_ONE);
-
- lcm_util.set_gpio_mode(GPIO110, GPIO_MODE_00);
- lcm_util.set_gpio_dir(GPIO110, GPIO_DIR_OUT);
- lcm_util.set_gpio_out(GPIO110, GPIO_OUT_ONE);
-
- lcm_util.set_gpio_mode(GPIO59, GPIO_MODE_00);
- lcm_util.set_gpio_dir(GPIO59, GPIO_DIR_OUT);
- lcm_util.set_gpio_out(GPIO59, GPIO_OUT_ONE);
- lcm_util.set_gpio_mode(GPIO111, GPIO_MODE_00);
- lcm_util.set_gpio_dir(GPIO111, GPIO_DIR_OUT);
- lcm_util.set_gpio_out(GPIO111, GPIO_OUT_ONE);
-
- return 0;
- }
- static void SPI_SendData(unsigned char i)//(SPIê±DòOK)
- {
- unsigned char n;
- UDELAY(1);
- for(n=0; n<8; n++)
- {
- if(i&0x80) SPI_SDA(1);
- else SPI_SDA(0);
- i<<= 1;
-
- UDELAY(1);
- SPI_SCL(0);
- UDELAY(1);
- SPI_SCL(1);
- UDELAY(1);
- }
- }
- static void write_SPI_commond(unsigned char i)
- {
- SPI_CS(0);
- UDELAY(1);
- SPI_SDA(0);
- SPI_SCL(0);
- UDELAY(1);
- SPI_SCL(1);
- SPI_SendData(i);
-
- SPI_CS(1);
- }
- static void write_SPI_data(unsigned char i)
- {
- SPI_CS(0);
- UDELAY(1);
- SPI_SDA(1);
- SPI_SCL(0);
- UDELAY(1);
- SPI_SCL(1);
- SPI_SendData(i);
- SPI_CS(1);
- }
- static void LCD_ILI9325_init(void)
- {
- if(SPI_Gpio_init()<0)return;
- MDELAY(10);
- //udelay(10*1000);
- write_SPI_commond(0x01);write_SPI_data( 0x01);write_SPI_data(0x00); // set SS and SM bit SM=0 SS=1
- write_SPI_commond(0x02);write_SPI_data( 0x02);write_SPI_data(0x00); // set 1 line inversion
- write_SPI_commond(0x03);write_SPI_data( 0x10);write_SPI_data(0x30); // set GRAM write direction and BGR=1.
- write_SPI_commond(0x04);write_SPI_data( 0x00);write_SPI_data(0x00); // Resize register
- write_SPI_commond(0x08);write_SPI_data( 0x06);write_SPI_data(0x06); // set the back porch and front porch//0606
- write_SPI_commond(0x09);write_SPI_data( 0x00);write_SPI_data(0x00); // set non-display area refresh cycle ISC[3:0]
- write_SPI_commond(0x0A);write_SPI_data( 0x00);write_SPI_data(0x00); // FMARK function
- write_SPI_commond(0x0C);write_SPI_data( 0x01);write_SPI_data(0x10); // RGB interface setting//0111=16bit);write_SPI_data(0110=18bit);write_SPI_data(
- write_SPI_commond(0x0D);write_SPI_data( 0x00);write_SPI_data(0x00); // Frame marker Position
- write_SPI_commond(0x0F);write_SPI_data( 0x00);write_SPI_data(0x0a); // RGB interface polarity
- //*************Power On sequence ****************//
- write_SPI_commond(0x10);write_SPI_data( 0x00);write_SPI_data(0x00); // SAP);write_SPI_data( BT[3:0]);write_SPI_data( AP);write_SPI_data(
- write_SPI_commond(0x11);write_SPI_data( 0x00);write_SPI_data(0x07); // DC1[2:0]);write_SPI_data( DC0[2:0]);write_SPI_data( VC[2:0]
- write_SPI_commond(0x12);write_SPI_data( 0x00);write_SPI_data(0x00); // VREG1OUT voltage
- write_SPI_commond(0x13);write_SPI_data( 0x00);write_SPI_data(0x00); // VDV[4:0] for VCOM amplitude
- write_SPI_commond(0x07);write_SPI_data( 0x00);write_SPI_data(0x01); // Set VCM[5:0] for VCOMH
-
- write_SPI_commond(0x10);write_SPI_data( 0x12);write_SPI_data(0x90); // SAP);write_SPI_data( BT[3:0]);write_SPI_data( AP);write_SPI_data(
- write_SPI_commond(0x11);write_SPI_data( 0x02);write_SPI_data(0x27); // DC1[2:0]);write_SPI_data( DC0[2:0]);write_SPI_data( VC[2:0]
- //udelay(50*1000);
- MDELAY(50);
- write_SPI_commond(0x12);write_SPI_data( 0x00);write_SPI_data(0x8B); // Internal reference voltage= Vci;
- // udelay(50*1000);
- MDELAY(50);
- write_SPI_commond(0x13);write_SPI_data( 0x12);write_SPI_data(0x00); // Set VDV[4:0] for VCOM amplitude
-
- write_SPI_commond(0x29);write_SPI_data( 0x00);write_SPI_data(0x23); // Set VCM[5:0] for VCOMH
- write_SPI_commond(0x2B);write_SPI_data( 0x00);write_SPI_data(0x0c); // Set Frame Rate //0C
- //udelay(50*1000);
- MDELAY(50);
- write_SPI_commond(0x20);write_SPI_data( 0x00);write_SPI_data(0x00); // GRAM horizontal Address
- write_SPI_commond(0x21);write_SPI_data( 0x00);write_SPI_data(0x00); // GRAM Vertical Address
- // ----------- Adjust the Gamma Curve ----------//
- write_SPI_commond(0x30);write_SPI_data( 0x00);write_SPI_data(0x00);
- write_SPI_commond(0x31);write_SPI_data( 0x04);write_SPI_data(0x04);
- write_SPI_commond(0x32);write_SPI_data( 0x00);write_SPI_data(0x02);
- write_SPI_commond(0x35);write_SPI_data( 0x03);write_SPI_data(0x01);
- write_SPI_commond(0x36);write_SPI_data( 0x00);write_SPI_data(0x04);
- write_SPI_commond(0x37);write_SPI_data( 0x05);write_SPI_data(0x07);
- write_SPI_commond(0x38);write_SPI_data( 0x03);write_SPI_data(0x03);
- write_SPI_commond(0x39);write_SPI_data( 0x07);write_SPI_data(0x07);
- write_SPI_commond(0x3C);write_SPI_data( 0x01);write_SPI_data(0x03);
- write_SPI_commond(0x3D);write_SPI_data( 0x00);write_SPI_data(0x04);
- //------------------ Set GRAM area ---------------//
- write_SPI_commond(0x50);write_SPI_data( 0x00);write_SPI_data(0x00); // Horizontal GRAM Start Address
- write_SPI_commond(0x51);write_SPI_data( 0x00);write_SPI_data(0xEF); // Horizontal GRAM End Address
- write_SPI_commond(0x52);write_SPI_data( 0x00);write_SPI_data(0x00); // Vertical GRAM Start Address
- write_SPI_commond(0x53);write_SPI_data( 0x01);write_SPI_data(0x3F); // Vertical GRAM Start Address
- write_SPI_commond(0x60);write_SPI_data( 0xA7);write_SPI_data(0x00); // Gate Scan Line
- write_SPI_commond(0x61);write_SPI_data( 0x00);write_SPI_data(0x01); // NDL);write_SPI_data(VLE);write_SPI_data( REV
- write_SPI_commond(0x6A);write_SPI_data( 0x00);write_SPI_data(0x00); // set scrolling line
- //-------------- Partial Display Control ---------//
- write_SPI_commond(0x80);write_SPI_data( 0x00);write_SPI_data(0x00);
- write_SPI_commond(0x81);write_SPI_data( 0x00);write_SPI_data(0x00);
- write_SPI_commond(0x82);write_SPI_data( 0x00);write_SPI_data(0x00);
- write_SPI_commond(0x83);write_SPI_data( 0x00);write_SPI_data(0x00);
- write_SPI_commond(0x84);write_SPI_data( 0x00);write_SPI_data(0x00);
- write_SPI_commond(0x85);write_SPI_data( 0x00);write_SPI_data(0x00);
- //-------------- Panel Control -------------------//
- write_SPI_commond(0x90);write_SPI_data( 0x00);write_SPI_data(0x10);
- write_SPI_commond(0x92);write_SPI_data( 0x06);write_SPI_data(0x00);
- write_SPI_commond(0x07);write_SPI_data( 0x01);write_SPI_data(0x33); // 262K color and display ON
- write_SPI_commond(0x22);
- }
- static __inline void send_ctrl_cmd(unsigned int cmd)
- {
- }
- static __inline void send_data_cmd(unsigned int data)
- {
-
- }
- static __inline void set_lcm_register(unsigned int regIndex,
- unsigned int regData)
- {
- send_ctrl_cmd(regIndex);
- send_data_cmd(regData);
- }
- // ---------------------------------------------------------------------------
- // LCM Driver Implementations
- // ---------------------------------------------------------------------------
- static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
- {
- memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
- }
- static void lcm_get_params(LCM_PARAMS *params)
- {
- memset(params, 0, sizeof(LCM_PARAMS));
- #if 1
- params->type = LCM_TYPE_DPI;
- params->ctrl = LCM_CTRL_NONE;
- params->width = FRAME_WIDTH;
- params->height = FRAME_HEIGHT;
- params->io_select_mode = 0;
- /* RGB interface configurations
-
- Pixel Clock Frequency = 26MHz * mipi_pll_clk_div1
- / (mipi_pll_clk_ref + 1)
- / (2 * mipi_pll_clk_div2)
- / dpi_clk_div
- */
- #if 0
- params->dpi.mipi_pll_clk_ref = 1;
- params->dpi.mipi_pll_clk_div1 = 0;
- params->dpi.mipi_pll_clk_div2 = 0;
- params->dpi.dpi_clk_div = 2;
- params->dpi.dpi_clk_duty = 1;
- params->dpi.mipi_pll_clk_fbk_div = 10;//11(34Hhz) 13 (41Mhz) 15(48Mhz) 16(51Mhz)
- params->dpi.mipi_pll_clk_fbk_sel = 0;
- #else
- params->dpi.mipi_pll_clk_ref = 0; //the most important parameters: set pll clk to 66Mhz and dpi clk to 33Mhz
- params->dpi.mipi_pll_clk_div1 = 42;//25 yqf modify 2013-6-22(14:21:15) 31 24 27/31(25M) 28(100M)43
- params->dpi.mipi_pll_clk_div2 = 10; //yqf 4 4
- params->dpi.dpi_clk_div = 2; //yqf 2 2
- params->dpi.dpi_clk_duty = 1; //yqf 1 1
- #endif
- #if 0
- params->dpi.clk_pol = LCM_POLARITY_RISING;
- params->dpi.de_pol = LCM_POLARITY_RISING;
- params->dpi.vsync_pol = LCM_POLARITY_FALLING;
- params->dpi.hsync_pol = LCM_POLARITY_RISING;
- #else
- params->dpi.clk_pol = LCM_POLARITY_RISING;
- params->dpi.de_pol = LCM_POLARITY_RISING;
- params->dpi.vsync_pol = LCM_POLARITY_FALLING;
- params->dpi.hsync_pol = LCM_POLARITY_RISING;
- #endif
- params->dpi.hsync_pulse_width = 5;
- params->dpi.hsync_back_porch = 8;
- params->dpi.hsync_front_porch = 8;
- params->dpi.vsync_pulse_width = 2;
- params->dpi.vsync_back_porch = 6;
- params->dpi.vsync_front_porch = 6;
- params->dpi.format = LCM_DPI_FORMAT_RGB666;
- params->dpi.rgb_order = LCM_COLOR_ORDER_RGB;
- params->dpi.is_serial_output = 0;
- //params->dpi.i2x_en = 1;
- //params->dpi.i2x_edge = 1;
- //params->dpi.embsync = 0;
-
- params->dpi.intermediat_buffer_num = 2;
- params->dpi.io_driving_current = LCM_DRIVING_CURRENT_4MA;
- #else
- params->type = LCM_TYPE_DPI;
- params->ctrl = LCM_CTRL_SERIAL_DBI;
- params->width = FRAME_WIDTH;
- params->height = FRAME_HEIGHT;
- params->io_select_mode = 0;
- /* RGB interface configurations
-
- Pixel Clock Frequency = 26MHz * mipi_pll_clk_div1
- / (mipi_pll_clk_ref + 1)
- / (2 * mipi_pll_clk_div2)
- / dpi_clk_div
- */
-
- params->dpi.mipi_pll_clk_ref = 1; //
- params->dpi.mipi_pll_clk_div1 = 0;//
- params->dpi.mipi_pll_clk_div2 = 0; //
- params->dpi.mipi_pll_clk_fbk_div = 10;//11(34Hhz) 13 (41Mhz) 15(48Mhz) 16(51Mhz)
- params->dpi.mipi_pll_clk_fbk_sel = 0;
- params->dpi.dpi_clk_div = 0x02; //
- params->dpi.dpi_clk_duty = 0x01; //
- #if 0
- params->dpi.mipi_pll_clk_ref = 0; //the most important parameters: set pll clk to 66Mhz and dpi clk to 33Mhz
- params->dpi.mipi_pll_clk_div1 = 25;//25 yqf modify 2013-6-22(14:21:15) 31 24 27/31(25M) 28(100M)43
- params->dpi.mipi_pll_clk_div2 = 4; //yqf 4 4
- params->dpi.dpi_clk_div = 2; //yqf 2 2
- params->dpi.dpi_clk_duty = 1; //yqf 1 1
- #endif
- params->dpi.clk_pol = LCM_POLARITY_FALLING;
- //params->dpi.clk_pol = LCM_POLARITY_RISING;
- params->dpi.de_pol = LCM_POLARITY_RISING;
- params->dpi.vsync_pol = LCM_POLARITY_FALLING;
- params->dpi.hsync_pol = LCM_POLARITY_FALLING;
- #if 0
- params->dpi.hsync_pulse_width = 128;
- params->dpi.hsync_back_porch = 152;
- params->dpi.hsync_front_porch = 40;
- params->dpi.vsync_pulse_width = 3;
- params->dpi.vsync_back_porch = 12;
- params->dpi.vsync_front_porch = 10;
- #else
- params->dpi.hsync_pulse_width = 48;
- params->dpi.hsync_back_porch = 40;
- params->dpi.hsync_front_porch = 40;
- params->dpi.vsync_pulse_width = 1;
- params->dpi.vsync_back_porch = 31;
- params->dpi.vsync_front_porch = 13;
- #endif
-
- params->dpi.format = LCM_DPI_FORMAT_RGB888; // format is 24 bit
- params->dpi.rgb_order = LCM_COLOR_ORDER_RGB;
- params->dpi.is_serial_output = 0;
- params->dpi.intermediat_buffer_num = 2;
- params->dpi.io_driving_current = LCM_DRIVING_CURRENT_8MA; //yqf modify 2013-6-15(23:39:46)
- #endif
- }
- static void lcm_init(void)
- {
- #ifdef BUILD_LK
- pmic_config_interface(DIGLDO_CON7, 0x1, PMIC_RG_VGP1_EN_MASK, PMIC_RG_VGP1_EN_SHIFT);
- pmic_config_interface(DIGLDO_CON28, 0x07, PMIC_RG_VGP1_VOSEL_MASK, PMIC_RG_VGP1_VOSEL_SHIFT);
- MDELAY(10);
- pmic_config_interface(DIGLDO_CON9, 0x1, PMIC_RG_VGP3_EN_MASK, PMIC_RG_VGP3_EN_SHIFT);
- pmic_config_interface(DIGLDO_CON30, 0x03, PMIC_RG_VGP3_VOSEL_MASK, PMIC_RG_VGP3_VOSEL_SHIFT);
- MDELAY(100);
- LCD_ILI9325_init();
- LCD_ILI9325_init();
- #else
- //hwPowerOn(MT65XX_POWER_LDO_VGP1, VOL_3300, "VGP1");
- //MDELAY(10);
- //hwPowerOn(MT65XX_POWER_LDO_VGP3, VOL_1800, "VGP3");
- #endif
- ////
- ////
-
- }
- static void lcm_suspend(void)
- {
- //////
- //////
- }
- static void lcm_resume(void)
- {
- ////
- ////
-
- }
- LCM_DRIVER ili9325_lcm_drv =
- {
- .name = "ili9325",
- .set_util_funcs = lcm_set_util_funcs,
- .get_params = lcm_get_params,
- .init = lcm_init,
- .suspend = lcm_suspend,
- .resume = lcm_resume,
- };
复制代码 |
|