Commit d200d6ae authored by Felix Fietkau's avatar Felix Fietkau

mt76: mt7915: move pci specific code back to pci.c

This avoids the need to check for the device type in mmio.c and makes the code
cleaner
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent b71d3911
...@@ -505,7 +505,7 @@ static void mt7915_irq_tasklet(struct tasklet_struct *t) ...@@ -505,7 +505,7 @@ static void mt7915_irq_tasklet(struct tasklet_struct *t)
} }
} }
static irqreturn_t mt7915_irq_handler(int irq, void *dev_instance) irqreturn_t mt7915_irq_handler(int irq, void *dev_instance)
{ {
struct mt7915_dev *dev = dev_instance; struct mt7915_dev *dev = dev_instance;
...@@ -521,10 +521,8 @@ static irqreturn_t mt7915_irq_handler(int irq, void *dev_instance) ...@@ -521,10 +521,8 @@ static irqreturn_t mt7915_irq_handler(int irq, void *dev_instance)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
int mt7915_mmio_probe(struct device *pdev, struct mt7915_dev *mt7915_mmio_probe(struct device *pdev,
void __iomem *mem_base, void __iomem *mem_base, u32 device_id)
u32 device_id,
int irq, struct mt7915_hif *hif2)
{ {
static const struct mt76_driver_ops drv_ops = { static const struct mt76_driver_ops drv_ops = {
/* txwi_size = txd size + txp size */ /* txwi_size = txd size + txp size */
...@@ -551,11 +549,11 @@ int mt7915_mmio_probe(struct device *pdev, ...@@ -551,11 +549,11 @@ int mt7915_mmio_probe(struct device *pdev,
ops = devm_kmemdup(pdev, &mt7915_ops, sizeof(mt7915_ops), GFP_KERNEL); ops = devm_kmemdup(pdev, &mt7915_ops, sizeof(mt7915_ops), GFP_KERNEL);
if (!ops) if (!ops)
return -ENOMEM; return ERR_PTR(-ENOMEM);
mdev = mt76_alloc_device(pdev, sizeof(*dev), ops, &drv_ops); mdev = mt76_alloc_device(pdev, sizeof(*dev), ops, &drv_ops);
if (!mdev) if (!mdev)
return -ENOMEM; return ERR_PTR(-ENOMEM);
dev = container_of(mdev, struct mt7915_dev, mt76); dev = container_of(mdev, struct mt7915_dev, mt76);
...@@ -566,49 +564,13 @@ int mt7915_mmio_probe(struct device *pdev, ...@@ -566,49 +564,13 @@ int mt7915_mmio_probe(struct device *pdev,
tasklet_setup(&dev->irq_tasklet, mt7915_irq_tasklet); tasklet_setup(&dev->irq_tasklet, mt7915_irq_tasklet);
mt76_wr(dev, MT_INT_MASK_CSR, 0); mt76_wr(dev, MT_INT_MASK_CSR, 0);
/* master switch of PCIe tnterrupt enable */
if (dev_is_pci(pdev))
mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0xff);
ret = devm_request_irq(mdev->dev, irq, mt7915_irq_handler,
IRQF_SHARED, KBUILD_MODNAME, dev);
if (ret)
goto error;
if (hif2 && dev_is_pci(pdev)) {
dev->hif2 = hif2;
mt76_wr(dev, MT_INT1_MASK_CSR, 0);
/* master switch of PCIe tnterrupt enable */
if (is_mt7915(mdev))
mt76_wr(dev, MT_PCIE1_MAC_INT_ENABLE, 0xff);
else
mt76_wr(dev, MT_PCIE1_MAC_INT_ENABLE_MT7916, 0xff);
ret = devm_request_irq(mdev->dev, dev->hif2->irq,
mt7915_irq_handler, IRQF_SHARED,
KBUILD_MODNAME "-hif", dev);
if (ret) {
put_device(dev->hif2->dev);
goto free_irq;
}
}
ret = mt7915_register_device(dev);
if (ret)
goto free_hif2_irq;
return 0; return dev;
free_hif2_irq:
if (dev->hif2)
devm_free_irq(mdev->dev, dev->hif2->irq, dev);
free_irq:
devm_free_irq(mdev->dev, irq, dev);
error: error:
mt76_free_device(&dev->mt76); mt76_free_device(&dev->mt76);
return ret; return ERR_PTR(ret);
} }
static int __init mt7915_init(void) static int __init mt7915_init(void)
......
...@@ -380,10 +380,9 @@ extern const struct mt76_testmode_ops mt7915_testmode_ops; ...@@ -380,10 +380,9 @@ extern const struct mt76_testmode_ops mt7915_testmode_ops;
extern struct pci_driver mt7915_pci_driver; extern struct pci_driver mt7915_pci_driver;
extern struct pci_driver mt7915_hif_driver; extern struct pci_driver mt7915_hif_driver;
int mt7915_mmio_probe(struct device *pdev, struct mt7915_dev *mt7915_mmio_probe(struct device *pdev,
void __iomem *mem_base, void __iomem *mem_base, u32 device_id);
u32 device_id, irqreturn_t mt7915_irq_handler(int irq, void *dev_instance);
int irq, struct mt7915_hif *hif2);
u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif); u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif);
int mt7915_register_device(struct mt7915_dev *dev); int mt7915_register_device(struct mt7915_dev *dev);
void mt7915_unregister_device(struct mt7915_dev *dev); void mt7915_unregister_device(struct mt7915_dev *dev);
......
...@@ -95,7 +95,10 @@ static int mt7915_pci_hif2_probe(struct pci_dev *pdev) ...@@ -95,7 +95,10 @@ static int mt7915_pci_hif2_probe(struct pci_dev *pdev)
static int mt7915_pci_probe(struct pci_dev *pdev, static int mt7915_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
struct mt7915_dev *dev;
struct mt76_dev *mdev;
struct mt7915_hif *hif2; struct mt7915_hif *hif2;
int irq;
int ret; int ret;
ret = pcim_enable_device(pdev); ret = pcim_enable_device(pdev);
...@@ -117,18 +120,63 @@ static int mt7915_pci_probe(struct pci_dev *pdev, ...@@ -117,18 +120,63 @@ static int mt7915_pci_probe(struct pci_dev *pdev,
if (id->device == 0x7916 || id->device == 0x790a) if (id->device == 0x7916 || id->device == 0x790a)
return mt7915_pci_hif2_probe(pdev); return mt7915_pci_hif2_probe(pdev);
dev = mt7915_mmio_probe(&pdev->dev, pcim_iomap_table(pdev)[0],
id->device);
if (IS_ERR(dev))
return PTR_ERR(dev);
mdev = &dev->mt76;
hif2 = mt7915_pci_init_hif2(pdev);
ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
if (ret < 0) if (ret < 0)
return ret; goto free_device;
hif2 = mt7915_pci_init_hif2(pdev); irq = pdev->irq;
ret = devm_request_irq(mdev->dev, irq, mt7915_irq_handler,
IRQF_SHARED, KBUILD_MODNAME, dev);
if (ret)
goto free_irq_vector;
mt76_wr(dev, MT_INT_MASK_CSR, 0);
/* master switch of PCIe tnterrupt enable */
mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0xff);
if (hif2) {
dev->hif2 = hif2;
mt76_wr(dev, MT_INT1_MASK_CSR, 0);
/* master switch of PCIe tnterrupt enable */
if (is_mt7915(mdev))
mt76_wr(dev, MT_PCIE1_MAC_INT_ENABLE, 0xff);
else
mt76_wr(dev, MT_PCIE1_MAC_INT_ENABLE_MT7916, 0xff);
ret = devm_request_irq(mdev->dev, dev->hif2->irq,
mt7915_irq_handler, IRQF_SHARED,
KBUILD_MODNAME "-hif", dev);
if (ret)
goto free_hif2;
}
ret = mt7915_register_device(dev);
if (ret)
goto free_hif2_irq;
ret = mt7915_mmio_probe(&pdev->dev, pcim_iomap_table(pdev)[0],
id->device, pdev->irq, hif2);
if (!ret)
return 0; return 0;
free_hif2_irq:
if (dev->hif2)
devm_free_irq(mdev->dev, dev->hif2->irq, dev);
free_hif2:
if (dev->hif2)
put_device(dev->hif2->dev);
devm_free_irq(mdev->dev, irq, dev);
free_irq_vector:
pci_free_irq_vectors(pdev); pci_free_irq_vectors(pdev);
free_device:
mt76_free_device(&dev->mt76);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment