4 * Copyright (C) 2007-2009 Renesas Solutions Corp.
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef __R8A66597_H__
24 #define __R8A66597_H__
26 #ifdef CONFIG_HAVE_CLK
27 #include <linux/clk.h>
30 #include <linux/usb/r8a66597.h>
32 #define R8A66597_MAX_SAMPLING 10
34 #define R8A66597_MAX_NUM_PIPE 8
35 #define R8A66597_MAX_NUM_BULK 3
36 #define R8A66597_MAX_NUM_ISOC 2
37 #define R8A66597_MAX_NUM_INT 2
39 #define R8A66597_BASE_PIPENUM_BULK 3
40 #define R8A66597_BASE_PIPENUM_ISOC 1
41 #define R8A66597_BASE_PIPENUM_INT 6
43 #define R8A66597_BASE_BUFNUM 6
44 #define R8A66597_MAX_BUFNUM 0x4F
46 #define is_bulk_pipe(pipenum) \
47 ((pipenum >= R8A66597_BASE_PIPENUM_BULK) && \
48 (pipenum < (R8A66597_BASE_PIPENUM_BULK + R8A66597_MAX_NUM_BULK)))
49 #define is_interrupt_pipe(pipenum) \
50 ((pipenum >= R8A66597_BASE_PIPENUM_INT) && \
51 (pipenum < (R8A66597_BASE_PIPENUM_INT + R8A66597_MAX_NUM_INT)))
52 #define is_isoc_pipe(pipenum) \
53 ((pipenum >= R8A66597_BASE_PIPENUM_ISOC) && \
54 (pipenum < (R8A66597_BASE_PIPENUM_ISOC + R8A66597_MAX_NUM_ISOC)))
56 struct r8a66597_pipe_info {
65 struct r8a66597_request {
66 struct usb_request req;
67 struct list_head queue;
72 struct r8a66597 *r8a66597;
74 struct list_head queue;
76 unsigned internal_ccpl:1; /* use only control */
78 /* this member can able to after r8a66597_enable */
82 const struct usb_endpoint_descriptor *desc;
83 /* register address */
84 unsigned char fifoaddr;
85 unsigned char fifosel;
86 unsigned char fifoctr;
87 unsigned char fifotrn;
88 unsigned char pipectr;
95 #ifdef CONFIG_HAVE_CLK
98 struct r8a66597_platdata *pdata;
100 struct usb_gadget gadget;
101 struct usb_gadget_driver *driver;
103 struct r8a66597_ep ep[R8A66597_MAX_NUM_PIPE];
104 struct r8a66597_ep *pipenum2ep[R8A66597_MAX_NUM_PIPE];
105 struct r8a66597_ep *epaddr2ep[16];
107 struct timer_list timer;
108 struct usb_request *ep0_req; /* for internal request */
109 u16 ep0_data; /* for internal request */
115 unsigned short bi_bufnum; /* bulk and isochronous's bufnum */
117 unsigned char interrupt;
118 unsigned char isochronous;
119 unsigned char num_dma;
121 unsigned irq_sense_low:1;
124 #define gadget_to_r8a66597(_gadget) \
125 container_of(_gadget, struct r8a66597, gadget)
126 #define r8a66597_to_gadget(r8a66597) (&r8a66597->gadget)
128 static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset)
130 return inw(r8a66597->reg + offset);
133 static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597,
134 unsigned long offset, u16 *buf,
137 if (r8a66597->pdata->on_chip) {
138 unsigned long fifoaddr = r8a66597->reg + offset;
142 unsigned char byte[4];
148 insl(fifoaddr, buf, count);
150 if (len & 0x00000003) {
151 data.dword = inl(fifoaddr);
152 pb = (unsigned char *)buf + count * 4;
153 for (i = 0; i < (len & 0x00000003); i++)
154 pb[i] = data.byte[i];
158 insw(r8a66597->reg + offset, buf, len);
162 static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val,
163 unsigned long offset)
165 outw(val, r8a66597->reg + offset);
168 static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
169 unsigned long offset, u16 *buf,
172 unsigned long fifoaddr = r8a66597->reg + offset;
174 if (r8a66597->pdata->on_chip) {
180 outsl(fifoaddr, buf, count);
182 if (len & 0x00000003) {
183 pb = (unsigned char *)buf + count * 4;
184 for (i = 0; i < (len & 0x00000003); i++) {
185 if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND)
186 outb(pb[i], fifoaddr + i);
188 outb(pb[i], fifoaddr + 3 - i);
192 int odd = len & 0x0001;
195 outsw(fifoaddr, buf, len);
198 outb((unsigned char)*buf, fifoaddr);
203 static inline void r8a66597_mdfy(struct r8a66597 *r8a66597,
204 u16 val, u16 pat, unsigned long offset)
207 tmp = r8a66597_read(r8a66597, offset);
210 r8a66597_write(r8a66597, tmp, offset);
213 static inline u16 get_xtal_from_pdata(struct r8a66597_platdata *pdata)
217 switch (pdata->xtal) {
218 case R8A66597_PLATDATA_XTAL_12MHZ:
221 case R8A66597_PLATDATA_XTAL_24MHZ:
224 case R8A66597_PLATDATA_XTAL_48MHZ:
228 printk(KERN_ERR "r8a66597: platdata clock is wrong.\n");
235 #define r8a66597_bclr(r8a66597, val, offset) \
236 r8a66597_mdfy(r8a66597, 0, val, offset)
237 #define r8a66597_bset(r8a66597, val, offset) \
238 r8a66597_mdfy(r8a66597, val, 0, offset)
240 #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2)
242 #define enable_irq_ready(r8a66597, pipenum) \
243 enable_pipe_irq(r8a66597, pipenum, BRDYENB)
244 #define disable_irq_ready(r8a66597, pipenum) \
245 disable_pipe_irq(r8a66597, pipenum, BRDYENB)
246 #define enable_irq_empty(r8a66597, pipenum) \
247 enable_pipe_irq(r8a66597, pipenum, BEMPENB)
248 #define disable_irq_empty(r8a66597, pipenum) \
249 disable_pipe_irq(r8a66597, pipenum, BEMPENB)
250 #define enable_irq_nrdy(r8a66597, pipenum) \
251 enable_pipe_irq(r8a66597, pipenum, NRDYENB)
252 #define disable_irq_nrdy(r8a66597, pipenum) \
253 disable_pipe_irq(r8a66597, pipenum, NRDYENB)
255 #endif /* __R8A66597_H__ */