From patchwork Tue Jan 16 13:46:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 124691 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1019616lje; Tue, 16 Jan 2018 05:48:28 -0800 (PST) X-Google-Smtp-Source: ACJfBos2ZZFAGNCM0k9sBEa09FQgC148zY4X9UNDjW9aO9W3A1hti/kAGkLbK0mApU0zmzuIdrff X-Received: by 10.80.145.41 with SMTP id e38mr22713481eda.63.1516110507978; Tue, 16 Jan 2018 05:48:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516110507; cv=none; d=google.com; s=arc-20160816; b=KEZLjgv88wSTbtqJoiYDddUGPgBWnb1CYldOBqh3/EqW0zszEvfRFnNeXYtXjRdVa9 oiRi8n+fTaZhsLJivXm7l0tx+p6iMJglDnkhpb1JEMyOvsUkJitu9VZwO4NfUfve+VcW sCKj0yqdon5LAzAkpHNQ7sBg89J7bbE/bqr1VFFDO9QHN1BAkCfEljsM5iL5r77O1znc O43roES8TDKB/esHj9I1WrobMZ+92lrQakZOC5SFNTS7pN4wfwgOtHYgMZoTqLjzktPc ZFSPtFzWNK7hcKroNrECWAOpWHIess3idl+TFVlC6X553FyscuE0AyyuTG0hPFtt1l6G cWkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:arc-authentication-results; bh=uzbCpuW6Dx3uxnnH1j8RzuG+JM0Fe8fVoCzsYd/xT/w=; b=0KZRyfUCgMOoajNn4Zmt1GIGeF5oVIiP3ibLQ3ETcoXH1mhylQ4XpHDqNItT9Z+FJh xE11Y5rnQO40ewNvM0DfbbUwgq4s+SFmvSsvW2ujBfzZ304OZ7VA3MN4AFasl3xgyK4Z QML+K9WnDX1Vp/6nohsufrOaMQlfbR5vh4lJiAvyTS3KpmeEZUYNCvW2oA1q3KouECNv YAer9QWC2AsYjF+/wMtLRgKxBFzODD/bI6T7QpFPs9YW5vicsW1MUf9Qdl5xj2q7jcZr KKl7NxOoTzPwLpULUOdLo6vSzG4WEwOG2ZMlMgTqSH0OJ+TRmXznBhbdNG5HQnbbf30l b6DA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 6si2045941edf.460.2018.01.16.05.48.27; Tue, 16 Jan 2018 05:48:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 8825AC21DEF; Tue, 16 Jan 2018 13:47:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 86953C21E0F; Tue, 16 Jan 2018 13:46:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 91015C21DB0; Tue, 16 Jan 2018 13:46:45 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 1BE88C21C2F for ; Tue, 16 Jan 2018 13:46:45 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7E4CDAD05; Tue, 16 Jan 2018 13:46:44 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Tue, 16 Jan 2018 14:46:36 +0100 Message-Id: <20180116134638.3879-2-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180116134638.3879-1-agraf@suse.de> References: <20180116134638.3879-1-agraf@suse.de> Subject: [U-Boot] [PATCH 1/3] bcm2835_gpio: Add support for pinmux X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" On the bcm2835 the GPIO IP block is responsible to control pin muxing of the configurable pins on the chip. This adds a simple helper function that allows a device driver to set pin muxing according to device tree configuration on those devices. Signed-off-by: Alexander Graf --- arch/arm/mach-bcm283x/include/mach/gpio.h | 1 + drivers/gpio/bcm2835_gpio.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/arch/arm/mach-bcm283x/include/mach/gpio.h b/arch/arm/mach-bcm283x/include/mach/gpio.h index daaee52f81..751594d09f 100644 --- a/arch/arm/mach-bcm283x/include/mach/gpio.h +++ b/arch/arm/mach-bcm283x/include/mach/gpio.h @@ -62,5 +62,6 @@ struct bcm2835_gpio_platdata { }; int bcm2835_gpio_get_func_id(struct udevice *dev, unsigned gpio); +void bcm2835_gpio_set_pinmux(struct udevice *dev, int handle); #endif /* _BCM2835_GPIO_H_ */ diff --git a/drivers/gpio/bcm2835_gpio.c b/drivers/gpio/bcm2835_gpio.c index beaa21853a..209cbed9e6 100644 --- a/drivers/gpio/bcm2835_gpio.c +++ b/drivers/gpio/bcm2835_gpio.c @@ -83,6 +83,46 @@ int bcm2835_gpio_get_func_id(struct udevice *dev, unsigned gpio) return (val >> BCM2835_GPIO_FSEL_SHIFT(gpio) & BCM2835_GPIO_FSEL_MASK); } +static void bcm2835_gpio_set_func_id(struct udevice *dev, unsigned gpio, int func) +{ + struct bcm2835_gpios *gpios = dev_get_priv(dev); + u32 val; + + val = readl(&gpios->reg->gpfsel[BCM2835_GPIO_FSEL_BANK(gpio)]); + val &= ~(BCM2835_GPIO_FSEL_MASK << BCM2835_GPIO_FSEL_SHIFT(gpio)); + val |= (func << BCM2835_GPIO_FSEL_SHIFT(gpio)); + writel(val, &gpios->reg->gpfsel[BCM2835_GPIO_FSEL_BANK(gpio)]); +} + +void bcm2835_gpio_set_pinmux(struct udevice *dev, int handle) +{ + int node = fdt_node_offset_by_phandle(gd->fdt_blob, handle); + u32 pins[16]; + int len; + u32 func; + int i; + + if (!node) + goto err; + + func = fdtdec_get_int(gd->fdt_blob, node, "brcm,function", -1); + if (func <= 0) + goto err; + + len = fdtdec_get_int_array_count(gd->fdt_blob, node, "brcm,pins", pins, + ARRAY_SIZE(pins)); + if (len <= 0) + goto err; + + for (i = 0; i < len; i++) + bcm2835_gpio_set_func_id(dev, pins[i], func); + + return; +err: + printf("Failed to pinmux phandle 0x%x\n", handle); + return; +} + static int bcm2835_gpio_get_function(struct udevice *dev, unsigned offset) { int funcid = bcm2835_gpio_get_func_id(dev, offset);