LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Mason Zhang <Mason.Zhang@mediatek.com>
Cc: Mark Brown <broonie@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Laxman Dewangan <ldewangan@nvidia.com>,
	linux-spi <linux-spi@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
	"moderated list:ARM/Mediatek SoC support" 
	<linux-mediatek@lists.infradead.org>,
	Mediatek WSD Upstream <wsd_upstream@mediatek.com>
Subject: Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
Date: Tue, 3 Aug 2021 21:20:19 +0300	[thread overview]
Message-ID: <CAHp75VcPhBB+21wVErWRq+mSDaCkpQBovn+xvMbXyfENnuu40Q@mail.gmail.com> (raw)
In-Reply-To: <20210803102428.6476-1-Mason.Zhang@mediatek.com>

On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang <Mason.Zhang@mediatek.com> wrote:
>
> This patch modified set_cs_timing callback:
>   1 support spi_device set cs_timing in their driver;
>   2 support set absolute time but no clk count, because;
>     clk src will change in different platform;
>   3 call this function in prepare_message but not in other API.

Perhaps it should be 3 patches?

...

> +static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
> +{
> +       struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
> +       struct spi_delay *cs_setup = &spi->cs_setup;
> +       struct spi_delay *cs_hold = &spi->cs_hold;
> +       struct spi_delay *cs_inactive = &spi->cs_inactive;
> +       u16 setup, hold, inactive;
> +       u32 reg_val;
> +       int delay;
> +
> +       delay = spi_delay_to_ns(cs_setup, NULL);
> +       if (delay < 0)
> +               return delay;
> +       setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);

1000 is NSEC_PER_USEC (here and below)?

> +       delay = spi_delay_to_ns(cs_hold, NULL);
> +       if (delay < 0)
> +               return delay;
> +       hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
> +
> +       delay = spi_delay_to_ns(cs_inactive, NULL);
> +       if (delay < 0)
> +               return delay;
> +       inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);

> +       setup    = setup ? setup : 1;
> +       hold     = hold ? hold : 1;
> +       inactive = inactive ? inactive : 1;

All of these can be simplified by using ?: (short ternary) form.

> +       reg_val = readl(mdata->base + SPI_CFG0_REG);
> +       if (mdata->dev_comp->enhance_timing) {
> +               reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> +               reg_val |= (((hold - 1) & 0xffff)
> +                          << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> +               reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> +               reg_val |= (((setup - 1) & 0xffff)
> +                          << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> +       } else {
> +               reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
> +               reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
> +               reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
> +               reg_val |= (((setup - 1) & 0xff)
> +                           << SPI_CFG0_CS_SETUP_OFFSET);
> +       }
> +       writel(reg_val, mdata->base + SPI_CFG0_REG);
> +
> +       reg_val = readl(mdata->base + SPI_CFG1_REG);
> +       reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
> +       reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
> +       writel(reg_val, mdata->base + SPI_CFG1_REG);
> +
> +       return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2021-08-03 18:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 10:24 Mason Zhang
2021-08-03 18:20 ` Andy Shevchenko [this message]
2021-08-03 19:30   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHp75VcPhBB+21wVErWRq+mSDaCkpQBovn+xvMbXyfENnuu40Q@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=Mason.Zhang@mediatek.com \
    --cc=broonie@kernel.org \
    --cc=ldewangan@nvidia.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=wsd_upstream@mediatek.com \
    --subject='Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).