1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2023 Intel Corporation
9 #include <linux/types.h>
13 /* ELD Header Block */
14 #define DRM_ELD_HEADER_BLOCK_SIZE 4
17 # define DRM_ELD_VER_SHIFT 3
18 # define DRM_ELD_VER_MASK (0x1f << 3)
19 # define DRM_ELD_VER_CEA861D (2 << 3) /* supports 861D or below */
20 # define DRM_ELD_VER_CANNED (0x1f << 3)
22 #define DRM_ELD_BASELINE_ELD_LEN 2 /* in dwords! */
24 /* ELD Baseline Block for ELD_Ver == 2 */
25 #define DRM_ELD_CEA_EDID_VER_MNL 4
26 # define DRM_ELD_CEA_EDID_VER_SHIFT 5
27 # define DRM_ELD_CEA_EDID_VER_MASK (7 << 5)
28 # define DRM_ELD_CEA_EDID_VER_NONE (0 << 5)
29 # define DRM_ELD_CEA_EDID_VER_CEA861 (1 << 5)
30 # define DRM_ELD_CEA_EDID_VER_CEA861A (2 << 5)
31 # define DRM_ELD_CEA_EDID_VER_CEA861BCD (3 << 5)
32 # define DRM_ELD_MNL_SHIFT 0
33 # define DRM_ELD_MNL_MASK (0x1f << 0)
35 #define DRM_ELD_SAD_COUNT_CONN_TYPE 5
36 # define DRM_ELD_SAD_COUNT_SHIFT 4
37 # define DRM_ELD_SAD_COUNT_MASK (0xf << 4)
38 # define DRM_ELD_CONN_TYPE_SHIFT 2
39 # define DRM_ELD_CONN_TYPE_MASK (3 << 2)
40 # define DRM_ELD_CONN_TYPE_HDMI (0 << 2)
41 # define DRM_ELD_CONN_TYPE_DP (1 << 2)
42 # define DRM_ELD_SUPPORTS_AI (1 << 1)
43 # define DRM_ELD_SUPPORTS_HDCP (1 << 0)
45 #define DRM_ELD_AUD_SYNCH_DELAY 6 /* in units of 2 ms */
46 # define DRM_ELD_AUD_SYNCH_DELAY_MAX 0xfa /* 500 ms */
48 #define DRM_ELD_SPEAKER 7
49 # define DRM_ELD_SPEAKER_MASK 0x7f
50 # define DRM_ELD_SPEAKER_RLRC (1 << 6)
51 # define DRM_ELD_SPEAKER_FLRC (1 << 5)
52 # define DRM_ELD_SPEAKER_RC (1 << 4)
53 # define DRM_ELD_SPEAKER_RLR (1 << 3)
54 # define DRM_ELD_SPEAKER_FC (1 << 2)
55 # define DRM_ELD_SPEAKER_LFE (1 << 1)
56 # define DRM_ELD_SPEAKER_FLR (1 << 0)
58 #define DRM_ELD_PORT_ID 8 /* offsets 8..15 inclusive */
59 # define DRM_ELD_PORT_ID_LEN 8
61 #define DRM_ELD_MANUFACTURER_NAME0 16
62 #define DRM_ELD_MANUFACTURER_NAME1 17
64 #define DRM_ELD_PRODUCT_CODE0 18
65 #define DRM_ELD_PRODUCT_CODE1 19
67 #define DRM_ELD_MONITOR_NAME_STRING 20 /* offsets 20..(20+mnl-1) inclusive */
69 #define DRM_ELD_CEA_SAD(mnl, sad) (20 + (mnl) + 3 * (sad))
72 * drm_eld_mnl - Get ELD monitor name length in bytes.
73 * @eld: pointer to an eld memory structure with mnl set
75 static inline int drm_eld_mnl(const u8
*eld
)
77 return (eld
[DRM_ELD_CEA_EDID_VER_MNL
] & DRM_ELD_MNL_MASK
) >> DRM_ELD_MNL_SHIFT
;
80 int drm_eld_sad_get(const u8
*eld
, int sad_index
, struct cea_sad
*cta_sad
);
81 int drm_eld_sad_set(u8
*eld
, int sad_index
, const struct cea_sad
*cta_sad
);
84 * drm_eld_sad - Get ELD SAD structures.
85 * @eld: pointer to an eld memory structure with sad_count set
87 static inline const u8
*drm_eld_sad(const u8
*eld
)
89 unsigned int ver
, mnl
;
91 ver
= (eld
[DRM_ELD_VER
] & DRM_ELD_VER_MASK
) >> DRM_ELD_VER_SHIFT
;
92 if (ver
!= 2 && ver
!= 31)
95 mnl
= drm_eld_mnl(eld
);
99 return eld
+ DRM_ELD_CEA_SAD(mnl
, 0);
103 * drm_eld_sad_count - Get ELD SAD count.
104 * @eld: pointer to an eld memory structure with sad_count set
106 static inline int drm_eld_sad_count(const u8
*eld
)
108 return (eld
[DRM_ELD_SAD_COUNT_CONN_TYPE
] & DRM_ELD_SAD_COUNT_MASK
) >>
109 DRM_ELD_SAD_COUNT_SHIFT
;
113 * drm_eld_calc_baseline_block_size - Calculate baseline block size in bytes
114 * @eld: pointer to an eld memory structure with mnl and sad_count set
116 * This is a helper for determining the payload size of the baseline block, in
117 * bytes, for e.g. setting the Baseline_ELD_Len field in the ELD header block.
119 static inline int drm_eld_calc_baseline_block_size(const u8
*eld
)
121 return DRM_ELD_MONITOR_NAME_STRING
- DRM_ELD_HEADER_BLOCK_SIZE
+
122 drm_eld_mnl(eld
) + drm_eld_sad_count(eld
) * 3;
126 * drm_eld_size - Get ELD size in bytes
127 * @eld: pointer to a complete eld memory structure
129 * The returned value does not include the vendor block. It's vendor specific,
130 * and comprises of the remaining bytes in the ELD memory buffer after
131 * drm_eld_size() bytes of header and baseline block.
133 * The returned value is guaranteed to be a multiple of 4.
135 static inline int drm_eld_size(const u8
*eld
)
137 return DRM_ELD_HEADER_BLOCK_SIZE
+ eld
[DRM_ELD_BASELINE_ELD_LEN
] * 4;
141 * drm_eld_get_spk_alloc - Get speaker allocation
142 * @eld: pointer to an ELD memory structure
144 * The returned value is the speakers mask. User has to use %DRM_ELD_SPEAKER
145 * field definitions to identify speakers.
147 static inline u8
drm_eld_get_spk_alloc(const u8
*eld
)
149 return eld
[DRM_ELD_SPEAKER
] & DRM_ELD_SPEAKER_MASK
;
153 * drm_eld_get_conn_type - Get device type hdmi/dp connected
154 * @eld: pointer to an ELD memory structure
156 * The caller need to use %DRM_ELD_CONN_TYPE_HDMI or %DRM_ELD_CONN_TYPE_DP to
157 * identify the display type connected.
159 static inline u8
drm_eld_get_conn_type(const u8
*eld
)
161 return eld
[DRM_ELD_SAD_COUNT_CONN_TYPE
] & DRM_ELD_CONN_TYPE_MASK
;
164 #endif /* __DRM_ELD_H__ */