Received: by 10.223.176.5 with SMTP id f5csp2670935wra; Thu, 1 Feb 2018 04:19:11 -0800 (PST) X-Google-Smtp-Source: AH8x227J9CihPjPlhWgKRuFfwqHv2W+8XUmx+dB4Q7kHuxjq72CsyGDlKJtz/ympKjeEbGN5eh/y X-Received: by 10.99.114.92 with SMTP id c28mr1390747pgn.344.1517487551016; Thu, 01 Feb 2018 04:19:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517487550; cv=none; d=google.com; s=arc-20160816; b=KeoLpsbtcx/SrXuGk/xOc5efg0EUEwWuS9XeupTHPDOTbaplTMMPpDzN3WwWavdPnh XPLg//nT9ifTN+f7oYM1gQMSUFM7skZZTgxJ+G1Md+Zb8KCMqOVSdGc/7yDIpEbrSzoP 8YZuO2TqmDFG5o+wfbQcp8gFhtRenCQxKZoguQxomwbTnt1DozhblVz2htZwiNy/qIhS XzP/vdTO9htOCyUQUi8/yx1suFVD7uXnpnuR7nyGnWvwzBgLFbKjrUhx60Jxmb6jbgZr TUUyjB1iAopTHZggghk64bF3KNYylaQybfDi0n3Qzh/vxc8uKV/GWf6yjA5zTAPXY0vc AWmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=cr9I3MNrDPKey8+5owhMva29qjqiaXFO4B3YoPATXNc=; b=BjxRYnmfeeCXvaC6CreCynz7meafAzazHZYomWtiNF3mHSrUE+0/OBjyfx3ZcAoK7C VfLedCiaUEGlrfQQejEI0YTaKjo+BHOtLtUqBH4womZsSEETJM0Y136TJzJ9v9DzVwht mEdg88cA6EPuq4zkFUSAZ826X+jKxQk7LMEJFOkHPXUpVxFLJuVYwHBUpBln5/UzITkT Z6uAYOatDOZo059P7iSGtsEjUV04uVvjii3pcsfOWzf4Zuf1aQa3GywAQcwzUcqYD0np Z42VZyOZs+Jes3axxYZU2NAQBlyBLlyhKHGVV1lWRUKCds7mhsgC7iTwuD5hm3d0ISdb kj8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cKjwvmwp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u27si1654000pfk.385.2018.02.01.04.18.55; Thu, 01 Feb 2018 04:19:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cKjwvmwp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752402AbeBAMSC (ORCPT + 99 others); Thu, 1 Feb 2018 07:18:02 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:37750 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751949AbeBAMR6 (ORCPT ); Thu, 1 Feb 2018 07:17:58 -0500 Received: by mail-lf0-f65.google.com with SMTP id 63so25874989lfv.4; Thu, 01 Feb 2018 04:17:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=cr9I3MNrDPKey8+5owhMva29qjqiaXFO4B3YoPATXNc=; b=cKjwvmwpBuVgT1K/qzrNr/k7qodGfSKldo1tdN1h6Da6HlDawfOEtPtydy6Ke/vqEd xMqvgwF1eXgz21JP4NvnBwkyoFgWYiMl/bgs/eMJH16SyCkcaWVvehHhDiYx5njyVLGh ytLX6TqjVxiPrliVH1Yq23AlQafRyWefCI4YvToB5ETbV6snEKHfAKu+qP/AvEPUvJFr 4jPGuUqQ0+7fJPUU3sSIk9gQgBBWRxo913cLsR1WUkPndPsIJ6DMNuGKXC3mF3mT8Bbs TtKiCHW88bzusttt02blpuSZMj9yziPRzEQcgfjZPddsCXSm4MbciCTVqOi74WQE3RvZ w8PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=cr9I3MNrDPKey8+5owhMva29qjqiaXFO4B3YoPATXNc=; b=XXVVfxRqqLEuKHRmTUs9kU/86YYWa/sEDv5bXyFsxdQOZytQ5eX9KzkX5oOgz/YhVt BmjCCbfhWlqmLKXQeMa18LRKklg5vlVC7C+nZ/VrSzuvo1P4yMV4Z+s+ESetTVM8Ovhw +C3WgfktjAlMWvF2a2NRQzogRVbOFDCuA9Qq306gMyciUP4kMvu5icuvOwlXZYmVYp36 rxuTacYstj9pejZtwtIdWVrKk4KUHsOl9ymy1EH+yIntDS11rgip09RMtYcw5NEToxla TROuBfWjuRaN6zeLQBlyg8yj7cL/f6Hc11KQbMqaGenYH9y4qvc1WZgypvFeoSzUCBE2 4FNw== X-Gm-Message-State: AKwxyteCKa7lZsnLCVI3N/xmZCD8dfv6qO+Hgcjo1ebLfd75czu/hpOK tAxQ8A+4fqCpmZvLBdZPI6I= X-Received: by 10.25.20.168 with SMTP id 40mr22162938lfu.23.1517487477011; Thu, 01 Feb 2018 04:17:57 -0800 (PST) Received: from gmail.com (c-2ec2e669-74736162.cust.telenor.se. [46.194.230.105]) by smtp.gmail.com with ESMTPSA id 2sm3670817ljv.37.2018.02.01.04.17.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Feb 2018 04:17:55 -0800 (PST) Date: Thu, 1 Feb 2018 13:17:53 +0100 From: Marcus Folkesson To: Baolin Wang Cc: linus.walleij@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, broonie@kernel.org Subject: Re: [PATCH 2/2] gpio: Add GPIO driver for Spreadtrum SC9860 platform Message-ID: <20180201121753.GB690@gmail.com> References: <2834309f69a1ec37b84a33f153a3d0b90336bcc6.1517313987.git.baolin.wang@linaro.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ZoaI/ZTpAVc4A5k6" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ZoaI/ZTpAVc4A5k6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Baolin, On Tue, Jan 30, 2018 at 08:07:43PM +0800, Baolin Wang wrote: > The Spreadtrum SC9860 platform GPIO controller contains 16 groups and > each group contains 16 GPIOs. Each GPIO can set input/output and has > the interrupt capability. >=20 > Signed-off-by: Baolin Wang > --- > diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c > new file mode 100644 > index 0000000..af59b9f > --- /dev/null > +++ b/drivers/gpio/gpio-sprd.c > @@ -0,0 +1,301 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2018 Spreadtrum Communications Inc. > + * Copyright (c) 2018 Linaro Ltd. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* GPIO registers definition */ > +#define SPRD_GPIO_DATA 0x0 > +#define SPRD_GPIO_DMSK 0x4 > +#define SPRD_GPIO_DIR 0x8 > +#define SPRD_GPIO_IS 0xc > +#define SPRD_GPIO_IBE 0x10 > +#define SPRD_GPIO_IEV 0x14 > +#define SPRD_GPIO_IE 0x18 > +#define SPRD_GPIO_RIS 0x1c > +#define SPRD_GPIO_MIS 0x20 > +#define SPRD_GPIO_IC 0x24 > +#define SPRD_GPIO_INEN 0x28 > + > +/* We have 16 groups GPIOs and each group contain 16 GPIOs */ > +#define SPRD_GPIO_GROUP_NR 16 > +#define SPRD_GPIO_NR 256 > +#define SPRD_GPIO_GROUP_SIZE 0x80 > +#define SPRD_GPIO_GROUP_MASK GENMASK(15, 0) > +#define SPRD_GPIO_BIT(x) ((x) & (SPRD_GPIO_GROUP_NR - 1)) > + > +struct sprd_gpio { > + struct gpio_chip chip; > + void __iomem *base; > + spinlock_t lock; > + int irq; > +}; > + > +static inline void __iomem *sprd_gpio_group_base(struct sprd_gpio *sprd_= gpio, > + unsigned int group) > +{ > + return sprd_gpio->base + SPRD_GPIO_GROUP_SIZE * group; > +} > + > +static void sprd_gpio_update(struct gpio_chip *chip, unsigned int offset, > + unsigned int reg, unsigned int val) > +{ > + struct sprd_gpio *sprd_gpio =3D gpiochip_get_data(chip); > + void __iomem *base =3D sprd_gpio_group_base(sprd_gpio, > + offset / SPRD_GPIO_GROUP_NR); > + u32 shift =3D SPRD_GPIO_BIT(offset); > + unsigned long flags; > + u32 orig, tmp; > + > + spin_lock_irqsave(&sprd_gpio->lock, flags); > + orig =3D readl_relaxed(base + reg); > + > + tmp =3D (orig & ~BIT(shift)) | (val << shift); > + writel_relaxed(tmp, base + reg); > + spin_unlock_irqrestore(&sprd_gpio->lock, flags); > +} > + > +static int sprd_gpio_read(struct gpio_chip *chip, unsigned int offset, > + unsigned int reg) > +{ > + struct sprd_gpio *sprd_gpio =3D gpiochip_get_data(chip); > + void __iomem *base =3D sprd_gpio_group_base(sprd_gpio, > + offset / SPRD_GPIO_GROUP_NR); > + u32 value =3D readl_relaxed(base + reg) & SPRD_GPIO_GROUP_MASK; > + u32 shift =3D SPRD_GPIO_BIT(offset); > + > + return !!(value & BIT(shift)); > +} > + > +static int sprd_gpio_request(struct gpio_chip *chip, unsigned int offset) > +{ > + sprd_gpio_update(chip, offset, SPRD_GPIO_DMSK, 1); > + return 0; > +} Better to change the function to void since the return value is not valueable. > + > +static void sprd_gpio_free(struct gpio_chip *chip, unsigned int offset) > +{ > + sprd_gpio_update(chip, offset, SPRD_GPIO_DMSK, 0); > +} > + > +static int sprd_gpio_direction_input(struct gpio_chip *chip, > + unsigned int offset) > +{ > + sprd_gpio_update(chip, offset, SPRD_GPIO_DIR, 0); > + sprd_gpio_update(chip, offset, SPRD_GPIO_INEN, 1); > + return 0; > +} Same here > + > +static int sprd_gpio_direction_output(struct gpio_chip *chip, > + unsigned int offset, int value) > +{ > + sprd_gpio_update(chip, offset, SPRD_GPIO_DIR, 1); > + sprd_gpio_update(chip, offset, SPRD_GPIO_INEN, 0); > + sprd_gpio_update(chip, offset, SPRD_GPIO_DATA, value); > + return 0; > +} and here. Thanks, Marcus Folkesson --ZoaI/ZTpAVc4A5k6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEBVGi6LZstU1kwSxliIBOb1ldUjIFAlpzBWwACgkQiIBOb1ld UjIGng/9HW0QXWylsPPRhKII4zxA72gXQIwh7QPstYT+6pnfNc/zR0VMvPXGBA3X v8wS05JvKmQWmQDd9ZJHGw0m2PtYeJ3RybVsdqvXuYu8Tq6rZ/lolcoI1ljvzGIH z0vBaCHt4BP0jkVeiz2mtLBQoYaUBvbhOb/Kv5EYVz1Lffpn7Srmq4+cxcmwj6TH mbkCcMZ+E+ve7XFNl9Z0kjTQ9VNycur3etsITNoM/JeeuiHthDPwqvpX2s1QLcqC qZGoQbL1el4xvOr9m5y/9vqUAUjrAwAR46kbm4RdyPoUWDa5qdQYJNsot2Fb2Fqy MQL1K+tz/XrMt9mLmnY6dKvOwfLneZpCFtcceUqvfOUu+THZwAa32AoHIz60V8+o QN3gZTrBcIVvc3JNmQj6+rEbxpzDmh9YjJl6CpOin8VgyYUrt/F1p4D2HVvsT9VO /q8PF6ArsYrmJ41pdCltbP9HflJpMofTgC3r4OrKniG8YlvVGZz2qwnlmtJsQ45I MbCjPPF82A1F85r7zUIN0kxIpeQpb89lU9C97toUMzMsCxYt5IpBWSY1MqsRg2Qb BDeqwYpt/L0M/zRMVCcBtWe8x5DOgmQ0wVd6qxSrtApYWG9IlfqClEBD5enp7RJT 3godEJ7c3lP5H3U8MvziMwIqd9LmFWOcz80cqfxe4yqbBzIHFTo= =yquO -----END PGP SIGNATURE----- --ZoaI/ZTpAVc4A5k6--