blob: e023735d94b7a7594d174c45ff4a74b63cccb7db [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Alexander Shishkine443b332012-05-11 17:25:46 +03002/*
3 * udc.h - ChipIdea UDC structures
4 *
5 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
6 *
7 * Author: David Lopo
Alexander Shishkine443b332012-05-11 17:25:46 +03008 */
9
10#ifndef __DRIVERS_USB_CHIPIDEA_UDC_H
11#define __DRIVERS_USB_CHIPIDEA_UDC_H
12
13#include <linux/list.h>
14
15#define CTRL_PAYLOAD_MAX 64
16#define RX 0 /* similar to USB_DIR_OUT but can be used as an index */
17#define TX 1 /* similar to USB_DIR_IN but can be used as an index */
18
19/* DMA layout of transfer descriptors */
Alexander Shishkin8e229782013-06-24 14:46:36 +030020struct ci_hw_td {
Alexander Shishkine443b332012-05-11 17:25:46 +030021 /* 0 */
Stephen Boyd34445fb2016-09-13 22:53:02 -070022 __le32 next;
Alexander Shishkine443b332012-05-11 17:25:46 +030023#define TD_TERMINATE BIT(0)
24#define TD_ADDR_MASK (0xFFFFFFEUL << 5)
25 /* 1 */
Stephen Boyd34445fb2016-09-13 22:53:02 -070026 __le32 token;
Alexander Shishkine443b332012-05-11 17:25:46 +030027#define TD_STATUS (0x00FFUL << 0)
28#define TD_STATUS_TR_ERR BIT(3)
29#define TD_STATUS_DT_ERR BIT(5)
30#define TD_STATUS_HALTED BIT(6)
31#define TD_STATUS_ACTIVE BIT(7)
32#define TD_MULTO (0x0003UL << 10)
33#define TD_IOC BIT(15)
34#define TD_TOTAL_BYTES (0x7FFFUL << 16)
35 /* 2 */
Stephen Boyd34445fb2016-09-13 22:53:02 -070036 __le32 page[5];
Alexander Shishkine443b332012-05-11 17:25:46 +030037#define TD_CURR_OFFSET (0x0FFFUL << 0)
38#define TD_FRAME_NUM (0x07FFUL << 0)
39#define TD_RESERVED_MASK (0x0FFFUL << 0)
Michael Grzeschika9c17432013-04-04 13:13:46 +030040} __attribute__ ((packed, aligned(4)));
Alexander Shishkine443b332012-05-11 17:25:46 +030041
42/* DMA layout of queue heads */
Alexander Shishkin8e229782013-06-24 14:46:36 +030043struct ci_hw_qh {
Alexander Shishkine443b332012-05-11 17:25:46 +030044 /* 0 */
Stephen Boyd34445fb2016-09-13 22:53:02 -070045 __le32 cap;
Alexander Shishkine443b332012-05-11 17:25:46 +030046#define QH_IOS BIT(15)
47#define QH_MAX_PKT (0x07FFUL << 16)
48#define QH_ZLT BIT(29)
49#define QH_MULT (0x0003UL << 30)
Michael Grzeschike4ce4ec2013-06-13 17:59:47 +030050#define QH_ISO_MULT(x) ((x >> 11) & 0x03)
Alexander Shishkine443b332012-05-11 17:25:46 +030051 /* 1 */
Stephen Boyd34445fb2016-09-13 22:53:02 -070052 __le32 curr;
Alexander Shishkine443b332012-05-11 17:25:46 +030053 /* 2 - 8 */
Alexander Shishkin8e229782013-06-24 14:46:36 +030054 struct ci_hw_td td;
Alexander Shishkine443b332012-05-11 17:25:46 +030055 /* 9 */
Stephen Boyd34445fb2016-09-13 22:53:02 -070056 __le32 RESERVED;
Alexander Shishkine443b332012-05-11 17:25:46 +030057 struct usb_ctrlrequest setup;
Michael Grzeschika9c17432013-04-04 13:13:46 +030058} __attribute__ ((packed, aligned(4)));
Alexander Shishkine443b332012-05-11 17:25:46 +030059
Michael Grzeschikcc9e6c42013-06-13 17:59:53 +030060struct td_node {
61 struct list_head td;
62 dma_addr_t dma;
Alexander Shishkin8e229782013-06-24 14:46:36 +030063 struct ci_hw_td *ptr;
Michael Grzeschikcc9e6c42013-06-13 17:59:53 +030064};
65
Alexander Shishkin551a8ac2012-05-11 17:25:49 +030066/**
Alexander Shishkin8e229782013-06-24 14:46:36 +030067 * struct ci_hw_req - usb request representation
Alexander Shishkin551a8ac2012-05-11 17:25:49 +030068 * @req: request structure for gadget drivers
Alexander Shishkin551a8ac2012-05-11 17:25:49 +030069 * @queue: link to QH list
70 * @ptr: transfer descriptor for this request
71 * @dma: dma address for the transfer descriptor
72 * @zptr: transfer descriptor for the zero packet
73 * @zdma: dma address of the zero packet's transfer descriptor
74 */
Alexander Shishkin8e229782013-06-24 14:46:36 +030075struct ci_hw_req {
Alexander Shishkin551a8ac2012-05-11 17:25:49 +030076 struct usb_request req;
Alexander Shishkin551a8ac2012-05-11 17:25:49 +030077 struct list_head queue;
Michael Grzeschikcc9e6c42013-06-13 17:59:53 +030078 struct list_head tds;
Alexander Shishkine443b332012-05-11 17:25:46 +030079};
80
81#ifdef CONFIG_USB_CHIPIDEA_UDC
Alexander Shishkin5f36e232012-05-11 17:25:47 +030082
Alexander Shishkin8e229782013-06-24 14:46:36 +030083int ci_hdrc_gadget_init(struct ci_hdrc *ci);
Peter Chen3f124d22013-08-14 12:44:07 +030084void ci_hdrc_gadget_destroy(struct ci_hdrc *ci);
Alexander Shishkin5f36e232012-05-11 17:25:47 +030085
Alexander Shishkine443b332012-05-11 17:25:46 +030086#else
Alexander Shishkin5f36e232012-05-11 17:25:47 +030087
Alexander Shishkin8e229782013-06-24 14:46:36 +030088static inline int ci_hdrc_gadget_init(struct ci_hdrc *ci)
Alexander Shishkine443b332012-05-11 17:25:46 +030089{
Alexander Shishkin5f36e232012-05-11 17:25:47 +030090 return -ENXIO;
Alexander Shishkine443b332012-05-11 17:25:46 +030091}
92
Peter Chen3f124d22013-08-14 12:44:07 +030093static inline void ci_hdrc_gadget_destroy(struct ci_hdrc *ci)
94{
95
96}
97
Alexander Shishkine443b332012-05-11 17:25:46 +030098#endif
99
100#endif /* __DRIVERS_USB_CHIPIDEA_UDC_H */