2 * Copyright (c) 2017, Linaro Ltd
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.
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.
14 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <linux/slab.h>
19 #include <linux/of_platform.h>
20 #include <linux/platform_device.h>
21 #include <linux/mailbox_controller.h>
23 #define QCOM_APCS_IPC_BITS 32
25 struct qcom_apcs_ipc
{
26 struct mbox_controller mbox
;
27 struct mbox_chan mbox_chans
[QCOM_APCS_IPC_BITS
];
33 static int qcom_apcs_ipc_send_data(struct mbox_chan
*chan
, void *data
)
35 struct qcom_apcs_ipc
*apcs
= container_of(chan
->mbox
,
36 struct qcom_apcs_ipc
, mbox
);
37 unsigned long idx
= (unsigned long)chan
->con_priv
;
39 writel(BIT(idx
), apcs
->reg
);
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
;
57 apcs
= devm_kzalloc(&pdev
->dev
, sizeof(*apcs
), GFP_KERNEL
);
61 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
62 base
= devm_ioremap_resource(&pdev
->dev
, res
);
66 offset
= (unsigned long)of_device_get_match_data(&pdev
->dev
);
68 apcs
->reg
= base
+ offset
;
70 /* Initialize channel identifiers */
71 for (i
= 0; i
< ARRAY_SIZE(apcs
->mbox_chans
); i
++)
72 apcs
->mbox_chans
[i
].con_priv
= (void *)i
;
74 apcs
->mbox
.dev
= &pdev
->dev
;
75 apcs
->mbox
.ops
= &qcom_apcs_ipc_ops
;
76 apcs
->mbox
.chans
= apcs
->mbox_chans
;
77 apcs
->mbox
.num_chans
= ARRAY_SIZE(apcs
->mbox_chans
);
79 ret
= mbox_controller_register(&apcs
->mbox
);
81 dev_err(&pdev
->dev
, "failed to register APCS IPC controller\n");
85 platform_set_drvdata(pdev
, apcs
);
90 static int qcom_apcs_ipc_remove(struct platform_device
*pdev
)
92 struct qcom_apcs_ipc
*apcs
= platform_get_drvdata(pdev
);
94 mbox_controller_unregister(&apcs
->mbox
);
99 /* .data is the offset of the ipc register within the global block */
100 static const struct of_device_id qcom_apcs_ipc_of_match
[] = {
101 { .compatible
= "qcom,msm8916-apcs-kpss-global", .data
= (void *)8 },
102 { .compatible
= "qcom,msm8996-apcs-hmss-global", .data
= (void *)16 },
105 MODULE_DEVICE_TABLE(of
, qcom_apcs_ipc_of_match
);
107 static struct platform_driver qcom_apcs_ipc_driver
= {
108 .probe
= qcom_apcs_ipc_probe
,
109 .remove
= qcom_apcs_ipc_remove
,
111 .name
= "qcom_apcs_ipc",
112 .of_match_table
= qcom_apcs_ipc_of_match
,
116 static int __init
qcom_apcs_ipc_init(void)
118 return platform_driver_register(&qcom_apcs_ipc_driver
);
120 postcore_initcall(qcom_apcs_ipc_init
);
122 static void __exit
qcom_apcs_ipc_exit(void)
124 platform_driver_unregister(&qcom_apcs_ipc_driver
);
126 module_exit(qcom_apcs_ipc_exit
);
128 MODULE_LICENSE("GPL v2");
129 MODULE_DESCRIPTION("Qualcomm APCS IPC driver");