From nobody Fri Dec 19 21:48:09 2025 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 8AE3715AAAF; Wed, 13 Mar 2024 16:47:28 +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=1710348448; cv=none; b=oylQ3XnUnsPNo6uztJ6RrVPOAbuS8ctG4oYwOk9k/iyLWNurtkANH+f8muSe/8yH32zmJHtZpCYThlO4vcK0oc+QoiHwFzhhoGNRArmHrSEEY4rmzSb4KOtZDSSmUKj4Tx1Eul4zjBC3pSxrACxTIxJ6vhQnsSi0DQmV0zJGbMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348448; c=relaxed/simple; bh=ch2Ufytfvwceqf3EZkbNtVSDHUYAfgp6GehJEaHk/Jo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=naK2n2O/rFDGAPzvx9jh2XSCM80uoSEd8TRz25NgA6w4yMIbD/AhVYyeRSAiplGNC0Jv329njIxa2YWs8gn2jyWhpJNlcm/cf2nZLw2PZ8e1x/DwGcPLLBGxDIxpakZZHtqIfMmUmVVnjAhQVxTsro5eNdEJvxQrukVu+5tHnEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QJ96jB6+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QJ96jB6+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1321C433C7; Wed, 13 Mar 2024 16:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348448; bh=ch2Ufytfvwceqf3EZkbNtVSDHUYAfgp6GehJEaHk/Jo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QJ96jB6++HH4JyTUzGDg6yjQs/Zq+81m3LIaYG1+v6ZBmAudfw04osx3YPKJa0JfM m22gm1cHxTtVJFzbcHmg2BRmh/42L01CjhuwUn070hhLfMUFL8mDxhEqDPBFMYAeEe UaQ5CLNtQfETC3wXqNqQDwjWUdgZYYsUVg0Lbp5vP+71b2YWjk4FNUldIV/2G5OCNE mfXJ2t8FNU81UHV6+NjTQn4dwa0OjohUa3v4i3kOUJ2Lk5RIP+S0/N14pKzOdcaqcJ pAs5BBDbZ46vWTaqtKBIAtBEwoahVY9EWD3AVEJMWOtZjRtEn1k+pVDWJ6Y4XUFteg NBP/6HvONHyuw== 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 42/73] serial: max310x: use a separate regmap for each port Date: Wed, 13 Mar 2024 12:46:09 -0400 Message-ID: <20240313164640.616049-43-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Cosmin Tanislav [ 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 Signed-off-by: Cosmin Tanislav Link: https://lore.kernel.org/r/20220605144659.4169853-3-demonsingur@gmail.= com Signed-off-by: Greg Kroah-Hartman Stable-dep-of: b35f8dbbce81 ("serial: max310x: prevent infinite while() loo= p in port startup") Signed-off-by: Sasha Levin --- 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 c0fa4ad104774..80298a5714bcb 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; =20 u8 rx_buf[MAX310X_FIFO_SIZE]; }; @@ -291,26 +292,26 @@ static DECLARE_BITMAP(max310x_lines, MAX310X_UART_NRM= AX); =20 static u8 max310x_port_read(struct uart_port *port, u8 reg) { - struct max310x_port *s =3D dev_get_drvdata(port->dev); + struct max310x_one *one =3D to_max310x_port(port); unsigned int val =3D 0; =20 - regmap_read(s->regmap, port->iobase + reg, &val); + regmap_read(one->regmap, reg, &val); =20 return val; } =20 static void max310x_port_write(struct uart_port *port, u8 reg, u8 val) { - struct max310x_port *s =3D dev_get_drvdata(port->dev); + struct max310x_one *one =3D to_max310x_port(port); =20 - regmap_write(s->regmap, port->iobase + reg, val); + regmap_write(one->regmap, reg, val); } =20 static void max310x_port_update(struct uart_port *port, u8 reg, u8 mask, u= 8 val) { - struct max310x_port *s =3D dev_get_drvdata(port->dev); + struct max310x_one *one =3D to_max310x_port(port); =20 - regmap_update_bits(s->regmap, port->iobase + reg, mask, val); + regmap_update_bits(one->regmap, reg, mask, val); } =20 static int max3107_detect(struct device *dev) @@ -449,7 +450,7 @@ static const struct max310x_devtype max14830_devtype = =3D { =20 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, u= nsigned int reg) =20 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, un= signed int reg) =20 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, st= ruct max310x_port *s, =20 static void max310x_batch_write(struct uart_port *port, u8 *txbuf, unsigne= d int len) { - struct max310x_port *s =3D dev_get_drvdata(port->dev); - u8 reg =3D port->iobase + MAX310X_THR_REG; + struct max310x_one *one =3D to_max310x_port(port); =20 - regmap_raw_write(s->regmap, reg, txbuf, len); + regmap_raw_write(one->regmap, MAX310X_THR_REG, txbuf, len); } =20 static void max310x_batch_read(struct uart_port *port, u8 *rxbuf, unsigned= int len) { - struct max310x_port *s =3D dev_get_drvdata(port->dev); - u8 reg =3D port->iobase + MAX310X_RHR_REG; + struct max310x_one *one =3D to_max310x_port(port); =20 - regmap_raw_read(s->regmap, reg, rxbuf, len); + regmap_raw_read(one->regmap, MAX310X_RHR_REG, rxbuf, len); } =20 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 =20 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 =3D 0; bool xtal; =20 - if (IS_ERR(regmap)) - return PTR_ERR(regmap); + for (i =3D 0; i < devtype->nr; i++) + if (IS_ERR(regmaps[i])) + return PTR_ERR(regmaps[i]); =20 /* Alloc port structure */ s =3D devm_kzalloc(dev, struct_size(s, p, devtype->nr), GFP_KERNEL); @@ -1306,7 +1306,7 @@ static int max310x_probe(struct device *dev, const st= ruct max310x_devtype *devty goto out_clk; } =20 - s->regmap =3D regmap; + s->regmap =3D regmaps[0]; s->devtype =3D devtype; dev_set_drvdata(dev, s); =20 @@ -1316,22 +1316,18 @@ static int max310x_probe(struct device *dev, const = struct max310x_devtype *devty goto out_clk; =20 for (i =3D 0; i < devtype->nr; i++) { - unsigned int offs =3D 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); =20 /* Wait for port startup */ do { - regmap_read(s->regmap, - MAX310X_BRGDIVLSB_REG + offs, &ret); + regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &ret); } while (ret !=3D 0x01); =20 - regmap_write(s->regmap, MAX310X_MODE1_REG + offs, - devtype->mode1); + regmap_write(regmaps[i], MAX310X_MODE1_REG, devtype->mode1); } =20 uartclk =3D max310x_set_ref_clk(dev, s, freq, xtal); @@ -1359,11 +1355,13 @@ static int max310x_probe(struct device *dev, const = struct max310x_devtype *devty s->p[i].port.fifosize =3D MAX310X_FIFO_SIZE; s->p[i].port.flags =3D UPF_FIXED_TYPE | UPF_LOW_LATENCY; s->p[i].port.iotype =3D UPIO_PORT; - s->p[i].port.iobase =3D i * 0x20; + s->p[i].port.iobase =3D i; s->p[i].port.membase =3D (void __iomem *)~0; s->p[i].port.uartclk =3D uartclk; s->p[i].port.rs485_config =3D max310x_rs485_config; s->p[i].port.ops =3D &max310x_ops; + s->p[i].regmap =3D regmaps[i]; + /* Disable all interrupts */ max310x_port_write(&s->p[i].port, MAX310X_IRQEN_REG, 0); /* Clear IRQ status register */ @@ -1460,6 +1458,7 @@ static struct regmap_config regcfg =3D { .val_bits =3D 8, .write_flag_mask =3D MAX310X_WRITE_BIT, .cache_type =3D REGCACHE_RBTREE, + .max_register =3D MAX310X_REG_1F, .writeable_reg =3D max310x_reg_writeable, .volatile_reg =3D max310x_reg_volatile, .precious_reg =3D max310x_reg_precious, @@ -1469,7 +1468,8 @@ static struct regmap_config regcfg =3D { 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; =20 /* Setup SPI bus */ @@ -1484,10 +1484,14 @@ static int max310x_spi_probe(struct spi_device *spi) if (!devtype) devtype =3D (struct max310x_devtype *)spi_get_device_id(spi)->driver_dat= a; =20 - regcfg.max_register =3D devtype->nr * 0x20 - 1; - regmap =3D devm_regmap_init_spi(spi, ®cfg); + for (i =3D 0; i < devtype->nr; i++) { + u8 port_mask =3D i * 0x20; + regcfg.read_flag_mask =3D port_mask; + regcfg.write_flag_mask =3D port_mask | MAX310X_WRITE_BIT; + regmaps[i] =3D devm_regmap_init_spi(spi, ®cfg); + } =20 - return max310x_probe(&spi->dev, devtype, regmap, spi->irq); + return max310x_probe(&spi->dev, devtype, regmaps, spi->irq); } =20 static int max310x_spi_remove(struct spi_device *spi) --=20 2.43.0