summaryrefslogtreecommitdiffstats
path: root/drivers/usb/musb/musb_dsps.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/musb/musb_dsps.c')
-rw-r--r--drivers/usb/musb/musb_dsps.c135
1 files changed, 57 insertions, 78 deletions
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 5fe3bcb7cd..97b64302ec 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* Texas Instruments DSPS platforms "glue layer"
*
@@ -7,22 +8,6 @@
*
* This file is part of the Inventra Controller Driver for Linux.
*
- * The Inventra Controller Driver for Linux 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.
- *
- * The Inventra Controller Driver for Linux 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 The Inventra Controller Driver for Linux ; if not,
- * write to the Free Software Foundation, Inc., 59 Temple Place,
- * Suite 330, Boston, MA 02111-1307 USA
- *
* musb_dsps.c will be a common file for all the TI DSPS platforms
* such as dm64x, dm36x, dm35x, da8x, am35x and ti81x.
* For now only ti81x is using this and in future davinci.c, am35x.c
@@ -32,14 +17,13 @@
#include <common.h>
#include <init.h>
#include <clock.h>
-#include <usb/usb.h>
-#include <usb/musb.h>
+#include <linux/usb/usb.h>
+#include <linux/usb/musb.h>
#include <malloc.h>
#include <linux/err.h>
#include <linux/barebox-wrapper.h>
#include "musb_core.h"
-#include "phy-am335x.h"
static __maybe_unused struct of_device_id musb_dsps_dt_ids[];
@@ -115,7 +99,7 @@ struct dsps_musb_wrapper {
* DSPS glue structure.
*/
struct dsps_glue {
- struct device_d *dev;
+ struct device *dev;
void __iomem *base;
unsigned long flags;
enum musb_mode mode;
@@ -124,7 +108,7 @@ struct dsps_glue {
const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
struct poller_async timer; /* otg_workaround timer */
uint64_t last_timer; /* last timer data for each instance */
- struct device_d otg_dev;
+ struct device otg_dev;
uint32_t otgmode;
struct musb_hdrc_platform_data pdata;
};
@@ -217,10 +201,6 @@ static int dsps_musb_init(struct musb *musb)
const struct dsps_musb_wrapper *wrp = glue->wrp;
u32 rev, val, mode;
- musb->xceiv = am335x_get_usb_phy();
- if (IS_ERR(musb->xceiv))
- return PTR_ERR(musb->xceiv);
-
/* Returns zero if e.g. not clocked */
rev = dsps_readl(musb->ctrl_base, wrp->revision);
if (!rev)
@@ -280,11 +260,11 @@ static int get_int_prop(struct device_node *dn, const char *s)
return val;
}
-static int get_musb_port_mode(struct device_d *dev)
+static int get_musb_port_mode(struct device *dev)
{
enum usb_dr_mode mode;
- mode = of_usb_get_dr_mode(dev->device_node, NULL);
+ mode = of_usb_get_dr_mode(dev->of_node, NULL);
switch (mode) {
case USB_DR_MODE_HOST:
return MUSB_PORT_MODE_HOST;
@@ -303,57 +283,29 @@ static int get_musb_port_mode(struct device_d *dev)
}
}
-static int dsps_set_mode(struct param_d *param, void *priv)
+static int dsps_set_mode(void *ctx, enum usb_dr_mode mode)
{
- struct dsps_glue *glue = priv;
-
- if (glue->pdata.mode != MUSB_PORT_MODE_DUAL_ROLE)
- return -EBUSY;
+ struct dsps_glue *glue = ctx;
- switch (glue->otgmode) {
- case 0:
- default:
- return -EINVAL;
- case 1:
+ if (mode == USB_DR_MODE_HOST)
glue->pdata.mode = MUSB_PORT_MODE_HOST;
- break;
- case 2:
+ else if (mode == USB_DR_MODE_PERIPHERAL)
glue->pdata.mode = MUSB_PORT_MODE_GADGET;
- break;
- }
+ else
+ return -EINVAL;
return musb_init_controller(&glue->musb, &glue->pdata);
}
-static const char *dsps_mode_names[] = {
- "otg", "host", "peripheral"
-};
-
-static int dsps_register_otg_device(struct dsps_glue *glue)
-{
- int ret;
-
- dev_set_name(&glue->otg_dev, "otg");
- glue->otg_dev.id = DEVICE_ID_DYNAMIC,
- glue->otg_dev.parent = glue->dev;
-
- ret = register_device(&glue->otg_dev);
- if (ret)
- return ret;
-
- dev_add_param_enum(&glue->otg_dev, "mode",
- dsps_set_mode, NULL, &glue->otgmode,
- dsps_mode_names, ARRAY_SIZE(dsps_mode_names), glue);
- return 0;
-}
-
-static int dsps_probe(struct device_d *dev)
+static int dsps_probe(struct device *dev)
{
- struct resource *iores;
+ struct resource *iores[2];
struct musb_hdrc_platform_data *pdata;
struct musb_hdrc_config *config;
- struct device_node *dn = dev->device_node;
+ struct device_node *dn = dev->of_node;
const struct dsps_musb_wrapper *wrp;
+ struct device_node *phy_node;
+ struct device *phy_dev;
struct dsps_glue *glue;
int ret;
@@ -367,6 +319,14 @@ static int dsps_probe(struct device_d *dev)
return -ENODEV;
}
+ phy_node = of_parse_phandle(dn, "phys", 0);
+ if (!phy_node)
+ return -ENODEV;
+
+ phy_dev = of_find_device_by_node(phy_node);
+ if (!phy_dev || !phy_dev->priv)
+ return -EPROBE_DEFER;
+
/* allocate glue */
glue = kzalloc(sizeof(*glue), GFP_KERNEL);
if (!glue) {
@@ -379,17 +339,22 @@ static int dsps_probe(struct device_d *dev)
pdata = &glue->pdata;
- iores = dev_request_mem_resource(dev, 0);
- if (IS_ERR(iores))
- return PTR_ERR(iores);
- glue->musb.mregs = IOMEM(iores->start);
+ iores[0] = dev_request_mem_resource(dev, 0);
+ if (IS_ERR(iores[0])) {
+ ret = PTR_ERR(iores[0]);
+ goto free_glue;
+ }
+ glue->musb.mregs = IOMEM(iores[0]->start);
- iores = dev_request_mem_resource(dev, 1);
- if (IS_ERR(iores))
- return PTR_ERR(iores);
- glue->musb.ctrl_base = IOMEM(iores->start);
+ iores[1] = dev_request_mem_resource(dev, 1);
+ if (IS_ERR(iores[1])) {
+ ret = PTR_ERR(iores[1]);
+ goto release_iores0;
+ }
+ glue->musb.ctrl_base = IOMEM(iores[1]->start);
glue->musb.controller = dev;
+ glue->musb.xceiv = phy_dev->priv;
config = &glue->config;
@@ -405,13 +370,26 @@ static int dsps_probe(struct device_d *dev)
config->multipoint = of_property_read_bool(dn, "mentor,multipoint");
if (pdata->mode == MUSB_PORT_MODE_DUAL_ROLE) {
- ret = dsps_register_otg_device(glue);
+ ret = usb_register_otg_device(dev, dsps_set_mode, glue);
if (ret)
- return ret;
+ goto release_iores1;
return 0;
}
- return musb_init_controller(&glue->musb, pdata);
+ ret = musb_init_controller(&glue->musb, pdata);
+ if (ret)
+ goto release_iores1;
+
+ return 0;
+
+release_iores1:
+ release_region(iores[1]);
+release_iores0:
+ release_region(iores[0]);
+free_glue:
+ free(glue);
+
+ return ret;
}
static const struct dsps_musb_wrapper am33xx_driver_data = {
@@ -450,8 +428,9 @@ static __maybe_unused struct of_device_id musb_dsps_dt_ids[] = {
/* sentinel */
},
};
+MODULE_DEVICE_TABLE(of, musb_dsps_dt_ids);
-static struct driver_d dsps_usbss_driver = {
+static struct driver dsps_usbss_driver = {
.name = "musb-dsps",
.probe = dsps_probe,
.of_compatible = DRV_OF_COMPAT(musb_dsps_dt_ids),