diff mbox series

[19/26] mt76x0: pci: add hw initialization at bootstrap

Message ID 74b90927973b06ffe237f7d568ffb3fa12791058.1538036134.git.lorenzo.bianconi@redhat.com (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show
Series add mt76x0e hw initialization support | expand

Commit Message

Lorenzo Bianconi Sept. 27, 2018, 9:01 a.m. UTC
Add mt76x0e_register_device routine in pci_init.c
to initialize the device during hw probe.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 .../wireless/mediatek/mt76/mt76x0/Makefile    |  2 +-
 .../net/wireless/mediatek/mt76/mt76x0/init.c  | 10 +--
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h    |  2 +
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  2 +-
 .../wireless/mediatek/mt76/mt76x0/pci_init.c  | 65 +++++++++++++++++++
 .../wireless/mediatek/mt76/mt76x02_eeprom.h   |  1 +
 6 files changed, 73 insertions(+), 9 deletions(-)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/pci_init.c

Comments

Stanislaw Gruszka Sept. 27, 2018, 10:24 a.m. UTC | #1
On Thu, Sep 27, 2018 at 11:01:48AM +0200, Lorenzo Bianconi wrote:
> Add mt76x0e_register_device routine in pci_init.c
> to initialize the device during hw probe.
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
>  .../wireless/mediatek/mt76/mt76x0/Makefile    |  2 +-
>  .../net/wireless/mediatek/mt76/mt76x0/init.c  | 10 +--
>  .../wireless/mediatek/mt76/mt76x0/mt76x0.h    |  2 +
>  .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  2 +-
>  .../wireless/mediatek/mt76/mt76x0/pci_init.c  | 65 +++++++++++++++++++
>  .../wireless/mediatek/mt76/mt76x02_eeprom.h   |  1 +
>  6 files changed, 73 insertions(+), 9 deletions(-)
>  create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/pci_init.c
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
> index 30c84a557076..daa4929bdee6 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
> @@ -6,7 +6,7 @@ mt76x0-common-y := \
>  	init.o main.o trace.o eeprom.o phy.o \
>  	mac.o debugfs.o tx.o
>  mt76x0u-y := usb.o usb_mcu.o usb_init.o
> -mt76x0e-y := pci.o pci_mcu.o
> +mt76x0e-y := pci.o pci_mcu.o pci_init.o

How much {pci,usb}_{init,mcu}.c files are expected to grow?
For now they are about between 100 and 200 lines of code
and I do not see reason to move code into separate files
so far. It could be easy placed in usb.c and pci.c files.
But if the files will grow, I'm ok with code moving.

Thanks
Stanislaw
Lorenzo Bianconi Sept. 27, 2018, 3:18 p.m. UTC | #2
> On Thu, Sep 27, 2018 at 11:01:48AM +0200, Lorenzo Bianconi wrote:
> > Add mt76x0e_register_device routine in pci_init.c
> > to initialize the device during hw probe.
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> > ---
> >  .../wireless/mediatek/mt76/mt76x0/Makefile    |  2 +-
> >  .../net/wireless/mediatek/mt76/mt76x0/init.c  | 10 +--
> >  .../wireless/mediatek/mt76/mt76x0/mt76x0.h    |  2 +
> >  .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  2 +-
> >  .../wireless/mediatek/mt76/mt76x0/pci_init.c  | 65 +++++++++++++++++++
> >  .../wireless/mediatek/mt76/mt76x02_eeprom.h   |  1 +
> >  6 files changed, 73 insertions(+), 9 deletions(-)
> >  create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/pci_init.c
> > 
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
> > index 30c84a557076..daa4929bdee6 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
> > +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
> > @@ -6,7 +6,7 @@ mt76x0-common-y := \
> >  	init.o main.o trace.o eeprom.o phy.o \
> >  	mac.o debugfs.o tx.o
> >  mt76x0u-y := usb.o usb_mcu.o usb_init.o
> > -mt76x0e-y := pci.o pci_mcu.o
> > +mt76x0e-y := pci.o pci_mcu.o pci_init.o
> 
> How much {pci,usb}_{init,mcu}.c files are expected to grow?
> For now they are about between 100 and 200 lines of code
> and I do not see reason to move code into separate files
> so far. It could be easy placed in usb.c and pci.c files.
> But if the files will grow, I'm ok with code moving.

At the moment I do not know how much {pci,usb}_{init,mcu}.c will
grow, I guess a little bit more. Anyway I would prefer to have
in {pci/usb}.c just bus specific code (but it is a matter of taste
actually)

Regards,
Lorenzo

> 
> Thanks
> Stanislaw
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
index 30c84a557076..daa4929bdee6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
@@ -6,7 +6,7 @@  mt76x0-common-y := \
 	init.o main.o trace.o eeprom.o phy.o \
 	mac.o debugfs.o tx.o
 mt76x0u-y := usb.o usb_mcu.o usb_init.o
-mt76x0e-y := pci.o pci_mcu.o
+mt76x0e-y := pci.o pci_mcu.o pci_init.o
 
 # ccflags-y := -DDEBUG
 CFLAGS_trace.o := -I$(src)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index 3426ec385380..ffd5c864aef1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -107,6 +107,9 @@  static void mt76x0_reset_csr_bbp(struct mt76x0_dev *dev)
 		MT_MAC_SYS_CTRL_RESET_CSR |
 		MT_MAC_SYS_CTRL_RESET_BBP);
 	msleep(200);
+	mt76_clear(dev, MT_MAC_SYS_CTRL,
+		   MT_MAC_SYS_CTRL_RESET_CSR |
+		   MT_MAC_SYS_CTRL_RESET_BBP);
 }
 
 #define RANDOM_WRITE(dev, tab)			\
@@ -152,13 +155,6 @@  static void mt76x0_init_mac_registers(struct mt76x0_dev *dev)
 	reg &= ~0x3;
 	mt76_wr(dev, MT_MAC_SYS_CTRL, reg);
 
-	if (is_mt7610e(dev)) {
-		/* Disable COEX_EN */
-		reg = mt76_rr(dev, MT_COEXCFG0);
-		reg &= 0xFFFFFFFE;
-		mt76_wr(dev, MT_COEXCFG0, reg);
-	}
-
 	/* Set 0x141C[15:12]=0xF */
 	reg = mt76_rr(dev, MT_EXT_CCA_CFG);
 	reg |= 0x0000F000;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index 70bb2f3af90b..507fa5a9da88 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -138,6 +138,8 @@  void mt76x0_mac_stop(struct mt76x0_dev *dev);
 void mt76x0u_cleanup(struct mt76x0_dev *dev);
 int mt76x0u_register_device(struct mt76x0_dev *dev);
 
+int mt76x0e_register_device(struct mt76x0_dev *dev);
+
 /* PHY */
 void mt76x0_phy_init(struct mt76x0_dev *dev);
 int mt76x0_wait_bbp_ready(struct mt76x0_dev *dev);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index 99d142319d1c..8cb33f44ac6c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
@@ -50,7 +50,7 @@  mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION);
 	dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev);
 
-	ret = mt76x0e_mcu_init(dev);
+	ret = mt76x0e_register_device(dev);
 	if (ret < 0)
 		goto error;
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt76x0/pci_init.c
new file mode 100644
index 000000000000..a3aab7d75f2b
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci_init.c
@@ -0,0 +1,65 @@ 
+/*
+ * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
+ *
+ * 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.
+ */
+#include <linux/kernel.h>
+#include <linux/firmware.h>
+
+#include "mt76x0.h"
+#include "mcu.h"
+#include "../mt76x02_dma.h"
+
+int mt76x0e_register_device(struct mt76x0_dev *dev)
+{
+	int err;
+
+	mt76x0_chip_onoff(dev, true, false);
+	if (!mt76x02_wait_for_mac(&dev->mt76))
+		return -ETIMEDOUT;
+
+	mt76x02_dma_disable(&dev->mt76);
+	err = mt76x0e_mcu_init(dev);
+	if (err < 0)
+		return err;
+
+	err = mt76x02_dma_init(&dev->mt76);
+	if (err < 0)
+		return err;
+
+	err = mt76x0_init_hardware(dev);
+	if (err < 0)
+		return err;
+
+	if (mt76_chip(&dev->mt76) == 0x7610) {
+		u16 val;
+
+		mt76_clear(dev, MT_COEXCFG0, BIT(0));
+		val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0);
+		if (val & MT_EE_NIC_CONF_0_PA_IO_CURRENT) {
+			u32 data;
+
+			/* set external external PA I/O
+			 * current to 16mA
+			 */
+			data = mt76_rr(dev, 0x11c);
+			val |= 0xc03;
+			mt76_wr(dev, 0x11c, val);
+		}
+	}
+
+	mt76_clear(dev, 0x110, BIT(9));
+	mt76_set(dev, MT_MAX_LEN_CFG, BIT(13));
+
+	return 0;
+}
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h
index b45e2afeadd0..bcd05f7c5f45 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h
@@ -107,6 +107,7 @@  enum mt76x02_eeprom_field {
 #define MT_EE_NIC_CONF_0_PA_TYPE		GENMASK(9, 8)
 #define MT_EE_NIC_CONF_0_PA_INT_2G		BIT(8)
 #define MT_EE_NIC_CONF_0_PA_INT_5G		BIT(9)
+#define MT_EE_NIC_CONF_0_PA_IO_CURRENT		BIT(10)
 #define MT_EE_NIC_CONF_0_BOARD_TYPE		GENMASK(13, 12)
 
 #define MT_EE_NIC_CONF_1_HW_RF_CTRL		BIT(0)