* [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload @ 2017-07-18 11:20 Chris Zhong 2017-07-18 11:20 ` [PATCH v2 2/2] drm/rockchip: cdn-dp: send audio infoframe to sink Chris Zhong 2017-07-18 15:16 ` [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Doug Anderson 0 siblings, 2 replies; 5+ messages in thread From: Chris Zhong @ 2017-07-18 11:20 UTC (permalink / raw) To: seanpaul, dianders, briannorris Cc: linux-rockchip, mark.yao, heiko, Chris Zhong, Bartlomiej Zolnierkiewicz, Shashank Sharma, Jose Abreu, Jani Nikula, Thierry Reding, linux-fbdev, linux-kernel The DP is using the same audio infoframe payload as hdmi, per DP 1.3 spec, but it has a different header. Provide a new interface here, it just packs the payload. Signed-off-by: Chris Zhong <zyw@rock-chips.com> --- Changes in v2: None drivers/video/hdmi.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- include/linux/hdmi.h | 3 ++- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 1cf907e..e0b041e 100644 --- a/drivers/video/hdmi.c +++ b/drivers/video/hdmi.c @@ -240,6 +240,49 @@ int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame) EXPORT_SYMBOL(hdmi_audio_infoframe_init); /** + * hdmi_audio_infoframe_pack_payload() - write HDMI audio infoframe payload to + * binary buffer + * @frame: HDMI audio infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Packs the information contained in the @frame structure into a binary + * representation that can be written into the corresponding controller + * registers. + * + * Returns 0 on success or a negative error code on failure. + */ +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, + void *buffer, size_t size) +{ + unsigned char channels; + u8 *ptr = buffer; + + if (size < frame->length) + return -ENOSPC; + + memset(buffer, 0, size); + + if (frame->channels >= 2) + channels = frame->channels - 1; + else + channels = 0; + + ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); + ptr[1] = ((frame->sample_frequency & 0x7) << 2) | + (frame->sample_size & 0x3); + ptr[2] = frame->coding_type_ext & 0x1f; + ptr[3] = frame->channel_allocation; + ptr[4] = (frame->level_shift_value & 0xf) << 3; + + if (frame->downmix_inhibit) + ptr[4] |= BIT(7); + + return 0; +} +EXPORT_SYMBOL(hdmi_audio_infoframe_pack_payload); + +/** * hdmi_audio_infoframe_pack() - write HDMI audio infoframe to binary buffer * @frame: HDMI audio infoframe * @buffer: destination buffer @@ -256,22 +299,15 @@ EXPORT_SYMBOL(hdmi_audio_infoframe_init); ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, void *buffer, size_t size) { - unsigned char channels; u8 *ptr = buffer; size_t length; + int ret; length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; if (size < length) return -ENOSPC; - memset(buffer, 0, size); - - if (frame->channels >= 2) - channels = frame->channels - 1; - else - channels = 0; - ptr[0] = frame->type; ptr[1] = frame->version; ptr[2] = frame->length; @@ -279,16 +315,10 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, /* start infoframe payload */ ptr += HDMI_INFOFRAME_HEADER_SIZE; - - ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); - ptr[1] = ((frame->sample_frequency & 0x7) << 2) | - (frame->sample_size & 0x3); - ptr[2] = frame->coding_type_ext & 0x1f; - ptr[3] = frame->channel_allocation; - ptr[4] = (frame->level_shift_value & 0xf) << 3; - - if (frame->downmix_inhibit) - ptr[4] |= BIT(7); + ret = hdmi_audio_infoframe_pack_payload(frame, ptr, + size - HDMI_INFOFRAME_HEADER_SIZE); + if (ret) + return ret; hdmi_infoframe_set_checksum(buffer, length); diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h index d271ff2..d93c709 100644 --- a/include/linux/hdmi.h +++ b/include/linux/hdmi.h @@ -272,7 +272,8 @@ struct hdmi_audio_infoframe { int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame); ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, void *buffer, size_t size); - +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, + void *buffer, size_t size); enum hdmi_3d_structure { HDMI_3D_STRUCTURE_INVALID = -1, HDMI_3D_STRUCTURE_FRAME_PACKING = 0, -- 2.7.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] drm/rockchip: cdn-dp: send audio infoframe to sink 2017-07-18 11:20 [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Chris Zhong @ 2017-07-18 11:20 ` Chris Zhong 2017-07-18 15:16 ` [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Doug Anderson 1 sibling, 0 replies; 5+ messages in thread From: Chris Zhong @ 2017-07-18 11:20 UTC (permalink / raw) To: seanpaul, dianders, briannorris Cc: linux-rockchip, mark.yao, heiko, Chris Zhong, David Airlie, Daniel Vetter, Jani Nikula, dri-devel, linux-arm-kernel, linux-kernel Some DP/HDMI sink need to receive the audio infoframe to play sound, especially some multi-channel AV receiver, they need the channel_allocation from infoframe to config the speakers. Send the audio infoframe via SDP will make them work properly. Signed-off-by: Chris Zhong <zyw@rock-chips.com> --- Changes in v2: - According to the advice of Sean Paul and Doug use hdmi_audio_infoframe_pack_payload to pack the buffer define a SDP_HEADER_SIZE drivers/gpu/drm/rockchip/cdn-dp-core.c | 20 ++++++++++++++++++++ drivers/gpu/drm/rockchip/cdn-dp-reg.c | 27 +++++++++++++++++++++++++++ drivers/gpu/drm/rockchip/cdn-dp-reg.h | 6 ++++++ include/drm/drm_dp_helper.h | 1 + 4 files changed, 54 insertions(+) diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c index 9b0b058..6a4fc66 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c @@ -802,6 +802,7 @@ static int cdn_dp_audio_hw_params(struct device *dev, void *data, .sample_rate = params->sample_rate, .channels = params->channels, }; + u8 buffer[HDMI_AUDIO_INFOFRAME_SIZE + EDP_SDP_HEADER_SIZE] = { 0 }; int ret; mutex_lock(&dp->lock); @@ -823,6 +824,25 @@ static int cdn_dp_audio_hw_params(struct device *dev, void *data, goto out; } + /* + * Prepare the infoframe header to SDP header per DP 1.3 spec, Table + * 2-98. + */ + buffer[0] = 0; + buffer[1] = HDMI_INFOFRAME_TYPE_AUDIO; + buffer[2] = 0x1b; + buffer[3] = 0x48; + + ret = hdmi_audio_infoframe_pack_payload(¶ms->cea, + &buffer[EDP_SDP_HEADER_SIZE], + HDMI_AUDIO_INFOFRAME_SIZE); + if (ret < 0) { + DRM_DEV_ERROR(dev, "Failed to pack audio infoframe: %d\n", ret); + goto out; + } + + cdn_dp_sdp_write(dp, 0, buffer, sizeof(buffer)); + ret = cdn_dp_audio_config(dp, &audio); if (!ret) dp->audio_info = audio; diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.c b/drivers/gpu/drm/rockchip/cdn-dp-reg.c index b14d211..4a818e4 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.c +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.c @@ -286,6 +286,33 @@ int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value) return ret; } +void cdn_dp_sdp_write(struct cdn_dp_device *dp, int entry_id, u8 *buf, + u32 buf_len) +{ + int idx; + u32 *packet = (u32 *)buf; + u32 num_packets = buf_len / 4; + u8 type; + + if (buf_len < EDP_SDP_HEADER_SIZE) { + DRM_DEV_ERROR(dp->dev, "sdp buffer length: %d\n", buf_len); + return; + } + + type = buf[1]; + + for (idx = 0; idx < num_packets; idx++) + writel(cpu_to_le32(*packet++), dp->regs + SOURCE_PIF_DATA_WR); + + writel(entry_id, dp->regs + SOURCE_PIF_WR_ADDR); + + writel(F_HOST_WR, dp->regs + SOURCE_PIF_WR_REQ); + + writel(PIF_PKT_TYPE_VALID | F_PACKET_TYPE(type) | entry_id, + dp->regs + SOURCE_PIF_PKT_ALLOC_REG); + writel(PIF_PKT_ALLOC_WR_EN, dp->regs + SOURCE_PIF_PKT_ALLOC_WR_EN); +} + int cdn_dp_load_firmware(struct cdn_dp_device *dp, const u32 *i_mem, u32 i_size, const u32 *d_mem, u32 d_size) { diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.h b/drivers/gpu/drm/rockchip/cdn-dp-reg.h index c4bbb4a83..6ec0e81 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.h +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.h @@ -424,6 +424,11 @@ /* Reference cycles when using lane clock as reference */ #define LANE_REF_CYC 0x8000 +#define F_HOST_WR BIT(0) +#define PIF_PKT_ALLOC_WR_EN BIT(0) +#define PIF_PKT_TYPE_VALID (3 << 16) +#define F_PACKET_TYPE(x) (((x) & 0xff) << 8) + enum voltage_swing_level { VOLTAGE_LEVEL_0, VOLTAGE_LEVEL_1, @@ -478,5 +483,6 @@ int cdn_dp_set_video_status(struct cdn_dp_device *dp, int active); int cdn_dp_config_video(struct cdn_dp_device *dp); int cdn_dp_audio_stop(struct cdn_dp_device *dp, struct audio_info *audio); int cdn_dp_audio_mute(struct cdn_dp_device *dp, bool enable); +void cdn_dp_sdp_write(struct cdn_dp_device *dp, int entry_id, u8 *buf, u32 len); int cdn_dp_audio_config(struct cdn_dp_device *dp, struct audio_info *audio); #endif /* _CDN_DP_REG_H */ diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index b17476a..5d5dd07 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -878,6 +878,7 @@ struct edp_sdp_header { u8 HB3; /* 7:5 reserved, 4:0 number of valid data bytes */ } __packed; +#define EDP_SDP_HEADER_SIZE 4 #define EDP_SDP_HEADER_REVISION_MASK 0x1F #define EDP_SDP_HEADER_VALID_PAYLOAD_BYTES 0x1F -- 2.7.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload 2017-07-18 11:20 [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Chris Zhong 2017-07-18 11:20 ` [PATCH v2 2/2] drm/rockchip: cdn-dp: send audio infoframe to sink Chris Zhong @ 2017-07-18 15:16 ` Doug Anderson 2017-07-19 0:49 ` Chris Zhong 1 sibling, 1 reply; 5+ messages in thread From: Doug Anderson @ 2017-07-18 15:16 UTC (permalink / raw) To: Chris Zhong Cc: Sean Paul, Brian Norris, open list:ARM/Rockchip SoC..., Mark yao, Heiko Stübner, Bartlomiej Zolnierkiewicz, Shashank Sharma, Jose Abreu, Jani Nikula, Thierry Reding, linux-fbdev, linux-kernel Hi, On Tue, Jul 18, 2017 at 4:20 AM, Chris Zhong <zyw@rock-chips.com> wrote: > The DP is using the same audio infoframe payload as hdmi, per DP 1.3 > spec, but it has a different header. Provide a new interface here, > it just packs the payload. > > Signed-off-by: Chris Zhong <zyw@rock-chips.com> > --- > > Changes in v2: None > > drivers/video/hdmi.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- > include/linux/hdmi.h | 3 ++- > 2 files changed, 50 insertions(+), 19 deletions(-) > > diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c > index 1cf907e..e0b041e 100644 > --- a/drivers/video/hdmi.c > +++ b/drivers/video/hdmi.c > @@ -240,6 +240,49 @@ int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame) > EXPORT_SYMBOL(hdmi_audio_infoframe_init); > > /** > + * hdmi_audio_infoframe_pack_payload() - write HDMI audio infoframe payload to > + * binary buffer > + * @frame: HDMI audio infoframe > + * @buffer: destination buffer > + * @size: size of buffer > + * > + * Packs the information contained in the @frame structure into a binary > + * representation that can be written into the corresponding controller > + * registers. > + * > + * Returns 0 on success or a negative error code on failure. > + */ > +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, > + void *buffer, size_t size) > +{ > + unsigned char channels; > + u8 *ptr = buffer; > + > + if (size < frame->length) You also need to return -ENOSPC if (size < 5). That's because below you always write 5 elements into this array. I'll leave it to someone with actual DRM experience to say whether they want a #define of some sort here. Probably they do since someone made a #define for "HDMI_INFOFRAME_HEADER_SIZE". Also: you don't use frame->length anywhere in this function and it doesn't seem to be related with packing the payload. Seems like you shouldn't check it here. > + return -ENOSPC; > + > + memset(buffer, 0, size); I don't think the memset belongs here. It seems like all this function is doing is setting up ptr[0] through ptr[4] and the memset() doesn't belong with that, does it? > @@ -256,22 +299,15 @@ EXPORT_SYMBOL(hdmi_audio_infoframe_init); > ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, > void *buffer, size_t size) > { > - unsigned char channels; > u8 *ptr = buffer; > size_t length; > + int ret; > > length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; > > if (size < length) > return -ENOSPC; > > - memset(buffer, 0, size); It seems like the memset() belongs here, logically. This function deals with the whole buffer so it should be clearing it. > - > - if (frame->channels >= 2) > - channels = frame->channels - 1; > - else > - channels = 0; > - > ptr[0] = frame->type; > ptr[1] = frame->version; > ptr[2] = frame->length; > @@ -279,16 +315,10 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, > > /* start infoframe payload */ > ptr += HDMI_INFOFRAME_HEADER_SIZE; > - > - ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); > - ptr[1] = ((frame->sample_frequency & 0x7) << 2) | > - (frame->sample_size & 0x3); > - ptr[2] = frame->coding_type_ext & 0x1f; > - ptr[3] = frame->channel_allocation; > - ptr[4] = (frame->level_shift_value & 0xf) << 3; > - > - if (frame->downmix_inhibit) > - ptr[4] |= BIT(7); > + ret = hdmi_audio_infoframe_pack_payload(frame, ptr, > + size - HDMI_INFOFRAME_HEADER_SIZE); > + if (ret) > + return ret; > > hdmi_infoframe_set_checksum(buffer, length); > > diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h > index d271ff2..d93c709 100644 > --- a/include/linux/hdmi.h > +++ b/include/linux/hdmi.h > @@ -272,7 +272,8 @@ struct hdmi_audio_infoframe { > int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame); > ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, > void *buffer, size_t size); > - > +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, > + void *buffer, size_t size); nit: seems like you're changing whitespace here (there used to be a blank line before the enum). > enum hdmi_3d_structure { > HDMI_3D_STRUCTURE_INVALID = -1, > HDMI_3D_STRUCTURE_FRAME_PACKING = 0, > -- > 2.7.4 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload 2017-07-18 15:16 ` [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Doug Anderson @ 2017-07-19 0:49 ` Chris Zhong 2017-07-19 17:27 ` Doug Anderson 0 siblings, 1 reply; 5+ messages in thread From: Chris Zhong @ 2017-07-19 0:49 UTC (permalink / raw) To: Doug Anderson Cc: Sean Paul, Brian Norris, open list:ARM/Rockchip SoC..., Mark yao, Heiko Stübner, Bartlomiej Zolnierkiewicz, Shashank Sharma, Jose Abreu, Jani Nikula, Thierry Reding, linux-fbdev, linux-kernel Hi Doug On Tuesday, July 18, 2017 11:16 PM, Doug Anderson wrote: > Hi, > > On Tue, Jul 18, 2017 at 4:20 AM, Chris Zhong <zyw@rock-chips.com> wrote: >> The DP is using the same audio infoframe payload as hdmi, per DP 1.3 >> spec, but it has a different header. Provide a new interface here, >> it just packs the payload. >> >> Signed-off-by: Chris Zhong <zyw@rock-chips.com> >> --- >> >> Changes in v2: None >> >> drivers/video/hdmi.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- >> include/linux/hdmi.h | 3 ++- >> 2 files changed, 50 insertions(+), 19 deletions(-) >> >> diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c >> index 1cf907e..e0b041e 100644 >> --- a/drivers/video/hdmi.c >> +++ b/drivers/video/hdmi.c >> @@ -240,6 +240,49 @@ int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame) >> EXPORT_SYMBOL(hdmi_audio_infoframe_init); >> >> /** >> + * hdmi_audio_infoframe_pack_payload() - write HDMI audio infoframe payload to >> + * binary buffer >> + * @frame: HDMI audio infoframe >> + * @buffer: destination buffer >> + * @size: size of buffer >> + * >> + * Packs the information contained in the @frame structure into a binary >> + * representation that can be written into the corresponding controller >> + * registers. >> + * >> + * Returns 0 on success or a negative error code on failure. >> + */ >> +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, >> + void *buffer, size_t size) >> +{ >> + unsigned char channels; >> + u8 *ptr = buffer; >> + >> + if (size < frame->length) > You also need to return -ENOSPC if (size < 5). That's because below > you always write 5 elements into this array. I'll leave it to someone > with actual DRM experience to say whether they want a #define of some > sort here. Probably they do since someone made a #define for > "HDMI_INFOFRAME_HEADER_SIZE". > > Also: you don't use frame->length anywhere in this function and it > doesn't seem to be related with packing the payload. Seems like you > shouldn't check it here. Actually, I think it should be "if (size < HDMI_AUDIO_INFOFRAME_SIZE)" > > >> + return -ENOSPC; >> + >> + memset(buffer, 0, size); > I don't think the memset belongs here. It seems like all this > function is doing is setting up ptr[0] through ptr[4] and the memset() > doesn't belong with that, does it? > I think the length of payload is 10 Bytes(DB1~DB10), per audio infoframe Format, but we only use the front 5 Bytes, the back 5 bytes must be 0. If we take the 10 bytes as a whole, it make sense. >> @@ -256,22 +299,15 @@ EXPORT_SYMBOL(hdmi_audio_infoframe_init); >> ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, >> void *buffer, size_t size) >> { >> - unsigned char channels; >> u8 *ptr = buffer; >> size_t length; >> + int ret; >> >> length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; >> >> if (size < length) >> return -ENOSPC; >> >> - memset(buffer, 0, size); > It seems like the memset() belongs here, logically. This function > deals with the whole buffer so it should be clearing it. > >> - >> - if (frame->channels >= 2) >> - channels = frame->channels - 1; >> - else >> - channels = 0; >> - >> ptr[0] = frame->type; >> ptr[1] = frame->version; >> ptr[2] = frame->length; >> @@ -279,16 +315,10 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, >> >> /* start infoframe payload */ >> ptr += HDMI_INFOFRAME_HEADER_SIZE; >> - >> - ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); >> - ptr[1] = ((frame->sample_frequency & 0x7) << 2) | >> - (frame->sample_size & 0x3); >> - ptr[2] = frame->coding_type_ext & 0x1f; >> - ptr[3] = frame->channel_allocation; >> - ptr[4] = (frame->level_shift_value & 0xf) << 3; >> - >> - if (frame->downmix_inhibit) >> - ptr[4] |= BIT(7); >> + ret = hdmi_audio_infoframe_pack_payload(frame, ptr, >> + size - HDMI_INFOFRAME_HEADER_SIZE); >> + if (ret) >> + return ret; >> >> hdmi_infoframe_set_checksum(buffer, length); >> >> diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h >> index d271ff2..d93c709 100644 >> --- a/include/linux/hdmi.h >> +++ b/include/linux/hdmi.h >> @@ -272,7 +272,8 @@ struct hdmi_audio_infoframe { >> int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame); >> ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, >> void *buffer, size_t size); >> - >> +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, >> + void *buffer, size_t size); > nit: seems like you're changing whitespace here (there used to be a > blank line before the enum). > >> enum hdmi_3d_structure { >> HDMI_3D_STRUCTURE_INVALID = -1, >> HDMI_3D_STRUCTURE_FRAME_PACKING = 0, >> -- >> 2.7.4 >> > > -- Chris Zhong ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload 2017-07-19 0:49 ` Chris Zhong @ 2017-07-19 17:27 ` Doug Anderson 0 siblings, 0 replies; 5+ messages in thread From: Doug Anderson @ 2017-07-19 17:27 UTC (permalink / raw) To: Chris Zhong Cc: Sean Paul, Brian Norris, open list:ARM/Rockchip SoC..., Mark yao, Heiko Stübner, Bartlomiej Zolnierkiewicz, Shashank Sharma, Jose Abreu, Jani Nikula, Thierry Reding, linux-fbdev, linux-kernel Hi On Tue, Jul 18, 2017 at 5:49 PM, Chris Zhong <zyw@rock-chips.com> wrote: > Hi Doug > > > > On Tuesday, July 18, 2017 11:16 PM, Doug Anderson wrote: >> >> Hi, >> >> On Tue, Jul 18, 2017 at 4:20 AM, Chris Zhong <zyw@rock-chips.com> wrote: >>> >>> The DP is using the same audio infoframe payload as hdmi, per DP 1.3 >>> spec, but it has a different header. Provide a new interface here, >>> it just packs the payload. >>> >>> Signed-off-by: Chris Zhong <zyw@rock-chips.com> >>> --- >>> >>> Changes in v2: None >>> >>> drivers/video/hdmi.c | 66 >>> ++++++++++++++++++++++++++++++++++++++-------------- >>> include/linux/hdmi.h | 3 ++- >>> 2 files changed, 50 insertions(+), 19 deletions(-) >>> >>> diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c >>> index 1cf907e..e0b041e 100644 >>> --- a/drivers/video/hdmi.c >>> +++ b/drivers/video/hdmi.c >>> @@ -240,6 +240,49 @@ int hdmi_audio_infoframe_init(struct >>> hdmi_audio_infoframe *frame) >>> EXPORT_SYMBOL(hdmi_audio_infoframe_init); >>> >>> /** >>> + * hdmi_audio_infoframe_pack_payload() - write HDMI audio infoframe >>> payload to >>> + * binary buffer >>> + * @frame: HDMI audio infoframe >>> + * @buffer: destination buffer >>> + * @size: size of buffer >>> + * >>> + * Packs the information contained in the @frame structure into a binary >>> + * representation that can be written into the corresponding controller >>> + * registers. >>> + * >>> + * Returns 0 on success or a negative error code on failure. >>> + */ >>> +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe >>> *frame, >>> + void *buffer, size_t size) >>> +{ >>> + unsigned char channels; >>> + u8 *ptr = buffer; >>> + >>> + if (size < frame->length) >> >> You also need to return -ENOSPC if (size < 5). That's because below >> you always write 5 elements into this array. I'll leave it to someone >> with actual DRM experience to say whether they want a #define of some >> sort here. Probably they do since someone made a #define for >> "HDMI_INFOFRAME_HEADER_SIZE". >> >> Also: you don't use frame->length anywhere in this function and it >> doesn't seem to be related with packing the payload. Seems like you >> shouldn't check it here. > > Actually, I think it should be "if (size < HDMI_AUDIO_INFOFRAME_SIZE)" Ah, OK. My main point was that this function needed to make sense on its own. ...and the function in your patch writes to [0] through [4] without actually confirming that there are at least 5 elements. I'd be OK with: if ((size < frame->length || size < HDMI_AUDIO_INFOFRAME_SIZE) >>> + return -ENOSPC; >>> + >>> + memset(buffer, 0, size); >> >> I don't think the memset belongs here. It seems like all this >> function is doing is setting up ptr[0] through ptr[4] and the memset() >> doesn't belong with that, does it? >> > I think the length of payload is 10 Bytes(DB1~DB10), per audio infoframe > Format, > but we only use the front 5 Bytes, the back 5 bytes must be 0. If we take > the 10 > bytes as a whole, it make sense. OK, memset() here makes sense with what you say about the frame needing to be 10 bytes big. -Doug ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-07-19 17:27 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-07-18 11:20 [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Chris Zhong 2017-07-18 11:20 ` [PATCH v2 2/2] drm/rockchip: cdn-dp: send audio infoframe to sink Chris Zhong 2017-07-18 15:16 ` [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Doug Anderson 2017-07-19 0:49 ` Chris Zhong 2017-07-19 17:27 ` Doug Anderson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®