2012-05-11 14:25:54 +00:00
|
|
|
/*
|
|
|
|
* host.c - ChipIdea USB host controller driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Intel Corporation
|
|
|
|
*
|
|
|
|
* Author: Alexander Shishkin
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2012-11-03 16:39:27 +00:00
|
|
|
#include <linux/io.h>
|
2012-05-11 14:25:54 +00:00
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/hcd.h>
|
|
|
|
#include <linux/usb/chipidea.h>
|
usb: chipidea: host: add vbus regulator control
For boards which have board level vbus control (eg, through gpio), we
need to vbus operation according to below rules:
- For host, we need open vbus before start hcd, and close it
after remove hcd.
- For otg, the vbus needs to be on/off when usb role switches.
When the host roles begins, it opens vbus; when the host role
finishes, it closes vbus.
We put vbus operation to host as host is the only vbus user,
When we are at host mode, the vbus is on, when we are not at
host mode, vbus should be off.
Tested-by: Marek Vasut <marex@denx.de>
Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-14 09:44:04 +00:00
|
|
|
#include <linux/regulator/consumer.h>
|
2012-05-11 14:25:54 +00:00
|
|
|
|
2012-11-02 16:34:41 +00:00
|
|
|
#include "../host/ehci.h"
|
2012-05-11 14:25:54 +00:00
|
|
|
|
|
|
|
#include "ci.h"
|
|
|
|
#include "bits.h"
|
|
|
|
#include "host.h"
|
|
|
|
|
2012-11-02 16:34:41 +00:00
|
|
|
static struct hc_driver __read_mostly ci_ehci_hc_driver;
|
2015-02-11 04:44:59 +00:00
|
|
|
static int (*orig_bus_suspend)(struct usb_hcd *hcd);
|
2012-11-02 16:34:41 +00:00
|
|
|
|
2014-10-13 01:53:04 +00:00
|
|
|
struct ehci_ci_priv {
|
|
|
|
struct regulator *reg_vbus;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ehci_ci_portpower(struct usb_hcd *hcd, int portnum, bool enable)
|
|
|
|
{
|
|
|
|
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
|
|
|
struct ehci_ci_priv *priv = (struct ehci_ci_priv *)ehci->priv;
|
|
|
|
struct device *dev = hcd->self.controller;
|
|
|
|
int ret = 0;
|
|
|
|
int port = HCS_N_PORTS(ehci->hcs_params);
|
|
|
|
|
2015-02-11 04:45:02 +00:00
|
|
|
if (priv->reg_vbus) {
|
2014-10-13 01:53:04 +00:00
|
|
|
if (port > 1) {
|
|
|
|
dev_warn(dev,
|
|
|
|
"Not support multi-port regulator control\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (enable)
|
|
|
|
ret = regulator_enable(priv->reg_vbus);
|
|
|
|
else
|
|
|
|
ret = regulator_disable(priv->reg_vbus);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev,
|
|
|
|
"Failed to %s vbus regulator, ret=%d\n",
|
|
|
|
enable ? "enable" : "disable", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ehci_driver_overrides ehci_ci_overrides = {
|
|
|
|
.extra_priv_size = sizeof(struct ehci_ci_priv),
|
|
|
|
.port_power = ehci_ci_portpower,
|
|
|
|
};
|
|
|
|
|
2013-06-24 11:46:36 +00:00
|
|
|
static irqreturn_t host_irq(struct ci_hdrc *ci)
|
2012-05-11 14:25:54 +00:00
|
|
|
{
|
|
|
|
return usb_hcd_irq(ci->irq, ci->hcd);
|
|
|
|
}
|
|
|
|
|
2013-06-24 11:46:36 +00:00
|
|
|
static int host_start(struct ci_hdrc *ci)
|
2012-05-11 14:25:54 +00:00
|
|
|
{
|
|
|
|
struct usb_hcd *hcd;
|
|
|
|
struct ehci_hcd *ehci;
|
2014-10-13 01:53:04 +00:00
|
|
|
struct ehci_ci_priv *priv;
|
2012-05-11 14:25:54 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (usb_disabled())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
|
|
|
|
if (!hcd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-12-24 03:33:17 +00:00
|
|
|
dev_set_drvdata(ci->dev, ci);
|
2012-05-11 14:25:54 +00:00
|
|
|
hcd->rsrc_start = ci->hw_bank.phys;
|
|
|
|
hcd->rsrc_len = ci->hw_bank.size;
|
|
|
|
hcd->regs = ci->hw_bank.abs;
|
|
|
|
hcd->has_tt = 1;
|
|
|
|
|
2012-06-29 09:48:53 +00:00
|
|
|
hcd->power_budget = ci->platdata->power_budget;
|
2014-08-19 01:51:56 +00:00
|
|
|
hcd->tpl_support = ci->platdata->tpl_support;
|
2014-10-30 17:41:19 +00:00
|
|
|
if (ci->phy)
|
|
|
|
hcd->phy = ci->phy;
|
|
|
|
else
|
|
|
|
hcd->usb_phy = ci->usb_phy;
|
2012-05-11 14:25:55 +00:00
|
|
|
|
2012-05-11 14:25:54 +00:00
|
|
|
ehci = hcd_to_ehci(hcd);
|
|
|
|
ehci->caps = ci->hw_bank.cap;
|
|
|
|
ehci->has_hostpc = ci->hw_bank.lpm;
|
2013-08-12 13:06:49 +00:00
|
|
|
ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
|
2014-01-10 05:51:27 +00:00
|
|
|
ehci->imx28_write_fix = ci->imx28_write_fix;
|
2012-05-11 14:25:54 +00:00
|
|
|
|
2014-10-13 01:53:04 +00:00
|
|
|
priv = (struct ehci_ci_priv *)ehci->priv;
|
|
|
|
priv->reg_vbus = NULL;
|
|
|
|
|
2015-02-11 04:45:02 +00:00
|
|
|
if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) {
|
|
|
|
if (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON) {
|
|
|
|
ret = regulator_enable(ci->platdata->reg_vbus);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(ci->dev,
|
|
|
|
"Failed to enable vbus regulator, ret=%d\n",
|
|
|
|
ret);
|
|
|
|
goto put_hcd;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
priv->reg_vbus = ci->platdata->reg_vbus;
|
|
|
|
}
|
|
|
|
}
|
usb: chipidea: host: add vbus regulator control
For boards which have board level vbus control (eg, through gpio), we
need to vbus operation according to below rules:
- For host, we need open vbus before start hcd, and close it
after remove hcd.
- For otg, the vbus needs to be on/off when usb role switches.
When the host roles begins, it opens vbus; when the host role
finishes, it closes vbus.
We put vbus operation to host as host is the only vbus user,
When we are at host mode, the vbus is on, when we are not at
host mode, vbus should be off.
Tested-by: Marek Vasut <marex@denx.de>
Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-14 09:44:04 +00:00
|
|
|
|
2012-05-11 14:25:54 +00:00
|
|
|
ret = usb_add_hcd(hcd, 0, 0);
|
2014-04-23 07:56:46 +00:00
|
|
|
if (ret) {
|
2015-02-11 04:45:02 +00:00
|
|
|
goto disable_reg;
|
2014-04-23 07:56:46 +00:00
|
|
|
} else {
|
2014-10-30 17:41:16 +00:00
|
|
|
struct usb_otg *otg = &ci->otg;
|
2014-04-23 07:56:46 +00:00
|
|
|
|
2012-05-11 14:25:54 +00:00
|
|
|
ci->hcd = hcd;
|
2014-10-30 17:41:16 +00:00
|
|
|
|
|
|
|
if (ci_otg_is_fsm_mode(ci)) {
|
2014-04-23 07:56:46 +00:00
|
|
|
otg->host = &hcd->self;
|
|
|
|
hcd->self.otg_port = 1;
|
|
|
|
}
|
|
|
|
}
|
2012-05-11 14:25:54 +00:00
|
|
|
|
2013-06-24 11:46:36 +00:00
|
|
|
if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
|
2012-12-22 11:24:11 +00:00
|
|
|
hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
|
|
|
|
|
2015-02-11 04:44:58 +00:00
|
|
|
if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED)
|
|
|
|
hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC);
|
|
|
|
|
2012-05-11 14:25:54 +00:00
|
|
|
return ret;
|
usb: chipidea: host: add vbus regulator control
For boards which have board level vbus control (eg, through gpio), we
need to vbus operation according to below rules:
- For host, we need open vbus before start hcd, and close it
after remove hcd.
- For otg, the vbus needs to be on/off when usb role switches.
When the host roles begins, it opens vbus; when the host role
finishes, it closes vbus.
We put vbus operation to host as host is the only vbus user,
When we are at host mode, the vbus is on, when we are not at
host mode, vbus should be off.
Tested-by: Marek Vasut <marex@denx.de>
Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-14 09:44:04 +00:00
|
|
|
|
2015-02-11 04:45:02 +00:00
|
|
|
disable_reg:
|
|
|
|
if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
|
|
|
|
(ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON))
|
|
|
|
regulator_disable(ci->platdata->reg_vbus);
|
usb: chipidea: host: add vbus regulator control
For boards which have board level vbus control (eg, through gpio), we
need to vbus operation according to below rules:
- For host, we need open vbus before start hcd, and close it
after remove hcd.
- For otg, the vbus needs to be on/off when usb role switches.
When the host roles begins, it opens vbus; when the host role
finishes, it closes vbus.
We put vbus operation to host as host is the only vbus user,
When we are at host mode, the vbus is on, when we are not at
host mode, vbus should be off.
Tested-by: Marek Vasut <marex@denx.de>
Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-14 09:44:04 +00:00
|
|
|
put_hcd:
|
|
|
|
usb_put_hcd(hcd);
|
|
|
|
|
|
|
|
return ret;
|
2012-05-11 14:25:54 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 11:46:36 +00:00
|
|
|
static void host_stop(struct ci_hdrc *ci)
|
2012-05-11 14:25:54 +00:00
|
|
|
{
|
|
|
|
struct usb_hcd *hcd = ci->hcd;
|
|
|
|
|
2013-10-16 12:45:15 +00:00
|
|
|
if (hcd) {
|
|
|
|
usb_remove_hcd(hcd);
|
|
|
|
usb_put_hcd(hcd);
|
2015-02-11 04:45:02 +00:00
|
|
|
if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
|
|
|
|
(ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON))
|
|
|
|
regulator_disable(ci->platdata->reg_vbus);
|
2013-10-16 12:45:15 +00:00
|
|
|
}
|
2012-05-11 14:25:54 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 09:44:07 +00:00
|
|
|
|
|
|
|
void ci_hdrc_host_destroy(struct ci_hdrc *ci)
|
|
|
|
{
|
2013-10-22 03:13:41 +00:00
|
|
|
if (ci->role == CI_ROLE_HOST && ci->hcd)
|
2013-08-14 09:44:07 +00:00
|
|
|
host_stop(ci);
|
|
|
|
}
|
|
|
|
|
2015-02-11 04:44:59 +00:00
|
|
|
static int ci_ehci_bus_suspend(struct usb_hcd *hcd)
|
|
|
|
{
|
|
|
|
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
|
|
|
int port;
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
int ret = orig_bus_suspend(hcd);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
port = HCS_N_PORTS(ehci->hcs_params);
|
|
|
|
while (port--) {
|
|
|
|
u32 __iomem *reg = &ehci->regs->port_status[port];
|
|
|
|
u32 portsc = ehci_readl(ehci, reg);
|
|
|
|
|
|
|
|
if (portsc & PORT_CONNECT) {
|
|
|
|
/*
|
|
|
|
* For chipidea, the resume signal will be ended
|
|
|
|
* automatically, so for remote wakeup case, the
|
|
|
|
* usbcmd.rs may not be set before the resume has
|
|
|
|
* ended if other resume paths consumes too much
|
|
|
|
* time (~24ms), in that case, the SOF will not
|
|
|
|
* send out within 3ms after resume ends, then the
|
|
|
|
* high speed device will enter full speed mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmp = ehci_readl(ehci, &ehci->regs->command);
|
|
|
|
tmp |= CMD_RUN;
|
|
|
|
ehci_writel(ehci, tmp, &ehci->regs->command);
|
|
|
|
/*
|
|
|
|
* It needs a short delay between set RS bit and PHCD.
|
|
|
|
*/
|
|
|
|
usleep_range(150, 200);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-24 11:46:36 +00:00
|
|
|
int ci_hdrc_host_init(struct ci_hdrc *ci)
|
2012-05-11 14:25:54 +00:00
|
|
|
{
|
|
|
|
struct ci_role_driver *rdrv;
|
|
|
|
|
|
|
|
if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_HC))
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
|
|
|
|
if (!rdrv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rdrv->start = host_start;
|
|
|
|
rdrv->stop = host_stop;
|
|
|
|
rdrv->irq = host_irq;
|
|
|
|
rdrv->name = "host";
|
|
|
|
ci->roles[CI_ROLE_HOST] = rdrv;
|
|
|
|
|
2014-10-13 01:53:04 +00:00
|
|
|
ehci_init_driver(&ci_ehci_hc_driver, &ehci_ci_overrides);
|
2015-02-11 04:44:59 +00:00
|
|
|
orig_bus_suspend = ci_ehci_hc_driver.bus_suspend;
|
|
|
|
ci_ehci_hc_driver.bus_suspend = ci_ehci_bus_suspend;
|
2012-11-02 16:34:41 +00:00
|
|
|
|
2012-05-11 14:25:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|