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


C++ i2c_set_clientdata函数代码示例

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

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

示例1: z2_batt_probe

static int __devinit z2_batt_probe(struct i2c_client *client,
				const struct i2c_device_id *id)
{
	int ret = 0;
	int props = 1;	/* POWER_SUPPLY_PROP_PRESENT */
	struct z2_charger *charger;
	struct z2_battery_info *info = client->dev.platform_data;

	if (info == NULL) {
		dev_err(&client->dev,
			"Please set platform device platform_data"
			" to a valid z2_battery_info pointer!\n");
		return -EINVAL;
	}

	charger = kzalloc(sizeof(*charger), GFP_KERNEL);
	if (charger == NULL)
		return -ENOMEM;

	charger->bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
	charger->info = info;
	charger->client = client;
	i2c_set_clientdata(client, charger);

	mutex_init(&charger->work_lock);

	if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) {
		ret = gpio_request(info->charge_gpio, "BATT CHRG");
		if (ret)
			goto err;

		ret = gpio_direction_input(info->charge_gpio);
		if (ret)
			goto err2;

		set_irq_type(gpio_to_irq(info->charge_gpio),
				IRQ_TYPE_EDGE_BOTH);
		ret = request_irq(gpio_to_irq(info->charge_gpio),
				z2_charge_switch_irq, IRQF_DISABLED,
				"AC Detect", charger);
		if (ret)
			goto err3;
	}

	ret = z2_batt_ps_init(charger, props);
	if (ret)
		goto err3;

	INIT_WORK(&charger->bat_work, z2_batt_work);

	ret = power_supply_register(&client->dev, &charger->batt_ps);
	if (ret)
		goto err4;

	schedule_work(&charger->bat_work);

	return 0;

err4:
	kfree(charger->batt_ps.properties);
err3:
	if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio))
		free_irq(gpio_to_irq(info->charge_gpio), charger);
err2:
	if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio))
		gpio_free(info->charge_gpio);
err:
	kfree(charger);
	return ret;
}
开发者ID:karelh,项目名称:liquidware_beagleboard_linux,代码行数:70,代码来源:z2_battery.c


示例2: nxp_nci_i2c_probe

static int nxp_nci_i2c_probe(struct i2c_client *client,
			    const struct i2c_device_id *id)
{
	struct nxp_nci_i2c_phy *phy;
	struct nxp_nci_nfc_platform_data *pdata;
	int r;

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		nfc_err(&client->dev, "Need I2C_FUNC_I2C\n");
		r = -ENODEV;
		goto probe_exit;
	}

	phy = devm_kzalloc(&client->dev, sizeof(struct nxp_nci_i2c_phy),
			   GFP_KERNEL);
	if (!phy) {
		r = -ENOMEM;
		goto probe_exit;
	}

	phy->i2c_dev = client;
	i2c_set_clientdata(client, phy);

	pdata = client->dev.platform_data;

	if (!pdata && client->dev.of_node) {
		r = nxp_nci_i2c_parse_devtree(client);
		if (r < 0) {
			nfc_err(&client->dev, "Failed to get DT data\n");
			goto probe_exit;
		}
	} else if (pdata) {
		phy->gpio_en = pdata->gpio_en;
		phy->gpio_fw = pdata->gpio_fw;
	} else if (ACPI_HANDLE(&client->dev)) {
		r = nxp_nci_i2c_acpi_config(phy);
		if (r < 0)
			goto probe_exit;
		goto nci_probe;
	} else {
		nfc_err(&client->dev, "No platform data\n");
		r = -EINVAL;
		goto probe_exit;
	}

	r = devm_gpio_request_one(&phy->i2c_dev->dev, phy->gpio_en,
				  GPIOF_OUT_INIT_LOW, "nxp_nci_en");
	if (r < 0)
		goto probe_exit;

	r = devm_gpio_request_one(&phy->i2c_dev->dev, phy->gpio_fw,
				  GPIOF_OUT_INIT_LOW, "nxp_nci_fw");
	if (r < 0)
		goto probe_exit;

nci_probe:
	r = nxp_nci_probe(phy, &client->dev, &i2c_phy_ops,
			  NXP_NCI_I2C_MAX_PAYLOAD, &phy->ndev);
	if (r < 0)
		goto probe_exit;

	r = request_threaded_irq(client->irq, NULL,
				 nxp_nci_i2c_irq_thread_fn,
				 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
				 NXP_NCI_I2C_DRIVER_NAME, phy);
	if (r < 0)
		nfc_err(&client->dev, "Unable to register IRQ handler\n");

probe_exit:
	return r;
}
开发者ID:asmalldev,项目名称:linux,代码行数:71,代码来源:i2c.c


示例3: smb349_probe

static int __devinit smb349_probe(struct i2c_client *client,
				    const struct i2c_device_id *id)
{
	const struct smb349_platform_data *pdata;
	struct smb349_struct *smb349_chg;
	int ret = 0;

	pdata = client->dev.platform_data;

	if (pdata == NULL) {
		dev_err(&client->dev, "%s no platform data\n", __func__);
		ret = -EINVAL;
		goto out;
	}

	if (!i2c_check_functionality(client->adapter,
				I2C_FUNC_SMBUS_BYTE_DATA)) {
		ret = -EIO;
		goto out;
	}

	smb349_chg = kzalloc(sizeof(*smb349_chg), GFP_KERNEL);
	if (!smb349_chg) {
		ret = -ENOMEM;
		goto out;
	}

	smb349_chg->client = client;
	smb349_chg->chg_current_ma = pdata->chg_current_ma;
	ret = gpio_request(pdata->chg_susp_gpio, "smb349_suspend");
	if (ret) {
		dev_err(&client->dev, "%s gpio_request failed for %d ret=%d\n",
			__func__, pdata->chg_susp_gpio, ret);
		goto free_smb349_chg;
	}
	smb349_chg->chg_susp_gpio = pdata->chg_susp_gpio;

	ret = gpio_request(pdata->en_n_gpio, "smb349_charger_enable");
	if (ret) {
		dev_err(&client->dev, "%s gpio_request failed for %d ret=%d\n",
			__func__, pdata->en_n_gpio, ret);
		goto chg_susp_gpio_fail;
	}
	smb349_chg->en_n_gpio = pdata->en_n_gpio;

	i2c_set_clientdata(client, smb349_chg);

	ret = smb349_hwinit(smb349_chg);
	if (ret)
		goto free_smb349_chg;

	ret = smb349_init_ext_chg(smb349_chg);
	if (ret)
		goto chg_en_gpio_fail;

	the_smb349_chg = smb349_chg;

	spin_lock_init(&smb349_chg->lock);

	create_debugfs_entries(smb349_chg);
	INIT_WORK(&smb349_chg->chg_work, chg_worker);

	pr_info("OK connector present = %d\n", smb349_chg->present);
	return 0;

chg_en_gpio_fail:
	gpio_free(smb349_chg->en_n_gpio);
chg_susp_gpio_fail:
	gpio_free(smb349_chg->chg_susp_gpio);
free_smb349_chg:
	kfree(smb349_chg);
out:
	return ret;
}
开发者ID:ChangYeoun,项目名称:10.1,代码行数:74,代码来源:smb349.c


示例4: tc3589x_probe

static int tc3589x_probe(struct i2c_client *i2c,
				   const struct i2c_device_id *id)
{
	struct tc3589x_platform_data *pdata = i2c->dev.platform_data;
	struct device_node *np = i2c->dev.of_node;
	struct tc3589x *tc3589x;
	int ret;

	if (!pdata) {
		if (np) {
			pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL);
			if (!pdata)
				return -ENOMEM;

			ret = tc3589x_of_probe(np, pdata);
			if (ret)
				return ret;
		}
		else {
			dev_err(&i2c->dev, "No platform data or DT found\n");
			return -EINVAL;
		}
	}

	if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
				     | I2C_FUNC_SMBUS_I2C_BLOCK))
		return -EIO;

	tc3589x = kzalloc(sizeof(struct tc3589x), GFP_KERNEL);
	if (!tc3589x)
		return -ENOMEM;

	mutex_init(&tc3589x->lock);

	tc3589x->dev = &i2c->dev;
	tc3589x->i2c = i2c;
	tc3589x->pdata = pdata;
	tc3589x->irq_base = pdata->irq_base;
	tc3589x->num_gpio = id->driver_data;

	i2c_set_clientdata(i2c, tc3589x);

	ret = tc3589x_chip_init(tc3589x);
	if (ret)
		goto out_free;

	ret = tc3589x_irq_init(tc3589x, np);
	if (ret)
		goto out_free;

	ret = request_threaded_irq(tc3589x->i2c->irq, NULL, tc3589x_irq,
				   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
				   "tc3589x", tc3589x);
	if (ret) {
		dev_err(tc3589x->dev, "failed to request IRQ: %d\n", ret);
		goto out_free;
	}

	ret = tc3589x_device_init(tc3589x);
	if (ret) {
		dev_err(tc3589x->dev, "failed to add child devices\n");
		goto out_freeirq;
	}

	return 0;

out_freeirq:
	free_irq(tc3589x->i2c->irq, tc3589x);
out_free:
	kfree(tc3589x);
	return ret;
}
开发者ID:AdrianHuang,项目名称:linux-3.8.13,代码行数:72,代码来源:tc3589x.c


示例5: qt1070_probe

static int __devinit qt1070_probe(struct i2c_client *client,
				const struct i2c_device_id *id)
{
	struct qt1070_data *data;
	struct input_dev *input;
	int i;
	int err;

	err = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE);
	if (!err) {
		dev_err(&client->dev, "%s adapter not supported\n",
			dev_driver_string(&client->adapter->dev));
		return -ENODEV;
	}

	/* Identify the qt1070 chip */
	if (!qt1070_identify(client))
		return -ENODEV;

	data = kzalloc(sizeof(struct qt1070_data), GFP_KERNEL);
	input = input_allocate_device();
	if (!data || !input) {
		dev_err(&client->dev, "insufficient memory\n");
		err = -ENOMEM;
		goto err_free_mem;
	}

	data->client = client;
	data->input = input;
	data->irq = client->irq;

	input->name = "AT42QT1070 QTouch Sensor";
	input->dev.parent = &client->dev;
	input->id.bustype = BUS_I2C;

	/* Add the keycode */
	input->keycode = data->keycodes;
	input->keycodesize = sizeof(data->keycodes[0]);
	input->keycodemax = ARRAY_SIZE(qt1070_key2code);

	__set_bit(EV_KEY, input->evbit);

	for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) {
		data->keycodes[i] = qt1070_key2code[i];
		__set_bit(qt1070_key2code[i], input->keybit);
	}

	/* Calibrate device */
	qt1070_write(client, CALIBRATE_CMD, 1);
	msleep(QT1070_CAL_TIME);

	/* Soft reset */
	qt1070_write(client, RESET, 1);
	msleep(QT1070_RESET_TIME);

	/* Apply the interrupt */
	if (!client->irq) {
		dev_err(&client->dev, "please assign the irq to this device\n");
		goto err_free_mem;
	}

	err = request_threaded_irq(client->irq, NULL, qt1070_interrupt,
		IRQF_TRIGGER_NONE, client->dev.driver->name, data);
	if (err) {
		dev_err(&client->dev, "fail to request irq\n");
		goto err_free_mem;
	}

	/* Register the input device */
	err = input_register_device(data->input);
	if (err) {
		dev_err(&client->dev, "Failed to register input device\n");
		goto err_free_irq;
	}

	i2c_set_clientdata(client, data);

	/* Read to clear the chang line */
	qt1070_read(client, DET_STATUS);

	return 0;

err_free_irq:
	free_irq(client->irq, data);
err_free_mem:
	input_free_device(input);
	kfree(data);
	return err;
}
开发者ID:vickylinuxer,项目名称:at91sam9g35-kernel,代码行数:89,代码来源:qt1070.c


示例6: smb347_probe

static int smb347_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
	static char *battery[] = { "smb347-battery" };
	const struct smb347_charger_platform_data *pdata;
	struct device *dev = &client->dev;
	struct smb347_charger *smb;
	int ret;

	pdata = dev->platform_data;
	if (!pdata)
		return -EINVAL;

	if (!pdata->use_mains && !pdata->use_usb)
		return -EINVAL;

	smb = devm_kzalloc(dev, sizeof(*smb), GFP_KERNEL);
	if (!smb)
		return -ENOMEM;

	i2c_set_clientdata(client, smb);

	mutex_init(&smb->lock);
	smb->client = client;
	smb->pdata = pdata;

	ret = smb347_hw_init(smb);
	if (ret < 0)
		return ret;

	smb->mains.name = "smb347-mains";
	smb->mains.type = POWER_SUPPLY_TYPE_MAINS;
	smb->mains.get_property = smb347_mains_get_property;
	smb->mains.properties = smb347_mains_properties;
	smb->mains.num_properties = ARRAY_SIZE(smb347_mains_properties);
	smb->mains.supplied_to = battery;
	smb->mains.num_supplicants = ARRAY_SIZE(battery);

	smb->usb.name = "smb347-usb";
	smb->usb.type = POWER_SUPPLY_TYPE_USB;
	smb->usb.get_property = smb347_usb_get_property;
	smb->usb.properties = smb347_usb_properties;
	smb->usb.num_properties = ARRAY_SIZE(smb347_usb_properties);
	smb->usb.supplied_to = battery;
	smb->usb.num_supplicants = ARRAY_SIZE(battery);

	smb->battery.name = "smb347-battery";
	smb->battery.type = POWER_SUPPLY_TYPE_BATTERY;
	smb->battery.get_property = smb347_battery_get_property;
	smb->battery.properties = smb347_battery_properties;
	smb->battery.num_properties = ARRAY_SIZE(smb347_battery_properties);

	ret = power_supply_register(dev, &smb->mains);
	if (ret < 0)
		return ret;

	ret = power_supply_register(dev, &smb->usb);
	if (ret < 0) {
		power_supply_unregister(&smb->mains);
		return ret;
	}

	ret = power_supply_register(dev, &smb->battery);
	if (ret < 0) {
		power_supply_unregister(&smb->usb);
		power_supply_unregister(&smb->mains);
		return ret;
	}

	if (pdata->irq_gpio >= 0) {
		ret = smb347_irq_init(smb);
		if (ret < 0) {
			dev_warn(dev, "failed to initialize IRQ: %d\n", ret);
			dev_warn(dev, "disabling IRQ support\n");
		}
	}

	smb->dentry = debugfs_create_file("smb347-regs", S_IRUSR, NULL, smb,
					  &smb347_debugfs_fops);
	return 0;
}
开发者ID:DirtyDroidX,项目名称:android_kernel_htc_m8ul,代码行数:81,代码来源:smb347-charger.c


示例7: yas_probe

static int yas_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
{
	struct yas_state *st;
	struct iio_dev *indio_dev;
	int ret, i;
	int position;

	pr_err("%s : PROBE START\n", __func__);

	this_client = i2c;
	indio_dev = iio_device_alloc(sizeof(*st));
	if (!indio_dev) {
		ret = -ENOMEM;
		goto error_ret;
	}
	i2c_set_clientdata(i2c, indio_dev);

	indio_dev->name = YAS_MAG_NAME;
	indio_dev->dev.parent = &i2c->dev;
	indio_dev->info = &yas_info;
	indio_dev->channels = yas_channels;
	indio_dev->num_channels = ARRAY_SIZE(yas_channels);
	indio_dev->modes = INDIO_DIRECT_MODE;

	st = iio_priv(indio_dev);
	st->client = i2c;
	st->sampling_frequency = 20;
	st->mag.callback.device_open = yas_device_open;
	st->mag.callback.device_close = yas_device_close;
	st->mag.callback.device_read = yas_device_read;
	st->mag.callback.device_write = yas_device_write;
	st->mag.callback.usleep = yas_usleep;
	st->mag.callback.current_time = yas_current_time;
	INIT_DELAYED_WORK(&st->work, yas_work_func);
	mutex_init(&st->lock);
#ifdef CONFIG_HAS_EARLYSUSPEND
	st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	st->sus.suspend = yas_early_suspend;
	st->sus.resume = yas_late_resume;
	register_early_suspend(&st->sus);
#endif
	for (i = 0; i < 3; i++)
		st->compass_data[i] = 0;

	ret = yas_probe_buffer(indio_dev);
	if (ret)
		goto error_free_dev;
	ret = yas_probe_trigger(indio_dev);
	if (ret)
		goto error_remove_buffer;
	ret = iio_device_register(indio_dev);
	if (ret)
		goto error_remove_trigger;
	ret = yas_mag_driver_init(&st->mag);
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}
	ret = st->mag.init();
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}

	ret = yas_parse_dt(&i2c->dev, st);
	if(!ret){
	    position = st->position;
	    ret = st->mag.set_position(position);
	    pr_info("[SENSOR] set_position (%d)\n", position);
	}
	spin_lock_init(&st->spin_lock);

	ret = sensors_register(factory_dev, indio_dev, mag_sensor_attrs,
		MODULE_NAME_MAG);
	if (ret < 0) {
		pr_err("%s: cound not register mag sensor device(%d).\n",
			__func__, ret);
		goto err_mag_sensor_register_failed;
	}

	pr_err("%s : PROBE END\n", __func__);
	return 0;

err_mag_sensor_register_failed:
error_unregister_iio:
	iio_device_unregister(indio_dev);
error_remove_trigger:
	yas_remove_trigger(indio_dev);
error_remove_buffer:
	yas_remove_buffer(indio_dev);
error_free_dev:
#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&st->sus);
#endif
	iio_device_free(indio_dev);
error_ret:
	i2c_set_clientdata(i2c, NULL);
	this_client = NULL;
	return ret;
}
开发者ID:tyler6389,项目名称:android_kernel_samsung_slte,代码行数:100,代码来源:yas_mag_kernel.c


示例8: rmi_i2c_probe

