halReturn_t HalInstallSilExtDeviceIrqHandler(fwIrqHandler_t irqHandler)
{
	int				retStatus;
	halReturn_t 	halRet;
	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}
    halRet = HalGetGpioIrqNumber(GPIO_V_INT, &gMhlDevice.SilExtDeviceIRQ);
    if(halRet!= HAL_RET_SUCCESS)
    {
        return halRet;
    } 
    gMhlDevice.ExtDeviceirqHandler = irqHandler;
	retStatus = request_threaded_irq(gMhlDevice.SilExtDeviceIRQ,NULL,
									 HalSilExtDeviceIrqHandler,
									 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
									 gMhlI2cIdTable[0].name,
									 &gMhlDevice);
	if(retStatus != 0)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: request_threaded_irq failed, status: %d\n",
				retStatus);
        gMhlDevice.ExtDeviceirqHandler = NULL;
		return HAL_RET_FAILURE;
	}
	return HAL_RET_SUCCESS;
}
halReturn_t HalInstallSilMonRequestIrqHandler(void)
{
	int				retStatus;
	halReturn_t 	halRet;
	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}
    halRet = HalGetGpioIrqNumber(GPIO_REQ_IN, &gMhlDevice.SilMonRequestIRQ);
    if(halRet!= HAL_RET_SUCCESS)
    {
        return halRet;
    }   
    spin_lock_init(&gMhlDevice.SilMonRequestIRQ_Lock);
    gMhlDevice.SilMonControlReleased  = true;
	retStatus = request_threaded_irq(gMhlDevice.SilMonRequestIRQ, NULL,
									 HalSilMonRequestIrqHandler,
									 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
									 gMhlI2cIdTable[0].name,
									 &gMhlDevice);
	if(retStatus != 0)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: request_threaded_irq failed, status: %d\n",
				retStatus);
		return HAL_RET_FAILURE;
	}
	return HAL_RET_SUCCESS;
}
/**
 * @brief Read a series of bytes from an I2c device using SMBus protocol.
 *
 *****************************************************************************/
halReturn_t HalSmbusReadBlock(uint8_t command, uint8_t *buffer, uint8_t *bufferLen)
{
	halReturn_t		retStatus;
	int32_t			status;
	
	retStatus = I2cAccessCheck();
	if (retStatus != HAL_RET_SUCCESS)
	{
		return retStatus;
	}

	if(*bufferLen > I2C_SMBUS_BLOCK_MAX)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"HalSmbusReadBlock, bufferLen param too big (%d) max size (%d)!\n",
    			*bufferLen, I2C_SMBUS_BLOCK_MAX);
        return HAL_RET_PARAMETER_ERROR;

	}
	status = i2c_smbus_read_i2c_block_data(gMhlDevice.pI2cClient, command,
										   *bufferLen, buffer);
	if (status < 0)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"i2c_smbus_read_i2c_block_data returned error: %d\n",status);
		return HAL_RET_FAILURE;
	}

	*bufferLen = (uint8_t)status;	/* return # of bytes read */
	
	return HAL_RET_SUCCESS;
}
/**
 * @brief Write a series of bytes to an I2c device using SMBus protocol.
 *
 *****************************************************************************/
halReturn_t HalSmbusWriteBlock(uint8_t command, uint8_t const *blockData,
								  uint8_t length)
{
	halReturn_t		retStatus;
	int32_t			status;
	
	retStatus = I2cAccessCheck();
	if (retStatus != HAL_RET_SUCCESS)
	{
		return retStatus;
	}

	if(length > I2C_SMBUS_BLOCK_MAX)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"HalSmbusWriteBlock, bufferLen param too big (%d) max size (%d)!\n",
    			length, I2C_SMBUS_BLOCK_MAX);
        return HAL_RET_PARAMETER_ERROR;

	}
	status = i2c_smbus_write_i2c_block_data(gMhlDevice.pI2cClient, command,
											length, blockData);
	if (status < 0)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"i2c_smbus_write_i2c_block_data returned error: %d\n",status);
		return HAL_RET_FAILURE;
	}

	return HAL_RET_SUCCESS;
}
/**
 * @brief Read a series of bytes from an I2c device.
 *
 *****************************************************************************/
halReturn_t HalI2cMasterRead(uint8_t i2cAddr, uint8_t length,
								uint8_t *buffer)
{
    struct i2c_msg	i2cMsg;
    
	halReturn_t		retStatus;
	int32_t			status;
	
	retStatus = I2cAccessCheck();
	if (retStatus != HAL_RET_SUCCESS)
	{
		return retStatus;
	}

    i2cMsg.addr = (i2cAddr >> 1);
    i2cMsg.flags = I2C_M_RD;
    i2cMsg.len = length;
    i2cMsg.buf = buffer;

    status = i2c_transfer(gMhlDevice.pI2cClient->adapter, &i2cMsg, 1);
	if (status < 0)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE, "i2c_transfer error: %d\n",status);
		return HAL_RET_FAILURE;
	}

	return HAL_RET_SUCCESS;
}
uint8_t I2C_ReadBlock(uint8_t deviceID, uint8_t offset,uint8_t *buf, uint8_t len)
{
    int i;
	uint8_t					accessI2cAddr;
	union i2c_smbus_data	data;
	int32_t					status;
	if (I2cAccessCheck() != HAL_RET_SUCCESS)
	{
		return 0x00;
	}
    accessI2cAddr = deviceID>>1; 
    memset(buf,0xff,len);
    for(i = 0 ;i < len;i++)
    {
        status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
        						0, I2C_SMBUS_READ, offset + i, I2C_SMBUS_BYTE_DATA,
        						&data);
    	if (status < 0)
    	{
            return 0;
    	}
        *buf = data.byte;
        buf++;
    }
    return len;
}
void I2C_WriteBlock(uint8_t deviceID, uint8_t offset, uint8_t *buf, uint8_t len)
{
    int i;
	uint8_t					accessI2cAddr;
	union i2c_smbus_data	data;
	int32_t					status;
	if (I2cAccessCheck() != HAL_RET_SUCCESS)
	{
		return ;
	}
    accessI2cAddr = deviceID>>1; 
    for(i = 0 ;i < len;i++)
    {
        data.byte = *buf;
        status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
        						0, I2C_SMBUS_WRITE, offset + i, I2C_SMBUS_BYTE_DATA,
        						&data);
    	if (status < 0)
    	{
            return ;
    	}
        buf++;
    }
    return ;
}
halReturn_t HalInstallIrqHandler(fwIrqHandler_t irqHandler)
{
	//int				retStatus;
	halReturn_t 	halRet;

	init_waitqueue_head(&mhl_irq_wq);
	
	mhl_irq_task = kthread_create(mhl_irq_kthread, NULL, "hdmi_update_kthread"); 
	wake_up_process(mhl_irq_task);

	
	if(irqHandler == NULL)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: irqHandler cannot be NULL!\n");
		return HAL_RET_PARAMETER_ERROR;
	}
	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}
	#if 0
	if(gMhlDevice.pI2cClient->irq == 0)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: No IRQ assigned to I2C device!\n");
		return HAL_RET_FAILURE;
	}
#endif


#if 0
	mt_set_gpio_mode(GPIO_MHL_EINT_PIN, GPIO_MODE_01);
	mt_set_gpio_dir(GPIO_MHL_EINT_PIN, GPIO_DIR_IN);
	mt_set_gpio_pull_select(GPIO_MHL_EINT_PIN,  GPIO_PULL_UP);
    mt_set_gpio_pull_enable(GPIO_MHL_EINT_PIN, true);
