Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1881976lql; Wed, 13 Mar 2024 10:40:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+EZ4n5AOZi1eFzrF+o0wGWzKMKD11BD+YSEYXgKzLZdoMQYU/LFSUqoITOgLzSVOPXhiB8VdcwaXGDXy4J2f5Cse9zmJHpZpvHrlJpw== X-Google-Smtp-Source: AGHT+IFqMdgP+r1p4Dsx5UOCaI2l+QaT4kgNre1+b9C4kGCcvAwNOBz3+E+x/LU27spiOGwTBVfy X-Received: by 2002:a50:d557:0:b0:568:8e7c:8d89 with SMTP id f23-20020a50d557000000b005688e7c8d89mr701337edj.38.1710351640413; Wed, 13 Mar 2024 10:40:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710351640; cv=pass; d=google.com; s=arc-20160816; b=X45b2g/yFDRg7tCNwEQUacIyhgjb8TG/p2E74RmclFqkE06xwKBc+L383q+paDdE2r VnY4NQ/woP2eXs6huz8ble2UHeAnpC6ru1fule39H0mg3wQs8cV2l+LxnFiQSpKsqSqW hUh2RLwW/axLnrB65smmUaIHFhkSFOPClLL5KCAHI1XpNMLqVetIjiPpmhEVcQ4MqCsO c2LyR5ENxKDbHk/7crG+6j9nDv8sIOu3cMaB8gWxH6GwbFuR2eNEy/yP1ALYUH/p14+h agH8SBXc+TEiY5wB1SscNXVhj0l7/Rodg52VhCgCL+ZfpAT6/xQiKxd/uOHwtRyFUVNi PH9Q== 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:dkim-signature; bh=zaHYJKwEPLDDVbFhc4QnG8eCZsQi1fzSYxQ6IM3tUw0=; fh=x/vt0ctI9XaAtHjL/rnqCs6FX7jAjAlKyW2zeKn0OwY=; b=H8KOf2AvlvO72Mq4Hfuefe0mhEH7iNAdoqs3Vk0h1WIxSuW8ZXMZnEybgKSwIQOI9+ eDRuv9vq3zhgLwCqaElhv1Tj7a0qHNuOvl49vtCNrk96YP53oiqmiyxSeCKDpVB7auZL 3ml7XVR+n/7vJf2i6CIImY9cae3cwx7VPFx5o+KrolzTgTwgCRm/t8ISShedWOjdTNOP nhvCPtzUpRKqVWSrGHMp3VnJoA9QIfP8LyeqJeULYawku6l60VA0YlJryvhOhcuUmlVI rDePAECNJYpqelWZZWq4MBR+hhhozXJo8BPsmPan0JvNtbatcCjzWDTQbLlP3Fy46hfW yItg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VBsxCuWp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102015-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102015-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f9-20020a056402354900b00566afb7bb1asi4668689edd.62.2024.03.13.10.40.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102015-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VBsxCuWp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102015-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102015-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 6FB051F26099 for ; Wed, 13 Mar 2024 17:38:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BFC614EFC3; Wed, 13 Mar 2024 16:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VBsxCuWp" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F369564CF5; Wed, 13 Mar 2024 16:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348229; cv=none; b=hmDBDSYqYgOBrBv0GRH5mIclWInDxGp7cVm36yDeNUU78GfQnMnikvs6XJd+m1tPmYgJ3g+dhR4kEHOLkjAhY2FeeitJT8YosNyVKAu+BUq/V9zwjKQttImvfV8+Owi7xx0TyWFNDKywfLjqyt73J6Ka1DRGBSpA676NPnwrNk4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348229; c=relaxed/simple; bh=FlAnfQi6O4H9BoJpowWiJxTJFnaB688i8rTR2c3Ha+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YCxdngG/RseYK8BYLJHwe1AzHgwSVBj/+OlvAa64ceVBk8R/9fBQRFGxUzquOsOr3lmu5vv+LlACqaP3h8Tfq1fW+AI41XdCuo1gD+xyU6ntc+vPRNTjZgSApD7hjCYCboJ7z/9q+UH5EWzXdxRZ6cx9cSNqTINUv1wxXF0XMzE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VBsxCuWp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E540C43399; Wed, 13 Mar 2024 16:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348228; bh=FlAnfQi6O4H9BoJpowWiJxTJFnaB688i8rTR2c3Ha+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VBsxCuWpBdeV0hlRU+z9YbbgEZ3NaW9kv0w1EoYQqC5e0BeKxRONRSyIsnJ8fWUO4 KdRRbg9uFbUKNSyZfof5uFj69FvoAk/dVRKUKy/c8JJydFpFuRdzxiyDZTRPZr4g0K C0icF9yiu6aKXc7Ai2nZmW4QOnweKLjm7L2MSlmshy5PrSPypd76vPpagybvfMpYaF GNFBEcOh/PnpQF6pZJxnsRPBI8KMyiagKd4X6WToEHg3OWId9+bMMexEq61k0tb48b kq9wUf3STKl/ixSHhNRSPgx4NgwNGsHLDqVZoivY++t0EiH+YFniR0RYCmW20aMN/O DkCySvYjmtyqA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Cosmin Tanislav , Andy Shevchenko , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.15 74/76] serial: max310x: make accessing revision id interface-agnostic Date: Wed, 13 Mar 2024 12:42:21 -0400 Message-ID: <20240313164223.615640-75-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164223.615640-1-sashal@kernel.org> References: <20240313164223.615640-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.152-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.15.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.15.152-rc1 X-KernelTest-Deadline: 2024-03-15T16:42+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Cosmin Tanislav [ Upstream commit b3883ab5e95713e479f774ea68be275413e8e5b2 ] SPI can only use 5 address bits, since one bit is reserved for specifying R/W and 2 bits are used to specify the UART port. To access registers that have addresses past 0x1F, an extended register space can be enabled by writing to the GlobalCommand register (address 0x1F). I2C uses 8 address bits. The R/W bit is placed in the slave address, and so is the UART port. Because of this, registers that have addresses higher than 0x1F can be accessed normally. To access the RevID register, on SPI, 0xCE must be written to the 0x1F address to enable the extended register space, after which the RevID register is accessible at address 0x5. 0xCD must be written to the 0x1F address to disable the extended register space. On I2C, the RevID register is accessible at address 0x25. Create an interface config struct, and add a method for toggling the extended register space and a member for the RevId register address. Implement these for SPI. Reviewed-by: Andy Shevchenko Signed-off-by: Cosmin Tanislav Link: https://lore.kernel.org/r/20220605144659.4169853-4-demonsingur@gmail.com Signed-off-by: Greg Kroah-Hartman Stable-dep-of: 3f42b142ea11 ("serial: max310x: fix IO data corruption in batched operations") Signed-off-by: Sasha Levin --- drivers/tty/serial/max310x.c | 40 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 41251fdf7c845..4299211183a74 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -72,7 +72,7 @@ #define MAX310X_GLOBALCMD_REG MAX310X_REG_1F /* Global Command (WO) */ /* Extended registers */ -#define MAX310X_REVID_EXTREG MAX310X_REG_05 /* Revision ID */ +#define MAX310X_SPI_REVID_EXTREG MAX310X_REG_05 /* Revision ID */ /* IRQ register bits */ #define MAX310X_IRQ_LSR_BIT (1 << 0) /* LSR interrupt */ @@ -253,6 +253,12 @@ #define MAX14830_BRGCFG_CLKDIS_BIT (1 << 6) /* Clock Disable */ #define MAX14830_REV_ID (0xb0) +struct max310x_if_cfg { + int (*extended_reg_enable)(struct device *dev, bool enable); + + unsigned int rev_id_reg; +}; + struct max310x_devtype { char name[9]; int nr; @@ -275,6 +281,7 @@ struct max310x_one { struct max310x_port { const struct max310x_devtype *devtype; + const struct max310x_if_cfg *if_cfg; struct regmap *regmap; struct clk *clk; #ifdef CONFIG_GPIOLIB @@ -364,13 +371,12 @@ static int max3109_detect(struct device *dev) unsigned int val = 0; int ret; - ret = regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, - MAX310X_EXTREG_ENBL); + ret = s->if_cfg->extended_reg_enable(dev, true); if (ret) return ret; - regmap_read(s->regmap, MAX310X_REVID_EXTREG, &val); - regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, MAX310X_EXTREG_DSBL); + regmap_read(s->regmap, s->if_cfg->rev_id_reg, &val); + s->if_cfg->extended_reg_enable(dev, false); if (((val & MAX310x_REV_MASK) != MAX3109_REV_ID)) { dev_err(dev, "%s ID 0x%02x does not match\n", s->devtype->name, val); @@ -395,13 +401,12 @@ static int max14830_detect(struct device *dev) unsigned int val = 0; int ret; - ret = regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, - MAX310X_EXTREG_ENBL); + ret = s->if_cfg->extended_reg_enable(dev, true); if (ret) return ret; - regmap_read(s->regmap, MAX310X_REVID_EXTREG, &val); - regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, MAX310X_EXTREG_DSBL); + regmap_read(s->regmap, s->if_cfg->rev_id_reg, &val); + s->if_cfg->extended_reg_enable(dev, false); if (((val & MAX310x_REV_MASK) != MAX14830_REV_ID)) { dev_err(dev, "%s ID 0x%02x does not match\n", s->devtype->name, val); @@ -1250,6 +1255,7 @@ static int max310x_gpio_set_config(struct gpio_chip *chip, unsigned int offset, #endif static int max310x_probe(struct device *dev, const struct max310x_devtype *devtype, + const struct max310x_if_cfg *if_cfg, struct regmap *regmaps[], int irq) { int i, ret, fmin, fmax, freq; @@ -1308,6 +1314,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty s->regmap = regmaps[0]; s->devtype = devtype; + s->if_cfg = if_cfg; dev_set_drvdata(dev, s); /* Check device to ensure we are talking to what we expect */ @@ -1477,6 +1484,19 @@ static struct regmap_config regcfg = { }; #ifdef CONFIG_SPI_MASTER +static int max310x_spi_extended_reg_enable(struct device *dev, bool enable) +{ + struct max310x_port *s = dev_get_drvdata(dev); + + return regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, + enable ? MAX310X_EXTREG_ENBL : MAX310X_EXTREG_DSBL); +} + +static const struct max310x_if_cfg __maybe_unused max310x_spi_if_cfg = { + .extended_reg_enable = max310x_spi_extended_reg_enable, + .rev_id_reg = MAX310X_SPI_REVID_EXTREG, +}; + static int max310x_spi_probe(struct spi_device *spi) { const struct max310x_devtype *devtype; @@ -1503,7 +1523,7 @@ static int max310x_spi_probe(struct spi_device *spi) regmaps[i] = devm_regmap_init_spi(spi, ®cfg); } - return max310x_probe(&spi->dev, devtype, regmaps, spi->irq); + return max310x_probe(&spi->dev, devtype, &max310x_spi_if_cfg, regmaps, spi->irq); } static int max310x_spi_remove(struct spi_device *spi) -- 2.43.0