diff options
author | Ohad Ben-Cohen <ohad@wizery.com> | 2011-10-20 15:41:24 -0400 |
---|---|---|
committer | Ohad Ben-Cohen <ohad@wizery.com> | 2012-02-08 15:54:05 -0500 |
commit | 779b96d20ca97cfa19162b340bff0c27b405b4b2 (patch) | |
tree | 4f371baad4fcde0c4ae2050535174ab632b411f5 | |
parent | bcabbccabffe7326f046f25737ba1084f463c65c (diff) |
samples/rpmsg: add an rpmsg driver sample
Add an rpmsg driver sample, which demonstrates how to communicate with
an AMP-configured remote processor over the rpmsg bus.
Note how once probed, the driver can immediately start sending messages
using the rpmsg_send() API, without having to worry about creating endpoints
or allocating rpmsg addresses: all that work is done by the rpmsg bus,
and the required information is already embedded in the rpmsg channel
that the driver is probed with.
In this sample, the driver simply sends a "Hello World!" message to the remote
processor repeatedly.
Designed with Brian Swetland <swetland@google.com>.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Cc: Brian Swetland <swetland@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg KH <greg@kroah.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r-- | samples/Kconfig | 8 | ||||
-rw-r--r-- | samples/Makefile | 2 | ||||
-rw-r--r-- | samples/rpmsg/Makefile | 1 | ||||
-rw-r--r-- | samples/rpmsg/rpmsg_client_sample.c | 100 |
4 files changed, 110 insertions, 1 deletions
diff --git a/samples/Kconfig b/samples/Kconfig index 41063e7592d2..7b6792a18c05 100644 --- a/samples/Kconfig +++ b/samples/Kconfig | |||
@@ -61,4 +61,12 @@ config SAMPLE_KDB | |||
61 | Build an example of how to dynamically add the hello | 61 | Build an example of how to dynamically add the hello |
62 | command to the kdb shell. | 62 | command to the kdb shell. |
63 | 63 | ||
64 | config SAMPLE_RPMSG_CLIENT | ||
65 | tristate "Build rpmsg client sample -- loadable modules only" | ||
66 | depends on RPMSG && m | ||
67 | help | ||
68 | Build an rpmsg client sample driver, which demonstrates how | ||
69 | to communicate with an AMP-configured remote processor over | ||
70 | the rpmsg bus. | ||
71 | |||
64 | endif # SAMPLES | 72 | endif # SAMPLES |
diff --git a/samples/Makefile b/samples/Makefile index 6280817c2b7e..2f75851ec629 100644 --- a/samples/Makefile +++ b/samples/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # Makefile for Linux samples code | 1 | # Makefile for Linux samples code |
2 | 2 | ||
3 | obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ tracepoints/ trace_events/ \ | 3 | obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ tracepoints/ trace_events/ \ |
4 | hw_breakpoint/ kfifo/ kdb/ hidraw/ | 4 | hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ |
diff --git a/samples/rpmsg/Makefile b/samples/rpmsg/Makefile new file mode 100644 index 000000000000..2d4973c69663 --- /dev/null +++ b/samples/rpmsg/Makefile | |||
@@ -0,0 +1 @@ | |||
obj-$(CONFIG_SAMPLE_RPMSG_CLIENT) += rpmsg_client_sample.o | |||
diff --git a/samples/rpmsg/rpmsg_client_sample.c b/samples/rpmsg/rpmsg_client_sample.c new file mode 100644 index 000000000000..23ea9f2ae11d --- /dev/null +++ b/samples/rpmsg/rpmsg_client_sample.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Remote processor messaging - sample client driver | ||
3 | * | ||
4 | * Copyright (C) 2011 Texas Instruments, Inc. | ||
5 | * Copyright (C) 2011 Google, Inc. | ||
6 | * | ||
7 | * Ohad Ben-Cohen <ohad@wizery.com> | ||
8 | * Brian Swetland <swetland@google.com> | ||
9 | * | ||
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. | ||
13 | * | ||
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. | ||
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 | |||
27 | static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len, | ||
28 | void *priv, u32 src) | ||
29 | { | ||
30 | int ret; | ||
31 | static int rx_count; | ||
32 | |||
33 | dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", ++rx_count, src); | ||
34 | |||
35 | print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1, | ||
36 | data, len, true); | ||
37 | |||
38 | /* samples should not live forever */ | ||
39 | if (rx_count >= MSG_LIMIT) { | ||
40 | dev_info(&rpdev->dev, "goodbye!\n"); | ||
41 | return; | ||
42 | } | ||
43 | |||
44 | /* send a new message now */ | ||
45 | ret = rpmsg_send(rpdev, MSG, strlen(MSG)); | ||
46 | if (ret) | ||
47 | dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); | ||
48 | } | ||
49 | |||
50 | static int rpmsg_sample_probe(struct rpmsg_channel *rpdev) | ||
51 | { | ||
52 | int ret; | ||
53 | |||
54 | dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n", | ||
55 | rpdev->src, rpdev->dst); | ||
56 | |||
57 | /* send a message to our remote processor */ | ||
58 | ret = rpmsg_send(rpdev, MSG, strlen(MSG)); | ||
59 | if (ret) { | ||
60 | dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | static void __devexit rpmsg_sample_remove(struct rpmsg_channel *rpdev) | ||
68 | { | ||
69 | dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n"); | ||
70 | } | ||
71 | |||
72 | static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = { | ||
73 | { .name = "rpmsg-client-sample" }, | ||
74 | { }, | ||
75 | }; | ||
76 | MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table); | ||
77 | |||
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 = __devexit_p(rpmsg_sample_remove), | ||
85 | }; | ||
86 | |||
87 | static int __init rpmsg_client_sample_init(void) | ||
88 | { | ||
89 | return register_rpmsg_driver(&rpmsg_sample_client); | ||
90 | } | ||
91 | module_init(rpmsg_client_sample_init); | ||
92 | |||
93 | static void __exit rpmsg_client_sample_fini(void) | ||
94 | { | ||
95 | unregister_rpmsg_driver(&rpmsg_sample_client); | ||
96 | } | ||
97 | module_exit(rpmsg_client_sample_fini); | ||
98 | |||
99 | MODULE_DESCRIPTION("Remote processor messaging sample client driver"); | ||
100 | MODULE_LICENSE("GPL v2"); | ||