1 /* SPDX-License-Identifier: ISC */
2 
3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/platform_device.h>
6 
7 #include "mt7603.h"
8 
9 static int
10 mt76_wmac_probe(struct platform_device *pdev)
11 {
12 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
13 	struct mt7603_dev *dev;
14 	void __iomem *mem_base;
15 	struct mt76_dev *mdev;
16 	int irq;
17 	int ret;
18 
19 	irq = platform_get_irq(pdev, 0);
20 	if (irq < 0) {
21 		dev_err(&pdev->dev, "Failed to get device IRQ\n");
22 		return irq;
23 	}
24 
25 	mem_base = devm_ioremap_resource(&pdev->dev, res);
26 	if (IS_ERR(mem_base)) {
27 		dev_err(&pdev->dev, "Failed to get memory resource\n");
28 		return PTR_ERR(mem_base);
29 	}
30 
31 	mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt7603_ops,
32 				 &mt7603_drv_ops);
33 	if (!mdev)
34 		return -ENOMEM;
35 
36 	dev = container_of(mdev, struct mt7603_dev, mt76);
37 	mt76_mmio_init(mdev, mem_base);
38 
39 	mdev->rev = (mt76_rr(dev, MT_HW_CHIPID) << 16) |
40 		    (mt76_rr(dev, MT_HW_REV) & 0xff);
41 	dev_info(mdev->dev, "ASIC revision: %04x\n", mdev->rev);
42 
43 	ret = devm_request_irq(mdev->dev, irq, mt7603_irq_handler,
44 			       IRQF_SHARED, KBUILD_MODNAME, dev);
45 	if (ret)
46 		goto error;
47 
48 	ret = mt7603_register_device(dev);
49 	if (ret)
50 		goto error;
51 
52 	return 0;
53 error:
54 	ieee80211_free_hw(mt76_hw(dev));
55 	return ret;
56 }
57 
58 static int
59 mt76_wmac_remove(struct platform_device *pdev)
60 {
61 	struct mt76_dev *mdev = platform_get_drvdata(pdev);
62 	struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
63 
64 	mt7603_unregister_device(dev);
65 
66 	return 0;
67 }
68 
69 static const struct of_device_id of_wmac_match[] = {
70 	{ .compatible = "mediatek,mt7628-wmac" },
71 	{},
72 };
73 
74 MODULE_DEVICE_TABLE(of, of_wmac_match);
75 MODULE_FIRMWARE(MT7628_FIRMWARE_E1);
76 MODULE_FIRMWARE(MT7628_FIRMWARE_E2);
77 
78 struct platform_driver mt76_wmac_driver = {
79 	.probe		= mt76_wmac_probe,
80 	.remove		= mt76_wmac_remove,
81 	.driver = {
82 		.name = "mt76_wmac",
83 		.of_match_table = of_wmac_match,
84 	},
85 };
86