Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1676548

Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Jonathan Liu <net147@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus
Date Wed, 28 Jun 2017 12:50:02 +0200
Message-ID <tXiHM-5FO-23@gated-at.bofh.it> (permalink)
References <tWZOQ-1NK-77@gated-at.bofh.it> <tXhsm-50j-19@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=K7Eqt0P3dSCWvepqCY0lq4g+t2EJ8x3uaC8TC68koWY=; b=Xq5ll0oPbH8Zsy3t9dzIQQXePaDnM7txg8WvsXYsEXIBc8KVzjVBScXelzBdzGT65p dOOBv9cwQuqBbz+1n4RHICBCNnACRulaDYxypx+XqKxbEaP2YmFSDxq1tV8LVoGmVPKn kUC3Do6AFVfVw+PNQFRcW4KXl4Jn7DyfThtjmQSjl79os3lP43o7o4DBcRxFMkdvZu5j ZBYLdhtwXPyBowNHqmPGB84yrx98T2vWu+A08liyaQXYAavDHwv4EM/Q8NNW9RHSBE9S QNyD3skR2wJdwarQaHD4Xk+VnHBgBFrpUI0ZbCFUa1C70e6AU57p8rCAh19XSfxh4LdY B85Q==
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=K7Eqt0P3dSCWvepqCY0lq4g+t2EJ8x3uaC8TC68koWY=; b=i0CL6RXyiWXaXVlCmaa06n6ws5JpvgnoeMvsJKEKHURDyync3wo5JTqzihsTnFN8iH qQId8lT5xLZ6Py9ZUe7KdwxLgUSIUamrjHVbkIE0VZ7LpNEYqkMLXo4IHRq4c10LWVRt kVR6Qhzlv3G/Z1r9vkUrooh1YSR2zdn0uTdGyO22XeJWtTVenOtaM+mQrMwJB+13j7RR sC1Y4L05nRe1L4kboLgblnWqhLfPFXzZk3TOX9kK2FFWaeKmk092wwkvisGeU5pKdm9w olejEbzksKueoxWuIH0yrRARLJggIXzd/HwVAdRM0+wEwrVrBFhUH4kjZQj8QJrbWEAV iVYg==
X-Gm-Message-State AKS2vOyL7TzA7Hl4YGAOEld1jM89hmAHEVd5OB1cFbLkxynY0Xuig6iT vErseaBu9P/lRntj1fVSXx3m8fKj4w==
X-Received by 10.36.14.17 with SMTP id 17mr7520996ite.81.1498646374347; Wed, 28 Jun 2017 03:39:34 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset="UTF-8"
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 102
Organization linux.* mail to news gateway
X-Original-Cc David Airlie <airlied@linux.ie>, Chen-Yu Tsai <wens@csie.org>, linux-kernel <linux-kernel@vger.kernel.org>, dri-devel <dri-devel@lists.freedesktop.org>, linux-arm-kernel <linux-arm-kernel@lists.infradead.org>, linux-sunxi <linux-sunxi@googlegroups.com>
X-Original-Date Wed, 28 Jun 2017 20:39:33 +1000
X-Original-Message-ID <CANwerB0aTAbEoK3zrjZ0802+QEBiZ8tuuPovLsV+KWYtNzd3ig@mail.gmail.com>
X-Original-References <20170627143652.13075-1-net147@gmail.com> <20170628092024.ejxy6itqj3hx6yew@flea>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1676548

Show key headers only | View raw


Hi Maxime,

