mini/seeprom.c

76 lines
1.4 KiB
C
Raw Normal View History

2009-04-03 16:27:19 +02:00
/*
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
SEEPROM support
2009-04-13 22:13:45 +02:00
Copyright (C) 2008, 2009 Sven Peter <svenpeter@gmail.com>
2009-04-03 16:27:19 +02:00
2009-05-11 07:53:16 +02:00
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
2009-04-03 16:27:19 +02:00
*/
2009-05-11 07:53:16 +02:00
2009-02-16 13:52:26 +01:00
#include "types.h"
#include "utils.h"
#include "hollywood.h"
#include "start.h"
2009-03-06 05:22:22 +01:00
#include "gpio.h"
2009-02-16 13:52:26 +01:00
2009-03-06 05:22:50 +01:00
#define eeprom_delay() udelay(5)
2009-02-16 13:52:26 +01:00
void send_bits(int b, int bits)
{
while(bits--)
{
if(b & (1 << bits))
2009-03-06 05:22:22 +01:00
set32(HW_GPIO1OUT, GP_EEP_MOSI);
2009-02-16 13:52:26 +01:00
else
2009-03-06 05:22:22 +01:00
clear32(HW_GPIO1OUT, GP_EEP_MOSI);
2009-03-06 05:22:50 +01:00
eeprom_delay();
2009-03-06 05:22:22 +01:00
set32(HW_GPIO1OUT, GP_EEP_CLK);
2009-03-06 05:22:50 +01:00
eeprom_delay();
2009-03-06 05:22:22 +01:00
clear32(HW_GPIO1OUT, GP_EEP_CLK);
2009-03-06 05:22:50 +01:00
eeprom_delay();
2009-02-16 13:52:26 +01:00
}
}
int recv_bits(int bits)
{
int res = 0;
while(bits--)
{
res <<= 1;
2009-03-06 05:22:22 +01:00
set32(HW_GPIO1OUT, GP_EEP_CLK);
2009-03-06 05:22:50 +01:00
eeprom_delay();
2009-03-06 05:22:22 +01:00
clear32(HW_GPIO1OUT, GP_EEP_CLK);
2009-03-06 05:22:50 +01:00
eeprom_delay();
2009-03-06 05:22:22 +01:00
res |= !!(read32(HW_GPIO1IN) & GP_EEP_MISO);
2009-02-16 13:52:26 +01:00
}
return res;
}
int seeprom_read(void *dst, int offset, int size)
{
int i;
u16 *ptr = (u16 *)dst;
u16 recv;
if(size & 1)
return -1;
2009-03-06 05:22:22 +01:00
clear32(HW_GPIO1OUT, GP_EEP_CLK);
clear32(HW_GPIO1OUT, GP_EEP_CS);
2009-03-06 05:22:50 +01:00
eeprom_delay();
2009-02-16 13:52:26 +01:00
for(i = 0; i < size; ++i)
{
2009-03-06 05:22:22 +01:00
set32(HW_GPIO1OUT, GP_EEP_CS);
2009-02-16 13:52:26 +01:00
send_bits((0x600 | (offset + i)), 11);
recv = recv_bits(16);
*ptr++ = recv;
2009-03-06 05:22:22 +01:00
clear32(HW_GPIO1OUT, GP_EEP_CS);
2009-03-06 05:22:50 +01:00
eeprom_delay();
2009-02-16 13:52:26 +01:00
}
return size;
}
2009-04-13 22:13:45 +02:00