Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp344448pxu; Tue, 5 Jan 2021 12:35:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmJqWChm/v2b9vlGH+cDcdnitCb6PXHRx5aSEBAkuHDgCwdpm+HZSBR4ki9uT9Ywtzxfbu X-Received: by 2002:a17:906:e250:: with SMTP id gq16mr752245ejb.382.1609878900202; Tue, 05 Jan 2021 12:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609878900; cv=none; d=google.com; s=arc-20160816; b=CPuoGRvnJD0otXOxRE4J6gg3PhQr+9zybXvXJVYbs2f08Jk8Dc02jmqj2dU1xwS3Wt aZ68InrsqzwjbcPAAm0juuid7IYIw1lJ69AcqHgQHd8YVz65jZuJ+9seAbhbSXdw5KWN BhBt2PHEq0KIZKiJKmegmkx3CRhE8PSdNli9WoS8cuOSalmrxzjJ1z3ctaAztgnLiUiM z9hadt2Lc45Q8cRgUEJ4SESo9PjXgWli3sUlgnPpqAfbcYmo2Gdy6sD3S0AouiVMOrQU bKe4yl1s3useVy8CTG+c1UeVSvcrx8jhwu7nf187sWnVreoBsu8ihnTP96apME0K3eZu F5EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=wgEJw0Gi7656t3/rv1rBSKj4Jy3xKXdQbpqBhq9DA4M=; b=oqoQ7+ZkuA8K8GWJsOn9z4FSdDhGqvEcrDCF95vDO5y591xW4mV8WrvKHM2vtC0ATm hq9wPfVqzwob25f60LyathAek2AWRLiROcSNVyAlawE/mSk57RBBEwWmNKa+1UQ2nQgg zVfU6jU5sb+/tnyoCg52Axj7hlAPQjxWALL/HWmNaWYP8GlNtTVfMmIyUBFoV5E2v5ql s0xf1E5wA/RerGzS+ceXAGCmtfKQs7juQsOgNABZiMlqA2CaKLfMlQGbCBu6uEqqx6D5 XCiArOh0dKGwCqzQFM9iYaMWivlVU7/WKoBPMrOtjPvSd7O4Pilr7hh7lcqfypi43rgQ Bmww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c35si57461edf.522.2021.01.05.12.34.36; Tue, 05 Jan 2021 12:35:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729398AbhAEMy1 (ORCPT + 99 others); Tue, 5 Jan 2021 07:54:27 -0500 Received: from mail-lf1-f44.google.com ([209.85.167.44]:40180 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728006AbhAEMy0 (ORCPT ); Tue, 5 Jan 2021 07:54:26 -0500 Received: by mail-lf1-f44.google.com with SMTP id m12so72296218lfo.7; Tue, 05 Jan 2021 04:54:08 -0800 (PST) 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:mime-version :content-disposition; bh=wgEJw0Gi7656t3/rv1rBSKj4Jy3xKXdQbpqBhq9DA4M=; b=P20J6N/f/WDeIopDrafLbxGyEmnLsPs8ET9Sm90ec81NL/VbAzVmz19pSvKwYxuYRY Jrn0VAv50zHtrQjedbrwGfgoIRZ6H6ZdNA/XFTBGKyAbUH9cPbWY3+YTw8k5CWyKZPFm 93L3i4y5/Lu92+Y2zuKiLICFu0u4TLVv6crI1GZtaxM5P4rwQOPBpRfIm2iebwauYYB8 4tgQI/EaZzmDfc4Kj4byE9dzAiUriLksR41/gqsbJQJ1ihsCd+qx9PV8r24GWNgBPhF0 axWaavXMKF91mruK+E7eZCZRHNqblHhwGUYeOkZowgXqz0YPTlSsc+hjWifh3X8wTi+J Ny8g== X-Gm-Message-State: AOAM532Dgsr4kaHCORrfgSW1q4g5yXjeBr1KdKjKzllZ/Iv7ntpp5CeW UyCXqpfJZMCZ70x8GcPObnnvrKh+7mc= X-Received: by 2002:a19:3f12:: with SMTP id m18mr31690957lfa.519.1609851223026; Tue, 05 Jan 2021 04:53:43 -0800 (PST) Received: from localhost.localdomain (62-78-225-252.bb.dnainternet.fi. [62.78.225.252]) by smtp.gmail.com with ESMTPSA id l15sm4342029lfc.244.2021.01.05.04.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 04:53:42 -0800 (PST) Date: Tue, 5 Jan 2021 14:53:35 +0200 From: Matti Vaittinen To: matti.vaittinen@fi.rohmeurope.com, mazziesaccount@gmail.com Cc: Linus Walleij , Bartosz Golaszewski , linux-power@fi.rohmeurope.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] gpio: bd7xxxx: Do not depend on parent driver data Message-ID: <20210105125335.GA3430233@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ROHM BD70528 and BD71828 GPIO drivers only need the regmap pointer from parent. Regmap can be obtained via dev_get_regmap() so do not require parent to populate driver data for that. Signed-off-by: Matti Vaittinen --- drivers/gpio/gpio-bd70528.c | 46 +++++++++++++++++-------------------- drivers/gpio/gpio-bd71828.c | 28 ++++++++++------------ 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/drivers/gpio/gpio-bd70528.c b/drivers/gpio/gpio-bd70528.c index 45b3da8da336..276a0fe6346d 100644 --- a/drivers/gpio/gpio-bd70528.c +++ b/drivers/gpio/gpio-bd70528.c @@ -12,7 +12,8 @@ #define GPIO_OUT_REG(offset) (BD70528_REG_GPIO1_OUT + (offset) * 2) struct bd70528_gpio { - struct rohm_regmap_dev chip; + struct regmap *regmap; + struct device *dev; struct gpio_chip gpio; }; @@ -35,11 +36,11 @@ static int bd70528_set_debounce(struct bd70528_gpio *bdgpio, val = BD70528_DEBOUNCE_50MS; break; default: - dev_err(bdgpio->chip.dev, + dev_err(bdgpio->dev, "Invalid debounce value %u\n", debounce); return -EINVAL; } - return regmap_update_bits(bdgpio->chip.regmap, GPIO_IN_REG(offset), + return regmap_update_bits(bdgpio->regmap, GPIO_IN_REG(offset), BD70528_DEBOUNCE_MASK, val); } @@ -49,9 +50,9 @@ static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset) int val, ret; /* Do we need to do something to IRQs here? */ - ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val); + ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), &val); if (ret) { - dev_err(bdgpio->chip.dev, "Could not read gpio direction\n"); + dev_err(bdgpio->dev, "Could not read gpio direction\n"); return ret; } if (val & BD70528_GPIO_OUT_EN_MASK) @@ -67,13 +68,13 @@ static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset, switch (pinconf_to_config_param(config)) { case PIN_CONFIG_DRIVE_OPEN_DRAIN: - return regmap_update_bits(bdgpio->chip.regmap, + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD70528_GPIO_DRIVE_MASK, BD70528_GPIO_OPEN_DRAIN); break; case PIN_CONFIG_DRIVE_PUSH_PULL: - return regmap_update_bits(bdgpio->chip.regmap, + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD70528_GPIO_DRIVE_MASK, BD70528_GPIO_PUSH_PULL); @@ -93,7 +94,7 @@ static int bd70528_direction_input(struct gpio_chip *chip, unsigned int offset) struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); /* Do we need to do something to IRQs here? */ - return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD70528_GPIO_OUT_EN_MASK, BD70528_GPIO_OUT_DISABLE); } @@ -105,10 +106,10 @@ static void bd70528_gpio_set(struct gpio_chip *chip, unsigned int offset, struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); u8 val = (value) ? BD70528_GPIO_OUT_HI : BD70528_GPIO_OUT_LO; - ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), + ret = regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD70528_GPIO_OUT_MASK, val); if (ret) - dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value); + dev_err(bdgpio->dev, "Could not set gpio to %d\n", value); } static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset, @@ -117,7 +118,7 @@ static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset, struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); bd70528_gpio_set(chip, offset, value); - return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD70528_GPIO_OUT_EN_MASK, BD70528_GPIO_OUT_ENABLE); } @@ -129,11 +130,11 @@ static int bd70528_gpio_get_o(struct bd70528_gpio *bdgpio, unsigned int offset) int ret; unsigned int val; - ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val); + ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), &val); if (!ret) ret = !!(val & BD70528_GPIO_OUT_MASK); else - dev_err(bdgpio->chip.dev, "GPIO (out) state read failed\n"); + dev_err(bdgpio->dev, "GPIO (out) state read failed\n"); return ret; } @@ -143,12 +144,12 @@ static int bd70528_gpio_get_i(struct bd70528_gpio *bdgpio, unsigned int offset) unsigned int val; int ret; - ret = regmap_read(bdgpio->chip.regmap, BD70528_REG_GPIO_STATE, &val); + ret = regmap_read(bdgpio->regmap, BD70528_REG_GPIO_STATE, &val); if (!ret) ret = !(val & GPIO_IN_STATE_MASK(offset)); else - dev_err(bdgpio->chip.dev, "GPIO (in) state read failed\n"); + dev_err(bdgpio->dev, "GPIO (in) state read failed\n"); return ret; } @@ -173,7 +174,7 @@ static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset) else if (ret == GPIO_LINE_DIRECTION_IN) ret = bd70528_gpio_get_i(bdgpio, offset); else - dev_err(bdgpio->chip.dev, "failed to read GPIO direction\n"); + dev_err(bdgpio->dev, "failed to read GPIO direction\n"); return ret; } @@ -181,20 +182,13 @@ static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset) static int bd70528_probe(struct platform_device *pdev) { struct bd70528_gpio *bdgpio; - struct rohm_regmap_dev *bd70528; int ret; - bd70528 = dev_get_drvdata(pdev->dev.parent); - if (!bd70528) { - dev_err(&pdev->dev, "No MFD driver data\n"); - return -EINVAL; - } - bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio), GFP_KERNEL); if (!bdgpio) return -ENOMEM; - bdgpio->chip.dev = &pdev->dev; + bdgpio->dev = &pdev->dev; bdgpio->gpio.parent = pdev->dev.parent; bdgpio->gpio.label = "bd70528-gpio"; bdgpio->gpio.owner = THIS_MODULE; @@ -210,7 +204,9 @@ static int bd70528_probe(struct platform_device *pdev) #ifdef CONFIG_OF_GPIO bdgpio->gpio.of_node = pdev->dev.parent->of_node; #endif - bdgpio->chip.regmap = bd70528->regmap; + bdgpio->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!bdgpio->regmap) + return -ENODEV; ret = devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio, bdgpio); diff --git a/drivers/gpio/gpio-bd71828.c b/drivers/gpio/gpio-bd71828.c index 3dbbc638e9a9..fcdcbb57c76d 100644 --- a/drivers/gpio/gpio-bd71828.c +++ b/drivers/gpio/gpio-bd71828.c @@ -11,7 +11,8 @@ #define HALL_GPIO_OFFSET 3 struct bd71828_gpio { - struct rohm_regmap_dev chip; + struct regmap *regmap; + struct device *dev; struct gpio_chip gpio; }; @@ -29,10 +30,10 @@ static void bd71828_gpio_set(struct gpio_chip *chip, unsigned int offset, if (offset == HALL_GPIO_OFFSET) return; - ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), + ret = regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD71828_GPIO_OUT_MASK, val); if (ret) - dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value); + dev_err(bdgpio->dev, "Could not set gpio to %d\n", value); } static int bd71828_gpio_get(struct gpio_chip *chip, unsigned int offset) @@ -42,10 +43,10 @@ static int bd71828_gpio_get(struct gpio_chip *chip, unsigned int offset) struct bd71828_gpio *bdgpio = gpiochip_get_data(chip); if (offset == HALL_GPIO_OFFSET) - ret = regmap_read(bdgpio->chip.regmap, BD71828_REG_IO_STAT, + ret = regmap_read(bdgpio->regmap, BD71828_REG_IO_STAT, &val); else - ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), + ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), &val); if (!ret) ret = (val & BD71828_GPIO_OUT_MASK); @@ -63,12 +64,12 @@ static int bd71828_gpio_set_config(struct gpio_chip *chip, unsigned int offset, switch (pinconf_to_config_param(config)) { case PIN_CONFIG_DRIVE_OPEN_DRAIN: - return regmap_update_bits(bdgpio->chip.regmap, + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD71828_GPIO_DRIVE_MASK, BD71828_GPIO_OPEN_DRAIN); case PIN_CONFIG_DRIVE_PUSH_PULL: - return regmap_update_bits(bdgpio->chip.regmap, + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), BD71828_GPIO_DRIVE_MASK, BD71828_GPIO_PUSH_PULL); @@ -97,20 +98,13 @@ static int bd71828_get_direction(struct gpio_chip *chip, unsigned int offset) static int bd71828_probe(struct platform_device *pdev) { struct bd71828_gpio *bdgpio; - struct rohm_regmap_dev *bd71828; - - bd71828 = dev_get_drvdata(pdev->dev.parent); - if (!bd71828) { - dev_err(&pdev->dev, "No MFD driver data\n"); - return -EINVAL; - } bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio), GFP_KERNEL); if (!bdgpio) return -ENOMEM; - bdgpio->chip.dev = &pdev->dev; + bdgpio->dev = &pdev->dev; bdgpio->gpio.parent = pdev->dev.parent; bdgpio->gpio.label = "bd71828-gpio"; bdgpio->gpio.owner = THIS_MODULE; @@ -128,7 +122,9 @@ static int bd71828_probe(struct platform_device *pdev) */ bdgpio->gpio.ngpio = 4; bdgpio->gpio.of_node = pdev->dev.parent->of_node; - bdgpio->chip.regmap = bd71828->regmap; + bdgpio->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!bdgpio->regmap) + return -ENODEV; return devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio, bdgpio); base-commit: 2c85ebc57b3e1817b6ce1a6b703928e113a90442 -- 2.25.4 -- Matti Vaittinen, Linux device drivers ROHM Semiconductors, Finland SWDC Kiviharjunlenkki 1E 90220 OULU FINLAND ~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please. ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =]