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 static const struct regmap_config apcs_regmap_config
= {
31 .max_register
= 0xFFC,
35 static int qcom_apcs_ipc_send_data(struct mbox_chan
*chan
, void *data
)
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
;
41 return regmap_write(apcs
->regmap
, apcs
->offset
, BIT(idx
));
44 static const struct mbox_chan_ops qcom_apcs_ipc_ops
= {
45 .send_data
= qcom_apcs_ipc_send_data
,
48 static int qcom_apcs_ipc_probe(struct platform_device
*pdev
)
50 struct qcom_apcs_ipc
*apcs
;
51 struct regmap
*regmap
;
57 const struct of_device_id apcs_clk_match_table
[] = {
58 { .compatible
= "qcom,msm8916-apcs-kpss-global", },
59 { .compatible
= "qcom,qcs404-apcs-apps-global", },
63 apcs
= devm_kzalloc(&pdev
->dev
, sizeof(*apcs
), GFP_KERNEL
);
67 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
68 base
= devm_ioremap_resource(&pdev
->dev
, res
);
72 regmap
= devm_regmap_init_mmio(&pdev
->dev
, base
, &apcs_regmap_config
);
74 return PTR_ERR(regmap
);
76 offset
= (unsigned long)of_device_get_match_data(&pdev
->dev
);
78 apcs
->regmap
= regmap
;
79 apcs
->offset
= offset
;
81 /* Initialize channel identifiers */
82 for (i
= 0; i
< ARRAY_SIZE(apcs
->mbox_chans
); i
++)
83 apcs
->mbox_chans
[i
].con_priv
= (void *)i
;
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
);
90 ret
= devm_mbox_controller_register(&pdev
->dev
, &apcs
->mbox
);
92 dev_err(&pdev
->dev
, "failed to register APCS IPC controller\n");
96 if (of_match_device(apcs_clk_match_table
, &pdev
->dev
)) {
97 apcs
->clk
= platform_device_register_data(&pdev
->dev
,
98 "qcom-apcs-msm8916-clk",
101 if (IS_ERR(apcs
->clk
))
102 dev_err(&pdev
->dev
, "failed to register APCS clk\n");
105 platform_set_drvdata(pdev
, apcs
);
110 static int qcom_apcs_ipc_remove(struct platform_device
*pdev
)
112 struct qcom_apcs_ipc
*apcs
= platform_get_drvdata(pdev
);
113 struct platform_device
*clk
= apcs
->clk
;
115 platform_device_unregister(clk
);
120 /* .data is the offset of the ipc register within the global block */
121 static 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 },
124 { .compatible
= "qcom,msm8998-apcs-hmss-global", .data
= (void *)8 },
125 { .compatible
= "qcom,qcs404-apcs-apps-global", .data
= (void *)8 },
126 { .compatible
= "qcom,sc7180-apss-shared", .data
= (void *)12 },
127 { .compatible
= "qcom,sdm845-apss-shared", .data
= (void *)12 },
128 { .compatible
= "qcom,sm8150-apss-shared", .data
= (void *)12 },
129 { .compatible
= "qcom,ipq8074-apcs-apps-global", .data
= (void *)8 },
132 MODULE_DEVICE_TABLE(of
, qcom_apcs_ipc_of_match
);
134 static struct platform_driver qcom_apcs_ipc_driver
= {
135 .probe
= qcom_apcs_ipc_probe
,
136 .remove
= qcom_apcs_ipc_remove
,
138 .name
= "qcom_apcs_ipc",
139 .of_match_table
= qcom_apcs_ipc_of_match
,
143 static int __init
qcom_apcs_ipc_init(void)
145 return platform_driver_register(&qcom_apcs_ipc_driver
);
147 postcore_initcall(qcom_apcs_ipc_init
);
149 static void __exit
qcom_apcs_ipc_exit(void)
151 platform_driver_unregister(&qcom_apcs_ipc_driver
);
153 module_exit(qcom_apcs_ipc_exit
);
155 MODULE_LICENSE("GPL v2");
156 MODULE_DESCRIPTION("Qualcomm APCS IPC driver");