On 28 June 2017 at 19:20, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> On Wed, Jun 28, 2017 at 12:36:52AM +1000, Jonathan Liu wrote:
>> +#define SUN4I_HDMI_DDC_INT_STATUS_ERROR_MASK ( \
>> +     SUN4I_HDMI_DDC_INT_STATUS_ILLEGAL_FIFO_OPERATION | \
>> +     SUN4I_HDMI_DDC_INT_STATUS_DDC_RX_FIFO_UNDERFLOW | \
>> +     SUN4I_HDMI_DDC_INT_STATUS_DDC_TX_FIFO_OVERFLOW | \
>> +     SUN4I_HDMI_DDC_INT_STATUS_ARBITRATION_ERROR | \
>> +     SUN4I_HDMI_DDC_INT_STATUS_ACK_ERROR | \
>> +     SUN4I_HDMI_DDC_INT_STATUS_BUS_ERROR \
>> +)
>> +
>> +static bool is_err_status(u32 int_status)
>> +{
>> +     return !!(int_status & SUN4I_HDMI_DDC_INT_STATUS_ERROR_MASK);
>> +}
>> +
>> +static bool is_fifo_flag_unset(struct sun4i_hdmi *hdmi, u32 *fifo_status,
>> +                            u32 flag)
>> +{
>> +     *fifo_status = readl(hdmi->base + SUN4I_HDMI_DDC_FIFO_STATUS_REG);
>> +     return !(*fifo_status & flag);
>> +}
>> +
>> +static int fifo_transfer(struct sun4i_hdmi *hdmi, u8 *buf, int len, bool read)
>> +{
>> +     /* 1 byte takes 9 clock cycles (8 bits + 1 ACK) */
>> +     unsigned long byte_time = DIV_ROUND_UP(USEC_PER_SEC,
>> +                                            clk_get_rate(hdmi->ddc_clk)) * 9;
>
> There's no real need for it to be dynamic. The clock rate will not
> change, and the order of magnitude is roughly 100us, so let's just use
> that (and make a comment).
>

Ok.

>> +     u32 int_status;
>> +     u32 fifo_status;
>> +     /* Read needs empty flag unset, write needs full flag unset */
>> +     u32 flag = read ? SUN4I_HDMI_DDC_FIFO_STATUS_EMPTY :
>> +                       SUN4I_HDMI_DDC_FIFO_STATUS_FULL;
>> +     int ret;
>> +
>> +     /* Wait until error or FIFO ready */
>> +     ret = readl_poll_timeout(hdmi->base + SUN4I_HDMI_DDC_INT_STATUS_REG,
>> +                              int_status,
>> +                              is_err_status(int_status) ||
>> +                              is_fifo_flag_unset(hdmi, &fifo_status, flag),
>> +                              min(len, SUN4I_HDMI_DDC_FIFO_SIZE) * byte_time,
>> +                              100000);
>> +
>> +     if (is_err_status(int_status))
>> +             return -EIO;
>> +     if (ret)
>> +             return -ETIMEDOUT;
>
> Why not just have
> ret = readl_poll_timeout(hdmi->base + SUN4I_HDMI_DDC_FIFO_STATUS_REG, reg,
>                          !(reg & flag), 100, 100000);
>
> if (ret < 0)
>         if (is_err_status())
>                 return -EIO;
>         return ret;
>
>

If I check error status after readl_poll_timeout and there is an error
(e.g. the I2C address does not have a corresponding device connected
or nothing connected to HDMI port) it will keep checking the fifo
status even though error bit is set in the int status and then timeout
after 100 ms. If it checks the int status register at the same time,
it will error after 100 nanoseconds. I don't want to introduce
unnecessary delays considering part of the reason for adding this
driver to make it more usable for non-standard use cases.

>> +
>> +     /* Read FIFO level */
>> +     int level = (int)(fifo_status & SUN4I_HDMI_DDC_FIFO_STATUS_LEVEL_MASK);
>
> and explicitly read the fifo status here. That will make you remove
> that function that does two things while claiming that it does only
> one, and it will be more obvious.
>

I will fix the is_fifo_flag_unset function so it only does one thing.

> You can also just use reg at this point, instead of reading it once
> again.
>
> Maxime
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux and Kernel engineering
> http://free-electrons.com

Regards,
Jonathan

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus Jonathan Liu <net147@gmail.com> - 2017-06-27 16:40 +0200
  Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC  bus Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-06-28 11:30 +0200
    Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus Jonathan Liu <net147@gmail.com> - 2017-06-28 12:50 +0200
      Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC  bus Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-06-29 18:00 +0200
        Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus Jonathan Liu <net147@gmail.com> - 2017-06-30 00:30 +0200
          Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus Chen-Yu Tsai <wens@csie.org> - 2017-06-30 05:20 +0200
            Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus Jonathan Liu <net147@gmail.com> - 2017-06-30 16:20 +0200
              Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC  bus Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-06-30 18:10 +0200
          Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC  bus Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-06-30 11:40 +0200
            Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus Jonathan Liu <net147@gmail.com> - 2017-06-30 12:00 +0200
              Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC bus Jonathan Liu <net147@gmail.com> - 2017-07-01 08:30 +0200
  Re: [PATCH v5] drm/sun4i: hdmi: Implement I2C adapter for A10s DDC  bus kbuild test robot <lkp@intel.com> - 2017-06-29 00:10 +0200

csiph-web