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 | |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 27 | static const struct regmap_config apcs_regmap_config = { |
| 28 | .reg_bits = 32, |
| 29 | .reg_stride = 4, |
| 30 | .val_bits = 32, |
Jorge Ramirez-Ortiz | 556a096 | 2019-09-09 11:08:50 +0200 | [diff] [blame] | 31 | .max_register = 0xFFC, |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 32 | .fast_io = true, |
| 33 | }; |
| 34 | |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 35 | static 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 Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 41 | return regmap_write(apcs->regmap, apcs->offset, BIT(idx)); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static const struct mbox_chan_ops qcom_apcs_ipc_ops = { |
| 45 | .send_data = qcom_apcs_ipc_send_data, |
| 46 | }; |
| 47 | |
| 48 | static int qcom_apcs_ipc_probe(struct platform_device *pdev) |
| 49 | { |
| 50 | struct qcom_apcs_ipc *apcs; |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 51 | struct regmap *regmap; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 52 | struct resource *res; |
| 53 | unsigned long offset; |
| 54 | void __iomem *base; |
| 55 | unsigned long i; |
| 56 | int ret; |
Jorge Ramirez-Ortiz | 78c8645 | 2019-08-29 10:27:58 +0200 | [diff] [blame] | 57 | 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 Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 62 | |
| 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 Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 72 | regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config); |
| 73 | if (IS_ERR(regmap)) |
| 74 | return PTR_ERR(regmap); |
| 75 | |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 76 | offset = (unsigned long)of_device_get_match_data(&pdev->dev); |
| 77 | |
Georgi Djakov | c6a8b17 | 2017-12-05 17:46:56 +0200 | [diff] [blame] | 78 | apcs->regmap = regmap; |
| 79 | apcs->offset = offset; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 80 | |
| 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 Reding | 83dd44a | 2018-12-20 18:19:59 +0100 | [diff] [blame] | 90 | ret = devm_mbox_controller_register(&pdev->dev, &apcs->mbox); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 91 | if (ret) { |
| 92 | dev_err(&pdev->dev, "failed to register APCS IPC controller\n"); |
| 93 | return ret; |
| 94 | } |
| 95 | |
Jorge Ramirez-Ortiz | 78c8645 | 2019-08-29 10:27:58 +0200 | [diff] [blame] | 96 | if (of_match_device(apcs_clk_match_table, &pdev->dev)) { |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 97 | apcs->clk = platform_device_register_data(&pdev->dev, |
| 98 | "qcom-apcs-msm8916-clk", |
Jorge Ramirez-Ortiz | 16d52f3 | 2019-08-29 10:27:59 +0200 | [diff] [blame] | 99 | PLATFORM_DEVID_NONE, |
| 100 | NULL, 0); |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 101 | if (IS_ERR(apcs->clk)) |
| 102 | dev_err(&pdev->dev, "failed to register APCS clk\n"); |
| 103 | } |
| 104 | |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 105 | platform_set_drvdata(pdev, apcs); |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static int qcom_apcs_ipc_remove(struct platform_device *pdev) |
| 111 | { |
| 112 | struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev); |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 113 | struct platform_device *clk = apcs->clk; |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 114 | |
Georgi Djakov | c815d76 | 2017-12-05 17:46:57 +0200 | [diff] [blame] | 115 | platform_device_unregister(clk); |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 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 }, |
Bjorn Andersson | 61a2f6d | 2018-03-27 08:54:26 -0700 | [diff] [blame] | 124 | { .compatible = "qcom,msm8998-apcs-hmss-global", .data = (void *)8 }, |
Bjorn Andersson | 0a01fa9 | 2018-09-19 18:44:08 -0700 | [diff] [blame] | 125 | { .compatible = "qcom,qcs404-apcs-apps-global", .data = (void *)8 }, |
Sibi Sankar | 08a81d3 | 2019-08-07 12:39:55 +0530 | [diff] [blame] | 126 | { .compatible = "qcom,sc7180-apss-shared", .data = (void *)12 }, |
Sibi Sankar | 05e99a7 | 2018-04-25 20:08:02 +0530 | [diff] [blame] | 127 | { .compatible = "qcom,sdm845-apss-shared", .data = (void *)12 }, |
Sibi Sankar | 08a81d3 | 2019-08-07 12:39:55 +0530 | [diff] [blame] | 128 | { .compatible = "qcom,sm8150-apss-shared", .data = (void *)12 }, |
Gokul Sriram Palanisamy | 88ae25e | 2019-09-13 17:26:08 +0530 | [diff] [blame] | 129 | { .compatible = "qcom,ipq8074-apcs-apps-global", .data = (void *)8 }, |
Bjorn Andersson | 25bfee1 | 2017-05-27 16:14:04 -0700 | [diff] [blame] | 130 | {} |
| 131 | }; |
| 132 | MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match); |
| 133 | |
| 134 | static 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 | |
| 143 | static int __init qcom_apcs_ipc_init(void) |
| 144 | { |
| 145 | return platform_driver_register(&qcom_apcs_ipc_driver); |
| 146 | } |
| 147 | postcore_initcall(qcom_apcs_ipc_init); |
| 148 | |
| 149 | static void __exit qcom_apcs_ipc_exit(void) |
| 150 | { |
| 151 | platform_driver_unregister(&qcom_apcs_ipc_driver); |
| 152 | } |
| 153 | module_exit(qcom_apcs_ipc_exit); |
| 154 | |
| 155 | MODULE_LICENSE("GPL v2"); |
| 156 | MODULE_DESCRIPTION("Qualcomm APCS IPC driver"); |