^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * hdmi-codec.h - HDMI Codec driver API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Jyri Sarha <jsarha@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef __HDMI_CODEC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define __HDMI_CODEC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/of_graph.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/hdmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <drm/drm_edid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <sound/asoundef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <uapi/sound/asound.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Protocol between ASoC cpu-dai and HDMI-encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct hdmi_codec_daifmt {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) HDMI_I2S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) HDMI_RIGHT_J,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) HDMI_LEFT_J,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) HDMI_DSP_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) HDMI_DSP_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) HDMI_AC97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) HDMI_SPDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) } fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned int bit_clk_inv:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned int frame_clk_inv:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int bit_clk_master:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned int frame_clk_master:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* bit_fmt could be standard PCM format or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * IEC958 encoded format. ALSA IEC958 plugin will pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * IEC958_SUBFRAME format to the underneath driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) snd_pcm_format_t bit_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * HDMI audio parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct hdmi_codec_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct hdmi_audio_infoframe cea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct snd_aes_iec958 iec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int sample_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int sample_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) typedef void (*hdmi_codec_plugged_cb)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) bool plugged);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct hdmi_codec_pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct hdmi_codec_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Called when ASoC starts an audio stream setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Optional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int (*audio_startup)(struct device *dev, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * Configures HDMI-encoder for audio stream.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Having either prepare or hw_params is mandatory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int (*hw_params)(struct device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct hdmi_codec_daifmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct hdmi_codec_params *hparms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * Configures HDMI-encoder for audio stream. Can be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * multiple times for each setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Having either prepare or hw_params is mandatory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int (*prepare)(struct device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct hdmi_codec_daifmt *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct hdmi_codec_params *hparms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * Shuts down the audio stream.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Mandatory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void (*audio_shutdown)(struct device *dev, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Mute/unmute HDMI audio stream.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * Optional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int (*mute_stream)(struct device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) bool enable, int direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Provides EDID-Like-Data from connected HDMI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * Optional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int (*get_eld)(struct device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) uint8_t *buf, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * Getting DAI ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * Optional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int (*get_dai_id)(struct snd_soc_component *comment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct device_node *endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * Hook callback function to handle connector plug event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Optional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int (*hook_plugged_cb)(struct device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) hdmi_codec_plugged_cb fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct device *codec_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* bit field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int no_capture_mute:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* HDMI codec initalization data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct hdmi_codec_pdata {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) const struct hdmi_codec_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) uint i2s:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) uint spdif:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int max_i2s_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct snd_soc_component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct snd_soc_jack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif /* __HDMI_CODEC_H__ */