blob: 3365be19774991028511eed12b30eaf518a0cca4 [file] [log] [blame]
Patrick Georgi7f43dc12010-09-25 17:01:13 +00001/*
2 * This file is part of the libpayload project.
3 *
4 * Copyright (C) 2010 coresystems GmbH
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#ifndef __EHCI_PRIVATE_H
31#define __EHCI_PRIVATE_H
32
33#include <pci.h>
34#include <usb/usb.h>
35
36#define USBBASE 0x10
37#define FLADJ 0x61
38#define FLADJ_framelength(x) (((x)-59488)/16)
39
Patrick Georgi8fa27872011-11-24 13:19:57 +010040typedef volatile u32 portsc_t;
41#define P_CURR_CONN_STATUS (1 << 0)
42#define P_CONN_STATUS_CHANGE (1 << 1)
43#define P_PORT_ENABLE (1 << 2)
44#define P_PORT_RESET (1 << 8)
45#define P_LINE_STATUS (3 << 10)
46#define P_LINE_STATUS_LOWSPEED (1 << 10)
47#define P_PP (1 << 12)
48#define P_PORT_OWNER (1 << 13)
Patrick Georgi7f43dc12010-09-25 17:01:13 +000049
Patrick Georgi8bbdb612011-08-16 15:47:15 +020050typedef volatile struct {
Patrick Georgi8fa27872011-11-24 13:19:57 +010051#define HCS_NPORTS_MASK 0xf
Nico Huber5c4e7aa2012-05-21 14:56:21 +020052#define HCS_PORT_POWER_CONTROL 0x10
Patrick Georgi7f43dc12010-09-25 17:01:13 +000053 u8 caplength;
54 u8 res1;
55 u16 hciversion;
Patrick Georgi8fa27872011-11-24 13:19:57 +010056 u32 hcsparams;
57 u32 hccparams;
58 u64 hcsp_portroute;
Patrick Georgi7f43dc12010-09-25 17:01:13 +000059} __attribute__ ((packed)) hc_cap_t;
60
Patrick Georgi8bbdb612011-08-16 15:47:15 +020061typedef volatile struct {
Patrick Georgi8fa27872011-11-24 13:19:57 +010062 u32 usbcmd;
63#define HC_OP_RS 1
Anton Kochkov2fef58e2012-11-09 14:06:05 +010064#define HC_OP_HC_RESET (1 << 1)
Nico Huber62eb5b32012-05-25 10:09:13 +020065#define HC_OP_PERIODIC_SCHED_EN_SHIFT 4
66#define HC_OP_PERIODIC_SCHED_EN (1 << HC_OP_PERIODIC_SCHED_EN_SHIFT)
Patrick Georgi8fa27872011-11-24 13:19:57 +010067#define HC_OP_ASYNC_SCHED_EN_SHIFT 5
68#define HC_OP_ASYNC_SCHED_EN (1 << HC_OP_ASYNC_SCHED_EN_SHIFT)
69 u32 usbsts;
Nico Huber62eb5b32012-05-25 10:09:13 +020070#define HC_OP_PERIODIC_SCHED_STAT_SHIFT 14
71#define HC_OP_PERIODIC_SCHED_STAT (1 << HC_OP_PERIODIC_SCHED_STAT_SHIFT)
Patrick Georgi8fa27872011-11-24 13:19:57 +010072#define HC_OP_ASYNC_SCHED_STAT_SHIFT 15
73#define HC_OP_ASYNC_SCHED_STAT (1 << HC_OP_ASYNC_SCHED_STAT_SHIFT)
Anton Kochkov2fef58e2012-11-09 14:06:05 +010074#define HC_OP_HC_HALTED_SHIFT 12
75#define HC_OP_HC_HALTED (1 << HC_OP_HC_HALTED_SHIFT)
Patrick Georgi8fa27872011-11-24 13:19:57 +010076 u32 usbintr;
Patrick Georgi7f43dc12010-09-25 17:01:13 +000077 u32 frindex;
78 u32 ctrldssegment;
79 u32 periodiclistbase;
80 u32 asynclistaddr;
Stefan Reinauer441a4ba2013-05-17 11:56:09 -070081 u8 res1[0x40-0x1c];
Patrick Georgi7f43dc12010-09-25 17:01:13 +000082 u32 configflag;
83 portsc_t portsc[0];
Stefan Reinauer441a4ba2013-05-17 11:56:09 -070084} __attribute__ ((packed)) hc_op_t;
Patrick Georgi7f43dc12010-09-25 17:01:13 +000085
Patrick Georgi8bbdb612011-08-16 15:47:15 +020086typedef volatile struct {
Patrick Georgi8fa27872011-11-24 13:19:57 +010087#define QTD_TERMINATE 1
Nico Huber62eb5b32012-05-25 10:09:13 +020088#define QTD_PTR_MASK ~0x1f
Patrick Georgi8fa27872011-11-24 13:19:57 +010089 u32 next_qtd;
90 u32 alt_next_qtd;
91 u32 token;
92#define QTD_STATUS_MASK 0xff
Patrick Georgi3e0bd192012-01-31 14:37:59 +010093#define QTD_HALTED (1 << 6)
94#define QTD_ACTIVE (1 << 7)
Patrick Georgi8fa27872011-11-24 13:19:57 +010095#define QTD_PID_SHIFT 8
96#define QTD_PID_MASK (3 << QTD_PID_SHIFT)
97#define QTD_CERR_SHIFT 10
98#define QTD_CERR_MASK (3 << QTD_CERR_SHIFT)
99#define QTD_CPAGE_SHIFT 12
100#define QTD_CPAGE_MASK (7 << QTD_CPAGE_SHIFT)
101#define QTD_TOTAL_LEN_SHIFT 16
102#define QTD_TOTAL_LEN_MASK (((1<<15)-1) << QTD_TOTAL_LEN_SHIFT)
103#define QTD_TOGGLE_SHIFT 31
104#define QTD_TOGGLE_MASK (1 << 31)
105#define QTD_TOGGLE_DATA0 0
106#define QTD_TOGGLE_DATA1 (1 << QTD_TOGGLE_SHIFT)
107 u32 bufptrs[5];
Patrick Georgi7f43dc12010-09-25 17:01:13 +0000108 u32 bufptrs64[5];
109} __attribute__ ((packed)) qtd_t;
110
Patrick Georgi8bbdb612011-08-16 15:47:15 +0200111typedef volatile struct {
Patrick Georgi8fa27872011-11-24 13:19:57 +0100112 u32 horiz_link_ptr;
113#define QH_TERMINATE 1
114#define QH_iTD (0<<1)
115#define QH_QH (1<<1)
116#define QH_siTD (2<<1)
117#define QH_FSTN (3<<1)
118 u32 epchar;
119#define QH_EP_SHIFT 8
120#define QH_EPS_SHIFT 12
121#define QH_DTC_SHIFT 14
122#define QH_RECLAIM_HEAD_SHIFT 15
123#define QH_MPS_SHIFT 16
124#define QH_NON_HS_CTRL_EP_SHIFT 27
125#define QH_NAK_CNT_SHIFT 28
126 u32 epcaps;
Nico Huber62eb5b32012-05-25 10:09:13 +0200127#define QH_UFRAME_CMASK_SHIFT 8
Nico Huber1ab60752012-05-23 09:21:54 +0200128#define QH_HUB_ADDRESS_SHIFT 16
129#define QH_PORT_NUMBER_SHIFT 23
Patrick Georgi8fa27872011-11-24 13:19:57 +0100130#define QH_PIPE_MULTIPLIER_SHIFT 30
Patrick Georgi7f43dc12010-09-25 17:01:13 +0000131 volatile u32 current_td_ptr;
132 volatile qtd_t td;
Stefan Reinauer441a4ba2013-05-17 11:56:09 -0700133} __attribute__ ((packed)) ehci_qh_t;
Patrick Georgi7f43dc12010-09-25 17:01:13 +0000134
135typedef struct ehci {
136 hc_cap_t *capabilities;
137 hc_op_t *operation;
Nico Huber3ca35ca2012-06-14 13:27:39 +0200138 ehci_qh_t *dummy_qh;
Patrick Georgi7f43dc12010-09-25 17:01:13 +0000139} ehci_t;
140
Nico Huber62eb5b32012-05-25 10:09:13 +0200141#define PS_TERMINATE 1
142#define PS_TYPE_QH 1 << 1
143#define PS_PTR_MASK ~0x1f
144
Patrick Georgi7f43dc12010-09-25 17:01:13 +0000145
146#define EHCI_INST(controller) ((ehci_t*)((controller)->instance))
147
148#endif