From patchwork Wed May 26 06:10:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vaittinen, Matti" X-Patchwork-Id: 12280675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D252C2B9F7 for ; Wed, 26 May 2021 06:12:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C35E2613BA for ; Wed, 26 May 2021 06:12:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C35E2613BA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=fi.rohmeurope.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JIlf7mZ3FENjuqliosARas70Vvf8gQGPMCxmiKp9GZI=; b=IS7UHCV0NHqEZgpFS0uEUTDvC6 JfN759MoG5aPTuBqG2H8sUlKFDgeWE/nXcp3LdcBQVjppjrU6Z3+quWifz9AUsDpbwEgPe4inHosi WOHsSJXxaZN0cLzvwgBVLPI7X1N7L4YKqJiGP0Cxb61/FQYISIW4s7I1HbJYvUPjmgzQM5PXWuxq7 +H3iGVW5zbJi+xFeMnaYKJKJ4FHF+1CT8/9+tT85fpgbNtIOOHICgnA6A5QHH9mlJ7bVmflOF22tH sjUFT9DEMqJwcbEIzOfYoUo1NHb1rjsGzWL8cMmREIakVu03FcKoWk49+rMpNKiQdBKptfsXszTj9 KXSgLWLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llmkx-00BTab-Ib; Wed, 26 May 2021 06:11:03 +0000 Received: from mail-lf1-f47.google.com ([209.85.167.47]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1llmkn-00BTW1-1b for linux-arm-kernel@lists.infradead.org; Wed, 26 May 2021 06:10:54 +0000 Received: by mail-lf1-f47.google.com with SMTP id q1so785469lfo.3 for ; Tue, 25 May 2021 23:10:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7XFftguTcFQmlVkEMCNxVmipWHmtjK7hc0l8K1kFIUo=; b=V0kJc6wsAIGRANTRn1i51V2AQGqfIA6qdBsenr4zO25iFjej/oj06KWOQncllVXvk1 m3DvfIh8lkU0jf5aN21WHAAQY/Wgs0nLQ7LsSHde7A3lXzV6apHLRqgjRF3Qnh4r+GFY MnGsgeLnc9WoLZ6lzZDBFSSLnyReP/5/wClEF5cTRiGiD1/uUeqMsL/nKKDKH2liHRfs 7uPD1h8m7mhe1ESH8ztnMzCe2FCUFcJSJ1Q5ry6sBnhBAUwmrOs3qqcNM5AGjXH4ThDB kcRpzSoDYw97FByLYYkkNrPEmMTLGV+Q0makqByqg8GtnI5Rgdt2sFpWbJ7BCs/k+kJX LJ5Q== X-Gm-Message-State: AOAM531VycqlAZQf5vcmp9DYi1VKBrCUuudvhww1QYrR4mLmSZFuZ9ur 4Y8lgZQoLxEaksjWt0sLoqY= X-Google-Smtp-Source: ABdhPJxapYgCnSiU10EAGd5tm0TnaHp1gKF0IF4Qk7XditaD2JZZTrGgZbGH9PeqaTPuPVDgi2OsAA== X-Received: by 2002:a05:6512:3456:: with SMTP id j22mr1089312lfr.532.1622009451277; Tue, 25 May 2021 23:10:51 -0700 (PDT) Received: from localhost.localdomain (dc7vkhyyyyyyyyyyyyycy-3.rev.dnainternet.fi. [2001:14ba:16e2:8300::4]) by smtp.gmail.com with ESMTPSA id v21sm361009lfe.255.2021.05.25.23.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 23:10:50 -0700 (PDT) Date: Wed, 26 May 2021 09:10:45 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Linus Walleij , Bartosz Golaszewski , Matti Vaittinen , Michael Walle , Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, Jonas Gorski , =?iso-8859-1?q?=C1lvaro_Fern=E1ndez?= Rojas , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-power@fi.rohmeurope.com, linux-arm-kernel@lists.infradead.org, Andy Shevchenko Subject: [PATCH v4 3/3] gpio: bd71815: Use gpio-regmap Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210525_231053_145042_5C49EB26 X-CRM114-Status: GOOD ( 28.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Utilize the gpio-regmap helper and drop the custom functions Signed-off-by: Matti Vaittinen --- Changelog v3: - gpio: Adapt to changes in gpio_regmap --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-bd71815.c | 121 +++++++++--------------------------- 2 files changed, 32 insertions(+), 90 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 1dd0ec6727fd..97e1348cd410 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1120,6 +1120,7 @@ config GPIO_BD70528 config GPIO_BD71815 tristate "ROHM BD71815 PMIC GPIO support" depends on MFD_ROHM_BD71828 + select GPIO_REGMAP help Support for GPO(s) on ROHM BD71815 PMIC. There are two GPOs available on the ROHM PMIC. diff --git a/drivers/gpio/gpio-bd71815.c b/drivers/gpio/gpio-bd71815.c index 08ff2857256f..45782d376b3d 100644 --- a/drivers/gpio/gpio-bd71815.c +++ b/drivers/gpio/gpio-bd71815.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -17,82 +18,30 @@ /* For the BD71815 register definitions */ #include -struct bd71815_gpio { - /* chip.parent points the MFD which provides DT node and regmap */ - struct gpio_chip chip; - /* dev points to the platform device for devm and prints */ - struct device *dev; - struct regmap *regmap; -}; - -static int bd71815gpo_get(struct gpio_chip *chip, unsigned int offset) +static int bd71815_gpio_set_config(const struct gpio_regmap_config *gr_config, + unsigned int offset, unsigned long config) { - struct bd71815_gpio *bd71815 = gpiochip_get_data(chip); - int ret, val; - - ret = regmap_read(bd71815->regmap, BD71815_REG_GPO, &val); - if (ret) - return ret; - - return (val >> offset) & 1; -} - -static void bd71815gpo_set(struct gpio_chip *chip, unsigned int offset, - int value) -{ - struct bd71815_gpio *bd71815 = gpiochip_get_data(chip); - int ret, bit; - - bit = BIT(offset); - - if (value) - ret = regmap_set_bits(bd71815->regmap, BD71815_REG_GPO, bit); - else - ret = regmap_clear_bits(bd71815->regmap, BD71815_REG_GPO, bit); - - if (ret) - dev_warn(bd71815->dev, "failed to toggle GPO\n"); -} - -static int bd71815_gpio_set_config(struct gpio_chip *chip, unsigned int offset, - unsigned long config) -{ - struct bd71815_gpio *bdgpio = gpiochip_get_data(chip); + struct regmap *regmap = gr_config->regmap; switch (pinconf_to_config_param(config)) { case PIN_CONFIG_DRIVE_OPEN_DRAIN: - return regmap_update_bits(bdgpio->regmap, + return regmap_update_bits(regmap, BD71815_REG_GPO, BD71815_GPIO_DRIVE_MASK << offset, BD71815_GPIO_OPEN_DRAIN << offset); case PIN_CONFIG_DRIVE_PUSH_PULL: - return regmap_update_bits(bdgpio->regmap, + return regmap_update_bits(regmap, BD71815_REG_GPO, BD71815_GPIO_DRIVE_MASK << offset, BD71815_GPIO_CMOS << offset); default: + dev_err(gr_config->parent, "Unsupported config (0x%lx)\n", + config); break; } return -ENOTSUPP; } -/* BD71815 GPIO is actually GPO */ -static int bd71815gpo_direction_get(struct gpio_chip *gc, unsigned int offset) -{ - return GPIO_LINE_DIRECTION_OUT; -} - -/* Template for GPIO chip */ -static const struct gpio_chip bd71815gpo_chip = { - .label = "bd71815", - .owner = THIS_MODULE, - .get = bd71815gpo_get, - .get_direction = bd71815gpo_direction_get, - .set = bd71815gpo_set, - .set_config = bd71815_gpio_set_config, - .can_sleep = true, -}; - #define BD71815_TWO_GPIOS GENMASK(1, 0) #define BD71815_ONE_GPIO BIT(0) @@ -111,15 +60,17 @@ static const struct gpio_chip bd71815gpo_chip = { * but allows using it by providing the DT property * "rohm,enable-hidden-gpo". */ -static int bd71815_init_valid_mask(struct gpio_chip *gc, +static int bd71815_init_valid_mask(const struct gpio_regmap_config *c, unsigned long *valid_mask, unsigned int ngpios) { + if (ngpios != 2) return 0; - if (gc->parent && device_property_present(gc->parent, - "rohm,enable-hidden-gpo")) + /* The property should be in MFD DT node */ + if (c->parent && fwnode_property_present(c->fwnode, + "rohm,enable-hidden-gpo")) *valid_mask = BD71815_TWO_GPIOS; else *valid_mask = BD71815_ONE_GPIO; @@ -127,9 +78,21 @@ static int bd71815_init_valid_mask(struct gpio_chip *gc, return 0; } +/* Template for regmap gpio config */ +static const struct gpio_regmap_config gpio_cfg_template = { + .label = "bd71815", + .reg_set_base = BD71815_REG_GPO, + .ngpio = 2, +}; + +static const struct gpio_regmap_ops ops = { + .set_config = bd71815_gpio_set_config, + .init_valid_mask = bd71815_init_valid_mask, +}; + static int gpo_bd71815_probe(struct platform_device *pdev) { - struct bd71815_gpio *g; + struct gpio_regmap_config cfg; struct device *parent, *dev; /* @@ -140,34 +103,12 @@ static int gpo_bd71815_probe(struct platform_device *pdev) /* The device-tree and regmap come from MFD => use parent for that */ parent = dev->parent; - g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL); - if (!g) - return -ENOMEM; - - g->chip = bd71815gpo_chip; - - /* - * FIXME: As writing of this the sysfs interface for GPIO control does - * not respect the valid_mask. Do not trust it but rather set the ngpios - * to 1 if "rohm,enable-hidden-gpo" is not given. - * - * This check can be removed later if the sysfs export is fixed and - * if the fix is backported. - * - * For now it is safest to just set the ngpios though. - */ - if (device_property_present(parent, "rohm,enable-hidden-gpo")) - g->chip.ngpio = 2; - else - g->chip.ngpio = 1; - - g->chip.init_valid_mask = bd71815_init_valid_mask; - g->chip.base = -1; - g->chip.parent = parent; - g->regmap = dev_get_regmap(parent, NULL); - g->dev = dev; + cfg = gpio_cfg_template; + cfg.parent = parent; + cfg.regmap = dev_get_regmap(parent, NULL); + cfg.fwnode = dev_fwnode(dev); - return devm_gpiochip_add_data(dev, &g->chip, g); + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &cfg, &ops)); } static struct platform_driver gpo_bd71815_driver = {