double spinlock bugfix, qos_resume: use thread instead of tasklet, priority boost
[cor.git] / samples / rpmsg / rpmsg_client_sample.c
blobae50816622839141245cc6d8e2c42a4f183402af
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Remote processor messaging - sample client driver
5 * Copyright (C) 2011 Texas Instruments, Inc.
6 * Copyright (C) 2011 Google, Inc.
8 * Ohad Ben-Cohen <ohad@wizery.com>
9 * Brian Swetland <swetland@google.com>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/rpmsg.h>
16 #define MSG "hello world!"
18 static int count = 100;
19 module_param(count, int, 0644);
21 struct instance_data {
22 int rx_count;
25 static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
26 void *priv, u32 src)
28 int ret;
29 struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
31 dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n",
32 ++idata->rx_count, src);
34 print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data, len,
35 true);
37 /* samples should not live forever */
38 if (idata->rx_count >= count) {
39 dev_info(&rpdev->dev, "goodbye!\n");
40 return 0;
43 /* send a new message now */
44 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
45 if (ret)
46 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
48 return 0;
51 static int rpmsg_sample_probe(struct rpmsg_device *rpdev)
53 int ret;
54 struct instance_data *idata;
56 dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
57 rpdev->src, rpdev->dst);
59 idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
60 if (!idata)
61 return -ENOMEM;
63 dev_set_drvdata(&rpdev->dev, idata);
65 /* send a message to our remote processor */
66 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
67 if (ret) {
68 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
69 return ret;
72 return 0;
75 static void rpmsg_sample_remove(struct rpmsg_device *rpdev)
77 dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
80 static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
81 { .name = "rpmsg-client-sample" },
82 { },
84 MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
86 static struct rpmsg_driver rpmsg_sample_client = {
87 .drv.name = KBUILD_MODNAME,
88 .id_table = rpmsg_driver_sample_id_table,
89 .probe = rpmsg_sample_probe,
90 .callback = rpmsg_sample_cb,
91 .remove = rpmsg_sample_remove,
93 module_rpmsg_driver(rpmsg_sample_client);
95 MODULE_DESCRIPTION("Remote processor messaging sample client driver");
96 MODULE_LICENSE("GPL v2");