Commit some USB and ATA rework/refactoring (+ USB GPIO detection).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19165 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Maurus Cuelenaere 2008-11-21 12:50:06 +00:00
parent 0a61b71f73
commit c0b43a5ac2
11 changed files with 219 additions and 60 deletions

View file

@ -33,8 +33,8 @@
/* For Rolo and boot loader */
#define MODEL_NUMBER 35
#define HAVE_ATA_SD
#define HAVE_HOTSWAP
//#define HAVE_ATA_SD
//#define HAVE_HOTSWAP
//#define CONFIG_STORAGE (STORAGE_NAND | STORAGE_SD)
#define CONFIG_STORAGE STORAGE_RAMDISK /* Multivolume currently handled at firmware/target/ level */
@ -156,7 +156,7 @@
#define BOOTFILE "rockbox." BOOTFILE_EXT
#define BOOTDIR "/.rockbox"
#define CONFIG_USBOTG USBOTG_INGENIC
#define CONFIG_USBOTG USBOTG_JZ4740
#define HAVE_USBSTACK
#define USB_VENDOR_ID 0x041e
#define USB_PRODUCT_ID 0x4133

View file

@ -383,7 +383,7 @@
#define REG_TCU_TCNT4 REG16(TCU_TCNT4)
#define REG_TCU_TCSR4 REG16(TCU_TCSR4)
// n = 0,1,2,3,4,5
// n = 0,1,2,3,4,5,6,7
#define TCU_TDFR(n) (TCU_BASE + (0x40 + (n)*0x10)) /* Timer Data Full Reg */
#define TCU_TDHR(n) (TCU_BASE + (0x44 + (n)*0x10)) /* Timer Data Half Reg */
#define TCU_TCNT(n) (TCU_BASE + (0x48 + (n)*0x10)) /* Timer Counter Reg */
@ -2903,11 +2903,11 @@ do { \
/*
* MSC_CMD, MSC_CLK, MSC_D0 ~ MSC_D3
*/
#define __gpio_as_msc() \
do { \
#define __gpio_as_msc() \
do { \
REG_GPIO_PXFUNS(3) = 0x00003f00; \
REG_GPIO_PXSELC(3) = 0x00003f00; \
REG_GPIO_PXPES(3) = 0x00003f00; \
REG_GPIO_PXPES(3) = 0x00003f00; \
} while (0)
/*
@ -3027,8 +3027,8 @@ do { \
REG_GPIO_PXDIRS(p) = (1 << (o)); \
} while (0)
#define __gpio_port_as_input(p, o) \
do { \
#define __gpio_port_as_input(p, o) \
do { \
REG_GPIO_PXFUNC(p) = (1 << (o)); \
REG_GPIO_PXSELC(p) = (1 << (o)); \
REG_GPIO_PXDIRC(p) = (1 << (o)); \
@ -4168,9 +4168,9 @@ do { \
#define __msc_rd_rxfifo() ( REG_MSC_RXFIFO )
#define __msc_wr_txfifo(v) ( REG_MSC_TXFIFO = v )
#define __msc_reset() \
do { \
REG_MSC_STRPCL = MSC_STRPCL_RESET; \
#define __msc_reset() \
do { \
REG_MSC_STRPCL = MSC_STRPCL_RESET; \
while (REG_MSC_STAT & MSC_STAT_IS_RESETTING); \
} while (0)

View file

@ -32,7 +32,7 @@ int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* bu
case 0:
return nand_read_sectors(start, count, buf);
case 1:
return sd_read_sectors(start, count, buf);
return _sd_read_sectors(start, count, buf);
default:
panicf("ata_read_sectors: Drive %d unhandled!", drive);
return -1;
@ -46,7 +46,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v
case 0:
return nand_write_sectors(start, count, buf);
case 1:
return sd_write_sectors(start, count, buf);
return _sd_write_sectors(start, count, buf);
default:
panicf("ata_write_sectors: Drive %d unhandled!", drive);
return -1;
@ -55,7 +55,7 @@ int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const v
int ata_init(void)
{
if(sd_init() != 0)
if(_sd_init() != 0)
return -1;
if(nand_init() != 0)
return -2;

View file

@ -23,6 +23,7 @@
#include "jz4740.h"
#include "ata.h"
#include "ata-sd-target.h"
#include "sd.h"
#include "system.h"
#include "kernel.h"
#include "panic.h"
@ -36,10 +37,7 @@ static struct wakeup sd_wakeup;
//#define DEBUG(x...) DEBUGF(x);
#define DEBUG(x...) printf(x);
#define MMC_CD_PIN (29 + 1 * 32) /* Pin to check card insertion */
#define MMC_POWER_PIN (30 + 1 * 32) /* Pin to enable/disable card power */
//#define MMC_PW_PIN (14 + 3 * 32) /* Pin to check protect card */
#ifdef MMC_POWER_PIN
#define MMC_POWER_OFF() \
do { \
__gpio_set_pin(MMC_POWER_PIN); \
@ -49,8 +47,11 @@ do { \
do { \
__gpio_clear_pin(MMC_POWER_PIN); \
} while (0)
#endif
#ifdef MMC_CD_PIN
#define MMC_INSERT_STATUS() __gpio_get_pin(MMC_CD_PIN)
#endif
#define MMC_RESET() __msc_reset()
@ -60,24 +61,6 @@ do { \
REG_MSC_IREG = 0xffff; \
} while (0)
static inline void mmc_init_gpio(void)
{
__gpio_as_msc();
#ifdef MMC_POWER_PIN
__gpio_as_output(MMC_POWER_PIN);
__gpio_disable_pull(MMC_POWER_PIN);
__gpio_set_pin(MMC_POWER_PIN);
#endif
#ifdef MMC_CD_PIN
__gpio_as_input(MMC_CD_PIN);
__gpio_disable_pull(MMC_CD_PIN);
#endif
#ifdef MMC_PW_PIN
__gpio_as_input(MMC_PW_PIN);
__gpio_disable_pull(MMC_PW_PIN);
#endif
}
/* Error codes */
enum mmc_result_t
{
@ -509,7 +492,7 @@ static void jz_mmc_get_response(struct mmc_request *request)
buf[i] = (data >> 8) & 0xff;
buf[i + 1] = data & 0xff;
}
DEBUG("request %d, response [", request->rtype);
DEBUG("request %d, response []", request->rtype);
break;
}
case RESPONSE_NONE:
@ -768,12 +751,14 @@ static int jz_mmc_exec_cmd(struct mmc_request *request)
/* On reset, stop MMC clock */
jz_mmc_stop_clock();
}
#if 0
if (request->cmd == MMC_SEND_OP_COND)
{
DEBUG("Have a MMC card");
/* always use 1bit for MMC */
use_4bit = 0;
}
#endif
if (request->cmd == SET_BUS_WIDTH)
{
if (request->arg == 0x2)
@ -1070,13 +1055,16 @@ void MSC(void)
static void jz_mmc_hardware_init(void)
{
mmc_init_gpio(); /* init GPIO */
#ifdef MMC_POWER_ON
MMC_POWER_ON(); /* turn on power of card */
#endif
MMC_RESET(); /* reset mmc/sd controller */
MMC_IRQ_MASK(); /* mask all IRQs */
jz_mmc_stop_clock(); /* stop MMC/SD clock */
__cpm_start_msc();
#ifdef MMC_DMA_ENABLE
__cpm_start_dmac();
__dmac_enable_module();
// __cpm_start_dmac();
// __dmac_enable_module();
// REG_DMAC_DMACR = DMAC_DMACR_DME;
#if MMC_DMA_INTERRUPT
mmc_dma_rx_sem = OSSemCreate(0);
@ -1105,7 +1093,7 @@ static void mmc_send_cmd(struct mmc_request *request, int cmd, unsigned int arg,
}
static bool inited = false;
int sd_init(void)
int _sd_init(void)
{
if(!inited)
{
@ -1150,7 +1138,7 @@ tCardInfo* card_get_info_target(int card_no)
}
/* TODO */
int sd_read_sectors(unsigned long start, int count, void* buf)
int _sd_read_sectors(unsigned long start, int count, void* buf)
{
(void)start;
(void)count;
@ -1159,7 +1147,7 @@ int sd_read_sectors(unsigned long start, int count, void* buf)
}
/* TODO */
int sd_write_sectors(unsigned long start, int count, const void* buf)
int _sd_write_sectors(unsigned long start, int count, const void* buf)
{
(void)start;
(void)count;

View file

@ -18,11 +18,13 @@
* KIND, either express or implied.
*
****************************************************************************/
#ifndef ATA_SD_TARGET_H
#define ATA_SD_TARGET_H
#include "inttypes.h"
#include "hotswap.h"
#include "jz4740.h"
tCardInfo *card_get_info_target(int card_no);
bool card_detect_target(void);
@ -32,8 +34,22 @@ void card_enable_monitoring_target(bool on);
void microsd_int(void); /* ??? */
#endif
int sd_read_sectors(unsigned long start, int count, void* buf);
int sd_write_sectors(unsigned long start, int count, const void* buf);
int sd_init(void);
int _sd_read_sectors(unsigned long start, int count, void* buf);
int _sd_write_sectors(unsigned long start, int count, const void* buf);
int _sd_init(void);
#define MMC_CD_PIN (29 + 1 * 32) /* Pin to check card insertion */
//#define MMC_POWER_PIN (30 + 1 * 32) /* Pin to enable/disable card power */
//#define MMC_PW_PIN (14 + 3 * 32) /* Pin to check protect card */
static inline void mmc_init_gpio(void)
{
__gpio_as_msc();
__gpio_as_input(MMC_CD_PIN);
__gpio_enable_pull(32*3+29);
__gpio_enable_pull(32*3+10);
__gpio_enable_pull(32*3+11);
__gpio_enable_pull(32*3+12);
}
#endif

View file

@ -23,8 +23,7 @@
#include "jz4740.h"
#include "backlight-target.h"
#define GPIO_PWM (32*3)+31
#define PWM_CHN 7
#define PWM_CHN 7 /* PWM_CHN7 == GPIO(32*3 + 31) */
#define __gpio_as_PWM_CHN __gpio_as_pwm7
static void set_backlight(int val)

View file

@ -19,7 +19,30 @@
*
****************************************************************************/
#include <stdbool.h>
#ifndef __USB_TARGET_H
#define __USB_TARGET_H
#include "config.h"
#define __gpio_as_usb_detect() \
do { \
REG_GPIO_PXFUNS(3) = 0x10000000; \
REG_GPIO_PXSELS(3) = 0x10000000; \
REG_GPIO_PXPES(3) = 0x10000000; \
} while (0)
#define GPIO_UDC_DETE (32 * 3 + 28)
#define IRQ_GPIO_UDC_DETE (IRQ_GPIO_0 + GPIO_UDC_DETE)
static inline void usb_init_gpio(void)
{
__gpio_as_usb_detect();
system_enable_irq(IRQ_UDC);
__gpio_as_input(GPIO_UDC_DETE);
}
int usb_detect(void);
void usb_init_device(void);
bool usb_drv_connected(void);
#endif

View file

@ -0,0 +1,55 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2008 by Maurus Cuelenaere
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef ATA_SD_TARGET_H
#define ATA_SD_TARGET_H
#include "inttypes.h"
#include "hotswap.h"
#include "jz4740.h"
tCardInfo *card_get_info_target(int card_no);
bool card_detect_target(void);
#ifdef HAVE_HOTSWAP
void card_enable_monitoring_target(bool on);
void microsd_int(void); /* ??? */
#endif
int _sd_read_sectors(unsigned long start, int count, void* buf);
int _sd_write_sectors(unsigned long start, int count, const void* buf);
int _sd_init(void);
#define MMC_CD_PIN (29 + 1 * 32) /* Pin to check card insertion */
//#define MMC_POWER_PIN (30 + 1 * 32) /* Pin to enable/disable card power */
//#define MMC_PW_PIN (14 + 3 * 32) /* Pin to check protect card */
static inline void mmc_init_gpio(void)
{
__gpio_as_msc();
__gpio_as_input(MMC_CD_PIN);
__gpio_enable_pull(32*3+29);
__gpio_enable_pull(32*3+10);
__gpio_enable_pull(32*3+11);
__gpio_enable_pull(32*3+12);
}
#endif

View file

@ -0,0 +1,48 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2008 by Maurus Cuelenaere
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __USB_TARGET_H
#define __USB_TARGET_H
#include "config.h"
#define __gpio_as_usb_detect() \
do { \
REG_GPIO_PXFUNS(3) = 0x10000000; \
REG_GPIO_PXSELS(3) = 0x10000000; \
REG_GPIO_PXPES(3) = 0x10000000; \
} while (0)
#define GPIO_UDC_DETE (32 * 3 + 28)
#define IRQ_GPIO_UDC_DETE (IRQ_GPIO_0 + GPIO_UDC_DETE)
static inline void usb_init_gpio(void)
{
__gpio_as_usb_detect();
system_enable_irq(IRQ_UDC);
__gpio_as_input(GPIO_UDC_DETE);
}
int usb_detect(void);
void usb_init_device(void);
bool usb_drv_connected(void);
#endif

View file

@ -25,6 +25,7 @@
#include "usb_ch9.h"
#include "usb_drv.h"
#include "usb_core.h"
#include "usb-target.h"
#include "jz4740.h"
#include "thread.h"
@ -33,10 +34,6 @@
#define EP1_INTR_BIT 2
#define EP_FIFO_NOEMPTY 2
#define GPIO_UDC_DETE_PIN (32 * 3 + 6)
#define GPIO_UDC_DETE GPIO_UDC_DETE_PIN
#define IRQ_GPIO_UDC_DETE (IRQ_GPIO_0 + GPIO_UDC_DETE)
#define IS_CACHE(x) (x < 0xa0000000)
#define USB_EP0_IDLE 0
@ -81,7 +78,7 @@ static inline void select_endpoint(int ep)
}
static void readFIFO(struct usb_endpoint *ep, unsigned int size)
{
{
unsigned int *d = (unsigned int *)ep->ptr;
unsigned int s;
s = (size + 3) >> 2;
@ -90,7 +87,7 @@ static void readFIFO(struct usb_endpoint *ep, unsigned int size)
}
static void writeFIFO(struct usb_endpoint *ep, unsigned int size)
{
{
unsigned int *d = (unsigned int *)ep->ptr;
unsigned char *c;
int s, q;
@ -359,7 +356,7 @@ bool usb_drv_connected(void)
int usb_detect(void)
{
if(__gpio_get_pin(GPIO_UDC_DETE) == 1)
if(usb_drv_connected())
return USB_INSERTED;
else
return USB_EXTRACTED;
@ -367,9 +364,7 @@ int usb_detect(void)
void usb_init_device(void)
{
system_enable_irq(IRQ_UDC);
__gpio_as_input(GPIO_UDC_DETE_PIN);
return;
usb_init_gpio();
}
void usb_enable(bool on)
@ -442,6 +437,40 @@ void usb_drv_set_address(int address)
REG_USB_REG_FADDR = address;
}
int usb_drv_send(int endpoint, void* ptr, int length)
{
return 0;
}
int usb_drv_recv(int endpoint, void* ptr, int length)
{
return 0;
}
void usb_drv_set_test_mode(int mode)
{
}
int usb_drv_port_speed(void)
{
return ((REG_USB_REG_POWER & USB_POWER_HSMODE) != 0) ? 1 : 0;
}
void usb_drv_cancel_all_transfers(void)
{
int i;
for(i=0; i<5; i++)
{
endpoints[i].ptr = endpoints[i].buf;
endpoints[i].length = 0;
}
}
void usb_drv_release_endpoint(int ep)
{
}
#else

View file

@ -51,7 +51,8 @@
#if !defined(BOOTLOADER) || (CONFIG_CPU == SH7034) || \
(defined(TOSHIBA_GIGABEAT_S) && defined(USE_ROCKBOX_USB) && defined(USB_STORAGE)) || \
(defined(HAVE_USBSTACK) && (defined(CREATIVE_ZVx) || \
defined(CPU_TCC77X) || defined(CPU_TCC780X)))
defined(CPU_TCC77X) || defined(CPU_TCC780X))) || \
(CONFIG_USBOTG == USBOTG_JZ4740)
#define USB_FULL_INIT
#endif