usb: host: xhci-rcar: Avoid repeated matching
Subsystems (3)
Geert Uytterhoeven
maintainercover usb: host: xhci-rcar: Avoid repeated matching
Hi all,
On R-Car Gen2 and Gen3, the .plat_start() callback checks the XHCI's controller compatible value on each call, which happens multiple times during the lifetime of the device. This series fixes that by using separate .plat_start() callbacks, reducing source and binary size in the process.
This has been tested on R-Car H2 (Lager, disable pci2 first), and R-Car H3 ES2.0 (Salvator-XS).
Thanks for your comments
Geert Uytterhoeven (2):
usb: host: xhci-rcar: Remove SET_XHCI_PLAT_PRIV_FOR_RCAR() macro
usb: host: xhci-rcar: Split R-Car Gen2 and Gen3 .plat_start() handling
drivers/usb/host/xhci-rcar.c | 70 +++++++++++++++++------------------- 1 file changed, 33 insertions(+), 37 deletions(-)
Signature · 12 lines
2.43.0
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsGeert Uytterhoeven
maintainerPATCH 1/2 usb: host: xhci-rcar: Remove SET_XHCI_PLAT_PRIV_FOR_RCAR() macro
The SET_XHCI_PLAT_PRIV_FOR_RCAR() macro does not add much value (there are only two users), and stands in the way of handling differences between R-Car Gen2 and Gen3. Remove it.
--- drivers/usb/host/xhci-rcar.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rcar.c +10 -9
@@ -213,19 +213,20 @@ static int xhci_rcar_resume_quirk(struct usb_hcd *hcd)* long delay for the handshake of STS_HALT is neeed in xhci_suspend() * by using the XHCI_SLOW_SUSPEND quirk. */ -#define SET_XHCI_PLAT_PRIV_FOR_RCAR (firmware) \ - .firmware_name = firmware, \ - .quirks = XHCI_NO_64BIT_SUPPORT | XHCI_SLOW_SUSPEND, \ - .init_quirk = xhci_rcar_init_quirk, \ - .plat_start = xhci_rcar_start, \ - .resume_quirk = xhci_rcar_resume_quirk, -static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = { -SET_XHCI_PLAT_PRIV_FOR_RCAR (XHCI_RCAR_FIRMWARE_NAME_V1 ) + .firmware_name =XHCI_RCAR_FIRMWARE_NAME_V1 , + .quirks =XHCI_NO_64BIT_SUPPORT |XHCI_SLOW_SUSPEND , + .init_quirk = xhci_rcar_init_quirk, + .plat_start = xhci_rcar_start, + .resume_quirk = xhci_rcar_resume_quirk, };static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = { -SET_XHCI_PLAT_PRIV_FOR_RCAR (XHCI_RCAR_FIRMWARE_NAME_V3 ) + .firmware_name =XHCI_RCAR_FIRMWARE_NAME_V3 , + .quirks =XHCI_NO_64BIT_SUPPORT |XHCI_SLOW_SUSPEND , + .init_quirk = xhci_rcar_init_quirk, + .plat_start = xhci_rcar_start, + .resume_quirk = xhci_rcar_resume_quirk, };static const struct xhci_plat_priv xhci_plat_renesas_rzv2m = {
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH 2/2 usb: host: xhci-rcar: Split R-Car Gen2 and Gen3 .plat_start() handling
In reply to Geert UytterhoevenCurrently, R-Car Gen2 and Gen3 share the same .plat_start() callback. However, this single callback performs different operations, after checking the XHCI's controller compatible value.
Avoid repeated checking of compatible values and reduce kernel size by splitting this method in two separate functions. Update xhci_rcar_resume_quirk() to dispatch to the correct method by calling it through the .plat_start() function pointer, too.
--- drivers/usb/host/xhci-rcar.c | 53 ++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 29 deletions(-)
drivers/usb/host/xhci-rcar.c +24 -29
@@ -32,29 +32,6 @@MODULE_FIRMWARE (XHCI_RCAR_FIRMWARE_NAME_V1 );MODULE_FIRMWARE (XHCI_RCAR_FIRMWARE_NAME_V3 ); -static void xhci_rcar_start_gen2 (struct usb_hcd *hcd) -{ -/* LCLK Select */ -writel (RCAR_USB3_LCLK_ENA_VAL , hcd->regs +RCAR_USB3_LCLK ); -/* USB3.0 Configuration */ -writel (RCAR_USB3_CONF1_VAL , hcd->regs +RCAR_USB3_CONF1 ); -writel (RCAR_USB3_CONF2_VAL , hcd->regs +RCAR_USB3_CONF2 ); -writel (RCAR_USB3_CONF3_VAL , hcd->regs +RCAR_USB3_CONF3 ); -/* USB3.0 Polarity */ -writel (RCAR_USB3_RX_POL_VAL , hcd->regs +RCAR_USB3_RX_POL ); -writel (RCAR_USB3_TX_POL_VAL , hcd->regs +RCAR_USB3_TX_POL ); -} - -static int xhci_rcar_is_gen2 (struct device *dev) -{ -struct device_node *node = dev->of_node; - -return of_device_is_compatible (node,"renesas,xhci-r8a7790" ) || -of_device_is_compatible (node,"renesas,xhci-r8a7791" ) || -of_device_is_compatible (node,"renesas,xhci-r8a7793" ) || -of_device_is_compatible (node,"renesas,rcar-gen2-xhci" ); -} -static void xhci_rcar_start (struct usb_hcd *hcd) {u32 temp;
@@ -64,8 +41,23 @@ static void xhci_rcar_start(struct usb_hcd *hcd) temp =readl (hcd->regs +RCAR_USB3_INT_ENA ); temp |=RCAR_USB3_INT_ENA_VAL ;writel (temp, hcd->regs +RCAR_USB3_INT_ENA ); -if (xhci_rcar_is_gen2 (hcd->self.controller)) -xhci_rcar_start_gen2 (hcd); + } +} + +static void xhci_rcar_gen2_start (struct usb_hcd *hcd) +{ +if (hcd->regs !=NULL ) { +xhci_rcar_start (hcd); + +/* LCLK Select */ +writel (RCAR_USB3_LCLK_ENA_VAL , hcd->regs +RCAR_USB3_LCLK ); +/* USB3.0 Configuration */ +writel (RCAR_USB3_CONF1_VAL , hcd->regs +RCAR_USB3_CONF1 ); +writel (RCAR_USB3_CONF2_VAL , hcd->regs +RCAR_USB3_CONF2 ); +writel (RCAR_USB3_CONF3_VAL , hcd->regs +RCAR_USB3_CONF3 ); +/* USB3.0 Polarity */ +writel (RCAR_USB3_RX_POL_VAL , hcd->regs +RCAR_USB3_RX_POL ); +writel (RCAR_USB3_TX_POL_VAL , hcd->regs +RCAR_USB3_TX_POL ); } }
@@ -192,13 +184,16 @@ static int xhci_rcar_init_quirk(struct usb_hcd *hcd)static int xhci_rcar_resume_quirk (struct usb_hcd *hcd) { +struct xhci_plat_priv *priv;int ret; ret =xhci_rcar_download_firmware (hcd); -if (!ret) -xhci_rcar_start (hcd); +if (ret) +return ret; -return ret; + priv =hcd_to_xhci_priv (hcd); + priv->plat_start (hcd); +return 0 ; }/*
@@ -217,7 +212,7 @@ static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = { .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V1, .quirks = XHCI_NO_64BIT_SUPPORT | XHCI_SLOW_SUSPEND, .init_quirk = xhci_rcar_init_quirk, - .plat_start = xhci_rcar_start, + .plat_start = xhci_rcar_gen2_start, .resume_quirk = xhci_rcar_resume_quirk, };
Signature · 1 line
2.43.0