1 From 9853c7e97d70f17fe1d77f52c7a69757701aa780 Mon Sep 17 00:00:00 2001
2 From: Hans Verkuil <hans.verkuil@cisco.com>
3 Date: Thu, 13 Sep 2018 03:25:59 -0400
4 Subject: media: cec: make cec_get_edid_spa_location() an inline function
6 [ Upstream commit b915bf575d5b7774d0f22d57d6c143e07dcaade2 ]
8 This function is needed by both V4L2 and CEC, so move this to
9 cec.h as a static inline since there are no obvious shared
10 modules between the two subsystems.
12 This patch, together with the following ones, fixes a
13 dependency bug: if CEC_CORE is disabled, then building adv7604
14 (and other HDMI receivers) will fail because an essential
15 function is now stubbed out.
17 Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
18 Cc: <stable@vger.kernel.org> # for v4.17 and up
19 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
20 Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
22 drivers/media/cec/cec-edid.c | 60 -------------------------------
23 include/media/cec.h | 70 ++++++++++++++++++++++++++++++++++++
24 2 files changed, 70 insertions(+), 60 deletions(-)
26 diff --git a/drivers/media/cec/cec-edid.c b/drivers/media/cec/cec-edid.c
27 index 38e3fec6152b5..19a31d4c86035 100644
28 --- a/drivers/media/cec/cec-edid.c
29 +++ b/drivers/media/cec/cec-edid.c
31 #include <linux/types.h>
32 #include <media/cec.h>
35 - * This EDID is expected to be a CEA-861 compliant, which means that there are
36 - * at least two blocks and one or more of the extensions blocks are CEA-861
39 - * The returned location is guaranteed to be < size - 1.
41 -static unsigned int cec_get_edid_spa_location(const u8 *edid, unsigned int size)
43 - unsigned int blocks = size / 128;
47 - /* Sanity check: at least 2 blocks and a multiple of the block size */
48 - if (blocks < 2 || size % 128)
52 - * If there are fewer extension blocks than the size, then update
53 - * 'blocks'. It is allowed to have more extension blocks than the size,
54 - * since some hardware can only read e.g. 256 bytes of the EDID, even
55 - * though more blocks are present. The first CEA-861 extension block
56 - * should normally be in block 1 anyway.
58 - if (edid[0x7e] + 1 < blocks)
59 - blocks = edid[0x7e] + 1;
61 - for (block = 1; block < blocks; block++) {
62 - unsigned int offset = block * 128;
64 - /* Skip any non-CEA-861 extension blocks */
65 - if (edid[offset] != 0x02 || edid[offset + 1] != 0x03)
68 - /* search Vendor Specific Data Block (tag 3) */
69 - d = edid[offset + 2] & 0x7f;
70 - /* Check if there are Data Blocks */
74 - unsigned int i = offset + 4;
75 - unsigned int end = offset + d;
77 - /* Note: 'end' is always < 'size' */
79 - u8 tag = edid[i] >> 5;
80 - u8 len = edid[i] & 0x1f;
82 - if (tag == 3 && len >= 5 && i + len <= end &&
83 - edid[i + 1] == 0x03 &&
84 - edid[i + 2] == 0x0c &&
85 - edid[i + 3] == 0x00)
94 u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
97 diff --git a/include/media/cec.h b/include/media/cec.h
98 index df6b3bd312849..b7339cc6fd3d6 100644
99 --- a/include/media/cec.h
100 +++ b/include/media/cec.h
101 @@ -435,4 +435,74 @@ static inline void cec_phys_addr_invalidate(struct cec_adapter *adap)
102 cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false);
106 + * cec_get_edid_spa_location() - find location of the Source Physical Address
109 + * @size: the size of the EDID
111 + * This EDID is expected to be a CEA-861 compliant, which means that there are
112 + * at least two blocks and one or more of the extensions blocks are CEA-861
115 + * The returned location is guaranteed to be <= size-2.
117 + * This is an inline function since it is used by both CEC and V4L2.
118 + * Ideally this would go in a module shared by both, but it is overkill to do
119 + * that for just a single function.
121 +static inline unsigned int cec_get_edid_spa_location(const u8 *edid,
124 + unsigned int blocks = size / 128;
125 + unsigned int block;
128 + /* Sanity check: at least 2 blocks and a multiple of the block size */
129 + if (blocks < 2 || size % 128)
133 + * If there are fewer extension blocks than the size, then update
134 + * 'blocks'. It is allowed to have more extension blocks than the size,
135 + * since some hardware can only read e.g. 256 bytes of the EDID, even
136 + * though more blocks are present. The first CEA-861 extension block
137 + * should normally be in block 1 anyway.
139 + if (edid[0x7e] + 1 < blocks)
140 + blocks = edid[0x7e] + 1;
142 + for (block = 1; block < blocks; block++) {
143 + unsigned int offset = block * 128;
145 + /* Skip any non-CEA-861 extension blocks */
146 + if (edid[offset] != 0x02 || edid[offset + 1] != 0x03)
149 + /* search Vendor Specific Data Block (tag 3) */
150 + d = edid[offset + 2] & 0x7f;
151 + /* Check if there are Data Blocks */
155 + unsigned int i = offset + 4;
156 + unsigned int end = offset + d;
158 + /* Note: 'end' is always < 'size' */
160 + u8 tag = edid[i] >> 5;
161 + u8 len = edid[i] & 0x1f;
163 + if (tag == 3 && len >= 5 && i + len <= end &&
164 + edid[i + 1] == 0x03 &&
165 + edid[i + 2] == 0x0c &&
166 + edid[i + 3] == 0x00)
175 #endif /* _MEDIA_CEC_H */