All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH 1/3] rockchip: efuse: add support for RK3288 non-secure efuse
Date: Thu, 15 Oct 2020 09:05:39 -0600	[thread overview]
Message-ID: <CAPnjgZ0PASvdmzSoPtDPPC8QMK5B7vibFfqMPtJb6BxZwEHyow@mail.gmail.com> (raw)
In-Reply-To: <20201013202116.24850-2-jonas@kwiboo.se>

Hi Jonas,

On Tue, 13 Oct 2020 at 14:21, Jonas Karlman <jonas@kwiboo.se> wrote:
>
> From: Francis Fan <francis.fan@rock-chips.com>
>
> Extend rockchip efuse driver with support for RK3288 non-secure efuse.
>
> Signed-off-by: Francis Fan <francis.fan@rock-chips.com>
> Signed-off-by: Cody Xie <cody.xie@rock-chips.com>
> Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
> ---
>  drivers/misc/rockchip-efuse.c | 91 +++++++++++++++++++++++++++++++++--
>  1 file changed, 87 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c
> index 46ce6305fe..20423544d9 100644
> --- a/drivers/misc/rockchip-efuse.c
> +++ b/drivers/misc/rockchip-efuse.c
> @@ -27,6 +27,17 @@
>  #define RK3399_STROBE           BIT(1)
>  #define RK3399_CSB              BIT(0)
>
> +#define RK3288_A_SHIFT          6
> +#define RK3288_A_MASK           0x3ff
> +#define RK3288_NFUSES           32
> +#define RK3288_BYTES_PER_FUSE   1
> +#define RK3288_PGENB            BIT(3)
> +#define RK3288_LOAD             BIT(2)
> +#define RK3288_STROBE           BIT(1)
> +#define RK3288_CSB              BIT(0)
> +
> +typedef int (*EFUSE_READ)(struct udevice *dev, int offset, void *buf, int size);

Lower case, also how about efuse_read_func?

