1
2
3
4
5
6#include <linux/module.h>
7
8#include <asm/sgi/hpc3.h>
9#include <asm/sgi/ip22.h>
10
11
12#define EEPROM_READ 0xc000
13#define EEPROM_WEN 0x9800
14#define EEPROM_WRITE 0xa000
15#define EEPROM_WRALL 0x8800
16#define EEPROM_WDS 0x8000
17#define EEPROM_PRREAD 0xc000
18#define EEPROM_PREN 0x9800
19#define EEPROM_PRCLEAR 0xffff
20#define EEPROM_PRWRITE 0xa000
21#define EEPROM_PRDS 0x8000
22
23#define EEPROM_EPROT 0x01
24#define EEPROM_CSEL 0x02
25#define EEPROM_ECLK 0x04
26#define EEPROM_DATO 0x08
27#define EEPROM_DATI 0x10
28
29
30#define delay() ({ \
31 int x; \
32 for (x=0; x<100000; x++) __asm__ __volatile__(""); })
33
34#define eeprom_cs_on(ptr) ({ \
35 __raw_writel(__raw_readl(ptr) & ~EEPROM_DATO, ptr); \
36 __raw_writel(__raw_readl(ptr) & ~EEPROM_ECLK, ptr); \
37 __raw_writel(__raw_readl(ptr) & ~EEPROM_EPROT, ptr); \
38 delay(); \
39 __raw_writel(__raw_readl(ptr) | EEPROM_CSEL, ptr); \
40 __raw_writel(__raw_readl(ptr) | EEPROM_ECLK, ptr); })
41
42
43#define eeprom_cs_off(ptr) ({ \
44 __raw_writel(__raw_readl(ptr) & ~EEPROM_ECLK, ptr); \
45 __raw_writel(__raw_readl(ptr) & ~EEPROM_CSEL, ptr); \
46 __raw_writel(__raw_readl(ptr) | EEPROM_EPROT, ptr); \
47 __raw_writel(__raw_readl(ptr) | EEPROM_ECLK, ptr); })
48
49#define BITS_IN_COMMAND 11
50
51
52
53
54
55static inline void eeprom_cmd(unsigned int *ctrl, unsigned cmd, unsigned reg)
56{
57 unsigned short ser_cmd;
58 int i;
59
60 ser_cmd = cmd | (reg << (16 - BITS_IN_COMMAND));
61 for (i = 0; i < BITS_IN_COMMAND; i++) {
62 if (ser_cmd & (1<<15))
63 __raw_writel(__raw_readl(ctrl) | EEPROM_DATO, ctrl);
64 else
65 __raw_writel(__raw_readl(ctrl) & ~EEPROM_DATO, ctrl);
66 __raw_writel(__raw_readl(ctrl) & ~EEPROM_ECLK, ctrl);
67 delay();
68 __raw_writel(__raw_readl(ctrl) | EEPROM_ECLK, ctrl);
69 delay();
70 ser_cmd <<= 1;
71 }
72
73 __raw_writel(__raw_readl(ctrl) & ~EEPROM_DATO, ctrl);
74}
75
76unsigned short ip22_eeprom_read(unsigned int *ctrl, int reg)
77{
78 unsigned short res = 0;
79 int i;
80
81 __raw_writel(__raw_readl(ctrl) & ~EEPROM_EPROT, ctrl);
82 eeprom_cs_on(ctrl);
83 eeprom_cmd(ctrl, EEPROM_READ, reg);
84
85
86 for (i = 0; i < 16; i++) {
87 __raw_writel(__raw_readl(ctrl) & ~EEPROM_ECLK, ctrl);
88 delay();
89 __raw_writel(__raw_readl(ctrl) | EEPROM_ECLK, ctrl);
90 delay();
91 res <<= 1;
92 if (__raw_readl(ctrl) & EEPROM_DATI)
93 res |= 1;
94 }
95
96 eeprom_cs_off(ctrl);
97
98 return res;
99}
100
101EXPORT_SYMBOL(ip22_eeprom_read);
102
103
104
105
106unsigned short ip22_nvram_read(int reg)
107{
108 if (ip22_is_fullhouse())
109
110
111 return ip22_eeprom_read(&hpc3c0->eeprom, reg);
112 else {
113 unsigned short tmp;
114
115 reg <<= 1;
116 tmp = hpc3c0->bbram[reg++] & 0xff;
117 return (tmp << 8) | (hpc3c0->bbram[reg] & 0xff);
118 }
119}
120
121EXPORT_SYMBOL(ip22_nvram_read);
122