예제 #1
0
파일: tsl2550.c 프로젝트: avagin/linux
static int tsl2550_set_power_state(struct i2c_client *client, int state)
{
	struct tsl2550_data *data = i2c_get_clientdata(client);
	int ret;

	if (state == 0)
		ret = i2c_smbus_write_byte(client, TSL2550_POWER_DOWN);
	else {
		ret = i2c_smbus_write_byte(client, TSL2550_POWER_UP);

		/* On power up we should reset operating mode also... */
		tsl2550_set_operating_mode(client, data->operating_mode);
	}

	data->power_state = state;

	return ret;
}
예제 #2
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;
}
예제 #3
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;
}
예제 #4
0
파일: tsl2550.c 프로젝트: 19Dan01/linux
static int tsl2550_set_operating_mode(struct i2c_client *client, int mode)
{
	struct tsl2550_data *data = i2c_get_clientdata(client);

	int ret = i2c_smbus_write_byte(client, TSL2550_MODE_RANGE[mode]);

	data->operating_mode = mode;

	return ret;
}
예제 #5
0
static int bh1721fvc_write_byte(struct i2c_client *client, u8 value)
{
	int retry;

	for (retry = 0; retry < 5; retry++)
		if (!i2c_smbus_write_byte(client, value))
			return 0;

	return -EIO;
}
static int max1363_smbus_send(const struct i2c_client *client, const char *buf,
		int count)
{
	int i, err;

	for (i = err = 0; err == 0 && i < count; ++i)
		err = i2c_smbus_write_byte(client, buf[i]);

	return err ? err : count;
}
예제 #7
0
static int i2c_write_1b(struct eeprom *e, __u8 buf)
{
	int r;
	// we must simulate a plain I2C byte write with SMBus functions
	r = i2c_smbus_write_byte(e->fd, buf);
	if(r < 0)
		fprintf(stderr, "Error i2c_write_1b: %s\n", strerror(errno));
	usleep(10);
	return r;
}
예제 #8
0
파일: smbus_rw.c 프로젝트: jetma/iotools
static int
smbus_write_op(struct smbus_op_params *params, const struct smbus_op *op)
{
	int result;

	/* FIXME: Why is this needed if the open_i2c_slave performs the ioctl
	 * with I2C_SLAVE? */
	/* Double cast the last argument for compat with klibc. */
	if (ioctl(params->fd, I2C_SLAVE_FORCE,
	          (void *)(intptr_t)params->address) < 0) {
		fprintf(stderr, "can't set address 0x%02X, %s\n",
		        params->address, strerror(errno));
		return -1;
	}

	switch (op->size) {
	case SMBUS_SIZE_8:
		result = i2c_smbus_write_byte_data(params->fd, params->reg,
		             params->data.fixed.u8);
		break;
	case SMBUS_SIZE_16:
		result = i2c_smbus_write_word_data(params->fd, params->reg,
		             params->data.fixed.u16);
		break;
	case SMBUS_SIZE_BLOCK:
		result = i2c_smbus_write_block_data(params->fd, params->reg,
		             params->len, params->data.array);
		break;
	case SMBUS_SIZE_BYTE:
		result = i2c_smbus_write_byte(params->fd,
		                              params->data.fixed.u8);
		break;
	case SMBUS_QUICK:
		result = i2c_smbus_write_quick(params->fd,
		                              params->data.fixed.u8);
		break;
	default:
		fprintf(stderr, "Illegal SMBus size for write operation.\n");
		return -1;
	}

	if (result < 0) {
		if (op->size != SMBUS_SIZE_BYTE && op->size != SMBUS_QUICK) {
			fprintf(stderr, "can't write register 0x%02X, %s\n",
			        params->reg, strerror(errno));
		} else {
			fprintf(stderr, "can't write to device 0x%02X, %s\n",
			        params->address, strerror(errno));
		}
		return -1;
	}

	return 0;
}
예제 #9
0
static int gw_pld_output8(struct gpio_chip *gc, unsigned offset, int value)
{
	struct gw_pld *gw = gpiochip_get_data(gc);

	if (value)
		gw->out |= BIT(offset);
	else
		gw->out &= ~BIT(offset);

	return i2c_smbus_write_byte(gw->client, gw->out);
}
예제 #10
0
static int apds9801_set_command(struct i2c_client *client, int command)
{
	struct apds9801_data *data = i2c_get_clientdata(client);
	int ret;

	mutex_lock(&data->update_lock);
	ret = i2c_smbus_write_byte(client, command);
	mutex_unlock(&data->update_lock);

	return ret;
}
예제 #11
0
파일: qt2160.c 프로젝트: CSCLOG/beaglebone
static int __devinit qt2160_write(struct i2c_client *client, u8 reg, u8 data)
{
	int error;

	error = i2c_smbus_write_byte(client, reg);
	if (error) {
		dev_err(&client->dev,
			"couldn't send request. Returned %d\n", error);
		return error;
	}

	error = i2c_smbus_write_byte(client, data);
	if (error) {
		dev_err(&client->dev,
			"couldn't write data. Returned %d\n", error);
		return error;
	}

	return error;
}
예제 #12
0
static int bh1721fvc_write_byte(struct i2c_client *client, u8 value)
{
	int retry;

	for (retry = 0; retry < 10; retry++)
		if (!i2c_smbus_write_byte(client, value))
			return 0;

	printk("I2C read failed.. retry %d\n", retry);
	return -EIO;
}
//[*]--------------------------------------------------------------------------------------------------[*]
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;
}
예제 #14
0
static int elan_smbus_iap_reset(struct i2c_client *client)
{
	int error;

	error = i2c_smbus_write_byte(client, ETP_SMBUS_IAP_RESET_CMD);
	if (error) {
		dev_err(&client->dev, "cannot reset IC: %d\n", error);
		return error;
	}

	return 0;
}
예제 #15
0
static int blinkm_write(struct i2c_client *client, int cmd, u8 *arg)
{
	int result;
	int i;
	int arglen = blinkm_cmds[cmd].nr_args;
	/* write out cmd to blinkm - always / default step */
	result = i2c_smbus_write_byte(client, blinkm_cmds[cmd].cmdbyte);
	if (result < 0)
		return result;
	/* no args to write out */
	if (arglen == 0)
		return 0;

	for (i = 0; i < arglen; i++) {
		/* repeat for arglen */
		result = i2c_smbus_write_byte(client, arg[i]);
		if (result < 0)
			return result;
	}
	return 0;
}
예제 #16
0
/* Enable the mux to select a particular channel */
int
lightning_flash_mux_sel_chan(uint8_t mux, uint8_t channel) {

  int dev;
  int ret;
  uint8_t addr;
  uint8_t chan_en;
  char bus[32];

  if (mux == I2C_MUX_FLASH1)
    sprintf(bus, "%s", I2C_DEV_FLASH1);
  else if (mux == I2C_MUX_FLASH2)
    sprintf(bus, "%s", I2C_DEV_FLASH2);

  dev = open(bus, O_RDWR);
  if (dev < 0) {
    syslog(LOG_ERR, "lightning_flash_mux_sel_chan: open() failed");
    return -1;
  }

  switch(mux) {
    case I2C_MUX_FLASH1:
      addr = I2C_MUX_FLASH1_ADDR,
      chan_en = (1 << 3) | channel;
      break;

    case I2C_MUX_FLASH2:
      addr = I2C_MUX_FLASH2_ADDR,
      chan_en = (1 << 3) | channel;
      break;
  }

  /* Assign the i2c device address */
  ret = ioctl(dev, I2C_SLAVE, addr);
  if (ret < 0) {
    syslog(LOG_ERR, "lightning_flash_mux_sel_chan: ioctl() assigning i2c addr failed");
    close(dev);
    return -1;
  }

  /* Write the channel number to enable it */
  ret = i2c_smbus_write_byte(dev, chan_en);
  if (ret < 0) {
    syslog(LOG_ERR, "lightning_flash_mux_sel_chan: i2c_smbus_write_byte failed");
    close(dev);
    return -1;
  }

  close(dev);

  return 0;
}
예제 #17
0
char write_mark1_reg(unsigned char add){
    int resp = 0 ;
    if (ioctl(i2c_bus -> file, I2C_SLAVE, MARK1_ADDR) < 0) {
        /* ERROR HANDLING; you can check errno to see what went wrong */
        exit(1);
    }
    resp = i2c_smbus_write_byte(i2c_bus -> file, add);
    if (resp < 0) {
    	printf("error accessing i2c bus , returned :%d \n", resp);    
	exit(-1);    
    }
    return resp;
}
예제 #18
0
파일: myI2C.c 프로젝트: Cragjock/LCDI2C
int myI2C_write_byte(int file, uint8_t data)
{
    int res = i2c_smbus_write_byte(file, data);
    /** S Addr Wr [A] Data [A] P **/
    if (res<0)
    {
        printf("result i2c write error");
        return -1;
    }

    //printf("after mode 1 write: 0x%02X to register 0x%02X \n", buf[1], buf[0]);
    return 0;
}
static struct pem_data *pem_update_device(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct pem_data *data = i2c_get_clientdata(client);
	struct pem_data *ret = data;

	mutex_lock(&data->update_lock);

	if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
		int result;

		/* Read data string */
		result = pem_read_block(client, PEM_READ_DATA_STRING,
					data->data_string,
					sizeof(data->data_string));
		if (unlikely(result < 0)) {
			ret = ERR_PTR(result);
			goto abort;
		}

		/* Read input string */
		if (data->input_length) {
			result = pem_read_block(client, PEM_READ_INPUT_STRING,
						data->input_string,
						data->input_length);
			if (unlikely(result < 0)) {
				ret = ERR_PTR(result);
				goto abort;
			}
		}

		/* Read fan speeds */
		if (data->fans_supported) {
			result = pem_read_block(client, PEM_READ_FAN_SPEED,
						data->fan_speed,
						sizeof(data->fan_speed));
			if (unlikely(result < 0)) {
				ret = ERR_PTR(result);
				goto abort;
			}
		}

		i2c_smbus_write_byte(client, PEM_CLEAR_INFO_FLAGS);

		data->last_updated = jiffies;
		data->valid = 1;
	}
abort:
	mutex_unlock(&data->update_lock);
	return ret;
}
예제 #20
0
파일: dialog.cpp 프로젝트: yoos/school
void openfile()
{
    //open the device file
    snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
    file = open(filename, O_RDWR);

    if (file < 0)
    {
        printf("Failed to open i2c device.\n");
        exit(1);
    }

    //specify what device address you want to communicate

    int addr = 0x52;	 //address for nunchuck

		//Access the I2C slave

    if(ioctl(file, I2C_SLAVE, addr) < 0)
    {
        printf("Failed to acquire bus access to slave.\n");
        printf("error..., something is wrong %s\n", strerror(errno));
        exit(1);
    }

		//TODO: write initialization data to the nunchuk.
        //if it returns with error (-1) exit with status 1\

    // Initialize white nunchuck
//    if(i2c_smbus_write_byte(file, 0x40) == -1) {
//        printf("error..., something is wrong  gvcn jhbv %s\n", strerror(errno));
//        exit(1);
//    }
//    if(i2c_smbus_write_byte(file, 0x00) == -1) {
//        printf("error..., something is wrong %s\n", strerror(errno));
//        exit(1);
//    }

    if(i2c_smbus_write_byte_data(file, 0x40, 0x00) == -1)
    {
        printf("error..., something is wrong %s\n", strerror(errno));
        exit(1);
    }

    if(i2c_smbus_write_byte(file, 0x00) == -1) {
        printf("error..., something is wrong %s\n", strerror(errno));
        exit(1);
    }

}
예제 #21
0
static int ov7670_read(struct i2c_client *c, unsigned char reg,
		unsigned char *value)
{
	int ret;

	i2c_smbus_write_byte(c, reg);
	*value = i2c_smbus_read_byte(c);
	return 0;

	ret = i2c_smbus_read_byte_data(c, reg);
	if (ret >= 0)
		*value = (unsigned char) ret;
	return ret;
}
예제 #22
0
static int max732x_writeb(struct max732x_chip *chip, int group_a, uint8_t val)
{
	struct i2c_client *client;
	int ret;

	client = group_a ? chip->client_group_a : chip->client_group_b;
	ret = i2c_smbus_write_byte(client, val);
	if (ret < 0) {
		dev_err(&client->dev, "failed writing\n");
		return ret;
	}

	return 0;
}
예제 #23
0
u8 vct_get_version(int i2c) {
	if (i2c_smbus_write_byte(i2c, 0x03) < 0) {
		perror("Error sending version command");
		return 0;
	}

	int ver = i2c_smbus_read_byte(i2c);
	if (ver < 0) {
		perror("Error getting version number");
		return 0;
	}

	return ver;
}
예제 #24
0
BOOLEAN lge_melfas_i2c_write(UINT8 slave_addr, UINT8 *pData, UINT8 cLength)
{
	int nAddr = mcs6000_ts_dev.client->addr, nErr;

   	mcs6000_ts_dev.client->addr = slave_addr;
	nErr = i2c_smbus_write_byte(mcs6000_ts_dev.client, *pData);
   	mcs6000_ts_dev.client->addr = nAddr;

	if(nErr) {
		DMSG("lge_melfas_i2c_write ERROR\n");
		return FALSE;
	}

	return TRUE;
}
예제 #25
0
static int isl6271a_set_voltage_sel(struct regulator_dev *dev,
                                    unsigned selector)
{
    struct isl_pmic *pmic = rdev_get_drvdata(dev);
    int err;

    mutex_lock(&pmic->mtx);

    err = i2c_smbus_write_byte(pmic->client, selector);
    if (err < 0)
        dev_err(&pmic->client->dev, "Error setting voltage\n");

    mutex_unlock(&pmic->mtx);
    return err;
}
예제 #26
0
/**
 * ad525x_write - store the given value in the specified register on
 * the AD5258 device.
 * @client: value returned from i2c_new_device()
 * @reg: the register to write
 * @value: the byte to store in the register
 *
 * For certain instructions that do not require a data byte, "NULL"
 * should be specified for the "value" parameter.  These instructions
 * include NOP, RESTORE_FROM_EEPROM, and STORE_TO_EEPROM.
 *
 * A negative return value indicates an error occurred while reading
 * the register.
 */
