mailbox: qcom: Convert APCS IPC driver to use regmap
[linux-2.6-block.git] / drivers / mailbox / qcom-apcs-ipc-mailbox.c
CommitLineData
25bfee16
BA
1/*
2 * Copyright (c) 2017, Linaro Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/io.h>
17#include <linux/slab.h>
18#include <linux/of.h>
19#include <linux/of_platform.h>
20#include <linux/platform_device.h>
c6a8b171 21#include <linux/regmap.h>
25bfee16
BA
22#include <linux/mailbox_controller.h>
23
24#define QCOM_APCS_IPC_BITS 32
25
26struct qcom_apcs_ipc {
27 struct mbox_controller mbox;
28 struct mbox_chan mbox_chans[QCOM_APCS_IPC_BITS];
29
c6a8b171 30 struct regmap *regmap;
25bfee16
BA
31 unsigned long offset;
32};
33
c6a8b171
GD
34static const struct regmap_config apcs_regmap_config = {
35 .reg_bits = 32,
36 .reg_stride = 4,
37 .val_bits = 32,
38 .max_register = 0x1000,
39 .fast_io = true,
40};
41
25bfee16
BA
42static int qcom_apcs_ipc_send_data(struct mbox_chan *chan, void *data)
43{
44 struct qcom_apcs_ipc *apcs = container_of(chan->mbox,
45 struct qcom_apcs_ipc, mbox);
46 unsigned long idx = (unsigned long)chan->con_priv;
47
c6a8b171 48 return regmap_write(apcs->regmap, apcs->offset, BIT(idx));
25bfee16
BA
49}
50
51static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
52 .send_data = qcom_apcs_ipc_send_data,
53};
54
55static int qcom_apcs_ipc_probe(struct platform_device *pdev)
56{
c6a8b171 57 struct device_node *np = pdev->dev.of_node;
25bfee16 58 struct qcom_apcs_ipc *apcs;
c6a8b171 59 struct regmap *regmap;
25bfee16
BA
60 struct resource *res;
61 unsigned long offset;
62 void __iomem *base;
63 unsigned long i;
64 int ret;
65
66 apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
67 if (!apcs)
68 return -ENOMEM;
69
70 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
71 base = devm_ioremap_resource(&pdev->dev, res);
72 if (IS_ERR(base))
73 return PTR_ERR(base);
74
c6a8b171
GD
75 regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config);
76 if (IS_ERR(regmap))
77 return PTR_ERR(regmap);
78
25bfee16
BA
79 offset = (unsigned long)of_device_get_match_data(&pdev->dev);
80
c6a8b171
GD
81 apcs->regmap = regmap;
82 apcs->offset = offset;
25bfee16
BA
83
84 /* Initialize channel identifiers */
85 for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++)
86 apcs->mbox_chans[i].con_priv = (void *)i;
87
88 apcs->mbox.dev = &pdev->dev;
89 apcs->mbox.ops = &qcom_apcs_ipc_ops;
90 apcs->mbox.chans = apcs->mbox_chans;
91 apcs->mbox.num_chans = ARRAY_SIZE(apcs->mbox_chans);
92
93 ret = mbox_controller_register(&apcs->mbox);
94 if (ret) {
95 dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
96 return ret;
97 }
98
99 platform_set_drvdata(pdev, apcs);
100
101 return 0;
102}
103
104static int qcom_apcs_ipc_remove(struct platform_device *pdev)
105{
106 struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev);
107
108 mbox_controller_unregister(&apcs->mbox);
109
110 return 0;
111}
112
113/* .data is the offset of the ipc register within the global block */
114static const struct of_device_id qcom_apcs_ipc_of_match[] = {
115 { .compatible = "qcom,msm8916-apcs-kpss-global", .data = (void *)8 },
116 { .compatible = "qcom,msm8996-apcs-hmss-global", .data = (void *)16 },
117 {}
118};
119MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match);
120
121static struct platform_driver qcom_apcs_ipc_driver = {
122 .probe = qcom_apcs_ipc_probe,
123 .remove = qcom_apcs_ipc_remove,
124 .driver = {
125 .name = "qcom_apcs_ipc",
126 .of_match_table = qcom_apcs_ipc_of_match,
127 },
128};
129
130static int __init qcom_apcs_ipc_init(void)
131{
132 return platform_driver_register(&qcom_apcs_ipc_driver);
133}
134postcore_initcall(qcom_apcs_ipc_init);
135
136static void __exit qcom_apcs_ipc_exit(void)
137{
138 platform_driver_unregister(&qcom_apcs_ipc_driver);
139}
140module_exit(qcom_apcs_ipc_exit);
141
142MODULE_LICENSE("GPL v2");
143MODULE_DESCRIPTION("Qualcomm APCS IPC driver");