18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * c67x00.h: Cypress C67X00 USB register and field definitions 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2006-2008 Barco N.V. 68c2ecf20Sopenharmony_ci * Derived from the Cypress cy7c67200/300 ezusb linux driver and 78c2ecf20Sopenharmony_ci * based on multiple host controller drivers inside the linux kernel. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _USB_C67X00_H 118c2ecf20Sopenharmony_ci#define _USB_C67X00_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 148c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 158c2ecf20Sopenharmony_ci#include <linux/completion.h> 168c2ecf20Sopenharmony_ci#include <linux/mutex.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* --------------------------------------------------------------------- 198c2ecf20Sopenharmony_ci * Cypress C67x00 register definitions 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* Hardware Revision Register */ 238c2ecf20Sopenharmony_ci#define HW_REV_REG 0xC004 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* General USB registers */ 268c2ecf20Sopenharmony_ci/* ===================== */ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* USB Control Register */ 298c2ecf20Sopenharmony_ci#define USB_CTL_REG(x) ((x) ? 0xC0AA : 0xC08A) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define LOW_SPEED_PORT(x) ((x) ? 0x0800 : 0x0400) 328c2ecf20Sopenharmony_ci#define HOST_MODE 0x0200 338c2ecf20Sopenharmony_ci#define PORT_RES_EN(x) ((x) ? 0x0100 : 0x0080) 348c2ecf20Sopenharmony_ci#define SOF_EOP_EN(x) ((x) ? 0x0002 : 0x0001) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* USB status register - Notice it has different content in hcd/udc mode */ 378c2ecf20Sopenharmony_ci#define USB_STAT_REG(x) ((x) ? 0xC0B0 : 0xC090) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define EP0_IRQ_FLG 0x0001 408c2ecf20Sopenharmony_ci#define EP1_IRQ_FLG 0x0002 418c2ecf20Sopenharmony_ci#define EP2_IRQ_FLG 0x0004 428c2ecf20Sopenharmony_ci#define EP3_IRQ_FLG 0x0008 438c2ecf20Sopenharmony_ci#define EP4_IRQ_FLG 0x0010 448c2ecf20Sopenharmony_ci#define EP5_IRQ_FLG 0x0020 458c2ecf20Sopenharmony_ci#define EP6_IRQ_FLG 0x0040 468c2ecf20Sopenharmony_ci#define EP7_IRQ_FLG 0x0080 478c2ecf20Sopenharmony_ci#define RESET_IRQ_FLG 0x0100 488c2ecf20Sopenharmony_ci#define SOF_EOP_IRQ_FLG 0x0200 498c2ecf20Sopenharmony_ci#define ID_IRQ_FLG 0x4000 508c2ecf20Sopenharmony_ci#define VBUS_IRQ_FLG 0x8000 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* USB Host only registers */ 538c2ecf20Sopenharmony_ci/* ======================= */ 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* Host n Control Register */ 568c2ecf20Sopenharmony_ci#define HOST_CTL_REG(x) ((x) ? 0xC0A0 : 0xC080) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define PREAMBLE_EN 0x0080 /* Preamble enable */ 598c2ecf20Sopenharmony_ci#define SEQ_SEL 0x0040 /* Data Toggle Sequence Bit Select */ 608c2ecf20Sopenharmony_ci#define ISO_EN 0x0010 /* Isochronous enable */ 618c2ecf20Sopenharmony_ci#define ARM_EN 0x0001 /* Arm operation */ 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* Host n Interrupt Enable Register */ 648c2ecf20Sopenharmony_ci#define HOST_IRQ_EN_REG(x) ((x) ? 0xC0AC : 0xC08C) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define SOF_EOP_IRQ_EN 0x0200 /* SOF/EOP Interrupt Enable */ 678c2ecf20Sopenharmony_ci#define SOF_EOP_TMOUT_IRQ_EN 0x0800 /* SOF/EOP Timeout Interrupt Enable */ 688c2ecf20Sopenharmony_ci#define ID_IRQ_EN 0x4000 /* ID interrupt enable */ 698c2ecf20Sopenharmony_ci#define VBUS_IRQ_EN 0x8000 /* VBUS interrupt enable */ 708c2ecf20Sopenharmony_ci#define DONE_IRQ_EN 0x0001 /* Done Interrupt Enable */ 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* USB status register */ 738c2ecf20Sopenharmony_ci#define HOST_STAT_MASK 0x02FD 748c2ecf20Sopenharmony_ci#define PORT_CONNECT_CHANGE(x) ((x) ? 0x0020 : 0x0010) 758c2ecf20Sopenharmony_ci#define PORT_SE0_STATUS(x) ((x) ? 0x0008 : 0x0004) 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* Host Frame Register */ 788c2ecf20Sopenharmony_ci#define HOST_FRAME_REG(x) ((x) ? 0xC0B6 : 0xC096) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define HOST_FRAME_MASK 0x07FF 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* USB Peripheral only registers */ 838c2ecf20Sopenharmony_ci/* ============================= */ 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* Device n Port Sel reg */ 868c2ecf20Sopenharmony_ci#define DEVICE_N_PORT_SEL(x) ((x) ? 0xC0A4 : 0xC084) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Device n Interrupt Enable Register */ 898c2ecf20Sopenharmony_ci#define DEVICE_N_IRQ_EN_REG(x) ((x) ? 0xC0AC : 0xC08C) 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define DEVICE_N_ENDPOINT_N_CTL_REG(dev, ep) ((dev) \ 928c2ecf20Sopenharmony_ci ? (0x0280 + (ep << 4)) \ 938c2ecf20Sopenharmony_ci : (0x0200 + (ep << 4))) 948c2ecf20Sopenharmony_ci#define DEVICE_N_ENDPOINT_N_STAT_REG(dev, ep) ((dev) \ 958c2ecf20Sopenharmony_ci ? (0x0286 + (ep << 4)) \ 968c2ecf20Sopenharmony_ci : (0x0206 + (ep << 4))) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define DEVICE_N_ADDRESS(dev) ((dev) ? (0xC0AE) : (0xC08E)) 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* HPI registers */ 1018c2ecf20Sopenharmony_ci/* ============= */ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/* HPI Status register */ 1048c2ecf20Sopenharmony_ci#define SOFEOP_FLG(x) (1 << ((x) ? 12 : 10)) 1058c2ecf20Sopenharmony_ci#define SIEMSG_FLG(x) (1 << (4 + (x))) 1068c2ecf20Sopenharmony_ci#define RESET_FLG(x) ((x) ? 0x0200 : 0x0002) 1078c2ecf20Sopenharmony_ci#define DONE_FLG(x) (1 << (2 + (x))) 1088c2ecf20Sopenharmony_ci#define RESUME_FLG(x) (1 << (6 + (x))) 1098c2ecf20Sopenharmony_ci#define MBX_OUT_FLG 0x0001 /* Message out available */ 1108c2ecf20Sopenharmony_ci#define MBX_IN_FLG 0x0100 1118c2ecf20Sopenharmony_ci#define ID_FLG 0x4000 1128c2ecf20Sopenharmony_ci#define VBUS_FLG 0x8000 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* Interrupt routing register */ 1158c2ecf20Sopenharmony_ci#define HPI_IRQ_ROUTING_REG 0x0142 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define HPI_SWAP_ENABLE(x) ((x) ? 0x0100 : 0x0001) 1188c2ecf20Sopenharmony_ci#define RESET_TO_HPI_ENABLE(x) ((x) ? 0x0200 : 0x0002) 1198c2ecf20Sopenharmony_ci#define DONE_TO_HPI_ENABLE(x) ((x) ? 0x0008 : 0x0004) 1208c2ecf20Sopenharmony_ci#define RESUME_TO_HPI_ENABLE(x) ((x) ? 0x0080 : 0x0040) 1218c2ecf20Sopenharmony_ci#define SOFEOP_TO_HPI_EN(x) ((x) ? 0x2000 : 0x0800) 1228c2ecf20Sopenharmony_ci#define SOFEOP_TO_CPU_EN(x) ((x) ? 0x1000 : 0x0400) 1238c2ecf20Sopenharmony_ci#define ID_TO_HPI_ENABLE 0x4000 1248c2ecf20Sopenharmony_ci#define VBUS_TO_HPI_ENABLE 0x8000 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci/* SIE msg registers */ 1278c2ecf20Sopenharmony_ci#define SIEMSG_REG(x) ((x) ? 0x0148 : 0x0144) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define HUSB_TDListDone 0x1000 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define SUSB_EP0_MSG 0x0001 1328c2ecf20Sopenharmony_ci#define SUSB_EP1_MSG 0x0002 1338c2ecf20Sopenharmony_ci#define SUSB_EP2_MSG 0x0004 1348c2ecf20Sopenharmony_ci#define SUSB_EP3_MSG 0x0008 1358c2ecf20Sopenharmony_ci#define SUSB_EP4_MSG 0x0010 1368c2ecf20Sopenharmony_ci#define SUSB_EP5_MSG 0x0020 1378c2ecf20Sopenharmony_ci#define SUSB_EP6_MSG 0x0040 1388c2ecf20Sopenharmony_ci#define SUSB_EP7_MSG 0x0080 1398c2ecf20Sopenharmony_ci#define SUSB_RST_MSG 0x0100 1408c2ecf20Sopenharmony_ci#define SUSB_SOF_MSG 0x0200 1418c2ecf20Sopenharmony_ci#define SUSB_CFG_MSG 0x0400 1428c2ecf20Sopenharmony_ci#define SUSB_SUS_MSG 0x0800 1438c2ecf20Sopenharmony_ci#define SUSB_ID_MSG 0x4000 1448c2ecf20Sopenharmony_ci#define SUSB_VBUS_MSG 0x8000 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/* BIOS interrupt routines */ 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci#define SUSBx_RECEIVE_INT(x) ((x) ? 97 : 81) 1498c2ecf20Sopenharmony_ci#define SUSBx_SEND_INT(x) ((x) ? 96 : 80) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#define SUSBx_DEV_DESC_VEC(x) ((x) ? 0x00D4 : 0x00B4) 1528c2ecf20Sopenharmony_ci#define SUSBx_CONF_DESC_VEC(x) ((x) ? 0x00D6 : 0x00B6) 1538c2ecf20Sopenharmony_ci#define SUSBx_STRING_DESC_VEC(x) ((x) ? 0x00D8 : 0x00B8) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define CY_HCD_BUF_ADDR 0x500 /* Base address for host */ 1568c2ecf20Sopenharmony_ci#define SIE_TD_SIZE 0x200 /* size of the td list */ 1578c2ecf20Sopenharmony_ci#define SIE_TD_BUF_SIZE 0x400 /* size of the data buffer */ 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci#define SIE_TD_OFFSET(host) ((host) ? (SIE_TD_SIZE+SIE_TD_BUF_SIZE) : 0) 1608c2ecf20Sopenharmony_ci#define SIE_BUF_OFFSET(host) (SIE_TD_OFFSET(host) + SIE_TD_SIZE) 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/* Base address of HCD + 2 x TD_SIZE + 2 x TD_BUF_SIZE */ 1638c2ecf20Sopenharmony_ci#define CY_UDC_REQ_HEADER_BASE 0x1100 1648c2ecf20Sopenharmony_ci/* 8- byte request headers for IN/OUT transfers */ 1658c2ecf20Sopenharmony_ci#define CY_UDC_REQ_HEADER_SIZE 8 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci#define CY_UDC_REQ_HEADER_ADDR(ep_num) (CY_UDC_REQ_HEADER_BASE + \ 1688c2ecf20Sopenharmony_ci ((ep_num) * CY_UDC_REQ_HEADER_SIZE)) 1698c2ecf20Sopenharmony_ci#define CY_UDC_DESC_BASE_ADDRESS (CY_UDC_REQ_HEADER_ADDR(8)) 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#define CY_UDC_BIOS_REPLACE_BASE 0x1800 1728c2ecf20Sopenharmony_ci#define CY_UDC_REQ_BUFFER_BASE 0x2000 1738c2ecf20Sopenharmony_ci#define CY_UDC_REQ_BUFFER_SIZE 0x0400 1748c2ecf20Sopenharmony_ci#define CY_UDC_REQ_BUFFER_ADDR(ep_num) (CY_UDC_REQ_BUFFER_BASE + \ 1758c2ecf20Sopenharmony_ci ((ep_num) * CY_UDC_REQ_BUFFER_SIZE)) 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* --------------------------------------------------------------------- 1788c2ecf20Sopenharmony_ci * Driver data structures 1798c2ecf20Sopenharmony_ci */ 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistruct c67x00_device; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci/** 1848c2ecf20Sopenharmony_ci * struct c67x00_sie - Common data associated with a SIE 1858c2ecf20Sopenharmony_ci * @lock: lock to protect this struct and the associated chip registers 1868c2ecf20Sopenharmony_ci * @private_data: subdriver dependent data 1878c2ecf20Sopenharmony_ci * @irq: subdriver dependent irq handler, set NULL when not used 1888c2ecf20Sopenharmony_ci * @dev: link to common driver structure 1898c2ecf20Sopenharmony_ci * @sie_num: SIE number on chip, starting from 0 1908c2ecf20Sopenharmony_ci * @mode: SIE mode (host/peripheral/otg/not used) 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_cistruct c67x00_sie { 1938c2ecf20Sopenharmony_ci /* Entries to be used by the subdrivers */ 1948c2ecf20Sopenharmony_ci spinlock_t lock; /* protect this structure */ 1958c2ecf20Sopenharmony_ci void *private_data; 1968c2ecf20Sopenharmony_ci void (*irq) (struct c67x00_sie *sie, u16 int_status, u16 msg); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci /* Read only: */ 1998c2ecf20Sopenharmony_ci struct c67x00_device *dev; 2008c2ecf20Sopenharmony_ci int sie_num; 2018c2ecf20Sopenharmony_ci int mode; 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#define sie_dev(s) (&(s)->dev->pdev->dev) 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci/** 2078c2ecf20Sopenharmony_ci * struct c67x00_lcp 2088c2ecf20Sopenharmony_ci */ 2098c2ecf20Sopenharmony_cistruct c67x00_lcp { 2108c2ecf20Sopenharmony_ci /* Internal use only */ 2118c2ecf20Sopenharmony_ci struct mutex mutex; 2128c2ecf20Sopenharmony_ci struct completion msg_received; 2138c2ecf20Sopenharmony_ci u16 last_msg; 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/* 2178c2ecf20Sopenharmony_ci * struct c67x00_hpi 2188c2ecf20Sopenharmony_ci */ 2198c2ecf20Sopenharmony_cistruct c67x00_hpi { 2208c2ecf20Sopenharmony_ci void __iomem *base; 2218c2ecf20Sopenharmony_ci int regstep; 2228c2ecf20Sopenharmony_ci spinlock_t lock; 2238c2ecf20Sopenharmony_ci struct c67x00_lcp lcp; 2248c2ecf20Sopenharmony_ci}; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci#define C67X00_SIES 2 2278c2ecf20Sopenharmony_ci#define C67X00_PORTS 2 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci/** 2308c2ecf20Sopenharmony_ci * struct c67x00_device - Common data associated with a c67x00 instance 2318c2ecf20Sopenharmony_ci * @hpi: hpi addresses 2328c2ecf20Sopenharmony_ci * @sie: array of sie's on this chip 2338c2ecf20Sopenharmony_ci * @pdev: platform device of instance 2348c2ecf20Sopenharmony_ci * @pdata: configuration provided by the platform 2358c2ecf20Sopenharmony_ci */ 2368c2ecf20Sopenharmony_cistruct c67x00_device { 2378c2ecf20Sopenharmony_ci struct c67x00_hpi hpi; 2388c2ecf20Sopenharmony_ci struct c67x00_sie sie[C67X00_SIES]; 2398c2ecf20Sopenharmony_ci struct platform_device *pdev; 2408c2ecf20Sopenharmony_ci struct c67x00_platform_data *pdata; 2418c2ecf20Sopenharmony_ci}; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci/* --------------------------------------------------------------------- 2448c2ecf20Sopenharmony_ci * Low level interface functions 2458c2ecf20Sopenharmony_ci */ 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci/* Host Port Interface (HPI) functions */ 2488c2ecf20Sopenharmony_ciu16 c67x00_ll_hpi_status(struct c67x00_device *dev); 2498c2ecf20Sopenharmony_civoid c67x00_ll_hpi_reg_init(struct c67x00_device *dev); 2508c2ecf20Sopenharmony_civoid c67x00_ll_hpi_enable_sofeop(struct c67x00_sie *sie); 2518c2ecf20Sopenharmony_civoid c67x00_ll_hpi_disable_sofeop(struct c67x00_sie *sie); 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci/* General functions */ 2548c2ecf20Sopenharmony_ciu16 c67x00_ll_fetch_siemsg(struct c67x00_device *dev, int sie_num); 2558c2ecf20Sopenharmony_ciu16 c67x00_ll_get_usb_ctl(struct c67x00_sie *sie); 2568c2ecf20Sopenharmony_civoid c67x00_ll_usb_clear_status(struct c67x00_sie *sie, u16 bits); 2578c2ecf20Sopenharmony_ciu16 c67x00_ll_usb_get_status(struct c67x00_sie *sie); 2588c2ecf20Sopenharmony_civoid c67x00_ll_write_mem_le16(struct c67x00_device *dev, u16 addr, 2598c2ecf20Sopenharmony_ci void *data, int len); 2608c2ecf20Sopenharmony_civoid c67x00_ll_read_mem_le16(struct c67x00_device *dev, u16 addr, 2618c2ecf20Sopenharmony_ci void *data, int len); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci/* Host specific functions */ 2648c2ecf20Sopenharmony_civoid c67x00_ll_set_husb_eot(struct c67x00_device *dev, u16 value); 2658c2ecf20Sopenharmony_civoid c67x00_ll_husb_reset(struct c67x00_sie *sie, int port); 2668c2ecf20Sopenharmony_civoid c67x00_ll_husb_set_current_td(struct c67x00_sie *sie, u16 addr); 2678c2ecf20Sopenharmony_ciu16 c67x00_ll_husb_get_current_td(struct c67x00_sie *sie); 2688c2ecf20Sopenharmony_ciu16 c67x00_ll_husb_get_frame(struct c67x00_sie *sie); 2698c2ecf20Sopenharmony_civoid c67x00_ll_husb_init_host_port(struct c67x00_sie *sie); 2708c2ecf20Sopenharmony_civoid c67x00_ll_husb_reset_port(struct c67x00_sie *sie, int port); 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci/* Called by c67x00_irq to handle lcp interrupts */ 2738c2ecf20Sopenharmony_civoid c67x00_ll_irq(struct c67x00_device *dev, u16 int_status); 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci/* Setup and teardown */ 2768c2ecf20Sopenharmony_civoid c67x00_ll_init(struct c67x00_device *dev); 2778c2ecf20Sopenharmony_civoid c67x00_ll_release(struct c67x00_device *dev); 2788c2ecf20Sopenharmony_ciint c67x00_ll_reset(struct c67x00_device *dev); 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci#endif /* _USB_C67X00_H */ 281