Received: by 10.223.164.202 with SMTP id h10csp989509wrb; Thu, 23 Nov 2017 09:20:58 -0800 (PST) X-Google-Smtp-Source: AGs4zMYIGx05PB0aIXLYBCUfVm7VnOYfc+PqbdZaLPYX8Uv2jUQtmsQ4XA7itQBiQ9KKgvIJRIjW X-Received: by 10.101.64.71 with SMTP id h7mr13327950pgp.144.1511457658821; Thu, 23 Nov 2017 09:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511457658; cv=none; d=google.com; s=arc-20160816; b=dy5QDHjn7czdS3kifmZyFQS/3uLMjo9W3UWVcEYxAyDXi6yv7Z+FHtWkKJuqNEvQb6 yemW0M7jXE0BhrNqBYOAJ8SPBeg8L91no60qZ7WCA2X87SYmAe3FYDscF/b85iwYSH+6 4shGuHlyUsGYeDCzmF1zK+vELMzV5dGLWAqcqvGu4YZgSeDx0J/a2W4rqGY0G602jrMA 0Kswr240ct5S1BhwadR1AOwVQFu/Z9JcQW42uzEmvoHb+8OgXQA0ZSd80kll1ESSz/cE mG7iXAsNOKUOJarnekbpMBRRmi8m6/CYx6xuZnb7ySRRPG3EEEE90kjPI5JkGAvI7rL1 mu8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=JKwBu3E89C1BtYTzbWes408Xh8dTYne3hKyoFZbg1rY=; b=auzRzLWmnvCX+UxysQP2B5Av2aF+tUr8cG1nty/a0NXNLlHB0qCxPg0hEFfTCltg5m 1C63OPeqTzqzlZimjH6s2jdA4747yvmJnHwkcxTxV208/OX8SZ1Ws8MxWvjTEgB0vCba WWLfkQuOk9+jK54O/R+NNSAfepACp9o5SVF3yHUL41lNRfLW3x8om3ng4YLCfCShZLiv cEeCpul02nQiVXK3bSzkRG4Hdc9qqcwLGcZMm9+UGAJhzgRReP16e92fpybyp6IaT5h0 2y2tyZJtjyg7hvJTPMdZb6crJv9hBboAzk3YeW4DefONIOESGXBjA0uUNe6vourfpJUb NgHw== ARC-Authentication-Results: i=1; mx.google.com; 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 m10si16466881pgt.446.2017.11.23.09.20.47; Thu, 23 Nov 2017 09:20:58 -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; 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 S1753454AbdKWRSK (ORCPT + 76 others); Thu, 23 Nov 2017 12:18:10 -0500 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:55538 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753143AbdKWRNi (ORCPT ); Thu, 23 Nov 2017 12:13:38 -0500 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vANH9HXO002497; Thu, 23 Nov 2017 11:13:27 -0600 Authentication-Results: ppops.net; spf=none smtp.mailfrom=rf@opensource.wolfsonmicro.com Received: from mail1.cirrus.com (mail1.cirrus.com [141.131.3.20]) by mx0b-001ae601.pphosted.com with ESMTP id 2ecrj59pgq-2; Thu, 23 Nov 2017 11:13:27 -0600 Received: from EX17.ad.cirrus.com (unknown [172.20.9.81]) by mail1.cirrus.com (Postfix) with ESMTP id 1AE1260D9749; Thu, 23 Nov 2017 11:13:27 -0600 (CST) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Thu, 23 Nov 2017 17:13:22 +0000 Received: from edi-sw-dsktp006.ad.cirrus.com (edi-sw-dsktp006.ad.cirrus.com [198.90.223.54]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id vANHDKxC008967; Thu, 23 Nov 2017 17:13:21 GMT From: Richard Fitzgerald To: , , , , , , CC: , , , , , Richard Fitzgerald , Nariman Poushin , Charles Keepax Subject: [PATCH v6 12/17] gpio: madera: Support Cirrus Logic Madera class codecs Date: Thu, 23 Nov 2017 17:13:11 +0000 Message-ID: <20171123171316.10868-13-rf@opensource.wolfsonmicro.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171123171316.10868-1-rf@opensource.wolfsonmicro.com> References: <20171123171316.10868-1-rf@opensource.wolfsonmicro.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711230233 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds support for the GPIOs on Cirrus Logic Madera class codecs. Any pins not used for special functions (see the pinctrl driver) can be used as general single-bit input or output lines. The number of available GPIOs varies between codecs. Signed-off-by: Nariman Poushin Signed-off-by: Richard Fitzgerald Signed-off-by: Charles Keepax Acked-by: Linus Walleij --- MAINTAINERS | 1 + drivers/gpio/Kconfig | 6 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-madera.c | 196 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 204 insertions(+) create mode 100644 drivers/gpio/gpio-madera.c diff --git a/MAINTAINERS b/MAINTAINERS index 2c6772f81d88..7f3f2de4cc44 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3490,6 +3490,7 @@ F: Documentation/devicetree/bindings/mfd/madera.txt F: Documentation/devicetree/bindings/pinctrl/cirrus,madera-pinctrl.txt F: include/linux/irqchip/irq-madera* F: include/linux/mfd/madera/* +F: drivers/gpio/gpio-madera* F: drivers/irqchip/irq-madera* F: drivers/mfd/madera* F: drivers/mfd/cs47l* diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index d6a8e851ad13..95e4bbcf9bf7 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -993,6 +993,12 @@ config GPIO_LP87565 This driver can also be built as a module. If so, the module will be called gpio-lp87565. +config GPIO_MADERA + bool "Cirrus Logic Madera class codecs" + depends on PINCTRL_MADERA + help + Support for GPIOs on Cirrus Logic Madera class codecs. + config GPIO_MAX77620 tristate "GPIO support for PMIC MAX77620 and MAX20024" depends on MFD_MAX77620 diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 4bc24febb889..765125eb7d4c 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -70,6 +70,7 @@ obj-$(CONFIG_ARCH_LPC32XX) += gpio-lpc32xx.o obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o obj-$(CONFIG_GPIO_LYNXPOINT) += gpio-lynxpoint.o +obj-$(CONFIG_GPIO_MADERA) += gpio-madera.o obj-$(CONFIG_GPIO_MAX3191X) += gpio-max3191x.o obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o diff --git a/drivers/gpio/gpio-madera.c b/drivers/gpio/gpio-madera.c new file mode 100644 index 000000000000..e45905d59238 --- /dev/null +++ b/drivers/gpio/gpio-madera.c @@ -0,0 +1,196 @@ +/* + * GPIO support for Cirrus Logic Madera codecs + * + * Copyright 2015-2017 Cirrus Logic + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +struct madera_gpio { + struct madera *madera; + struct gpio_chip gpio_chip; +}; + +static int madera_gpio_get_direction(struct gpio_chip *chip, + unsigned int offset) +{ + struct madera_gpio *madera_gpio = gpiochip_get_data(chip); + struct madera *madera = madera_gpio->madera; + unsigned int val; + int ret; + + ret = regmap_read(madera->regmap, + MADERA_GPIO1_CTRL_2 + (2 * offset), &val); + if (ret < 0) + return ret; + + return (val & MADERA_GP1_DIR_MASK) >> MADERA_GP1_DIR_SHIFT; +} + +static int madera_gpio_direction_in(struct gpio_chip *chip, unsigned int offset) +{ + struct madera_gpio *madera_gpio = gpiochip_get_data(chip); + struct madera *madera = madera_gpio->madera; + + return regmap_update_bits(madera->regmap, + MADERA_GPIO1_CTRL_2 + (2 * offset), + MADERA_GP1_DIR_MASK, MADERA_GP1_DIR); +} + +static int madera_gpio_get(struct gpio_chip *chip, unsigned int offset) +{ + struct madera_gpio *madera_gpio = gpiochip_get_data(chip); + struct madera *madera = madera_gpio->madera; + unsigned int val; + int ret; + + ret = regmap_read(madera->regmap, + MADERA_GPIO1_CTRL_1 + (2 * offset), &val); + if (ret < 0) + return ret; + + return !!(val & MADERA_GP1_LVL_MASK); +} + +static int madera_gpio_direction_out(struct gpio_chip *chip, + unsigned int offset, int value) +{ + struct madera_gpio *madera_gpio = gpiochip_get_data(chip); + struct madera *madera = madera_gpio->madera; + unsigned int regval; + int ret; + + if (value) + regval = MADERA_GP1_LVL; + else + regval = 0; + + ret = regmap_update_bits(madera->regmap, + MADERA_GPIO1_CTRL_2 + (2 * offset), + MADERA_GP1_DIR_MASK, 0); + if (ret < 0) + return ret; + + return regmap_update_bits(madera->regmap, + MADERA_GPIO1_CTRL_1 + (2 * offset), + MADERA_GP1_LVL_MASK, regval); +} + +static void madera_gpio_set(struct gpio_chip *chip, unsigned int offset, + int value) +{ + struct madera_gpio *madera_gpio = gpiochip_get_data(chip); + struct madera *madera = madera_gpio->madera; + unsigned int regval; + int ret; + + if (value) + regval = MADERA_GP1_LVL; + else + regval = 0; + + ret = regmap_update_bits(madera->regmap, + MADERA_GPIO1_CTRL_1 + (2 * offset), + MADERA_GP1_LVL_MASK, regval); + if (ret) + dev_warn(madera->dev, "Failed to write to 0x%x (%d)\n", + MADERA_GPIO1_CTRL_1 + (2 * offset), ret); +} + +static struct gpio_chip template_chip = { + .label = "madera", + .owner = THIS_MODULE, + .request = gpiochip_generic_request, + .free = gpiochip_generic_free, + .get_direction = madera_gpio_get_direction, + .direction_input = madera_gpio_direction_in, + .get = madera_gpio_get, + .direction_output = madera_gpio_direction_out, + .set = madera_gpio_set, + .set_config = gpiochip_generic_config, + .can_sleep = true, +}; + +static int madera_gpio_probe(struct platform_device *pdev) +{ + struct madera *madera = dev_get_drvdata(pdev->dev.parent); + struct madera_pdata *pdata = dev_get_platdata(madera->dev); + struct madera_gpio *madera_gpio; + int ret; + + madera_gpio = devm_kzalloc(&pdev->dev, sizeof(*madera_gpio), + GFP_KERNEL); + if (!madera_gpio) + return -ENOMEM; + + madera_gpio->madera = madera; + madera_gpio->gpio_chip = template_chip; + madera_gpio->gpio_chip.parent = &pdev->dev; + + if (IS_ENABLED(CONFIG_OF_GPIO)) + madera_gpio->gpio_chip.of_node = madera->dev->of_node; + + switch (madera->type) { + case CS47L35: + madera_gpio->gpio_chip.ngpio = CS47L35_NUM_GPIOS; + break; + case CS47L85: + case WM1840: + madera_gpio->gpio_chip.ngpio = CS47L85_NUM_GPIOS; + break; + case CS47L90: + case CS47L91: + madera_gpio->gpio_chip.ngpio = CS47L90_NUM_GPIOS; + break; + default: + dev_err(&pdev->dev, "Unknown chip variant %d\n", madera->type); + return -EINVAL; + } + + if (pdata && pdata->gpio_base) + madera_gpio->gpio_chip.base = pdata->gpio_base; + else + madera_gpio->gpio_chip.base = -1; + + ret = devm_gpiochip_add_data(&pdev->dev, &madera_gpio->gpio_chip, + madera_gpio); + if (ret < 0) { + dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); + return ret; + } + + ret = gpiochip_add_pin_range(&madera_gpio->gpio_chip, "madera-pinctrl", + 0, 0, madera_gpio->gpio_chip.ngpio); + if (ret) { + dev_warn(&pdev->dev, "Failed to add pin range (%d)\n", ret); + return ret; + } + + return 0; +} + +static struct platform_driver madera_gpio_driver = { + .driver.name = "madera-gpio", + .driver.owner = THIS_MODULE, + .probe = madera_gpio_probe, +}; + +module_platform_driver(madera_gpio_driver); + +MODULE_DESCRIPTION("GPIO interface for Madera codecs"); +MODULE_AUTHOR("Nariman Poushin "); +MODULE_AUTHOR("Richard Fitzgerald "); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:madera-gpio"); -- 2.11.0 From 1584815361377279941@xxx Thu Nov 23 00:41:46 +0000 2017 X-GM-THRID: 1584815361377279941 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread