usb: ehci-ppc-of: use platform for irq and ioremap
Subsystems (2)
PATCH 1/1 usb: ehci-ppc-of: use platform for irq and ioremap
Replace the open-coded of_address_to_resource() plus devm_ioremap_resource() sequence with devm_platform_get_and_ioremap_resource(), which looks up the resource and maps it in one call. The helper returns a pointer to the resource, so update rsrc_start / rsrc_len to dereference it, assign the mapped address to hcd->regs, and use a separate on-stack resource (ohci_res) for the unrelated ibm,usb-ohci-440epx erratum lookup rather than aliasing the returned resource pointer.
Switch IRQ acquisition from irq_of_parse_and_map() to platform_get_irq(), which only retrieves the interrupt the OF/platform core has already set up rather than transferring mapping ownership to the driver. Drop the now unneeded irq_dispose_mapping() calls (probe error path and ehci_hcd_ppc_of_remove()) and the now-unused of_irq.h and of_platform.h includes, keeping linux/of_address.h for the erratum block's of_address_to_resource().
Behaviorally equivalent with respect to region reservation: the prior code used devm_ioremap_resource(), which already reserved the region.
Built for PowerPC (ppc44x_defconfig + CONFIG_USB_EHCI_HCD_PPC_OF) with LLVM=1; drivers/usb/host/ehci-hcd.o (which includes ehci-ppc-of.c) compiles cleanly.
--- drivers/usb/host/ehci-ppc-of.c | 47 ++++++++++++---------------------- 1 file changed, 17 insertions(+), 30 deletions(-)
drivers/usb/host/ehci-ppc-of.c +17 -30
@@ -18,8 +18,6 @@#include <linux/of.h> #include <linux/of_address.h> -#include <linux/of_irq.h> -#include <linux/of_platform.h> static const struct hc_driver ehci_ppc_of_hc_driver = {
@@ -96,7 +94,9 @@ static int ehci_hcd_ppc_of_probe(struct platform_device *op)struct device_node *dn = op->dev.of_node;struct usb_hcd *hcd;struct ehci_hcd *ehci =NULL ; -struct resource res; +struct resource *res; +struct resource ohci_res; +void __iomem *regs;int irq;int rv;
@@ -107,39 +107,30 @@ static int ehci_hcd_ppc_of_probe(struct platform_device *op)dev_dbg (&op->dev,"initializing PPC-OF USB Controller\n" ); - rv =of_address_to_resource (dn,0 , &res); -if (rv) -return rv; + regs =devm_platform_get_and_ioremap_resource (op,0 , &res); +if (IS_ERR (regs)) +return PTR_ERR (regs); + + irq =platform_get_irq (op,0 ); +if (irq <0 ) +return irq; hcd =usb_create_hcd (&ehci_ppc_of_hc_driver, &op->dev,"PPC-OF USB" );if (!hcd)return -ENOMEM ; - hcd->rsrc_start = res.start; - hcd->rsrc_len =resource_size (&res); - - irq =irq_of_parse_and_map (dn,0 ); -if (!irq) { -dev_err (&op->dev,"%s: irq_of_parse_and_map failed\n" , - __FILE__); - rv = -EBUSY ; - goto err_irq; - } - - hcd->regs =devm_ioremap_resource (&op->dev, &res); -if (IS_ERR (hcd->regs)) { - rv =PTR_ERR (hcd->regs); - goto err_ioremap; - } + hcd->regs = regs; + hcd->rsrc_start = res->start; + hcd->rsrc_len =resource_size (res); ehci =hcd_to_ehci (hcd); np =of_find_compatible_node (NULL ,NULL ,"ibm,usb-ohci-440epx" );if (np !=NULL ) {/* claim we really affected by usb23 erratum */ -if (!of_address_to_resource (np,0 , &res)) +if (!of_address_to_resource (np,0 , &ohci_res)) ehci->ohci_hcctrl_reg =devm_ioremap (&op->dev, - res.start +OHCI_HCCTRL_OFFSET , + ohci_res.start +OHCI_HCCTRL_OFFSET ,OHCI_HCCTRL_LEN );else pr_debug ("%s: no ohci offset in fdt\n" , __FILE__);
@@ -170,14 +161,12 @@ static int ehci_hcd_ppc_of_probe(struct platform_device *op) rv =usb_add_hcd (hcd, irq,0 );if (rv) - goto err_ioremap; + goto err;device_wakeup_enable (hcd->self.controller);return 0 ; -err_ioremap: -irq_dispose_mapping (irq); -err_irq: +err:usb_put_hcd (hcd);return rv;
@@ -196,8 +185,6 @@ static void ehci_hcd_ppc_of_remove(struct platform_device *op)usb_remove_hcd (hcd); -irq_dispose_mapping (hcd->irq); -/* use request_mem_region to test if the ohci driver is loaded. if so * ensure the ohci core is operational. */
Signature · 1 line
2.55.0