static s32 ad525x_write(struct i2c_client *client, u8 reg, u8 value)
{
	struct dpot_data *data = i2c_get_clientdata(client);

	/* Only write the instruction byte for certain commands */
	if (reg & AD525X_I2C_CMD)
		return i2c_smbus_write_byte(client, reg);

	if (data->max_pos > 256)
		return i2c_smbus_write_word_data(client, (reg & 0xF8) |
						((reg & 0x7) << 1), value);
	else
		/* All other registers require instruction + data bytes */
		return i2c_smbus_write_byte_data(client, reg, value);
}
예제 #27
0
파일: tsc2004.c 프로젝트: AK101111/linux
static int tsc2004_cmd(struct device *dev, u8 cmd)
{
	u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
	s32 data;
	struct i2c_client *i2c = to_i2c_client(dev);

	data = i2c_smbus_write_byte(i2c, tx);
	if (data < 0) {
		dev_err(dev, "%s: failed, command: %x i2c error: %d\n",
			__func__, cmd, data);
		return data;
	}

	return 0;
}
예제 #28
0
static int ms5611_i2c_read_adc_temp_and_pressure(struct device *dev,
						 s32 *temp, s32 *pressure)
{
	int ret;
	struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
	const struct ms5611_osr *osr = st->temp_osr;

	ret = i2c_smbus_write_byte(st->client, osr->cmd);
	if (ret < 0)
		return ret;

	usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
	ret = ms5611_i2c_read_adc(st, temp);
	if (ret < 0)
		return ret;

	osr = st->pressure_osr;
	ret = i2c_smbus_write_byte(st->client, osr->cmd);
	if (ret < 0)
		return ret;

	usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
	return ms5611_i2c_read_adc(st, pressure);
}
예제 #29
0
static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
    struct i2c_client *client = to_i2c_client(dev);
    struct pcf8591_data *data = i2c_get_clientdata(client);
    unsigned long val = simple_strtoul(buf, NULL, 10);

    mutex_lock(&data->update_lock);
    if (val)
        data->control |= PCF8591_CONTROL_AOEF;
    else
        data->control &= ~PCF8591_CONTROL_AOEF;
    i2c_smbus_write_byte(client, data->control);
    mutex_unlock(&data->update_lock);
    return count;
}
예제 #30
0
int i2cget(int i2cbus, int address, int daddress)
{
	char *end;
	int res, size, file;
	
	char filename[20];

	size = I2C_SMBUS_BYTE;


	sprintf(filename, "/dev/i2c-%d", i2cbus);
	file = open(filename, O_RDWR);
	if (file<0) {
		if (errno == ENOENT) {
			fprintf(stderr, "Error: Could not open file "
				"/dev/i2c-%d: %s\n", i2cbus, strerror(ENOENT));
		} else {
			fprintf(stderr, "Error: Could not open file "
				"`%s': %s\n", filename, strerror(errno));
			if (errno == EACCES)
				fprintf(stderr, "Run as root?\n");
		}
		exit(1);
	}

	if (ioctl(file, I2C_SLAVE, address) < 0) {
		fprintf(stderr,
			"Error: Could not set address to 0x%02x: %s\n",
			address, strerror(errno));
		return -errno;
	}

	res = i2c_smbus_write_byte(file, daddress);
	if (res < 0) {
		fprintf(stderr, "Warning - write failed, filename=%s, daddress=%d\n",
			filename, daddress);
	}
	
	res = i2c_smbus_read_byte_data(file, daddress);
	close(file);

	if (res < 0) {
		fprintf(stderr, "Error: Read failed, res=%d\n", res);
		exit(2);
	}

	return res;
}