Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 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 | |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 27 | struct instance_data { |
| 28 | int rx_count; |
| 29 | }; |
| 30 | |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 31 | 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] | 32 | void *priv, u32 src) |
| 33 | { |
| 34 | int ret; |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 35 | struct instance_data *idata = dev_get_drvdata(&rpdev->dev); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 36 | |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 37 | dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", |
| 38 | ++idata->rx_count, src); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 39 | |
| 40 | print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1, |
| 41 | data, len, true); |
| 42 | |
| 43 | /* samples should not live forever */ |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 44 | if (idata->rx_count >= MSG_LIMIT) { |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 45 | dev_info(&rpdev->dev, "goodbye!\n"); |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 46 | return 0; |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* send a new message now */ |
Bjorn Andersson | 2a48d73 | 2016-09-01 15:27:55 -0700 | [diff] [blame] | 50 | ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG)); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 51 | if (ret) |
| 52 | dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 53 | |
| 54 | return 0; |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 57 | static int rpmsg_sample_probe(struct rpmsg_device *rpdev) |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 58 | { |
| 59 | int ret; |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 60 | struct instance_data *idata; |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 61 | |
| 62 | dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n", |
| 63 | rpdev->src, rpdev->dst); |
| 64 | |
Anna, Suman | a138c88 | 2016-08-12 18:42:28 -0500 | [diff] [blame] | 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 | |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 71 | /* send a message to our remote processor */ |
Bjorn Andersson | 2a48d73 | 2016-09-01 15:27:55 -0700 | [diff] [blame] | 72 | ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG)); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 73 | if (ret) { |
| 74 | dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 81 | static void rpmsg_sample_remove(struct rpmsg_device *rpdev) |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 82 | { |
| 83 | dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n"); |
| 84 | } |
| 85 | |
| 86 | static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = { |
| 87 | { .name = "rpmsg-client-sample" }, |
| 88 | { }, |
| 89 | }; |
| 90 | MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table); |
| 91 | |
| 92 | static struct rpmsg_driver rpmsg_sample_client = { |
| 93 | .drv.name = KBUILD_MODNAME, |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 94 | .id_table = rpmsg_driver_sample_id_table, |
| 95 | .probe = rpmsg_sample_probe, |
| 96 | .callback = rpmsg_sample_cb, |
Greg Kroah-Hartman | 6ae1417 | 2012-12-21 15:16:45 -0800 | [diff] [blame] | 97 | .remove = rpmsg_sample_remove, |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 98 | }; |
Andrew F. Davis | b4f7825 | 2016-05-04 17:01:39 -0500 | [diff] [blame] | 99 | module_rpmsg_driver(rpmsg_sample_client); |
Ohad Ben-Cohen | 779b96d | 2011-10-20 21:41:24 +0200 | [diff] [blame] | 100 | |
| 101 | MODULE_DESCRIPTION("Remote processor messaging sample client driver"); |
| 102 | MODULE_LICENSE("GPL v2"); |