Received: by 10.223.164.202 with SMTP id h10csp4532684wrb; Wed, 29 Nov 2017 07:49:36 -0800 (PST) X-Google-Smtp-Source: AGs4zMaawPC1CDkrJqTzcFzO4wvOmjotwptagRlt3n1Q8D9V/2VUhb4j9zlUSRUJg6EiXfZCpmIx X-Received: by 10.98.12.211 with SMTP id 80mr3375598pfm.169.1511970576846; Wed, 29 Nov 2017 07:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511970576; cv=none; d=google.com; s=arc-20160816; b=KWL9bhKutNWBvJgE3HnHS2wcp4S9BTAZTW8cFtGYTEeymPT2H5RMUFioYzkV7dzOfH 8iwqU2XGWVl+n4Y//dOwYK1LCeE7E2OIro2J06hVGfEh57KD1GTGDh4byjcC3Wd5kUkN C+T+SU73HkFVPGrY9WoqMRRaQENQotSkaXCbZBK66Gu6Z9fQ7PNYTlsE40apwB8/bv77 d8sdD0vo9F+bRbxs7LCE4yT8uBa2v3nfhM7/5GkWMfOfIuKKPdlf0tesvBxTcECtQFqC GG6B59OmxTzVuhupPd3ZECdCR8v+0DqvsFAiNkLo2CMIBxSwv4McZt3WGQpGL1ZC63ud wtCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=YrGpdFkRBTYc7ZnG2h6l8lQbgX40IZvXPLBHEnMMtQQ=; b=Q/wRJ3+bTtZ9jCZWUUn9Uthppf3m4ELyX5Cr/0mFQUeNu/M2ro+UI+mpZIbRd1fEwq FpwrAVVz1GcfYcdLEnJ3wpKq+0Sz6kwehF+Z7t+aVb8Vv+HLcplyuR/zcN49sa2WHhgb RdPKnfMRw3e2+1sdhr70ehGGUWVOWuKm1TOEZHvN2mpTpZRR8pISUjA3s5GcTPaHcXnz ocwRUwEQ9sN6kJ3LhkmuLwf+TWSRZNgVCYhB+98cbWvig/DEaJO1nXfyhoaKaRayRN7c 8QME+uboYuwfEBOrVKa9W19Z7q9umjl6FeD8PDSyN5eqjhGLQi14jVgltNXHFnNGohS+ iXog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=wdG9yKPe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a7si1410822pgc.357.2017.11.29.07.49.26; Wed, 29 Nov 2017 07:49:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=wdG9yKPe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933525AbdK2PrT (ORCPT + 69 others); Wed, 29 Nov 2017 10:47:19 -0500 Received: from mail-wr0-f170.google.com ([209.85.128.170]:33103 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933511AbdK2PrQ (ORCPT ); Wed, 29 Nov 2017 10:47:16 -0500 Received: by mail-wr0-f170.google.com with SMTP id v22so3826624wrb.0 for ; Wed, 29 Nov 2017 07:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=YrGpdFkRBTYc7ZnG2h6l8lQbgX40IZvXPLBHEnMMtQQ=; b=wdG9yKPe7znYwU/UxWMX2I8WxPsRAEEyZYZYs9jcwxu+VsnM+sajItnZgt9FpQz0Qt VtN1qtZn2WdUl1vq9Mu2P43vHzd7Lf2+tWVY3Lr45Fn55kZZFWbmGuUKyYY/MhQ+hgxW CxpxrXNcYasMITVpNVAWLNS63iPXK9SIJktb6Ptqutw6m9zytdN3esRhkVtA3K3WHjlh ihAMlbE8AIAppXvamqQz5HcJ9wgMkkwK151xkEMqBrbij7EjK10/T2RczWaitWBMz5ky hDP1A90nLYQ3v7xIHqFWaz3X907LyFAEcr/MOv2coHAUeTUo8Pp2spr5W0EXkn6Ru5YF /tJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=YrGpdFkRBTYc7ZnG2h6l8lQbgX40IZvXPLBHEnMMtQQ=; b=qAM6YSoLLXQsDr4IfA1jyBs1rmbmarNakcQGTqpyXQK4WJc9M9xexWXyT1GErZtzUI Eto5YaKGLNQU12U0Ofmer8r5FM8M6dfNXb1wVVphYn92ZoTs0oR7nl7qm53aUAD77Udq x0z9TEa+Lf6NwOj6s6rYlV2z+51hnVuXmKaKPZbev5oltT1gvUQFJCj82F8Ej5GHWBHa JNk/V1MnSttwok+YyfoTsovyGB7vBDNwB97IGXS6yOnTEdWK/PhMoLaXYEcYo3ZaWN6Q JYbLqQvKr/6fzmGqe0k4ZG8gBEQKeEOXWyEh05leV1GiFaE/XflOClp7Dl48hB/HT0dY 6FNg== X-Gm-Message-State: AJaThX4olANvWkBQYBzFMepc2AOSEbYvilJMu77vQnwGqCwKEietn1Bw 0zTZuPtF7TwZzIBEaq0m2mrFkIoljkdqvMBmrXv1qg== X-Received: by 10.223.165.89 with SMTP id j25mr2958317wrb.206.1511970434508; Wed, 29 Nov 2017 07:47:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.16.198 with HTTP; Wed, 29 Nov 2017 07:47:13 -0800 (PST) In-Reply-To: <0f5227cb-913b-1d55-0b1a-5c41d68f5bf9@xs4all.nl> References: <1510253136-14153-1-git-send-email-tharvey@gateworks.com> <1510253136-14153-4-git-send-email-tharvey@gateworks.com> <4048cb21-c65c-6282-a1d7-81ad9a0d7cfa@xs4all.nl> <0f5227cb-913b-1d55-0b1a-5c41d68f5bf9@xs4all.nl> From: Tim Harvey Date: Wed, 29 Nov 2017 07:47:13 -0800 Message-ID: Subject: Re: [PATCH 3/5] media: i2c: Add TDA1997x HDMI receiver driver To: Hans Verkuil Cc: linux-media , alsa-devel@alsa-project.org, "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Shawn Guo , Steve Longerbeam , Philipp Zabel , Hans Verkuil , Mauro Carvalho Chehab Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 23, 2017 at 12:08 AM, Hans Verkuil wrote: > On 11/23/2017 05:27 AM, Tim Harvey wrote: >> On Mon, Nov 20, 2017 at 7:39 AM, Hans Verkuil wrote: >>> Hi Tim, >>> >>> Some more review comments: >>> >>> On 11/09/2017 07:45 PM, Tim Harvey wrote: >>>> Add support for the TDA1997x HDMI receivers. >> >>>> + */ >>>> +struct color_matrix_coefs { >>>> + const char *name; >>>> + /* Input offsets */ >>>> + s16 offint1; >>>> + s16 offint2; >>>> + s16 offint3; >>>> + /* Coeficients */ >>>> + s16 p11coef; >>>> + s16 p12coef; >>>> + s16 p13coef; >>>> + s16 p21coef; >>>> + s16 p22coef; >>>> + s16 p23coef; >>>> + s16 p31coef; >>>> + s16 p32coef; >>>> + s16 p33coef; >>>> + /* Output offsets */ >>>> + s16 offout1; >>>> + s16 offout2; >>>> + s16 offout3; >>>> +}; >>>> + >>>> +enum { >>>> + ITU709_RGBLIMITED, >>>> + ITU709_RGBFULL, >>>> + ITU601_RGBLIMITED, >>>> + ITU601_RGBFULL, >>>> + RGBLIMITED_RGBFULL, >>>> + RGBLIMITED_ITU601, >>>> + RGBFULL_ITU601, >>> >>> This can't be right. >>> ITU709_RGBLIMITED >>> You have these conversions: >>> >>> ITU709_RGBFULL >>> ITU601_RGBFULL >>> RGBLIMITED_RGBFULL >>> RGBLIMITED_ITU601 >>> RGBFULL_ITU601 >>> RGBLIMITED_ITU709 >>> RGBFULL_ITU709 >>> >>> I.e. on the HDMI receiver side you can receive RGB full/limited or ITU601/709. >>> On the output side you have RGB full or ITU601/709. >>> >>> So something like ITU709_RGBLIMITED makes no sense. >>> >> >> I misunderstood the V4L2_CID_DV_RX_RGB_RANGE thinking that it allowed >> you to configure the output range. If output to the SoC is only ever >> full quant range for RGB then I can drop the >> ITU709_RGBLIMITED/ITU601_RGBLIMITED conversions. > > Output for RGB is always full range. The reason is simply that the V4L2 API > has no way of selecting the quantization range it wants to receive. I made > a patch for that a few years back, but there really is no demand for it (yet). > Userspace expects full range RGB and limited range YUV. > >> >> However, If the output is YUV how do I know if I need to convert to >> ITU709 or ITU601 and what are my conversion matrices for >> RGBLIMITED_ITU709/RGBFULL_ITU709? > > You can choose yourself whether you convert to YUV 601 or 709. I would > recommend to use 601 for SDTV resolutions (i.e. width/height <= 720x576) > and 709 for HDTV. > > I made a little program that calculates the values for RGB lim/full to > YUV 601/709: > > ------------------------------------- > #include > #include > > #define COEFF(v, r) ((v) * (r) * 16.0) > > static const double bt601[3][3] = { > { COEFF(0.299, 219), COEFF(0.587, 219), COEFF(0.114, 219) }, > { COEFF(-0.1687, 224), COEFF(-0.3313, 224), COEFF(0.5, 224) }, > { COEFF(0.5, 224), COEFF(-0.4187, 224), COEFF(-0.0813, 224) }, > }; > static const double rec709[3][3] = { > { COEFF(0.2126, 219), COEFF(0.7152, 219), COEFF(0.0722, 219) }, > { COEFF(-0.1146, 224), COEFF(-0.3854, 224), COEFF(0.5, 224) }, > { COEFF(0.5, 224), COEFF(-0.4542, 224), COEFF(-0.0458, 224) }, > }; > > int main(int argc, char **argv) > { > int i, j; > int mapi[] = { 0, 2, 1 }; > int mapj[] = { 1, 0, 2 }; > > printf("rgb full -> 601\n"); > printf(" 0, 0, 0,\n"); > for (i = 0; i < 3; i++) { > for (j = 0; j < 3; j++) { > printf("%5d, ", (int)(0.5 + bt601[mapi[i]][mapj[j]])); > } > printf("\n"); > } > printf(" 256, 2048, 2048,\n\n"); > > printf("rgb lim -> 601\n"); > printf(" -256, -256, -256,\n"); > for (i = 0; i < 3; i++) { > for (j = 0; j < 3; j++) { > printf("%5d, ", (int)(0.5 + 255.0 / 219.0 * bt601[mapi[i]][mapj[j]])); > } > printf("\n"); > } > printf(" 256, 2048, 2048,\n\n"); > > printf("rgb full -> 709\n"); > printf(" 0, 0, 0,\n"); > for (i = 0; i < 3; i++) { > for (j = 0; j < 3; j++) { > printf("%5d, ", (int)(0.5 + rec709[mapi[i]][mapj[j]])); > } > printf("\n"); > } > printf(" 256, 2048, 2048,\n\n"); > > printf("rgb lim -> 709\n"); > printf(" -256, -256, -256,\n"); > for (i = 0; i < 3; i++) { > for (j = 0; j < 3; j++) { > printf("%5d, ", (int)(0.5 + 255.0 / 219.0 * rec709[mapi[i]][mapj[j]])); > } > printf("\n"); > } > printf(" 256, 2048, 2048,\n\n"); > return 0; > } > ------------------------------------- > > This should give you the needed matrices. It's up to you whether to keep the > existing matrices for 601 or replace them with these. Probably best to keep > them. > Hans, Thanks for the code - this gives me what I need. >> >> Sorry for all the questions, the colorspace/colorimetry options >> confuse the heck out of me. >> >>>> +}; >>>> + >> >>>> + >>>> +/* parse an infoframe and do some sanity checks on it */ >>>> +static unsigned int >>>> +tda1997x_parse_infoframe(struct tda1997x_state *state, u16 addr) >>>> +{ >>>> + struct v4l2_subdev *sd = &state->sd; >>>> + union hdmi_infoframe frame; >>>> + u8 buffer[40]; >>>> + u8 reg; >>>> + int len, err; >>>> + >>>> + /* read data */ >>>> + len = io_readn(sd, addr, sizeof(buffer), buffer); >>>> + err = hdmi_infoframe_unpack(&frame, buffer); >>>> + if (err) { >>>> + v4l_err(state->client, >>>> + "failed parsing %d byte infoframe: 0x%04x/0x%02x\n", >>>> + len, addr, buffer[0]); >>>> + return err; >>>> + } >>>> + hdmi_infoframe_log(KERN_INFO, &state->client->dev, &frame); >>>> + switch (frame.any.type) { >>>> + /* Audio InfoFrame: see HDMI spec 8.2.2 */ >>>> + case HDMI_INFOFRAME_TYPE_AUDIO: >>>> + /* sample rate */ >>>> + switch (frame.audio.sample_frequency) { >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_32000: >>>> + state->audio_samplerate = 32000; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_44100: >>>> + state->audio_samplerate = 44100; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_48000: >>>> + state->audio_samplerate = 48000; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_88200: >>>> + state->audio_samplerate = 88200; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_96000: >>>> + state->audio_samplerate = 96000; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_176400: >>>> + state->audio_samplerate = 176400; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_192000: >>>> + state->audio_samplerate = 192000; >>>> + break; >>>> + default: >>>> + case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM: >>>> + break; >>>> + } >>>> + >>>> + /* sample size */ >>>> + switch (frame.audio.sample_size) { >>>> + case HDMI_AUDIO_SAMPLE_SIZE_16: >>>> + state->audio_samplesize = 16; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_SIZE_20: >>>> + state->audio_samplesize = 20; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_SIZE_24: >>>> + state->audio_samplesize = 24; >>>> + break; >>>> + case HDMI_AUDIO_SAMPLE_SIZE_STREAM: >>>> + default: >>>> + break; >>>> + } >>>> + >>>> + /* Channel Count */ >>>> + state->audio_channels = frame.audio.channels; >>>> + if (frame.audio.channel_allocation && >>>> + frame.audio.channel_allocation != state->audio_ch_alloc) { >>>> + /* use the channel assignment from the infoframe */ >>>> + state->audio_ch_alloc = frame.audio.channel_allocation; >>>> + tda1997x_configure_audout(sd, state->audio_ch_alloc); >>>> + /* reset the audio FIFO */ >>>> + tda1997x_hdmi_info_reset(sd, RESET_AUDIO, false); >>>> + } >>>> + break; >>>> + >>>> + /* Auxiliary Video information (AVI) InfoFrame: see HDMI spec 8.2.1 */ >>>> + case HDMI_INFOFRAME_TYPE_AVI: >>>> + state->colorspace = frame.avi.colorspace; >>>> + state->colorimetry = frame.avi.colorimetry; >>>> + state->range = frame.avi.quantization_range; >>> >>> This should be ignored if it is overridden by the RGB Quantization Range >>> control, or am I missing something? >>> >> >> Ok. Sounds like I should only use the range from the infoframe if >> range == V4L2_DV_RGB_RANGE_AUTO: >> >> /* Quantization Range */ >> if (state->range == V4L2_DV_RGB_RANGE_AUTO) >> state->range = frame.avi.quantization_range; > > Huh? You're mixing V4L2_DV_RGB_* defines with HDMI_QUANTIZATION_RANGE_* > defines. > > You probably mean to check the control value here. > Yes, I think I've got it now and will post a v4 today. Tim From 1584843556901251506@xxx Thu Nov 23 08:09:55 +0000 2017 X-GM-THRID: 1583615313022071316 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread