From patchwork Sun Sep 23 11:17:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 973658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="KAZ9VcvV"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42J4Yr07K7z9s9G for ; Sun, 23 Sep 2018 21:17:35 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726088AbeIWROl (ORCPT ); Sun, 23 Sep 2018 13:14:41 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41782 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeIWROl (ORCPT ); Sun, 23 Sep 2018 13:14:41 -0400 Received: by mail-wr1-f67.google.com with SMTP id j15-v6so12804816wrt.8 for ; Sun, 23 Sep 2018 04:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=1m0YyAtxJOgDdSvDgUSwdK7l8EcqEmjPAMMrfTja28w=; b=KAZ9VcvVpy3LN/667gyN/UKxEuiYn6tEpJN4bbw+OVxgWufVoniUwrRtiNlG1S8KQU UiSzStsYc4PkL/0HjaHeW/WuCDKF0dPEyAu7dTX5IYnZSFU+3qVRI+YHdlezIoH3Ca4q zV0EhJizhv+/BGAxy6xdyPcTG0cxtEognrkpkUwS+TgUJjciVk26IWEKf1iTMhe7RW2b jI6INgG4GMZbfcTu9LAxTLgClTjZePKJzD0CjV79KRWAIjkIM8onEF2LOVYolr88/7Dw CZ7LiJ+LVMXqAmdEb7MuL1B8J2vlsSp/JLbiJtyooSCS8VDlgpjpl5e9O3QygfXdBCa/ UeHw== 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; bh=1m0YyAtxJOgDdSvDgUSwdK7l8EcqEmjPAMMrfTja28w=; b=oa/OE3iau1GbD2sC77jwIWXbVoJF3PY0klbo0nZy7sBD2TTlJVMi2FZq5h1elocYWT bdQsKPC5atT4E3kTDB59WtCyJWSwJiIkPb23Fk4KGdDy8OgkwmFf/eBiWIouxygwPGOp gPbQoGkvw6Z7cpnNJMcCcOkCF51UHwtdkjInMUOE4LUtBLjmILgX14AdtQySjjm08A97 puc54zHX+VOa8YaoLu/czZxj6p88Q2p1/hBXJEhJfvE/WTWkgp8VvV/nMR9AXBlg6k2K 8dHmbE0ZVZVSs53wKKk7p/k+DtFT9RVyWeC50LDF4tE1LD+TRD80pEZ+2N5iK7AxwMu1 o5Kg== X-Gm-Message-State: ABuFfohKlpusfnlkYrpmefhk05gT3Yf8VMZ45gdw8PpGiIPhJ1gzuDQk 7MJcJ43zrAgDhhr/EyXCcAKfoQ== X-Google-Smtp-Source: ACcGV63eNMYRiWBJ/PDDVgChvhSWcvB5QD9Yj3NKtsnmfoK3djF0gsKscolV729VoxERBQLIw2f0gA== X-Received: by 2002:adf:e603:: with SMTP id p3-v6mr1970200wrm.254.1537701451542; Sun, 23 Sep 2018 04:17:31 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id a1-v6sm5241800wrt.9.2018.09.23.04.17.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Sep 2018 04:17:30 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Bamvor Jian Zhang , Vincent Whitchurch Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] gpio: mockup: use device properties instead of platform_data Date: Sun, 23 Sep 2018 13:17:27 +0200 Message-Id: <20180923111727.10378-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Some users want to introduce device tree support to the mockup driver. Let's make it easier by switching to using generic device properties. The driver stays compatible with previous use cases and after this conversion there'll be no need to change the way probing of mockup GPIO chips works. Tested with libgpiod test suite. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 82 ++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index d66b7a768ecd..4e66bd83b76c 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "gpiolib.h" @@ -28,6 +29,8 @@ * of GPIO lines. */ #define GPIO_MOCKUP_MAX_RANGES (GPIO_MOCKUP_MAX_GC * 2) +/* Maximum of three properties + the sentinel. */ +#define GPIO_MOCKUP_MAX_PROP 4 #define gpio_mockup_err(...) pr_err(GPIO_MOCKUP_NAME ": " __VA_ARGS__) @@ -59,13 +62,6 @@ struct gpio_mockup_dbgfs_private { int offset; }; -struct gpio_mockup_platform_data { - int base; - int ngpio; - int index; - bool named_lines; -}; - static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_RANGES]; static int gpio_mockup_num_ranges; module_param_array(gpio_mockup_ranges, int, &gpio_mockup_num_ranges, 0400); @@ -255,26 +251,37 @@ static int gpio_mockup_name_lines(struct device *dev, static int gpio_mockup_probe(struct platform_device *pdev) { - struct gpio_mockup_platform_data *pdata; struct gpio_mockup_chip *chip; struct gpio_chip *gc; - int rv, base, ngpio; struct device *dev; - char *name; + const char *name; + int rv, base; + u16 ngpio; dev = &pdev->dev; - pdata = dev_get_platdata(dev); - base = pdata->base; - ngpio = pdata->ngpio; + + rv = device_property_read_u32(dev, "gpio-base", &base); + if (rv && rv == -ENOENT) + base = -1; + + rv = device_property_read_u16(dev, "nr-gpios", &ngpio); + if (rv) + return rv; + + rv = device_property_read_string(dev, "chip-name", &name); + if (rv) + name = NULL; chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; - name = devm_kasprintf(dev, GFP_KERNEL, "%s-%c", - pdev->name, pdata->index); - if (!name) - return -ENOMEM; + if (!name) { + name = devm_kasprintf(dev, GFP_KERNEL, + "%s-%c", pdev->name, pdev->id + 'A'); + if (!name) + return -ENOMEM; + } gc = &chip->gc; gc->base = base; @@ -295,7 +302,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (!chip->lines) return -ENOMEM; - if (pdata->named_lines) { + if (device_property_read_bool(dev, "named-gpio-lines")) { rv = gpio_mockup_name_lines(dev, chip); if (rv) return rv; @@ -339,9 +346,11 @@ static void gpio_mockup_unregister_pdevs(void) static int __init gpio_mockup_init(void) { - int i, num_chips, err = 0, index = 'A'; - struct gpio_mockup_platform_data pdata; + struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; + int i, prop, num_chips, err = 0, base; + struct platform_device_info pdevinfo; struct platform_device *pdev; + u16 ngpio; if ((gpio_mockup_num_ranges < 2) || (gpio_mockup_num_ranges % 2) || @@ -371,17 +380,28 @@ static int __init gpio_mockup_init(void) } for (i = 0; i < num_chips; i++) { - pdata.index = index++; - pdata.base = gpio_mockup_range_base(i); - pdata.ngpio = pdata.base < 0 - ? gpio_mockup_range_ngpio(i) - : gpio_mockup_range_ngpio(i) - pdata.base; - pdata.named_lines = gpio_mockup_named_lines; - - pdev = platform_device_register_resndata(NULL, - GPIO_MOCKUP_NAME, - i, NULL, 0, &pdata, - sizeof(pdata)); + memset(properties, 0, sizeof(properties)); + memset(&pdevinfo, 0, sizeof(pdevinfo)); + prop = 0; + + base = gpio_mockup_range_base(i); + if (base >= 0) + properties[prop++] = PROPERTY_ENTRY_U32("gpio-base", + base); + + ngpio = base < 0 ? gpio_mockup_range_ngpio(i) + : gpio_mockup_range_ngpio(i) - base; + properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio); + + if (gpio_mockup_named_lines) + properties[prop++] = PROPERTY_ENTRY_BOOL( + "named-gpio-lines"); + + pdevinfo.name = GPIO_MOCKUP_NAME; + pdevinfo.id = i; + pdevinfo.properties = properties; + + pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) { gpio_mockup_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver);