blob: ae50816622839141245cc6d8e2c42a4f183402af [file] [log] [blame]
Thomas Gleixner9c92ab62019-05-29 07:17:56 -07001// SPDX-License-Identifier: GPL-2.0-only
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +02002/*
3 * Remote processor messaging - sample client driver
4 *
5 * Copyright (C) 2011 Texas Instruments, Inc.
6 * Copyright (C) 2011 Google, Inc.
7 *
8 * Ohad Ben-Cohen <ohad@wizery.com>
9 * Brian Swetland <swetland@google.com>
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020010 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/rpmsg.h>
15
16#define MSG "hello world!"
Suman Anna9a703eb2019-08-09 11:27:10 -050017
18static int count = 100;
19module_param(count, int, 0644);
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020020
Anna, Sumana138c882016-08-12 18:42:28 -050021struct instance_data {
22 int rx_count;
23};
24
Bjorn Andersson4b83c522016-09-01 15:28:08 -070025static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020026 void *priv, u32 src)
27{
28 int ret;
Anna, Sumana138c882016-08-12 18:42:28 -050029 struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020030
Anna, Sumana138c882016-08-12 18:42:28 -050031 dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n",
32 ++idata->rx_count, src);
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020033
Suman Anna2519fbb2019-08-09 11:27:09 -050034 print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data, len,
35 true);
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020036
37 /* samples should not live forever */
Suman Anna9a703eb2019-08-09 11:27:10 -050038 if (idata->rx_count >= count) {
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020039 dev_info(&rpdev->dev, "goodbye!\n");
Bjorn Andersson4b83c522016-09-01 15:28:08 -070040 return 0;
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020041 }
42
43 /* send a new message now */
Bjorn Andersson2a48d732016-09-01 15:27:55 -070044 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020045 if (ret)
46 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
Bjorn Andersson4b83c522016-09-01 15:28:08 -070047
48 return 0;
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020049}
50
Bjorn Andersson92e1de52016-09-01 15:27:57 -070051static int rpmsg_sample_probe(struct rpmsg_device *rpdev)
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020052{
53 int ret;
Anna, Sumana138c882016-08-12 18:42:28 -050054 struct instance_data *idata;
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020055
56 dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
57 rpdev->src, rpdev->dst);
58
Anna, Sumana138c882016-08-12 18:42:28 -050059 idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
60 if (!idata)
61 return -ENOMEM;
62
63 dev_set_drvdata(&rpdev->dev, idata);
64
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020065 /* send a message to our remote processor */
Bjorn Andersson2a48d732016-09-01 15:27:55 -070066 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020067 if (ret) {
68 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
69 return ret;
70 }
71
72 return 0;
73}
74
Bjorn Andersson92e1de52016-09-01 15:27:57 -070075static void rpmsg_sample_remove(struct rpmsg_device *rpdev)
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020076{
77 dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
78}
79
80static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
81 { .name = "rpmsg-client-sample" },
82 { },
83};
84MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
85
86static struct rpmsg_driver rpmsg_sample_client = {
87 .drv.name = KBUILD_MODNAME,
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020088 .id_table = rpmsg_driver_sample_id_table,
89 .probe = rpmsg_sample_probe,
90 .callback = rpmsg_sample_cb,
Greg Kroah-Hartman6ae14172012-12-21 15:16:45 -080091 .remove = rpmsg_sample_remove,
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020092};
Andrew F. Davisb4f782592016-05-04 17:01:39 -050093module_rpmsg_driver(rpmsg_sample_client);
Ohad Ben-Cohen779b96d2011-10-20 21:41:24 +020094
95MODULE_DESCRIPTION("Remote processor messaging sample client driver");
96MODULE_LICENSE("GPL v2");