Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project. |
| 6 | * |
| 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. |
| 10 | * |
| 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 |
| 14 | * more details. |
| 15 | * |
| 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 |
| 19 | * |
| 20 | * The full GNU General Public License is included in this distribution in the |
| 21 | * file called LICENSE. |
| 22 | * |
| 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 |
| 26 | * |
| 27 | *****************************************************************************/ |
| 28 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 29 | #ifndef __iwl3945_io_h__ |
| 30 | #define __iwl3945_io_h__ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 31 | |
| 32 | #include <linux/io.h> |
| 33 | |
Christoph Hellwig | 5d08cd1 | 2007-10-25 17:15:50 +0800 | [diff] [blame] | 34 | #include "iwl-3945-debug.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * IO, register, and NIC memory access functions |
| 38 | * |
| 39 | * NOTE on naming convention and macro usage for these |
| 40 | * |
| 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. |
| 43 | * |
| 44 | * A double __ prefix before an access function means that state is checked |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 45 | * and the current line number is printed in addition to any other debug output. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 46 | * |
| 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. |
| 49 | * |
| 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 |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 52 | * routines, for example _iwl3945_read_direct32 calls the non-check version of |
| 53 | * _iwl3945_read32.) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 54 | * |
| 55 | * These declarations are *extremely* useful in quickly isolating code deltas |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 56 | * which result in misconfiguration of the hardware I/O. In combination with |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 57 | * git-bisect and the IO debug level you can quickly determine the specific |
| 58 | * commit which breaks the IO sequence to the hardware. |
| 59 | * |
| 60 | */ |
| 61 | |
Tomas Winkler | f5efde3 | 2008-09-03 11:26:34 +0800 | [diff] [blame] | 62 | #define _iwl3945_write32(priv, ofs, val) iowrite32((val), (priv)->hw_base + (ofs)) |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 63 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 64 | static inline void __iwl3945_write32(const char *f, u32 l, struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 65 | u32 ofs, u32 val) |
| 66 | { |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 67 | IWL_DEBUG_IO("write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l); |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 68 | _iwl3945_write32(priv, ofs, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 69 | } |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 70 | #define iwl3945_write32(priv, ofs, val) \ |
| 71 | __iwl3945_write32(__FILE__, __LINE__, priv, ofs, val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 72 | #else |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 73 | #define iwl3945_write32(priv, ofs, val) _iwl3945_write32(priv, ofs, val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 74 | #endif |
| 75 | |
Tomas Winkler | f5efde3 | 2008-09-03 11:26:34 +0800 | [diff] [blame] | 76 | #define _iwl3945_read32(priv, ofs) ioread32((priv)->hw_base + (ofs)) |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 77 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 78 | static inline u32 __iwl3945_read32(char *f, u32 l, struct iwl3945_priv *priv, u32 ofs) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 79 | { |
| 80 | IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l); |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 81 | return _iwl3945_read32(priv, ofs); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 82 | } |
Tomas Winkler | f5efde3 | 2008-09-03 11:26:34 +0800 | [diff] [blame] | 83 | #define iwl3945_read32(priv, ofs)__iwl3945_read32(__FILE__, __LINE__, priv, ofs) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 84 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 85 | #define iwl3945_read32(p, o) _iwl3945_read32(p, o) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 86 | #endif |
| 87 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 88 | static inline int _iwl3945_poll_bit(struct iwl3945_priv *priv, u32 addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 89 | u32 bits, u32 mask, int timeout) |
| 90 | { |
| 91 | int i = 0; |
| 92 | |
| 93 | do { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 94 | if ((_iwl3945_read32(priv, addr) & mask) == (bits & mask)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 95 | return i; |
| 96 | mdelay(10); |
| 97 | i += 10; |
| 98 | } while (i < timeout); |
| 99 | |
| 100 | return -ETIMEDOUT; |
| 101 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 102 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 103 | static inline int __iwl3945_poll_bit(const char *f, u32 l, |
| 104 | struct iwl3945_priv *priv, u32 addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 105 | u32 bits, u32 mask, int timeout) |
| 106 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 107 | int ret = _iwl3945_poll_bit(priv, addr, bits, mask, timeout); |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 108 | IWL_DEBUG_IO("poll_bit(0x%08X, 0x%08X, 0x%08X) - %s- %s %d\n", |
| 109 | addr, bits, mask, |
| 110 | unlikely(ret == -ETIMEDOUT)?"timeout":"", f, l); |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 111 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 112 | } |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 113 | #define iwl3945_poll_bit(priv, addr, bits, mask, timeout) \ |
| 114 | __iwl3945_poll_bit(__FILE__, __LINE__, priv, addr, bits, mask, timeout) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 115 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 116 | #define iwl3945_poll_bit(p, a, b, m, t) _iwl3945_poll_bit(p, a, b, m, t) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 117 | #endif |
| 118 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 119 | static inline void _iwl3945_set_bit(struct iwl3945_priv *priv, u32 reg, u32 mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 120 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 121 | _iwl3945_write32(priv, reg, _iwl3945_read32(priv, reg) | mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 122 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 123 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 124 | static inline void __iwl3945_set_bit(const char *f, u32 l, |
| 125 | struct iwl3945_priv *priv, u32 reg, u32 mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 126 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 127 | u32 val = _iwl3945_read32(priv, reg) | mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 128 | IWL_DEBUG_IO("set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 129 | _iwl3945_write32(priv, reg, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 130 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 131 | #define iwl3945_set_bit(p, r, m) __iwl3945_set_bit(__FILE__, __LINE__, p, r, m) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 132 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 133 | #define iwl3945_set_bit(p, r, m) _iwl3945_set_bit(p, r, m) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 134 | #endif |
| 135 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 136 | static inline void _iwl3945_clear_bit(struct iwl3945_priv *priv, u32 reg, u32 mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 137 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 138 | _iwl3945_write32(priv, reg, _iwl3945_read32(priv, reg) & ~mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 139 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 140 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 141 | static inline void __iwl3945_clear_bit(const char *f, u32 l, |
| 142 | struct iwl3945_priv *priv, u32 reg, u32 mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 143 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 144 | u32 val = _iwl3945_read32(priv, reg) & ~mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 145 | IWL_DEBUG_IO("clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 146 | _iwl3945_write32(priv, reg, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 147 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 148 | #define iwl3945_clear_bit(p, r, m) __iwl3945_clear_bit(__FILE__, __LINE__, p, r, m) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 149 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 150 | #define iwl3945_clear_bit(p, r, m) _iwl3945_clear_bit(p, r, m) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 151 | #endif |
| 152 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 153 | static inline int _iwl3945_grab_nic_access(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 154 | { |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 155 | int ret; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 156 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 157 | if (atomic_read(&priv->restrict_refcnt)) |
| 158 | return 0; |
| 159 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 160 | /* this bit wakes up the NIC */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 161 | _iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 162 | ret = _iwl3945_poll_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 163 | CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN, |
| 164 | (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY | |
| 165 | CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 50); |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 166 | if (ret < 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 167 | IWL_ERROR("MAC is in deep sleep!\n"); |
| 168 | return -EIO; |
| 169 | } |
| 170 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 171 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 172 | atomic_inc(&priv->restrict_refcnt); |
| 173 | #endif |
| 174 | return 0; |
| 175 | } |
| 176 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 177 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 178 | static inline int __iwl3945_grab_nic_access(const char *f, u32 l, |
| 179 | struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 180 | { |
| 181 | if (atomic_read(&priv->restrict_refcnt)) |
| 182 | IWL_DEBUG_INFO("Grabbing access while already held at " |
| 183 | "line %d.\n", l); |
| 184 | |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 185 | IWL_DEBUG_IO("grabbing nic access - %s %d\n", f, l); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 186 | return _iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 187 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 188 | #define iwl3945_grab_nic_access(priv) \ |
| 189 | __iwl3945_grab_nic_access(__FILE__, __LINE__, priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 190 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 191 | #define iwl3945_grab_nic_access(priv) \ |
| 192 | _iwl3945_grab_nic_access(priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 193 | #endif |
| 194 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 195 | static inline void _iwl3945_release_nic_access(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 196 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 197 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 198 | if (atomic_dec_and_test(&priv->restrict_refcnt)) |
| 199 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 200 | _iwl3945_clear_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 201 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 202 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 203 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 204 | static inline void __iwl3945_release_nic_access(const char *f, u32 l, |
| 205 | struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 206 | { |
| 207 | if (atomic_read(&priv->restrict_refcnt) <= 0) |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 208 | IWL_ERROR("Release unheld nic access at line %d.\n", l); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 209 | |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 210 | IWL_DEBUG_IO("releasing nic access - %s %d\n", f, l); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 211 | _iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 212 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 213 | #define iwl3945_release_nic_access(priv) \ |
| 214 | __iwl3945_release_nic_access(__FILE__, __LINE__, priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 215 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 216 | #define iwl3945_release_nic_access(priv) \ |
| 217 | _iwl3945_release_nic_access(priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 218 | #endif |
| 219 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 220 | static inline u32 _iwl3945_read_direct32(struct iwl3945_priv *priv, u32 reg) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 221 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 222 | return _iwl3945_read32(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 223 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 224 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 225 | static inline u32 __iwl3945_read_direct32(const char *f, u32 l, |
| 226 | struct iwl3945_priv *priv, u32 reg) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 227 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 228 | u32 value = _iwl3945_read_direct32(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 229 | if (!atomic_read(&priv->restrict_refcnt)) |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 230 | IWL_ERROR("Nic access not held from %s %d\n", f, l); |
| 231 | IWL_DEBUG_IO("read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 232 | f, l); |
| 233 | return value; |
| 234 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 235 | #define iwl3945_read_direct32(priv, reg) \ |
| 236 | __iwl3945_read_direct32(__FILE__, __LINE__, priv, reg) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 237 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 238 | #define iwl3945_read_direct32 _iwl3945_read_direct32 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 239 | #endif |
| 240 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 241 | static inline void _iwl3945_write_direct32(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 242 | u32 reg, u32 value) |
| 243 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 244 | _iwl3945_write32(priv, reg, value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 245 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 246 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 247 | static void __iwl3945_write_direct32(u32 line, |
| 248 | struct iwl3945_priv *priv, u32 reg, u32 value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 249 | { |
| 250 | if (!atomic_read(&priv->restrict_refcnt)) |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 251 | IWL_ERROR("Nic access not held from line %d\n", line); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 252 | _iwl3945_write_direct32(priv, reg, value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 253 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 254 | #define iwl3945_write_direct32(priv, reg, value) \ |
| 255 | __iwl3945_write_direct32(__LINE__, priv, reg, value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 256 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 257 | #define iwl3945_write_direct32 _iwl3945_write_direct32 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 258 | #endif |
| 259 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 260 | static inline void iwl3945_write_reg_buf(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 261 | u32 reg, u32 len, u32 *values) |
| 262 | { |
| 263 | u32 count = sizeof(u32); |
| 264 | |
| 265 | if ((priv != NULL) && (values != NULL)) { |
| 266 | for (; 0 < len; len -= count, reg += count, values++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 267 | _iwl3945_write_direct32(priv, reg, *values); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 271 | static inline int _iwl3945_poll_direct_bit(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 272 | u32 addr, u32 mask, int timeout) |
| 273 | { |
| 274 | int i = 0; |
| 275 | |
| 276 | do { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 277 | if ((_iwl3945_read_direct32(priv, addr) & mask) == mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 278 | return i; |
| 279 | mdelay(10); |
| 280 | i += 10; |
| 281 | } while (i < timeout); |
| 282 | |
| 283 | return -ETIMEDOUT; |
| 284 | } |
| 285 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 286 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 287 | static inline int __iwl3945_poll_direct_bit(const char *f, u32 l, |
| 288 | struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 289 | u32 addr, u32 mask, int timeout) |
| 290 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 291 | int ret = _iwl3945_poll_direct_bit(priv, addr, mask, timeout); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 292 | |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 293 | if (unlikely(ret == -ETIMEDOUT)) |
| 294 | IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 295 | "timedout - %s %d\n", addr, mask, f, l); |
| 296 | else |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 297 | IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) = 0x%08X " |
| 298 | "- %s %d\n", addr, mask, ret, f, l); |
| 299 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 300 | } |
Tomas Winkler | 5c1b095 | 2008-02-13 11:32:30 -0800 | [diff] [blame] | 301 | #define iwl3945_poll_direct_bit(priv, addr, mask, timeout) \ |
| 302 | __iwl3945_poll_direct_bit(__FILE__, __LINE__, priv, addr, mask, timeout) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 303 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 304 | #define iwl3945_poll_direct_bit _iwl3945_poll_direct_bit |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 305 | #endif |
| 306 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 307 | static inline u32 _iwl3945_read_prph(struct iwl3945_priv *priv, u32 reg) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 308 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 309 | _iwl3945_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24)); |
| 310 | return _iwl3945_read_direct32(priv, HBUS_TARG_PRPH_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 311 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 312 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 313 | static inline u32 __iwl3945_read_prph(u32 line, struct iwl3945_priv *priv, u32 reg) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 314 | { |
| 315 | if (!atomic_read(&priv->restrict_refcnt)) |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 316 | IWL_ERROR("Nic access not held from line %d\n", line); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 317 | return _iwl3945_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 320 | #define iwl3945_read_prph(priv, reg) \ |
| 321 | __iwl3945_read_prph(__LINE__, priv, reg) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 322 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 323 | #define iwl3945_read_prph _iwl3945_read_prph |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 324 | #endif |
| 325 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 326 | static inline void _iwl3945_write_prph(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 327 | u32 addr, u32 val) |
| 328 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 329 | _iwl3945_write_direct32(priv, HBUS_TARG_PRPH_WADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 330 | ((addr & 0x0000FFFF) | (3 << 24))); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 331 | _iwl3945_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 332 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 333 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 334 | static inline void __iwl3945_write_prph(u32 line, struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 335 | u32 addr, u32 val) |
| 336 | { |
| 337 | if (!atomic_read(&priv->restrict_refcnt)) |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 338 | IWL_ERROR("Nic access from line %d\n", line); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 339 | _iwl3945_write_prph(priv, addr, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 342 | #define iwl3945_write_prph(priv, addr, val) \ |
| 343 | __iwl3945_write_prph(__LINE__, priv, addr, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 344 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 345 | #define iwl3945_write_prph _iwl3945_write_prph |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 346 | #endif |
| 347 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 348 | #define _iwl3945_set_bits_prph(priv, reg, mask) \ |
| 349 | _iwl3945_write_prph(priv, reg, (_iwl3945_read_prph(priv, reg) | mask)) |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 350 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 351 | static inline void __iwl3945_set_bits_prph(u32 line, struct iwl3945_priv *priv, |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 352 | u32 reg, u32 mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 353 | { |
| 354 | if (!atomic_read(&priv->restrict_refcnt)) |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 355 | IWL_ERROR("Nic access not held from line %d\n", line); |
| 356 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 357 | _iwl3945_set_bits_prph(priv, reg, mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 358 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 359 | #define iwl3945_set_bits_prph(priv, reg, mask) \ |
| 360 | __iwl3945_set_bits_prph(__LINE__, priv, reg, mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 361 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 362 | #define iwl3945_set_bits_prph _iwl3945_set_bits_prph |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 363 | #endif |
| 364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 365 | #define _iwl3945_set_bits_mask_prph(priv, reg, bits, mask) \ |
| 366 | _iwl3945_write_prph(priv, reg, ((_iwl3945_read_prph(priv, reg) & mask) | bits)) |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 367 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 368 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 369 | static inline void __iwl3945_set_bits_mask_prph(u32 line, |
| 370 | struct iwl3945_priv *priv, u32 reg, u32 bits, u32 mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | { |
| 372 | if (!atomic_read(&priv->restrict_refcnt)) |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 373 | IWL_ERROR("Nic access not held from line %d\n", line); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 374 | _iwl3945_set_bits_mask_prph(priv, reg, bits, mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 375 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 376 | #define iwl3945_set_bits_mask_prph(priv, reg, bits, mask) \ |
| 377 | __iwl3945_set_bits_mask_prph(__LINE__, priv, reg, bits, mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 378 | #else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 379 | #define iwl3945_set_bits_mask_prph _iwl3945_set_bits_mask_prph |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | #endif |
| 381 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 382 | static inline void iwl3945_clear_bits_prph(struct iwl3945_priv |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 383 | *priv, u32 reg, u32 mask) |
| 384 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 385 | u32 val = _iwl3945_read_prph(priv, reg); |
| 386 | _iwl3945_write_prph(priv, reg, (val & ~mask)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 389 | static inline u32 iwl3945_read_targ_mem(struct iwl3945_priv *priv, u32 addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 390 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 391 | iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr); |
| 392 | return iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 395 | static inline void iwl3945_write_targ_mem(struct iwl3945_priv *priv, u32 addr, u32 val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 396 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 397 | iwl3945_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); |
| 398 | iwl3945_write_direct32(priv, HBUS_TARG_MEM_WDAT, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 401 | static inline void iwl3945_write_targ_mem_buf(struct iwl3945_priv *priv, u32 addr, |
Tomas Winkler | af7cca2 | 2007-10-25 17:15:36 +0800 | [diff] [blame] | 402 | u32 len, u32 *values) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 403 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 404 | iwl3945_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 405 | for (; 0 < len; len -= sizeof(u32), values++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 406 | iwl3945_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 407 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 408 | #endif |