* [PATCH v3 0/8] serial: max3100: Put into shape
@ 2024-04-09 14:45 Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 1/8] serial: max3100: Enable TIOCM_LOOP Andy Shevchenko
` (7 more replies)
0 siblings, 8 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
Put the driver into the shape with all new bells and whistles
from the kernel.
Tested on Intel Merrifield with MAX3111e connected.
In v3:
- dropped applied patches
- rebased on top of tty-testing
- v2 (20240402195306.269276-1-andriy.shevchenko@linux.intel.com)
In v2:
- fixed a few typos in the commit messages (Hugo)
- added an additional fix to patch 2 (Hugo)
- appended tag to patch 13 (Hugo)
- v1 (20240402154219.3583679-1-andriy.shevchenko@linux.intel.com)
Andy Shevchenko (8):
serial: max3100: Enable TIOCM_LOOP
serial: max3100: Get crystal frequency via device property
serial: max3100: Remove duplicating irq field
serial: max3100: Switch to use dev_err_probe()
serial: max3100: Replace MODULE_ALIAS() with respective ID tables
serial: max3100: Switch to DEFINE_SIMPLE_DEV_PM_OPS()
serial: max3100: Extract to_max3100_port() helper macro
serial: max3100: Sort headers
drivers/tty/serial/max3100.c | 208 +++++++++++++++--------------------
1 file changed, 86 insertions(+), 122 deletions(-)
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/8] serial: max3100: Enable TIOCM_LOOP
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 2/8] serial: max3100: Get crystal frequency via device property Andy Shevchenko
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
Enable or disable loopback at run-time.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/max3100.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 75e96ff74571..4a4343e7b1fa 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -32,14 +32,12 @@
/**
* struct plat_max3100 - MAX3100 SPI UART platform data
- * @loopback: force MAX3100 in loopback
* @crystal: 1 for 3.6864 Mhz, 0 for 1.8432
*
* You should use this structure in your machine description to specify
* how the MAX3100 is connected.
*/
struct plat_max3100 {
- int loopback;
int crystal;
};
@@ -109,6 +107,7 @@ struct max3100_port {
int minor; /* minor number */
int crystal; /* 1 if 3.6864Mhz crystal 0 for 1.8432 */
+ int loopback_commit; /* need to change loopback */
int loopback; /* 1 if we are in loopback mode */
/* for handling irqs: need workqueue since we do spi_sync */
@@ -241,9 +240,9 @@ static void max3100_work(struct work_struct *w)
struct max3100_port *s = container_of(w, struct max3100_port, work);
struct tty_port *tport = &s->port.state->port;
unsigned char ch;
+ int conf, cconf, cloopback, crts;
int rxchars;
u16 tx, rx;
- int conf, cconf, crts;
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -253,11 +252,15 @@ static void max3100_work(struct work_struct *w)
conf = s->conf;
cconf = s->conf_commit;
s->conf_commit = 0;
+ cloopback = s->loopback_commit;
+ s->loopback_commit = 0;
crts = s->rts_commit;
s->rts_commit = 0;
spin_unlock(&s->conf_lock);
if (cconf)
max3100_sr(s, MAX3100_WC | conf, &rx);
+ if (cloopback)
+ max3100_sr(s, 0x4001, &rx);
if (crts) {
max3100_sr(s, MAX3100_WD | MAX3100_TE |
(s->rts ? MAX3100_RTS : 0), &rx);
@@ -395,18 +398,24 @@ static void max3100_set_mctrl(struct uart_port *port, unsigned int mctrl)
struct max3100_port *s = container_of(port,
struct max3100_port,
port);
- int rts;
+ int loopback, rts;
dev_dbg(&s->spi->dev, "%s\n", __func__);
+ loopback = (mctrl & TIOCM_LOOP) > 0;
rts = (mctrl & TIOCM_RTS) > 0;
spin_lock(&s->conf_lock);
+ if (s->loopback != loopback) {
+ s->loopback = loopback;
+ s->loopback_commit = 1;
+ }
if (s->rts != rts) {
s->rts = rts;
s->rts_commit = 1;
- max3100_dowork(s);
}
+ if (s->loopback_commit || s->rts_commit)
+ max3100_dowork(s);
spin_unlock(&s->conf_lock);
}
@@ -593,12 +602,6 @@ static int max3100_startup(struct uart_port *port)
return -EBUSY;
}
- if (s->loopback) {
- u16 tx, rx;
- tx = 0x4001;
- max3100_sr(s, tx, &rx);
- }
-
s->conf_commit = 1;
max3100_dowork(s);
/* wait for clock to settle */
@@ -754,7 +757,6 @@ static int max3100_probe(struct spi_device *spi)
spi_set_drvdata(spi, max3100s[i]);
pdata = dev_get_platdata(&spi->dev);
max3100s[i]->crystal = pdata->crystal;
- max3100s[i]->loopback = pdata->loopback;
max3100s[i]->minor = i;
timer_setup(&max3100s[i]->timer, max3100_timeout, 0);
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 2/8] serial: max3100: Get crystal frequency via device property
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 1/8] serial: max3100: Enable TIOCM_LOOP Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 3/8] serial: max3100: Remove duplicating irq field Andy Shevchenko
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
Get crystal frequency via device property instead of using
a platform data.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/max3100.c | 49 +++++++++++++++---------------------
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 4a4343e7b1fa..446bc78061e3 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -20,6 +20,7 @@
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/module.h>
+#include <linux/property.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
#include <linux/spi/spi.h>
@@ -30,17 +31,6 @@
#include <asm/unaligned.h>
-/**
- * struct plat_max3100 - MAX3100 SPI UART platform data
- * @crystal: 1 for 3.6864 Mhz, 0 for 1.8432
- *
- * You should use this structure in your machine description to specify
- * how the MAX3100 is connected.
- */
-struct plat_max3100 {
- int crystal;
-};
-
#define MAX3100_C (1<<14)
#define MAX3100_D (0<<14)
#define MAX3100_W (1<<15)
@@ -106,7 +96,6 @@ struct max3100_port {
int irq; /* irq assigned to the max3100 */
int minor; /* minor number */
- int crystal; /* 1 if 3.6864Mhz crystal 0 for 1.8432 */
int loopback_commit; /* need to change loopback */
int loopback; /* 1 if we are in loopback mode */
@@ -426,7 +415,8 @@ max3100_set_termios(struct uart_port *port, struct ktermios *termios,
struct max3100_port *s = container_of(port,
struct max3100_port,
port);
- int baud = 0;
+ unsigned int baud = port->uartclk / 16;
+ unsigned int baud230400 = (baud == 230400) ? 1 : 0;
unsigned cflag;
u32 param_new, param_mask, parity = 0;
@@ -439,40 +429,40 @@ max3100_set_termios(struct uart_port *port, struct ktermios *termios,
param_new = s->conf & MAX3100_BAUD;
switch (baud) {
case 300:
- if (s->crystal)
+ if (baud230400)
baud = s->baud;
else
param_new = 15;
break;
case 600:
- param_new = 14 + s->crystal;
+ param_new = 14 + baud230400;
break;
case 1200:
- param_new = 13 + s->crystal;
+ param_new = 13 + baud230400;
break;
case 2400:
- param_new = 12 + s->crystal;
+ param_new = 12 + baud230400;
break;
case 4800:
- param_new = 11 + s->crystal;
+ param_new = 11 + baud230400;
break;
case 9600:
- param_new = 10 + s->crystal;
+ param_new = 10 + baud230400;
break;
case 19200:
- param_new = 9 + s->crystal;
+ param_new = 9 + baud230400;
break;
case 38400:
- param_new = 8 + s->crystal;
+ param_new = 8 + baud230400;
break;
case 57600:
- param_new = 1 + s->crystal;
+ param_new = 1 + baud230400;
break;
case 115200:
- param_new = 0 + s->crystal;
+ param_new = 0 + baud230400;
break;
case 230400:
- if (s->crystal)
+ if (baud230400)
param_new = 0;
else
baud = s->baud;
@@ -575,7 +565,7 @@ static int max3100_startup(struct uart_port *port)
dev_dbg(&s->spi->dev, "%s\n", __func__);
s->conf = MAX3100_RM;
- s->baud = s->crystal ? 230400 : 115200;
+ s->baud = port->uartclk / 16;
s->rx_enabled = 1;
if (s->suspending)
@@ -718,8 +708,8 @@ static int uart_driver_registered;
static int max3100_probe(struct spi_device *spi)
{
+ struct device *dev = &spi->dev;
int i, retval;
- struct plat_max3100 *pdata;
u16 rx;
mutex_lock(&max3100s_lock);
@@ -755,20 +745,21 @@ static int max3100_probe(struct spi_device *spi)
max3100s[i]->irq = spi->irq;
spin_lock_init(&max3100s[i]->conf_lock);
spi_set_drvdata(spi, max3100s[i]);
- pdata = dev_get_platdata(&spi->dev);
- max3100s[i]->crystal = pdata->crystal;
max3100s[i]->minor = i;
timer_setup(&max3100s[i]->timer, max3100_timeout, 0);
dev_dbg(&spi->dev, "%s: adding port %d\n", __func__, i);
max3100s[i]->port.irq = max3100s[i]->irq;
- max3100s[i]->port.uartclk = max3100s[i]->crystal ? 3686400 : 1843200;
max3100s[i]->port.fifosize = 16;
max3100s[i]->port.ops = &max3100_ops;
max3100s[i]->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
max3100s[i]->port.line = i;
max3100s[i]->port.type = PORT_MAX3100;
max3100s[i]->port.dev = &spi->dev;
+
+ /* Read clock frequency from a property, uart_add_one_port() will fail if it's not set */
+ device_property_read_u32(dev, "clock-frequency", &max3100s[i]->port.uartclk);
+
retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port);
if (retval < 0)
dev_warn(&spi->dev,
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 3/8] serial: max3100: Remove duplicating irq field
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 1/8] serial: max3100: Enable TIOCM_LOOP Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 2/8] serial: max3100: Get crystal frequency via device property Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 4/8] serial: max3100: Switch to use dev_err_probe() Andy Shevchenko
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
The struct uart_port has a copy of the IRQ that is also stored
in the private data structure. Remove the duplication in the latter
one.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/max3100.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 446bc78061e3..e3104ea7a3ca 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -93,8 +93,6 @@ struct max3100_port {
#define MAX3100_7BIT 4
int rx_enabled; /* if we should rx chars */
- int irq; /* irq assigned to the max3100 */
-
int minor; /* minor number */
int loopback_commit; /* need to change loopback */
int loopback; /* 1 if we are in loopback mode */
@@ -548,8 +546,8 @@ static void max3100_shutdown(struct uart_port *port)
destroy_workqueue(s->workqueue);
s->workqueue = NULL;
}
- if (s->irq)
- free_irq(s->irq, s);
+ if (port->irq)
+ free_irq(port->irq, s);
/* set shutdown mode to save power */
max3100_sr(s, MAX3100_WC | MAX3100_SHDN, &rx);
@@ -561,6 +559,7 @@ static int max3100_startup(struct uart_port *port)
struct max3100_port,
port);
char b[12];
+ int ret;
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -583,10 +582,10 @@ static int max3100_startup(struct uart_port *port)
}
INIT_WORK(&s->work, max3100_work);
- if (request_irq(s->irq, max3100_irq,
- IRQF_TRIGGER_FALLING, "max3100", s) < 0) {
- dev_warn(&s->spi->dev, "cannot allocate irq %d\n", s->irq);
- s->irq = 0;
+ ret = request_irq(port->irq, max3100_irq, IRQF_TRIGGER_FALLING, "max3100", s);
+ if (ret < 0) {
+ dev_warn(&s->spi->dev, "cannot allocate irq %d\n", port->irq);
+ port->irq = 0;
destroy_workqueue(s->workqueue);
s->workqueue = NULL;
return -EBUSY;
@@ -742,14 +741,13 @@ static int max3100_probe(struct spi_device *spi)
return -ENOMEM;
}
max3100s[i]->spi = spi;
- max3100s[i]->irq = spi->irq;
spin_lock_init(&max3100s[i]->conf_lock);
spi_set_drvdata(spi, max3100s[i]);
max3100s[i]->minor = i;
timer_setup(&max3100s[i]->timer, max3100_timeout, 0);
dev_dbg(&spi->dev, "%s: adding port %d\n", __func__, i);
- max3100s[i]->port.irq = max3100s[i]->irq;
+ max3100s[i]->port.irq = spi->irq;
max3100s[i]->port.fifosize = 16;
max3100s[i]->port.ops = &max3100_ops;
max3100s[i]->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
@@ -813,7 +811,7 @@ static int max3100_suspend(struct device *dev)
dev_dbg(&s->spi->dev, "%s\n", __func__);
- disable_irq(s->irq);
+ disable_irq(s->port.irq);
s->suspending = 1;
uart_suspend_port(&max3100_uart_driver, &s->port);
@@ -832,7 +830,7 @@ static int max3100_resume(struct device *dev)
uart_resume_port(&max3100_uart_driver, &s->port);
s->suspending = 0;
- enable_irq(s->irq);
+ enable_irq(s->port.irq);
s->conf_commit = 1;
if (s->workqueue)
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 4/8] serial: max3100: Switch to use dev_err_probe()
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
` (2 preceding siblings ...)
2024-04-09 14:45 ` [PATCH v3 3/8] serial: max3100: Remove duplicating irq field Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 5/8] serial: max3100: Replace MODULE_ALIAS() with respective ID tables Andy Shevchenko
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
Switch to use dev_err_probe() to simplify the error path and
unify a message template.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/max3100.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index e3104ea7a3ca..09ec2ca06989 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -716,9 +716,8 @@ static int max3100_probe(struct spi_device *spi)
if (!uart_driver_registered) {
retval = uart_register_driver(&max3100_uart_driver);
if (retval) {
- printk(KERN_ERR "Couldn't register max3100 uart driver\n");
mutex_unlock(&max3100s_lock);
- return retval;
+ return dev_err_probe(dev, retval, "Couldn't register max3100 uart driver\n");
}
uart_driver_registered = 1;
@@ -728,15 +727,12 @@ static int max3100_probe(struct spi_device *spi)
if (!max3100s[i])
break;
if (i == MAX_MAX3100) {
- dev_warn(&spi->dev, "too many MAX3100 chips\n");
mutex_unlock(&max3100s_lock);
- return -ENOMEM;
+ return dev_err_probe(dev, -ENOMEM, "too many MAX3100 chips\n");
}
max3100s[i] = kzalloc(sizeof(struct max3100_port), GFP_KERNEL);
if (!max3100s[i]) {
- dev_warn(&spi->dev,
- "kmalloc for max3100 structure %d failed!\n", i);
mutex_unlock(&max3100s_lock);
return -ENOMEM;
}
@@ -760,9 +756,7 @@ static int max3100_probe(struct spi_device *spi)
retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port);
if (retval < 0)
- dev_warn(&spi->dev,
- "uart_add_one_port failed for line %d with error %d\n",
- i, retval);
+ dev_err_probe(dev, retval, "uart_add_one_port failed for line %d\n", i);
/* set shutdown mode to save power. Will be woken-up on open */
max3100_sr(max3100s[i], MAX3100_WC | MAX3100_SHDN, &rx);
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 5/8] serial: max3100: Replace MODULE_ALIAS() with respective ID tables
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
` (3 preceding siblings ...)
2024-04-09 14:45 ` [PATCH v3 4/8] serial: max3100: Switch to use dev_err_probe() Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 6/8] serial: max3100: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Andy Shevchenko
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
MODULE_ALIAS() in most cases is a pure hack to avoid placing ID tables.
Replace it with the respective ID tables.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/max3100.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 09ec2ca06989..3004a95e573f 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -19,6 +19,7 @@
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/device.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/serial_core.h>
@@ -840,13 +841,27 @@ static SIMPLE_DEV_PM_OPS(max3100_pm_ops, max3100_suspend, max3100_resume);
#define MAX3100_PM_OPS NULL
#endif
+static const struct spi_device_id max3100_spi_id[] = {
+ { "max3100" },
+ { }
+};
+MODULE_DEVICE_TABLE(spi, max3100_spi_id);
+
+static const struct of_device_id max3100_of_match[] = {
+ { .compatible = "maxim,max3100" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, max3100_of_match);
+
static struct spi_driver max3100_driver = {
.driver = {
.name = "max3100",
+ .of_match_table = max3100_of_match,
.pm = MAX3100_PM_OPS,
},
.probe = max3100_probe,
.remove = max3100_remove,
+ .id_table = max3100_spi_id,
};
module_spi_driver(max3100_driver);
@@ -854,4 +869,3 @@ module_spi_driver(max3100_driver);
MODULE_DESCRIPTION("MAX3100 driver");
MODULE_AUTHOR("Christian Pellegrin <chripell@evolware.org>");
MODULE_LICENSE("GPL");
-MODULE_ALIAS("spi:max3100");
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 6/8] serial: max3100: Switch to DEFINE_SIMPLE_DEV_PM_OPS()
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
` (4 preceding siblings ...)
2024-04-09 14:45 ` [PATCH v3 5/8] serial: max3100: Replace MODULE_ALIAS() with respective ID tables Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 7/8] serial: max3100: Extract to_max3100_port() helper macro Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 8/8] serial: max3100: Sort headers Andy Shevchenko
7 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
The SIMPLE_DEV_PM_OPS() is deprecated, replace it with the
DEFINE_SIMPLE_DEV_PM_OPS() and use pm_sleep_ptr() for setting
the driver's PM routines.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/max3100.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 3004a95e573f..db543eaa39c8 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -21,6 +21,7 @@
#include <linux/device.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/property.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
@@ -797,8 +798,6 @@ static void max3100_remove(struct spi_device *spi)
mutex_unlock(&max3100s_lock);
}
-#ifdef CONFIG_PM_SLEEP
-
static int max3100_suspend(struct device *dev)
{
struct max3100_port *s = dev_get_drvdata(dev);
@@ -834,12 +833,7 @@ static int max3100_resume(struct device *dev)
return 0;
}
-static SIMPLE_DEV_PM_OPS(max3100_pm_ops, max3100_suspend, max3100_resume);
-#define MAX3100_PM_OPS (&max3100_pm_ops)
-
-#else
-#define MAX3100_PM_OPS NULL
-#endif
+static DEFINE_SIMPLE_DEV_PM_OPS(max3100_pm_ops, max3100_suspend, max3100_resume);
static const struct spi_device_id max3100_spi_id[] = {
{ "max3100" },
@@ -857,7 +851,7 @@ static struct spi_driver max3100_driver = {
.driver = {
.name = "max3100",
.of_match_table = max3100_of_match,
- .pm = MAX3100_PM_OPS,
+ .pm = pm_sleep_ptr(&max3100_pm_ops),
},
.probe = max3100_probe,
.remove = max3100_remove,
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 7/8] serial: max3100: Extract to_max3100_port() helper macro
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
` (5 preceding siblings ...)
2024-04-09 14:45 ` [PATCH v3 6/8] serial: max3100: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
2024-04-10 7:17 ` Jiri Slaby
2024-04-09 14:45 ` [PATCH v3 8/8] serial: max3100: Sort headers Andy Shevchenko
7 siblings, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby, Hugo Villeneuve
Instead of using container_of() explicitly, introduce a helper macro.
This saves a lot of lines of code.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
drivers/tty/serial/max3100.c | 67 ++++++++++--------------------------
1 file changed, 19 insertions(+), 48 deletions(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index db543eaa39c8..4e7cd037cfc2 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -16,6 +16,7 @@
/* 4 MAX3100s should be enough for everyone */
#define MAX_MAX3100 4
+#include <linux/container_of.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/device.h>
@@ -110,6 +111,8 @@ struct max3100_port {
struct timer_list timer;
};
+#define to_max3100_port(port) container_of(port, struct max3100_port, port)
+
static struct max3100_port *max3100s[MAX_MAX3100]; /* the chips */
static DEFINE_MUTEX(max3100s_lock); /* race on probe */
@@ -320,9 +323,7 @@ static irqreturn_t max3100_irq(int irqno, void *dev_id)
static void max3100_enable_ms(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
mod_timer(&s->timer, jiffies);
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -330,9 +331,7 @@ static void max3100_enable_ms(struct uart_port *port)
static void max3100_start_tx(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -341,9 +340,7 @@ static void max3100_start_tx(struct uart_port *port)
static void max3100_stop_rx(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -357,9 +354,7 @@ static void max3100_stop_rx(struct uart_port *port)
static unsigned int max3100_tx_empty(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -370,9 +365,7 @@ static unsigned int max3100_tx_empty(struct uart_port *port)
static unsigned int max3100_get_mctrl(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -384,9 +377,7 @@ static unsigned int max3100_get_mctrl(struct uart_port *port)
static void max3100_set_mctrl(struct uart_port *port, unsigned int mctrl)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
int loopback, rts;
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -412,9 +403,7 @@ static void
max3100_set_termios(struct uart_port *port, struct ktermios *termios,
const struct ktermios *old)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
unsigned int baud = port->uartclk / 16;
unsigned int baud230400 = (baud == 230400) ? 1 : 0;
unsigned cflag;
@@ -530,9 +519,7 @@ max3100_set_termios(struct uart_port *port, struct ktermios *termios,
static void max3100_shutdown(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
u16 rx;
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -557,9 +544,7 @@ static void max3100_shutdown(struct uart_port *port)
static int max3100_startup(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
char b[12];
int ret;
@@ -605,9 +590,7 @@ static int max3100_startup(struct uart_port *port)
static const char *max3100_type(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -616,18 +599,14 @@ static const char *max3100_type(struct uart_port *port)
static void max3100_release_port(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
}
static void max3100_config_port(struct uart_port *port, int flags)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -638,9 +617,7 @@ static void max3100_config_port(struct uart_port *port, int flags)
static int max3100_verify_port(struct uart_port *port,
struct serial_struct *ser)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
int ret = -EINVAL;
dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -652,18 +629,14 @@ static int max3100_verify_port(struct uart_port *port,
static void max3100_stop_tx(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
}
static int max3100_request_port(struct uart_port *port)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
return 0;
@@ -671,9 +644,7 @@ static int max3100_request_port(struct uart_port *port)
static void max3100_break_ctl(struct uart_port *port, int break_state)
{
- struct max3100_port *s = container_of(port,
- struct max3100_port,
- port);
+ struct max3100_port *s = to_max3100_port(port);
dev_dbg(&s->spi->dev, "%s\n", __func__);
}
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 8/8] serial: max3100: Sort headers
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
` (6 preceding siblings ...)
2024-04-09 14:45 ` [PATCH v3 7/8] serial: max3100: Extract to_max3100_port() helper macro Andy Shevchenko
@ 2024-04-09 14:45 ` Andy Shevchenko
7 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-09 14:45 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby
Sort the headers in alphabetic order in order to ease
the maintenance for this part.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/max3100.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 4e7cd037cfc2..ce24588150bf 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -18,18 +18,18 @@
#include <linux/container_of.h>
#include <linux/delay.h>
-#include <linux/slab.h>
#include <linux/device.h>
+#include <linux/freezer.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/pm.h>
#include <linux/property.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
+#include <linux/slab.h>
#include <linux/spi/spi.h>
-#include <linux/freezer.h>
-#include <linux/tty.h>
#include <linux/tty_flip.h>
+#include <linux/tty.h>
#include <linux/types.h>
#include <asm/unaligned.h>
--
2.43.0.rc1.1.gbec44491f096
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 7/8] serial: max3100: Extract to_max3100_port() helper macro
2024-04-09 14:45 ` [PATCH v3 7/8] serial: max3100: Extract to_max3100_port() helper macro Andy Shevchenko
@ 2024-04-10 7:17 ` Jiri Slaby
2024-04-10 13:55 ` Andy Shevchenko
0 siblings, 1 reply; 11+ messages in thread
From: Jiri Slaby @ 2024-04-10 7:17 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Hugo Villeneuve
On 09. 04. 24, 16:45, Andy Shevchenko wrote:
> Instead of using container_of() explicitly, introduce a helper macro.
> This saves a lot of lines of code.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
...
> @@ -110,6 +111,8 @@ struct max3100_port {
> struct timer_list timer;
> };
>
> +#define to_max3100_port(port) container_of(port, struct max3100_port, port)
This is wrong. If you pass something other than "port" to
to_max3100_port(), the third arg of container_of() will explode.
Use an inline to avoid mistakes like this.
regards,
--
js
suse labs
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 7/8] serial: max3100: Extract to_max3100_port() helper macro
2024-04-10 7:17 ` Jiri Slaby
@ 2024-04-10 13:55 ` Andy Shevchenko
0 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2024-04-10 13:55 UTC (permalink / raw)
To: Jiri Slaby
Cc: linux-kernel, linux-serial, Greg Kroah-Hartman, Hugo Villeneuve
On Wed, Apr 10, 2024 at 09:17:28AM +0200, Jiri Slaby wrote:
> On 09. 04. 24, 16:45, Andy Shevchenko wrote:
> > Instead of using container_of() explicitly, introduce a helper macro.
> > This saves a lot of lines of code.
...
> > +#define to_max3100_port(port) container_of(port, struct max3100_port, port)
>
> This is wrong. If you pass something other than "port" to to_max3100_port(),
> the third arg of container_of() will explode.
Then don't do that :-)
> Use an inline to avoid mistakes like this.
Sure, thanks for catching this. Should I send an update to prevent this from
happening?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-04-10 13:55 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09 14:45 [PATCH v3 0/8] serial: max3100: Put into shape Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 1/8] serial: max3100: Enable TIOCM_LOOP Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 2/8] serial: max3100: Get crystal frequency via device property Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 3/8] serial: max3100: Remove duplicating irq field Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 4/8] serial: max3100: Switch to use dev_err_probe() Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 5/8] serial: max3100: Replace MODULE_ALIAS() with respective ID tables Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 6/8] serial: max3100: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 7/8] serial: max3100: Extract to_max3100_port() helper macro Andy Shevchenko
2024-04-10 7:17 ` Jiri Slaby
2024-04-10 13:55 ` Andy Shevchenko
2024-04-09 14:45 ` [PATCH v3 8/8] serial: max3100: Sort headers Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox