blob: cec34f0af6ce30a8fc9645056e7404b9617e3ad9 [file] [log] [blame]
Thomas Gleixner97fb5e82019-05-29 07:17:58 -07001// SPDX-License-Identifier: GPL-2.0-only
Bjorn Andersson25bfee12017-05-27 16:14:04 -07002/*
3 * Copyright (c) 2017, Linaro Ltd
Bjorn Andersson25bfee12017-05-27 16:14:04 -07004 */
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>
Georgi Djakovc6a8b172017-12-05 17:46:56 +020013#include <linux/regmap.h>
Bjorn Andersson25bfee12017-05-27 16:14:04 -070014#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
Georgi Djakovc6a8b172017-12-05 17:46:56 +020022 struct regmap *regmap;
Bjorn Andersson25bfee12017-05-27 16:14:04 -070023 unsigned long offset;
Georgi Djakovc815d762017-12-05 17:46:57 +020024 struct platform_device *clk;
Bjorn Andersson25bfee12017-05-27 16:14:04 -070025};
26
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +053027struct qcom_apcs_ipc_data {
28 int offset;
29 char *clk_name;
30};
31
Sivaprakash Murugesane9f901d2020-06-08 15:07:27 +053032static const struct qcom_apcs_ipc_data ipq6018_apcs_data = {
33 .offset = 8, .clk_name = "qcom,apss-ipq6018-clk"
34};
35
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +053036static const struct qcom_apcs_ipc_data ipq8074_apcs_data = {
37 .offset = 8, .clk_name = NULL
38};
39
40static const struct qcom_apcs_ipc_data msm8916_apcs_data = {
41 .offset = 8, .clk_name = "qcom-apcs-msm8916-clk"
42};
43
44static const struct qcom_apcs_ipc_data msm8996_apcs_data = {
45 .offset = 16, .clk_name = NULL
46};
47
48static const struct qcom_apcs_ipc_data msm8998_apcs_data = {
49 .offset = 8, .clk_name = NULL
50};
51
52static const struct qcom_apcs_ipc_data apps_shared_apcs_data = {
53 .offset = 12, .clk_name = NULL
54};
55
Georgi Djakovc6a8b172017-12-05 17:46:56 +020056static const struct regmap_config apcs_regmap_config = {
57 .reg_bits = 32,
58 .reg_stride = 4,
59 .val_bits = 32,
Jorge Ramirez-Ortiz556a0962019-09-09 11:08:50 +020060 .max_register = 0xFFC,
Georgi Djakovc6a8b172017-12-05 17:46:56 +020061 .fast_io = true,
62};
63
Bjorn Andersson25bfee12017-05-27 16:14:04 -070064static int qcom_apcs_ipc_send_data(struct mbox_chan *chan, void *data)
65{
66 struct qcom_apcs_ipc *apcs = container_of(chan->mbox,
67 struct qcom_apcs_ipc, mbox);
68 unsigned long idx = (unsigned long)chan->con_priv;
69
Georgi Djakovc6a8b172017-12-05 17:46:56 +020070 return regmap_write(apcs->regmap, apcs->offset, BIT(idx));
Bjorn Andersson25bfee12017-05-27 16:14:04 -070071}
72
73static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
74 .send_data = qcom_apcs_ipc_send_data,
75};
76
77static int qcom_apcs_ipc_probe(struct platform_device *pdev)
78{
79 struct qcom_apcs_ipc *apcs;
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +053080 const struct qcom_apcs_ipc_data *apcs_data;
Georgi Djakovc6a8b172017-12-05 17:46:56 +020081 struct regmap *regmap;
Bjorn Andersson25bfee12017-05-27 16:14:04 -070082 struct resource *res;
Bjorn Andersson25bfee12017-05-27 16:14:04 -070083 void __iomem *base;
84 unsigned long i;
85 int ret;
86
87 apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
88 if (!apcs)
89 return -ENOMEM;
90
91 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
92 base = devm_ioremap_resource(&pdev->dev, res);
93 if (IS_ERR(base))
94 return PTR_ERR(base);
95
Georgi Djakovc6a8b172017-12-05 17:46:56 +020096 regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config);
97 if (IS_ERR(regmap))
98 return PTR_ERR(regmap);
99
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +0530100 apcs_data = of_device_get_match_data(&pdev->dev);
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700101
Georgi Djakovc6a8b172017-12-05 17:46:56 +0200102 apcs->regmap = regmap;
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +0530103 apcs->offset = apcs_data->offset;
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700104
105 /* Initialize channel identifiers */
106 for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++)
107 apcs->mbox_chans[i].con_priv = (void *)i;
108
109 apcs->mbox.dev = &pdev->dev;
110 apcs->mbox.ops = &qcom_apcs_ipc_ops;
111 apcs->mbox.chans = apcs->mbox_chans;
112 apcs->mbox.num_chans = ARRAY_SIZE(apcs->mbox_chans);
113
Thierry Reding83dd44a2018-12-20 18:19:59 +0100114 ret = devm_mbox_controller_register(&pdev->dev, &apcs->mbox);
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700115 if (ret) {
116 dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
117 return ret;
118 }
119
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +0530120 if (apcs_data->clk_name) {
Georgi Djakovc815d762017-12-05 17:46:57 +0200121 apcs->clk = platform_device_register_data(&pdev->dev,
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +0530122 apcs_data->clk_name,
Jorge Ramirez-Ortiz16d52f32019-08-29 10:27:59 +0200123 PLATFORM_DEVID_NONE,
124 NULL, 0);
Georgi Djakovc815d762017-12-05 17:46:57 +0200125 if (IS_ERR(apcs->clk))
126 dev_err(&pdev->dev, "failed to register APCS clk\n");
127 }
128
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700129 platform_set_drvdata(pdev, apcs);
130
131 return 0;
132}
133
134static int qcom_apcs_ipc_remove(struct platform_device *pdev)
135{
136 struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev);
Georgi Djakovc815d762017-12-05 17:46:57 +0200137 struct platform_device *clk = apcs->clk;
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700138
Georgi Djakovc815d762017-12-05 17:46:57 +0200139 platform_device_unregister(clk);
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700140
141 return 0;
142}
143
144/* .data is the offset of the ipc register within the global block */
145static const struct of_device_id qcom_apcs_ipc_of_match[] = {
Sivaprakash Murugesane9f901d2020-06-08 15:07:27 +0530146 { .compatible = "qcom,ipq6018-apcs-apps-global", .data = &ipq6018_apcs_data },
Sivaprakash Murugesan9b007932020-06-08 15:07:26 +0530147 { .compatible = "qcom,ipq8074-apcs-apps-global", .data = &ipq8074_apcs_data },
148 { .compatible = "qcom,msm8916-apcs-kpss-global", .data = &msm8916_apcs_data },
149 { .compatible = "qcom,msm8996-apcs-hmss-global", .data = &msm8996_apcs_data },
150 { .compatible = "qcom,msm8998-apcs-hmss-global", .data = &msm8998_apcs_data },
151 { .compatible = "qcom,qcs404-apcs-apps-global", .data = &msm8916_apcs_data },
152 { .compatible = "qcom,sc7180-apss-shared", .data = &apps_shared_apcs_data },
153 { .compatible = "qcom,sdm845-apss-shared", .data = &apps_shared_apcs_data },
154 { .compatible = "qcom,sm8150-apss-shared", .data = &apps_shared_apcs_data },
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700155 {}
156};
157MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match);
158
159static struct platform_driver qcom_apcs_ipc_driver = {
160 .probe = qcom_apcs_ipc_probe,
161 .remove = qcom_apcs_ipc_remove,
162 .driver = {
163 .name = "qcom_apcs_ipc",
164 .of_match_table = qcom_apcs_ipc_of_match,
165 },
166};
167
168static int __init qcom_apcs_ipc_init(void)
169{
170 return platform_driver_register(&qcom_apcs_ipc_driver);
171}
172postcore_initcall(qcom_apcs_ipc_init);
173
174static void __exit qcom_apcs_ipc_exit(void)
175{
176 platform_driver_unregister(&qcom_apcs_ipc_driver);
177}
178module_exit(qcom_apcs_ipc_exit);
179
180MODULE_LICENSE("GPL v2");
181MODULE_DESCRIPTION("Qualcomm APCS IPC driver");