| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Broadcom B43 wireless driver | 
					
						
							|  |  |  |   Common PHY routines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>, | 
					
						
							|  |  |  |   Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it> | 
					
						
							| 
									
										
										
										
											2011-07-04 20:50:05 +02:00
										 |  |  |   Copyright (c) 2005-2008 Michael Buesch <m@bues.ch> | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  |   Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org> | 
					
						
							|  |  |  |   Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |   it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |   the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |   (at your option) any later version. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |   GNU General Public License for more details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |   along with this program; see the file COPYING.  If not, write to | 
					
						
							|  |  |  |   the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, | 
					
						
							|  |  |  |   Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "phy_common.h"
 | 
					
						
							|  |  |  | #include "phy_g.h"
 | 
					
						
							|  |  |  | #include "phy_a.h"
 | 
					
						
							| 
									
										
										
										
											2008-08-30 02:27:19 +02:00
										 |  |  | #include "phy_n.h"
 | 
					
						
							| 
									
										
										
										
											2008-08-30 10:55:48 +02:00
										 |  |  | #include "phy_lp.h"
 | 
					
						
							| 
									
										
										
										
											2011-06-13 16:20:06 +02:00
										 |  |  | #include "phy_ht.h"
 | 
					
						
							| 
									
										
										
										
											2011-07-07 18:58:25 +02:00
										 |  |  | #include "phy_lcn.h"
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | #include "b43.h"
 | 
					
						
							|  |  |  | #include "main.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-02 13:00:34 +02:00
										 |  |  | int b43_phy_allocate(struct b43_wldev *dev) | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct b43_phy *phy = &(dev->phy); | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	phy->ops = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (phy->type) { | 
					
						
							|  |  |  | 	case B43_PHYTYPE_A: | 
					
						
							|  |  |  | 		phy->ops = &b43_phyops_a; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case B43_PHYTYPE_G: | 
					
						
							|  |  |  | 		phy->ops = &b43_phyops_g; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case B43_PHYTYPE_N: | 
					
						
							| 
									
										
										
										
											2010-12-07 21:56:00 +01:00
										 |  |  | #ifdef CONFIG_B43_PHY_N
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 		phy->ops = &b43_phyops_n; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case B43_PHYTYPE_LP: | 
					
						
							| 
									
										
										
										
											2008-08-30 10:55:48 +02:00
										 |  |  | #ifdef CONFIG_B43_PHY_LP
 | 
					
						
							|  |  |  | 		phy->ops = &b43_phyops_lp; | 
					
						
							| 
									
										
										
										
											2011-06-13 16:20:06 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case B43_PHYTYPE_HT: | 
					
						
							|  |  |  | #ifdef CONFIG_B43_PHY_HT
 | 
					
						
							|  |  |  | 		phy->ops = &b43_phyops_ht; | 
					
						
							| 
									
										
										
										
											2011-07-07 18:58:25 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case B43_PHYTYPE_LCN: | 
					
						
							|  |  |  | #ifdef CONFIG_B43_PHY_LCN
 | 
					
						
							|  |  |  | 		phy->ops = &b43_phyops_lcn; | 
					
						
							| 
									
										
										
										
											2008-08-30 10:55:48 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (B43_WARN_ON(!phy->ops)) | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = phy->ops->allocate(dev); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		phy->ops = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-02 13:00:34 +02:00
										 |  |  | void b43_phy_free(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dev->phy.ops->free(dev); | 
					
						
							|  |  |  | 	dev->phy.ops = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | int b43_phy_init(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct b43_phy *phy = &dev->phy; | 
					
						
							|  |  |  | 	const struct b43_phy_operations *ops = phy->ops; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	phy->channel = ops->get_default_chan(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 13:01:37 +02:00
										 |  |  | 	ops->software_rfkill(dev, false); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	err = ops->init(dev); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		b43err(dev->wl, "PHY init failed\n"); | 
					
						
							|  |  |  | 		goto err_block_rf; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* Make sure to switch hardware and firmware (SHM) to
 | 
					
						
							|  |  |  | 	 * the default channel. */ | 
					
						
							|  |  |  | 	err = b43_switch_channel(dev, ops->get_default_chan(dev)); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		b43err(dev->wl, "PHY init: Channel switch to default failed\n"); | 
					
						
							|  |  |  | 		goto err_phy_exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_phy_exit: | 
					
						
							|  |  |  | 	if (ops->exit) | 
					
						
							|  |  |  | 		ops->exit(dev); | 
					
						
							|  |  |  | err_block_rf: | 
					
						
							| 
									
										
										
										
											2009-06-02 13:01:37 +02:00
										 |  |  | 	ops->software_rfkill(dev, true); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_phy_exit(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const struct b43_phy_operations *ops = dev->phy.ops; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 13:01:37 +02:00
										 |  |  | 	ops->software_rfkill(dev, true); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	if (ops->exit) | 
					
						
							|  |  |  | 		ops->exit(dev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool b43_has_hardware_pctl(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!dev->phy.hardware_power_control) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	if (!dev->phy.ops->supports_hwpctl) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	return dev->phy.ops->supports_hwpctl(dev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_radio_lock(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 macctl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 12:27:32 +02:00
										 |  |  | #if B43_DEBUG
 | 
					
						
							|  |  |  | 	B43_WARN_ON(dev->phy.radio_locked); | 
					
						
							| 
									
										
										
										
											2011-12-19 13:56:45 +00:00
										 |  |  | 	dev->phy.radio_locked = true; | 
					
						
							| 
									
										
										
										
											2009-03-31 12:27:32 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	macctl = b43_read32(dev, B43_MMIO_MACCTL); | 
					
						
							|  |  |  | 	macctl |= B43_MACCTL_RADIOLOCK; | 
					
						
							|  |  |  | 	b43_write32(dev, B43_MMIO_MACCTL, macctl); | 
					
						
							| 
									
										
										
										
											2009-03-31 12:27:32 +02:00
										 |  |  | 	/* Commit the write and wait for the firmware
 | 
					
						
							|  |  |  | 	 * to finish any radio register access. */ | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	b43_read32(dev, B43_MMIO_MACCTL); | 
					
						
							|  |  |  | 	udelay(10); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_radio_unlock(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 macctl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 12:27:32 +02:00
										 |  |  | #if B43_DEBUG
 | 
					
						
							|  |  |  | 	B43_WARN_ON(!dev->phy.radio_locked); | 
					
						
							| 
									
										
										
										
											2011-12-19 13:56:45 +00:00
										 |  |  | 	dev->phy.radio_locked = false; | 
					
						
							| 
									
										
										
										
											2009-03-31 12:27:32 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	/* Commit any write */ | 
					
						
							|  |  |  | 	b43_read16(dev, B43_MMIO_PHY_VER); | 
					
						
							|  |  |  | 	/* unlock */ | 
					
						
							|  |  |  | 	macctl = b43_read32(dev, B43_MMIO_MACCTL); | 
					
						
							|  |  |  | 	macctl &= ~B43_MACCTL_RADIOLOCK; | 
					
						
							|  |  |  | 	b43_write32(dev, B43_MMIO_MACCTL, macctl); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_phy_lock(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if B43_DEBUG
 | 
					
						
							|  |  |  | 	B43_WARN_ON(dev->phy.phy_locked); | 
					
						
							| 
									
										
										
										
											2011-12-19 13:56:45 +00:00
										 |  |  | 	dev->phy.phy_locked = true; | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-05-18 02:06:38 +02:00
										 |  |  | 	B43_WARN_ON(dev->dev->core_rev < 3); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-11 00:01:58 +02:00
										 |  |  | 	if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP)) | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 		b43_power_saving_ctl_bits(dev, B43_PS_AWAKE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_phy_unlock(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if B43_DEBUG
 | 
					
						
							|  |  |  | 	B43_WARN_ON(!dev->phy.phy_locked); | 
					
						
							| 
									
										
										
										
											2011-12-19 13:56:45 +00:00
										 |  |  | 	dev->phy.phy_locked = false; | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-05-18 02:06:38 +02:00
										 |  |  | 	B43_WARN_ON(dev->dev->core_rev < 3); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-11 00:01:58 +02:00
										 |  |  | 	if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP)) | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 		b43_power_saving_ctl_bits(dev, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 22:13:39 +01:00
										 |  |  | static inline void assert_mac_suspended(struct b43_wldev *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!B43_DEBUG) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	if ((b43_status(dev) >= B43_STAT_INITIALIZED) && | 
					
						
							|  |  |  | 	    (dev->mac_suspended <= 0)) { | 
					
						
							|  |  |  | 		b43dbg(dev->wl, "PHY/RADIO register access with " | 
					
						
							|  |  |  | 		       "enabled MAC.\n"); | 
					
						
							|  |  |  | 		dump_stack(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | u16 b43_radio_read(struct b43_wldev *dev, u16 reg) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-18 22:13:39 +01:00
										 |  |  | 	assert_mac_suspended(dev); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	return dev->phy.ops->radio_read(dev, reg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_radio_write(struct b43_wldev *dev, u16 reg, u16 value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-18 22:13:39 +01:00
										 |  |  | 	assert_mac_suspended(dev); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	dev->phy.ops->radio_write(dev, reg, value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	b43_radio_write16(dev, offset, | 
					
						
							|  |  |  | 			  b43_radio_read16(dev, offset) & mask); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	b43_radio_write16(dev, offset, | 
					
						
							|  |  |  | 			  b43_radio_read16(dev, offset) | set); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	b43_radio_write16(dev, offset, | 
					
						
							|  |  |  | 			  (b43_radio_read16(dev, offset) & mask) | set); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-26 00:07:37 +02:00
										 |  |  | bool b43_radio_wait_value(struct b43_wldev *dev, u16 offset, u16 mask, | 
					
						
							|  |  |  | 			  u16 value, int delay, int timeout) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16 val; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < timeout; i += delay) { | 
					
						
							|  |  |  | 		val = b43_radio_read(dev, offset); | 
					
						
							|  |  |  | 		if ((val & mask) == value) | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		udelay(delay); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | u16 b43_phy_read(struct b43_wldev *dev, u16 reg) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-18 22:13:39 +01:00
										 |  |  | 	assert_mac_suspended(dev); | 
					
						
							| 
									
										
										
										
											2010-12-07 09:42:07 +01:00
										 |  |  | 	dev->phy.writes_counter = 0; | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	return dev->phy.ops->phy_read(dev, reg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-18 22:13:39 +01:00
										 |  |  | 	assert_mac_suspended(dev); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	dev->phy.ops->phy_write(dev, reg, value); | 
					
						
							| 
									
										
										
										
											2010-12-07 09:42:07 +01:00
										 |  |  | 	if (++dev->phy.writes_counter == B43_MAX_WRITES_IN_ROW) { | 
					
						
							|  |  |  | 		b43_read16(dev, B43_MMIO_PHY_VER); | 
					
						
							|  |  |  | 		dev->phy.writes_counter = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-03 01:28:12 +02:00
										 |  |  | void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assert_mac_suspended(dev); | 
					
						
							|  |  |  | 	dev->phy.ops->phy_write(dev, destreg, | 
					
						
							|  |  |  | 		dev->phy.ops->phy_read(dev, srcreg)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
											
												b43: Fix and update LP-PHY code
-Fix a few nasty typos (b43_phy_* operations instead of b43_radio_*)
 in the channel tune routines.
-Fix some typos & spec errors found by MMIO tracing.
-Optimize b43_phy_write & b43_phy_mask/set/maskset to use
 only the minimal number of MMIO accesses. (Write is possible
 using a single 32-bit MMIO write, while set/mask/maskset can
 be done in 3 16-bit MMIOs).
-Set the default channel back to 1, as the bug forcing us to use
 channel 7 is now fixed.
With this, the device comes up, scans, associates, transmits,
receives, monitors and injects on all channels - in other words,
it's fully functional. Sensitivity and TX power are still sub-optimal,
due to the lack of calibration (that's next on my list).
Signed-off-by: Gábor Stefanik <netrolller.3d@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
											
										 
											2009-08-26 20:51:25 +02:00
										 |  |  | 	if (dev->phy.ops->phy_maskset) { | 
					
						
							|  |  |  | 		assert_mac_suspended(dev); | 
					
						
							|  |  |  | 		dev->phy.ops->phy_maskset(dev, offset, mask, 0); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		b43_phy_write(dev, offset, | 
					
						
							|  |  |  | 			      b43_phy_read(dev, offset) & mask); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
											
												b43: Fix and update LP-PHY code
-Fix a few nasty typos (b43_phy_* operations instead of b43_radio_*)
 in the channel tune routines.
-Fix some typos & spec errors found by MMIO tracing.
-Optimize b43_phy_write & b43_phy_mask/set/maskset to use
 only the minimal number of MMIO accesses. (Write is possible
 using a single 32-bit MMIO write, while set/mask/maskset can
 be done in 3 16-bit MMIOs).
-Set the default channel back to 1, as the bug forcing us to use
 channel 7 is now fixed.
With this, the device comes up, scans, associates, transmits,
receives, monitors and injects on all channels - in other words,
it's fully functional. Sensitivity and TX power are still sub-optimal,
due to the lack of calibration (that's next on my list).
Signed-off-by: Gábor Stefanik <netrolller.3d@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
											
										 
											2009-08-26 20:51:25 +02:00
										 |  |  | 	if (dev->phy.ops->phy_maskset) { | 
					
						
							|  |  |  | 		assert_mac_suspended(dev); | 
					
						
							|  |  |  | 		dev->phy.ops->phy_maskset(dev, offset, 0xFFFF, set); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		b43_phy_write(dev, offset, | 
					
						
							|  |  |  | 			      b43_phy_read(dev, offset) | set); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
											
												b43: Fix and update LP-PHY code
-Fix a few nasty typos (b43_phy_* operations instead of b43_radio_*)
 in the channel tune routines.
-Fix some typos & spec errors found by MMIO tracing.
-Optimize b43_phy_write & b43_phy_mask/set/maskset to use
 only the minimal number of MMIO accesses. (Write is possible
 using a single 32-bit MMIO write, while set/mask/maskset can
 be done in 3 16-bit MMIOs).
-Set the default channel back to 1, as the bug forcing us to use
 channel 7 is now fixed.
With this, the device comes up, scans, associates, transmits,
receives, monitors and injects on all channels - in other words,
it's fully functional. Sensitivity and TX power are still sub-optimal,
due to the lack of calibration (that's next on my list).
Signed-off-by: Gábor Stefanik <netrolller.3d@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
											
										 
											2009-08-26 20:51:25 +02:00
										 |  |  | 	if (dev->phy.ops->phy_maskset) { | 
					
						
							|  |  |  | 		assert_mac_suspended(dev); | 
					
						
							|  |  |  | 		dev->phy.ops->phy_maskset(dev, offset, mask, set); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		b43_phy_write(dev, offset, | 
					
						
							|  |  |  | 			      (b43_phy_read(dev, offset) & mask) | set); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct b43_phy *phy = &(dev->phy); | 
					
						
							|  |  |  | 	u16 channelcookie, savedcookie; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (new_channel == B43_DEFAULT_CHANNEL) | 
					
						
							|  |  |  | 		new_channel = phy->ops->get_default_chan(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* First we set the channel radio code to prevent the
 | 
					
						
							|  |  |  | 	 * firmware from sending ghost packets. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	channelcookie = new_channel; | 
					
						
							|  |  |  | 	if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ) | 
					
						
							| 
									
										
										
										
											2010-10-06 07:50:07 +02:00
										 |  |  | 		channelcookie |= B43_SHM_SH_CHAN_5GHZ; | 
					
						
							|  |  |  | 	/* FIXME: set 40Mhz flag if required */ | 
					
						
							|  |  |  | 	if (0) | 
					
						
							|  |  |  | 		channelcookie |= B43_SHM_SH_CHAN_40MHZ; | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | 	savedcookie = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN); | 
					
						
							|  |  |  | 	b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Now try to switch the PHY hardware channel. */ | 
					
						
							|  |  |  | 	err = phy->ops->switch_channel(dev, new_channel); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto err_restore_cookie; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dev->phy.channel = new_channel; | 
					
						
							|  |  |  | 	/* Wait for the radio to tune to the channel and stabilize. */ | 
					
						
							|  |  |  | 	msleep(8); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_restore_cookie: | 
					
						
							|  |  |  | 	b43_shm_write16(dev, B43_SHM_SHARED, | 
					
						
							|  |  |  | 			B43_SHM_SH_CHAN, savedcookie); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 13:01:37 +02:00
										 |  |  | void b43_software_rfkill(struct b43_wldev *dev, bool blocked) | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct b43_phy *phy = &dev->phy; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-19 18:40:00 +01:00
										 |  |  | 	b43_mac_suspend(dev); | 
					
						
							| 
									
										
										
										
											2009-06-02 13:01:37 +02:00
										 |  |  | 	phy->ops->software_rfkill(dev, blocked); | 
					
						
							|  |  |  | 	phy->radio_on = !blocked; | 
					
						
							| 
									
										
										
										
											2008-12-19 18:40:00 +01:00
										 |  |  | 	b43_mac_enable(dev); | 
					
						
							| 
									
										
										
										
											2008-08-27 18:53:02 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-08-28 19:33:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * b43_phy_txpower_adjust_work - TX power workqueue. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Workqueue for updating the TX power parameters in hardware. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void b43_phy_txpower_adjust_work(struct work_struct *work) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct b43_wl *wl = container_of(work, struct b43_wl, | 
					
						
							|  |  |  | 					 txpower_adjust_work); | 
					
						
							|  |  |  | 	struct b43_wldev *dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&wl->mutex); | 
					
						
							|  |  |  | 	dev = wl->current_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (likely(dev && (b43_status(dev) >= B43_STAT_STARTED))) | 
					
						
							|  |  |  | 		dev->phy.ops->adjust_txpower(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_unlock(&wl->mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct b43_phy *phy = &dev->phy; | 
					
						
							|  |  |  | 	unsigned long now = jiffies; | 
					
						
							|  |  |  | 	enum b43_txpwr_result result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(flags & B43_TXPWR_IGNORE_TIME)) { | 
					
						
							|  |  |  | 		/* Check if it's time for a TXpower check. */ | 
					
						
							|  |  |  | 		if (time_before(now, phy->next_txpwr_check_time)) | 
					
						
							|  |  |  | 			return; /* Not yet */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* The next check will be needed in two seconds, or later. */ | 
					
						
							|  |  |  | 	phy->next_txpwr_check_time = round_jiffies(now + (HZ * 2)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-18 02:06:42 +02:00
										 |  |  | 	if ((dev->dev->board_vendor == SSB_BOARDVENDOR_BCM) && | 
					
						
							|  |  |  | 	    (dev->dev->board_type == SSB_BOARD_BU4306)) | 
					
						
							| 
									
										
										
										
											2008-08-28 19:33:40 +02:00
										 |  |  | 		return; /* No software txpower adjustment needed */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = phy->ops->recalc_txpower(dev, !!(flags & B43_TXPWR_IGNORE_TSSI)); | 
					
						
							|  |  |  | 	if (result == B43_TXPWR_RES_DONE) | 
					
						
							|  |  |  | 		return; /* We are done. */ | 
					
						
							|  |  |  | 	B43_WARN_ON(result != B43_TXPWR_RES_NEED_ADJUST); | 
					
						
							|  |  |  | 	B43_WARN_ON(phy->ops->adjust_txpower == NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We must adjust the transmission power in hardware.
 | 
					
						
							|  |  |  | 	 * Schedule b43_phy_txpower_adjust_work(). */ | 
					
						
							| 
									
										
										
										
											2009-07-29 20:08:07 -04:00
										 |  |  | 	ieee80211_queue_work(dev->wl->hw, &dev->wl->txpower_adjust_work); | 
					
						
							| 
									
										
										
										
											2008-08-28 19:33:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const bool is_ofdm = (shm_offset != B43_SHM_SH_TSSI_CCK); | 
					
						
							|  |  |  | 	unsigned int a, b, c, d; | 
					
						
							|  |  |  | 	unsigned int average; | 
					
						
							|  |  |  | 	u32 tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tmp = b43_shm_read32(dev, B43_SHM_SHARED, shm_offset); | 
					
						
							|  |  |  | 	a = tmp & 0xFF; | 
					
						
							|  |  |  | 	b = (tmp >> 8) & 0xFF; | 
					
						
							|  |  |  | 	c = (tmp >> 16) & 0xFF; | 
					
						
							|  |  |  | 	d = (tmp >> 24) & 0xFF; | 
					
						
							|  |  |  | 	if (a == 0 || a == B43_TSSI_MAX || | 
					
						
							|  |  |  | 	    b == 0 || b == B43_TSSI_MAX || | 
					
						
							|  |  |  | 	    c == 0 || c == B43_TSSI_MAX || | 
					
						
							|  |  |  | 	    d == 0 || d == B43_TSSI_MAX) | 
					
						
							|  |  |  | 		return -ENOENT; | 
					
						
							|  |  |  | 	/* The values are OK. Clear them. */ | 
					
						
							|  |  |  | 	tmp = B43_TSSI_MAX | (B43_TSSI_MAX << 8) | | 
					
						
							|  |  |  | 	      (B43_TSSI_MAX << 16) | (B43_TSSI_MAX << 24); | 
					
						
							|  |  |  | 	b43_shm_write32(dev, B43_SHM_SHARED, shm_offset, tmp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (is_ofdm) { | 
					
						
							|  |  |  | 		a = (a + 32) & 0x3F; | 
					
						
							|  |  |  | 		b = (b + 32) & 0x3F; | 
					
						
							|  |  |  | 		c = (c + 32) & 0x3F; | 
					
						
							|  |  |  | 		d = (d + 32) & 0x3F; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get the average of the values with 0.5 added to each value. */ | 
					
						
							|  |  |  | 	average = (a + b + c + d + 2) / 4; | 
					
						
							|  |  |  | 	if (is_ofdm) { | 
					
						
							|  |  |  | 		/* Adjust for CCK-boost */ | 
					
						
							| 
									
										
										
										
											2012-07-25 16:58:38 +02:00
										 |  |  | 		if (b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF1) | 
					
						
							| 
									
										
										
										
											2008-08-28 19:33:40 +02:00
										 |  |  | 		    & B43_HF_CCKBOOST) | 
					
						
							|  |  |  | 			average = (average >= 13) ? (average - 13) : 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return average; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-09-03 12:12:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-25 18:59:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 21:55:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool b43_channel_type_is_40mhz(enum nl80211_channel_type channel_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (channel_type == NL80211_CHAN_HT40MINUS || | 
					
						
							|  |  |  | 		channel_type == NL80211_CHAN_HT40PLUS); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-12 00:03:26 +02:00
										 |  |  | /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BmacPhyClkFgc */ | 
					
						
							|  |  |  | void b43_phy_force_clock(struct b43_wldev *dev, bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WARN_ON(dev->phy.type != B43_PHYTYPE_N && | 
					
						
							|  |  |  | 		dev->phy.type != B43_PHYTYPE_HT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (dev->dev->bus_type) { | 
					
						
							|  |  |  | #ifdef CONFIG_B43_BCMA
 | 
					
						
							|  |  |  | 	case B43_BUS_BCMA: | 
					
						
							|  |  |  | 		tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL); | 
					
						
							|  |  |  | 		if (force) | 
					
						
							|  |  |  | 			tmp |= BCMA_IOCTL_FGC; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			tmp &= ~BCMA_IOCTL_FGC; | 
					
						
							|  |  |  | 		bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef CONFIG_B43_SSB
 | 
					
						
							|  |  |  | 	case B43_BUS_SSB: | 
					
						
							|  |  |  | 		tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW); | 
					
						
							|  |  |  | 		if (force) | 
					
						
							|  |  |  | 			tmp |= SSB_TMSLOW_FGC; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			tmp &= ~SSB_TMSLOW_FGC; | 
					
						
							|  |  |  | 		ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-25 19:00:00 +01:00
										 |  |  | /* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */ | 
					
						
							| 
									
										
										
										
											2010-01-25 18:59:59 +01:00
										 |  |  | struct b43_c32 b43_cordic(int theta) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-20 18:38:56 -08:00
										 |  |  | 	static const u32 arctg[] = { | 
					
						
							|  |  |  | 		2949120, 1740967, 919879, 466945, 234379, 117304, | 
					
						
							|  |  |  | 		  58666,   29335,  14668,   7334,   3667,   1833, | 
					
						
							|  |  |  | 		    917,     458,    229,    115,     57,     29, | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2010-01-25 19:00:00 +01:00
										 |  |  | 	u8 i; | 
					
						
							|  |  |  | 	s32 tmp; | 
					
						
							|  |  |  | 	s8 signx = 1; | 
					
						
							|  |  |  | 	u32 angle = 0; | 
					
						
							| 
									
										
										
										
											2010-01-25 18:59:59 +01:00
										 |  |  | 	struct b43_c32 ret = { .i = 39797, .q = 0, }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-25 19:00:00 +01:00
										 |  |  | 	while (theta > (180 << 16)) | 
					
						
							|  |  |  | 		theta -= (360 << 16); | 
					
						
							|  |  |  | 	while (theta < -(180 << 16)) | 
					
						
							|  |  |  | 		theta += (360 << 16); | 
					
						
							| 
									
										
										
										
											2010-01-25 18:59:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-25 19:00:00 +01:00
										 |  |  | 	if (theta > (90 << 16)) { | 
					
						
							|  |  |  | 		theta -= (180 << 16); | 
					
						
							| 
									
										
										
										
											2010-01-25 18:59:59 +01:00
										 |  |  | 		signx = -1; | 
					
						
							| 
									
										
										
										
											2010-01-25 19:00:00 +01:00
										 |  |  | 	} else if (theta < -(90 << 16)) { | 
					
						
							|  |  |  | 		theta += (180 << 16); | 
					
						
							| 
									
										
										
										
											2010-01-25 18:59:59 +01:00
										 |  |  | 		signx = -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i <= 17; i++) { | 
					
						
							|  |  |  | 		if (theta > angle) { | 
					
						
							|  |  |  | 			tmp = ret.i - (ret.q >> i); | 
					
						
							|  |  |  | 			ret.q += ret.i >> i; | 
					
						
							|  |  |  | 			ret.i = tmp; | 
					
						
							|  |  |  | 			angle += arctg[i]; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			tmp = ret.i + (ret.q >> i); | 
					
						
							|  |  |  | 			ret.q -= ret.i >> i; | 
					
						
							|  |  |  | 			ret.i = tmp; | 
					
						
							|  |  |  | 			angle -= arctg[i]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret.i *= signx; | 
					
						
							|  |  |  | 	ret.q *= signx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } |