Skip to content

Commit

Permalink
staging: comedi: addi_eeprom: add defines for the 93c76 eeprom bits
Browse files Browse the repository at this point in the history
Define the magic values used for the clock, chip-select, data out,
and data in signals to the 93c76 eeprom.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Oct 30, 2012
1 parent 6baf510 commit d615de2
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions drivers/staging/comedi/drivers/addi-data/addi_eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ You should also find the complete GPL in the COPYING file accompanying this sour
#define NVCMD_BEGIN_READ (0x7 << 5) /* nvRam begin read command */
#define NVCMD_LOAD_LOW (0x4 << 5) /* nvRam load low command */
#define NVCMD_LOAD_HIGH (0x5 << 5) /* nvRam load high command */

#define EE93C76_CLK_BIT (1 << 0)
#define EE93C76_CS_BIT (1 << 1)
#define EE93C76_DOUT_BIT (1 << 2)
#define EE93C76_DIN_BIT (1 << 3)
#define EE76_CMD_LEN 13 /* bits in instructions */
#define EE_READ 0x0180 /* 01 1000 0000 read instruction */

Expand Down Expand Up @@ -110,38 +115,30 @@ struct str_AnalogInputHeader {
static void v_EepromClock76(unsigned long iobase,
unsigned int dw_RegisterValue)
{
/* Set EEPROM clock Low */
outl(dw_RegisterValue & 0x6, iobase);
outl(dw_RegisterValue & ~EE93C76_CLK_BIT, iobase);
udelay(100);

/* Set EEPROM clock High */
outl(dw_RegisterValue | 0x1, iobase);
outl(dw_RegisterValue | EE93C76_CLK_BIT, iobase);
udelay(100);
}

static void v_EepromSendCommand76(unsigned long iobase,
unsigned int dw_EepromCommand,
unsigned char b_DataLengthInBits)
{
unsigned int dw_RegisterValue = EE93C76_CS_BIT;
char c_BitPos = 0;
unsigned int dw_RegisterValue = 0;

/* Enable EEPROM Chip Select */
dw_RegisterValue = 0x2;

/* Toggle EEPROM's Chip select to get it out of Shift Register Mode */
outl(dw_RegisterValue, iobase);
udelay(100);

/* Send EEPROM command - one bit at a time */
for (c_BitPos = (b_DataLengthInBits - 1); c_BitPos >= 0; c_BitPos--) {
if (dw_EepromCommand & (1 << c_BitPos)) {
/* Write 1 */
dw_RegisterValue = dw_RegisterValue | 0x4;
} else {
/* Write 0 */
dw_RegisterValue = dw_RegisterValue & 0x3;
}
if (dw_EepromCommand & (1 << c_BitPos))
dw_RegisterValue = dw_RegisterValue | EE93C76_DOUT_BIT;
else
dw_RegisterValue = dw_RegisterValue & ~EE93C76_DOUT_BIT;

/* Write the command */
outl(dw_RegisterValue, iobase);
Expand All @@ -165,7 +162,7 @@ static void v_EepromCs76Read(unsigned long iobase,
EE76_CMD_LEN);

/* Get the last register value */
dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | 0x2;
dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | EE93C76_CS_BIT;

/* Set the 16-bit value of 0 */
*pw_Value = 0;
Expand All @@ -180,7 +177,7 @@ static void v_EepromCs76Read(unsigned long iobase,
udelay(100);

/* Get bit value and shift into result */
if (dw_RegisterValueRead & 0x8) {
if (dw_RegisterValueRead & EE93C76_DIN_BIT) {
/* Read 1 */
*pw_Value = (*pw_Value << 1) | 0x1;
} else {
Expand Down

0 comments on commit d615de2

Please sign in to comment.