Skip to content

Commit e16d5f1

Browse files
YinboZhugregkh
authored andcommitted
usb: dwc2: add pci_device_id driver_data parse support
The dwc2 driver has everything we need to run in PCI mode except for pci_device_id driver_data parse. With that to set Loongson dwc2 element and added identified as PCI_VENDOR_ID_LOONGSON and PCI_DEVICE_ID_LOONGSON_DWC2 in dwc2_pci_ids, the Loongson dwc2 controller will work. Signed-off-by: Yinbo Zhu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 333ab99 commit e16d5f1

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

drivers/usb/dwc2/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
13301330
/* The device ID match table */
13311331
extern const struct of_device_id dwc2_of_match_table[];
13321332
extern const struct acpi_device_id dwc2_acpi_match[];
1333+
extern const struct pci_device_id dwc2_pci_ids[];
13331334

13341335
int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
13351336
int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);

drivers/usb/dwc2/params.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
#include <linux/module.h>
88
#include <linux/of_device.h>
99
#include <linux/usb/of.h>
10+
#include <linux/pci_ids.h>
11+
#include <linux/pci.h>
1012

1113
#include "core.h"
1214

15+
#define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
16+
#define PCI_DEVICE_ID_LOONGSON_DWC2 0x7a04
17+
1318
static void dwc2_set_bcm_params(struct dwc2_hsotg *hsotg)
1419
{
1520
struct dwc2_core_params *p = &hsotg->params;
@@ -55,6 +60,14 @@ static void dwc2_set_jz4775_params(struct dwc2_hsotg *hsotg)
5560
!device_property_read_bool(hsotg->dev, "disable-over-current");
5661
}
5762

63+
static void dwc2_set_loongson_params(struct dwc2_hsotg *hsotg)
64+
{
65+
struct dwc2_core_params *p = &hsotg->params;
66+
67+
p->phy_utmi_width = 8;
68+
p->power_down = DWC2_POWER_DOWN_PARAM_PARTIAL;
69+
}
70+
5871
static void dwc2_set_x1600_params(struct dwc2_hsotg *hsotg)
5972
{
6073
struct dwc2_core_params *p = &hsotg->params;
@@ -302,6 +315,23 @@ const struct acpi_device_id dwc2_acpi_match[] = {
302315
};
303316
MODULE_DEVICE_TABLE(acpi, dwc2_acpi_match);
304317

318+
const struct pci_device_id dwc2_pci_ids[] = {
319+
{
320+
PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
321+
},
322+
{
323+
PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
324+
PCI_DEVICE_ID_STMICRO_USB_OTG),
325+
},
326+
{
327+
PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_DWC2),
328+
.driver_data = (unsigned long)dwc2_set_loongson_params,
329+
},
330+
{ /* end: all zeroes */ }
331+
};
332+
MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
333+
EXPORT_SYMBOL_GPL(dwc2_pci_ids);
334+
305335
static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg)
306336
{
307337
switch (hsotg->hw_params.op_mode) {
@@ -948,13 +978,20 @@ int dwc2_init_params(struct dwc2_hsotg *hsotg)
948978
if (match && match->data) {
949979
set_params = match->data;
950980
set_params(hsotg);
951-
} else {
981+
} else if (!match) {
952982
const struct acpi_device_id *amatch;
983+
const struct pci_device_id *pmatch = NULL;
953984

954985
amatch = acpi_match_device(dwc2_acpi_match, hsotg->dev);
955986
if (amatch && amatch->driver_data) {
956987
set_params = (set_params_cb)amatch->driver_data;
957988
set_params(hsotg);
989+
} else if (!amatch)
990+
pmatch = pci_match_id(dwc2_pci_ids, to_pci_dev(hsotg->dev->parent));
991+
992+
if (pmatch && pmatch->driver_data) {
993+
set_params = (set_params_cb)pmatch->driver_data;
994+
set_params(hsotg);
958995
}
959996
}
960997

drivers/usb/dwc2/pci.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <linux/platform_device.h>
2525
#include <linux/usb/usb_phy_generic.h>
2626

27-
#define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
27+
#include "core.h"
2828

2929
static const char dwc2_driver_name[] = "dwc2-pci";
3030

@@ -122,18 +122,6 @@ static int dwc2_pci_probe(struct pci_dev *pci,
122122
return ret;
123123
}
124124

125-
static const struct pci_device_id dwc2_pci_ids[] = {
126-
{
127-
PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
128-
},
129-
{
130-
PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
131-
PCI_DEVICE_ID_STMICRO_USB_OTG),
132-
},
133-
{ /* end: all zeroes */ }
134-
};
135-
MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
136-
137125
static struct pci_driver dwc2_pci_driver = {
138126
.name = dwc2_driver_name,
139127
.id_table = dwc2_pci_ids,

0 commit comments

Comments
 (0)