blob: 4fc733c8c570e3fa74fb17916996dbb64341283d [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Jyri Sarha09184112016-03-31 16:36:00 +03002/*
3 * hdmi-codec.h - HDMI Codec driver API
4 *
Alexander A. Klimov7ed33ea2020-07-19 17:17:05 +02005 * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com
Jyri Sarha09184112016-03-31 16:36:00 +03006 *
7 * Author: Jyri Sarha <jsarha@ti.com>
Jyri Sarha09184112016-03-31 16:36:00 +03008 */
9
10#ifndef __HDMI_CODEC_H__
11#define __HDMI_CODEC_H__
12
Kuninori Morimoto96203fb2017-05-18 01:40:20 +000013#include <linux/of_graph.h>
Jyri Sarha09184112016-03-31 16:36:00 +030014#include <linux/hdmi.h>
15#include <drm/drm_edid.h>
16#include <sound/asoundef.h>
Kuninori Morimoto96203fb2017-05-18 01:40:20 +000017#include <sound/soc.h>
Jyri Sarha09184112016-03-31 16:36:00 +030018#include <uapi/sound/asound.h>
19
20/*
21 * Protocol between ASoC cpu-dai and HDMI-encoder
22 */
23struct hdmi_codec_daifmt {
24 enum {
25 HDMI_I2S,
26 HDMI_RIGHT_J,
27 HDMI_LEFT_J,
28 HDMI_DSP_A,
29 HDMI_DSP_B,
30 HDMI_AC97,
31 HDMI_SPDIF,
32 } fmt;
Takashi Sakamoto9e4d59a2016-12-16 18:26:54 +090033 unsigned int bit_clk_inv:1;
34 unsigned int frame_clk_inv:1;
35 unsigned int bit_clk_master:1;
36 unsigned int frame_clk_master:1;
Sia Jee Heng28785f52021-02-04 09:42:55 +080037 /* bit_fmt could be standard PCM format or
38 * IEC958 encoded format. ALSA IEC958 plugin will pass
39 * IEC958_SUBFRAME format to the underneath driver.
40 */
41 snd_pcm_format_t bit_fmt;
Jyri Sarha09184112016-03-31 16:36:00 +030042};
43
44/*
45 * HDMI audio parameters
46 */
47struct hdmi_codec_params {
48 struct hdmi_audio_infoframe cea;
49 struct snd_aes_iec958 iec;
50 int sample_rate;
51 int sample_width;
52 int channels;
53};
54
Cheng-Yi Chiang6fa59632019-07-17 16:33:23 +080055typedef void (*hdmi_codec_plugged_cb)(struct device *dev,
56 bool plugged);
57
Kuninori Morimotoefc91942016-06-24 02:47:55 +000058struct hdmi_codec_pdata;
Jyri Sarha09184112016-03-31 16:36:00 +030059struct hdmi_codec_ops {
60 /*
61 * Called when ASoC starts an audio stream setup.
62 * Optional
63 */
Kuninori Morimotoefc91942016-06-24 02:47:55 +000064 int (*audio_startup)(struct device *dev, void *data);
Jyri Sarha09184112016-03-31 16:36:00 +030065
66 /*
67 * Configures HDMI-encoder for audio stream.
Maxime Ripard2fef64e2021-05-25 15:23:47 +020068 * Having either prepare or hw_params is mandatory.
Jyri Sarha09184112016-03-31 16:36:00 +030069 */
Kuninori Morimotoefc91942016-06-24 02:47:55 +000070 int (*hw_params)(struct device *dev, void *data,
Jyri Sarha09184112016-03-31 16:36:00 +030071 struct hdmi_codec_daifmt *fmt,
72 struct hdmi_codec_params *hparms);
73
74 /*
Maxime Ripard2fef64e2021-05-25 15:23:47 +020075 * Configures HDMI-encoder for audio stream. Can be called
76 * multiple times for each setup.
77 *
78 * Having either prepare or hw_params is mandatory.
79 */
80 int (*prepare)(struct device *dev, void *data,
81 struct hdmi_codec_daifmt *fmt,
82 struct hdmi_codec_params *hparms);
83
84 /*
Jyri Sarha09184112016-03-31 16:36:00 +030085 * Shuts down the audio stream.
86 * Mandatory
87 */
Kuninori Morimotoefc91942016-06-24 02:47:55 +000088 void (*audio_shutdown)(struct device *dev, void *data);
Jyri Sarha09184112016-03-31 16:36:00 +030089
90 /*
91 * Mute/unmute HDMI audio stream.
92 * Optional
93 */
Kuninori Morimotod7897102020-07-09 10:55:45 +090094 int (*mute_stream)(struct device *dev, void *data,
95 bool enable, int direction);
Jyri Sarha09184112016-03-31 16:36:00 +030096
97 /*
98 * Provides EDID-Like-Data from connected HDMI device.
99 * Optional
100 */
Kuninori Morimotoefc91942016-06-24 02:47:55 +0000101 int (*get_eld)(struct device *dev, void *data,
102 uint8_t *buf, size_t len);
Kuninori Morimoto96203fb2017-05-18 01:40:20 +0000103
104 /*
105 * Getting DAI ID
106 * Optional
107 */
108 int (*get_dai_id)(struct snd_soc_component *comment,
109 struct device_node *endpoint);
Cheng-Yi Chiang6fa59632019-07-17 16:33:23 +0800110
111 /*
112 * Hook callback function to handle connector plug event.
113 * Optional
114 */
115 int (*hook_plugged_cb)(struct device *dev, void *data,
116 hdmi_codec_plugged_cb fn,
117 struct device *codec_dev);
Kuninori Morimotod7897102020-07-09 10:55:45 +0900118
119 /* bit field */
120 unsigned int no_capture_mute:1;
Jyri Sarha09184112016-03-31 16:36:00 +0300121};
122
123/* HDMI codec initalization data */
124struct hdmi_codec_pdata {
125 const struct hdmi_codec_ops *ops;
126 uint i2s:1;
127 uint spdif:1;
128 int max_i2s_channels;
Kuninori Morimotoefc91942016-06-24 02:47:55 +0000129 void *data;
Jyri Sarha09184112016-03-31 16:36:00 +0300130};
131
Cheng-Yi Chiang6fa59632019-07-17 16:33:23 +0800132struct snd_soc_component;
133struct snd_soc_jack;
134
Jyri Sarha09184112016-03-31 16:36:00 +0300135#define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
136
137#endif /* __HDMI_CODEC_H__ */