Пример #1
0
static int pcf8591_read_channel(struct device *dev, int channel)
{
    u8 value;
    struct i2c_client *client = to_i2c_client(dev);
    struct pcf8591_data *data = i2c_get_clientdata(client);

    mutex_lock(&data->update_lock);

    if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) {
        data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK)
                        | channel;
        i2c_smbus_write_byte(client, data->control);

        /* The first byte transmitted contains the conversion code of
           the previous read cycle. FLUSH IT! */
        i2c_smbus_read_byte(client);
    }
    value = i2c_smbus_read_byte(client);

    mutex_unlock(&data->update_lock);

    if ((channel == 2 && input_mode == 2) ||
            (channel != 3 && (input_mode == 1 || input_mode == 3)))
        return (10 * REG_TO_SIGNED(value));
    else
        return (10 * value);
}
//[*]--------------------------------------------------------------------------------------------------[*]
static int bh1780_measure(struct bh1780_data *bh1780)
{
	struct i2c_client *client = bh1780->client;
	int	low_data, high_data;

	/* read light sensor data */
	if(i2c_smbus_write_byte(bh1780->client, (BH1780_COMMAND_REG + BH1780_DATA_LOW_REG)) < 0)	{
		dev_err(&client->dev, "I2C write byte error: data=0x%02x\n", (BH1780_COMMAND_REG + BH1780_DATA_LOW_REG));
		goto err;
	}
	if((low_data = i2c_smbus_read_byte(client)) < 0)	{
		dev_err(&client->dev, "I2C read byte error\n");
		goto err;
	}

	if(i2c_smbus_write_byte(bh1780->client, (BH1780_COMMAND_REG + BH1780_DATA_HIGH_REG)) < 0)	{
		dev_err(&client->dev, "I2C write byte error: data=0x%02x\n", (BH1780_COMMAND_REG + BH1780_DATA_HIGH_REG));
		goto err;
	}
	if((high_data = i2c_smbus_read_byte(client)) < 0)	{
		dev_err(&client->dev, "I2C read byte error\n");
		goto err;
	}

	bh1780->light_data = BH1780_DATA_CAL(high_data, low_data);

err:

	return 0;
}
Пример #3
0
static int pcf8591_read_channel(struct device *dev, int channel)
{
    u8 value;
    struct i2c_client *client = to_i2c_client(dev);
    struct pcf8591_data *data = i2c_get_clientdata(client);

    mutex_lock(&data->update_lock);

    if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) {
        data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK)
                        | channel;
        i2c_smbus_write_byte(client, data->control);

        i2c_smbus_read_byte(client);
    }
    value = i2c_smbus_read_byte(client);

    mutex_unlock(&data->update_lock);

    if ((channel == 2 && input_mode == 2) ||
            (channel != 3 && (input_mode == 1 || input_mode == 3)))
        return 10 * REG_TO_SIGNED(value);
    else
        return 10 * value;
}
Пример #4
0
/**
 * Performs the read byte function.
 *
 * @param data	The ds2482 channel pointer
 * @return	The value read
 */
