*/
while (peekIO(0x3ce, 0x61) & 0x10);
#else
- int i, Temp;
+ int i, tmp;
for (i = 0; i < 600; i++) {
- Temp = i;
- Temp += i;
+ tmp = i;
+ tmp += i;
}
#endif
}
*/
static void sw_i2c_scl(unsigned char value)
{
- unsigned long ulGPIOData;
- unsigned long ulGPIODirection;
+ unsigned long gpio_data;
+ unsigned long gpio_dir;
- ulGPIODirection = PEEK32(sw_i2c_clk_gpio_data_dir_reg);
+ gpio_dir = PEEK32(sw_i2c_clk_gpio_data_dir_reg);
if (value) { /* High */
/* Set direction as input. This will automatically pull the signal up. */
- ulGPIODirection &= ~(1 << sw_i2c_clk_gpio);
- POKE32(sw_i2c_clk_gpio_data_dir_reg, ulGPIODirection);
+ gpio_dir &= ~(1 << sw_i2c_clk_gpio);
+ POKE32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir);
} else { /* Low */
/* Set the signal down */
- ulGPIOData = PEEK32(sw_i2c_clk_gpio_data_reg);
- ulGPIOData &= ~(1 << sw_i2c_clk_gpio);
- POKE32(sw_i2c_clk_gpio_data_reg, ulGPIOData);
+ gpio_data = PEEK32(sw_i2c_clk_gpio_data_reg);
+ gpio_data &= ~(1 << sw_i2c_clk_gpio);
+ POKE32(sw_i2c_clk_gpio_data_reg, gpio_data);
/* Set direction as output */
- ulGPIODirection |= (1 << sw_i2c_clk_gpio);
- POKE32(sw_i2c_clk_gpio_data_dir_reg, ulGPIODirection);
+ gpio_dir |= (1 << sw_i2c_clk_gpio);
+ POKE32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir);
}
}
*/
static void sw_i2c_sda(unsigned char value)
{
- unsigned long ulGPIOData;
- unsigned long ulGPIODirection;
+ unsigned long gpio_data;
+ unsigned long gpio_dir;
- ulGPIODirection = PEEK32(sw_i2c_data_gpio_data_dir_reg);
+ gpio_dir = PEEK32(sw_i2c_data_gpio_data_dir_reg);
if (value) { /* High */
/* Set direction as input. This will automatically pull the signal up. */
- ulGPIODirection &= ~(1 << sw_i2c_data_gpio);
- POKE32(sw_i2c_data_gpio_data_dir_reg, ulGPIODirection);
+ gpio_dir &= ~(1 << sw_i2c_data_gpio);
+ POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
} else { /* Low */
/* Set the signal down */
- ulGPIOData = PEEK32(sw_i2c_data_gpio_data_reg);
- ulGPIOData &= ~(1 << sw_i2c_data_gpio);
- POKE32(sw_i2c_data_gpio_data_reg, ulGPIOData);
+ gpio_data = PEEK32(sw_i2c_data_gpio_data_reg);
+ gpio_data &= ~(1 << sw_i2c_data_gpio);
+ POKE32(sw_i2c_data_gpio_data_reg, gpio_data);
/* Set direction as output */
- ulGPIODirection |= (1 << sw_i2c_data_gpio);
- POKE32(sw_i2c_data_gpio_data_dir_reg, ulGPIODirection);
+ gpio_dir |= (1 << sw_i2c_data_gpio);
+ POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
}
}
*/
static unsigned char sw_i2c_read_sda(void)
{
- unsigned long ulGPIODirection;
- unsigned long ulGPIOData;
+ unsigned long gpio_dir;
+ unsigned long gpio_data;
/* Make sure that the direction is input (High) */
- ulGPIODirection = PEEK32(sw_i2c_data_gpio_data_dir_reg);
- if ((ulGPIODirection & (1 << sw_i2c_data_gpio)) != (~(1 << sw_i2c_data_gpio))) {
- ulGPIODirection &= ~(1 << sw_i2c_data_gpio);
- POKE32(sw_i2c_data_gpio_data_dir_reg, ulGPIODirection);
+ gpio_dir = PEEK32(sw_i2c_data_gpio_data_dir_reg);
+ if ((gpio_dir & (1 << sw_i2c_data_gpio)) != (~(1 << sw_i2c_data_gpio))) {
+ gpio_dir &= ~(1 << sw_i2c_data_gpio);
+ POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
}
/* Now read the SDA line */
- ulGPIOData = PEEK32(sw_i2c_data_gpio_data_reg);
- if (ulGPIOData & (1 << sw_i2c_data_gpio))
+ gpio_data = PEEK32(sw_i2c_data_gpio_data_reg);
+ if (gpio_data & (1 << sw_i2c_data_gpio))
return 1;
else
return 0;
* This function initializes GPIO port for SW I2C communication.
*
* Parameters:
- * i2cClkGPIO - The GPIO pin to be used as i2c SCL
- * i2cDataGPIO - The GPIO pin to be used as i2c SDA
+ * clk_gpio - The GPIO pin to be used as i2c SCL
+ * data_gpio - The GPIO pin to be used as i2c SDA
*
* Return Value:
* -1 - Fail to initialize the i2c
* 0 - Success
*/
-static long sm750le_i2c_init(unsigned char i2cClkGPIO,
- unsigned char i2cDataGPIO)
+static long sm750le_i2c_init(unsigned char clk_gpio,
+ unsigned char data_gpio)
{
int i;
sw_i2c_clk_gpio_data_dir_reg = GPIO_DATA_DIRECTION_SM750LE;
/* Initialize the Clock GPIO Offset */
- sw_i2c_clk_gpio = i2cClkGPIO;
+ sw_i2c_clk_gpio = clk_gpio;
/* Initialize the GPIO pin for the i2c Data Register */
sw_i2c_data_gpio_data_reg = GPIO_DATA_SM750LE;
sw_i2c_data_gpio_data_dir_reg = GPIO_DATA_DIRECTION_SM750LE;
/* Initialize the Data GPIO Offset */
- sw_i2c_data_gpio = i2cDataGPIO;
+ sw_i2c_data_gpio = data_gpio;
/* Note that SM750LE don't have GPIO MUX and power is always on */
* This function initializes the i2c attributes and bus
*
* Parameters:
- * i2cClkGPIO - The GPIO pin to be used as i2c SCL
- * i2cDataGPIO - The GPIO pin to be used as i2c SDA
+ * clk_gpio - The GPIO pin to be used as i2c SCL
+ * data_gpio - The GPIO pin to be used as i2c SDA
*
* Return Value:
* -1 - Fail to initialize the i2c
* 0 - Success
*/
long sm750_sw_i2c_init(
- unsigned char i2cClkGPIO,
- unsigned char i2cDataGPIO
+ unsigned char clk_gpio,
+ unsigned char data_gpio
)
{
int i;
/* Return 0 if the GPIO pins to be used is out of range. The range is only from [0..63] */
- if ((i2cClkGPIO > 31) || (i2cDataGPIO > 31))
+ if ((clk_gpio > 31) || (data_gpio > 31))
return -1;
if (getChipType() == SM750LE)
- return sm750le_i2c_init(i2cClkGPIO, i2cDataGPIO);
+ return sm750le_i2c_init(clk_gpio, data_gpio);
/* Initialize the GPIO pin for the i2c Clock Register */
sw_i2c_clk_gpio_mux_reg = GPIO_MUX;
sw_i2c_clk_gpio_data_dir_reg = GPIO_DATA_DIRECTION;
/* Initialize the Clock GPIO Offset */
- sw_i2c_clk_gpio = i2cClkGPIO;
+ sw_i2c_clk_gpio = clk_gpio;
/* Initialize the GPIO pin for the i2c Data Register */
sw_i2c_data_gpio_mux_reg = GPIO_MUX;
sw_i2c_data_gpio_data_dir_reg = GPIO_DATA_DIRECTION;
/* Initialize the Data GPIO Offset */
- sw_i2c_data_gpio = i2cDataGPIO;
+ sw_i2c_data_gpio = data_gpio;
/* Enable the GPIO pins for the i2c Clock and Data (GPIO MUX) */
POKE32(sw_i2c_clk_gpio_mux_reg,
* This function reads the slave device's register
*
* Parameters:
- * deviceAddress - i2c Slave device address which register
+ * addr - i2c Slave device address which register
* to be read from
- * registerIndex - Slave device's register to be read
+ * reg - Slave device's register to be read
*
* Return Value:
* Register value
*/
unsigned char sm750_sw_i2c_read_reg(
- unsigned char deviceAddress,
- unsigned char registerIndex
+ unsigned char addr,
+ unsigned char reg
)
{
unsigned char data;
sw_i2c_start();
/* Send the device address */
- sw_i2c_write_byte(deviceAddress);
+ sw_i2c_write_byte(addr);
/* Send the register index */
- sw_i2c_write_byte(registerIndex);
+ sw_i2c_write_byte(reg);
/* Get the bus again and get the data from the device read address */
sw_i2c_start();
- sw_i2c_write_byte(deviceAddress + 1);
+ sw_i2c_write_byte(addr + 1);
data = sw_i2c_read_byte(1);
/* Stop swI2C and release the bus */
* This function writes a value to the slave device's register
*
* Parameters:
- * deviceAddress - i2c Slave device address which register
+ * addr - i2c Slave device address which register
* to be written
- * registerIndex - Slave device's register to be written
+ * reg - Slave device's register to be written
* data - Data to be written to the register
*
* Result:
* -1 - Fail
*/
long sm750_sw_i2c_write_reg(
- unsigned char deviceAddress,
- unsigned char registerIndex,
+ unsigned char addr,
+ unsigned char reg,
unsigned char data
)
{
- long returnValue = 0;
+ long ret = 0;
/* Send the Start signal */
sw_i2c_start();
/* Send the device address and read the data. All should return success
in order for the writing processed to be successful
*/
- if ((sw_i2c_write_byte(deviceAddress) != 0) ||
- (sw_i2c_write_byte(registerIndex) != 0) ||
+ if ((sw_i2c_write_byte(addr) != 0) ||
+ (sw_i2c_write_byte(reg) != 0) ||
(sw_i2c_write_byte(data) != 0)) {
- returnValue = -1;
+ ret = -1;
}
/* Stop i2c and release the bus */
sw_i2c_stop();
- return returnValue;
+ return ret;
}