wireless: use __packed in ieee80211.h
[carl9170fw.git] / carlfw / usb / fifo.c
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * Copyright (c) 2000-2005  ZyDAS Technology Corporation
5  * Copyright (c) 2007-2009 Atheros Communications, Inc.
6  * Copyright    2009    Johannes Berg <johannes@sipsolutions.net>
7  * Copyright 2009-2011  Christian Lamparter <chunkeey@googlemail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "carl9170.h"
25 #include "printf.h"
26 #include "rom.h"
27 #include "usb_fifo.h"
28
29 /* TODO / TOTEST */
30 #ifdef CONFIG_CARL9170FW_USB_MODESWITCH
31 static void usb_ep_map(const uint8_t ep, const uint8_t map)
32 {
33         setb(AR9170_USB_REG_EP_MAP + (ep - 1), map);
34 }
35
36 static void usb_fifo_map(const uint8_t fifo, const uint8_t map)
37 {
38         setb(AR9170_USB_REG_FIFO_MAP + (fifo - 1), map);
39 }
40
41 static void usb_fifo_config(const uint8_t fifo, const uint8_t cfg)
42 {
43         setb(AR9170_USB_REG_FIFO_CONFIG + (fifo - 1), cfg);
44 }
45
46 static void usb_ep_packet_size_hi(const uint8_t ep, const uint8_t dir,
47                              const uint16_t size)
48 {
49         setb(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (((dir * 0x20) + ep) << 1),
50              (size >> 8) & 0xf);
51 }
52
53 static void usb_ep_packet_size_lo(const uint8_t ep, const uint8_t dir,
54                             const uint16_t size)
55 {
56         setb(AR9170_USB_REG_EP_IN_MAX_SIZE_LOW + (((dir * 0x20) + ep) << 1),
57              size & 0xff);
58 }
59
60 static void usb_ep_in_highbandset(const uint8_t ep, const uint8_t dir,
61                                 const uint16_t size)
62 {
63         andb(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (ep << 1), ~(BIT(6) | BIT(5)));
64
65         switch (dir) {
66         case DIRECTION_IN:
67                 setb(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (ep << 1),
68                      ((size >> 11) + 1) << 5);
69                 break;
70         case DIRECTION_OUT:
71         default:
72                 break;
73         }
74 }
75
76 /*
77  *      vUsbFIFO_EPxCfg_HS(void)
78  *      Description:
79  *          1. Configure the FIFO and EPx map
80  *      input: none
81  *      output: none
82  */
83
84 void usb_init_highspeed_fifo_cfg(void)
85 {
86         int i;
87
88         /* EP 1 */
89         usb_ep_map(1, HS_C1_I0_A0_EP1_MAP);
90         usb_fifo_map(HS_C1_I0_A0_EP1_FIFO_START, HS_C1_I0_A0_EP1_FIFO_MAP);
91         usb_fifo_config(HS_C1_I0_A0_EP1_FIFO_START, HS_C1_I0_A0_EP1_FIFO_CONFIG);
92
93         for (i = HS_C1_I0_A0_EP1_FIFO_START + 1;
94              i < HS_C1_I0_A0_EP1_FIFO_START + HS_C1_I0_A0_EP1_FIFO_NO; i++) {
95                 usb_fifo_config(i, (HS_C1_I0_A0_EP1_FIFO_CONFIG & (~BIT(7))));
96         }
97
98         usb_ep_packet_size_hi(1, HS_C1_I0_A0_EP1_DIRECTION, (HS_C1_I0_A0_EP1_MAX_PACKET & 0x7ff));
99         usb_ep_packet_size_lo(1, HS_C1_I0_A0_EP1_DIRECTION, (HS_C1_I0_A0_EP1_MAX_PACKET & 0x7ff));
100         usb_ep_in_highbandset(1, HS_C1_I0_A0_EP1_DIRECTION, HS_C1_I0_A0_EP1_MAX_PACKET);
101
102         /* EP 2 */
103         usb_ep_map(2, HS_C1_I0_A0_EP2_MAP);
104         usb_fifo_map(HS_C1_I0_A0_EP2_FIFO_START, HS_C1_I0_A0_EP2_FIFO_MAP);
105         usb_fifo_config(HS_C1_I0_A0_EP2_FIFO_START, HS_C1_I0_A0_EP2_FIFO_CONFIG);
106
107         for (i = HS_C1_I0_A0_EP2_FIFO_START + 1;
108              i < HS_C1_I0_A0_EP2_FIFO_START + HS_C1_I0_A0_EP2_FIFO_NO; i++) {
109                 usb_fifo_config(i, (HS_C1_I0_A0_EP2_FIFO_CONFIG & (~BIT(7))));
110         }
111
112         usb_ep_packet_size_hi(2, HS_C1_I0_A0_EP2_DIRECTION, (HS_C1_I0_A0_EP2_MAX_PACKET & 0x7ff));
113         usb_ep_packet_size_lo(2, HS_C1_I0_A0_EP2_DIRECTION, (HS_C1_I0_A0_EP2_MAX_PACKET & 0x7ff));
114         usb_ep_in_highbandset(2, HS_C1_I0_A0_EP2_DIRECTION, HS_C1_I0_A0_EP2_MAX_PACKET);
115
116         /* EP 3 */
117         usb_ep_map(3, HS_C1_I0_A0_EP3_MAP);
118         usb_fifo_map(HS_C1_I0_A0_EP3_FIFO_START, HS_C1_I0_A0_EP3_FIFO_MAP);
119         usb_fifo_config(HS_C1_I0_A0_EP3_FIFO_START, HS_C1_I0_A0_EP3_FIFO_CONFIG);
120
121         for (i = HS_C1_I0_A0_EP3_FIFO_START + 1;
122              i < HS_C1_I0_A0_EP3_FIFO_START + HS_C1_I0_A0_EP3_FIFO_NO; i++) {
123                 usb_fifo_config(i, (HS_C1_I0_A0_EP3_FIFO_CONFIG & (~BIT(7))));
124         }
125
126         usb_ep_packet_size_hi(3, HS_C1_I0_A0_EP3_DIRECTION, (HS_C1_I0_A0_EP3_MAX_PACKET & 0x7ff));
127         usb_ep_packet_size_lo(3, HS_C1_I0_A0_EP3_DIRECTION, (HS_C1_I0_A0_EP3_MAX_PACKET & 0x7ff));
128         usb_ep_in_highbandset(3, HS_C1_I0_A0_EP3_DIRECTION, HS_C1_I0_A0_EP3_MAX_PACKET);
129
130         /* EP 4 */
131         usb_ep_map(4, HS_C1_I0_A0_EP4_MAP);
132         usb_fifo_map(HS_C1_I0_A0_EP4_FIFO_START, HS_C1_I0_A0_EP4_FIFO_MAP);
133         usb_fifo_config(HS_C1_I0_A0_EP4_FIFO_START, HS_C1_I0_A0_EP4_FIFO_CONFIG);
134
135         for (i = HS_C1_I0_A0_EP4_FIFO_START + 1;
136              i < HS_C1_I0_A0_EP4_FIFO_START + HS_C1_I0_A0_EP4_FIFO_NO; i++) {
137                 usb_fifo_config(i, (HS_C1_I0_A0_EP4_FIFO_CONFIG & (~BIT(7))));
138         }
139
140         usb_ep_packet_size_hi(4, HS_C1_I0_A0_EP4_DIRECTION, (HS_C1_I0_A0_EP4_MAX_PACKET & 0x7ff));
141         usb_ep_packet_size_lo(4, HS_C1_I0_A0_EP4_DIRECTION, (HS_C1_I0_A0_EP4_MAX_PACKET & 0x7ff));
142         usb_ep_in_highbandset(4, HS_C1_I0_A0_EP4_DIRECTION, HS_C1_I0_A0_EP4_MAX_PACKET);
143 }
144
145 void usb_init_fullspeed_fifo_cfg(void)
146 {
147         int i;
148
149         /* EP 1 */
150         usb_ep_map(1, FS_C1_I0_A0_EP1_MAP);
151         usb_fifo_map(FS_C1_I0_A0_EP1_FIFO_START, FS_C1_I0_A0_EP1_FIFO_MAP);
152         usb_fifo_config(FS_C1_I0_A0_EP1_FIFO_START, FS_C1_I0_A0_EP1_FIFO_CONFIG);
153
154         for (i = FS_C1_I0_A0_EP1_FIFO_START + 1;
155              i < FS_C1_I0_A0_EP1_FIFO_START + FS_C1_I0_A0_EP1_FIFO_NO; i++) {
156                 usb_fifo_config(i, (FS_C1_I0_A0_EP1_FIFO_CONFIG & (~BIT(7))));
157         }
158
159         usb_ep_packet_size_hi(1, FS_C1_I0_A0_EP1_DIRECTION, (FS_C1_I0_A0_EP1_MAX_PACKET & 0x7ff));
160         usb_ep_packet_size_lo(1, FS_C1_I0_A0_EP1_DIRECTION, (FS_C1_I0_A0_EP1_MAX_PACKET & 0x7ff));
161         /* ``.JWEI 2003/04/29 */
162         usb_ep_in_highbandset(1, FS_C1_I0_A0_EP1_DIRECTION, FS_C1_I0_A0_EP1_MAX_PACKET);
163
164         /* EP 2 */
165         usb_ep_map(2, FS_C1_I0_A0_EP2_MAP);
166         usb_fifo_map(FS_C1_I0_A0_EP2_FIFO_START, FS_C1_I0_A0_EP2_FIFO_MAP);
167         usb_fifo_config(FS_C1_I0_A0_EP2_FIFO_START, FS_C1_I0_A0_EP2_FIFO_CONFIG);
168
169         for (i = FS_C1_I0_A0_EP2_FIFO_START + 1;
170              i < FS_C1_I0_A0_EP2_FIFO_START + FS_C1_I0_A0_EP2_FIFO_NO; i++) {
171                 usb_fifo_config(i, (FS_C1_I0_A0_EP2_FIFO_CONFIG & (~BIT(7))));
172         }
173
174         usb_ep_packet_size_hi(2, FS_C1_I0_A0_EP2_DIRECTION, (FS_C1_I0_A0_EP2_MAX_PACKET & 0x7ff));
175         usb_ep_packet_size_lo(2, FS_C1_I0_A0_EP2_DIRECTION, (FS_C1_I0_A0_EP2_MAX_PACKET & 0x7ff));
176         usb_ep_in_highbandset(2, FS_C1_I0_A0_EP2_DIRECTION, FS_C1_I0_A0_EP2_MAX_PACKET);
177
178         /* EP 3 */
179         usb_ep_map(3, FS_C1_I0_A0_EP3_MAP);
180         usb_fifo_map(FS_C1_I0_A0_EP3_FIFO_START, FS_C1_I0_A0_EP3_FIFO_MAP);
181         usb_fifo_config(FS_C1_I0_A0_EP3_FIFO_START, FS_C1_I0_A0_EP3_FIFO_CONFIG);
182
183         for (i = FS_C1_I0_A0_EP3_FIFO_START + 1;
184              i < FS_C1_I0_A0_EP3_FIFO_START + FS_C1_I0_A0_EP3_FIFO_NO; i++) {
185                 usb_fifo_config(i, (FS_C1_I0_A0_EP3_FIFO_CONFIG & (~BIT(7))));
186         }
187
188         usb_ep_packet_size_hi(3, FS_C1_I0_A0_EP3_DIRECTION, (FS_C1_I0_A0_EP3_MAX_PACKET & 0x7ff));
189         usb_ep_packet_size_lo(3, FS_C1_I0_A0_EP3_DIRECTION, (FS_C1_I0_A0_EP3_MAX_PACKET & 0x7ff));
190         usb_ep_in_highbandset(3, FS_C1_I0_A0_EP3_DIRECTION, FS_C1_I0_A0_EP3_MAX_PACKET);
191
192         /* EP 4 */
193         usb_ep_map(4, FS_C1_I0_A0_EP4_MAP);
194         usb_fifo_map(FS_C1_I0_A0_EP4_FIFO_START, FS_C1_I0_A0_EP4_FIFO_MAP);
195         usb_fifo_config(FS_C1_I0_A0_EP4_FIFO_START, FS_C1_I0_A0_EP4_FIFO_CONFIG);
196
197         for (i = FS_C1_I0_A0_EP4_FIFO_START + 1;
198              i < FS_C1_I0_A0_EP4_FIFO_START + FS_C1_I0_A0_EP4_FIFO_NO; i++) {
199                 usb_fifo_config(i, (FS_C1_I0_A0_EP4_FIFO_CONFIG & (~BIT(7))));
200         }
201
202         usb_ep_packet_size_hi(4, FS_C1_I0_A0_EP4_DIRECTION, (FS_C1_I0_A0_EP4_MAX_PACKET & 0x7ff));
203         usb_ep_packet_size_lo(4, FS_C1_I0_A0_EP4_DIRECTION, (FS_C1_I0_A0_EP4_MAX_PACKET & 0x7ff));
204         usb_ep_in_highbandset(4, FS_C1_I0_A0_EP4_DIRECTION, FS_C1_I0_A0_EP4_MAX_PACKET);
205 }
206 #endif /* CONFIG_CARL9170FW_USB_MODESWITCH */