1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2017, Linaro Ltd
6 #include <linux/kernel.h>
7 #include <linux/module.h>
9 #include <linux/slab.h>
11 #include <linux/of_platform.h>
12 #include <linux/platform_device.h>
13 #include <linux/regmap.h>
14 #include <linux/mailbox_controller.h>
16 #define QCOM_APCS_IPC_BITS 32
18 struct qcom_apcs_ipc
{
19 struct mbox_controller mbox
;
20 struct mbox_chan mbox_chans
[QCOM_APCS_IPC_BITS
];
22 struct regmap
*regmap
;
24 struct platform_device
*clk
;
27 struct qcom_apcs_ipc_data
{
32 static const struct qcom_apcs_ipc_data ipq6018_apcs_data
= {
33 .offset
= 8, .clk_name
= "qcom,apss-ipq6018-clk"
36 static const struct qcom_apcs_ipc_data ipq8074_apcs_data
= {
37 .offset
= 8, .clk_name
= NULL
40 static const struct qcom_apcs_ipc_data msm8916_apcs_data
= {
41 .offset
= 8, .clk_name
= "qcom-apcs-msm8916-clk"
44 static const struct qcom_apcs_ipc_data msm8994_apcs_data
= {
45 .offset
= 8, .clk_name
= NULL
48 static const struct qcom_apcs_ipc_data msm8996_apcs_data
= {
49 .offset
= 16, .clk_name
= NULL
52 static const struct qcom_apcs_ipc_data msm8998_apcs_data
= {
53 .offset
= 8, .clk_name
= NULL
56 static const struct qcom_apcs_ipc_data sdm660_apcs_data
= {
57 .offset
= 8, .clk_name
= NULL
60 static const struct qcom_apcs_ipc_data apps_shared_apcs_data
= {
61 .offset
= 12, .clk_name
= NULL
64 static const struct regmap_config apcs_regmap_config
= {
68 .max_register
= 0xFFC,
72 static int qcom_apcs_ipc_send_data(struct mbox_chan
*chan
, void *data
)
74 struct qcom_apcs_ipc
*apcs
= container_of(chan
->mbox
,
75 struct qcom_apcs_ipc
, mbox
);
76 unsigned long idx
= (unsigned long)chan
->con_priv
;
78 return regmap_write(apcs
->regmap
, apcs
->offset
, BIT(idx
));
81 static const struct mbox_chan_ops qcom_apcs_ipc_ops
= {
82 .send_data
= qcom_apcs_ipc_send_data
,
85 static int qcom_apcs_ipc_probe(struct platform_device
*pdev
)
87 struct qcom_apcs_ipc
*apcs
;
88 const struct qcom_apcs_ipc_data
*apcs_data
;
89 struct regmap
*regmap
;
95 apcs
= devm_kzalloc(&pdev
->dev
, sizeof(*apcs
), GFP_KERNEL
);
99 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
100 base
= devm_ioremap_resource(&pdev
->dev
, res
);
102 return PTR_ERR(base
);
104 regmap
= devm_regmap_init_mmio(&pdev
->dev
, base
, &apcs_regmap_config
);
106 return PTR_ERR(regmap
);
108 apcs_data
= of_device_get_match_data(&pdev
->dev
);
110 apcs
->regmap
= regmap
;
111 apcs
->offset
= apcs_data
->offset
;
113 /* Initialize channel identifiers */
114 for (i
= 0; i
< ARRAY_SIZE(apcs
->mbox_chans
); i
++)
115 apcs
->mbox_chans
[i
].con_priv
= (void *)i
;
117 apcs
->mbox
.dev
= &pdev
->dev
;
118 apcs
->mbox
.ops
= &qcom_apcs_ipc_ops
;
119 apcs
->mbox
.chans
= apcs
->mbox_chans
;
120 apcs
->mbox
.num_chans
= ARRAY_SIZE(apcs
->mbox_chans
);
122 ret
= devm_mbox_controller_register(&pdev
->dev
, &apcs
->mbox
);
124 dev_err(&pdev
->dev
, "failed to register APCS IPC controller\n");
128 if (apcs_data
->clk_name
) {
129 apcs
->clk
= platform_device_register_data(&pdev
->dev
,
133 if (IS_ERR(apcs
->clk
))
134 dev_err(&pdev
->dev
, "failed to register APCS clk\n");
137 platform_set_drvdata(pdev
, apcs
);
142 static int qcom_apcs_ipc_remove(struct platform_device
*pdev
)
144 struct qcom_apcs_ipc
*apcs
= platform_get_drvdata(pdev
);
145 struct platform_device
*clk
= apcs
->clk
;
147 platform_device_unregister(clk
);
152 /* .data is the offset of the ipc register within the global block */
153 static const struct of_device_id qcom_apcs_ipc_of_match
[] = {
154 { .compatible
= "qcom,ipq6018-apcs-apps-global", .data
= &ipq6018_apcs_data
},
155 { .compatible
= "qcom,ipq8074-apcs-apps-global", .data
= &ipq8074_apcs_data
},
156 { .compatible
= "qcom,msm8916-apcs-kpss-global", .data
= &msm8916_apcs_data
},
157 { .compatible
= "qcom,msm8994-apcs-kpss-global", .data
= &msm8994_apcs_data
},
158 { .compatible
= "qcom,msm8996-apcs-hmss-global", .data
= &msm8996_apcs_data
},
159 { .compatible
= "qcom,msm8998-apcs-hmss-global", .data
= &msm8998_apcs_data
},
160 { .compatible
= "qcom,qcs404-apcs-apps-global", .data
= &msm8916_apcs_data
},
161 { .compatible
= "qcom,sc7180-apss-shared", .data
= &apps_shared_apcs_data
},
162 { .compatible
= "qcom,sdm660-apcs-hmss-global", .data
= &sdm660_apcs_data
},
163 { .compatible
= "qcom,sdm845-apss-shared", .data
= &apps_shared_apcs_data
},
164 { .compatible
= "qcom,sm8150-apss-shared", .data
= &apps_shared_apcs_data
},
167 MODULE_DEVICE_TABLE(of
, qcom_apcs_ipc_of_match
);
169 static struct platform_driver qcom_apcs_ipc_driver
= {
170 .probe
= qcom_apcs_ipc_probe
,
171 .remove
= qcom_apcs_ipc_remove
,
173 .name
= "qcom_apcs_ipc",
174 .of_match_table
= qcom_apcs_ipc_of_match
,
178 static int __init
qcom_apcs_ipc_init(void)
180 return platform_driver_register(&qcom_apcs_ipc_driver
);
182 postcore_initcall(qcom_apcs_ipc_init
);
184 static void __exit
qcom_apcs_ipc_exit(void)
186 platform_driver_unregister(&qcom_apcs_ipc_driver
);
188 module_exit(qcom_apcs_ipc_exit
);
190 MODULE_LICENSE("GPL v2");
191 MODULE_DESCRIPTION("Qualcomm APCS IPC driver");