Thomas Gleixner | 9c92ab6 | 2019-05-29 07:17:56 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 2 | /* |
| 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-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/rpmsg.h> |
| 15 | |
| 16 | #define MSG "hello world!" |
Suman Anna | 9a703eb | 2019-08-09 11:27:10 -0500 | [diff] [blame] | 17 | |
| 18 | static int count = 100; |
| 19 | module_param(count, int, 0644); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 20 | |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 21 | struct instance_data { |
| 22 | int rx_count; |
| 23 | }; |
| 24 | |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 25 | static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len, |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 26 | void *priv, u32 src) |
| 27 | { |
| 28 | int ret; |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 29 | struct instance_data *idata = dev_get_drvdata(&rpdev->dev); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 30 | |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 31 | dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", |
| 32 | ++idata->rx_count, src); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 33 | |
Suman Anna | 2519fbb | 2019-08-09 11:27:09 -0500 | [diff] [blame] | 34 | print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data, len, |
| 35 | true); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 36 | |
| 37 | /* samples should not live forever */ |
Suman Anna | 9a703eb | 2019-08-09 11:27:10 -0500 | [diff] [blame] | 38 | if (idata->rx_count >= count) { |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 39 | dev_info(&rpdev->dev, "goodbye!\n"); |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 40 | return 0; |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /* send a new message now */ |
Bjorn Andersson | 2a48d73 | 2016-09-01 15:27:55 -0700 | [diff] [blame] | 44 | ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG)); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 45 | if (ret) |
| 46 | dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 47 | |
| 48 | return 0; |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 51 | static int rpmsg_sample_probe(struct rpmsg_device *rpdev) |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 52 | { |
| 53 | int ret; |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 54 | struct instance_data *idata; |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 55 | |
| 56 | dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n", |
| 57 | rpdev->src, rpdev->dst); |
| 58 | |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 59 | 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-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 65 | /* send a message to our remote processor */ |
Bjorn Andersson | 2a48d73 | 2016-09-01 15:27:55 -0700 | [diff] [blame] | 66 | ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG)); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 67 | if (ret) { |
| 68 | dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 75 | static void rpmsg_sample_remove(struct rpmsg_device *rpdev) |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 76 | { |
| 77 | dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n"); |
| 78 | } |
| 79 | |
| 80 | static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = { |
| 81 | { .name = "rpmsg-client-sample" }, |
| 82 | { }, |
| 83 | }; |
| 84 | MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table); |
| 85 | |
| 86 | static struct rpmsg_driver rpmsg_sample_client = { |
| 87 | .drv.name = KBUILD_MODNAME, |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 88 | .id_table = rpmsg_driver_sample_id_table, |
| 89 | .probe = rpmsg_sample_probe, |
| 90 | .callback = rpmsg_sample_cb, |
Greg Kroah-Hartman | 6ae1417 | 2012-12-21 15:16:45 -0800 | [diff] [blame] | 91 | .remove = rpmsg_sample_remove, |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 92 | }; |
Andrew F. Davis | b4f78259 | 2016-05-04 17:01:39 -0500 | [diff] [blame] | 93 | module_rpmsg_driver(rpmsg_sample_client); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 94 | |
| 95 | MODULE_DESCRIPTION("Remote processor messaging sample client driver"); |
| 96 | MODULE_LICENSE("GPL v2"); |