static int tpd_read_edid(struct omap_dss_device *dssdev,
		u8 *edid, int len)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);
	struct omap_dss_device *in = ddata->in;
	int r = 0;

	if (!gpio_get_value_cansleep(ddata->hpd_gpio))
		return -ENODEV;

	if (gpio_is_valid(ddata->ls_oe_gpio))
		gpio_set_value_cansleep(ddata->ls_oe_gpio, 1);

	i2c_lock_adapter(ddata->ddc_i2c_adapter);

	hdmi_i2c2_hack_demux(dssdev->dev, SEL_HDMI);

	r = in->ops.hdmi->read_edid(in, edid, len);

	hdmi_i2c2_hack_demux(dssdev->dev, SEL_I2C2);

	i2c_unlock_adapter(ddata->ddc_i2c_adapter);

	if (gpio_is_valid(ddata->ls_oe_gpio))
		gpio_set_value_cansleep(ddata->ls_oe_gpio, 0);

	return r;
}
static int mlx90614_wakeup(struct mlx90614_data *data)
{
	if (!data->wakeup_gpio) {
		dev_dbg(&data->client->dev, "Wake-up disabled");
		return -ENOSYS;
	}

	dev_dbg(&data->client->dev, "Requesting wake-up");

	i2c_lock_adapter(data->client->adapter);
	gpiod_direction_output(data->wakeup_gpio, 0);
	msleep(MLX90614_TIMING_WAKEUP);
	gpiod_direction_input(data->wakeup_gpio);
	i2c_unlock_adapter(data->client->adapter);

	data->ready_timestamp = jiffies +
			msecs_to_jiffies(MLX90614_TIMING_STARTUP);

	/*
	 * Quirk: the i2c controller may get confused right after the
	 * wake-up signal has been sent.  As a workaround, do a dummy read.
	 * If the read fails, the controller will probably be reset so that
	 * further reads will work.
	 */
	i2c_smbus_read_word_data(data->client, MLX90614_CONFIG);

	return 0;
}
static int sfn4111t_reset(struct efx_nic *efx)
{
	struct falcon_board *board = falcon_board(efx);
	efx_oword_t reg;

	/* GPIO 3 and the GPIO register are shared with I2C, so block that */
	i2c_lock_adapter(&board->i2c_adap);

	/* Pull RST_N (GPIO 2) low then let it up again, setting the
	 * FLASH_CFG_1 strap (GPIO 3) appropriately.  Only change the
	 * output enables; the output levels should always be 0 (low)
	 * and we rely on external pull-ups. */
	efx_reado(efx, &reg, FR_AB_GPIO_CTL);
	EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, true);
	efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
	msleep(1000);
	EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, false);
	EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN,
			    !!(efx->phy_mode & PHY_MODE_SPECIAL));
	efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
	msleep(1);

	i2c_unlock_adapter(&board->i2c_adap);

	ssleep(1);
	return 0;
}
示例#4
0
static int msm_i2c_resume_noirq(struct device *device) {
	struct platform_device *pdev = to_platform_device(device);
	struct msm_i2c_dev *dev = platform_get_drvdata(pdev);

	/* Block to allow any i2c_xfers to finish */
	i2c_lock_adapter(&dev->adapter);
	dev->is_suspended = false;
	i2c_unlock_adapter(&dev->adapter);
	return 0;
}
static int ak7343_write(struct i2c_client *client,
			unsigned long reg, unsigned long val)
{
	int ret = 0;
	unsigned long mfp_pin[2];
	unsigned long i2c0_mfps[] = {
		GPIO053_GPIO_53,		/* SCL */
		GPIO054_GPIO_54,		/* SDA */
	};
	unsigned long scl, sda;
	scl = MFP_PIN_GPIO53;
	sda = MFP_PIN_GPIO54;
	i2c_lock_adapter(client->adapter);
	if (gpio_request(scl, "SCL")) {
		pr_err("Failed to request GPIO for SCL pin!\n");
		ret = -1;
		goto out0;
	}
	if (gpio_request(sda, "SDA")) {
		pr_err("Failed to request GPIO for SDA pin!\n");
		ret = -1;
		goto out1;
	};
	mfp_pin[0] = mfp_read(MFP_PIN_GPIO53);
	mfp_pin[1] = mfp_read(MFP_PIN_GPIO54);
	mfp_config(i2c0_mfps, ARRAY_SIZE(i2c0_mfps));
	i2c_start(scl, sda);
	if (i2c_sendbyte(scl, sda,  (client->addr<<1) | 0) < 0) {
		ret = -1;
		goto out2;
	}
	if (i2c_sendbyte(scl, sda, (u8)reg) < 0) {
		ret = -1;
		goto out2;
	}
	if (i2c_sendbyte(scl, sda, (u8)val) < 0) {
		ret = -1;
		goto out2;
	}
out2:
	i2c_stop(scl, sda);
	mfp_write(MFP_PIN_GPIO53, mfp_pin[0]);
	mfp_write(MFP_PIN_GPIO54, mfp_pin[1]);
	gpio_free(sda);

out1:
	gpio_free(scl);
out0:
	i2c_unlock_adapter(client->adapter);
	return ret;
}
static void cptk_update_firmware_cb(const struct firmware *fw, void *context)
{

	int ret;
	struct cptk_data *cptk = context;
	struct device *dev = &cptk->input_dev->dev;
	int retries = 3;

	pr_info("cptk: firware download start\n");

	if (fw->size != FW_SIZE) {
		dev_err(dev, "%s: Firmware file size invalid size:%d\n",
							__func__, fw->size);
		return;
	}

	mutex_lock(&cptk->lock);

	disable_irq(cptk->client->irq);

	/* Lock the i2c bus since the firmware updater accesses it */
	i2c_lock_adapter(cptk->client->adapter);
	while (retries--) {
		ret = touchkey_flash_firmware(cptk->pdata, fw->data);
		if (!ret)
			break;
	}
	if (ret) {
		cptk->touchkey_update_status = -1;
		dev_err(dev, "%s: Firmware update failed\n", __func__);
	} else {
		cptk->touchkey_update_status = 0;
		pr_info("cptk: firware download finished\n");
	}

	i2c_unlock_adapter(cptk->client->adapter);
	enable_irq(cptk->client->irq);

	release_firmware(fw);
	mutex_unlock(&cptk->lock);

	cptk_i2c_read(cptk, KEYCODE_REG, cptk->cur_firm_ver,
						sizeof(cptk->cur_firm_ver));

	pr_info("cptk: current firm ver = 0x%.2x, latest firm ver = 0x%.2x\n",
				cptk->cur_firm_ver[1], cptk->pdata->firm_ver);

	return;
}
示例#7
0
int pm860x_page_bulk_read(struct i2c_client *i2c, int reg,
			  int count, unsigned char *buf)
{
	unsigned char zero = 0;
	int ret;

	i2c_lock_adapter(i2c->adapter);
	read_device(i2c, 0xfa, 0, &zero);
	read_device(i2c, 0xfb, 0, &zero);
	read_device(i2c, 0xff, 0, &zero);
	ret = read_device(i2c, reg, count, buf);
	read_device(i2c, 0xFE, 0, &zero);
	read_device(i2c, 0xFC, 0, &zero);
	i2c_unlock_adapter(i2c->adapter);
	return ret;
}
示例#8
0
int pm860x_page_reg_write(struct i2c_client *i2c, int reg,
			  unsigned char data)
{
	unsigned char zero;
	int ret;

	i2c_lock_adapter(i2c->adapter);
	read_device(i2c, 0xFA, 0, &zero);
	read_device(i2c, 0xFB, 0, &zero);
	read_device(i2c, 0xFF, 0, &zero);
	ret = write_device(i2c, reg, 1, &data);
	read_device(i2c, 0xFE, 0, &zero);
	read_device(i2c, 0xFC, 0, &zero);
	i2c_unlock_adapter(i2c->adapter);
	return ret;
}
static int ak7343_subdev_open(struct v4l2_subdev *sd,
				struct v4l2_subdev_fh *fh)
{
	struct ak7343 *core = to_ak7343(sd);
	struct i2c_client *client = v4l2_get_subdevdata(&core->subdev);
	unsigned long mfp_pin[2];
	unsigned long i2c0_mfps[] = {
		GPIO053_GPIO_53,
		GPIO054_GPIO_54,
	};
	unsigned long scl, sda;
	if (core->openflag == 1)
		return -EBUSY;
	core->openflag = 1;

	scl = MFP_PIN_GPIO53;
	sda = MFP_PIN_GPIO54;
	i2c_lock_adapter(client->adapter);
	if (gpio_request(scl, "SCL"))
		pr_err("Failed to request GPIO for SCL pin!\n");
	if (gpio_request(sda, "SDA"))
		pr_err("Failed to request GPIO for SDA pin!\n");
	mfp_pin[0] = mfp_read(MFP_PIN_GPIO53);
	mfp_pin[1] = mfp_read(MFP_PIN_GPIO54);
	mfp_config(i2c0_mfps, ARRAY_SIZE(i2c0_mfps));
	gpio_direction_output(sda, 0);
	gpio_direction_output(scl, 0);
	mdelay(100);
	vcm_power(core, 1);
	mdelay(10);
	gpio_direction_output(sda, 1);
	gpio_direction_output(scl, 1);

	mfp_write(MFP_PIN_GPIO53, mfp_pin[0]);
	mfp_write(MFP_PIN_GPIO54, mfp_pin[1]);
	gpio_free(sda);
	gpio_free(scl);
	i2c_unlock_adapter(client->adapter);
	mdelay(120);
	ak7343_write(client, 0x05, 0x7a);
	ak7343_write(client, 0x01, 0x01);
	mdelay(200);
	ak7343_write(client, 0x02, 0x01);
	mdelay(120);
	ak7343_write(client, 0x01, 0x00);
	return 0;
}
/**
 * Reboot chip
 *
 * Caution : IRQ must be disabled before mms_reboot and enabled after mms_reboot.
 */
void mms_reboot(struct mms_ts_info *info)
{
	struct i2c_adapter *adapter = to_i2c_adapter(info->client->dev.parent);

	dev_dbg(&info->client->dev, "%s [START]\n", __func__);

	i2c_lock_adapter(adapter);

	mms_power_control(info, 0);
	mms_power_control(info, 1);

	i2c_unlock_adapter(adapter);

	msleep(30);

	dev_info(&info->client->dev, "%s [DONE]\n", __func__);
}
示例#11
0
int pm860x_page_reg_read(struct i2c_client *i2c, int reg)
{
	unsigned char zero = 0;
	unsigned char data;
	int ret;

	i2c_lock_adapter(i2c->adapter);
	read_device(i2c, 0xFA, 0, &zero);
	read_device(i2c, 0xFB, 0, &zero);
	read_device(i2c, 0xFF, 0, &zero);
	ret = read_device(i2c, reg, 1, &data);
	if (ret >= 0)
		ret = (int)data;
	read_device(i2c, 0xFE, 0, &zero);
	read_device(i2c, 0xFC, 0, &zero);
	i2c_unlock_adapter(i2c->adapter);
	return ret;
}
示例#12
0
/*
 * iic_tpm_read() - read from TPM register
 * @addr: register address to read from
 * @buffer: provided by caller
 * @len: number of bytes to read
 *
 * Read len bytes from TPM register and put them into
 * buffer (little-endian format, i.e. first byte is put into buffer[0]).
 *
 * NOTE: TPM is big-endian for multi-byte values. Multi-byte
 * values have to be swapped.
 *
 * NOTE: We can't unfortunately use the combined read/write functions
 * provided by the i2c core as the TPM currently does not support the
 * repeated start condition and due to it's special requirements.
 * The i2c_smbus* functions do not work for this chip.
 *
 * Return -EIO on error, 0 on success.
 */
