1 /* credit winbond-840.c
5 void (*set_cs
)(void *ee
);
6 void (*clear_cs
)(void *ee
);
9 #define EEPOL_EEDI 0x01
10 #define EEPOL_EEDO 0x02
11 #define EEPOL_EECLK 0x04
12 #define EEPOL_EESEL 0x08
16 struct eeprom_ops
*ops
;
20 unsigned ee_addr_bits
;
34 u8
eeprom_readb(struct eeprom
*ee
, unsigned address
);
35 void eeprom_read(struct eeprom
*ee
, unsigned address
, u8
*bytes
,
37 void eeprom_writeb(struct eeprom
*ee
, unsigned address
, u8 data
);
38 void eeprom_write(struct eeprom
*ee
, unsigned address
, u8
*bytes
,
41 /* The EEPROM commands include the alway-set leading bit. */
43 EE_WriteCmd
=(5 << 6), EE_ReadCmd
=(6 << 6), EE_EraseCmd
=(7 << 6),
46 void setup_ee_mem_bitbanger(struct eeprom
*ee
, long memaddr
, int eesel_bit
, int eeclk_bit
, int eedo_bit
, int eedi_bit
, unsigned polarity
)
49 ee
->eesel
= 1 << eesel_bit
;
50 ee
->eeclk
= 1 << eeclk_bit
;
51 ee
->eedo
= 1 << eedo_bit
;
52 ee
->eedi
= 1 << eedi_bit
;
54 ee
->polarity
= polarity
;
56 *ee
->cache
= readl(ee
->addr
);
59 /* foo. put this in a .c file */
60 static inline void eeprom_update(struct eeprom
*ee
, u32 mask
, int pol
)
65 spin_lock_irqsave(ee
->lock
, flags
);
73 //printk("update: %08x\n", data);
74 writel(data
, ee
->addr
);
75 spin_unlock_irqrestore(ee
->lock
, flags
);
78 void eeprom_clk_lo(struct eeprom
*ee
)
80 int pol
= !!(ee
->polarity
& EEPOL_EECLK
);
82 eeprom_update(ee
, ee
->eeclk
, pol
);
86 void eeprom_clk_hi(struct eeprom
*ee
)
88 int pol
= !!(ee
->polarity
& EEPOL_EECLK
);
90 eeprom_update(ee
, ee
->eeclk
, !pol
);
94 void eeprom_send_addr(struct eeprom
*ee
, unsigned address
)
96 int pol
= !!(ee
->polarity
& EEPOL_EEDI
);
100 /* Shift the read command bits out. */
101 for (i
=0; i
<11; i
++) {
102 eeprom_update(ee
, ee
->eedi
, ((address
>> 10) & 1) ^ pol
);
107 eeprom_update(ee
, ee
->eedi
, pol
);
110 u16
eeprom_readw(struct eeprom
*ee
, unsigned address
)
116 eeprom_update(ee
, ee
->eesel
, 1 ^ !!(ee
->polarity
& EEPOL_EESEL
));
117 eeprom_send_addr(ee
, address
);
119 for (i
=0; i
<16; i
++) {
123 data
= readl(ee
->addr
);
124 //printk("eeprom_readw: %08x\n", data);
125 res
|= !!(data
& ee
->eedo
) ^ !!(ee
->polarity
& EEPOL_EEDO
);
128 eeprom_update(ee
, ee
->eesel
, 0 ^ !!(ee
->polarity
& EEPOL_EESEL
));
134 void eeprom_writeb(struct eeprom
*ee
, unsigned address
, u8 data
)