Commit 8af46811 authored by Jani Nikula's avatar Jani Nikula

drm/edid: add helpers to get/set struct cea_sad from/to 3-byte sad

Add helpers to pack/unpack SADs. Both ways and non-static, as follow-up
work needs them.

v2: Add include to get the declarations

Cc: Mitul Golani <mitulkumar.ajitkumar.golani@intel.com>
Reviewed-by: default avatarMitul Golani <mitulkumar.ajitkumar.golani@intel.com>
Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/21d657ca854ce26423b461c0bb71e7a0727ba437.1698747331.git.jani.nikula@intel.com
parent e8d0b2c0
......@@ -46,6 +46,7 @@
#include <drm/drm_print.h>
#include "drm_crtc_internal.h"
#include "drm_internal.h"
static int oui(u8 first, u8 second, u8 third)
{
......@@ -5507,6 +5508,27 @@ static void clear_eld(struct drm_connector *connector)
connector->audio_latency[1] = 0;
}
/*
* Get 3-byte SAD buffer from struct cea_sad.
*/
void drm_edid_cta_sad_get(const struct cea_sad *cta_sad, u8 *sad)
{
sad[0] = cta_sad->format << 3 | cta_sad->channels;
sad[1] = cta_sad->freq;
sad[2] = cta_sad->byte2;
}
/*
* Set struct cea_sad from 3-byte SAD buffer.
*/
void drm_edid_cta_sad_set(struct cea_sad *cta_sad, const u8 *sad)
{
cta_sad->format = (sad[0] & 0x78) >> 3;
cta_sad->channels = sad[0] & 0x07;
cta_sad->freq = sad[1] & 0x7f;
cta_sad->byte2 = sad[2];
}
/*
* drm_edid_to_eld - build ELD from EDID
* @connector: connector corresponding to the HDMI/DP sink
......@@ -5601,21 +5623,15 @@ static int _drm_edid_to_sad(const struct drm_edid *drm_edid,
cea_db_iter_for_each(db, &iter) {
if (cea_db_tag(db) == CTA_DB_AUDIO) {
struct cea_sad *sads;
int j;
int i;
count = cea_db_payload_len(db) / 3; /* SAD is 3B */
sads = kcalloc(count, sizeof(*sads), GFP_KERNEL);
*psads = sads;
if (!sads)
return -ENOMEM;
for (j = 0; j < count; j++) {
const u8 *sad = &db->data[j * 3];
sads[j].format = (sad[0] & 0x78) >> 3;
sads[j].channels = sad[0] & 0x7;
sads[j].freq = sad[1] & 0x7F;
sads[j].byte2 = sad[2];
}
for (i = 0; i < count; i++)
drm_edid_cta_sad_set(&sads[i], &db->data[i * 3]);
break;
}
}
......
......@@ -22,6 +22,7 @@
*/
#include <linux/kthread.h>
#include <linux/types.h>
#include <drm/drm_ioctl.h>
#include <drm/drm_vblank.h>
......@@ -31,6 +32,7 @@
#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
struct cea_sad;
struct dentry;
struct dma_buf;
struct iosys_map;
......@@ -267,3 +269,7 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
const struct drm_framebuffer *fb);
void drm_framebuffer_debugfs_init(struct drm_device *dev);
/* drm_edid.c */
void drm_edid_cta_sad_get(const struct cea_sad *cta_sad, u8 *sad);
void drm_edid_cta_sad_set(struct cea_sad *cta_sad, const u8 *sad);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment