From 7cd25bf08c2bc4794b026feea0230b9caf787744 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 29 Oct 2012 17:07:30 -0700 Subject: [PATCH] staging: comedi: addi_eeprom: cleanup i_EepromReadMainHeader() 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 Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../comedi/drivers/addi-data/addi_eeprom.c | 76 ++++++------------- 1 file changed, 24 insertions(+), 52 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c b/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c index 3ea831954374..529f9b1341cd 100644 --- a/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c +++ b/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; -- 2.39.5