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.15 49/76] serial: max310x: use a separate regmap for each port
Date: Wed, 13 Mar 2024 12:41:56 -0400 [thread overview]
Message-ID: <20240313164223.615640-50-sashal@kernel.org> (raw)
In-Reply-To: <20240313164223.615640-1-sashal@kernel.org>
From: Cosmin Tanislav <cosmin.tanislav@analog.com>
[ Upstream commit 6ef281daf020592c219fa91780abc381c6c20db5 ]
The driver currently does manual register manipulation in
multiple places to talk to a specific UART port.
In order to talk to a specific UART port over SPI, the bits U1
and U0 of the register address can be set, as explained in the
Command byte configuration section of the datasheet.
Make this more elegant by creating regmaps for each UART port
and setting the read_flag_mask and write_flag_mask
accordingly.
All communcations regarding global registers are done on UART
port 0, so replace the global regmap entirely with the port 0
regmap.
Also, remove the 0x1f masks from reg_writeable(), reg_volatile()
and reg_precious() methods, since setting the U1 and U0 bits of
the register address happens inside the regmap core now.
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-3-demonsingur@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Stable-dep-of: b35f8dbbce81 ("serial: max310x: prevent infinite while() loop in port startup")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/tty/serial/max310x.c | 68 +++++++++++++++++++-----------------
1 file changed, 36 insertions(+), 32 deletions(-)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index c9032e300a586..d61e8a6bc99dd 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -262,6 +262,7 @@ struct max310x_one {
struct work_struct tx_work;
struct work_struct md_work;
struct work_struct rs_work;
+ struct regmap *regmap;
u8 rx_buf[MAX310X_FIFO_SIZE];
};
@@ -291,26 +292,26 @@ static DECLARE_BITMAP(max310x_lines, MAX310X_UART_NRMAX);
static u8 max310x_port_read(struct uart_port *port, u8 reg)
{
- struct max310x_port *s = dev_get_drvdata(port->dev);
+ struct max310x_one *one = to_max310x_port(port);
unsigned int val = 0;
- regmap_read(s->regmap, port->iobase + reg, &val);
+ regmap_read(one->regmap, reg, &val);
return val;
}
static void max310x_port_write(struct uart_port *port, u8 reg, u8 val)
{
- struct max310x_port *s = dev_get_drvdata(port->dev);
+ struct max310x_one *one = to_max310x_port(port);
- regmap_write(s->regmap, port->iobase + reg, val);
+ regmap_write(one->regmap, reg, val);
}
static void max310x_port_update(struct uart_port *port, u8 reg, u8 mask, u8 val)
{
- struct max310x_port *s = dev_get_drvdata(port->dev);
+ struct max310x_one *one = to_max310x_port(port);
- regmap_update_bits(s->regmap, port->iobase + reg, mask, val);
+ regmap_update_bits(one->regmap, reg, mask, val);
}
static int max3107_detect(struct device *dev)
@@ -449,7 +450,7 @@ static const struct max310x_devtype max14830_devtype = {
static bool max310x_reg_writeable(struct device *dev, unsigned int reg)
{
- switch (reg & 0x1f) {
+ switch (reg) {
case MAX310X_IRQSTS_REG:
case MAX310X_LSR_IRQSTS_REG:
case MAX310X_SPCHR_IRQSTS_REG:
@@ -466,7 +467,7 @@ static bool max310x_reg_writeable(struct device *dev, unsigned int reg)
static bool max310x_reg_volatile(struct device *dev, unsigned int reg)
{
- switch (reg & 0x1f) {
+ switch (reg) {
case MAX310X_RHR_REG:
case MAX310X_IRQSTS_REG:
case MAX310X_LSR_IRQSTS_REG:
@@ -488,7 +489,7 @@ static bool max310x_reg_volatile(struct device *dev, unsigned int reg)
static bool max310x_reg_precious(struct device *dev, unsigned int reg)
{
- switch (reg & 0x1f) {
+ switch (reg) {
case MAX310X_RHR_REG:
case MAX310X_IRQSTS_REG:
case MAX310X_SPCHR_IRQSTS_REG:
@@ -633,18 +634,16 @@ static s32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s,
static void max310x_batch_write(struct uart_port *port, u8 *txbuf, unsigned int len)
{
- struct max310x_port *s = dev_get_drvdata(port->dev);
- u8 reg = port->iobase + MAX310X_THR_REG;
+ struct max310x_one *one = to_max310x_port(port);
- regmap_raw_write(s->regmap, reg, txbuf, len);
+ regmap_raw_write(one->regmap, MAX310X_THR_REG, txbuf, len);
}
static void max310x_batch_read(struct uart_port *port, u8 *rxbuf, unsigned int len)
{
- struct max310x_port *s = dev_get_drvdata(port->dev);
- u8 reg = port->iobase + MAX310X_RHR_REG;
+ struct max310x_one *one = to_max310x_port(port);
- regmap_raw_read(s->regmap, reg, rxbuf, len);
+ regmap_raw_read(one->regmap, MAX310X_RHR_REG, rxbuf, len);
}
static void max310x_handle_rx(struct uart_port *port, unsigned int rxlen)
@@ -1247,15 +1246,16 @@ 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,
- struct regmap *regmap, int irq)
+ struct regmap *regmaps[], int irq)
{
int i, ret, fmin, fmax, freq;
struct max310x_port *s;
s32 uartclk = 0;
bool xtal;
- if (IS_ERR(regmap))
- return PTR_ERR(regmap);
+ for (i = 0; i < devtype->nr; i++)
+ if (IS_ERR(regmaps[i]))
+ return PTR_ERR(regmaps[i]);
/* Alloc port structure */
s = devm_kzalloc(dev, struct_size(s, p, devtype->nr), GFP_KERNEL);
@@ -1302,7 +1302,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
goto out_clk;
}
- s->regmap = regmap;
+ s->regmap = regmaps[0];
s->devtype = devtype;
dev_set_drvdata(dev, s);
@@ -1312,22 +1312,18 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
goto out_clk;
for (i = 0; i < devtype->nr; i++) {
- unsigned int offs = i << 5;
-
/* Reset port */
- regmap_write(s->regmap, MAX310X_MODE2_REG + offs,
+ regmap_write(regmaps[i], MAX310X_MODE2_REG,
MAX310X_MODE2_RST_BIT);
/* Clear port reset */
- regmap_write(s->regmap, MAX310X_MODE2_REG + offs, 0);
+ regmap_write(regmaps[i], MAX310X_MODE2_REG, 0);
/* Wait for port startup */
do {
- regmap_read(s->regmap,
- MAX310X_BRGDIVLSB_REG + offs, &ret);
+ regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &ret);
} while (ret != 0x01);
- regmap_write(s->regmap, MAX310X_MODE1_REG + offs,
- devtype->mode1);
+ regmap_write(regmaps[i], MAX310X_MODE1_REG, devtype->mode1);
}
uartclk = max310x_set_ref_clk(dev, s, freq, xtal);
@@ -1355,11 +1351,13 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
s->p[i].port.fifosize = MAX310X_FIFO_SIZE;
s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY;
s->p[i].port.iotype = UPIO_PORT;
- s->p[i].port.iobase = i * 0x20;
+ s->p[i].port.iobase = i;
s->p[i].port.membase = (void __iomem *)~0;
s->p[i].port.uartclk = uartclk;
s->p[i].port.rs485_config = max310x_rs485_config;
s->p[i].port.ops = &max310x_ops;
+ s->p[i].regmap = regmaps[i];
+
/* Disable all interrupts */
max310x_port_write(&s->p[i].port, MAX310X_IRQEN_REG, 0);
/* Clear IRQ status register */
@@ -1456,6 +1454,7 @@ static struct regmap_config regcfg = {
.val_bits = 8,
.write_flag_mask = MAX310X_WRITE_BIT,
.cache_type = REGCACHE_RBTREE,
+ .max_register = MAX310X_REG_1F,
.writeable_reg = max310x_reg_writeable,
.volatile_reg = max310x_reg_volatile,
.precious_reg = max310x_reg_precious,
@@ -1465,7 +1464,8 @@ static struct regmap_config regcfg = {
static int max310x_spi_probe(struct spi_device *spi)
{
const struct max310x_devtype *devtype;
- struct regmap *regmap;
+ struct regmap *regmaps[4];
+ unsigned int i;
int ret;
/* Setup SPI bus */
@@ -1480,10 +1480,14 @@ static int max310x_spi_probe(struct spi_device *spi)
if (!devtype)
devtype = (struct max310x_devtype *)spi_get_device_id(spi)->driver_data;
- regcfg.max_register = devtype->nr * 0x20 - 1;
- regmap = devm_regmap_init_spi(spi, ®cfg);
+ for (i = 0; i < devtype->nr; i++) {
+ u8 port_mask = i * 0x20;
+ regcfg.read_flag_mask = port_mask;
+ regcfg.write_flag_mask = port_mask | MAX310X_WRITE_BIT;
+ regmaps[i] = devm_regmap_init_spi(spi, ®cfg);
+ }
- return max310x_probe(&spi->dev, devtype, regmap, spi->irq);
+ return max310x_probe(&spi->dev, devtype, regmaps, spi->irq);
}
static int max310x_spi_remove(struct spi_device *spi)
--
2.43.0
next prev parent reply other threads:[~2024-03-13 16:43 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 16:41 [PATCH 5.15 00/76] 5.15.152-rc1 review Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 01/76] mmc: mmci: stm32: use a buffer for unaligned DMA requests Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 02/76] mmc: mmci: stm32: fix DMA API overlapping mappings warning Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 03/76] net: lan78xx: fix runtime PM count underflow on link stop Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 04/76] ixgbe: {dis, en}able irqs in ixgbe_txrx_ring_{dis, en}able Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 05/76] i40e: disable NAPI right after disabling irqs when handling xsk_pool Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 06/76] tracing/net_sched: Fix tracepoints that save qdisc_dev() as a string Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 07/76] geneve: make sure to pull inner header in geneve_rx() Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 08/76] net: sparx5: Fix use after free inside sparx5_del_mact_entry Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 09/76] net: ice: Fix potential NULL pointer dereference in ice_bridge_setlink() Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 10/76] net/ipv6: avoid possible UAF in ip6_route_mpath_notify() Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 11/76] cpumap: Zero-initialise xdp_rxq_info struct before running XDP program Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 12/76] net/rds: fix WARNING in rds_conn_connect_if_down Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 13/76] netfilter: nft_ct: fix l3num expectations with inet pseudo family Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 14/76] netfilter: nf_conntrack_h323: Add protection for bmp length out of range Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 15/76] erofs: apply proper VMA alignment for memory mapped files on THP Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 16/76] netrom: Fix a data-race around sysctl_netrom_default_path_quality Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 17/76] netrom: Fix a data-race around sysctl_netrom_obsolescence_count_initialiser Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 18/76] netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 19/76] netrom: Fix a data-race around sysctl_netrom_transport_timeout Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 20/76] netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 21/76] netrom: Fix a data-race around sysctl_netrom_transport_acknowledge_delay Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 22/76] netrom: Fix a data-race around sysctl_netrom_transport_busy_delay Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 23/76] netrom: Fix a data-race around sysctl_netrom_transport_requested_window_size Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 24/76] netrom: Fix a data-race around sysctl_netrom_transport_no_activity_timeout Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 25/76] netrom: Fix a data-race around sysctl_netrom_routing_control Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 26/76] netrom: Fix a data-race around sysctl_netrom_link_fails_count Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 27/76] netrom: Fix data-races around sysctl_net_busy_read Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 28/76] ALSA: usb-audio: Refcount multiple accesses on the single clock Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 29/76] ALSA: usb-audio: Clear fixed clock rate at closing EP Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 30/76] ALSA: usb-audio: Split endpoint setups for hw_params and prepare (take#2) Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 31/76] ALSA: usb-audio: Properly refcounting clock rate Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 32/76] ALSA: usb-audio: Apply mutex around snd_usb_endpoint_set_params() Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 33/76] ALSA: usb-audio: Correct the return code from snd_usb_endpoint_set_params() Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 34/76] ALSA: usb-audio: Avoid superfluous endpoint setup Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 35/76] ALSA: usb-audio: Add quirk for Tascam Model 12 Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 36/76] ALSA: usb-audio: Add new quirk FIXED_RATE for JBL Quantum810 Wireless Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 37/76] ALSA: usb-audio: Fix microphone sound on Nexigo webcam Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 38/76] ALSA: usb-audio: add quirk for RODE NT-USB+ Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 39/76] drm/amd/display: Fix uninitialized variable usage in core_link_ 'read_dpcd() & write_dpcd()' functions Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 40/76] nfp: flower: add goto_chain_index for ct entry Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 41/76] nfp: flower: add hardware offload check for post " Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 42/76] selftests/mm: switch to bash from sh Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 43/76] selftests: mm: fix map_hugetlb failure on 64K page size systems Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 44/76] modpost: Include '.text.*' in TEXT_SECTIONS Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 45/76] modpost: Add '.ltext' and '.ltext.*' to TEXT_SECTIONS Sasha Levin
2024-03-13 17:12 ` Nathan Chancellor
2024-03-13 20:13 ` Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 46/76] xhci: process isoc TD properly when there was a transaction error mid TD Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 47/76] xhci: handle isoc Babble and Buffer Overrun events properly Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 48/76] serial: max310x: use regmap methods for SPI batch operations Sasha Levin
2024-03-13 16:41 ` Sasha Levin [this message]
2024-03-13 16:41 ` [PATCH 5.15 50/76] serial: max310x: prevent infinite while() loop in port startup Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 51/76] drm/amd/pm: do not expose the API used internally only in kv_dpm.c Sasha Levin
2024-03-13 16:41 ` [PATCH 5.15 52/76] drm/amdgpu: Reset IH OVERFLOW_CLEAR bit Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 53/76] selftests: mptcp: decrease BW in simult flows Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 54/76] hv_netvsc: use netif_is_bond_master() instead of open code Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 55/76] hv_netvsc: Register VF in netvsc_probe if NET_DEVICE_REGISTER missed Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 56/76] drm/amd/display: Re-arrange FPU code structure for dcn2x Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 57/76] drm/amd/display: move calcs folder into DML Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 58/76] drm/amd/display: remove DML Makefile duplicate lines Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 59/76] drm/amd/display: Increase frame-larger-than for all display_mode_vba files Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 60/76] getrusage: add the "signal_struct *sig" local variable Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 61/76] getrusage: move thread_group_cputime_adjusted() outside of lock_task_sighand() Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 62/76] getrusage: use __for_each_thread() Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 63/76] getrusage: use sig->stats_lock rather than lock_task_sighand() Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 64/76] proc: Use task_is_running() for wchan in /proc/$pid/stat Sasha Levin
2024-03-14 3:04 ` Kees Cook
2024-03-15 18:31 ` Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 65/76] fs/proc: do_task_stat: move thread_group_cputime_adjusted() outside of lock_task_sighand() Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 66/76] exit: Fix typo in comment: s/sub-theads/sub-threads Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 67/76] exit: wait_task_zombie: kill the no longer necessary spin_lock_irq(siglock) Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 68/76] ALSA: usb-audio: Fix wrong kfree issue in snd_usb_endpoint_free_all Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 69/76] ALSA: usb-audio: Always initialize fixed_rate in snd_usb_find_implicit_fb_sync_format() Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 70/76] ALSA: usb-audio: Add FIXED_RATE quirk for JBL Quantum610 Wireless Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 71/76] ALSA: usb-audio: Sort quirk table entries Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 72/76] regmap: allow to define reg_update_bits for no bus configuration Sasha Levin
2024-03-13 16:46 ` Mark Brown
2024-03-13 17:16 ` Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 73/76] regmap: Add bulk read/write callbacks into regmap_config Sasha Levin
2024-03-13 16:46 ` Mark Brown
2024-03-13 17:14 ` Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 74/76] serial: max310x: make accessing revision id interface-agnostic Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 75/76] serial: max310x: fix IO data corruption in batched operations Sasha Levin
2024-03-13 16:42 ` [PATCH 5.15 76/76] Linux 5.15.152-rc1 Sasha Levin
2024-03-13 19:21 ` [PATCH 5.15 00/76] 5.15.152-rc1 review Daniel Díaz
2024-03-13 20:21 ` Sasha Levin
2024-03-14 15:02 ` Harshit Mogalapalli
2024-03-14 20:14 ` Florian Fainelli
2024-03-14 23:08 ` SeongJae Park
2024-03-15 10:43 ` Shreeya Patel
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=20240313164223.615640-50-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;
as well as URLs for NNTP newsgroup(s).