Skip to content

Commit

Permalink
staging: comedi: addi_eeprom: cleanup i_EepromReadMainHeader()
Browse files Browse the repository at this point in the history
Consolidate the two loops used to read the main header data and the
individual function header data from the eeprom.

The structs used to read the main header are not used outside this
function so remove them by reading the eeprom data into local
variables used in the loop.

Consolidate the 'timer' function cases.

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 85c1dcb commit 7cd25bf
Showing 1 changed file with 24 additions and 52 deletions.
76 changes: 24 additions & 52 deletions drivers/staging/comedi/drivers/addi-data/addi_eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ You should also find the complete GPL in the COPYING file accompanying this sour
#define EEPROM_WATCHDOG 5
#define EEPROM_TIMER_WATCHDOG_COUNTER 10

struct str_Functionality {
unsigned char b_Type;
unsigned short w_Address;
};

struct str_MainHeader {
unsigned short w_HeaderSize;
unsigned char b_Nfunctions;
struct str_Functionality s_Functions[7];
};

struct str_DigitalInputHeader {
unsigned short w_Nchannel;
unsigned char b_Interruptible;
Expand Down Expand Up @@ -377,50 +366,41 @@ static int i_EepromReadMainHeader(unsigned long iobase,
{
const struct addi_board *this_board = comedi_board(dev);
struct addi_private *devpriv = dev->private;
unsigned short w_Temp, i, w_Count = 0;
unsigned int ui_Temp;
struct str_MainHeader s_MainHeader;
struct str_DigitalInputHeader s_DigitalInputHeader;
struct str_DigitalOutputHeader s_DigitalOutputHeader;
/* struct str_TimerMainHeader s_TimerMainHeader,s_WatchdogMainHeader; */
struct str_AnalogOutputHeader s_AnalogOutputHeader;
struct str_AnalogInputHeader s_AnalogInputHeader;
unsigned short size;
unsigned char nfuncs;
int i;

/* Read size */
s_MainHeader.w_HeaderSize = addi_eeprom_readw(iobase, type, 8);

/* Read nbr of functionality */
w_Temp = addi_eeprom_readw(iobase, type, 10);
s_MainHeader.b_Nfunctions = (unsigned char) w_Temp & 0x00FF;
size = addi_eeprom_readw(iobase, type, 8);
nfuncs = addi_eeprom_readw(iobase, type, 10) & 0xff;

/* Read functionality details */
for (i = 0; i < s_MainHeader.b_Nfunctions; i++) {
/* Read Type */
w_Temp = addi_eeprom_readw(iobase, type, 12 + w_Count);
s_MainHeader.s_Functions[i].b_Type = (unsigned char) w_Temp & 0x3F;
w_Count = w_Count + 2;
/* Read Address */
s_MainHeader.s_Functions[i].w_Address =
addi_eeprom_readw(iobase, type, 12 + w_Count);
w_Count = w_Count + 2;
}
for (i = 0; i < nfuncs; i++) {
unsigned short offset = i * 4;
unsigned short addr;
unsigned char func;

/* Display main header info */
for (i = 0; i < s_MainHeader.b_Nfunctions; i++) {
func = addi_eeprom_readw(iobase, type, 12 + offset) & 0x3f;
addr = addi_eeprom_readw(iobase, type, 14 + offset);

switch (s_MainHeader.s_Functions[i].b_Type) {
switch (func) {
case EEPROM_DIGITALINPUT:
i_EepromReadDigitalInputHeader(iobase, type,
s_MainHeader.s_Functions[i].w_Address,
&s_DigitalInputHeader);
i_EepromReadDigitalInputHeader(iobase, type, addr,
&s_DigitalInputHeader);

devpriv->s_EeParameters.i_NbrDiChannel =
s_DigitalInputHeader.w_Nchannel;
break;

case EEPROM_DIGITALOUTPUT:
i_EepromReadDigitalOutputHeader(iobase, type,
s_MainHeader.s_Functions[i].w_Address,
&s_DigitalOutputHeader);
i_EepromReadDigitalOutputHeader(iobase, type, addr,
&s_DigitalOutputHeader);

devpriv->s_EeParameters.i_NbrDoChannel =
s_DigitalOutputHeader.w_Nchannel;
ui_Temp = 0xffffffff;
Expand All @@ -430,9 +410,9 @@ static int i_EepromReadMainHeader(unsigned long iobase,
break;

case EEPROM_ANALOGINPUT:
i_EepromReadAnlogInputHeader(iobase, type,
s_MainHeader.s_Functions[i].w_Address,
&s_AnalogInputHeader);
i_EepromReadAnlogInputHeader(iobase, type, addr,
&s_AnalogInputHeader);

if (!(strcmp(this_board->pc_DriverName, "apci3200")))
devpriv->s_EeParameters.i_NbrAiChannel =
s_AnalogInputHeader.w_Nchannel * 4;
Expand All @@ -454,9 +434,9 @@ static int i_EepromReadMainHeader(unsigned long iobase,
break;

case EEPROM_ANALOGOUTPUT:
i_EepromReadAnlogOutputHeader(iobase, type,
s_MainHeader.s_Functions[i].w_Address,
&s_AnalogOutputHeader);
i_EepromReadAnlogOutputHeader(iobase, type, addr,
&s_AnalogOutputHeader);

devpriv->s_EeParameters.i_NbrAoChannel =
s_AnalogOutputHeader.w_Nchannel;
ui_Temp = 0xffff;
Expand All @@ -466,15 +446,7 @@ static int i_EepromReadMainHeader(unsigned long iobase,
break;

case EEPROM_TIMER:
/* Timer subdevice present */
devpriv->s_EeParameters.i_Timer = 1;
break;

case EEPROM_WATCHDOG:
/* Timer subdevice present */
devpriv->s_EeParameters.i_Timer = 1;
break;

case EEPROM_TIMER_WATCHDOG_COUNTER:
/* Timer subdevice present */
devpriv->s_EeParameters.i_Timer = 1;
Expand Down

0 comments on commit 7cd25bf

Please sign in to comment.