static int __devinit rmi_i2c_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct rmi_phys_device *rmi_phys;
	struct rmi_i2c_data *data;
	struct rmi_device_platform_data *pdata = client->dev.platform_data;
	int error;

	if (!pdata) {
		printk( "ITUCH : Device(%s) no platform data\n", dev_name( &client->dev ) );
		return -EINVAL;
	}
	printk( "ITUCH : Probing %s at %#02x (IRQ %d)\n", pdata->sensor_name ? pdata->sensor_name : "-no name-", client->addr, pdata->attn_gpio );

	error = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if (!error) {
		printk( "ITUCH : Device(%s) i2c_check_functionality error(%d)\n", dev_name( &client->dev ), error );
		return error;
	}

	rmi_phys = kzalloc(sizeof(struct rmi_phys_device), GFP_KERNEL);
	if (!rmi_phys)
		return -ENOMEM;

	data = kzalloc(sizeof(struct rmi_i2c_data), GFP_KERNEL);
	if (!data) {
		error = -ENOMEM;
		goto err_phys;
	}

	if( gpio_request( pdata->reset_gpio, "RMI4_RESET" ) )
		printk( "ITUCH : Unable to request gpio%d\n", pdata->reset_gpio );

	reset_touch( pdata );

	data->enabled = true;	/* We plan to come up enabled. */
	data->irq = gpio_to_irq(pdata->attn_gpio);
	if (pdata->level_triggered) {
		data->irq_flags = IRQF_ONESHOT |
			((pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ?
			IRQF_TRIGGER_HIGH : IRQF_TRIGGER_LOW);
	} else {
		data->irq_flags =
			(pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ?
			IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
	}
	data->phys = rmi_phys;

	rmi_phys->data = data;
	rmi_phys->dev = &client->dev;

	rmi_phys->write = rmi_i2c_write;
	rmi_phys->write_block = rmi_i2c_write_block;
	rmi_phys->read = rmi_i2c_read;
	rmi_phys->read_block = rmi_i2c_read_block;
	rmi_phys->enable_device = enable_device;
	rmi_phys->disable_device = disable_device;

	rmi_phys->info.proto = phys_proto_name;

	mutex_init(&data->page_mutex);

	/* Setting the page to zero will (a) make sure the PSR is in a
	 * known state, and (b) make sure we can talk to the device.
	 */
	error = rmi_set_page(rmi_phys, 0);
	if (error) {
		printk( "ITUCH : Device(%s) failed to set page select to 0\n", dev_name( &client->dev ) );
		goto err_data;
	}

	if (pdata->gpio_config) {
		error = pdata->gpio_config(pdata->gpio_data, true);
		if (error < 0) {
			printk( "ITUCH : Device(%s) failed to setup irq%d\n", dev_name( &client->dev ), pdata->attn_gpio );
			goto err_data;
		}
	}

	error = rmi_register_phys_device(rmi_phys);
	if (error) {
		printk( "ITUCH : Device(%s) failed to register physical driver at 0x%.2X\n", dev_name( &client->dev ), client->addr );
		goto err_gpio;
	}
	i2c_set_clientdata(client, rmi_phys);

	if (pdata->attn_gpio > 0) {
		error = acquire_attn_irq(data);
		if (error < 0) {
			printk( "ITUCH : Device(%s) request_threaded_irq(IRQ%d) failed\n", dev_name( &client->dev ), pdata->attn_gpio );
			goto err_unregister;
		}
	}

#if defined(CONFIG_RMI4_DEV)
	error = gpio_export(pdata->attn_gpio, false);
	if (error) {
		printk( "ITUCH : Device(%s) failed to export ATTN gpio\n", dev_name( &client->dev ) );
		error = 0;
	} else {
//.........这里部分代码省略.........
开发者ID:C-Aniruddh,项目名称:PixCMKernel,代码行数:101,代码来源:rmi_i2c.c


示例9: gp2a_probe

static int __devinit gp2a_probe(struct i2c_client *client,
				const struct i2c_device_id *id)
{
	const struct gp2a_platform_data *pdata = client->dev.platform_data;
	struct gp2a_data *dt;
	int error;

	if (!pdata)
		return -EINVAL;

	if (pdata->hw_setup) {
		error = pdata->hw_setup(client);
		if (error < 0)
			return error;
	}

	error = gpio_request_one(pdata->vout_gpio, GPIOF_IN, GP2A_I2C_NAME);
	if (error)
		goto err_hw_shutdown;

	dt = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL);
	if (!dt) {
		error = -ENOMEM;
		goto err_free_gpio;
	}

	dt->pdata = pdata;
	dt->i2c_client = client;

	error = gp2a_initialize(dt);
	if (error < 0)
		goto err_free_mem;

	dt->input = input_allocate_device();
	if (!dt->input) {
		error = -ENOMEM;
		goto err_free_mem;
	}

	input_set_drvdata(dt->input, dt);

	dt->input->open = gp2a_device_open;
	dt->input->close = gp2a_device_close;
	dt->input->name = GP2A_I2C_NAME;
	dt->input->id.bustype = BUS_I2C;
	dt->input->dev.parent = &client->dev;

	input_set_capability(dt->input, EV_SW, SW_FRONT_PROXIMITY);

	error = request_threaded_irq(client->irq, NULL, gp2a_irq,
			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
				IRQF_ONESHOT,
			GP2A_I2C_NAME, dt);
	if (error) {
		dev_err(&client->dev, "irq request failed\n");
		goto err_free_input_dev;
	}

	error = input_register_device(dt->input);
	if (error) {
		dev_err(&client->dev, "device registration failed\n");
		goto err_free_irq;
	}

	device_init_wakeup(&client->dev, pdata->wakeup);
	i2c_set_clientdata(client, dt);

	return 0;

err_free_irq:
	free_irq(client->irq, dt);
err_free_input_dev:
	input_free_device(dt->input);
err_free_mem:
	kfree(dt);
err_free_gpio:
	gpio_free(pdata->vout_gpio);
err_hw_shutdown:
	if (pdata->hw_shutdown)
		pdata->hw_shutdown(client);
	return error;
}
开发者ID:33d,项目名称:linux-2.6.21-hh20,代码行数:82,代码来源:gp2ap002a00f.c


示例10: rt5033_mfd_probe

static int __devinit rt5033_mfd_probe(struct i2c_client *i2c,
		const struct i2c_device_id *id)
{
	int ret = 0;
	u8 data = 0;

	rt5033_mfd_chip_t *chip;
	rt5033_mfd_platform_data_t *pdata = i2c->dev.platform_data;

	pr_info("%s : RT5033 MFD Driver start probe\n", __func__);

	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
	if (chip ==  NULL) {
		dev_err(chip->dev, "Memory is not enough.\n");
		ret = -ENOMEM;
		goto err_mfd_nomem;
	}

	ret = i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
			I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_I2C_BLOCK);
	if (!ret) {
		ret = i2c_get_functionality(i2c->adapter);
		dev_err(chip->dev, "I2C functionality is not supported.\n");
		ret = -ENOSYS;
		goto err_i2cfunc_not_support;
	}

	chip->dev = &i2c->dev;
	chip->i2c_client = i2c;
	chip->pdata = pdata;

	pdata->irq_base = irq_alloc_descs(-1, 0, RT5033_IRQS_NR, -1);
	if (pdata->irq_base < 0) {
		pr_err("%s:%s irq_alloc_descs Fail! ret(%d)\n",
				"rt5033-mfd", __func__, pdata->irq_base);
		ret = -EINVAL;
		goto irq_base_err;
	} else {
		chip->irq_base = pdata->irq_base;
	}

	i2c_set_clientdata(i2c, chip);
	mutex_init(&chip->io_lock);

	wake_lock_init(&(chip->irq_wake_lock), WAKE_LOCK_SUSPEND,
			"rt5033mfd_wakelock");

	ret = rt5033_clr_bits(i2c, 0x47, 1<<3);
	pr_info("Diable MANUAL RESET (%d)\n", ret);

	ret = rt5033_init_irq(chip);

	if (ret < 0) {
		dev_err(chip->dev,
				"Error : can't initialize RT5033 MFD irq\n");
		goto err_init_irq;
	}

#ifdef CONFIG_REGULATOR_RT5033
#if (LINUX_VERSION_CODE>=KERNEL_VERSION(3,6,0))
	ret = mfd_add_devices(chip->dev, 0, &rt5033_regulator_devs[0],
			ARRAY_SIZE(rt5033_regulator_devs),
			NULL, chip->irq_base, NULL);
#else
	ret = mfd_add_devices(chip->dev, 0, &rt5033_regulator_devs[0],
			ARRAY_SIZE(rt5033_regulator_devs),
			NULL, chip->irq_base);
#endif
	if (ret < 0) {
		dev_err(chip->dev,
				"Error : can't add regulator\n");
		goto err_add_regulator_devs;
	}
#endif /*CONFIG_REGULATOR_RT5033*/

#ifdef CONFIG_FLED_RT5033
#if (LINUX_VERSION_CODE>=KERNEL_VERSION(3,6,0))
	ret = mfd_add_devices(chip->dev, 0, &rt5033_fled_devs[0],
			ARRAY_SIZE(rt5033_fled_devs),
			NULL, chip->irq_base, NULL);
#else
	ret = mfd_add_devices(chip->dev, 0, &rt5033_fled_devs[0],
			ARRAY_SIZE(rt5033_fled_devs),
			NULL, chip->irq_base);
#endif
	if (ret < 0)
	{
		dev_err(chip->dev,"Failed : add FlashLED devices");
		goto err_add_fled_devs;
	}
#endif /*CONFIG_FLED_RT5033*/


#ifdef CONFIG_CHARGER_RT5033
#if (LINUX_VERSION_CODE>=KERNEL_VERSION(3,6,0))
	ret = mfd_add_devices(chip->dev, 0, &rt5033_charger_devs[0],
			ARRAY_SIZE(rt5033_charger_devs),
			NULL, chip->irq_base, NULL);
#else
	ret = mfd_add_devices(chip->dev, 0, &rt5033_charger_devs[0],
//.........这里部分代码省略.........
开发者ID:dflow81,项目名称:android_kernel_samsung_goyawifi,代码行数:101,代码来源:rt5033_core.c


示例11: lsm303dlh_m_probe

static int lsm303dlh_m_probe(struct i2c_client *client,
					const struct i2c_device_id *id)
{
	struct lsm303dlh_m_data *data;
	int err = 0;

	data = kzalloc(sizeof(struct lsm303dlh_m_data), GFP_KERNEL);
	if (!data) {
		dev_err(&client->dev, "memory allocation failed\n");
		err = -ENOMEM;
		goto exit;
	}
	/* check for valid platform data */
	if (!client->dev.platform_data) {
		dev_err(&client->dev, "Invalid platform data\n");
		err = -ENOMEM;
		goto exit1;
	}
	data->pdata = client->dev.platform_data;

	data->mode = SLEEP_MODE;
	data->config = NORMAL_CFG;
	data->range = RANGE_1_3G;
	data->rate = RATE_00_75;
	data->device_status = DEVICE_OFF;
	data->client = client;

	i2c_set_clientdata(client, data);

	data->regulator = regulator_get(&client->dev, "vdd");
	if (IS_ERR(data->regulator)) {
		err = PTR_ERR(data->regulator);
		dev_err(&client->dev, "failed to get regulator = %d\n", err);
		goto exit1;
	}
	/* Enable regulator */
	lsm303dlh_m_enable(data);

	lsm303dlh_m_setup(client);

	mutex_init(&data->lock);

	data->indio_dev = iio_allocate_device(0);
	if (!data->indio_dev) {
		dev_err(&client->dev, "iio allocation failed\n");
		err = -ENOMEM;
		goto exit2;
	}
	data->indio_dev->info = &lsmdlh303m_info;
	data->indio_dev->dev.parent = &client->dev;
	data->indio_dev->dev_data = (void *)data;
	data->indio_dev->modes = INDIO_DIRECT_MODE;

	err = iio_device_register(data->indio_dev);
	if (err)
		goto exit3;

#ifdef CONFIG_HAS_EARLYSUSPEND
	data->early_suspend.level =
				EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	data->early_suspend.suspend = lsm303dlh_m_early_suspend;
	data->early_suspend.resume = lsm303dlh_m_late_resume;
	register_early_suspend(&data->early_suspend);
#endif
	/* Disable regulator */
	lsm303dlh_m_disable(data);

	return 0;

exit3:
	iio_free_device(data->indio_dev);
exit2:
	lsm303dlh_m_disable(data);
	regulator_put(data->regulator);
exit1:
	kfree(data);
exit:
	return err;
}
开发者ID:Agontuk,项目名称:android_kernel_sony_u8500,代码行数:79,代码来源:lsm303dlh.c


示例12: summit_smb347_probe

static int summit_smb347_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	struct summit_smb347_info *info;
	int ret = 0;
#ifdef SUMMIT_SMB347_DEBUG
	int i = 0;
#endif
	int error = 0;
	unsigned char value = 0xff;

	info = kzalloc(sizeof(*info), GFP_KERNEL);
	if (!info) {
		return -ENOMEM;
	}

	client->addr = SUMMIT_SMB347_I2C_ADDRESS;

	i2c_set_clientdata(client, info);
	info->client = client;

	info->charger.name = "summit_smb347_ac";
	info->charger.type = POWER_SUPPLY_TYPE_MAINS;
	info->charger.get_property = smb347_get_ac_property;
	info->charger.properties = smb347_charger_props;
	info->charger.num_properties = ARRAY_SIZE(smb347_charger_props);

	info->usb.name = "summit_smb347_usb";
	info->usb.type = POWER_SUPPLY_TYPE_USB;
	info->usb.get_property = smb347_get_usb_property;
	info->usb.properties = smb347_usb_props;
	info->usb.num_properties = ARRAY_SIZE(smb347_usb_props);

	info->battery.name = "summit_smb347_battery";
	info->battery.type = POWER_SUPPLY_TYPE_BATTERY;
	info->battery.get_property = smb347_get_battery_property;
	info->battery.properties = smb347_battery_props;
	info->battery.num_properties = ARRAY_SIZE(smb347_battery_props);

	ret = power_supply_register(&client->dev, &info->charger);
	if (ret) {
		dev_err(&client->dev, "failed: power supply register\n");
		i2c_set_clientdata(client, NULL);
		kfree(info);
		return ret;
	}

	ret = power_supply_register(&client->dev, &info->usb);
	if (ret) {
		dev_err(&client->dev, "failed: power supply register\n");
		i2c_set_clientdata(client, NULL);
		kfree(info);
		return ret;
	}

	ret = power_supply_register(&client->dev, &info->battery);
	if (ret) {
		dev_err(&client->dev, "failed: battery power supply register\n");
		i2c_set_clientdata(client, NULL);
		kfree(info);
		return ret;
	}

	summit_smb347_i2c_client = info->client;
	summit_smb347_i2c_client->addr = SUMMIT_SMB347_I2C_ADDRESS;

	if (summit_smb347_read_id(&summit_smb347_id_reg) < 0)
		return -ENODEV;

	printk(KERN_INFO "Summit SMB347 detected, chip_id=0x%x\n", summit_smb347_id_reg);

	ret = request_irq(summit_smb347_i2c_client->irq, summit_smb347_irq,
			IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING, "summit_smb347", NULL);

	if (ret != 0) {
		printk(KERN_ERR "Failed to request IRQ %d: %d\n",
				summit_smb347_i2c_client->irq, ret);
	}

	summit_smb347_init_registers();

#ifdef SUMMIT_SMB347_DEBUG
	for (i = 0; i <= 0xE; i++) {
		ret = summit_smb347_i2c_read(i, &value);
		printk(KERN_INFO "summit_smb347: reg=%d, value=0x%x\n", i, value);
	}

	for (i = 0x30; i <= 0x3F; i++) {
		ret = summit_smb347_i2c_read(i, &value);
		printk(KERN_INFO "summit_smb347: reg=%d, value=0x%x\n", i, value);
	}
#endif

	error = sysdev_class_register(&smb347_reg_sysclass);

	if (!error)
		error = sysdev_register(&device_smb347_reg);

	if (!error)
		error = sysdev_create_file(&device_smb347_reg, &attr_smb347_reg);

//.........这里部分代码省略.........
开发者ID:Loki154,项目名称:Android-kernel-for-kindle-fire,代码行数:101,代码来源:summit_smb347.c


示例13: cyttsp4_i2c_probe

static int cyttsp4_i2c_probe(struct i2c_client *client,
	const struct i2c_device_id *i2c_id)
{
	struct cyttsp4_i2c *ts_i2c;
	struct device *dev = &client->dev;
	char const *adap_id = dev_get_platdata(dev);
	char const *id;
	int rc;

	dev_info(dev, "%s: Starting %s probe...\n", __func__, CYTTSP4_I2C_NAME);

	dev_dbg(dev, "%s: debug on\n", __func__);
	dev_vdbg(dev, "%s: verbose debug on\n", __func__);

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_err(dev, "%s: fail check I2C functionality\n", __func__);
		rc = -EIO;
		goto error_alloc_data_failed;
	}

	ts_i2c = kzalloc(sizeof(struct cyttsp4_i2c), GFP_KERNEL);
	if (ts_i2c == NULL) {
		dev_err(dev, "%s: Error, kzalloc.\n", __func__);
		rc = -ENOMEM;
		goto error_alloc_data_failed;
	}

	mutex_init(&ts_i2c->lock);
	ts_i2c->client = client;
	client->dev.bus = &i2c_bus_type;
	i2c_set_clientdata(client, ts_i2c);
	dev_set_drvdata(&client->dev, ts_i2c);

	if (adap_id)
		id = adap_id;
	else
		id = CYTTSP4_I2C_NAME;

	dev_dbg(dev, "%s: add adap='%s' (CYTTSP4_I2C_NAME=%s)\n", __func__, id,
		CYTTSP4_I2C_NAME);

	pm_runtime_enable(&client->dev);

	rc = cyttsp4_add_adapter(id, &ops, dev);
	if (rc) {
		dev_err(dev, "%s: Error on probe %s\n", __func__,
			CYTTSP4_I2C_NAME);
		goto add_adapter_err;
	}

	dev_info(dev, "%s: Successful probe %s\n", __func__, CYTTSP4_I2C_NAME);

	return 0;

add_adapter_err:
	pm_runtime_disable(&client->dev);
	dev_set_drvdata(&client->dev, NULL);
	i2c_set_clientdata(client, NULL);
	kfree(ts_i2c);
error_alloc_data_failed:
	return rc;
}
开发者ID:jawad6233,项目名称:android_kernel_huawei_h30t00,代码行数:62,代码来源:cyttsp4_i2c.c


示例14: bebot_base_probe

static int bebot_base_probe(struct i2c_client *client,
			    const struct i2c_device_id *id)
{
	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
	struct bebot_base_device *base;
	struct senseact_poll_device *senseact_poll;
	struct senseact_device *senseact;
	int rc;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA
				     | I2C_FUNC_SMBUS_I2C_BLOCK))
		return -ENODEV;

	base = kzalloc(sizeof(struct bebot_base_device), GFP_KERNEL);
	if (!base) {
		dev_err(&client->dev, "not enough memory for bebot_base device\n");
		rc = -ENOMEM;
		goto exit;
	}

	/* set speed to 0 */
	rc = i2c_smbus_write_i2c_block_data(client, SETSPEED_REG, SETSPEED_COUNT, base->speed);
	if (rc < 0)
		goto exit_kfree;

	base->client = client;

	senseact_poll = senseact_allocate_poll_device();
	if (!senseact_poll) {
		dev_err(&client->dev, "not enough memory for senseact poll device\n");
		rc = -ENOMEM;
		goto exit_kfree;
	}

	base->senseact_poll = senseact_poll;

	/* set senseact poll device handler */
	senseact_poll->poll = bebot_base_poll;
	senseact_poll->poll_interval = 250;

	/* set senseact device handler */	
	senseact = senseact_poll->senseact;
	senseact->name = client->name;
	snprintf(base->addr, sizeof(base->addr), "%01d-%04x", client->adapter->nr, client->addr);
	senseact->addr = base->addr;
	senseact->dev.parent = &client->dev;
	senseact->pass = bebot_base_pass;

	senseact_set_drvdata(senseact, base);

	senseact_set_capabilities(senseact, SENSEACT_TYPE_SPEED, 4);
	senseact_set_capabilities(senseact, SENSEACT_TYPE_INCREMENT, 2);
	senseact_set_capabilities(senseact, SENSEACT_TYPE_POSITION, 2);
	senseact_set_capability(senseact, SENSEACT_TYPE_ANGLE);

	rc = senseact_register_poll_device(senseact_poll);
	if (rc) {
		dev_err(&client->dev, "could not register senseact poll device\n");
		goto exit_free_poll;
	}

	i2c_set_clientdata(client, base);

	return 0;

exit_free_poll:
	senseact_free_poll_device(senseact_poll);
exit_kfree:
	kfree(base);
exit:
	return rc;
}
开发者ID:BackupTheBerlios,项目名称:openrobotix-svn,代码行数:72,代码来源:bebot-base.c