#endif
	mt65xx_eint_set_sens(CUST_EINT_MHL_NUM, MT65xx_LEVEL_SENSITIVE);
    mt65xx_eint_registration(CUST_EINT_MHL_NUM, 0, MT65XX_EINT_POL_NEG, &mhl8338_irq_handler, 0);

	#if 0
	gMhlDevice.irqHandler = irqHandler;
	retStatus = request_threaded_irq(gMhlDevice.pI2cClient->irq, NULL,
									 HalThreadedIrqHandler,
									 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
									 gMhlI2cIdTable[0].name,
									 &gMhlDevice);
	if(retStatus != 0)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: request_threaded_irq failed, status: %d\n",
				retStatus);
		gMhlDevice.irqHandler = NULL;
		return HAL_RET_FAILURE;
	}
	#endif
	return HAL_RET_SUCCESS;
}
uint8_t I2C_ReadBlock(uint8_t deviceID, uint8_t offset,uint8_t *buf, uint8_t len)
{
    //printk("hdmi enter %s (0x%02x, 0x%02x, 0x%02x)\n", __func__, deviceID, offset, len);
    int i;
    uint8_t					accessI2cAddr;
#if USE_DEFAULT_I2C_CODE
    union i2c_smbus_data	data;
#endif
    int32_t					status;
    u32 client_main_addr;
    if (I2cAccessCheck() != HAL_RET_SUCCESS)
    {
        return 0x00;
    }
    accessI2cAddr = deviceID>>1;

    //backup addr
    client_main_addr = gMhlDevice.pI2cClient->addr;
    gMhlDevice.pI2cClient->addr = accessI2cAddr;


    memset(buf,0xff,len);
    for(i = 0 ; i < len; i++)
    {
#if USE_DEFAULT_I2C_CODE
        status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
                                0, I2C_SMBUS_READ, offset + i, I2C_SMBUS_BYTE_DATA,
                                &data);
        if (status < 0)
        {
            return 0;
        }
        *buf = data.byte;
#else
        u8 tmp;
        tmp = offset + i;
        gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
        status = i2c_master_send(gMhlDevice.pI2cClient, (const char*)&tmp, 1);
        if (status < 0)
        {
            printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
                   deviceID, offset, status);
        }

        status = i2c_master_recv(gMhlDevice.pI2cClient, (char*)&tmp, 1);
        *buf = tmp;
#endif

        buf++;
    }

    /* restore default client address */
    gMhlDevice.pI2cClient->addr = client_main_addr;
    return len;
}
halReturn_t HalRemoveSilMonRequestIrqHandler(void)
{
	halReturn_t 	halRet;
	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}
	free_irq(gMhlDevice.SilMonRequestIRQ, &gMhlDevice);
	return HAL_RET_SUCCESS;
}
Example #11
0
void I2C_WriteBlock(uint8_t deviceID, uint8_t offset, uint8_t *buf, uint8_t len)
{
    //printk("hdmi enter %s (0x%02x, 0x%02x, 0x%02x)\n",__func__, deviceID, offset, len);
    int i;
    uint8_t					accessI2cAddr;
#if USE_DEFAULT_I2C_CODE
    union i2c_smbus_data	data;
#endif
    int32_t					status;
    u8 tmp[2] = {0};
    u32 client_main_addr;

    if (I2cAccessCheck() != HAL_RET_SUCCESS)
    {
        return ;
    }
    accessI2cAddr = deviceID>>1;

    //backup addr
    client_main_addr = gMhlDevice.pI2cClient->addr;
    gMhlDevice.pI2cClient->addr = accessI2cAddr;


    for(i = 0 ; i < len; i++)
    {
#if USE_DEFAULT_I2C_CODE
        data.byte = *buf;
        status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
                                0, I2C_SMBUS_WRITE, offset + i, I2C_SMBUS_BYTE_DATA,
                                &data);
#else
        tmp[0] = offset + i;
        tmp[1] = *buf;
        gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
        status = i2c_master_send( gMhlDevice.pI2cClient, (const char*)tmp, 2);

#endif
        if (status < 0)
        {
            /* restore default client address */
            gMhlDevice.pI2cClient->addr = client_main_addr;
            return ;
        }
        buf++;
    }

    /* restore default client address */
    gMhlDevice.pI2cClient->addr = client_main_addr;
    return ;
}
halReturn_t HalRemoveSilExtDeviceIrqHandler(void)
{
	halReturn_t 	halRet;
	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}
	if(gMhlDevice.ExtDeviceirqHandler == NULL)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalRemoveSilExtDeviceIrqHandler: no irqHandler installed!\n");
		return HAL_RET_FAILURE;
	}
	free_irq(gMhlDevice.SilExtDeviceIRQ, &gMhlDevice);
	return HAL_RET_SUCCESS;
}
Example #13
0
void I2C_WriteByte(uint8_t deviceID, uint8_t offset, uint8_t value)
{
    //printk("hdmi enter I2C_WriteByte(0x%02x, 0x%02x, 0x%02x) \n",
    //    deviceID, offset, value);

    uint8_t					accessI2cAddr;
#if USE_DEFAULT_I2C_CODE
    union i2c_smbus_data	data;
#endif
    int32_t					status;
    u32 client_main_addr;
    u8 buf[2];
    if (I2cAccessCheck() != HAL_RET_SUCCESS)
    {
        return;
    }
    accessI2cAddr = deviceID>>1;//?

    //backup addr
    client_main_addr = gMhlDevice.pI2cClient->addr;
    gMhlDevice.pI2cClient->addr = accessI2cAddr;

#if USE_DEFAULT_I2C_CODE
    data.byte = value;
    status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
                            0, I2C_SMBUS_WRITE, offset, I2C_SMBUS_BYTE_DATA,
                            &data);
