rpmsg_client_sample.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #define MSG_LIMIT 100
  24. static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
  25. void *priv, u32 src)
  26. {
  27. int ret;
  28. static int rx_count;
  29. dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", ++rx_count, src);
  30. print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
  31. data, len, true);
  32. /* samples should not live forever */
  33. if (rx_count >= MSG_LIMIT) {
  34. dev_info(&rpdev->dev, "goodbye!\n");
  35. return;
  36. }
  37. /* send a new message now */
  38. ret = rpmsg_send(rpdev, MSG, strlen(MSG));
  39. if (ret)
  40. dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
  41. }
  42. static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
  43. {
  44. int ret;
  45. dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
  46. rpdev->src, rpdev->dst);
  47. /* send a message to our remote processor */
  48. ret = rpmsg_send(rpdev, MSG, strlen(MSG));
  49. if (ret) {
  50. dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
  51. return ret;
  52. }
  53. return 0;
  54. }
  55. static void __devexit rpmsg_sample_remove(struct rpmsg_channel *rpdev)
  56. {
  57. dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
  58. }
  59. static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
  60. { .name = "rpmsg-client-sample" },
  61. { },
  62. };
  63. MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
  64. static struct rpmsg_driver rpmsg_sample_client = {
  65. .drv.name = KBUILD_MODNAME,
  66. .drv.owner = THIS_MODULE,
  67. .id_table = rpmsg_driver_sample_id_table,
  68. .probe = rpmsg_sample_probe,
  69. .callback = rpmsg_sample_cb,
  70. .remove = __devexit_p(rpmsg_sample_remove),
  71. };
  72. static int __init rpmsg_client_sample_init(void)
  73. {
  74. return register_rpmsg_driver(&rpmsg_sample_client);
  75. }
  76. module_init(rpmsg_client_sample_init);
  77. static void __exit rpmsg_client_sample_fini(void)
  78. {
  79. unregister_rpmsg_driver(&rpmsg_sample_client);
  80. }
  81. module_exit(rpmsg_client_sample_fini);
  82. MODULE_DESCRIPTION("Remote processor messaging sample client driver");
  83. MODULE_LICENSE("GPL v2");