1
2
3
4
5
6
7
8#ifndef __R8A66597_H__
9#define __R8A66597_H__
10
11#include <linux/bitops.h>
12#define SYSCFG0 0x00
13#define SYSCFG1 0x02
14#define SYSSTS0 0x04
15#define SYSSTS1 0x06
16#define DVSTCTR0 0x08
17#define DVSTCTR1 0x0A
18#define TESTMODE 0x0C
19#define PINCFG 0x0E
20#define DMA0CFG 0x10
21#define DMA1CFG 0x12
22#define CFIFO 0x14
23#define D0FIFO 0x18
24#define D1FIFO 0x1C
25#define CFIFOSEL 0x20
26#define CFIFOCTR 0x22
27#define CFIFOSIE 0x24
28#define D0FIFOSEL 0x28
29#define D0FIFOCTR 0x2A
30#define D1FIFOSEL 0x2C
31#define D1FIFOCTR 0x2E
32#define INTENB0 0x30
33#define INTENB1 0x32
34#define INTENB2 0x34
35#define BRDYENB 0x36
36#define NRDYENB 0x38
37#define BEMPENB 0x3A
38#define SOFCFG 0x3C
39#define INTSTS0 0x40
40#define INTSTS1 0x42
41#define INTSTS2 0x44
42#define BRDYSTS 0x46
43#define NRDYSTS 0x48
44#define BEMPSTS 0x4A
45#define FRMNUM 0x4C
46#define UFRMNUM 0x4E
47#define USBADDR 0x50
48#define USBREQ 0x54
49#define USBVAL 0x56
50#define USBINDX 0x58
51#define USBLENG 0x5A
52#define DCPCFG 0x5C
53#define DCPMAXP 0x5E
54#define DCPCTR 0x60
55#define PIPESEL 0x64
56#define PIPECFG 0x68
57#define PIPEBUF 0x6A
58#define PIPEMAXP 0x6C
59#define PIPEPERI 0x6E
60#define PIPE1CTR 0x70
61#define PIPE2CTR 0x72
62#define PIPE3CTR 0x74
63#define PIPE4CTR 0x76
64#define PIPE5CTR 0x78
65#define PIPE6CTR 0x7A
66#define PIPE7CTR 0x7C
67#define PIPE8CTR 0x7E
68#define PIPE9CTR 0x80
69#define PIPE1TRE 0x90
70#define PIPE1TRN 0x92
71#define PIPE2TRE 0x94
72#define PIPE2TRN 0x96
73#define PIPE3TRE 0x98
74#define PIPE3TRN 0x9A
75#define PIPE4TRE 0x9C
76#define PIPE4TRN 0x9E
77#define PIPE5TRE 0xA0
78#define PIPE5TRN 0xA2
79#define DEVADD0 0xD0
80#define DEVADD1 0xD2
81#define DEVADD2 0xD4
82#define DEVADD3 0xD6
83#define DEVADD4 0xD8
84#define DEVADD5 0xDA
85#define DEVADD6 0xDC
86#define DEVADD7 0xDE
87#define DEVADD8 0xE0
88#define DEVADD9 0xE2
89#define DEVADDA 0xE4
90#define SUSPMODE0 0x102
91
92
93#define HSE 0x0080
94#define DCFM 0x0040
95#define DRPD 0x0020
96#define DPRPU 0x0010
97#define XTAL 0x0004
98#define XTAL12 0x0004
99#define XTAL48 0x0000
100#define UPLLE 0x0002
101#define USBE 0x0001
102
103
104#define OVCBIT 0x8000
105#define OVCMON 0xC000
106#define SOFEA 0x0020
107#define IDMON 0x0004
108#define LNST 0x0003
109#define SE1 0x0003
110#define FS_KSTS 0x0002
111#define FS_JSTS 0x0001
112#define LS_JSTS 0x0002
113#define LS_KSTS 0x0001
114#define SE0 0x0000
115
116
117#define EXTLP0 0x0400
118#define VBOUT 0x0200
119#define WKUP 0x0100
120#define RWUPE 0x0080
121#define USBRST 0x0040
122#define RESUME 0x0020
123#define UACT 0x0010
124#define RHST 0x0007
125#define HSPROC 0x0004
126#define HSMODE 0x0003
127#define FSMODE 0x0002
128#define LSMODE 0x0001
129#define UNDECID 0x0000
130
131
132#define UTST 0x000F
133#define H_TST_PACKET 0x000C
134#define H_TST_SE0_NAK 0x000B
135#define H_TST_K 0x000A
136#define H_TST_J 0x0009
137#define H_TST_NORMAL 0x0000
138#define P_TST_PACKET 0x0004
139#define P_TST_SE0_NAK 0x0003
140#define P_TST_K 0x0002
141#define P_TST_J 0x0001
142#define P_TST_NORMAL 0x0000
143
144
145#define LDRV 0x8000
146#define VIF1 0x0000
147#define VIF3 0x8000
148#define INTA 0x0001
149
150
151#define DREQA 0x4000
152#define BURST 0x2000
153#define DACKA 0x0400
154#define DFORM 0x0380
155#define CPU_ADR_RD_WR 0x0000
156#define CPU_DACK_RD_WR 0x0100
157#define CPU_DACK_ONLY 0x0180
158#define SPLIT_DACK_ONLY 0x0200
159#define DENDA 0x0040
160#define PKTM 0x0020
161#define DENDE 0x0010
162#define OBUS 0x0004
163
164
165#define RCNT 0x8000
166#define REW 0x4000
167#define DCLRM 0x2000
168#define DREQE 0x1000
169#define MBW 0x0800
170#define MBW_8 0x0000
171#define MBW_16 0x0400
172#define MBW_32 0x0800
173#define BIGEND 0x0100
174#define BYTE_LITTLE 0x0000
175#define BYTE_BIG 0x0100
176#define ISEL 0x0020
177#define CURPIPE 0x000F
178
179
180#define BVAL 0x8000
181#define BCLR 0x4000
182#define FRDY 0x2000
183#define DTLN 0x0FFF
184
185
186#define VBSE 0x8000
187#define RSME 0x4000
188#define SOFE 0x2000
189#define DVSE 0x1000
190#define CTRE 0x0800
191#define BEMPE 0x0400
192#define NRDYE 0x0200
193#define BRDYE 0x0100
194
195
196#define OVRCRE 0x8000
197#define BCHGE 0x4000
198#define DTCHE 0x1000
199#define ATTCHE 0x0800
200#define EOFERRE 0x0040
201#define SIGNE 0x0020
202#define SACKE 0x0010
203
204
205#define BRDY9 0x0200
206#define BRDY8 0x0100
207#define BRDY7 0x0080
208#define BRDY6 0x0040
209#define BRDY5 0x0020
210#define BRDY4 0x0010
211#define BRDY3 0x0008
212#define BRDY2 0x0004
213#define BRDY1 0x0002
214#define BRDY0 0x0001
215
216
217#define NRDY9 0x0200
218#define NRDY8 0x0100
219#define NRDY7 0x0080
220#define NRDY6 0x0040
221#define NRDY5 0x0020
222#define NRDY4 0x0010
223#define NRDY3 0x0008
224#define NRDY2 0x0004
225#define NRDY1 0x0002
226#define NRDY0 0x0001
227
228
229#define BEMP9 0x0200
230#define BEMP8 0x0100
231#define BEMP7 0x0080
232#define BEMP6 0x0040
233#define BEMP5 0x0020
234#define BEMP4 0x0010
235#define BEMP3 0x0008
236#define BEMP2 0x0004
237#define BEMP1 0x0002
238#define BEMP0 0x0001
239
240
241#define TRNENSEL 0x0100
242#define BRDYM 0x0040
243#define INTL 0x0020
244#define EDGESTS 0x0010
245#define SOFMODE 0x000C
246#define SOF_125US 0x0008
247#define SOF_1MS 0x0004
248#define SOF_DISABLE 0x0000
249
250
251#define VBINT 0x8000
252#define RESM 0x4000
253#define SOFR 0x2000
254#define DVST 0x1000
255#define CTRT 0x0800
256#define BEMP 0x0400
257#define NRDY 0x0200
258#define BRDY 0x0100
259#define VBSTS 0x0080
260#define DVSQ 0x0070
261#define DS_SPD_CNFG 0x0070
262#define DS_SPD_ADDR 0x0060
263#define DS_SPD_DFLT 0x0050
264#define DS_SPD_POWR 0x0040
265#define DS_SUSP 0x0040
266#define DS_CNFG 0x0030
267#define DS_ADDS 0x0020
268#define DS_DFLT 0x0010
269#define DS_POWR 0x0000
270#define DVSQS 0x0030
271#define VALID 0x0008
272#define CTSQ 0x0007
273#define CS_SQER 0x0006
274#define CS_WRND 0x0005
275#define CS_WRSS 0x0004
276#define CS_WRDS 0x0003
277#define CS_RDSS 0x0002
278#define CS_RDDS 0x0001
279#define CS_IDST 0x0000
280
281
282#define OVRCR 0x8000
283#define BCHG 0x4000
284#define DTCH 0x1000
285#define ATTCH 0x0800
286#define EOFERR 0x0040
287#define SIGN 0x0020
288#define SACK 0x0010
289
290
291#define OVRN 0x8000
292#define CRCE 0x4000
293#define FRNM 0x07FF
294
295
296#define UFRNM 0x0007
297
298
299
300#define DEVSEL 0xF000
301#define MAXP 0x007F
302
303
304#define BSTS 0x8000
305#define SUREQ 0x4000
306#define CSCLR 0x2000
307#define CSSTS 0x1000
308#define SUREQCLR 0x0800
309#define SQCLR 0x0100
310#define SQSET 0x0080
311#define SQMON 0x0040
312#define PBUSY 0x0020
313#define PINGE 0x0010
314#define CCPL 0x0004
315#define PID 0x0003
316#define PID_STALL11 0x0003
317#define PID_STALL 0x0002
318#define PID_BUF 0x0001
319#define PID_NAK 0x0000
320
321
322#define PIPENM 0x0007
323
324
325#define R8A66597_TYP 0xC000
326#define R8A66597_ISO 0xC000
327#define R8A66597_INT 0x8000
328#define R8A66597_BULK 0x4000
329#define R8A66597_BFRE 0x0400
330#define R8A66597_DBLB 0x0200
331#define R8A66597_CNTMD 0x0100
332#define R8A66597_SHTNAK 0x0080
333#define R8A66597_DIR 0x0010
334#define R8A66597_EPNUM 0x000F
335
336
337#define BUFSIZE 0x7C00
338#define BUFNMB 0x007F
339#define PIPE0BUF 256
340#define PIPExBUF 64
341
342
343#define MXPS 0x07FF
344
345
346#define IFIS 0x1000
347#define IITV 0x0007
348
349
350#define BSTS 0x8000
351#define INBUFM 0x4000
352#define CSCLR 0x2000
353#define CSSTS 0x1000
354#define ATREPM 0x0400
355#define ACLRM 0x0200
356#define SQCLR 0x0100
357#define SQSET 0x0080
358#define SQMON 0x0040
359#define PBUSY 0x0020
360#define PID 0x0003
361
362
363#define TRENB 0x0200
364#define TRCLR 0x0100
365
366
367#define TRNCNT 0xFFFF
368
369
370#define UPPHUB 0x7800
371#define HUBPORT 0x0700
372#define USBSPD 0x00C0
373#define RTPORT 0x0001
374
375
376#define SUSPM 0x4000
377
378#define R8A66597_MAX_NUM_PIPE 10
379#define R8A66597_BUF_BSIZE 8
380#define R8A66597_MAX_DEVICE 10
381#define R8A66597_MAX_ROOT_HUB 2
382#define R8A66597_MAX_SAMPLING 5
383#define R8A66597_RH_POLL_TIME 10
384
385#define BULK_IN_PIPENUM 3
386#define BULK_IN_BUFNUM 8
387
388#define BULK_OUT_PIPENUM 4
389#define BULK_OUT_BUFNUM 40
390
391#define make_devsel(addr) ((addr) << 12)
392
393struct r8a66597 {
394 unsigned long reg;
395 unsigned short pipe_config;
396 unsigned short port_status;
397 unsigned short port_change;
398 u16 speed;
399 unsigned char rh_devnum;
400 struct udevice *vbus_supply;
401};
402
403static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset)
404{
405 return readw(r8a66597->reg + offset);
406}
407
408static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597,
409 unsigned long offset, void *buf,
410 int len)
411{
412 int i;
413 unsigned long fifoaddr = r8a66597->reg + offset;
414 unsigned long count;
415 unsigned long *p = buf;
416
417 count = len / 4;
418 for (i = 0; i < count; i++)
419 p[i] = readl(r8a66597->reg + offset);
420
421 if (len & 0x00000003) {
422 unsigned long tmp = readl(fifoaddr);
423
424 memcpy((unsigned char *)buf + count * 4, &tmp, len & 0x03);
425 }
426}
427
428static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val,
429 unsigned long offset)
430{
431 writew(val, r8a66597->reg + offset);
432}
433
434static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
435 unsigned long offset, void *buf,
436 int len)
437{
438 int i;
439 unsigned long fifoaddr = r8a66597->reg + offset;
440 unsigned long count;
441 unsigned char *pb;
442 unsigned long *p = buf;
443
444 count = len / 4;
445 for (i = 0; i < count; i++)
446 writel(p[i], fifoaddr);
447
448 if (len & 0x00000003) {
449 pb = (unsigned char *)buf + count * 4;
450 for (i = 0; i < (len & 0x00000003); i++) {
451 if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND)
452 writeb(pb[i], fifoaddr + i);
453 else
454 writeb(pb[i], fifoaddr + 3 - i);
455 }
456 }
457}
458
459static inline void r8a66597_mdfy(struct r8a66597 *r8a66597,
460 u16 val, u16 pat, unsigned long offset)
461{
462 u16 tmp;
463
464 tmp = r8a66597_read(r8a66597, offset);
465 tmp = tmp & (~pat);
466 tmp = tmp | val;
467 r8a66597_write(r8a66597, tmp, offset);
468}
469
470#define r8a66597_bclr(r8a66597, val, offset) \
471 r8a66597_mdfy(r8a66597, 0, val, offset)
472#define r8a66597_bset(r8a66597, val, offset) \
473 r8a66597_mdfy(r8a66597, val, 0, offset)
474
475static inline unsigned long get_syscfg_reg(int port)
476{
477 return port == 0 ? SYSCFG0 : SYSCFG1;
478}
479
480static inline unsigned long get_syssts_reg(int port)
481{
482 return port == 0 ? SYSSTS0 : SYSSTS1;
483}
484
485static inline unsigned long get_dvstctr_reg(int port)
486{
487 return port == 0 ? DVSTCTR0 : DVSTCTR1;
488}
489
490static inline unsigned long get_dmacfg_reg(int port)
491{
492 return port == 0 ? DMA0CFG : DMA1CFG;
493}
494
495static inline unsigned long get_intenb_reg(int port)
496{
497 return port == 0 ? INTENB1 : INTENB2;
498}
499
500static inline unsigned long get_intsts_reg(int port)
501{
502 return port == 0 ? INTSTS1 : INTSTS2;
503}
504
505static inline u16 get_rh_usb_speed(struct r8a66597 *r8a66597, int port)
506{
507 unsigned long dvstctr_reg = get_dvstctr_reg(port);
508
509 return r8a66597_read(r8a66597, dvstctr_reg) & RHST;
510}
511
512static inline void r8a66597_port_power(struct r8a66597 *r8a66597, int port,
513 int power)
514{
515 unsigned long dvstctr_reg = get_dvstctr_reg(port);
516
517 if (power)
518 r8a66597_bset(r8a66597, VBOUT, dvstctr_reg);
519 else
520 r8a66597_bclr(r8a66597, VBOUT, dvstctr_reg);
521}
522
523#define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2)
524#define get_pipetre_addr(pipenum) (PIPE1TRE + (pipenum - 1) * 4)
525#define get_pipetrn_addr(pipenum) (PIPE1TRN + (pipenum - 1) * 4)
526#define get_devadd_addr(address) (DEVADD0 + address * 2)
527
528
529
530
531#define RH_INTERFACE 0x01
532#define RH_ENDPOINT 0x02
533#define RH_OTHER 0x03
534
535#define RH_CLASS 0x20
536#define RH_VENDOR 0x40
537
538
539#define RH_GET_STATUS 0x0080
540#define RH_CLEAR_FEATURE 0x0100
541#define RH_SET_FEATURE 0x0300
542#define RH_SET_ADDRESS 0x0500
543#define RH_GET_DESCRIPTOR 0x0680
544#define RH_SET_DESCRIPTOR 0x0700
545#define RH_GET_CONFIGURATION 0x0880
546#define RH_SET_CONFIGURATION 0x0900
547#define RH_GET_STATE 0x0280
548#define RH_GET_INTERFACE 0x0A80
549#define RH_SET_INTERFACE 0x0B00
550#define RH_SYNC_FRAME 0x0C80
551
552#define RH_SET_EP 0x2000
553
554
555#define RH_PORT_CONNECTION 0x00
556#define RH_PORT_ENABLE 0x01
557#define RH_PORT_SUSPEND 0x02
558#define RH_PORT_OVER_CURRENT 0x03
559#define RH_PORT_RESET 0x04
560#define RH_PORT_POWER 0x08
561#define RH_PORT_LOW_SPEED 0x09
562
563#define RH_C_PORT_CONNECTION 0x10
564#define RH_C_PORT_ENABLE 0x11
565#define RH_C_PORT_SUSPEND 0x12
566#define RH_C_PORT_OVER_CURRENT 0x13
567#define RH_C_PORT_RESET 0x14
568
569
570#define RH_C_HUB_LOCAL_POWER 0x00
571#define RH_C_HUB_OVER_CURRENT 0x01
572
573#define RH_DEVICE_REMOTE_WAKEUP 0x00
574#define RH_ENDPOINT_STALL 0x01
575
576#define RH_ACK 0x01
577#define RH_REQ_ERR -1
578#define RH_NACK 0x00
579
580
581
582
583#define RH_PS_CCS 0x00000001
584#define RH_PS_PES 0x00000002
585#define RH_PS_PSS 0x00000004
586#define RH_PS_POCI 0x00000008
587#define RH_PS_PRS 0x00000010
588#define RH_PS_PPS 0x00000100
589#define RH_PS_LSDA 0x00000200
590#define RH_PS_CSC 0x00010000
591#define RH_PS_PESC 0x00020000
592#define RH_PS_PSSC 0x00040000
593#define RH_PS_OCIC 0x00080000
594#define RH_PS_PRSC 0x00100000
595
596
597#define RH_HS_LPS 0x00000001
598#define RH_HS_OCI 0x00000002
599#define RH_HS_DRWE 0x00008000
600#define RH_HS_LPSC 0x00010000
601#define RH_HS_OCIC 0x00020000
602#define RH_HS_CRWE 0x80000000
603
604
605#define RH_B_DR 0x0000ffff
606#define RH_B_PPCM 0xffff0000
607
608
609#define RH_A_NDP (0xff << 0)
610#define RH_A_PSM BIT(8)
611#define RH_A_NPS BIT(9)
612#define RH_A_DT BIT(10)
613#define RH_A_OCPM BIT(11)
614#define RH_A_NOCP BIT(12)
615#define RH_A_POTPGT (0xff << 24)
616
617#endif
618