From 2bb9a8534a2626e7a1364a68b35e64059a8e53f2 Mon Sep 17 00:00:00 2001 From: lyz Date: Fri, 21 Nov 2014 16:18:49 +0800 Subject: [PATCH] usb: dwc_otg: fix problems of commit 058d627 1. schedule_delayed_work(&pcd->check_id_work,msecs_to_jiffies(HZ)) should be schedule_delayed_work(&pcd->check_id_work,HZ) 2.fix coding-style to pass checkpatch.pl 3.set otg controler working on foece host/device mode to avoid mode_missmatch_interrupts --- drivers/usb/dwc_otg_310/dwc_otg_cil.c | 22 +++++++++++++++++++++ drivers/usb/dwc_otg_310/dwc_otg_cil.h | 2 ++ drivers/usb/dwc_otg_310/dwc_otg_driver.c | 22 --------------------- drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c | 16 +++++++-------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/drivers/usb/dwc_otg_310/dwc_otg_cil.c b/drivers/usb/dwc_otg_310/dwc_otg_cil.c index 653b2b600f91..89fdaa9e0a82 100755 --- a/drivers/usb/dwc_otg_310/dwc_otg_cil.c +++ b/drivers/usb/dwc_otg_310/dwc_otg_cil.c @@ -7736,3 +7736,25 @@ int dwc_otg_check_haps_status(dwc_otg_core_if_t *core_if) } } + +void dwc_otg_set_force_mode(dwc_otg_core_if_t *core_if, int mode) +{ + gusbcfg_data_t usbcfg = {.d32 = 0 }; + + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg); + switch (mode) { + case USB_MODE_FORCE_HOST: + usbcfg.b.force_host_mode = 1; + usbcfg.b.force_dev_mode = 0; + break; + case USB_MODE_FORCE_DEVICE: + usbcfg.b.force_host_mode = 0; + usbcfg.b.force_dev_mode = 1; + break; + case USB_MODE_NORMAL: + usbcfg.b.force_host_mode = 0; + usbcfg.b.force_dev_mode = 0; + break; + } + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32); +} diff --git a/drivers/usb/dwc_otg_310/dwc_otg_cil.h b/drivers/usb/dwc_otg_310/dwc_otg_cil.h index 10f8cf07a120..f0170d2a5230 100755 --- a/drivers/usb/dwc_otg_310/dwc_otg_cil.h +++ b/drivers/usb/dwc_otg_310/dwc_otg_cil.h @@ -1501,4 +1501,6 @@ static inline void cil_pcd_resume(dwc_otg_core_if_t *core_if) } } +void dwc_otg_set_force_mode(dwc_otg_core_if_t *core_if, int mode); + #endif diff --git a/drivers/usb/dwc_otg_310/dwc_otg_driver.c b/drivers/usb/dwc_otg_310/dwc_otg_driver.c index 1279c0d623d8..16a4464dc51d 100755 --- a/drivers/usb/dwc_otg_310/dwc_otg_driver.c +++ b/drivers/usb/dwc_otg_310/dwc_otg_driver.c @@ -447,28 +447,6 @@ void dwc_otg_force_device(dwc_otg_core_if_t *core_if) local_irq_restore(flags); } -static void dwc_otg_set_force_mode(dwc_otg_core_if_t *core_if, int mode) -{ - gusbcfg_data_t usbcfg = {.d32 = 0 }; - printk("!!!dwc_otg_set_force_mode\n"); - usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg); - switch (mode) { - case USB_MODE_FORCE_HOST: - usbcfg.b.force_host_mode = 1; - usbcfg.b.force_dev_mode = 0; - break; - case USB_MODE_FORCE_DEVICE: - usbcfg.b.force_host_mode = 0; - usbcfg.b.force_dev_mode = 1; - break; - case USB_MODE_NORMAL: - usbcfg.b.force_host_mode = 0; - usbcfg.b.force_dev_mode = 0; - break; - } - DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32); -} - static ssize_t force_usb_mode_show(struct device_driver *drv, char *buf) { dwc_otg_device_t *otg_dev = g_otgdev; diff --git a/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c b/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c index 5d99badf5d5d..b5c73a0ffdf2 100755 --- a/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c +++ b/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c @@ -1502,7 +1502,7 @@ static void dwc_phy_reconnect(struct work_struct *work) } } -void id_status_change(dwc_otg_core_if_t *p, bool current_id) +static void id_status_change(dwc_otg_core_if_t *p, bool current_id) { dwc_otg_core_if_t *core_if = p; uint32_t count = 0; @@ -1513,7 +1513,7 @@ void id_status_change(dwc_otg_core_if_t *p, bool current_id) DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32); DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts); - if( core_if->usb_mode != USB_MODE_NORMAL ) + if (core_if->usb_mode != USB_MODE_NORMAL) return; /* B-Device connector (Device Mode) */ @@ -1535,6 +1535,7 @@ void id_status_change(dwc_otg_core_if_t *p, bool current_id) DWC_PRINTF("Connection id status change timed out"); return; } + dwc_otg_set_force_mode(core_if, USB_MODE_FORCE_DEVICE); core_if->op_state = B_PERIPHERAL; cil_hcd_stop(core_if); /* pcd->phy_suspend = 1; */ @@ -1558,6 +1559,7 @@ void id_status_change(dwc_otg_core_if_t *p, bool current_id) } core_if->op_state = A_HOST; + dwc_otg_set_force_mode(core_if, USB_MODE_FORCE_HOST); cancel_delayed_work(&pcd->check_vbus_work); @@ -1580,8 +1582,8 @@ static void check_id(struct work_struct *work) static int last_id = -1; int id = pldata->get_status(USB_STATUS_ID); - if((last_id != id)) { - printk("[otg id chg] last id %d current id %d \n", last_id, id); + if (last_id != id) { + pr_info("[otg id chg] last id %d current id %d\n", last_id, id); if (!id) { /* Force Host */ if (pldata->phy_status == USB_PHY_SUSPEND) { pldata->clock_enable(pldata, 1); @@ -1594,7 +1596,6 @@ static void check_id(struct work_struct *work) } last_id = id; schedule_delayed_work(&_pcd->check_id_work, (HZ)); - return; } static void dwc_otg_pcd_check_vbus_work(struct work_struct *work) @@ -1743,12 +1744,11 @@ static void dwc_otg_pcd_work_init(dwc_otg_pcd_t *pcd, /* usb phy bypass to uart mode */ pldata->dwc_otg_uart_mode(pldata, PHY_UART_MODE); } - } - else if (pldata->dwc_otg_uart_mode != NULL) { + } else if (pldata->dwc_otg_uart_mode != NULL) { /* host mode,enter usb phy mode */ pldata->dwc_otg_uart_mode(pldata, PHY_USB_MODE); } - schedule_delayed_work(&pcd->check_id_work, msecs_to_jiffies(HZ)); + schedule_delayed_work(&pcd->check_id_work, HZ); } #endif /* DWC_HOST_ONLY */ -- 2.34.1