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 mt7603_dev *dev;
13 	void __iomem *mem_base;
14 	struct mt76_dev *mdev;
15 	int irq;
16 	int ret;
17 
18 	irq = platform_get_irq(pdev, 0);
19 	if (irq < 0)
20 		return irq;
21 
22 	mem_base = devm_platform_ioremap_resource(pdev, 0);
23 	if (IS_ERR(mem_base))
24 		return PTR_ERR(mem_base);
25 
26 	mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt7603_ops,
27 				 &mt7603_drv_ops);
28 	if (!mdev)
29 		return -ENOMEM;
30 
31 	dev = container_of(mdev, struct mt7603_dev, mt76);
32 	mt76_mmio_init(mdev, mem_base);
33 
34 	mdev->rev = (mt76_rr(dev, MT_HW_CHIPID) << 16) |
35 		    (mt76_rr(dev, MT_HW_REV) & 0xff);
36 	dev_info(mdev->dev, "ASIC revision: %04x\n", mdev->rev);
37 
38 	ret = devm_request_irq(mdev->dev, irq, mt7603_irq_handler,
39 			       IRQF_SHARED, KBUILD_MODNAME, dev);
40 	if (ret)
41 		goto error;
42 
43 	ret = mt7603_register_device(dev);
44 	if (ret)
45 		goto error;
46 
47 	return 0;
48 error:
49 	ieee80211_free_hw(mt76_hw(dev));
50 	return ret;
51 }
52 
53 static int
54 mt76_wmac_remove(struct platform_device *pdev)
55 {
56 	struct mt76_dev *mdev = platform_get_drvdata(pdev);
57 	struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
58 
59 	mt7603_unregister_device(dev);
60 
61 	return 0;
62 }
63 
64 static const struct of_device_id of_wmac_match[] = {
65 	{ .compatible = "mediatek,mt7628-wmac" },
66 	{},
67 };
68 
69 MODULE_DEVICE_TABLE(of, of_wmac_match);
70 MODULE_FIRMWARE(MT7628_FIRMWARE_E1);
71 MODULE_FIRMWARE(MT7628_FIRMWARE_E2);
72 
73 struct platform_driver mt76_wmac_driver = {
74 	.probe		= mt76_wmac_probe,
75 	.remove		= mt76_wmac_remove,
76 	.driver = {
77 		.name = "mt76_wmac",
78 		.of_match_table = of_wmac_match,
79 	},
80 };
81