Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | 4e31826 | 2011-12-27 11:21:32 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -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 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 25 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | * |
| 27 | *****************************************************************************/ |
Emmanuel Grumbach | 83ed901 | 2011-08-25 23:11:14 -0700 | [diff] [blame] | 28 | #include <linux/delay.h> |
| 29 | #include <linux/device.h> |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 30 | #include <linux/export.h> |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 31 | |
| 32 | #include "iwl-io.h" |
Paul Bolle | 6ac7d11 | 2012-06-06 14:17:46 +0200 | [diff] [blame] | 33 | #include "iwl-csr.h" |
Emmanuel Grumbach | 83ed901 | 2011-08-25 23:11:14 -0700 | [diff] [blame] | 34 | #include "iwl-debug.h" |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 35 | |
| 36 | #define IWL_POLL_INTERVAL 10 /* microseconds */ |
| 37 | |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 38 | void __iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 39 | { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 40 | iwl_write32(trans, reg, iwl_read32(trans, reg) | mask); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 43 | void __iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 44 | { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 45 | iwl_write32(trans, reg, iwl_read32(trans, reg) & ~mask); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 48 | void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 49 | { |
| 50 | unsigned long flags; |
| 51 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 52 | spin_lock_irqsave(&trans->reg_lock, flags); |
| 53 | __iwl_set_bit(trans, reg, mask); |
| 54 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 55 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 56 | EXPORT_SYMBOL_GPL(iwl_set_bit); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 57 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 58 | void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 59 | { |
| 60 | unsigned long flags; |
| 61 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 62 | spin_lock_irqsave(&trans->reg_lock, flags); |
| 63 | __iwl_clear_bit(trans, reg, mask); |
| 64 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 65 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 66 | EXPORT_SYMBOL_GPL(iwl_clear_bit); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 67 | |
Johannes Berg | 2baa2e57 | 2012-05-29 14:47:30 +0200 | [diff] [blame] | 68 | void iwl_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value) |
| 69 | { |
| 70 | unsigned long flags; |
| 71 | u32 v; |
| 72 | |
| 73 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 74 | WARN_ON_ONCE(value & ~mask); |
| 75 | #endif |
| 76 | |
| 77 | spin_lock_irqsave(&trans->reg_lock, flags); |
| 78 | v = iwl_read32(trans, reg); |
| 79 | v &= ~mask; |
| 80 | v |= value; |
| 81 | iwl_write32(trans, reg, v); |
| 82 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
| 83 | } |
| 84 | EXPORT_SYMBOL_GPL(iwl_set_bits_mask); |
| 85 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 86 | int iwl_poll_bit(struct iwl_trans *trans, u32 addr, |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 87 | u32 bits, u32 mask, int timeout) |
| 88 | { |
| 89 | int t = 0; |
| 90 | |
| 91 | do { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 92 | if ((iwl_read32(trans, addr) & mask) == (bits & mask)) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 93 | return t; |
| 94 | udelay(IWL_POLL_INTERVAL); |
| 95 | t += IWL_POLL_INTERVAL; |
| 96 | } while (t < timeout); |
| 97 | |
| 98 | return -ETIMEDOUT; |
| 99 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 100 | EXPORT_SYMBOL_GPL(iwl_poll_bit); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 101 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 102 | u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 103 | { |
| 104 | u32 value; |
| 105 | unsigned long flags; |
| 106 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 107 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 108 | iwl_trans_grab_nic_access(trans, false); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 109 | value = iwl_read32(trans, reg); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 110 | iwl_trans_release_nic_access(trans); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 111 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 112 | |
| 113 | return value; |
| 114 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 115 | EXPORT_SYMBOL_GPL(iwl_read_direct32); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 116 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 117 | void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 118 | { |
| 119 | unsigned long flags; |
| 120 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 121 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 122 | if (likely(iwl_trans_grab_nic_access(trans, false))) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 123 | iwl_write32(trans, reg, value); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 124 | iwl_trans_release_nic_access(trans); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 125 | } |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 126 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 127 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 128 | EXPORT_SYMBOL_GPL(iwl_write_direct32); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 129 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 130 | int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask, |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 131 | int timeout) |
| 132 | { |
| 133 | int t = 0; |
| 134 | |
| 135 | do { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 136 | if ((iwl_read_direct32(trans, addr) & mask) == mask) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 137 | return t; |
| 138 | udelay(IWL_POLL_INTERVAL); |
| 139 | t += IWL_POLL_INTERVAL; |
| 140 | } while (t < timeout); |
| 141 | |
| 142 | return -ETIMEDOUT; |
| 143 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 144 | EXPORT_SYMBOL_GPL(iwl_poll_direct_bit); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 145 | |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 146 | static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 147 | { |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 148 | u32 val = iwl_trans_read_prph(trans, ofs); |
| 149 | trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val); |
| 150 | return val; |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 153 | static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 154 | { |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 155 | trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val); |
| 156 | iwl_trans_write_prph(trans, ofs, val); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 159 | u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 160 | { |
| 161 | unsigned long flags; |
| 162 | u32 val; |
| 163 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 164 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 165 | iwl_trans_grab_nic_access(trans, false); |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 166 | val = __iwl_read_prph(trans, ofs); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 167 | iwl_trans_release_nic_access(trans); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 168 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 169 | return val; |
| 170 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 171 | EXPORT_SYMBOL_GPL(iwl_read_prph); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 172 | |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 173 | void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 174 | { |
| 175 | unsigned long flags; |
| 176 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 177 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 178 | if (likely(iwl_trans_grab_nic_access(trans, false))) { |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 179 | __iwl_write_prph(trans, ofs, val); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 180 | iwl_trans_release_nic_access(trans); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 181 | } |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 182 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 183 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 184 | EXPORT_SYMBOL_GPL(iwl_write_prph); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 185 | |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 186 | void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 187 | { |
| 188 | unsigned long flags; |
| 189 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 190 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 191 | if (likely(iwl_trans_grab_nic_access(trans, false))) { |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 192 | __iwl_write_prph(trans, ofs, |
| 193 | __iwl_read_prph(trans, ofs) | mask); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 194 | iwl_trans_release_nic_access(trans); |
Stanislaw Gruszka | bfe4b80 | 2012-03-07 09:52:24 -0800 | [diff] [blame] | 195 | } |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 196 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 197 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 198 | EXPORT_SYMBOL_GPL(iwl_set_bits_prph); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 199 | |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 200 | void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 201 | u32 bits, u32 mask) |
| 202 | { |
| 203 | unsigned long flags; |
| 204 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 205 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 206 | if (likely(iwl_trans_grab_nic_access(trans, false))) { |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 207 | __iwl_write_prph(trans, ofs, |
| 208 | (__iwl_read_prph(trans, ofs) & mask) | bits); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 209 | iwl_trans_release_nic_access(trans); |
Stanislaw Gruszka | bfe4b80 | 2012-03-07 09:52:24 -0800 | [diff] [blame] | 210 | } |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 211 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 212 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 213 | EXPORT_SYMBOL_GPL(iwl_set_bits_mask_prph); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 214 | |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 215 | void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 216 | { |
| 217 | unsigned long flags; |
| 218 | u32 val; |
| 219 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 220 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 221 | if (likely(iwl_trans_grab_nic_access(trans, false))) { |
Emmanuel Grumbach | 6a06b6c | 2012-12-02 13:07:30 +0200 | [diff] [blame] | 222 | val = __iwl_read_prph(trans, ofs); |
| 223 | __iwl_write_prph(trans, ofs, (val & ~mask)); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 224 | iwl_trans_release_nic_access(trans); |
Stanislaw Gruszka | bfe4b80 | 2012-03-07 09:52:24 -0800 | [diff] [blame] | 225 | } |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 226 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 227 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 228 | EXPORT_SYMBOL_GPL(iwl_clear_bits_prph); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 229 | |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 230 | void _iwl_read_targ_mem_dwords(struct iwl_trans *trans, u32 addr, |
| 231 | void *buf, int dwords) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 232 | { |
| 233 | unsigned long flags; |
Johannes Berg | e46f653 | 2011-04-13 03:14:43 -0700 | [diff] [blame] | 234 | int offs; |
| 235 | u32 *vals = buf; |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 236 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 237 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 238 | if (likely(iwl_trans_grab_nic_access(trans, false))) { |
Stanislaw Gruszka | bfe4b80 | 2012-03-07 09:52:24 -0800 | [diff] [blame] | 239 | iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr); |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 240 | for (offs = 0; offs < dwords; offs++) |
Stanislaw Gruszka | bfe4b80 | 2012-03-07 09:52:24 -0800 | [diff] [blame] | 241 | vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 242 | iwl_trans_release_nic_access(trans); |
Stanislaw Gruszka | bfe4b80 | 2012-03-07 09:52:24 -0800 | [diff] [blame] | 243 | } |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 244 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Johannes Berg | e46f653 | 2011-04-13 03:14:43 -0700 | [diff] [blame] | 245 | } |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 246 | EXPORT_SYMBOL_GPL(_iwl_read_targ_mem_dwords); |
Johannes Berg | e46f653 | 2011-04-13 03:14:43 -0700 | [diff] [blame] | 247 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 248 | u32 iwl_read_targ_mem(struct iwl_trans *trans, u32 addr) |
Johannes Berg | e46f653 | 2011-04-13 03:14:43 -0700 | [diff] [blame] | 249 | { |
| 250 | u32 value; |
| 251 | |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 252 | _iwl_read_targ_mem_dwords(trans, addr, &value, 1); |
Johannes Berg | e46f653 | 2011-04-13 03:14:43 -0700 | [diff] [blame] | 253 | |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 254 | return value; |
| 255 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 256 | EXPORT_SYMBOL_GPL(iwl_read_targ_mem); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 257 | |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 258 | int _iwl_write_targ_mem_dwords(struct iwl_trans *trans, u32 addr, |
Emmanuel Grumbach | 986ea6c | 2012-09-30 16:25:43 +0200 | [diff] [blame] | 259 | const void *buf, int dwords) |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 260 | { |
| 261 | unsigned long flags; |
Hsu, Kenny | ee8ba88 | 2011-12-09 03:11:18 -0800 | [diff] [blame] | 262 | int offs, result = 0; |
Emmanuel Grumbach | 986ea6c | 2012-09-30 16:25:43 +0200 | [diff] [blame] | 263 | const u32 *vals = buf; |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 264 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 265 | spin_lock_irqsave(&trans->reg_lock, flags); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 266 | if (likely(iwl_trans_grab_nic_access(trans, false))) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 267 | iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr); |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 268 | for (offs = 0; offs < dwords; offs++) |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 269 | iwl_write32(trans, HBUS_TARG_MEM_WDAT, vals[offs]); |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 270 | iwl_trans_release_nic_access(trans); |
| 271 | } else { |
Hsu, Kenny | ee8ba88 | 2011-12-09 03:11:18 -0800 | [diff] [blame] | 272 | result = -EBUSY; |
Emmanuel Grumbach | 7a65d17 | 2012-12-24 15:01:24 +0200 | [diff] [blame^] | 273 | } |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 274 | spin_unlock_irqrestore(&trans->reg_lock, flags); |
Hsu, Kenny | ee8ba88 | 2011-12-09 03:11:18 -0800 | [diff] [blame] | 275 | |
| 276 | return result; |
| 277 | } |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 278 | EXPORT_SYMBOL_GPL(_iwl_write_targ_mem_dwords); |
Hsu, Kenny | ee8ba88 | 2011-12-09 03:11:18 -0800 | [diff] [blame] | 279 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 280 | int iwl_write_targ_mem(struct iwl_trans *trans, u32 addr, u32 val) |
Hsu, Kenny | ee8ba88 | 2011-12-09 03:11:18 -0800 | [diff] [blame] | 281 | { |
Emmanuel Grumbach | e4b1681 | 2012-06-06 08:18:40 +0300 | [diff] [blame] | 282 | return _iwl_write_targ_mem_dwords(trans, addr, &val, 1); |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 283 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 284 | EXPORT_SYMBOL_GPL(iwl_write_targ_mem); |