public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v5 19/33] spi: dw: Add device tree properties for fields in CTRL1
Date: Wed, 4 Mar 2020 10:01:23 -0500	[thread overview]
Message-ID: <6d330350-96e1-803b-8634-ed2c11bc1461@gmail.com> (raw)
In-Reply-To: <CAN5B=eKbsc2Nw5hFAusQrO8hXUnjj9Ge4Fhc0skeXCKzXX0-6w@mail.gmail.com>

On 3/4/20 1:15 AM, Rick Chen wrote:
> Hi Sean
> 
>> Some devices have different layouts for the fields in CTRL1 (e.g. the
> 
> Still not fix this typo in commit message
> CTRL1 -> CTRL0
> 
> Thanks,
> Rick

Ah, whoops. I think I fixed it, the forgot I had done so, and changed it
again. Hopefully I can get this straight.

--Sean

> 
>> Kendryte K210). Allow this layout to be configurable from the device tree.
>> The documentation has been taken from Linux.
>>
>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>> Changes in v4:
>> - New
>>
>>  .../spi/snps,dw-apb-ssi.txt                   | 43 +++++++++++++++++++
>>  drivers/spi/designware_spi.c                  | 40 ++++++++++-------
>>  2 files changed, 68 insertions(+), 15 deletions(-)
>>  create mode 100644 doc/device-tree-bindings/spi/snps,dw-apb-ssi.txt
>>
>> diff --git a/doc/device-tree-bindings/spi/snps,dw-apb-ssi.txt b/doc/device-tree-bindings/spi/snps,dw-apb-ssi.txt
>> new file mode 100644
>> index 0000000000..4b6152f6b7
>> --- /dev/null
>> +++ b/doc/device-tree-bindings/spi/snps,dw-apb-ssi.txt
>> @@ -0,0 +1,43 @@
>> +Synopsys DesignWare AMBA 2.0 Synchronous Serial Interface.
>> +
>> +Required properties:
>> +- compatible : "snps,dw-apb-ssi"
>> +- reg : The register base for the controller. For "mscc,<soc>-spi", a second
>> +  register set is required (named ICPU_CFG:SPI_MST)
>> +- #address-cells : <1>, as required by generic SPI binding.
>> +- #size-cells : <0>, also as required by generic SPI binding.
>> +- clocks : phandles for the clocks, see the description of clock-names below.
>> +   The phandle for the "ssi_clk" is required. The phandle for the "pclk" clock
>> +   is optional. If a single clock is specified but no clock-name, it is the
>> +   "ssi_clk" clock. If both clocks are listed, the "ssi_clk" must be first.
>> +
>> +Optional properties:
>> +- clock-names : Contains the names of the clocks:
>> +    "ssi_clk", for the core clock used to generate the external SPI clock.
>> +    "pclk", the interface clock, required for register access.
>> +- cs-gpios : Specifies the gpio pins to be used for chipselects.
>> +- num-cs : The number of chipselects. If omitted, this will default to 4.
>> +- reg-io-width : The I/O register width (in bytes) implemented by this
>> +  device.  Supported values are 2 or 4 (the default).
>> +- snps,dfs-offset The offset in bits of the DFS field in CTRL0, defaulting to 0
>> +- snps,frf-offset The offset in bits of the FRF field in CTRL0, defaulting to 4
>> +- snps,tmod-offset The offset in bits of the tmode field in CTRL0, defaulting
>> +  to 6
>> +- snps,mode-offset The offset in bits of the work mode field in CTRL0,
>> +  defaulting to 8
>> +
>> +Child nodes as per the generic SPI binding.
>> +
>> +Example:
>> +
>> +       spi at fff00000 {
>> +               compatible = "snps,dw-apb-ssi";
>> +               reg = <0xfff00000 0x1000>;
>> +               interrupts = <0 154 4>;
>> +               #address-cells = <1>;
>> +               #size-cells = <0>;
>> +               clocks = <&spi_m_clk>;
>> +               num-cs = <2>;
>> +               cs-gpios = <&gpio0 13 0>,
>> +                          <&gpio0 14 0>;
>> +       };
>> diff --git a/drivers/spi/designware_spi.c b/drivers/spi/designware_spi.c
>> index 2dc16736a3..6e1c289297 100644
>> --- a/drivers/spi/designware_spi.c
>> +++ b/drivers/spi/designware_spi.c
>> @@ -3,6 +3,7 @@
>>   * Designware master SPI core controller driver
>>   *
>>   * Copyright (C) 2014 Stefan Roese <sr@denx.de>
>> + * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
>>   *
>>   * Very loosely based on the Linux driver:
>>   * drivers/spi/spi-dw.c, which is:
>> @@ -51,20 +52,14 @@
>>  #define DW_SPI_DR                      0x60
>>
>>  /* Bit fields in CTRLR0 */
>> -#define SPI_DFS_OFFSET                 0
>> -
>> -#define SPI_FRF_OFFSET                 4
>>  #define SPI_FRF_SPI                    0x0
>>  #define SPI_FRF_SSP                    0x1
>>  #define SPI_FRF_MICROWIRE              0x2
>>  #define SPI_FRF_RESV                   0x3
>>
>> -#define SPI_MODE_OFFSET                        6
>> -#define SPI_SCPH_OFFSET                        6
>> -#define SPI_SCOL_OFFSET                        7
>> +#define SPI_MODE_SCPH                  0x1
>> +#define SPI_MODE_SCOL                  0x2
>>
>> -#define SPI_TMOD_OFFSET                        8
>> -#define SPI_TMOD_MASK                  (0x3 << SPI_TMOD_OFFSET)
>>  #define        SPI_TMOD_TR                     0x0             /* xmit & recv */
>>  #define SPI_TMOD_TO                    0x1             /* xmit only */
>>  #define SPI_TMOD_RO                    0x2             /* recv only */
>> @@ -89,6 +84,12 @@
>>  struct dw_spi_platdata {
>>         s32 frequency;          /* Default clock frequency, -1 for none */
>>         void __iomem *regs;
>> +
>> +       /* Offsets in CTRL0 */
>> +       u8 dfs_off;
>> +       u8 frf_off;
>> +       u8 tmod_off;
>> +       u8 mode_off;
>>  };
>>
>>  struct dw_spi_priv {
>> @@ -115,6 +116,15 @@ struct dw_spi_priv {
>>         struct reset_ctl_bulk   resets;
>>  };
>>
>> +static inline u32 GEN_CTRL0(struct dw_spi_priv *priv,
>> +                           struct dw_spi_platdata *plat)
>> +{
>> +       return ((priv->bits_per_word - 1) << plat->dfs_off |
>> +             (priv->type << plat->frf_off) |
>> +             (priv->mode << plat->mode_off) |
>> +             (priv->tmode << plat->tmod_off));
>> +}
>> +
>>  static inline u32 dw_read(struct dw_spi_priv *priv, u32 offset)
>>  {
>>         return __raw_readl(priv->regs + offset);
>> @@ -160,6 +170,10 @@ static int dw_spi_ofdata_to_platdata(struct udevice *bus)
>>         /* Use 500KHz as a suitable default */
>>         plat->frequency = dev_read_u32_default(bus, "spi-max-frequency",
>>                                                500000);
>> +       plat->dfs_off = dev_read_u32_default(bus, "snps,dfs-offset", 0);
>> +       plat->frf_off = dev_read_u32_default(bus, "snps,frf-offset", 4);
>> +       plat->mode_off = dev_read_u32_default(bus, "snps,mode-offset", 6);
>> +       plat->tmod_off = dev_read_u32_default(bus, "snps,tmod-offset", 8);
>>         debug("%s: regs=%p max-frequency=%d\n", __func__, plat->regs,
>>               plat->frequency);
>>
>> @@ -388,6 +402,7 @@ static int dw_spi_xfer(struct udevice *dev, unsigned int bitlen,
>>                        const void *dout, void *din, unsigned long flags)
>>  {
>>         struct udevice *bus = dev->parent;
>> +       struct dw_spi_platdata *plat = dev_get_platdata(bus);
>>         struct dw_spi_priv *priv = dev_get_priv(bus);
>>         const u8 *tx = dout;
>>         u8 *rx = din;
>> @@ -406,10 +421,6 @@ static int dw_spi_xfer(struct udevice *dev, unsigned int bitlen,
>>         if (flags & SPI_XFER_BEGIN)
>>                 external_cs_manage(dev, false);
>>
>> -       cr0 = (priv->bits_per_word - 1) | (priv->type << SPI_FRF_OFFSET) |
>> -               (priv->mode << SPI_MODE_OFFSET) |
>> -               (priv->tmode << SPI_TMOD_OFFSET);
>> -
>>         if (rx && tx)
>>                 priv->tmode = SPI_TMOD_TR;
>>         else if (rx)
>> @@ -421,8 +432,7 @@ static int dw_spi_xfer(struct udevice *dev, unsigned int bitlen,
>>                  */
>>                 priv->tmode = SPI_TMOD_TR;
>>
>> -       cr0 &= ~SPI_TMOD_MASK;
>> -       cr0 |= (priv->tmode << SPI_TMOD_OFFSET);
>> +       cr0 = GEN_CTRL0(priv, plat);
>>
>>         priv->len = bitlen >> 3;
>>         debug("%s: rx=%p tx=%p len=%d [bytes]\n", __func__, rx, tx, priv->len);
>> @@ -476,7 +486,7 @@ static int dw_spi_xfer(struct udevice *dev, unsigned int bitlen,
>>
>>  static int dw_spi_set_speed(struct udevice *bus, uint speed)
>>  {
>> -       struct dw_spi_platdata *plat = bus->platdata;
>> +       struct dw_spi_platdata *plat = dev_get_platdata(bus);
>>         struct dw_spi_priv *priv = dev_get_priv(bus);
>>         u16 clk_div;
>>
>> --
>> 2.25.0
>>

  reply	other threads:[~2020-03-04 15:01 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28 21:05 [PATCH v5 00/33] riscv: Add Sipeed Maix support Sean Anderson
2020-02-28 21:05 ` [PATCH v5 01/33] clk: Always use the supplied struct clk Sean Anderson
2020-02-28 21:05 ` [PATCH v5 02/33] clk: Check that ops of composite clock components exist before calling Sean Anderson
2020-02-28 21:05 ` [PATCH v5 03/33] clk: Unconditionally recursively en-/dis-able clocks Sean Anderson
2020-03-04  6:50   ` Rick Chen
2020-02-28 21:05 ` [PATCH v5 04/33] clk: Add functions to register CCF clock structs Sean Anderson
2020-02-28 21:05 ` [PATCH v5 05/33] clk: Add K210 pll support Sean Anderson
2020-02-28 21:05 ` [PATCH v5 06/33] clk: Add a bypass clock for K210 Sean Anderson
2020-02-28 21:05 ` [PATCH v5 07/33] clk: Add K210 clock support Sean Anderson
2020-03-04  6:58   ` Rick Chen
2020-03-04 14:54     ` Sean Anderson
2020-02-28 21:05 ` [PATCH v5 08/33] doc: Fix typo in FIT documentation Sean Anderson
2020-03-02  2:21   ` Bin Meng
2020-02-28 21:05 ` [PATCH v5 09/33] dm: Add support for simple-pm-bus Sean Anderson
2020-02-28 21:05 ` [PATCH v5 10/33] dm: Fix error handling for dev_read_addr_ptr Sean Anderson
2020-03-02  2:22   ` Bin Meng
2020-03-02 19:46   ` Simon Glass
2020-02-28 21:05 ` [PATCH v5 11/33] reset: Add generic reset driver Sean Anderson
2020-02-28 21:05 ` [PATCH v5 12/33] lib: Always set errno in hcreate_r Sean Anderson
2020-03-02  2:24   ` Bin Meng
2020-02-28 21:05 ` [PATCH v5 13/33] pinctrl: Add support for Kendryte K210 FPIOA Sean Anderson
2020-03-04  6:47   ` Rick Chen
2020-03-04 15:00     ` Sean Anderson
2020-02-28 21:05 ` [PATCH v5 14/33] gpio: sifive: Use generic reg read function Sean Anderson
2020-03-02  2:24   ` Bin Meng
2020-02-28 21:05 ` [PATCH v5 15/33] gpio: dw: Fix warnings about casting int to pointer Sean Anderson
2020-03-02  2:27   ` Bin Meng
2020-03-02  3:50     ` Sean Anderson
2020-02-28 21:05 ` [PATCH v5 16/33] gpio: dw: Add a trailing underscore to generated name Sean Anderson
2020-02-28 21:05 ` [PATCH v5 17/33] gpio: dw: Return output value when direction is out Sean Anderson
2020-02-28 21:05 ` [PATCH v5 18/33] led: gpio: Default to using node name if label is absent Sean Anderson
2020-02-28 21:05 ` [PATCH v5 19/33] spi: dw: Add device tree properties for fields in CTRL1 Sean Anderson
2020-03-04  6:15   ` Rick Chen
2020-03-04 15:01     ` Sean Anderson [this message]
2020-02-28 21:05 ` [PATCH v5 20/33] spi: dw: Rename "cs-gpio" to "cs-gpios" Sean Anderson
2020-02-28 21:05 ` [PATCH v5 21/33] spi: dw: Use generic function to read reg address Sean Anderson
2020-02-28 21:05 ` [PATCH v5 22/33] spi: dw: Speed up transfer loops Sean Anderson
2020-02-28 21:05 ` [PATCH v5 23/33] spi: dw: Properly set rx_end when not recieving Sean Anderson
2020-02-29 17:47   ` Sean Anderson
2020-02-28 21:05 ` [PATCH v5 24/33] spi: dw: Add mem_ops Sean Anderson
2020-02-28 21:05 ` [PATCH v5 25/33] wdt: Move asm/utils.h to log2.h Sean Anderson
2020-02-28 21:46   ` Marek Vasut
2020-02-28 22:43     ` Sean Anderson
2020-02-28 23:27       ` Marek Vasut
2020-03-03  6:58   ` Rick Chen
2020-03-03 14:11     ` Sean Anderson
2020-02-28 21:05 ` [PATCH v5 26/33] riscv: Add headers for asm/global_data.h Sean Anderson
2020-02-28 21:05 ` [PATCH v5 27/33] riscv: Fix race conditions when initializing IPI Sean Anderson
2020-03-02  9:08   ` Rick Chen
2020-03-02 15:43     ` Sean Anderson
2020-03-02 23:15       ` Lukas Auer
2020-03-03  8:27         ` Rick Chen
2020-03-05  2:18           ` Rick Chen
2020-03-02 23:17   ` Lukas Auer
2020-03-02 23:43     ` Sean Anderson
2020-03-03 21:53       ` Lukas Auer
2020-03-03 21:57         ` Sean Anderson
2020-03-04 15:25           ` Lukas Auer
2020-02-28 21:05 ` [PATCH v5 28/33] riscv: Add option to support RISC-V privileged spec 1.9 Sean Anderson
2020-03-04  6:20   ` Rick Chen
2020-02-28 21:05 ` [PATCH v5 29/33] riscv: Allow use of reset drivers Sean Anderson
2020-02-28 21:05 ` [PATCH v5 30/33] riscv: Try to get cpu frequency from a "clocks" node if it exists Sean Anderson
2020-02-28 21:05 ` [PATCH v5 31/33] riscv: Enable cpu clock if it is present Sean Anderson
2020-02-28 21:05 ` [PATCH v5 32/33] riscv: Add device tree for K210 and Sipeed Maix BitM Sean Anderson
2020-02-28 21:05 ` [PATCH v5 33/33] riscv: Add Sipeed Maix support Sean Anderson
2020-03-04  6:04   ` Rick Chen
2020-03-04  7:47     ` Rick Chen
2020-03-04 15:11       ` Sean Anderson
2020-03-05  3:40         ` Bin Meng

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=6d330350-96e1-803b-8634-ed2c11bc1461@gmail.com \
    --to=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox