fsl_utils.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Freescale ALSA SoC Machine driver utility
  3. *
  4. * Author: Timur Tabi <timur@freescale.com>
  5. *
  6. * Copyright 2010 Freescale Semiconductor, Inc.
  7. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of any
  10. * kind, whether express or implied.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/of_address.h>
  14. #include <sound/soc.h>
  15. #include "fsl_utils.h"
  16. /**
  17. * fsl_asoc_get_dma_channel - determine the dma channel for a SSI node
  18. *
  19. * @ssi_np: pointer to the SSI device tree node
  20. * @name: name of the phandle pointing to the dma channel
  21. * @dai: ASoC DAI link pointer to be filled with platform_name
  22. * @dma_channel_id: dma channel id to be returned
  23. * @dma_id: dma id to be returned
  24. *
  25. * This function determines the dma and channel id for given SSI node. It
  26. * also discovers the platform_name for the ASoC DAI link.
  27. */
  28. int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
  29. const char *name,
  30. struct snd_soc_dai_link *dai,
  31. unsigned int *dma_channel_id,
  32. unsigned int *dma_id)
  33. {
  34. struct resource res;
  35. struct device_node *dma_channel_np, *dma_np;
  36. const u32 *iprop;
  37. int ret;
  38. dma_channel_np = of_parse_phandle(ssi_np, name, 0);
  39. if (!dma_channel_np)
  40. return -EINVAL;
  41. if (!of_device_is_compatible(dma_channel_np, "fsl,ssi-dma-channel")) {
  42. of_node_put(dma_channel_np);
  43. return -EINVAL;
  44. }
  45. /* Determine the dev_name for the device_node. This code mimics the
  46. * behavior of of_device_make_bus_id(). We need this because ASoC uses
  47. * the dev_name() of the device to match the platform (DMA) device with
  48. * the CPU (SSI) device. It's all ugly and hackish, but it works (for
  49. * now).
  50. *
  51. * dai->platform name should already point to an allocated buffer.
  52. */
  53. ret = of_address_to_resource(dma_channel_np, 0, &res);
  54. if (ret) {
  55. of_node_put(dma_channel_np);
  56. return ret;
  57. }
  58. snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s",
  59. (unsigned long long) res.start, dma_channel_np->name);
  60. iprop = of_get_property(dma_channel_np, "cell-index", NULL);
  61. if (!iprop) {
  62. of_node_put(dma_channel_np);
  63. return -EINVAL;
  64. }
  65. *dma_channel_id = be32_to_cpup(iprop);
  66. dma_np = of_get_parent(dma_channel_np);
  67. iprop = of_get_property(dma_np, "cell-index", NULL);
  68. if (!iprop) {
  69. of_node_put(dma_np);
  70. return -EINVAL;
  71. }
  72. *dma_id = be32_to_cpup(iprop);
  73. of_node_put(dma_np);
  74. of_node_put(dma_channel_np);
  75. return 0;
  76. }
  77. EXPORT_SYMBOL(fsl_asoc_get_dma_channel);
  78. MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
  79. MODULE_DESCRIPTION("Freescale ASoC utility code");
  80. MODULE_LICENSE("GPL v2");