Skip to content

Commit

Permalink
usb: phytium: Add support for Phytium USB controller
Browse files Browse the repository at this point in the history
This patch adds the Phytium USBHS DRD controller support.

Signed-off-by: Wang Zhimin <[email protected]>
Signed-off-by: Li Mingzhe <[email protected]>
Signed-off-by: Zuo Qian <[email protected]>
Signed-off-by: Chen Zhenhua <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
  • Loading branch information
Chen Zhenhua authored and wangzhimin1179 committed May 14, 2024
1 parent f9eead8 commit 26095b2
Show file tree
Hide file tree
Showing 15 changed files with 7,685 additions and 0 deletions.
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 26095b2

Please sign in to comment.