From owner-svn-src-all@freebsd.org Sat May 14 20:11:49 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 80681B3BC85; Sat, 14 May 2016 20:11:49 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5C135152B; Sat, 14 May 2016 20:11:49 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4EKBmSK024604; Sat, 14 May 2016 20:11:48 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4EKBm2O024602; Sat, 14 May 2016 20:11:48 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201605142011.u4EKBm2O024602@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Sat, 14 May 2016 20:11:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299758 - head/sys/dev/bwn X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 May 2016 20:11:49 -0000 Author: adrian Date: Sat May 14 20:11:48 2016 New Revision: 299758 URL: https://svnweb.freebsd.org/changeset/base/299758 Log: [bwn] begin migrating PHY common routines into if_bwn_phy_common.[ch]. This isn't compiled in yet; so some code here duplicates what is in the existing code. I'll migrate it all out in subsequent commits. Obtained from: b43 (definitions), bcm-v4 specifications website Added: head/sys/dev/bwn/if_bwn_phy_common.c (contents, props changed) head/sys/dev/bwn/if_bwn_phy_common.h (contents, props changed) Added: head/sys/dev/bwn/if_bwn_phy_common.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/bwn/if_bwn_phy_common.c Sat May 14 20:11:48 2016 (r299758) @@ -0,0 +1,206 @@ +/*- + * Copyright (c) 2009-2010 Weongyo Jeong + * Copyright (c) 2016 Adrian Chadd + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * The Broadcom Wireless LAN controller driver. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +void +bwn_mac_switch_freq(struct bwn_mac *mac, int spurmode) +{ + struct bwn_softc *sc = mac->mac_sc; + uint16_t chip_id = siba_get_chipid(sc->sc_dev); + + if (chip_id == BCMA_CHIP_ID_BCM4331) { + switch (spurmode) { + case 2: /* 168 Mhz: 2^26/168 = 0x61862 */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x1862); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x6); + break; + case 1: /* 164 Mhz: 2^26/164 = 0x63e70 */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x3e70); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x6); + break; + default: /* 160 Mhz: 2^26/160 = 0x66666 */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x6666); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x6); + break; + } + } else if (chip_id == BCMA_CHIP_ID_BCM43131 || + chip_id == BCMA_CHIP_ID_BCM43217 || + chip_id == BCMA_CHIP_ID_BCM43222 || + chip_id == BCMA_CHIP_ID_BCM43224 || + chip_id == BCMA_CHIP_ID_BCM43225 || + chip_id == BCMA_CHIP_ID_BCM43227 || + chip_id == BCMA_CHIP_ID_BCM43228) { + switch (spurmode) { + case 2: /* 126 Mhz */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x2082); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x8); + break; + case 1: /* 123 Mhz */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x5341); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x8); + break; + default: /* 120 Mhz */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x8889); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x8); + break; + } + } else if (mac->mac_phy.type == BWN_PHYTYPE_LCN) { + switch (spurmode) { + case 1: /* 82 Mhz */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x7CE0); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0xC); + break; + default: /* 80 Mhz */ + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0xCCCD); + BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0xC); + break; + } + } +} + +/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BmacPhyClkFgc */ +void +bwn_phy_force_clock(struct bwn_mac *mac, int force) +{ + struct bwn_softc *sc = mac->mac_sc; + uint32_t tmp; + + /* XXX Only for N, HT and AC PHYs */ + + /* XXX bhnd bus */ + if (bwn_is_bus_siba(mac)) { + tmp = siba_read_4(sc->sc_dev, SIBA_TGSLOW); + if (force) + tmp |= SIBA_TGSLOW_FGC; + else + tmp &= ~SIBA_TGSLOW_FGC; + siba_write_4(sc->sc_dev, SIBA_TGSLOW, tmp); + } +} + +int +bwn_radio_wait_value(struct bwn_mac *mac, uint16_t offset, uint16_t mask, + uint16_t value, int delay, int timeout) +{ + uint16_t val; + int i; + + for (i = 0; i < timeout; i += delay) { + val = BWN_RF_READ(mac, offset); + if ((val & mask) == value) + return (1); + DELAY(delay); + } + return (0); +} + +void +bwn_mac_phy_clock_set(struct bwn_mac *mac, int enabled) +{ + struct bwn_softc *sc = mac->mac_sc; + uint32_t val; + + /* XXX bhnd bus */ + if (bwn_is_bus_siba(mac)) { + val = siba_read_4(sc->sc_dev, SIBA_TGSLOW); + if (enabled) + val |= BWN_TMSLOW_MACPHYCLKEN; + else + val &= ~BWN_TMSLOW_MACPHYCLKEN; + siba_write_4(sc->sc_dev, SIBA_TGSLOW, val); + } +} + +/* http://bcm-v4.sipsolutions.net/802.11/PHY/BmacCorePllReset */ +void +bwn_wireless_core_phy_pll_reset(struct bwn_mac *mac) +{ + struct bwn_softc *sc = mac->mac_sc; + + /* XXX bhnd bus */ + if (bwn_is_bus_siba(mac)) { + siba_cc_write32(sc->sc_dev, SIBA_CC_CHIPCTL_ADDR, 0); + siba_cc_mask32(sc->sc_dev, SIBA_CC_CHIPCTL_DATA, ~0x4); + siba_cc_set32(sc->sc_dev, SIBA_CC_CHIPCTL_DATA, 0x4); + siba_cc_mask32(sc->sc_dev, SIBA_CC_CHIPCTL_DATA, ~0x4); + } +} Added: head/sys/dev/bwn/if_bwn_phy_common.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/bwn/if_bwn_phy_common.h Sat May 14 20:11:48 2016 (r299758) @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2016 Adrian Chadd . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ +#ifndef __PHY_COMMON_H__ +#define __PHY_COMMON_H__ + +extern void bwn_mac_switch_freq(struct bwn_mac *mac, int spurmode); +extern void bwn_phy_force_clock(struct bwn_mac *mac, int force); +extern int bwn_radio_wait_value(struct bwn_mac *mac, uint16_t offset, + uint16_t mask, uint16_t value, int delay, int timeout); +extern void bwn_mac_phy_clock_set(struct bwn_mac *mac, int enabled); +extern void bwn_wireless_core_phy_pll_reset(struct bwn_mac *mac); + +#endif /* __PHY_COMMON_H__ */