一娇钱、綜述
目前Android 8.1 項(xiàng)目會(huì)過一個(gè)新GSI測(cè)試項(xiàng)柳畔,
需要刷入谷歌提供的system.img文件,其中默認(rèn)的LCD旋轉(zhuǎn)角度為0度钾麸,
若是在平板項(xiàng)目中更振,正式軟件的LCD旋轉(zhuǎn)角度可能為270度。
因此會(huì)造成TP和Gsensor方向功能異常問題饭尝。
(ps:后來谷歌爸爸終于把關(guān)于平板項(xiàng)目的旋轉(zhuǎn)角度調(diào)回來了肯腕,也就是白改了)
二、實(shí)現(xiàn)思路
當(dāng)前解決思路如下:
刷入谷歌提供的system.img軟件時(shí)钥平,開機(jī)系統(tǒng)狀態(tài):androidboot.verifiedbootstate=orange
軟件正式開機(jī)系統(tǒng)狀態(tài):
androidboot.verifiedbootstate=green
此狀態(tài)會(huì)在lk->kernel的過程中实撒,通過cmdline的參數(shù)傳給kernel層,
從log中搜索cmdline涉瘾,如下
因此通過在kernel層判斷此狀態(tài)來改變TP和Gsensor方向
三知态、解決方案(代碼實(shí)現(xiàn))
1.TP修改
kernel-3.18/drivers/input/touchscreen/mediatek/gslX68X_9709
#include <linux/string.h>//add by zcf 2018.04.24
static bool used_defautl_tp_rotation = false;//add by zcf 2018.04.24
static int __init tpd_driver_init(void) {
char * sub = "androidboot.verifiedbootstate=orange";//add by zcf 2018.04.24
print_info("Sileadinc gslX680 touch panel driver init\n");
//add by zcf 2018.04.24
if(strstr(saved_command_line,sub)){
//if boot state == orange ,change tp rotation to 0
used_defautl_tp_rotation = true;
}
//end add by zcf 2018.04.24
#ifdef ADD_I2C_DEVICE_ANDROID_4_0
//i2c_register_board_info(1, &gslX680_i2c_tpd, 1);
#endif
tpd_get_dts_info();
if(tpd_driver_add(&tpd_device_driver) < 0)
print_err("add gslX680 driver failed\n");
return 0;
}
void tpd_down( int id, int x, int y, int p)
{
print_info("+++tpd_down++++ x =%d y=%d ++++++++++++++++ \n", x, y);
if(!used_defautl_tp_rotation){ //add by zcf 2018.04.24
#if defined(TPD_ROTATE_90)
tpd_rotate_90(&x,&y);
#elif defined(TPD_ROTATE_270)||defined(TPD_ROTATE_270_2)
tpd_rotate_270(&x,&y);
#endif
} //add by zcf 2018.04.24
//省略部分代碼
}
不同的項(xiàng)目TP驅(qū)動(dòng)不同個(gè),但修改思路是相同的睡汹,在tpd_driver_init()函數(shù)里肴甸,
char * sub = "androidboot.verifiedbootstate=orange";
if(strstr(saved_command_line,sub)){
//if boot state == orange ,change tp rotation to 0
used_defautl_tp_rotation = true;
}
解析saved_command_line是否包含"androidboot.verifiedbootstate=orange"
如果是的話寂殉,我們就需要改變TP的方向囚巴,使用默認(rèn)旋轉(zhuǎn)度為0的方向。
在tpd_down()友扰,禁止旋轉(zhuǎn)90度或者270度彤叉,也就是使用默認(rèn)0度方向。
同樣道理
kernel-3.18/drivers/input/touchscreen/mediatek
static int tpd_probe(struct platform_device *pdev)
{
int touch_type = 1; /* 0:R-touch, 1: Cap-touch */
int i = 0;
char * sub = "androidboot.verifiedbootstate=orange";//add by zcf 2018.04.24
//省略....代碼
//add by zcf 2018.04.24
if(strstr(saved_command_line,sub)){
//if boot state == orange ,change tp rotation to 0
goto tp_rotate_to_zero;
}
// end add by zcf 2018.04.24
#ifdef CONFIG_MTK_LCM_PHYSICAL_ROTATION
if (0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "90", 2)
|| 0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "270", 3)) {
#ifdef CONFIG_MTK_FB
/*Fix build errors,as some projects cannot support these apis while bring up*/
TPD_RES_Y = DISP_GetScreenWidth();
TPD_RES_X = DISP_GetScreenHeight();
#endif
} else
#endif
{
tp_rotate_to_zero://add by zcf 2018.04.24
#ifdef CONFIG_CUSTOM_LCM_X
#ifndef CONFIG_MTK_FPGA
#ifdef CONFIG_MTK_FB
如果f boot state == orange 村怪,就調(diào)過CONFIG_MTK_LCM_PHYSICAL_ROTATION宏所定義的代碼秽浇,即不旋轉(zhuǎn)
直接goto -> tp_rotate_to_zero:后面的代碼
2.Gsensor方向的修改
kernel-3.18/arch/arm/boot/dts
&i2c2 {
gsensor@18 {
i2c_num = <2>;
i2c_addr = <0x18 0 0 0>;
direction = <7>;
direction_for_gsi = <6>;/*add by zcf 2018.04.24*/
power_id = <0xffff>;
power_vol = <0>;
firlen = <0>;
is_batch_supported = <0>;
};
}
在dts里面添加direction_for_gsi ,如果刷了gsi的system.img甚负,就使用這個(gè)方向柬焕,否則使用默認(rèn)的direction
kernel-3.18/drivers/misc/mediatek/sensors-1.0/hwmon/sensor_dts
int get_accel_dts_func(struct device_node *node, struct acc_hw *hw)
{
char * sub = "androidboot.verifiedbootstate=orange";//add by zcf 2018.04.24
int i, ret;
u32 i2c_num[] = {0};
u32 i2c_addr[G_CUST_I2C_ADDR_NUM] = {0};
u32 direction[] = {0};
u32 direction_for_gsi[] = {0};// add by zcf 2018.04.24
u32 power_id[] = {0};
u32 power_vol[] = {0};
//省略...代碼
ret = of_property_read_u32_array(node, "direction", direction,
ARRAY_SIZE(direction));
if (ret == 0)
hw->direction = direction[0];
//add by zcf 2018.04.24
if(strstr(saved_command_line,sub)){
//if boot state == orange ,used the direction_for_gsi for gsi test
if(of_find_property(node,"direction_for_gsi",NULL)) {
ret = of_property_read_u32_array(node, "direction_for_gsi",
direction_for_gsi, ARRAY_SIZE(direction_for_gsi));
hw->direction = direction_for_gsi[0];
}
}
//end add by zcf 2018.04.24
}
如果saved_command_line包含androidboot.verifiedbootstate=orange;
判斷direction_for_gsi節(jié)點(diǎn)是否為空
不為空就獲取direction_for_gsi的值賦給hw->direction
hw->direction = direction_for_gsi[0];
saved_command_line在內(nèi)核中的定義和使用
saved_command_line是全局變量梭域,該變量通過EXPOER_SYMBOL(saved_command_line)宏斑举,使得全局可用。
這個(gè)變量定義在main.c
在sparc_ksyms_32.c或者sparc_ksyms_64.c里export為全局變量
我們可以看一下內(nèi)核中試如何使用的病涨,模仿即可
直接調(diào)用strstr(saved_command_line, "lcm=")富玷,
不需要定義saved_command_line。
到此既穆,就寫完了赎懦,收工練琴!
Stay hungry幻工,Stay foolish!
荊軻刺秦王