#else
    gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
    buf[0] = offset;
    buf[1] = value;
    status = i2c_master_send( gMhlDevice.pI2cClient, (const char*)buf, 2 /*sizeof(buf)*/);
#endif

    if (status < 0)
    {
        printk("I2C_WriteByte(0x%02x, 0x%02x, 0x%02x), i2c_transfer error: %d\n",
               deviceID, offset, value, status);
    }

    /* restore default client address */
    gMhlDevice.pI2cClient->addr = client_main_addr;
}
Example #14
0
/**
 * @brief Install IRQ handler.
 *
 *****************************************************************************/
halReturn_t HalInstallIrqHandler(fwIrqHandler_t irqHandler)
{
	int				retStatus;
	halReturn_t 	halRet;

	if(irqHandler == NULL)
	{
		SII_DEBUG_PRINT(MSG_ERR,"HalInstallIrqHandler: irqHandler cannot be NULL!\n");
		return HAL_RET_PARAMETER_ERROR;
	}

	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}

	if(gMhlDevice.pI2cClient->irq == 0)
	{
		SII_DEBUG_PRINT(MSG_ERR,"HalInstallIrqHandler: No IRQ assigned to I2C device!\n");
		return HAL_RET_FAILURE;
	}

	gMhlDevice.irqHandler = irqHandler;

	aml_config_gpio_irq();

	retStatus = request_threaded_irq(gMhlDevice.pI2cClient->irq, NULL,
									 HalThreadedIrqHandler,
									 IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
									 gMhlI2cIdTable[0].name,
									 &gMhlDevice);

	if(retStatus != 0)
	{
		SII_DEBUG_PRINT(MSG_ERR,"sii5293 HalInstallIrqHandler: request_threaded_irq failed, status: %d\n",
				retStatus);
		gMhlDevice.irqHandler = NULL;
		return HAL_RET_FAILURE;
	}

	return HAL_RET_SUCCESS;
}
void I2C_WriteByte(uint8_t deviceID, uint8_t offset, uint8_t value)
{
	uint8_t					accessI2cAddr;
	union i2c_smbus_data	data;
	int32_t					status;
	if (I2cAccessCheck() != HAL_RET_SUCCESS)
	{
		return;
	}
    accessI2cAddr = deviceID>>1;
	data.byte = value;
    status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
    						0, I2C_SMBUS_WRITE, offset, I2C_SMBUS_BYTE_DATA,
    						&data);
	if (status < 0)
	{
		printk("I2C_WriteByte(0x%02x, 0x%02x, 0x%02x), i2c_transfer error: %d\n",
						deviceID, offset, value, status);
	}
}
/**
 * @brief Read a single byte from a register within an I2c device.
 *
 *****************************************************************************/
uint8_t I2C_ReadByte(uint8_t deviceID, uint8_t offset)
{
	uint8_t					accessI2cAddr;
	uint8_t					addrOffset;
	union i2c_smbus_data	data;
	int32_t					status;


	if (I2cAccessCheck() != HAL_RET_SUCCESS)
	{
		/* Driver expects failed I2C reads to return 0xFF */
		return 0xFF;
	}

	// Figure I2c address offset from base of I2c device to requested
	// I2c address.
	addrOffset = deviceID - BASE_I2C_ADDR;

	// Get REAL base address of the I2c device on the platform.
	accessI2cAddr = (uint8_t)(gMhlDevice.pI2cClient->addr << 1);

	// Calculate REAL I2c access address.
	accessI2cAddr += addrOffset;

	accessI2cAddr >>= 1;

    status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
    						0, I2C_SMBUS_READ, offset, I2C_SMBUS_BYTE_DATA,
    						&data);
	if (status < 0)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
    			deviceID, offset, status);
		data.byte = 0xFF;
	}

	return data.byte;
}
/**
 * @brief Write a word to an I2c device using SMBus protocol.
 *
 *****************************************************************************/
