📄 dwc_otg_cil_intr.c
字号:
/* ========================================================================== * * Synopsys HS OTG Linux Software Driver and documentation (hereinafter, * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless * otherwise expressly agreed to in writing between Synopsys and you. * * The Software IS NOT an item of Licensed Software or Licensed Product under * any End User Software License Agreement or Agreement for Licensed Product * with Synopsys or any supplement thereto. You are permitted to use and * redistribute this Software in source and binary forms, with or without * modification, provided that redistributions of source code must retain this * notice. You may not view, use, disclose, copy or distribute this file or * any information contained herein except pursuant to this license grant from * Synopsys. If you do not agree with this notice, including the disclaimer * below, then you are not authorized to use the Software. * * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * ========================================================================== *//** @file * * The Core Interface Layer provides basic services for accessing and * managing the DWC_otg hardware. These services are used by both the * Host Controller Driver and the Peripheral Controller Driver. * * This file contains the Common Interrupt handlers. */#include <linux/kernel.h>#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/init.h>#include <linux/device.h>#include <linux/errno.h>#include <linux/types.h>#include <linux/stat.h> /* permission constants */#include <linux/version.h>#include <linux/platform_device.h>#include <linux/irq.h>#include "dwc_otg_plat.h"#include "dwc_otg_regs.h"#include "dwc_otg_cil.h"#ifdef DEBUGinline const char *op_state_str(dwc_otg_core_if_t * _core_if){ return (_core_if->op_state == A_HOST ? "a_host" : (_core_if->op_state == A_SUSPEND ? "a_suspend" : (_core_if->op_state == A_PERIPHERAL ? "a_peripheral" : (_core_if->op_state == B_PERIPHERAL ? "b_peripheral" : (_core_if->op_state == B_HOST ? "b_host" : "unknown")))));}#endif/** This function will log a debug message * * @param _core_if Programming view of DWC_otg controller. */int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * _core_if){ gintsts_data_t gintsts; printk("Mode Mismatch Interrupt: currently in %s mode\n", dwc_otg_mode(_core_if) ? "Host" : "Device"); /* Clear interrupt */ gintsts.d32 = 0; gintsts.b.modemismatch = 1; dwc_write_reg32(&_core_if->core_global_regs->gintsts, gintsts.d32); return 1;}/** Start the HCD. Helper function for using the HCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void hcd_start(dwc_otg_core_if_t * _core_if){ if (_core_if->hcd_cb && _core_if->hcd_cb->start) { _core_if->hcd_cb->start(_core_if->hcd_cb->p); }}/** Stop the HCD. Helper function for using the HCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void hcd_stop(dwc_otg_core_if_t * _core_if){ if (_core_if->hcd_cb && _core_if->hcd_cb->stop) { _core_if->hcd_cb->stop(_core_if->hcd_cb->p); }}/** Disconnect the HCD. Helper function for using the HCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void hcd_disconnect(dwc_otg_core_if_t * _core_if){ if (_core_if->hcd_cb && _core_if->hcd_cb->disconnect) { _core_if->hcd_cb->disconnect(_core_if->hcd_cb->p); }}/** Inform the HCD the a New Session has begun. Helper function for * using the HCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void hcd_session_start(dwc_otg_core_if_t * _core_if){ if (_core_if->hcd_cb && _core_if->hcd_cb->session_start) { _core_if->hcd_cb->session_start(_core_if->hcd_cb->p); }}/** Start the PCD. Helper function for using the PCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void pcd_start(dwc_otg_core_if_t * _core_if){ if (_core_if->pcd_cb && _core_if->pcd_cb->start) { _core_if->pcd_cb->start(_core_if->pcd_cb->p); }}/** Stop the PCD. Helper function for using the PCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void pcd_stop(dwc_otg_core_if_t * _core_if){ if (_core_if->pcd_cb && _core_if->pcd_cb->stop) { _core_if->pcd_cb->stop(_core_if->pcd_cb->p); }}/** Suspend the PCD. Helper function for using the PCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void pcd_suspend(dwc_otg_core_if_t * _core_if){ if (_core_if->pcd_cb && _core_if->pcd_cb->suspend) { _core_if->pcd_cb->suspend(_core_if->pcd_cb->p); }}/** Resume the PCD. Helper function for using the PCD callbacks. * * @param _core_if Programming view of DWC_otg controller. */static inline void pcd_resume(dwc_otg_core_if_t * _core_if){ if (_core_if->pcd_cb && _core_if->pcd_cb->resume_wakeup) { _core_if->pcd_cb->resume_wakeup(_core_if->pcd_cb->p); }}/** * This function handles the OTG Interrupts. It reads the OTG * Interrupt Register (GOTGINT) to determine what interrupt has * occurred. * * @param _core_if Programming view of DWC_otg controller. */int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * _core_if){ dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs; gotgint_data_t gotgint; gotgctl_data_t gotgctl; gintmsk_data_t gintmsk; gotgint.d32 = dwc_read_reg32(&global_regs->gotgint); gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl); DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32, op_state_str(_core_if)); //DWC_DEBUGPL(DBG_CIL, "gotgctl=%08x\n", gotgctl.d32 ); if (gotgint.b.sesenddet) { DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Session End Detected++ (%s)\n", op_state_str(_core_if)); gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl); if (_core_if->op_state == B_HOST) { pcd_start(_core_if); _core_if->op_state = B_PERIPHERAL; } else { /* If not B_HOST and Device HNP still set. HNP * Did not succeed!*/ if (gotgctl.b.devhnpen) { DWC_DEBUGPL(DBG_ANY, "Session End Detected\n"); DWC_ERROR("Device Not Connected/Responding!\n"); } /* If Session End Detected the B-Cable has * been disconnected. */ /* Reset PCD and Gadget driver to a * clean state. */ pcd_stop(_core_if); } gotgctl.d32 = 0; gotgctl.b.devhnpen = 1; dwc_modify_reg32(&global_regs->gotgctl, gotgctl.d32, 0); } if (gotgint.b.sesreqsucstschng) { DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Session Reqeust Success Status Change++\n"); gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl); if (gotgctl.b.sesreqscs) { if ((_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) && (_core_if->core_params->i2c_enable)) { _core_if->srp_success = 1; } else { pcd_resume(_core_if); /* Clear Session Request */ gotgctl.d32 = 0; gotgctl.b.sesreq = 1; dwc_modify_reg32(&global_regs->gotgctl, gotgctl.d32, 0); } } } if (gotgint.b.hstnegsucstschng) { /* Print statements during the HNP interrupt handling * can cause it to fail.*/ gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl); if (gotgctl.b.hstnegscs) { if (dwc_otg_is_host_mode(_core_if)) { _core_if->op_state = B_HOST; /* * Need to disable SOF interrupt immediately. * When switching from device to host, the PCD * interrupt handler won't handle the * interrupt if host mode is already set. The * HCD interrupt handler won't get called if * the HCD state is HALT. This means that the * interrupt does not get handled and Linux * complains loudly. */ gintmsk.d32 = 0; gintmsk.b.sofintr = 1; dwc_modify_reg32(&global_regs->gintmsk, gintmsk.d32, 0); pcd_stop(_core_if); /* * Initialize the Core for Host mode. */ hcd_start(_core_if); _core_if->op_state = B_HOST; } } else { gotgctl.d32 = 0; gotgctl.b.hnpreq = 1; gotgctl.b.devhnpen = 1; dwc_modify_reg32(&global_regs->gotgctl, gotgctl.d32, 0); DWC_DEBUGPL(DBG_ANY, "HNP Failed\n"); DWC_ERROR("Device Not Connected/Responding\n"); } } if (gotgint.b.hstnegdet) { /* The disconnect interrupt is set at the same time as * Host Negotiation Detected. During the mode * switch all interrupts are cleared so the disconnect * interrupt handler will not get executed. */ DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Host Negotiation Detected++ (%s)\n", (dwc_otg_is_host_mode(_core_if) ? "Host" : "Device")); if (dwc_otg_is_device_mode(_core_if)) { DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n", _core_if->op_state); hcd_disconnect(_core_if); pcd_start(_core_if); _core_if->op_state = A_PERIPHERAL; } else { /* * Need to disable SOF interrupt immediately. When * switching from device to host, the PCD interrupt * handler won't handle the interrupt if host mode is * already set. The HCD interrupt handler won't get * called if the HCD state is HALT. This means that * the interrupt does not get handled and Linux * complains loudly. */ gintmsk.d32 = 0; gintmsk.b.sofintr = 1; dwc_modify_reg32(&global_regs->gintmsk, gintmsk.d32, 0); pcd_stop(_core_if); hcd_start(_core_if); _core_if->op_state = A_HOST; } } if (gotgint.b.adevtoutchng) { DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "A-Device Timeout Change++\n"); } if (gotgint.b.debdone) { DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n"); } /* Clear GOTGINT */ dwc_write_reg32(&_core_if->core_global_regs->gotgint, gotgint.d32); return 1;}/** * This function handles the Connector ID Status Change Interrupt. It * reads the OTG Interrupt Register (GOTCTL) to determine whether this * is a Device to Host Mode transition or a Host Mode to Device * Transition. * * This only occurs when the cable is connected/removed from the PHY * connector. * * @param _core_if Programming view of DWC_otg controller. */int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * _core_if){ uint32_t count = 0; gintsts_data_t gintsts = {.d32 = 0 }; gintmsk_data_t gintmsk = {.d32 = 0 }; gotgctl_data_t gotgctl = {.d32 = 0 }; /* * Need to disable SOF interrupt immediately. If switching from device * to host, the PCD interrupt handler won't handle the interrupt if * host mode is already set. The HCD interrupt handler won't get * called if the HCD state is HALT. This means that the interrupt does * not get handled and Linux complains loudly. */ gintmsk.b.sofintr = 1; dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, gintmsk.d32, 0); DWC_DEBUGPL(DBG_CIL, " ++Connector ID Status Change Interrupt++ (%s)\n", (dwc_otg_is_host_mode(_core_if) ? "Host" : "Device")); gotgctl.d32 = dwc_read_reg32(&_core_if->core_global_regs->gotgctl); DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32); DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts); /* B-Device connector (Device Mode) */ if (gotgctl.b.conidsts) { /* Wait for switch to device mode. */ while (!dwc_otg_is_device_mode(_core_if)) { printk("Waiting for Peripheral Mode, Mode=%s\n", (dwc_otg_is_host_mode(_core_if) ? "Host" : "Peripheral")); mdelay(100); if (++count > 10000) *(uint32_t *) NULL = 0; } _core_if->op_state = B_PERIPHERAL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -