Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1889339lql; Wed, 13 Mar 2024 10:56:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9zIdHkCBnUYNpiwyW5agPOwlJ6pN4nD1flfTJuTac8oFqBqJggAZZJ1N5O4A2Sq+HDj+AWDuUyW2FVtSFqHatMEsNRBFhO5ZSw95bTA== X-Google-Smtp-Source: AGHT+IGnKZ2dzjGJvpgrVZkVP8YvxTSod2IUtou2NTgBmIsyxg3tJ1b8C96dG/oh7VT90d46Ui+8 X-Received: by 2002:a05:6a21:670b:b0:1a1:8c6c:2b91 with SMTP id wh11-20020a056a21670b00b001a18c6c2b91mr11872791pzb.27.1710352596681; Wed, 13 Mar 2024 10:56:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710352596; cv=pass; d=google.com; s=arc-20160816; b=iPw9PxP9yXIL2c6+3KmCCYWSLYVNm6XjELShjpLwzSWkm3mlUk/U7MxETHTKXq7mz0 oftTW9i8VAAeufw00Hy1ttUfuI+qP1LWuhntnA2mQi0Q/rHgbNyZnSFhsW39SqGpZiDl faGo5VNrLcuHz5o76YHmsjB6PPD/oiGqAPfgU1T1pbiM0BI/N1H6g1hrUc9YEc+24mVa 0Szwi2To2gVC1kDCEnl9sr+sgtsj2RChENDQdjSPpWSaEMTRZfR00aRENDsEBHGHL9ZQ WMT61Xbfs+5oH7yyivIP7G+p9AIBMKFOXIGujsCPsdhPX0eErsOVs8ijGx+A8O/EF0ws +s6g== 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=Ej/SVYWTWvcOaVKLBmj5N54skznmqwIKMa8t94V1pyQ=; fh=x/vt0ctI9XaAtHjL/rnqCs6FX7jAjAlKyW2zeKn0OwY=; b=1HygdsknGODsTJT/q4g+EAkNo89lMpQbMXCgBdgQii0qS73qKXak/esZLTHwjsVMn1 spMV1Vt/GDNcXweNX3T+NeEl0W+ZG2lUhR085S2sqNLBYU0CYNj3oXvQTHbq41OS+via sBSXtecCErZBdU7SJU3dHvt1DUbt4fskzKIjsfmoucyOJ1A6I9BL2swLFsImzgkh1Rd+ +H/hhW4zbE8Xz9DTIVztSnwBUoq3MsMYBUbv4t8Mc9FmHorWy4NXytJpW80hTkSro1wM lqk1S1YwdXuVDJeJNhLLLkpMp90XtjO5Oebdz6VtRIu+rT8php4aZs44AD1GOjgsVCV6 EdRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jbHrL0xi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102097-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102097-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q14-20020a63e20e000000b005dc5061f211si9664353pgh.560.2024.03.13.10.56.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:56:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102097-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jbHrL0xi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102097-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102097-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5709928349E for ; Wed, 13 Mar 2024 17:56:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2A2918DCAE; Wed, 13 Mar 2024 16:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jbHrL0xi" 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 9713718DC8E; Wed, 13 Mar 2024 16:48:01 +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=1710348481; cv=none; b=rgdL4BLVHv42MK7MssctMb5eQzrjOf5IeQzmmbY+99Ls7tUnzr7mePmT2esHi+78IOaLSDrSxUMvYWwK3TJ4uHztpYI7shJCFi8DqpHTfpi0kvB/3c0h7nImjWv5cdwt8eaegQo5aVAvtn4ddhnFRG4tfkeHe1TjNqGL7wFXgoA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348481; c=relaxed/simple; bh=9lzwCHS6A32+VxdmU1FhUsZBTyFFxCDk4Ecv5s2kmnk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QGdgJuxbkheS/Ln3MPLklhGiWdFSYlgQbsmwOyYxzjlQQaL9O8ADwzpJIe/gjm0kDlq3poaEl2DzXUyEc+veQPT644X/xKtnDn+73e0lGZHl15tHE5sPJtv0kYTo7OC2JyVTjIS+iw74noCxqQoBHXbRY1QpGFb/8xiZ4Lxj7Ho= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jbHrL0xi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5644C43394; Wed, 13 Mar 2024 16:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348481; bh=9lzwCHS6A32+VxdmU1FhUsZBTyFFxCDk4Ecv5s2kmnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbHrL0xiGhLyDksWIfHoB3oKru/DusjKae7jC3lNf7OTuRcuW0S1Vgl01SPDNN/mn vcT1q4bQ+2DiEx17bx/tX4zDaz6kr7PtblvsrgHnjE7COksVYAEd80WkPAW4fBBvZb TdIiOMEp23LDTtIaoPAA7DcouyPs2kkVchV4J/6/Tc5JtJezuuDWQ4hr94vvVLUVBi H6UE5faV4gmQu+CVFjANknehv5BwyPw232BO4ZdrndxTRayUHkWvJ9lLSJhplCHFZm /vVm+EQx9wmJnC+FSWbL2KLHkLgaJyP+PA4wrY3hhb+u7wKOPSy3mPsfGqN3bMWh+H KgOHr1bKi476A== 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.10 70/73] serial: max310x: make accessing revision id interface-agnostic Date: Wed, 13 Mar 2024 12:46:37 -0400 Message-ID: <20240313164640.616049-71-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164640.616049-1-sashal@kernel.org> References: <20240313164640.616049-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.10.213-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.10.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.10.213-rc1 X-KernelTest-Deadline: 2024-03-15T16:46+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 a09ec46e0310d..b90281ac54c85 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; @@ -1313,6 +1319,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 */ @@ -1482,6 +1489,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; @@ -1508,7 +1528,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