2 * Remote processor messaging - sample client driver
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Copyright (C) 2011 Google, Inc.
7 * Ohad Ben-Cohen <ohad@wizery.com>
8 * Brian Swetland <swetland@google.com>
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/rpmsg.h>
24 #define MSG "hello world!"
27 static void rpmsg_sample_cb(struct rpmsg_channel
*rpdev
, void *data
, int len
,
33 dev_info(&rpdev
->dev
, "incoming msg %d (src: 0x%x)\n", ++rx_count
, src
);
35 print_hex_dump(KERN_DEBUG
, __func__
, DUMP_PREFIX_NONE
, 16, 1,
38 /* samples should not live forever */
39 if (rx_count
>= MSG_LIMIT
) {
40 dev_info(&rpdev
->dev
, "goodbye!\n");
44 /* send a new message now */
45 ret
= rpmsg_send(rpdev
, MSG
, strlen(MSG
));
47 dev_err(&rpdev
->dev
, "rpmsg_send failed: %d\n", ret
);
50 static int rpmsg_sample_probe(struct rpmsg_channel
*rpdev
)
54 dev_info(&rpdev
->dev
, "new channel: 0x%x -> 0x%x!\n",
55 rpdev
->src
, rpdev
->dst
);
57 /* send a message to our remote processor */
58 ret
= rpmsg_send(rpdev
, MSG
, strlen(MSG
));
60 dev_err(&rpdev
->dev
, "rpmsg_send failed: %d\n", ret
);
67 static void rpmsg_sample_remove(struct rpmsg_channel
*rpdev
)
69 dev_info(&rpdev
->dev
, "rpmsg sample client driver is removed\n");
72 static struct rpmsg_device_id rpmsg_driver_sample_id_table
[] = {
73 { .name
= "rpmsg-client-sample" },
76 MODULE_DEVICE_TABLE(rpmsg
, rpmsg_driver_sample_id_table
);
78 static struct rpmsg_driver rpmsg_sample_client
= {
79 .drv
.name
= KBUILD_MODNAME
,
80 .drv
.owner
= THIS_MODULE
,
81 .id_table
= rpmsg_driver_sample_id_table
,
82 .probe
= rpmsg_sample_probe
,
83 .callback
= rpmsg_sample_cb
,
84 .remove
= rpmsg_sample_remove
,
87 static int __init
rpmsg_client_sample_init(void)
89 return register_rpmsg_driver(&rpmsg_sample_client
);
91 module_init(rpmsg_client_sample_init
);
93 static void __exit
rpmsg_client_sample_fini(void)
95 unregister_rpmsg_driver(&rpmsg_sample_client
);
97 module_exit(rpmsg_client_sample_fini
);
99 MODULE_DESCRIPTION("Remote processor messaging sample client driver");
100 MODULE_LICENSE("GPL v2");