From patchwork Thu Nov 21 17:05:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 179938 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3880102ilf; Thu, 21 Nov 2019 09:07:36 -0800 (PST) X-Google-Smtp-Source: APXvYqwCJwfYUCHWwJIXi+Xf8FbrY9wFjoP02wwz6gdhFuJVSkpLKzWwF5x7gsxl1ZT43gPtVPzn X-Received: by 2002:a17:906:3ec8:: with SMTP id d8mr15365775ejj.55.1574355979795; Thu, 21 Nov 2019 09:06:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574355979; cv=none; d=google.com; s=arc-20160816; b=UiWS74VhqJBnUS1Vp35IrwJdBcGRtyVS+weTgikLJRx/I1aSwhZ/2xrXqI8IUNSLhS x3zCo4iEFf9HvlVFi4Pa6AzRs07+edQlqW8SjjpbPDtrKRnYiK8XH8oxz3z2wnrXCjSP 94So8f2mha8bMKnH+vpdWP4M3zsqmBVs8Nys7QwQ23ZUV4kJqYaIUYO1Up1UMsX5t41G VriLgGo0QIOlbaC+Y1zVL+aVHu5KflljxcaOY64gQmhvO9xcH/GQiFKy/yYk+WwkvUcq kf5ssEDf5UFGN3m51sVN01BkxetSzyY+lYlw4Kshr44XF3+k6dPUdKRuFnW6QJsgCcGe f03Q== 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=KYUxe40Wol2l12APUosgjjHbStmZ9vI8Y93vuvE0IMw=; b=Kk+uLeAi0LW1WA15ZLrCBgHb+CpYn8TZf/V52rECBPb4e5XrxrF/rilCgA/G1GKUNt uvn4IC368Yz15GQBCpnKGHYWNoKEMpfT1pqMfcGCB6+PgS1GiKNd4E1jQVOXZIO3jaMF KtQAkwnlPqOPxQjlaz1T17cknCqjSkf0LRWc87UIJJbwnVlBEs4aZvrureCTwAgmumru zj/9GT1TjadyxVshl+jxAR56nnEVWaT97dwpiqXKh23Hg+Hp3rRet2tBPmFdXLjHuDcW 7c3BwHV3Dr/3Z8r7H31JZHl6UFr4sPNM4zMba7h7fAqSd9DdedcYE/rbUlYFl9WAAP36 juLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fj/q972O"; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si2109478ejr.327.2019.11.21.09.06.19; Thu, 21 Nov 2019 09:06:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=@linaro.org header.s=google header.b="Fj/q972O"; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727192AbfKURGR (ORCPT + 5 others); Thu, 21 Nov 2019 12:06:17 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37356 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727188AbfKURGA (ORCPT ); Thu, 21 Nov 2019 12:06:00 -0500 Received: by mail-wm1-f65.google.com with SMTP id f129so3234713wmf.2 for ; Thu, 21 Nov 2019 09:05:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KYUxe40Wol2l12APUosgjjHbStmZ9vI8Y93vuvE0IMw=; b=Fj/q972O6NzUzRqqoKcM+qwH0llcsqcI03zOHVs2Xjro3wGmfgwBxhBMAgfctGYbZ/ H4Z49RWmZiMiRUlI5aQp0fq2lo++40eHTv7EQVo6XAOIRsoNbs18O46k8OMPjq3JC0d7 tMuOClISTjj6wUrESFTA8nxM/kXvCxBWeOQtB5u0rrNfxV/7aqjLBTC+k8qLg7d3lRUO vw34CGHXeV7ywVgJW9Qy9dO0YEjpOsDc0gv/tHkWaBX9vO9RSCelmpHS66m28YgrM7Ap 5qDA7A1/wuGDbRLPstGSqE7NemgAevZUBiJGv7gOPYtoc0/TQT+ugT6hhMPC8bFFK7aM GhWA== 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=KYUxe40Wol2l12APUosgjjHbStmZ9vI8Y93vuvE0IMw=; b=Ic58vVsbW5ZBm/lGanQuUc9Q+6Lf+3PTU6tSQ/P9rrKjeskJVHiVRqPqTwfI7KhCF7 Nbnwezp0n3qQ17/JYEAUjso07MPUoVdtJ8N8ZgURcMzs8x6dT5d5L+zUs3nhk+DkqdyJ 7fuxtgaaa4KnOwMk+9cEQw7i8gkiyZPZnR3GAGSNlqCumeC6Wfuc0h1zx1QE6Czqy2Dh Ey6SMxVD/M6N3ok0LbFNtfowRYydyPsnKzVNsoO9AHrAxrBpZ2am06CSmZzey2kPjifg ewf8bH4IrLWmDVbLyKw+bJDwPiCzfdGLHa54UiBQ4LgLTF2bvBKwe0A/KRawHdvC3RDZ 2f7g== X-Gm-Message-State: APjAAAXNSvwjVgLGLY5ZyD59GgHOrR/irGH3DgKb5NifCoZV5VjaRJ4h oCNh3yxhWNwvVz+fBU1+kekB7g== X-Received: by 2002:a1c:544e:: with SMTP id p14mr10892438wmi.17.1574355958461; Thu, 21 Nov 2019 09:05:58 -0800 (PST) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id i71sm4423731wri.68.2019.11.21.09.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 09:05:57 -0800 (PST) From: Srinivas Kandagatla To: robh@kernel.org, broonie@kernel.org, lee.jones@linaro.org, linus.walleij@linaro.org Cc: vinod.koul@linaro.org, alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, spapothi@codeaurora.org, bgoswami@codeaurora.org, linux-gpio@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v4 10/12] gpio: wcd934x: Add support to wcd934x gpio controller Date: Thu, 21 Nov 2019 17:05:07 +0000 Message-Id: <20191121170509.10579-11-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191121170509.10579-1-srinivas.kandagatla@linaro.org> References: <20191121170509.10579-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This patch adds support to wcd934x gpio block found in WCD9340/WC9341 Audio codecs. Signed-off-by: Srinivas Kandagatla --- drivers/gpio/Kconfig | 8 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-wcd934x.c | 104 ++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 drivers/gpio/gpio-wcd934x.c -- 2.21.0 diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 38e096e6925f..4be583933b1e 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -586,6 +586,14 @@ config GPIO_VX855 additional drivers must be enabled in order to use the functionality of the device. +config GPIO_WCD934X + tristate "Qualcomm Technologies Inc WCD9340/WCD9341 gpio controller driver" + depends on MFD_WCD934X && OF_GPIO + select GPIO_GENERIC + help + This driver is to supprot GPIO block found on the Qualcomm Technologies + Inc WCD9340/WCD9341 Audio Codec. + config GPIO_XGENE bool "APM X-Gene GPIO controller support" depends on ARM64 && OF_GPIO diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index d2fd19c15bae..496f632ac5c5 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -154,6 +154,7 @@ obj-$(CONFIG_GPIO_VF610) += gpio-vf610.o obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o +obj-$(CONFIG_GPIO_WCD934X) += gpio-wcd934x.o obj-$(CONFIG_GPIO_WHISKEY_COVE) += gpio-wcove.o obj-$(CONFIG_GPIO_WINBOND) += gpio-winbond.o obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o diff --git a/drivers/gpio/gpio-wcd934x.c b/drivers/gpio/gpio-wcd934x.c new file mode 100644 index 000000000000..0aac33235c5f --- /dev/null +++ b/drivers/gpio/gpio-wcd934x.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2019, Linaro Limited + +#include +#include +#include +#include +#include + +#define WCD_PIN_MASK(p) BIT(p - 1) +#define WCD_REG_DIR_CTL_OFFSET 0x42 +#define WCD_REG_VAL_CTL_OFFSET 0x43 +#define WCD934X_NPINS 5 + +struct wcd_gpio_data { + struct regmap *map; + struct gpio_chip chip; +}; + +static int wcd_gpio_direction_input(struct gpio_chip *chip, unsigned int pin) +{ + struct wcd_gpio_data *data = gpiochip_get_data(chip); + + return regmap_update_bits(data->map, WCD_REG_DIR_CTL_OFFSET, + WCD_PIN_MASK(pin), 0); +} + +static int wcd_gpio_direction_output(struct gpio_chip *chip, unsigned int pin, + int val) +{ + struct wcd_gpio_data *data = gpiochip_get_data(chip); + + regmap_update_bits(data->map, WCD_REG_DIR_CTL_OFFSET, + WCD_PIN_MASK(pin), WCD_PIN_MASK(pin)); + + return regmap_update_bits(data->map, WCD_REG_VAL_CTL_OFFSET, + WCD_PIN_MASK(pin), + val ? WCD_PIN_MASK(pin) : 0); +} + +static int wcd_gpio_get(struct gpio_chip *chip, unsigned int pin) +{ + struct wcd_gpio_data *data = gpiochip_get_data(chip); + int value; + + regmap_read(data->map, WCD_REG_VAL_CTL_OFFSET, &value); + + return !!(value && WCD_PIN_MASK(pin)); +} + +static void wcd_gpio_set(struct gpio_chip *chip, unsigned int pin, int val) +{ + wcd_gpio_direction_output(chip, pin, val); +} + +static int wcd_gpio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct wcd_gpio_data *data; + struct gpio_chip *chip; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->map = dev_get_regmap(dev->parent, NULL); + if (!data->map) { + dev_err(dev, "%s: failed to get regmap\n", __func__); + return -EINVAL; + } + + chip = &data->chip; + chip->direction_input = wcd_gpio_direction_input; + chip->direction_output = wcd_gpio_direction_output; + chip->get = wcd_gpio_get; + chip->set = wcd_gpio_set; + chip->parent = dev; + chip->base = -1; + chip->ngpio = WCD934X_NPINS; + chip->label = dev_name(dev); + chip->of_gpio_n_cells = 2; + chip->can_sleep = false; + + return devm_gpiochip_add_data(dev, chip, data); +} + +static const struct of_device_id wcd_gpio_of_match[] = { + { .compatible = "qcom,wcd9340-gpio" }, + { .compatible = "qcom,wcd9341-gpio" }, + { } +}; +MODULE_DEVICE_TABLE(of, wcd_gpio_of_match); + +static struct platform_driver wcd_gpio_driver = { + .driver = { + .name = "wcd934x-gpio", + .of_match_table = wcd_gpio_of_match, + }, + .probe = wcd_gpio_probe, +}; + +module_platform_driver(wcd_gpio_driver); +MODULE_DESCRIPTION("Qualcomm Technologies, Inc WCD GPIO control driver"); +MODULE_LICENSE("GPL v2");