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
16int 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
32static 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		return irq;
41
42	mem_base = devm_ioremap_resource(&pdev->dev, res);
43	if (IS_ERR(mem_base)) {
44		dev_err(&pdev->dev, "Failed to get memory resource\n");
45		return PTR_ERR(mem_base);
46	}
47
48	return mt7615_mmio_probe(&pdev->dev, mem_base, irq, mt7615e_reg_map);
49}
50
51static int mt7622_wmac_remove(struct platform_device *pdev)
52{
53	struct mt7615_dev *dev = platform_get_drvdata(pdev);
54
55	mt7615_unregister_device(dev);
56
57	return 0;
58}
59
60static const struct of_device_id mt7622_wmac_of_match[] = {
61	{ .compatible = "mediatek,mt7622-wmac" },
62	{},
63};
64
65struct platform_driver mt7622_wmac_driver = {
66	.driver = {
67		.name = "mt7622-wmac",
68		.of_match_table = mt7622_wmac_of_match,
69	},
70	.probe = mt7622_wmac_probe,
71	.remove = mt7622_wmac_remove,
72};
73
74MODULE_FIRMWARE(MT7622_FIRMWARE_N9);
75MODULE_FIRMWARE(MT7622_ROM_PATCH);
76