2008-06-27 23:24:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Dave Chapman
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2008-06-27 23:24:34 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-10-04 15:02:40 +00:00
|
|
|
#include "config.h"
|
2008-11-11 14:11:49 +00:00
|
|
|
#include "ata_idle_notify.h"
|
2008-06-27 23:24:34 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include "thread.h"
|
|
|
|
#include "disk.h"
|
2009-10-04 15:02:40 +00:00
|
|
|
#include "storage.h"
|
2008-06-27 23:24:34 +00:00
|
|
|
#include "panic.h"
|
|
|
|
#include "usb.h"
|
2009-10-04 15:02:40 +00:00
|
|
|
#include "ftl-target.h"
|
2009-10-11 10:10:49 +00:00
|
|
|
#include "nand-target.h"
|
2008-06-27 23:24:34 +00:00
|
|
|
|
|
|
|
/* for compatibility */
|
|
|
|
long last_disk_activity = -1;
|
|
|
|
|
|
|
|
/** static, private data **/
|
|
|
|
static bool initialized = false;
|
|
|
|
|
2009-10-11 12:45:27 +00:00
|
|
|
static long nand_stack[20];
|
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
/* API Functions */
|
|
|
|
|
2009-07-17 22:28:49 +00:00
|
|
|
int nand_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
|
2008-06-27 23:24:34 +00:00
|
|
|
void* inbuf)
|
|
|
|
{
|
2009-10-11 12:45:27 +00:00
|
|
|
int rc = ftl_read(start, incount, inbuf);
|
|
|
|
last_disk_activity = current_tick;
|
|
|
|
return rc;
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:28:49 +00:00
|
|
|
int nand_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
|
2008-06-27 23:24:34 +00:00
|
|
|
const void* outbuf)
|
|
|
|
{
|
2009-10-11 12:45:27 +00:00
|
|
|
int rc = ftl_write(start, count, outbuf);
|
|
|
|
last_disk_activity = current_tick;
|
|
|
|
return rc;
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 16:34:34 +00:00
|
|
|
void nand_spindown(int seconds)
|
|
|
|
{
|
|
|
|
(void)seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nand_sleep(void)
|
|
|
|
{
|
2009-10-11 10:10:49 +00:00
|
|
|
nand_power_down();
|
2009-07-17 16:34:34 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 20:36:09 +00:00
|
|
|
void nand_sleepnow(void)
|
|
|
|
{
|
2009-10-11 10:10:49 +00:00
|
|
|
nand_power_down();
|
2009-10-09 20:36:09 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 16:34:34 +00:00
|
|
|
void nand_spin(void)
|
|
|
|
{
|
2009-10-11 12:45:27 +00:00
|
|
|
last_disk_activity = current_tick;
|
2009-10-11 10:10:49 +00:00
|
|
|
nand_power_up();
|
2009-07-17 16:34:34 +00:00
|
|
|
}
|
|
|
|
|
2008-11-04 19:36:17 +00:00
|
|
|
void nand_enable(bool on)
|
2008-06-27 23:24:34 +00:00
|
|
|
{
|
2009-07-12 19:36:27 +00:00
|
|
|
(void)on;
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:28:49 +00:00
|
|
|
void nand_get_info(IF_MD2(int drive,) struct storage_info *info)
|
2009-07-12 19:36:27 +00:00
|
|
|
{
|
2009-10-17 23:00:49 +00:00
|
|
|
uint32_t ppb = ftl_banks * (*ftl_nand_type).pagesperblock;
|
2009-10-23 23:50:32 +00:00
|
|
|
(*info).sector_size = SECTOR_SIZE;
|
|
|
|
(*info).num_sectors = (*ftl_nand_type).userblocks * ppb;
|
|
|
|
(*info).vendor = "Apple";
|
|
|
|
(*info).product = "iPod Nano 2G";
|
2009-10-17 23:00:49 +00:00
|
|
|
(*info).revision = "1.0";
|
2009-07-12 19:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long nand_last_disk_activity(void)
|
|
|
|
{
|
2009-10-11 12:45:27 +00:00
|
|
|
return last_disk_activity;
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 20:36:09 +00:00
|
|
|
#ifdef HAVE_STORAGE_FLUSH
|
|
|
|
int nand_flush(void)
|
|
|
|
{
|
2009-10-11 12:45:27 +00:00
|
|
|
last_disk_activity = current_tick;
|
2009-10-12 08:54:51 +00:00
|
|
|
int rc = ftl_sync();
|
|
|
|
if (rc != 0) panicf("Failed to unmount flash: %X", rc);
|
|
|
|
return rc;
|
2009-10-09 20:36:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-11 12:45:27 +00:00
|
|
|
static void nand_thread(void)
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (TIME_AFTER(current_tick, last_disk_activity + HZ / 5))
|
|
|
|
nand_power_down();
|
|
|
|
sleep(HZ / 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 19:36:17 +00:00
|
|
|
int nand_init(void)
|
2008-06-27 23:24:34 +00:00
|
|
|
{
|
2009-10-04 15:02:40 +00:00
|
|
|
if (ftl_init()) return 1;
|
|
|
|
|
2009-10-11 12:45:27 +00:00
|
|
|
last_disk_activity = current_tick;
|
|
|
|
|
|
|
|
create_thread(nand_thread, nand_stack,
|
|
|
|
sizeof(nand_stack), 0, "nand"
|
|
|
|
IF_PRIO(, PRIORITY_USER_INTERFACE)
|
|
|
|
IF_COP(, CPU));
|
|
|
|
|
2009-07-12 19:36:27 +00:00
|
|
|
initialized = true;
|
|
|
|
return 0;
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
2009-07-12 19:36:27 +00:00
|
|
|
|
2009-07-17 22:28:49 +00:00
|
|
|
#ifdef CONFIG_STORAGE_MULTI
|
|
|
|
int nand_num_drives(int first_drive)
|
|
|
|
{
|
|
|
|
/* We don't care which logical drive number(s) we have been assigned */
|
|
|
|
(void)first_drive;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|