Skip to content

Commit b915bf5

Browse files
Hans Verkuilmchehab
authored andcommitted
media: cec: make cec_get_edid_spa_location() an inline function
This function is needed by both V4L2 and CEC, so move this to cec.h as a static inline since there are no obvious shared modules between the two subsystems. This patch, together with the following ones, fixes a dependency bug: if CEC_CORE is disabled, then building adv7604 (and other HDMI receivers) will fail because an essential function is now stubbed out. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Cc: <stable@vger.kernel.org> # for v4.17 and up Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
1 parent 985cdcb commit b915bf5

2 files changed

Lines changed: 70 additions & 60 deletions

File tree

‎drivers/media/cec/cec-edid.c‎

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,6 @@
1010
#include <linux/types.h>
1111
#include <media/cec.h>
1212

13-
/*
14-
* This EDID is expected to be a CEA-861 compliant, which means that there are
15-
* at least two blocks and one or more of the extensions blocks are CEA-861
16-
* blocks.
17-
*
18-
* The returned location is guaranteed to be < size - 1.
19-
*/
20-
static unsigned int cec_get_edid_spa_location(const u8 *edid, unsigned int size)
21-
{
22-
unsigned int blocks = size / 128;
23-
unsigned int block;
24-
u8 d;
25-
26-
/* Sanity check: at least 2 blocks and a multiple of the block size */
27-
if (blocks < 2 || size % 128)
28-
return 0;
29-
30-
/*
31-
* If there are fewer extension blocks than the size, then update
32-
* 'blocks'. It is allowed to have more extension blocks than the size,
33-
* since some hardware can only read e.g. 256 bytes of the EDID, even
34-
* though more blocks are present. The first CEA-861 extension block
35-
* should normally be in block 1 anyway.
36-
*/
37-
if (edid[0x7e] + 1 < blocks)
38-
blocks = edid[0x7e] + 1;
39-
40-
for (block = 1; block < blocks; block++) {
41-
unsigned int offset = block * 128;
42-
43-
/* Skip any non-CEA-861 extension blocks */
44-
if (edid[offset] != 0x02 || edid[offset + 1] != 0x03)
45-
continue;
46-
47-
/* search Vendor Specific Data Block (tag 3) */
48-
d = edid[offset + 2] & 0x7f;
49-
/* Check if there are Data Blocks */
50-
if (d <= 4)
51-
continue;
52-
if (d > 4) {
53-
unsigned int i = offset + 4;
54-
unsigned int end = offset + d;
55-
56-
/* Note: 'end' is always < 'size' */
57-
do {
58-
u8 tag = edid[i] >> 5;
59-
u8 len = edid[i] & 0x1f;
60-
61-
if (tag == 3 && len >= 5 && i + len <= end &&
62-
edid[i + 1] == 0x03 &&
63-
edid[i + 2] == 0x0c &&
64-
edid[i + 3] == 0x00)
65-
return i + 4;
66-
i += len + 1;
67-
} while (i < end);
68-
}
69-
}
70-
return 0;
71-
}
72-
7313
u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
7414
unsigned int *offset)
7515
{

‎include/media/cec.h‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,74 @@ static inline void cec_phys_addr_invalidate(struct cec_adapter *adap)
461461
cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false);
462462
}
463463

464+
/**
465+
* cec_get_edid_spa_location() - find location of the Source Physical Address
466+
*
467+
* @edid: the EDID
468+
* @size: the size of the EDID
469+
*
470+
* This EDID is expected to be a CEA-861 compliant, which means that there are
471+
* at least two blocks and one or more of the extensions blocks are CEA-861
472+
* blocks.
473+
*
474+
* The returned location is guaranteed to be <= size-2.
475+
*
476+
* This is an inline function since it is used by both CEC and V4L2.
477+
* Ideally this would go in a module shared by both, but it is overkill to do
478+
* that for just a single function.
479+
*/
480+
static inline unsigned int cec_get_edid_spa_location(const u8 *edid,
481+
unsigned int size)
482+
{
483+
unsigned int blocks = size / 128;
484+
unsigned int block;
485+
u8 d;
486+
487+
/* Sanity check: at least 2 blocks and a multiple of the block size */
488+
if (blocks < 2 || size % 128)
489+
return 0;
490+
491+
/*
492+
* If there are fewer extension blocks than the size, then update
493+
* 'blocks'. It is allowed to have more extension blocks than the size,
494+
* since some hardware can only read e.g. 256 bytes of the EDID, even
495+
* though more blocks are present. The first CEA-861 extension block
496+
* should normally be in block 1 anyway.
497+
*/
498+
if (edid[0x7e] + 1 < blocks)
499+
blocks = edid[0x7e] + 1;
500+
501+
for (block = 1; block < blocks; block++) {
502+
unsigned int offset = block * 128;
503+
504+
/* Skip any non-CEA-861 extension blocks */
505+
if (edid[offset] != 0x02 || edid[offset + 1] != 0x03)
506+
continue;
507+
508+
/* search Vendor Specific Data Block (tag 3) */
509+
d = edid[offset + 2] & 0x7f;
510+
/* Check if there are Data Blocks */
511+
if (d <= 4)
512+
continue;
513+
if (d > 4) {
514+
unsigned int i = offset + 4;
515+
unsigned int end = offset + d;
516+
517+
/* Note: 'end' is always < 'size' */
518+
do {
519+
u8 tag = edid[i] >> 5;
520+
u8 len = edid[i] & 0x1f;
521+
522+
if (tag == 3 && len >= 5 && i + len <= end &&
523+
edid[i + 1] == 0x03 &&
524+
edid[i + 2] == 0x0c &&
525+
edid[i + 3] == 0x00)
526+
return i + 4;
527+
i += len + 1;
528+
} while (i < end);
529+
}
530+
}
531+
return 0;
532+
}
533+
464534
#endif /* _MEDIA_CEC_H */

0 commit comments

Comments
 (0)