2012-05-11 22:25:54 +08: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-04 00:39:27 +08:00
|
|
|
#include <linux/io.h>
|
2012-05-11 22:25:54 +08: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 17:44:04 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
2012-05-11 22:25:54 +08:00
|
|
|
|
2012-11-03 00:34:41 +08:00
|
|
|
#include "../host/ehci.h"
|
2012-05-11 22:25:54 +08:00
|
|
|
|
|
|
|
#include "ci.h"
|
|
|
|
#include "bits.h"
|
|
|
|
#include "host.h"
|
|
|
|
|
2012-11-03 00:34:41 +08:00
|
|
|
static struct hc_driver __read_mostly ci_ehci_hc_driver;
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static irqreturn_t host_irq(struct ci_hdrc *ci)
|
2012-05-11 22:25:54 +08:00
|
|
|
{
|
|
|
|
return usb_hcd_irq(ci->irq, ci->hcd);
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static int host_start(struct ci_hdrc *ci)
|
2012-05-11 22:25:54 +08:00
|
|
|
{
|
|
|
|
struct usb_hcd *hcd;
|
|
|
|
struct ehci_hcd *ehci;
|
|
|
|
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;
|
|
|
|
|
|
|
|
dev_set_drvdata(ci->dev, ci);
|
|
|
|
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 17:48:53 +08:00
|
|
|
hcd->power_budget = ci->platdata->power_budget;
|
2012-07-07 22:56:46 +08:00
|
|
|
hcd->phy = ci->transceiver;
|
2012-05-11 22:25:55 +08:00
|
|
|
|
2012-05-11 22:25:54 +08:00
|
|
|
ehci = hcd_to_ehci(hcd);
|
|
|
|
ehci->caps = ci->hw_bank.cap;
|
|
|
|
ehci->has_hostpc = ci->hw_bank.lpm;
|
2013-08-12 21:06:49 +08:00
|
|
|
ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
|
2012-05-11 22:25:54 +08:00
|
|
|
|
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 17:44:04 +08:00
|
|
|
if (ci->platdata->reg_vbus) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-11 22:25:54 +08:00
|
|
|
ret = usb_add_hcd(hcd, 0, 0);
|
|
|
|
if (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 17:44:04 +08:00
|
|
|
goto disable_reg;
|
2012-05-11 22:25:54 +08:00
|
|
|
else
|
|
|
|
ci->hcd = hcd;
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
|
2012-12-22 19:24:11 +08:00
|
|
|
hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
|
|
|
|
|
2012-05-11 22:25:54 +08: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 17:44:04 +08:00
|
|
|
|
|
|
|
disable_reg:
|
|
|
|
regulator_disable(ci->platdata->reg_vbus);
|
|
|
|
|
|
|
|
put_hcd:
|
|
|
|
usb_put_hcd(hcd);
|
|
|
|
|
|
|
|
return ret;
|
2012-05-11 22:25:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static void host_stop(struct ci_hdrc *ci)
|
2012-05-11 22:25:54 +08:00
|
|
|
{
|
|
|
|
struct usb_hcd *hcd = ci->hcd;
|
|
|
|
|
|
|
|
usb_remove_hcd(hcd);
|
|
|
|
usb_put_hcd(hcd);
|
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 17:44:04 +08:00
|
|
|
if (ci->platdata->reg_vbus)
|
|
|
|
regulator_disable(ci->platdata->reg_vbus);
|
2012-05-11 22:25:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
int ci_hdrc_host_init(struct ci_hdrc *ci)
|
2012-05-11 22:25:54 +08: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;
|
|
|
|
|
2012-11-08 05:12:47 +08:00
|
|
|
ehci_init_driver(&ci_ehci_hc_driver, NULL);
|
2012-11-03 00:34:41 +08:00
|
|
|
|
2012-05-11 22:25:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|