0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/kernel.h>
0013 #include <linux/module.h>
0014 #include <linux/rpmsg.h>
0015
0016 #define MSG "hello world!"
0017
0018 static int count = 100;
0019 module_param(count, int, 0644);
0020
0021 struct instance_data {
0022 int rx_count;
0023 };
0024
0025 static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
0026 void *priv, u32 src)
0027 {
0028 int ret;
0029 struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
0030
0031 dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n",
0032 ++idata->rx_count, src);
0033
0034 print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data, len,
0035 true);
0036
0037
0038 if (idata->rx_count >= count) {
0039 dev_info(&rpdev->dev, "goodbye!\n");
0040 return 0;
0041 }
0042
0043
0044 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
0045 if (ret)
0046 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
0047
0048 return 0;
0049 }
0050
0051 static int rpmsg_sample_probe(struct rpmsg_device *rpdev)
0052 {
0053 int ret;
0054 struct instance_data *idata;
0055
0056 dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
0057 rpdev->src, rpdev->dst);
0058
0059 idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
0060 if (!idata)
0061 return -ENOMEM;
0062
0063 dev_set_drvdata(&rpdev->dev, idata);
0064
0065
0066 ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
0067 if (ret) {
0068 dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
0069 return ret;
0070 }
0071
0072 return 0;
0073 }
0074
0075 static void rpmsg_sample_remove(struct rpmsg_device *rpdev)
0076 {
0077 dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
0078 }
0079
0080 static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
0081 { .name = "rpmsg-client-sample" },
0082 { },
0083 };
0084 MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
0085
0086 static struct rpmsg_driver rpmsg_sample_client = {
0087 .drv.name = KBUILD_MODNAME,
0088 .id_table = rpmsg_driver_sample_id_table,
0089 .probe = rpmsg_sample_probe,
0090 .callback = rpmsg_sample_cb,
0091 .remove = rpmsg_sample_remove,
0092 };
0093 module_rpmsg_driver(rpmsg_sample_client);
0094
0095 MODULE_DESCRIPTION("Remote processor messaging sample client driver");
0096 MODULE_LICENSE("GPL v2");