之前一直没有记录工作过程的想法,现在开始慢慢想去记录和输出一些东西,废话少说,直奔主题吧。
下面是我在MTK6580 Android P PSC5415A 快充带OTG调试遇到的问题和解决方法。
一,6580 android P版本跑的是4.9的内核,先在对应项目的config里面打开otg相关的两个宏
kernel-4.9-lc\arch\arm\configs\k80_bsp_debug_defconfig 这是debug,如果user,对应改一下user的config
CONFIG_USB_MTK_OTG=y
CONFIG_USB_MTK_HDRC_HCD=y
二,usb id中断脚的配置,在otg设备没有插入时id脚为高电平,插入后为低电平。对应中断是否注册成功
可以在adb shell cat proc/interrupts 查看
kernel-4.9-lc\arch\arm\boot\dts\k80_bsp.dts
&pio {usbiddig_pins_default: usbiddigint7default {};usbiddig_pins_as_int: usbiddigint@7 {pins_cmd_dat {pinmux = <PINMUX_GPIO7__FUNC_EINT7>;slew-rate = <0>;bias-pull-up = <00>;};};
};&usbiddig {pinctrl-names = "usb_default", "usbiddig_pin_init";//, "drvvbus_init", "drvvbus_low", "drvvbus_high";pinctrl-0 = <&usbiddig_pins_default>;pinctrl-1 = <&usbiddig_pins_as_int>;status = "okay";
};
kernel-4.9-lc\drivers\misc\mediatek\dws\mt6580\k80_bsp.dws,注意dws在lk,pl,factory下也要做相应的改动
通过request_irq注册mt_usb_ext_iddig_int中断,低电平触发
kernel-4.9-lc\drivers\misc\mediatek\usb20\mt6580\usb20_host.c
struct device *dev = &pdev->dev;struct device_node *node = dev->of_node;//zx PSC5005 add startpinctrl = devm_pinctrl_get(&pdev->dev);pinctrl_iddig = pinctrl_lookup_state(pinctrl, "usbiddig_pin_init");if (IS_ERR(pinctrl_iddig)) {printk("Cannot find usb pinctrl otg_iddig_pin_init\n");return -ENODEV;}pinctrl_select_state(pinctrl, pinctrl_iddig);//zx PSC5005 add endiddig_eint_num = irq_of_parse_and_map(node, 0);DBG(0, "iddig_eint_num<%d>\n", iddig_eint_num);if (iddig_eint_num < 0)return -ENODEV;ret = request_irq(iddig_eint_num, mt_usb_ext_iddig_int,IRQF_TRIGGER_LOW, "USB_IDDIG", NULL);
注意看一cust.dtsi,有没有生成usbiddig中断,swithing_charger_mtk有没有注册到i2c1下面,psc5415 会根据 "mediatek,swithing_charger"来加载对应的驱动,这一点非常重要。
out\target\product\k80_bsp\obj\KERNEL_OBJ\arch\arm\boot\dts\k80_bsp\cust.dtsi
&i2c1 {#address-cells = <1>;#size-cells = <0>;cap_touch_mtk:cap_touch@5d {compatible = "mediatek,cap_touch";reg = <0x5d>;status = "okay";};ext_buck_mtk:ext_buck@60 {compatible = "mediatek,ext_buck";reg = <0x60>;status = "okay";};swithing_charger_mtk:swithing_charger@6a {compatible = "mediatek,swithing_charger";reg = <0x6a>;status = "okay";};
};
&usbiddig {interrupt-parent = <&eintc>;interrupts = <7 IRQ_TYPE_LEVEL_LOW>;debounce = <7 0>;status = "okay";
};
三、中断ok之后,插入otg u盘,发现vbus没有5v输出,打串口log发现如下问题:
[MUSB]vbus_init 171: **** before Init Drive VBUS KS!!!
[ 643.312533] <0>.(0)[3211:kworker/u8:9][MUSB]vbus_init 176: Cannot find usb pinctrl drvvbus
因为PSX5415 vbus是由psc5415 控制寄存器输出的,不需要再通过ldo输出vbus,所以在dts里面没有 “drvvbus_init”,“drvvbus_low”,"drvvbus_high"控制,导致VBUS输出异常,修改方法在vbus_init里面判断如果有定义CONFIG_MTK_PSC5005_SUPPORT,直接return 0,这样vbus5v就能够正常输出
int vbus_init(void)
{
#ifdef CONFIG_MTK_PSC5005_SUPPORT //zx PSC5005 modifyreturn 0;
#else#if !(defined(SWITCH_CHARGER) || defined(FPGA_PLATFORM))int ret = 0;DBG(0, "**** before Init Drive VBUS KS!!!!!\n");pinctrl_drvvbus = pinctrl_lookup_state(pinctrl, "drvvbus_init");if (IS_ERR(pinctrl_drvvbus)) {ret = PTR_ERR(pinctrl_drvvbus);DBG(0, "Cannot find usb pinctrl drvvbus\n");return -ENODEV;}pinctrl_drvvbus_low = pinctrl_lookup_state(pinctrl, "drvvbus_low");if (IS_ERR(pinctrl_drvvbus_low)) {ret = PTR_ERR(pinctrl_drvvbus_low);DBG(0, "zx cannot find usb pinctrl drvvbus_low\n");return -ENODEV;}pinctrl_drvvbus_high = pinctrl_lookup_state(pinctrl, "drvvbus_high");if (IS_ERR(pinctrl_drvvbus_high)) {ret = PTR_ERR(pinctrl_drvvbus_high);DBG(0, "Cannot find usb pinctrl drvvbus_high\n");return -ENODEV;}pinctrl_select_state(pinctrl, pinctrl_drvvbus);DBG(0, "**** end Init Drive VBUS KS!!!!!\n");return 0;#endif
#endif
}
四、在开完机,还遇到一个问题,插入充电器或者usb,直接关机进入充电模式
打串口log发现
[ 600.072238] <1>.(1)[188:mtk charger_hv_][MUSB]usb20_check_vbus_on 208: vbus_on<0>
[ 600.073537] <1>.(1)[188:mtk charger_hv_][BATTERY] Battery is not exist, power off FAN5405 and system (3)
[ 600.076327] <1>.(1)[188:mtk charger_hv_]charging_set_power_off
[ 600.077097] <1>.(1)[188:mtk charger_hv_]mtk_rtc_common: mt_power_off
[ 600.077940] <1>-(1)[188:mtk charger_hv_]mtk_rtc_hal: hal_rtc_bbpu_pwdn (RTC_CON=0x4a6)
[ 600.079127] <1>-(1)[188:mtk charger_hv_]mtk_rtc_hal: hal_rtc_bbpu_pwdn (RTC_CON=0x4a6)
然后找到对应的代码
void check_battery_exist(void)
{
//#if defined(CONFIG_DIS_CHECK_BATTERY)
#if 1// zx modify by charge otg, customer not supply bat just for debugbattery_log(BAT_LOG_CRTI, "[BATTERY] Disable check battery exist.\n");
#elseunsigned int baton_count = 0;unsigned int charging_enable = KAL_FALSE;unsigned int battery_status;unsigned int i;for (i = 0; i < 3; i++) {battery_charging_control(CHARGING_CMD_GET_BATTERY_STATUS, &battery_status);baton_count += battery_status;}if (baton_count >= 3) {if ((g_platform_boot_mode == META_BOOT) || (g_platform_boot_mode == ADVMETA_BOOT)|| (g_platform_boot_mode == ATE_FACTORY_BOOT)) {battery_log(BAT_LOG_FULL,"[BATTERY] boot mode = %d, bypass battery check\n",g_platform_boot_mode);} else {battery_log(BAT_LOG_CRTI,"[BATTERY] Battery is not exist, power off FAN5405 and system (%d)\n",baton_count);battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable);#ifdef CONFIG_MTK_POWER_PATH_MANAGEMENT_SUPPORTbattery_charging_control(CHARGING_CMD_SET_PLATFORM_RESET, NULL);#elsebattery_charging_control(CHARGING_CMD_SET_POWER_OFF, NULL);#endif}}
#endif
}
由于主板调试阶段,客户没有提供电池过来,所以用电源供电,在check_battery_exist检测到电池没有存在,所以调用mt_power_off函数关机了。
最后晒两张靓图,otg调试OK