Skip to content

Commit 546d0d9

Browse files
authored
Merge pull request #212 from wangzhimin1179/linux-6.6.y
usb: phytium: Add support for Phytium USB controller
2 parents 8056dd5 + 38ee0fb commit 546d0d9

File tree

16 files changed

+7718
-0
lines changed

16 files changed

+7718
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/usb/phytium,usb2.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Phytium USBHS-DRD controller bindings
8+
9+
maintainers:
10+
- Chen Baozi <[email protected]>
11+
12+
properties:
13+
compatible:
14+
const: phytium,usb2
15+
16+
reg:
17+
items:
18+
- description: USB controller registers
19+
- description: PHY registers
20+
21+
interrupts:
22+
maxItems: 1
23+
24+
dr_mode:
25+
enum: [host, otg, peripheral]
26+
27+
required:
28+
- compatible
29+
- reg
30+
- interrupts
31+
32+
additionalProperties: false
33+
34+
examples:
35+
- |
36+
usb2_0: usb2@31800000 {
37+
compatible = "phytium,usb2";
38+
reg = <0x0 0x31800000 0x0 0x80000>,
39+
<0x0 0x31990000 0x0 0x10000>;
40+
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
41+
};

drivers/usb/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ source "drivers/usb/chipidea/Kconfig"
129129

130130
source "drivers/usb/isp1760/Kconfig"
131131

132+
source "drivers/usb/phytium/Kconfig"
133+
132134
comment "USB port drivers"
133135

134136
if USB

drivers/usb/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ obj-$(CONFIG_USB_CDNS3) += cdns3/
1818
obj-$(CONFIG_USB_CDNSP_PCI) += cdns3/
1919

2020
obj-$(CONFIG_USB_FOTG210) += fotg210/
21+
obj-$(CONFIG_USB_PHYTIUM) += phytium/
2122

2223
obj-$(CONFIG_USB_MON) += mon/
2324
obj-$(CONFIG_USB_MTU3) += mtu3/

drivers/usb/phytium/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
config USB_PHYTIUM
2+
tristate "Phytium USB Support"
3+
depends on USB
4+
depends on USB_GADGET
5+
help
6+
Say Y or M here if your system has a OTG USB Controller based on PHYTIUM SOC.
7+
like Pe220x.
8+
9+
If you choose to build this driver is a dynamically linked modules, the module will
10+
be called phytium-usb.ko
11+
12+
config USB_PHYTIUM_PCI
13+
tristate "Phytium PCI USB Support"
14+
default n
15+
depends on USB
16+
depends on USB_GADGET
17+
help
18+
Say Y or M here if your system has a OTG USB Controller based on PHYTIUM SOC.
19+
like Pe220x.
20+
21+
If you choose to build this driver is a dynamically linked modules, the module will
22+
be called phytium-usb.ko

drivers/usb/phytium/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
obj-$(CONFIG_USB_PHYTIUM) += phytium-usb.o
4+
obj-$(CONFIG_USB_PHYTIUM_PCI) += phytium-usb-pci.o
5+
6+
phytium-usb-y := core.o dma.o platform.o host.o gadget.o
7+
phytium-usb-pci-y := core.o dma.o pci.o host.o gadget.o

drivers/usb/phytium/core.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "core.h"
4+
5+
int phytium_core_reset(struct phytium_cusb *config, bool skip_wait)
6+
{
7+
if (!config)
8+
return 0;
9+
10+
spin_lock_init(&config->lock);
11+
12+
return 0;
13+
}
14+
15+
uint32_t phytium_read32(uint32_t *address)
16+
{
17+
return readl(address);
18+
}
19+
20+
void phytium_write32(uint32_t *address, uint32_t value)
21+
{
22+
writel(value, address);
23+
}
24+
25+
uint16_t phytium_read16(uint16_t *address)
26+
{
27+
return readw(address);
28+
}
29+
30+
void phytium_write16(uint16_t *address, uint16_t value)
31+
{
32+
writew(value, address);
33+
}
34+
35+
uint8_t phytium_read8(uint8_t *address)
36+
{
37+
return readb(address);
38+
}
39+
40+
void phytium_write8(uint8_t *address, uint8_t value)
41+
{
42+
writeb(value, address);
43+
}
44+

