1 /* credit winbond-840.c
6 void (*set_cs)(void *ee);
7 void (*clear_cs)(void *ee);
10 #define EEPOL_EEDI 0x01
11 #define EEPOL_EEDO 0x02
12 #define EEPOL_EECLK 0x04
13 #define EEPOL_EESEL 0x08
17 struct eeprom_ops *ops;
21 unsigned ee_addr_bits;
35 u8 eeprom_readb(struct eeprom *ee, unsigned address);
36 void eeprom_read(struct eeprom *ee, unsigned address, u8 *bytes,
38 void eeprom_writeb(struct eeprom *ee, unsigned address, u8 data);
39 void eeprom_write(struct eeprom *ee, unsigned address, u8 *bytes,
42 /* The EEPROM commands include the alway-set leading bit. */
44 EE_WriteCmd=(5 << 6), EE_ReadCmd=(6 << 6), EE_EraseCmd=(7 << 6),
47 void setup_ee_mem_bitbanger(struct eeprom *ee, long memaddr, int eesel_bit, int eeclk_bit, int eedo_bit, int eedi_bit, unsigned polarity)
50 ee->eesel = 1 << eesel_bit;
51 ee->eeclk = 1 << eeclk_bit;
52 ee->eedo = 1 << eedo_bit;
53 ee->eedi = 1 << eedi_bit;
55 ee->polarity = polarity;
57 *ee->cache = readl(ee->addr);
60 /* foo. put this in a .c file */
61 static inline void eeprom_update(struct eeprom *ee, u32 mask, int pol)
66 spin_lock_irqsave(ee->lock, flags);
74 //printk("update: %08x\n", data);
75 writel(data, ee->addr);
76 spin_unlock_irqrestore(ee->lock, flags);
79 void eeprom_clk_lo(struct eeprom *ee)
81 int pol = !!(ee->polarity & EEPOL_EECLK);
83 eeprom_update(ee, ee->eeclk, pol);
87 void eeprom_clk_hi(struct eeprom *ee)
89 int pol = !!(ee->polarity & EEPOL_EECLK);
91 eeprom_update(ee, ee->eeclk, !pol);
95 void eeprom_send_addr(struct eeprom *ee, unsigned address)
97 int pol = !!(ee->polarity & EEPOL_EEDI);
101 /* Shift the read command bits out. */
102 for (i=0; i<11; i++) {
103 eeprom_update(ee, ee->eedi, ((address >> 10) & 1) ^ pol);
108 eeprom_update(ee, ee->eedi, pol);
111 u16 eeprom_readw(struct eeprom *ee, unsigned address)
117 eeprom_update(ee, ee->eesel, 1 ^ !!(ee->polarity & EEPOL_EESEL));
118 eeprom_send_addr(ee, address);
120 for (i=0; i<16; i++) {
124 data = readl(ee->addr);
125 //printk("eeprom_readw: %08x\n", data);
126 res |= !!(data & ee->eedo) ^ !!(ee->polarity & EEPOL_EEDO);
129 eeprom_update(ee, ee->eesel, 0 ^ !!(ee->polarity & EEPOL_EESEL));
135 void eeprom_writeb(struct eeprom *ee, unsigned address, u8 data)