2 * ci.h - common structures, functions, and macros of the ChipIdea driver
4 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #ifndef __DRIVERS_USB_CHIPIDEA_CI_H
14 #define __DRIVERS_USB_CHIPIDEA_CI_H
16 #include <linux/list.h>
17 #include <linux/irqreturn.h>
18 #include <linux/usb.h>
19 #include <linux/usb/gadget.h>
21 /******************************************************************************
23 *****************************************************************************/
24 #define TD_PAGE_COUNT 5
25 #define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */
28 /******************************************************************************
30 *****************************************************************************/
32 * struct ci13xxx_ep - endpoint representation
33 * @ep: endpoint structure for gadget drivers
34 * @dir: endpoint direction (TX/RX)
35 * @num: endpoint number
36 * @type: endpoint type
37 * @name: string description of the endpoint
38 * @qh: queue head for this endpoint
39 * @wedge: is the endpoint wedged
40 * @ci: pointer to the controller
41 * @lock: pointer to controller's spinlock
42 * @td_pool: pointer to controller's TD pool
51 struct list_head queue
;
52 struct ci13xxx_qh
*ptr
;
57 /* global resources */
60 struct dma_pool
*td_pool
;
70 * struct ci_role_driver - host/gadget role driver
71 * start: start this role
72 * stop: stop this role
73 * irq: irq handler for this role
74 * name: role name string (host/gadget)
76 struct ci_role_driver
{
77 int (*start
)(struct ci13xxx
*);
78 void (*stop
)(struct ci13xxx
*);
79 irqreturn_t (*irq
)(struct ci13xxx
*);
84 * struct hw_bank - hardware register mapping representation
85 * @lpm: set if the device is LPM capable
86 * @phys: physical address of the controller's registers
87 * @abs: absolute address of the beginning of register window
88 * @cap: capability registers
89 * @op: operational registers
90 * @size: size of the register window
91 * @regmap: register lookup table
100 void __iomem
**regmap
;
104 * struct ci13xxx - chipidea device representation
105 * @dev: pointer to parent device
106 * @lock: access synchronization
107 * @hw_bank: hardware register mapping
109 * @roles: array of supported roles for this controller
110 * @role: current role
111 * @is_otg: if the device is otg-capable
112 * @work: work for role changing
113 * @wq: workqueue thread
114 * @qh_pool: allocation pool for queue heads
115 * @td_pool: allocation pool for transfer descriptors
116 * @gadget: device side representation for peripheral controller
117 * @driver: gadget driver
118 * @hw_ep_max: total number of endpoints supported by hardware
119 * @ci13xxx_ep: array of endpoints
120 * @ep0_dir: ep0 direction
121 * @ep0out: pointer to ep0 OUT endpoint
122 * @ep0in: pointer to ep0 IN endpoint
123 * @status: ep0 status request
124 * @setaddr: if we should set the address on status completion
125 * @address: usb address received from the host
126 * @remote_wakeup: host-enabled remote wakeup
127 * @suspended: suspended by host
128 * @test_mode: the selected test mode
129 * @platdata: platform specific information supplied by parent device
130 * @vbus_active: is VBUS active
131 * @transceiver: pointer to USB PHY, if any
132 * @hcd: pointer to usb_hcd for ehci host driver
133 * @debugfs: root dentry for this controller in debugfs
138 struct hw_bank hw_bank
;
140 struct ci_role_driver
*roles
[CI_ROLE_END
];
143 struct work_struct work
;
144 struct workqueue_struct
*wq
;
146 struct dma_pool
*qh_pool
;
147 struct dma_pool
*td_pool
;
149 struct usb_gadget gadget
;
150 struct usb_gadget_driver
*driver
;
152 struct ci13xxx_ep ci13xxx_ep
[ENDPT_MAX
];
154 struct ci13xxx_ep
*ep0out
, *ep0in
;
156 struct usb_request
*status
;
163 struct ci13xxx_platform_data
*platdata
;
165 /* FIXME: some day, we'll not use global phy */
167 struct usb_phy
*transceiver
;
169 struct dentry
*debugfs
;
172 static inline struct ci_role_driver
*ci_role(struct ci13xxx
*ci
)
174 BUG_ON(ci
->role
>= CI_ROLE_END
|| !ci
->roles
[ci
->role
]);
175 return ci
->roles
[ci
->role
];
178 static inline int ci_role_start(struct ci13xxx
*ci
, enum ci_role role
)
182 if (role
>= CI_ROLE_END
)
185 if (!ci
->roles
[role
])
188 ret
= ci
->roles
[role
]->start(ci
);
194 static inline void ci_role_stop(struct ci13xxx
*ci
)
196 enum ci_role role
= ci
->role
;
198 if (role
== CI_ROLE_END
)
201 ci
->role
= CI_ROLE_END
;
203 ci
->roles
[role
]->stop(ci
);
206 /******************************************************************************
208 *****************************************************************************/
210 #define REG_BITS (32)
212 /* register indices */
218 CAP_LAST
= CAP_TESTMODE
,
234 /* endptctrl1..15 follow */
235 OP_LAST
= OP_ENDPTCTRL
+ ENDPT_MAX
/ 2,
239 * hw_read: reads from a hw register
240 * @reg: register index
241 * @mask: bitfield mask
243 * This function returns register contents
245 static inline u32
hw_read(struct ci13xxx
*ci
, enum ci13xxx_regs reg
, u32 mask
)
247 return ioread32(ci
->hw_bank
.regmap
[reg
]) & mask
;
251 * hw_write: writes to a hw register
252 * @reg: register index
253 * @mask: bitfield mask
256 static inline void hw_write(struct ci13xxx
*ci
, enum ci13xxx_regs reg
,
260 data
= (ioread32(ci
->hw_bank
.regmap
[reg
]) & ~mask
)
263 iowrite32(data
, ci
->hw_bank
.regmap
[reg
]);
267 * hw_test_and_clear: tests & clears a hw register
268 * @reg: register index
269 * @mask: bitfield mask
271 * This function returns register contents
273 static inline u32
hw_test_and_clear(struct ci13xxx
*ci
, enum ci13xxx_regs reg
,
276 u32 val
= ioread32(ci
->hw_bank
.regmap
[reg
]) & mask
;
278 iowrite32(val
, ci
->hw_bank
.regmap
[reg
]);
283 * hw_test_and_write: tests & writes a hw register
284 * @reg: register index
285 * @mask: bitfield mask
288 * This function returns register contents
290 static inline u32
hw_test_and_write(struct ci13xxx
*ci
, enum ci13xxx_regs reg
,
293 u32 val
= hw_read(ci
, reg
, ~0);
295 hw_write(ci
, reg
, mask
, data
);
296 return (val
& mask
) >> __ffs(mask
);
299 int hw_device_reset(struct ci13xxx
*ci
, u32 mode
);
301 int hw_port_test_set(struct ci13xxx
*ci
, u8 mode
);
303 u8
hw_port_test_get(struct ci13xxx
*ci
);
305 #endif /* __DRIVERS_USB_CHIPIDEA_CI_H */