avionic design with actual uboot and tooling
submodule of avionic design uboot bootloader and with included tools to get you started , read readme.md and readme-tk1-loader.md
This commit is contained in:
33
u-boot/drivers/usb/ulpi/Kconfig
Normal file
33
u-boot/drivers/usb/ulpi/Kconfig
Normal file
@@ -0,0 +1,33 @@
|
||||
comment "ULPI drivers"
|
||||
|
||||
choice
|
||||
prompt "ULPI Viewport type"
|
||||
optional
|
||||
default n
|
||||
help
|
||||
Select ULPI viewport (SoC-side interface to ULPI) implementation
|
||||
appropriate for the device if you want to communicate with
|
||||
UTMI (USB PHY) via ULPI interface.
|
||||
|
||||
config USB_ULPI_VIEWPORT
|
||||
bool "Generic ULPI Viewport"
|
||||
help
|
||||
Support generic ULPI Viewport implementation that is used on
|
||||
some Tegra and Snapdragon devices.
|
||||
|
||||
config USB_ULPI_VIEWPORT_OMAP
|
||||
bool "OMAP ULPI Viewport"
|
||||
help
|
||||
Support ULPI Viewport implementation that is used on OMAP devices.
|
||||
|
||||
endchoice
|
||||
|
||||
config USB_ULPI
|
||||
bool "ULPI support"
|
||||
depends on (USB_ULPI_VIEWPORT || USB_ULPI_VIEWPORT_OMAP)
|
||||
help
|
||||
Select to commnicate with USB PHY via ULPI interface.
|
||||
ULPI is wrapper on UTMI+ core that is used as
|
||||
PHY Transreceiver for USB controllers.
|
||||
|
||||
This driver uses ULPI viewports that are specific for each SoC.
|
||||
9
u-boot/drivers/usb/ulpi/Makefile
Normal file
9
u-boot/drivers/usb/ulpi/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
#
|
||||
|
||||
obj-$(CONFIG_USB_ULPI) += ulpi.o
|
||||
obj-$(CONFIG_USB_ULPI_VIEWPORT) += ulpi-viewport.o
|
||||
obj-$(CONFIG_USB_ULPI_VIEWPORT_OMAP) += omap-ulpi-viewport.o
|
||||
71
u-boot/drivers/usb/ulpi/omap-ulpi-viewport.c
Normal file
71
u-boot/drivers/usb/ulpi/omap-ulpi-viewport.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* OMAP ulpi viewport support
|
||||
* Based on drivers/usb/ulpi/ulpi-viewport.c
|
||||
*
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
|
||||
* Author: Govindraj R <govindraj.raja@ti.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <asm/io.h>
|
||||
#include <usb/ulpi.h>
|
||||
|
||||
#define OMAP_ULPI_WR_OPSEL (2 << 22)
|
||||
#define OMAP_ULPI_RD_OPSEL (3 << 22)
|
||||
#define OMAP_ULPI_START (1 << 31)
|
||||
|
||||
/*
|
||||
* Wait for having ulpi in done state
|
||||
*/
|
||||
static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
|
||||
{
|
||||
int timeout = CONFIG_USB_ULPI_TIMEOUT;
|
||||
|
||||
while (--timeout) {
|
||||
if (!(readl(ulpi_vp->viewport_addr) & mask))
|
||||
return 0;
|
||||
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return ULPI_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue a ULPI read/write request
|
||||
*/
|
||||
static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
|
||||
{
|
||||
int err;
|
||||
|
||||
writel(value, ulpi_vp->viewport_addr);
|
||||
|
||||
err = ulpi_wait(ulpi_vp, OMAP_ULPI_START);
|
||||
if (err)
|
||||
debug("ULPI request timed out\n");
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
|
||||
{
|
||||
u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
|
||||
OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
|
||||
|
||||
return ulpi_request(ulpi_vp, val);
|
||||
}
|
||||
|
||||
u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
|
||||
{
|
||||
int err;
|
||||
u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
|
||||
OMAP_ULPI_RD_OPSEL | ((u32)reg << 16);
|
||||
|
||||
err = ulpi_request(ulpi_vp, val);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return readl(ulpi_vp->viewport_addr) & 0xff;
|
||||
}
|
||||
113
u-boot/drivers/usb/ulpi/ulpi-viewport.c
Normal file
113
u-boot/drivers/usb/ulpi/ulpi-viewport.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
|
||||
* Copyright (C) 2011 CompuLab, Ltd. <www.compulab.co.il>
|
||||
*
|
||||
* Authors: Jana Rapava <fermata7@gmail.com>
|
||||
* Igor Grinberg <grinberg@compulab.co.il>
|
||||
*
|
||||
* Based on:
|
||||
* linux/drivers/usb/otg/ulpi_viewport.c
|
||||
*
|
||||
* Original Copyright follow:
|
||||
* Copyright (C) 2011 Google, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <asm/io.h>
|
||||
#include <usb/ulpi.h>
|
||||
|
||||
/* ULPI viewport control bits */
|
||||
#define ULPI_SS (1 << 27)
|
||||
#define ULPI_RWCTRL (1 << 29)
|
||||
#define ULPI_RWRUN (1 << 30)
|
||||
#define ULPI_WU (1 << 31)
|
||||
|
||||
/*
|
||||
* Wait for the ULPI request to complete
|
||||
*
|
||||
* @ulpi_viewport - the address of the viewport
|
||||
* @mask - expected value to wait for
|
||||
*
|
||||
* returns 0 on mask match, ULPI_ERROR on time out.
|
||||
*/
|
||||
static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
|
||||
{
|
||||
int timeout = CONFIG_USB_ULPI_TIMEOUT;
|
||||
|
||||
/* Wait for the bits in mask to become zero. */
|
||||
while (--timeout) {
|
||||
if ((readl(ulpi_vp->viewport_addr) & mask) == 0)
|
||||
return 0;
|
||||
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return ULPI_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wake the ULPI PHY up for communication
|
||||
*
|
||||
* returns 0 on success.
|
||||
*/
|
||||
static int ulpi_wakeup(struct ulpi_viewport *ulpi_vp)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (readl(ulpi_vp->viewport_addr) & ULPI_SS)
|
||||
return 0; /* already awake */
|
||||
|
||||
writel(ULPI_WU, ulpi_vp->viewport_addr);
|
||||
|
||||
err = ulpi_wait(ulpi_vp, ULPI_WU);
|
||||
if (err)
|
||||
printf("ULPI wakeup timed out\n");
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue a ULPI read/write request
|
||||
*
|
||||
* @value - the ULPI request
|
||||
*/
|
||||
static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = ulpi_wakeup(ulpi_vp);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
writel(value, ulpi_vp->viewport_addr);
|
||||
|
||||
err = ulpi_wait(ulpi_vp, ULPI_RWRUN);
|
||||
if (err)
|
||||
printf("ULPI request timed out\n");
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
|
||||
{
|
||||
u32 addr = (uintptr_t)reg & 0xFF;
|
||||
u32 val = ULPI_RWRUN | ULPI_RWCTRL | addr << 16 | (value & 0xff);
|
||||
|
||||
val |= (ulpi_vp->port_num & 0x7) << 24;
|
||||
return ulpi_request(ulpi_vp, val);
|
||||
}
|
||||
|
||||
u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
|
||||
{
|
||||
int err;
|
||||
u32 val = ULPI_RWRUN | ((uintptr_t)reg & 0xFF) << 16;
|
||||
|
||||
val |= (ulpi_vp->port_num & 0x7) << 24;
|
||||
err = ulpi_request(ulpi_vp, val);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return (readl(ulpi_vp->viewport_addr) >> 8) & 0xff;
|
||||
}
|
||||
245
u-boot/drivers/usb/ulpi/ulpi.c
Normal file
245
u-boot/drivers/usb/ulpi/ulpi.c
Normal file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
|
||||
* Copyright (C) 2011 CompuLab, Ltd. <www.compulab.co.il>
|
||||
*
|
||||
* Authors: Jana Rapava <fermata7@gmail.com>
|
||||
* Igor Grinberg <grinberg@compulab.co.il>
|
||||
*
|
||||
* Based on:
|
||||
* linux/drivers/usb/otg/ulpi.c
|
||||
* Generic ULPI USB transceiver support
|
||||
*
|
||||
* Original Copyright follow:
|
||||
* Copyright (C) 2009 Daniel Mack <daniel@caiaq.de>
|
||||
*
|
||||
* Based on sources from
|
||||
*
|
||||
* Sascha Hauer <s.hauer@pengutronix.de>
|
||||
* Freescale Semiconductors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <exports.h>
|
||||
#include <usb/ulpi.h>
|
||||
|
||||
#define ULPI_ID_REGS_COUNT 4
|
||||
#define ULPI_TEST_VALUE 0x55 /* 0x55 == 0b01010101 */
|
||||
|
||||
static struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
|
||||
|
||||
static int ulpi_integrity_check(struct ulpi_viewport *ulpi_vp)
|
||||
{
|
||||
u32 val, tval = ULPI_TEST_VALUE;
|
||||
int err, i;
|
||||
|
||||
/* Use the 'special' test value to check all bits */
|
||||
for (i = 0; i < 2; i++, tval <<= 1) {
|
||||
err = ulpi_write(ulpi_vp, &ulpi->scratch, tval);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
val = ulpi_read(ulpi_vp, &ulpi->scratch);
|
||||
if (val != tval) {
|
||||
printf("ULPI integrity check failed\n");
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ulpi_init(struct ulpi_viewport *ulpi_vp)
|
||||
{
|
||||
u32 val, id = 0;
|
||||
u8 *reg = &ulpi->product_id_high;
|
||||
int i;
|
||||
|
||||
/* Assemble ID from four ULPI ID registers (8 bits each). */
|
||||
for (i = 0; i < ULPI_ID_REGS_COUNT; i++) {
|
||||
val = ulpi_read(ulpi_vp, reg - i);
|
||||
if (val == ULPI_ERROR)
|
||||
return val;
|
||||
|
||||
id = (id << 8) | val;
|
||||
}
|
||||
|
||||
/* Split ID into vendor and product ID. */
|
||||
debug("ULPI transceiver ID 0x%04x:0x%04x\n", id >> 16, id & 0xffff);
|
||||
|
||||
return ulpi_integrity_check(ulpi_vp);
|
||||
}
|
||||
|
||||
int ulpi_select_transceiver(struct ulpi_viewport *ulpi_vp, unsigned speed)
|
||||
{
|
||||
u32 tspeed = ULPI_FC_FULL_SPEED;
|
||||
u32 val;
|
||||
|
||||
switch (speed) {
|
||||
case ULPI_FC_HIGH_SPEED:
|
||||
case ULPI_FC_FULL_SPEED:
|
||||
case ULPI_FC_LOW_SPEED:
|
||||
case ULPI_FC_FS4LS:
|
||||
tspeed = speed;
|
||||
break;
|
||||
default:
|
||||
printf("ULPI: %s: wrong transceiver speed specified: %u, "
|
||||
"falling back to full speed\n", __func__, speed);
|
||||
}
|
||||
|
||||
val = ulpi_read(ulpi_vp, &ulpi->function_ctrl);
|
||||
if (val == ULPI_ERROR)
|
||||
return val;
|
||||
|
||||
/* clear the previous speed setting */
|
||||
val = (val & ~ULPI_FC_XCVRSEL_MASK) | tspeed;
|
||||
|
||||
return ulpi_write(ulpi_vp, &ulpi->function_ctrl, val);
|
||||
}
|
||||
|
||||
int ulpi_set_vbus(struct ulpi_viewport *ulpi_vp, int on, int ext_power)
|
||||
{
|
||||
u32 flags = ULPI_OTG_DRVVBUS;
|
||||
u8 *reg = on ? &ulpi->otg_ctrl_set : &ulpi->otg_ctrl_clear;
|
||||
|
||||
if (ext_power)
|
||||
flags |= ULPI_OTG_DRVVBUS_EXT;
|
||||
|
||||
return ulpi_write(ulpi_vp, reg, flags);
|
||||
}
|
||||
|
||||
int ulpi_set_vbus_indicator(struct ulpi_viewport *ulpi_vp, int external,
|
||||
int passthu, int complement)
|
||||
{
|
||||
u32 flags, val;
|
||||
u8 *reg;
|
||||
|
||||
reg = external ? &ulpi->otg_ctrl_set : &ulpi->otg_ctrl_clear;
|
||||
val = ulpi_write(ulpi_vp, reg, ULPI_OTG_EXTVBUSIND);
|
||||
if (val)
|
||||
return val;
|
||||
|
||||
flags = passthu ? ULPI_IFACE_PASSTHRU : 0;
|
||||
flags |= complement ? ULPI_IFACE_EXTVBUS_COMPLEMENT : 0;
|
||||
|
||||
val = ulpi_read(ulpi_vp, &ulpi->iface_ctrl);
|
||||
if (val == ULPI_ERROR)
|
||||
return val;
|
||||
|
||||
val = val & ~(ULPI_IFACE_PASSTHRU & ULPI_IFACE_EXTVBUS_COMPLEMENT);
|
||||
val |= flags;
|
||||
val = ulpi_write(ulpi_vp, &ulpi->iface_ctrl, val);
|
||||
if (val)
|
||||
return val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ulpi_set_pd(struct ulpi_viewport *ulpi_vp, int enable)
|
||||
{
|
||||
u32 val = ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN;
|
||||
u8 *reg = enable ? &ulpi->otg_ctrl_set : &ulpi->otg_ctrl_clear;
|
||||
|
||||
return ulpi_write(ulpi_vp, reg, val);
|
||||
}
|
||||
|
||||
int ulpi_opmode_sel(struct ulpi_viewport *ulpi_vp, unsigned opmode)
|
||||
{
|
||||
u32 topmode = ULPI_FC_OPMODE_NORMAL;
|
||||
u32 val;
|
||||
|
||||
switch (opmode) {
|
||||
case ULPI_FC_OPMODE_NORMAL:
|
||||
case ULPI_FC_OPMODE_NONDRIVING:
|
||||
case ULPI_FC_OPMODE_DISABLE_NRZI:
|
||||
case ULPI_FC_OPMODE_NOSYNC_NOEOP:
|
||||
topmode = opmode;
|
||||
break;
|
||||
default:
|
||||
printf("ULPI: %s: wrong OpMode specified: %u, "
|
||||
"falling back to OpMode Normal\n", __func__, opmode);
|
||||
}
|
||||
|
||||
val = ulpi_read(ulpi_vp, &ulpi->function_ctrl);
|
||||
if (val == ULPI_ERROR)
|
||||
return val;
|
||||
|
||||
/* clear the previous opmode setting */
|
||||
val = (val & ~ULPI_FC_OPMODE_MASK) | topmode;
|
||||
|
||||
return ulpi_write(ulpi_vp, &ulpi->function_ctrl, val);
|
||||
}
|
||||
|
||||
int ulpi_serial_mode_enable(struct ulpi_viewport *ulpi_vp, unsigned smode)
|
||||
{
|
||||
switch (smode) {
|
||||
case ULPI_IFACE_6_PIN_SERIAL_MODE:
|
||||
case ULPI_IFACE_3_PIN_SERIAL_MODE:
|
||||
break;
|
||||
default:
|
||||
printf("ULPI: %s: unrecognized Serial Mode specified: %u\n",
|
||||
__func__, smode);
|
||||
return ULPI_ERROR;
|
||||
}
|
||||
|
||||
return ulpi_write(ulpi_vp, &ulpi->iface_ctrl_set, smode);
|
||||
}
|
||||
|
||||
int ulpi_suspend(struct ulpi_viewport *ulpi_vp)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = ulpi_write(ulpi_vp, &ulpi->function_ctrl_clear,
|
||||
ULPI_FC_SUSPENDM);
|
||||
if (err)
|
||||
printf("ULPI: %s: failed writing the suspend bit\n", __func__);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for ULPI PHY reset to complete.
|
||||
* Actual wait for reset must be done in a view port specific way,
|
||||
* because it involves checking the DIR line.
|
||||
*/
|
||||
static int __ulpi_reset_wait(struct ulpi_viewport *ulpi_vp)
|
||||
{
|
||||
u32 val;
|
||||
int timeout = CONFIG_USB_ULPI_TIMEOUT;
|
||||
|
||||
/* Wait for the RESET bit to become zero */
|
||||
while (--timeout) {
|
||||
/*
|
||||
* This function is generic and suppose to work
|
||||
* with any viewport, so we cheat here and don't check
|
||||
* for the error of ulpi_read(), if there is one, then
|
||||
* there will be a timeout.
|
||||
*/
|
||||
val = ulpi_read(ulpi_vp, &ulpi->function_ctrl);
|
||||
if (!(val & ULPI_FC_RESET))
|
||||
return 0;
|
||||
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
printf("ULPI: %s: reset timed out\n", __func__);
|
||||
|
||||
return ULPI_ERROR;
|
||||
}
|
||||
int ulpi_reset_wait(struct ulpi_viewport *ulpi_vp)
|
||||
__attribute__((weak, alias("__ulpi_reset_wait")));
|
||||
|
||||
int ulpi_reset(struct ulpi_viewport *ulpi_vp)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = ulpi_write(ulpi_vp,
|
||||
&ulpi->function_ctrl_set, ULPI_FC_RESET);
|
||||
if (err) {
|
||||
printf("ULPI: %s: failed writing reset bit\n", __func__);
|
||||
return err;
|
||||
}
|
||||
|
||||
return ulpi_reset_wait(ulpi_vp);
|
||||
}
|
||||
Reference in New Issue
Block a user