drivers/usbhost/husbhost_max3421e.c: Corret how VBUS power is controlled.

This commit is contained in:
Gregory Nutt 2018-07-14 08:50:08 -06:00
parent 29474a2b08
commit 38073a523a
6 changed files with 50 additions and 12 deletions

View File

@ -5125,7 +5125,7 @@ static void stm32_host_initialize(FAR struct stm32_usbhost_s *priv)
stm32_putreg(STM32_OTGFS_HCINTMSK(i), 0);
}
/* Driver Vbus +5V (the smoke test). Should be done elsewhere in OTG
/* Drive Vbus +5V (the smoke test). Should be done elsewhere in OTG
* mode.
*/

View File

@ -87,6 +87,14 @@ config VIEWTOOL_MAX3421E_FREQUENCY
default 20000000
range 400000 26000000
config VIEWTOOL_MAX3421E_RST
bool "MAX3421E reset pin"
default y
config VIEWTOOL_MAX3421E_PWR
bool "USB Host power control"
default n
config VIEWTOOL_MAX3421E_CONNMON_STACKSIZE
int "MAX3421E USB connection monitor stack size"
default 2048

View File

@ -102,6 +102,8 @@ static int max3421e_attach(FAR const struct max3421e_lowerhalf_s *lower,
static void max3421e_enable(FAR const struct max3421e_lowerhalf_s *lower,
bool enable);
static void max3421e_acknowledge(FAR const struct max3421e_lowerhalf_s *lower);
static void max3421e_power(FAR const struct max3421e_lowerhalf_s *lower,
bool enable);
/****************************************************************************
* Private Data
@ -130,6 +132,7 @@ static struct viewtool_max3421elower_s g_max3421e_lower =
.attach = max3421e_attach, /* Attach interrupt handler */
.enable = max3421e_enable, /* Enable interrupt */
.acknowledge = max3421e_acknowledge, /* Acknowledge/clear interrupt */
.power = max3421e_power, /* Enable VBUS power */
},
};
@ -149,6 +152,7 @@ static FAR struct usbhost_connection_s *g_usbconn;
* attach - Attach the ADS7843E interrupt handler to the GPIO interrupt
* enable - Enable or disable the GPIO interrupt
* acknowledge - Acknowledge/clear any pending GPIO interrupt as necessary.
* power - Enable or disable 5V VBUS power
*
****************************************************************************/
@ -219,6 +223,14 @@ static void max3421e_acknowledge(FAR const struct max3421e_lowerhalf_s *lower)
/* Does nothing */
}
static void max3421e_power(FAR const struct max3421e_lowerhalf_s *lower,
bool enable)
{
#ifdef CONFIG_VIEWTOOL_MAX3421E_PWR
stm32_gpiowrite(GPIO_MAX3421E_PWR, enable);
#endif
}
/*****************************************************************************
* Name: usbhost_detect
*
@ -271,13 +283,20 @@ int stm32_max3421e_setup(void)
pid_t monpid;
int ret;
/* Configure the MAX3421E interrupt pin and VBUS pins as an inputs and the
* reset pin as an output. Device is initially in reset.
/* Configure the MAX3421E interrupt pin as an input and the reset and power
* pins as an outputs. Device is initially in reset and 5V power is not
* provided.
*/
(void)stm32_configgpio(GPIO_MAX3421E_INT);
#ifdef CONFIG_VIEWTOOL_MAX3421E_RST
(void)stm32_configgpio(GPIO_MAX3421E_RST);
(void)stm32_configgpio(GPIO_MAX3421E_VBUS);
#endif
#ifdef CONFIG_VIEWTOOL_MAX3421E_PWR
(void)stm32_configgpio(GPIO_MAX3421E_PWR);
#endif
/* Get an instance of the SPI interface for the touchscreen chip select */
@ -357,9 +376,11 @@ int stm32_max3421e_setup(void)
}
#endif
#ifdef CONFIG_VIEWTOOL_MAX3421E_RST
/* Take the MAX3412E out of reset */
stm32_gpiowrite(GPIO_MAX3421E_RST, true);
#endif
/* Initialize and register the MAX3421E device */

View File

@ -333,9 +333,8 @@
* ------ ----------- --------------------
* CS# J8 Pin 12 PA4/NSS1 (For SPI1)
* CS# J8 Pin 6 PB12/NSS2 (For SPI2)
* INT# J18 Pin 6 PC5
* INT# J18 Pin 10 PA0
* RST# J18 Pin 8 PA1
* VBUS J18 Pin 10 PA0
*/
#if defined(CONFIG_VIEWTOOL_MAX3421E_SPI1)
@ -348,11 +347,9 @@
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN12)
#endif
#define GPIO_MAX3421E_INT (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \
GPIO_EXTI | GPIO_PORTC | GPIO_PIN5)
#define GPIO_MAX3421E_RST (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \
GPIO_OUTPUT_CLEAR | GPIO_PORTA| GPIO_PIN1)
#define GPIO_MAX3421E_VBUS (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \
GPIO_EXTI | GPIO_PORTA | GPIO_PIN0)
#define GPIO_MAX3421E_RST (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \
GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN1)
/****************************************************************************
* Public Functions

View File

@ -4705,7 +4705,8 @@ max3421e_usbhost_initialize(FAR const struct max3421e_lowerhalf_s *lower)
int ret;
DEBUGASSERT(lower != NULL && lower->spi != NULL && lower->attach != NULL &&
lower->attach != NULL && lower->acknowledge != NULL);
lower->attach != NULL && lower->acknowledge != NULL &&
lower->power != NULL);
/* Allocate and instance of the MAX4321E state structure */
@ -4737,7 +4738,15 @@ max3421e_usbhost_initialize(FAR const struct max3421e_lowerhalf_s *lower)
goto errout_with_alloc;
}
/* Enable interrupts at the interrupt controller */
/* Drive Vbus +5V (the smoke test).
*
* REVISIT: Should be done elsewhere in order to support device self-
* powered mode? How does the MAX3421E VBUS detect logic work?
*/
lower->power(lower, true);
/* Enable host interrupts */
lower->enable(lower, true);
return &conn->conn;

View File

@ -459,6 +459,7 @@ struct max3421e_lowerhalf_s
* attach - Attach the interrupt handler to the GPIO interrupt
* enable - Enable or disable the GPIO interrupt
* acknowledge - Acknowledge/clear any pending GPIO interrupt
* power - Enable or disable 5V VBUS power
*/
CODE int (*attach)(FAR const struct max3421e_lowerhalf_s *lower,
@ -466,6 +467,8 @@ struct max3421e_lowerhalf_s
CODE void (*enable)(FAR const struct max3421e_lowerhalf_s *lower,
bool enable);
CODE void (*acknowledge)(FAR const struct max3421e_lowerhalf_s *lower);
CODE void (*power)(FAR const struct max3421e_lowerhalf_s *lower,
bool enable);
/* Additional, driver-specific state data may follow */
};