diff options
author | Jani Nikula <jani.nikula@intel.com> | 2022-05-03 12:23:50 +0300 |
---|---|---|
committer | Jani Nikula <jani.nikula@intel.com> | 2022-05-05 20:16:44 +0300 |
commit | 94afc5382669c3a201c5817c47b57a879b6dabce (patch) | |
tree | e6e8e0841683fc125cea488cc6d54547d26c875f /drivers/gpu/drm/drm_edid.c | |
parent | 9d72b7e2d2ce3746950929a2c54171d183ea89f2 (diff) | |
download | linux-94afc5382669c3a201c5817c47b57a879b6dabce.tar.xz |
drm/edid: add iterator for EDID base and extension blocks
Add an iterator abstraction for going through all the EDID blocks.
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/ce02778b353b906c928268de9d7569d493a9be5d.1651569697.git.jani.nikula@intel.com
Diffstat (limited to 'drivers/gpu/drm/drm_edid.c')
-rw-r--r-- | drivers/gpu/drm/drm_edid.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 67eaa01f1d7c..6d71b2b77639 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1599,6 +1599,54 @@ static const void *edid_extension_block_data(const struct edid *edid, int index) return edid_block_data(edid, index + 1); } +/* + * EDID base and extension block iterator. + * + * struct drm_edid_iter iter; + * const u8 *block; + * + * drm_edid_iter_begin(edid, &iter); + * drm_edid_iter_for_each(block, &iter) { + * // do stuff with block + * } + * drm_edid_iter_end(&iter); + */ +struct drm_edid_iter { + const struct edid *edid; + + /* Current block index. */ + int index; +}; + +static void drm_edid_iter_begin(const struct edid *edid, + struct drm_edid_iter *iter) +{ + memset(iter, 0, sizeof(*iter)); + + iter->edid = edid; +} + +static const void *__drm_edid_iter_next(struct drm_edid_iter *iter) +{ + const void *block = NULL; + + if (!iter->edid) + return NULL; + + if (iter->index < edid_block_count(iter->edid)) + block = edid_block_data(iter->edid, iter->index++); + + return block; +} + +#define drm_edid_iter_for_each(__block, __iter) \ + while (((__block) = __drm_edid_iter_next(__iter))) + +static void drm_edid_iter_end(struct drm_edid_iter *iter) +{ + memset(iter, 0, sizeof(*iter)); +} + static const u8 edid_header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; |