Thomas Gleixner | 97fb5e8 | 2019-05-29 07:17:58 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017, Linaro Ltd |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 4 | */ |
| 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 Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 13 | #include <linux/regmap.h> |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 14 | #include <linux/mailbox_controller.h> |
| 15 | |
| 16 | #define QCOM_APCS_IPC_BITS 32 |
| 17 | |
| 18 | struct qcom_apcs_ipc { |
| 19 | struct mbox_controller mbox; |
| 20 | struct mbox_chan mbox_chans[QCOM_APCS_IPC_BITS]; |
| 21 | |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 22 | struct regmap *regmap; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 23 | unsigned long offset; |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 24 | struct platform_device *clk; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 25 | }; |
| 26 | |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 27 | struct qcom_apcs_ipc_data { |
| 28 | int offset; |
| 29 | char *clk_name; |
| 30 | }; |
| 31 | |
Sivaprakash Murugesan | e9f901d | 2020-06-08 15:07:27 +0530 | [diff] [blame] | 32 | static const struct qcom_apcs_ipc_data ipq6018_apcs_data = { |
| 33 | .offset = 8, .clk_name = "qcom,apss-ipq6018-clk" |
| 34 | }; |
| 35 | |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 36 | static const struct qcom_apcs_ipc_data msm8916_apcs_data = { |
| 37 | .offset = 8, .clk_name = "qcom-apcs-msm8916-clk" |
| 38 | }; |
| 39 | |
Konrad Dybcio | dde6805 | 2020-06-24 17:01:03 +0200 | [diff] [blame] | 40 | static const struct qcom_apcs_ipc_data msm8994_apcs_data = { |
| 41 | .offset = 8, .clk_name = NULL |
| 42 | }; |
| 43 | |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 44 | static const struct qcom_apcs_ipc_data msm8996_apcs_data = { |
| 45 | .offset = 16, .clk_name = NULL |
| 46 | }; |
| 47 | |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 48 | static const struct qcom_apcs_ipc_data apps_shared_apcs_data = { |
| 49 | .offset = 12, .clk_name = NULL |
| 50 | }; |
| 51 | |
Manivannan Sadhasivam | c319f78 | 2021-01-18 09:41:53 +0530 | [diff] [blame] | 52 | static const struct qcom_apcs_ipc_data sdx55_apcs_data = { |
| 53 | .offset = 0x1008, .clk_name = "qcom-sdx55-acps-clk" |
| 54 | }; |
| 55 | |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 56 | static const struct regmap_config apcs_regmap_config = { |
| 57 | .reg_bits = 32, |
| 58 | .reg_stride = 4, |
| 59 | .val_bits = 32, |
Manivannan Sadhasivam | c319f78 | 2021-01-18 09:41:53 +0530 | [diff] [blame] | 60 | .max_register = 0x1008, |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 61 | .fast_io = true, |
| 62 | }; |
| 63 | |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 64 | static 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 Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 70 | return regmap_write(apcs->regmap, apcs->offset, BIT(idx)); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static const struct mbox_chan_ops qcom_apcs_ipc_ops = { |
| 74 | .send_data = qcom_apcs_ipc_send_data, |
| 75 | }; |
| 76 | |
| 77 | static int qcom_apcs_ipc_probe(struct platform_device *pdev) |
| 78 | { |
| 79 | struct qcom_apcs_ipc *apcs; |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 80 | const struct qcom_apcs_ipc_data *apcs_data; |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 81 | struct regmap *regmap; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 82 | void __iomem *base; |
| 83 | unsigned long i; |
| 84 | int ret; |
| 85 | |
| 86 | apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL); |
| 87 | if (!apcs) |
| 88 | return -ENOMEM; |
| 89 | |
Cai Huoqing | 78c6798 | 2021-09-07 15:41:39 +0800 | [diff] [blame] | 90 | base = devm_platform_ioremap_resource(pdev, 0); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 91 | if (IS_ERR(base)) |
| 92 | return PTR_ERR(base); |
| 93 | |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 94 | regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config); |
| 95 | if (IS_ERR(regmap)) |
| 96 | return PTR_ERR(regmap); |
| 97 | |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 98 | apcs_data = of_device_get_match_data(&pdev->dev); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 99 | |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 100 | apcs->regmap = regmap; |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 101 | apcs->offset = apcs_data->offset; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 102 | |
| 103 | /* Initialize channel identifiers */ |
| 104 | for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++) |
| 105 | apcs->mbox_chans[i].con_priv = (void *)i; |
| 106 | |
| 107 | apcs->mbox.dev = &pdev->dev; |
| 108 | apcs->mbox.ops = &qcom_apcs_ipc_ops; |
| 109 | apcs->mbox.chans = apcs->mbox_chans; |
| 110 | apcs->mbox.num_chans = ARRAY_SIZE(apcs->mbox_chans); |
| 111 | |
Thierry Reding | 83dd44a | 2018-12-20 18:19:59 +0100 | [diff] [blame] | 112 | ret = devm_mbox_controller_register(&pdev->dev, &apcs->mbox); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 113 | if (ret) { |
| 114 | dev_err(&pdev->dev, "failed to register APCS IPC controller\n"); |
| 115 | return ret; |
| 116 | } |
| 117 | |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 118 | if (apcs_data->clk_name) { |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 119 | apcs->clk = platform_device_register_data(&pdev->dev, |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 120 | apcs_data->clk_name, |
Shawn Guo | 96e39e9 | 2021-06-22 08:39:18 +0800 | [diff] [blame] | 121 | PLATFORM_DEVID_AUTO, |
Jorge Ramirez-Ortiz | 16d52f3 | 2019-08-29 10:27:59 +0200 | [diff] [blame] | 122 | NULL, 0); |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 123 | if (IS_ERR(apcs->clk)) |
| 124 | dev_err(&pdev->dev, "failed to register APCS clk\n"); |
| 125 | } |
| 126 | |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 127 | platform_set_drvdata(pdev, apcs); |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | static int qcom_apcs_ipc_remove(struct platform_device *pdev) |
| 133 | { |
| 134 | struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev); |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 135 | struct platform_device *clk = apcs->clk; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 136 | |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 137 | platform_device_unregister(clk); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | /* .data is the offset of the ipc register within the global block */ |
| 143 | static const struct of_device_id qcom_apcs_ipc_of_match[] = { |
Sivaprakash Murugesan | e9f901d | 2020-06-08 15:07:27 +0530 | [diff] [blame] | 144 | { .compatible = "qcom,ipq6018-apcs-apps-global", .data = &ipq6018_apcs_data }, |
Shawn Guo | 4523ec8 | 2021-09-14 09:40:48 +0800 | [diff] [blame] | 145 | { .compatible = "qcom,ipq8074-apcs-apps-global", .data = &msm8994_apcs_data }, |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 146 | { .compatible = "qcom,msm8916-apcs-kpss-global", .data = &msm8916_apcs_data }, |
Shawn Guo | 8a7cdb1 | 2021-06-22 08:39:19 +0800 | [diff] [blame] | 147 | { .compatible = "qcom,msm8939-apcs-kpss-global", .data = &msm8916_apcs_data }, |
Vladimir Lypak | e5c11ee | 2021-08-10 16:44:33 +0000 | [diff] [blame] | 148 | { .compatible = "qcom,msm8953-apcs-kpss-global", .data = &msm8994_apcs_data }, |
Konrad Dybcio | dde6805 | 2020-06-24 17:01:03 +0200 | [diff] [blame] | 149 | { .compatible = "qcom,msm8994-apcs-kpss-global", .data = &msm8994_apcs_data }, |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 150 | { .compatible = "qcom,msm8996-apcs-hmss-global", .data = &msm8996_apcs_data }, |
Shawn Guo | 4523ec8 | 2021-09-14 09:40:48 +0800 | [diff] [blame] | 151 | { .compatible = "qcom,msm8998-apcs-hmss-global", .data = &msm8994_apcs_data }, |
Shawn Guo | db28a59 | 2021-09-14 09:40:50 +0800 | [diff] [blame] | 152 | { .compatible = "qcom,qcm2290-apcs-hmss-global", .data = &msm8994_apcs_data }, |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 153 | { .compatible = "qcom,qcs404-apcs-apps-global", .data = &msm8916_apcs_data }, |
| 154 | { .compatible = "qcom,sc7180-apss-shared", .data = &apps_shared_apcs_data }, |
Bjorn Andersson | d10c851 | 2021-01-20 17:41:30 -0800 | [diff] [blame] | 155 | { .compatible = "qcom,sc8180x-apss-shared", .data = &apps_shared_apcs_data }, |
Shawn Guo | 4523ec8 | 2021-09-14 09:40:48 +0800 | [diff] [blame] | 156 | { .compatible = "qcom,sdm660-apcs-hmss-global", .data = &msm8994_apcs_data }, |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 157 | { .compatible = "qcom,sdm845-apss-shared", .data = &apps_shared_apcs_data }, |
Shawn Guo | 4523ec8 | 2021-09-14 09:40:48 +0800 | [diff] [blame] | 158 | { .compatible = "qcom,sm6125-apcs-hmss-global", .data = &msm8994_apcs_data }, |
Sivaprakash Murugesan | 9b00793 | 2020-06-08 15:07:26 +0530 | [diff] [blame] | 159 | { .compatible = "qcom,sm8150-apss-shared", .data = &apps_shared_apcs_data }, |
Shawn Guo | 4523ec8 | 2021-09-14 09:40:48 +0800 | [diff] [blame] | 160 | { .compatible = "qcom,sm6115-apcs-hmss-global", .data = &msm8994_apcs_data }, |
Manivannan Sadhasivam | c319f78 | 2021-01-18 09:41:53 +0530 | [diff] [blame] | 161 | { .compatible = "qcom,sdx55-apcs-gcc", .data = &sdx55_apcs_data }, |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 162 | {} |
| 163 | }; |
| 164 | MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match); |
| 165 | |
| 166 | static struct platform_driver qcom_apcs_ipc_driver = { |
| 167 | .probe = qcom_apcs_ipc_probe, |
| 168 | .remove = qcom_apcs_ipc_remove, |
| 169 | .driver = { |
| 170 | .name = "qcom_apcs_ipc", |
| 171 | .of_match_table = qcom_apcs_ipc_of_match, |
| 172 | }, |
| 173 | }; |
| 174 | |
| 175 | static int __init qcom_apcs_ipc_init(void) |
| 176 | { |
| 177 | return platform_driver_register(&qcom_apcs_ipc_driver); |
| 178 | } |
| 179 | postcore_initcall(qcom_apcs_ipc_init); |
| 180 | |
| 181 | static void __exit qcom_apcs_ipc_exit(void) |
| 182 | { |
| 183 | platform_driver_unregister(&qcom_apcs_ipc_driver); |
| 184 | } |
| 185 | module_exit(qcom_apcs_ipc_exit); |
| 186 | |
| 187 | MODULE_LICENSE("GPL v2"); |
| 188 | MODULE_DESCRIPTION("Qualcomm APCS IPC driver"); |