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