halReturn_t HalSmbusWriteWordData(uint8_t command, uint16_t wordData)
{
	halReturn_t		retStatus;
	int32_t			status;
	
	retStatus = I2cAccessCheck();
	if (retStatus != HAL_RET_SUCCESS)
	{
		return retStatus;
	}
	
	status = i2c_smbus_write_word_data(gMhlDevice.pI2cClient,
									   command, wordData);
	if (status < 0)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"i2c_smbus_write_word_data returned error: %d\n",status);
		return HAL_RET_FAILURE;
	}

	return HAL_RET_SUCCESS;
}
/**
 * @brief Read a byte from an I2c device using SMBus protocol.
 *
 *****************************************************************************/
halReturn_t HalSmbusReadByteData(uint8_t command, uint8_t *pRetByteRead)
{
	halReturn_t		retStatus;
	int32_t			status;
	
	retStatus = I2cAccessCheck();
	if (retStatus != HAL_RET_SUCCESS)
	{
		return retStatus;
	}
	
	status = i2c_smbus_read_byte_data(gMhlDevice.pI2cClient, command);
	if (status < 0)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"i2c_smbus_read_byte_data returned error: %d\n",status);
		return HAL_RET_FAILURE;
	}

	*pRetByteRead = (uint8_t)status;
	return HAL_RET_SUCCESS;
}
Example #19
0
/**
 * @brief Remove IRQ handler.
 *
 *****************************************************************************/
halReturn_t HalRemoveIrqHandler(void)
{
	halReturn_t 	halRet;

	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}

	if(gMhlDevice.irqHandler == NULL)
	{
		SII_DEBUG_PRINT(MSG_ERR,"HalRemoveIrqHandler: no irqHandler installed!\n");
		return HAL_RET_FAILURE;
	}

	free_irq(gMhlDevice.pI2cClient->irq, &gMhlDevice);

	gMhlDevice.irqHandler = NULL;

	return HAL_RET_SUCCESS;
}
uint8_t I2C_ReadByte(uint8_t deviceID, uint8_t offset)
{
	uint8_t					accessI2cAddr;
	union i2c_smbus_data	data;
	int32_t					status;
	if (I2cAccessCheck() != HAL_RET_SUCCESS)
	{
		return 0xFF;
	}
    accessI2cAddr = deviceID>>1;  
    status = i2c_smbus_xfer(gMhlDevice.pI2cClient->adapter, accessI2cAddr,
    						0, I2C_SMBUS_READ, offset, I2C_SMBUS_BYTE_DATA,
    						&data);
	if (status < 0)
	{
        if(deviceID != 0xfc)
        {
            printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
                            deviceID, offset, status);
        }
		data.byte = 0xFF;
	}
	return data.byte;
}
/**
 * @brief Linux implementation of CRA driver platform interface function
 * 		  SiiMasterI2cTransfer.
 *
 *****************************************************************************/
