From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sven Schwermer Date: Thu, 15 Nov 2018 09:20:36 +0100 Subject: [U-Boot] [PATCH] usb: Introduce CONFIG_SPL_DM_USB Message-ID: <1E5C137C-1801-422C-B504-AD727DA094BA@svenschwermer.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This allows building the SPL without driver model for USB. So far, support has only been added to the iMX6/7 host driver. Other boards will keep their existing behaviour. Signed-off-by: Sven Schwermer --- This solves the dependency problem I described in [1]. [1]: http://u-boot.10912.n7.nabble.com/-td347224.html common/usb_storage.c | 34 +++++++++++++++++----------------- drivers/usb/Kconfig | 5 +++++ drivers/usb/gadget/ci_udc.c | 2 +- drivers/usb/host/Makefile | 3 ++- drivers/usb/host/ehci-hcd.c | 12 ++++++------ drivers/usb/host/ehci-mx6.c | 2 +- include/usb.h | 12 ++++++------ 7 files changed, 38 insertions(+), 32 deletions(-) diff --git a/common/usb_storage.c b/common/usb_storage.c index d92ebb6eb1..ff881aa0c9 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -66,7 +66,7 @@ static __u32 CBWTag; static int usb_max_devs; /* number of highest available usb device */ -#ifndef CONFIG_BLK +#if !CONFIG_IS_ENABLED(BLK) static struct blk_desc usb_dev_desc[USB_MAX_STOR_DEV]; #endif @@ -99,7 +99,7 @@ struct us_data { unsigned short max_xfer_blk; /* maximum transfer blocks */ }; -#ifndef CONFIG_BLK +#if !CONFIG_IS_ENABLED(BLK) static struct us_data usb_stor[USB_MAX_STOR_DEV]; #endif @@ -111,7 +111,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *us, struct blk_desc *dev_desc); int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, struct us_data *ss); -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) static unsigned long usb_stor_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer); static unsigned long usb_stor_write(struct udevice *dev, lbaint_t blknr, @@ -136,7 +136,7 @@ static void usb_show_progress(void) int usb_stor_info(void) { int count = 0; -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) struct udevice *dev; for (blk_first_device(IF_TYPE_USB, &dev); @@ -186,7 +186,7 @@ static int usb_stor_probe_device(struct usb_device *udev) { int lun, max_lun; -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) struct us_data *data; int ret; #else @@ -197,7 +197,7 @@ static int usb_stor_probe_device(struct usb_device *udev) #endif debug("\n\nProbing for storage\n"); -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) /* * We store the us_data in the mass storage device's platdata. It * is shared by all LUNs (block devices) attached to this mass storage @@ -301,7 +301,7 @@ int usb_stor_scan(int mode) if (mode == 1) printf(" scanning usb for storage devices... "); -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) unsigned char i; usb_disable_asynch(1); /* asynch transfer not allowed */ @@ -944,7 +944,7 @@ static void usb_stor_set_max_xfer_blk(struct usb_device *udev, size_t __maybe_unused size; int __maybe_unused ret; -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) #ifdef CONFIG_USB_EHCI_HCD /* * The U-Boot EHCI driver can handle any transfer length as long as @@ -1121,7 +1121,7 @@ static void usb_bin_fixup(struct usb_device_descriptor descriptor, } #endif /* CONFIG_USB_BIN_FIXUP */ -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) static unsigned long usb_stor_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer) #else @@ -1136,14 +1136,14 @@ static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr, struct us_data *ss; int retry; struct scsi_cmd *srb = &usb_ccb; -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) struct blk_desc *block_dev; #endif if (blkcnt == 0) return 0; /* Setup device */ -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) block_dev = dev_get_uclass_platdata(dev); udev = dev_get_parent_priv(dev_get_parent(dev)); debug("\nusb_read: udev %d\n", block_dev->devnum); @@ -1202,7 +1202,7 @@ retry_it: return blkcnt; } -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) static unsigned long usb_stor_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer) #else @@ -1217,7 +1217,7 @@ static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr, struct us_data *ss; int retry; struct scsi_cmd *srb = &usb_ccb; -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) struct blk_desc *block_dev; #endif @@ -1225,7 +1225,7 @@ static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr, return 0; /* Setup device */ -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) block_dev = dev_get_uclass_platdata(dev); udev = dev_get_parent_priv(dev_get_parent(dev)); debug("\nusb_read: udev %d\n", block_dev->devnum); @@ -1497,7 +1497,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss, return 1; } -#ifdef CONFIG_DM_USB +#if CONFIG_IS_ENABLED(DM_USB) static int usb_mass_storage_probe(struct udevice *dev) { @@ -1521,7 +1521,7 @@ U_BOOT_DRIVER(usb_mass_storage) = { .id = UCLASS_MASS_STORAGE, .of_match = usb_mass_storage_ids, .probe = usb_mass_storage_probe, -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) .platdata_auto_alloc_size = sizeof(struct us_data), #endif }; @@ -1542,7 +1542,7 @@ static const struct usb_device_id mass_storage_id_table[] = { U_BOOT_USB_DEVICE(usb_mass_storage, mass_storage_id_table); #endif -#ifdef CONFIG_BLK +#if CONFIG_IS_ENABLED(BLK) static const struct blk_ops usb_storage_ops = { .read = usb_stor_read, .write = usb_stor_write, diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 4fbe172e05..03746dd12f 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -47,6 +47,11 @@ config DM_USB declared with the U_BOOT_USB_DEVICE() macro and will be automatically probed when found on the bus. +config SPL_DM_USB + bool "Enable driver model for USB in SPL" + depends on DM_USB + default y + source "drivers/usb/host/Kconfig" source "drivers/usb/dwc3/Kconfig" diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index 0a84f6850d..bd596ce977 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -1015,7 +1015,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) if (driver->speed != USB_SPEED_FULL && driver->speed != USB_SPEED_HIGH) return -EINVAL; -#ifdef CONFIG_DM_USB +#if CONFIG_IS_ENABLED(DM_USB) ret = usb_setup_ehci_gadget(&controller.ctrl); #else ret = usb_lowlevel_init(0, USB_INIT_DEVICE, (void **)&controller.ctrl); diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index cb8c315a15..94839ffd97 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -3,8 +3,9 @@ # (C) Copyright 2000-2007 # Wolfgang Denk, DENX Software Engineering, wd at denx.de. +obj-$(CONFIG_$(SPL_)DM_USB) += usb-uclass.o + ifdef CONFIG_DM_USB -obj-$(CONFIG_CMD_USB) += usb-uclass.o obj-$(CONFIG_SANDBOX) += usb-sandbox.o endif diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index d1d8f08d98..4b28db70a5 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -30,7 +30,7 @@ */ #define HCHALT_TIMEOUT (8 * 1000) -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) static struct ehci_ctrl ehcic[CONFIG_USB_MAX_CONTROLLER_COUNT]; #endif @@ -111,7 +111,7 @@ static struct descriptor { static struct ehci_ctrl *ehci_get_ctrl(struct usb_device *udev) { -#ifdef CONFIG_DM_USB +#if CONFIG_IS_ENABLED(DM_USB) return dev_get_priv(usb_get_bus(udev->dev)); #else return udev->controller; @@ -973,7 +973,7 @@ static void ehci_setup_ops(struct ehci_ctrl *ctrl, const struct ehci_ops *ops) } } -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) void ehci_set_controller_priv(int index, void *priv, const struct ehci_ops *ops) { struct ehci_ctrl *ctrl = &ehcic[index]; @@ -1097,7 +1097,7 @@ static int ehci_common_init(struct ehci_ctrl *ctrl, uint tweaks) return 0; } -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) int usb_lowlevel_stop(int index) { ehci_shutdown(&ehcic[index]); @@ -1518,7 +1518,7 @@ static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe, return result; } -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int length) { @@ -1556,7 +1556,7 @@ int destroy_int_queue(struct usb_device *dev, struct int_queue *queue) } #endif -#ifdef CONFIG_DM_USB +#if CONFIG_IS_ENABLED(DM_USB) static int ehci_submit_control_msg(struct udevice *dev, struct usb_device *udev, unsigned long pipe, void *buffer, int length, struct devrequest *setup) diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index be010b1adb..1acf08dfb7 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -335,7 +335,7 @@ int ehci_mx6_common_init(struct usb_ehci *ehci, int index) return 0; } -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { diff --git a/include/usb.h b/include/usb.h index b6b48a8c60..420a30e49f 100644 --- a/include/usb.h +++ b/include/usb.h @@ -140,7 +140,7 @@ struct usb_device { int act_len; /* transferred bytes */ int maxchild; /* Number of ports if hub */ int portnr; /* Port number, 1=first */ -#ifndef CONFIG_DM_USB +#if !CONFIG_IS_ENABLED(DM_USB) /* parent hub, or NULL if this is the root hub */ struct usb_device *parent; struct usb_device *children[USB_MAXCHILDREN]; @@ -148,7 +148,7 @@ struct usb_device { #endif /* slot_id - for xHCI enabled devices */ unsigned int slot_id; -#ifdef CONFIG_DM_USB +#if CONFIG_IS_ENABLED(DM_USB) struct udevice *dev; /* Pointer to associated device */ struct udevice *controller_dev; /* Pointer to associated controller */ #endif @@ -173,7 +173,7 @@ enum usb_init_type { int usb_lowlevel_init(int index, enum usb_init_type init, void **controller); int usb_lowlevel_stop(int index); -#if defined(CONFIG_USB_MUSB_HOST) || defined(CONFIG_DM_USB) +#if defined(CONFIG_USB_MUSB_HOST) || CONFIG_IS_ENABLED(DM_USB) int usb_reset_root_port(struct usb_device *dev); #else #define usb_reset_root_port(dev) @@ -187,7 +187,7 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int transfer_len, int interval); #if defined CONFIG_USB_EHCI_HCD || defined CONFIG_USB_MUSB_HOST \ - || defined(CONFIG_DM_USB) + || CONFIG_IS_ENABLED(DM_USB) struct int_queue *create_int_queue(struct usb_device *dev, unsigned long pipe, int queuesize, int elementsize, void *buffer, int interval); int destroy_int_queue(struct usb_device *dev, struct int_queue *queue); @@ -588,7 +588,7 @@ struct usb_hub_device { struct usb_tt tt; /* Transaction Translator */ }; -#ifdef CONFIG_DM_USB +#if CONFIG_IS_ENABLED(DM_USB) /** * struct usb_platdata - Platform data about a USB controller * @@ -912,7 +912,7 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp); */ void usb_stor_reset(void); -#else /* !CONFIG_DM_USB */ +#else /* !CONFIG_IS_ENABLED(DM_USB) */ struct usb_device *usb_get_dev_index(int index); -- 2.17.1