/drivers/staging/tidspbridge/rmgr/dspdrv.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 144 lines · 79 code · 18 blank · 47 comment · 19 complexity · f209326b142ceb1e85d454a3810fa06b MD5 · raw file

  1. /*
  2. * dspdrv.c
  3. *
  4. * DSP-BIOS Bridge driver support functions for TI OMAP processors.
  5. *
  6. * Interface to allocate and free bridge resources.
  7. *
  8. * Copyright (C) 2005-2006 Texas Instruments, Inc.
  9. *
  10. * This package is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17. */
  18. /* ----------------------------------- Host OS */
  19. #include <linux/types.h>
  20. #include <dspbridge/host_os.h>
  21. /* ----------------------------------- DSP/BIOS Bridge */
  22. #include <dspbridge/dbdefs.h>
  23. /* ----------------------------------- Trace & Debug */
  24. #include <dspbridge/dbc.h>
  25. /* ----------------------------------- Platform Manager */
  26. #include <dspbridge/drv.h>
  27. #include <dspbridge/dev.h>
  28. #include <dspbridge/dspapi.h>
  29. /* ----------------------------------- Resource Manager */
  30. #include <dspbridge/mgr.h>
  31. /* ----------------------------------- This */
  32. #include <dspbridge/dspdrv.h>
  33. /*
  34. * ======== dsp_init ========
  35. * Allocates bridge resources. Loads a base image onto DSP, if specified.
  36. */
  37. u32 dsp_init(u32 *init_status)
  38. {
  39. char dev_node[MAXREGPATHLENGTH] = "TIOMAP1510";
  40. int status = -EPERM;
  41. struct drv_object *drv_obj = NULL;
  42. u32 device_node;
  43. u32 device_node_string;
  44. if (!api_init())
  45. goto func_cont;
  46. status = drv_create(&drv_obj);
  47. if (status) {
  48. api_exit();
  49. goto func_cont;
  50. }
  51. /* End drv_create */
  52. /* Request Resources */
  53. status = drv_request_resources((u32) &dev_node, &device_node_string);
  54. if (!status) {
  55. /* Attempt to Start the Device */
  56. status = dev_start_device((struct cfg_devnode *)
  57. device_node_string);
  58. if (status)
  59. (void)drv_release_resources
  60. ((u32) device_node_string, drv_obj);
  61. } else {
  62. dev_dbg(bridge, "%s: drv_request_resources Failed\n", __func__);
  63. status = -EPERM;
  64. }
  65. /* Unwind whatever was loaded */
  66. if (status) {
  67. /* irrespective of the status of dev_remove_device we conitinue
  68. * unloading. Get the Driver Object iterate through and remove.
  69. * Reset the status to E_FAIL to avoid going through
  70. * api_init_complete2. */
  71. for (device_node = drv_get_first_dev_extension();
  72. device_node != 0;
  73. device_node = drv_get_next_dev_extension(device_node)) {
  74. (void)dev_remove_device((struct cfg_devnode *)
  75. device_node);
  76. (void)drv_release_resources((u32) device_node, drv_obj);
  77. }
  78. /* Remove the Driver Object */
  79. (void)drv_destroy(drv_obj);
  80. drv_obj = NULL;
  81. api_exit();
  82. dev_dbg(bridge, "%s: Logical device failed init\n", __func__);
  83. } /* Unwinding the loaded drivers */
  84. func_cont:
  85. /* Attempt to Start the Board */
  86. if (!status) {
  87. /* BRD_AutoStart could fail if the dsp execuetable is not the
  88. * correct one. We should not propagate that error
  89. * into the device loader. */
  90. (void)api_init_complete2();
  91. } else {
  92. dev_dbg(bridge, "%s: Failed\n", __func__);
  93. } /* End api_init_complete2 */
  94. DBC_ENSURE((!status && drv_obj != NULL) ||
  95. (status && drv_obj == NULL));
  96. *init_status = status;
  97. /* Return the Driver Object */
  98. return (u32) drv_obj;
  99. }
  100. /*
  101. * ======== dsp_deinit ========
  102. * Frees the resources allocated for bridge.
  103. */
  104. bool dsp_deinit(u32 device_context)
  105. {
  106. bool ret = true;
  107. u32 device_node;
  108. struct mgr_object *mgr_obj = NULL;
  109. struct drv_data *drv_datap = dev_get_drvdata(bridge);
  110. while ((device_node = drv_get_first_dev_extension()) != 0) {
  111. (void)dev_remove_device((struct cfg_devnode *)device_node);
  112. (void)drv_release_resources((u32) device_node,
  113. (struct drv_object *)device_context);
  114. }
  115. (void)drv_destroy((struct drv_object *)device_context);
  116. /* Get the Manager Object from driver data
  117. * MGR Destroy will unload the DCD dll */
  118. if (drv_datap && drv_datap->mgr_object) {
  119. mgr_obj = drv_datap->mgr_object;
  120. (void)mgr_destroy(mgr_obj);
  121. } else {
  122. pr_err("%s: Failed to retrieve the object handle\n", __func__);
  123. }
  124. api_exit();
  125. return ret;
  126. }