1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/rpmsg.h>
23
24#define MSG "hello world!"
25#define MSG_LIMIT 100
26
27struct instance_data {
28 int rx_count;
29};
30
31static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
32 void *priv, u32 src)
33{
34 int ret;
35 struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
36
37 dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n",
38 ++idata->rx_count, src);
39
40 print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
41 data, len, true);
42
43
44 if (idata->rx_count >= MSG_LIMIT) {
45 dev_info(&rpdev->dev, "goodbye!\n");
46 return 0;
47 }
48
49
50 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
51 if (ret)
52 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
53
54 return 0;
55}
56
57static int rpmsg_sample_probe(struct rpmsg_device *rpdev)
58{
59 int ret;
60 struct instance_data *idata;
61
62 dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
63 rpdev->src, rpdev->dst);
64
65 idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
66 if (!idata)
67 return -ENOMEM;
68
69 dev_set_drvdata(&rpdev->dev, idata);
70
71
72 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
73 if (ret) {
74 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
75 return ret;
76 }
77
78 return 0;
79}
80
81static void rpmsg_sample_remove(struct rpmsg_device *rpdev)
82{
83 dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
84}
85
86static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
87 { .name = "rpmsg-client-sample" },
88 { },
89};
90MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
91
92static struct rpmsg_driver rpmsg_sample_client = {
93 .drv.name = KBUILD_MODNAME,
94 .id_table = rpmsg_driver_sample_id_table,
95 .probe = rpmsg_sample_probe,
96 .callback = rpmsg_sample_cb,
97 .remove = rpmsg_sample_remove,
98};
99module_rpmsg_driver(rpmsg_sample_client);
100
101MODULE_DESCRIPTION("Remote processor messaging sample client driver");
102MODULE_LICENSE("GPL v2");
103