From 6ab1b6d82dd4695f9640f7a34085057c7ab043c2 Mon Sep 17 00:00:00 2001 From: Holger Waechtler Date: Sat, 14 Jun 2003 20:06:03 +0000 Subject: i2c fixes and build fixes. Must have been brain-amputated yesterday... --- linux/drivers/media/common/saa7146_i2c.c | 13 +++- linux/drivers/media/dvb/ttpci/budget-core.c | 4 +- linux/drivers/media/dvb/ttpci/ttpci-eeprom.c | 107 +++++++++++++++++++++++++++ linux/drivers/media/dvb/ttpci/ttpci-eeprom.h | 32 ++++++++ linux/drivers/media/dvb/ttpci/ttpci_eeprom.c | 107 --------------------------- linux/drivers/media/dvb/ttpci/ttpci_eeprom.h | 32 -------- 6 files changed, 151 insertions(+), 144 deletions(-) create mode 100644 linux/drivers/media/dvb/ttpci/ttpci-eeprom.c create mode 100644 linux/drivers/media/dvb/ttpci/ttpci-eeprom.h delete mode 100644 linux/drivers/media/dvb/ttpci/ttpci_eeprom.c delete mode 100644 linux/drivers/media/dvb/ttpci/ttpci_eeprom.h (limited to 'linux/drivers') diff --git a/linux/drivers/media/common/saa7146_i2c.c b/linux/drivers/media/common/saa7146_i2c.c index 535cd55ba..b5d2745a0 100644 --- a/linux/drivers/media/common/saa7146_i2c.c +++ b/linux/drivers/media/common/saa7146_i2c.c @@ -190,6 +190,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword) { u32 status = 0, mc2 = 0; + int trial = 0; int timeout; /* write out i2c-command */ @@ -230,10 +231,13 @@ int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword) /* wait until we get a transfer done or error */ timeout = jiffies + HZ/100 + 1; /* 10ms */ while(1) { + /** + * first read usually delivers bogus results... + */ + saa7146_i2c_status(dev); status = saa7146_i2c_status(dev); - if( (0x3 == (status & 0x3)) || (0 == (status & 0x1)) ) { + if ((status & 0x3) != 1) break; - } if (jiffies > timeout) { /* this is normal when probing the bus * (no answer from nonexisistant device...) @@ -241,7 +245,10 @@ int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword) DEB_I2C(("saa7146_i2c_writeout: timed out waiting for end of xfer\n")); return -EIO; } - my_wait(dev,1); + if (++trial < 10) + udelay(10); + else + my_wait(dev,1); } } diff --git a/linux/drivers/media/dvb/ttpci/budget-core.c b/linux/drivers/media/dvb/ttpci/budget-core.c index a2227a94b..f0a5d3592 100644 --- a/linux/drivers/media/dvb/ttpci/budget-core.c +++ b/linux/drivers/media/dvb/ttpci/budget-core.c @@ -1,5 +1,5 @@ #include "budget.h" -#include "ttpci_eeprom.h" +#include "ttpci-eeprom.h" int budget_debug = 0; @@ -231,7 +231,7 @@ int ttpci_budget_init (struct budget *budget, get recognized before the main driver is loaded */ saa7146_write(dev, GPIO_CTRL, 0x500000); - saa7146_i2c_adapter_prepare(dev, NULL, SAA7146_I2C_BUS_BIT_RATE_3200); + saa7146_i2c_adapter_prepare(dev, NULL, SAA7146_I2C_BUS_BIT_RATE_120); budget->i2c_bus = dvb_register_i2c_bus (master_xfer, dev, budget->dvb_adapter, 0); diff --git a/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c b/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c new file mode 100644 index 000000000..aa9c68f0b --- /dev/null +++ b/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c @@ -0,0 +1,107 @@ +/* + Retrieve encoded MAC address from ATMEL ttpci_eeprom serial 2-wire EEPROM, + decode it and store it in associated adapter net device + + Robert Schlabbach GMX + Michael Glaum KVH Industries + Holger Waechtler Convergence + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include +#include + +#include "dvb_i2c.h" +#include "dvb_functions.h" + +#if 0 +#define dprintk(x...) printk(x) +#else +#define dprintk(x...) +#endif + + +static +int ttpci_eeprom_read_encodedMAC (struct dvb_i2c_bus *i2c, u8 * encodedMAC ) +{ + int ret; + u8 b0 [] = { 0xd4 }; + struct i2c_msg msg [] = { { addr: 0x50, flags: 0, buf: b0, len: 1 }, + { addr: 0x50, flags: I2C_M_RD, buf: encodedMAC, len: 6 } }; + + dprintk ("%s\n", __FUNCTION__); + + ret = i2c->xfer (i2c, msg, 2); + + if (ret != 2) // Assume EEPROM isn't there + return( -ENODEV ); + + return 0; +} + +static +void decodeMAC (u8 *decodedMAC, const u8* encodedMAC) +{ + u8 ormask0[3] = { 0x54, 0x7B, 0x9E }; + u8 ormask1[3] = { 0xD3, 0xF1, 0x23 }; + u8 low; + u8 high; + u8 shift; + int i; + + decodedMAC[0] = 0x00; + decodedMAC[1] = 0xD0; + decodedMAC[2] = 0x5C; + + for (i=0; i<3; i++) { + low = encodedMAC[ 2*i ] ^ ormask0[i]; + high = encodedMAC[ 2*i+1 ] ^ ormask1[i]; + shift = ( high >> 6 ) & 0x3; + + decodedMAC[5-i] = ((high<<8) | low) >> shift; + } + +} + + +int ttpci_eeprom_parse_mac (struct dvb_i2c_bus *i2c) +{ + int ret; + u8 encodedMAC[6]; + u8 decodedMAC[6]; + + ret = ttpci_eeprom_read_encodedMAC(i2c, encodedMAC); + + if (ret != 0) { // Will only be -ENODEV + dprintk("Couldn't read from EEPROM: not there?\n"); + return ret; + } + + decodeMAC(decodedMAC, encodedMAC); + memcpy(i2c->adapter->proposed_mac, decodedMAC, 6); + + dprintk("%s adapter %i has MAC addr = %x:%x:%x:%x:%x:%x\n", + i2c->adapter->name, i2c->adapter->num, + decodedMAC[0],decodedMAC[1],decodedMAC[2], + decodedMAC[3],decodedMAC[4],decodedMAC[5]); + + return 0; +} + + diff --git a/linux/drivers/media/dvb/ttpci/ttpci-eeprom.h b/linux/drivers/media/dvb/ttpci/ttpci-eeprom.h new file mode 100644 index 000000000..66cb85ced --- /dev/null +++ b/linux/drivers/media/dvb/ttpci/ttpci-eeprom.h @@ -0,0 +1,32 @@ +/* + Retrieve encoded MAC address from ATMEL ttpci_eeprom serial 2-wire EEPROM, + decode it and store it in associated adapter net device + + Robert Schlabbach GMX + Michael Glaum KVH Industries + Holger Waechtler Convergence + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __TTPCI_EEPROM_H__ +#define __TTPCI_EEPROM_H__ + +#include "dvb_i2c.h" + +extern int ttpci_eeprom_parse_mac (struct dvb_i2c_bus *i2c); + +#endif diff --git a/linux/drivers/media/dvb/ttpci/ttpci_eeprom.c b/linux/drivers/media/dvb/ttpci/ttpci_eeprom.c deleted file mode 100644 index aa9c68f0b..000000000 --- a/linux/drivers/media/dvb/ttpci/ttpci_eeprom.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - Retrieve encoded MAC address from ATMEL ttpci_eeprom serial 2-wire EEPROM, - decode it and store it in associated adapter net device - - Robert Schlabbach GMX - Michael Glaum KVH Industries - Holger Waechtler Convergence - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include -#include - -#include "dvb_i2c.h" -#include "dvb_functions.h" - -#if 0 -#define dprintk(x...) printk(x) -#else -#define dprintk(x...) -#endif - - -static -int ttpci_eeprom_read_encodedMAC (struct dvb_i2c_bus *i2c, u8 * encodedMAC ) -{ - int ret; - u8 b0 [] = { 0xd4 }; - struct i2c_msg msg [] = { { addr: 0x50, flags: 0, buf: b0, len: 1 }, - { addr: 0x50, flags: I2C_M_RD, buf: encodedMAC, len: 6 } }; - - dprintk ("%s\n", __FUNCTION__); - - ret = i2c->xfer (i2c, msg, 2); - - if (ret != 2) // Assume EEPROM isn't there - return( -ENODEV ); - - return 0; -} - -static -void decodeMAC (u8 *decodedMAC, const u8* encodedMAC) -{ - u8 ormask0[3] = { 0x54, 0x7B, 0x9E }; - u8 ormask1[3] = { 0xD3, 0xF1, 0x23 }; - u8 low; - u8 high; - u8 shift; - int i; - - decodedMAC[0] = 0x00; - decodedMAC[1] = 0xD0; - decodedMAC[2] = 0x5C; - - for (i=0; i<3; i++) { - low = encodedMAC[ 2*i ] ^ ormask0[i]; - high = encodedMAC[ 2*i+1 ] ^ ormask1[i]; - shift = ( high >> 6 ) & 0x3; - - decodedMAC[5-i] = ((high<<8) | low) >> shift; - } - -} - - -int ttpci_eeprom_parse_mac (struct dvb_i2c_bus *i2c) -{ - int ret; - u8 encodedMAC[6]; - u8 decodedMAC[6]; - - ret = ttpci_eeprom_read_encodedMAC(i2c, encodedMAC); - - if (ret != 0) { // Will only be -ENODEV - dprintk("Couldn't read from EEPROM: not there?\n"); - return ret; - } - - decodeMAC(decodedMAC, encodedMAC); - memcpy(i2c->adapter->proposed_mac, decodedMAC, 6); - - dprintk("%s adapter %i has MAC addr = %x:%x:%x:%x:%x:%x\n", - i2c->adapter->name, i2c->adapter->num, - decodedMAC[0],decodedMAC[1],decodedMAC[2], - decodedMAC[3],decodedMAC[4],decodedMAC[5]); - - return 0; -} - - diff --git a/linux/drivers/media/dvb/ttpci/ttpci_eeprom.h b/linux/drivers/media/dvb/ttpci/ttpci_eeprom.h deleted file mode 100644 index 66cb85ced..000000000 --- a/linux/drivers/media/dvb/ttpci/ttpci_eeprom.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Retrieve encoded MAC address from ATMEL ttpci_eeprom serial 2-wire EEPROM, - decode it and store it in associated adapter net device - - Robert Schlabbach GMX - Michael Glaum KVH Industries - Holger Waechtler Convergence - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef __TTPCI_EEPROM_H__ -#define __TTPCI_EEPROM_H__ - -#include "dvb_i2c.h" - -extern int ttpci_eeprom_parse_mac (struct dvb_i2c_bus *i2c); - -#endif -- cgit v1.2.3