* [PATCH v4 0/2] Add support for the TI SM-USB-DIG
@ 2016-08-09 14:55 ` Andrew F. Davis
0 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-09 14:55 UTC (permalink / raw)
To: Wolfram Sang, Lee Jones
Cc: linux-i2c, linux-usb, linux-kernel, Andrew F . Davis
Hello all,
This series adds initial support for the TI SM-USB-DIG, this is a USB
to I2C/SPI/1Wire/GPIO adapter, we only add support for I2C here, drivers
for the other protocols are still in the works.
Thanks,
Andrew
Changes from v3:
- Rebased on v4.8-rc1
- Added this cover letter to track series changes
Changes from v2:
- Rename sm-usb-dig -> ti-smusbdig
- Inline helper functions in header
- Alphabetize includes
Changes from v1:
- Added missing dependency on USB to Kconfig
Andrew F. Davis (2):
mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
i2c: ti-smusbdig: add TI SM-USB-DIG I2C bus driver
drivers/i2c/busses/Kconfig | 10 ++
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ti-smusbdig.c | 189 +++++++++++++++++++++++++++++++++++
drivers/mfd/Kconfig | 9 ++
drivers/mfd/Makefile | 2 +
drivers/mfd/ti-smusbdig.c | 138 +++++++++++++++++++++++++
include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++
7 files changed, 424 insertions(+)
create mode 100644 drivers/i2c/busses/i2c-ti-smusbdig.c
create mode 100644 drivers/mfd/ti-smusbdig.c
create mode 100644 include/linux/mfd/ti-smusbdig.h
--
2.9.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 0/2] Add support for the TI SM-USB-DIG
@ 2016-08-09 14:55 ` Andrew F. Davis
0 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-09 14:55 UTC (permalink / raw)
To: Wolfram Sang, Lee Jones
Cc: linux-i2c, linux-usb, linux-kernel, Andrew F . Davis
Hello all,
This series adds initial support for the TI SM-USB-DIG, this is a USB
to I2C/SPI/1Wire/GPIO adapter, we only add support for I2C here, drivers
for the other protocols are still in the works.
Thanks,
Andrew
Changes from v3:
- Rebased on v4.8-rc1
- Added this cover letter to track series changes
Changes from v2:
- Rename sm-usb-dig -> ti-smusbdig
- Inline helper functions in header
- Alphabetize includes
Changes from v1:
- Added missing dependency on USB to Kconfig
Andrew F. Davis (2):
mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
i2c: ti-smusbdig: add TI SM-USB-DIG I2C bus driver
drivers/i2c/busses/Kconfig | 10 ++
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ti-smusbdig.c | 189 +++++++++++++++++++++++++++++++++++
drivers/mfd/Kconfig | 9 ++
drivers/mfd/Makefile | 2 +
drivers/mfd/ti-smusbdig.c | 138 +++++++++++++++++++++++++
include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++
7 files changed, 424 insertions(+)
create mode 100644 drivers/i2c/busses/i2c-ti-smusbdig.c
create mode 100644 drivers/mfd/ti-smusbdig.c
create mode 100644 include/linux/mfd/ti-smusbdig.h
--
2.9.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
2016-08-09 14:55 ` Andrew F. Davis
@ 2016-08-09 14:55 ` Andrew F. Davis
-1 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-09 14:55 UTC (permalink / raw)
To: Wolfram Sang, Lee Jones
Cc: linux-i2c, linux-usb, linux-kernel, Andrew F . Davis
The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter.
Add MFD core support.
Signed-off-by: Andrew F. Davis <afd@ti.com>
---
drivers/mfd/Kconfig | 9 +++
drivers/mfd/Makefile | 2 +
drivers/mfd/ti-smusbdig.c | 138 ++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++++++++++
4 files changed, 224 insertions(+)
create mode 100644 drivers/mfd/ti-smusbdig.c
create mode 100644 include/linux/mfd/ti-smusbdig.h
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 2d1fb64..0b63431 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1387,6 +1387,15 @@ config MFD_LM3533
additional drivers must be enabled in order to use the LED,
backlight or ambient-light-sensor functionality of the device.
+config MFD_TI_SMUSBDIG
+ tristate "Texas Instruments SM-USB-DIG interface adapter"
+ depends on USB
+ select MFD_CORE
+ help
+ Support for the TI SM-USB-DIG USB to SPI/I2C/1Wire/GPIO adapter.
+ Additional drivers such as SPI_TI_SMUSBDIG, I2C_TI_SMUSBDIG, etc. must
+ be enabled in order to use the functionality of the device.
+
config MFD_TIMBERDALE
tristate "Timberdale FPGA"
select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 2ba3ba3..aa2845e 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -68,6 +68,8 @@ obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
wm8994-objs := wm8994-core.o wm8994-irq.o wm8994-regmap.o
obj-$(CONFIG_MFD_WM8994) += wm8994.o
+obj-$(CONFIG_MFD_TI_SMUSBDIG) += ti-smusbdig.o
+
obj-$(CONFIG_TPS6105X) += tps6105x.o
obj-$(CONFIG_TPS65010) += tps65010.o
obj-$(CONFIG_TPS6507X) += tps6507x.o
diff --git a/drivers/mfd/ti-smusbdig.c b/drivers/mfd/ti-smusbdig.c
new file mode 100644
index 0000000..19f48c6
--- /dev/null
+++ b/drivers/mfd/ti-smusbdig.c
@@ -0,0 +1,138 @@
+/*
+ * MFD Core driver for TI SM-USB-DIG
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#include <linux/mfd/core.h>
+#include <linux/mfd/ti-smusbdig.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+
+#define TI_USB_VENDOR_ID 0x0451
+#define TI_USB_DEVICE_ID_SM_USB_DIG 0x2f90
+
+#define TI_SMUSBDIG_USB_TIMEOUT_MS 1000
+
+struct ti_smusbdig_device {
+ struct usb_device *usb_dev;
+ struct usb_interface *interface;
+};
+
+int ti_smusbdig_xfer(struct ti_smusbdig_device *ti_smusbdig,
+ u8 *buffer, int size)
+{
+ struct device *dev = &ti_smusbdig->interface->dev;
+ int actual_length, ret;
+
+ if (!ti_smusbdig || !buffer || size <= 0)
+ return -EINVAL;
+
+ ret = usb_interrupt_msg(ti_smusbdig->usb_dev,
+ usb_sndctrlpipe(ti_smusbdig->usb_dev, 1),
+ buffer, size, &actual_length,
+ TI_SMUSBDIG_USB_TIMEOUT_MS);
+ if (ret) {
+ dev_err(dev, "USB transaction failed\n");
+ return ret;
+ }
+
+ ret = usb_interrupt_msg(ti_smusbdig->usb_dev,
+ usb_rcvctrlpipe(ti_smusbdig->usb_dev, 1),
+ buffer, TI_SMUSBDIG_PACKET_SIZE, &actual_length,
+ TI_SMUSBDIG_USB_TIMEOUT_MS);
+ if (ret) {
+ dev_err(dev, "USB transaction failed\n");
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ti_smusbdig_xfer);
+
+static const struct mfd_cell ti_smusbdig_mfd_cells[] = {
+ { .name = "ti-sm-usb-dig-gpio", },
+ { .name = "ti-sm-usb-dig-i2c", },
+ { .name = "ti-sm-usb-dig-spi", },
+ { .name = "ti-sm-usb-dig-w1", },
+};
+
+static int ti_smusbdig_probe(struct usb_interface *interface,
+ const struct usb_device_id *usb_id)
+{
+ struct usb_host_interface *hostif = interface->cur_altsetting;
+ struct device *dev = &interface->dev;
+ struct ti_smusbdig_device *ti_smusbdig;
+ u8 buffer[TI_SMUSBDIG_PACKET_SIZE];
+ int ret;
+
+ if (hostif->desc.bInterfaceNumber != 0 ||
+ hostif->desc.bNumEndpoints < 2)
+ return -ENODEV;
+
+ ti_smusbdig = devm_kzalloc(dev, sizeof(*ti_smusbdig), GFP_KERNEL);
+ if (!ti_smusbdig)
+ return -ENOMEM;
+
+ ti_smusbdig->usb_dev = usb_get_dev(interface_to_usbdev(interface));
+ ti_smusbdig->interface = interface;
+ usb_set_intfdata(interface, ti_smusbdig);
+
+ buffer[0] = TI_SMUSBDIG_VERSION;
+ ret = ti_smusbdig_xfer(ti_smusbdig, buffer, 1);
+ if (ret)
+ return ret;
+
+ dev_info(dev, "TI SM-USB-DIG Version: %d.%02d Found\n",
+ buffer[0], buffer[1]);
+
+ /* Turn on power supply output */
+ buffer[0] = TI_SMUSBDIG_COMMAND;
+ buffer[1] = TI_SMUSBDIG_COMMAND_DUTPOWERON;
+ ret = ti_smusbdig_xfer(ti_smusbdig, buffer, 2);
+ if (ret)
+ return ret;
+
+ dev_set_drvdata(dev, ti_smusbdig);
+ ret = mfd_add_hotplug_devices(dev, ti_smusbdig_mfd_cells,
+ ARRAY_SIZE(ti_smusbdig_mfd_cells));
+ if (ret) {
+ dev_err(dev, "unable to add MFD devices\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+static void ti_smusbdig_disconnect(struct usb_interface *interface)
+{
+ mfd_remove_devices(&interface->dev);
+}
+
+static const struct usb_device_id ti_smusbdig_id_table[] = {
+ { USB_DEVICE(TI_USB_VENDOR_ID, TI_USB_DEVICE_ID_SM_USB_DIG) },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(usb, ti_smusbdig_id_table);
+
+static struct usb_driver ti_smusbdig_driver = {
+ .name = "ti-sm-usb-dig",
+ .probe = ti_smusbdig_probe,
+ .disconnect = ti_smusbdig_disconnect,
+ .id_table = ti_smusbdig_id_table,
+};
+module_usb_driver(ti_smusbdig_driver);
+
+MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
+MODULE_DESCRIPTION("Core driver for TI SM-USB-DIG interface adapter");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/mfd/ti-smusbdig.h b/include/linux/mfd/ti-smusbdig.h
new file mode 100644
index 0000000..46fd2da
--- /dev/null
+++ b/include/linux/mfd/ti-smusbdig.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#ifndef __LINUX_MFD_TI_SMUSBDIG_H
+#define __LINUX_MFD_TI_SMUSBDIG_H
+
+#define TI_SMUSBDIG_PACKET_SIZE 32
+/* (packet size - packet header */
+#define TI_SMUSBDIG_DATA_SIZE (TI_SMUSBDIG_PACKET_SIZE - 7)
+
+enum ti_smusbdig_function {
+ TI_SMUSBDIG_SPI = 0x01,
+ TI_SMUSBDIG_I2C = 0x02,
+ TI_SMUSBDIG_1W = 0x03,
+ TI_SMUSBDIG_COMMAND = 0x04,
+ TI_SMUSBDIG_VERSION = 0x07,
+};
+
+enum ti_smusbdig_sub_command {
+ TI_SMUSBDIG_COMMAND_DUTPOWERON = 0x01,
+ TI_SMUSBDIG_COMMAND_DUTPOWEROFF = 0x02,
+};
+
+struct ti_smusbdig_packet {
+ u8 function;
+ u8 channel;
+ u8 edge_polarity;
+ u8 num_commands;
+ u8 is_command_mask[3];
+ u8 data[TI_SMUSBDIG_DATA_SIZE];
+} __packed;
+
+static inline void
+ti_smusbdig_packet_add_command(struct ti_smusbdig_packet *packet, int command)
+{
+ int num_commands = packet->num_commands;
+ int mask_number = num_commands / 8;
+ int mask_bit = num_commands % 8;
+
+ if (num_commands >= TI_SMUSBDIG_DATA_SIZE)
+ return;
+
+ packet->is_command_mask[mask_number] |= BIT(7 - mask_bit);
+ packet->data[num_commands] = command;
+ packet->num_commands++;
+}
+
+static inline void
+ti_smusbdig_packet_add_data(struct ti_smusbdig_packet *packet, u8 data)
+{
+ int num_commands = packet->num_commands;
+
+ if (num_commands >= TI_SMUSBDIG_DATA_SIZE)
+ return;
+
+ packet->data[num_commands] = data;
+ packet->num_commands++;
+}
+
+struct ti_smusbdig_device;
+int ti_smusbdig_xfer(struct ti_smusbdig_device *ti_smusbdig,
+ u8 *buffer, int size);
+
+#endif /* __LINUX_MFD_TI_SMUSBDIG_H */
--
2.9.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
@ 2016-08-09 14:55 ` Andrew F. Davis
0 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-09 14:55 UTC (permalink / raw)
To: Wolfram Sang, Lee Jones
Cc: linux-i2c, linux-usb, linux-kernel, Andrew F . Davis
The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter.
Add MFD core support.
Signed-off-by: Andrew F. Davis <afd@ti.com>
---
drivers/mfd/Kconfig | 9 +++
drivers/mfd/Makefile | 2 +
drivers/mfd/ti-smusbdig.c | 138 ++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++++++++++
4 files changed, 224 insertions(+)
create mode 100644 drivers/mfd/ti-smusbdig.c
create mode 100644 include/linux/mfd/ti-smusbdig.h
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 2d1fb64..0b63431 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1387,6 +1387,15 @@ config MFD_LM3533
additional drivers must be enabled in order to use the LED,
backlight or ambient-light-sensor functionality of the device.
+config MFD_TI_SMUSBDIG
+ tristate "Texas Instruments SM-USB-DIG interface adapter"
+ depends on USB
+ select MFD_CORE
+ help
+ Support for the TI SM-USB-DIG USB to SPI/I2C/1Wire/GPIO adapter.
+ Additional drivers such as SPI_TI_SMUSBDIG, I2C_TI_SMUSBDIG, etc. must
+ be enabled in order to use the functionality of the device.
+
config MFD_TIMBERDALE
tristate "Timberdale FPGA"
select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 2ba3ba3..aa2845e 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -68,6 +68,8 @@ obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
wm8994-objs := wm8994-core.o wm8994-irq.o wm8994-regmap.o
obj-$(CONFIG_MFD_WM8994) += wm8994.o
+obj-$(CONFIG_MFD_TI_SMUSBDIG) += ti-smusbdig.o
+
obj-$(CONFIG_TPS6105X) += tps6105x.o
obj-$(CONFIG_TPS65010) += tps65010.o
obj-$(CONFIG_TPS6507X) += tps6507x.o
diff --git a/drivers/mfd/ti-smusbdig.c b/drivers/mfd/ti-smusbdig.c
new file mode 100644
index 0000000..19f48c6
--- /dev/null
+++ b/drivers/mfd/ti-smusbdig.c
@@ -0,0 +1,138 @@
+/*
+ * MFD Core driver for TI SM-USB-DIG
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#include <linux/mfd/core.h>
+#include <linux/mfd/ti-smusbdig.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+
+#define TI_USB_VENDOR_ID 0x0451
+#define TI_USB_DEVICE_ID_SM_USB_DIG 0x2f90
+
+#define TI_SMUSBDIG_USB_TIMEOUT_MS 1000
+
+struct ti_smusbdig_device {
+ struct usb_device *usb_dev;
+ struct usb_interface *interface;
+};
+
+int ti_smusbdig_xfer(struct ti_smusbdig_device *ti_smusbdig,
+ u8 *buffer, int size)
+{
+ struct device *dev = &ti_smusbdig->interface->dev;
+ int actual_length, ret;
+
+ if (!ti_smusbdig || !buffer || size <= 0)
+ return -EINVAL;
+
+ ret = usb_interrupt_msg(ti_smusbdig->usb_dev,
+ usb_sndctrlpipe(ti_smusbdig->usb_dev, 1),
+ buffer, size, &actual_length,
+ TI_SMUSBDIG_USB_TIMEOUT_MS);
+ if (ret) {
+ dev_err(dev, "USB transaction failed\n");
+ return ret;
+ }
+
+ ret = usb_interrupt_msg(ti_smusbdig->usb_dev,
+ usb_rcvctrlpipe(ti_smusbdig->usb_dev, 1),
+ buffer, TI_SMUSBDIG_PACKET_SIZE, &actual_length,
+ TI_SMUSBDIG_USB_TIMEOUT_MS);
+ if (ret) {
+ dev_err(dev, "USB transaction failed\n");
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ti_smusbdig_xfer);
+
+static const struct mfd_cell ti_smusbdig_mfd_cells[] = {
+ { .name = "ti-sm-usb-dig-gpio", },
+ { .name = "ti-sm-usb-dig-i2c", },
+ { .name = "ti-sm-usb-dig-spi", },
+ { .name = "ti-sm-usb-dig-w1", },
+};
+
+static int ti_smusbdig_probe(struct usb_interface *interface,
+ const struct usb_device_id *usb_id)
+{
+ struct usb_host_interface *hostif = interface->cur_altsetting;
+ struct device *dev = &interface->dev;
+ struct ti_smusbdig_device *ti_smusbdig;
+ u8 buffer[TI_SMUSBDIG_PACKET_SIZE];
+ int ret;
+
+ if (hostif->desc.bInterfaceNumber != 0 ||
+ hostif->desc.bNumEndpoints < 2)
+ return -ENODEV;
+
+ ti_smusbdig = devm_kzalloc(dev, sizeof(*ti_smusbdig), GFP_KERNEL);
+ if (!ti_smusbdig)
+ return -ENOMEM;
+
+ ti_smusbdig->usb_dev = usb_get_dev(interface_to_usbdev(interface));
+ ti_smusbdig->interface = interface;
+ usb_set_intfdata(interface, ti_smusbdig);
+
+ buffer[0] = TI_SMUSBDIG_VERSION;
+ ret = ti_smusbdig_xfer(ti_smusbdig, buffer, 1);
+ if (ret)
+ return ret;
+
+ dev_info(dev, "TI SM-USB-DIG Version: %d.%02d Found\n",
+ buffer[0], buffer[1]);
+
+ /* Turn on power supply output */
+ buffer[0] = TI_SMUSBDIG_COMMAND;
+ buffer[1] = TI_SMUSBDIG_COMMAND_DUTPOWERON;
+ ret = ti_smusbdig_xfer(ti_smusbdig, buffer, 2);
+ if (ret)
+ return ret;
+
+ dev_set_drvdata(dev, ti_smusbdig);
+ ret = mfd_add_hotplug_devices(dev, ti_smusbdig_mfd_cells,
+ ARRAY_SIZE(ti_smusbdig_mfd_cells));
+ if (ret) {
+ dev_err(dev, "unable to add MFD devices\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+static void ti_smusbdig_disconnect(struct usb_interface *interface)
+{
+ mfd_remove_devices(&interface->dev);
+}
+
+static const struct usb_device_id ti_smusbdig_id_table[] = {
+ { USB_DEVICE(TI_USB_VENDOR_ID, TI_USB_DEVICE_ID_SM_USB_DIG) },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(usb, ti_smusbdig_id_table);
+
+static struct usb_driver ti_smusbdig_driver = {
+ .name = "ti-sm-usb-dig",
+ .probe = ti_smusbdig_probe,
+ .disconnect = ti_smusbdig_disconnect,
+ .id_table = ti_smusbdig_id_table,
+};
+module_usb_driver(ti_smusbdig_driver);
+
+MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
+MODULE_DESCRIPTION("Core driver for TI SM-USB-DIG interface adapter");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/mfd/ti-smusbdig.h b/include/linux/mfd/ti-smusbdig.h
new file mode 100644
index 0000000..46fd2da
--- /dev/null
+++ b/include/linux/mfd/ti-smusbdig.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#ifndef __LINUX_MFD_TI_SMUSBDIG_H
+#define __LINUX_MFD_TI_SMUSBDIG_H
+
+#define TI_SMUSBDIG_PACKET_SIZE 32
+/* (packet size - packet header */
+#define TI_SMUSBDIG_DATA_SIZE (TI_SMUSBDIG_PACKET_SIZE - 7)
+
+enum ti_smusbdig_function {
+ TI_SMUSBDIG_SPI = 0x01,
+ TI_SMUSBDIG_I2C = 0x02,
+ TI_SMUSBDIG_1W = 0x03,
+ TI_SMUSBDIG_COMMAND = 0x04,
+ TI_SMUSBDIG_VERSION = 0x07,
+};
+
+enum ti_smusbdig_sub_command {
+ TI_SMUSBDIG_COMMAND_DUTPOWERON = 0x01,
+ TI_SMUSBDIG_COMMAND_DUTPOWEROFF = 0x02,
+};
+
+struct ti_smusbdig_packet {
+ u8 function;
+ u8 channel;
+ u8 edge_polarity;
+ u8 num_commands;
+ u8 is_command_mask[3];
+ u8 data[TI_SMUSBDIG_DATA_SIZE];
+} __packed;
+
+static inline void
+ti_smusbdig_packet_add_command(struct ti_smusbdig_packet *packet, int command)
+{
+ int num_commands = packet->num_commands;
+ int mask_number = num_commands / 8;
+ int mask_bit = num_commands % 8;
+
+ if (num_commands >= TI_SMUSBDIG_DATA_SIZE)
+ return;
+
+ packet->is_command_mask[mask_number] |= BIT(7 - mask_bit);
+ packet->data[num_commands] = command;
+ packet->num_commands++;
+}
+
+static inline void
+ti_smusbdig_packet_add_data(struct ti_smusbdig_packet *packet, u8 data)
+{
+ int num_commands = packet->num_commands;
+
+ if (num_commands >= TI_SMUSBDIG_DATA_SIZE)
+ return;
+
+ packet->data[num_commands] = data;
+ packet->num_commands++;
+}
+
+struct ti_smusbdig_device;
+int ti_smusbdig_xfer(struct ti_smusbdig_device *ti_smusbdig,
+ u8 *buffer, int size);
+
+#endif /* __LINUX_MFD_TI_SMUSBDIG_H */
--
2.9.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v4 2/2] i2c: ti-smusbdig: add TI SM-USB-DIG I2C bus driver
2016-08-09 14:55 ` Andrew F. Davis
@ 2016-08-09 14:55 ` Andrew F. Davis
-1 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-09 14:55 UTC (permalink / raw)
To: Wolfram Sang, Lee Jones
Cc: linux-i2c, linux-usb, linux-kernel, Andrew F . Davis
Add support for the I2C bus functionality of the TI SM-USB-DIG.
Signed-off-by: Andrew F. Davis <afd@ti.com>
---
drivers/i2c/busses/Kconfig | 10 ++
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ti-smusbdig.c | 189 +++++++++++++++++++++++++++++++++++
3 files changed, 200 insertions(+)
create mode 100644 drivers/i2c/busses/i2c-ti-smusbdig.c
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 5c3993b..fe8bee8 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -1079,6 +1079,16 @@ config I2C_ROBOTFUZZ_OSIF
This driver can also be built as a module. If so, the module
will be called i2c-osif.
+config I2C_TI_SMUSBDIG
+ tristate "Texas Instruments SM-USB-DIG I2C interface"
+ depends on MFD_TI_SMUSBDIG
+ help
+ This adds support for the I2C bus functionality of the
+ TI SM-USB-DIG USB interface adapter.
+
+ This driver can also be built as a module. If so, the module
+ will be called i2c-ti-smusbdig.
+
config I2C_TAOS_EVM
tristate "TAOS evaluation module"
depends on TTY
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 37f2819..38c0d87 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -103,6 +103,7 @@ obj-$(CONFIG_I2C_DLN2) += i2c-dln2.o
obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF) += i2c-robotfuzz-osif.o
+obj-$(CONFIG_I2C_TI_SMUSBDIG) += i2c-ti-smusbdig.o
obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o
obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
obj-$(CONFIG_I2C_VIPERBOARD) += i2c-viperboard.o
diff --git a/drivers/i2c/busses/i2c-ti-smusbdig.c b/drivers/i2c/busses/i2c-ti-smusbdig.c
new file mode 100644
index 0000000..dfd3ca0
--- /dev/null
+++ b/drivers/i2c/busses/i2c-ti-smusbdig.c
@@ -0,0 +1,189 @@
+/*
+ * I2C bus driver for TI SM-USB-DIG
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#include <linux/i2c.h>
+#include <linux/mfd/ti-smusbdig.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+/* (data size - start condition - address - ACK) / ACK after data byte */
+#define TI_SMUSBDIG_I2C_MAX_MSG ((TI_SMUSBDIG_DATA_SIZE - 3) / 2)
+
+struct ti_smusbdig_i2c {
+ struct device *dev;
+ struct ti_smusbdig_device *ti_smusbdig;
+ struct i2c_adapter adapter;
+};
+
+enum ti_smusbdig_i2c_command {
+ TI_SMUSBDIG_I2C_START = 0x3,
+ TI_SMUSBDIG_I2C_STOP = 0x4,
+ TI_SMUSBDIG_I2C_ACKM = 0x5,
+ TI_SMUSBDIG_I2C_ACKS = 0x6,
+};
+
+static void ti_smusbdig_i2c_packet_init(struct ti_smusbdig_packet *packet)
+{
+ memset(packet, 0, sizeof(*packet));
+ packet->function = TI_SMUSBDIG_I2C;
+ packet->channel = 0x1;
+}
+
+static int ti_smusbdig_i2c_xfer(struct i2c_adapter *adapter,
+ struct i2c_msg *msgs, int num)
+{
+ struct ti_smusbdig_i2c *ti_smusbdig_i2c = i2c_get_adapdata(adapter);
+ struct ti_smusbdig_packet packet;
+ int i, j, k, ret;
+
+ for (i = 0; i < num; i++) {
+ ti_smusbdig_i2c_packet_init(&packet);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_START);
+ /* add read bit to address if needed */
+ msgs[i].addr <<= 1;
+ if (msgs[i].flags & I2C_M_RD)
+ msgs[i].addr |= BIT(0);
+ ti_smusbdig_packet_add_data(&packet, msgs[i].addr);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_ACKS);
+ if (msgs[i].flags & I2C_M_RD) {
+ for (j = 0; j < msgs[i].len; j++) {
+ ti_smusbdig_packet_add_data(&packet, 0xff);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_ACKM);
+ }
+ } else {
+ for (j = 0; j < msgs[i].len; j++) {
+ ti_smusbdig_packet_add_data(&packet, msgs[i].buf[j]);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_ACKS);
+ }
+ }
+
+ ret = ti_smusbdig_xfer(ti_smusbdig_i2c->ti_smusbdig,
+ (u8 *)&packet, sizeof(packet));
+ if (ret)
+ return ret;
+
+ /*
+ * now we read in any data we got during read MSGs
+ * and check ACKS
+ */
+ if (((u8 *)&packet)[2]) {
+ num = -EPROTO;
+ goto stop;
+ }
+ for (j = 0, k = 3; j < msgs[i].len; j++, k += 2) {
+ if (msgs[i].flags & I2C_M_RD) {
+ msgs[i].buf[j] = ((u8 *)&packet)[k];
+ } else if (((u8 *)&packet)[k + 1]) {
+ num = -EPROTO;
+ goto stop;
+ }
+ }
+ }
+
+stop:
+ /* send stop condition */
+ ti_smusbdig_i2c_packet_init(&packet);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_STOP);
+ ret = ti_smusbdig_xfer(ti_smusbdig_i2c->ti_smusbdig,
+ (u8 *)&packet, sizeof(packet));
+ if (ret)
+ return ret;
+
+ return num;
+}
+
+static u32 ti_smusbdig_i2c_func(struct i2c_adapter *adapter)
+{
+ return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+}
+
+static const struct i2c_algorithm ti_smusbdig_i2c_algo = {
+ .master_xfer = ti_smusbdig_i2c_xfer,
+ .functionality = ti_smusbdig_i2c_func,
+};
+
+static struct i2c_adapter ti_smusbdig_i2c_adapter = {
+ .owner = THIS_MODULE,
+ .class = I2C_CLASS_HWMON,
+ .algo = &ti_smusbdig_i2c_algo,
+};
+
+static struct i2c_adapter_quirks dln2_i2c_quirks = {
+ .max_read_len = TI_SMUSBDIG_I2C_MAX_MSG,
+ .max_write_len = TI_SMUSBDIG_I2C_MAX_MSG,
+};
+
+static int ti_smusbdig_i2c_probe(struct platform_device *pdev)
+{
+ struct ti_smusbdig_i2c *ti_smusbdig_i2c;
+ struct device *dev = &pdev->dev;
+ int ret;
+
+ ti_smusbdig_i2c = devm_kzalloc(dev, sizeof(*ti_smusbdig_i2c), GFP_KERNEL);
+ if (!ti_smusbdig_i2c)
+ return -ENOMEM;
+
+ ti_smusbdig_i2c->dev = dev;
+ ti_smusbdig_i2c->ti_smusbdig = dev_get_drvdata(dev->parent);
+ ti_smusbdig_i2c->adapter = ti_smusbdig_i2c_adapter;
+ strlcpy(ti_smusbdig_i2c->adapter.name, dev_name(dev),
+ sizeof(ti_smusbdig_i2c->adapter.name));
+ ti_smusbdig_i2c->adapter.quirks = &dln2_i2c_quirks;
+ ti_smusbdig_i2c->adapter.dev.parent = dev;
+ ti_smusbdig_i2c->adapter.dev.of_node = dev->of_node;
+
+ i2c_set_adapdata(&ti_smusbdig_i2c->adapter, ti_smusbdig_i2c);
+ platform_set_drvdata(pdev, ti_smusbdig_i2c);
+
+ ret = i2c_add_adapter(&ti_smusbdig_i2c->adapter);
+ if (ret) {
+ dev_err(dev, "unable to add I2C adapter\n");
+ return ret;
+ }
+
+ dev_info(dev, "TI SM-USB-DIG Added: I2C Bus\n");
+
+ return 0;
+}
+
+static int ti_smusbdig_i2c_remove(struct platform_device *pdev)
+{
+ struct ti_smusbdig_i2c *ti_smusbdig_i2c = platform_get_drvdata(pdev);
+
+ i2c_del_adapter(&ti_smusbdig_i2c->adapter);
+
+ return 0;
+}
+
+static const struct platform_device_id ti_smusbdig_i2c_id_table[] = {
+ { "ti-sm-usb-dig-i2c", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, ti_smusbdig_i2c_id_table);
+
+static struct platform_driver ti_smusbdig_i2c_driver = {
+ .driver = {
+ .name = "ti-sm-usb-dig-i2c",
+ },
+ .probe = ti_smusbdig_i2c_probe,
+ .remove = ti_smusbdig_i2c_remove,
+ .id_table = ti_smusbdig_i2c_id_table,
+};
+module_platform_driver(ti_smusbdig_i2c_driver);
+
+MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
+MODULE_DESCRIPTION("I2C bus driver for TI SM-USB-DIG interface adapter");
+MODULE_LICENSE("GPL v2");
--
2.9.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v4 2/2] i2c: ti-smusbdig: add TI SM-USB-DIG I2C bus driver
@ 2016-08-09 14:55 ` Andrew F. Davis
0 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-09 14:55 UTC (permalink / raw)
To: Wolfram Sang, Lee Jones
Cc: linux-i2c, linux-usb, linux-kernel, Andrew F . Davis
Add support for the I2C bus functionality of the TI SM-USB-DIG.
Signed-off-by: Andrew F. Davis <afd@ti.com>
---
drivers/i2c/busses/Kconfig | 10 ++
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ti-smusbdig.c | 189 +++++++++++++++++++++++++++++++++++
3 files changed, 200 insertions(+)
create mode 100644 drivers/i2c/busses/i2c-ti-smusbdig.c
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 5c3993b..fe8bee8 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -1079,6 +1079,16 @@ config I2C_ROBOTFUZZ_OSIF
This driver can also be built as a module. If so, the module
will be called i2c-osif.
+config I2C_TI_SMUSBDIG
+ tristate "Texas Instruments SM-USB-DIG I2C interface"
+ depends on MFD_TI_SMUSBDIG
+ help
+ This adds support for the I2C bus functionality of the
+ TI SM-USB-DIG USB interface adapter.
+
+ This driver can also be built as a module. If so, the module
+ will be called i2c-ti-smusbdig.
+
config I2C_TAOS_EVM
tristate "TAOS evaluation module"
depends on TTY
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 37f2819..38c0d87 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -103,6 +103,7 @@ obj-$(CONFIG_I2C_DLN2) += i2c-dln2.o
obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF) += i2c-robotfuzz-osif.o
+obj-$(CONFIG_I2C_TI_SMUSBDIG) += i2c-ti-smusbdig.o
obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o
obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
obj-$(CONFIG_I2C_VIPERBOARD) += i2c-viperboard.o
diff --git a/drivers/i2c/busses/i2c-ti-smusbdig.c b/drivers/i2c/busses/i2c-ti-smusbdig.c
new file mode 100644
index 0000000..dfd3ca0
--- /dev/null
+++ b/drivers/i2c/busses/i2c-ti-smusbdig.c
@@ -0,0 +1,189 @@
+/*
+ * I2C bus driver for TI SM-USB-DIG
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#include <linux/i2c.h>
+#include <linux/mfd/ti-smusbdig.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+/* (data size - start condition - address - ACK) / ACK after data byte */
+#define TI_SMUSBDIG_I2C_MAX_MSG ((TI_SMUSBDIG_DATA_SIZE - 3) / 2)
+
+struct ti_smusbdig_i2c {
+ struct device *dev;
+ struct ti_smusbdig_device *ti_smusbdig;
+ struct i2c_adapter adapter;
+};
+
+enum ti_smusbdig_i2c_command {
+ TI_SMUSBDIG_I2C_START = 0x3,
+ TI_SMUSBDIG_I2C_STOP = 0x4,
+ TI_SMUSBDIG_I2C_ACKM = 0x5,
+ TI_SMUSBDIG_I2C_ACKS = 0x6,
+};
+
+static void ti_smusbdig_i2c_packet_init(struct ti_smusbdig_packet *packet)
+{
+ memset(packet, 0, sizeof(*packet));
+ packet->function = TI_SMUSBDIG_I2C;
+ packet->channel = 0x1;
+}
+
+static int ti_smusbdig_i2c_xfer(struct i2c_adapter *adapter,
+ struct i2c_msg *msgs, int num)
+{
+ struct ti_smusbdig_i2c *ti_smusbdig_i2c = i2c_get_adapdata(adapter);
+ struct ti_smusbdig_packet packet;
+ int i, j, k, ret;
+
+ for (i = 0; i < num; i++) {
+ ti_smusbdig_i2c_packet_init(&packet);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_START);
+ /* add read bit to address if needed */
+ msgs[i].addr <<= 1;
+ if (msgs[i].flags & I2C_M_RD)
+ msgs[i].addr |= BIT(0);
+ ti_smusbdig_packet_add_data(&packet, msgs[i].addr);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_ACKS);
+ if (msgs[i].flags & I2C_M_RD) {
+ for (j = 0; j < msgs[i].len; j++) {
+ ti_smusbdig_packet_add_data(&packet, 0xff);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_ACKM);
+ }
+ } else {
+ for (j = 0; j < msgs[i].len; j++) {
+ ti_smusbdig_packet_add_data(&packet, msgs[i].buf[j]);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_ACKS);
+ }
+ }
+
+ ret = ti_smusbdig_xfer(ti_smusbdig_i2c->ti_smusbdig,
+ (u8 *)&packet, sizeof(packet));
+ if (ret)
+ return ret;
+
+ /*
+ * now we read in any data we got during read MSGs
+ * and check ACKS
+ */
+ if (((u8 *)&packet)[2]) {
+ num = -EPROTO;
+ goto stop;
+ }
+ for (j = 0, k = 3; j < msgs[i].len; j++, k += 2) {
+ if (msgs[i].flags & I2C_M_RD) {
+ msgs[i].buf[j] = ((u8 *)&packet)[k];
+ } else if (((u8 *)&packet)[k + 1]) {
+ num = -EPROTO;
+ goto stop;
+ }
+ }
+ }
+
+stop:
+ /* send stop condition */
+ ti_smusbdig_i2c_packet_init(&packet);
+ ti_smusbdig_packet_add_command(&packet, TI_SMUSBDIG_I2C_STOP);
+ ret = ti_smusbdig_xfer(ti_smusbdig_i2c->ti_smusbdig,
+ (u8 *)&packet, sizeof(packet));
+ if (ret)
+ return ret;
+
+ return num;
+}
+
+static u32 ti_smusbdig_i2c_func(struct i2c_adapter *adapter)
+{
+ return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+}
+
+static const struct i2c_algorithm ti_smusbdig_i2c_algo = {
+ .master_xfer = ti_smusbdig_i2c_xfer,
+ .functionality = ti_smusbdig_i2c_func,
+};
+
+static struct i2c_adapter ti_smusbdig_i2c_adapter = {
+ .owner = THIS_MODULE,
+ .class = I2C_CLASS_HWMON,
+ .algo = &ti_smusbdig_i2c_algo,
+};
+
+static struct i2c_adapter_quirks dln2_i2c_quirks = {
+ .max_read_len = TI_SMUSBDIG_I2C_MAX_MSG,
+ .max_write_len = TI_SMUSBDIG_I2C_MAX_MSG,
+};
+
+static int ti_smusbdig_i2c_probe(struct platform_device *pdev)
+{
+ struct ti_smusbdig_i2c *ti_smusbdig_i2c;
+ struct device *dev = &pdev->dev;
+ int ret;
+
+ ti_smusbdig_i2c = devm_kzalloc(dev, sizeof(*ti_smusbdig_i2c), GFP_KERNEL);
+ if (!ti_smusbdig_i2c)
+ return -ENOMEM;
+
+ ti_smusbdig_i2c->dev = dev;
+ ti_smusbdig_i2c->ti_smusbdig = dev_get_drvdata(dev->parent);
+ ti_smusbdig_i2c->adapter = ti_smusbdig_i2c_adapter;
+ strlcpy(ti_smusbdig_i2c->adapter.name, dev_name(dev),
+ sizeof(ti_smusbdig_i2c->adapter.name));
+ ti_smusbdig_i2c->adapter.quirks = &dln2_i2c_quirks;
+ ti_smusbdig_i2c->adapter.dev.parent = dev;
+ ti_smusbdig_i2c->adapter.dev.of_node = dev->of_node;
+
+ i2c_set_adapdata(&ti_smusbdig_i2c->adapter, ti_smusbdig_i2c);
+ platform_set_drvdata(pdev, ti_smusbdig_i2c);
+
+ ret = i2c_add_adapter(&ti_smusbdig_i2c->adapter);
+ if (ret) {
+ dev_err(dev, "unable to add I2C adapter\n");
+ return ret;
+ }
+
+ dev_info(dev, "TI SM-USB-DIG Added: I2C Bus\n");
+
+ return 0;
+}
+
+static int ti_smusbdig_i2c_remove(struct platform_device *pdev)
+{
+ struct ti_smusbdig_i2c *ti_smusbdig_i2c = platform_get_drvdata(pdev);
+
+ i2c_del_adapter(&ti_smusbdig_i2c->adapter);
+
+ return 0;
+}
+
+static const struct platform_device_id ti_smusbdig_i2c_id_table[] = {
+ { "ti-sm-usb-dig-i2c", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, ti_smusbdig_i2c_id_table);
+
+static struct platform_driver ti_smusbdig_i2c_driver = {
+ .driver = {
+ .name = "ti-sm-usb-dig-i2c",
+ },
+ .probe = ti_smusbdig_i2c_probe,
+ .remove = ti_smusbdig_i2c_remove,
+ .id_table = ti_smusbdig_i2c_id_table,
+};
+module_platform_driver(ti_smusbdig_i2c_driver);
+
+MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
+MODULE_DESCRIPTION("I2C bus driver for TI SM-USB-DIG interface adapter");
+MODULE_LICENSE("GPL v2");
--
2.9.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
2016-08-09 14:55 ` Andrew F. Davis
(?)
@ 2016-08-09 15:27 ` Lee Jones
2016-08-16 16:43 ` Andrew F. Davis
-1 siblings, 1 reply; 11+ messages in thread
From: Lee Jones @ 2016-08-09 15:27 UTC (permalink / raw)
To: Andrew F. Davis; +Cc: Wolfram Sang, linux-i2c, linux-usb, linux-kernel
On Tue, 09 Aug 2016, Andrew F. Davis wrote:
> The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter.
> Add MFD core support.
>
> Signed-off-by: Andrew F. Davis <afd@ti.com>
> ---
> drivers/mfd/Kconfig | 9 +++
> drivers/mfd/Makefile | 2 +
> drivers/mfd/ti-smusbdig.c | 138 ++++++++++++++++++++++++++++++++++++++++
> include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++++++++++
> 4 files changed, 224 insertions(+)
> create mode 100644 drivers/mfd/ti-smusbdig.c
> create mode 100644 include/linux/mfd/ti-smusbdig.h
Still requires a DT Ack.
Please ping the relevant guys.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
2016-08-09 15:27 ` Lee Jones
@ 2016-08-16 16:43 ` Andrew F. Davis
0 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-16 16:43 UTC (permalink / raw)
To: Lee Jones; +Cc: Wolfram Sang, linux-i2c, linux-usb, linux-kernel
On 08/09/2016 10:27 AM, Lee Jones wrote:
> On Tue, 09 Aug 2016, Andrew F. Davis wrote:
>
>> The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter.
>> Add MFD core support.
>>
>> Signed-off-by: Andrew F. Davis <afd@ti.com>
>> ---
>> drivers/mfd/Kconfig | 9 +++
>> drivers/mfd/Makefile | 2 +
>> drivers/mfd/ti-smusbdig.c | 138 ++++++++++++++++++++++++++++++++++++++++
>> include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++++++++++
>> 4 files changed, 224 insertions(+)
>> create mode 100644 drivers/mfd/ti-smusbdig.c
>> create mode 100644 include/linux/mfd/ti-smusbdig.h
>
> Still requires a DT Ack.
>
> Please ping the relevant guys.
>
This driver doesn't touch DT.
If you meant USB, could you give me a hint as to who needs to ack
drivers that communicate over USB?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
@ 2016-08-16 16:43 ` Andrew F. Davis
0 siblings, 0 replies; 11+ messages in thread
From: Andrew F. Davis @ 2016-08-16 16:43 UTC (permalink / raw)
To: Lee Jones; +Cc: Wolfram Sang, linux-i2c, linux-usb, linux-kernel
On 08/09/2016 10:27 AM, Lee Jones wrote:
> On Tue, 09 Aug 2016, Andrew F. Davis wrote:
>
>> The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter.
>> Add MFD core support.
>>
>> Signed-off-by: Andrew F. Davis <afd@ti.com>
>> ---
>> drivers/mfd/Kconfig | 9 +++
>> drivers/mfd/Makefile | 2 +
>> drivers/mfd/ti-smusbdig.c | 138 ++++++++++++++++++++++++++++++++++++++++
>> include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++++++++++
>> 4 files changed, 224 insertions(+)
>> create mode 100644 drivers/mfd/ti-smusbdig.c
>> create mode 100644 include/linux/mfd/ti-smusbdig.h
>
> Still requires a DT Ack.
>
> Please ping the relevant guys.
>
This driver doesn't touch DT.
If you meant USB, could you give me a hint as to who needs to ack
drivers that communicate over USB?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
2016-08-16 16:43 ` Andrew F. Davis
(?)
@ 2016-08-17 7:45 ` Lee Jones
-1 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2016-08-17 7:45 UTC (permalink / raw)
To: Andrew F. Davis
Cc: Wolfram Sang, linux-i2c, linux-usb, linux-kernel, Johan Hovold
On Tue, 16 Aug 2016, Andrew F. Davis wrote:
> On 08/09/2016 10:27 AM, Lee Jones wrote:
> > On Tue, 09 Aug 2016, Andrew F. Davis wrote:
> >
> >> The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter.
> >> Add MFD core support.
> >>
> >> Signed-off-by: Andrew F. Davis <afd@ti.com>
> >> ---
> >> drivers/mfd/Kconfig | 9 +++
> >> drivers/mfd/Makefile | 2 +
> >> drivers/mfd/ti-smusbdig.c | 138 ++++++++++++++++++++++++++++++++++++++++
> >> include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++++++++++
> >> 4 files changed, 224 insertions(+)
> >> create mode 100644 drivers/mfd/ti-smusbdig.c
> >> create mode 100644 include/linux/mfd/ti-smusbdig.h
> >
> > Still requires a DT Ack.
> >
> > Please ping the relevant guys.
> >
>
> This driver doesn't touch DT.
>
> If you meant USB, could you give me a hint as to who needs to ack
> drivers that communicate over USB?
Ah yes, my bad. I was on auto-pilot, since that's what I usually find
myself asking for.
W.R.T. the USB Ack, Johan (now CC'ed) has been pretty helpful in the
past.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG
2016-08-09 14:55 ` Andrew F. Davis
(?)
(?)
@ 2016-08-26 9:28 ` Johan Hovold
-1 siblings, 0 replies; 11+ messages in thread
From: Johan Hovold @ 2016-08-26 9:28 UTC (permalink / raw)
To: Andrew F. Davis
Cc: Wolfram Sang, Lee Jones, linux-i2c, linux-usb, linux-kernel
On Tue, Aug 09, 2016 at 09:55:16AM -0500, Andrew F. Davis wrote:
> The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter.
> Add MFD core support.
>
> Signed-off-by: Andrew F. Davis <afd@ti.com>
> ---
> drivers/mfd/Kconfig | 9 +++
> drivers/mfd/Makefile | 2 +
> drivers/mfd/ti-smusbdig.c | 138 ++++++++++++++++++++++++++++++++++++++++
> include/linux/mfd/ti-smusbdig.h | 75 ++++++++++++++++++++++
> 4 files changed, 224 insertions(+)
> create mode 100644 drivers/mfd/ti-smusbdig.c
> create mode 100644 include/linux/mfd/ti-smusbdig.h
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 2d1fb64..0b63431 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1387,6 +1387,15 @@ config MFD_LM3533
> additional drivers must be enabled in order to use the LED,
> backlight or ambient-light-sensor functionality of the device.
>
> +config MFD_TI_SMUSBDIG
> + tristate "Texas Instruments SM-USB-DIG interface adapter"
> + depends on USB
> + select MFD_CORE
> + help
> + Support for the TI SM-USB-DIG USB to SPI/I2C/1Wire/GPIO adapter.
> + Additional drivers such as SPI_TI_SMUSBDIG, I2C_TI_SMUSBDIG, etc. must
> + be enabled in order to use the functionality of the device.
> +
> config MFD_TIMBERDALE
> tristate "Timberdale FPGA"
> select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 2ba3ba3..aa2845e 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -68,6 +68,8 @@ obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
> wm8994-objs := wm8994-core.o wm8994-irq.o wm8994-regmap.o
> obj-$(CONFIG_MFD_WM8994) += wm8994.o
>
> +obj-$(CONFIG_MFD_TI_SMUSBDIG) += ti-smusbdig.o
> +
> obj-$(CONFIG_TPS6105X) += tps6105x.o
> obj-$(CONFIG_TPS65010) += tps65010.o
> obj-$(CONFIG_TPS6507X) += tps6507x.o
> diff --git a/drivers/mfd/ti-smusbdig.c b/drivers/mfd/ti-smusbdig.c
> new file mode 100644
> index 0000000..19f48c6
> --- /dev/null
> +++ b/drivers/mfd/ti-smusbdig.c
> @@ -0,0 +1,138 @@
> +/*
> + * MFD Core driver for TI SM-USB-DIG
> + *
> + * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
> + * Andrew F. Davis <afd@ti.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether expressed or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License version 2 for more details.
> + */
> +
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/ti-smusbdig.h>
> +#include <linux/module.h>
> +#include <linux/usb.h>
> +
> +#define TI_USB_VENDOR_ID 0x0451
> +#define TI_USB_DEVICE_ID_SM_USB_DIG 0x2f90
> +
> +#define TI_SMUSBDIG_USB_TIMEOUT_MS 1000
> +
> +struct ti_smusbdig_device {
> + struct usb_device *usb_dev;
> + struct usb_interface *interface;
> +};
> +
> +int ti_smusbdig_xfer(struct ti_smusbdig_device *ti_smusbdig,
> + u8 *buffer, int size)
> +{
> + struct device *dev = &ti_smusbdig->interface->dev;
> + int actual_length, ret;
> +
> + if (!ti_smusbdig || !buffer || size <= 0)
> + return -EINVAL;
Why not use size_t and skip the negative size check?
> +
> + ret = usb_interrupt_msg(ti_smusbdig->usb_dev,
> + usb_sndctrlpipe(ti_smusbdig->usb_dev, 1),
This should be usb_sndintpipe.
Hardcoding the EP number isn't that nice, consider using a define or
determine and store it at probe.
> + buffer, size, &actual_length,
> + TI_SMUSBDIG_USB_TIMEOUT_MS);
> + if (ret) {
> + dev_err(dev, "USB transaction failed\n");
Please include the errno in your error messages (e.g. "failed: %d\n").
You also need to check for short transfers.
> + return ret;
> + }
> +
> + ret = usb_interrupt_msg(ti_smusbdig->usb_dev,
> + usb_rcvctrlpipe(ti_smusbdig->usb_dev, 1),
usb_rcvintpipe, same comment about hardcoded EP number.
> + buffer, TI_SMUSBDIG_PACKET_SIZE, &actual_length,
> + TI_SMUSBDIG_USB_TIMEOUT_MS);
> + if (ret) {
> + dev_err(dev, "USB transaction failed\n");
> + return ret;
> + }
What about the size of the received data? Don't you either need to check
it against TI_SMUSBDIG_PACKET_SIZE or return the actual size read?
> +
> + return 0;
> +}
You also need to serialise access to the transfer function, or replies
could potentially be mismatched.
> +EXPORT_SYMBOL_GPL(ti_smusbdig_xfer);
> +
> +static const struct mfd_cell ti_smusbdig_mfd_cells[] = {
> + { .name = "ti-sm-usb-dig-gpio", },
> + { .name = "ti-sm-usb-dig-i2c", },
> + { .name = "ti-sm-usb-dig-spi", },
> + { .name = "ti-sm-usb-dig-w1", },
> +};
> +
> +static int ti_smusbdig_probe(struct usb_interface *interface,
> + const struct usb_device_id *usb_id)
> +{
> + struct usb_host_interface *hostif = interface->cur_altsetting;
> + struct device *dev = &interface->dev;
> + struct ti_smusbdig_device *ti_smusbdig;
> + u8 buffer[TI_SMUSBDIG_PACKET_SIZE];
You must not use a stack-allocated buffer for DMA transfers (use kalloc
here or in the transfer function).
> + int ret;
> +
> + if (hostif->desc.bInterfaceNumber != 0 ||
> + hostif->desc.bNumEndpoints < 2)
> + return -ENODEV;
> +
> + ti_smusbdig = devm_kzalloc(dev, sizeof(*ti_smusbdig), GFP_KERNEL);
> + if (!ti_smusbdig)
> + return -ENOMEM;
> +
> + ti_smusbdig->usb_dev = usb_get_dev(interface_to_usbdev(interface));
You must put the reference you acquire here in error paths and at
disconnect.
> + ti_smusbdig->interface = interface;
> + usb_set_intfdata(interface, ti_smusbdig);
> +
> + buffer[0] = TI_SMUSBDIG_VERSION;
> + ret = ti_smusbdig_xfer(ti_smusbdig, buffer, 1);
> + if (ret)
> + return ret;
> +
> + dev_info(dev, "TI SM-USB-DIG Version: %d.%02d Found\n",
> + buffer[0], buffer[1]);
> +
> + /* Turn on power supply output */
> + buffer[0] = TI_SMUSBDIG_COMMAND;
> + buffer[1] = TI_SMUSBDIG_COMMAND_DUTPOWERON;
> + ret = ti_smusbdig_xfer(ti_smusbdig, buffer, 2);
> + if (ret)
> + return ret;
> +
> + dev_set_drvdata(dev, ti_smusbdig);
> + ret = mfd_add_hotplug_devices(dev, ti_smusbdig_mfd_cells,
> + ARRAY_SIZE(ti_smusbdig_mfd_cells));
> + if (ret) {
> + dev_err(dev, "unable to add MFD devices\n");
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static void ti_smusbdig_disconnect(struct usb_interface *interface)
> +{
> + mfd_remove_devices(&interface->dev);
> +}
> +
> +static const struct usb_device_id ti_smusbdig_id_table[] = {
> + { USB_DEVICE(TI_USB_VENDOR_ID, TI_USB_DEVICE_ID_SM_USB_DIG) },
> + { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(usb, ti_smusbdig_id_table);
> +
> +static struct usb_driver ti_smusbdig_driver = {
> + .name = "ti-sm-usb-dig",
> + .probe = ti_smusbdig_probe,
> + .disconnect = ti_smusbdig_disconnect,
> + .id_table = ti_smusbdig_id_table,
> +};
> +module_usb_driver(ti_smusbdig_driver);
> +
> +MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
> +MODULE_DESCRIPTION("Core driver for TI SM-USB-DIG interface adapter");
> +MODULE_LICENSE("GPL v2");
> diff --git a/include/linux/mfd/ti-smusbdig.h b/include/linux/mfd/ti-smusbdig.h
> new file mode 100644
> index 0000000..46fd2da
> --- /dev/null
> +++ b/include/linux/mfd/ti-smusbdig.h
> @@ -0,0 +1,75 @@
> +/*
> + * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
> + * Andrew F. Davis <afd@ti.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether expressed or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License version 2 for more details.
> + */
> +
> +#ifndef __LINUX_MFD_TI_SMUSBDIG_H
> +#define __LINUX_MFD_TI_SMUSBDIG_H
> +
> +#define TI_SMUSBDIG_PACKET_SIZE 32
> +/* (packet size - packet header */
> +#define TI_SMUSBDIG_DATA_SIZE (TI_SMUSBDIG_PACKET_SIZE - 7)
> +
> +enum ti_smusbdig_function {
> + TI_SMUSBDIG_SPI = 0x01,
> + TI_SMUSBDIG_I2C = 0x02,
> + TI_SMUSBDIG_1W = 0x03,
> + TI_SMUSBDIG_COMMAND = 0x04,
> + TI_SMUSBDIG_VERSION = 0x07,
> +};
> +
> +enum ti_smusbdig_sub_command {
> + TI_SMUSBDIG_COMMAND_DUTPOWERON = 0x01,
> + TI_SMUSBDIG_COMMAND_DUTPOWEROFF = 0x02,
> +};
> +
> +struct ti_smusbdig_packet {
> + u8 function;
> + u8 channel;
> + u8 edge_polarity;
> + u8 num_commands;
> + u8 is_command_mask[3];
> + u8 data[TI_SMUSBDIG_DATA_SIZE];
> +} __packed;
So this packet format isn't used for all functions (e.g.
TI_SMUSBDIG_COMMAND above). Is the protocol documented somewhere?
Making the code and header more self-contained would be good, but you
could also provide a link to the documentation.
Thanks,
Johan
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2016-08-26 9:28 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-09 14:55 [PATCH v4 0/2] Add support for the TI SM-USB-DIG Andrew F. Davis
2016-08-09 14:55 ` Andrew F. Davis
2016-08-09 14:55 ` [PATCH v4 1/2] mfd: ti-smusbdig: " Andrew F. Davis
2016-08-09 14:55 ` Andrew F. Davis
2016-08-09 15:27 ` Lee Jones
2016-08-16 16:43 ` Andrew F. Davis
2016-08-16 16:43 ` Andrew F. Davis
2016-08-17 7:45 ` Lee Jones
2016-08-26 9:28 ` Johan Hovold
2016-08-09 14:55 ` [PATCH v4 2/2] i2c: ti-smusbdig: add TI SM-USB-DIG I2C bus driver Andrew F. Davis
2016-08-09 14:55 ` Andrew F. Davis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.