unsigned int serial_out_i2c(unsigned int addr, int offset, int value) { //printk( "serial_out_i2c(%X):%X,%X\n", addr, offset, value ); unsigned short int data_hibyte; unsigned short int data_lowbyte; data_hibyte =(unsigned char) (value>>8); data_lowbyte =(unsigned char) (value & 0xff); if( addr != ALC5628_I2C_ADDR ) return 0; //printk("(%d)", __LINE__); // start i2c_start_condition( &alc5628_i2c_dev ); // addr + write i2c_serial_write_byte( &alc5628_i2c_dev, ALC5628_I2C_ADDR | ALC5628_I2C_WRITE ); // read ACK if( i2c_ACK( &alc5628_i2c_dev ) != 0 ) return 0; //printk("(%d)", __LINE__); // write register address i2c_serial_write_byte( &alc5628_i2c_dev, offset ); // read ACK if( i2c_ACK( &alc5628_i2c_dev ) != 0 ) return 0; //printk("(%d)", __LINE__); // write data hibyte i2c_serial_write_byte( &alc5628_i2c_dev, data_hibyte ); // read ACK if( i2c_ACK( &alc5628_i2c_dev ) != 0 ) return 0; //printk("(%d)", __LINE__); // write data lowbyte i2c_serial_write_byte( &alc5628_i2c_dev, data_lowbyte ); // read ACK if( i2c_ACK( &alc5628_i2c_dev ) != 0 ) return 0; //printk("(%d)", __LINE__); // stop i2c_stop_condition( &alc5628_i2c_dev ); return 0; }
unsigned int serial_in_i2c(unsigned int addr, int offset) { unsigned short int data_hibyte=0; unsigned short int data_lowbyte=0; unsigned short int data; //printk( "serial_in_i2c(%X):%X\n", addr, offset ); if( addr != ALC5628_I2C_ADDR ) return 0; // start i2c_start_condition( &alc5628_i2c_dev ); // addr + write i2c_serial_write_byte( &alc5628_i2c_dev, ALC5628_I2C_ADDR | ALC5628_I2C_WRITE ); // read ACK if( i2c_ACK( &alc5628_i2c_dev ) != 0 ) return 0; // write register address i2c_serial_write_byte( &alc5628_i2c_dev, offset ); // read ACK if( i2c_ACK( &alc5628_i2c_dev ) != 0 ) return 0; // start i2c_start_condition( &alc5628_i2c_dev ); // addr + read i2c_serial_write_byte( &alc5628_i2c_dev, ALC5628_I2C_ADDR | ALC5628_I2C_READ ); // read ACK if( i2c_ACK( &alc5628_i2c_dev ) != 0 ) return 0; // read data_hibyte i2c_serial_read( &alc5628_i2c_dev, &data_hibyte ); //write ACK i2c_ACK_w(&alc5628_i2c_dev, 0); // read data_lowbyte i2c_serial_read( &alc5628_i2c_dev, &data_lowbyte ); data = (data_hibyte<<8) | data_lowbyte; // write negative-ACK i2c_ACK_w( &alc5628_i2c_dev, 1 ); // stop i2c_stop_condition( &alc5628_i2c_dev ); //printk( "in[%X]\n", data ); return data; }
/* @func int | _rtl865xC_i2c_rawWrite_alc5621 | Write several bits to device @parm i2c_dev_t* | pI2C_Dev | Structure containing device information @parm unsigned char* | pDEV_ID | i2c id address @parm unsigned char* | pReg | i2c register address @parm unsigned short int* | pData | i2c data @comm */ static void __i2c_rawWrite_alc5621( i2c_dev_t* pI2C_Dev, const unsigned char *pDEV_ID, unsigned char *pReg, unsigned short int *pData) { int i; //char j; //unsigned int buf; unsigned char dev_id, reg, data_hibyte, data_lowbyte; if ((pData == NULL) || (pDEV_ID == NULL) || (pReg == NULL)) { printk("Wrong I2C write function\n"); return; } start_condition: dev_id = (*pDEV_ID<<1) & 0xfe; //shift DEV_ID 1-bit left and unset in writting operation reg = *pReg; data_hibyte =(unsigned char) (*pData>>8); data_lowbyte =(unsigned char) (*pData & 0xff); #if 1 i2c_start_condition( pI2C_Dev ); #else __i2c_initGpioPin(pI2C_Dev->sdio, GPIO_DIR_OUT, GPIO_INT_DISABLE);//change sdio to output __i2c_setGpioDataBit( pI2C_Dev->sdio, 1); /* raise sdio*/ __i2c_setGpioDataBit( pI2C_Dev->sclk, 1); /* raise sclk*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_setGpioDataBit( pI2C_Dev->sdio, 0); /* fall down sdio*//*start condition*/ //delay 2 us. #ifdef __kernel_used__ udelay(2*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<2000*I2C_RATING_FACTOR;i++); #endif #endif i2c_serial_write(pI2C_Dev,&dev_id);//write pDEV_ID,from MSB to LSB if (i2c_ACK(pI2C_Dev) != 0) goto start_condition; i2c_serial_write(pI2C_Dev,®);//write pReg,from MSB to LSB if (i2c_ACK(pI2C_Dev) != 0) goto start_condition; i2c_serial_write(pI2C_Dev,&data_hibyte);//write pData(hibtye),from MSB to LSB (bit15 - bit 8) if (i2c_ACK(pI2C_Dev) != 0) goto start_condition; i2c_serial_write(pI2C_Dev,&data_lowbyte);//write pData(lowbtye),from MSB to LSB (bit7 - bit 0) if (i2c_ACK(pI2C_Dev) != 0) goto start_condition; #if 1 i2c_stop_condition( pI2C_Dev ); #else __i2c_setGpioDataBit( pI2C_Dev->sclk, 0); /* fall down sclk*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_setGpioDataBit( pI2C_Dev->sclk, 1); /* raise sclk*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_initGpioPin(pI2C_Dev->sdio, GPIO_DIR_OUT, GPIO_INT_DISABLE);//change sdio to output __i2c_setGpioDataBit( pI2C_Dev->sdio, 1); /* raise sdio*//*stop condition*/ #endif return; }
/* @func int | _rtl865xC_i2c_rawRead | Read several bits from device @parm i2c_dev_t* | pI2C_Dev | Structure containing device information @parm unsigned char* | pDEV_ID | i2c id address @parm unsigned char* | pReg | i2c register address @parm unsigned short int* | pData | i2c data @comm */ static void __i2c_rawRead_alc5621( i2c_dev_t* pI2C_Dev, const unsigned char *pDEV_ID, unsigned char *pReg, unsigned short int *pData) { int i; unsigned short int buf; unsigned char dev_id, reg; if ((pData == NULL) || (pDEV_ID == NULL) || (pReg == NULL)) { printk("Wrong I2C Read function\n"); return; } start_condition_read: //dev_id = (*pDEV_ID<<1) | 0x01; //shift DEV_ID 1-bit left and set bit0 in reading operation dev_id = (*pDEV_ID<<1) & 0xfe; //shift DEV_ID 1-bit left and unset in writting operation reg = *pReg; *pData = 0; #if 1 i2c_start_condition( pI2C_Dev ); #else __i2c_initGpioPin(pI2C_Dev->sdio, GPIO_DIR_OUT, GPIO_INT_DISABLE);//change sdio to output __i2c_setGpioDataBit( pI2C_Dev->sdio, 1); /* raise sdio*/ __i2c_setGpioDataBit( pI2C_Dev->sclk, 1); /* raise sclk*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_setGpioDataBit( pI2C_Dev->sdio, 0); /* fall down sdio*//*start condition*/ //delay 2 us. #ifdef __kernel_used__ udelay(2*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<2000*I2C_RATING_FACTOR;i++); #endif #endif i2c_serial_write(pI2C_Dev,&dev_id);//write pDEV_ID,from MSB to LSB if (i2c_ACK(pI2C_Dev) != 0) goto start_condition_read; i2c_serial_write(pI2C_Dev,®);//write pReg,from MSB to LSB if (i2c_ACK(pI2C_Dev) != 0) goto start_condition_read; #if 1 i2c_start_condition( pI2C_Dev ); #else //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_initGpioPin(pI2C_Dev->sdio, GPIO_DIR_OUT, GPIO_INT_DISABLE);//change sdio to output __i2c_setGpioDataBit( pI2C_Dev->sdio, 1); /* raise sdio*/ __i2c_setGpioDataBit( pI2C_Dev->sclk, 1); /* raise sclk*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_setGpioDataBit( pI2C_Dev->sdio, 0); /* fall down sdio*//*start condition*/ //delay 2 us. #ifdef __kernel_used__ udelay(2*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<2000*I2C_RATING_FACTOR;i++); #endif #endif dev_id = (*pDEV_ID<<1) | 0x01; //shift DEV_ID 1-bit left and set bit0 in reading operation i2c_serial_write(pI2C_Dev,&dev_id);//write pDEV_ID,from MSB to LSB if (i2c_ACK(pI2C_Dev) != 0) goto start_condition_read; buf=0; //init buf data to 0 i2c_serial_read(pI2C_Dev,&buf);//read high byte data from device i2c_ACK_w(pI2C_Dev, 0); //write ACK i2c_serial_read(pI2C_Dev,pData);//read low byte data from device i2c_ACK_w(pI2C_Dev, 1); //write NACK *pData = *pData | (buf <<8); #if 1 i2c_stop_condition( pI2C_Dev ); #else __i2c_initGpioPin(pI2C_Dev->sdio, GPIO_DIR_OUT, GPIO_INT_DISABLE);//change sdio to output __i2c_setGpioDataBit( pI2C_Dev->sclk, 0); /* fall down sclk*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_setGpioDataBit( pI2C_Dev->sdio, 0); /* fall down sdio*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_setGpioDataBit( pI2C_Dev->sclk, 1); /* raise sclk*/ //delay 1 us. #ifdef __kernel_used__ udelay(1*I2C_RATING_FACTOR); #endif #ifdef __test_program_used__ for (i=0;i<1000*I2C_RATING_FACTOR;i++); #endif __i2c_setGpioDataBit( pI2C_Dev->sdio, 1); /* raise sdio*//*stop condition*/ #endif return; }