Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1990982rdb; Sun, 21 Jan 2024 02:36:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqA/h1YwceVzMeU26nAoy9eIlddKov9khsKNvARbuCd1ny3DLY7jLMGtNc2A8NTg/uI17P X-Received: by 2002:a17:907:a788:b0:a2b:2503:88c3 with SMTP id vx8-20020a170907a78800b00a2b250388c3mr987867ejc.134.1705833387648; Sun, 21 Jan 2024 02:36:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705833387; cv=pass; d=google.com; s=arc-20160816; b=oiqyDLjA0kEnlkfJr0tNdjnJjNJuqQBIUn3U6nxZXCuJnRIUNV2Dpm5vh9EBJ5MeGd IZwj/9CLerH4ddYEnJKgX3e2Khv6pusvCEFmlCAcOqBNtsxfbcCv3a2mfIHpuhEsWSnv pPooTjtgke5COEgTQvw+/v5hhIgwRvOs6G2uuyw4aCPNmsUaEvlViqvF1Um78ipuN/s9 Nqgo47vLpihPQU3Qi7+dIHfLNi6wnkSFAl3Hvd4ViEPhiGZkABWDtNysrbYMXG8aYcGI YG9vjWGJdJ3uiAUNpAbiYHXqh0JrRZiI8mT148NJLH5cIXqBqbFW3C1ksqsR4C0wKYqg mHUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=bzstwqtqzSt1YIxK6axPSO5HowFES3RUWntTa10Xu2g=; fh=8bb1O3s5yzUhW9TkvhS28eMcS5nD+ayDEghHwK14PXw=; b=FOjAEBcwxBUDeqNfISa/Bi5iUxqxtjklJgmt8n21ZCCrP6IDJVaoZe6BWQX8wgYQ1H 7v/A2J53j6R3Yhm1NdQJ+bWG1OcenCfV14sQSZRXKmbhJEobvSb69mTR8WX3lBQ9wput jO0jKQZ3mA3GwrBVnY38Z4CbG9oDjR/2DpJnumSnFiKQ6fh8BVmEqfJEiQONinCh0tu9 5iQYIzlhDIqlCdl0QdKEQl0BTMjrNlHl3OSx2Iwb6TPPmWl8BWzP6Acc1L1w1fR1Vj+w Bwzap2FW+BTZ7Tdprgaij79l+PG2BmGsTaGGqn/9AxFnQNeC5MDx/yyAIBp3rIGBkG46 cEZw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=analog.com dmarc=pass fromdomain=analog.com); spf=pass (google.com: domain of linux-kernel+bounces-32011-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32011-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s16-20020a170906355000b00a2c1dfcd216si9696353eja.838.2024.01.21.02.36.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 02:36:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32011-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=analog.com dmarc=pass fromdomain=analog.com); spf=pass (google.com: domain of linux-kernel+bounces-32011-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32011-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3955A1F21016 for ; Sun, 21 Jan 2024 10:36:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91F2A125DA; Sun, 21 Jan 2024 10:35:47 +0000 (UTC) Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74B5B36B00; Sun, 21 Jan 2024 10:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705833346; cv=none; b=DRD3zeAHgPff7dQhWqcxEUCZaVo+FfxVcx/8+9yMBdubMHChzYHDm+hCo3znDzwrx84rXd26lABEDvxehC+wL1gV613t2TjuhbGKdnrmIIfE9vq2079y75J7Cd/uJUFK90JeYkxxcMKZ9pHZDC0t6bs04KmdTYfKXBnqU5EwTDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705833346; c=relaxed/simple; bh=Wb6M8XBxNNu/xmwdmMOGAKwII+CjP3Atro/4wU/nls8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QVuMbp6/BAY5PqiMVc+ui/jhaEc1edZD3d4Yomy+rgQ/MKvCZMsSZ3vMfCFI/ke5mEL5osolhM/M0mNoEsMEmaABs34L4foj+txV0s+bpNMPl2vUNc2CTmsTdHIczCm1zQnADP0NmQbMj/S4mZJeF0Oyw8Z3hgtX+DkQFU2KCZY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40L4xkGv011754; Sun, 21 Jan 2024 05:35:31 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3vr8w7bgwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 21 Jan 2024 05:35:30 -0500 (EST) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 40LAZTtc059850 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 21 Jan 2024 05:35:29 -0500 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Sun, 21 Jan 2024 05:35:28 -0500 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Sun, 21 Jan 2024 05:35:28 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Sun, 21 Jan 2024 05:35:28 -0500 Received: from kim-VirtualBox.ad.analog.com (KPALLER2-L03.ad.analog.com [10.116.242.67]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 40LAZAof021011; Sun, 21 Jan 2024 05:35:23 -0500 From: Kim Seer Paller To: , , CC: Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Kim Seer Paller" Subject: [PATCH 2/2] gpio: gpio-adg1414: New driver Date: Sun, 21 Jan 2024 18:35:05 +0800 Message-ID: <20240121103505.26475-3-kimseer.paller@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240121103505.26475-1-kimseer.paller@analog.com> References: <20240121103505.26475-1-kimseer.paller@analog.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: n7xPRH64Yqg_pLCV_UZII8v7YDAwOTKm X-Proofpoint-ORIG-GUID: n7xPRH64Yqg_pLCV_UZII8v7YDAwOTKm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-20_06,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401210082 The ADG1414 is a 9.5 Ω RON ±15 V/+12 V/±5 V iCMOS Serially-Controlled Octal SPST Switches Signed-off-by: Kim Seer Paller --- MAINTAINERS | 1 + drivers/gpio/Kconfig | 10 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-adg1414.c | 141 ++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 drivers/gpio/gpio-adg1414.c diff --git a/MAINTAINERS b/MAINTAINERS index 526145e69..254ba7ea5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -466,6 +466,7 @@ M: Kim Seer Paller S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/gpio/gpio-adg1414.yaml +F: drivers/gpio/gpio-adg1414.c ADM1025 HARDWARE MONITOR DRIVER M: Jean Delvare diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 1301cec94..25d467d70 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1728,6 +1728,16 @@ config GPIO_74X164 shift registers. This driver can be used to provide access to more GPIO outputs. +config GPIO_ADG1414 + tristate "ADG1414 SPST Switch Driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADG1414 SPST + Switch Driver + + To compile this driver as a module, choose M here: the + module will be called gpio-adg1414. + config GPIO_MAX3191X tristate "Maxim MAX3191x industrial serializer" select CRC8 diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 9e40af196..9ab45d128 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o +obj-$(CONFIG_GPIO_ADG1414) += gpio-adg1414.o obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o obj-$(CONFIG_GPIO_AGGREGATOR) += gpio-aggregator.o diff --git a/drivers/gpio/gpio-adg1414.c b/drivers/gpio/gpio-adg1414.c new file mode 100644 index 000000000..6c0830ee2 --- /dev/null +++ b/drivers/gpio/gpio-adg1414.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ADG1414 SPST Switch Driver + * + * Copyright 2024 Analog Devices Inc. + */ + +#include +#include +#include +#include +#include +#include + +#define ADG1414_MAX_DEVICES 4 + +struct adg1414_state { + struct spi_device *spi; + struct gpio_chip chip; + struct mutex lock; /* protect sensor state */ + u32 buf; + + __be32 tx __aligned(ARCH_DMA_MINALIGN); +}; + +static void adg1414_set(struct gpio_chip *chip, + unsigned int offset, + int value) +{ + struct adg1414_state *st = gpiochip_get_data(chip); + int ret; + + struct spi_transfer xfer = { + .tx_buf = &st->tx, + .len = st->chip.ngpio / 8, + }; + + mutex_lock(&st->lock); + + if (value) + st->buf |= BIT(offset); + else + st->buf &= ~BIT(offset); + + st->tx = cpu_to_be32(st->buf << (32 - st->chip.ngpio)); + + ret = spi_sync_transfer(st->spi, &xfer, 1); + if (ret) + goto out; + +out: + mutex_unlock(&st->lock); +} + +static int adg1414_get(struct gpio_chip *chip, + unsigned int offset) +{ + struct adg1414_state *st = gpiochip_get_data(chip); + int value; + + mutex_lock(&st->lock); + + value = st->buf & BIT(offset); + + mutex_unlock(&st->lock); + + return value; +} + +static int adg1414_get_direction(struct gpio_chip *chip, + unsigned int offset) +{ + return GPIO_LINE_DIRECTION_OUT; +} + +static int adg1414_probe(struct spi_device *spi) +{ + struct adg1414_state *st; + struct gpio_desc *reset; + struct device *dev = &spi->dev; + u32 num_devices; + int ret; + + st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + if (!st) + return -ENOMEM; + + st->spi = spi; + + /* Use reset pin to reset the device */ + reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(reset)) + return dev_err_probe(dev, PTR_ERR(reset), + "Failed to get reset gpio"); + + if (reset) { + fsleep(1); + gpiod_set_value_cansleep(reset, 0); + } + + num_devices = 1; + ret = device_property_read_u32(dev, "#daisy-chained-devices", + &num_devices); + if (!ret) { + if (!num_devices || num_devices > ADG1414_MAX_DEVICES) + return dev_err_probe(dev, ret, + "Failed to get daisy-chained-devices property\n"); + } + + st->chip.label = "adg1414"; + st->chip.parent = dev; + st->chip.get_direction = adg1414_get_direction; + st->chip.set = adg1414_set; + st->chip.get = adg1414_get; + st->chip.base = -1; + st->chip.ngpio = num_devices * 8; + st->chip.can_sleep = true; + + mutex_init(&st->lock); + + return devm_gpiochip_add_data(dev, &st->chip, st); +} + +static const struct of_device_id adg1414_of_match[] = { + { .compatible = "adi,adg1414" }, + { } +}; +MODULE_DEVICE_TABLE(of, adg1414_of_match); + +static struct spi_driver adg1414_driver = { + .driver = { + .name = "adg1414", + .of_match_table = adg1414_of_match, + }, + .probe = adg1414_probe, +}; +module_spi_driver(adg1414_driver); + +MODULE_AUTHOR("Kim Seer Paller "); +MODULE_DESCRIPTION("ADG1414 SPST Switch Driver"); +MODULE_LICENSE("GPL"); -- 2.34.1