xref: /freebsd/sys/contrib/dev/mediatek/mt76/mt7603/soc.c (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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 	mt76_wr(dev, MT_INT_MASK_CSR, 0);
39 
40 	ret = devm_request_irq(mdev->dev, irq, mt7603_irq_handler,
41 			       IRQF_SHARED, KBUILD_MODNAME, dev);
42 	if (ret)
43 		goto error;
44 
45 	ret = mt7603_register_device(dev);
46 	if (ret)
47 		goto error;
48 
49 	return 0;
50 error:
51 	ieee80211_free_hw(mt76_hw(dev));
52 	return ret;
53 }
54 
55 static int
56 mt76_wmac_remove(struct platform_device *pdev)
57 {
58 	struct mt76_dev *mdev = platform_get_drvdata(pdev);
59 	struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
60 
61 	mt7603_unregister_device(dev);
62 
63 	return 0;
64 }
65 
66 static const struct of_device_id of_wmac_match[] = {
67 	{ .compatible = "mediatek,mt7628-wmac" },
68 	{},
69 };
70 
71 MODULE_DEVICE_TABLE(of, of_wmac_match);
72 MODULE_FIRMWARE(MT7628_FIRMWARE_E1);
73 MODULE_FIRMWARE(MT7628_FIRMWARE_E2);
74 
75 struct platform_driver mt76_wmac_driver = {
76 	.probe		= mt76_wmac_probe,
77 	.remove		= mt76_wmac_remove,
78 	.driver = {
79 		.name = "mt76_wmac",
80 		.of_match_table = of_wmac_match,
81 	},
82 };
83