> +
>  struct rockchip_efuse_regs {
>         u32 ctrl;      /* 0x00  efuse control register */
>         u32 dout;      /* 0x04  efuse data out register */
> @@ -53,7 +64,7 @@ static int dump_efuses(struct cmd_tbl *cmdtp, int flag,
>          */
>
>         struct udevice *dev;
> -       u8 fuses[128];
> +       u8 fuses[128] = {0};

comment - what does this actually contain

>         int ret;
>
>         /* retrieve the device */
> @@ -77,7 +88,7 @@ static int dump_efuses(struct cmd_tbl *cmdtp, int flag,
>  }
>
>  U_BOOT_CMD(
> -       rk3399_dump_efuses, 1, 1, dump_efuses,
> +       rockchip_dump_efuses, 1, 1, dump_efuses,
>         "Dump the content of the efuses",
>         ""
>  );
> @@ -127,10 +138,59 @@ static int rockchip_rk3399_efuse_read(struct udevice *dev, int offset,
>         return 0;
>  }
>
> +static int rockchip_rk3288_efuse_read(struct udevice *dev, int offset,
> +                                     void *buf, int size)
> +{
> +       struct rockchip_efuse_platdata *plat = dev_get_platdata(dev);
> +       struct rockchip_efuse_regs *efuse =
> +               (struct rockchip_efuse_regs *)plat->base;
> +       u8 *buffer = buf;
> +       int max_size = RK3288_NFUSES * RK3288_BYTES_PER_FUSE;
> +
> +       if (size > (max_size - offset))
> +               size = max_size - offset;
> +
> +       /* Switch to read mode */
> +       writel(RK3288_LOAD | RK3288_PGENB, &efuse->ctrl);
> +       udelay(1);
> +
> +       while (size--) {
> +               writel(readl(&efuse->ctrl) &
> +                               (~(RK3288_A_MASK << RK3288_A_SHIFT)),
> +                               &efuse->ctrl);
> +               /* set addr */
> +               writel(readl(&efuse->ctrl) |
> +                               ((offset++ & RK3288_A_MASK) << RK3288_A_SHIFT),

Can offset++ go@the end of this loop?

> +                               &efuse->ctrl);
> +               udelay(1);
> +               /* strobe low to high */
> +               writel(readl(&efuse->ctrl) |
> +                               RK3288_STROBE, &efuse->ctrl);

setbits_le32(&efuse->ctrl), RK3288_STROBE)l;

> +               ndelay(60);
> +               /* read data */
> +               *buffer++ = readl(&efuse->dout);
> +               /* reset strobe to low */
> +               writel(readl(&efuse->ctrl) &
> +                               (~RK3288_STROBE), &efuse->ctrl);

clrbits_le32

> +               udelay(1);
> +       }
> +
> +       /* Switch to standby mode */
> +       writel(RK3288_PGENB | RK3288_CSB, &efuse->ctrl);

as above

> +
> +       return 0;
> +}
> +
>  static int rockchip_efuse_read(struct udevice *dev, int offset,
>                                void *buf, int size)
>  {
> -       return rockchip_rk3399_efuse_read(dev, offset, buf, size);
> +

 efuse_read = NULL;
> +
> +       efuse_read = (EFUSE_READ)dev_get_driver_data(dev);
> +       if (!efuse_read)
> +               return -ENOSYS;
> +
> +       return (*efuse_read)(dev, offset, buf, size);

Drop the *

>  }
>
>  static const struct misc_ops rockchip_efuse_ops = {
> @@ -146,7 +206,30 @@ static int rockchip_efuse_ofdata_to_platdata(struct udevice *dev)
>  }
>
>  static const struct udevice_id rockchip_efuse_ids[] = {
> -       { .compatible = "rockchip,rk3399-efuse" },
> +       {
> +               .compatible = "rockchip,rk3066a-efuse",
> +               .data = (ulong)&rockchip_rk3288_efuse_read,

You could use an enum to set the type, but it's up to you.

> +       },
> +       {
> +               .compatible = "rockchip,rk3188-efuse",
> +               .data = (ulong)&rockchip_rk3288_efuse_read,
> +       },
> +       {
> +               .compatible = "rockchip,rk3228-efuse",
> +               .data = (ulong)&rockchip_rk3288_efuse_read,
> +       },
> +       {
> +               .compatible = "rockchip,rk3288-efuse",
> +               .data = (ulong)&rockchip_rk3288_efuse_read,
> +       },
> +       {
> +               .compatible = "rockchip,rk3368-efuse",
> +               .data = (ulong)&rockchip_rk3288_efuse_read,
> +       },
> +       {
> +               .compatible = "rockchip,rk3399-efuse",
> +               .data = (ulong)&rockchip_rk3399_efuse_read,
> +       },
>         {}
>  };
>
> --
> 2.17.1
>

Regards,
Simon

  reply	other threads:[~2020-10-15 15:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-13 20:21 [PATCH 0/3] rockchip: efuse: add RK3288/RK3328 support Jonas Karlman
2020-10-13 20:21 ` [PATCH 1/3] rockchip: efuse: add support for RK3288 non-secure efuse Jonas Karlman
2020-10-15 15:05   ` Simon Glass [this message]
2020-10-30 10:21   ` Kever Yang
2020-10-13 20:21 ` [PATCH 2/3] rockchip: efuse: add support for RK3328 " Jonas Karlman
2020-10-15 15:05   ` Simon Glass
2020-10-13 20:21 ` [PATCH 3/3] rockchip: dts: rk3288: enable efuse node Jonas Karlman
2020-10-15 15:05   ` Simon Glass

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=CAPnjgZ0PASvdmzSoPtDPPC8QMK5B7vibFfqMPtJb6BxZwEHyow@mail.gmail.com \
    --to=sjg@chromium.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.