commit
dfc91c3395
@ -1,343 +0,0 @@ |
||||
/*
|
||||
* (C) Copyright 2002 |
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
||||
* Alex Zuepke <azu@sysgo.de> |
||||
* |
||||
* (C) Copyright 2005 |
||||
* 2N Telekomunikace, a.s. <www.2n.cz> |
||||
* Ladislav Michl <michl@2n.cz> |
||||
* |
||||
* See file CREDITS for list of people who contributed to this |
||||
* project. |
||||
* |
||||
* 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 program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
||||
* MA 02111-1307 USA |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
|
||||
/*#if 0 */ |
||||
#if (PHYS_SDRAM_1_SIZE != SZ_32M) |
||||
|
||||
#include "crcek.h" |
||||
|
||||
#if (CONFIG_SYS_MAX_FLASH_BANKS > 1) |
||||
#error There is always only _one_ flash chip |
||||
#endif |
||||
|
||||
flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; |
||||
|
||||
#define CMD_READ_ARRAY 0x000000f0 |
||||
#define CMD_UNLOCK1 0x000000aa |
||||
#define CMD_UNLOCK2 0x00000055 |
||||
#define CMD_ERASE_SETUP 0x00000080 |
||||
#define CMD_ERASE_CONFIRM 0x00000030 |
||||
#define CMD_PROGRAM 0x000000a0 |
||||
#define CMD_UNLOCK_BYPASS 0x00000020 |
||||
|
||||
#define MEM_FLASH_ADDR1 (*(volatile u16 *)(CONFIG_SYS_FLASH_BASE + (0x00000555 << 1))) |
||||
#define MEM_FLASH_ADDR2 (*(volatile u16 *)(CONFIG_SYS_FLASH_BASE + (0x000002aa << 1))) |
||||
|
||||
#define BIT_ERASE_DONE 0x00000080 |
||||
#define BIT_RDY_MASK 0x00000080 |
||||
#define BIT_PROGRAM_ERROR 0x00000020 |
||||
#define BIT_TIMEOUT 0x80000000 /* our flag */ |
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
*/ |
||||
|
||||
ulong flash_init(void) |
||||
{ |
||||
int i; |
||||
|
||||
flash_info[0].flash_id = (AMD_MANUFACT & FLASH_VENDMASK) | |
||||
(AMD_ID_LV800B & FLASH_TYPEMASK); |
||||
flash_info[0].size = PHYS_FLASH_1_SIZE; |
||||
flash_info[0].sector_count = CONFIG_SYS_MAX_FLASH_SECT; |
||||
memset(flash_info[0].protect, 0, CONFIG_SYS_MAX_FLASH_SECT); |
||||
|
||||
for (i = 0; i < flash_info[0].sector_count; i++) { |
||||
switch (i) { |
||||
case 0: /* 16kB */ |
||||
flash_info[0].start[0] = CONFIG_SYS_FLASH_BASE; |
||||
break; |
||||
case 1: /* 8kB */ |
||||
flash_info[0].start[1] = CONFIG_SYS_FLASH_BASE + 0x4000; |
||||
break; |
||||
case 2: /* 8kB */ |
||||
flash_info[0].start[2] = CONFIG_SYS_FLASH_BASE + 0x4000 + |
||||
0x2000; |
||||
break; |
||||
case 3: /* 32 KB */ |
||||
flash_info[0].start[3] = CONFIG_SYS_FLASH_BASE + 0x4000 + |
||||
2 * 0x2000; |
||||
break; |
||||
case 4: |
||||
flash_info[0].start[4] = CONFIG_SYS_FLASH_BASE + 0x4000 + |
||||
2 * 0x2000 + 0x8000; |
||||
break; |
||||
default: /* 64kB */ |
||||
flash_info[0].start[i] = flash_info[0].start[i-1] + |
||||
0x10000; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/* U-Boot */ |
||||
flash_protect(FLAG_PROTECT_SET, |
||||
LOADER1_OFFSET, |
||||
LOADER1_OFFSET + LOADER_SIZE - 1, flash_info); |
||||
/* Protect crcek, env and r_env as well */ |
||||
flash_protect(FLAG_PROTECT_SET, 0, 0x8000 - 1, flash_info); |
||||
|
||||
return flash_info[0].size; |
||||
} |
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
*/ |
||||
void flash_print_info(flash_info_t *info) |
||||
{ |
||||
int i; |
||||
|
||||
switch (info->flash_id & FLASH_VENDMASK) { |
||||
case (AMD_MANUFACT & FLASH_VENDMASK): |
||||
puts("AMD: "); |
||||
break; |
||||
default: |
||||
puts("Unknown vendor "); |
||||
break; |
||||
} |
||||
|
||||
switch (info->flash_id & FLASH_TYPEMASK) { |
||||
case (AMD_ID_LV800B & FLASH_TYPEMASK): |
||||
puts("AM29LV800BB (8Mb)\n"); |
||||
break; |
||||
default: |
||||
puts("Unknown chip type\n"); |
||||
return; |
||||
} |
||||
|
||||
printf(" Size: %ld MB in %d sectors\n", |
||||
info->size >> 20, info->sector_count); |
||||
|
||||
puts(" Sector start addresses:"); |
||||
for (i = 0; i < info->sector_count; i++) { |
||||
if ((i % 5) == 0) |
||||
puts("\n "); |
||||
|
||||
printf(" %08lX%s", info->start[i], |
||||
info->protect[i] ? " (RO)" : " "); |
||||
} |
||||
puts("\n"); |
||||
} |
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
*/ |
||||
|
||||
int flash_erase(flash_info_t *info, int s_first, int s_last) |
||||
{ |
||||
ushort result; |
||||
int prot, sect; |
||||
int rc = ERR_OK; |
||||
|
||||
/* first look for protection bits */ |
||||
|
||||
if (info->flash_id == FLASH_UNKNOWN) |
||||
return ERR_UNKNOWN_FLASH_TYPE; |
||||
|
||||
if ((s_first < 0) || (s_first > s_last)) |
||||
return ERR_INVAL; |
||||
|
||||
if ((info->flash_id & FLASH_VENDMASK) != |
||||
(AMD_MANUFACT & FLASH_VENDMASK)) |
||||
return ERR_UNKNOWN_FLASH_VENDOR; |
||||
|
||||
prot = 0; |
||||
for (sect = s_first; sect <= s_last; ++sect) |
||||
if (info->protect[sect]) |
||||
prot++; |
||||
|
||||
if (prot) |
||||
printf("- Warning: %d protected sectors will not be erased!\n", |
||||
prot); |
||||
else |
||||
putc('\n'); |
||||
|
||||
/* Start erase on unprotected sectors */ |
||||
for (sect = s_first; sect <= s_last && !ctrlc (); sect++) { |
||||
if (info->protect[sect] == 0) { /* not protected */ |
||||
vu_short *addr = (vu_short *) (info->start[sect]); |
||||
|
||||
/* arm simple, non interrupt dependent timer */ |
||||
reset_timer_masked(); |
||||
|
||||
MEM_FLASH_ADDR1 = CMD_UNLOCK1; |
||||
MEM_FLASH_ADDR2 = CMD_UNLOCK2; |
||||
MEM_FLASH_ADDR1 = CMD_ERASE_SETUP; |
||||
|
||||
MEM_FLASH_ADDR1 = CMD_UNLOCK1; |
||||
MEM_FLASH_ADDR2 = CMD_UNLOCK2; |
||||
*addr = CMD_ERASE_CONFIRM; |
||||
|
||||
/* wait until flash is ready */ |
||||
while (1) { |
||||
result = *addr; |
||||
|
||||
/* check timeout */ |
||||
if (get_timer_masked() > CONFIG_SYS_FLASH_ERASE_TOUT) { |
||||
MEM_FLASH_ADDR1 = CMD_READ_ARRAY; |
||||
rc = ERR_TIMOUT; |
||||
break; |
||||
} |
||||
|
||||
if ((result & 0xfff) & BIT_ERASE_DONE) |
||||
break; |
||||
|
||||
if ((result & 0xffff) & BIT_PROGRAM_ERROR) { |
||||
rc = ERR_PROG_ERROR; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
MEM_FLASH_ADDR1 = CMD_READ_ARRAY; |
||||
|
||||
if (rc != ERR_OK) |
||||
goto out; |
||||
|
||||
putc('.'); |
||||
} |
||||
} |
||||
out: |
||||
/* allow flash to settle - wait 10 ms */ |
||||
udelay_masked(10000); |
||||
|
||||
return rc; |
||||
} |
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
* Copy memory to flash |
||||
*/ |
||||
|
||||
static int write_hword(flash_info_t *info, ulong dest, ushort data) |
||||
{ |
||||
vu_short *addr = (vu_short *) dest; |
||||
ushort result; |
||||
int rc = ERR_OK; |
||||
|
||||
/* check if flash is (sufficiently) erased */ |
||||
result = *addr; |
||||
if ((result & data) != data) |
||||
return ERR_NOT_ERASED; |
||||
|
||||
MEM_FLASH_ADDR1 = CMD_UNLOCK1; |
||||
MEM_FLASH_ADDR2 = CMD_UNLOCK2; |
||||
MEM_FLASH_ADDR1 = CMD_PROGRAM; |
||||
*addr = data; |
||||
|
||||
/* arm simple, non interrupt dependent timer */ |
||||
reset_timer_masked(); |
||||
|
||||
/* wait until flash is ready */ |
||||
while (1) { |
||||
result = *addr; |
||||
|
||||
/* check timeout */ |
||||
if (get_timer_masked () > CONFIG_SYS_FLASH_ERASE_TOUT) { |
||||
rc = ERR_TIMOUT; |
||||
break; |
||||
} |
||||
|
||||
if ((result & 0x80) == (data & 0x80)) |
||||
break; |
||||
|
||||
if ((result & 0xffff) & BIT_PROGRAM_ERROR) { |
||||
result = *addr; |
||||
|
||||
if ((result & 0x80) != (data & 0x80)) |
||||
rc = ERR_PROG_ERROR; |
||||
} |
||||
} |
||||
|
||||
*addr = CMD_READ_ARRAY; |
||||
|
||||
if (*addr != data) |
||||
rc = ERR_PROG_ERROR; |
||||
|
||||
return rc; |
||||
} |
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
* Copy memory to flash. |
||||
*/ |
||||
|
||||
int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) |
||||
{ |
||||
ulong cp, wp; |
||||
int l; |
||||
int i, rc; |
||||
ushort data; |
||||
|
||||
wp = (addr & ~1); /* get lower word aligned address */ |
||||
|
||||
/*
|
||||
* handle unaligned start bytes |
||||
*/ |
||||
if ((l = addr - wp) != 0) { |
||||
data = 0; |
||||
for (i = 0, cp = wp; i < l; ++i, ++cp) |
||||
data = (data >> 8) | (*(uchar *) cp << 8); |
||||
for (; i < 2 && cnt > 0; ++i) { |
||||
data = (data >> 8) | (*src++ << 8); |
||||
--cnt; |
||||
++cp; |
||||
} |
||||
for (; cnt == 0 && i < 2; ++i, ++cp) |
||||
data = (data >> 8) | (*(uchar *) cp << 8); |
||||
|
||||
if ((rc = write_hword(info, wp, data)) != 0) |
||||
return (rc); |
||||
wp += 2; |
||||
} |
||||
|
||||
/*
|
||||
* handle word aligned part |
||||
*/ |
||||
while (cnt >= 2) { |
||||
data = *((vu_short *) src); |
||||
if ((rc = write_hword(info, wp, data)) != 0) |
||||
return (rc); |
||||
src += 2; |
||||
wp += 2; |
||||
cnt -= 2; |
||||
} |
||||
|
||||
if (cnt == 0) |
||||
return ERR_OK; |
||||
|
||||
/*
|
||||
* handle unaligned tail bytes |
||||
*/ |
||||
data = 0; |
||||
for (i = 0, cp = wp; i < 2 && cnt > 0; ++i, ++cp) { |
||||
data = (data >> 8) | (*src++ << 8); |
||||
--cnt; |
||||
} |
||||
for (; i < 2; ++i, ++cp) |
||||
data = (data >> 8) | (*(uchar *) cp << 8); |
||||
|
||||
return write_hword(info, wp, data); |
||||
} |
||||
|
||||
#endif |
@ -1,62 +0,0 @@ |
||||
/*
|
||||
* (C) Copyright 2005 2N TELEKOMUNIKACE, Ladislav Michl |
||||
* |
||||
* See file CREDITS for list of people who contributed to this |
||||
* project. |
||||
* |
||||
* 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 program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
||||
* MA 02111-1307 USA |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <asm/io.h> |
||||
|
||||
#if defined(CONFIG_CMD_NAND) |
||||
|
||||
#include <nand.h> |
||||
|
||||
/*
|
||||
* hardware specific access to control-lines |
||||
*/ |
||||
#define MASK_CLE 0x02 |
||||
#define MASK_ALE 0x04 |
||||
|
||||
static void netstar_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
||||
{ |
||||
struct nand_chip *this = mtd->priv; |
||||
ulong IO_ADDR_W = (ulong) this->IO_ADDR_W; |
||||
|
||||
IO_ADDR_W &= ~(MASK_ALE|MASK_CLE); |
||||
if (ctrl & NAND_CTRL_CHANGE) { |
||||
if ( ctrl & NAND_CLE ) |
||||
IO_ADDR_W |= MASK_CLE; |
||||
if ( ctrl & NAND_ALE ) |
||||
IO_ADDR_W |= MASK_ALE; |
||||
} |
||||
this->IO_ADDR_W = (void __iomem *) IO_ADDR_W; |
||||
|
||||
if (cmd != NAND_CMD_NONE) |
||||
writeb(cmd, this->IO_ADDR_W); |
||||
} |
||||
|
||||
int board_nand_init(struct nand_chip *nand) |
||||
{ |
||||
nand->options = NAND_SAMSUNG_LP_OPTIONS; |
||||
nand->ecc.mode = NAND_ECC_SOFT; |
||||
nand->cmd_ctrl = netstar_nand_hwcontrol; |
||||
nand->chip_delay = 400; |
||||
return 0; |
||||
} |
||||
#endif |
@ -0,0 +1,46 @@ |
||||
#
|
||||
# (C) Copyright 2000-2008
|
||||
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
||||
#
|
||||
# See file CREDITS for list of people who contributed to this
|
||||
# project.
|
||||
#
|
||||
# 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 program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
# MA 02111-1307 USA
|
||||
#
|
||||
|
||||
include $(TOPDIR)/config.mk |
||||
|
||||
LIB = $(obj)lib$(SOC).a
|
||||
|
||||
COBJS-y += cache.o
|
||||
|
||||
SRCS := $(SOBJS:.o=.S) $(COBJS-y:.o=.c)
|
||||
OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS-y))
|
||||
|
||||
all: $(obj).depend $(LIB) |
||||
|
||||
$(LIB): $(OBJS) |
||||
$(AR) $(ARFLAGS) $@ $(OBJS)
|
||||
|
||||
#########################################################################
|
||||
|
||||
# defines $(obj).depend target
|
||||
include $(SRCTREE)/rules.mk |
||||
|
||||
sinclude $(obj).depend |
||||
|
||||
#########################################################################
|
||||
|
@ -0,0 +1,86 @@ |
||||
/*
|
||||
* (C) Copyright 2002 |
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
||||
* Marius Groeger <mgroeger@sysgo.de> |
||||
* |
||||
* (C) Copyright 2002 |
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
||||
* Alex Zuepke <azu@sysgo.de> |
||||
* |
||||
* See file CREDITS for list of people who contributed to this |
||||
* project. |
||||
* |
||||
* 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 program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
||||
* MA 02111-1307 USA |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <asm/hardware.h> |
||||
|
||||
void icache_enable (void) |
||||
{ |
||||
s32 i; |
||||
|
||||
/* disable all cache bits */ |
||||
CLR_REG( REG_SYSCFG, 0x3F); |
||||
|
||||
/* 8KB cache, write enable */ |
||||
SET_REG( REG_SYSCFG, CACHE_WRITE_BUFF | CACHE_MODE_01); |
||||
|
||||
/* clear TAG RAM bits */ |
||||
for ( i = 0; i < 256; i++) |
||||
PUT_REG( CACHE_TAG_RAM + 4*i, 0x00000000); |
||||
|
||||
/* clear SET0 RAM */ |
||||
for(i=0; i < 1024; i++) |
||||
PUT_REG( CACHE_SET0_RAM + 4*i, 0x00000000); |
||||
|
||||
/* clear SET1 RAM */ |
||||
for(i=0; i < 1024; i++) |
||||
PUT_REG( CACHE_SET1_RAM + 4*i, 0x00000000); |
||||
|
||||
/* enable cache */ |
||||
SET_REG( REG_SYSCFG, CACHE_ENABLE); |
||||
|
||||
} |
||||
|
||||
void icache_disable (void) |
||||
{ |
||||
/* disable all cache bits */ |
||||
CLR_REG( REG_SYSCFG, 0x3F); |
||||
} |
||||
|
||||
int icache_status (void) |
||||
{ |
||||
return GET_REG( REG_SYSCFG) & CACHE_ENABLE; |
||||
} |
||||
|
||||
void dcache_enable (void) |
||||
{ |
||||
/* we don't have seperate instruction/data caches */ |
||||
icache_enable(); |
||||
} |
||||
|
||||
void dcache_disable (void) |
||||
{ |
||||
/* we don't have seperate instruction/data caches */ |
||||
icache_disable(); |
||||
} |
||||
|
||||
int dcache_status (void) |
||||
{ |
||||
/* we don't have seperate instruction/data caches */ |
||||
return icache_status(); |
||||
} |
@ -0,0 +1,91 @@ |
||||
/*
|
||||
* (C) Copyright 2004 |
||||
* DAVE Srl |
||||
* http://www.dave-tech.it
|
||||
* http://www.wawnet.biz
|
||||
* mailto:info@wawnet.biz |
||||
* |
||||
* See file CREDITS for list of people who contributed to this |
||||
* project. |
||||
* |
||||
* 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 program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
||||
* MA 02111-1307 USA |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <command.h> |
||||
#include <asm/hardware.h> |
||||
|
||||
static void s3c44b0_flush_cache(void) |
||||
{ |
||||
volatile int i; |
||||
/* flush cycle */ |
||||
for(i=0x10002000;i<0x10004800;i+=16) |
||||
{ |
||||
*((int *)i)=0x0; |
||||
} |
||||
} |
||||
|
||||
void icache_enable (void) |
||||
{ |
||||
ulong reg; |
||||
|
||||
s3c44b0_flush_cache(); |
||||
|
||||
/*
|
||||
Init cache |
||||
Non-cacheable area (everything outside RAM) |
||||
0x0000:0000 - 0x0C00:0000 |
||||
*/ |
||||
NCACHBE0 = 0xC0000000; |
||||
NCACHBE1 = 0x00000000; |
||||
|
||||
/*
|
||||
Enable chache |
||||
*/ |
||||
reg = SYSCFG; |
||||
reg |= 0x00000006; /* 8kB */ |
||||
SYSCFG = reg; |
||||
} |
||||
|
||||
void icache_disable (void) |
||||
{ |
||||
ulong reg; |
||||
|
||||
reg = SYSCFG; |
||||
reg &= ~0x00000006; /* 8kB */ |
||||
SYSCFG = reg; |
||||
} |
||||
|
||||
int icache_status (void) |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
void dcache_enable (void) |
||||
{ |
||||
icache_enable(); |
||||
} |
||||
|
||||
void dcache_disable (void) |
||||
{ |
||||
icache_disable(); |
||||
} |
||||
|
||||
int dcache_status (void) |
||||
{ |
||||
return dcache_status(); |
||||
} |
||||
|
@ -0,0 +1,315 @@ |
||||
/*
|
||||
* (C) Copyright 2004 |
||||
* DAVE Srl |
||||
* http://www.dave-tech.it
|
||||
* http://www.wawnet.biz
|
||||
* mailto:info@wawnet.biz |
||||
* |
||||
* See file CREDITS for list of people who contributed to this |
||||
* project. |
||||
* |
||||
* 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 program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
||||
* MA 02111-1307 USA |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <command.h> |
||||
#include <asm/hardware.h> |
||||
|
||||
/*
|
||||
* Initialization, must be called once on start up, may be called |
||||
* repeatedly to change the speed and slave addresses. |
||||
*/ |
||||
void i2c_init(int speed, int slaveaddr) |
||||
{ |
||||
/*
|
||||
setting up I2C support |
||||
*/ |
||||
unsigned int save_F,save_PF,rIICCON,rPCONA,rPDATA,rPCONF,rPUPF; |
||||
|
||||
save_F = PCONF; |
||||
save_PF = PUPF; |
||||
|
||||
rPCONF = ((save_F & ~(0xF))| 0xa); |
||||
rPUPF = (save_PF | 0x3); |
||||
PCONF = rPCONF; /*PF0:IICSCL, PF1:IICSDA*/ |
||||
PUPF = rPUPF; /* Disable pull-up */ |
||||
|
||||
/* Configuring pin for WC pin of EEprom */ |
||||
rPCONA = PCONA; |
||||
rPCONA &= ~(1<<9); |
||||
PCONA = rPCONA; |
||||
|
||||
rPDATA = PDATA; |
||||
rPDATA &= ~(1<<9); |
||||
PDATA = rPDATA; |
||||
|
||||
/*
|
||||
Enable ACK, IICCLK=MCLK/16, enable interrupt |
||||
75MHz/16/(12+1) = 390625 Hz |
||||
*/ |
||||
rIICCON=(1<<7)|(0<<6)|(1<<5)|(0xC); |
||||
IICCON = rIICCON; |
||||
|
||||
IICADD = slaveaddr; |
||||
} |
||||
|
||||
/*
|
||||
* Probe the given I2C chip address. Returns 0 if a chip responded, |
||||
* not 0 on failure. |
||||
*/ |
||||
int i2c_probe(uchar chip) |
||||
{ |
||||
/*
|
||||
not implemented |
||||
*/ |
||||
|
||||
printf("i2c_probe chip %d\n", (int) chip); |
||||
return -1; |
||||
} |
||||
|
||||
/*
|
||||
* Read/Write interface: |
||||
* chip: I2C chip address, range 0..127 |
||||
* addr: Memory (register) address within the chip |
||||
* alen: Number of bytes to use for addr (typically 1, 2 for larger |
||||
* memories, 0 for register type devices with only one |
||||
* register) |
||||
* buffer: Where to read/write the data |
||||
* len: How many bytes to read/write |
||||
* |
||||
* Returns: 0 on success, not 0 on failure |
||||
*/ |
||||
|
||||
#define S3C44B0X_rIIC_INTPEND (1<<4) |
||||
#define S3C44B0X_rIIC_LAST_RECEIV_BIT (1<<0) |
||||
#define S3C44B0X_rIIC_INTERRUPT_ENABLE (1<<5) |
||||
#define S3C44B0_IIC_TIMEOUT 100 |
||||
|
||||
int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) |
||||
{ |
||||
|
||||
int k, j, temp; |
||||
u32 rIICSTAT; |
||||
|
||||
/*
|
||||
send the device offset |
||||
*/ |
||||
|
||||
rIICSTAT = 0xD0; |
||||
IICSTAT = rIICSTAT; |
||||
|
||||
IICDS = chip; /* this is a write operation... */ |
||||
|
||||
rIICSTAT |= (1<<5); |
||||
IICSTAT = rIICSTAT; |
||||
|
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
udelay(2000); |
||||
} |
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
/* wait and check ACK */ |
||||
temp = IICSTAT; |
||||
if ((temp & S3C44B0X_rIIC_LAST_RECEIV_BIT) == S3C44B0X_rIIC_LAST_RECEIV_BIT ) |
||||
return -1; |
||||
|
||||
IICDS = addr; |
||||
IICCON = IICCON & ~(S3C44B0X_rIIC_INTPEND); |
||||
|
||||
/* wait and check ACK */ |
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
udelay(2000); |
||||
} |
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
temp = IICSTAT; |
||||
if ((temp & S3C44B0X_rIIC_LAST_RECEIV_BIT) == S3C44B0X_rIIC_LAST_RECEIV_BIT ) |
||||
return -1; |
||||
|
||||
/*
|
||||
now we can start with the read operation... |
||||
*/ |
||||
|
||||
IICDS = chip | 0x01; /* this is a read operation... */ |
||||
|
||||
rIICSTAT = 0x90; /*master recv*/ |
||||
rIICSTAT |= (1<<5); |
||||
IICSTAT = rIICSTAT; |
||||
|
||||
IICCON = IICCON & ~(S3C44B0X_rIIC_INTPEND); |
||||
|
||||
/* wait and check ACK */ |
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
udelay(2000); |
||||
} |
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
temp = IICSTAT; |
||||
if ((temp & S3C44B0X_rIIC_LAST_RECEIV_BIT) == S3C44B0X_rIIC_LAST_RECEIV_BIT ) |
||||
return -1; |
||||
|
||||
for (j=0; j<len-1; j++) { |
||||
|
||||
/*clear pending bit to resume */ |
||||
|
||||
temp = IICCON & ~(S3C44B0X_rIIC_INTPEND); |
||||
IICCON = temp; |
||||
|
||||
/* wait and check ACK */ |
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
udelay(2000); |
||||
} |
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
|
||||
buffer[j] = IICDS; /*save readed data*/ |
||||
|
||||
} /*end for(j)*/ |
||||
|
||||
/*
|
||||
reading the last data |
||||
unset ACK generation |
||||
*/ |
||||
temp = IICCON & ~(S3C44B0X_rIIC_INTPEND | (1<<7)); |
||||
IICCON = temp; |
||||
|
||||
/* wait but NOT check ACK */ |
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
udelay(2000); |
||||
} |
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
buffer[j] = IICDS; /*save readed data*/ |
||||
|
||||
rIICSTAT = 0x90; /*master recv*/ |
||||
|
||||
/* Write operation Terminate sending STOP */ |
||||
IICSTAT = rIICSTAT; |
||||
/*Clear Int Pending Bit to RESUME*/ |
||||
temp = IICCON; |
||||
IICCON = temp & (~S3C44B0X_rIIC_INTPEND); |
||||
|
||||
IICCON = IICCON | (1<<7); /*restore ACK generation*/ |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) |
||||
{ |
||||
int j, k; |
||||
u32 rIICSTAT, temp; |
||||
|
||||
|
||||
/*
|
||||
send the device offset |
||||
*/ |
||||
|
||||
rIICSTAT = 0xD0; |
||||
IICSTAT = rIICSTAT; |
||||
|
||||
IICDS = chip; /* this is a write operation... */ |
||||
|
||||
rIICSTAT |= (1<<5); |
||||
IICSTAT = rIICSTAT; |
||||
|
||||
IICCON = IICCON & ~(S3C44B0X_rIIC_INTPEND); |
||||
|
||||
/* wait and check ACK */ |
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
udelay(2000); |
||||
} |
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
temp = IICSTAT; |
||||
if ((temp & S3C44B0X_rIIC_LAST_RECEIV_BIT) == S3C44B0X_rIIC_LAST_RECEIV_BIT ) |
||||
return -1; |
||||
|
||||
IICDS = addr; |
||||
IICCON = IICCON & ~(S3C44B0X_rIIC_INTPEND); |
||||
|
||||
/* wait and check ACK */ |
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
udelay(2000); |
||||
} |
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
temp = IICSTAT; |
||||
if ((temp & S3C44B0X_rIIC_LAST_RECEIV_BIT) == S3C44B0X_rIIC_LAST_RECEIV_BIT ) |
||||
return -1; |
||||
|
||||
/*
|
||||
now we can start with the read write operation |
||||
*/ |
||||
for (j=0; j<len; j++) { |
||||
|
||||
IICDS = buffer[j]; /*prerare data to write*/ |
||||
|
||||
/*clear pending bit to resume*/ |
||||
|
||||
temp = IICCON & ~(S3C44B0X_rIIC_INTPEND); |
||||
IICCON = temp; |
||||
|
||||
/* wait but NOT check ACK */ |
||||
for(k=0; k<S3C44B0_IIC_TIMEOUT; k++) { |
||||
temp = IICCON; |
||||
if( (temp & S3C44B0X_rIIC_INTPEND) == S3C44B0X_rIIC_INTPEND) |
||||
break; |
||||
|
||||
udelay(2000); |
||||
} |
||||
|
||||
if (k==S3C44B0_IIC_TIMEOUT) |
||||
return -1; |
||||
|
||||
} /* end for(j) */ |
||||
|
||||
/* sending stop to terminate */ |
||||
rIICSTAT = 0xD0; /*master send*/ |
||||
IICSTAT = rIICSTAT; |
||||
/*Clear Int Pending Bit to RESUME*/ |
||||
temp = IICCON; |
||||
IICCON = temp & (~S3C44B0X_rIIC_INTPEND); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,102 @@ |
||||
/*
|
||||
* (C) Copyright 2004 |
||||
* DAVE Srl |
||||
* http://www.dave-tech.it
|
||||
* http://www.wawnet.biz
|
||||
* mailto:info@wawnet.biz |
||||
* |
||||
* See file CREDITS for list of people who contributed to this |
||||
* project. |
||||
* |
||||
* 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 program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
||||
* MA 02111-1307 USA |
||||
*/ |
||||
|
||||
/*
|
||||
* S3C44B0 CPU specific code |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <command.h> |
||||
#include <asm/hardware.h> |
||||
#include <rtc.h> |
||||
#include <bcd.h> |
||||
|
||||
int rtc_get (struct rtc_time* tm) |
||||
{ |
||||
RTCCON |= 1; |
||||
tm->tm_year = BCD2BIN(BCDYEAR); |
||||
tm->tm_mon = BCD2BIN(BCDMON); |
||||
tm->tm_wday = BCD2BIN(BCDDATE); |
||||
tm->tm_mday = BCD2BIN(BCDDAY); |
||||
tm->tm_hour = BCD2BIN(BCDHOUR); |
||||
tm->tm_min = BCD2BIN(BCDMIN); |
||||
tm->tm_sec = BCD2BIN(BCDSEC); |
||||
|
||||
if (tm->tm_sec==0) { |
||||
/* we have to re-read the rtc data because of the "one second deviation" problem */ |
||||
/* see RTC datasheet for more info about it */ |
||||
tm->tm_year = BCD2BIN(BCDYEAR); |
||||
tm->tm_mon = BCD2BIN(BCDMON); |
||||
tm->tm_mday = BCD2BIN(BCDDAY); |
||||
tm->tm_wday = BCD2BIN(BCDDATE); |
||||
tm->tm_hour = BCD2BIN(BCDHOUR); |
||||
tm->tm_min = BCD2BIN(BCDMIN); |
||||
tm->tm_sec = BCD2BIN(BCDSEC); |
||||
} |
||||
|
||||
RTCCON &= ~1; |
||||
|
||||
if(tm->tm_year >= 70) |
||||
tm->tm_year += 1900; |
||||
else |
||||
tm->tm_year += 2000; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int rtc_set (struct rtc_time* tm) |
||||
{ |
||||
if(tm->tm_year < 2000) |
||||
tm->tm_year -= 1900; |
||||
else |
||||
tm->tm_year -= 2000; |
||||
|
||||
RTCCON |= 1; |
||||
BCDYEAR = BIN2BCD(tm->tm_year); |
||||
BCDMON = BIN2BCD(tm->tm_mon); |
||||
BCDDAY = BIN2BCD(tm->tm_mday); |
||||
BCDDATE = BIN2BCD(tm->tm_wday); |
||||
BCDHOUR = BIN2BCD(tm->tm_hour); |
||||
BCDMIN = BIN2BCD(tm->tm_min); |
||||
BCDSEC = BIN2BCD(tm->tm_sec); |
||||
RTCCON &= 1; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
void rtc_reset (void) |
||||
{ |
||||
RTCCON |= 1; |
||||
BCDYEAR = 0; |
||||
BCDMON = 0; |
||||
BCDDAY = 0; |
||||
BCDDATE = 0; |
||||
BCDHOUR = 0; |
||||
BCDMIN = 0; |
||||
BCDSEC = 0; |
||||
RTCCON &= 1; |
||||
} |
||||
|
@ -0,0 +1,105 @@ |
||||
/*
|
||||
* (C) Copyright 2002-2004 |
||||
* Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
||||
* |
||||
* (C) Copyright 2002 |
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
||||
* Marius Groeger <mgroeger@sysgo.de> |
||||
* |
||||
* (C) Copyright 2002 |
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
||||
* Alex Zuepke <azu@sysgo.de> |
||||
* |
||||
* Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) |
||||
* |
||||
* 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 program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||||
* |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <asm/arch/hardware.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
void serial_setbrg (void) |
||||
{ |
||||
unsigned short divisor = 0; |
||||
|
||||
switch (gd->baudrate) { |
||||
case 1200: divisor = 3072; break; |
||||
case 9600: divisor = 384; break; |
||||
case 19200: divisor = 192; break; |
||||
case 38400: divisor = 96; break; |
||||
case 57600: divisor = 64; break; |
||||
case 115200: divisor = 32; break; |
||||
default: hang (); break; |
||||
} |
||||
|
||||
/* init serial UART0 */ |
||||
PUT8(U0LCR, 0); |
||||
PUT8(U0IER, 0); |
||||
PUT8(U0LCR, 0x80); /* DLAB=1 */ |
||||
PUT8(U0DLL, (unsigned char)(divisor & 0x00FF)); |
||||
PUT8(U0DLM, (unsigned char)(divisor >> 8)); |
||||
PUT8(U0LCR, 0x03); /* 8N1, DLAB=0 */ |
||||
PUT8(U0FCR, 1); /* Enable RX and TX FIFOs */ |
||||
} |
||||
|
||||
int serial_init (void) |
||||
{ |
||||
unsigned long pinsel0; |
||||
|
||||
serial_setbrg (); |
||||
|
||||
pinsel0 = GET32(PINSEL0); |
||||
pinsel0 &= ~(0x00000003); |
||||
pinsel0 |= 5; |
||||
PUT32(PINSEL0, pinsel0); |
||||
|
||||
return (0); |
||||
} |
||||
|
||||
void serial_putc (const char c) |
||||
{ |
||||
if (c == '\n') |
||||
{ |
||||
while((GET8(U0LSR) & (1<<5)) == 0); /* Wait for empty U0THR */ |
||||
PUT8(U0THR, '\r'); |
||||
} |
||||
|
||||
while((GET8(U0LSR) & (1<<5)) == 0); /* Wait for empty U0THR */ |
||||
PUT8(U0THR, c); |
||||
} |
||||
|
||||
int serial_getc (void) |
||||
{ |
||||
while((GET8(U0LSR) & 1) == 0); |
||||
return GET8(U0RBR); |
||||
} |
||||
|
||||
void |
||||
serial_puts (const char *s) |
||||
{ |
||||
while (*s) { |
||||
serial_putc (*s++); |
||||
} |
||||
} |
||||
|
||||
/* Test if there is a byte to read */ |
||||
int serial_tstc (void) |
||||
{ |
||||
return (GET8(U0LSR) & 1); |
||||
} |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue