Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
work in progress of usb controller and usb stack for omap3
Browse files Browse the repository at this point in the history
  • Loading branch information
travisg committed Jan 1, 2009
1 parent 6ec9c27 commit 2c691e8
Show file tree
Hide file tree
Showing 13 changed files with 472 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dev/usb/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LOCAL_DIR := $(GET_LOCAL_DIR)

OBJS += \
$(LOCAL_DIR)/usb.o

31 changes: 31 additions & 0 deletions dev/usb/usb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <debug.h>
#include <dev/usb.h>
#include <dev/usbc.h>
#include <hw/usb.h>

void usb_init(void)
{
}

31 changes: 31 additions & 0 deletions include/dev/usb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_USB_H
#define __DEV_USB_H

/* device side usb stack api */

void usb_init(void);

#endif

30 changes: 30 additions & 0 deletions include/dev/usbc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_USBC_H
#define __DEV_USBC_H

/* device side usb controller api (used by the usb stack) */
void usbc_init(void);

#endif

106 changes: 106 additions & 0 deletions include/hw/usb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __HW_USB_H
#define __HW_USB_H

#include <sys/types.h>
#include <compiler.h>

/* GLOBAL STATUS VALUES */
#define STD_COMMAND 0x00
#define SETUP_COMMAND_PHASE 0x40
#define FUNCTION_ERROR 0x7F /* Used when we are stalling the function EP0 */
#define HUB_ERROR 0xFF /* Used when we are stalling the HUB EP0 */

/* Request Types */
#define DIR_OUT (0 << 7)
#define DIR_IN (1 << 7)
#define DIR_MASK (1 << 7)
#define TYPE_STANDARD (0 << 5)
#define TYPE_CLASS (1 << 5)
#define TYPE_VENDOR (2 << 5)
#define TYPE_MASK (3 << 5)
#define RECIP_DEVICE (0 << 0)
#define RECIP_INTERFACE (1 << 0)
#define RECIP_ENDPOINT (2 << 0)
#define RECIP_OTHER (3 << 0)
#define RECIP_MASK (0x1f << 0)

/* 1.0 Request Values */
#define GET_STATUS 0x00
#define CLEAR_FEATURE 0x01
#define SET_FEATURE 0x03
#define SET_ADDRESS 0x05
#define GET_DESCRIPTOR 0x06
#define SET_DESCRIPTOR 0x07
#define GET_CONFIGURATION 0x08
#define SET_CONFIGURATION 0x09
#define GET_INTERFACE 0x0A
#define SET_INTERFACE 0x0B
#define SYNCH_FRAME 0x0C

/* Mass storage requests */
#define MASS_STORAGE_GET_MAX_LUN 0xfe
#define MASS_STORAGE_RESET 0xff

/* DFU requests */
#define DFU_DETACH 0x00
#define DFU_DNLOAD 0x01
#define DFU_UPLOAD 0x02
#define DFU_GETSTATUS 0x03
#define DFU_CLRSTATUS 0x04
#define DFU_GETSTATE 0x05
#define DFU_ABORT 0x06

/* HID Request Values */
#define GET_REPORT 0x01
#define GET_IDLE 0x02
#define GET_PROTOCOL 0x03
#define SET_REPORT 0x09
#define SET_IDLE 0x0A
#define SET_PROTOCOL 0x0B

/* Descriptor Types */
#define DEVICE 0x01
#define CONFIGURATION 0x02
#define STRING 0x03
#define INTERFACE 0x04
#define ENDPOINT 0x05
#define DEVICE_QUALIFIER 0x06
#define OTHER_SPEED_CONFIGURATION 0x07
#define INTERFACE_POWER 0x08
#define HID 0x21
#define HIDREPORT 0x22
#define HIDPHYSICAL 0x23

/* general USB defines */
struct usb_setup {
uint8_t request_type;
uint8_t request;
uint16_t value;
uint16_t index;
uint16_t length;
} __PACKED;

#endif

5 changes: 5 additions & 0 deletions include/reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#define REG16(addr) ((volatile uint16_t *)(addr))
#define REG8(addr) ((volatile uint8_t *)(addr))

#define RMWREG64(addr, startbit, width, val) *REG64(addr) = (*REG64(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
#define RMWREG32(addr, startbit, width, val) *REG32(addr) = (*REG32(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
#define RMWREG16(addr, startbit, width, val) *REG16(addr) = (*REG16(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
#define RMWREG8(addr, startbit, width, val) *REG8(addr) = (*REG8(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))

#define writel(v, a) (*REG32(a) = (v))
#define readl(a) (*REG32(a))

Expand Down
4 changes: 4 additions & 0 deletions platform/omap3/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ void i2c_init_early(void)
{
LTRACE_ENTRY;

/* enable clocks on i2c 0-2 */
RMWREG32(CM_FCLKEN1_CORE, 15, 3, 0x7),
RMWREG32(CM_ICLKEN1_CORE, 15, 3, 0x7),

i2c_reset_bus(0);
i2c_reset_bus(1);
i2c_reset_bus(2);
Expand Down
54 changes: 54 additions & 0 deletions platform/omap3/include/platform/omap3.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,47 @@
/* clocks */
#define CM_CLKSEL_PER (L4_BASE + 0x5040)

/* PRCM */
#define CM_FCLKEN_IVA2 (L4_BASE + 0x4000)
#define CM_CLKEN_PLL_IVA2 (L4_BASE + 0x4004)
#define CM_IDLEST_PLL_IVA2 (L4_BASE + 0x4024)
#define CM_CLKSEL1_PLL_IVA2 (L4_BASE + 0x4040)
#define CM_CLKSEL2_PLL_IVA2 (L4_BASE + 0x4044)
#define CM_CLKEN_PLL_MPU (L4_BASE + 0x4904)
#define CM_IDLEST_PLL_MPU (L4_BASE + 0x4924)
#define CM_CLKSEL1_PLL_MPU (L4_BASE + 0x4940)
#define CM_CLKSEL2_PLL_MPU (L4_BASE + 0x4944)
#define CM_FCLKEN1_CORE (L4_BASE + 0x4a00)
#define CM_ICLKEN1_CORE (L4_BASE + 0x4a10)
#define CM_ICLKEN2_CORE (L4_BASE + 0x4a14)
#define CM_CLKSEL_CORE (L4_BASE + 0x4a40)
#define CM_FCLKEN_GFX (L4_BASE + 0x4b00)
#define CM_ICLKEN_GFX (L4_BASE + 0x4b10)
#define CM_CLKSEL_GFX (L4_BASE + 0x4b40)
#define CM_FCLKEN_WKUP (L4_BASE + 0x4c00)
#define CM_ICLKEN_WKUP (L4_BASE + 0x4c10)
#define CM_CLKSEL_WKUP (L4_BASE + 0x4c40)
#define CM_IDLEST_WKUP (L4_BASE + 0x4c20)
#define CM_CLKEN_PLL (L4_BASE + 0x4d00)
#define CM_IDLEST_CKGEN (L4_BASE + 0x4d20)
#define CM_CLKSEL1_PLL (L4_BASE + 0x4d40)
#define CM_CLKSEL2_PLL (L4_BASE + 0x4d44)
#define CM_CLKSEL3_PLL (L4_BASE + 0x4d48)
#define CM_FCLKEN_DSS (L4_BASE + 0x4e00)
#define CM_ICLKEN_DSS (L4_BASE + 0x4e10)
#define CM_CLKSEL_DSS (L4_BASE + 0x4e40)
#define CM_FCLKEN_CAM (L4_BASE + 0x4f00)
#define CM_ICLKEN_CAM (L4_BASE + 0x4f10)
#define CM_CLKSEL_CAM (L4_BASE + 0x4F40)
#define CM_FCLKEN_PER (L4_BASE + 0x5000)
#define CM_ICLKEN_PER (L4_BASE + 0x5010)
#define CM_CLKSEL_PER (L4_BASE + 0x5040)
#define CM_CLKSEL1_EMU (L4_BASE + 0x5140)

#define PRM_CLKSEL (L4_BASE + 0x306d40)
#define PRM_RSTCTRL (L4_BASE + 0x307250)
#define PRM_CLKSRC_CTRL (L4_BASE + 0x307270)

/* General Purpose Timers */
#define OMAP34XX_GPT1 (L4_BASE + 0x318000)
#define OMAP34XX_GPT2 (L4_BASE + 0x1032000)
Expand Down Expand Up @@ -171,6 +212,19 @@
#define INT_VECTORS 96
#define GPT2_IRQ 38

/* HS USB */
#define USB_HS_BASE (L4_BASE + 0xab000)

/* USB OTG */
#define OTG_BASE (L4_BASE + 0xab400)

#define OTG_REVISION (OTG_BASE + 0x00)
#define OTG_SYSCONFIG (OTG_BASE + 0x04)
#define OTG_SYSSTATUS (OTG_BASE + 0x08)
#define OTG_INTERFSEL (OTG_BASE + 0x0C)
#define OTG_SIMENABLE (OTG_BASE + 0x10)
#define OTG_FORCESTDBY (OTG_BASE + 0x14)

/* I2C */
#define I2C1_BASE (L4_BASE + 0x70000)
#define I2C2_BASE (L4_BASE + 0x72000)
Expand Down
5 changes: 5 additions & 0 deletions platform/omap3/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <platform/omap3.h>
#include <dev/i2c.h>
#include <dev/uart.h>
#include <dev/usbc.h>

void platform_init_mmu_mappings(void)
{
Expand Down Expand Up @@ -56,5 +57,9 @@ void platform_early_init(void)
void platform_init(void)
{
i2c_init();

uart_init();

usbc_init();
}

10 changes: 9 additions & 1 deletion platform/omap3/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ ARCH := arm
ARM_CPU := cortex-a8
CPU := generic

DEVS += usb

# provides a few devices
DEFINES += \
WITH_DEV_USBC=1 \
WITH_DEV_UART=1

INCLUDES += \
-I$(LOCAL_DIR)/include

Expand All @@ -14,7 +21,8 @@ OBJS += \
$(LOCAL_DIR)/interrupts.o \
$(LOCAL_DIR)/platform.o \
$(LOCAL_DIR)/timer.o \
$(LOCAL_DIR)/uart.o
$(LOCAL_DIR)/uart.o \
$(LOCAL_DIR)/usbc.o

MEMBASE := 0x80000000

Expand Down
5 changes: 5 additions & 0 deletions platform/omap3/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ static enum handler_return os_timer_tick(void *arg)

void platform_init_timer(void)
{
/* GPT2 */
RMWREG32(CM_CLKSEL_PER, 0, 1, 1);
RMWREG32(CM_ICLKEN_PER, 3, 1, 1);
RMWREG32(CM_FCLKEN_PER, 3, 1, 1);

// reset the GP timer
TIMER_REG(TIOCP_CFG) = 0x2;
while ((TIMER_REG(TISTAT) & 1) == 0)
Expand Down
13 changes: 13 additions & 0 deletions platform/omap3/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <debug.h>
#include <reg.h>
#include <dev/uart.h>
#include <platform/omap3.h>
#include <target/debugconfig.h>
Expand Down Expand Up @@ -105,6 +106,18 @@ void uart_init_port(int port, uint baud)

void uart_init_early(void)
{
/* UART1 */
RMWREG32(CM_FCLKEN1_CORE, 13, 1, 1),
RMWREG32(CM_ICLKEN1_CORE, 13, 1, 1),

/* UART2 */
RMWREG32(CM_FCLKEN1_CORE, 14, 1, 1),
RMWREG32(CM_ICLKEN1_CORE, 14, 1, 1),

/* UART3 */
RMWREG32(CM_FCLKEN_PER, 11, 1, 1),
RMWREG32(CM_ICLKEN_PER, 11, 1, 1),

uart_init_port(DEBUG_UART, 115200);
}

Expand Down
Loading

0 comments on commit 2c691e8

Please sign in to comment.