diff options
Diffstat (limited to 'drivers/usb/otg')
-rw-r--r-- | drivers/usb/otg/Kconfig | 1 | ||||
-rw-r--r-- | drivers/usb/otg/Makefile | 1 | ||||
-rw-r--r-- | drivers/usb/otg/otgdev.c | 96 | ||||
-rw-r--r-- | drivers/usb/otg/twl4030.c | 14 | ||||
-rw-r--r-- | drivers/usb/otg/ulpi.c | 12 |
5 files changed, 75 insertions, 49 deletions
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig index 2c094452b6..f8e592e89e 100644 --- a/drivers/usb/otg/Kconfig +++ b/drivers/usb/otg/Kconfig @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only config USB_ULPI bool "ULPI Transceiver support" help diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile index 49c2491e58..d6cac86cff 100644 --- a/drivers/usb/otg/Makefile +++ b/drivers/usb/otg/Makefile @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_USB_ULPI) += ulpi.o obj-$(CONFIG_USB_TWL4030) += twl4030.o obj-$(CONFIG_USB_OTGDEV) += otgdev.o diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c index 7017796e8c..5a86263430 100644 --- a/drivers/usb/otg/otgdev.c +++ b/drivers/usb/otg/otgdev.c @@ -1,31 +1,36 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0-only #include <common.h> #include <driver.h> -#include <usb/usb.h> - -static int (*set_mode_callback)(void *ctx, enum usb_dr_mode mode); -static unsigned int otg_mode; +#include <linux/usb/usb.h> + +struct otg_mode { + struct device dev; + unsigned int var_mode; + unsigned int cur_mode; + int (*set_mode_callback)(void *ctx, enum usb_dr_mode mode); + void *ctx; +}; static int otg_set_mode(struct param_d *param, void *ctx) { - static int cur_mode = USB_DR_MODE_OTG; + struct otg_mode *otg = ctx; int ret; - if (otg_mode == USB_DR_MODE_UNKNOWN) + if (otg->var_mode == USB_DR_MODE_UNKNOWN) return -EINVAL; - if (otg_mode == cur_mode) + if (otg->var_mode == otg->cur_mode) return 0; - if (cur_mode != USB_DR_MODE_OTG) + if (otg->cur_mode != USB_DR_MODE_OTG) return -EBUSY; - ret = set_mode_callback(ctx, otg_mode); + ret = otg->set_mode_callback(otg->ctx, otg->var_mode); if (ret) return ret; - cur_mode = otg_mode; + otg->cur_mode = otg->var_mode; return 0; } @@ -37,33 +42,70 @@ static const char *otg_mode_names[] = { [USB_DR_MODE_OTG] = "otg", }; -static struct device_d otg_device = { - .name = "otg", - .id = DEVICE_ID_SINGLE, +static int register_otg_device(struct device *dev, struct otg_mode *otg) +{ + struct param_d *param_mode; + int ret; + + ret = register_device(dev); + if (ret) + return ret; + + param_mode = dev_add_param_enum(dev, "mode", + otg_set_mode, NULL, &otg->var_mode, + otg_mode_names, ARRAY_SIZE(otg_mode_names), otg); + + return PTR_ERR_OR_ZERO(param_mode); +} + +struct bus_type otg_bus_type = { + .name = "usbotg" /* "otg" is already taken for the alias */ }; -int usb_register_otg_device(struct device_d *parent, +int otg_device_get_mode(struct device *dev) +{ + struct otg_mode *otg; + + if (dev->bus != &otg_bus_type) + return -ENODEV; + + otg = dev->priv; + + return otg->cur_mode; +} + +int usb_register_otg_device(struct device *parent, int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx) { + bool first_otg = list_empty(&otg_bus_type.device_list); int ret; - struct param_d *param_mode; + struct otg_mode *otg; - if (otg_device.parent) - return -EBUSY; + otg = xzalloc(sizeof(*otg)); + otg->dev.priv = otg; + otg->dev.parent = parent; + otg->dev.bus = &otg_bus_type; + otg->dev.id = DEVICE_ID_DYNAMIC; + dev_set_name(&otg->dev, "otg"); - otg_device.parent = parent; - set_mode_callback = set_mode; - otg_mode = USB_DR_MODE_OTG; + otg->var_mode = USB_DR_MODE_OTG; + otg->cur_mode = USB_DR_MODE_OTG; + otg->set_mode_callback = set_mode; + otg->ctx = ctx; - ret = register_device(&otg_device); + ret = register_otg_device(&otg->dev, otg); if (ret) return ret; - param_mode = dev_add_param_enum(&otg_device, "mode", - otg_set_mode, NULL, &otg_mode, - otg_mode_names, ARRAY_SIZE(otg_mode_names), ctx); - if (IS_ERR(param_mode)) - return PTR_ERR(param_mode); + /* register otg.mode as an alias of otg0.mode */ + if (first_otg) + dev_add_alias(&otg->dev, "otg"); return 0; } + +static int otg_bus_init(void) +{ + return bus_register(&otg_bus_type); +} +pure_initcall(otg_bus_init); diff --git a/drivers/usb/otg/twl4030.c b/drivers/usb/otg/twl4030.c index 3668870b9e..5cbf734ded 100644 --- a/drivers/usb/otg/twl4030.c +++ b/drivers/usb/otg/twl4030.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2009 Wind River Systems, Inc. * Tom Rix <Tom.Rix@windriver.com> @@ -20,21 +21,10 @@ * Author: Atin Malaviya (atin.malaviya@gmail.com) * * ------------------------------------------------------------------------ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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. - * */ #include <mfd/twl4030.h> -#include <usb/twl4030.h> +#include <linux/usb/twl4030.h> #include <clock.h> static int twl4030_usb_write(u8 address, u8 data) diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c index 9bc432fa86..d231b49b08 100644 --- a/drivers/usb/otg/ulpi.c +++ b/drivers/usb/otg/ulpi.c @@ -1,20 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * 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. */ #include <common.h> #include <io.h> #include <errno.h> -#include <usb/ulpi.h> +#include <linux/usb/ulpi.h> /* ULPIVIEW register bits */ #define ULPIVW_WU (1 << 31) /* Wakeup */ |