Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp103837imm; Wed, 3 Oct 2018 12:40:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV635taTDOUlI4vGdnIK6uqxhgsuN+pCoDzPwKT/funhBee2cnfvXYvLrD//GlLy7w4mCYuxF X-Received: by 2002:a62:215b:: with SMTP id h88-v6mr3113765pfh.233.1538595600491; Wed, 03 Oct 2018 12:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538595600; cv=none; d=google.com; s=arc-20160816; b=iJSFTqmxdwhchMNNdA+HcHIgTFPQYN60Qgxho795pJ5GW1FL4DOIsBO7msf3A4HMGZ ot0MFioe2Pku5jk+PpfsEqv9shBGHwJgDVyjnWjHmm69z553s6x7oImRcjcMES/Qsar7 FXkYcxjSFSlG0RIzifPlJo3fbID0hNAkU3Yt8+TxsgMxWd2pDGYbtg5HtfYmixfzkfeE jg4VXC9MGz3dv/aUAhWJaccq+rKXWm16cEeNz9SQ/OO/4o4qEI//z5mFkAc0RF2WhEUG RPBO6iJrU1LUpTqX4tLVGAX9fVwLbPQ3LlZi4DBrWUUA7rO/0FUy41D6hLPq0n6EMXIn dosA== 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=DnDkdVlT4uEmccUEt9jQFZdRTiIQUnmLL0jvRMKg+cQ=; b=FarR3Tryc2JHIyzhRisW+4dYwEHkHyrfyxJotn7YUeSY6FMqcz5GW7G9s+OZMtXVjj 416yMFhsjGHJguIL7xodhOEV3WnoQeW1pZw2/N4B0VlVRdoLGJkkeCh50/uD3KnPe/en hI5VB0neS0f2+bcMGuUAan3gJQcz+h+Q7wzNC9k144YhGBoPS/w8+JRlm10ZBYS03rZg lLma0+o7+dQh9h1JtFFZM4Uq0fZv+jh4qq27wgQlGnV59pMcog9rvK0d2YB9X+1EYGiZ OSWMzhLuS0aKTJdzS9jIUSpPUENmGdUWBevk79GCQ+9WzauC9XRSBBv8dfGww293GxSq NnDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OMuoRPGc; 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 14-v6si2390742pgk.497.2018.10.03.12.39.44; Wed, 03 Oct 2018 12:40:00 -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=OMuoRPGc; 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 S1727472AbeJDC27 (ORCPT + 99 others); Wed, 3 Oct 2018 22:28:59 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:35485 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbeJDC26 (ORCPT ); Wed, 3 Oct 2018 22:28:58 -0400 Received: by mail-ed1-f66.google.com with SMTP id y19-v6so6457289edd.2 for ; Wed, 03 Oct 2018 12:39:11 -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=DnDkdVlT4uEmccUEt9jQFZdRTiIQUnmLL0jvRMKg+cQ=; b=OMuoRPGcGpz8FkPZUZD3n2l6dG+9sat0wpTlDPyQbOzaV6hxR5SsKZzOdDGV/BCZIj fE0GjLFZqq6GAKRZWbc85enJQ1GE4QPjUYTpY8dXUqU+q2PdYyRnv6X2ssC+pZw1RrpR ac4lEYB4sSXt21a7Py7YxI6y0TTGmnMmmuTWBeHIkpA3IrYlcAv3vZ4VEQ47KxNk1t9n myexaSNdudU+NmBzM0M3BupfkNLiR+rr3dll1GWLXfqDJVsy/tKd8mxq/UrHkbl4V+Jl MaUfZJWT5nK1+SF6HACeBc4iLHtStwj7bykDFtJVGjoLmye2g6J6rtWUpkChB1QQpAgs y1aQ== 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=DnDkdVlT4uEmccUEt9jQFZdRTiIQUnmLL0jvRMKg+cQ=; b=Hj8fmVp1Jz8t9a4gDM8KMnLbWgrUGIz58yA98O21JDY2mst3mpu5/ZrMZgsh/iGAqX 3P+dyCDjlZie+Sj8jd8y/RmMAxRsJH4MHFEGN2lG7lo1LRcf6jZPk2mk1bKKfFjHS61O djOK42rqb1xUiVc/DaOOLbcFEGPeCYDLvC6ohFG/8cA0jNsiy7fS37NUC5Zp0mrbrRd5 eYbOgS/gWS4XRbqQuv9Se4Lef24VFfbmS4Z3RxUWzQiUpYu6mHQet/bq+cH64ob/8OJU z/dwgVDomPs/hlZn7gXmvrEDvCQVkYIEMKzrQNvlqFMMmCBzHxRD/ZquA29Io+LEl/5c N0XA== X-Gm-Message-State: ABuFfohqs+a0G+5Cw/1Us9nuLwjIv2J0NZMBTr0Irdz4odJpKga9mtGa QXLp4/QJr/yEqUINdR16XuM8MYMS X-Received: by 2002:a17:906:344b:: with SMTP id d11-v6mr3402240ejb.130.1538595550814; Wed, 03 Oct 2018 12:39:10 -0700 (PDT) Received: from piling.lan (80-71-134-83.u.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id b49-v6sm765263eda.70.2018.10.03.12.39.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 12:39:09 -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 v5 6/8] mtd: maps: gpio-addr-flash: Convert to gpiod Date: Wed, 3 Oct 2018 21:38:57 +0200 Message-Id: <20181003193859.23928-6-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181003193859.23928-1-ricardo.ribalda@gmail.com> References: <20181003193859.23928-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 | 52 +++++++++++------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 47b12a6fead4..9e370e3158cd 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,19 @@ 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 = { .... ); + * }; + * 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 +205,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, NULL, 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 +231,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 +241,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