net: dsa: mv88e6xxx: Add support for port mirroring
[linux-2.6-block.git] / drivers / mailbox / qcom-apcs-ipc-mailbox.c
CommitLineData
97fb5e8d 1// SPDX-License-Identifier: GPL-2.0-only
25bfee16
BA
2/*
3 * Copyright (c) 2017, Linaro Ltd
25bfee16
BA
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/io.h>
9#include <linux/slab.h>
10#include <linux/of.h>
11#include <linux/of_platform.h>
12#include <linux/platform_device.h>
c6a8b171 13#include <linux/regmap.h>
25bfee16
BA
14#include <linux/mailbox_controller.h>
15
16#define QCOM_APCS_IPC_BITS 32
17
18struct qcom_apcs_ipc {
19 struct mbox_controller mbox;
20 struct mbox_chan mbox_chans[QCOM_APCS_IPC_BITS];
21
c6a8b171 22 struct regmap *regmap;
25bfee16 23 unsigned long offset;
c815d769 24 struct platform_device *clk;
25bfee16
BA
25};
26
c6a8b171
GD
27static const struct regmap_config apcs_regmap_config = {
28 .reg_bits = 32,
29 .reg_stride = 4,
30 .val_bits = 32,
556a0964 31 .max_register = 0xFFC,
c6a8b171
GD
32 .fast_io = true,
33};
34
25bfee16
BA
35static int qcom_apcs_ipc_send_data(struct mbox_chan *chan, void *data)
36{
37 struct qcom_apcs_ipc *apcs = container_of(chan->mbox,
38 struct qcom_apcs_ipc, mbox);
39 unsigned long idx = (unsigned long)chan->con_priv;
40
c6a8b171 41 return regmap_write(apcs->regmap, apcs->offset, BIT(idx));
25bfee16
BA
42}
43
44static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
45 .send_data = qcom_apcs_ipc_send_data,
46};
47
48static int qcom_apcs_ipc_probe(struct platform_device *pdev)
49{
50 struct qcom_apcs_ipc *apcs;
c6a8b171 51 struct regmap *regmap;
25bfee16
BA
52 struct resource *res;
53 unsigned long offset;
54 void __iomem *base;
55 unsigned long i;
56 int ret;
78c86458
JRO
57 const struct of_device_id apcs_clk_match_table[] = {
58 { .compatible = "qcom,msm8916-apcs-kpss-global", },
59 { .compatible = "qcom,qcs404-apcs-apps-global", },
60 {}
61 };
25bfee16
BA
62
63 apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
64 if (!apcs)
65 return -ENOMEM;
66
67 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
68 base = devm_ioremap_resource(&pdev->dev, res);
69 if (IS_ERR(base))
70 return PTR_ERR(base);
71
c6a8b171
GD
72 regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config);
73 if (IS_ERR(regmap))
74 return PTR_ERR(regmap);
75
25bfee16
BA
76 offset = (unsigned long)of_device_get_match_data(&pdev->dev);
77
c6a8b171
GD
78 apcs->regmap = regmap;
79 apcs->offset = offset;
25bfee16
BA
80
81 /* Initialize channel identifiers */
82 for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++)
83 apcs->mbox_chans[i].con_priv = (void *)i;
84
85 apcs->mbox.dev = &pdev->dev;
86 apcs->mbox.ops = &qcom_apcs_ipc_ops;
87 apcs->mbox.chans = apcs->mbox_chans;
88 apcs->mbox.num_chans = ARRAY_SIZE(apcs->mbox_chans);
89
83dd44a1 90 ret = devm_mbox_controller_register(&pdev->dev, &apcs->mbox);
25bfee16
BA
91 if (ret) {
92 dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
93 return ret;
94 }
95
78c86458 96 if (of_match_device(apcs_clk_match_table, &pdev->dev)) {
c815d769
GD
97 apcs->clk = platform_device_register_data(&pdev->dev,
98 "qcom-apcs-msm8916-clk",
16d52f33
JRO
99 PLATFORM_DEVID_NONE,
100 NULL, 0);
c815d769
GD
101 if (IS_ERR(apcs->clk))
102 dev_err(&pdev->dev, "failed to register APCS clk\n");
103 }
104
25bfee16
BA
105 platform_set_drvdata(pdev, apcs);
106
107 return 0;
108}
109
110static int qcom_apcs_ipc_remove(struct platform_device *pdev)
111{
112 struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev);
c815d769 113 struct platform_device *clk = apcs->clk;
25bfee16 114
c815d769 115 platform_device_unregister(clk);
25bfee16
BA
116
117 return 0;
118}
119
120/* .data is the offset of the ipc register within the global block */
121static const struct of_device_id qcom_apcs_ipc_of_match[] = {
122 { .compatible = "qcom,msm8916-apcs-kpss-global", .data = (void *)8 },
123 { .compatible = "qcom,msm8996-apcs-hmss-global", .data = (void *)16 },
61a2f6db 124 { .compatible = "qcom,msm8998-apcs-hmss-global", .data = (void *)8 },
0a01fa94 125 { .compatible = "qcom,qcs404-apcs-apps-global", .data = (void *)8 },
08a81d3a 126 { .compatible = "qcom,sc7180-apss-shared", .data = (void *)12 },
05e99a7d 127 { .compatible = "qcom,sdm845-apss-shared", .data = (void *)12 },
08a81d3a 128 { .compatible = "qcom,sm8150-apss-shared", .data = (void *)12 },
88ae25e4 129 { .compatible = "qcom,ipq8074-apcs-apps-global", .data = (void *)8 },
25bfee16
BA
130 {}
131};
132MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match);
133
134static struct platform_driver qcom_apcs_ipc_driver = {
135 .probe = qcom_apcs_ipc_probe,
136 .remove = qcom_apcs_ipc_remove,
137 .driver = {
138 .name = "qcom_apcs_ipc",
139 .of_match_table = qcom_apcs_ipc_of_match,
140 },
141};
142
143static int __init qcom_apcs_ipc_init(void)
144{
145 return platform_driver_register(&qcom_apcs_ipc_driver);
146}
147postcore_initcall(qcom_apcs_ipc_init);
148
149static void __exit qcom_apcs_ipc_exit(void)
150{
151 platform_driver_unregister(&qcom_apcs_ipc_driver);
152}
153module_exit(qcom_apcs_ipc_exit);
154
155MODULE_LICENSE("GPL v2");
156MODULE_DESCRIPTION("Qualcomm APCS IPC driver");