3 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
5 * otg_{get,set}_transceiver() are from arm/plat-omap/usb.c.
6 * which is Copyright (C) 2004 Texas Instruments, Inc.
10 * The code contained herein is licensed under the GNU General Public
11 * License. You may obtain a copy of the GNU General Public License
12 * Version 2 or later at the following locations:
14 * http://www.opensource.org/licenses/gpl-license.html
15 * http://www.gnu.org/copyleft/gpl.html
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/types.h>
21 #include <linux/errno.h>
22 #include <linux/init.h>
24 #include <linux/err.h>
25 #include <linux/platform_device.h>
26 #include <linux/usb/otg.h>
27 #include <linux/delay.h>
28 #include <linux/fsl_devices.h>
29 #include <linux/usb/fsl_xcvr.h>
32 /* The dmamask must be set for EHCI to work */
33 static u64 ehci_dmamask = ~(u32) 0;
35 struct fsl_xcvr_ops *xc_ops[3] = { NULL };
37 void fsl_usb_enable_clk(void)
40 EXPORT_SYMBOL(fsl_usb_enable_clk);
42 void fsl_usb_disable_clk(void)
45 EXPORT_SYMBOL(fsl_usb_disable_clk);
47 void fsl_usb_xcvr_register(struct fsl_xcvr_ops *xcvr_ops)
49 pr_debug("%s ctrlr=%d\n", __FUNCTION__, xcvr_ops->ctrlr);
50 xc_ops[xcvr_ops->ctrlr] = xcvr_ops;
53 EXPORT_SYMBOL(fsl_usb_xcvr_register);
55 void fsl_usb_xcvr_unregister(enum fsl_usb_ctrlr ctrlr)
57 pr_debug("%s ctrlr=%d\n", __FUNCTION__, ctrlr);
60 EXPORT_SYMBOL(fsl_usb_xcvr_unregister);
63 * Register an instance of a USB host platform device.
65 * @param res: resource pointer
66 * @param n_res: number of resources
67 * @param config: config pointer
69 * @return newly-registered platform_device
71 * DDD fix this comment:
72 * The USB controller supports 3 host interfaces, and the
73 * kernel can be configured to support some number of them.
74 * Each supported host interface is registered as an instance
75 * of the "fsl-ehci" device. Call this function multiple times
76 * to register each host interface.
78 static int instance_id;
79 struct platform_device *host_pdev_register(struct resource *res, int n_res,
80 struct fsl_usb2_platform_data *config)
82 struct platform_device *pdev;
84 pr_debug("register host res=0x%p, size=%d\n", res, n_res);
86 pdev = platform_device_register_simple("fsl-ehci",
87 instance_id, res, n_res);
89 printk(KERN_ERR "usb: can't register %s Host, %ld\n",
90 config->name, PTR_ERR(pdev));
94 pdev->dev.coherent_dma_mask = 0xffffffff;
95 pdev->dev.dma_mask = &ehci_dmamask;
98 * platform_device_add_data() makes a copy of
99 * the platform_data passed in. That makes it
100 * impossible to share the same config struct for
101 * all OTG devices (host,gadget,otg). So, just
102 * set the platform_data pointer ourselves.
104 pdev->dev.platform_data = config;
106 printk(KERN_INFO "usb: %s Host registered\n", config->name);
107 pr_debug("pdev=0x%p dev=0x%p resources=0x%p pdata=0x%p\n",
108 pdev, &pdev->dev, pdev->resource, pdev->dev.platform_data);
116 int fsl_usb_mem_init(struct platform_device *pdev)
118 struct resource *res;
119 struct fsl_usb2_platform_data *pdata;
121 pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
123 pr_debug("%s: pdev=0x%p pdata=0x%p\n", __FUNCTION__, pdev, pdata);
125 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
127 dev_err(&pdev->dev, "no MEM resource.\n");
131 pdata->r_start = res->start;
132 pdata->r_len = res->end - res->start + 1;
133 pr_debug("%s: MEM resource start=0x%x len=0x%x\n", pdata->name,
134 res->start, pdata->r_len);
136 if (!request_mem_region(pdata->r_start, pdata->r_len, "OTG")) {
137 dev_err(&pdev->dev, "request_mem_region failed\n");
140 pdata->regs = ioremap(pdata->r_start, pdata->r_len);
141 pr_debug("ioremapped to 0x%p\n", pdata->regs);
143 if (pdata->regs == NULL) {
144 dev_err(&pdev->dev, "ioremap failed\n");
145 release_mem_region(pdata->r_start, pdata->r_len);
149 pr_debug("%s: success\n", __FUNCTION__);
154 #if defined(CONFIG_USB_OTG)
155 static struct otg_transceiver *xceiv;
158 * otg_get_transceiver - find the (single) OTG transceiver driver
160 * Returns the transceiver driver, after getting a refcount to it; or
161 * null if there is no such transceiver. The caller is responsible for
162 * releasing that count.
164 struct otg_transceiver *otg_get_transceiver(void)
166 pr_debug("%s xceiv=0x%p\n", __FUNCTION__, xceiv);
168 get_device(xceiv->dev);
171 EXPORT_SYMBOL(otg_get_transceiver);
173 int otg_set_transceiver(struct otg_transceiver *x)
175 pr_debug("%s xceiv=0x%p x=0x%p\n", __FUNCTION__, xceiv, x);
181 EXPORT_SYMBOL(otg_set_transceiver);