Lines Matching full:eeprom
2 * QEMU EEPROM 93xx emulation
28 * eeprom93xx_new - add a new EEPROM (with 16, 64 or 256 words)
29 * eeprom93xx_free - destroy EEPROM
30 * eeprom93xx_read - read data from the EEPROM
31 * eeprom93xx_write - write data to the EEPROM
32 * eeprom93xx_data - get EEPROM data array for external manipulation
35 * - No emulation of EEPROM timings.
43 /* Debug EEPROM emulation. */
47 #define logout(fmt, ...) fprintf(stderr, "EEPROM\t%-24s" fmt, __func__, ## __VA_ARGS__)
92 /* Code for saving and restoring of EEPROM state. */
131 .name = "eeprom",
155 void eeprom93xx_write(eeprom_t *eeprom, int eecs, int eesk, int eedi) in eeprom93xx_write() argument
157 uint8_t tick = eeprom->tick; in eeprom93xx_write()
158 uint8_t eedo = eeprom->eedo; in eeprom93xx_write()
159 uint16_t address = eeprom->address; in eeprom93xx_write()
160 uint8_t command = eeprom->command; in eeprom93xx_write()
165 if (!eeprom->eecs && eecs) { in eeprom93xx_write()
171 } else if (eeprom->eecs && !eecs) { in eeprom93xx_write()
173 if (eeprom->writable) { in eeprom93xx_write()
174 uint8_t subcommand = address >> (eeprom->addrbits - 2); in eeprom93xx_write()
177 for (address = 0; address < eeprom->size; address++) { in eeprom93xx_write()
178 eeprom->contents[address] = 0xffff; in eeprom93xx_write()
182 eeprom->contents[address] = 0xffff; in eeprom93xx_write()
183 } else if (tick >= 2 + 2 + eeprom->addrbits + 16) { in eeprom93xx_write()
186 eeprom->contents[address] &= eeprom->data; in eeprom93xx_write()
189 for (address = 0; address < eeprom->size; address++) { in eeprom93xx_write()
190 eeprom->contents[address] &= eeprom->data; in eeprom93xx_write()
197 } else if (eecs && !eeprom->eesk && eesk) { in eeprom93xx_write()
224 } else if (tick < 2 + 2 + eeprom->addrbits) { in eeprom93xx_write()
228 if (tick == 2 + 2 + eeprom->addrbits) { in eeprom93xx_write()
230 opstring[command], address, eeprom->contents[address]); in eeprom93xx_write()
234 address = address % eeprom->size; in eeprom93xx_write()
237 switch (address >> (eeprom->addrbits - 2)) { in eeprom93xx_write()
240 eeprom->writable = 0; in eeprom93xx_write()
250 eeprom->writable = 1; in eeprom93xx_write()
255 eeprom->data = eeprom->contents[address]; in eeprom93xx_write()
258 } else if (tick < 2 + 2 + eeprom->addrbits + 16) { in eeprom93xx_write()
263 eedo = ((eeprom->data & 0x8000) != 0); in eeprom93xx_write()
265 eeprom->data <<= 1; in eeprom93xx_write()
266 eeprom->data += eedi; in eeprom93xx_write()
271 /* Save status of EEPROM. */ in eeprom93xx_write()
272 eeprom->tick = tick; in eeprom93xx_write()
273 eeprom->eecs = eecs; in eeprom93xx_write()
274 eeprom->eesk = eesk; in eeprom93xx_write()
275 eeprom->eedo = eedo; in eeprom93xx_write()
276 eeprom->address = address; in eeprom93xx_write()
277 eeprom->command = command; in eeprom93xx_write()
280 uint16_t eeprom93xx_read(eeprom_t *eeprom) in eeprom93xx_read() argument
283 logout("CS=%u DO=%u\n", eeprom->eecs, eeprom->eedo); in eeprom93xx_read()
284 return eeprom->eedo; in eeprom93xx_read()
288 void eeprom93xx_reset(eeprom_t *eeprom)
290 /* prepare eeprom */
291 logout("eeprom = 0x%p\n", eeprom);
292 eeprom->tick = 0;
293 eeprom->command = 0;
299 /* Add a new EEPROM (with 16, 64 or 256 words). */ in eeprom93xx_new()
300 eeprom_t *eeprom; in eeprom93xx_new() local
313 assert(!"Unsupported EEPROM size, fallback to 64 words!"); in eeprom93xx_new()
318 eeprom = g_malloc0(sizeof(*eeprom) + nwords * 2); in eeprom93xx_new()
319 eeprom->size = nwords; in eeprom93xx_new()
320 eeprom->addrbits = addrbits; in eeprom93xx_new()
322 eeprom->eedo = 1; in eeprom93xx_new()
323 logout("eeprom = 0x%p, nwords = %u\n", eeprom, nwords); in eeprom93xx_new()
324 vmstate_register_any(VMSTATE_IF(dev), &vmstate_eeprom, eeprom); in eeprom93xx_new()
325 return eeprom; in eeprom93xx_new()
328 void eeprom93xx_free(DeviceState *dev, eeprom_t *eeprom) in eeprom93xx_free() argument
330 /* Destroy EEPROM. */ in eeprom93xx_free()
331 logout("eeprom = 0x%p\n", eeprom); in eeprom93xx_free()
332 vmstate_unregister(VMSTATE_IF(dev), &vmstate_eeprom, eeprom); in eeprom93xx_free()
333 g_free(eeprom); in eeprom93xx_free()
336 uint16_t *eeprom93xx_data(eeprom_t *eeprom) in eeprom93xx_data() argument
338 /* Get EEPROM data array. */ in eeprom93xx_data()
339 return &eeprom->contents[0]; in eeprom93xx_data()