/* This file is part of the program psim.
|
/* This file is part of the program psim.
|
|
|
Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
|
Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
*/
|
*/
|
|
|
|
|
#ifndef _HW_EEPROM_C_
|
#ifndef _HW_EEPROM_C_
|
#define _HW_EEPROM_C_
|
#define _HW_EEPROM_C_
|
|
|
#include "device_table.h"
|
#include "device_table.h"
|
|
|
#ifdef HAVE_STRING_H
|
#ifdef HAVE_STRING_H
|
#include <string.h>
|
#include <string.h>
|
#else
|
#else
|
#ifdef HAVE_STRINGS_H
|
#ifdef HAVE_STRINGS_H
|
#include <strings.h>
|
#include <strings.h>
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
|
|
/* DEVICE
|
/* DEVICE
|
|
|
|
|
eeprom - JEDEC? compatible electricaly erasable programable device
|
eeprom - JEDEC? compatible electricaly erasable programable device
|
|
|
|
|
DESCRIPTION
|
DESCRIPTION
|
|
|
|
|
This device implements a small byte addressable EEPROM.
|
This device implements a small byte addressable EEPROM.
|
Programming is performed using the same write sequences as used by
|
Programming is performed using the same write sequences as used by
|
standard modern EEPROM components. Writes occure in real time, the
|
standard modern EEPROM components. Writes occure in real time, the
|
device returning a progress value until the programing has been
|
device returning a progress value until the programing has been
|
completed.
|
completed.
|
|
|
It is based on the AMD 29F040 component.
|
It is based on the AMD 29F040 component.
|
|
|
|
|
PROPERTIES
|
PROPERTIES
|
|
|
|
|
reg = <address> <size> (required)
|
reg = <address> <size> (required)
|
|
|
Determine where the device lives in the parents address space.
|
Determine where the device lives in the parents address space.
|
|
|
|
|
nr-sectors = <integer> (required)
|
nr-sectors = <integer> (required)
|
|
|
When erasing an entire sector is cleared at a time. This specifies
|
When erasing an entire sector is cleared at a time. This specifies
|
the number of sectors in the EEPROM component.
|
the number of sectors in the EEPROM component.
|
|
|
|
|
sector-size = <integer> (required)
|
sector-size = <integer> (required)
|
|
|
The number of bytes in a sector. When erasing, memory chunks of
|
The number of bytes in a sector. When erasing, memory chunks of
|
this size are cleared.
|
this size are cleared.
|
|
|
NOTE: The product nr-sectors * sector-size does not need to map the
|
NOTE: The product nr-sectors * sector-size does not need to map the
|
size specified in the reg property. If the specified size is
|
size specified in the reg property. If the specified size is
|
smaller part of the eeprom will not be accessible while if it is
|
smaller part of the eeprom will not be accessible while if it is
|
larger the addresses will wrap.
|
larger the addresses will wrap.
|
|
|
|
|
byte-write-delay = <integer> (required)
|
byte-write-delay = <integer> (required)
|
|
|
Number of clock ticks before the programming of a single byte
|
Number of clock ticks before the programming of a single byte
|
completes.
|
completes.
|
|
|
|
|
sector-start-delay = <integer> (required)
|
sector-start-delay = <integer> (required)
|
|
|
When erasing sectors, the number of clock ticks after the sector
|
When erasing sectors, the number of clock ticks after the sector
|
has been specified that the actual erase process commences.
|
has been specified that the actual erase process commences.
|
|
|
|
|
erase-delay = <intger> (required)
|
erase-delay = <intger> (required)
|
|
|
Number of clock ticks before an erase program completes
|
Number of clock ticks before an erase program completes
|
|
|
|
|
manufacture-code = <integer> (required)
|
manufacture-code = <integer> (required)
|
|
|
The one byte value returned when the auto-select manufacturer code
|
The one byte value returned when the auto-select manufacturer code
|
is read.
|
is read.
|
|
|
|
|
device-code = <integer> (required)
|
device-code = <integer> (required)
|
|
|
The one byte value returned when the auto-select device code is
|
The one byte value returned when the auto-select device code is
|
read.
|
read.
|
|
|
|
|
input-file = <file-name> (optional)
|
input-file = <file-name> (optional)
|
|
|
Initialize the eeprom using the specified binary file.
|
Initialize the eeprom using the specified binary file.
|
|
|
|
|
output-file = <file-name> (optional)
|
output-file = <file-name> (optional)
|
|
|
When ever the eeprom is updated, save the modified image into the
|
When ever the eeprom is updated, save the modified image into the
|
specified file.
|
specified file.
|
|
|
|
|
EXAMPLES
|
EXAMPLES
|
|
|
|
|
Enable tracing of the eeprom:
|
Enable tracing of the eeprom:
|
|
|
| bash$ psim -t eeprom-device \
|
| bash$ psim -t eeprom-device \
|
|
|
|
|
Configure something very like the Amd Am29F040 - 512byte EEPROM
|
Configure something very like the Amd Am29F040 - 512byte EEPROM
|
(but a bit faster):
|
(but a bit faster):
|
|
|
| -o '/eeprom@0xfff00000/reg 0xfff00000 0x80000' \
|
| -o '/eeprom@0xfff00000/reg 0xfff00000 0x80000' \
|
| -o '/eeprom@0xfff00000/nr-sectors 8' \
|
| -o '/eeprom@0xfff00000/nr-sectors 8' \
|
| -o '/eeprom@0xfff00000/sector-size 0x10000' \
|
| -o '/eeprom@0xfff00000/sector-size 0x10000' \
|
| -o '/eeprom@0xfff00000/byte-write-delay 1000' \
|
| -o '/eeprom@0xfff00000/byte-write-delay 1000' \
|
| -o '/eeprom@0xfff00000/sector-start-delay 100' \
|
| -o '/eeprom@0xfff00000/sector-start-delay 100' \
|
| -o '/eeprom@0xfff00000/erase-delay 1000' \
|
| -o '/eeprom@0xfff00000/erase-delay 1000' \
|
| -o '/eeprom@0xfff00000/manufacture-code 0x01' \
|
| -o '/eeprom@0xfff00000/manufacture-code 0x01' \
|
| -o '/eeprom@0xfff00000/device-code 0xa4' \
|
| -o '/eeprom@0xfff00000/device-code 0xa4' \
|
|
|
|
|
Initialize the eeprom from the file <</dev/zero>>:
|
Initialize the eeprom from the file <</dev/zero>>:
|
|
|
| -o '/eeprom@0xfff00000/input-file /dev/zero'
|
| -o '/eeprom@0xfff00000/input-file /dev/zero'
|
|
|
|
|
BUGS
|
BUGS
|
|
|
|
|
*/
|
*/
|
|
|
typedef enum {
|
typedef enum {
|
read_reset,
|
read_reset,
|
write_nr_2,
|
write_nr_2,
|
write_nr_3,
|
write_nr_3,
|
write_nr_4,
|
write_nr_4,
|
write_nr_5,
|
write_nr_5,
|
write_nr_6,
|
write_nr_6,
|
byte_program,
|
byte_program,
|
byte_programming,
|
byte_programming,
|
chip_erase,
|
chip_erase,
|
sector_erase,
|
sector_erase,
|
sector_erase_suspend,
|
sector_erase_suspend,
|
autoselect,
|
autoselect,
|
} hw_eeprom_states;
|
} hw_eeprom_states;
|
|
|
static const char *
|
static const char *
|
state2a(hw_eeprom_states state)
|
state2a(hw_eeprom_states state)
|
{
|
{
|
switch (state) {
|
switch (state) {
|
case read_reset: return "read_reset";
|
case read_reset: return "read_reset";
|
case write_nr_2: return "write_nr_2";
|
case write_nr_2: return "write_nr_2";
|
case write_nr_3: return "write_nr_3";
|
case write_nr_3: return "write_nr_3";
|
case write_nr_4: return "write_nr_4";
|
case write_nr_4: return "write_nr_4";
|
case write_nr_5: return "write_nr_5";
|
case write_nr_5: return "write_nr_5";
|
case write_nr_6: return "write_nr_6";
|
case write_nr_6: return "write_nr_6";
|
case byte_program: return "byte_program";
|
case byte_program: return "byte_program";
|
case byte_programming: return "byte_programming";
|
case byte_programming: return "byte_programming";
|
case chip_erase: return "chip_erase";
|
case chip_erase: return "chip_erase";
|
case sector_erase: return "sector_erase";
|
case sector_erase: return "sector_erase";
|
case sector_erase_suspend: return "sector_erase_suspend";
|
case sector_erase_suspend: return "sector_erase_suspend";
|
case autoselect: return "autoselect";
|
case autoselect: return "autoselect";
|
}
|
}
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
typedef struct _hw_eeprom_device {
|
typedef struct _hw_eeprom_device {
|
/* general */
|
/* general */
|
hw_eeprom_states state;
|
hw_eeprom_states state;
|
unsigned8 *memory;
|
unsigned8 *memory;
|
unsigned sizeof_memory;
|
unsigned sizeof_memory;
|
unsigned erase_delay;
|
unsigned erase_delay;
|
signed64 program_start_time;
|
signed64 program_start_time;
|
signed64 program_finish_time;
|
signed64 program_finish_time;
|
unsigned8 manufacture_code;
|
unsigned8 manufacture_code;
|
unsigned8 device_code;
|
unsigned8 device_code;
|
unsigned8 toggle_bit;
|
unsigned8 toggle_bit;
|
/* initialization */
|
/* initialization */
|
const char *input_file_name;
|
const char *input_file_name;
|
const char *output_file_name;
|
const char *output_file_name;
|
/* for sector and sector programming */
|
/* for sector and sector programming */
|
hw_eeprom_states sector_state;
|
hw_eeprom_states sector_state;
|
unsigned8 *sectors;
|
unsigned8 *sectors;
|
unsigned nr_sectors;
|
unsigned nr_sectors;
|
unsigned sizeof_sector;
|
unsigned sizeof_sector;
|
unsigned sector_start_delay;
|
unsigned sector_start_delay;
|
unsigned sector_start_time;
|
unsigned sector_start_time;
|
/* byte and byte programming */
|
/* byte and byte programming */
|
unsigned byte_write_delay;
|
unsigned byte_write_delay;
|
unsigned_word byte_program_address;
|
unsigned_word byte_program_address;
|
unsigned8 byte_program_byte;
|
unsigned8 byte_program_byte;
|
} hw_eeprom_device;
|
} hw_eeprom_device;
|
|
|
typedef struct _hw_eeprom_reg_spec {
|
typedef struct _hw_eeprom_reg_spec {
|
unsigned32 base;
|
unsigned32 base;
|
unsigned32 size;
|
unsigned32 size;
|
} hw_eeprom_reg_spec;
|
} hw_eeprom_reg_spec;
|
|
|
static void
|
static void
|
hw_eeprom_init_data(device *me)
|
hw_eeprom_init_data(device *me)
|
{
|
{
|
hw_eeprom_device *eeprom = (hw_eeprom_device*)device_data(me);
|
hw_eeprom_device *eeprom = (hw_eeprom_device*)device_data(me);
|
|
|
/* have we any input or output files */
|
/* have we any input or output files */
|
if (device_find_property(me, "input-file") != NULL)
|
if (device_find_property(me, "input-file") != NULL)
|
eeprom->input_file_name = device_find_string_property(me, "input-file");
|
eeprom->input_file_name = device_find_string_property(me, "input-file");
|
if (device_find_property(me, "output-file") != NULL)
|
if (device_find_property(me, "output-file") != NULL)
|
eeprom->input_file_name = device_find_string_property(me, "output-file");
|
eeprom->input_file_name = device_find_string_property(me, "output-file");
|
|
|
/* figure out the sectors in the eeprom */
|
/* figure out the sectors in the eeprom */
|
if (eeprom->sectors == NULL) {
|
if (eeprom->sectors == NULL) {
|
eeprom->nr_sectors = device_find_integer_property(me, "nr-sectors");
|
eeprom->nr_sectors = device_find_integer_property(me, "nr-sectors");
|
eeprom->sizeof_sector = device_find_integer_property(me, "sector-size");
|
eeprom->sizeof_sector = device_find_integer_property(me, "sector-size");
|
eeprom->sectors = zalloc(eeprom->nr_sectors);
|
eeprom->sectors = zalloc(eeprom->nr_sectors);
|
}
|
}
|
else
|
else
|
memset(eeprom->sectors, 0, eeprom->nr_sectors);
|
memset(eeprom->sectors, 0, eeprom->nr_sectors);
|
|
|
/* initialize the eeprom */
|
/* initialize the eeprom */
|
if (eeprom->memory == NULL) {
|
if (eeprom->memory == NULL) {
|
eeprom->sizeof_memory = eeprom->sizeof_sector * eeprom->nr_sectors;
|
eeprom->sizeof_memory = eeprom->sizeof_sector * eeprom->nr_sectors;
|
eeprom->memory = zalloc(eeprom->sizeof_memory);
|
eeprom->memory = zalloc(eeprom->sizeof_memory);
|
}
|
}
|
else
|
else
|
memset(eeprom->memory, 0, eeprom->sizeof_memory);
|
memset(eeprom->memory, 0, eeprom->sizeof_memory);
|
if (eeprom->input_file_name != NULL) {
|
if (eeprom->input_file_name != NULL) {
|
int i;
|
int i;
|
FILE *input_file = fopen(eeprom->input_file_name, "r");
|
FILE *input_file = fopen(eeprom->input_file_name, "r");
|
if (input_file == NULL) {
|
if (input_file == NULL) {
|
perror("eeprom");
|
perror("eeprom");
|
device_error(me, "Failed to open input file %s\n", eeprom->input_file_name);
|
device_error(me, "Failed to open input file %s\n", eeprom->input_file_name);
|
}
|
}
|
for (i = 0; i < eeprom->sizeof_memory; i++) {
|
for (i = 0; i < eeprom->sizeof_memory; i++) {
|
if (fread(&eeprom->memory[i], 1, 1, input_file) != 1)
|
if (fread(&eeprom->memory[i], 1, 1, input_file) != 1)
|
break;
|
break;
|
}
|
}
|
fclose(input_file);
|
fclose(input_file);
|
}
|
}
|
|
|
/* timing */
|
/* timing */
|
eeprom->byte_write_delay = device_find_integer_property(me, "byte-write-delay");
|
eeprom->byte_write_delay = device_find_integer_property(me, "byte-write-delay");
|
eeprom->sector_start_delay = device_find_integer_property(me, "sector-start-delay");
|
eeprom->sector_start_delay = device_find_integer_property(me, "sector-start-delay");
|
eeprom->erase_delay = device_find_integer_property(me, "erase-delay");
|
eeprom->erase_delay = device_find_integer_property(me, "erase-delay");
|
|
|
/* misc */
|
/* misc */
|
eeprom->manufacture_code = device_find_integer_property(me, "manufacture-code");
|
eeprom->manufacture_code = device_find_integer_property(me, "manufacture-code");
|
eeprom->device_code = device_find_integer_property(me, "device-code");
|
eeprom->device_code = device_find_integer_property(me, "device-code");
|
}
|
}
|
|
|
|
|
static void
|
static void
|
invalid_read(device *me,
|
invalid_read(device *me,
|
hw_eeprom_states state,
|
hw_eeprom_states state,
|
unsigned_word address,
|
unsigned_word address,
|
const char *reason)
|
const char *reason)
|
{
|
{
|
DTRACE(eeprom, ("Invalid read to 0x%lx while in state %s (%s)\n",
|
DTRACE(eeprom, ("Invalid read to 0x%lx while in state %s (%s)\n",
|
(unsigned long)address,
|
(unsigned long)address,
|
state2a(state),
|
state2a(state),
|
reason));
|
reason));
|
}
|
}
|
|
|
static void
|
static void
|
invalid_write(device *me,
|
invalid_write(device *me,
|
hw_eeprom_states state,
|
hw_eeprom_states state,
|
unsigned_word address,
|
unsigned_word address,
|
unsigned8 data,
|
unsigned8 data,
|
const char *reason)
|
const char *reason)
|
{
|
{
|
DTRACE(eeprom, ("Invalid write of 0x%lx to 0x%lx while in state %s (%s)\n",
|
DTRACE(eeprom, ("Invalid write of 0x%lx to 0x%lx while in state %s (%s)\n",
|
(unsigned long)data,
|
(unsigned long)data,
|
(unsigned long)address,
|
(unsigned long)address,
|
state2a(state),
|
state2a(state),
|
reason));
|
reason));
|
}
|
}
|
|
|
static void
|
static void
|
dump_eeprom(device *me,
|
dump_eeprom(device *me,
|
hw_eeprom_device *eeprom)
|
hw_eeprom_device *eeprom)
|
{
|
{
|
if (eeprom->output_file_name != NULL) {
|
if (eeprom->output_file_name != NULL) {
|
int i;
|
int i;
|
FILE *output_file = fopen(eeprom->output_file_name, "w");
|
FILE *output_file = fopen(eeprom->output_file_name, "w");
|
if (output_file == NULL) {
|
if (output_file == NULL) {
|
perror("eeprom");
|
perror("eeprom");
|
device_error(me, "Failed to open output file %s\n",
|
device_error(me, "Failed to open output file %s\n",
|
eeprom->output_file_name);
|
eeprom->output_file_name);
|
}
|
}
|
for (i = 0; i < eeprom->sizeof_memory; i++) {
|
for (i = 0; i < eeprom->sizeof_memory; i++) {
|
if (fwrite(&eeprom->memory[i], 1, 1, output_file) != 1)
|
if (fwrite(&eeprom->memory[i], 1, 1, output_file) != 1)
|
break;
|
break;
|
}
|
}
|
fclose(output_file);
|
fclose(output_file);
|
}
|
}
|
}
|
}
|
|
|
|
|
/* program a single byte of eeprom */
|
/* program a single byte of eeprom */
|
|
|
static void
|
static void
|
start_programming_byte(device *me,
|
start_programming_byte(device *me,
|
hw_eeprom_device *eeprom,
|
hw_eeprom_device *eeprom,
|
unsigned_word address,
|
unsigned_word address,
|
unsigned8 new_byte)
|
unsigned8 new_byte)
|
{
|
{
|
unsigned8 old_byte = eeprom->memory[address];
|
unsigned8 old_byte = eeprom->memory[address];
|
DTRACE(eeprom, ("start-programing-byte - address 0x%lx, new 0x%lx, old 0x%lx\n",
|
DTRACE(eeprom, ("start-programing-byte - address 0x%lx, new 0x%lx, old 0x%lx\n",
|
(unsigned long)address,
|
(unsigned long)address,
|
(unsigned long)new_byte,
|
(unsigned long)new_byte,
|
(unsigned long)old_byte));
|
(unsigned long)old_byte));
|
eeprom->byte_program_address = address;
|
eeprom->byte_program_address = address;
|
/* : old new : ~old : new&~old
|
/* : old new : ~old : new&~old
|
: 0 0 : 1 : 0
|
: 0 0 : 1 : 0
|
: 0 1 : 1 : 1 -- can not set a bit
|
: 0 1 : 1 : 1 -- can not set a bit
|
: 1 0 : 0 : 0
|
: 1 0 : 0 : 0
|
: 1 1 : 0 : 0 */
|
: 1 1 : 0 : 0 */
|
if (~old_byte & new_byte)
|
if (~old_byte & new_byte)
|
invalid_write(me, eeprom->state, address, new_byte, "setting cleared bit");
|
invalid_write(me, eeprom->state, address, new_byte, "setting cleared bit");
|
/* : old new : old&new
|
/* : old new : old&new
|
: 0 0 : 0
|
: 0 0 : 0
|
: 0 1 : 0
|
: 0 1 : 0
|
: 1 0 : 0
|
: 1 0 : 0
|
: 1 1 : 1 */
|
: 1 1 : 1 */
|
eeprom->byte_program_byte = new_byte & old_byte;
|
eeprom->byte_program_byte = new_byte & old_byte;
|
eeprom->memory[address] = ~new_byte & ~0x24; /* LE-bits 5:3 zero */
|
eeprom->memory[address] = ~new_byte & ~0x24; /* LE-bits 5:3 zero */
|
eeprom->program_start_time = device_event_queue_time(me);
|
eeprom->program_start_time = device_event_queue_time(me);
|
eeprom->program_finish_time = (eeprom->program_start_time
|
eeprom->program_finish_time = (eeprom->program_start_time
|
+ eeprom->byte_write_delay);
|
+ eeprom->byte_write_delay);
|
}
|
}
|
|
|
static void
|
static void
|
finish_programming_byte(device *me,
|
finish_programming_byte(device *me,
|
hw_eeprom_device *eeprom)
|
hw_eeprom_device *eeprom)
|
{
|
{
|
DTRACE(eeprom, ("finish-programming-byte - address 0x%lx, byte 0x%lx\n",
|
DTRACE(eeprom, ("finish-programming-byte - address 0x%lx, byte 0x%lx\n",
|
(unsigned long)eeprom->byte_program_address,
|
(unsigned long)eeprom->byte_program_address,
|
(unsigned long)eeprom->byte_program_byte));
|
(unsigned long)eeprom->byte_program_byte));
|
eeprom->memory[eeprom->byte_program_address] = eeprom->byte_program_byte;
|
eeprom->memory[eeprom->byte_program_address] = eeprom->byte_program_byte;
|
dump_eeprom(me, eeprom);
|
dump_eeprom(me, eeprom);
|
}
|
}
|
|
|
|
|
/* erase the eeprom completly */
|
/* erase the eeprom completly */
|
|
|
static void
|
static void
|
start_erasing_chip(device *me,
|
start_erasing_chip(device *me,
|
hw_eeprom_device *eeprom)
|
hw_eeprom_device *eeprom)
|
{
|
{
|
DTRACE(eeprom, ("start-erasing-chip\n"));
|
DTRACE(eeprom, ("start-erasing-chip\n"));
|
memset(eeprom->memory, 0, eeprom->sizeof_memory);
|
memset(eeprom->memory, 0, eeprom->sizeof_memory);
|
eeprom->program_start_time = device_event_queue_time(me);
|
eeprom->program_start_time = device_event_queue_time(me);
|
eeprom->program_finish_time = (eeprom->program_start_time
|
eeprom->program_finish_time = (eeprom->program_start_time
|
+ eeprom->erase_delay);
|
+ eeprom->erase_delay);
|
}
|
}
|
|
|
static void
|
static void
|
finish_erasing_chip(device *me,
|
finish_erasing_chip(device *me,
|
hw_eeprom_device *eeprom)
|
hw_eeprom_device *eeprom)
|
{
|
{
|
DTRACE(eeprom, ("finish-erasing-chip\n"));
|
DTRACE(eeprom, ("finish-erasing-chip\n"));
|
memset(eeprom->memory, 0xff, eeprom->sizeof_memory);
|
memset(eeprom->memory, 0xff, eeprom->sizeof_memory);
|
dump_eeprom(me, eeprom);
|
dump_eeprom(me, eeprom);
|
}
|
}
|
|
|
|
|
/* erase a single sector of the eeprom */
|
/* erase a single sector of the eeprom */
|
|
|
static void
|
static void
|
start_erasing_sector(device *me,
|
start_erasing_sector(device *me,
|
hw_eeprom_device *eeprom,
|
hw_eeprom_device *eeprom,
|
unsigned_word address)
|
unsigned_word address)
|
{
|
{
|
int sector = address / eeprom->sizeof_sector;
|
int sector = address / eeprom->sizeof_sector;
|
DTRACE(eeprom, ("start-erasing-sector - address 0x%lx, sector %d\n",
|
DTRACE(eeprom, ("start-erasing-sector - address 0x%lx, sector %d\n",
|
(unsigned long)address, sector));
|
(unsigned long)address, sector));
|
ASSERT(sector < eeprom->nr_sectors);
|
ASSERT(sector < eeprom->nr_sectors);
|
eeprom->sectors[sector] = 1;
|
eeprom->sectors[sector] = 1;
|
memset(eeprom->memory + sector * eeprom->sizeof_sector,
|
memset(eeprom->memory + sector * eeprom->sizeof_sector,
|
0x4, eeprom->sizeof_sector);
|
0x4, eeprom->sizeof_sector);
|
eeprom->program_start_time = device_event_queue_time(me);
|
eeprom->program_start_time = device_event_queue_time(me);
|
eeprom->sector_start_time = (eeprom->program_start_time
|
eeprom->sector_start_time = (eeprom->program_start_time
|
+ eeprom->sector_start_delay);
|
+ eeprom->sector_start_delay);
|
eeprom->program_finish_time = (eeprom->sector_start_time
|
eeprom->program_finish_time = (eeprom->sector_start_time
|
+ eeprom->erase_delay);
|
+ eeprom->erase_delay);
|
|
|
}
|
}
|
|
|
static void
|
static void
|
finish_erasing_sector(device *me,
|
finish_erasing_sector(device *me,
|
hw_eeprom_device *eeprom)
|
hw_eeprom_device *eeprom)
|
{
|
{
|
int sector;
|
int sector;
|
DTRACE(eeprom, ("finish-erasing-sector\n"));
|
DTRACE(eeprom, ("finish-erasing-sector\n"));
|
for (sector = 0; sector < eeprom->nr_sectors; sector++) {
|
for (sector = 0; sector < eeprom->nr_sectors; sector++) {
|
if (eeprom->sectors[sector]) {
|
if (eeprom->sectors[sector]) {
|
eeprom->sectors[sector] = 0;
|
eeprom->sectors[sector] = 0;
|
memset(eeprom->memory + sector * eeprom->sizeof_sector,
|
memset(eeprom->memory + sector * eeprom->sizeof_sector,
|
0xff, eeprom->sizeof_sector);
|
0xff, eeprom->sizeof_sector);
|
}
|
}
|
}
|
}
|
dump_eeprom(me, eeprom);
|
dump_eeprom(me, eeprom);
|
}
|
}
|
|
|
|
|
/* eeprom reads */
|
/* eeprom reads */
|
|
|
static unsigned8
|
static unsigned8
|
toggle(hw_eeprom_device *eeprom,
|
toggle(hw_eeprom_device *eeprom,
|
unsigned8 byte)
|
unsigned8 byte)
|
{
|
{
|
eeprom->toggle_bit = eeprom->toggle_bit ^ 0x40; /* le-bit 6 */
|
eeprom->toggle_bit = eeprom->toggle_bit ^ 0x40; /* le-bit 6 */
|
return eeprom->toggle_bit ^ byte;
|
return eeprom->toggle_bit ^ byte;
|
}
|
}
|
|
|
static unsigned8
|
static unsigned8
|
read_byte(device *me,
|
read_byte(device *me,
|
hw_eeprom_device *eeprom,
|
hw_eeprom_device *eeprom,
|
unsigned_word address)
|
unsigned_word address)
|
{
|
{
|
/* may need multiple iterations of this */
|
/* may need multiple iterations of this */
|
while (1) {
|
while (1) {
|
switch (eeprom->state) {
|
switch (eeprom->state) {
|
|
|
case read_reset:
|
case read_reset:
|
return eeprom->memory[address];
|
return eeprom->memory[address];
|
|
|
case autoselect:
|
case autoselect:
|
if ((address & 0xff) == 0x00)
|
if ((address & 0xff) == 0x00)
|
return eeprom->manufacture_code;
|
return eeprom->manufacture_code;
|
else if ((address & 0xff) == 0x01)
|
else if ((address & 0xff) == 0x01)
|
return eeprom->device_code;
|
return eeprom->device_code;
|
else
|
else
|
return 0; /* not certain about this */
|
return 0; /* not certain about this */
|
|
|
case byte_programming:
|
case byte_programming:
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
finish_programming_byte(me, eeprom);
|
finish_programming_byte(me, eeprom);
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
continue;
|
continue;
|
}
|
}
|
else if (address == eeprom->byte_program_address) {
|
else if (address == eeprom->byte_program_address) {
|
return toggle(eeprom, eeprom->memory[address]);
|
return toggle(eeprom, eeprom->memory[address]);
|
}
|
}
|
else {
|
else {
|
/* trash that memory location */
|
/* trash that memory location */
|
invalid_read(me, eeprom->state, address, "not byte program address");
|
invalid_read(me, eeprom->state, address, "not byte program address");
|
eeprom->memory[address] = (eeprom->memory[address]
|
eeprom->memory[address] = (eeprom->memory[address]
|
& eeprom->byte_program_byte);
|
& eeprom->byte_program_byte);
|
return toggle(eeprom, eeprom->memory[eeprom->byte_program_address]);
|
return toggle(eeprom, eeprom->memory[eeprom->byte_program_address]);
|
}
|
}
|
|
|
case chip_erase:
|
case chip_erase:
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
finish_erasing_chip(me, eeprom);
|
finish_erasing_chip(me, eeprom);
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
continue;
|
continue;
|
}
|
}
|
else {
|
else {
|
return toggle(eeprom, eeprom->memory[address]);
|
return toggle(eeprom, eeprom->memory[address]);
|
}
|
}
|
|
|
case sector_erase:
|
case sector_erase:
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
finish_erasing_sector(me, eeprom);
|
finish_erasing_sector(me, eeprom);
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
continue;
|
continue;
|
}
|
}
|
else if (!eeprom->sectors[address / eeprom->sizeof_sector]) {
|
else if (!eeprom->sectors[address / eeprom->sizeof_sector]) {
|
/* read to wrong sector */
|
/* read to wrong sector */
|
invalid_read(me, eeprom->state, address, "sector not being erased");
|
invalid_read(me, eeprom->state, address, "sector not being erased");
|
return toggle(eeprom, eeprom->memory[address]) & ~0x8;
|
return toggle(eeprom, eeprom->memory[address]) & ~0x8;
|
}
|
}
|
else if (device_event_queue_time(me) > eeprom->sector_start_time) {
|
else if (device_event_queue_time(me) > eeprom->sector_start_time) {
|
return toggle(eeprom, eeprom->memory[address]) | 0x8;
|
return toggle(eeprom, eeprom->memory[address]) | 0x8;
|
}
|
}
|
else {
|
else {
|
return toggle(eeprom, eeprom->memory[address]) & ~0x8;
|
return toggle(eeprom, eeprom->memory[address]) & ~0x8;
|
}
|
}
|
|
|
case sector_erase_suspend:
|
case sector_erase_suspend:
|
if (!eeprom->sectors[address / eeprom->sizeof_sector]) {
|
if (!eeprom->sectors[address / eeprom->sizeof_sector]) {
|
return eeprom->memory[address];
|
return eeprom->memory[address];
|
}
|
}
|
else {
|
else {
|
invalid_read(me, eeprom->state, address, "sector being erased");
|
invalid_read(me, eeprom->state, address, "sector being erased");
|
return eeprom->memory[address];
|
return eeprom->memory[address];
|
}
|
}
|
|
|
default:
|
default:
|
invalid_read(me, eeprom->state, address, "invalid state");
|
invalid_read(me, eeprom->state, address, "invalid state");
|
return eeprom->memory[address];
|
return eeprom->memory[address];
|
|
|
}
|
}
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static unsigned
|
static unsigned
|
hw_eeprom_io_read_buffer(device *me,
|
hw_eeprom_io_read_buffer(device *me,
|
void *dest,
|
void *dest,
|
int space,
|
int space,
|
unsigned_word addr,
|
unsigned_word addr,
|
unsigned nr_bytes,
|
unsigned nr_bytes,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
hw_eeprom_device *eeprom = (hw_eeprom_device*)device_data(me);
|
hw_eeprom_device *eeprom = (hw_eeprom_device*)device_data(me);
|
int i;
|
int i;
|
for (i = 0; i < nr_bytes; i++) {
|
for (i = 0; i < nr_bytes; i++) {
|
unsigned_word address = (addr + i) % eeprom->sizeof_memory;
|
unsigned_word address = (addr + i) % eeprom->sizeof_memory;
|
unsigned8 byte = read_byte(me, eeprom, address);
|
unsigned8 byte = read_byte(me, eeprom, address);
|
((unsigned8*)dest)[i] = byte;
|
((unsigned8*)dest)[i] = byte;
|
}
|
}
|
return nr_bytes;
|
return nr_bytes;
|
}
|
}
|
|
|
|
|
/* eeprom writes */
|
/* eeprom writes */
|
|
|
static void
|
static void
|
write_byte(device *me,
|
write_byte(device *me,
|
hw_eeprom_device *eeprom,
|
hw_eeprom_device *eeprom,
|
unsigned_word address,
|
unsigned_word address,
|
unsigned8 data)
|
unsigned8 data)
|
{
|
{
|
/* may need multiple transitions to process a write */
|
/* may need multiple transitions to process a write */
|
while (1) {
|
while (1) {
|
switch (eeprom->state) {
|
switch (eeprom->state) {
|
|
|
case read_reset:
|
case read_reset:
|
if (address == 0x5555 && data == 0xaa)
|
if (address == 0x5555 && data == 0xaa)
|
eeprom->state = write_nr_2;
|
eeprom->state = write_nr_2;
|
else if (data == 0xf0)
|
else if (data == 0xf0)
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
return;
|
return;
|
|
|
case write_nr_2:
|
case write_nr_2:
|
if (address == 0x2aaa && data == 0x55)
|
if (address == 0x2aaa && data == 0x55)
|
eeprom->state = write_nr_3;
|
eeprom->state = write_nr_3;
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
return;
|
return;
|
|
|
case write_nr_3:
|
case write_nr_3:
|
if (address == 0x5555 && data == 0xf0)
|
if (address == 0x5555 && data == 0xf0)
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
else if (address == 0x5555 && data == 0x90)
|
else if (address == 0x5555 && data == 0x90)
|
eeprom->state = autoselect;
|
eeprom->state = autoselect;
|
else if (address == 0x5555 && data == 0xa0) {
|
else if (address == 0x5555 && data == 0xa0) {
|
eeprom->state = byte_program;
|
eeprom->state = byte_program;
|
}
|
}
|
else if (address == 0x5555 && data == 0x80)
|
else if (address == 0x5555 && data == 0x80)
|
eeprom->state = write_nr_4;
|
eeprom->state = write_nr_4;
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
return;
|
return;
|
|
|
case write_nr_4:
|
case write_nr_4:
|
if (address == 0x5555 && data == 0xaa)
|
if (address == 0x5555 && data == 0xaa)
|
eeprom->state = write_nr_5;
|
eeprom->state = write_nr_5;
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
return;
|
return;
|
|
|
case write_nr_5:
|
case write_nr_5:
|
if (address == 0x2aaa && data == 0x55)
|
if (address == 0x2aaa && data == 0x55)
|
eeprom->state = write_nr_6;
|
eeprom->state = write_nr_6;
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
invalid_write(me, eeprom->state, address, data, "unexpected");
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
return;
|
return;
|
|
|
case write_nr_6:
|
case write_nr_6:
|
if (address == 0x5555 && data == 0x10) {
|
if (address == 0x5555 && data == 0x10) {
|
start_erasing_chip(me, eeprom);
|
start_erasing_chip(me, eeprom);
|
eeprom->state = chip_erase;
|
eeprom->state = chip_erase;
|
}
|
}
|
else {
|
else {
|
start_erasing_sector(me, eeprom, address);
|
start_erasing_sector(me, eeprom, address);
|
eeprom->sector_state = read_reset;
|
eeprom->sector_state = read_reset;
|
eeprom->state = sector_erase;
|
eeprom->state = sector_erase;
|
}
|
}
|
return;
|
return;
|
|
|
case autoselect:
|
case autoselect:
|
if (data == 0xf0)
|
if (data == 0xf0)
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
else if (address == 0x5555 && data == 0xaa)
|
else if (address == 0x5555 && data == 0xaa)
|
eeprom->state = write_nr_2;
|
eeprom->state = write_nr_2;
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, "unsupported address");
|
invalid_write(me, eeprom->state, address, data, "unsupported address");
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
return;
|
return;
|
|
|
case byte_program:
|
case byte_program:
|
start_programming_byte(me, eeprom, address, data);
|
start_programming_byte(me, eeprom, address, data);
|
eeprom->state = byte_programming;
|
eeprom->state = byte_programming;
|
return;
|
return;
|
|
|
case byte_programming:
|
case byte_programming:
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
finish_programming_byte(me, eeprom);
|
finish_programming_byte(me, eeprom);
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
continue;
|
continue;
|
}
|
}
|
/* ignore it */
|
/* ignore it */
|
return;
|
return;
|
|
|
case chip_erase:
|
case chip_erase:
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
finish_erasing_chip(me, eeprom);
|
finish_erasing_chip(me, eeprom);
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
continue;
|
continue;
|
}
|
}
|
/* ignore it */
|
/* ignore it */
|
return;
|
return;
|
|
|
case sector_erase:
|
case sector_erase:
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
if (device_event_queue_time(me) > eeprom->program_finish_time) {
|
finish_erasing_sector(me, eeprom);
|
finish_erasing_sector(me, eeprom);
|
eeprom->state = eeprom->sector_state;
|
eeprom->state = eeprom->sector_state;
|
continue;
|
continue;
|
}
|
}
|
else if (device_event_queue_time(me) > eeprom->sector_start_time
|
else if (device_event_queue_time(me) > eeprom->sector_start_time
|
&& data == 0xb0) {
|
&& data == 0xb0) {
|
eeprom->sector_state = read_reset;
|
eeprom->sector_state = read_reset;
|
eeprom->state = sector_erase_suspend;
|
eeprom->state = sector_erase_suspend;
|
}
|
}
|
else {
|
else {
|
if (eeprom->sector_state == read_reset
|
if (eeprom->sector_state == read_reset
|
&& address == 0x5555 && data == 0xaa)
|
&& address == 0x5555 && data == 0xaa)
|
eeprom->sector_state = write_nr_2;
|
eeprom->sector_state = write_nr_2;
|
else if (eeprom->sector_state == write_nr_2
|
else if (eeprom->sector_state == write_nr_2
|
&& address == 0x2aaa && data == 0x55)
|
&& address == 0x2aaa && data == 0x55)
|
eeprom->sector_state = write_nr_3;
|
eeprom->sector_state = write_nr_3;
|
else if (eeprom->sector_state == write_nr_3
|
else if (eeprom->sector_state == write_nr_3
|
&& address == 0x5555 && data == 0x80)
|
&& address == 0x5555 && data == 0x80)
|
eeprom->sector_state = write_nr_4;
|
eeprom->sector_state = write_nr_4;
|
else if (eeprom->sector_state == write_nr_4
|
else if (eeprom->sector_state == write_nr_4
|
&& address == 0x5555 && data == 0xaa)
|
&& address == 0x5555 && data == 0xaa)
|
eeprom->sector_state = write_nr_5;
|
eeprom->sector_state = write_nr_5;
|
else if (eeprom->sector_state == write_nr_5
|
else if (eeprom->sector_state == write_nr_5
|
&& address == 0x2aaa && data == 0x55)
|
&& address == 0x2aaa && data == 0x55)
|
eeprom->sector_state = write_nr_6;
|
eeprom->sector_state = write_nr_6;
|
else if (eeprom->sector_state == write_nr_6
|
else if (eeprom->sector_state == write_nr_6
|
&& address != 0x5555 && data == 0x30) {
|
&& address != 0x5555 && data == 0x30) {
|
if (device_event_queue_time(me) > eeprom->sector_start_time) {
|
if (device_event_queue_time(me) > eeprom->sector_start_time) {
|
DTRACE(eeprom, ("sector erase command after window closed\n"));
|
DTRACE(eeprom, ("sector erase command after window closed\n"));
|
eeprom->sector_state = read_reset;
|
eeprom->sector_state = read_reset;
|
}
|
}
|
else {
|
else {
|
start_erasing_sector(me, eeprom, address);
|
start_erasing_sector(me, eeprom, address);
|
eeprom->sector_state = read_reset;
|
eeprom->sector_state = read_reset;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, state2a(eeprom->sector_state));
|
invalid_write(me, eeprom->state, address, data, state2a(eeprom->sector_state));
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
}
|
}
|
return;
|
return;
|
|
|
case sector_erase_suspend:
|
case sector_erase_suspend:
|
if (data == 0x30)
|
if (data == 0x30)
|
eeprom->state = sector_erase;
|
eeprom->state = sector_erase;
|
else {
|
else {
|
invalid_write(me, eeprom->state, address, data, "not resume command");
|
invalid_write(me, eeprom->state, address, data, "not resume command");
|
eeprom->state = read_reset;
|
eeprom->state = read_reset;
|
}
|
}
|
return;
|
return;
|
|
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
static unsigned
|
static unsigned
|
hw_eeprom_io_write_buffer(device *me,
|
hw_eeprom_io_write_buffer(device *me,
|
const void *source,
|
const void *source,
|
int space,
|
int space,
|
unsigned_word addr,
|
unsigned_word addr,
|
unsigned nr_bytes,
|
unsigned nr_bytes,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
hw_eeprom_device *eeprom = (hw_eeprom_device*)device_data(me);
|
hw_eeprom_device *eeprom = (hw_eeprom_device*)device_data(me);
|
int i;
|
int i;
|
for (i = 0; i < nr_bytes; i++) {
|
for (i = 0; i < nr_bytes; i++) {
|
unsigned_word address = (addr + i) % eeprom->sizeof_memory;
|
unsigned_word address = (addr + i) % eeprom->sizeof_memory;
|
unsigned8 byte = ((unsigned8*)source)[i];
|
unsigned8 byte = ((unsigned8*)source)[i];
|
write_byte(me, eeprom, address, byte);
|
write_byte(me, eeprom, address, byte);
|
}
|
}
|
return nr_bytes;
|
return nr_bytes;
|
}
|
}
|
|
|
|
|
/* An instance of the eeprom */
|
/* An instance of the eeprom */
|
|
|
typedef struct _hw_eeprom_instance {
|
typedef struct _hw_eeprom_instance {
|
unsigned_word pos;
|
unsigned_word pos;
|
hw_eeprom_device *eeprom;
|
hw_eeprom_device *eeprom;
|
device *me;
|
device *me;
|
} hw_eeprom_instance;
|
} hw_eeprom_instance;
|
|
|
static void
|
static void
|
hw_eeprom_instance_delete(device_instance *instance)
|
hw_eeprom_instance_delete(device_instance *instance)
|
{
|
{
|
hw_eeprom_instance *data = device_instance_data(instance);
|
hw_eeprom_instance *data = device_instance_data(instance);
|
zfree(data);
|
zfree(data);
|
}
|
}
|
|
|
static int
|
static int
|
hw_eeprom_instance_read(device_instance *instance,
|
hw_eeprom_instance_read(device_instance *instance,
|
void *buf,
|
void *buf,
|
unsigned_word len)
|
unsigned_word len)
|
{
|
{
|
hw_eeprom_instance *data = device_instance_data(instance);
|
hw_eeprom_instance *data = device_instance_data(instance);
|
int i;
|
int i;
|
if (data->eeprom->state != read_reset)
|
if (data->eeprom->state != read_reset)
|
DITRACE(eeprom, ("eeprom not idle during instance read\n"));
|
DITRACE(eeprom, ("eeprom not idle during instance read\n"));
|
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
((unsigned8*)buf)[i] = data->eeprom->memory[data->pos];
|
((unsigned8*)buf)[i] = data->eeprom->memory[data->pos];
|
data->pos = (data->pos + 1) % data->eeprom->sizeof_memory;
|
data->pos = (data->pos + 1) % data->eeprom->sizeof_memory;
|
}
|
}
|
return len;
|
return len;
|
}
|
}
|
|
|
static int
|
static int
|
hw_eeprom_instance_write(device_instance *instance,
|
hw_eeprom_instance_write(device_instance *instance,
|
const void *buf,
|
const void *buf,
|
unsigned_word len)
|
unsigned_word len)
|
{
|
{
|
hw_eeprom_instance *data = device_instance_data(instance);
|
hw_eeprom_instance *data = device_instance_data(instance);
|
int i;
|
int i;
|
if (data->eeprom->state != read_reset)
|
if (data->eeprom->state != read_reset)
|
DITRACE(eeprom, ("eeprom not idle during instance write\n"));
|
DITRACE(eeprom, ("eeprom not idle during instance write\n"));
|
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
data->eeprom->memory[data->pos] = ((unsigned8*)buf)[i];
|
data->eeprom->memory[data->pos] = ((unsigned8*)buf)[i];
|
data->pos = (data->pos + 1) % data->eeprom->sizeof_memory;
|
data->pos = (data->pos + 1) % data->eeprom->sizeof_memory;
|
}
|
}
|
dump_eeprom(data->me, data->eeprom);
|
dump_eeprom(data->me, data->eeprom);
|
return len;
|
return len;
|
}
|
}
|
|
|
static int
|
static int
|
hw_eeprom_instance_seek(device_instance *instance,
|
hw_eeprom_instance_seek(device_instance *instance,
|
unsigned_word pos_hi,
|
unsigned_word pos_hi,
|
unsigned_word pos_lo)
|
unsigned_word pos_lo)
|
{
|
{
|
hw_eeprom_instance *data = device_instance_data(instance);
|
hw_eeprom_instance *data = device_instance_data(instance);
|
if (pos_lo >= data->eeprom->sizeof_memory)
|
if (pos_lo >= data->eeprom->sizeof_memory)
|
device_error(data->me, "seek value 0x%lx out of range\n",
|
device_error(data->me, "seek value 0x%lx out of range\n",
|
(unsigned long)pos_lo);
|
(unsigned long)pos_lo);
|
data->pos = pos_lo;
|
data->pos = pos_lo;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static const device_instance_callbacks hw_eeprom_instance_callbacks = {
|
static const device_instance_callbacks hw_eeprom_instance_callbacks = {
|
hw_eeprom_instance_delete,
|
hw_eeprom_instance_delete,
|
hw_eeprom_instance_read,
|
hw_eeprom_instance_read,
|
hw_eeprom_instance_write,
|
hw_eeprom_instance_write,
|
hw_eeprom_instance_seek,
|
hw_eeprom_instance_seek,
|
};
|
};
|
|
|
static device_instance *
|
static device_instance *
|
hw_eeprom_create_instance(device *me,
|
hw_eeprom_create_instance(device *me,
|
const char *path,
|
const char *path,
|
const char *args)
|
const char *args)
|
{
|
{
|
hw_eeprom_device *eeprom = device_data(me);
|
hw_eeprom_device *eeprom = device_data(me);
|
hw_eeprom_instance *data = ZALLOC(hw_eeprom_instance);
|
hw_eeprom_instance *data = ZALLOC(hw_eeprom_instance);
|
data->eeprom = eeprom;
|
data->eeprom = eeprom;
|
data->me = me;
|
data->me = me;
|
return device_create_instance_from(me, NULL,
|
return device_create_instance_from(me, NULL,
|
data,
|
data,
|
path, args,
|
path, args,
|
&hw_eeprom_instance_callbacks);
|
&hw_eeprom_instance_callbacks);
|
}
|
}
|
|
|
|
|
|
|
static device_callbacks const hw_eeprom_callbacks = {
|
static device_callbacks const hw_eeprom_callbacks = {
|
{ generic_device_init_address,
|
{ generic_device_init_address,
|
hw_eeprom_init_data },
|
hw_eeprom_init_data },
|
{ NULL, }, /* address */
|
{ NULL, }, /* address */
|
{ hw_eeprom_io_read_buffer,
|
{ hw_eeprom_io_read_buffer,
|
hw_eeprom_io_write_buffer }, /* IO */
|
hw_eeprom_io_write_buffer }, /* IO */
|
{ NULL, }, /* DMA */
|
{ NULL, }, /* DMA */
|
{ NULL, }, /* interrupt */
|
{ NULL, }, /* interrupt */
|
{ NULL, }, /* unit */
|
{ NULL, }, /* unit */
|
hw_eeprom_create_instance,
|
hw_eeprom_create_instance,
|
};
|
};
|
|
|
static void *
|
static void *
|
hw_eeprom_create(const char *name,
|
hw_eeprom_create(const char *name,
|
const device_unit *unit_address,
|
const device_unit *unit_address,
|
const char *args)
|
const char *args)
|
{
|
{
|
hw_eeprom_device *eeprom = ZALLOC(hw_eeprom_device);
|
hw_eeprom_device *eeprom = ZALLOC(hw_eeprom_device);
|
return eeprom;
|
return eeprom;
|
}
|
}
|
|
|
|
|
|
|
const device_descriptor hw_eeprom_device_descriptor[] = {
|
const device_descriptor hw_eeprom_device_descriptor[] = {
|
{ "eeprom", hw_eeprom_create, &hw_eeprom_callbacks },
|
{ "eeprom", hw_eeprom_create, &hw_eeprom_callbacks },
|
{ NULL },
|
{ NULL },
|
};
|
};
|
|
|
#endif /* _HW_EEPROM_C_ */
|
#endif /* _HW_EEPROM_C_ */
|
|
|