Commit c9535c8b authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: addi_eeprom: cleanup v_EepromCs76Read()

Add namespace to the function by renaming the CamelCase function to
addi_eeprom_read_93c76().

Change the return type of the function to unsigned short and just
return the read value instead of passing it through a pointer.

Rename the CamelCase parameters and local variables.

Make addi_eeprom_cmd_93c76() return the last value so it does not
need to be calculated.

Rename the EE_READ and EE76_CMD_LEN defines so they have namespace
associated with the other 93c76 defines.

Cleanup the loop that reads the eeprom bits so it's a bit more concise.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6311e135
...@@ -53,8 +53,8 @@ You should also find the complete GPL in the COPYING file accompanying this sour ...@@ -53,8 +53,8 @@ You should also find the complete GPL in the COPYING file accompanying this sour
#define EE93C76_CS_BIT (1 << 1) #define EE93C76_CS_BIT (1 << 1)
#define EE93C76_DOUT_BIT (1 << 2) #define EE93C76_DOUT_BIT (1 << 2)
#define EE93C76_DIN_BIT (1 << 3) #define EE93C76_DIN_BIT (1 << 3)
#define EE76_CMD_LEN 13 /* bits in instructions */ #define EE93C76_READ_CMD (0x0180 << 4)
#define EE_READ 0x0180 /* 01 1000 0000 read instruction */ #define EE93C76_CMD_LEN 13
#define EEPROM_DIGITALINPUT 0 #define EEPROM_DIGITALINPUT 0
#define EEPROM_DIGITALOUTPUT 1 #define EEPROM_DIGITALOUTPUT 1
...@@ -121,9 +121,9 @@ static void addi_eeprom_clk_93c76(unsigned long iobase, unsigned int val) ...@@ -121,9 +121,9 @@ static void addi_eeprom_clk_93c76(unsigned long iobase, unsigned int val)
udelay(100); udelay(100);
} }
static void addi_eeprom_cmd_93c76(unsigned long iobase, static unsigned int addi_eeprom_cmd_93c76(unsigned long iobase,
unsigned int cmd, unsigned int cmd,
unsigned char len) unsigned char len)
{ {
unsigned int val = EE93C76_CS_BIT; unsigned int val = EE93C76_CS_BIT;
int i; int i;
...@@ -145,50 +145,38 @@ static void addi_eeprom_cmd_93c76(unsigned long iobase, ...@@ -145,50 +145,38 @@ static void addi_eeprom_cmd_93c76(unsigned long iobase,
addi_eeprom_clk_93c76(iobase, val); addi_eeprom_clk_93c76(iobase, val);
} }
return val;
} }
static void v_EepromCs76Read(unsigned long iobase, static unsigned short addi_eeprom_readw_93c76(unsigned long iobase,
unsigned short w_offset, unsigned short addr)
unsigned short *pw_Value)
{ {
char c_BitPos = 0; unsigned short val = 0;
unsigned int dw_RegisterValue = 0; unsigned int cmd;
unsigned int dw_RegisterValueRead = 0; unsigned int tmp;
int i;
/* Send EEPROM read command and offset to EEPROM */ /* Send EEPROM read command and offset to EEPROM */
addi_eeprom_cmd_93c76(iobase, (EE_READ << 4) | (w_offset / 2), cmd = EE93C76_READ_CMD | (addr / 2);
EE76_CMD_LEN); cmd = addi_eeprom_cmd_93c76(iobase, cmd, EE93C76_CMD_LEN);
/* Get the last register value */
dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | EE93C76_CS_BIT;
/* Set the 16-bit value of 0 */
*pw_Value = 0;
/* Get the 16-bit value */ /* Get the 16-bit value */
for (c_BitPos = 0; c_BitPos < 16; c_BitPos++) { for (i = 0; i < 16; i++) {
addi_eeprom_clk_93c76(iobase, dw_RegisterValue); addi_eeprom_clk_93c76(iobase, cmd);
/* Get the result bit */ tmp = inl(iobase);
dw_RegisterValueRead = inl(iobase);
udelay(100); udelay(100);
/* Get bit value and shift into result */ val <<= 1;
if (dw_RegisterValueRead & EE93C76_DIN_BIT) { if (tmp & EE93C76_DIN_BIT)
/* Read 1 */ val |= 0x1;
*pw_Value = (*pw_Value << 1) | 0x1;
} else {
/* Read 0 */
*pw_Value = (*pw_Value << 1);
}
} }
/* Clear all EEPROM bits */
dw_RegisterValue = 0x0;
/* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */
outl(dw_RegisterValue, iobase); outl(0, iobase);
udelay(100); udelay(100);
return val;
} }
static void v_EepromWaitBusy(unsigned long iobase) static void v_EepromWaitBusy(unsigned long iobase)
...@@ -270,10 +258,8 @@ static unsigned short w_EepromReadWord(unsigned long iobase, ...@@ -270,10 +258,8 @@ static unsigned short w_EepromReadWord(unsigned long iobase,
w_ReadWord = (b_ReadLowByte | (((unsigned short) b_ReadHighByte) * 256)); w_ReadWord = (b_ReadLowByte | (((unsigned short) b_ReadHighByte) * 256));
} }
if (!strcmp(type, "93C76")) { if (!strcmp(type, "93C76"))
/* Read 16 bit from the EEPROM 93C76 */ w_ReadWord = addi_eeprom_readw_93c76(iobase, w_EepromStartAddress);
v_EepromCs76Read(iobase, w_EepromStartAddress, &w_ReadWord);
}
return w_ReadWord; return w_ReadWord;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment