当前位置: 首页>>代码示例>>C++>>正文


C++ i2c_smbus_write_word_data函数代码示例

本文整理汇总了C++中i2c_smbus_write_word_data函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_smbus_write_word_data函数的具体用法?C++ i2c_smbus_write_word_data怎么用?C++ i2c_smbus_write_word_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了i2c_smbus_write_word_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dump_info

void dump_info() {
#define DEVICE_TYPE 0x0001
#define FW_VERSION 0x0002
#define HW_VERSION 0x0003
#define DF_VERSION 0x001F
    int res;
    short data;
    res = ioctl(i2c_fd, I2C_SLAVE_FORCE, I2C_DEV_NORMAL_ADDR);
    CHECK(res);

    printf("===== DUMP INFO 0x%x =====\n", I2C_DEV_NORMAL_ADDR);

    i2c_smbus_write_word_data(i2c_fd, 0x00, DEVICE_TYPE);
    i2c_smbus_write_word_data(i2c_fd, 0x01, DEVICE_TYPE);
    data = i2c_smbus_read_word_data(i2c_fd, 0x00);
    printf("DEVICE_TYPE: %x\n", data);

    i2c_smbus_write_word_data(i2c_fd, 0x00, FW_VERSION);
    i2c_smbus_write_word_data(i2c_fd, 0x01, FW_VERSION);
    data = i2c_smbus_read_word_data(i2c_fd, 0x00);
    printf("FW_VERSION: %x\n", data);

    i2c_smbus_write_word_data(i2c_fd, 0x00, HW_VERSION);
    i2c_smbus_write_word_data(i2c_fd, 0x01, HW_VERSION);
    data = i2c_smbus_read_word_data(i2c_fd, 0x00);
    printf("HW_VERSION: %x\n", data);

    i2c_smbus_write_word_data(i2c_fd, 0x00, DF_VERSION);
    i2c_smbus_write_word_data(i2c_fd, 0x01, DF_VERSION);
    data = i2c_smbus_read_word_data(i2c_fd, 0x00);
    printf("DF_VERSION: %x\n", data);
    printf("=====================\n");
}
开发者ID:Casperkings,项目名称:FastBoot,代码行数:33,代码来源:dfi_update.c

示例2: us5182d_setup_prox

static int us5182d_setup_prox(struct iio_dev *indio_dev,
			      enum iio_event_direction dir, u16 val)
{
	struct us5182d_data *data = iio_priv(indio_dev);

	if (dir == IIO_EV_DIR_FALLING)
		return i2c_smbus_write_word_data(data->client,
						 US5182D_REG_PXL_TH, val);
	else if (dir == IIO_EV_DIR_RISING)
		return i2c_smbus_write_word_data(data->client,
						 US5182D_REG_PXH_TH, val);

	return 0;
}
开发者ID:AshishNamdev,项目名称:linux,代码行数:14,代码来源:us5182d.c

示例3: __locked_start_current_mon

static s32 __locked_start_current_mon(struct i2c_client *client)
{
	s32 retval;
	s32 shunt_uV;
	s16 shunt_limit;
	s16 alert_mask;
	struct ina230_data *data = i2c_get_clientdata(client);

	if (!data->pdata->current_threshold) {
		dev_err(&client->dev, "no current threshold specified\n");
		return -EINVAL;
	}

	retval = i2c_smbus_write_word_data(client, INA230_CONFIG,
				    __constant_cpu_to_be16(INA230_CONT_CONFIG));
	if (retval < 0) {
		dev_err(&client->dev, "config data write failed sts: 0x%x\n",
			retval);
		return retval;
	}

	shunt_uV = data->pdata->resistor * data->pdata->current_threshold;
	if (data->pdata->shunt_polarity_inverted)
		shunt_uV *= -1;

	shunt_limit = (s16) uv_to_alert_register(shunt_uV);

	retval = i2c_smbus_write_word_data(client, INA230_ALERT,
					   cpu_to_be16(shunt_limit));
	if (retval < 0) {
		dev_err(&client->dev, "alert data write failed sts: 0x%x\n",
			retval);
		return retval;
	}

	alert_mask = shunt_limit >= 0 ? INA230_MASK_SOL : INA230_MASK_SUL;
	retval = i2c_smbus_write_word_data(client, INA230_MASK,
					   cpu_to_be16(alert_mask));
	if (retval < 0) {
		dev_err(&client->dev, "mask data write failed sts: 0x%x\n",
			retval);
		return retval;
	}

	data->running = true;

	return 0;
}
开发者ID:vocoderism,项目名称:Tegra-Note-7,代码行数:48,代码来源:ina230.c

