dw-hdmi-i2s-audio.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * dw-hdmi-i2s-audio.c
  3. *
  4. * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <drm/bridge/dw_hdmi.h>
  11. #include <sound/hdmi-codec.h>
  12. #include "dw-hdmi.h"
  13. #include "dw-hdmi-audio.h"
  14. #define DRIVER_NAME "dw-hdmi-i2s-audio"
  15. static inline void hdmi_write(struct dw_hdmi_i2s_audio_data *audio,
  16. u8 val, int offset)
  17. {
  18. struct dw_hdmi *hdmi = audio->hdmi;
  19. audio->write(hdmi, val, offset);
  20. }
  21. static inline u8 hdmi_read(struct dw_hdmi_i2s_audio_data *audio, int offset)
  22. {
  23. struct dw_hdmi *hdmi = audio->hdmi;
  24. return audio->read(hdmi, offset);
  25. }
  26. static int dw_hdmi_i2s_hw_params(struct device *dev, void *data,
  27. struct hdmi_codec_daifmt *fmt,
  28. struct hdmi_codec_params *hparms)
  29. {
  30. struct dw_hdmi_i2s_audio_data *audio = data;
  31. struct dw_hdmi *hdmi = audio->hdmi;
  32. u8 conf0 = 0;
  33. u8 conf1 = 0;
  34. u8 inputclkfs = 0;
  35. /* it cares I2S only */
  36. if ((fmt->fmt != HDMI_I2S) ||
  37. (fmt->bit_clk_master | fmt->frame_clk_master)) {
  38. dev_err(dev, "unsupported format/settings\n");
  39. return -EINVAL;
  40. }
  41. inputclkfs = HDMI_AUD_INPUTCLKFS_64FS;
  42. conf0 = HDMI_AUD_CONF0_I2S_ALL_ENABLE;
  43. switch (hparms->sample_width) {
  44. case 16:
  45. conf1 = HDMI_AUD_CONF1_WIDTH_16;
  46. break;
  47. case 24:
  48. case 32:
  49. conf1 = HDMI_AUD_CONF1_WIDTH_24;
  50. break;
  51. }
  52. dw_hdmi_set_sample_rate(hdmi, hparms->sample_rate);
  53. hdmi_write(audio, inputclkfs, HDMI_AUD_INPUTCLKFS);
  54. hdmi_write(audio, conf0, HDMI_AUD_CONF0);
  55. hdmi_write(audio, conf1, HDMI_AUD_CONF1);
  56. dw_hdmi_audio_enable(hdmi);
  57. return 0;
  58. }
  59. static void dw_hdmi_i2s_audio_shutdown(struct device *dev, void *data)
  60. {
  61. struct dw_hdmi_i2s_audio_data *audio = data;
  62. struct dw_hdmi *hdmi = audio->hdmi;
  63. dw_hdmi_audio_disable(hdmi);
  64. hdmi_write(audio, HDMI_AUD_CONF0_SW_RESET, HDMI_AUD_CONF0);
  65. }
  66. static struct hdmi_codec_ops dw_hdmi_i2s_ops = {
  67. .hw_params = dw_hdmi_i2s_hw_params,
  68. .audio_shutdown = dw_hdmi_i2s_audio_shutdown,
  69. };
  70. static int snd_dw_hdmi_probe(struct platform_device *pdev)
  71. {
  72. struct dw_hdmi_i2s_audio_data *audio = pdev->dev.platform_data;
  73. struct platform_device_info pdevinfo;
  74. struct hdmi_codec_pdata pdata;
  75. struct platform_device *platform;
  76. pdata.ops = &dw_hdmi_i2s_ops;
  77. pdata.i2s = 1;
  78. pdata.max_i2s_channels = 6;
  79. pdata.data = audio;
  80. memset(&pdevinfo, 0, sizeof(pdevinfo));
  81. pdevinfo.parent = pdev->dev.parent;
  82. pdevinfo.id = PLATFORM_DEVID_AUTO;
  83. pdevinfo.name = HDMI_CODEC_DRV_NAME;
  84. pdevinfo.data = &pdata;
  85. pdevinfo.size_data = sizeof(pdata);
  86. pdevinfo.dma_mask = DMA_BIT_MASK(32);
  87. platform = platform_device_register_full(&pdevinfo);
  88. if (IS_ERR(platform))
  89. return PTR_ERR(platform);
  90. dev_set_drvdata(&pdev->dev, platform);
  91. return 0;
  92. }
  93. static int snd_dw_hdmi_remove(struct platform_device *pdev)
  94. {
  95. struct platform_device *platform = dev_get_drvdata(&pdev->dev);
  96. platform_device_unregister(platform);
  97. return 0;
  98. }
  99. static struct platform_driver snd_dw_hdmi_driver = {
  100. .probe = snd_dw_hdmi_probe,
  101. .remove = snd_dw_hdmi_remove,
  102. .driver = {
  103. .name = DRIVER_NAME,
  104. .owner = THIS_MODULE,
  105. },
  106. };
  107. module_platform_driver(snd_dw_hdmi_driver);
  108. MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
  109. MODULE_DESCRIPTION("Synopsis Designware HDMI I2S ALSA SoC interface");
  110. MODULE_LICENSE("GPL v2");
  111. MODULE_ALIAS("platform:" DRIVER_NAME);