-
Notifications
You must be signed in to change notification settings - Fork 6
/
seeprom.c
75 lines (63 loc) · 1.36 KB
/
seeprom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
SEEPROM support
Copyright (C) 2008, 2009 Sven Peter <[email protected]>
# 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
*/
#include "types.h"
#include "utils.h"
#include "hollywood.h"
#include "start.h"
#include "gpio.h"
#define eeprom_delay() udelay(5)
void send_bits(int b, int bits)
{
while(bits--)
{
if(b & (1 << bits))
set32(HW_GPIO1OUT, GP_EEP_MOSI);
else
clear32(HW_GPIO1OUT, GP_EEP_MOSI);
eeprom_delay();
set32(HW_GPIO1OUT, GP_EEP_CLK);
eeprom_delay();
clear32(HW_GPIO1OUT, GP_EEP_CLK);
eeprom_delay();
}
}
int recv_bits(int bits)
{
int res = 0;
while(bits--)
{
res <<= 1;
set32(HW_GPIO1OUT, GP_EEP_CLK);
eeprom_delay();
clear32(HW_GPIO1OUT, GP_EEP_CLK);
eeprom_delay();
res |= !!(read32(HW_GPIO1IN) & GP_EEP_MISO);
}
return res;
}
int seeprom_read(void *dst, int offset, int size)
{
int i;
u16 *ptr = (u16 *)dst;
u16 recv;
if(size & 1)
return -1;
clear32(HW_GPIO1OUT, GP_EEP_CLK);
clear32(HW_GPIO1OUT, GP_EEP_CS);
eeprom_delay();
for(i = 0; i < size; ++i)
{
set32(HW_GPIO1OUT, GP_EEP_CS);
send_bits((0x600 | (offset + i)), 11);
recv = recv_bits(16);
*ptr++ = recv;
clear32(HW_GPIO1OUT, GP_EEP_CS);
eeprom_delay();
}
return size;
}