Commit 2735a6dd authored by Stanislaw Gruszka's avatar Stanislaw Gruszka Committed by Kalle Valo
Browse files

mt76: unify wait_for_mac



Create new mt76x02_mac.h for common mac functions of mt76x0 and mt76x2
and unity wait_for_mac for both drivers.

Signed-off-by: default avatarStanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent ac5d5b3f
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -384,9 +384,11 @@ int mt76x0_init_hardware(struct mt76x0_dev *dev)

	mt76x0_chip_onoff(dev, true, true);

	ret = mt76x0_wait_asic_ready(dev);
	if (ret)
	if (!mt76x02_wait_for_mac(&dev->mt76)) {
		ret = -ETIMEDOUT;
		goto err;
	}

	ret = mt76x0_mcu_init(dev);
	if (ret)
		goto err;
@@ -399,9 +401,10 @@ int mt76x0_init_hardware(struct mt76x0_dev *dev)
	}

	/* Wait for ASIC ready after FW load. */
	ret = mt76x0_wait_asic_ready(dev);
	if (ret)
	if (!mt76x02_wait_for_mac(&dev->mt76)) {
		ret = -ETIMEDOUT;
		goto err;
	}

	mt76x0_reset_csr_bbp(dev);
	mt76x0_init_usb_dma(dev);
+1 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <linux/debugfs.h>

#include "../mt76.h"
#include "../mt76x02_mac.h"
#include "regs.h"

#define MT_CALIBRATE_INTERVAL		(4 * HZ)
@@ -263,8 +264,6 @@ static inline bool is_mt7610e(struct mt76x0_dev *dev)

void mt76x0_init_debugfs(struct mt76x0_dev *dev);

int mt76x0_wait_asic_ready(struct mt76x0_dev *dev);

/* Compatibility with mt76 */
#define mt76_rmw_field(_dev, _reg, _field, _val)	\
	mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val))
+3 −2
Original line number Diff line number Diff line
@@ -287,9 +287,10 @@ static int mt76x0_probe(struct usb_interface *usb_intf,
	/* Disable the HW, otherwise MCU fail to initalize on hot reboot */
	mt76x0_chip_onoff(dev, false, false);

	ret = mt76x0_wait_asic_ready(dev);
	if (ret)
	if (!mt76x02_wait_for_mac(&dev->mt76)) {
		ret = -ETIMEDOUT;
		goto err;
	}

	asic_rev = mt76_rr(dev, MT_ASIC_VERSION);
	mac_rev = mt76_rr(dev, MT_MAC_CSR0);
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
 * Copyright (C) 2018 Stanislaw Gruszka <stf_xl@wp.pl>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef __MT76X02_MAC_H
#define __MT76X02_MAC_H

static inline bool mt76x02_wait_for_mac(struct mt76_dev *dev)
{
	const u32 MAC_CSR0 = 0x1000;
	int i;

	for (i = 0; i < 500; i++) {
		if (test_bit(MT76_REMOVED, &dev->state))
			return -EIO;

		switch (dev->bus->rr(dev, MAC_CSR0)) {
		case 0:
		case ~0:
			break;
		default:
			return true;
		}
		usleep_range(5000, 10000);
	}
	return false;
}

#endif
+0 −17
Original line number Diff line number Diff line
@@ -163,23 +163,6 @@ struct mt76x2_sta {
	int inactive_count;
};

static inline bool mt76x2_wait_for_mac(struct mt76x2_dev *dev)
{
	int i;

	for (i = 0; i < 500; i++) {
		switch (mt76_rr(dev, MT_MAC_CSR0)) {
		case 0:
		case ~0:
			break;
		default:
			return true;
		}
		usleep_range(5000, 10000);
	}
	return false;
}

static inline bool is_mt7612(struct mt76x2_dev *dev)
{
	return mt76_chip(&dev->mt76) == 0x7612;
Loading