Merged in extent3d/nuttx/usb-calibration (pull request #594)

SAMDL: Added loading factory USB calibration data from NVRAM

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Matt Thompson 2018-02-11 13:10:19 +00:00 committed by Gregory Nutt
parent 399d59028f
commit 2bb5795e54

View File

@ -107,17 +107,13 @@
#include "up_arch.h"
#include "up_internal.h"
#if defined(CONFIG_ARCH_FAMILY_SAMD20) || defined(CONFIG_ARCH_FAMILY_SAMD21)
#include "samd_periphclks.h"
#elif defined(CONFIG_ARCH_FAMILY_SAML21)
#include "saml_periphclks.h"
#endif
#include "sam_gclk.h"
#include "chip.h"
#include "sam_port.h"
#include "sam_pinmap.h"
#include "sam_usb.h"
#include "sam_fuses.h"
#include "sam_periphclks.h"
#if defined(CONFIG_USBHOST) && defined(CONFIG_SAMDL_USB)
# error USBHOST mode not yet implemented!
@ -2476,8 +2472,6 @@ static void sam_ep0_dispatch(struct sam_usbdev_s *priv)
static void sam_setdevaddr(struct sam_usbdev_s *priv, uint8_t address)
{
uint32_t regval;
DEBUGASSERT(address <= 0x7f);
if (address)
{
@ -3435,6 +3429,8 @@ static int sam_usb_interrupt(int irq, void *context, void *arg)
uwarn("WARNING: Unhandled_EP:0x%X\n", pendingep);
}
#endif
return OK;
}
void up_usbuninitialize(void)
@ -3782,6 +3778,10 @@ static void sam_hw_setup(struct sam_usbdev_s *priv)
uint16_t regval;
uint32_t padcalib;
uint8_t calib_transn;
uint8_t calib_transp;
uint8_t calib_trim;
/* To use the USB, the programmer must first configure the USB clock
* input,
*/
@ -3792,11 +3792,21 @@ static void sam_hw_setup(struct sam_usbdev_s *priv)
sam_ctrla_write(USB_CTRLA_SWRST);
/* TODO: load PAD calibration from NVM or ...
* now using default values
*/
/* Load USB factory calibration values from NVRAM */
calib_transn = getreg32(SYSCTRL_FUSES_USBTRANSN_ADDR) &
SYSCTRL_FUSES_USBTRANSN_MASK >> SYSCTRL_FUSES_USBTRANSN_SHIFT;
calib_transp = getreg32(SYSCTRL_FUSES_USBTRANSP_ADDR) &
SYSCTRL_FUSES_USBTRANSP_MASK >> SYSCTRL_FUSES_USBTRANSP_SHIFT;
calib_trim = getreg32(SYSCTRL_FUSES_USBTRIM_ADDR) &
SYSCTRL_FUSES_USBTRIM_MASK >> SYSCTRL_FUSES_USBTRIM_SHIFT;
padcalib = USB_PADCAL_TRANSP(calib_transp) |
USB_PADCAL_TRANSN(calib_transn) |
USB_PADCAL_TRIM(calib_trim);
padcalib = USB_PADCAL_TRANSP(29) | USB_PADCAL_TRANSN(5) | USB_PADCAL_TRIM(3);
sam_putreg32(padcalib, SAM_USB_PADCAL);
/* set config
@ -3866,8 +3876,6 @@ static void sam_hw_setup(struct sam_usbdev_s *priv)
static void sam_hw_shutdown(struct sam_usbdev_s *priv)
{
uint16_t regval;
priv->usbdev.speed = USB_SPEED_UNKNOWN;
/* Disable all interrupts */