rpmsg_client_sample.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/rpmsg.h>
  22. #define MSG "hello world!"
  23. static int count = 100;
  24. module_param(count, int, 0644);
  25. struct instance_data {
  26. int rx_count;
  27. };
  28. static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
  29. void *priv, u32 src)
  30. {
  31. int ret;
  32. struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
  33. dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n",
  34. ++idata->rx_count, src);
  35. print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data, len,
  36. true);
  37. /* samples should not live forever */
  38. if (idata->rx_count >= count) {
  39. dev_info(&rpdev->dev, "goodbye!\n");
  40. return 0;
  41. }
  42. /* send a new message now */
  43. ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
  44. if (ret)
  45. dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
  46. return 0;
  47. }
  48. static int rpmsg_sample_probe(struct rpmsg_device *rpdev)
  49. {
  50. int ret;
  51. struct instance_data *idata;
  52. dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
  53. rpdev->src, rpdev->dst);
  54. idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
  55. if (!idata)
  56. return -ENOMEM;
  57. dev_set_drvdata(&rpdev->dev, idata);
  58. /* send a message to our remote processor */
  59. ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
  60. if (ret) {
  61. dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
  62. return ret;
  63. }
  64. return 0;
  65. }
  66. static void rpmsg_sample_remove(struct rpmsg_device *rpdev)
  67. {
  68. dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
  69. }
  70. static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
  71. { .name = "rpmsg-client-sample" },
  72. { .name = "ti.ipc4.ping-pong" },
  73. { },
  74. };
  75. MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
  76. static struct rpmsg_driver rpmsg_sample_client = {
  77. .drv.name = KBUILD_MODNAME,
  78. .id_table = rpmsg_driver_sample_id_table,
  79. .probe = rpmsg_sample_probe,
  80. .callback = rpmsg_sample_cb,
  81. .remove = rpmsg_sample_remove,
  82. };
  83. module_rpmsg_driver(rpmsg_sample_client);
  84. MODULE_DESCRIPTION("Remote processor messaging sample client driver");
  85. MODULE_LICENSE("GPL v2");