SiiPlatformStatus_t SiiMasterI2cTransfer(deviceAddrTypes_t busIndex,
										 SiiI2cMsg_t *pMsgs, uint8_t msgNum)
{
	uint8_t				idx;
	uint8_t				msgCount = 0;
    struct i2c_msg		i2cMsg[MAX_I2C_MESSAGES];
	uint8_t				*pBuffer = NULL;
    SiiPlatformStatus_t	siiStatus = PLATFORM_FAIL;
    int					i2cStatus;


    do {
    	if (I2cAccessCheck() != HAL_RET_SUCCESS)
    	{
    		break;
    	}

    	if(busIndex != DEV_I2C_0)
    	{
        	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
        			"SiiMasterI2cTransfer error: implementation supports" \
        			"only one I2C bus\n");
    		break;
    	}

    	if(msgNum > MAX_I2C_MESSAGES)
    	{
        	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
        			"SiiMasterI2cTransfer error: implementation supports" \
        			"only %d message segments\n", MAX_I2C_MESSAGES);
    		break;
    	}

    	// Function parameter checks passed, assume at this point that the
    	// function will complete successfully.
    	siiStatus = PLATFORM_SUCCESS;

    	for(idx=0; idx < msgNum; idx++) {
    		i2cMsg[idx].addr	= pMsgs[idx].addr >> 1;
    		i2cMsg[idx].buf		= pMsgs[idx].pBuf;
    		i2cMsg[idx].len		= pMsgs[idx].len;
    		i2cMsg[idx].flags	= (pMsgs[idx].cmdFlags & SII_MI2C_RD) ? I2C_M_RD : 0;
    		if(pMsgs[idx].cmdFlags & SII_MI2C_TEN) {
    			pMsgs[idx].cmdFlags |= I2C_M_TEN;
    		}
    		if(pMsgs[idx].cmdFlags & SII_MI2C_APPEND_NEXT_MSG) {
    			// Caller is asking that we append the buffer from the next
    			// message to this one.  We will do this IF there is a next
    			// message AND the direction of the two messages is the same
    			// AND we haven't already appended a message.

    			siiStatus = PLATFORM_INVALID_PARAMETER;
    			if(idx+1 < msgNum && pBuffer == NULL) {
    				if(!((pMsgs[idx].cmdFlags ^ pMsgs[idx+1].cmdFlags) & SII_MI2C_RD)) {

    					i2cMsg[idx].len += pMsgs[idx+1].len;

    				    pBuffer = kmalloc(i2cMsg[idx].len, GFP_KERNEL);
    				    if(pBuffer == NULL) {
    				    	siiStatus = PLATFORM_FAIL;
    				    	break;
    				    }

    				    i2cMsg[idx].buf = pBuffer;
    				    memmove(pBuffer, pMsgs[idx].pBuf, pMsgs[idx].len);
    				    memmove(&pBuffer[pMsgs[idx].len], pMsgs[idx+1].pBuf, pMsgs[idx+1].len);

    				    idx += 1;
    				    siiStatus = PLATFORM_SUCCESS;
    				}
    			}
    		}
    		msgCount++;
    	}

    	if(siiStatus != PLATFORM_SUCCESS) {
        	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
        			"SiiMasterI2cTransfer failed, returning error: %d\n", siiStatus);

    		if(pBuffer != NULL) {
        		kfree(pBuffer);
        	}

    		return siiStatus;
    	}

    	i2cStatus = i2c_transfer(gMhlDevice.pI2cClient->adapter, i2cMsg, msgCount);

    	if(pBuffer != NULL) {
    		kfree(pBuffer);
    	}

    	if(i2cStatus < msgCount)
    	{
    		// All the messages were not transferred, some sort of error occurred.
    		// Try to return the most appropriate error code to the caller.
    		if (i2cStatus < 0)
    		{
    	    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    	    			"SiiMasterI2cTransfer, i2c_transfer error: %d  " \
    	    			"deviceId: 0x%02x regOffset: 0x%02x\n",
    	    			i2cStatus, pMsgs->addr, *pMsgs->pBuf);
    			siiStatus = PLATFORM_FAIL;
    		}
    		else
    		{
    			// One or more messages transferred so error probably occurred on the
    			// first unsent message.  Look to see if the message was a read or write
    			// and set the appropriate return code.
    			if(pMsgs[i2cStatus].cmdFlags & SII_MI2C_RD)
    			{
    				siiStatus = PLATFORM_I2C_READ_FAIL;
    			}
    			else
    			{
    				siiStatus = PLATFORM_I2C_WRITE_FAIL;
    			}
    		}
    	}

	} while(0);

	return siiStatus;
}
Example #22
0
uint8_t I2C_ReadByte(uint8_t deviceID, uint8_t offset)
{
    //printk("hdmi enter I2C_ReadByte(0x%02x, 0x%02x)\n",
    //       deviceID, offset);

    uint8_t					accessI2cAddr;
    union i2c_smbus_data	data;
    int32_t					status;
    u32 client_main_addr;
    char buf;
    if (I2cAccessCheck() != HAL_RET_SUCCESS)
    {
        return 0xFF;
    }
    accessI2cAddr = deviceID>>1;

    //backup addr
    client_main_addr = gMhlDevice.pI2cClient->addr;
    gMhlDevice.pI2cClient->addr = accessI2cAddr;

#if 1
    gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
    status = i2c_master_send(gMhlDevice.pI2cClient, &offset, 1);
    if (status < 0)
    {
        printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
               deviceID, offset, status);
    }
    msleep(10);

    gMhlDevice.pI2cClient->ext_flag |= I2C_DIRECTION_FLAG;
    status = i2c_master_recv(gMhlDevice.pI2cClient, (char*)&buf, 1);
    data.byte = buf;

    if (status < 0)
    {
        if(deviceID != 0xfc)
        {
            printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
                   deviceID, offset, status);
        }
        data.byte = 0xFF;
    }
