Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3151956imu; Fri, 18 Jan 2019 05:46:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN5cHOTbBqV1g+/NiMIWsatbRWIYxXVde2qvJBZlcHhUvtMcsms6CejIAPZbqr9tkOuLlxB5 X-Received: by 2002:a63:235f:: with SMTP id u31mr17640867pgm.122.1547819171531; Fri, 18 Jan 2019 05:46:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547819171; cv=none; d=google.com; s=arc-20160816; b=QHAcVtnvCUpNnHGnPPXUzNqE/TWptEnFfZ/kH7PVr4a8ptMt9sFZVqbMxrxEU+50aB uOSg4zzqgEand6XVNJzqMMIQDIaWAHoEPtzVLFmjeooywy05bH7J1d6Mx+ZoNyFZt9qq Coj+QFmfr1crDYtjViThG4RotXOBybaThe5MsV8EwL0WSHcmQKs+39hbeVEmnX2ZcQl5 UA05A3mzWGAdsOAJH+IQk0WZnkLkeyEtaveYLvSAUELrRko5keZJibUWur861rA6bh9b 7CFhcMNOtvZPO1/RiRrPghIl7oTvxMcpGt7jARKBcFQNNmjQeReTalPsRWo232Qel28i mJZQ== 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=b7GG3XEgt2NPOKiP92/4vQ+rpuGmgCrv8THIa/2i3M8=; b=xG/hl6AgIELm18R26F7WKQGxld5owzEcZnrERzLtCw2DdFYYIIIq7rXjOOjBZ1RNej +ETi3XoPj6Av09DpBJZqVcg2TNrpyo8uyPHwOAGouJFsPQJ+skAnOkDfpnQXmTmmXVo7 9q1n/EyazJu525s1Fr0yojJL/rdsU8PkvtJ7m6GBs9seazX63HxFYvO1yh1jAAdPIiS9 M9aoe374HjJBtunp8wwV6q9WC1NBV9BAVfOmV1x7+y11NX3pijoAfb0Kl6x+R3GbRn/y Awsw4eCsZRWUmJckQDv/ZLmulSyqanrb7hvAO2I183cDD6Fs8QFe30W7BVa72zx2nc60 hNdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=12lAkieX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i129si5232726pfb.32.2019.01.18.05.45.56; Fri, 18 Jan 2019 05:46:11 -0800 (PST) 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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=12lAkieX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727980AbfARNnn (ORCPT + 99 others); Fri, 18 Jan 2019 08:43:43 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45308 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727835AbfARNnU (ORCPT ); Fri, 18 Jan 2019 08:43:20 -0500 Received: by mail-wr1-f68.google.com with SMTP id t6so15067563wrr.12 for ; Fri, 18 Jan 2019 05:43:18 -0800 (PST) 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=b7GG3XEgt2NPOKiP92/4vQ+rpuGmgCrv8THIa/2i3M8=; b=12lAkieXrNDGb7HTzAtpPk9S+qAtpbmIEuA3xr/ammLkT0cEZB4U2M+TTVMLmvp72K CPJ/YAK3sFhOj1DPXuEMIkLRsMdNccN61gy9/lUG5V9gjvq5r8AHbpygjlPNKvi1aWWY Dm7hsczYpsg2+2OFjxr5rN4gLd01RiJ0EJHFvLf7Bs/fSjQJVPQsqCsMUgflnnSHj4dM I4ZXnuHpGvdpSmblAfaOg3U6JeeYN4rwKhe8f1nf7T3ArDCGQlg6bcSH35p0hv62V4nE 6xhVPucFMdNPkY7TxhfbyMtlPQmA6/dAJUtqKTd4wyBR5XTWXBNlgyLdKjIGnJI/JPYG W+HA== 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=b7GG3XEgt2NPOKiP92/4vQ+rpuGmgCrv8THIa/2i3M8=; b=oeandz+4uNmRr1f8k441RgtzEJ5r9RspHQ5zIHxOhffACNM/X7HfjUMi6rYB2YRtR/ J54CfPOjaok/pNxFBNI1a6FSHoSMq/cZt/cGNexRCiezAmnmKx/j+tjonDqwQfp9s5PT 8OyeNOV0bz9myrT9NNqQDWiJYGApjyQRuaWht0FTrqjf9KJ5EQWauGwZNSiR0h3yvnjr A7sHDxVlLBi+JAIsdd902Y6hKrBUTuCeOWpjeNSFHZPdU2fICxzf+PszsJ+tBdUiIYT9 vBmVW0uSaLAcpcFYs6SXHegEedI34H88ddR1vOw9QDW8DVuP+69SAMraFbl0/AZXFDPy DYDg== X-Gm-Message-State: AJcUuke/svBVcRJ777HvnS9CZlTPDpdSiwkiI23KgPceyEHPon+37VXd UrCVY3Xcxk1aaiGCyhuHeHO+/A== X-Received: by 2002:a5d:4586:: with SMTP id p6mr16107044wrq.69.1547818997498; Fri, 18 Jan 2019 05:43:17 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id a132sm51033934wmh.5.2019.01.18.05.43.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 05:43:16 -0800 (PST) From: Bartosz Golaszewski To: Rob Herring , Mark Rutland , Linus Walleij , Dmitry Torokhov , Jacek Anaszewski , Pavel Machek , Lee Jones , Sebastian Reichel , Liam Girdwood , Mark Brown , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 10/13] gpio: max77650: add GPIO support Date: Fri, 18 Jan 2019 14:42:41 +0100 Message-Id: <20190118134244.22253-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190118134244.22253-1-brgl@bgdev.pl> References: <20190118134244.22253-1-brgl@bgdev.pl> 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 From: Bartosz Golaszewski Add GPIO support for max77650 mfd device. This PMIC exposes a single GPIO line. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/Kconfig | 7 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-max77650.c | 189 +++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 drivers/gpio/gpio-max77650.c diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index b5a2845347ec..fb297fe5bfec 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1095,6 +1095,13 @@ config GPIO_MAX77620 driver also provides interrupt support for each of the gpios. Say yes here to enable the max77620 to be used as gpio controller. +config GPIO_MAX77650 + tristate "Maxim MAX77650/77651 GPIO support" + depends on MFD_MAX77650 + help + GPIO driver for MAX77650/77651 PMIC from Maxim Semiconductor. + These chips have a single pin that can be configured as GPIO. + config GPIO_MSIC bool "Intel MSIC mixed signal gpio support" depends on (X86 || COMPILE_TEST) && MFD_INTEL_MSIC diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 37628f8dbf70..8bdad50db822 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -78,6 +78,7 @@ obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o obj-$(CONFIG_GPIO_MAX77620) += gpio-max77620.o +obj-$(CONFIG_GPIO_MAX77650) += gpio-max77650.o obj-$(CONFIG_GPIO_MB86S7X) += gpio-mb86s7x.o obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o diff --git a/drivers/gpio/gpio-max77650.c b/drivers/gpio/gpio-max77650.c new file mode 100644 index 000000000000..f8fe2b083e4d --- /dev/null +++ b/drivers/gpio/gpio-max77650.c @@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 BayLibre SAS + * Author: Bartosz Golaszewski + * + * GPIO driver for MAXIM 77650/77651 charger/power-supply. + */ + +#include +#include +#include +#include +#include +#include + +#define MAX77650_GPIO_DIR_MASK BIT(0) +#define MAX77650_GPIO_INVAL_MASK BIT(1) +#define MAX77650_GPIO_DRV_MASK BIT(2) +#define MAX77650_GPIO_OUTVAL_MASK BIT(3) +#define MAX77650_GPIO_DEBOUNCE_MASK BIT(4) + +#define MAX77650_GPIO_DIR_OUT 0x00 +#define MAX77650_GPIO_DIR_IN BIT(0) +#define MAX77650_GPIO_OUT_LOW 0x00 +#define MAX77650_GPIO_OUT_HIGH BIT(3) +#define MAX77650_GPIO_DRV_OPEN_DRAIN 0x00 +#define MAX77650_GPIO_DRV_PUSH_PULL BIT(2) +#define MAX77650_GPIO_DEBOUNCE BIT(4) + +#define MAX77650_GPIO_DIR_BITS(_reg) \ + ((_reg) & MAX77650_GPIO_DIR_MASK) +#define MAX77650_GPIO_INVAL_BITS(_reg) \ + (((_reg) & MAX77650_GPIO_INVAL_MASK) >> 1) + +struct max77650_gpio_chip { + struct regmap *map; + struct regmap_irq_chip_data *irq_chip_data; + struct gpio_chip gc; +}; + +static int max77650_gpio_direction_input(struct gpio_chip *gc, + unsigned int offset) +{ + struct max77650_gpio_chip *chip = gpiochip_get_data(gc); + + return regmap_update_bits(chip->map, + MAX77650_REG_CNFG_GPIO, + MAX77650_GPIO_DIR_MASK, + MAX77650_GPIO_DIR_IN); +} + +static int max77650_gpio_direction_output(struct gpio_chip *gc, + unsigned int offset, int value) +{ + struct max77650_gpio_chip *chip = gpiochip_get_data(gc); + int mask, regval; + + mask = MAX77650_GPIO_DIR_MASK | MAX77650_GPIO_OUTVAL_MASK; + regval = value ? MAX77650_GPIO_OUT_HIGH : MAX77650_GPIO_OUT_LOW; + regval |= MAX77650_GPIO_DIR_OUT; + + return regmap_update_bits(chip->map, + MAX77650_REG_CNFG_GPIO, mask, regval); +} + +static void max77650_gpio_set_value(struct gpio_chip *gc, + unsigned int offset, int value) +{ + struct max77650_gpio_chip *chip = gpiochip_get_data(gc); + int rv, regval; + + regval = value ? MAX77650_GPIO_OUT_HIGH : MAX77650_GPIO_OUT_LOW; + + rv = regmap_update_bits(chip->map, MAX77650_REG_CNFG_GPIO, + MAX77650_GPIO_OUTVAL_MASK, regval); + if (rv) + dev_err(gc->parent, "cannot set GPIO value: %d\n", rv); +} + +static int max77650_gpio_get_value(struct gpio_chip *gc, + unsigned int offset) +{ + struct max77650_gpio_chip *chip = gpiochip_get_data(gc); + unsigned int val; + int rv; + + rv = regmap_read(chip->map, MAX77650_REG_CNFG_GPIO, &val); + if (rv) + return rv; + + return MAX77650_GPIO_INVAL_BITS(val); +} + +static int max77650_gpio_get_direction(struct gpio_chip *gc, + unsigned int offset) +{ + struct max77650_gpio_chip *chip = gpiochip_get_data(gc); + unsigned int val; + int rv; + + rv = regmap_read(chip->map, MAX77650_REG_CNFG_GPIO, &val); + if (rv) + return rv; + + return MAX77650_GPIO_DIR_BITS(val); +} + +static int max77650_gpio_set_config(struct gpio_chip *gc, + unsigned int offset, unsigned long cfg) +{ + struct max77650_gpio_chip *chip = gpiochip_get_data(gc); + + switch (pinconf_to_config_param(cfg)) { + case PIN_CONFIG_DRIVE_OPEN_DRAIN: + return regmap_update_bits(chip->map, + MAX77650_REG_CNFG_GPIO, + MAX77650_GPIO_DRV_MASK, + MAX77650_GPIO_DRV_OPEN_DRAIN); + case PIN_CONFIG_DRIVE_PUSH_PULL: + return regmap_update_bits(chip->map, + MAX77650_REG_CNFG_GPIO, + MAX77650_GPIO_DRV_MASK, + MAX77650_GPIO_DRV_PUSH_PULL); + case PIN_CONFIG_INPUT_DEBOUNCE: + return regmap_update_bits(chip->map, + MAX77650_REG_CNFG_GPIO, + MAX77650_GPIO_DEBOUNCE_MASK, + MAX77650_GPIO_DEBOUNCE); + default: + return -ENOTSUPP; + } +} + +static int max77650_gpio_to_irq(struct gpio_chip *gc, unsigned int offset) +{ + struct max77650_gpio_chip *chip = gpiochip_get_data(gc); + + return regmap_irq_get_virq(chip->irq_chip_data, MAX77650_INT_GPI); +} + +static int max77650_gpio_probe(struct platform_device *pdev) +{ + struct max77650_gpio_chip *chip; + struct device *dev, *parent; + struct i2c_client *i2c; + + dev = &pdev->dev; + parent = dev->parent; + i2c = to_i2c_client(parent); + + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->map = dev_get_regmap(parent, NULL); + if (!chip->map) + return -ENODEV; + + chip->irq_chip_data = i2c_get_clientdata(i2c); + + chip->gc.base = -1; + chip->gc.ngpio = 1; + chip->gc.label = i2c->name; + chip->gc.parent = dev; + chip->gc.owner = THIS_MODULE; + chip->gc.can_sleep = true; + + chip->gc.direction_input = max77650_gpio_direction_input; + chip->gc.direction_output = max77650_gpio_direction_output; + chip->gc.set = max77650_gpio_set_value; + chip->gc.get = max77650_gpio_get_value; + chip->gc.get_direction = max77650_gpio_get_direction; + chip->gc.set_config = max77650_gpio_set_config; + chip->gc.to_irq = max77650_gpio_to_irq; + + return devm_gpiochip_add_data(dev, &chip->gc, chip); +} + +static struct platform_driver max77650_gpio_driver = { + .driver = { + .name = "max77650-gpio", + }, + .probe = max77650_gpio_probe, +}; +module_platform_driver(max77650_gpio_driver); + +MODULE_DESCRIPTION("MAXIM 77650/77651 GPIO driver"); +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_LICENSE("GPL"); -- 2.19.1