Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp944934imm; Thu, 4 Oct 2018 06:02:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV63cvXkI259jh0az7tbXye99/lwrregzohNSx3ALY2unVGpP6h7D1QVmkowYPaZnojgStIdH X-Received: by 2002:a62:37c1:: with SMTP id e184-v6mr6790824pfa.112.1538658147398; Thu, 04 Oct 2018 06:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538658147; cv=none; d=google.com; s=arc-20160816; b=DBQlMZ5QXt7UozdVEgWmk0p/bHU9bql1I0nm80BT8OyhrqKjlpS+d/K5qVD6UYUGGv NbMS9Oiubrpov6x7K7Mqttgy0KDlu5eUzlsopL4f3MvM8/J7m6d/1v2/1BtFqPo8hyku cEGTtpKdmjuKHkmvCSkBScSVP5WY5uSCRVyWaIZNxLnVWyw6uFO4ucaIThDIRYdw9sPv TZ3NeczhQUE/GAwL3IFshf8d7whqiBGeWsqRcZl+x2r4Zefp9638nInYhjA0hwvWOk28 igFGAYm+r6x4ge+iZb6x2DpS8MpjgfFridFlY4A2ul3py2FbZNM0qhnQTtSy5TzWGZC9 KNiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t04/5xTYqJKjawPYGYipOMCnPHvhrwprfxMj3JMdytY=; b=DyY6Zr2Edu/ShrJO8mypbKYPmnPOGX8pHnSMQfASSv05WuG+rIswhLzqXcSl12srZV e6HUOMM6dtcdQyo5B0EqI6sxWRALDqafAvkM8OLKKZ76I7wati0egEtdfMMYOQo1y77O e/3XGr+bS17k4tyzZifkVU6q9rAovUPtkiYJ1+dax7iAxfNmBX78scyehRyjwclUWbxY LdX5E3voWINcRP50k1JxESmOykPfma0fKtSbq+F+2RUKyypQV1/2K6giaHWgnW83srzT oJgcuJETx4Y1Ryds2RG9lp9mWDvFBmwmFBwUEg1dEcL95rYRxe08JcQdeR+tj0CrEriw BcYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nwK0R2OZ; 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=QUARANTINE 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 u22-v6si4501980pfn.111.2018.10.04.06.02.11; Thu, 04 Oct 2018 06:02:27 -0700 (PDT) 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=nwK0R2OZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727759AbeJDTzE (ORCPT + 99 others); Thu, 4 Oct 2018 15:55:04 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:33816 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727264AbeJDTys (ORCPT ); Thu, 4 Oct 2018 15:54:48 -0400 Received: by mail-lf1-f67.google.com with SMTP id y10-v6so6712382lfj.1 for ; Thu, 04 Oct 2018 06:01:36 -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 :mime-version:content-transfer-encoding; bh=t04/5xTYqJKjawPYGYipOMCnPHvhrwprfxMj3JMdytY=; b=nwK0R2OZSH5UwBEsGTDz2oT3Btz/yRnkX9VTpHuhJGNn4Tt5zkXj0nb2wJ8aFo4ovG FmTUjuQu+6PN37LR5phe790zzKjkxT9TEeEcova6fEuV+i98v+19wAZfudwXMYdyTH5k g3H0F8e1HQWOcfG7GO6PgvguzjjZWEZ3QG6Fp57HnbW2k4/k6EPc3sfS1R+Dqrv72z8d nqan44CBVi7Ny+OUu9ITvY1BXbX3q8gONXz/JCTX5Cv9xd32jlyLmuqLrWzwBf7E1szO 5/q7ZxEjcobfWP0qdOXcrb5SvgLP2zv7YkPDDBFexVeYilLlhNamtUh6bOsPpnYtvkVX qasA== 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:mime-version:content-transfer-encoding; bh=t04/5xTYqJKjawPYGYipOMCnPHvhrwprfxMj3JMdytY=; b=AkROrWcg56Ubk7OoNsB7H1lA13vCoJthpJ2/SFnuq9OwgIwQ83skJCVdDmKjI3xCHs d05qsmu9KOdhQz6rQEOLyiaPD+JA7IFF49WzWOYTkFOfKPDuEaJ6KhtaJkzM2PQbHIr/ 3zfUO3l2DFPTFfDYkDj80SUZk+8KqqnR4LpYr3yqffAG4CVkdjagVeXYNLDgIjbgaadO TY8wVOwmAG8lcoBJOKDHqpFKxJJYBZQBCBejB2G52mslm4q/beBfxx1SrMeTg8ZlrF1m KG0cFF0kHEVP4xT35tx364vG9YgF3qJECNS6Qm9jn1KNE2wF9hLmW0E9JzEdi1F/yX/j +90Q== X-Gm-Message-State: ABuFfohoDugXcvRzfH4PlOIb/pjJkcIyU5mxmlB79Qf/P+NTPCIlMBav gkj5n0+EmRkRyIGuEJexGxE= X-Received: by 2002:a19:518a:: with SMTP id g10-v6mr4039220lfl.63.1538658095799; Thu, 04 Oct 2018 06:01:35 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id a1-v6sm421415lfk.63.2018.10.04.06.01.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 06:01:34 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, open list Cc: Ricardo Ribalda Delgado Subject: [PATCH v6 08/10] mtd: maps: gpio-addr-flash: Convert to gpiod Date: Thu, 4 Oct 2018 15:01:08 +0200 Message-Id: <20181004130110.8496-8-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181004130110.8496-1-ricardo.ribalda@gmail.com> References: <20181004130110.8496-1-ricardo.ribalda@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert from legacy gpio API to gpiod. Board files will have to use gpiod_lookup_tables. Signed-off-by: Ricardo Ribalda Delgado Suggested-by: Boris Brezillon --- drivers/mtd/maps/gpio-addr-flash.c | 55 ++++++++++++------------------ 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 47b12a6fead4..a20e85aa770e 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -33,16 +34,14 @@ * struct async_state - keep GPIO flash state * @mtd: MTD state for this mapping * @map: MTD map state for this flash - * @gpio_count: number of GPIOs used to address - * @gpio_addrs: array of GPIOs to twiddle + * @gpios: Struct containing the array of GPIO descriptors * @gpio_values: cached GPIO values * @win_order: dedicated memory size (if no GPIOs) */ struct async_state { struct mtd_info *mtd; struct map_info map; - size_t gpio_count; - unsigned *gpio_addrs; + struct gpio_descs *gpios; unsigned int gpio_values; unsigned int win_order; }; @@ -66,11 +65,11 @@ static void gf_set_gpios(struct async_state *state, unsigned long ofs) if (ofs == state->gpio_values) return; - for (i = 0; i < state->gpio_count; i++) { + for (i = 0; i < state->gpios->ndescs; i++) { if ((ofs & BIT(i)) == (state->gpio_values & BIT(i))) continue; - gpio_set_value(state->gpio_addrs[i], !!(ofs & BIT(i))); + gpiod_set_value(state->gpios->desc[i], !!(ofs & BIT(i))); } state->gpio_values = ofs; @@ -182,18 +181,22 @@ static const char * const part_probe_types[] = { * The platform resource layout expected looks something like: * struct mtd_partition partitions[] = { ... }; * struct physmap_flash_data flash_data = { ... }; - * unsigned flash_gpios[] = { GPIO_XX, GPIO_XX, ... }; + * static struct gpiod_lookup_table addr_flash_gpios = { + * .dev_id = "gpio-addr-flash.0", + * .table = { + * GPIO_LOOKUP_IDX("gpio.0", 15, "addr", 0, GPIO_ACTIVE_HIGH), + * GPIO_LOOKUP_IDX("gpio.0", 16, "addr", 1, GPIO_ACTIVE_HIGH), + * ); + * }; + * gpiod_add_lookup_table(&addr_flash_gpios); + * * struct resource flash_resource[] = { * { * .name = "cfi_probe", * .start = 0x20000000, * .end = 0x201fffff, * .flags = IORESOURCE_MEM, - * }, { - * .start = (unsigned long)flash_gpios, - * .end = ARRAY_SIZE(flash_gpios), - * .flags = IORESOURCE_IRQ, - * } + * }, * }; * struct platform_device flash_device = { * .name = "gpio-addr-flash", @@ -205,29 +208,24 @@ static const char * const part_probe_types[] = { */ static int gpio_flash_probe(struct platform_device *pdev) { - size_t i; struct physmap_flash_data *pdata; struct resource *memory; - struct resource *gpios; struct async_state *state; pdata = dev_get_platdata(&pdev->dev); memory = platform_get_resource(pdev, IORESOURCE_MEM, 0); - gpios = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!memory || !gpios || !gpios->end) + if (!memory) return -EINVAL; state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); if (!state) return -ENOMEM; - /* - * We cast start/end to known types in the boards file, so cast - * away their pointer types here to the known types (gpios->xxx). - */ - state->gpio_count = gpios->end; - state->gpio_addrs = (void *)(unsigned long)gpios->start; + state->gpios = devm_gpiod_get_array(&pdev->dev, "addr", GPIOD_OUT_LOW); + if (IS_ERR(state->gpios)) + return PTR_ERR(state->gpios); + state->win_order = get_bitmask_order(resource_size(memory)) - 1; state->map.name = DRIVER_NAME; @@ -236,7 +234,7 @@ static int gpio_flash_probe(struct platform_device *pdev) state->map.write = gf_write; state->map.copy_to = gf_copy_to; state->map.bankwidth = pdata->width; - state->map.size = BIT(state->win_order + state->gpio_count); + state->map.size = BIT(state->win_order + state->gpios->ndescs); state->map.virt = devm_ioremap_resource(&pdev->dev, memory); if (IS_ERR(state->map.virt)) return PTR_ERR(state->map.virt); @@ -246,17 +244,6 @@ static int gpio_flash_probe(struct platform_device *pdev) platform_set_drvdata(pdev, state); - i = 0; - do { - if (devm_gpio_request(&pdev->dev, state->gpio_addrs[i], - DRIVER_NAME)) { - dev_err(&pdev->dev, "failed to request gpio %d\n", - state->gpio_addrs[i]); - return -EBUSY; - } - gpio_direction_output(state->gpio_addrs[i], 0); - } while (++i < state->gpio_count); - dev_notice(&pdev->dev, "probing %d-bit flash bus\n", state->map.bankwidth * 8); state->mtd = do_map_probe(memory->name, &state->map); -- 2.19.0