Example #1
0
static struct wf_lm75_sensor *wf_lm75_create(struct i2c_adapter *adapter,
                         u8 addr, int ds1775,
                         const char *loc)
{
    struct wf_lm75_sensor *lm;
    int rc;

    DBG("wf_lm75: creating  %s device at address 0x%02x\n",
        ds1775 ? "ds1775" : "lm75", addr);

    lm = kzalloc(sizeof(struct wf_lm75_sensor), GFP_KERNEL);
    if (lm == NULL)
        return NULL;

    /* Usual rant about sensor names not beeing very consistent in
     * the device-tree, oh well ...
     * Add more entries below as you deal with more setups
     */
    if (!strcmp(loc, "Hard drive") || !strcmp(loc, "DRIVE BAY"))
        lm->sens.name = "hd-temp";
    else if (!strcmp(loc, "Incoming Air Temp"))
        lm->sens.name = "incoming-air-temp";
    else if (!strcmp(loc, "ODD Temp"))
        lm->sens.name = "optical-drive-temp";
    else if (!strcmp(loc, "HD Temp"))
        lm->sens.name = "hard-drive-temp";
    else
        goto fail;

    lm->inited = 0;
    lm->sens.ops = &wf_lm75_ops;
    lm->ds1775 = ds1775;
    lm->i2c.addr = (addr >> 1) & 0x7f;
    lm->i2c.adapter = adapter;
    lm->i2c.driver = &wf_lm75_driver;
    strncpy(lm->i2c.name, lm->sens.name, I2C_NAME_SIZE-1);

    rc = i2c_attach_client(&lm->i2c);
    if (rc) {
        printk(KERN_ERR "windfarm: failed to attach %s %s to i2c,"
               " err %d\n", ds1775 ? "ds1775" : "lm75",
               lm->i2c.name, rc);
        goto fail;
    }

    if (wf_register_sensor(&lm->sens)) {
        i2c_detach_client(&lm->i2c);
        goto fail;
    }

    return lm;
 fail:
    kfree(lm);
    return NULL;
}
Example #2
0
/* If the i2c layer weren't so broken, we could pass this kind of data
   around */
static int ak4671_codec_probe(struct i2c_adapter *adap, int addr, int kind)
{
	struct snd_soc_device *socdev = ak4671_socdev;
	struct ak4671_setup_data *setup = socdev->codec_data;
	struct snd_soc_codec *codec = socdev->codec;
	struct i2c_client *i2c;
	int ret;

	if (addr != setup->i2c_address)
		return -ENODEV;
	ak4671_client.adapter = adap;
	ak4671_client.addr = addr;

	i2c = kmemdup(&ak4671_client, sizeof(ak4671_client), GFP_KERNEL);
	if (i2c == NULL)
		return -ENOMEM;

	i2c_set_clientdata(i2c, codec);
	codec->control_data = i2c;

	ret = i2c_attach_client(i2c);
	if (ret < 0) {
		printk(KERN_ERR "failed to attach codec at addr %x\n", addr);
		goto err;
	}

	ret = ak4671_init(socdev);
	if (ret < 0) {
		printk(KERN_ERR "failed to initialise AK4671\n");
		goto err;
	}

	set_registers(codec, MM_AUDIO_PLAYBACK_SPK);

#if 0 // i2c test
	p("---> 0x01 = 0x%02x\n", ak4671_read(codec, 0x01)); 	
	ak4671_write(codec, 0x01, 0x78); 	
	P("---> 0x01 = 0x%02x\n", ak4671_read(codec, 0x01)); 	

	P("---> 0x02 = 0x%02x\n", ak4671_read(codec, 0x02)); 	
	ak4671_write(codec, 0x02, 0x01); 
	P("---> 0x02 = 0x%02x\n", ak4671_read(codec, 0x02)); 	

	P("---> 0x03 = 0x%02x\n", ak4671_read(codec, 0x03)); 	
	ak4671_write(codec, 0x03, 0x03);
	P("---> 0x03 = 0x%02x\n", ak4671_read(codec, 0x03)); 	
#endif

	return ret;

err:
	kfree(i2c);
	return ret;
}
Example #3
0
static int tda9840_detect(struct i2c_adapter *adapter, int address, int kind)
{
	struct	i2c_client *client;
	int result = 0;

	int byte = 0x0;
			
	/* let's see whether this adapter can support what we need */
	if ( 0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA|I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
		return 0;
	}

	/* allocate memory for client structure */
	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
        if (0 == client) {
		printk("tda9840.o: not enough kernel memory.\n");
		return -ENOMEM;
	}
	memset(client, 0, sizeof(struct i2c_client));
	
	/* fill client structure */
	sprintf(client->name,"tda9840 (0x%02x)", address);
	client->id = tda9840_id++;
	client->flags = 0;
	client->addr = address;
	client->adapter = adapter;
	client->driver = &driver;
	i2c_set_clientdata(client, NULL);

	/* tell the i2c layer a new client has arrived */
	if (0 != (result = i2c_attach_client(client))) {
		kfree(client);
		return result;
	}

	/* set initial values for level & stereo - adjustment, mode */
	byte = 0;
	if ( 0 != (result = tda9840_command(client, TDA9840_LEVEL_ADJUST, &byte))) {
 		printk("tda9840.o: could not initialize ic #1. continuing anyway. (result:%d)\n",result);
	}
	
	if ( 0 != (result = tda9840_command(client, TDA9840_STEREO_ADJUST, &byte))) {
 		printk("tda9840.o: could not initialize ic #2. continuing anyway. (result:%d)\n",result);
	}

	byte = TDA9840_SET_MONO;
	if ( 0 != (result = tda9840_command(client, TDA9840_SWITCH, &byte))) {
 		printk("tda9840.o: could not initialize ic #3. continuing anyway. (result:%d)\n",result);
	} 
	
	printk("tda9840.o: detected @ 0x%02x on adapter %s\n",2*address,&client->adapter->name[0]);

	return 0;
}
Example #4
0
static int tvp5150_detect_client(struct i2c_adapter *adapter,
                 int address, int kind)
{
    struct i2c_client *c;
    struct tvp5150 *core;
    int rv;

    if (debug)
        printk( KERN_INFO
        "tvp5150.c: detecting tvp5150 client on address 0x%x\n",
        address << 1);

    client_template.adapter = adapter;
    client_template.addr = address;

    /* Check if the adapter supports the needed features */
    if (!i2c_check_functionality
        (adapter,
         I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
        return 0;

    c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
    if (!c)
        return -ENOMEM;
    memcpy(c, &client_template, sizeof(struct i2c_client));

    core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
    if (!core) {
        kfree(c);
        return -ENOMEM;
    }
    i2c_set_clientdata(c, core);

    rv = i2c_attach_client(c);

    core->norm = V4L2_STD_ALL;    /* Default is autodetect */
    core->route.input = TVP5150_COMPOSITE1;
    core->enable = 1;
    core->bright = 128;
    core->contrast = 128;
    core->hue = 0;
    core->sat = 128;

    if (rv) {
        kfree(c);
        kfree(core);
        return rv;
    }

    if (debug > 1)
        dump_reg(c);
    return 0;
}
Example #5
0
static int uor_i2c_detect(struct i2c_adapter *adapter, int address, int kind)

{

	struct i2c_client *client;



//	printk("uor.c:uor_i2c_detect() --oql\n");

	

    client = kzalloc(sizeof(*client), GFP_KERNEL);

    if (client == NULL)

	{

		printk("uor.c:uor_i2c_detect() client ==null--oql\n");	

    	return -ENOMEM;

	}

    client->adapter = adapter;

    client->addr = address;

	client->driver = &uor_i2c_driver;

	client->Channel = I2C_CH0;

	client->mode = NORMALMODE;

	client->speed = 100;// 80;// 400;
	client->addressBit = I2C_7BIT_ADDRESS_8BIT_REG;

	i2c_set_clientdata(client, &ts);	

	ts.client = client; // save the client we get

    i2c_attach_client(client);

	 if(Init_UOR_HW() < 0)

		 printk(KERN_ERR "uor.c: Init_UOR_HW() fail in uor_init()!\n");

	

	return 0;

}
Example #6
0
static int isp1301_detect_client(struct i2c_adapter *adapter, int address,
				 int kind)
{
	isp1301_i2c_client.adapter = adapter;
	if (i2c_attach_client(&isp1301_i2c_client)) {
		isp1301_i2c_client.adapter = NULL;
		printk(KERN_ERR "isp1301_attach: i2c_attach_client failed\n");
		return -1;
	}

	printk(KERN_INFO "isp1301 Detected\n");
	return 0;
}
Example #7
0
static int ds1374_probe(struct i2c_adapter *adapter, int address, int kind)
{
	struct ds1374 *ds1374;
	struct i2c_client *client;
	int ret;

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

	client = &ds1374->client;
	client->addr = address;
	client->adapter = adapter;
	client->driver = &ds1374_driver;
	client->flags = 0;
	strlcpy(client->name, "ds1374", I2C_NAME_SIZE);

	i2c_set_clientdata(client, ds1374);

	mutex_init(&ds1374->mutex);

	ret = i2c_attach_client(client);
	if (ret)
		goto attach_failed;

	ret = ds1374_check_rtc_status(client);
	if (ret)
		goto status_failed;

	ds1374->rtc = rtc_device_register(client->name, &client->dev,
	                                  &ds1374_rtc_ops, THIS_MODULE);
	if (IS_ERR(ds1374->rtc)) {
		ret = PTR_ERR(ds1374->rtc);
		dev_err(&client->dev, "unable to register the class device\n");
		goto rtc_register_failed;
	}

	return 0;

rtc_register_failed:
status_failed:
	i2c_detach_client(client);
attach_failed:
	i2c_set_clientdata(client, NULL);
	kfree(ds1374);
	printk(KERN_ERR "ds1374: failed to probe\n");
	return ret;
}
Example #8
0
static int at24cxx_detect(struct i2c_adapter *adapter, int address, int kind)
{
	struct i2c_client *new_client;
	
	printk("at24cxx_detect\n");

	/* 构构一个i2c_client结构体: 以后收改数据时会用到它 */
	new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
	new_client->addr    = address;
	new_client->adapter = adapter;
	new_client->driver  = &at24cxx_driver;
	strcpy(new_client->name, "at24cxx");
	i2c_attach_client(new_client);
	
	return 0;
}
Example #9
0
static int wis_saa7115_detect(struct i2c_adapter *adapter, int addr, int kind)
{
    struct i2c_client *client;
    struct wis_saa7115 *dec;

    if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
        return 0;

    client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
    if (client == NULL)
        return -ENOMEM;
    memcpy(client, &wis_saa7115_client_templ,
           sizeof(wis_saa7115_client_templ));
    client->adapter = adapter;
    client->addr = addr;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
    client->id = wis_saa7115_i2c_id++;
#endif

    dec = kmalloc(sizeof(struct wis_saa7115), GFP_KERNEL);
    if (dec == NULL) {
        kfree(client);
        return -ENOMEM;
    }
    dec->norm = VIDEO_MODE_NTSC;
    dec->brightness = 128;
    dec->contrast = 64;
    dec->saturation = 64;
    dec->hue = 0;
    i2c_set_clientdata(client, dec);

    printk(KERN_DEBUG
           "wis-saa7115: initializing SAA7115 at address %d on %s\n",
           addr, adapter->name);

    if (write_regs(client, initial_registers) < 0)
    {
        printk(KERN_ERR
               "wis-saa7115: error initializing SAA7115\n");
        kfree(client);
        kfree(dec);
        return 0;
    }

    i2c_attach_client(client);
    return 0;
}
Example #10
0
/* This function is called by i2c_detect */
static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
{
	struct i2c_client *new_client;
	struct pca9539_data *data;
	int err = 0;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		goto exit;

	/* OK. For now, we presume we have a valid client. We now create the
	   client structure, even though we cannot fill it completely yet. */
	if (!(data = kmalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
		err = -ENOMEM;
		goto exit;
	}
	memset(data, 0, sizeof(struct pca9539_data));

	new_client = &data->client;
	i2c_set_clientdata(new_client, data);
	new_client->addr = address;
	new_client->adapter = adapter;
	new_client->driver = &pca9539_driver;
	new_client->flags = 0;

	/* Detection: the pca9539 only has 8 registers (0-7).
	   A read of 7 should succeed, but a read of 8 should fail. */
	if ((i2c_smbus_read_byte_data(new_client, 7) < 0) ||
	    (i2c_smbus_read_byte_data(new_client, 8) >= 0))
		goto exit_kfree;

	strlcpy(new_client->name, "pca9539", I2C_NAME_SIZE);

	/* Tell the I2C layer a new client has arrived */
	if ((err = i2c_attach_client(new_client)))
		goto exit_kfree;

	/* Register sysfs hooks (don't care about failure) */
	sysfs_create_group(&new_client->dev.kobj, &pca9539_defattr_group);

	return 0;

exit_kfree:
	kfree(data);
exit:
	return err;
}
static int si4709_i2c_probe(struct i2c_adapter *adapter, int address, int kind)
{
	int err = 0;         

	printk("----- %s %d\n", __func__, __LINE__);

	Si4709_i2c_client.addr = address; 
	Si4709_i2c_client.adapter = adapter;
	Si4709_i2c_client.driver = &Si4709_i2c_driver;

	if ((err = i2c_attach_client(&Si4709_i2c_client)))
		return err;

	Si4709_probe(&Si4709_i2c_client);

	return 0;
}
Example #12
0
static int irrtc_detect_client(struct i2c_adapter * adapter, int address, int kind)
{
    int ret = 0;
    struct i2c_client* client = NULL;

    if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
    {
        dbg("ERROR returned from i2c_check_functionality");
        ret = -1;
        goto out;
    }

    if (!(client = kmalloc(sizeof(*client), GFP_KERNEL)))
    {
        dbg("ERROR error returned from kmalloc");
        ret = -ENOMEM;
        goto out;
    }

    memset(client, 0, sizeof(struct i2c_client));

    client->addr = address;
    client->adapter = adapter;
    client->driver = &irrtc_driver;
    client->flags = I2C_M_IGNORE_NAK;

    strcpy(client->name, "irrtc");

    if ((ret = i2c_attach_client(client)) != 0)
    {
        dbg("%s Unable to attach client.\n", pname);
        kfree(client);
        ret = -1;
        goto out;
    }

    irrtc_client = client;

#if 0
    printk("Reading remote ID\n");
    printk("Register:Value 0x%02X:0x%02X\n", 0x36, i2c_read(0x36));
#endif
out:
    return ret;
}
Example #13
0
/* tvp7002_i2c_attach_client : This function is used to attach i2c client
 */
static int tvp7002_i2c_attach_client(struct i2c_client *client,
				     struct i2c_driver *driver,
				     struct i2c_adapter *adap, int addr)
{
	int err = 0;
	if (client->adapter) {
		err = -EBUSY;	/* our client is already attached */
	} else {
		client->addr = addr;
		client->driver = driver;
		client->adapter = adap;
		err = i2c_attach_client(client);
		if (err) {
			client->adapter = NULL;
		}
	}
	return err;
}
Example #14
0
/* this function is called by i2c_probe */
static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
{
	struct i2c_client *client;
	int err = 0, i = 0;

	/* let's see whether this adapter can support what we need */
	if (0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) {
		return 0;
	}

	/* allocate memory for client structure */
	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
	if (0 == client) {
		return -ENOMEM;
	}
	memset(client, 0x0, sizeof(struct i2c_client));

	/* fill client structure */
	memcpy(client, &client_template, sizeof(struct i2c_client));
	client->addr = address;
	client->adapter = adapter;

	/* tell the i2c layer a new client has arrived */
	if (0 != (err = i2c_attach_client(client))) {
		kfree(client);
		return err;
	}

	/* set initial values: set "mute"-input to all outputs at gain 0 */
	err = 0;
	for (i = 1; i < 5; i++) {
		err += tea6420_switch(client, 6, i, 0);
	}
	if (err) {
		dprintk("could not initialize tea6420\n");
		kfree(client);
		return -ENODEV;
	}

	printk("tea6420: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);

	return 0;
}
Example #15
0
static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind)
{
	struct i2c_client *c;

	c = (struct i2c_client *)kzalloc(sizeof(*c), GFP_KERNEL);

	if (!c)
		return -ENOMEM;

	strcpy(c->name, "isp1301");
	c->flags = 0;
	c->addr = addr;
	c->adapter = adap;
	c->driver = &isp1301_driver;

	isp1301_i2c_client = c;

	return i2c_attach_client(c);
}
Example #16
0
static int at24cxx_detect(struct i2c_adapter *adapter, int address, int kind)
{	
	printk("at24cxx_detect\n");

	/* 构构一个i2c_client结构体: 以后收改数据时会用到它 */
	at24cxx_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
	at24cxx_client->addr    = address;
	at24cxx_client->adapter = adapter;
	at24cxx_client->driver  = &at24cxx_driver;
	strcpy(at24cxx_client->name, "at24cxx");
	i2c_attach_client(at24cxx_client);
	
	major = register_chrdev(0, "at24cxx", &at24cxx_fops);

	cls = class_create(THIS_MODULE, "at24cxx");
	class_device_create(cls, NULL, MKDEV(major, 0), NULL, "at24cxx"); /* /dev/at24cxx */
	
	return 0;
}
Example #17
0
static int opt_attach(struct i2c_adapter *adap, int addr, int kind)
{
	struct i2c_client *c;
	int ret,err=0;

	
	gprintk("\n");
	if ( !i2c_check_functionality(adap,I2C_FUNC_SMBUS_BYTE_DATA) ) {
		printk(KERN_INFO "byte op is not permited.\n");
		return err;
	}
	c = kzalloc(sizeof(struct i2c_client),GFP_KERNEL);
	if (!c)
	{
		printk("kzalloc error \n");
		return -ENOMEM;

	}

	memset(c, 0, sizeof(struct i2c_client));	
	strncpy(c->name,"gp2a",I2C_NAME_SIZE);
	c->addr = addr;
	c->adapter = adap;
	c->driver = &opt_i2c_driver;
	c->flags = I2C_DF_NOTIFY | I2C_M_IGNORE_NAK;

	if ((ret = i2c_attach_client(c)) < 0)
	{
		printk("i2c_attach_client error\n");
		goto error;
	}
	opt_i2c_client = c;

	gprintk("\n");
	return ret;

error:
	printk("in %s , ret = %d \n",__func__,ret);
	kfree(c);
	return err;
}
static int i2c_acc_kr3dm_probe_client(struct i2c_adapter *adapter, int address, int kind)
{
	struct i2c_client *new_client;
	int err = 0;


	if ( !i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA) ) {
		printk(KERN_INFO "byte op is not permited.\n");
		goto ERROR0;
	}

	new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL );

	if ( !new_client )  {
		err = -ENOMEM;
		goto ERROR0;
	}

	new_client->addr = address;
 	new_client->adapter = adapter;
	new_client->driver = &acc_kr3dm_i2c_driver;
	new_client->flags = I2C_DF_NOTIFY | I2C_M_IGNORE_NAK;

	g_client = new_client;

	strlcpy(new_client->name, "kr3dm", I2C_NAME_SIZE);

	if ((err = i2c_attach_client(new_client)))
		goto ERROR1;
#ifdef DEBUG
	printk("i2c_acc_kr3dm_probe_client() completed!!!!!!!!!!!!!!!!!!\n");
#endif
	return 0;

	ERROR1:
		printk("i2c_acc_kr3dm_probe_client() ERROR1\n");
		kfree(new_client);
	ERROR0:
		printk("i2c_acc_kr3dm_probe_client() ERROR0\n");
    	return err;
}
Example #19
0
static int ak4183_i2c_probe(struct i2c_adapter *bus, int address, int kind)
{
	int ret;

	D("enter!\n");
	
	ak4183_i2c_client.adapter = bus;
	ak4183_i2c_client.addr= AK4183_I2C_ADDR >> 1;
	ak4183_i2c_client.mode = NORMALMODE;
	ak4183_i2c_client.Channel = I2C_CH1;
	ak4183_i2c_client.addressBit = I2C_7BIT_ADDRESS_8BIT_REG;
	ak4183_i2c_client.speed = 60;

	ret = i2c_attach_client(&ak4183_i2c_client);

	if (ret < 0){
		E("i2c_attach_client err!\n");
	}

	return ret;
}
Example #20
0
static int ov3640_attach(struct i2c_adapter *adap, int addr, int kind)
{
	struct i2c_client *c;

	c = kmalloc(sizeof(*c), GFP_KERNEL);
	if (!c)
		return -ENOMEM;

	memset(c, 0, sizeof(struct i2c_client));	

	strcpy(c->name, "ov3640");
	c->addr = addr;
	c->adapter = adap;
	c->driver = &ov3640_i2c_driver;

	ov3640_data.client = c;

	printk("ov3640 attached successfully\n");

	return i2c_attach_client(c);
}
Example #21
0
//------------------------------- tda9887_attach -------------------------------
static int tda9887_attach(struct i2c_adapter *adap, int addr,
           unsigned short flags, int kind)
{
 struct tda9887 *t;
 client_template.adapter = adap;
 client_template.addr    = addr;
 CPK(printk("tda9887: chip found @ 0x%x\n", addr<<1));
 if (NULL == (t = (struct tda9887*)kmalloc(sizeof(*t), GFP_KERNEL)))
  return -ENOMEM;
 memset(t,0,sizeof(*t));
 t->client = client_template;
 t->pinnacle_id = -1;
 t->tvnorm=VIDEO_MODE_PAL;
 i2c_set_clientdata(&t->client,t);
#ifdef TARGET_OS2
 rmDeviceStruct.DevDescriptName=(PSZ)"TDA9887";
#endif
 i2c_attach_client(&t->client);
 MOD_INC_USE_COUNT;
 return 0;
}
Example #22
0
static int s5k3ba_attach(struct i2c_adapter *adap, int addr, int kind)
{
	struct i2c_client *c;

	c = kmalloc(sizeof(*c), GFP_KERNEL);
	if (!c)
		return -ENOMEM;

	memset(c, 0, sizeof(struct i2c_client));	

	strcpy(c->name, "s5k3ba");
	c->addr = addr;
	c->adapter = adap;
	c->driver = &s5k3ba_i2c_driver;

	s5k3ba_data.client = c;

	info("s5k3ba attached successfully\n");

	return i2c_attach_client(c);
}
Example #23
0
/*!
 * @brief Handles the addition of an I2C adapter capable of supporting the KeyV Chip
 *
 * This function is called by the I2C driver when an adapter has been added to the
 * system that can support communications with the KeyV Chip.  The function will
 * attempt to register a I2C client structure with the adapter so that communication
 * can start.  If the client is successfully registered, the KeyV initialization
 * function will be called to do any register writes required at power-up.
 *
 * @param    adap   A pointer to I2C adapter 
 *
 * @return   This function returns 0 if successful
 */
static int adapter_attach (struct i2c_adapter *adap)
{
    int retval;

    /* Allocate memory for client structure */
    keyv_i2c_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
    memset(keyv_i2c_client, 0, (sizeof(struct i2c_client)));
    
    if(keyv_i2c_client == NULL)
    {
        return -ENOMEM;
    }
    
    /* Fill in the required fields */
    keyv_i2c_client->adapter = adap;
    keyv_i2c_client->addr = KEYV_ADDR;
    keyv_i2c_client->driver = &driver;
    
    /* Register our client */
    retval = i2c_attach_client(keyv_i2c_client);
    
    if(retval != 0)
    {
        /* Request failed, free the memory that we allocated */
        kfree(keyv_i2c_client);
        keyv_i2c_client = NULL;
    }
    /* else we are registered */
    else
    {
        /* Initialize KeyV registers now */
        if(keyv_reg_init != NULL)
        {
            (*keyv_reg_init)();
        }
    }
    
    return retval;
}
Example #24
0
static int conf_attach(struct i2c_adapter *adap, int addr,
			 unsigned short flags,int kind)
{
	struct i2c_client *c;

	c = (struct i2c_client *)kmalloc(sizeof(*c), GFP_KERNEL);
	if (!c)
		return -ENOMEM;
	memset (c, 0, sizeof(*c));

	strcpy(c->name, conf_driver.name);
	c->id = conf_driver.id;
	c->flags = 0;
	c->addr = addr;
	c->adapter = adap;
	c->driver = &conf_driver;
	c->data = NULL;

	conf_client = c;

	return i2c_attach_client(c);
}
Example #25
0
static int
s5k4xa_attach(struct i2c_adapter *adap, int addr, int kind)
{
	struct i2c_client *c;

	c = kmalloc(sizeof(*c), GFP_KERNEL);
	if (!c)
		return -ENOMEM;

	memset(c, 0, sizeof(struct i2c_client));	

	strcpy(c->name, "S5K4XA");
	c->addr = addr;
	c->adapter = adap;
	c->driver = &sensor_driver;
	c->data = &data;
	data.sensor = c;

	s3c_camif_register_sensor(c);

	return i2c_attach_client(c);
}
Example #26
0
/*******************************************************************************
**		Driver Functions
*******************************************************************************/
static int eeprom_attach( struct i2c_adapter *adap, int addr, int unused )
{
	DBG("Attaching client.\n" ) ;
	
	eeprom_client = kmalloc( sizeof( *eeprom_client), GFP_KERNEL );
	if( !eeprom_client ){
		return -ENOMEM;
	}

	strcpy( eeprom_client->name, "AT24Cx" );
	eeprom_client->id = eeprom_driver.id;
	eeprom_client->flags = 0;
	eeprom_client->addr = addr;
	eeprom_client->adapter = adap;

	eeprom_client->driver = &eeprom_driver;
#if 0
	eeprom_client->data = NULL;
#endif

	return i2c_attach_client( eeprom_client );
}
Example #27
0
static int tda9887_attach(struct i2c_adapter *adap, int addr,
			  unsigned short flags, int kind)
{
	struct tda9887 *t;

        client_template.adapter = adap;
        client_template.addr    = addr;

        printk("tda9887: chip found @ 0x%x\n", addr<<1);

        if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
                return -ENOMEM;
	memset(t,0,sizeof(*t));
	t->client = client_template;
	t->pinnacle_id = -1;
	t->tvnorm=VIDEO_MODE_PAL;
        i2c_set_clientdata(&t->client, t);
        i2c_attach_client(&t->client);
        
	MOD_INC_USE_COUNT;
	return 0;
}
Example #28
0
static int keywest_attach_adapter(struct i2c_adapter *adapter)
{
    int err;
    struct i2c_client *new_client;

    if (! keywest_ctx)
        return -EINVAL;

    if (strncmp(i2c_device_name(adapter), "mac-io", 6))
        return 0; /* ignored */

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

    new_client->addr = keywest_ctx->addr;
    i2c_set_clientdata(new_client, keywest_ctx);
    new_client->adapter = adapter;
    new_client->driver = &keywest_driver;
    new_client->flags = 0;

    strcpy(i2c_device_name(new_client), keywest_ctx->name);
    keywest_ctx->client = new_client;

    /* Tell the i2c layer a new client has arrived */
    if (i2c_attach_client(new_client)) {
        snd_printk(KERN_ERR "tumbler: cannot attach i2c client\n");
        err = -ENODEV;
        goto __err;
    }

    return 0;

__err:
    kfree(new_client);
    keywest_ctx->client = NULL;
    return err;
}
Example #29
0
static int
tas_detect_client(struct i2c_adapter *adapter, int address)
{
	static const char *client_name = "tas Digital Equalizer";
	struct i2c_client *new_client;
	int rc = -ENODEV;

	if (!driver_hooks) {
		printk(KERN_ERR "tas_detect_client called with no hooks !\n");
		return -ENODEV;
	}
	
	new_client = kmalloc(sizeof(*new_client), GFP_KERNEL);
	if (!new_client)
		return -ENOMEM;
	memset(new_client, 0, sizeof(*new_client));

	new_client->addr = address;
	new_client->adapter = adapter;
	new_client->driver = &tas_driver;
	strlcpy(new_client->name, client_name, DEVICE_NAME_SIZE);

        if (driver_hooks->init(new_client))
		goto bail;

	/* Tell the i2c layer a new client has arrived */
	if (i2c_attach_client(new_client)) {
		driver_hooks->uninit(dev_get_drvdata(&new_client->dev));
		goto bail;
	}

	tas_client = new_client;
	return 0;
 bail:
	tas_client = NULL;
	kfree(new_client);
	return rc;
}
Example #30
0
static int wis_tw2804_detect(struct i2c_adapter *adapter, int addr, int kind)
{
	struct i2c_client *client;
	struct wis_tw2804 *dec;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return 0;

	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
	if (client == NULL)
		return -ENOMEM;
	memcpy(client, &wis_tw2804_client_templ,
			sizeof(wis_tw2804_client_templ));
	client->adapter = adapter;
	client->addr = addr;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
	client->id = wis_tw2804_i2c_id++;
#endif

	dec = kmalloc(sizeof(struct wis_tw2804), GFP_KERNEL);
	if (dec == NULL) {
		kfree(client);
		return -ENOMEM;
	}
	dec->channel = -1;
	dec->norm = VIDEO_MODE_NTSC;
	dec->brightness = 128;
	dec->contrast = 128;
	dec->saturation = 128;
	dec->hue = 128;
	i2c_set_clientdata(client, dec);

	printk(KERN_DEBUG "wis-tw2804: creating TW2804 at address %d on %s\n",
		addr, adapter->name);

	i2c_attach_client(client);
	return 0;
}