From patchwork Mon Jun 3 12:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Wang X-Patchwork-Id: 801361 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (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 2D21A12C522; Mon, 3 Jun 2024 12:37:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717418267; cv=none; b=cjiAdDYrWgH+hHU6QP5H5LkADqIC1jTkJZFOVFCMNLwfc359uWZMvf7ed6IzuDZrEPSN1abEZuuTf2ezsnwLEHTVc8ZV7qjLP3tFh6OODczlKQiT/BwLwy530piwTOhJoe6oMVM16B9gNlfyjr//8tTRMlA942YZy+7RVliB+wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717418267; c=relaxed/simple; bh=iNqoXL3l6pGrCO8tF1wXllFct7L4FEYTzyPho9173rY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=LeKzglNU3DWop6g+oHdf5gFWZ9dQT5Or0JkgiaGfA9V3J9WRXcJkA/5Kjtp4IpOT1Dkje4C7x6Fa9pURmL9eelU1lWAjoHrcLm5eBDaWHWQlq0iFCcZOQ+JIY/g8gBxRxXMh0Nl6eTgEvAjMRxSkzjOYuxUcwRkWm5exZnLJlo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=gJIX7C0w; arc=none smtp.client-ip=185.125.188.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="gJIX7C0w" Received: from hwang4-ThinkPad-T14s-Gen-2a.conference (unknown [123.112.65.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id ECF243F5DC; Mon, 3 Jun 2024 12:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1717418256; bh=F5M+W+x3E5jyNkr7sCMlyiuydTbGqQoGu0AaMJzisok=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gJIX7C0wCbNvEPyuplbpqn1Rx1l36yx+fxa6xV9X1OwyynZFvjLallTKBnek4sykJ wmeRWToP5fYinagzivKKlxh1ibDDD5aVNG2wHTVqFxEEUOBJx1ZOnHcAbP3ut0Quwd R0Oaggnjovy2k+JEEJj0qzjWI9iogJkHEllmZRtlhaR7DeELD3sk2W4f7/SJsZ0luy SkXwWzo5xsNpIncHY4TEHqoSc3kmi0iERvCWZN8AHKtj/p3utdBhVVn7aLeq0GKW4c ihnZ/Ldt1q0KOVDa3HOXpaelM0Y7NEg5pUeYkZiVY/YMeaoiesJ/w91pA0enGqutTu RIE0ELS9FvE1g== From: Hui Wang To: linux-serial@vger.kernel.org, devicetree@vger.kernel.org, gregkh@linuxfoundation.org Cc: jirislaby@kernel.org, hvilleneuve@dimonoff.com, hui.wang@canonical.com Subject: [PATCH 1/2] dt-bindings: serial: sc16is7xx: add reset-gpios Date: Mon, 3 Jun 2024 20:37:09 +0800 Message-Id: <20240603123710.649549-1-hui.wang@canonical.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In some designs, the chip reset pin is connected to a gpio, this gpio needs to be set correctly before probing the driver, so adding a reset-gpios in the device tree. Signed-off-by: Hui Wang --- Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml b/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml index 5dec15b7e7c3..62aff6e034cb 100644 --- a/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml +++ b/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml @@ -28,6 +28,9 @@ properties: clocks: maxItems: 1 + reset-gpios: + maxItems: 1 + clock-frequency: description: When there is no clock provider visible to the platform, this @@ -120,6 +123,7 @@ examples: compatible = "nxp,sc16is752"; reg = <0x54>; clocks = <&clk20m>; + reset-gpios = <&gpio5 13 GPIO_ACTIVE_LOW>; interrupt-parent = <&gpio3>; interrupts = <7 IRQ_TYPE_EDGE_FALLING>; nxp,modem-control-line-ports = <0 1>; /* Ports 0 and 1 as modem control lines */ From patchwork Mon Jun 3 12:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Wang X-Patchwork-Id: 801900 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (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 DC85512C478; Mon, 3 Jun 2024 12:37:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717418269; cv=none; b=gdN2wNjpVbU7gCQno+en1SlBqaFcePVkd9LKSATFSnphTQIIt16ExK5rQJWmTBBDPFNKtqTcj7mG+XW+u33NQE8ES2cdLYbWUsiNbbiUHMsfOzjbLpwZ/ilNoAxnubXoyAc7CgDuAprFZq1lB/WM8EFxDR7+1T551CVT+vDYyCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717418269; c=relaxed/simple; bh=RsZDNYZFr1sN1TmKUqEFg9ql+dm/ol7ON0v/8wO17Og=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IaaS21sp2R6h8/4iGWGDoXahAE+eZMEIuV5KhE2INcB5y9siCeqd/7nC6C9qblhWyyv89vVwYIr6LK2M/ClM79eHeC30HfkB/AaV/Eu+0FGaecfE0XSFRx8KDZVqu/ZFs67o9Dt5yc3fxybXfuiml/c8CTFc8PC5y4e+PpBD7Y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=K3eZgebq; arc=none smtp.client-ip=185.125.188.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="K3eZgebq" Received: from hwang4-ThinkPad-T14s-Gen-2a.conference (unknown [123.112.65.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 0C34F3FAE8; Mon, 3 Jun 2024 12:37:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1717418259; bh=lXgAgJh56208citeJjAWVQZbibVrADnZ2ctRoypgJtw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K3eZgebqwPs6PmTcDznpCJ8RH2M6Np5F/p6En0baCYlgVpOwAwBWWk+xAs961O43I +64GU80bCddCSIj4WDVcXHDx5lSKdL2yyWgT33tcKuQUpNY4t0Dhkej0sPLleyFUKZ UKMN5oU1zrPEorBpBo+Nd1iEMoUWZfGsa9L2iqwbsz2mjzfhI5JB5QvuXUGtWTOox1 01Ef1YIiWylP0URJ0mJzMpXdkRrTWz2bMhLfIgYdWOQ1jgY5lUq+RDVlI0S1GvPUZO 9rns/V0mop0xryMoRRC8K0MieZFbEPzu13lCD36Cch4rxSHe50a+GVPehvIJlp86jv gcs6QQVsiCGwg== From: Hui Wang To: linux-serial@vger.kernel.org, devicetree@vger.kernel.org, gregkh@linuxfoundation.org Cc: jirislaby@kernel.org, hvilleneuve@dimonoff.com, hui.wang@canonical.com Subject: [PATCH 2/2] serial: sc16is7xx: setup reset pin if it is defined in device tree Date: Mon, 3 Jun 2024 20:37:10 +0800 Message-Id: <20240603123710.649549-2-hui.wang@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603123710.649549-1-hui.wang@canonical.com> References: <20240603123710.649549-1-hui.wang@canonical.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Certain designs connect a gpio to the reset pin, and the reset pin needs to be setup correctly before accessing the chip. Here adding a function to handle the reset pin. This change has no impact if there is no reset_gpios defined in the device tree. Signed-off-by: Hui Wang --- drivers/tty/serial/sc16is7xx.c | 22 ++++++++++++++++++++++ drivers/tty/serial/sc16is7xx.h | 2 ++ drivers/tty/serial/sc16is7xx_i2c.c | 2 ++ drivers/tty/serial/sc16is7xx_spi.c | 2 ++ 4 files changed, 28 insertions(+) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index bf0065d1c8e9..53bfb603b03c 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1467,6 +1468,27 @@ static const struct serial_rs485 sc16is7xx_rs485_supported = { .delay_rts_after_send = 1, /* Not supported but keep returning -EINVAL */ }; +void sc16is7xx_setup_reset_pin(struct device *dev) +{ + struct device_node *np = dev->of_node; + int reset_gpio, err; + + reset_gpio = of_get_named_gpio(np, "reset-gpios", 0); + if (!gpio_is_valid(reset_gpio)) + return; + + err = devm_gpio_request_one(dev, reset_gpio, GPIOF_OUT_INIT_LOW, + "sc16is7xx-reset"); + if (err) { + dev_err(dev, "failed to request sc16is7xx-reset-gpios: %d\n", err); + return; + } + + /* Deassert the reset pin */ + gpio_set_value_cansleep(reset_gpio, 1); +} +EXPORT_SYMBOL_GPL(sc16is7xx_setup_reset_pin); + int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, struct regmap *regmaps[], int irq) { diff --git a/drivers/tty/serial/sc16is7xx.h b/drivers/tty/serial/sc16is7xx.h index afb784eaee45..f4ae114cc41a 100644 --- a/drivers/tty/serial/sc16is7xx.h +++ b/drivers/tty/serial/sc16is7xx.h @@ -33,6 +33,8 @@ const char *sc16is7xx_regmap_name(u8 port_id); unsigned int sc16is7xx_regmap_port_mask(unsigned int port_id); +void sc16is7xx_setup_reset_pin(struct device *dev); + int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, struct regmap *regmaps[], int irq); diff --git a/drivers/tty/serial/sc16is7xx_i2c.c b/drivers/tty/serial/sc16is7xx_i2c.c index 3ed47c306d85..9833c3b935c2 100644 --- a/drivers/tty/serial/sc16is7xx_i2c.c +++ b/drivers/tty/serial/sc16is7xx_i2c.c @@ -21,6 +21,8 @@ static int sc16is7xx_i2c_probe(struct i2c_client *i2c) if (!devtype) return dev_err_probe(&i2c->dev, -ENODEV, "Failed to match device\n"); + sc16is7xx_setup_reset_pin(&i2c->dev); + memcpy(®cfg, &sc16is7xx_regcfg, sizeof(struct regmap_config)); for (i = 0; i < devtype->nr_uart; i++) { diff --git a/drivers/tty/serial/sc16is7xx_spi.c b/drivers/tty/serial/sc16is7xx_spi.c index 73df36f8a7fd..ce38561faaf0 100644 --- a/drivers/tty/serial/sc16is7xx_spi.c +++ b/drivers/tty/serial/sc16is7xx_spi.c @@ -38,6 +38,8 @@ static int sc16is7xx_spi_probe(struct spi_device *spi) if (!devtype) return dev_err_probe(&spi->dev, -ENODEV, "Failed to match device\n"); + sc16is7xx_setup_reset_pin(&spi->dev); + memcpy(®cfg, &sc16is7xx_regcfg, sizeof(struct regmap_config)); for (i = 0; i < devtype->nr_uart; i++) {