host.c 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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>
23
#include <linux/io.h>
24 25 26 27
#include <linux/usb.h>
#include <linux/usb/hcd.h>
#include <linux/usb/chipidea.h>

28
#include "../host/ehci.h"
29 30 31 32 33

#include "ci.h"
#include "bits.h"
#include "host.h"

34 35
static struct hc_driver __read_mostly ci_ehci_hc_driver;

36
static irqreturn_t host_irq(struct ci_hdrc *ci)
37 38 39 40
{
	return usb_hcd_irq(ci->irq, ci->hcd);
}

41
static int host_start(struct ci_hdrc *ci)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
{
	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;

60
	hcd->power_budget = ci->platdata->power_budget;
61
	hcd->phy = ci->transceiver;
62

63 64 65 66 67 68
	ehci = hcd_to_ehci(hcd);
	ehci->caps = ci->hw_bank.cap;
	ehci->has_hostpc = ci->hw_bank.lpm;

	ret = usb_add_hcd(hcd, 0, 0);
	if (ret)
69
		usb_put_hcd(hcd);
70 71 72
	else
		ci->hcd = hcd;

73
	if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
74 75
		hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);

76 77 78
	return ret;
}

79
static void host_stop(struct ci_hdrc *ci)
80 81 82 83 84 85 86
{
	struct usb_hcd *hcd = ci->hcd;

	usb_remove_hcd(hcd);
	usb_put_hcd(hcd);
}

87
int ci_hdrc_host_init(struct ci_hdrc *ci)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
{
	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;

104
	ehci_init_driver(&ci_ehci_hc_driver, NULL);
105

106 107
	return 0;
}