]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/media-cec-make-cec_get_edid_spa_location-an-inline-f.patch
autosel fixes for 4.14
[thirdparty/kernel/stable-queue.git] / queue-4.14 / media-cec-make-cec_get_edid_spa_location-an-inline-f.patch
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
5
6 [ Upstream commit b915bf575d5b7774d0f22d57d6c143e07dcaade2 ]
7
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.
11
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.
16
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>
21 ---
22 drivers/media/cec/cec-edid.c | 60 -------------------------------
23 include/media/cec.h | 70 ++++++++++++++++++++++++++++++++++++
24 2 files changed, 70 insertions(+), 60 deletions(-)
25
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
30 @@ -22,66 +22,6 @@
31 #include <linux/types.h>
32 #include <media/cec.h>
33
34 -/*
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
37 - * blocks.
38 - *
39 - * The returned location is guaranteed to be < size - 1.
40 - */
41 -static unsigned int cec_get_edid_spa_location(const u8 *edid, unsigned int size)
42 -{
43 - unsigned int blocks = size / 128;
44 - unsigned int block;
45 - u8 d;
46 -
47 - /* Sanity check: at least 2 blocks and a multiple of the block size */
48 - if (blocks < 2 || size % 128)
49 - return 0;
50 -
51 - /*
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.
57 - */
58 - if (edid[0x7e] + 1 < blocks)
59 - blocks = edid[0x7e] + 1;
60 -
61 - for (block = 1; block < blocks; block++) {
62 - unsigned int offset = block * 128;
63 -
64 - /* Skip any non-CEA-861 extension blocks */
65 - if (edid[offset] != 0x02 || edid[offset + 1] != 0x03)
66 - continue;
67 -
68 - /* search Vendor Specific Data Block (tag 3) */
69 - d = edid[offset + 2] & 0x7f;
70 - /* Check if there are Data Blocks */
71 - if (d <= 4)
72 - continue;
73 - if (d > 4) {
74 - unsigned int i = offset + 4;
75 - unsigned int end = offset + d;
76 -
77 - /* Note: 'end' is always < 'size' */
78 - do {
79 - u8 tag = edid[i] >> 5;
80 - u8 len = edid[i] & 0x1f;
81 -
82 - if (tag == 3 && len >= 5 && i + len <= end &&
83 - edid[i + 1] == 0x03 &&
84 - edid[i + 2] == 0x0c &&
85 - edid[i + 3] == 0x00)
86 - return i + 4;
87 - i += len + 1;
88 - } while (i < end);
89 - }
90 - }
91 - return 0;
92 -}
93 -
94 u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
95 unsigned int *offset)
96 {
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);
103 }
104
105 +/**
106 + * cec_get_edid_spa_location() - find location of the Source Physical Address
107 + *
108 + * @edid: the EDID
109 + * @size: the size of the EDID
110 + *
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
113 + * blocks.
114 + *
115 + * The returned location is guaranteed to be <= size-2.
116 + *
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.
120 + */
121 +static inline unsigned int cec_get_edid_spa_location(const u8 *edid,
122 + unsigned int size)
123 +{
124 + unsigned int blocks = size / 128;
125 + unsigned int block;
126 + u8 d;
127 +
128 + /* Sanity check: at least 2 blocks and a multiple of the block size */
129 + if (blocks < 2 || size % 128)
130 + return 0;
131 +
132 + /*
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.
138 + */
139 + if (edid[0x7e] + 1 < blocks)
140 + blocks = edid[0x7e] + 1;
141 +
142 + for (block = 1; block < blocks; block++) {
143 + unsigned int offset = block * 128;
144 +
145 + /* Skip any non-CEA-861 extension blocks */
146 + if (edid[offset] != 0x02 || edid[offset + 1] != 0x03)
147 + continue;
148 +
149 + /* search Vendor Specific Data Block (tag 3) */
150 + d = edid[offset + 2] & 0x7f;
151 + /* Check if there are Data Blocks */
152 + if (d <= 4)
153 + continue;
154 + if (d > 4) {
155 + unsigned int i = offset + 4;
156 + unsigned int end = offset + d;
157 +
158 + /* Note: 'end' is always < 'size' */
159 + do {
160 + u8 tag = edid[i] >> 5;
161 + u8 len = edid[i] & 0x1f;
162 +
163 + if (tag == 3 && len >= 5 && i + len <= end &&
164 + edid[i + 1] == 0x03 &&
165 + edid[i + 2] == 0x0c &&
166 + edid[i + 3] == 0x00)
167 + return i + 4;
168 + i += len + 1;
169 + } while (i < end);
170 + }
171 + }
172 + return 0;
173 +}
174 +
175 #endif /* _MEDIA_CEC_H */
176 --
177 2.20.1
178