serial: max310x: Improve driver. Part 2.
PATCH 4/8 serial: max310x: Add missing mutex_destroy() on driver exit
In reply to Alexander Shiyan--- drivers/tty/serial/max310x.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/max310x.c +5 -2
@@ -1134,8 +1134,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, s->devtype = devtype;dev_set_drvdata (dev, s); -mutex_init (&s->mutex); -/* Check device to ensure we are talking to what we expect */ ret = devtype->detect (dev);if (ret)
@@ -1193,6 +1191,8 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, goto out_uart;#endif +mutex_init (&s->mutex); +for (i =0 ; i < devtype->nr; i++) {/* Initialize port data */ s->p[i].port.line = i;
@@ -1233,6 +1233,8 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,dev_err (dev,"Unable to reguest IRQ %i\n" , irq); +mutex_destroy (&s->mutex); +#ifdef CONFIG_GPIOLIB WARN_ON (gpiochip_remove (&s->gpio));#endif
@@ -1264,6 +1266,7 @@ static int max310x_remove(struct device *dev) s->devtype->power (&s->p[i].port,0 ); } +mutex_destroy (&s->mutex);uart_unregister_driver (&s->uart);clk_disable_unprepare (s->clk);
Signature · 1 line
1.8.3.2
PATCH 3/8 serial: max310x: Always use dynamic GPIO ID assignment
In reply to Alexander ShiyanAlways register GPIOs and use dynamic GPIO ID assignment. This is no much worth if GPIOs is not used, but helps remove private driver header and add DT support in the future. Additionally, patch adds missing uart_unregister_driver() call if probe() fails.
--- drivers/tty/serial/max310x.c | 55 ++++++++++++++++++----------------- include/linux/platform_data/max310x.h | 3 -- 2 files changed, 28 insertions(+), 30 deletions(-)
drivers/tty/serial/max310x.c +28 -27
@@ -294,7 +294,6 @@ struct max310x_port {struct mutex mutex;struct clk *clk;struct max310x_pdata *pdata; -int gpio_used;#ifdef CONFIG_GPIOLIB struct gpio_chip gpio;#endif
@@ -1177,6 +1176,23 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, goto out_clk; } +#ifdef CONFIG_GPIOLIB +/* Setup GPIO cotroller */ + s->gpio.owner =THIS_MODULE ; + s->gpio.dev = dev; + s->gpio.label =dev_name (dev); + s->gpio.direction_input = max310x_gpio_direction_input; + s->gpio.get = max310x_gpio_get; + s->gpio.direction_output= max310x_gpio_direction_output; + s->gpio.set = max310x_gpio_set; + s->gpio.base =-1 ; + s->gpio.ngpio = devtype->nr *4 ; + s->gpio.can_sleep =1 ; + ret =gpiochip_add (&s->gpio); +if (ret) + goto out_uart; +#endif +for (i =0 ; i < devtype->nr; i++) {/* Initialize port data */ s->p[i].port.line = i;
@@ -1208,25 +1224,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, devtype->power (&s->p[i].port,0 ); } -#ifdef CONFIG_GPIOLIB -/* Setup GPIO cotroller */ -if (s->pdata->gpio_base) { - s->gpio.owner =THIS_MODULE ; - s->gpio.dev = dev; - s->gpio.label =dev_name (dev); - s->gpio.direction_input = max310x_gpio_direction_input; - s->gpio.get = max310x_gpio_get; - s->gpio.direction_output= max310x_gpio_direction_output; - s->gpio.set = max310x_gpio_set; - s->gpio.base = s->pdata->gpio_base; - s->gpio.ngpio = devtype->nr *4 ; - s->gpio.can_sleep =1 ; -if (!gpiochip_add (&s->gpio)) - s->gpio_used =1 ; - }else -dev_info (dev,"GPIO support not enabled\n" ); -#endif -/* Setup interrupt */ ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
@@ -1235,11 +1232,14 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,return 0 ;dev_err (dev,"Unable to reguest IRQ %i\n" , irq); +#ifdef CONFIG_GPIOLIB -if (s->gpio_used) -WARN_ON (gpiochip_remove (&s->gpio)); +WARN_ON (gpiochip_remove (&s->gpio));#endif +out_uart: +uart_unregister_driver (&s->uart); + out_clk:clk_disable_unprepare (s->clk);
@@ -1251,6 +1251,12 @@ static int max310x_remove(struct device *dev)struct max310x_port *s =dev_get_drvdata (dev);int i, ret =0 ; +#ifdef CONFIG_GPIOLIB + ret =gpiochip_remove (&s->gpio); +if (ret) +return ret; +#endif +for (i =0 ; i < s->uart.nr; i++) {cancel_work_sync (&s->p[i].tx_work);cancel_work_sync (&s->p[i].md_work);
@@ -1261,11 +1267,6 @@ static int max310x_remove(struct device *dev)uart_unregister_driver (&s->uart);clk_disable_unprepare (s->clk); -#ifdef CONFIG_GPIOLIB -if (s->gpio_used) - ret =gpiochip_remove (&s->gpio); -#endif -return ret; }
include/linux/platform_data/max310x.h +0 -3
@@ -21,7 +21,6 @@* * static struct max310x_pdata max3107_pdata = { * .uart_flags[0] = MAX310X_ECHO_SUPRESS | MAX310X_AUTO_DIR_CTRL, -* .gpio_base = -1, * }; * * static struct spi_board_info spi_device_max3107[] = {
@@ -45,8 +44,6 @@ struct max310x_pdata {#define MAX310X_AUTO_DIR_CTRL (0x00000004)/* Enable Auto direction * control (RS-485) */ -/* GPIO base number (can be negative) */ - const int gpio_base; };#endif
Signature · 1 line
1.8.3.2
PATCH 7/8 serial: max310x: Add devicetree support
In reply to Alexander ShiyanThis patch adds devicetree support for the MAX310X serial driver.
--- drivers/tty/serial/max310x.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-)
drivers/tty/serial/max310x.c +32 -9
@@ -19,6 +19,8 @@#include <linux/device.h> #include <linux/gpio.h> #include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/regmap.h> #include <linux/serial_core.h> #include <linux/serial.h>
@@ -1093,7 +1095,7 @@ static int max310x_gpio_direction_output(struct gpio_chip *chip,#endif static int max310x_probe (struct device *dev,struct max310x_devtype *devtype, -struct regmap *regmap,int irq) +struct regmap *regmap,int irq,unsigned long flags) {int i, ret, fmin, fmax, freq, uartclk;struct clk *clk_osc, *clk_xtal;
@@ -1237,8 +1239,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,/* Setup interrupt */ ret =devm_request_threaded_irq (dev, irq,NULL , max310x_ist, -IRQF_TRIGGER_FALLING |IRQF_ONESHOT , -dev_name (dev), s); +IRQF_ONESHOT | flags,dev_name (dev), s);if (!ret)return 0 ;
@@ -1284,6 +1285,15 @@ static int max310x_remove(struct device *dev)return ret; } +static const struct of_device_id __maybe_unused max310x_dt_ids[] = { + { .compatible ="maxim,max3107" , .data = &max3107_devtype, }, + { .compatible ="maxim,max3108" , .data = &max3108_devtype, }, + { .compatible ="maxim,max3109" , .data = &max3109_devtype, }, + { .compatible ="maxim,max14830" , .data = &max14830_devtype }, + { } +}; +MODULE_DEVICE_TABLE (of, max310x_dt_ids); +static struct regmap_config regcfg = { .reg_bits =8 , .val_bits =8 ,
@@ -1297,8 +1307,8 @@ static struct regmap_config regcfg = {#ifdef CONFIG_SPI_MASTER static int max310x_spi_probe (struct spi_device *spi) { -struct max310x_devtype *devtype = - (struct max310x_devtype *)spi_get_device_id (spi)->driver_data; +struct max310x_devtype *devtype; +unsigned long flags =0 ;struct regmap *regmap;int ret;
@@ -1310,10 +1320,22 @@ static int max310x_spi_probe(struct spi_device *spi)if (ret)return ret; +if (spi->dev.of_node) { +const struct of_device_id *of_id = +of_match_device (max310x_dt_ids, &spi->dev); + + devtype = (struct max310x_devtype *)of_id->data; + }else { +const struct spi_device_id *id_entry =spi_get_device_id (spi); + + devtype = (struct max310x_devtype *)id_entry->driver_data; + flags =IRQF_TRIGGER_FALLING ; + } + regcfg.max_register = devtype->nr *0x20 -1 ; regmap =devm_regmap_init_spi (spi, ®cfg); -return max310x_probe (&spi->dev, devtype, regmap, spi->irq); +return max310x_probe (&spi->dev, devtype, regmap, spi->irq, flags); }static int max310x_spi_remove (struct spi_device *spi)
@@ -1332,9 +1354,10 @@ MODULE_DEVICE_TABLE(spi, max310x_id_table);static struct spi_driver max310x_uart_driver = { .driver = { - .name =MAX310X_NAME , - .owner =THIS_MODULE , - .pm = &max310x_pm_ops, + .name =MAX310X_NAME , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (max310x_dt_ids), + .pm = &max310x_pm_ops, }, .probe = max310x_spi_probe, .remove = max310x_spi_remove,
Signature · 1 line
1.8.3.2
PATCH 2/8 serial: max310x: Migrate to CLK API
In reply to Alexander ShiyanThis patch removes "frequency" parameter from MAX310X platform_data and uses CLK API for getting clock. Clock type (XTAL/OSC) is determined by clk name.
--- drivers/tty/serial/max310x.c | 86 ++++++++++++++++++++++------------- include/linux/platform_data/max310x.h | 7 --- 2 files changed, 55 insertions(+), 38 deletions(-)
drivers/tty/serial/max310x.c +55 -31
@@ -17,6 +17,7 @@#include <linux/delay.h> #include <linux/device.h> #include <linux/bitops.h> +#include <linux/clk.h> #include <linux/serial_core.h> #include <linux/serial.h> #include <linux/tty.h>
@@ -291,6 +292,7 @@ struct max310x_port {struct max310x_devtype *devtype;struct regmap *regmap;struct mutex mutex; +struct clk *clk;struct max310x_pdata *pdata;int gpio_used;#ifdef CONFIG_GPIOLIB
@@ -546,18 +548,19 @@ static int max310x_update_best_err(unsigned long f, long *besterr)return 1 ; } -static int max310x_set_ref_clk (struct max310x_port *s) +static int max310x_set_ref_clk (struct max310x_port *s,unsigned long freq, +bool xtal) {unsigned int div, clksrc, pllcfg =0 ;long besterr =-1 ; -unsigned long fdiv, fmul, bestfreq = s->pdata->frequency; +unsigned long fdiv, fmul, bestfreq = freq;/* First, update error without PLL */ -max310x_update_best_err (s->pdata->frequency, &besterr); +max310x_update_best_err (freq, &besterr);/* Try all possible PLL dividers */ for (div =1 ; (div <=63 ) && besterr; div++) { - fdiv =DIV_ROUND_CLOSEST (s->pdata->frequency, div); + fdiv =DIV_ROUND_CLOSEST (freq, div);/* Try multiplier 6 */ fmul = fdiv *6 ;
@@ -590,10 +593,7 @@ static int max310x_set_ref_clk(struct max310x_port *s) }/* Configure clock source */ -if (s->pdata->driver_flags &MAX310X_EXT_CLK ) - clksrc =MAX310X_CLKSRC_EXTCLK_BIT ; -else - clksrc =MAX310X_CLKSRC_CRYST_BIT ; + clksrc = xtal ?MAX310X_CLKSRC_CRYST_BIT :MAX310X_CLKSRC_EXTCLK_BIT ;/* Configure PLL */ if (pllcfg) {
@@ -605,7 +605,7 @@ static int max310x_set_ref_clk(struct max310x_port *s)regmap_write (s->regmap,MAX310X_CLKSRC_REG , clksrc);/* Wait for crystal */ -if (pllcfg && !(s->pdata->driver_flags &MAX310X_EXT_CLK )) +if (pllcfg && xtal)msleep (10 );return (int )bestfreq;
@@ -1078,9 +1078,11 @@ static int max310x_gpio_direction_output(struct gpio_chip *chip,static int max310x_probe (struct device *dev,struct max310x_devtype *devtype,struct regmap *regmap,int irq) { -struct max310x_port *s;struct max310x_pdata *pdata =dev_get_platdata (dev); -int i, ret, uartclk; +int i, ret, fmin, fmax, freq, uartclk; +struct clk *clk_osc, *clk_xtal; +struct max310x_port *s; +bool xtal = false;if (IS_ERR (regmap))return PTR_ERR (regmap);
@@ -1098,14 +1100,35 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,return -ENOMEM ; } -/* Check input frequency */ -if ((pdata->driver_flags &MAX310X_EXT_CLK ) && - ((pdata->frequency <500000 ) || (pdata->frequency >35000000 ))) - goto err_freq; -/* Check frequency for quartz */ -if (!(pdata->driver_flags &MAX310X_EXT_CLK ) && - ((pdata->frequency <1000000 ) || (pdata->frequency >4000000 ))) - goto err_freq; + clk_osc =devm_clk_get (dev,"osc" ); + clk_xtal =devm_clk_get (dev,"xtal" ); +if (!IS_ERR (clk_osc)) { + s->clk = clk_osc; + fmin =500000 ; + fmax =35000000 ; + }else if (!IS_ERR (clk_xtal)) { + s->clk = clk_xtal; + fmin =1000000 ; + fmax =4000000 ; + xtal = true; + }else if (PTR_ERR (clk_osc) == -EPROBE_DEFER || +PTR_ERR (clk_xtal) == -EPROBE_DEFER ) { +return -EPROBE_DEFER ; + }else { +dev_err (dev,"Cannot get clock\n" ); +return -EINVAL ; + } + + ret =clk_prepare_enable (s->clk); +if (ret) +return ret; + + freq =clk_get_rate (s->clk); +/* Check frequency limits */ +if (freq < fmin || freq > fmax) { + ret = -ERANGE ; + goto out_clk; + } s->pdata = pdata; s->regmap = regmap;
@@ -1117,7 +1140,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,/* Check device to ensure we are talking to what we expect */ ret = devtype->detect (dev);if (ret) -return ret; + goto out_clk;for (i =0 ; i < devtype->nr; i++) {unsigned int offs = i <<5 ;
@@ -1139,7 +1162,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, MAX310X_MODE1_AUTOSLEEP_BIT); } - uartclk =max310x_set_ref_clk (s); + uartclk =max310x_set_ref_clk (s, freq, xtal);dev_dbg (dev,"Reference clock set to %i Hz\n" , uartclk);/* Register UART driver */
@@ -1151,7 +1174,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, ret =uart_register_driver (&s->uart);if (ret) {dev_err (dev,"Registering UART driver failed\n" ); -return ret; + goto out_clk; }for (i =0 ; i < devtype->nr; i++) {
@@ -1208,19 +1231,19 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, ret =devm_request_threaded_irq (dev, irq,NULL , max310x_ist,IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,dev_name (dev), s); -if (ret) { -dev_err (dev,"Unable to reguest IRQ %i\n" , irq); +if (!ret) +return 0 ; + +dev_err (dev,"Unable to reguest IRQ %i\n" , irq);#ifdef CONFIG_GPIOLIB -if (s->gpio_used) -WARN_ON (gpiochip_remove (&s->gpio)); +if (s->gpio_used) +WARN_ON (gpiochip_remove (&s->gpio));#endif - } -return ret; +out_clk: +clk_disable_unprepare (s->clk); -err_freq: -dev_err (dev,"Frequency parameter incorrect\n" ); -return -EINVAL ; +return ret; }static int max310x_remove (struct device *dev)
@@ -1236,6 +1259,7 @@ static int max310x_remove(struct device *dev) }uart_unregister_driver (&s->uart); +clk_disable_unprepare (s->clk);#ifdef CONFIG_GPIOLIB if (s->gpio_used)
include/linux/platform_data/max310x.h +0 -7
@@ -20,9 +20,7 @@* Example board initialization data: * * static struct max310x_pdata max3107_pdata = { -* .driver_flags = MAX310X_EXT_CLK, * .uart_flags[0] = MAX310X_ECHO_SUPRESS | MAX310X_AUTO_DIR_CTRL, -* .frequency = 3686400, * .gpio_base = -1, * }; *
@@ -41,17 +39,12 @@/* MAX310X platform data structure */ struct max310x_pdata { -/* Flags global to driver */ -const u8 driver_flags; -#define MAX310X_EXT_CLK (0x00000001)/* External clock enable */ /* Flags global to UART port */ const u8 uart_flags[MAX310X_MAX_UARTS ];#define MAX310X_ECHO_SUPRESS (0x00000002)/* Enable echo supress */ #define MAX310X_AUTO_DIR_CTRL (0x00000004)/* Enable Auto direction * control (RS-485) */ -/* Frequency (extrenal clock or crystal) */ -const int frequency;/* GPIO base number (can be negative) */ const int gpio_base; };
Signature · 1 line
1.8.3.2
PATCH 1/8 serial: max310x: Move all SPI-dependent stuff in one place
In reply to Alexander ShiyanPatch move all SPI-dependent stuff in one place. This include move PM-function definitions out of CONFIG_SPI_MASTER and move regmap initialization out of common probe into CONFIG_SPI_MASTER which may help to add I2C support in the future for this driver.
--- drivers/tty/serial/max310x.c | 56 +++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 32 deletions(-)
drivers/tty/serial/max310x.c +24 -32
@@ -290,7 +290,6 @@ struct max310x_port {struct uart_driver uart;struct max310x_devtype *devtype;struct regmap *regmap; -struct regmap_config regcfg;struct mutex mutex;struct max310x_pdata *pdata;int gpio_used;
@@ -1028,6 +1027,8 @@ static int __maybe_unused max310x_resume(struct device *dev)return 0 ; } +static SIMPLE_DEV_PM_OPS(max310x_pm_ops, max310x_suspend, max310x_resume); +#ifdef CONFIG_GPIOLIB static int max310x_gpio_get (struct gpio_chip *chip,unsigned offset) {
@@ -1074,13 +1075,16 @@ static int max310x_gpio_direction_output(struct gpio_chip *chip, }#endif -static int max310x_probe (struct device *dev,int is_spi, -struct max310x_devtype *devtype,int irq) +static int max310x_probe (struct device *dev,struct max310x_devtype *devtype, +struct regmap *regmap,int irq) {struct max310x_port *s;struct max310x_pdata *pdata =dev_get_platdata (dev);int i, ret, uartclk; +if (IS_ERR (regmap)) +return PTR_ERR (regmap); +if (!pdata) {dev_err (dev,"No platform data supplied\n" );return -EINVAL ;
@@ -1104,34 +1108,12 @@ static int max310x_probe(struct device *dev, int is_spi, goto err_freq; s->pdata = pdata; + s->regmap = regmap; s->devtype = devtype;dev_set_drvdata (dev, s);mutex_init (&s->mutex); -/* Setup regmap */ - s->regcfg.reg_bits =8 ; - s->regcfg.val_bits =8 ; - s->regcfg.read_flag_mask =0x00 ; - s->regcfg.write_flag_mask =0x80 ; - s->regcfg.cache_type =REGCACHE_RBTREE ; - s->regcfg.writeable_reg = max310x_reg_writeable; - s->regcfg.volatile_reg = max310x_reg_volatile; - s->regcfg.precious_reg = max310x_reg_precious; - s->regcfg.max_register = devtype->nr *0x20 -1 ; - -if (IS_ENABLED (CONFIG_SPI_MASTER ) && is_spi) { -struct spi_device *spi =to_spi_device (dev); - - s->regmap =devm_regmap_init_spi (spi, &s->regcfg); - }else -return -ENOTSUPP ; - -if (IS_ERR (s->regmap)) { -dev_err (dev,"Failed to initialize register map\n" ); -return PTR_ERR (s->regmap); - } -/* Check device to ensure we are talking to what we expect */ ret = devtype->detect (dev);if (ret)
@@ -1263,11 +1245,22 @@ static int max310x_remove(struct device *dev)return ret; } +static struct regmap_config regcfg = { + .reg_bits =8 , + .val_bits =8 , + .write_flag_mask =0x80 , + .cache_type =REGCACHE_RBTREE , + .writeable_reg = max310x_reg_writeable, + .volatile_reg = max310x_reg_volatile, + .precious_reg = max310x_reg_precious, +}; +#ifdef CONFIG_SPI_MASTER static int max310x_spi_probe (struct spi_device *spi) {struct max310x_devtype *devtype = (struct max310x_devtype *)spi_get_device_id (spi)->driver_data; +struct regmap *regmap;int ret;/* Setup SPI bus */
@@ -1275,12 +1268,13 @@ static int max310x_spi_probe(struct spi_device *spi) spi->mode = spi->mode ? :SPI_MODE_0 ; spi->max_speed_hz = spi->max_speed_hz ? :26000000 ; ret =spi_setup (spi); -if (ret) { -dev_err (&spi->dev,"SPI setup failed\n" ); +if (ret)return ret; - } -return max310x_probe (&spi->dev,1 , devtype, spi->irq); + regcfg.max_register = devtype->nr *0x20 -1 ; + regmap =devm_regmap_init_spi (spi, ®cfg); + +return max310x_probe (&spi->dev, devtype, regmap, spi->irq); }static int max310x_spi_remove (struct spi_device *spi)
@@ -1288,8 +1282,6 @@ static int max310x_spi_remove(struct spi_device *spi)return max310x_remove (&spi->dev); } -static SIMPLE_DEV_PM_OPS(max310x_pm_ops, max310x_suspend, max310x_resume); -static const struct spi_device_id max310x_id_table[] = { {"max3107" , (kernel_ulong_t)&max3107_devtype, }, {"max3108" , (kernel_ulong_t)&max3108_devtype, },
Signature · 1 line
1.8.3.2
cover serial: max310x: Improve driver. Part 2.
This patchset provide various improvements/fixes for MAX310X serial driver.
Series is designed to overlay on top of the first part of a series of improvements. The end result of this series adds DT support for this driver and eliminates private header.
Alexander Shiyan (8):
serial: max310x: Move all SPI-dependent stuff in one place
serial: max310x: Migrate to CLK API
serial: max310x: Always use dynamic GPIO ID assignment
serial: max310x: Add missing mutex_destroy() on driver exit
serial: max310x: Add support for RS-485 mode
serial: max310x: Driver cleanup
serial: max310x: Add devicetree support
serial: max310x: Add bindings documentation for the MAX310X UARTs
.../devicetree/bindings/serial/maxim,max310x.txt | 36 +++ drivers/tty/serial/max310x.c | 340 ++++++++++++--------- include/linux/platform_data/max310x.h | 59 ---- 3 files changed, 233 insertions(+), 202 deletions(-) create mode 100644 Documentation/devicetree/bindings/serial/maxim,max310x.txt delete mode 100644 include/linux/platform_data/max310x.h
Signature · 1 line
1.8.3.2
PATCH 5/8 serial: max310x: Add support for RS-485 mode
This patch adds support for RS-485 (TIOCSRS485/TIOCGRS485) IOCTLs. As a result this patch eliminate private driver header.
--- drivers/tty/serial/max310x.c | 77 +++++++++++++++++++++++++---------- include/linux/platform_data/max310x.h | 49 ---------------------- 2 files changed, 56 insertions(+), 70 deletions(-) delete mode 100644 include/linux/platform_data/max310x.h
drivers/tty/serial/max310x.c +56 -21
@@ -26,8 +26,6 @@#include <linux/gpio.h> #include <linux/spi/spi.h> -#include <linux/platform_data/max310x.h> -#define MAX310X_NAME "max310x"#define MAX310X_MAJOR 204#define MAX310X_MINOR 209
@@ -293,7 +291,6 @@ struct max310x_port {struct regmap *regmap;struct mutex mutex;struct clk *clk; -struct max310x_pdata *pdata;#ifdef CONFIG_GPIOLIB struct gpio_chip gpio;#endif
@@ -898,26 +895,70 @@ static void max310x_set_termios(struct uart_port *port,uart_update_timeout (port, termios->c_cflag, baud); } +static int max310x_ioctl (struct uart_port *port,unsigned int cmd, +unsigned long arg) +{ +struct serial_rs485 rs485; +unsigned int val; + +switch (cmd) { +case TIOCSRS485 : +if (copy_from_user (&rs485, (struct serial_rs485 *)arg, +sizeof (rs485))) +return -EFAULT ; +if (rs485.delay_rts_before_send >0x0f || + rs485.delay_rts_after_send >0x0f ) +return -ERANGE ; + val = (rs485.delay_rts_before_send <<4 ) | + rs485.delay_rts_after_send; +max310x_port_write (port,MAX310X_HDPIXDELAY_REG , val); +if (rs485.flags &SER_RS485_ENABLED ) { +max310x_port_update (port,MAX310X_MODE1_REG , +MAX310X_MODE1_TRNSCVCTRL_BIT , +MAX310X_MODE1_TRNSCVCTRL_BIT ); +max310x_port_update (port,MAX310X_MODE2_REG , +MAX310X_MODE2_ECHOSUPR_BIT , +MAX310X_MODE2_ECHOSUPR_BIT ); + }else { +max310x_port_update (port,MAX310X_MODE1_REG , +MAX310X_MODE1_TRNSCVCTRL_BIT ,0 ); +max310x_port_update (port,MAX310X_MODE2_REG , +MAX310X_MODE2_ECHOSUPR_BIT ,0 ); + } +break ; +case TIOCGRS485 : +memset (&rs485,0 ,sizeof (rs485)); + val =max310x_port_read (port,MAX310X_MODE1_REG ); + rs485.flags = (val &MAX310X_MODE1_TRNSCVCTRL_BIT ) ? +SER_RS485_ENABLED :0 ; + rs485.flags |=SER_RS485_RTS_ON_SEND ; + val =max310x_port_read (port,MAX310X_HDPIXDELAY_REG ); + rs485.delay_rts_before_send = val >>4 ; + rs485.delay_rts_after_send = val &0x0f ; +if (copy_to_user ((struct serial_rs485 *)arg, &rs485, +sizeof (rs485))) +return -EFAULT ; +break ; +default : +return -ENOIOCTLCMD ; + } + +return 0 ; +} +static int max310x_startup (struct uart_port *port) { -unsigned int val, line = port->line;struct max310x_port *s =dev_get_drvdata (port->dev); +unsigned int val; s->devtype->power (port,1 );/* Configure MODE1 register */ max310x_port_update (port,MAX310X_MODE1_REG , -MAX310X_MODE1_TRNSCVCTRL_BIT , - (s->pdata->uart_flags[line] &MAX310X_AUTO_DIR_CTRL ) - ?MAX310X_MODE1_TRNSCVCTRL_BIT :0 ); +MAX310X_MODE1_TRNSCVCTRL_BIT ,0 ); -/* Configure MODE2 register */ - val =MAX310X_MODE2_RXEMPTINV_BIT ; -if (s->pdata->uart_flags[line] &MAX310X_ECHO_SUPRESS ) - val |=MAX310X_MODE2_ECHOSUPR_BIT ; - -/* Reset FIFOs */ - val |=MAX310X_MODE2_FIFORST_BIT ; +/* Configure MODE2 register & Reset FIFOs*/ + val =MAX310X_MODE2_RXEMPTINV_BIT |MAX310X_MODE2_FIFORST_BIT ;max310x_port_write (port,MAX310X_MODE2_REG , val);max310x_port_update (port,MAX310X_MODE2_REG ,MAX310X_MODE2_FIFORST_BIT ,0 );
@@ -998,6 +1039,7 @@ static const struct uart_ops max310x_ops = { .release_port = max310x_null_void, .config_port = max310x_config_port, .verify_port = max310x_verify_port, + .ioctl = max310x_ioctl, };static int __maybe_unused max310x_suspend (struct device *dev)
@@ -1077,7 +1119,6 @@ static int max310x_gpio_direction_output(struct gpio_chip *chip,static int max310x_probe (struct device *dev,struct max310x_devtype *devtype,struct regmap *regmap,int irq) { -struct max310x_pdata *pdata =dev_get_platdata (dev);int i, ret, fmin, fmax, freq, uartclk;struct clk *clk_osc, *clk_xtal;struct max310x_port *s;
@@ -1086,11 +1127,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,if (IS_ERR (regmap))return PTR_ERR (regmap); -if (!pdata) { -dev_err (dev,"No platform data supplied\n" ); -return -EINVAL ; - } -/* Alloc port structure */ s =devm_kzalloc (dev,sizeof (*s) +sizeof (struct max310x_one ) * devtype->nr,GFP_KERNEL );
@@ -1129,7 +1165,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, goto out_clk; } - s->pdata = pdata; s->regmap = regmap; s->devtype = devtype;dev_set_drvdata (dev, s);
include/linux/platform_data/max310x.h deleted +0 -49
49 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 6/8 serial: max310x: Driver cleanup
In reply to Alexander ShiyanThis patch removes some unused definitions from driver code and sort #includes alphabetically.
--- drivers/tty/serial/max310x.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-)
drivers/tty/serial/max310x.c +5 -29
@@ -13,17 +13,17 @@* (at your option) any later version. */ -#include <linux/module.h> -#include <linux/delay.h> -#include <linux/device.h> #include <linux/bitops.h> #include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/gpio.h> +#include <linux/module.h> +#include <linux/regmap.h> #include <linux/serial_core.h> #include <linux/serial.h> #include <linux/tty.h> #include <linux/tty_flip.h> -#include <linux/regmap.h> -#include <linux/gpio.h> #include <linux/spi/spi.h> #define MAX310X_NAME "max310x"
@@ -160,10 +160,6 @@/* IRDA register bits */ #define MAX310X_IRDA_IRDAEN_BIT (1 << 0)/* IRDA mode enable */ #define MAX310X_IRDA_SIR_BIT (1 << 1)/* SIR mode enable */ -#define MAX310X_IRDA_SHORTIR_BIT (1 << 2)/* Short SIR mode enable */ -#define MAX310X_IRDA_MIR_BIT (1 << 3)/* MIR mode enable */ -#define MAX310X_IRDA_RXINV_BIT (1 << 4)/* RX logic inversion enable */ -#define MAX310X_IRDA_TXINV_BIT (1 << 5)/* TX logic inversion enable */ /* Flow control trigger level register masks */ #define MAX310X_FLOWLVL_HALT_MASK (0x000f)/* Flow control halt level */
@@ -219,26 +215,6 @@* XOFF2 */ -/* GPIO configuration register bits */ -#define MAX310X_GPIOCFG_GP0OUT_BIT (1 << 0)/* GPIO 0 output enable */ -#define MAX310X_GPIOCFG_GP1OUT_BIT (1 << 1)/* GPIO 1 output enable */ -#define MAX310X_GPIOCFG_GP2OUT_BIT (1 << 2)/* GPIO 2 output enable */ -#define MAX310X_GPIOCFG_GP3OUT_BIT (1 << 3)/* GPIO 3 output enable */ -#define MAX310X_GPIOCFG_GP0OD_BIT (1 << 4)/* GPIO 0 open-drain enable */ -#define MAX310X_GPIOCFG_GP1OD_BIT (1 << 5)/* GPIO 1 open-drain enable */ -#define MAX310X_GPIOCFG_GP2OD_BIT (1 << 6)/* GPIO 2 open-drain enable */ -#define MAX310X_GPIOCFG_GP3OD_BIT (1 << 7)/* GPIO 3 open-drain enable */ - -/* GPIO DATA register bits */ -#define MAX310X_GPIODATA_GP0OUT_BIT (1 << 0)/* GPIO 0 output value */ -#define MAX310X_GPIODATA_GP1OUT_BIT (1 << 1)/* GPIO 1 output value */ -#define MAX310X_GPIODATA_GP2OUT_BIT (1 << 2)/* GPIO 2 output value */ -#define MAX310X_GPIODATA_GP3OUT_BIT (1 << 3)/* GPIO 3 output value */ -#define MAX310X_GPIODATA_GP0IN_BIT (1 << 4)/* GPIO 0 input value */ -#define MAX310X_GPIODATA_GP1IN_BIT (1 << 5)/* GPIO 1 input value */ -#define MAX310X_GPIODATA_GP2IN_BIT (1 << 6)/* GPIO 2 input value */ -#define MAX310X_GPIODATA_GP3IN_BIT (1 << 7)/* GPIO 3 input value */ -/* PLL configuration register masks */ #define MAX310X_PLLCFG_PREDIV_MASK (0x3f)/* PLL predivision value */ #define MAX310X_PLLCFG_PLLFACTOR_MASK (0xc0)/* PLL multiplication factor */
Signature · 1 line
1.8.3.2