Skip to content

Commit

Permalink
Merge pull request #212 from wangzhimin1179/linux-6.6.y
Browse files Browse the repository at this point in the history
usb: phytium: Add support for Phytium USB controller
  • Loading branch information
opsiff authored Jun 25, 2024
2 parents 8056dd5 + 38ee0fb commit 546d0d9
Show file tree
Hide file tree
Showing 16 changed files with 7,718 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Documentation/devicetree/bindings/usb/phytium,usb2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/usb/phytium,usb2.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Phytium USBHS-DRD controller bindings

maintainers:
- Chen Baozi <[email protected]>

properties:
compatible:
const: phytium,usb2

reg:
items:
- description: USB controller registers
- description: PHY registers

interrupts:
maxItems: 1

dr_mode:
enum: [host, otg, peripheral]

required:
- compatible
- reg
- interrupts

additionalProperties: false

examples:
- |
usb2_0: usb2@31800000 {
compatible = "phytium,usb2";
reg = <0x0 0x31800000 0x0 0x80000>,
<0x0 0x31990000 0x0 0x10000>;
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
};
2 changes: 2 additions & 0 deletions drivers/usb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ source "drivers/usb/chipidea/Kconfig"

source "drivers/usb/isp1760/Kconfig"

source "drivers/usb/phytium/Kconfig"

comment "USB port drivers"

if USB
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ obj-$(CONFIG_USB_CDNS3) += cdns3/
obj-$(CONFIG_USB_CDNSP_PCI) += cdns3/

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

obj-$(CONFIG_USB_MON) += mon/
obj-$(CONFIG_USB_MTU3) += mtu3/
Expand Down
22 changes: 22 additions & 0 deletions drivers/usb/phytium/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
config USB_PHYTIUM
tristate "Phytium USB Support"
depends on USB
depends on USB_GADGET
help
Say Y or M here if your system has a OTG USB Controller based on PHYTIUM SOC.
like Pe220x.

If you choose to build this driver is a dynamically linked modules, the module will
be called phytium-usb.ko

config USB_PHYTIUM_PCI
tristate "Phytium PCI USB Support"
default n
depends on USB
depends on USB_GADGET
help
Say Y or M here if your system has a OTG USB Controller based on PHYTIUM SOC.
like Pe220x.

If you choose to build this driver is a dynamically linked modules, the module will
be called phytium-usb.ko
7 changes: 7 additions & 0 deletions drivers/usb/phytium/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: GPL-2.0

obj-$(CONFIG_USB_PHYTIUM) += phytium-usb.o
obj-$(CONFIG_USB_PHYTIUM_PCI) += phytium-usb-pci.o

phytium-usb-y := core.o dma.o platform.o host.o gadget.o
phytium-usb-pci-y := core.o dma.o pci.o host.o gadget.o
44 changes: 44 additions & 0 deletions drivers/usb/phytium/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: GPL-2.0

#include "core.h"

int phytium_core_reset(struct phytium_cusb *config, bool skip_wait)
{
if (!config)
return 0;

spin_lock_init(&config->lock);

return 0;
}

uint32_t phytium_read32(uint32_t *address)
{
return readl(address);
}

void phytium_write32(uint32_t *address, uint32_t value)
{
writel(value, address);
}

uint16_t phytium_read16(uint16_t *address)
{
return readw(address);
}

void phytium_write16(uint16_t *address, uint16_t value)
{
writew(value, address);
}

uint8_t phytium_read8(uint8_t *address)
{
return readb(address);
}

void phytium_write8(uint8_t *address, uint8_t value)
{
writeb(value, address);
}

98 changes: 98 additions & 0 deletions drivers/usb/phytium/core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __PHYTIUM_CORE_H__
#define __PHYTIUM_CORE_H__

#include <linux/usb/gadget.h>
#include <linux/usb/otg.h>
#include "host_api.h"
#include "gadget.h"

#define MAX_EPS_CHANNELS 16

struct phytium_ep {
struct phytium_cusb *config;
u16 max_packet;
u8 ep_num;
struct GADGET_EP *gadget_ep;
struct list_head req_list;
struct usb_ep end_point;
char name[12];
u8 is_tx;
const struct usb_endpoint_descriptor *desc;
u8 busy;
};

struct phytium_request {
struct usb_request request;
struct GADGET_REQ *gadget_request;
struct list_head list;
struct phytium_ep *ep;
struct phytium_cusb *config;
u8 is_tx;
u8 epnum;
};

struct phytium_cusb {
struct device *dev;
void __iomem *regs;
void __iomem *phy_regs;
int irq;
spinlock_t lock;
enum usb_dr_mode dr_mode;

struct GADGET_OBJ *gadget_obj;
struct GADGET_CFG gadget_cfg;
struct GADGET_CALLBACKS gadget_callbacks;
struct GADGET_SYSREQ gadget_sysreq;
struct GADGET_DEV *gadget_dev;
void *gadget_priv;

struct usb_gadget gadget;
struct usb_gadget_driver *gadget_driver;
struct phytium_ep endpoints_tx[MAX_EPS_CHANNELS];
struct phytium_ep endpoints_rx[MAX_EPS_CHANNELS];
u8 ep0_data_stage_is_tx;

struct HOST_OBJ *host_obj;
struct HOST_CFG host_cfg;
struct HOST_CALLBACKS host_callbacks;
struct HOST_SYSREQ host_sysreq;
void *host_priv;
struct usb_hcd *hcd;

struct DMA_OBJ *dma_obj;
struct DMA_CFG dma_cfg;
struct DMA_CALLBACKS dma_callbacks;
struct DMA_SYSREQ dma_sysreq;
bool isVhubHost;
};

int phytium_core_reset(struct phytium_cusb *config, bool skip_wait);

int phytium_host_init(struct phytium_cusb *config);
int phytium_host_uninit(struct phytium_cusb *config);

#ifdef CONFIG_PM
int phytium_host_resume(void *priv);
int phytium_host_suspend(void *priv);
int phytium_gadget_resume(void *priv);
int phytium_gadget_suspend(void *priv);
#endif

int phytium_gadget_init(struct phytium_cusb *config);
int phytium_gadget_uninit(struct phytium_cusb *config);

uint32_t phytium_read32(uint32_t *address);

void phytium_write32(uint32_t *address, uint32_t value);

uint16_t phytium_read16(uint16_t *address);

void phytium_write16(uint16_t *address, uint16_t value);

uint8_t phytium_read8(uint8_t *address);

void phytium_write8(uint8_t *address, uint8_t value);

#endif
Loading

0 comments on commit 546d0d9

Please sign in to comment.