8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/pci.h>
13 #include <linux/errno.h>
14 #include <linux/list.h>
16 #include <linux/usb/ch9.h>
22 static int vbus_gpio_port = -1;
24 #define PCH_VBUS_PERIOD 3000
25 #define PCH_VBUS_INTERVAL 10
28 #define UDC_EP_REG_SHIFT 0x20
30 #define UDC_EPCTL_ADDR 0x00
31 #define UDC_EPSTS_ADDR 0x04
32 #define UDC_BUFIN_FRAMENUM_ADDR 0x08
33 #define UDC_BUFOUT_MAXPKT_ADDR 0x0C
34 #define UDC_SUBPTR_ADDR 0x10
35 #define UDC_DESPTR_ADDR 0x14
36 #define UDC_CONFIRM_ADDR 0x18
38 #define UDC_DEVCFG_ADDR 0x400
39 #define UDC_DEVCTL_ADDR 0x404
40 #define UDC_DEVSTS_ADDR 0x408
41 #define UDC_DEVIRQSTS_ADDR 0x40C
42 #define UDC_DEVIRQMSK_ADDR 0x410
43 #define UDC_EPIRQSTS_ADDR 0x414
44 #define UDC_EPIRQMSK_ADDR 0x418
45 #define UDC_DEVLPM_ADDR 0x41C
46 #define UDC_CSR_BUSY_ADDR 0x4f0
47 #define UDC_SRST_ADDR 0x4fc
48 #define UDC_CSR_ADDR 0x500
52 #define UDC_EPCTL_MRXFLUSH (1 << 12)
53 #define UDC_EPCTL_RRDY (1 << 9)
54 #define UDC_EPCTL_CNAK (1 << 8)
55 #define UDC_EPCTL_SNAK (1 << 7)
56 #define UDC_EPCTL_NAK (1 << 6)
57 #define UDC_EPCTL_P (1 << 3)
58 #define UDC_EPCTL_F (1 << 1)
59 #define UDC_EPCTL_S (1 << 0)
60 #define UDC_EPCTL_ET_SHIFT 4
62 #define UDC_EPCTL_ET_MASK 0x00000030
64 #define UDC_EPCTL_ET_CONTROL 0
65 #define UDC_EPCTL_ET_ISO 1
66 #define UDC_EPCTL_ET_BULK 2
67 #define UDC_EPCTL_ET_INTERRUPT 3
71 #define UDC_EPSTS_XFERDONE (1 << 27)
72 #define UDC_EPSTS_RSS (1 << 26)
73 #define UDC_EPSTS_RCS (1 << 25)
74 #define UDC_EPSTS_TXEMPTY (1 << 24)
75 #define UDC_EPSTS_TDC (1 << 10)
76 #define UDC_EPSTS_HE (1 << 9)
77 #define UDC_EPSTS_MRXFIFO_EMP (1 << 8)
78 #define UDC_EPSTS_BNA (1 << 7)
79 #define UDC_EPSTS_IN (1 << 6)
80 #define UDC_EPSTS_OUT_SHIFT 4
82 #define UDC_EPSTS_OUT_MASK 0x00000030
83 #define UDC_EPSTS_ALL_CLR_MASK 0x1F0006F0
85 #define UDC_EPSTS_OUT_SETUP 2
86 #define UDC_EPSTS_OUT_DATA 1
90 #define UDC_DEVCFG_CSR_PRG (1 << 17)
91 #define UDC_DEVCFG_SP (1 << 3)
93 #define UDC_DEVCFG_SPD_HS 0x0
94 #define UDC_DEVCFG_SPD_FS 0x1
95 #define UDC_DEVCFG_SPD_LS 0x2
99 #define UDC_DEVCTL_THLEN_SHIFT 24
100 #define UDC_DEVCTL_BRLEN_SHIFT 16
101 #define UDC_DEVCTL_CSR_DONE (1 << 13)
102 #define UDC_DEVCTL_SD (1 << 10)
103 #define UDC_DEVCTL_MODE (1 << 9)
104 #define UDC_DEVCTL_BREN (1 << 8)
105 #define UDC_DEVCTL_THE (1 << 7)
106 #define UDC_DEVCTL_DU (1 << 4)
107 #define UDC_DEVCTL_TDE (1 << 3)
108 #define UDC_DEVCTL_RDE (1 << 2)
109 #define UDC_DEVCTL_RES (1 << 0)
113 #define UDC_DEVSTS_TS_SHIFT 18
114 #define UDC_DEVSTS_ENUM_SPEED_SHIFT 13
115 #define UDC_DEVSTS_ALT_SHIFT 8
116 #define UDC_DEVSTS_INTF_SHIFT 4
117 #define UDC_DEVSTS_CFG_SHIFT 0
119 #define UDC_DEVSTS_TS_MASK 0xfffc0000
120 #define UDC_DEVSTS_ENUM_SPEED_MASK 0x00006000
121 #define UDC_DEVSTS_ALT_MASK 0x00000f00
122 #define UDC_DEVSTS_INTF_MASK 0x000000f0
123 #define UDC_DEVSTS_CFG_MASK 0x0000000f
125 #define UDC_DEVSTS_ENUM_SPEED_FULL 1
126 #define UDC_DEVSTS_ENUM_SPEED_HIGH 0
127 #define UDC_DEVSTS_ENUM_SPEED_LOW 2
128 #define UDC_DEVSTS_ENUM_SPEED_FULLX 3
132 #define UDC_DEVINT_RWKP (1 << 7)
133 #define UDC_DEVINT_ENUM (1 << 6)
134 #define UDC_DEVINT_SOF (1 << 5)
135 #define UDC_DEVINT_US (1 << 4)
136 #define UDC_DEVINT_UR (1 << 3)
137 #define UDC_DEVINT_ES (1 << 2)
138 #define UDC_DEVINT_SI (1 << 1)
139 #define UDC_DEVINT_SC (1 << 0)
141 #define UDC_DEVINT_MSK 0x7f
145 #define UDC_EPINT_IN_SHIFT 0
146 #define UDC_EPINT_OUT_SHIFT 16
147 #define UDC_EPINT_IN_EP0 (1 << 0)
148 #define UDC_EPINT_OUT_EP0 (1 << 16)
150 #define UDC_EPINT_MSK_DISABLE_ALL 0xffffffff
154 #define UDC_CSR_BUSY (1 << 0)
158 #define UDC_PSRST (1 << 1)
159 #define UDC_SRST (1 << 0)
163 #define UDC_CSR_NE_NUM_SHIFT 0
164 #define UDC_CSR_NE_DIR_SHIFT 4
165 #define UDC_CSR_NE_TYPE_SHIFT 5
166 #define UDC_CSR_NE_CFG_SHIFT 7
167 #define UDC_CSR_NE_INTF_SHIFT 11
168 #define UDC_CSR_NE_ALT_SHIFT 15
169 #define UDC_CSR_NE_MAX_PKT_SHIFT 19
171 #define UDC_CSR_NE_NUM_MASK 0x0000000f
172 #define UDC_CSR_NE_DIR_MASK 0x00000010
173 #define UDC_CSR_NE_TYPE_MASK 0x00000060
174 #define UDC_CSR_NE_CFG_MASK 0x00000780
175 #define UDC_CSR_NE_INTF_MASK 0x00007800
176 #define UDC_CSR_NE_ALT_MASK 0x00078000
177 #define UDC_CSR_NE_MAX_PKT_MASK 0x3ff80000
179 #define PCH_UDC_CSR(ep) (UDC_CSR_ADDR + ep*4)
180 #define PCH_UDC_EPINT(in, num)\
181 (1 << (num + (in ? UDC_EPINT_IN_SHIFT : UDC_EPINT_OUT_SHIFT)))
184 #define UDC_EP0IN_IDX 0
185 #define UDC_EP0OUT_IDX 1
186 #define UDC_EPIN_IDX(ep) (ep * 2)
187 #define UDC_EPOUT_IDX(ep) (ep * 2 + 1)
188 #define PCH_UDC_EP0 0
189 #define PCH_UDC_EP1 1
190 #define PCH_UDC_EP2 2
191 #define PCH_UDC_EP3 3
194 #define PCH_UDC_EP_NUM 32
195 #define PCH_UDC_USED_EP_NUM 4
197 #define PCH_UDC_BRLEN 0x0F
198 #define PCH_UDC_THLEN 0x1F
200 #define UDC_EP0IN_BUFF_SIZE 16
201 #define UDC_EPIN_BUFF_SIZE 256
202 #define UDC_EP0OUT_BUFF_SIZE 16
203 #define UDC_EPOUT_BUFF_SIZE 256
205 #define UDC_EP0IN_MAX_PKT_SIZE 64
206 #define UDC_EP0OUT_MAX_PKT_SIZE 64
207 #define UDC_BULK_MAX_PKT_SIZE 512
212 #define DMA_ADDR_INVALID (~(dma_addr_t)0)
213 #define UDC_DMA_MAXPACKET 65536
246 #define PCH_UDC_BUFF_STS 0xC0000000
247 #define PCH_UDC_BS_HST_RDY 0x00000000
248 #define PCH_UDC_BS_DMA_BSY 0x40000000
249 #define PCH_UDC_BS_DMA_DONE 0x80000000
250 #define PCH_UDC_BS_HST_BSY 0xC0000000
252 #define PCH_UDC_RXTX_STS 0x30000000
253 #define PCH_UDC_RTS_SUCC 0x00000000
254 #define PCH_UDC_RTS_DESERR 0x10000000
255 #define PCH_UDC_RTS_BUFERR 0x30000000
257 #define PCH_UDC_DMA_LAST 0x08000000
259 #define PCH_UDC_RXTX_BYTES 0x0000ffff
379 #define PCH_UDC_PCI_BAR 1
380 #define PCI_DEVICE_ID_INTEL_EG20T_UDC 0x8808
381 #define PCI_VENDOR_ID_ROHM 0x10DB
382 #define PCI_DEVICE_ID_ML7213_IOH_UDC 0x801D
383 #define PCI_DEVICE_ID_ML7831_IOH_UDC 0x8808
385 static const char ep0_string[] =
"ep0in";
388 static bool speed_fs;
426 unsigned long val,
unsigned long reg)
435 pch_udc_writel(dev, pch_udc_readl(dev, reg) | bitmask, reg);
438 static inline void pch_udc_bit_clr(
struct pch_udc_dev *dev,
440 unsigned long bitmask)
442 pch_udc_writel(dev, pch_udc_readl(dev, reg) & ~(bitmask), reg);
445 static inline u32 pch_udc_ep_readl(
struct pch_udc_ep *ep,
unsigned long reg)
450 static inline void pch_udc_ep_writel(
struct pch_udc_ep *ep,
451 unsigned long val,
unsigned long reg)
456 static inline void pch_udc_ep_bit_set(
struct pch_udc_ep *ep,
458 unsigned long bitmask)
460 pch_udc_ep_writel(ep, pch_udc_ep_readl(ep, reg) | bitmask, reg);
463 static inline void pch_udc_ep_bit_clr(
struct pch_udc_ep *ep,
465 unsigned long bitmask)
467 pch_udc_ep_writel(ep, pch_udc_ep_readl(ep, reg) & ~(bitmask), reg);
474 static void pch_udc_csr_busy(
struct pch_udc_dev *dev)
476 unsigned int count = 200;
483 dev_err(&dev->
pdev->dev,
"%s: wait error\n", __func__);
492 static void pch_udc_write_csr(
struct pch_udc_dev *dev,
unsigned long val,
497 pch_udc_csr_busy(dev);
498 pch_udc_writel(dev, val, reg);
499 pch_udc_csr_busy(dev);
509 static u32 pch_udc_read_csr(
struct pch_udc_dev *dev,
unsigned int ep)
513 pch_udc_csr_busy(dev);
514 pch_udc_readl(dev, reg);
515 pch_udc_csr_busy(dev);
516 return pch_udc_readl(dev, reg);
523 static inline void pch_udc_rmt_wakeup(
struct pch_udc_dev *dev)
535 static inline int pch_udc_get_frame(
struct pch_udc_dev *dev)
545 static inline void pch_udc_clear_selfpowered(
struct pch_udc_dev *dev)
554 static inline void pch_udc_set_selfpowered(
struct pch_udc_dev *dev)
563 static inline void pch_udc_set_disconnect(
struct pch_udc_dev *dev)
572 static void pch_udc_clear_disconnect(
struct pch_udc_dev *dev)
588 static void pch_udc_reconnect(
struct pch_udc_dev *dev)
612 static inline void pch_udc_vbus_session(
struct pch_udc_dev *dev,
616 pch_udc_reconnect(dev);
620 spin_unlock(&dev->
lock);
622 spin_lock(&dev->
lock);
624 pch_udc_set_disconnect(dev);
633 static void pch_udc_ep_set_stall(
struct pch_udc_ep *ep)
647 static inline void pch_udc_ep_clear_stall(
struct pch_udc_ep *ep)
660 static inline void pch_udc_ep_set_trfr_type(
struct pch_udc_ep *ep,
672 static void pch_udc_ep_set_bufsz(
struct pch_udc_ep *ep,
678 data = (data & 0xffff0000) | (buf_size & 0xffff);
682 data = (buf_size << 16) | (data & 0xffff);
692 static void pch_udc_ep_set_maxpkt(
struct pch_udc_ep *ep,
u32 pkt_size)
695 data = (data & 0xffff0000) | (pkt_size & 0xffff);
723 static inline void pch_udc_ep_set_pd(
struct pch_udc_ep *ep)
732 static inline void pch_udc_ep_set_rrdy(
struct pch_udc_ep *ep)
741 static inline void pch_udc_ep_clear_rrdy(
struct pch_udc_ep *ep)
754 static inline void pch_udc_set_dma(
struct pch_udc_dev *dev,
int dir)
770 static inline void pch_udc_clear_dma(
struct pch_udc_dev *dev,
int dir)
783 static inline void pch_udc_set_csr_done(
struct pch_udc_dev *dev)
793 static inline void pch_udc_disable_interrupts(
struct pch_udc_dev *dev,
804 static inline void pch_udc_enable_interrupts(
struct pch_udc_dev *dev,
815 static inline void pch_udc_disable_ep_interrupts(
struct pch_udc_dev *dev,
826 static inline void pch_udc_enable_ep_interrupts(
struct pch_udc_dev *dev,
837 static inline u32 pch_udc_read_device_interrupts(
struct pch_udc_dev *dev)
847 static inline void pch_udc_write_device_interrupts(
struct pch_udc_dev *dev,
858 static inline u32 pch_udc_read_ep_interrupts(
struct pch_udc_dev *dev)
868 static inline void pch_udc_write_ep_interrupts(
struct pch_udc_dev *dev,
879 static inline u32 pch_udc_read_device_status(
struct pch_udc_dev *dev)
889 static inline u32 pch_udc_read_ep_control(
struct pch_udc_ep *ep)
899 static inline void pch_udc_clear_ep_control(
struct pch_udc_ep *ep)
909 static inline u32 pch_udc_read_ep_status(
struct pch_udc_ep *ep)
919 static inline void pch_udc_clear_ep_status(
struct pch_udc_ep *ep,
930 static inline void pch_udc_ep_set_nak(
struct pch_udc_ep *ep)
940 static void pch_udc_ep_clear_nak(
struct pch_udc_ep *ep)
942 unsigned int loopcnt = 0;
957 while ((pch_udc_read_ep_control(ep) & UDC_EPCTL_NAK) && --loopcnt) {
962 dev_err(&dev->
pdev->dev,
"%s: Clear NAK not set for ep%d%s\n",
963 __func__, ep->
num, (ep->
in ?
"in" :
"out"));
973 static void pch_udc_ep_fifo_flush(
struct pch_udc_ep *ep,
int dir)
986 static void pch_udc_ep_enable(
struct pch_udc_ep *ep,
998 pch_udc_ep_set_bufsz(ep, buff_size, ep->
in);
999 pch_udc_ep_set_maxpkt(ep, usb_endpoint_maxp(desc));
1000 pch_udc_ep_set_nak(ep);
1001 pch_udc_ep_fifo_flush(ep, ep->
in);
1021 static void pch_udc_ep_disable(
struct pch_udc_ep *ep)
1041 static void pch_udc_wait_ep_stall(
struct pch_udc_ep *ep)
1043 unsigned int count = 10000;
1046 while ((pch_udc_read_ep_control(ep) &
UDC_EPCTL_S) && --count)
1049 dev_err(&ep->
dev->pdev->dev,
"%s: wait error\n", __func__);
1059 pr_err(
"%s: Invalid address\n", __func__);
1102 pch_udc_set_disconnect(dev);
1120 return pch_udc_get_frame(dev);
1131 static int pch_udc_pcd_wakeup(
struct usb_gadget *gadget)
1134 unsigned long flags;
1140 pch_udc_rmt_wakeup(dev);
1141 spin_unlock_irqrestore(&dev->
lock, flags);
1155 static int pch_udc_pcd_selfpowered(
struct usb_gadget *gadget,
int value)
1163 pch_udc_set_selfpowered(dev);
1165 pch_udc_clear_selfpowered(dev);
1179 static int pch_udc_pcd_pullup(
struct usb_gadget *gadget,
int is_on)
1187 pch_udc_reconnect(dev);
1190 spin_unlock(&dev->
lock);
1192 spin_lock(&dev->
lock);
1194 pch_udc_set_disconnect(dev);
1211 static int pch_udc_pcd_vbus_session(
struct usb_gadget *gadget,
int is_active)
1218 pch_udc_vbus_session(dev, is_active);
1233 static int pch_udc_pcd_vbus_draw(
struct usb_gadget *gadget,
unsigned int mA)
1242 .get_frame = pch_udc_pcd_get_frame,
1243 .wakeup = pch_udc_pcd_wakeup,
1244 .set_selfpowered = pch_udc_pcd_selfpowered,
1245 .pullup = pch_udc_pcd_pullup,
1246 .vbus_session = pch_udc_pcd_vbus_session,
1247 .vbus_draw = pch_udc_pcd_vbus_draw,
1248 .start = pch_udc_start,
1249 .stop = pch_udc_stop,
1261 static int pch_vbus_gpio_get_value(
struct pch_udc_dev *dev)
1285 int vbus_saved = -1;
1294 vbus = pch_vbus_gpio_get_value(dev);
1296 if ((vbus_saved == vbus) && (vbus == 0)) {
1299 && dev->
driver->disconnect) {
1306 pch_udc_reconnect(dev);
1320 static void pch_vbus_gpio_work_rise(
struct work_struct *irq_work)
1332 vbus = pch_vbus_gpio_get_value(dev);
1336 pch_udc_reconnect(dev);
1357 if (pch_vbus_gpio_get_value(dev))
1374 static int pch_vbus_gpio_init(
struct pch_udc_dev *dev,
int vbus_gpio_port)
1382 if (vbus_gpio_port <= -1)
1385 err = gpio_is_valid(vbus_gpio_port);
1387 pr_err(
"%s: gpio port %d is invalid\n",
1388 __func__, vbus_gpio_port);
1394 pr_err(
"%s: can't request gpio port %d, err: %d\n",
1395 __func__, vbus_gpio_port, err);
1407 "vbus_detect", dev);
1411 pch_vbus_gpio_work_rise);
1413 pr_err(
"%s: can't request irq %d, err: %d\n",
1414 __func__, irq_num, err);
1425 static void pch_vbus_gpio_free(
struct pch_udc_dev *dev)
1445 unsigned halted = ep->
halted;
1447 list_del_init(&req->
queue);
1453 status = req->
req.status;
1484 spin_unlock(&dev->
lock);
1486 pch_udc_ep_clear_rrdy(ep);
1487 req->
req.complete(&ep->
ep, &req->
req);
1488 spin_lock(&dev->
lock);
1496 static void empty_req_queue(
struct pch_udc_ep *ep)
1501 while (!list_empty(&ep->
queue)) {
1516 static void pch_udc_free_dma_chain(
struct pch_udc_dev *dev,
1525 for (; i > 1; --
i) {
1548 static int pch_udc_create_dma_chain(
struct pch_udc_ep *ep,
1550 unsigned long buf_len,
1554 unsigned long bytes = req->
req.length, i = 0;
1559 pch_udc_free_dma_chain(ep->
dev, req);
1567 for (; ; bytes -= buf_len, ++len) {
1569 if (bytes <= buf_len)
1572 td = pci_pool_alloc(ep->
dev->data_requests, gfp_flags,
1590 pch_udc_free_dma_chain(ep->
dev, req);
1613 retval = pch_udc_create_dma_chain(ep, req, ep->
ep.maxpacket, gfp);
1615 pr_err(
"%s: could not create DMA chain:%d\n", __func__, retval);
1635 complete_req(ep, req, 0);
1641 pch_udc_set_csr_done(dev);
1656 static void pch_udc_start_rxrequest(
struct pch_udc_ep *ep,
1676 pch_udc_ep_clear_nak(ep);
1677 pch_udc_ep_set_rrdy(ep);
1691 static int pch_udc_pcd_ep_enable(
struct usb_ep *usbep,
1696 unsigned long iflags;
1698 if (!usbep || (usbep->
name == ep0_string) || !desc ||
1709 pch_udc_ep_enable(ep, &ep->
dev->cfg_data, desc);
1710 ep->
ep.maxpacket = usb_endpoint_maxp(desc);
1712 spin_unlock_irqrestore(&dev->
lock, iflags);
1725 static int pch_udc_pcd_ep_disable(
struct usb_ep *usbep)
1729 unsigned long iflags;
1736 if ((usbep->
name == ep0_string) || !ep->
ep.desc)
1740 empty_req_queue(ep);
1742 pch_udc_ep_disable(ep);
1745 INIT_LIST_HEAD(&ep->
queue);
1746 spin_unlock_irqrestore(&ep->
dev->lock, iflags);
1772 req = kzalloc(
sizeof *req, gfp);
1777 INIT_LIST_HEAD(&req->
queue);
1778 if (!ep->
dev->dma_addr)
1781 dma_desc = pci_pool_alloc(ep->
dev->data_requests, gfp,
1783 if (
NULL == dma_desc) {
1802 static void pch_udc_free_request(
struct usb_ep *usbep,
1809 if (!usbep || !usbreq)
1814 if (!list_empty(&req->
queue))
1815 dev_err(&dev->
pdev->dev,
"%s: %s req=0x%p queue not empty\n",
1816 __func__, usbep->
name, req);
1819 pch_udc_free_dma_chain(ep->
dev, req);
1820 pci_pool_free(ep->
dev->data_requests, req->
td_data,
1844 unsigned long iflags;
1846 if (!usbep || !usbreq || !usbreq->
complete || !usbreq->
buf)
1850 if (!ep->
ep.desc && ep->
num)
1853 if (!list_empty(&req->
queue))
1861 if (!((
unsigned long)(usbreq->
buf) & 0x03)) {
1892 if (usbreq->
length > 0) {
1903 process_zlp(ep, req);
1908 pch_udc_start_rxrequest(ep, req);
1915 pch_udc_wait_ep_stall(ep);
1916 pch_udc_ep_clear_nak(ep);
1917 pch_udc_enable_ep_interrupts(ep->
dev, (1 << ep->
num));
1925 spin_unlock_irqrestore(&dev->
lock, iflags);
1939 static int pch_udc_pcd_dequeue(
struct usb_ep *usbep,
1945 unsigned long flags;
1950 if (!usbep || !usbreq || (!ep->
ep.desc && ep->
num))
1956 if (&req->
req == usbreq) {
1957 pch_udc_ep_set_nak(ep);
1958 if (!list_empty(&req->
queue))
1964 spin_unlock_irqrestore(&ep->
dev->lock, flags);
1978 static int pch_udc_pcd_set_halt(
struct usb_ep *usbep,
int halt)
1982 unsigned long iflags;
1989 if (!ep->
ep.desc && !ep->
num)
1994 if (list_empty(&ep->
queue)) {
1998 pch_udc_ep_set_stall(ep);
1999 pch_udc_enable_ep_interrupts(ep->
dev,
2003 pch_udc_ep_clear_stall(ep);
2009 spin_unlock_irqrestore(&udc_stall_spinlock, iflags);
2023 static int pch_udc_pcd_set_wedge(
struct usb_ep *usbep)
2027 unsigned long iflags;
2034 if (!ep->
ep.desc && !ep->
num)
2039 if (!list_empty(&ep->
queue)) {
2044 pch_udc_ep_set_stall(ep);
2045 pch_udc_enable_ep_interrupts(ep->
dev,
2047 ep->
dev->prot_stall = 1;
2050 spin_unlock_irqrestore(&udc_stall_spinlock, iflags);
2058 static void pch_udc_pcd_fifo_flush(
struct usb_ep *usbep)
2066 if (ep->
ep.desc || !ep->
num)
2067 pch_udc_ep_fifo_flush(ep, ep->
in);
2070 static const struct usb_ep_ops pch_udc_ep_ops = {
2071 .enable = pch_udc_pcd_ep_enable,
2072 .disable = pch_udc_pcd_ep_disable,
2073 .alloc_request = pch_udc_alloc_request,
2074 .free_request = pch_udc_free_request,
2075 .queue = pch_udc_pcd_queue,
2076 .dequeue = pch_udc_pcd_dequeue,
2077 .set_halt = pch_udc_pcd_set_halt,
2078 .set_wedge = pch_udc_pcd_set_wedge,
2079 .fifo_status =
NULL,
2080 .fifo_flush = pch_udc_pcd_fifo_flush,
2089 static u32 pky_marker;
2103 static void pch_udc_start_next_txrequest(
struct pch_udc_ep *ep)
2111 if (list_empty(&ep->
queue))
2120 pch_udc_wait_ep_stall(ep);
2122 pch_udc_ep_set_ddptr(ep, 0);
2133 pch_udc_ep_set_pd(ep);
2135 pch_udc_ep_clear_nak(ep);
2142 static void pch_udc_complete_transfer(
struct pch_udc_ep *ep)
2147 if (list_empty(&ep->
queue))
2155 dev_err(&dev->
pdev->dev,
"Invalid RXTX status (0x%08x) "
2156 "epstatus=0x%08x\n",
2162 req->
req.actual = req->
req.length;
2165 complete_req(ep, req, 0);
2167 if (!list_empty(&ep->
queue)) {
2168 pch_udc_wait_ep_stall(ep);
2169 pch_udc_ep_clear_nak(ep);
2170 pch_udc_enable_ep_interrupts(ep->
dev,
2173 pch_udc_disable_ep_interrupts(ep->
dev,
2182 static void pch_udc_complete_receiver(
struct pch_udc_ep *ep)
2190 if (list_empty(&ep->
queue))
2195 pch_udc_ep_set_ddptr(ep, 0);
2204 dev_err(&dev->
pdev->dev,
"Invalid RXTX status=0x%08x "
2205 "epstatus=0x%08x\n",
2216 dev_err(&dev->
pdev->dev,
"Not complete RX descriptor");
2230 complete_req(ep, req, 0);
2232 if (!list_empty(&ep->
queue)) {
2234 pch_udc_start_rxrequest(ep, req);
2244 static void pch_udc_svc_data_in(
struct pch_udc_dev *dev,
int ep_num)
2262 pch_udc_ep_set_stall(ep);
2263 pch_udc_enable_ep_interrupts(ep->
dev,
2268 pch_udc_ep_clear_stall(ep);
2270 pch_udc_ep_set_stall(ep);
2271 pch_udc_enable_ep_interrupts(ep->
dev,
2276 pch_udc_complete_transfer(ep);
2278 if ((epsts &
UDC_EPSTS_IN) && !(epsts & UDC_EPSTS_RSS) &&
2280 pch_udc_start_next_txrequest(ep);
2288 static void pch_udc_svc_data_out(
struct pch_udc_dev *dev,
int ep_num)
2298 if ((epsts & UDC_EPSTS_BNA) && (!list_empty(&ep->
queue))) {
2305 pch_udc_start_rxrequest(ep, req);
2309 if (epsts & UDC_EPSTS_HE)
2311 if (epsts & UDC_EPSTS_RSS) {
2312 pch_udc_ep_set_stall(ep);
2313 pch_udc_enable_ep_interrupts(ep->
dev,
2316 if (epsts & UDC_EPSTS_RCS) {
2318 pch_udc_ep_clear_stall(ep);
2320 pch_udc_ep_set_stall(ep);
2321 pch_udc_enable_ep_interrupts(ep->
dev,
2327 if (ep->
dev->prot_stall == 1) {
2328 pch_udc_ep_set_stall(ep);
2329 pch_udc_enable_ep_interrupts(ep->
dev,
2332 pch_udc_complete_receiver(ep);
2335 if (list_empty(&ep->
queue))
2343 static void pch_udc_svc_control_in(
struct pch_udc_dev *dev)
2354 if (!(epsts & (UDC_EPSTS_IN | UDC_EPSTS_BNA | UDC_EPSTS_HE |
2358 if ((epsts & UDC_EPSTS_BNA))
2360 if (epsts & UDC_EPSTS_HE)
2362 if ((epsts & UDC_EPSTS_TDC) && (!dev->
stall)) {
2363 pch_udc_complete_transfer(ep);
2368 pch_udc_ep_clear_nak(ep_out);
2370 pch_udc_ep_set_rrdy(ep_out);
2373 if ((epsts & UDC_EPSTS_IN) && !(epsts & UDC_EPSTS_TDC) &&
2375 pch_udc_start_next_txrequest(ep);
2383 static void pch_udc_svc_control_out(
struct pch_udc_dev *dev)
2386 int setup_supported;
2400 pch_udc_init_setup_buff(ep->
td_stp);
2408 spin_unlock(&dev->
lock);
2410 if ((dev->
setup_data.bRequestType == 0x21) &&
2416 spin_lock(&dev->
lock);
2425 if (setup_supported >= 0 && setup_supported <
2432 pch_udc_ep_clear_nak(ep);
2434 }
else if (setup_supported < 0) {
2437 pch_udc_enable_ep_interrupts(ep->
dev,
2447 pch_udc_ep_set_ddptr(ep, 0);
2448 if (!list_empty(&ep->
queue)) {
2454 pch_udc_ep_set_rrdy(ep);
2464 static void pch_udc_postsvc_epinters(
struct pch_udc_dev *dev,
int ep_num)
2470 if (!list_empty(&ep->
queue)) {
2472 pch_udc_enable_ep_interrupts(ep->
dev,
2474 pch_udc_ep_clear_nak(ep);
2483 static void pch_udc_read_all_epstatus(
struct pch_udc_dev *dev,
u32 ep_intr)
2490 if (ep_intr & (0x1 << i)) {
2492 ep->
epsts = pch_udc_read_ep_status(ep);
2493 pch_udc_clear_ep_status(ep, ep->
epsts);
2496 if (ep_intr & (0x10000 << i)) {
2498 ep->
epsts = pch_udc_read_ep_status(ep);
2499 pch_udc_clear_ep_status(ep, ep->
epsts);
2509 static void pch_udc_activate_control_ep(
struct pch_udc_dev *dev)
2516 pch_udc_clear_ep_control(ep);
2517 pch_udc_ep_fifo_flush(ep, ep->
in);
2528 pch_udc_clear_ep_control(ep);
2529 pch_udc_ep_fifo_flush(ep, ep->
in);
2536 pch_udc_init_setup_buff(ep->
td_stp);
2547 pch_udc_ep_clear_nak(ep);
2555 static void pch_udc_svc_ur_interrupt(
struct pch_udc_dev *dev)
2570 pch_udc_clear_ep_control(ep);
2571 pch_udc_ep_set_ddptr(ep, 0);
2572 pch_udc_write_csr(ep->
dev, 0x00, i);
2580 for (i = 0; i < (PCH_UDC_USED_EP_NUM*2); i++) {
2582 pch_udc_ep_set_nak(ep);
2583 pch_udc_ep_fifo_flush(ep, ep->
in);
2585 empty_req_queue(ep);
2588 spin_unlock(&dev->
lock);
2590 spin_lock(&dev->
lock);
2599 static void pch_udc_svc_enum_interrupt(
struct pch_udc_dev *dev)
2601 u32 dev_stat, dev_speed;
2604 dev_stat = pch_udc_read_device_status(dev);
2607 switch (dev_speed) {
2620 dev->
gadget.speed = speed;
2621 pch_udc_activate_control_ep(dev);
2638 static void pch_udc_svc_intf_interrupt(
struct pch_udc_dev *dev)
2643 dev_stat = pch_udc_read_device_status(dev);
2663 for (i = 0; i < PCH_UDC_USED_EP_NUM * 2; i++) {
2665 pch_udc_ep_clear_stall(&(dev->
ep[i]));
2666 dev->
ep[
i].halted = 0;
2669 spin_unlock(&dev->
lock);
2671 spin_lock(&dev->
lock);
2679 static void pch_udc_svc_cfg_interrupt(
struct pch_udc_dev *dev)
2684 dev_stat = pch_udc_read_device_status(dev);
2698 for (i = 0; i < PCH_UDC_USED_EP_NUM * 2; i++) {
2700 pch_udc_ep_clear_stall(&(dev->
ep[i]));
2701 dev->
ep[
i].halted = 0;
2706 spin_unlock(&dev->
lock);
2708 spin_lock(&dev->
lock);
2717 static void pch_udc_dev_isr(
struct pch_udc_dev *dev,
u32 dev_intr)
2723 pch_udc_svc_ur_interrupt(dev);
2728 pch_udc_svc_enum_interrupt(dev);
2733 pch_udc_svc_intf_interrupt(dev);
2736 pch_udc_svc_cfg_interrupt(dev);
2740 && dev->
driver->suspend) {
2741 spin_unlock(&dev->
lock);
2743 spin_lock(&dev->
lock);
2746 vbus = pch_vbus_gpio_get_value(dev);
2750 spin_unlock(&dev->
lock);
2752 spin_lock(&dev->
lock);
2754 pch_udc_reconnect(dev);
2778 static irqreturn_t pch_udc_isr(
int irq,
void *pdev)
2781 u32 dev_intr, ep_intr;
2784 dev_intr = pch_udc_read_device_interrupts(dev);
2785 ep_intr = pch_udc_read_ep_interrupts(dev);
2788 if (dev_intr == ep_intr)
2797 pch_udc_write_device_interrupts(dev, dev_intr);
2800 pch_udc_write_ep_interrupts(dev, ep_intr);
2801 if (!dev_intr && !ep_intr)
2803 spin_lock(&dev->
lock);
2805 pch_udc_dev_isr(dev, dev_intr);
2807 pch_udc_read_all_epstatus(dev, ep_intr);
2810 pch_udc_svc_control_in(dev);
2811 pch_udc_postsvc_epinters(dev, 0);
2815 pch_udc_svc_control_out(dev);
2818 if (ep_intr & (1 << i)) {
2819 pch_udc_svc_data_in(dev, i);
2820 pch_udc_postsvc_epinters(dev, i);
2826 if (ep_intr & (1 << i))
2827 pch_udc_svc_data_out(dev, i -
2830 spin_unlock(&dev->
lock);
2838 static void pch_udc_setup_ep0(
struct pch_udc_dev *dev)
2841 pch_udc_enable_ep_interrupts(dev, UDC_EPINT_IN_EP0 |
2844 pch_udc_enable_interrupts(dev, UDC_DEVINT_UR | UDC_DEVINT_US |
2845 UDC_DEVINT_ES | UDC_DEVINT_ENUM |
2846 UDC_DEVINT_SI | UDC_DEVINT_SC);
2853 static void gadget_release(
struct device *pdev)
2864 static void pch_udc_pcd_reinit(
struct pch_udc_dev *dev)
2866 const char *
const ep_string[] = {
2867 ep0_string,
"ep0out",
"ep1in",
"ep1out",
"ep2in",
"ep2out",
2868 "ep3in",
"ep3out",
"ep4in",
"ep4out",
"ep5in",
"ep5out",
2869 "ep6in",
"ep6out",
"ep7in",
"ep7out",
"ep8in",
"ep8out",
2870 "ep9in",
"ep9out",
"ep10in",
"ep10out",
"ep11in",
"ep11out",
2871 "ep12in",
"ep12out",
"ep13in",
"ep13out",
"ep14in",
"ep14out",
2872 "ep15in",
"ep15out",
2877 INIT_LIST_HEAD(&dev->
gadget.ep_list);
2887 ep->
ep.name = ep_string[
i];
2888 ep->
ep.ops = &pch_udc_ep_ops;
2897 INIT_LIST_HEAD(&ep->
queue);
2907 INIT_LIST_HEAD(&dev->
gadget.ep0->ep_list);
2917 static int pch_udc_pcd_init(
struct pch_udc_dev *dev)
2920 pch_udc_pcd_reinit(dev);
2921 pch_vbus_gpio_init(dev, vbus_gpio_port);
2929 static int init_dma_pools(
struct pch_udc_dev *dev)
2938 dev_err(&dev->
pdev->dev,
"%s: can't get request data pool\n",
2947 dev_err(&dev->
pdev->dev,
"%s: can't get setup request pool\n",
2956 "%s: can't allocate setup dma descriptor\n", __func__);
2966 "%s: can't allocate data dma descriptor\n", __func__);
2993 "%s: invalid driver parameter\n", __func__);
3001 dev_err(&dev->
pdev->dev,
"%s: already bound\n", __func__);
3009 retval = bind(&dev->
gadget, driver);
3012 dev_err(&dev->
pdev->dev,
"%s: binding to %s returning %d\n",
3013 __func__, driver->
driver.name, retval);
3019 pch_udc_setup_ep0(dev);
3022 if ((pch_vbus_gpio_get_value(dev) != 0) || !dev->
vbus_gpio.intr)
3023 pch_udc_clear_disconnect(dev);
3036 if (!driver || (driver != dev->
driver)) {
3038 "%s: invalid driver parameter\n", __func__);
3052 pch_udc_set_disconnect(dev);
3056 static void pch_udc_shutdown(
struct pci_dev *pdev)
3064 pch_udc_set_disconnect(dev);
3067 static void pch_udc_remove(
struct pci_dev *pdev)
3076 "%s: gadget driver still bound!!!\n", __func__);
3101 pch_vbus_gpio_free(dev);
3117 pci_set_drvdata(pdev,
NULL);
3133 "%s: could not save PCI config state\n", __func__);
3148 dev_err(&pdev->
dev,
"%s: pci_enable_device failed\n", __func__);
3155 #define pch_udc_suspend NULL
3156 #define pch_udc_resume NULL
3159 static int pch_udc_probe(
struct pci_dev *pdev,
3169 pr_err(
"%s: already probed\n", __func__);
3175 pr_err(
"%s: no memory for device structure\n", __func__);
3181 pr_err(
"%s: pci_enable_device failed\n", __func__);
3185 pci_set_drvdata(pdev, dev);
3192 dev_err(&pdev->
dev,
"%s: pci device used already\n", __func__);
3201 pr_err(
"%s: device memory cannot be mapped\n", __func__);
3206 dev_err(&pdev->
dev,
"%s: irq not set\n", __func__);
3212 if (pch_udc_pcd_init(dev)) {
3218 dev_err(&pdev->
dev,
"%s: request_irq(%d) fail\n", __func__,
3232 dev->
gadget.ops = &pch_udc_ops;
3234 retval = init_dma_pools(dev);
3240 dev->
gadget.dev.dma_mask = pdev->
dev.dma_mask;
3241 dev->
gadget.dev.release = gadget_release;
3242 dev->
gadget.name = KBUILD_MODNAME;
3251 pch_udc_set_disconnect(dev);
3258 pch_udc_remove(pdev);
3266 .class_mask = 0xffffffff,
3271 .class_mask = 0xffffffff,
3276 .class_mask = 0xffffffff,
3284 .name = KBUILD_MODNAME,
3285 .id_table = pch_udc_pcidev_id,
3286 .probe = pch_udc_probe,
3287 .remove = pch_udc_remove,
3290 .shutdown = pch_udc_shutdown,