static u8 ds2482_w1_read_byte(void *data)
{
	struct ds2482_w1_chan *pchan = data;
	struct ds2482_data    *pdev = pchan->pdev;
	int result;

	mutex_lock(&pdev->access_lock);

	/* Select the channel */
	ds2482_wait_1wire_idle(pdev);
	if (pdev->w1_count > 1)
		ds2482_set_channel(pdev, pchan->channel);

	/* Send the read byte command */
	ds2482_send_cmd(pdev, DS2482_CMD_1WIRE_READ_BYTE);

	/* Wait until 1WB == 0 */
	ds2482_wait_1wire_idle(pdev);

	/* Select the data register */
	ds2482_select_register(pdev, DS2482_PTR_CODE_DATA);

	/* Read the data byte */
	result = i2c_smbus_read_byte(pdev->client);

	mutex_unlock(&pdev->access_lock);

	return result;
}
Пример #5
0
u8 SII9234_i2c_read(struct i2c_client *client, u8 reg)
{
	u8 ret;
	
	u16 ret1;

	u8 ret2;

	u32 ret3;
	
	if(!MHL_i2c_init)
	{
		SII_DEV_DBG("I2C not ready");
		return 0;
	}
	
	i2c_smbus_write_byte(client, reg);
	

	ret = i2c_smbus_read_byte(client);

	//printk("#######Read reg %x data %x\n", reg, ret);

	if (ret < 0)
	{
		SII_DEV_DBG("i2c read fail");
		return -EIO;
	}
	return ret;

}
Пример #6
0
static int mcsdl_prepare_program(void)
{
	int i;
	int ret = 0;
	int read_data = 0;
	uint8_t i2c_buffer[4] = {0x0F,							/* isp program flash cmd */
							0x00,							/* isp program timing value 0 */
							0x00,							/* isp program timing value 1 */
							0x78};							/* isp program timing value 2 */

	/* Write Program timing information */
	for(i=0; i<4; i++){
		ret = i2c_smbus_write_byte(g_client, i2c_buffer[i]);
		if( 0 != ret ){
			printk("mcsdl Write Program timing information error\n");
			return -1;
		}
		udelay(15);
	}
	udelay(500);

	/* Read Result */
	read_data = i2c_smbus_read_byte(g_client);
	if (read_data != 0x8F) {								/* 0x8F is prepare program flash OK status */	
		printk("mcsdl prepare program error\n");
		return -1;
	}
	ndelay(100);

	return 0;
}
Пример #7
0
static void qcikbd_work_handler(struct work_struct *_work)
{
	unsigned char scancode;
	unsigned int  keycode;

	struct i2ckbd_drv_data *ikbd_drv_data =
		container_of(_work, struct i2ckbd_drv_data, work);

	struct i2c_client *ikbdclient = ikbd_drv_data->ki2c_client;
	struct input_dev *ikbdev = ikbd_drv_data->qcikbd_dev;

	scancode = i2c_smbus_read_byte(ikbdclient);

	if (scancode == KEY_ACK_FA) {
		return;
	} else if (scancode == RC_KEY_FN) {
		ikbd_drv_data->fn = 0x80;     /* select keycode table  > 0x7F */
	} else {
		ikbd_drv_data->key_down = 1;
		if (scancode & RC_KEY_BREAK) {
			ikbd_drv_data->key_down = 0;
			if ((scancode & 0x7F) == RC_KEY_FN)
				ikbd_drv_data->fn = 0;
		}
		keycode = on2_keycode[(scancode & 0x7F) | ikbd_drv_data->fn];
		if (keycode != NOKEY) {
			input_report_key(ikbdev,
					 keycode,
					 ikbd_drv_data->key_down);
			input_sync(ikbdev);
		}
	}
}
Пример #8
0
static u8 l3g4200d_read_reg(struct i2c_client *client, u8 addr){
          s32 err = i2c_smbus_write_byte(client,addr);
          s32 val = i2c_smbus_read_byte(client);
     
          return (u8) val;

}
Пример #9
0
int main (void){
    int device_handle;
    if ((device_handle = open("/dev/i2c-1", O_RDWR)) < 0){
        printf("Error: Couldn't open device %d\n", device_handle);
        return 1;
    }

    if (ioctl(device_handle, I2C_SLAVE, 4) < 0){
        printf("Error: Couldn't find arduino on address!\n");
        return 1;
    }

    char data[4] = {0x65, 0x66, 0x67, 0x68};
    i2c_smbus_write_byte(device_handle, data[0]);
    i2c_smbus_write_byte(device_handle, data[1]);
    i2c_smbus_write_byte(device_handle, data[2]);
    i2c_smbus_write_byte(device_handle, data[3]);
    //write(device_handle, data, 4);
    char b = i2c_smbus_read_byte(device_handle);
    printf("%i\n",b);

    close(device_handle);

    return 0;
}
Пример #10
0
/* Single byte -- assumes channel selection already done */
static GOOD_OR_BAD DS2482_send_and_get(FILE_DESCRIPTOR_OR_ERROR file_descriptor, const BYTE wr, BYTE * rd)
{
    int read_back;
    BYTE c;

    /* Write data byte */
    if (i2c_smbus_write_byte_data(file_descriptor, DS2482_CMD_1WIRE_WRITE_BYTE, wr) < 0) {
        return gbBAD;
    }

    /* read status for done */
    RETURN_BAD_IF_BAD( DS2482_readstatus(&c, file_descriptor, DS2482_1wire_write_usec) ) ;

    /* Select the data register */
    if (i2c_smbus_write_byte_data(file_descriptor, DS2482_CMD_SET_READ_PTR, DS2482_READ_DATA_REGISTER) < 0) {
        return gbBAD;
    }

    /* Read the data byte */
    read_back = i2c_smbus_read_byte(file_descriptor);

    if (read_back < 0) {
        return gbBAD;
    }
    rd[0] = (BYTE) read_back;

    return gbGOOD;
}
Пример #11
0
static inline int aps_i2c_reg_read(struct aps_data *aps , int reg)
{
	int val = 0;
	int ret = 0;
	int i = 0;

	mutex_lock(&aps->mlock);

	/* First write reg, then read reg data, resolve i2c error */
	//val = i2c_smbus_read_byte_data(aps->client, reg);
	for( i = 0; i < 3; i++){
		ret = i2c_smbus_write_byte(aps->client, reg);
		if(ret >= 0)
			break;
	}
	if ( 3 == i )
		printk(KERN_ERR "%s: failed to write reg[%d], err=%d\n", __FUNCTION__, reg, val);

	for( i = 0; i < 3; i++){
		val = i2c_smbus_read_byte(aps->client);
		if(val >= 0)
			break;
	}
	if ( 3 == i )
		printk(KERN_ERR "%s: failed to read reg[%d], err=%d\n", __FUNCTION__, reg, val);

	mutex_unlock(&aps->mlock);

	return val;
}
Пример #12
0
int ps5101_i2c_read(struct i2c_client *client, u8 reg, u8* value)
{
	int ret;

	if (!MHL_i2c_init) {
		print_err("I2C not ready\n");
		return -EIO;
	}

	ret = i2c_smbus_write_byte(client, reg);
	if (ret < 0) {
		print_err("Write reg 0x%02x error\n", reg);
		return ret;
	}


	ret = i2c_smbus_read_byte(client);


	if (ret < 0) {
		print_err("I2C read fail\n");
		return -EIO;
	}

	*value = ret & 0x000000ff;
	return ret;

}
Пример #13
0
u8 sii9234_i2c_read(struct i2c_client *client, u8 reg)
{
	u8 ret;

	if (!mhl_i2c_init) {
		SII_DEV_DBG("I2C not ready");
		return 0;
	}

	ret = i2c_smbus_write_byte(client, reg);
	if (ret < 0) {
		printk(KERN_ERR	"%s() I2C cmd write error", __func__);
		return  -EIO;
	}


	ret = i2c_smbus_read_byte(client);

	if (ret < 0) {
		SII_DEV_DBG("i2c read fail");
		return -EIO;
	}

	return ret;

}
static int pure_sensord(void *arg)
{
	struct pure *p = arg;
	int s, slow, shigh, sxor;

	/* TODO: finish me! */
	while (!kthread_should_stop()) {
		set_current_state(TASK_INTERRUPTIBLE);
		schedule();

		pr_err("%s: running!\n", __func__);

		s = i2c_smbus_read_byte(&p->client);
		slow = (s & 0xf);
		shigh = (s & 0xf0) >> 4;
		sxor = slow ^ shigh;
		
		/* TODO: this isn't entirely correct! */
		if (sxor & 1) {
			p->a = (slow & 1) ? 1 : 0;
			complete(&p->ca);
		}
		if (sxor & 2) {
			p->b = (slow & 2) ? 1 : 0;
			complete(&p->cb);
		}
	}
	return 0;
}
static int i2c_touchkey_read_byte(struct cypress_touchkey_devdata *devdata,
					u8 *val)
{
	int ret;
	int retry = 2;

	down(&i2c_sem);

	while (true) {
		ret = i2c_smbus_read_byte(devdata->client);
		if (ret >= 0 ) {
			*val = ret;
			up(&i2c_sem);
			return 0;
		}

		dev_err(&devdata->client->dev, "i2c read error\n");
		if (!retry--)
			break;
		msleep(10);
	}

	up(&i2c_sem);

	return ret;
}
Пример #16
0
static int clear_alert(struct tmon_info *data)
{
	struct i2c_client *ara = data->ara;
	int alrt_stat;

	alrt_stat = i2c_smbus_read_byte(ara);
	return 0;
}
Пример #17
0
static int mcsdl_enter_download_mode(void)
{
	int i;
	int ret = 0;
	int read_data = 0;
	uint8_t enter_code[14] = { 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1 };

	/* CE set output and low */
	ret = gpio_tlmm_config(GPIO_CFG(TS_RESET_GPIO, 0, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_2MA), GPIO_ENABLE);
	ret = gpio_direction_output(TS_RESET_GPIO, 0);

	/* config SCL/SDA output mode and set low  */
	ret = gpio_tlmm_config(GPIO_CFG(TS_SCL_GPIO, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA), GPIO_ENABLE);
	ret = gpio_tlmm_config(GPIO_CFG(TS_SDA_GPIO, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA), GPIO_ENABLE);
	ret = gpio_direction_output(TS_SCL_GPIO, 0);
	ret = gpio_direction_output(TS_SDA_GPIO, 0);

	/* INTR set output and low */
	ret = gpio_tlmm_config(GPIO_CFG(TS_INT_GPIO, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA), GPIO_ENABLE);
	ret = gpio_direction_output(TS_INT_GPIO, 0);
	mdelay(100);

	ret = gpio_direction_output(TS_RESET_GPIO, 1);			/* CE set high */
	ret = gpio_direction_output(TS_SDA_GPIO, 1);			/* SDA set high */
	mdelay(25);												/* must delay 25msec */

	/* input download mode single */
	for (i=0; i<14; i++) {
		if( enter_code[i] ){
			ret = gpio_direction_output(TS_INT_GPIO, 1);	/* INTR set high */
		} else {
			ret = gpio_direction_output(TS_INT_GPIO, 0);	/* INTR set low */
		}

		ret = gpio_direction_output(TS_SCL_GPIO, 1);		/* SCL set high */
		udelay(15);
		ret = gpio_direction_output(TS_SCL_GPIO, 0);		/* SCL set low */
		ret = gpio_direction_output(TS_INT_GPIO, 0);		/* INTR set low */
		udelay(100);
	}
	ret = gpio_direction_output(TS_SCL_GPIO, 1);			/* SCL set high */
	udelay(100);
	ret = gpio_direction_output(TS_INT_GPIO, 1);			/* INTR set high */
	mdelay(1);

	/* config I/O to i2c mode */
	ret = gpio_tlmm_config(GPIO_CFG(TS_SCL_GPIO, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA), GPIO_ENABLE);
	ret = gpio_tlmm_config(GPIO_CFG(TS_SDA_GPIO, 1, GPIO_INPUT, GPIO_NO_PULL, GPIO_2MA), GPIO_ENABLE);
	mdelay(1);

	read_data = i2c_smbus_read_byte(g_client);
	if (read_data != 0x55) {							/* 0x55 is i2c slave ready status */
		printk("mcsdl enter download mode error\n");
		return -1;
	}

	return 0;		/* success */
}
Пример #18
0
int i2c_readbyte(int i2c_fd)
{
	int byte;
	if ((byte = i2c_smbus_read_byte(i2c_fd)) < 0) {
		// perror("Failed to read byte from I2C slave");
		return -1;
	}
	return byte;
}
Пример #19
0
Файл: i2c.c Проект: dinuand/mraa
uint8_t
mraa_i2c_read_byte(mraa_i2c_context dev)
{
    uint8_t byte = i2c_smbus_read_byte(dev->fh);
    if (byte < 0) {
        return -1;
    }
    return byte;
}
Пример #20
0
static int gw_pld_get8(struct gpio_chip *gc, unsigned offset)
{
	struct gw_pld *gw = gpiochip_get_data(gc);
	s32 val;

	val = i2c_smbus_read_byte(gw->client);

	return (val < 0) ? 0 : !!(val & BIT(offset));
}
static void tegra_camera_dump_port_switch_regs(struct nvhost_device *ndev)
{
#ifdef DEBUG
	u8 val;

	val = i2c_smbus_read_byte(port_switch);
	dev_info(&ndev->dev, "I2C switch reg = 0x%02x\n", val);
#endif
}
Пример #22
0
__u8 sensor_read(__u8 uRegAddr)
{
		u8 val;		
		//printk("sensor_read i2c_smbus_read_byte uRegAddr=0x%x\n",uRegAddr);
		i2c_smbus_write_byte(save_client, uRegAddr);
		//printk("sensor_read i2c_smbus_write_byte\n");
		val = i2c_smbus_read_byte(save_client);		
		return val;
}
Пример #23
0
static int bh1780_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	struct bh1780_data *bh1780;
	int err;

	/* setup private data */
	bh1780 = kzalloc(sizeof(struct bh1780_data), GFP_KERNEL);
	if (!bh1780) {
		err = -ENOMEM;
		goto error_0;
	}
	mutex_init(&bh1780->enable_mutex);
	mutex_init(&bh1780->data_mutex);

	/* setup i2c client */
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		err = -ENODEV;
		goto error_1;
	}
	i2c_set_clientdata(client, bh1780);
	bh1780->client = client;

	/* detect and init hardware */
	if ((err = bh1780_detect(client, NULL))) {
		goto error_1;
	}

	if((err = i2c_smbus_write_byte(bh1780->client, (BH1780_COMMAND_REG + BH1780_PART_REV_REG))) < 0)	{
		dev_err(&client->dev, "I2C write byte error: data=0x%02x\n", (BH1780_COMMAND_REG + BH1780_PART_REV_REG));
		goto error_1;
	}
	if((err = i2c_smbus_read_byte(client)) < 0)	{
		dev_err(&client->dev, "I2C read byte error\n");
		goto error_1;
	}
	
	dev_info(&client->dev, "%s found\n", id->name);
	dev_info(&client->dev, "part number=%d, rev=%d\n", ((err >> 4) & 0x0F), (err & 0x0F));

	bh1780_power_up(bh1780);	bh1780_set_delay(&client->dev, BH1780_DEFAULT_DELAY);

	/* setup driver interfaces */
	INIT_DELAYED_WORK(&bh1780->work, bh1780_work_func);
	
	if ((err = bh1780_input_init(bh1780)) < 0)		goto error_1;

	if ((err = sysfs_create_group(&bh1780->input->dev.kobj, &bh1780_attribute_group)) < 0)		goto error_2;

	return 0;

