mux: adgs1408: new driver for Analog Devices ADGS1408/1409 mux …
Subsystems (2)
Mircea Caprioru
maintainerPATCH v2 1/2 mux: adgs1408: new driver for Analog Devices ADGS1408/1409 mux …
This patch adds basic support for Analog Device ADGS1408/09 SPI mux controller.
The device is probed and set to a disabled state. It uses the new mux controller framework.
---
Changelog V1 -> V2
- removed adgs140x wildcard
- removed cells verification since only 0 configuration supported
- added id enum for ADGS1408 and ADGS1409
- sorted includes
MAINTAINERS | 5 ++ drivers/mux/Kconfig | 12 +++++ drivers/mux/Makefile | 2 + drivers/mux/adgs1408.c | 120 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 drivers/mux/adgs1408.c
MAINTAINERS +5 -0
@@ -810,6 +810,11 @@ L: [email protected] S: Maintained F: drivers/media/i2c/ad9389b* +ANALOG DEVICES INC ADGS1408 DRIVER +M: Mircea Caprioru <[email protected]> +S: Supported +F: drivers/mux/adgs1408.c + ANALOG DEVICES INC ADV7180 DRIVER M: Lars-Peter Clausen <[email protected]> L: [email protected]
drivers/mux/Kconfig +12 -0
@@ -21,6 +21,18 @@ config MUX_ADG792A To compile the driver as a module, choose M here: the module will be called mux-adg792a. +config MUX_ADGS1408 + tristate "Analog Devices ADGS1408/ADGS1409 Multiplexers" + depends on SPI + help + ADGS1408 8:1 multiplexer and ADGS1409 double 4:1 multiplexer + switches. + + The driver supports driving each switch independently. + + To compile the driver as a module, choose M here: the module will + be called mux-adgs1408. + config MUX_GPIO tristate "GPIO-controlled Multiplexer" depends on GPIOLIB || COMPILE_TEST
drivers/mux/Makefile +2 -0
@@ -5,10 +5,12 @@ mux-core-objs := core.o mux-adg792a-objs := adg792a.o +mux-adgs1408-objs := adgs1408.o mux-gpio-objs := gpio.o mux-mmio-objs := mmio.o obj-$(CONFIG_MULTIPLEXER) += mux-core.o obj-$(CONFIG_MUX_ADG792A) += mux-adg792a.o +obj-$(CONFIG_MUX_ADGS1408) += mux-adgs1408.o obj-$(CONFIG_MUX_GPIO) += mux-gpio.o obj-$(CONFIG_MUX_MMIO) += mux-mmio.o
drivers/mux/adgs1408.c new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 11 lines · Mircea Caprioru
This patch adds basic support for Analog Device ADGS1408/09 SPI mux controller.
The device is probed and set to a disabled state. It uses the new mux controller framework.
Signed-off-by Mircea Caprioru <[email protected]>---
Changelog V1 -> V2
- removed adgs140x wildcard
- removed cells verification since only 0 configuration supported
Ahhh, the two muxes in 1409 cannot be operated independently, as this is a "differential" mux. That simplifies things quite a bit, and good thing you caught this early!
Quoted 32 lines
- added id enum for ADGS1408 and ADGS1409
- sorted includesMAINTAINERS | 5 ++ drivers/mux/Kconfig | 12 +++++ drivers/mux/Makefile | 2 + drivers/mux/adgs1408.c | 120 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 drivers/mux/adgs1408.cMAINTAINERS +5
-0@@ -810,6 +810,11 @@ L: [email protected] S: Maintained F: drivers/media/i2c/ad9389b* +ANALOG DEVICES INC ADGS1408 DRIVER +M: Mircea Caprioru <[email protected]> +S: Supported +F: drivers/mux/adgs1408.c + ANALOG DEVICES INC ADV7180 DRIVER M: Lars-Peter Clausen <[email protected]> L: [email protected]drivers/mux/Kconfig +0
-0@@ -21,6 +21,18 @@ config MUX_ADG792A To compile the driver as a module, choose M here: the module will
drivers/mux/Kconfig config MUX_ADG792A · line 31
Quoted 10 lines
drivers/mux/Kconfig +8
-0be called mux-adg792a. +config MUX_ADGS1408 + tristate "Analog Devices ADGS1408/ADGS1409 Multiplexers" + depends on SPI + help + ADGS1408 8:1 multiplexer and ADGS1409 double 4:1 multiplexer + switches. + + The driver supports driving each switch independently.
Remove this line. It is confusing since 1408 only have one mux and the two muxes in the dual 1409 cannot be operated independently.
Quoted 30 lines
drivers/mux/Kconfig +4
-0+ + To compile the driver as a module, choose M here: the module will + be called mux-adgs1408. + config MUX_GPIO tristate "GPIO-controlled Multiplexer" depends on GPIOLIB || COMPILE_TESTdrivers/mux/Makefile +2
-0@@ -5,10 +5,12 @@ mux-core-objs := core.o mux-adg792a-objs := adg792a.o +mux-adgs1408-objs := adgs1408.o mux-gpio-objs := gpio.o mux-mmio-objs := mmio.o obj-$(CONFIG_MULTIPLEXER) += mux-core.o obj-$(CONFIG_MUX_ADG792A) += mux-adg792a.o +obj-$(CONFIG_MUX_ADGS1408) += mux-adgs1408.o obj-$(CONFIG_MUX_GPIO) += mux-gpio.o obj-$(CONFIG_MUX_MMIO) += mux-mmio.odrivers/mux/adgs1408.c new file +0
-0
drivers/mux/adgs1408.c line 1
Quoted 1 line
drivers/mux/adgs1408.c new file +1
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0+
The preferred spelling is GPL-2.0-or-later
drivers/mux/adgs1408.c line 3
Quoted 2 lines
drivers/mux/adgs1408.c new file +2
-0+/* +* ADG1408 SPI MUX driver
ADGS1408; you are missing the S.
And I think you could/should mention ADGS1409 here.
drivers/mux/adgs1408.c line 9
Quoted 6 lines
drivers/mux/adgs1408.c new file +6
-0+* +* Copyright 2018 Analog Devices Inc. +*/ + +#include <linux/err.h> +#include <linux/spi/spi.h>
This #include sorts after linux/property.h.
drivers/mux/adgs1408.c line 22
Quoted 13 lines
drivers/mux/adgs1408.c new file +13
-0+#include <linux/module.h> +#include <linux/mux/driver.h> +#include <linux/of_platform.h> +#include <linux/property.h> + +#define ADGS1408_SW_DATA (0x01) +#define ADGS1408_REG_READ (reg) ((reg) | 0x80) +#define ADGS1408_DISABLE (0x00) +#define ADGS1408_MUX (state) (((state) << 1) | 1) + +enum { +ADGS1408 , +ADGS1409
Add a trailing comma here, to make future changes less intrusive.
Quoted 44 lines
drivers/mux/adgs1408.c new file +44
-0+}; + +static int adgs1408_spi_reg_write (struct spi_device *spi, +u8 reg_addr,u8 reg_data) +{ +u8 tx_buf[2 ]; + + tx_buf[0 ] = reg_addr; + tx_buf[1 ] = reg_data; + +return spi_write_then_read (spi, tx_buf,sizeof (tx_buf),NULL ,0 ); +} + +static int adgs1408_set (struct mux_control *mux,int state) +{ +struct spi_device *spi =to_spi_device (mux->chip->dev.parent); +u8 reg; + +if (state ==MUX_IDLE_DISCONNECT ) + reg =ADGS1408_DISABLE ; +else + reg =ADGS1408_MUX (state); + +return adgs1408_spi_reg_write (spi,ADGS1408_SW_DATA , reg); +} + +static const struct mux_control_ops adgs1408_ops = { + .set = adgs1408_set, +}; + +static int adgs1408_probe (struct spi_device *spi) +{ +const struct spi_device_id *id =spi_get_device_id (spi); +struct device *dev = &spi->dev; +struct mux_chip *mux_chip; +struct mux_control *mux; +int ret, idle_state; + + mux_chip =devm_mux_chip_alloc (dev,1 ,0 ); +if (IS_ERR (mux_chip)) +return PTR_ERR (mux_chip); + + mux_chip->ops = &adgs1408_ops; +
drivers/mux/adgs1408.c line 76
Quoted 10 lines
drivers/mux/adgs1408.c new file +10
-0+ ret =adgs1408_spi_reg_write (spi,ADGS1408_SW_DATA ,ADGS1408_DISABLE ); +if (ret <0 ) +return ret; + + ret =device_property_read_u32_array (dev,"idle-state" , + &idle_state, + mux_chip->controllers); +if (ret <0 ) { + idle_state =MUX_IDLE_AS_IS ; + }
Drop the {} here.
Quoted 7 lines
drivers/mux/adgs1408.c new file +7
-0+ + mux = mux_chip->mux; + +if (id->driver_data ==ADGS1408 ) + mux->states =8 ; +else + mux->states =4 ;
drivers/mux/adgs1408.c line 93
Quoted 10 lines
drivers/mux/adgs1408.c new file +10
-0+ +switch (idle_state) { +case MUX_IDLE_DISCONNECT : +case MUX_IDLE_AS_IS : + case 0 ... 7: +/* adgs1409 supports only 4 states */ +if (id->driver_data ==ADGS1409 && idle_state >3 ) +return -EINVAL ; + mux->idle_state = idle_state; +break ;
If you reverse the test above, or if you rewrite it like below, you can fall through and get the error message (w/o duplication), like this (since the MUX_IDLE_... defines are both negative, but you already depend on that):
/* adgs1409 supports only 4 states */
if (idle_state < mux->states) {
mux->idle_state = idle_state;
break;
}
/* fall through */drivers/mux/adgs1408.c line 104
Quoted 11 lines
drivers/mux/adgs1408.c new file +11
-0+default : +dev_err (dev,"invalid idle-state %d\n" , idle_state); +return -EINVAL ; + } + +return devm_mux_chip_register (dev, mux_chip); +} + +static const struct spi_device_id adgs1408_id[] = { + {"adi,adgs1408" ,ADGS1408 }, + {"adi,adgs1409" ,ADGS1409 },
This looks weird. Other spi_device_id lookup-tables do not have dt-style ids like this; they have the equivalent of "adgs1408" and "adgs1409".
drivers/mux/adgs1408.c line 111
Quoted 7 lines
drivers/mux/adgs1408.c new file +7
-0+ { } +}; +MODULE_DEVICE_TABLE (spi, adgs1408_id); + +static struct spi_driver adgs1408_driver = { + .driver = { + .name ="adgs1408" ,
You have (silently) dropped .of_match_table since v1. Why is it not needed? I felt much more comfortable with what was in v1 for this area of the patch.
Cheers,
Peter
Quoted 9 lines
drivers/mux/adgs1408.c new file +8
-0+ }, + .probe = adgs1408_probe, + .id_table = adgs1408_id, +}; +module_spi_driver (adgs1408_driver); + +MODULE_AUTHOR ("Mircea Caprioru <[email protected]>" ); +MODULE_DESCRIPTION("Analog Devices ADGS1408 MUX driver");> +MODULE_LICENSE("GPL v2");
Caprioru, Mircea
maintainerQuoted 14 lines · Peter Rosin
Quoted 7 lines · Mircea Caprioru
This patch adds basic support for Analog Device ADGS1408/09 SPI mux controller.
The device is probed and set to a disabled state. It uses the new mux
controller framework.Quoted 5 lines
Signed-off-by Mircea Caprioru <[email protected]>---
Changelog V1 -> V2
- removed adgs140x wildcard
- removed cells verification since only 0 configuration supported
Quoted 5 lines
Ahhh, the two muxes in 1409 cannot be operated independently, as this is a
"differential" mux. That simplifies things quite a bit, and good thing you
caught this early!
Yeah, I understood the mux framework a bit better the second time I looked at it (after your first review).
Quoted 37 lines
Quoted 37 lines
- added id enum for ADGS1408 and ADGS1409
- sorted includesMAINTAINERS | 5 ++ drivers/mux/Kconfig | 12 +++++ drivers/mux/Makefile | 2 + drivers/mux/adgs1408.c | 120 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 drivers/mux/adgs1408.cMAINTAINERS +5
-0@@ -810,6 +810,11 @@ L: [email protected] S: Maintained F: drivers/media/i2c/ad9389b* +ANALOG DEVICES INC ADGS1408 DRIVER +M: Mircea Caprioru <[email protected]> +S: Supported +F: drivers/mux/adgs1408.c + ANALOG DEVICES INC ADV7180 DRIVER M: Lars-Peter Clausen <[email protected]> L: [email protected]drivers/mux/Kconfig +0
-0@@ -21,6 +21,18 @@ config MUX_ADG792A To compile the driver as a module, choose M here: themodule will
be called mux-adg792a.
Quoted 12 lines
drivers/mux/Kconfig config MUX_ADG792A · line 31
Quoted 9 lines
drivers/mux/Kconfig +5
-0+config MUX_ADGS1408 + tristate "Analog Devices ADGS1408/ADGS1409 Multiplexers" + depends on SPI + help + ADGS1408 8:1 multiplexer and ADGS1409 double 4:1multiplexer
drivers/mux/Kconfig +3
-0+ switches. + + The driver supports driving each switch independently.Remove this line. It is confusing since 1408 only have one mux and the two muxes in the dual 1409 cannot be operated independently.
Ack.
Quoted 21 lines
Quoted 21 lines
drivers/mux/Kconfig +2
-0+ + To compile the driver as a module, choose M here: themodule will
drivers/mux/Kconfig +2
-0+ be called mux-adgs1408. + config MUX_GPIO tristate "GPIO-controlled Multiplexer" depends on GPIOLIB || COMPILE_TESTdrivers/mux/Makefile +1
-0@@ -5,10 +5,12 @@ mux-core-objs := core.o mux-adg792a-objs := adg792a.o +mux-adgs1408-objs := adgs1408.o mux-gpio-objs := gpio.o mux-mmio-objs := mmio.o
Quoted 14 lines
drivers/mux/adgs1408.c line 1
Quoted 12 lines
drivers/mux/Makefile +1
-0obj-$(CONFIG_MULTIPLEXER) += mux-core.o obj-$(CONFIG_MUX_ADG792A) += mux-adg792a.o +obj-$(CONFIG_MUX_ADGS1408) += mux-adgs1408.o obj-$(CONFIG_MUX_GPIO) += mux-gpio.o obj-$(CONFIG_MUX_MMIO) += mux-mmio.odrivers/mux/adgs1408.c new file +1
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0+ The preferred spelling is GPL-2.0-or-later
Hmmm...
This seems to be new. There are quite a few places where GPL-2.0+ is used.
Will use GPL-2.0-or-later here.
Quoted 7 lines
drivers/mux/adgs1408.c line 3
Quoted 3 lines
drivers/mux/adgs1408.c new file +2
-0+/* +* ADG1408 SPI MUX driver ADGS1408; you are missing the S.
And I think you could/should mention ADGS1409 here.
Ack.
Quoted 10 lines
drivers/mux/adgs1408.c line 9
Quoted 7 lines
drivers/mux/adgs1408.c new file +6
-0+* +* Copyright 2018 Analog Devices Inc. +*/ + +#include <linux/err.h> +#include <linux/spi/spi.h> This #include sorts after
linux/property.h.
Quoted 15 lines
drivers/mux/adgs1408.c line 22
Quoted 13 lines
drivers/mux/adgs1408.c new file +13
-0+#include <linux/module.h> +#include <linux/mux/driver.h> +#include <linux/of_platform.h> +#include <linux/property.h> + +#define ADGS1408_SW_DATA (0x01) +#define ADGS1408_REG_READ (reg) ((reg) | 0x80) +#define ADGS1408_DISABLE (0x00) +#define ADGS1408_MUX (state) (((state) << 1) | 1) + +enum { +ADGS1408 , +ADGS1409 Add a trailing comma here, to make future changes less intrusive.
Ack.
Quoted 55 lines
Quoted 55 lines
drivers/mux/adgs1408.c new file +11
-0+}; + +static int adgs1408_spi_reg_write (struct spi_device *spi, +u8 reg_addr,u8 reg_data) +{ +u8 tx_buf[2 ]; + + tx_buf[0 ] = reg_addr; + tx_buf[1 ] = reg_data; + + return spi_write_then_read(spi, tx_buf, sizeof(tx_buf),NULL, 0);
drivers/mux/adgs1408.c new file +5
-0+} + +static int adgs1408_set (struct mux_control *mux,int state) +{ + struct spi_device *spi = to_spi_device(mux->chip-Quoted 1 line
dev.parent);
drivers/mux/adgs1408.c new file +29
-0+u8 reg; + +if (state ==MUX_IDLE_DISCONNECT ) + reg =ADGS1408_DISABLE ; +else + reg =ADGS1408_MUX (state); + +return adgs1408_spi_reg_write (spi,ADGS1408_SW_DATA , reg); +} + +static const struct mux_control_ops adgs1408_ops = { + .set = adgs1408_set, +}; + +static int adgs1408_probe (struct spi_device *spi) +{ +const struct spi_device_id *id =spi_get_device_id (spi); +struct device *dev = &spi->dev; +struct mux_chip *mux_chip; +struct mux_control *mux; +int ret, idle_state; + + mux_chip =devm_mux_chip_alloc (dev,1 ,0 ); +if (IS_ERR (mux_chip)) +return PTR_ERR (mux_chip); + + mux_chip->ops = &adgs1408_ops; + + ret = adgs1408_spi_reg_write(spi, ADGS1408_SW_DATA,
ADGS1408_DISABLE);drivers/mux/adgs1408.c new file +6
-0+if (ret <0 ) +return ret; + + ret = device_property_read_u32_array(dev, "idle-state", + &idle_state, + mux_chip-
Quoted 6 lines
drivers/mux/adgs1408.c line 76
Quoted 4 lines
Quoted 1 line
controllers);
drivers/mux/adgs1408.c new file +3
-0+if (ret <0 ) { + idle_state =MUX_IDLE_AS_IS ; + }Drop the {} here.
Ack.
Quoted 26 lines
Quoted 8 lines
drivers/mux/adgs1408.c new file +7
-0+ + mux = mux_chip->mux; + +if (id->driver_data ==ADGS1408 ) + mux->states =8 ; +else + mux->states =4 ;drivers/mux/adgs1408.c line 93
Quoted 10 lines
drivers/mux/adgs1408.c new file +10
-0+ +switch (idle_state) { +case MUX_IDLE_DISCONNECT : +case MUX_IDLE_AS_IS : + case 0 ... 7: +/* adgs1409 supports only 4 states */ +if (id->driver_data ==ADGS1409 && idle_state >3 ) +return -EINVAL ; + mux->idle_state = idle_state; +break ;If you reverse the test above, or if you rewrite it like below, you can fall
through and get the error message (w/o duplication), like this (since theMUX_IDLE_... defines are both negative, but you already depend on that):
Quoted 6 lines
/* adgs1409 supports only 4 states */
if (idle_state < mux->states) {
mux->idle_state = idle_state;
break;
}
/* fall through */Makes sense.
Quoted 17 lines
drivers/mux/adgs1408.c line 104
Quoted 13 lines
drivers/mux/adgs1408.c new file +2
-0+default : + dev_err(dev, "invalid idle-state %d\n",
idle_state);drivers/mux/adgs1408.c new file +9
-0+return -EINVAL ; + } + +return devm_mux_chip_register (dev, mux_chip); +} + +static const struct spi_device_id adgs1408_id[] = { + {"adi,adgs1408" ,ADGS1408 }, + {"adi,adgs1409" ,ADGS1409 },This looks weird. Other
spi_device_idlookup-tables do not have dt- style
ids like this; they have the equivalent of "adgs1408" and "adgs1409".
Will revert to the old form here. I am still getting the hang of this spi_device_id stuff.
Quoted 13 lines
drivers/mux/adgs1408.c line 111
Quoted 8 lines
drivers/mux/adgs1408.c new file +7
-0+ { } +}; +MODULE_DEVICE_TABLE (spi, adgs1408_id); + +static struct spi_driver adgs1408_driver = { + .driver = { + .name ="adgs1408" ,You have (silently) dropped .of_match_table since v1. Why is it not needed?
I felt much more comfortable with what was in v1 for this area of the patch.
Yeah, my bad about dropping this. Will revert to the old form.
Quoted 3 lines
Cheers,
Peter
Thanks,
Mircea
Quoted 13 lines
Quoted 11 lines
drivers/mux/adgs1408.c new file +9
-0+ }, + .probe = adgs1408_probe, + .id_table = adgs1408_id, +}; +module_spi_driver (adgs1408_driver); + +MODULE_AUTHOR ("Mircea Caprioru <[email protected]>" ); +MODULE_DESCRIPTION("Analog Devices ADGS1408 MUX driver");> +MODULE_LICENSE ("GPL v2" );