Skip to content

Commit 4efb2f6

Browse files
shimodaygregkh
authored andcommitted
usb: host: xhci-plat: add struct xhci_plat_priv
This patch adds struct xhci_plat_priv to simplify the code to match platform specific variables. For now, this patch adds a member "type" in the structure. Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 79a17dd commit 4efb2f6

File tree

2 files changed

+85
-25
lines changed

2 files changed

+85
-25
lines changed

drivers/usb/host/xhci-plat.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/acpi.h>
2323

2424
#include "xhci.h"
25+
#include "xhci-plat.h"
2526
#include "xhci-mvebu.h"
2627
#include "xhci-rcar.h"
2728

@@ -31,6 +32,7 @@ static int xhci_plat_setup(struct usb_hcd *hcd);
3132
static int xhci_plat_start(struct usb_hcd *hcd);
3233

3334
static const struct xhci_driver_overrides xhci_plat_overrides __initconst = {
35+
.extra_priv_size = sizeof(struct xhci_plat_priv),
3436
.reset = xhci_plat_setup,
3537
.start = xhci_plat_start,
3638
};
@@ -48,11 +50,9 @@ static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
4850
/* called during probe() after chip reset completes */
4951
static int xhci_plat_setup(struct usb_hcd *hcd)
5052
{
51-
struct device_node *of_node = hcd->self.controller->of_node;
5253
int ret;
5354

54-
if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
55-
of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) {
55+
if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2)) {
5656
ret = xhci_rcar_init_quirk(hcd);
5757
if (ret)
5858
return ret;
@@ -63,19 +63,49 @@ static int xhci_plat_setup(struct usb_hcd *hcd)
6363

6464
static int xhci_plat_start(struct usb_hcd *hcd)
6565
{
66-
struct device_node *of_node = hcd->self.controller->of_node;
67-
68-
if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
69-
of_device_is_compatible(of_node, "renesas,xhci-r8a7791"))
66+
if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2))
7067
xhci_rcar_start(hcd);
7168

7269
return xhci_run(hcd);
7370
}
7471

72+
#ifdef CONFIG_OF
73+
static const struct xhci_plat_priv xhci_plat_marvell_armada = {
74+
.type = XHCI_PLAT_TYPE_MARVELL_ARMADA,
75+
};
76+
77+
static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = {
78+
.type = XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2,
79+
};
80+
81+
static const struct of_device_id usb_xhci_of_match[] = {
82+
{
83+
.compatible = "generic-xhci",
84+
}, {
85+
.compatible = "xhci-platform",
86+
}, {
87+
.compatible = "marvell,armada-375-xhci",
88+
.data = &xhci_plat_marvell_armada,
89+
}, {
90+
.compatible = "marvell,armada-380-xhci",
91+
.data = &xhci_plat_marvell_armada,
92+
}, {
93+
.compatible = "renesas,xhci-r8a7790",
94+
.data = &xhci_plat_renesas_rcar_gen2,
95+
}, {
96+
.compatible = "renesas,xhci-r8a7791",
97+
.data = &xhci_plat_renesas_rcar_gen2,
98+
}, {
99+
},
100+
};
101+
MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
102+
#endif
103+
75104
static int xhci_plat_probe(struct platform_device *pdev)
76105
{
77106
struct device_node *node = pdev->dev.of_node;
78107
struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
108+
const struct of_device_id *match;
79109
const struct hc_driver *driver;
80110
struct xhci_hcd *xhci;
81111
struct resource *res;
@@ -133,18 +163,24 @@ static int xhci_plat_probe(struct platform_device *pdev)
133163
goto put_hcd;
134164
}
135165

136-
if (of_device_is_compatible(pdev->dev.of_node,
137-
"marvell,armada-375-xhci") ||
138-
of_device_is_compatible(pdev->dev.of_node,
139-
"marvell,armada-380-xhci")) {
166+
xhci = hcd_to_xhci(hcd);
167+
match = of_match_node(usb_xhci_of_match, node);
168+
if (match) {
169+
const struct xhci_plat_priv *priv_match = match->data;
170+
struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
171+
172+
/* Just copy data for now */
173+
*priv = *priv_match;
174+
}
175+
176+
if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_MARVELL_ARMADA)) {
140177
ret = xhci_mvebu_mbus_init_quirk(pdev);
141178
if (ret)
142179
goto disable_clk;
143180
}
144181

145182
device_wakeup_enable(hcd->self.controller);
146183

147-
xhci = hcd_to_xhci(hcd);
148184
xhci->clk = clk;
149185
xhci->main_hcd = hcd;
150186
xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
@@ -255,19 +291,6 @@ static const struct dev_pm_ops xhci_plat_pm_ops = {
255291
#define DEV_PM_OPS NULL
256292
#endif /* CONFIG_PM */
257293

258-
#ifdef CONFIG_OF
259-
static const struct of_device_id usb_xhci_of_match[] = {
260-
{ .compatible = "generic-xhci" },
261-
{ .compatible = "xhci-platform" },
262-
{ .compatible = "marvell,armada-375-xhci"},
263-
{ .compatible = "marvell,armada-380-xhci"},
264-
{ .compatible = "renesas,xhci-r8a7790"},
265-
{ .compatible = "renesas,xhci-r8a7791"},
266-
{ },
267-
};
268-
MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
269-
#endif
270-
271294
static const struct acpi_device_id usb_xhci_acpi_match[] = {
272295
/* XHCI-compliant USB Controller */
273296
{ "PNP0D10", },

drivers/usb/host/xhci-plat.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* xhci-plat.h - xHCI host controller driver platform Bus Glue.
3+
*
4+
* Copyright (C) 2015 Renesas Electronics Corporation
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* version 2 as published by the Free Software Foundation.
9+
*/
10+
11+
#ifndef _XHCI_PLAT_H
12+
#define _XHCI_PLAT_H
13+
14+
#include "xhci.h" /* for hcd_to_xhci() */
15+
16+
enum xhci_plat_type {
17+
XHCI_PLAT_TYPE_MARVELL_ARMADA,
18+
XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2,
19+
};
20+
21+
struct xhci_plat_priv {
22+
enum xhci_plat_type type;
23+
};
24+
25+
#define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv)
26+
27+
static inline bool xhci_plat_type_is(struct usb_hcd *hcd,
28+
enum xhci_plat_type type)
29+
{
30+
struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
31+
32+
if (priv && priv->type == type)
33+
return true;
34+
else
35+
return false;
36+
}
37+
#endif /* _XHCI_PLAT_H */

0 commit comments

Comments
 (0)