drivers/usb/phytium/core.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __PHYTIUM_CORE_H__
4+
#define __PHYTIUM_CORE_H__
5+
6+
#include <linux/usb/gadget.h>
7+
#include <linux/usb/otg.h>
8+
#include "host_api.h"
9+
#include "gadget.h"
10+
11+
#define MAX_EPS_CHANNELS 16
12+
13+
struct phytium_ep {
14+
struct phytium_cusb *config;
15+
u16 max_packet;
16+
u8 ep_num;
17+
struct GADGET_EP *gadget_ep;
18+
struct list_head req_list;
19+
struct usb_ep end_point;
20+
char name[12];
21+
u8 is_tx;
22+
const struct usb_endpoint_descriptor *desc;
23+
u8 busy;
24+
};
25+
26+
struct phytium_request {
27+
struct usb_request request;
28+
struct GADGET_REQ *gadget_request;
29+
struct list_head list;
30+
struct phytium_ep *ep;
31+
struct phytium_cusb *config;
32+
u8 is_tx;
33+
u8 epnum;
34+
};
35+
36+
struct phytium_cusb {
37+
struct device *dev;
38+
void __iomem *regs;
39+
void __iomem *phy_regs;
40+
int irq;
41+
spinlock_t lock;
42+
enum usb_dr_mode dr_mode;
43+
44+
struct GADGET_OBJ *gadget_obj;
45+
struct GADGET_CFG gadget_cfg;
46+
struct GADGET_CALLBACKS gadget_callbacks;
47+
struct GADGET_SYSREQ gadget_sysreq;
48+
struct GADGET_DEV *gadget_dev;
49+
void *gadget_priv;
50+
51+
struct usb_gadget gadget;
52+
struct usb_gadget_driver *gadget_driver;
53+
struct phytium_ep endpoints_tx[MAX_EPS_CHANNELS];
54+
struct phytium_ep endpoints_rx[MAX_EPS_CHANNELS];
55+
u8 ep0_data_stage_is_tx;
56+
57+
struct HOST_OBJ *host_obj;
58+
struct HOST_CFG host_cfg;
59+
struct HOST_CALLBACKS host_callbacks;
60+
struct HOST_SYSREQ host_sysreq;
61+
void *host_priv;
62+
struct usb_hcd *hcd;
63+
64+
struct DMA_OBJ *dma_obj;
65+
struct DMA_CFG dma_cfg;
66+
struct DMA_CALLBACKS dma_callbacks;
67+
struct DMA_SYSREQ dma_sysreq;
68+
bool isVhubHost;
69+
};
70+
71+
int phytium_core_reset(struct phytium_cusb *config, bool skip_wait);
72+
73+
int phytium_host_init(struct phytium_cusb *config);
74+
int phytium_host_uninit(struct phytium_cusb *config);
75+
76+
#ifdef CONFIG_PM
77+
int phytium_host_resume(void *priv);
78+
int phytium_host_suspend(void *priv);
79+
int phytium_gadget_resume(void *priv);
80+
int phytium_gadget_suspend(void *priv);
81+
#endif
82+
83+
int phytium_gadget_init(struct phytium_cusb *config);
84+
int phytium_gadget_uninit(struct phytium_cusb *config);
85+
86+
uint32_t phytium_read32(uint32_t *address);
87+
88+
void phytium_write32(uint32_t *address, uint32_t value);
89+
90+
uint16_t phytium_read16(uint16_t *address);
91+
92+
void phytium_write16(uint16_t *address, uint16_t value);
93+
94+
uint8_t phytium_read8(uint8_t *address);
95+
96+
void phytium_write8(uint8_t *address, uint8_t value);
97+
98+
#endif

0 commit comments

Comments
 (0)