Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb: phytium: Add support for Phytium USB controller #140

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议和飞腾其它驱动配置项保持一致,PHYTIUM改为Phytium

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