From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbdBFIzL (ORCPT ); Mon, 6 Feb 2017 03:55:11 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:38985 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750937AbdBFIyS (ORCPT ); Mon, 6 Feb 2017 03:54:18 -0500 Date: Mon, 6 Feb 2017 09:54:16 +0100 From: Maxime Ripard To: Icenowy Zheng Cc: Srinivas Kandagatla , Rob Herring , Chen-Yu Tsai , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com Subject: Re: [PATCH v3 2/3] nvmem: sunxi-sid: add support for H3's SID controller Message-ID: <20170206085416.4qtd3wfhtinp42xv@lukather> References: <20170202131338.20234-1-icenowy@aosc.xyz> <20170202131338.20234-2-icenowy@aosc.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="stlvygp37kektter" Content-Disposition: inline In-Reply-To: <20170202131338.20234-2-icenowy@aosc.xyz> User-Agent: Mutt/1.6.2-neo (2016-08-21) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --stlvygp37kektter Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 02, 2017 at 09:13:37PM +0800, Icenowy Zheng wrote: > The H3 SoC have a bigger SID controller, which has its direct read > address at 0x200 position in the SID block, not 0x0. >=20 > Also, H3 SID controller has some silicon bug that makes the direct read > value wrong at cold boot, add code to workaround the bug. (This bug has > already been fixed on A64 and later SoCs) >=20 > Signed-off-by: Icenowy Zheng > --- > This patch is the part of [PATCH v2 1/1] that adds support for H3 SID > controller. >=20 > .../bindings/nvmem/allwinner,sunxi-sid.txt | 12 +++- > drivers/nvmem/sunxi_sid.c | 72 ++++++++++++++++= +++++- > 2 files changed, 82 insertions(+), 2 deletions(-) >=20 > diff --git a/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.= txt b/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt > index d543ed3f5363..9ab9e75a6351 100644 > --- a/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt > +++ b/Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt > @@ -1,7 +1,11 @@ > Allwinner sunxi-sid > =20 > Required properties: > -- compatible: "allwinner,sun4i-a10-sid" or "allwinner,sun7i-a20-sid" > +- compatible: Should be one of the following (depending on your SoC): > + "allwinner,sun4i-a10-sid" > + "allwinner,sun7i-a20-sid" > + "allwinner,sun8i-h3-sid" > + > - reg: Should contain registers location and length > =20 > =3D Data cells =3D > @@ -19,3 +23,9 @@ Example for sun7i: > compatible =3D "allwinner,sun7i-a20-sid"; > reg =3D <0x01c23800 0x200> > }; > + > +Example for sun8i-h3: > + sid@01c14000 { > + compatible =3D "allwinner,sun8i-h3-sid"; > + reg =3D <0x01c14000 0x400>; > + }; > diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c > index 69524b67007f..476a161ff23a 100644 > --- a/drivers/nvmem/sunxi_sid.c > +++ b/drivers/nvmem/sunxi_sid.c > @@ -25,6 +25,16 @@ > #include > #include > =20 > +/* Registers and special values for doing register-based SID readout on = H3 */ > +#define SUN8I_SID_PRCTL 0x40 > +#define SUN8I_SID_RDKEY 0x60 > + > +#define SUN8I_SID_OP_LOCK 0xAC > +#define SUN8I_SID_OFFSET_MASK 0x1FF > +#define SUN8I_SID_OFFSET_SHIFT 16 > +#define SUN8I_SID_LOCK_SHIFT 8 > +#define SUN8I_SID_READ BIT(1) > + > static struct nvmem_config econfig =3D { > .name =3D "sunxi-sid", > .read_only =3D true, > @@ -34,11 +44,14 @@ static struct nvmem_config econfig =3D { > }; > =20 > struct sunxi_sid_cfg { > + u32 value_offset; > u32 size; > + bool need_register_readout; > }; > =20 > struct sunxi_sid { > void __iomem *base; > + u32 value_offset; > }; > =20 > /* We read the entire key, due to a 32 bit read alignment requirement. S= ince we > @@ -51,7 +64,8 @@ static u8 sunxi_sid_read_byte(const struct sunxi_sid *s= id, > { > u32 sid_key; > =20 > - sid_key =3D ioread32be(sid->base + round_down(offset, 4)); > + sid_key =3D ioread32be(sid->base + sid->value_offset + > + round_down(offset, 4)); This would probably be more logical to have this in sunxi_sid_read. > sid_key >>=3D (offset % 4) * 8; > =20 > return sid_key; /* Only return the last byte */ > @@ -69,6 +83,33 @@ static int sunxi_sid_read(void *context, unsigned int = offset, > return 0; > } > =20 > +static int sun8i_sid_register_readout(const struct sunxi_sid *sid, > + const unsigned int word, > + u32 *out) > +{ > + u32 reg_val; > + unsigned long expire =3D jiffies + msecs_to_jiffies(250); > + > + /* Set word, lock access, and set read command */ > + reg_val =3D (word & SUN8I_SID_OFFSET_MASK) > + << SUN8I_SID_OFFSET_SHIFT; > + reg_val |=3D SUN8I_SID_OP_LOCK << SUN8I_SID_LOCK_SHIFT; You're not using those mask and shifts anywhere else, why not just define the value / macro you need directly? > + reg_val |=3D SUN8I_SID_READ; > + writel(reg_val, sid->base + SUN8I_SID_PRCTL); > + > + do { > + reg_val =3D readl(sid->base + SUN8I_SID_PRCTL); > + } while (time_before(jiffies, expire) && (reg_val & SUN8I_SID_READ)); readl_poll_timeout? > + if (reg_val & SUN8I_SID_READ) > + return -EIO; > + > + if (out) > + *out =3D readl(sid->base + SUN8I_SID_RDKEY); Why do you need that out parameter? Thanks, Maxime --=20 Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com --stlvygp37kektter Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJYmDmzAAoJEBx+YmzsjxAg184P/3Udk/gbwTVkv2StfJanUQij uVqV3XAK2uL51AK/3QdBkxY2ti88G8LiubzieauqxhcPzJuN0Wt5cAroh3UMKipM dVT2D49IubmvQdpS/XpJPBnUP04X+4elYrgrQ5arYTre0EMS2OcF8vB2FQn9JDqB 411PySp2nzc/UyxI+sf6Xoa2sWyHg+G5BpWZBTYcdFIOti60Gwnbg+5hFFR8R2WA FtQsu1+kTX0C5qEY9yHn3/Gl8B+gBAXnP/VdjocmTopocPVrzG18yLocTFCMncLQ +HS2D+3IR8rrUr0yo2nsFJThrEwt+w7Qj+bpianhvRH+1G5pLTvRMyawL264p74g 2ExnSnxu7ZmWew/bdLA4RiNs4EqZsPK1mZ4TWEJ5n5Dl4eiAka342EgGSFB70EAe Lkif6j8PDvyBI/Nyg5eC1pmPiY/X6/n7/F914e6MDi/amMLHzbvb2SdFUedChEI7 ygp9Xyyi1UOER2D+o1Nc+M+AnchmUFyYjfgZUp8A+fo/cykRyrRWYkc1Zilfk4Yn 2ndHjylp9/Is0FeeMZDJDCI08xGYetVr/yQ8THuyT4h5lbLGl+isD3/6SJNXw57u StTR6gVBMEeL7RGdBw+ySIddSVpVPBBKfNTdbxrmQoDw6t8hrL0BGx/rViw3l+s9 HCB0D7usxqgv1ufu/jCH =tMMT -----END PGP SIGNATURE----- --stlvygp37kektter--