Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2017, Linaro Ltd
 
 
 
 
 
 
 
 
 
  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>
 13#include <linux/regmap.h>
 14#include <linux/mailbox_controller.h>
 15
 16#define QCOM_APCS_IPC_BITS	32
 17
 18struct qcom_apcs_ipc {
 19	struct mbox_controller mbox;
 20	struct mbox_chan mbox_chans[QCOM_APCS_IPC_BITS];
 21
 22	struct regmap *regmap;
 23	unsigned long offset;
 24	struct platform_device *clk;
 25};
 26
 27struct qcom_apcs_ipc_data {
 28	int offset;
 29	char *clk_name;
 30};
 31
 32static const struct qcom_apcs_ipc_data ipq6018_apcs_data = {
 33	.offset = 8, .clk_name = "qcom,apss-ipq6018-clk"
 34};
 35
 36static const struct qcom_apcs_ipc_data ipq8074_apcs_data = {
 37	.offset = 8, .clk_name = NULL
 38};
 39
 40static const struct qcom_apcs_ipc_data msm8916_apcs_data = {
 41	.offset = 8, .clk_name = "qcom-apcs-msm8916-clk"
 42};
 43
 44static const struct qcom_apcs_ipc_data msm8994_apcs_data = {
 45	.offset = 8, .clk_name = NULL
 46};
 47
 48static const struct qcom_apcs_ipc_data msm8996_apcs_data = {
 49	.offset = 16, .clk_name = NULL
 50};
 51
 52static const struct qcom_apcs_ipc_data msm8998_apcs_data = {
 53	.offset = 8, .clk_name = NULL
 54};
 55
 56static const struct qcom_apcs_ipc_data sdm660_apcs_data = {
 57	.offset = 8, .clk_name = NULL
 58};
 59
 60static const struct qcom_apcs_ipc_data apps_shared_apcs_data = {
 61	.offset = 12, .clk_name = NULL
 62};
 63
 64static const struct regmap_config apcs_regmap_config = {
 65	.reg_bits = 32,
 66	.reg_stride = 4,
 67	.val_bits = 32,
 68	.max_register = 0xFFC,
 69	.fast_io = true,
 70};
 71
 72static int qcom_apcs_ipc_send_data(struct mbox_chan *chan, void *data)
 73{
 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;
 77
 78	return regmap_write(apcs->regmap, apcs->offset, BIT(idx));
 79}
 80
 81static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
 82	.send_data = qcom_apcs_ipc_send_data,
 83};
 84
 85static int qcom_apcs_ipc_probe(struct platform_device *pdev)
 86{
 
 87	struct qcom_apcs_ipc *apcs;
 88	const struct qcom_apcs_ipc_data *apcs_data;
 89	struct regmap *regmap;
 90	struct resource *res;
 
 91	void __iomem *base;
 92	unsigned long i;
 93	int ret;
 94
 95	apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
 96	if (!apcs)
 97		return -ENOMEM;
 98
 99	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
100	base = devm_ioremap_resource(&pdev->dev, res);
101	if (IS_ERR(base))
102		return PTR_ERR(base);
103
104	regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config);
105	if (IS_ERR(regmap))
106		return PTR_ERR(regmap);
107
108	apcs_data = of_device_get_match_data(&pdev->dev);
109
110	apcs->regmap = regmap;
111	apcs->offset = apcs_data->offset;
112
113	/* Initialize channel identifiers */
114	for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++)
115		apcs->mbox_chans[i].con_priv = (void *)i;
116
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);
121
122	ret = devm_mbox_controller_register(&pdev->dev, &apcs->mbox);
123	if (ret) {
124		dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
125		return ret;
126	}
127
128	if (apcs_data->clk_name) {
129		apcs->clk = platform_device_register_data(&pdev->dev,
130							  apcs_data->clk_name,
131							  PLATFORM_DEVID_NONE,
132							  NULL, 0);
133		if (IS_ERR(apcs->clk))
134			dev_err(&pdev->dev, "failed to register APCS clk\n");
135	}
136
137	platform_set_drvdata(pdev, apcs);
138
139	return 0;
140}
141
142static int qcom_apcs_ipc_remove(struct platform_device *pdev)
143{
144	struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev);
145	struct platform_device *clk = apcs->clk;
146
 
