caif_shm_u5500.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
  4. * Author: Amarnath Revanna / amarnath.bangalore.revanna@stericsson.com
  5. * License terms: GNU General Public License (GPL) version 2
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ":" fmt
  8. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/netdevice.h>
  11. #include <mach/mbox-db5500.h>
  12. #include <net/caif/caif_shm.h>
  13. MODULE_LICENSE("GPL");
  14. MODULE_DESCRIPTION("CAIF Shared Memory protocol driver");
  15. #define MAX_SHM_INSTANCES 1
  16. enum {
  17. MBX_ACC0,
  18. MBX_ACC1,
  19. MBX_DSP
  20. };
  21. static struct shmdev_layer shmdev_lyr[MAX_SHM_INSTANCES];
  22. static unsigned int shm_start;
  23. static unsigned int shm_size;
  24. module_param(shm_size, uint , 0440);
  25. MODULE_PARM_DESC(shm_total_size, "Start of SHM shared memory");
  26. module_param(shm_start, uint , 0440);
  27. MODULE_PARM_DESC(shm_total_start, "Total Size of SHM shared memory");
  28. static int shmdev_send_msg(u32 dev_id, u32 mbx_msg)
  29. {
  30. /* Always block until msg is written successfully */
  31. mbox_send(shmdev_lyr[dev_id].hmbx, mbx_msg, true);
  32. return 0;
  33. }
  34. static int shmdev_mbx_setup(void *pshmdrv_cb, struct shmdev_layer *pshm_dev,
  35. void *pshm_drv)
  36. {
  37. /*
  38. * For UX5500, we have only 1 SHM instance which uses MBX0
  39. * for communication with the peer modem
  40. */
  41. pshm_dev->hmbx = mbox_setup(MBX_ACC0, pshmdrv_cb, pshm_drv);
  42. if (!pshm_dev->hmbx)
  43. return -ENODEV;
  44. else
  45. return 0;
  46. }
  47. static int __init caif_shmdev_init(void)
  48. {
  49. int i, result;
  50. /* Loop is currently overkill, there is only one instance */
  51. for (i = 0; i < MAX_SHM_INSTANCES; i++) {
  52. shmdev_lyr[i].shm_base_addr = shm_start;
  53. shmdev_lyr[i].shm_total_sz = shm_size;
  54. if (((char *)shmdev_lyr[i].shm_base_addr == NULL)
  55. || (shmdev_lyr[i].shm_total_sz <= 0)) {
  56. pr_warn("ERROR,"
  57. "Shared memory Address and/or Size incorrect"
  58. ", Bailing out ...\n");
  59. result = -EINVAL;
  60. goto clean;
  61. }
  62. pr_info("SHM AREA (instance %d) STARTS"
  63. " AT %p\n", i, (char *)shmdev_lyr[i].shm_base_addr);
  64. shmdev_lyr[i].shm_id = i;
  65. shmdev_lyr[i].pshmdev_mbxsend = shmdev_send_msg;
  66. shmdev_lyr[i].pshmdev_mbxsetup = shmdev_mbx_setup;
  67. /*
  68. * Finally, CAIF core module is called with details in place:
  69. * 1. SHM base address
  70. * 2. SHM size
  71. * 3. MBX handle
  72. */
  73. result = caif_shmcore_probe(&shmdev_lyr[i]);
  74. if (result) {
  75. pr_warn("ERROR[%d],"
  76. "Could not probe SHM core (instance %d)"
  77. " Bailing out ...\n", result, i);
  78. goto clean;
  79. }
  80. }
  81. return 0;
  82. clean:
  83. /*
  84. * For now, we assume that even if one instance of SHM fails, we bail
  85. * out of the driver support completely. For this, we need to release
  86. * any memory allocated and unregister any instance of SHM net device.
  87. */
  88. for (i = 0; i < MAX_SHM_INSTANCES; i++) {
  89. if (shmdev_lyr[i].pshm_netdev)
  90. unregister_netdev(shmdev_lyr[i].pshm_netdev);
  91. }
  92. return result;
  93. }
  94. static void __exit caif_shmdev_exit(void)
  95. {
  96. int i;
  97. for (i = 0; i < MAX_SHM_INSTANCES; i++) {
  98. caif_shmcore_remove(shmdev_lyr[i].pshm_netdev);
  99. kfree((void *)shmdev_lyr[i].shm_base_addr);
  100. }
  101. }
  102. module_init(caif_shmdev_init);
  103. module_exit(caif_shmdev_exit);