smd-rpm.c (f26e8817b235d8764363bffcc9cbfc61867371f2) smd-rpm.c (5052de8deff5619a9b7071f00084fd0264b58e17)
1/*
2 * Copyright (c) 2015, Sony Mobile Communications AB.
3 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
8 *

--- 5 unchanged lines hidden (view full) ---

14
15#include <linux/module.h>
16#include <linux/platform_device.h>
17#include <linux/of_platform.h>
18#include <linux/io.h>
19#include <linux/interrupt.h>
20#include <linux/slab.h>
21
1/*
2 * Copyright (c) 2015, Sony Mobile Communications AB.
3 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
8 *

--- 5 unchanged lines hidden (view full) ---

14
15#include <linux/module.h>
16#include <linux/platform_device.h>
17#include <linux/of_platform.h>
18#include <linux/io.h>
19#include <linux/interrupt.h>
20#include <linux/slab.h>
21
22#include <linux/soc/qcom/smd.h>
22#include <linux/rpmsg.h>
23#include <linux/soc/qcom/smd-rpm.h>
24
25#define RPM_REQUEST_TIMEOUT (5 * HZ)
26
27/**
28 * struct qcom_smd_rpm - state of the rpm device driver
29 * @rpm_channel: reference to the smd channel
30 * @ack: completion for acks
31 * @lock: mutual exclusion around the send/complete pair
32 * @ack_status: result of the rpm request
33 */
34struct qcom_smd_rpm {
23#include <linux/soc/qcom/smd-rpm.h>
24
25#define RPM_REQUEST_TIMEOUT (5 * HZ)
26
27/**
28 * struct qcom_smd_rpm - state of the rpm device driver
29 * @rpm_channel: reference to the smd channel
30 * @ack: completion for acks
31 * @lock: mutual exclusion around the send/complete pair
32 * @ack_status: result of the rpm request
33 */
34struct qcom_smd_rpm {
35 struct qcom_smd_channel *rpm_channel;
35 struct rpmsg_endpoint *rpm_channel;
36 struct device *dev;
37
38 struct completion ack;
39 struct mutex lock;
40 int ack_status;
41};
42
43/**

--- 84 unchanged lines hidden (view full) ---

128
129 pkt->req.msg_id = cpu_to_le32(msg_id++);
130 pkt->req.flags = cpu_to_le32(state);
131 pkt->req.type = cpu_to_le32(type);
132 pkt->req.id = cpu_to_le32(id);
133 pkt->req.data_len = cpu_to_le32(count);
134 memcpy(pkt->payload, buf, count);
135
36 struct device *dev;
37
38 struct completion ack;
39 struct mutex lock;
40 int ack_status;
41};
42
43/**

--- 84 unchanged lines hidden (view full) ---

128
129 pkt->req.msg_id = cpu_to_le32(msg_id++);
130 pkt->req.flags = cpu_to_le32(state);
131 pkt->req.type = cpu_to_le32(type);
132 pkt->req.id = cpu_to_le32(id);
133 pkt->req.data_len = cpu_to_le32(count);
134 memcpy(pkt->payload, buf, count);
135
136 ret = qcom_smd_send(rpm->rpm_channel, pkt, size);
136 ret = rpmsg_send(rpm->rpm_channel, pkt, size);
137 if (ret)
138 goto out;
139
140 left = wait_for_completion_timeout(&rpm->ack, RPM_REQUEST_TIMEOUT);
141 if (!left)
142 ret = -ETIMEDOUT;
143 else
144 ret = rpm->ack_status;
145
146out:
147 kfree(pkt);
148 mutex_unlock(&rpm->lock);
149 return ret;
150}
151EXPORT_SYMBOL(qcom_rpm_smd_write);
152
137 if (ret)
138 goto out;
139
140 left = wait_for_completion_timeout(&rpm->ack, RPM_REQUEST_TIMEOUT);
141 if (!left)
142 ret = -ETIMEDOUT;
143 else
144 ret = rpm->ack_status;
145
146out:
147 kfree(pkt);
148 mutex_unlock(&rpm->lock);
149 return ret;
150}
151EXPORT_SYMBOL(qcom_rpm_smd_write);
152
153static int qcom_smd_rpm_callback(struct qcom_smd_channel *channel,
154 const void *data,
155 size_t count)
153static int qcom_smd_rpm_callback(struct rpmsg_device *rpdev,
154 void *data,
155 int count,
156 void *priv,
157 u32 addr)
156{
157 const struct qcom_rpm_header *hdr = data;
158 size_t hdr_length = le32_to_cpu(hdr->length);
159 const struct qcom_rpm_message *msg;
158{
159 const struct qcom_rpm_header *hdr = data;
160 size_t hdr_length = le32_to_cpu(hdr->length);
161 const struct qcom_rpm_message *msg;
160 struct qcom_smd_rpm *rpm = qcom_smd_get_drvdata(channel);
162 struct qcom_smd_rpm *rpm = dev_get_drvdata(&rpdev->dev);
161 const u8 *buf = data + sizeof(struct qcom_rpm_header);
162 const u8 *end = buf + hdr_length;
163 char msgbuf[32];
164 int status = 0;
165 u32 len, msg_length;
166
167 if (le32_to_cpu(hdr->service_type) != RPM_SERVICE_TYPE_REQUEST ||
168 hdr_length < sizeof(struct qcom_rpm_message)) {

--- 22 unchanged lines hidden (view full) ---

191 buf = PTR_ALIGN(buf + 2 * sizeof(u32) + msg_length, 4);
192 }
193
194 rpm->ack_status = status;
195 complete(&rpm->ack);
196 return 0;
197}
198
163 const u8 *buf = data + sizeof(struct qcom_rpm_header);
164 const u8 *end = buf + hdr_length;
165 char msgbuf[32];
166 int status = 0;
167 u32 len, msg_length;
168
169 if (le32_to_cpu(hdr->service_type) != RPM_SERVICE_TYPE_REQUEST ||
170 hdr_length < sizeof(struct qcom_rpm_message)) {

--- 22 unchanged lines hidden (view full) ---

193 buf = PTR_ALIGN(buf + 2 * sizeof(u32) + msg_length, 4);
194 }
195
196 rpm->ack_status = status;
197 complete(&rpm->ack);
198 return 0;
199}
200
199static int qcom_smd_rpm_probe(struct qcom_smd_device *sdev)
201static int qcom_smd_rpm_probe(struct rpmsg_device *rpdev)
200{
201 struct qcom_smd_rpm *rpm;
202
202{
203 struct qcom_smd_rpm *rpm;
204
203 rpm = devm_kzalloc(&sdev->dev, sizeof(*rpm), GFP_KERNEL);
205 rpm = devm_kzalloc(&rpdev->dev, sizeof(*rpm), GFP_KERNEL);
204 if (!rpm)
205 return -ENOMEM;
206
207 mutex_init(&rpm->lock);
208 init_completion(&rpm->ack);
209
206 if (!rpm)
207 return -ENOMEM;
208
209 mutex_init(&rpm->lock);
210 init_completion(&rpm->ack);
211
210 rpm->dev = &sdev->dev;
211 rpm->rpm_channel = sdev->channel;
212 qcom_smd_set_drvdata(sdev->channel, rpm);
212 rpm->dev = &rpdev->dev;
213 rpm->rpm_channel = rpdev->ept;
214 dev_set_drvdata(&rpdev->dev, rpm);
213
215
214 dev_set_drvdata(&sdev->dev, rpm);
215
216 return of_platform_populate(sdev->dev.of_node, NULL, NULL, &sdev->dev);
216 return of_platform_populate(rpdev->dev.of_node, NULL, NULL, &rpdev->dev);
217}
218
217}
218
219static void qcom_smd_rpm_remove(struct qcom_smd_device *sdev)
219static void qcom_smd_rpm_remove(struct rpmsg_device *rpdev)
220{
220{
221 of_platform_depopulate(&sdev->dev);
221 of_platform_depopulate(&rpdev->dev);
222}
223
224static const struct of_device_id qcom_smd_rpm_of_match[] = {
225 { .compatible = "qcom,rpm-apq8084" },
226 { .compatible = "qcom,rpm-msm8916" },
227 { .compatible = "qcom,rpm-msm8974" },
228 {}
229};
230MODULE_DEVICE_TABLE(of, qcom_smd_rpm_of_match);
231
222}
223
224static const struct of_device_id qcom_smd_rpm_of_match[] = {
225 { .compatible = "qcom,rpm-apq8084" },
226 { .compatible = "qcom,rpm-msm8916" },
227 { .compatible = "qcom,rpm-msm8974" },
228 {}
229};
230MODULE_DEVICE_TABLE(of, qcom_smd_rpm_of_match);
231
232static struct qcom_smd_driver qcom_smd_rpm_driver = {
232static struct rpmsg_driver qcom_smd_rpm_driver = {
233 .probe = qcom_smd_rpm_probe,
234 .remove = qcom_smd_rpm_remove,
235 .callback = qcom_smd_rpm_callback,
233 .probe = qcom_smd_rpm_probe,
234 .remove = qcom_smd_rpm_remove,
235 .callback = qcom_smd_rpm_callback,
236 .driver = {
236 .drv = {
237 .name = "qcom_smd_rpm",
237 .name = "qcom_smd_rpm",
238 .owner = THIS_MODULE,
239 .of_match_table = qcom_smd_rpm_of_match,
240 },
241};
242
243static int __init qcom_smd_rpm_init(void)
244{
238 .of_match_table = qcom_smd_rpm_of_match,
239 },
240};
241
242static int __init qcom_smd_rpm_init(void)
243{
245 return qcom_smd_driver_register(&qcom_smd_rpm_driver);
244 return register_rpmsg_driver(&qcom_smd_rpm_driver);
246}
247arch_initcall(qcom_smd_rpm_init);
248
249static void __exit qcom_smd_rpm_exit(void)
250{
245}
246arch_initcall(qcom_smd_rpm_init);
247
248static void __exit qcom_smd_rpm_exit(void)
249{
251 qcom_smd_driver_unregister(&qcom_smd_rpm_driver);
250 unregister_rpmsg_driver(&qcom_smd_rpm_driver);
252}
253module_exit(qcom_smd_rpm_exit);
254
255MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
256MODULE_DESCRIPTION("Qualcomm SMD backed RPM driver");
257MODULE_LICENSE("GPL v2");
251}
252module_exit(qcom_smd_rpm_exit);
253
254MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
255MODULE_DESCRIPTION("Qualcomm SMD backed RPM driver");
256MODULE_LICENSE("GPL v2");