示例4: iI2cWriteReg16

// -----------------------------------------------------------------------------
int
iI2cWriteReg16 (int fd, uint8_t reg, uint16_t value) {
  int i = i2c_smbus_write_word_data (fd, reg, value);

  vI2cPrintDebug (i, __func__);
  return i;
}
开发者ID:epsilonrt,项目名称:sysio,代码行数:8,代码来源:i2c.c

示例5: menf21bmc_wdt_shutdown

static void menf21bmc_wdt_shutdown(struct platform_device *pdev)
{
	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);

	i2c_smbus_write_word_data(drv_data->i2c_client,
				  BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
}
开发者ID:avagin,项目名称:linux,代码行数:7,代码来源:menf21bmc_wdt.c

示例6: show_alarm

static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
			  char *buf)
{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
	struct ds620_data *data = ds620_update_client(dev);
	struct i2c_client *client = to_i2c_client(dev);
	u16 conf, new_conf;
	int res;

	if (IS_ERR(data))
		return PTR_ERR(data);

	/* reset alarms if necessary */
	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
	if (res < 0)
		return res;

	conf = swab16(res);
	new_conf = conf;
	new_conf &= ~attr->index;
	if (conf != new_conf) {
		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
						swab16(new_conf));
		if (res < 0)
			return res;
	}

	return sprintf(buf, "%d\n", !!(conf & attr->index));
}
开发者ID:1111saeid,项目名称:jb_kernel_3.0.16_htc_golfu,代码行数:29,代码来源:ds620.c

示例7: pca9539_write_reg

/* NOTE:  we can't currently rely on fault codes to come from SMBus
 * calls, so we map all errors to EIO here and return zero otherwise.
 */
static int pca9539_write_reg(struct pca9539_chip *chip, int reg, uint16_t val)
{
    if (i2c_smbus_write_word_data(chip->client, reg, val) < 0)
        return -EIO;
    else
        return 0;
}
开发者ID:amalrajt,项目名称:linux-sh4-2.6.23.17_stm23_A18B,代码行数:10,代码来源:pca9539.c

示例8: ds620_init_client

static void ds620_init_client(struct i2c_client *client)
{
	struct ds620_platform_data *ds620_info = client->dev.platform_data;
	u16 conf, new_conf;

	new_conf = conf =
	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));

	/* switch to continuous conversion mode */
	new_conf &= ~DS620_REG_CONFIG_1SHOT;
	/* already high at power-on, but don't trust the BIOS! */
	new_conf |= DS620_REG_CONFIG_PO2;
	/* thermostat mode according to platform data */
	if (ds620_info && ds620_info->pomode == 1)
		new_conf &= ~DS620_REG_CONFIG_PO1; /* PO_LOW */
	else if (ds620_info && ds620_info->pomode == 2)
		new_conf |= DS620_REG_CONFIG_PO1; /* PO_HIGH */
	else
		new_conf &= ~DS620_REG_CONFIG_PO2; /* always low */
	/* with highest precision */
	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;

	if (conf != new_conf)
		i2c_smbus_write_word_data(client, DS620_REG_CONF,
					  swab16(new_conf));

	/* start conversion */
	i2c_smbus_write_byte(client, DS620_COM_START);
}
开发者ID:1111saeid,项目名称:jb_kernel_3.0.16_htc_golfu,代码行数:29,代码来源:ds620.c

示例9: cm32181_write_als_it

/**
 * cm32181_write_als_it() - Write sensor integration time
 * @cm32181:	pointer of struct cm32181.
 * @val:	integration time by millisecond.
 *
 * Convert integration time (ms) to sensor value.
 *
 * Return: i2c_smbus_write_word_data command return value.
 */
static int cm32181_write_als_it(struct cm32181_chip *cm32181, int val)
{
	struct i2c_client *client = cm32181->client;
	u16 als_it;
	int ret, i, n;

	n = ARRAY_SIZE(als_it_value);
	for (i = 0; i < n; i++)
		if (val <= als_it_value[i])
			break;
	if (i >= n)
		i = n - 1;

	als_it = als_it_bits[i];
	als_it <<= CM32181_CMD_ALS_IT_SHIFT;

	mutex_lock(&cm32181->lock);
	cm32181->conf_regs[CM32181_REG_ADDR_CMD] &=
		~CM32181_CMD_ALS_IT_MASK;
	cm32181->conf_regs[CM32181_REG_ADDR_CMD] |=
		als_it;
	ret = i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
			cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
	mutex_unlock(&cm32181->lock);

	return ret;
}
开发者ID:CenturyGlorion,项目名称:linux,代码行数:36,代码来源:cm32181.c

示例10: cm32181_reg_init

/**
 * cm32181_reg_init() - Initialize CM32181 registers
 * @cm32181:	pointer of struct cm32181.
 *
 * Initialize CM32181 ambient light sensor register to default values.
 *
 * Return: 0 for success; otherwise for error code.
 */
static int cm32181_reg_init(struct cm32181_chip *cm32181)
{
	struct i2c_client *client = cm32181->client;
	int i;
	s32 ret;

	ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ID);
	if (ret < 0)
		return ret;

	/* check device ID */
	if ((ret & 0xFF) != 0x81)
		return -ENODEV;

	/* Default Values */
	cm32181->conf_regs[CM32181_REG_ADDR_CMD] = CM32181_CMD_ALS_ENABLE |
			CM32181_CMD_ALS_IT_DEFAULT | CM32181_CMD_ALS_SM_DEFAULT;
	cm32181->calibscale = CM32181_CALIBSCALE_DEFAULT;

	/* Initialize registers*/
	for (i = 0; i < CM32181_CONF_REG_NUM; i++) {
		ret = i2c_smbus_write_word_data(client, cm32181_reg[i],
			cm32181->conf_regs[i]);
		if (ret < 0)
			return ret;
	}

	return 0;
}
开发者ID:CenturyGlorion,项目名称:linux,代码行数:37,代码来源:cm32181.c

示例11: cm3218_write_als_it

/**
 * cm3218_write_als_it() - Write sensor integration time
 * @cm3218:	pointer of struct cm3218.
 * @val:	integration time in second.
 * @val2:	integration time in millisecond.
 *
 * Convert integration time to sensor value.
 *
 * Return: i2c_smbus_write_word_data command return value.
 */
static int cm3218_write_als_it(struct cm3218_chip *chip, int val, int val2)
{
	u16 als_it, cmd;
	int i;
	s32 ret;

	for (i = 0; i < ARRAY_SIZE(cm3218_als_it_scales); i++) {
		if (val == cm3218_als_it_scales[i].val &&
			val2 == cm3218_als_it_scales[i].val2) {
			als_it = cm3218_als_it_scales[i].it;
			als_it <<= CM3218_CMD_ALS_IT_SHIFT;

			cmd = chip->conf_regs[CM3218_REG_ADDR_CMD] &
				~CM3218_CMD_ALS_IT_MASK;
			cmd |= als_it;
			ret = i2c_smbus_write_word_data(
						chip->als_client,
						CM3218_REG_ADDR_CMD,
						cmd);
			if (ret < 0)
				return ret;
			chip->conf_regs[CM3218_REG_ADDR_CMD] = cmd;
			return 0;
		}
	}
	return -EINVAL;
}
开发者ID:hadess,项目名称:cm3218,代码行数:37,代码来源:cm3218.c

示例12: stv_mbx_poweroff_probe

static int __devinit stv_mbx_poweroff_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	u16 data;
	int res = 0;
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
		pr_err("%s: i2c_check_functionality failed\n", __FUNCTION__);
		res = -ENODEV;
		goto out;
	}
	/* remember our client */
	stv_mbx_poweroff_client = client;

	/* setup power handling */
	data  = i2c_smbus_read_word_data(stv_mbx_poweroff_client, STV_MBX_PWR_ADDRESS);
	printk("stv_mbx_poweroff_probe, status reg = 0x%x\n", data);
	/* enable power control */
	data &= ~ATV_MBX_PWR_DISABLE;
	/* set hw power button to power off when held for > 3 seconds. */
	data |=  ATV_MBX_PWR_HW_BUTTON;
	/* set ir power button to power off when held for > 3 seconds. */
	data |=  ATV_MBX_PWR_IR_BUTTON;
	i2c_smbus_write_word_data(stv_mbx_poweroff_client, STV_MBX_PWR_ADDRESS, data);

	/* hook the poweroff power mananger routine*/
	pm_power_off = stv_mbx_poweroff;
out:
	return res;
}
开发者ID:mattburris,项目名称:buildroot-linux-kernel-m3,代码行数:28,代码来源:stv_mbx_poweroff.c

示例13: tmd2771x_als_polling_work_handler

/* ALS polling routine */
static void tmd2771x_als_polling_work_handler(struct work_struct *work)
{
	struct i2c_client *client=data->client;
	int cdata, irdata, pdata;
	int luxValue=0;

	//1. work queue is reentrant in SMP.
	//2. serveral function here calls need mutex.
	mutex_lock(&data->update_lock);
	cdata = i2c_smbus_read_word_data(client, CMD_WORD|TMD2771X_CDATAL_REG);
	irdata = i2c_smbus_read_word_data(client, CMD_WORD|TMD2771X_IRDATAL_REG);
	pdata = i2c_smbus_read_word_data(client, CMD_WORD|TMD2771X_PDATAL_REG);

	if ((cdata < 0) || (irdata < 0) || (pdata < 0)) {
		mutex_unlock(&data->update_lock);
		return;
	}

	luxValue = LuxCalculation(client, cdata, irdata);
	luxValue = luxValue>0 ? luxValue : 0;
	luxValue = luxValue<10000 ? luxValue : 10000;
	light_data = luxValue;
	//printk("%s: lux = %d cdata = %x  irdata = %x pdata = %x \n", __func__, luxValue, cdata, irdata, pdata);
	// check PS under sunlight
	if ( (data->ps_detection == 1) && (cdata > (75*(1024*(256-data->atime)))/100))	// PS was previously in far-to-near condition
	{
		// need to inform input event as there will be no interrupt from the PS
		input_report_abs(data->input_dev_ps, ABS_DISTANCE, 1);/* NEAR-to-FAR detection */
		input_sync(data->input_dev_ps);

		i2c_smbus_write_word_data(client, CMD_WORD|TMD2771X_PILTL_REG, 0);
		i2c_smbus_write_word_data(client, CMD_WORD|TMD2771X_PIHTL_REG, data->ps_threshold);

		data->pilt = 0;
		data->piht = data->ps_threshold;

		data->ps_detection = 0;	/* near-to-far detected */

		printk("tmd2771x_proximity_handler = FAR\n");
	}

	input_report_abs(data->input_dev_als, ABS_MISC, luxValue); // report the lux level
	input_sync(data->input_dev_als);

	schedule_delayed_work(&data->als_dwork, msecs_to_jiffies(data->als_poll_delay));	// restart timer
	mutex_unlock(&data->update_lock);
}
开发者ID:ColonelSaumon,项目名称:android_kernel_nokia_msm8x25,代码行数:48,代码来源:tmd2771x.c

示例14: fsa9480_reg_init