static int iic_tpm_read(u8 addr, u8 *buffer, size_t len)
{

	struct i2c_msg msg1 = { tpm_dev.client->addr, 0, 1, &addr };
	struct i2c_msg msg2 = { tpm_dev.client->addr, I2C_M_RD, len, buffer };

	int rc;
	int count;

	/* Lock the adapter for the duration of the whole sequence. */
	if (!tpm_dev.client->adapter->algo->master_xfer)
		return -EOPNOTSUPP;
	i2c_lock_adapter(tpm_dev.client->adapter);

	for (count = 0; count < MAX_COUNT; count++) {
		rc = __i2c_transfer(tpm_dev.client->adapter, &msg1, 1);
		if (rc > 0)
			break;	/* break here to skip sleep */

		usleep_range(SLEEP_DURATION_LOW, SLEEP_DURATION_HI);
	}

	if (rc <= 0)
		goto out;

	/* After the TPM has successfully received the register address it needs
	 * some time, thus we're sleeping here again, before retrieving the data
	 */
	for (count = 0; count < MAX_COUNT; count++) {
		usleep_range(SLEEP_DURATION_LOW, SLEEP_DURATION_HI);
		rc = __i2c_transfer(tpm_dev.client->adapter, &msg2, 1);
		if (rc > 0)
			break;

	}

out:
	i2c_unlock_adapter(tpm_dev.client->adapter);
	if (rc <= 0)
		return -EIO;

	return 0;
}
示例#13
0
static int update_firmware(struct cypress_touchkey_devdata *devdata)
{
	int ret;
	const struct firmware *fw = NULL;
	struct device *dev = &devdata->input_dev->dev;
	int retries = 10;

	dev_info(dev, "%s: Updating " DEVICE_NAME " firmware\n", __func__);

	if (!devdata->pdata->fw_name) {
		dev_err(dev, "%s: Device firmware name is not set\n", __func__);
		return -EINVAL;
	}

	ret = request_firmware(&fw, devdata->pdata->fw_name, dev);
	if (ret) {
		dev_err(dev, "%s: Can't open firmware file from %s\n", __func__,
						devdata->pdata->fw_name);
		return ret;
	}

	if (fw->size != FW_SIZE) {
		dev_err(dev, "%s: Firmware file size invalid\n", __func__);
		return -EINVAL;
	}

	disable_irq(devdata->client->irq);
	/* Lock the i2c bus since the firmware updater accesses it */
	i2c_lock_adapter(devdata->client->adapter);
	while (retries--) {
		ret = touchkey_flash_firmware(devdata->pdata, fw->data);
		if (!ret)
			break;
	}
	if (ret)
		dev_err(dev, "%s: Firmware update failed\n", __func__);
	i2c_unlock_adapter(devdata->client->adapter);
	enable_irq(devdata->client->irq);

	release_firmware(fw);
	return ret;
}
示例#14
0
static void mms_reboot(struct mms_ts_info *info)
{
	struct i2c_adapter *adapter = to_i2c_adapter(info->client->dev.parent);
	int ret = 0;
	
	dev_dbg(&info->client->dev, "%s\n", __func__);

//before Touch VDD off, send oscillator off command to prevent abnormal behavior
	ret = i2c_smbus_write_byte_data(info->client, MMS_OSC_OFF, 0x1);  // OSC off command
	dev_dbg(&info->client->dev, "i2c_smbus_write return : %d\n", ret);
	msleep(10);

	i2c_lock_adapter(adapter);
	
	mms_ts_power_on(info, 0);
	msleep(100);

	mms_ts_power_on(info, 1);
	msleep(50);

	i2c_unlock_adapter(adapter);
}
示例#15
0
static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len,
				 unsigned int sleep_low,
				 unsigned int sleep_hi, u8 max_count)
{
	int rc = -EIO;
	int count;

	struct i2c_msg msg1 = { tpm_dev.client->addr, 0, len + 1, tpm_dev.buf };

	if (len > TPM_BUFSIZE)
		return -EINVAL;

	if (!tpm_dev.client->adapter->algo->master_xfer)
		return -EOPNOTSUPP;
	i2c_lock_adapter(tpm_dev.client->adapter);

	/* prepend the 'register address' to the buffer */
	tpm_dev.buf[0] = addr;
	memcpy(&(tpm_dev.buf[1]), buffer, len);

	/*
	 * NOTE: We have to use these special mechanisms here and unfortunately
	 * cannot rely on the standard behavior of i2c_transfer.
	 */
	for (count = 0; count < max_count; count++) {
		rc = __i2c_transfer(tpm_dev.client->adapter, &msg1, 1);
		if (rc > 0)
			break;

		usleep_range(sleep_low, sleep_hi);
	}

	i2c_unlock_adapter(tpm_dev.client->adapter);
	if (rc <= 0)
		return -EIO;

	return 0;
}
示例#16
0
int pm860x_page_set_bits(struct i2c_client *i2c, int reg,
			 unsigned char mask, unsigned char data)
{
	unsigned char zero;
	unsigned char value;
	int ret;

	i2c_lock_adapter(i2c->adapter);
	read_device(i2c, 0xFA, 0, &zero);
	read_device(i2c, 0xFB, 0, &zero);
	read_device(i2c, 0xFF, 0, &zero);
	ret = read_device(i2c, reg, 1, &value);
	if (ret < 0)
		goto out;
	value &= ~mask;
	value |= data;
	ret = write_device(i2c, reg, 1, &value);
out:
	read_device(i2c, 0xFE, 0, &zero);
	read_device(i2c, 0xFC, 0, &zero);
	i2c_unlock_adapter(i2c->adapter);
	return ret;
}
示例#17
0
static int bcm5301x_xfer(struct i2c_adapter *adap, struct i2c_msg *pmsg_arr, int num)
{
	struct bcm5301x_i2c_data *pdata = adap->algo_data;
	struct i2c_msg *pmsg = &pmsg_arr[0];
	int rc = -ENOSYS;

	if (num < 1) {
		return -EINVAL;
	}

	i2c_lock_adapter(&pdata->bb_adap);

	if (bcm5301x_xfer_hw_supp(pmsg_arr, num)) {
		rc = bcm5301x_xfer_hw(pdata, pmsg);
	}

	if (rc < 0) {
		rc = bcm5301x_xfer_bb(&pdata->bb_adap, pmsg_arr, num);
	}

	i2c_unlock_adapter(&pdata->bb_adap);

	return rc;
}