#else
    char buf = offset;
    u32 ext_flag = I2C_DIRECTION_FLAG | I2C_WR_FLAG;
    status = mt_i2c_master_send(gMhlDevice.pI2cClient, &buf, (1 << 8) | 1, ext_flag);

    data.byte = buf;

    if (status < 0)
    {
        if(deviceID != 0xfc)
        {
            printk("I2C_ReadByte(0x%02x, 0x%02x), i2c_transfer error: %d\n",
                   deviceID, offset, status);
        }
        data.byte = 0xFF;
    }
#endif

    //printk("hdmi exit I2C_ReadByte 0x%02x \n", data.byte);
    // restore default client address
    gMhlDevice.pI2cClient->addr = client_main_addr;
    return data.byte;
}
halReturn_t HalInstallIrqHandler(fwIrqHandler_t irqHandler)
{
	//int				retStatus;
	halReturn_t 	halRet;

	init_waitqueue_head(&mhl_irq_wq);
	
	mhl_irq_task = kthread_create(mhl_irq_kthread, NULL, "mhl_irq_kthread"); 
	wake_up_process(mhl_irq_task);

    #ifdef MTK_SMARTBOOK_SUPPORT
    //add by kirby
    init_waitqueue_head(&smartbook_wq);
	smartbook_task = kthread_create(smartbook_kthread, NULL, "smartbook_kthread"); 
	wake_up_process(smartbook_task);
    #endif
	
	if(irqHandler == NULL)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: irqHandler cannot be NULL!\n");
		return HAL_RET_PARAMETER_ERROR;
	}
	halRet = I2cAccessCheck();
	if (halRet != HAL_RET_SUCCESS)
	{
		return halRet;
	}
	#if 0
	if(gMhlDevice.pI2cClient->irq == 0)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: No IRQ assigned to I2C device!\n");
		return HAL_RET_FAILURE;
	}
#endif


#if 0
	mt_set_gpio_mode(GPIO_MHL_EINT_PIN, GPIO_MODE_01);
	mt_set_gpio_dir(GPIO_MHL_EINT_PIN, GPIO_DIR_IN);
	mt_set_gpio_pull_select(GPIO_MHL_EINT_PIN,  GPIO_PULL_UP);
    mt_set_gpio_pull_enable(GPIO_MHL_EINT_PIN, true);
#endif

#ifdef CUST_EINT_MHL_NUM
	///mt_eint_set_sens(CUST_EINT_MHL_NUM, MT_LEVEL_SENSITIVE);
	///mt_eint_set_hw_debounce(CUST_EINT_MHL_NUM, CUST_EINT_MHL_DEBOUNCE_CN);
    mt_eint_registration(CUST_EINT_MHL_NUM, CUST_EINT_MHL_TYPE, &mhl8338_irq_handler, 0);
    mt_eint_unmask(CUST_EINT_MHL_NUM);
#else
    printk("%s,%d Error: CUST_EINT_MHL_NUM is not defined\n", __func__, __LINE__);
#endif
	#if 0
	gMhlDevice.irqHandler = irqHandler;
	retStatus = request_threaded_irq(gMhlDevice.pI2cClient->irq, NULL,
									 HalThreadedIrqHandler,
									 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
									 gMhlI2cIdTable[0].name,
									 &gMhlDevice);
	if(retStatus != 0)
	{
		SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,"HalInstallIrqHandler: request_threaded_irq failed, status: %d\n",
				retStatus);
		gMhlDevice.irqHandler = NULL;
		return HAL_RET_FAILURE;
	}
	#endif
	return HAL_RET_SUCCESS;
}