dwc3: Check USB LPM status before accessing any register
USB debugfs entries can be accessed when USB session is not active or USB is in low power mode. This results into unclocked register access. Fix this issue by checking USB LPM status. debugfs_create_regset32() fops related APIs are used to get USB dwc3 register dump. These fops don't have support to query device status before accessing registers. Hence by default disabling creation of regdump debugfs entry. Change-Id: I67b00532eca159e000c848cb056d9759c47aefe9 Signed-off-by: Mayank Rana <mrana@codeaurora.org>
This commit is contained in:
parent
de5fd0b3ce
commit
b36879a9e9
2 changed files with 41 additions and 4 deletions
|
@ -852,6 +852,7 @@ struct dwc3_scratchpad_array {
|
|||
* @vbus_draw: current to be drawn from USB
|
||||
* @imod_interval: set the interrupt moderation interval in 250ns
|
||||
* increments or 0 to disable.
|
||||
* @create_reg_debugfs: create debugfs entry to allow dwc3 register dump
|
||||
*/
|
||||
struct dwc3 {
|
||||
struct usb_ctrlrequest *ctrl_req;
|
||||
|
@ -1048,6 +1049,7 @@ struct dwc3 {
|
|||
unsigned long l1_remote_wakeup_cnt;
|
||||
|
||||
wait_queue_head_t wait_linkstate;
|
||||
bool create_reg_debugfs;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
|
|
@ -368,6 +368,11 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
|
|||
unsigned long flags;
|
||||
u32 reg;
|
||||
|
||||
if (atomic_read(&dwc->in_lpm)) {
|
||||
seq_puts(s, "USB device is powered off\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&dwc->lock, flags);
|
||||
reg = dwc3_readl(dwc->regs, DWC3_GCTL);
|
||||
spin_unlock_irqrestore(&dwc->lock, flags);
|
||||
|
@ -403,6 +408,11 @@ static ssize_t dwc3_mode_write(struct file *file,
|
|||
u32 mode = 0;
|
||||
char buf[32] = {};
|
||||
|
||||
if (atomic_read(&dwc->in_lpm)) {
|
||||
dev_err(dwc->dev, "USB device is powered off\n");
|
||||
return count;
|
||||
}
|
||||
|
||||
if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
|
||||
return -EFAULT;
|
||||
|
||||
|
@ -437,6 +447,12 @@ static int dwc3_testmode_show(struct seq_file *s, void *unused)
|
|||
unsigned long flags;
|
||||
u32 reg;
|
||||
|
||||
|
||||
if (atomic_read(&dwc->in_lpm)) {
|
||||
seq_puts(s, "USB device is powered off\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&dwc->lock, flags);
|
||||
reg = dwc3_readl(dwc->regs, DWC3_DCTL);
|
||||
reg &= DWC3_DCTL_TSTCTRL_MASK;
|
||||
|
@ -483,6 +499,11 @@ static ssize_t dwc3_testmode_write(struct file *file,
|
|||
u32 testmode = 0;
|
||||
char buf[32] = {};
|
||||
|
||||
if (atomic_read(&dwc->in_lpm)) {
|
||||
seq_puts(s, "USB device is powered off\n");
|
||||
return count;
|
||||
}
|
||||
|
||||
if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
|
||||
return -EFAULT;
|
||||
|
||||
|
@ -521,6 +542,11 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused)
|
|||
enum dwc3_link_state state;
|
||||
u32 reg;
|
||||
|
||||
if (atomic_read(&dwc->in_lpm)) {
|
||||
seq_puts(s, "USB device is powered off\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&dwc->lock, flags);
|
||||
reg = dwc3_readl(dwc->regs, DWC3_DSTS);
|
||||
state = DWC3_DSTS_USBLNKST(reg);
|
||||
|
@ -590,6 +616,11 @@ static ssize_t dwc3_link_state_write(struct file *file,
|
|||
enum dwc3_link_state state = 0;
|
||||
char buf[32] = {};
|
||||
|
||||
if (atomic_read(&dwc->in_lpm)) {
|
||||
seq_puts(s, "USB device is powered off\n");
|
||||
return count;
|
||||
}
|
||||
|
||||
if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
|
||||
return -EFAULT;
|
||||
|
||||
|
@ -1241,10 +1272,14 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
|
|||
dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
|
||||
dwc->regset->base = dwc->regs;
|
||||
|
||||
file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
|
||||
if (!file) {
|
||||
ret = -ENOMEM;
|
||||
goto err1;
|
||||
if (dwc->create_reg_debugfs) {
|
||||
file = debugfs_create_regset32("regdump", 0444,
|
||||
root, dwc->regset);
|
||||
if (!file) {
|
||||
dev_dbg(dwc->dev, "Can't create debugfs regdump\n");
|
||||
ret = -ENOMEM;
|
||||
goto err1;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue