Exemple #1
0
/* Load an i2c sub-device. */
struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
		struct i2c_adapter *adapter, struct i2c_board_info *info,
		const unsigned short *probe_addrs)
{
	struct v4l2_subdev *sd = NULL;
	struct i2c_client *client;

	BUG_ON(!v4l2_dev);

	request_module(I2C_MODULE_PREFIX "%s", info->type);

	/* Create the i2c client */
	if (info->addr == 0 && probe_addrs)
		client = i2c_new_probed_device(adapter, info, probe_addrs,
					       NULL);
	else
		client = i2c_new_device(adapter, info);

	/* Note: by loading the module first we are certain that c->driver
	   will be set if the driver was found. If the module was not loaded
	   first, then the i2c core tries to delay-load the module for us,
	   and then c->driver is still NULL until the module is finally
	   loaded. This delay-load mechanism doesn't work if other drivers
	   want to use the i2c device, so explicitly loading the module
	   is the best alternative. */
	if (client == NULL || client->driver == NULL)
		goto error;

	/* Lock the module so we can safely get the v4l2_subdev pointer */
	if (!try_module_get(client->driver->driver.owner))
		goto error;
	sd = i2c_get_clientdata(client);

	/* Register with the v4l2_device which increases the module's
	   use count as well. */
	if (v4l2_device_register_subdev(v4l2_dev, sd))
		sd = NULL;
	/* Decrease the module use count to match the first try_module_get. */
	module_put(client->driver->driver.owner);

error:
	/* If we have a client but no subdev, then something went wrong and
	   we must unregister the client. */
	if (client && sd == NULL)
		i2c_unregister_device(client);
	return sd;
}
Exemple #2
0
struct i2c_client *hdpvr_register_ir_rx_i2c(struct hdpvr_device *dev)
{
	struct IR_i2c_init_data *init_data = &dev->ir_i2c_init_data;
	struct i2c_board_info hdpvr_ir_rx_i2c_board_info = {
		I2C_BOARD_INFO("ir_rx_z8f0811_hdpvr", Z8F0811_IR_RX_I2C_ADDR),
	};

	/* Our default information for ir-kbd-i2c.c to use */
	init_data->ir_codes = RC_MAP_HAUPPAUGE;
	init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
	init_data->type = RC_BIT_RC5;
	init_data->name = "HD-PVR";
	init_data->polling_interval = 405; /* ms, duplicated from Windows */
	hdpvr_ir_rx_i2c_board_info.platform_data = init_data;

	return i2c_new_device(&dev->i2c_adapter, &hdpvr_ir_rx_i2c_board_info);
}
Exemple #3
0
/* Instantiate the I2C IR receiver device, if present */
void init_bttv_i2c_ir(struct bttv *btv)
{
	const unsigned short addr_list[] = {
		0x1a, 0x18, 0x64, 0x30, 0x71,
		I2C_CLIENT_END
	};
	struct i2c_board_info info;
	struct i2c_client *i2c_dev;

	if (0 != btv->i2c_rc)
		return;

	memset(&info, 0, sizeof(struct i2c_board_info));
	memset(&btv->init_data, 0, sizeof(btv->init_data));
	strlcpy(info.type, "ir_video", I2C_NAME_SIZE);

	switch (btv->c.type) {
	case BTTV_BOARD_PV951:
		btv->init_data.name = "PV951";
		btv->init_data.get_key = get_key_pv951;
		btv->init_data.ir_codes = RC_MAP_PV951;
		info.addr = 0x4b;
		break;
	}

	if (btv->init_data.name) {
		info.platform_data = &btv->init_data;
		i2c_dev = i2c_new_device(&btv->c.i2c_adap, &info);
	} else {
		/*
		 * The external IR receiver is at i2c address 0x34 (0x35 for
		 * reads).  Future Hauppauge cards will have an internal
		 * receiver at 0x30 (0x31 for reads).  In theory, both can be
		 * fitted, and Hauppauge suggest an external overrides an
		 * internal.
		 * That's why we probe 0x1a (~0x34) first. CB
		 */
		i2c_dev = i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
	}
	if (NULL == i2c_dev)
		return;

#if defined(CONFIG_MODULES) && defined(MODULE)
	request_module("ir-kbd-i2c");
#endif
}
Exemple #4
0
int cx231xx_ir_init(struct cx231xx *dev)
{
	struct i2c_board_info info;
	u8 ir_i2c_bus;

	dev_dbg(&dev->udev->dev, "%s\n", __func__);

	/* Only initialize if a rc keycode map is defined */
	if (!cx231xx_boards[dev->model].rc_map_name)
		return -ENODEV;

	request_module("ir-kbd-i2c");

	memset(&info, 0, sizeof(struct i2c_board_info));
	memset(&dev->init_data, 0, sizeof(dev->init_data));
	dev->init_data.rc_dev = rc_allocate_device();
	if (!dev->init_data.rc_dev)
		return -ENOMEM;

	dev->init_data.name = cx231xx_boards[dev->model].name;

	strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
	info.platform_data = &dev->init_data;

	/*
	 * Board-dependent values
	 *
	 * For now, there's just one type of hardware design using
	 * an i2c device.
	 */
	dev->init_data.get_key = get_key_isdbt;
	dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
	/* The i2c micro-controller only outputs the cmd part of NEC protocol */
	dev->init_data.rc_dev->scanmask = 0xff;
	dev->init_data.rc_dev->driver_name = "cx231xx";
	dev->init_data.type = RC_BIT_NEC;
	info.addr = 0x30;

	/* Load and bind ir-kbd-i2c */
	ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
	dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
		ir_i2c_bus, info.addr);
	dev->ir_i2c_client = i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info);

	return 0;
}
static int aml_audio_codec_probe(struct platform_device *pdev)
{
	struct device_node* audio_codec_node = pdev->dev.of_node;
	struct device_node* child;
	struct i2c_board_info board_info;
	struct i2c_adapter *adapter;
	struct i2c_client *client;
	aml_audio_codec_info_t temp_audio_codec;
#ifdef CONFIG_SND_AML_M6TV_AUDIO_CODEC
	struct tas57xx_platform_data *pdata;
	char tmp[NAME_SIZE];

	pdata = kzalloc(sizeof(struct tas57xx_platform_data), GFP_KERNEL);
	if (!pdata) {
		printk("ERROR, NO enough mem for tas57xx_platform_data!\n");
		return -ENOMEM;
    }
#endif
	memset(&board_info, 0, sizeof(board_info));

	audio_codec_pdev = pdev;

	for_each_child_of_node(audio_codec_node, child) {

        memset(&temp_audio_codec, 0, sizeof(aml_audio_codec_info_t));
        regist_codec_info(child,&temp_audio_codec);
        if (get_audio_codec_i2c_info(child, &temp_audio_codec)) {
            continue;
        }
        memset(&board_info, 0, sizeof(board_info));
		strncpy(board_info.type, temp_audio_codec.name, I2C_NAME_SIZE);
        adapter = i2c_get_adapter(temp_audio_codec.i2c_bus_type);
        board_info.addr = temp_audio_codec.i2c_addr;
        board_info.platform_data = &temp_audio_codec;
        client = i2c_new_device(adapter, &board_info);
#ifdef CONFIG_SND_AML_M6TV_AUDIO_CODEC
	snprintf(tmp, I2C_NAME_SIZE, "%s", temp_audio_codec.name);
	strlcpy(codec_info.name, tmp, I2C_NAME_SIZE);
	snprintf(tmp, I2C_NAME_SIZE, "%s.%s", temp_audio_codec.name, dev_name(&client->dev));
	strlcpy(codec_info.name_bus, tmp, I2C_NAME_SIZE);

	codec_get_of_pdata(pdata, child);
	client->dev.platform_data = pdata;
#endif
    }
int bq27520_bat_upt_i2c_init(void)
{
    int ret = 0;
    struct i2c_adapter *adapter = NULL;
    struct i2c_client *client   = NULL;
    struct i2c_board_info *board_info= NULL;

    BAT_DBG("++++ %s ++++\n", __func__);

    //register i2c device
    board_info = &bq27520_bat_upt_i2c_board_info;
    adapter = i2c_get_adapter(((struct bq27520_bat_platform_data *)board_info->platform_data)->i2c_bus_id);
    if (adapter == NULL) {
        BAT_DBG_E("can not get i2c adapter, client address error\n");
        ret = -ENODEV;
        goto get_adapter_fail;
    }

    client = i2c_new_device(adapter, board_info);
    if (client == NULL) {
        BAT_DBG("allocate i2c client failed\n");
        ret = -ENOMEM;
        goto register_i2c_device_fail;
    }
    i2c_put_adapter(adapter);

    mutex_lock(&batt_dev_upt_mutex);    
    batt_upt_dev_info.i2c = client;
    mutex_unlock(&batt_dev_upt_mutex);

    //register i2c driver
    ret =  i2c_add_driver(&bq27520_bat_upt_i2c_driver);
    if (ret) {
        BAT_DBG("register bq27520 battery update i2c driver failed\n");
        goto i2c_register_driver_fail;
    }

    return ret;

i2c_register_driver_fail:
    i2c_unregister_device(client);
register_i2c_device_fail:
get_adapter_fail:
    return ret;
}
static int camera_auto_detect(void)
{
	struct i2c_adapter *adap = i2c_get_adapter(2);

	pr_info("%s ++ %04x - %04x - %04x\n",
		__func__, ad5816_devid, dw9718_devid, max77387_devid);

	if ((ad5816_devid & 0xff00) == 0x2400) {
		if ((max77387_devid & 0xff) == 0x91) {
			/* IMX135 found */
			i2c_new_device(adap, &pluto_i2c_board_info_imx135);
		} else {
			/* IMX091 found*/
			i2c_new_device(adap, &pluto_i2c_board_info_imx091);
		}
	} else if (dw9718_devid) {
		if (!max77387_devid) {
			/* board e1823, IMX135 found */
			i2c_new_device(adap, &pluto_i2c_board_info_imx135);
			/* remove current dw9718 */
			device_for_each_child(&adap->dev,
				&pluto_i2c_board_info_dw9718.addr,
				pluto_chk_conflict);
			/* reinstall with new device node */
			pluto_dw9718_pdata.num = 0;
			i2c_new_device(adap, &pluto_i2c_board_info_dw9718);
		} else {
			/* AR0833 found */
			i2c_new_device(adap, &pluto_i2c_board_info_ar0833);
		}
	} else { /* default using ov5693 + ad5823 */
		device_for_each_child(&adap->dev,
			&pluto_i2c_board_info_ad5823.addr,
			pluto_chk_conflict);
		i2c_new_device(adap, &pluto_i2c_board_info_ov5693);
		i2c_new_device(adap, &pluto_i2c_board_info_ad5823);
	}
	i2c_new_device(adap, &pluto_i2c_board_info_imx132);

	pr_info("%s --\n", __func__);
	return 0;
}
int stmvl6180_init_i2c(void)
{
	int ret = 0;

#ifdef STM_TEST
	struct i2c_client *client = NULL;
	struct i2c_adapter *adapter;
	struct i2c_board_info info = {
		.type = "stmvl6180",
		.addr = VL6180_I2C_ADDRESS,
	};
#endif

	vl6180_dbgmsg("Enter\n");

	/* register as a i2c client device */
	ret = i2c_add_driver(&stmvl6180_driver);
	if (ret)
		vl6180_errmsg("%d erro ret:%d\n", __LINE__, ret);

#ifdef STM_TEST
	if (!ret) {
		adapter = i2c_get_adapter(4);
		if (!adapter)
			ret = -EINVAL;
		else
			client = i2c_new_device(adapter, &info);
		if (!client)
			ret = -EINVAL;
	}
#endif

	vl6180_dbgmsg("End with rc:%d\n", ret);

	return ret;
}

void stmvl6180_exit_i2c(void *i2c_object)
{
	vl6180_dbgmsg("Enter\n");
	i2c_del_driver(&stmvl6180_driver);

	vl6180_dbgmsg("End\n");
}
static int __init vt1603_bat_i2c_init(void)
{
    int ret = 0;
    struct i2c_adapter *adapter = NULL;
    struct i2c_client *client   = NULL;
    struct i2c_board_info *vt1603_i2c_bi = NULL;

    bat_dbg("Enter\n");
    ret = vt1603_bat_uboot_env_check();
    if (ret) {
        bat_dbg("vt1603_bat uboot env check failed\n");
        goto out;                
    }

    vt1603_i2c_bi = &vt1603_bat_i2c_board_info;
    adapter = i2c_get_adapter(vt1603_bat_pdata.i2c_bus_id);
    if (NULL == adapter) {
        bat_dbg("can not get i2c adapter, client address error\n");
        ret = -ENODEV;
        goto out;
    }

    client = i2c_new_device(adapter, vt1603_i2c_bi);
    if (client == NULL) {
        bat_dbg("allocate i2c client failed\n");
        ret = -ENOMEM;
        goto out;
    }
    i2c_put_adapter(adapter);

    ret =  i2c_add_driver(&vt1603_bat_i2c_driver);
    if (ret) {
        bat_dbg("register vt1603 battery i2c driver failed\n");
        goto release_client;
    }
    bat_dbg("Exit\n");
    goto out;

release_client:
    i2c_unregister_device(client);
    client = NULL;
out:
    return ret;
}
Exemple #10
0
static int ak8975c_i2c_register(void)
{
    struct i2c_board_info info;
    struct i2c_adapter *adapter;
    struct i2c_client *client;

    memset(&info, 0, sizeof(struct i2c_board_info));
    info.addr = AK8975C_I2C_ADDRESS;
    strlcpy(info.type, "tcc-magne-sensor", I2C_NAME_SIZE);
#if defined(CONFIG_ARCH_TCC93XX)
    adapter = i2c_get_adapter(3);
#else
    if(machine_is_m57te()) {
        msensor_dbg(KERN_INFO "%s : i2c_get_adapter(1), m57te_89\n", __FUNCTION__);
        adapter = i2c_get_adapter(1);
    }
    else if(machine_is_m801())  // 89_froyo
    {
        msensor_dbg(KERN_INFO "%s : i2c_get_adapter(0), M801_89\n", __FUNCTION__);
        adapter = i2c_get_adapter(0);
    }
    else { // 88_froyo (88_93 demo black board)  // M801_8803
        msensor_dbg(KERN_INFO "%s : i2c_get_adapter(0), M801_88 or other\n", __FUNCTION__);
        adapter = i2c_get_adapter(0);
    }
#endif
    if (!adapter)
    {
        msensor_dbg(KERN_ERR "can't get i2c adapter 0 for tcc-magne-sensor\n");
        return -ENODEV;
    }

    client = i2c_new_device(adapter, &info);
    i2c_put_adapter(adapter);
    if (!client)
    {
        msensor_dbg(KERN_ERR "can't add i2c device at 0x%x\n", (unsigned int)info.addr);
        return -ENODEV;
    }

    msensor_i2c_client = client;

    return 0;
}
static int __init apds9960_init(void)
{
	int i = 0;
	struct i2c_adapter *adap = NULL;

	for (i = 0; i < 3; i++) {
		adap = i2c_get_adapter(i);
		if (!adap)
			return -1;

		if (!strcmp(adap->name, "Synopsys DesignWare I2C adapter"))
			break;
	}

	apds9960_accel_device.irq = gpio_to_irq(APDS9960_I2C_IRQ);

	i2c_client = i2c_new_device(adap, &apds9960_accel_device);
	return 0;
}
static int register_i2c_codec_device(aml_audio_codec_info_t* audio_codec_dev)
{
	struct i2c_adapter *adapter;
	struct i2c_client *client;
	struct i2c_board_info board_info;
	char tmp[NAME_SIZE];

	strncpy(board_info.type, audio_codec_dev->name, I2C_NAME_SIZE);
	board_info.addr = audio_codec_dev->i2c_addr;
	
	adapter = i2c_get_adapter(audio_codec_dev->i2c_bus_type);
	client = i2c_new_device(adapter, &board_info);
	snprintf(tmp, NAME_SIZE, "%s", audio_codec_dev->name);
	strlcpy(codec_info.name, tmp, NAME_SIZE);
	snprintf(tmp, NAME_SIZE, "%s.%s", audio_codec_dev->name, dev_name(&client->dev));
	strlcpy(codec_info.name_bus, tmp, NAME_SIZE);

	return 0;
}
Exemple #13
0
static int __init mma7660_init(void)
{
#if CFG_GSENSOR_USE_CONFIG > 0
	struct i2c_adapter *i2c_adap;
	unsigned int cfg_i2c_adap_id;
	int ret;

	ret = get_config(CFG_GSENSOR_ADAP_ID, (char *)(&cfg_i2c_adap_id), sizeof(unsigned int));
	if (ret != 0) {
		printk(KERN_ERR"get i2c_adap_id %d fail\n", cfg_i2c_adap_id);
		return ret;
	}

	i2c_adap = i2c_get_adapter(cfg_i2c_adap_id);
	mma7660_client = i2c_new_device(i2c_adap, &mma7660_board_info);
	i2c_put_adapter(i2c_adap);
#endif
	return i2c_add_driver(&mma7660_driver);
}
Exemple #14
0
static bool
probe_monitoring_device(struct nouveau_i2c_chan *i2c,
			struct i2c_board_info *info)
{
	struct i2c_client *client;

	request_module("%s%s", I2C_MODULE_PREFIX, info->type);

	client = i2c_new_device(&i2c->adapter, info);
	if (!client)
		return false;

	if (!client->driver || client->driver->detect(client, info)) {
		i2c_unregister_device(client);
		return false;
	}

	return true;
}
Exemple #15
0
static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
						 struct device_node *node)
{
	struct i2c_client *client;
	struct i2c_board_info info;
	int ret;

	dev_dbg(&adap->dev, "of_i2c: register %pOF\n", node);

	ret = of_i2c_get_board_info(&adap->dev, node, &info);
	if (ret)
		return ERR_PTR(ret);

	client = i2c_new_device(adap, &info);
	if (!client) {
		dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n", node);
		return ERR_PTR(-EINVAL);
	}
	return client;
}
Exemple #16
0
static inline int bq27x00_battery_i2c_init(void)
{
    struct i2c_adapter *adapter;
    struct i2c_client *client;

    int ret = i2c_add_driver(&bq27x00_battery_driver);
    if (ret)
        printk(KERN_ERR "Unable to register BQ27x00 i2c driver\n");

    adapter = i2c_get_adapter(0);
    if (!adapter)
        return -ENODEV;
    client = i2c_new_device(adapter, i2c_board_info);

    i2c_put_adapter(adapter);
    if (!client)
        return -ENODEV;

    return ret;
}
Exemple #17
0
int sensor_i2c_register_device (void)
{
	struct i2c_board_info *sensor_i2c_bi;
	struct i2c_adapter *adapter = NULL;
	//struct i2c_client *client   = NULL;
	sensor_i2c_bi = &sensor_i2c_board_info;
	adapter = i2c_get_adapter(2);/*in bus 2*/

	if (NULL == adapter) {
		printk("can not get i2c adapter, client address error\n");
		return -1;
	}
	sensor_client = i2c_new_device(adapter, sensor_i2c_bi);
	if (sensor_client == NULL) {
		printk("allocate i2c client failed\n");
		return -1;
	}
	i2c_put_adapter(adapter);
	return 0;
}
static int wlf_gf_module_probe(struct i2c_client *i2c,
			       const struct i2c_device_id *i2c_id)
{
	int ret, i, j, id, rev;

	ret = i2c_smbus_read_byte_data(i2c, 0);
	if (ret < 0) {
		dev_err(&i2c->dev, "Failed to read ID: %d\n", ret);
		return ret;
	}

	id = (ret & 0xfe) >> 2;
	rev = ret & 0x3;
	for (i = 0; i < ARRAY_SIZE(gf_mods); i++)
		if (id == gf_mods[i].id && (gf_mods[i].rev == 0xff ||
					    rev == gf_mods[i].rev))
			break;

	gpiod_add_lookup_table(&wm5102_reva_gpiod_table);
	gpiod_add_lookup_table(&wm5102_gpiod_table);

	if (i < ARRAY_SIZE(gf_mods)) {
		dev_info(&i2c->dev, "%s revision %d\n",
			 gf_mods[i].name, rev + 1);

		for (j = 0; j < gf_mods[i].num_i2c_devs; j++) {
			if (!i2c_new_device(i2c->adapter,
					    &(gf_mods[i].i2c_devs[j])))
				dev_err(&i2c->dev,
					"Failed to register dev: %d\n", ret);
		}

		spi_register_board_info(gf_mods[i].spi_devs,
					gf_mods[i].num_spi_devs);
	} else {
		dev_warn(&i2c->dev, "Unknown module ID 0x%x revision %d\n",
			 id, rev + 1);
	}

	return 0;
}
Exemple #19
0
// init i2c devices
int __init mi2c_init_i2c(int numdevices, struct i2c_board_info * board_info )
{
	int i,ret;
	struct i2c_adapter *adapter;


	num_devices =numdevices;

	/* register our driver */
	ret = i2c_add_driver(&mi2c_i2c_driver);
	if (ret) {
		printk(KERN_ALERT "Error registering i2c driver\n");
		return ret;
	}
	i=0;


		/* get adapter */
			adapter = i2c_get_adapter(I2C_BUS_2);

			if (!adapter) {
				printk(KERN_ALERT "i2c_get_adapter(%d) failed\n", I2C_BUS_2);
				return -1;
			}

			/* add our devices */
			for (i = 0; i < num_devices; i++) {
				mi2c_i2c_client[i] = i2c_new_device(adapter,&board_info[i]);

				if (!mi2c_i2c_client[i]) {
					printk(KERN_ALERT "i2c_new_device failed\n");
					break;
				} else {

				}
			}

			i2c_put_adapter(adapter);

	return i == num_devices ? 0 : -1;
}
Exemple #20
0
void of_register_i2c_devices(struct i2c_adapter *adap,
			     struct device_node *adap_node)
{
	void *result;
	struct device_node *node;

	for_each_child_of_node(adap_node, node) {
		struct i2c_board_info info = {};
		const u32 *addr;
		int len;

		addr = of_get_property(node, "reg", &len);
		if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
			printk(KERN_ERR
			       "of-i2c: invalid i2c device entry\n");
			continue;
		}

		info.irq = irq_of_parse_and_map(node, 0);
		if (info.irq == NO_IRQ)
			info.irq = -1;

		if (of_find_i2c_driver(node, &info) < 0) {
			irq_dispose_mapping(info.irq);
			continue;
		}

		info.addr = *addr;

		request_module(info.type);

		result = i2c_new_device(adap, &info);
		if (result == NULL) {
			printk(KERN_ERR
			       "of-i2c: Failed to load driver for %s\n",
			       info.type);
			irq_dispose_mapping(info.irq);
			continue;
		}
	}
}
Exemple #21
0
static bool
probe_monitoring_device(struct nouveau_i2c_chan *i2c,
			struct i2c_board_info *info)
{
	char modalias[16] = "i2c:";
	struct i2c_client *client;

	strlcat(modalias, info->type, sizeof(modalias));
	request_module(modalias);

	client = i2c_new_device(&i2c->adapter, info);
	if (!client)
		return false;

	if (!client->driver || client->driver->detect(client, info)) {
		i2c_unregister_device(client);
		return false;
	}

	return true;
}
Exemple #22
0
static int ch7026_attach_adapter(void)
{
	struct i2c_board_info info;
	struct i2c_adapter *adapter;
	struct i2c_client *client;
	printk("[VGA] ch7026_attach_adapter.\n");
	
	adapter = i2c_get_adapter(I2C_BUS_NUM);

	memset(&info, 0, sizeof(struct i2c_board_info));

	strlcpy(info.type, "ch7026", I2C_NAME_SIZE);
	info.addr = CH7026_I2C_ADDR;
	client = i2c_new_device(adapter, &info);
	if (!client)
	{
		printk("failed to add i2c driver\n");
		return -ENODEV;
	}
	return 0;
}
Exemple #23
0
static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq)
{
	struct i2c_client *ccgx_client;

	i2cd->gpu_ccgx_ucsi = devm_kzalloc(i2cd->dev,
					   sizeof(*i2cd->gpu_ccgx_ucsi),
					   GFP_KERNEL);
	if (!i2cd->gpu_ccgx_ucsi)
		return -ENOMEM;

	strlcpy(i2cd->gpu_ccgx_ucsi->type, "ccgx-ucsi",
		sizeof(i2cd->gpu_ccgx_ucsi->type));
	i2cd->gpu_ccgx_ucsi->addr = 0x8;
	i2cd->gpu_ccgx_ucsi->irq = irq;
	i2cd->gpu_ccgx_ucsi->properties = ccgx_props;
	ccgx_client = i2c_new_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi);
	if (!ccgx_client)
		return -ENODEV;

	return 0;
}
Exemple #24
0
static struct i2c_client *add_smbus_device(struct i2c_adapter *adap,
					   const char *name,
					   struct i2c_board_info *info)
{
	const struct dmi_device *dmi_dev;
	const struct dmi_dev_onboard *dev_data;

	dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
	if (!dmi_dev) {
		pr_err("%s failed to dmi find device %s.\n", __func__, name);
		return NULL;
	}
	dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
	if (!dev_data) {
		pr_err("%s failed to get device data from dmi.\n",
		       __func__);
		return NULL;
	}
	info->irq = dev_data->instance;
	return i2c_new_device(adap, info);
}
static int ak4535_add_i2c_device(struct platform_device *pdev,
				 const struct ak4535_setup_data *setup)
{
	struct i2c_board_info info;
	struct i2c_adapter *adapter;
	struct i2c_client *client;
	int ret;

	ret = i2c_add_driver(&ak4535_i2c_driver);
	if (ret != 0) {
		dev_err(&pdev->dev, "can't add i2c driver\n");
		return ret;
	}

	memset(&info, 0, sizeof(struct i2c_board_info));
	info.addr = setup->i2c_address;
	strlcpy(info.type, "ak4535", I2C_NAME_SIZE);

	adapter = i2c_get_adapter(setup->i2c_bus);
	if (!adapter) {
		dev_err(&pdev->dev, "can't get i2c adapter %d\n",
			setup->i2c_bus);
		goto err_driver;
	}

	client = i2c_new_device(adapter, &info);
	i2c_put_adapter(adapter);
	if (!client) {
		dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
			(unsigned int)info.addr);
		goto err_driver;
	}

	return 0;

