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 #include <linux/clk.h>
30 #include <linux/usb/r8a66597.h>
32 #define R8A66597_MAX_NUM_PIPE 10
33 #define R8A66597_BUF_BSIZE 8
34 #define R8A66597_MAX_DEVICE 10
35 #define R8A66597_MAX_ROOT_HUB 2
36 #define R8A66597_MAX_SAMPLING 5
37 #define R8A66597_RH_POLL_TIME 10
38 #define R8A66597_MAX_DMA_CHANNEL 2
39 #define R8A66597_PIPE_NO_DMA R8A66597_MAX_DMA_CHANNEL
40 #define check_bulk_or_isoc(pipenum) ((pipenum >= 1 && pipenum <= 5))
41 #define check_interrupt(pipenum) ((pipenum >= 6 && pipenum <= 9))
42 #define make_devsel(addr) (addr << 12)
44 struct r8a66597_pipe_info
{
45 unsigned long timer_interval
;
47 u16 address
; /* R8A66597 HCD usb address */
57 struct r8a66597_pipe
{
58 struct r8a66597_pipe_info info
;
60 unsigned long fifoaddr
;
61 unsigned long fifosel
;
62 unsigned long fifoctr
;
63 unsigned long pipectr
;
64 unsigned long pipetre
;
65 unsigned long pipetrn
;
69 struct r8a66597_pipe
*pipe
;
71 struct list_head queue
;
77 u16 address
; /* R8A66597's USB address */
80 unsigned zero_packet
:1;
81 unsigned short_packet
:1;
82 unsigned set_address
:1;
85 struct r8a66597_device
{
86 u16 address
; /* R8A66597's USB address */
90 unsigned short ep_in_toggle
;
91 unsigned short ep_out_toggle
;
92 unsigned char pipe_cnt
[R8A66597_MAX_NUM_PIPE
];
93 unsigned char dma_map
;
95 enum usb_device_state state
;
97 struct usb_device
*udev
;
99 struct list_head device_list
;
102 struct r8a66597_root_hub
{
107 struct r8a66597_device
*dev
;
114 struct r8a66597_platdata
*pdata
;
115 struct r8a66597_device device0
;
116 struct r8a66597_root_hub root_hub
[R8A66597_MAX_ROOT_HUB
];
117 struct list_head pipe_queue
[R8A66597_MAX_NUM_PIPE
];
119 struct timer_list rh_timer
;
120 struct timer_list td_timer
[R8A66597_MAX_NUM_PIPE
];
121 struct timer_list interval_timer
[R8A66597_MAX_NUM_PIPE
];
123 unsigned short address_map
;
124 unsigned short timeout_map
;
125 unsigned short interval_map
;
126 unsigned char pipe_cnt
[R8A66597_MAX_NUM_PIPE
];
127 unsigned char dma_map
;
128 unsigned int max_root_hub
;
130 struct list_head child_device
;
131 unsigned long child_connect_map
[4];
133 unsigned bus_suspended
:1;
134 unsigned irq_sense_low
:1;
137 static inline struct r8a66597
*hcd_to_r8a66597(struct usb_hcd
*hcd
)
139 return (struct r8a66597
*)(hcd
->hcd_priv
);
142 static inline struct usb_hcd
*r8a66597_to_hcd(struct r8a66597
*r8a66597
)
144 return container_of((void *)r8a66597
, struct usb_hcd
, hcd_priv
);
147 static inline struct r8a66597_td
*r8a66597_get_td(struct r8a66597
*r8a66597
,
150 if (unlikely(list_empty(&r8a66597
->pipe_queue
[pipenum
])))
153 return list_entry(r8a66597
->pipe_queue
[pipenum
].next
,
154 struct r8a66597_td
, queue
);
157 static inline struct urb
*r8a66597_get_urb(struct r8a66597
*r8a66597
,
160 struct r8a66597_td
*td
;
162 td
= r8a66597_get_td(r8a66597
, pipenum
);
163 return (td
? td
->urb
: NULL
);
166 static inline u16
r8a66597_read(struct r8a66597
*r8a66597
, unsigned long offset
)
168 return ioread16(r8a66597
->reg
+ offset
);
171 static inline void r8a66597_read_fifo(struct r8a66597
*r8a66597
,
172 unsigned long offset
, u16
*buf
,
175 void __iomem
*fifoaddr
= r8a66597
->reg
+ offset
;
178 if (r8a66597
->pdata
->on_chip
) {
180 ioread32_rep(fifoaddr
, buf
, count
);
182 if (len
& 0x00000003) {
183 unsigned long tmp
= ioread32(fifoaddr
);
184 memcpy((unsigned char *)buf
+ count
* 4, &tmp
,
189 ioread16_rep(fifoaddr
, buf
, len
);
193 static inline void r8a66597_write(struct r8a66597
*r8a66597
, u16 val
,
194 unsigned long offset
)
196 iowrite16(val
, r8a66597
->reg
+ offset
);
199 static inline void r8a66597_mdfy(struct r8a66597
*r8a66597
,
200 u16 val
, u16 pat
, unsigned long offset
)
203 tmp
= r8a66597_read(r8a66597
, offset
);
206 r8a66597_write(r8a66597
, tmp
, offset
);
209 #define r8a66597_bclr(r8a66597, val, offset) \
210 r8a66597_mdfy(r8a66597, 0, val, offset)
211 #define r8a66597_bset(r8a66597, val, offset) \
212 r8a66597_mdfy(r8a66597, val, 0, offset)
214 static inline void r8a66597_write_fifo(struct r8a66597
*r8a66597
,
215 struct r8a66597_pipe
*pipe
, u16
*buf
,
218 void __iomem
*fifoaddr
= r8a66597
->reg
+ pipe
->fifoaddr
;
223 if (r8a66597
->pdata
->on_chip
) {
225 iowrite32_rep(fifoaddr
, buf
, count
);
227 if (len
& 0x00000003) {
228 pb
= (unsigned char *)buf
+ count
* 4;
229 for (i
= 0; i
< (len
& 0x00000003); i
++) {
230 if (r8a66597_read(r8a66597
, CFIFOSEL
) & BIGEND
)
231 iowrite8(pb
[i
], fifoaddr
+ i
);
233 iowrite8(pb
[i
], fifoaddr
+ 3 - i
);
237 int odd
= len
& 0x0001;
240 iowrite16_rep(fifoaddr
, buf
, len
);
243 if (r8a66597
->pdata
->wr0_shorted_to_wr1
)
244 r8a66597_bclr(r8a66597
, MBW_16
, pipe
->fifosel
);
245 iowrite8((unsigned char)*buf
, fifoaddr
);
246 if (r8a66597
->pdata
->wr0_shorted_to_wr1
)
247 r8a66597_bset(r8a66597
, MBW_16
, pipe
->fifosel
);
252 static inline unsigned long get_syscfg_reg(int port
)
254 return port
== 0 ? SYSCFG0
: SYSCFG1
;
257 static inline unsigned long get_syssts_reg(int port
)
259 return port
== 0 ? SYSSTS0
: SYSSTS1
;
262 static inline unsigned long get_dvstctr_reg(int port
)
264 return port
== 0 ? DVSTCTR0
: DVSTCTR1
;
267 static inline unsigned long get_dmacfg_reg(int port
)
269 return port
== 0 ? DMA0CFG
: DMA1CFG
;
272 static inline unsigned long get_intenb_reg(int port
)
274 return port
== 0 ? INTENB1
: INTENB2
;
277 static inline unsigned long get_intsts_reg(int port
)
279 return port
== 0 ? INTSTS1
: INTSTS2
;
282 static inline u16
get_rh_usb_speed(struct r8a66597
*r8a66597
, int port
)
284 unsigned long dvstctr_reg
= get_dvstctr_reg(port
);
286 return r8a66597_read(r8a66597
, dvstctr_reg
) & RHST
;
289 static inline void r8a66597_port_power(struct r8a66597
*r8a66597
, int port
,
292 unsigned long dvstctr_reg
= get_dvstctr_reg(port
);
294 if (r8a66597
->pdata
->port_power
) {
295 r8a66597
->pdata
->port_power(port
, power
);
298 r8a66597_bset(r8a66597
, VBOUT
, dvstctr_reg
);
300 r8a66597_bclr(r8a66597
, VBOUT
, dvstctr_reg
);
304 static inline u16
get_xtal_from_pdata(struct r8a66597_platdata
*pdata
)
308 switch (pdata
->xtal
) {
309 case R8A66597_PLATDATA_XTAL_12MHZ
:
312 case R8A66597_PLATDATA_XTAL_24MHZ
:
315 case R8A66597_PLATDATA_XTAL_48MHZ
:
319 printk(KERN_ERR
"r8a66597: platdata clock is wrong.\n");
326 #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2)
327 #define get_pipetre_addr(pipenum) (PIPE1TRE + (pipenum - 1) * 4)
328 #define get_pipetrn_addr(pipenum) (PIPE1TRN + (pipenum - 1) * 4)
329 #define get_devadd_addr(address) (DEVADD0 + address * 2)
331 #define enable_irq_ready(r8a66597, pipenum) \
332 enable_pipe_irq(r8a66597, pipenum, BRDYENB)
333 #define disable_irq_ready(r8a66597, pipenum) \
334 disable_pipe_irq(r8a66597, pipenum, BRDYENB)
335 #define enable_irq_empty(r8a66597, pipenum) \
336 enable_pipe_irq(r8a66597, pipenum, BEMPENB)
337 #define disable_irq_empty(r8a66597, pipenum) \
338 disable_pipe_irq(r8a66597, pipenum, BEMPENB)
339 #define enable_irq_nrdy(r8a66597, pipenum) \
340 enable_pipe_irq(r8a66597, pipenum, NRDYENB)
341 #define disable_irq_nrdy(r8a66597, pipenum) \
342 disable_pipe_irq(r8a66597, pipenum, NRDYENB)
344 #endif /* __R8A66597_H__ */