示例15: cs42l52_i2c_probe

static int cs42l52_i2c_probe(struct i2c_client *i2c_client,
			     const struct i2c_device_id *id)
{
	struct cs42l52_private *cs42l52;
	struct cs42l52_platform_data *pdata = dev_get_platdata(&i2c_client->dev);
	int ret;
	unsigned int devid = 0;
	unsigned int reg;
	u32 val32;

	cs42l52 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l52_private),
			       GFP_KERNEL);
	if (cs42l52 == NULL)
		return -ENOMEM;
	cs42l52->dev = &i2c_client->dev;

	cs42l52->regmap = devm_regmap_init_i2c(i2c_client, &cs42l52_regmap);
	if (IS_ERR(cs42l52->regmap)) {
		ret = PTR_ERR(cs42l52->regmap);
		dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret);
		return ret;
	}
	if (pdata) {
		cs42l52->pdata = *pdata;
	} else {
		pdata = devm_kzalloc(&i2c_client->dev,
				     sizeof(struct cs42l52_platform_data),
				GFP_KERNEL);
		if (!pdata) {
			dev_err(&i2c_client->dev, "could not allocate pdata\n");
			return -ENOMEM;
		}
		if (i2c_client->dev.of_node) {
			if (of_property_read_bool(i2c_client->dev.of_node,
				"cirrus,mica-differential-cfg"))
				pdata->mica_diff_cfg = true;

			if (of_property_read_bool(i2c_client->dev.of_node,
				"cirrus,micb-differential-cfg"))
				pdata->micb_diff_cfg = true;

			if (of_property_read_u32(i2c_client->dev.of_node,
				"cirrus,micbias-lvl", &val32) >= 0)
				pdata->micbias_lvl = val32;

			if (of_property_read_u32(i2c_client->dev.of_node,
				"cirrus,chgfreq-divisor", &val32) >= 0)
				pdata->chgfreq = val32;

			pdata->reset_gpio =
				of_get_named_gpio(i2c_client->dev.of_node,
						"cirrus,reset-gpio", 0);
		}
		cs42l52->pdata = *pdata;
	}

	if (cs42l52->pdata.reset_gpio) {
		ret = devm_gpio_request_one(&i2c_client->dev,
					    cs42l52->pdata.reset_gpio,
					    GPIOF_OUT_INIT_HIGH,
					    "CS42L52 /RST");
		if (ret < 0) {
			dev_err(&i2c_client->dev, "Failed to request /RST %d: %d\n",
				cs42l52->pdata.reset_gpio, ret);
			return ret;
		}
		gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 0);
		gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 1);
	}

	i2c_set_clientdata(i2c_client, cs42l52);

	ret = regmap_register_patch(cs42l52->regmap, cs42l52_threshold_patch,
				    ARRAY_SIZE(cs42l52_threshold_patch));
	if (ret != 0)
		dev_warn(cs42l52->dev, "Failed to apply regmap patch: %d\n",
			 ret);

	ret = regmap_read(cs42l52->regmap, CS42L52_CHIP, &reg);
	devid = reg & CS42L52_CHIP_ID_MASK;
	if (devid != CS42L52_CHIP_ID) {
		ret = -ENODEV;
		dev_err(&i2c_client->dev,
			"CS42L52 Device ID (%X). Expected %X\n",
			devid, CS42L52_CHIP_ID);
		return ret;
	}

	dev_info(&i2c_client->dev, "Cirrus Logic CS42L52, Revision: %02X\n",
		 reg & CS42L52_CHIP_REV_MASK);

	/* Set Platform Data */
	if (cs42l52->pdata.mica_diff_cfg)
		regmap_update_bits(cs42l52->regmap, CS42L52_MICA_CTL,
				   CS42L52_MIC_CTL_TYPE_MASK,
				cs42l52->pdata.mica_diff_cfg <<
				CS42L52_MIC_CTL_TYPE_SHIFT);

	if (cs42l52->pdata.micb_diff_cfg)
		regmap_update_bits(cs42l52->regmap, CS42L52_MICB_CTL,
//.........这里部分代码省略.........
开发者ID:383530895,项目名称:linux,代码行数:101,代码来源:cs42l52.c


示例16: stkxxx_probe

/**
 * stkxxx_probe() - initialize the I2C client
 * @client:    client to initialize
 * @id:                I2C device ID
 */
static int stkxxx_probe(struct i2c_client *client,
               const struct i2c_device_id *id)
{
       struct stkxxx *ts;
       int err = 0;

       ts = kzalloc(sizeof(struct stkxxx), GFP_KERNEL);
       if (!ts) {
               err = -ENOMEM;
               goto fail;
       }

    ts->client = client;
    stkxxx_reset(ts);

    if (stkxxx_register_input(ts) < 0) {
        dev_err(&client->dev, "register input fail!\n");
        goto fail;
    }

       /* setup platform-specific hooks */
       ts->pdata = client->dev.platform_data;
       if (!ts->pdata || !ts->pdata->init_irq || !ts->pdata->get_irq_level) {
               dev_err(&client->dev, "no platform-specific callbacks "
                               "provided\n");
               err = -ENXIO;
               goto fail;
       }

       if (ts->pdata->init_irq) {
               err = ts->pdata->init_irq();
               if (err < 0) {
                       dev_err(&client->dev, "failed to initialize IRQ#%d: "
                                       "%d\n", client->irq, err);
                       goto fail;
               }
       }

       spin_lock_init(&ts->lock);
#ifdef TS_DELAY_WORK
    INIT_DELAYED_WORK(&ts->work, stkxxx_work);
#else
       hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
       ts->timer.function = stkxxx_timer;
    INIT_WORK(&ts->work, stkxxx_work);
    ts->workqueue = create_singlethread_workqueue("stkxxx");
    if (ts->workqueue == NULL) {
        dev_err(&client->dev, "can't create work queue\n");
        err = -ENOMEM;
        goto fail;
    }
    printk("work create: %x\n", ts->workqueue);
#endif

       ts->pendown = 0;
       ts->touching_num = 0;
       ts->pre_touching_num = 0;
       err = request_irq(client->irq, stkxxx_interrupt, IRQF_TRIGGER_FALLING,
                       client->dev.driver->name, client);
       if (err) {
               dev_err(&client->dev, "failed to request IRQ#%d: %d\n",
                               client->irq, err);
                goto fail_irq;
       }

       i2c_set_clientdata(client, ts);
//  INIT_DELAYED_WORK(&ts->cal_work, stkxxx_cal_work);
//  schedule_delayed_work(&ts->cal_work, 20*HZ);
       err = 0;
       goto out;

fail_irq:
       free_irq(client->irq, client);

fail:
       if (ts) {
               input_free_device(ts->input);
               kfree(ts);
       }

       i2c_set_clientdata(client, NULL);
out:
       printk("stkxxx touch screen driver ok\n");
       return err;
}
开发者ID:OpenLD,项目名称:linux-wetek-3.10.y,代码行数:90,代码来源:stkxxx.c


示例17: ds278x_battery_probe

static int ds278x_battery_probe(struct i2c_client *client,
				const struct i2c_device_id *id)
{
	struct ds278x_platform_data *pdata = client->dev.platform_data;
	struct ds278x_info *info;
	int ret;
	int num;

	/*
	 * ds2786 should have the sense resistor value set
	 * in the platform data
	 */
	if (id->driver_data == DS2786 && !pdata) {
		dev_err(&client->dev, "missing platform data for ds2786\n");
		return -EINVAL;
	}

	/* Get an ID for this battery */
	ret = idr_pre_get(&battery_id, GFP_KERNEL);
	if (ret == 0) {
		ret = -ENOMEM;
		goto fail_id;
	}

	mutex_lock(&battery_lock);
	ret = idr_get_new(&battery_id, client, &num);
	mutex_unlock(&battery_lock);
	if (ret < 0)
		goto fail_id;

	info = kzalloc(sizeof(*info), GFP_KERNEL);
	if (!info) {
		ret = -ENOMEM;
		goto fail_info;
	}

	info->battery.name = kasprintf(GFP_KERNEL, "%s-%d", client->name, num);
	if (!info->battery.name) {
		ret = -ENOMEM;
		goto fail_name;
	}

	if (id->driver_data == DS2786)
		info->rsns = pdata->rsns;

	i2c_set_clientdata(client, info);
	info->client = client;
	info->id = num;
	info->ops  = &ds278x_ops[id->driver_data];
	ds278x_power_supply_init(&info->battery);

	ret = power_supply_register(&client->dev, &info->battery);
	if (ret) {
		dev_err(&client->dev, "failed to register battery\n");
		goto fail_register;
	}

	return 0;

fail_register:
	kfree(info->battery.name);
fail_name:
	kfree(info);
fail_info:
	mutex_lock(&battery_lock);
	idr_remove(&battery_id, num);
	mutex_unlock(&battery_lock);
fail_id:
	return ret;
}
开发者ID:119-org,项目名称:hi3518-osdrv,代码行数:70,代码来源:ds2782_battery.c


示例18: yas_probe

static int yas_probe(struct i2c_client *client,
	const struct i2c_device_id *id)
{
	struct yas_state *st;
	struct iio_dev *indio_dev;
	int ret, i;
	u8 temp;

	pr_info("[SENSOR]: %s - Probe Start!\n", __func__);

	this_client = client;

	/* Check if the device is there or not. */
	ret = yas_device_read(YAS_TYPE_MAG, REG_DIDR, &temp, 1);
	if (ret < 0) {
		ret = -ENODEV;
		goto error_check_dev;
	}

	indio_dev = iio_device_alloc(sizeof(*st));
	if (!indio_dev) {
		ret = -ENOMEM;
		goto error_ret;
	}

	st = iio_priv(indio_dev);
	i2c_set_clientdata(client, indio_dev);

	st->client = client;

	/* IIO device init */
	indio_dev->name = "magnetic_sensor";
	indio_dev->channels = yas_channels;
	indio_dev->num_channels = ARRAY_SIZE(yas_channels);
	indio_dev->dev.parent = &client->dev;
	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->info = &yas_info;

	st->sampling_frequency = 20;
	st->mag.callback.device_open = yas_device_open;
	st->mag.callback.device_close = yas_device_close;
	st->mag.callback.device_read = yas_device_read;
	st->mag.callback.device_write = yas_device_write;
	st->mag.callback.usleep = yas_usleep;
	st->mag.callback.current_time = yas_current_time;

	INIT_DELAYED_WORK(&st->work, yas_work_func);
	mutex_init(&st->lock);
#ifdef CONFIG_HAS_EARLYSUSPEND
	st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	st->sus.suspend = yas_early_suspend;
	st->sus.resume = yas_late_resume;
	register_early_suspend(&st->sus);
#endif
	for (i = 0; i < 3; i++)
		st->compass_data[i] = 0;

	ret = yas_probe_buffer(indio_dev);
	if (ret)
		goto error_free_dev;
	ret = yas_probe_trigger(indio_dev);
	if (ret)
		goto error_remove_buffer;
	ret = iio_device_register(indio_dev);
	if (ret)
		goto error_remove_trigger;
	ret = yas_mag_driver_init(&st->mag);
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}
	ret = st->mag.init();
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}
	ret = yas_parse_dt(st, &client->dev);
	if (ret < 0) {
		pr_err("%s of_node error\n", __func__);
		ret = -ENODEV;
		goto error_of_node;
	}
	ret= st->mag.set_position(st->chip_pos);
	if (ret < 0) {
		ret = -EFAULT;
		goto error_of_node;
	}
	spin_lock_init(&st->spin_lock);

	ret = sensors_register(st->factory_dev, st, mag_sensor_attrs,
		MODULE_NAME);
	if (ret < 0) {
		pr_err("[SENSOR] %s: cound not register mag device(%d).\n",
			__func__, ret);
		goto err_mag_sensor_register_failed;
	}

	pr_info("[SENSOR]: %s - Probe done!\n", __func__);
	return 0;

//.........这里部分代码省略.........
开发者ID:ShinySide,项目名称:SM-G361H,代码行数:101,代码来源:yas_mag_kernel.c


示例19: pn547_probe


//.........这里部分代码省略.........
	pn547_dev->clk_req_irq = platform_data->clk_req_irq;
#endif
	pn547_dev->client = client;

	/* init mutex and queues */
	init_waitqueue_head(&pn547_dev->read_wq);
	mutex_init(&pn547_dev->read_mutex);

	pn547_dev->pn547_device.minor = MISC_DYNAMIC_MINOR;
#ifdef CONFIG_NFC_PN547
	pn547_dev->pn547_device.name = "pn547";
#else
	pn547_dev->pn547_device.name = "pn544";
#endif
	pn547_dev->pn547_device.fops = &pn547_dev_fops;

	ret = misc_register(&pn547_dev->pn547_device);
	if (ret) {
		pr_err("%s : misc_register failed\n", __FILE__);
		goto err_misc_register;
	}

	/* request irq.  the irq is set whenever the chip has data available
	 * for reading.  it is cleared when all data has been read.
	 */
	pr_info("%s : requesting IRQ %d\n", __func__, client->irq);
	gpio_direction_input(pn547_dev->irq_gpio);
	gpio_direction_output(pn547_dev->ven_gpio, 0);
	gpio_direction_output(pn547_dev->firm_gpio, 0);
