2 * R8A66597 HCD (Host Controller Driver)
4 * Copyright (C) 2006-2007 Renesas Solutions Corp.
5 * Portions Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
6 * Portions Copyright (C) 2004-2005 David Brownell
7 * Portions Copyright (C) 1999 Roman Weissgaerber
9 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #ifndef __R8A66597_H__
27 #define __R8A66597_H__
29 #ifdef CONFIG_HAVE_CLK
30 #include <linux/clk.h>
33 #include <linux/usb/r8a66597.h>
35 #define R8A66597_MAX_NUM_PIPE 10
36 #define R8A66597_BUF_BSIZE 8
37 #define R8A66597_MAX_DEVICE 10
38 #define R8A66597_MAX_ROOT_HUB 2
39 #define R8A66597_MAX_SAMPLING 5
40 #define R8A66597_RH_POLL_TIME 10
41 #define R8A66597_MAX_DMA_CHANNEL 2
42 #define R8A66597_PIPE_NO_DMA R8A66597_MAX_DMA_CHANNEL
43 #define check_bulk_or_isoc(pipenum) ((pipenum >= 1 && pipenum <= 5))
44 #define check_interrupt(pipenum) ((pipenum >= 6 && pipenum <= 9))
45 #define make_devsel(addr) (addr << 12)
47 struct r8a66597_pipe_info
{
48 unsigned long timer_interval
;
50 u16 address
; /* R8A66597 HCD usb address */
60 struct r8a66597_pipe
{
61 struct r8a66597_pipe_info info
;
63 unsigned long fifoaddr
;
64 unsigned long fifosel
;
65 unsigned long fifoctr
;
66 unsigned long pipectr
;
67 unsigned long pipetre
;
68 unsigned long pipetrn
;
72 struct r8a66597_pipe
*pipe
;
74 struct list_head queue
;
80 u16 address
; /* R8A66597's USB address */
83 unsigned zero_packet
:1;
84 unsigned short_packet
:1;
85 unsigned set_address
:1;
88 struct r8a66597_device
{
89 u16 address
; /* R8A66597's USB address */
93 unsigned short ep_in_toggle
;
94 unsigned short ep_out_toggle
;
95 unsigned char pipe_cnt
[R8A66597_MAX_NUM_PIPE
];
96 unsigned char dma_map
;
98 enum usb_device_state state
;
100 struct usb_device
*udev
;
102 struct list_head device_list
;
105 struct r8a66597_root_hub
{
110 struct r8a66597_device
*dev
;
116 #ifdef CONFIG_HAVE_CLK
119 struct r8a66597_platdata
*pdata
;
120 struct r8a66597_device device0
;
121 struct r8a66597_root_hub root_hub
[R8A66597_MAX_ROOT_HUB
];
122 struct list_head pipe_queue
[R8A66597_MAX_NUM_PIPE
];
124 struct timer_list rh_timer
;
125 struct timer_list td_timer
[R8A66597_MAX_NUM_PIPE
];
126 struct timer_list interval_timer
[R8A66597_MAX_NUM_PIPE
];
128 unsigned short address_map
;
129 unsigned short timeout_map
;
130 unsigned short interval_map
;
131 unsigned char pipe_cnt
[R8A66597_MAX_NUM_PIPE
];
132 unsigned char dma_map
;
133 unsigned int max_root_hub
;
135 struct list_head child_device
;
136 unsigned long child_connect_map
[4];
138 unsigned bus_suspended
:1;
139 unsigned irq_sense_low
:1;
142 static inline struct r8a66597
*hcd_to_r8a66597(struct usb_hcd
*hcd
)
144 return (struct r8a66597
*)(hcd
->hcd_priv
);
147 static inline struct usb_hcd
*r8a66597_to_hcd(struct r8a66597
*r8a66597
)
149 return container_of((void *)r8a66597
, struct usb_hcd
, hcd_priv
);
152 static inline struct r8a66597_td
*r8a66597_get_td(struct r8a66597
*r8a66597
,
155 if (unlikely(list_empty(&r8a66597
->pipe_queue
[pipenum
])))
158 return list_entry(r8a66597
->pipe_queue
[pipenum
].next
,
159 struct r8a66597_td
, queue
);
162 static inline struct urb
*r8a66597_get_urb(struct r8a66597
*r8a66597
,
165 struct r8a66597_td
*td
;
167 td
= r8a66597_get_td(r8a66597
, pipenum
);
168 return (td
? td
->urb
: NULL
);
171 static inline u16
r8a66597_read(struct r8a66597
*r8a66597
, unsigned long offset
)
173 return ioread16(r8a66597
->reg
+ offset
);
176 static inline void r8a66597_read_fifo(struct r8a66597
*r8a66597
,
177 unsigned long offset
, u16
*buf
,
180 void __iomem
*fifoaddr
= r8a66597
->reg
+ offset
;
183 if (r8a66597
->pdata
->on_chip
) {
185 ioread32_rep(fifoaddr
, buf
, count
);
187 if (len
& 0x00000003) {
188 unsigned long tmp
= ioread32(fifoaddr
);
189 memcpy((unsigned char *)buf
+ count
* 4, &tmp
,
194 ioread16_rep(fifoaddr
, buf
, len
);
198 static inline void r8a66597_write(struct r8a66597
*r8a66597
, u16 val
,
199 unsigned long offset
)
201 iowrite16(val
, r8a66597
->reg
+ offset
);
204 static inline void r8a66597_write_fifo(struct r8a66597
*r8a66597
,
205 unsigned long offset
, u16
*buf
,
208 void __iomem
*fifoaddr
= r8a66597
->reg
+ offset
;
213 if (r8a66597
->pdata
->on_chip
) {
215 iowrite32_rep(fifoaddr
, buf
, count
);
217 if (len
& 0x00000003) {
218 pb
= (unsigned char *)buf
+ count
* 4;
219 for (i
= 0; i
< (len
& 0x00000003); i
++) {
220 if (r8a66597_read(r8a66597
, CFIFOSEL
) & BIGEND
)
221 iowrite8(pb
[i
], fifoaddr
+ i
);
223 iowrite8(pb
[i
], fifoaddr
+ 3 - i
);
227 int odd
= len
& 0x0001;
230 iowrite16_rep(fifoaddr
, buf
, len
);
233 iowrite8((unsigned char)*buf
, fifoaddr
);
238 static inline void r8a66597_mdfy(struct r8a66597
*r8a66597
,
239 u16 val
, u16 pat
, unsigned long offset
)
242 tmp
= r8a66597_read(r8a66597
, offset
);
245 r8a66597_write(r8a66597
, tmp
, offset
);
248 #define r8a66597_bclr(r8a66597, val, offset) \
249 r8a66597_mdfy(r8a66597, 0, val, offset)
250 #define r8a66597_bset(r8a66597, val, offset) \
251 r8a66597_mdfy(r8a66597, val, 0, offset)
253 static inline unsigned long get_syscfg_reg(int port
)
255 return port
== 0 ? SYSCFG0
: SYSCFG1
;
258 static inline unsigned long get_syssts_reg(int port
)
260 return port
== 0 ? SYSSTS0
: SYSSTS1
;
263 static inline unsigned long get_dvstctr_reg(int port
)
265 return port
== 0 ? DVSTCTR0
: DVSTCTR1
;
268 static inline unsigned long get_dmacfg_reg(int port
)
270 return port
== 0 ? DMA0CFG
: DMA1CFG
;
273 static inline unsigned long get_intenb_reg(int port
)
275 return port
== 0 ? INTENB1
: INTENB2
;
278 static inline unsigned long get_intsts_reg(int port
)
280 return port
== 0 ? INTSTS1
: INTSTS2
;
283 static inline u16
get_rh_usb_speed(struct r8a66597
*r8a66597
, int port
)
285 unsigned long dvstctr_reg
= get_dvstctr_reg(port
);
287 return r8a66597_read(r8a66597
, dvstctr_reg
) & RHST
;
290 static inline void r8a66597_port_power(struct r8a66597
*r8a66597
, int port
,
293 unsigned long dvstctr_reg
= get_dvstctr_reg(port
);
295 if (r8a66597
->pdata
->port_power
) {
296 r8a66597
->pdata
->port_power(port
, power
);
299 r8a66597_bset(r8a66597
, VBOUT
, dvstctr_reg
);
301 r8a66597_bclr(r8a66597
, VBOUT
, dvstctr_reg
);
305 static inline u16
get_xtal_from_pdata(struct r8a66597_platdata
*pdata
)
309 switch (pdata
->xtal
) {
310 case R8A66597_PLATDATA_XTAL_12MHZ
:
313 case R8A66597_PLATDATA_XTAL_24MHZ
:
316 case R8A66597_PLATDATA_XTAL_48MHZ
:
320 printk(KERN_ERR
"r8a66597: platdata clock is wrong.\n");
327 #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2)
328 #define get_pipetre_addr(pipenum) (PIPE1TRE + (pipenum - 1) * 4)
329 #define get_pipetrn_addr(pipenum) (PIPE1TRN + (pipenum - 1) * 4)
330 #define get_devadd_addr(address) (DEVADD0 + address * 2)
332 #define enable_irq_ready(r8a66597, pipenum) \
333 enable_pipe_irq(r8a66597, pipenum, BRDYENB)
334 #define disable_irq_ready(r8a66597, pipenum) \
335 disable_pipe_irq(r8a66597, pipenum, BRDYENB)
336 #define enable_irq_empty(r8a66597, pipenum) \
337 enable_pipe_irq(r8a66597, pipenum, BEMPENB)
338 #define disable_irq_empty(r8a66597, pipenum) \
339 disable_pipe_irq(r8a66597, pipenum, BEMPENB)
340 #define enable_irq_nrdy(r8a66597, pipenum) \
341 enable_pipe_irq(r8a66597, pipenum, NRDYENB)
342 #define disable_irq_nrdy(r8a66597, pipenum) \
343 disable_pipe_irq(r8a66597, pipenum, NRDYENB)
345 #endif /* __R8A66597_H__ */