err_driver:
	i2c_del_driver(&ak4535_i2c_driver);
	return -ENODEV;
}
static void ir2e69_register(void)
{
	struct i2c_adapter *adapter;
	int ret;

	adapter = i2c_get_adapter(I2C_ADAPTER);
	i2c_client = i2c_new_device(adapter, &dcdc_board_info);

	mipi_reset_gpio = get_gpio_by_name("mipi-reset");
	if (mipi_reset_gpio < 0) {
		DRM_ERROR("can't get mipi-reset gpio pin\n");
		mipi_reset_gpio = -1;
		return;
	}
	ret = gpio_request(mipi_reset_gpio, "mipi_display");
	if (ret < 0) {
		DRM_ERROR("failed to request gpio %d\n", mipi_reset_gpio);
		mipi_reset_gpio = -1;
		return;
	}
	gpio_direction_output(mipi_reset_gpio, 0);
}
Exemple #27
0
Fichier : test.c Projet : sktwj/var
static int ldm_init(void)
{
	printk("%s %s\n", __FILE__, __FUNCTION__);

	//获得表示1号i2c总线的adapter对象
	struct i2c_adapter *i2c_adap = i2c_get_adapter(1);

	ldm_ts_client = i2c_new_device(i2c_adap, &ldm_ts_info);
	if (!ldm_ts_client) {
		printk(KERN_ERR "i2c_new_device failed\n");
		goto err_i2c_new_device;
	}

	//销毁i2c_adapter
	i2c_put_adapter(i2c_adap);

	return 0;

err_i2c_new_device:
	i2c_put_adapter(i2c_adap);
	return -1;
}
int __init smba_camera_init(void)
{
	int i, ret;
	struct i2c_client *client;
	struct i2c_adapter *adapter;

	pr_info("smba camera init!\n");

	init_camera_gpio();

//	cam_ldo6 = regulator_get(NULL, "vdd_ldo6");
//	if (IS_ERR_OR_NULL(cam_ldo6)) {
//		pr_err("camera : can't get vdd_ldo6\n");
//		return -EFAULT;
//	}
//	cam_ldo9 = regulator_get(NULL, "vdd_ldo9");
//	if (IS_ERR_OR_NULL(cam_ldo9)) {
//		pr_err("camera : can't get vdd_ldo6");
//		return -EFAULT;
//	}

	adapter = i2c_get_adapter(3);
	if (adapter == NULL) {
		pr_err("camera : can't get i2c bus #3 adapter\n");
		return -EFAULT;
	}
	for (i = 0; i < ARRAY_SIZE(smba_i2c3_board_info_camera); i++) {
		client = i2c_new_device(adapter,
				&smba_i2c3_board_info_camera[i]);
		if (client == NULL) {
			pr_err("camera : register camera #%d failed\n", i);
			return -EFAULT;
		}
	}
	i2c_put_adapter(adapter);

	return ret;
}
Exemple #29
0
static s32 tcpal_i2c_add_device(void)
{
	s32 ret;
	struct i2c_board_info info;
	struct i2c_adapter *adapter;
	struct i2c_client *client;

	ret = i2c_add_driver(&tcpal_i2c_driver);
	if (ret < 0) {
		tcbd_debug(DEBUG_TCPAL_I2C, "can't add i2c driver\n");
		return ret;
	}

	memset(&info, 0, sizeof(struct i2c_board_info));
	info.addr = I2C_ADDR;
	strlcpy(info.type, "tc317x", I2C_NAME_SIZE);

	adapter = i2c_get_adapter(I2C_BUS);
	if (!adapter) {
		tcbd_debug(DEBUG_TCPAL_I2C,
			"can't get i2c adapter :%d\n", I2C_BUS);
		goto err_driver;
	}

	client = i2c_new_device(adapter, &info);
	i2c_put_adapter(adapter);
	if (!client) {
		tcbd_debug(DEBUG_TCPAL_I2C,
			"can't add i2c device at 0x%X\n", info.addr);
		goto err_driver;
	}

	return 0;

err_driver:
	i2c_del_driver(&tcpal_i2c_driver);
	return -ENODEV;
}
Exemple #30
0
static int __init raumfeld_audio_init(void)
{
	int ret;

	if (!machine_is_raumfeld_speaker() &&
	    !machine_is_raumfeld_connector())
		return 0;

	max9486_client = i2c_new_device(i2c_get_adapter(0),
					&max9486_hwmon_info);

	if (!max9486_client)
		return -ENOMEM;

	set_max9485_clk(MAX9485_MCLK_FREQ_122880);

	/* Register analog device */
	raumfeld_audio_device = platform_device_alloc("soc-audio", 0);
	if (!raumfeld_audio_device)
		return -ENOMEM;

	if (machine_is_raumfeld_speaker())
		platform_set_drvdata(raumfeld_audio_device,
				     &snd_soc_raumfeld_speaker);

	if (machine_is_raumfeld_connector())
		platform_set_drvdata(raumfeld_audio_device,
				     &snd_soc_raumfeld_connector);

	ret = platform_device_add(raumfeld_audio_device);
	if (ret < 0) {
		platform_device_put(raumfeld_audio_device);
		return ret;
	}

	raumfeld_enable_audio(true);
	return 0;
}