blob: eeebafd546e56e47f0dec5a2679359c7702fbc20 [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
Georgi Djakovc6a8b172017-12-05 17:46:56 +020027static const struct regmap_config apcs_regmap_config = {
28 .reg_bits = 32,
29 .reg_stride = 4,
30 .val_bits = 32,
Jorge Ramirez-Ortiz556a0962019-09-09 11:08:50 +020031 .max_register = 0xFFC,
Georgi Djakovc6a8b172017-12-05 17:46:56 +020032 .fast_io = true,
33};
34
Bjorn Andersson25bfee12017-05-27 16:14:04 -070035static 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
Georgi Djakovc6a8b172017-12-05 17:46:56 +020041 return regmap_write(apcs->regmap, apcs->offset, BIT(idx));
Bjorn Andersson25bfee12017-05-27 16:14:04 -070042}
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;
Georgi Djakovc6a8b172017-12-05 17:46:56 +020051 struct regmap *regmap;
Bjorn Andersson25bfee12017-05-27 16:14:04 -070052 struct resource *res;
53 unsigned long offset;
54 void __iomem *base;
55 unsigned long i;
56 int ret;
Jorge Ramirez-Ortiz78c86452019-08-29 10:27:58 +020057 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 };
Bjorn Andersson25bfee12017-05-27 16:14:04 -070062
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
Georgi Djakovc6a8b172017-12-05 17:46:56 +020072 regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config);
73 if (IS_ERR(regmap))
74 return PTR_ERR(regmap);
75
Bjorn Andersson25bfee12017-05-27 16:14:04 -070076 offset = (unsigned long)of_device_get_match_data(&pdev->dev);
77
Georgi Djakovc6a8b172017-12-05 17:46:56 +020078 apcs->regmap = regmap;
79 apcs->offset = offset;
Bjorn Andersson25bfee12017-05-27 16:14:04 -070080
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
Thierry Reding83dd44a2018-12-20 18:19:59 +010090 ret = devm_mbox_controller_register(&pdev->dev, &apcs->mbox);
Bjorn Andersson25bfee12017-05-27 16:14:04 -070091 if (ret) {
92 dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
93 return ret;
94 }
95
Jorge Ramirez-Ortiz78c86452019-08-29 10:27:58 +020096 if (of_match_device(apcs_clk_match_table, &pdev->dev)) {
Georgi Djakovc815d762017-12-05 17:46:57 +020097 apcs->clk = platform_device_register_data(&pdev->dev,
98 "qcom-apcs-msm8916-clk",
Jorge Ramirez-Ortiz16d52f32019-08-29 10:27:59 +020099 PLATFORM_DEVID_NONE,
100 NULL, 0);
Georgi Djakovc815d762017-12-05 17:46:57 +0200101 if (IS_ERR(apcs->clk))
102 dev_err(&pdev->dev, "failed to register APCS clk\n");
103 }
104
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700105 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);
Georgi Djakovc815d762017-12-05 17:46:57 +0200113 struct platform_device *clk = apcs->clk;
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700114
Georgi Djakovc815d762017-12-05 17:46:57 +0200115 platform_device_unregister(clk);
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700116
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 },
Bjorn Andersson61a2f6d2018-03-27 08:54:26 -0700124 { .compatible = "qcom,msm8998-apcs-hmss-global", .data = (void *)8 },
Bjorn Andersson0a01fa92018-09-19 18:44:08 -0700125 { .compatible = "qcom,qcs404-apcs-apps-global", .data = (void *)8 },
Sibi Sankar08a81d32019-08-07 12:39:55 +0530126 { .compatible = "qcom,sc7180-apss-shared", .data = (void *)12 },
Sibi Sankar05e99a72018-04-25 20:08:02 +0530127 { .compatible = "qcom,sdm845-apss-shared", .data = (void *)12 },
Sibi Sankar08a81d32019-08-07 12:39:55 +0530128 { .compatible = "qcom,sm8150-apss-shared", .data = (void *)12 },
Gokul Sriram Palanisamy88ae25e2019-09-13 17:26:08 +0530129 { .compatible = "qcom,ipq8074-apcs-apps-global", .data = (void *)8 },
Bjorn Andersson25bfee12017-05-27 16:14:04 -0700130 {}
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");