From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Cosmin Tanislav <cosmin.tanislav@analog.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.4 48/51] serial: max310x: make accessing revision id interface-agnostic
Date: Wed, 13 Mar 2024 13:02:09 -0400 [thread overview]
Message-ID: <20240313170212.616443-49-sashal@kernel.org> (raw)
In-Reply-To: <20240313170212.616443-1-sashal@kernel.org>
From: Cosmin Tanislav <cosmin.tanislav@analog.com>
[ 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 <andy.shevchenko@gmail.com>
Signed-off-by: Cosmin Tanislav <cosmin.tanislav@analog.com>
Link: https://lore.kernel.org/r/20220605144659.4169853-4-demonsingur@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Stable-dep-of: 3f42b142ea11 ("serial: max310x: fix IO data corruption in batched operations")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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
next prev parent reply other threads:[~2024-03-13 17:03 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 17:01 [PATCH 5.4 00/51] 5.4.272-rc1 review Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 01/51] lan78xx: Fix white space and style issues Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 02/51] lan78xx: Add missing return code checks Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 03/51] lan78xx: Fix partial packet errors on suspend/resume Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 04/51] lan78xx: Fix race conditions in suspend/resume handling Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 05/51] net: lan78xx: fix runtime PM count underflow on link stop Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 06/51] ixgbe: {dis, en}able irqs in ixgbe_txrx_ring_{dis, en}able Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 07/51] geneve: make sure to pull inner header in geneve_rx() Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 08/51] net: ice: Fix potential NULL pointer dereference in ice_bridge_setlink() Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 09/51] net/ipv6: avoid possible UAF in ip6_route_mpath_notify() Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 10/51] net/rds: fix WARNING in rds_conn_connect_if_down Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 11/51] netfilter: nft_ct: fix l3num expectations with inet pseudo family Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 12/51] netfilter: nf_conntrack_h323: Add protection for bmp length out of range Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 13/51] netrom: Fix a data-race around sysctl_netrom_default_path_quality Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 14/51] netrom: Fix a data-race around sysctl_netrom_obsolescence_count_initialiser Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 15/51] netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 16/51] netrom: Fix a data-race around sysctl_netrom_transport_timeout Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 17/51] netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 18/51] netrom: Fix a data-race around sysctl_netrom_transport_acknowledge_delay Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 19/51] netrom: Fix a data-race around sysctl_netrom_transport_busy_delay Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 20/51] netrom: Fix a data-race around sysctl_netrom_transport_requested_window_size Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 21/51] netrom: Fix a data-race around sysctl_netrom_transport_no_activity_timeout Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 22/51] netrom: Fix a data-race around sysctl_netrom_routing_control Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 23/51] netrom: Fix a data-race around sysctl_netrom_link_fails_count Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 24/51] netrom: Fix data-races around sysctl_net_busy_read Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 25/51] selftests: mm: fix map_hugetlb failure on 64K page size systems Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 26/51] um: allow not setting extra rpaths in the linux binary Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 27/51] serial: max310x: Use devm_clk_get_optional() to get the input clock Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 28/51] serial: max310x: Try to get crystal clock rate from property Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 29/51] serial: max310x: fail probe if clock crystal is unstable Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 30/51] serial: max310x: Make use of device properties Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 31/51] serial: max310x: use regmap methods for SPI batch operations Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 32/51] serial: max310x: use a separate regmap for each port Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 33/51] serial: max310x: prevent infinite while() loop in port startup Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 34/51] Input: i8042 - fix strange behavior of touchpad on Clevo NS70PU Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 35/51] hv_netvsc: Make netvsc/VF binding check both MAC and serial number Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 36/51] hv_netvsc: use netif_is_bond_master() instead of open code Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 37/51] hv_netvsc: Register VF in netvsc_probe if NET_DEVICE_REGISTER missed Sasha Levin
2024-03-13 17:01 ` [PATCH 5.4 38/51] y2038: rusage: use __kernel_old_timeval Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 39/51] getrusage: add the "signal_struct *sig" local variable Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 40/51] getrusage: move thread_group_cputime_adjusted() outside of lock_task_sighand() Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 41/51] getrusage: use __for_each_thread() Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 42/51] getrusage: use sig->stats_lock rather than lock_task_sighand() Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 43/51] exit: Fix typo in comment: s/sub-theads/sub-threads Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 44/51] exit: wait_task_zombie: kill the no longer necessary spin_lock_irq(siglock) Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 45/51] serial: max310x: Unprepare and disable clock in error path Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 46/51] regmap: allow to define reg_update_bits for no bus configuration Sasha Levin
2024-03-13 17:08 ` Mark Brown
2024-03-13 17:02 ` [PATCH 5.4 47/51] regmap: Add bulk read/write callbacks into regmap_config Sasha Levin
2024-03-13 17:09 ` Mark Brown
2024-03-13 17:02 ` Sasha Levin [this message]
2024-03-13 17:02 ` [PATCH 5.4 49/51] serial: max310x: implement I2C support Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 50/51] serial: max310x: fix IO data corruption in batched operations Sasha Levin
2024-03-13 17:02 ` [PATCH 5.4 51/51] Linux 5.4.272-rc1 Sasha Levin
2024-03-14 14:59 ` [PATCH 5.4 00/51] 5.4.272-rc1 review Harshit Mogalapalli
2024-03-14 18:29 ` Naresh Kamboju
2024-03-14 19:38 ` Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240313170212.616443-49-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=cosmin.tanislav@analog.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox