From patchwork Tue Aug 9 14:55:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 73562 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp526842qga; Tue, 9 Aug 2016 07:55:58 -0700 (PDT) X-Received: by 10.66.147.234 with SMTP id tn10mr149541675pab.144.1470754557989; Tue, 09 Aug 2016 07:55:57 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 15si43008230pfv.78.2016.08.09.07.55.57; Tue, 09 Aug 2016 07:55:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932898AbcHIOzz (ORCPT + 27 others); Tue, 9 Aug 2016 10:55:55 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:53613 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932492AbcHIOzY (ORCPT ); Tue, 9 Aug 2016 10:55:24 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id u79EtKkf004166; Tue, 9 Aug 2016 09:55:20 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u79EtILd030333; Tue, 9 Aug 2016 09:55:18 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Tue, 9 Aug 2016 09:55:17 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u79EtIJx028315; Tue, 9 Aug 2016 09:55:18 -0500 Received: from localhost (uda0226330.am.dhcp.ti.com [128.247.83.4]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id u79EtI314950; Tue, 9 Aug 2016 09:55:18 -0500 (CDT) From: "Andrew F. Davis" To: Wolfram Sang , Lee Jones CC: , , , "Andrew F . Davis" Subject: [PATCH v4 1/2] mfd: ti-smusbdig: Add support for the TI SM-USB-DIG Date: Tue, 9 Aug 2016 09:55:16 -0500 Message-ID: <20160809145517.22815-2-afd@ti.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20160809145517.22815-1-afd@ti.com> References: <20160809145517.22815-1-afd@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The TI SM-USB-DIG is a USB to SPI/I2C/1Wire/GPIO adapter. Add MFD core support. Signed-off-by: Andrew F. Davis --- 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 -- 2.9.2 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 + * + * 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 +#include +#include +#include + +#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 "); +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 + * + * 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 */