error_2:
	bh1780_input_fini(bh1780);
error_1:
	kfree(bh1780);
error_0:
	return err;
}
Пример #24
0
int i2cget(int file,int address)
{
	int i;
	i = -1;
	ioctl(file,I2C_SLAVE_FORCE,address);
	i = i2c_smbus_read_byte(file);
	printf("read = %d",i);
	return i;
}
Пример #25
0
int i2c_readbyte(int i2c_id)
{
	// printf ("Read byte %d\n", i2c_id);
	int data;
	data = i2c_smbus_read_byte(i2c_buses[i2c_id]);
	// data = wiringPiI2CRead (i2c_buses[i2c_id]);
	if (data < 0) return -1;
	else return data;
	//return mraa_i2c_read_byte (i2c_buses[i2c_bus]);	
}
Пример #26
0
static int ricoh_pmu_check_device(struct i2c_client *client)
{
    int ret = -1;

    ret = i2c_smbus_read_byte(client);
    if (ret < 0) {
        RICOH_DBG("%s, i2c xfer failed, ret:%d\n", __func__, ret);
    }
    return ret;
}
Пример #27
0
static int mcsdl_erase_flash(void)
{
	int i;
	int ret = 0;
	int read_data = 0;
	uint8_t i2c_buffer[4] = {0x0F, 						/* isp erase timing cmd */
							0x01, 						/* isp erase timing value 0 */
							0xD4, 						/* isp erase timing value 1 */
							0xC0};						/* isp erase timing value 2 */

	/* Send Erase Setting code */
	for(i=0; i<4; i++){
		ret = i2c_smbus_write_byte(g_client, i2c_buffer[i]);
		if( 0 != ret ){
			printk("mcsdl prepare erase flash error\n");
			return -1;
		}
		udelay(15);
	}
	udelay(500);

	/* Read Result */
	read_data = i2c_smbus_read_byte(g_client);
	if (read_data != 0x8F) {							/* isp ack prepare erase done */
		printk("mcsdl erase flash error0\n");
		return -1;
	}
	mdelay(1);

	/*Send Erase code */
	ret = i2c_smbus_write_byte(g_client, 0x02);
	if( 0 != ret ){
		printk("mcsdl send erase code error\n");
		return -1;
	}
	mdelay(45);
	read_data = i2c_smbus_read_byte(g_client);
	if (read_data != 0x82) {
		printk("mcsdl erase flash error1\n");
		return -1;
	}
	return 0;
}
Пример #28
0
static void pcf8591_init_client(struct i2c_client *client)
{
    struct pcf8591_data *data = i2c_get_clientdata(client);
    data->control = PCF8591_INIT_CONTROL;
    data->aout = PCF8591_INIT_AOUT;

    i2c_smbus_write_byte_data(client, data->control, data->aout);

    i2c_smbus_read_byte(client);
}
Пример #29
0
static int qcikbd_resume(struct device *dev)
{
	struct i2ckbd_drv_data *context = input_get_drvdata(g_qci_keyboard_dev);
	struct i2c_client *ikbdclient = context->ki2c_client;

	disable_irq_wake(context->qcikbd_irq);

	/* consume any keypress generated while suspended */
	i2c_smbus_read_byte(ikbdclient);
	return 0;
}
//[*]--------------------------------------------------------------------------------------------------[*]
static int bh1780_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	struct bh1780_data  *bh1780;
	int                 err;

	/* setup private data */
	bh1780 = kzalloc(sizeof(struct bh1780_data), GFP_KERNEL);
	if (!bh1780) {
		pr_err("%s: failed to allocate memory for module\n", __func__);
		return -ENOMEM;
	}

	i2c_set_clientdata(client, bh1780);

	dev_set_drvdata(&client->dev, bh1780);

	bh1780->client = client;

	/* detect and init hardware */
	if ((err = bh1780_detect(client, NULL)) != 0)   goto error;

	if((err = i2c_smbus_write_byte(bh1780->client, (BH1780_COMMAND_REG + BH1780_PART_REV_REG))) < 0)	{
		dev_err(&client->dev, "I2C write byte error: data=0x%02x\n", (BH1780_COMMAND_REG + BH1780_PART_REV_REG));
		goto error;
	}
	if((err = i2c_smbus_read_byte(client)) < 0)	{
		dev_err(&client->dev, "I2C read byte error\n");
		goto error;
	}

	dev_info(&client->dev, "%s found\n", id->name);
	dev_info(&client->dev, "part number=%d, rev=%d\n", ((err >> 4) & 0x0F), (err & 0x0F));

	bh1780_power_up(bh1780);

	INIT_DELAYED_WORK(&bh1780->work, bh1780_work_func);

	#if defined(CONFIG_ODROID_EXYNOS5_IOBOARD_DEBUG)
		bh1780->enabled = 1;
	#endif

	if(bh1780->enabled) schedule_delayed_work(&bh1780->work, BH1780_WORK_PERIOD);

	if ((err = sysfs_create_group(&client->dev.kobj, &bh1780_attribute_group)) < 0)		goto error;

	printk("\n=================== ioboard_%s ===================\n\n", __func__);

	return 0;

error:
	printk("\n=================== ioboard_%s FAIL! ===================\n\n", __func__);

	return err;
}