1
/******************************************************************************
3
* Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
5
* Portions of this file are derived from the ipw3945 project.
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of version 2 of the GNU General Public License as
9
* published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
* You should have received a copy of the GNU General Public License along with
17
* this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20
* The full GNU General Public License is included in this distribution in the
21
* file called LICENSE.
23
* Contact Information:
24
* James P. Ketrenos <ipw2100-admin@linux.intel.com>
25
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
*****************************************************************************/
29
#ifndef __iwl3945_io_h__
30
#define __iwl3945_io_h__
34
#include "iwl-3945-debug.h"
37
* IO, register, and NIC memory access functions
39
* NOTE on naming convention and macro usage for these
41
* A single _ prefix before a an access function means that no state
42
* check or debug information is printed when that function is called.
44
* A double __ prefix before an access function means that state is checked
45
* and the current line number is printed in addition to any other debug output.
47
* The non-prefixed name is the #define that maps the caller into a
48
* #define that provides the caller's __LINE__ to the double prefix version.
50
* If you wish to call the function without any debug or state checking,
51
* you should use the single _ prefix version (as is used by dependent IO
52
* routines, for example _iwl3945_read_direct32 calls the non-check version of
55
* These declarations are *extremely* useful in quickly isolating code deltas
56
* which result in misconfiguring of the hardware I/O. In combination with
57
* git-bisect and the IO debug level you can quickly determine the specific
58
* commit which breaks the IO sequence to the hardware.
62
#define _iwl3945_write32(iwl, ofs, val) writel((val), (iwl)->hw_base + (ofs))
63
#ifdef CONFIG_IWL3945_DEBUG
64
static inline void __iwl3945_write32(const char *f, u32 l, struct iwl3945_priv *iwl,
67
IWL_DEBUG_IO("write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l);
68
_iwl3945_write32(iwl, ofs, val);
70
#define iwl3945_write32(iwl, ofs, val) \
71
__iwl3945_write32(__FILE__, __LINE__, iwl, ofs, val)
73
#define iwl3945_write32(iwl, ofs, val) _iwl3945_write32(iwl, ofs, val)
76
#define _iwl3945_read32(iwl, ofs) readl((iwl)->hw_base + (ofs))
77
#ifdef CONFIG_IWL3945_DEBUG
78
static inline u32 __iwl3945_read32(char *f, u32 l, struct iwl3945_priv *iwl, u32 ofs)
80
IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l);
81
return _iwl3945_read32(iwl, ofs);
83
#define iwl3945_read32(iwl, ofs) __iwl3945_read32(__FILE__, __LINE__, iwl, ofs)
85
#define iwl3945_read32(p, o) _iwl3945_read32(p, o)
88
static inline int _iwl3945_poll_bit(struct iwl3945_priv *priv, u32 addr,
89
u32 bits, u32 mask, int timeout)
94
if ((_iwl3945_read32(priv, addr) & mask) == (bits & mask))
98
} while (i < timeout);
102
#ifdef CONFIG_IWL3945_DEBUG
103
static inline int __iwl3945_poll_bit(const char *f, u32 l,
104
struct iwl3945_priv *priv, u32 addr,
105
u32 bits, u32 mask, int timeout)
107
int ret = _iwl3945_poll_bit(priv, addr, bits, mask, timeout);
108
if (unlikely(ret == -ETIMEDOUT))
110
("poll_bit(0x%08X, 0x%08X, 0x%08X) - timedout - %s %d\n",
111
addr, bits, mask, f, l);
114
("poll_bit(0x%08X, 0x%08X, 0x%08X) = 0x%08X - %s %d\n",
115
addr, bits, mask, ret, f, l);
118
#define iwl3945_poll_bit(iwl, addr, bits, mask, timeout) \
119
__iwl3945_poll_bit(__FILE__, __LINE__, iwl, addr, bits, mask, timeout)
121
#define iwl3945_poll_bit(p, a, b, m, t) _iwl3945_poll_bit(p, a, b, m, t)
124
static inline void _iwl3945_set_bit(struct iwl3945_priv *priv, u32 reg, u32 mask)
126
_iwl3945_write32(priv, reg, _iwl3945_read32(priv, reg) | mask);
128
#ifdef CONFIG_IWL3945_DEBUG
129
static inline void __iwl3945_set_bit(const char *f, u32 l,
130
struct iwl3945_priv *priv, u32 reg, u32 mask)
132
u32 val = _iwl3945_read32(priv, reg) | mask;
133
IWL_DEBUG_IO("set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
134
_iwl3945_write32(priv, reg, val);
136
#define iwl3945_set_bit(p, r, m) __iwl3945_set_bit(__FILE__, __LINE__, p, r, m)
138
#define iwl3945_set_bit(p, r, m) _iwl3945_set_bit(p, r, m)
141
static inline void _iwl3945_clear_bit(struct iwl3945_priv *priv, u32 reg, u32 mask)
143
_iwl3945_write32(priv, reg, _iwl3945_read32(priv, reg) & ~mask);
145
#ifdef CONFIG_IWL3945_DEBUG
146
static inline void __iwl3945_clear_bit(const char *f, u32 l,
147
struct iwl3945_priv *priv, u32 reg, u32 mask)
149
u32 val = _iwl3945_read32(priv, reg) & ~mask;
150
IWL_DEBUG_IO("clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
151
_iwl3945_write32(priv, reg, val);
153
#define iwl3945_clear_bit(p, r, m) __iwl3945_clear_bit(__FILE__, __LINE__, p, r, m)
155
#define iwl3945_clear_bit(p, r, m) _iwl3945_clear_bit(p, r, m)
158
static inline int _iwl3945_grab_nic_access(struct iwl3945_priv *priv)
163
#ifdef CONFIG_IWL3945_DEBUG
164
if (atomic_read(&priv->restrict_refcnt))
167
if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
168
test_bit(STATUS_RF_KILL_SW, &priv->status)) {
169
IWL_WARNING("WARNING: Requesting MAC access during RFKILL "
172
/* 10 msec allows time for NIC to complete its data save */
173
gp_ctl = _iwl3945_read32(priv, CSR_GP_CNTRL);
174
if (gp_ctl & CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY) {
175
IWL_DEBUG_RF_KILL("Wait for complete power-down, "
176
"gpctl = 0x%08x\n", gp_ctl);
179
IWL_DEBUG_RF_KILL("power-down complete, "
180
"gpctl = 0x%08x\n", gp_ctl);
183
/* this bit wakes up the NIC */
184
_iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
185
ret = _iwl3945_poll_bit(priv, CSR_GP_CNTRL,
186
CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
187
(CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
188
CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 50);
190
IWL_ERROR("MAC is in deep sleep!\n");
194
#ifdef CONFIG_IWL3945_DEBUG
195
atomic_inc(&priv->restrict_refcnt);
200
#ifdef CONFIG_IWL3945_DEBUG
201
static inline int __iwl3945_grab_nic_access(const char *f, u32 l,
202
struct iwl3945_priv *priv)
204
if (atomic_read(&priv->restrict_refcnt))
205
IWL_DEBUG_INFO("Grabbing access while already held at "
208
IWL_DEBUG_IO("grabbing nic access - %s %d\n", f, l);
209
return _iwl3945_grab_nic_access(priv);
211
#define iwl3945_grab_nic_access(priv) \
212
__iwl3945_grab_nic_access(__FILE__, __LINE__, priv)
214
#define iwl3945_grab_nic_access(priv) \
215
_iwl3945_grab_nic_access(priv)
218
static inline void _iwl3945_release_nic_access(struct iwl3945_priv *priv)
220
#ifdef CONFIG_IWL3945_DEBUG
221
if (atomic_dec_and_test(&priv->restrict_refcnt))
223
_iwl3945_clear_bit(priv, CSR_GP_CNTRL,
224
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
226
#ifdef CONFIG_IWL3945_DEBUG
227
static inline void __iwl3945_release_nic_access(const char *f, u32 l,
228
struct iwl3945_priv *priv)
230
if (atomic_read(&priv->restrict_refcnt) <= 0)
231
IWL_ERROR("Release unheld nic access at line %d.\n", l);
233
IWL_DEBUG_IO("releasing nic access - %s %d\n", f, l);
234
_iwl3945_release_nic_access(priv);
236
#define iwl3945_release_nic_access(priv) \
237
__iwl3945_release_nic_access(__FILE__, __LINE__, priv)
239
#define iwl3945_release_nic_access(priv) \
240
_iwl3945_release_nic_access(priv)
243
static inline u32 _iwl3945_read_direct32(struct iwl3945_priv *priv, u32 reg)
245
return _iwl3945_read32(priv, reg);
247
#ifdef CONFIG_IWL3945_DEBUG
248
static inline u32 __iwl3945_read_direct32(const char *f, u32 l,
249
struct iwl3945_priv *priv, u32 reg)
251
u32 value = _iwl3945_read_direct32(priv, reg);
252
if (!atomic_read(&priv->restrict_refcnt))
253
IWL_ERROR("Nic access not held from %s %d\n", f, l);
254
IWL_DEBUG_IO("read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value,
258
#define iwl3945_read_direct32(priv, reg) \
259
__iwl3945_read_direct32(__FILE__, __LINE__, priv, reg)
261
#define iwl3945_read_direct32 _iwl3945_read_direct32
264
static inline void _iwl3945_write_direct32(struct iwl3945_priv *priv,
267
_iwl3945_write32(priv, reg, value);
269
#ifdef CONFIG_IWL3945_DEBUG
270
static void __iwl3945_write_direct32(u32 line,
271
struct iwl3945_priv *priv, u32 reg, u32 value)
273
if (!atomic_read(&priv->restrict_refcnt))
274
IWL_ERROR("Nic access not held from line %d\n", line);
275
_iwl3945_write_direct32(priv, reg, value);
277
#define iwl3945_write_direct32(priv, reg, value) \
278
__iwl3945_write_direct32(__LINE__, priv, reg, value)
280
#define iwl3945_write_direct32 _iwl3945_write_direct32
283
static inline void iwl3945_write_reg_buf(struct iwl3945_priv *priv,
284
u32 reg, u32 len, u32 *values)
286
u32 count = sizeof(u32);
288
if ((priv != NULL) && (values != NULL)) {
289
for (; 0 < len; len -= count, reg += count, values++)
290
_iwl3945_write_direct32(priv, reg, *values);
294
static inline int _iwl3945_poll_direct_bit(struct iwl3945_priv *priv,
295
u32 addr, u32 mask, int timeout)
300
if ((_iwl3945_read_direct32(priv, addr) & mask) == mask)
304
} while (i < timeout);
309
#ifdef CONFIG_IWL3945_DEBUG
310
static inline int __iwl3945_poll_direct_bit(const char *f, u32 l,
311
struct iwl3945_priv *priv,
312
u32 addr, u32 mask, int timeout)
314
int ret = _iwl3945_poll_direct_bit(priv, addr, mask, timeout);
316
if (unlikely(ret == -ETIMEDOUT))
317
IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) - "
318
"timedout - %s %d\n", addr, mask, f, l);
320
IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) = 0x%08X "
321
"- %s %d\n", addr, mask, ret, f, l);
324
#define iwl3945_poll_direct_bit(iwl, addr, mask, timeout) \
325
__iwl3945_poll_direct_bit(__FILE__, __LINE__, iwl, addr, mask, timeout)
327
#define iwl3945_poll_direct_bit _iwl3945_poll_direct_bit
330
static inline u32 _iwl3945_read_prph(struct iwl3945_priv *priv, u32 reg)
332
_iwl3945_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
333
return _iwl3945_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
335
#ifdef CONFIG_IWL3945_DEBUG
336
static inline u32 __iwl3945_read_prph(u32 line, struct iwl3945_priv *priv, u32 reg)
338
if (!atomic_read(&priv->restrict_refcnt))
339
IWL_ERROR("Nic access not held from line %d\n", line);
340
return _iwl3945_read_prph(priv, reg);
343
#define iwl3945_read_prph(priv, reg) \
344
__iwl3945_read_prph(__LINE__, priv, reg)
346
#define iwl3945_read_prph _iwl3945_read_prph
349
static inline void _iwl3945_write_prph(struct iwl3945_priv *priv,
352
_iwl3945_write_direct32(priv, HBUS_TARG_PRPH_WADDR,
353
((addr & 0x0000FFFF) | (3 << 24)));
354
_iwl3945_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
356
#ifdef CONFIG_IWL3945_DEBUG
357
static inline void __iwl3945_write_prph(u32 line, struct iwl3945_priv *priv,
360
if (!atomic_read(&priv->restrict_refcnt))
361
IWL_ERROR("Nic access from line %d\n", line);
362
_iwl3945_write_prph(priv, addr, val);
365
#define iwl3945_write_prph(priv, addr, val) \
366
__iwl3945_write_prph(__LINE__, priv, addr, val);
368
#define iwl3945_write_prph _iwl3945_write_prph
371
#define _iwl3945_set_bits_prph(priv, reg, mask) \
372
_iwl3945_write_prph(priv, reg, (_iwl3945_read_prph(priv, reg) | mask))
373
#ifdef CONFIG_IWL3945_DEBUG
374
static inline void __iwl3945_set_bits_prph(u32 line, struct iwl3945_priv *priv,
377
if (!atomic_read(&priv->restrict_refcnt))
378
IWL_ERROR("Nic access not held from line %d\n", line);
380
_iwl3945_set_bits_prph(priv, reg, mask);
382
#define iwl3945_set_bits_prph(priv, reg, mask) \
383
__iwl3945_set_bits_prph(__LINE__, priv, reg, mask)
385
#define iwl3945_set_bits_prph _iwl3945_set_bits_prph
388
#define _iwl3945_set_bits_mask_prph(priv, reg, bits, mask) \
389
_iwl3945_write_prph(priv, reg, ((_iwl3945_read_prph(priv, reg) & mask) | bits))
391
#ifdef CONFIG_IWL3945_DEBUG
392
static inline void __iwl3945_set_bits_mask_prph(u32 line,
393
struct iwl3945_priv *priv, u32 reg, u32 bits, u32 mask)
395
if (!atomic_read(&priv->restrict_refcnt))
396
IWL_ERROR("Nic access not held from line %d\n", line);
397
_iwl3945_set_bits_mask_prph(priv, reg, bits, mask);
399
#define iwl3945_set_bits_mask_prph(priv, reg, bits, mask) \
400
__iwl3945_set_bits_mask_prph(__LINE__, priv, reg, bits, mask)
402
#define iwl3945_set_bits_mask_prph _iwl3945_set_bits_mask_prph
405
static inline void iwl3945_clear_bits_prph(struct iwl3945_priv
406
*priv, u32 reg, u32 mask)
408
u32 val = _iwl3945_read_prph(priv, reg);
409
_iwl3945_write_prph(priv, reg, (val & ~mask));
412
static inline u32 iwl3945_read_targ_mem(struct iwl3945_priv *priv, u32 addr)
414
iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
415
return iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
418
static inline void iwl3945_write_targ_mem(struct iwl3945_priv *priv, u32 addr, u32 val)
420
iwl3945_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
421
iwl3945_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
424
static inline void iwl3945_write_targ_mem_buf(struct iwl3945_priv *priv, u32 addr,
425
u32 len, u32 *values)
427
iwl3945_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
428
for (; 0 < len; len -= sizeof(u32), values++)
429
iwl3945_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);