1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2019 MediaTek Inc.
3  *
4  * Author: Ryder Lee <ryder.lee@mediatek.com>
5  *         Felix Fietkau <nbd@nbd.name>
6  */
7 
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/regmap.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/of.h>
14 #include "mt7615.h"
15 
16 int mt7622_wmac_init(struct mt7615_dev *dev)
17 {
18 	struct device_node *np = dev->mt76.dev->of_node;
19 
20 	if (!is_mt7622(&dev->mt76))
21 		return 0;
22 
23 	dev->infracfg = syscon_regmap_lookup_by_phandle(np, "mediatek,infracfg");
24 	if (IS_ERR(dev->infracfg)) {
25 		dev_err(dev->mt76.dev, "Cannot find infracfg controller\n");
26 		return PTR_ERR(dev->infracfg);
27 	}
28 
29 	return 0;
30 }
31 
32 static int mt7622_wmac_probe(struct platform_device *pdev)
33 {
34 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
35 	void __iomem *mem_base;
36 	int irq;
37 
38 	irq = platform_get_irq(pdev, 0);
39 	if (irq < 0) {
40 		dev_err(&pdev->dev, "Failed to get device IRQ\n");
41 		return irq;
42 	}
43 
44 	mem_base = devm_ioremap_resource(&pdev->dev, res);
45 	if (IS_ERR(mem_base)) {
46 		dev_err(&pdev->dev, "Failed to get memory resource\n");
47 		return PTR_ERR(mem_base);
48 	}
49 
50 	return mt7615_mmio_probe(&pdev->dev, mem_base, irq, mt7615e_reg_map);
51 }
52 
53 static int mt7622_wmac_remove(struct platform_device *pdev)
54 {
55 	struct mt7615_dev *dev = platform_get_drvdata(pdev);
56 
57 	mt7615_unregister_device(dev);
58 
59 	return 0;
60 }
61 
62 static const struct of_device_id mt7622_wmac_of_match[] = {
63 	{ .compatible = "mediatek,mt7622-wmac" },
64 	{},
65 };
66 
67 struct platform_driver mt7622_wmac_driver = {
68 	.driver = {
69 		.name = "mt7622-wmac",
70 		.of_match_table = mt7622_wmac_of_match,
71 	},
72 	.probe = mt7622_wmac_probe,
73 	.remove = mt7622_wmac_remove,
74 };
75 
76 MODULE_FIRMWARE(MT7622_FIRMWARE_N9);
77 MODULE_FIRMWARE(MT7622_ROM_PATCH);
78