drivers/usbmisc: Add driver for Fairchild FUSB301 USB type-C controller.

From Harri Luhtala <harri.luhtala@haltian.com>. Tested with earlier
version of NuttX; with current version checked that it compiles.
This commit is contained in:
Juha Niskanen
2017-03-31 06:35:36 -06:00
committed by Gregory Nutt
parent 5e8ed2dd4e
commit 9d13a2463f
8 changed files with 1195 additions and 1 deletions
+10
View File
@@ -552,6 +552,16 @@ if USBHOST
source drivers/usbhost/Kconfig
endif # USBHOST
menuconfig USBMISC
bool "USB Miscellaneous drivers"
default n
---help---
USB Miscellaneous drivers.
if USBMISC
source drivers/usbmisc/Kconfig
endif # USBMISC
config HAVE_USBTRACE
bool
default n
+1
View File
@@ -72,6 +72,7 @@ include syslog$(DELIM)Make.defs
include timers$(DELIM)Make.defs
include usbdev$(DELIM)Make.defs
include usbhost$(DELIM)Make.defs
include usbmisc$(DELIM)Make.defs
include usbmonitor$(DELIM)Make.defs
include video$(DELIM)Make.defs
include wireless$(DELIM)Make.defs
+1 -1
View File
@@ -220,7 +220,7 @@ static const struct file_operations g_lps25hops =
lps25h_close, /* close */
lps25h_read, /* read */
lps25h_write, /* write */
0, /* seek */
NULL, /* seek */
lps25h_ioctl /* ioctl */
#ifndef CONFIG_DISABLE_POLL
, NULL /* poll */
+29
View File
@@ -0,0 +1,29 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
comment "USB Miscellaneous drivers"
config FUSB301
bool "Fairchild FUSB301 USB type-C controller support"
default n
select I2C
---help---
Enable device driver for Fairchild USB type-C controller
if FUSB301
config DEBUG_FUSB301
bool "Enable debug support for the FUSB301"
default n
---help---
Enables debug support for the FUSB301
config FUSB301_NPOLLWAITERS
int "Number of waiters to poll"
default 2
---help---
Maximum number of threads that can be waiting on poll()
endif
+49
View File
@@ -0,0 +1,49 @@
############################################################################
# drivers/usbmisc/Make.defs
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
ifeq ($(CONFIG_USBMISC),y)
# Include USB miscellaneous drivers
ifeq ($(CONFIG_FUSB301),y)
CSRCS += fusb301.c
endif
# Include USB miscellaneous build support
DEPPATH += --dep-path usbmisc
VPATH += :usbmisc
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)usbmisc}
endif
File diff suppressed because it is too large Load Diff
+7
View File
@@ -86,6 +86,7 @@
#define _SPIBASE (0x2100) /* SPI driver commands */
#define _GPIOBASE (0x2200) /* GPIO driver commands */
#define _CLIOCBASE (0x2300) /* Contactless modules ioctl commands */
#define _USBCBASE (0x2400) /* USB-C controller ioctl commands */
/* boardctl() commands share the same number space */
@@ -401,6 +402,12 @@
#define _CLIOCVALID(c) (_IOC_TYPE(c)==_CLIOCBASE)
#define _CLIOC(nr) _IOC(_CLIOCBASE,nr)
/* USB-C controller driver ioctl definitions ********************************/
/* (see nuttx/include/usb/xxx.h */
#define _USBCIOCVALID(c) (_IOC_TYPE(c)==_USBCBASE)
#define _USBCIOC(nr) _IOC(_USBCBASE,nr)
/* boardctl() command definitions *******************************************/
#define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE)
+243
View File
@@ -0,0 +1,243 @@
/****************************************************************************
* include/nuttx/usb/fusb301.h
* FUSB301 USB type-C controller driver
*
* Copyright (C) 2016-2017 Haltian Ltd. All rights reserved.
* Authors: Harri Luhtala <harri.luhtala@haltian.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_USB_FUSB301_H
#define __INCLUDE_NUTTX_USB_FUSB301_H
#include <nuttx/fs/ioctl.h>
/************************************************************************************
* Pre-Processor Declarations
************************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/* IOCTL Commands ***********************************************************/
#define USBCIOC_READ_DEVID _USBCIOC(0x0001) /* Arg: uint8_t* pointer */
#define USBCIOC_SETUP _USBCIOC(0x0002) /* Arg: uint8_t* pointer */
#define USBCIOC_SET_MODE _USBCIOC(0x0003) /* Arg: uint8_t value */
#define USBCIOC_SET_STATE _USBCIOC(0x0004) /* Arg: uint8_t value */
#define USBCIOC_READ_STATUS _USBCIOC(0x0005) /* Arg: uint8_t* pointer*/
#define USBCIOC_READ_DEVTYPE _USBCIOC(0x0006) /* Arg: uint8_t* pointer*/
#define USBCIOC_RESET _USBCIOC(0x0007) /* Arg: None */
/************************************************************************************
* Public Types
************************************************************************************/
enum fusb301_reg_address_e
{
FUSB301_DEV_ID_REG = 0x01,
FUSB301_MODE_REG,
FUSB301_CONTROL_REG,
FUSB301_MANUAL_REG,
FUSB301_RESET_REG,
FUSB301_MASK_REG = 0x10,
FUSB301_STATUS_REG,
FUSB301_TYPE_REG,
FUSB301_INTERRUPT_REG
};
/* Device ID - 0x01 */
enum fusb301_devid_mask_e
{
DEV_ID_REVISION_MASK = 0x0F,
DEV_ID_VERSION_MASK = 0xF0
};
#define DEV_ID_VER_A 0x10
#define DEV_ID_REV_C 0x02
/* Modes - 0x02 */
enum fusb301_mode_e
{
MODE_SRC = (1 << 0),
MODE_SRC_ACC = (1 << 1),
MODE_SNK = (1 << 2),
MODE_SNK_ACC = (1 << 3),
MODE_DRP = (1 << 4),
MODE_DRP_ACC = (1 << 5)
};
/* Control - 0x03 */
enum fusb301_control_e
{
CONTROL_INT_ENABLE = (0 << 0),
CONTROL_INT_DISABLE = (1 << 0),
CONTROL_CUR_DISABLED = (0 << 1),
CONTROL_CUR_DEFAULT = (1 << 1),
CONTROL_CUR_1500 = (2 << 1),
CONTROL_CUR_3000 = (3 << 1),
CONTROL_TGL_35_15MS = (0 << 4),
CONTROL_TGL_30_20MS = (1 << 4),
CONTROL_TGL_25_25MS = (2 << 4),
CONTROL_TGL_20_30MS = (3 << 4)
};
/* Manual - 0x04 */
enum fusb301_manual_e
{
MANUAL_ERROR_REC = (1 << 0),
MANUAL_DISABLED = (1 << 1),
MANUAL_UNATT_SRC = (1 << 2),
MANUAL_UNATT_SNK = (1 << 3)
};
/* Reset - 0x05 */
enum fusb301_reset_e
{
RESET_SW_RES = (1 << 0)
};
/* Interrupt mask - 0x10 */
enum fusb301_int_mask_e
{
INT_MASK_ATTACK = (1 << 0),
INT_MASK_DETACH = (1 << 1),
INT_MASK_BC_LVL = (1 << 2),
INT_MASK_ACC_CH = (1 << 3)
};
/* Status - 0x11 */
enum fusb301_status_e
{
STATUS_ATTACH = (1 << 0),
STATUS_BC_SINK_UNATT = (0 << 1),
STATUS_BC_SINK_DEF = (1 << 1),
STATUS_BC_SINK_1500 = (2 << 1),
STATUS_BC_SINK_3000 = (3 << 1),
STATUS_VBUS_OK = (1 << 3),
STATUS_CC_NO_CONN = (0 << 4),
STATUS_CC_1 = (1 << 4),
STATUS_CC_2 = (2 << 4),
STATUS_CC_FAULT = (3 << 4)
};
/* Type - 0x12 */
enum fusb301_type_e
{
TYPE_AUDIOACC = (1 << 0),
TYPE_DEBUGACC = (1 << 1),
TYPE_SOURCE = (1 << 3),
TYPE_SINK = (1 << 4)
};
/* Interrupt - 0x13 */
enum fusb301_interrupt_e
{
INTERRUPT_ATTACH = (1 << 0),
INTERRUPT_DETACH = (1 << 1),
INTERRUPT_BC_LVL = (1 << 2),
INTERRUPT_ACC_CH = (1 << 3)
};
struct fusb301_result_s
{
uint8_t status;
uint8_t dev_type;
};
struct fusb301_setup_s
{
uint8_t drp_toggle_timing;
uint8_t host_current;
uint8_t int_mask;
bool global_int_mask;
};
struct fusb301_config_s
{
/* Device characterization */
int irq;
CODE int (*irq_attach)(FAR struct fusb301_config_s *state, xcpt_t isr,
FAR void *arg);
CODE void (*irq_enable)(FAR struct fusb301_config_s *state, bool enable);
CODE void (*irq_clear)(FAR struct fusb301_config_s *state);
};
/************************************************************************************
* Public Function Prototypes
************************************************************************************/
/****************************************************************************
* Name: fusb301_register
*
* Description:
* Register the FUSB301 character device as 'devpath'
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/usbc0"
* i2c - An instance of the I2C interface to use to communicate with FUSB301
* addr - The I2C address of the FUSB301. The I2C address of the FUSB301 is 0x25.
* config - Pointer to FUSB301 configuration
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int fusb301_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
uint8_t addr, FAR struct fusb301_config_s *config);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_NUTTX_USB_FUSB301_H */