1 /* BEGIN PN:DTS2013053103858 , Added by d00238048, 2013.05.31*/
3 #include <linux/string.h>
8 #include <platform/mt_gpio.h>
9 #include <platform/mt_i2c.h>
10 #include <platform/mt_pmic.h>
11 #elif defined(BUILD_UBOOT)
12 #include <asm/arch/mt_gpio.h>
14 #include <mach/mt_pm_ldo.h>
15 #include <mach/mt_gpio.h>
17 #include <cust_gpio_usage.h>
20 #define LCD_DEBUG(fmt) dprintf(CRITICAL,fmt)
22 #define LCD_DEBUG(fmt) printk(fmt)
26 static const unsigned int BL_MIN_LEVEL
=20;
27 static LCM_UTIL_FUNCS lcm_util
;
29 #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
30 #define MDELAY(n) (lcm_util.mdelay(n))
32 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
37 #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
38 #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
39 #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
40 #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
41 #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
44 #include <linux/kernel.h>
45 #include <linux/module.h>
47 #include <linux/slab.h>
48 #include <linux/init.h>
49 #include <linux/list.h>
50 #include <linux/i2c.h>
51 #include <linux/irq.h>
52 //#include <linux/jiffies.h>
53 #include <linux/uaccess.h>
54 //#include <linux/delay.h>
55 #include <linux/interrupt.h>
57 #include <linux/platform_device.h>
58 /*****************************************************************************
60 *****************************************************************************/
62 #define TPS_I2C_BUSNUM I2C_I2C_LCD_BIAS_CHANNEL//for I2C channel 0
63 #define I2C_ID_NAME "tps65132"
66 /*****************************************************************************
68 *****************************************************************************/
69 static struct i2c_board_info __initdata tps65132_board_info
= {I2C_BOARD_INFO(I2C_ID_NAME
, TPS_ADDR
)};
70 static struct i2c_client
*tps65132_i2c_client
= NULL
;
73 /*****************************************************************************
75 *****************************************************************************/
76 static int tps65132_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
);
77 static int tps65132_remove(struct i2c_client
*client
);
78 /*****************************************************************************
80 *****************************************************************************/
83 struct i2c_client
*client
;
87 static const struct i2c_device_id tps65132_id
[] = {
92 //#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36))
93 //static struct i2c_client_address_data addr_data = { .forces = forces,};
95 static struct i2c_driver tps65132_iic_driver
= {
96 .id_table
= tps65132_id
,
97 .probe
= tps65132_probe
,
98 .remove
= tps65132_remove
,
99 //.detect = mt6605_detect,
101 .owner
= THIS_MODULE
,
106 /*****************************************************************************
108 *****************************************************************************/
112 /*****************************************************************************
114 *****************************************************************************/
115 static int tps65132_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
117 printk( "tps65132_iic_probe\n");
118 printk("TPS: info==>name=%s addr=0x%x\n",client
->name
,client
->addr
);
119 tps65132_i2c_client
= client
;
124 static int tps65132_remove(struct i2c_client
*client
)
126 printk( "tps65132_remove\n");
127 tps65132_i2c_client
= NULL
;
128 i2c_unregister_device(client
);
133 static int tps65132_write_bytes(unsigned char addr
, unsigned char value
)
136 struct i2c_client
*client
= tps65132_i2c_client
;
137 char write_data
[2]={0};
139 write_data
[1] = value
;
140 ret
=i2c_master_send(client
, write_data
, 2);
142 printk("tps65132 write data fail !!\n");
149 * module load/unload record keeping
152 static int __init
tps65132_iic_init(void)
155 printk( "tps65132_iic_init\n");
156 i2c_register_board_info(TPS_I2C_BUSNUM
, &tps65132_board_info
, 1);
157 printk( "tps65132_iic_init2\n");
158 i2c_add_driver(&tps65132_iic_driver
);
159 printk( "tps65132_iic_init success\n");
163 static void __exit
tps65132_iic_exit(void)
165 printk( "tps65132_iic_exit\n");
166 i2c_del_driver(&tps65132_iic_driver
);
170 module_init(tps65132_iic_init
);
171 module_exit(tps65132_iic_exit
);
173 MODULE_AUTHOR("Xiaokuan Shi");
174 MODULE_DESCRIPTION("MTK TPS65132 I2C Driver");
175 MODULE_LICENSE("GPL");
179 //static unsigned char lcd_id_pins_value = 0xFF;
180 static const unsigned char LCD_MODULE_ID
= 0x01; // haobing modified 2013.07.11
181 // ---------------------------------------------------------------------------
183 // ---------------------------------------------------------------------------
184 #define LCM_DSI_CMD_MODE 0
185 #define FRAME_WIDTH (1080)
186 #define FRAME_HEIGHT (1920)
187 #define GPIO_65132_EN GPIO_LCD_BIAS_ENP_PIN
190 #define REGFLAG_DELAY 0xFC
191 #define REGFLAG_END_OF_TABLE 0xFD // END OF REGISTERS MARKER
201 //static unsigned int lcm_esd_test = FALSE; ///only for ESD test
202 // ---------------------------------------------------------------------------
204 // ---------------------------------------------------------------------------
207 struct LCM_setting_table
{
210 unsigned char para_list
[64];
212 //update initial param for IC nt35520 0.01
213 static struct LCM_setting_table lcm_suspend_setting
[] = {
216 {REGFLAG_DELAY
, 120, {}}
219 //update initial param for IC nt35520 0.01
220 static struct LCM_setting_table lcm_initialization_setting
[] = {
221 {0xFF,1,{0x10}}, // Return To CMD1
222 {REGFLAG_DELAY
, 2, {}},
223 #if (LCM_DSI_CMD_MODE)
228 {0x3B,5,{0x03,0x0A,0x0A,0x0A,0x0A}},
232 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
235 {REGFLAG_DELAY
, 150, {}},
236 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
237 {0xFF,1,{0x24}}, // CMD2 Page 4 Entrance
238 {REGFLAG_DELAY
, 2, {}},
347 {0xFF,1,{0x20}}, // Page 0,1,{ power-related setting
348 {REGFLAG_DELAY
, 2, {}},
381 {0xFF,1,{0x20}}, // Page 0,1,{ power-related setting
382 {REGFLAG_DELAY
, 2, {}},
519 {0xFF,1,{0x21}}, // Page 0,1,{ power-related setting
520 {REGFLAG_DELAY
, 2, {}},
753 {0xFF,1,{0x21}}, // Page ,1,{ Gamma Default Update
754 {REGFLAG_DELAY
, 2, {}},
764 {0xFF,1,{0x23}}, // CMD2 Page 3 Entrance
765 {REGFLAG_DELAY
, 2, {}},
767 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
769 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
770 {0xFF,1,{0x10}}, // Return To CMD1
772 {REGFLAG_DELAY
, 2, {}},
775 //{0x51,1,{0xFF}}, // write display brightness
779 static struct LCM_setting_table lcm_set_window
[] = {
780 {0x2A, 4, {0x00, 0x00, (FRAME_WIDTH
>>8), (FRAME_WIDTH
&0xFF)}},
781 {0x2B, 4, {0x00, 0x00, (FRAME_HEIGHT
>>8), (FRAME_HEIGHT
&0xFF)}},
782 {REGFLAG_END_OF_TABLE
, 0x00, {}}
786 static struct LCM_setting_table lcm_sleep_out_setting
[] = {
789 {REGFLAG_DELAY
, 120, {}},
793 {REGFLAG_DELAY
, 20, {}},
794 {REGFLAG_END_OF_TABLE
, 0x00, {}}
798 static struct LCM_setting_table lcm_deep_sleep_mode_in_setting
[] = {
799 // Display off sequence
801 {REGFLAG_DELAY
, 20, {}},
805 {REGFLAG_DELAY
, 120, {}},
806 {REGFLAG_END_OF_TABLE
, 0x00, {}}
809 static void push_table(struct LCM_setting_table
*table
, unsigned int count
, unsigned char force_update
)
813 for(i
= 0; i
< count
; i
++)
821 if(table
[i
].count
<= 10)
822 MDELAY(table
[i
].count
);
824 MDELAY(table
[i
].count
);
827 case REGFLAG_END_OF_TABLE
:
831 dsi_set_cmdq_V2(cmd
, table
[i
].count
, table
[i
].para_list
, force_update
);
836 // ---------------------------------------------------------------------------
837 // LCM Driver Implementations
838 // ---------------------------------------------------------------------------
840 static void lcm_set_util_funcs(const LCM_UTIL_FUNCS
*util
)
842 memcpy(&lcm_util
, util
, sizeof(LCM_UTIL_FUNCS
));
846 static void lcm_get_params(LCM_PARAMS
*params
)
848 memset(params
, 0, sizeof(LCM_PARAMS
));
850 params
->type
= LCM_TYPE_DSI
;
852 params
->width
= FRAME_WIDTH
;
853 params
->height
= FRAME_HEIGHT
;
855 #if (LCM_DSI_CMD_MODE)
856 params
->dsi
.mode
= CMD_MODE
;
858 params
->dsi
.mode
= SYNC_PULSE_VDO_MODE
;
862 /* Command mode setting */
863 params
->dsi
.LANE_NUM
= LCM_FOUR_LANE
;
864 //The following defined the fomat for data coming from LCD engine.
865 params
->dsi
.data_format
.color_order
= LCM_COLOR_ORDER_RGB
;
866 params
->dsi
.data_format
.trans_seq
= LCM_DSI_TRANS_SEQ_MSB_FIRST
;
867 params
->dsi
.data_format
.padding
= LCM_DSI_PADDING_ON_LSB
;
868 params
->dsi
.data_format
.format
= LCM_DSI_FORMAT_RGB888
;
870 // Highly depends on LCD driver capability.
871 params
->dsi
.packet_size
=256;
874 params
->dsi
.PS
=LCM_PACKED_PS_24BIT_RGB888
;
876 params
->dsi
.vertical_sync_active
= 2;
877 params
->dsi
.vertical_backporch
= 8;
878 params
->dsi
.vertical_frontporch
= 10;
879 params
->dsi
.vertical_active_line
= FRAME_HEIGHT
;
881 params
->dsi
.horizontal_sync_active
= 10;
882 params
->dsi
.horizontal_backporch
= 20;
883 params
->dsi
.horizontal_frontporch
= 40;
884 params
->dsi
.horizontal_active_pixel
= FRAME_WIDTH
;
885 //params->dsi.ssc_disable = 1;
886 #if (LCM_DSI_CMD_MODE)
887 params
->dsi
.PLL_CLOCK
= 500; //this value must be in MTK suggested table
889 params
->dsi
.PLL_CLOCK
= 450; //this value must be in MTK suggested table
896 #define TPS65132_SLAVE_ADDR_WRITE 0x7C
897 static struct mt_i2c_t TPS65132_i2c
;
899 int TPS65132_write_byte(kal_uint8 addr
, kal_uint8 value
)
901 kal_uint32 ret_code
= I2C_OK
;
902 kal_uint8 write_data
[2];
906 write_data
[1] = value
;
908 TPS65132_i2c
.id
= I2C_I2C_LCD_BIAS_CHANNEL
;//I2C2;
909 /* Since i2c will left shift 1 bit, we need to set FAN5405 I2C address to >>1 */
910 TPS65132_i2c
.addr
= (TPS65132_SLAVE_ADDR_WRITE
>> 1);
911 TPS65132_i2c
.mode
= ST_MODE
;
912 TPS65132_i2c
.speed
= 100;
915 ret_code
= i2c_write(&TPS65132_i2c
, write_data
, len
);
916 //printf("%s: i2c_write: ret_code: %d\n", __func__, ret_code);
923 // extern int mt8193_i2c_write(u16 addr, u32 data);
924 // extern int mt8193_i2c_read(u16 addr, u32 *data);
926 // #define TPS65132_write_byte(add, data) mt8193_i2c_write(add, data)
927 //#define TPS65132_read_byte(add) mt8193_i2c_read(add)
933 static void lcm_init_power(void)
937 mt6331_upmu_set_rg_vgp1_en(1);
939 hwPowerOn(MT6331_POWER_LDO_VGP1
, VOL_DEFAULT
, "LCM_DRV");
943 static void lcm_suspend_power(void)
946 mt6331_upmu_set_rg_vgp1_en(0);
948 hwPowerDown(MT6331_POWER_LDO_VGP1
, "LCM_DRV");
953 static void lcm_resume_power(void)
956 mt6331_upmu_set_rg_vgp1_en(1);
958 hwPowerOn(MT6331_POWER_LDO_VGP1
, VOL_DEFAULT
, "LCM_DRV");
963 static void lcm_init(void)
965 unsigned char cmd
= 0x0;
966 unsigned char data
= 0xFF;
971 mt_set_gpio_mode(GPIO_65132_EN
, GPIO_MODE_00
);
972 mt_set_gpio_dir(GPIO_65132_EN
, GPIO_DIR_OUT
);
973 mt_set_gpio_out(GPIO_65132_EN
, GPIO_OUT_ONE
);
976 ret
=TPS65132_write_byte(cmd
,data
);
978 dprintf(0, "[LK]nt35595----tps6132----cmd=%0x--i2c write error----\n",cmd
);
980 dprintf(0, "[LK]nt35595----tps6132----cmd=%0x--i2c write success----\n",cmd
);
982 ret
=tps65132_write_bytes(cmd
,data
);
984 printk("[KERNEL]nt35595----tps6132---cmd=%0x-- i2c write error-----\n",cmd
);
986 printk("[KERNEL]nt35595----tps6132---cmd=%0x-- i2c write success-----\n",cmd
);
993 ret
=TPS65132_write_byte(cmd
,data
);
995 dprintf(0, "[LK]nt35595----tps6132----cmd=%0x--i2c write error----\n",cmd
);
997 dprintf(0, "[LK]nt35595----tps6132----cmd=%0x--i2c write success----\n",cmd
);
999 ret
=tps65132_write_bytes(cmd
,data
);
1001 printk("[KERNEL]nt35595----tps6132---cmd=%0x-- i2c write error-----\n",cmd
);
1003 printk("[KERNEL]nt35595----tps6132---cmd=%0x-- i2c write success-----\n",cmd
);
1015 // when phone initial , config output high, enable backlight drv chip
1016 push_table(lcm_initialization_setting
, sizeof(lcm_initialization_setting
) / sizeof(struct LCM_setting_table
), 1);
1019 static void lcm_suspend(void)
1021 push_table(lcm_suspend_setting
, sizeof(lcm_suspend_setting
) / sizeof(struct LCM_setting_table
), 1);
1023 mt_set_gpio_mode(GPIO_65132_EN
, GPIO_MODE_00
);
1024 mt_set_gpio_dir(GPIO_65132_EN
, GPIO_DIR_OUT
);
1025 mt_set_gpio_out(GPIO_65132_EN
, GPIO_OUT_ZERO
);
1029 static void lcm_resume(void)
1043 static void lcm_update(unsigned int x
, unsigned int y
, unsigned int width
, unsigned int height
)
1045 unsigned int x0
= x
;
1046 unsigned int y0
= y
;
1047 unsigned int x1
= x0
+ width
- 1;
1048 unsigned int y1
= y0
+ height
- 1;
1050 unsigned char x0_MSB
= ((x0
>>8)&0xFF);
1051 unsigned char x0_LSB
= (x0
&0xFF);
1052 unsigned char x1_MSB
= ((x1
>>8)&0xFF);
1053 unsigned char x1_LSB
= (x1
&0xFF);
1054 unsigned char y0_MSB
= ((y0
>>8)&0xFF);
1055 unsigned char y0_LSB
= (y0
&0xFF);
1056 unsigned char y1_MSB
= ((y1
>>8)&0xFF);
1057 unsigned char y1_LSB
= (y1
&0xFF);
1059 unsigned int data_array
[16];
1061 data_array
[0]= 0x00053902;
1062 data_array
[1]= (x1_MSB
<<24)|(x0_LSB
<<16)|(x0_MSB
<<8)|0x2a;
1063 data_array
[2]= (x1_LSB
);
1064 dsi_set_cmdq(data_array
, 3, 1);
1066 data_array
[0]= 0x00053902;
1067 data_array
[1]= (y1_MSB
<<24)|(y0_LSB
<<16)|(y0_MSB
<<8)|0x2b;
1068 data_array
[2]= (y1_LSB
);
1069 dsi_set_cmdq(data_array
, 3, 1);
1071 data_array
[0]= 0x002c3909;
1072 dsi_set_cmdq(data_array
, 1, 0);
1075 static unsigned int lcm_compare_id(void)
1080 LCM_DRIVER nt35595_fhd_dsi_vdo_truly_lcm_drv
=
1082 .name
= "nt35595_fhd_dsi_vdo_truly_lcm_drv",
1083 .set_util_funcs
= lcm_set_util_funcs
,
1084 .get_params
= lcm_get_params
,
1085 .init
= lcm_init
,/*tianma init fun.*/
1086 .suspend
= lcm_suspend
,
1087 .resume
= lcm_resume
,
1088 .compare_id
= lcm_compare_id
,
1089 .init_power
= lcm_init_power
,
1090 .resume_power
= lcm_resume_power
,
1091 .suspend_power
= lcm_suspend_power
,
1092 #if (LCM_DSI_CMD_MODE)
1093 .update
= lcm_update
,
1097 /* END PN:DTS2013053103858 , Added by d00238048, 2013.05.31*/