static void fsa9480_reg_init(struct fsa9480_usbsw *usbsw, int mansw_set)
{
	struct i2c_client *client = usbsw->client;
	unsigned int ctrl = CON_MASK;
	int ret;

	/* mask interrupts (unmask attach/detach/ovp_dcp_dis/ ovp_en only) */
	ret = i2c_smbus_write_word_data(client, FSA9480_REG_INT1_MASK, 0xFF5C);
	if (ret < 0)
		dev_err(&client->dev, "%s: err %d\n", __func__, ret);

	/* mask all car kit interrupts */
	ret = i2c_smbus_write_word_data(client,
			FSA9480_REG_CK_INTMASK1, 0x07ff);
	if (ret < 0)
		dev_err(&client->dev, "%s: err %d\n", __func__, ret);

	/* ADC Detect Time: 500ms */
	ret = i2c_smbus_write_byte_data(client, FSA9480_REG_TIMING1, 0x6);
	if (ret < 0)
		dev_err(&client->dev, "%s: err %d\n", __func__, ret);

	if (mansw_set) {
		if (usbsw->mansw) {
			ret = i2c_smbus_write_byte_data(client,
				FSA9480_REG_MANSW1, usbsw->mansw);
			if (ret < 0)
				dev_err(&client->dev,
					"%s: err %d\n", __func__, ret);
			ctrl &= ~CON_MANUAL_SW;	/* Manual Switching Mode */
		}

		ret = i2c_smbus_write_byte_data(client, FSA9480_REG_CTRL, ctrl);
	} else {
		usbsw->mansw = i2c_smbus_read_byte_data(client,
						FSA9480_REG_MANSW1);
		if (usbsw->mansw < 0)
			dev_err(&client->dev,
				"%s: err %d\n", __func__, usbsw->mansw);
	}

#if (defined(CONFIG_MHL_SWITCH) && defined(CONFIG_MHL_SII9234))	
	i2c_smbus_write_byte_data(client, FSA9480_REG_INT2_MASK, 0xFE & i2c_smbus_read_byte_data(client, 0x06));
#endif
	if (ret < 0)
		dev_err(&client->dev, "%s: err %d\n", __func__, ret);
}
开发者ID:AdiPat,项目名称:android_kernel_tegra_n1,代码行数:47,代码来源:fsa9480.c

示例15: ina3221_probe

static int __devinit ina3221_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
	struct ina3221_data *data;
	int ret, i;

	data = devm_kzalloc(&client->dev, sizeof(struct ina3221_data),
						GFP_KERNEL);
	if (!data) {
		ret = -ENOMEM;
		goto exit;
	}
	i2c_set_clientdata(client, data);
	data->plat_data = client->dev.platform_data;
	mutex_init(&data->mutex);

	data->mode = TRIGGERED;
	data->shutdown_complete = 0;
	/* reset ina3221 */
	ret = i2c_smbus_write_word_data(client, INA3221_CONFIG,
		__constant_cpu_to_be16((INA3221_RESET)));
	if (ret < 0) {
		dev_err(&client->dev, "ina3221 reset failure status: 0x%x\n",
			ret);
		goto exit_free;
	}

	for (i = 0; i < ARRAY_SIZE(ina3221); i++) {
		ret = device_create_file(&client->dev, &ina3221[i].dev_attr);
		if (ret) {
			dev_err(&client->dev, "device_create_file failed.\n");
			goto exit_remove;
		}
	}
	data->client = client;
	data->nb.notifier_call = ina3221_hotplug_notify;
	register_hotcpu_notifier(&(data->nb));

	data->hwmon_dev = hwmon_device_register(&client->dev);
	if (IS_ERR(data->hwmon_dev)) {
		ret = PTR_ERR(data->hwmon_dev);
		goto exit_remove;
	}

	/* set ina3221 to power down mode */
	ret = __locked_power_down_ina3221(client);
	if (ret < 0)
		goto exit_remove;

	return 0;

exit_remove:
	while (i--)
		device_remove_file(&client->dev, &ina3221[i].dev_attr);
exit_free:
	devm_kfree(&client->dev, data);
exit:
	return ret;
}
开发者ID:lostdeveloper,项目名称:Grouper-3.4,代码行数:59,代码来源:ina3221.c


注:本文中的i2c_smbus_write_word_data函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。