#ifdef CONFIG_NFC_PN547_CLOCK_REQUEST
	gpio_direction_input(pn547_dev->clk_req_gpio);
#endif

	i2c_set_clientdata(client, pn547_dev);
	wake_lock_init(&pn547_dev->nfc_wake_lock,
			WAKE_LOCK_SUSPEND, "nfc_wake_lock");
#ifdef CONFIG_NFC_PN547_CLOCK_REQUEST
	pn547_dev->wq_clock = create_singlethread_workqueue("nfc_wq");
	if (!pn547_dev->wq_clock) {
		ret = -ENOMEM;
		pr_err("%s: could not create workqueue\n", __func__);
		goto err_create_workqueue;
	}
	INIT_WORK(&pn547_dev->work_nfc_clock, nfc_work_func_clock);
#endif
	ret = request_irq(client->irq, pn547_dev_irq_handler,
			  IRQF_TRIGGER_RISING, "pn547", pn547_dev);
	if (ret) {
		dev_err(&client->dev, "request_irq failed\n");
		goto err_request_irq_failed;
	}
	disable_irq_nosync(pn547_dev->client->irq);
	atomic_set(&pn547_dev->irq_enabled, 0);

#ifdef CONFIG_NFC_PN547_CLOCK_REQUEST
	ret = request_irq(pn547_dev->clk_req_irq, pn547_dev_clk_req_irq_handler,
		IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
			, "pn547_clk_req", pn547_dev);
	if (ret) {
		dev_err(&client->dev, "request_irq(clk_req) failed\n");
		goto err_request_irq_failed;
	}

	enable_irq_wake(pn547_dev->clk_req_irq);
#endif
开发者ID:friedrich420,项目名称:Note-3-Kernel,代码行数:66,代码来源:pn547.c


示例20: sec_pmic_probe

static int sec_pmic_probe(struct i2c_client *i2c,
			    const struct i2c_device_id *id)
{
	struct sec_pmic_platform_data *pdata = i2c->dev.platform_data;
	struct sec_pmic_dev *sec_pmic;
	int ret = 0;

	if (!pdata) {
		dev_err(&i2c->dev, "No platform data found\n");
		return -EIO;
	}

	sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev),
				GFP_KERNEL);
	if (sec_pmic == NULL)
		return -ENOMEM;

	i2c_set_clientdata(i2c, sec_pmic);
	sec_pmic->dev = &i2c->dev;
	sec_pmic->i2c = i2c;
	sec_pmic->irq = i2c->irq;
	sec_pmic->type = id->driver_data;

	if (pdata) {
		sec_pmic->device_type = pdata->device_type;
		sec_pmic->ono = pdata->ono;
		sec_pmic->irq_base = pdata->irq_base;
		sec_pmic->wakeup = pdata->wakeup;
	}

	sec_pmic->regmap = regmap_init_i2c(i2c, &sec_regmap_config);
	if (IS_ERR(sec_pmic->regmap)) {
		ret = PTR_ERR(sec_pmic->regmap);
		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
			ret);
		goto err4;
	}
	mutex_init(&sec_pmic->iolock);
	sec_pmic->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR);
	if (IS_ERR(sec_pmic->rtc)) {
		ret = PTR_ERR(sec_pmic->rtc);
		dev_err(&i2c->dev, "Address %02x unavailable\n", RTC_I2C_ADDR);
		goto err3;
	}

	i2c_set_clientdata(sec_pmic->rtc, sec_pmic);
	sec_pmic->rtc_regmap = regmap_init_i2c(sec_pmic->rtc, &sec_regmap_config);
	if (IS_ERR(sec_pmic->rtc_regmap)) {
		ret = PTR_ERR(sec_pmic->rtc_regmap);
		dev_err(&sec_pmic->rtc->dev,
				"Failed to allocate register map: %d\n", ret);
		goto err2;
	}

	if (pdata && pdata->cfg_pmic_irq)
		pdata->cfg_pmic_irq();

	sec_irq_init(sec_pmic);

	pm_runtime_set_active(sec_pmic->dev);

	switch (sec_pmic->device_type) {
	case S5M8751X:
		ret = mfd_add_devices(sec_pmic->dev, -1, s5m8751_devs,
					ARRAY_SIZE(s5m8751_devs), NULL, 0);
		break;
	case S5M8763X:
		ret = mfd_add_devices(sec_pmic->dev, -1, s5m8763_devs,
					ARRAY_SIZE(s5m8763_devs), NULL, 0);
		break;
	case S5M8767X:
		ret = mfd_add_devices(sec_pmic->dev, -1, s5m8767_devs,
					ARRAY_SIZE(s5m8767_devs), NULL, 0);
		break;
	case S2MPS11X:
		ret = mfd_add_devices(sec_pmic->dev, -1, s2mps11_devs,
					ARRAY_SIZE(s2mps11_devs), NULL, 0);
		break;
	default:
		/* If this happens the probe function is problem */
		BUG();
	}

	if (ret < 0)
		goto err1;

	return ret;

err1:
	sec_irq_exit(sec_pmic);
	regmap_exit(sec_pmic->rtc_regmap);
err2:
	i2c_unregister_device(sec_pmic->rtc);
err3:
	regmap_exit(sec_pmic->regmap);
err4:
	return ret;
}
开发者ID:Svard73,项目名称:SM-T700-T705-Kernel,代码行数:98,代码来源:sec-core.c



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