1 /******************************************************************************
3 * Copyright(c) 2003 - 2013 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 * Intel Linux Wireless <ilw@linux.intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28 #include <linux/delay.h>
29 #include <linux/device.h>
30 #include <linux/export.h>
35 #include "iwl-debug.h"
37 #define IWL_POLL_INTERVAL 10 /* microseconds */
39 int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
40 u32 bits, u32 mask, int timeout)
45 if ((iwl_read32(trans, addr) & mask) == (bits & mask))
47 udelay(IWL_POLL_INTERVAL);
48 t += IWL_POLL_INTERVAL;
49 } while (t < timeout);
53 IWL_EXPORT_SYMBOL(iwl_poll_bit);
55 u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
57 u32 value = 0x5a5a5a5a;
59 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
60 value = iwl_read32(trans, reg);
61 iwl_trans_release_nic_access(trans, &flags);
66 IWL_EXPORT_SYMBOL(iwl_read_direct32);
68 void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
72 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
73 iwl_write32(trans, reg, value);
74 iwl_trans_release_nic_access(trans, &flags);
77 IWL_EXPORT_SYMBOL(iwl_write_direct32);
79 int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
85 if ((iwl_read_direct32(trans, addr) & mask) == mask)
87 udelay(IWL_POLL_INTERVAL);
88 t += IWL_POLL_INTERVAL;
89 } while (t < timeout);
93 IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
95 static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
97 u32 val = iwl_trans_read_prph(trans, ofs);
98 trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
102 static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
104 trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
105 iwl_trans_write_prph(trans, ofs, val);
108 u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
111 u32 val = 0x5a5a5a5a;
113 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
114 val = __iwl_read_prph(trans, ofs);
115 iwl_trans_release_nic_access(trans, &flags);
119 IWL_EXPORT_SYMBOL(iwl_read_prph);
121 void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
125 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
126 __iwl_write_prph(trans, ofs, val);
127 iwl_trans_release_nic_access(trans, &flags);
130 IWL_EXPORT_SYMBOL(iwl_write_prph);
132 void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
136 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
137 __iwl_write_prph(trans, ofs,
138 __iwl_read_prph(trans, ofs) | mask);
139 iwl_trans_release_nic_access(trans, &flags);
142 IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
144 void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
149 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
150 __iwl_write_prph(trans, ofs,
151 (__iwl_read_prph(trans, ofs) & mask) | bits);
152 iwl_trans_release_nic_access(trans, &flags);
155 IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
157 void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
162 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
163 val = __iwl_read_prph(trans, ofs);
164 __iwl_write_prph(trans, ofs, (val & ~mask));
165 iwl_trans_release_nic_access(trans, &flags);
168 IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);