147	platform_device_unregister(clk);
148
149	return 0;
150}
151
152/* .data is the offset of the ipc register within the global block */
153static 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 },
165	{}
166};
167MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match);
168
169static struct platform_driver qcom_apcs_ipc_driver = {
170	.probe = qcom_apcs_ipc_probe,
171	.remove = qcom_apcs_ipc_remove,
172	.driver = {
173		.name = "qcom_apcs_ipc",
174		.of_match_table = qcom_apcs_ipc_of_match,
175	},
176};
177
178static int __init qcom_apcs_ipc_init(void)
179{
180	return platform_driver_register(&qcom_apcs_ipc_driver);
181}
182postcore_initcall(qcom_apcs_ipc_init);
183
184static void __exit qcom_apcs_ipc_exit(void)
185{
186	platform_driver_unregister(&qcom_apcs_ipc_driver);
187}
188module_exit(qcom_apcs_ipc_exit);
189
190MODULE_LICENSE("GPL v2");
191MODULE_DESCRIPTION("Qualcomm APCS IPC driver");
v4.17
 
  1/*
  2 * Copyright (c) 2017, Linaro Ltd
  3 *
  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.
  7 *
  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.
 12 */
 13
 14#include <linux/kernel.h>
 15#include <linux/module.h>
 16#include <linux/io.h>
 17#include <linux/slab.h>
 18#include <linux/of.h>
 19#include <linux/of_platform.h>
 20#include <linux/platform_device.h>
 21#include <linux/regmap.h>
 22#include <linux/mailbox_controller.h>
 23
 24#define QCOM_APCS_IPC_BITS	32
 25
 26struct qcom_apcs_ipc {
 27	struct mbox_controller mbox;
 28	struct mbox_chan mbox_chans[QCOM_APCS_IPC_BITS];
 29
 30	struct regmap *regmap;
 31	unsigned long offset;
 32	struct platform_device *clk;
 33};
 34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 35static const struct regmap_config apcs_regmap_config = {
 36	.reg_bits = 32,
 37	.reg_stride = 4,
 38	.val_bits = 32,
 39	.max_register = 0x1000,
 40	.fast_io = true,
 41};
 42
 43static int qcom_apcs_ipc_send_data(struct mbox_chan *chan, void *data)
 44{
 45	struct qcom_apcs_ipc *apcs = container_of(chan->mbox,
 46						  struct qcom_apcs_ipc, mbox);
 47	unsigned long idx = (unsigned long)chan->con_priv;
 48
 49	return regmap_write(apcs->regmap, apcs->offset, BIT(idx));
 50}
 51
 52static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
 53	.send_data = qcom_apcs_ipc_send_data,
 54};
 55
 56static int qcom_apcs_ipc_probe(struct platform_device *pdev)
 57{
 58	struct device_node *np = pdev->dev.of_node;
 59	struct qcom_apcs_ipc *apcs;
 
 60	struct regmap *regmap;
 61	struct resource *res;
 62	unsigned long offset;
 63	void __iomem *base;
 64	unsigned long i;
 65	int ret;
 66
 67	apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
 68	if (!apcs)
 69		return -ENOMEM;
 70
 71	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 72	base = devm_ioremap_resource(&pdev->dev, res);
 73	if (IS_ERR(base))
 74		return PTR_ERR(base);
 75
 76	regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config);
 77	if (IS_ERR(regmap))
 78		return PTR_ERR(regmap);
 79
 80	offset = (unsigned long)of_device_get_match_data(&pdev->dev);
 81
 82	apcs->regmap = regmap;
 83	apcs->offset = offset;
 84
 85	/* Initialize channel identifiers */
 86	for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++)
 87		apcs->mbox_chans[i].con_priv = (void *)i;
 88
 89	apcs->mbox.dev = &pdev->dev;
 90	apcs->mbox.ops = &qcom_apcs_ipc_ops;
 91	apcs->mbox.chans = apcs->mbox_chans;
 92	apcs->mbox.num_chans = ARRAY_SIZE(apcs->mbox_chans);
 93
 94	ret = mbox_controller_register(&apcs->mbox);
 95	if (ret) {
 96		dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
 97		return ret;
 98	}
 99
100	if (of_device_is_compatible(np, "qcom,msm8916-apcs-kpss-global")) {
101		apcs->clk = platform_device_register_data(&pdev->dev,
102							  "qcom-apcs-msm8916-clk",
103							  -1, NULL, 0);
 
104		if (IS_ERR(apcs->clk))
105			dev_err(&pdev->dev, "failed to register APCS clk\n");
106	}
107
108	platform_set_drvdata(pdev, apcs);
109
110	return 0;
111}
112
113static int qcom_apcs_ipc_remove(struct platform_device *pdev)
114{
115	struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev);
116	struct platform_device *clk = apcs->clk;
117
118	mbox_controller_unregister(&apcs->mbox);
119	platform_device_unregister(clk);
120
121	return 0;
122}
123
124/* .data is the offset of the ipc register within the global block */
125static const struct of_device_id qcom_apcs_ipc_of_match[] = {
126	{ .compatible = "qcom,msm8916-apcs-kpss-global", .data = (void *)8 },
127	{ .compatible = "qcom,msm8996-apcs-hmss-global", .data = (void *)16 },
 
 
 
 
 
 
 
 
 
128	{}
129};
130MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match);
131
132static struct platform_driver qcom_apcs_ipc_driver = {
133	.probe = qcom_apcs_ipc_probe,
134	.remove = qcom_apcs_ipc_remove,
135	.driver = {
136		.name = "qcom_apcs_ipc",
137		.of_match_table = qcom_apcs_ipc_of_match,
138	},
139};
140
141static int __init qcom_apcs_ipc_init(void)
142{
143	return platform_driver_register(&qcom_apcs_ipc_driver);
144}
145postcore_initcall(qcom_apcs_ipc_init);
146
147static void __exit qcom_apcs_ipc_exit(void)
148{
149	platform_driver_unregister(&qcom_apcs_ipc_driver);
150}
151module_exit(qcom_apcs_ipc_exit);
152
153MODULE_LICENSE("GPL v2");
154MODULE_DESCRIPTION("Qualcomm APCS IPC driver");