From patchwork Sun Jul 9 22:30:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 9832117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1063460317 for ; Sun, 9 Jul 2017 22:31:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D07C280DE for ; Sun, 9 Jul 2017 22:31:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01EC1283C5; Sun, 9 Jul 2017 22:31:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 97FF7280DE for ; Sun, 9 Jul 2017 22:31:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=kUZLPNoT2r3YIH1BnQkFqb2yRWFz3uBaG2BeCscxY9Q=; b=mxFrVDdX6a4NNajWO6RncZo2pz OeIvYowNzv8jhuw++alb4ZiS9nTMGTFoQqghj+vqEA8gOZBgkwq8gufVQS5mA4jcHJT0bis2Bpw6X otMAZQN4nnnN8hoE7LIFsungpQLBpZCx9p69RzpU3o5oILskfPIzQYWPiod4H/zf+JysRmaMsbEmE djzHuy+YuYBxk7wa9IaPRabz1LAdvlYRbutTs1S4aSkrn6t5SAq5bXLeLdEKMbw6u7fz6RgQwsEZw cFpW3QjO3KK2kxLoDkkXxweUj4L0zgDMV8ekCbVu0sr4YLX8RqN/rwpgDkFS6+ksKq/MSIWYVBFFn 9VBryQQw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dUKjG-0006hf-4x; Sun, 09 Jul 2017 22:31:02 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dUKjA-0006Yw-11 for linux-amlogic@lists.infradead.org; Sun, 09 Jul 2017 22:30:58 +0000 Received: by mail-wr0-x241.google.com with SMTP id x23so21109074wrb.0 for ; Sun, 09 Jul 2017 15:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4ienMXYgpDAn6zVkivlb9DJZQLYTHJ4gWqEzX9v5uJ0=; b=QVG1jgxhjCEdH9KGZa5kybvlEs6Soyc3vqGo7OkUEBgfLfYyO8aAeIwyBPq9dZf315 PtHY+FrCpxfh2gNvkeqUqaNuc9NYxypZZyULcgDc3MVXIq3RqHvPWgpUDq7+USjh0DXu G3RhAaRDuSWdfltIYt8bbS02em7tVYCi68XDhkjWEjuteUrrd25aU5aU57ee2vHDqpAp vOLWuVTfLACi50UhgOmA6IAY+wfIohYmvFGhcDtin5rM6f/vrTc+ds1Vr8HJbvtHGDnb ML+9z8si9IwNgJuKHOUoLtdDES0SZ1fmBrh+oba2HoZhl5Dzp+97IhNsvgb50GR25TUj AvQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4ienMXYgpDAn6zVkivlb9DJZQLYTHJ4gWqEzX9v5uJ0=; b=JhKtumqnLJ9NAxl4jO0RWtmH1BsoAfbO2T6FLiaqBqE3zteHKi0LuzlX/X9mw6VWaU 8STsexfasbRJ4o6WKtzZ+FjuYHIr7io5ezkNkdYp1ZtTPiZT8LIHQZAaFcUkpkSj9wvJ xsNG+zQXGL/g4Z3Mgj9LFp8qAnBq6c3WhPrKHM685ckoiWDlE+44v8n/MQaerw9dQVuj rJtuvLybN31mty33zq54u++TF+qajGoqFOGvRCYNyZZ3c4vS1WkZo4cl9upjIci+l3yI A/5985S5KikRXOeT7TcnV6w6JKvIbsxlBjs/LOzrD2LLXfZWaX21RTCbUKHEaKmWWhiE O8rg== X-Gm-Message-State: AIVw112SAelgMMnGwGMGILJ4JBqt+GKzysPT3va/d2iEr/v+2VFxWA+S 87mvbHkTr+tzZw== X-Received: by 10.28.52.142 with SMTP id b136mr5782602wma.48.1499639433939; Sun, 09 Jul 2017 15:30:33 -0700 (PDT) Received: from sark.homenet.telecomitalia.it (host230-116-dynamic.211-62-r.retail.telecomitalia.it. [62.211.116.230]) by smtp.gmail.com with ESMTPSA id u80sm10697089wrb.1.2017.07.09.15.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2017 15:30:33 -0700 (PDT) From: Beniamino Galvani To: u-boot@lists.denx.de Subject: [PATCH v2 4/4] pinctrl: meson: convert to livetree Date: Mon, 10 Jul 2017 00:30:06 +0200 Message-Id: <20170709223006.3998-5-b.galvani@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170709223006.3998-1-b.galvani@gmail.com> References: <20170709223006.3998-1-b.galvani@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170709_153056_341849_0F9BFB4F X-CRM114-Status: GOOD ( 14.02 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Beniamino Galvani , Tom Rini , Simon Glass , linux-amlogic@lists.infradead.org, Albert Aribaud MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Update the Meson pinctrl/gpio driver to support a live device tree. Signed-off-by: Beniamino Galvani --- drivers/pinctrl/meson/pinctrl-meson.c | 66 +++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c index a860200..c8cae51 100644 --- a/drivers/pinctrl/meson/pinctrl-meson.c +++ b/drivers/pinctrl/meson/pinctrl-meson.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -257,66 +259,70 @@ static struct driver meson_gpio_driver = { .ops = &meson_gpio_ops, }; -static fdt_addr_t parse_address(int offset, const char *name, int na, int ns) +static phys_addr_t parse_address(struct udevice *dev, ofnode node, + const char *name) { - int index, len = 0; - const fdt32_t *reg; + struct resource r; + fdt_size_t sz; + int na, ns, index; - index = fdt_stringlist_search(gd->fdt_blob, offset, "reg-names", name); + index = ofnode_stringlist_search(node, "reg-names", name); if (index < 0) return FDT_ADDR_T_NONE; - reg = fdt_getprop(gd->fdt_blob, offset, "reg", &len); - if (!reg || (len <= (index * sizeof(fdt32_t) * (na + ns)))) + if (of_live_active()) { + if (of_address_to_resource(ofnode_to_np(node), index, &r)) + return FDT_ADDR_T_NONE; + else + return r.start; + } + + na = dev_read_addr_cells(dev->parent); + if (na < 1) { + debug("bad #address-cells\n"); return FDT_ADDR_T_NONE; + } - reg += index * (na + ns); + ns = dev_read_size_cells(dev->parent); + if (ns < 1) { + debug("bad #size-cells\n"); + return FDT_ADDR_T_NONE; + } - return fdt_translate_address((void *)gd->fdt_blob, offset, reg); + return fdtdec_get_addr_size_fixed(gd->fdt_blob, ofnode_to_offset(node), + "reg", index, na, ns, &sz, true); } int meson_pinctrl_probe(struct udevice *dev) { struct meson_pinctrl *priv = dev_get_priv(dev); + ofnode node, gpio = ofnode_null(); struct uclass_driver *drv; struct udevice *gpio_dev; - fdt_addr_t addr; - int node, gpio = -1, len; - int na, ns; + phys_addr_t addr; char *name; + int len; - na = fdt_address_cells(gd->fdt_blob, dev_of_offset(dev->parent)); - if (na < 1) { - debug("bad #address-cells\n"); - return -EINVAL; - } - - ns = fdt_size_cells(gd->fdt_blob, dev_of_offset(dev->parent)); - if (ns < 1) { - debug("bad #size-cells\n"); - return -EINVAL; - } - - fdt_for_each_subnode(node, gd->fdt_blob, dev_of_offset(dev)) { - if (fdt_getprop(gd->fdt_blob, node, "gpio-controller", &len)) { + dev_for_each_subnode(node, dev) { + if (ofnode_read_prop(node, "gpio-controller", &len)) { gpio = node; break; } } - if (!gpio) { + if (!ofnode_valid(gpio)) { debug("gpio node not found\n"); return -EINVAL; } - addr = parse_address(gpio, "mux", na, ns); + addr = parse_address(dev, gpio, "mux"); if (addr == FDT_ADDR_T_NONE) { debug("mux address not found\n"); return -EINVAL; } priv->reg_mux = (void __iomem *)addr; - addr = parse_address(gpio, "gpio", na, ns); + addr = parse_address(dev, gpio, "gpio"); if (addr == FDT_ADDR_T_NONE) { debug("gpio address not found\n"); return -EINVAL; @@ -335,8 +341,8 @@ int meson_pinctrl_probe(struct udevice *dev) sprintf(name, "meson-gpio"); /* Create child device UCLASS_GPIO and bind it */ - device_bind(dev, &meson_gpio_driver, name, NULL, gpio, &gpio_dev); - dev_set_of_offset(gpio_dev, gpio); + device_bind_with_driver_data(dev, &meson_gpio_driver, name, 0, + gpio, &gpio_dev); return 0; }