示例#1
0
/* This function is called by i2c_detect */
int ltc1710_detect(struct i2c_adapter *adapter, int address,
		   unsigned short flags, int kind)
{
	int i;
	struct i2c_client *new_client;
	struct ltc1710_data *data;
	int err = 0;
	const char *type_name, *client_name;

	/* Make sure we aren't probing the ISA bus!! This is just a safety check
	   at this moment; i2c_detect really won't call us. */
#ifdef DEBUG
	if (i2c_is_isa_adapter(adapter)) {
		printk
		    ("ltc1710.o: ltc1710_detect called for an ISA bus adapter?!?\n");
		return 0;
	}
#endif

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
		goto ERROR0;

	/* OK. For now, we presume we have a valid client. We now create the
	   client structure, even though we cannot fill it completely yet.
	   But it allows us to access ltc1710_{read,write}_value. */
	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct ltc1710_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}

	data = (struct ltc1710_data *) (new_client + 1);
	new_client->addr = address;
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &ltc1710_driver;
	new_client->flags = 0;

	/* Now, we would do the remaining detection. But the LTC1710 is plainly
	   impossible to detect! Stupid chip. */

	/* Determine the chip type - only one kind supported! */
	if (kind <= 0)
		kind = ltc1710;

	if (kind == ltc1710) {
		type_name = "ltc1710";
		client_name = "LTC1710 chip";
	} else {
#ifdef DEBUG
		printk("ltc1710.o: Internal error: unknown kind (%d)?!?",
		       kind);
#endif
		goto ERROR1;
	}

	/* Fill in the remaining client fields and put it into the global list */
	strcpy(new_client->name, client_name);

	new_client->id = ltc1710_id++;
	data->valid = 0;
	init_MUTEX(&data->update_lock);

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

	/* Register a new directory entry with module sensors */
	if ((i = i2c_register_entry(new_client, type_name,
					ltc1710_dir_table_template,
					THIS_MODULE)) < 0) {
		err = i;
		goto ERROR4;
	}
	data->sysctl_id = i;

	return 0;

/* OK, this is not exactly good programming practice, usually. But it is
   very code-efficient in this case. */

      ERROR4:
	i2c_detach_client(new_client);
      ERROR3:
      ERROR1:
	kfree(new_client);
      ERROR0:
	return err;
}
示例#2
0
int mtp008_detect(struct i2c_adapter *adapter, int address,
		  unsigned short flags, int kind)
{
	const char *type_name = "";
	const char *client_name = "";
	int is_isa, err, sysid;
	struct i2c_client *new_client;
	struct mtp008_data *data;

	err = 0;

	is_isa = i2c_is_isa_adapter(adapter);
	if (is_isa ||
	    !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		goto ERROR0;

	/*
	 * We presume we have a valid client.  We now create the client
	 * structure, even though we cannot fill it completely yet.  But it
	 * allows us to use mtp008_(read|write)_value().
	 */
	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct mtp008_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}
	data = (struct mtp008_data *) (new_client + 1);
	new_client->addr = address;
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &mtp008_driver;
	new_client->flags = 0;

	/*
	 * Remaining detection.
	 */
	if (kind < 0) {
		if (mtp008_read_value(new_client, MTP008_REG_CHIPID) != 0xac)
			goto ERROR1;
	}
	/*
	 * Fill in the remaining client fields and put it into the global list.
	 */
	type_name = "mtp008";
	client_name = "MTP008 chip";
	strcpy(new_client->name, client_name);
	data->type = kind;

	new_client->id = mtp008_id++;
	data->valid = 0;
	init_MUTEX(&data->update_lock);

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

	/*
	 * Register a new directory entry with the sensors module.
	 */
	if ((sysid = i2c_register_entry(new_client, type_name,
					    mtp008_dir_table_template,
					    THIS_MODULE)) < 0) {
		err = sysid;
		goto ERROR2;
	}
	data->sysctl_id = sysid;

	/*
	 * Initialize the MTP008 chip.
	 */
	mtp008_init_client(new_client);

	return 0;

	/*
	 * Error handling.  Bad programming practise but very code efficient.
	 */
      ERROR2:
	i2c_detach_client(new_client);
      ERROR1:
	kfree(new_client);

      ERROR0:
	return err;
}
示例#3
0
/* This function is called by i2c_detect */
int ddcmon_detect(struct i2c_adapter *adapter, int address,
		  unsigned short flags, int kind)
{
	int i, cs;
	struct i2c_client *new_client;
	struct ddcmon_data *data;
	int err = 0;
	const char *type_name, *client_name;

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

	/* OK. For now, we presume we have a valid client. We now create the
	   client structure, even though we cannot fill it completely yet.
	   But it allows us to access ddcmon_{read,write}_value. */
	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct ddcmon_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}

	data = (struct ddcmon_data *) (new_client + 1);
	new_client->addr = address;
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &ddcmon_driver;
	new_client->flags = 0;

	/* Now, we do the remaining detection. */
	/* Verify the first 8 locations 0x00FFFFFFFFFFFF00 */
	/* Allow force and force_ddcmon arguments */
	if(kind < 0)
	{
		for(i = 0; i < 8; i++) {
			cs = i2c_smbus_read_byte_data(new_client, i);
			if(i == 0 || i == 7) {
				if(cs != 0)
					goto ERROR1;
			} else if(cs != 0xff)
				goto ERROR1;
		}
	}

	type_name = "ddcmon";
	client_name = "DDC Monitor";

	/* Fill in the remaining client fields and put it in the global list */
	strcpy(new_client->name, client_name);

	new_client->id = ddcmon_id++;
	data->valid = 0;
	init_MUTEX(&data->update_lock);

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

	/* Register a new directory entry with module sensors */
	if ((i = i2c_register_entry(new_client, type_name,
					ddcmon_dir_table_template,
					THIS_MODULE)) < 0) {
		err = i;
		goto ERROR4;
	}
	data->sysctl_id = i;

	return 0;

      ERROR4:
	i2c_detach_client(new_client);
      ERROR3:
      ERROR1:
	kfree(new_client);
      ERROR0:
	return err;
}
示例#4
0
int sis5595_detect(struct i2c_adapter *adapter, int address,
		   unsigned short flags, int kind)
{
	int i;
	struct i2c_client *new_client;
	struct sis5595_data *data;
	int err = 0;
	const char *type_name = "sis5595";
	const char *client_name = "SIS5595 chip";
	char val;
	u16 a;

	/* Make sure we are probing the ISA bus!!  */
	if (!i2c_is_isa_adapter(adapter)) {
		printk
		    ("sis5595.o: sis5595_detect called for an I2C bus adapter?!?\n");
		return 0;
	}

	if(force_addr)
		address = force_addr & ~(SIS5595_EXTENT - 1);
	if (check_region(address, SIS5595_EXTENT)) {
		printk("sis5595.o: region 0x%x already in use!\n", address);
		return -ENODEV;
	}
	if(force_addr) {
		printk("sis5595.o: forcing ISA address 0x%04X\n", address);
		if (PCIBIOS_SUCCESSFUL !=
		    pci_write_config_word(s_bridge, SIS5595_BASE_REG, address))
			return -ENODEV;
		if (PCIBIOS_SUCCESSFUL !=
		    pci_read_config_word(s_bridge, SIS5595_BASE_REG, &a))
			return -ENODEV;
		if ((a & ~(SIS5595_EXTENT - 1)) != address) {
			/* doesn't work for some chips? */
			printk("sis5595.o: force address failed\n");
			return -ENODEV;
		}
	}

	if (PCIBIOS_SUCCESSFUL !=
	    pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val))
		return -ENODEV;
	if((val & 0x80) == 0) {
		printk("sis5595.o: enabling sensors\n");
		if (PCIBIOS_SUCCESSFUL !=
		    pci_write_config_byte(s_bridge, SIS5595_ENABLE_REG,
		                      val | 0x80))
			return -ENODEV;
		if (PCIBIOS_SUCCESSFUL !=
		    pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val))
			return -ENODEV;
		if((val & 0x80) == 0) {	/* doesn't work for some chips! */
			printk("sis5595.o: sensors enable failed - not supported?\n");
			return -ENODEV;
		}
	}

	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct sis5595_data),
				   GFP_KERNEL))) {
		return -ENOMEM;
	}

	data = (struct sis5595_data *) (new_client + 1);
	new_client->addr = address;
	init_MUTEX(&data->lock);
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &sis5595_driver;
	new_client->flags = 0;

	/* Reserve the ISA region */
	request_region(address, SIS5595_EXTENT, type_name);

	/* Check revision and pin registers to determine whether 3 or 4 voltages */
	pci_read_config_byte(s_bridge, SIS5595_REVISION_REG, &(data->revision));
	if(data->revision < REV2MIN) {
		data->maxins = 3;
	} else {
		pci_read_config_byte(s_bridge, SIS5595_PIN_REG, &val);
		if(val & 0x80)
			/* 3 voltages, 1 temp */
			data->maxins = 3;
		else
			/* 4 voltages, no temps */
			data->maxins = 4;
	}

	/* Fill in the remaining client fields and put it into the global list */
	strcpy(new_client->name, client_name);

	new_client->id = sis5595_id++;
	data->valid = 0;
	init_MUTEX(&data->update_lock);

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

	/* Register a new directory entry with module sensors */
	if ((i = i2c_register_entry((struct i2c_client *) new_client,
					type_name,
					sis5595_dir_table_template,
					THIS_MODULE)) < 0) {
		err = i;
		goto ERROR4;
	}
	data->sysctl_id = i;

	/* Initialize the SIS5595 chip */
	sis5595_init_client(new_client);
	return 0;

      ERROR4:
	i2c_detach_client(new_client);
      ERROR3:
	release_region(address, SIS5595_EXTENT);
	kfree(new_client);
	return err;
}
示例#5
0
/* This function is called by i2c_detect */
int icspll_detect(struct i2c_adapter *adapter, int address,
   	          unsigned short flags, int kind)
{
	int err, i;
	struct i2c_client *new_client;
	struct icspll_data *data;

	err = 0;
	/* Make sure we aren't probing the ISA bus!! */
	if (i2c_is_isa_adapter(adapter))
		return 0;

	if (address != ADDRESS)
		return 0;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BLOCK_DATA |
				     I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
		printk("icspll.o: Adapter does not support SMBus writes and Block reads\n");
		goto ERROR0;
	}

	/* Allocate space for a new client structure */
	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct icspll_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}

	/* Fill the new client structure with data */
	data = (struct icspll_data *) (new_client + 1);
	new_client->data = data;
	new_client->id = icspll_id++;
	new_client->addr = address;
	new_client->adapter = adapter;
	new_client->driver = &icspll_driver;
	new_client->flags = 0;
	strcpy(new_client->name, "Clock chip");
	data->valid = 0;
	init_MUTEX(&data->update_lock);

	/* use write-quick for detection */
	if (i2c_smbus_write_quick(new_client, 0x00) < 0) {
		printk("icspll.o: No device found at 0x%X\n", address);
		goto ERROR1;
	}

	/* fill data structure so unknown registers are 0xFF */
	data->data[0] = ICSPLL_SIZE;
	for (i = 1; i <= ICSPLL_SIZE; i++)
		data->data[i] = 0xFF;

	/* Tell i2c-core a new client has arrived */
	if ((err = i2c_attach_client(new_client)))
		goto ERROR2;

	/* Register a new directory entry with module sensors */
	if ((err = i2c_register_entry(new_client, "icspll",
					  icspll_dir_table_template,
					  THIS_MODULE)) < 0)
		goto ERROR3;
	data->sysctl_id = err;
	err = 0;

      ERROR3:
	i2c_detach_client(new_client);
      ERROR2:
      ERROR1:
	kfree(new_client);
      ERROR0:
	return err;
}
示例#6
0
文件: max1619.c 项目: OPSF/uClinux
/*
 * The following function does more than just detection. If detection
 * succeeds, it also registers the new chip.
 */
static int max1619_detect(struct i2c_adapter *adapter, int address,
	unsigned short flags, int kind)
{
	struct i2c_client *new_client;
	struct max1619_data *data;
	int err = 0;
	const char *type_name = "";
	const char *client_name = "";

#ifdef DEBUG
	if (i2c_is_isa_adapter(adapter)) {
		printk(KERN_DEBUG "max1619.o: Called for an ISA bus "
		       "adapter, aborting.\n");
		return 0;
	}
#endif

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
#ifdef DEBUG
		printk(KERN_DEBUG "max1619.o: I2C bus doesn't support "
		       "byte read mode, skipping.\n");
#endif
		return 0;
	}

	if (!(data = kmalloc(sizeof(struct max1619_data), GFP_KERNEL))) {
		printk(KERN_ERR "max1619.o: Out of memory in "
		       "max1619_detect (new_client).\n");
		return -ENOMEM;
	}

	/*
	 * The common I2C client data is placed right before the
	 * MAX1619-specific data. The MAX1619-specific data is pointed to
	 * by the data field from the I2C client da1ta.
	 */

	new_client = &data->client;
	new_client->addr = address;
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &max1619_driver;
	new_client->flags = 0;

	/*
	 * Now we do the remaining detection. A negative kind means that
	 * the driver was loaded with no force parameter (default), so we
	 * must both detect and identify the chip. A zero kind means that
	 * the driver was loaded with the force parameter, the detection
	 * step shall be skipped. A positive kind means that the driver
	 * was loaded with the force parameter and a given kind of chip is
	 * requested, so both the detection and the identification steps
	 * are skipped.
	 */

	if (kind < 0) {
		u8 reg_config, reg_convrate, reg_status;

		reg_config = i2c_smbus_read_byte_data(new_client,
			MAX1619_REG_R_CONFIG);
		reg_convrate = i2c_smbus_read_byte_data(new_client,
			MAX1619_REG_R_CONVRATE);
		reg_status = i2c_smbus_read_byte_data(new_client,
			MAX1619_REG_R_STATUS);

		if ((reg_config & 0x03) != 0x00
		 || reg_convrate > 0x07
		 || (reg_status & 0x61) != 0x00) {
#ifdef DEBUG
			printk(KERN_DEBUG "max1619.o: Detection failed at "
			       "0x%02x.\n", address);
#endif
			goto ERROR1;
		}
	}

	if (kind <= 0) {
		u8 man_id, chip_id;

		man_id = i2c_smbus_read_byte_data(new_client,
			MAX1619_REG_R_MAN_ID);
		chip_id = i2c_smbus_read_byte_data(new_client,
			MAX1619_REG_R_CHIP_ID);

		if ((man_id == 0x4D) && (chip_id == 0x04)) {
			kind = max1619;
		}
	}

	if (kind <= 0) {
		printk(KERN_INFO "max1619.o: Unsupported chip.\n");
		goto ERROR1;
	}

	if (kind == max1619) {
		type_name = "max1619";
		client_name = "MAX1619 chip";
	} else {
		printk(KERN_ERR "max1619.o: Unknown kind %d.\n", kind);
		goto ERROR1;
	}

	/*
	 * OK, we got a valid chip so we can fill in the remaining client
	 * fields.
	 */

	strcpy(new_client->name, client_name);
	data->valid = 0;
	init_MUTEX(&data->update_lock);

	/*
	 * Tell the I2C layer a new client has arrived.
	 */

	if ((err = i2c_attach_client(new_client))) {
		printk(KERN_ERR "max1619.o: Failed attaching client.\n");
		goto ERROR1;
	}

	/*
	 * Register a new directory entry.
	 */

	if ((err = i2c_register_entry(new_client, type_name,
	     max1619_dir_table_template, THIS_MODULE)) < 0) {
		printk(KERN_ERR "max1619.o: Failed registering directory "
		       "entry.\n");
		goto ERROR2;
	}
	data->sysctl_id = err;

	/*
	 * Initialize the MAX1619 chip.
	 */

	max1619_init_client(new_client);
	return 0;

ERROR2:
	i2c_detach_client(new_client);
ERROR1:
	kfree(data);
	return err;
}
示例#7
0
static int adm1025_detect(struct i2c_adapter *adapter, int address,
			  unsigned short flags, int kind)
{
	int i;
	struct i2c_client *new_client;
	struct adm1025_data *data;
	int err = 0;
	const char *type_name = "";
	const char *client_name = "";

	/* Make sure we aren't probing the ISA bus!! This is just a safety check
	   at this moment; i2c_detect really won't call us. */
#ifdef DEBUG
	if (i2c_is_isa_adapter(adapter)) {
		printk
		    ("adm1025.o: adm1025_detect called for an ISA bus adapter?!?\n");
		return 0;
	}
#endif

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

	/* OK. For now, we presume we have a valid client. We now create the
	   client structure, even though we cannot fill it completely yet.
	   But it allows us to access adm1025_{read,write}_value. */

	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct adm1025_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}

	data = (struct adm1025_data *) (new_client + 1);
	new_client->addr = address;
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &adm1025_driver;
	new_client->flags = 0;

	/* Now, we do the remaining detection. */

	if (kind < 0) {
		if((adm1025_read_value(new_client,ADM1025_REG_CONFIG) & 0x80) != 0x00)
			goto ERROR1;
	}

	/* Determine the chip type. */
	if (kind <= 0) {
		i = adm1025_read_value(new_client, ADM1025_REG_COMPANY_ID);
		if (i == 0x41)
			kind = adm1025;
		else {
			if (kind == 0)
				printk
				    ("adm1025.o: Ignoring 'force' parameter for unknown chip at "
				     "adapter %d, address 0x%02x\n",
				     i2c_adapter_id(adapter), address);
			goto ERROR1;
		}
	}

	if (kind == adm1025) {
		type_name = "adm1025";
		client_name = "ADM1025 chip";
	} else {
#ifdef DEBUG
		printk("adm1025.o: Internal error: unknown kind (%d)?!?",
		       kind);
#endif
		goto ERROR1;
	}

	/* Fill in the remaining client fields and put it into the global list */
	strcpy(new_client->name, client_name);
	data->type = kind;

	new_client->id = adm1025_id++;
	data->valid = 0;
	init_MUTEX(&data->update_lock);

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

	/* Register a new directory entry with module sensors */
	if ((i = i2c_register_entry(new_client,
					type_name,
					adm1025_dir_table_template,
					THIS_MODULE)) < 0) {
		err = i;
		goto ERROR4;
	}
	data->sysctl_id = i;

	/* Initialize the ADM1025 chip */
	adm1025_init_client(new_client);
	return 0;

/* OK, this is not exactly good programming practice, usually. But it is
   very code-efficient in this case. */

      ERROR4:
	i2c_detach_client(new_client);
      ERROR3:
      ERROR1:
	kfree(new_client);
      ERROR0:
	return err;
}
示例#8
0
/* This function is called by i2c_detect */
int pcf8591t_detect(struct i2c_adapter *adapter, int address,
                  unsigned short flags, int kind)
{
        int err = 0, i;
        struct i2c_client *new_client;
        struct pcf8591t_data *data;
        const char *type_name, *client_name;

        if (i2c_is_isa_adapter(adapter)) {
                printk(MSG_HEAD "bu9929_detect called for an ISA bus adapter?!?\n");
                return 0;
        }

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

        /* OK. For now, we presume we have a valid client. We now create the
           client structure, even though we cannot fill it completely yet.
           But it allows us to access ddcmon_{read,write}_value. */
        if (!(new_client = kmalloc(sizeof(struct i2c_client) +
                                   sizeof(struct pcf8591t_data),
                                   GFP_KERNEL))) {
                err = -ENOMEM;
                goto ERROR0;
        }

        data = (struct pcf8591t_data *) (new_client + 1);
        new_client->addr = address;
        new_client->data = data;
        new_client->adapter = adapter;
        new_client->driver = &pcf8591t_driver;
        new_client->flags = 0;

        if (kind < 0)
                kind = PCF8591T;

        if (kind == PCF8591T) {
                type_name = "pcf8591t";
                client_name = "PCF8591T A/D converter";
        } else {
#ifdef DEBUG
                printk(MSG_HEAD "Internal error: unknown kind (%d)?!?",
                       kind);
#endif
                goto ERROR1;
        }

        /* Fill in the remaining client fields and put it in the global list */
        strcpy(new_client->name, client_name);

        new_client->id = pcf8591t_id;
        init_MUTEX(&data->update_lock);

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

        /* Register a new directory entry with module sensors */
        if ((i = i2c_register_entry(new_client, type_name,
                                        pcf8591t_dir_table_template,
                                        THIS_MODULE)) < 0) {
                err = i;
                goto ERROR4;
        }
        data->sysctl_id = i;

        g_client = new_client;

        return 0;

ERROR4:
        i2c_detach_client(new_client);

ERROR3:
ERROR1:
        kfree(new_client);
ERROR0:
        return err;
}
示例#9
0
/* This function is called by i2c_detect */
int maxi_detect(struct i2c_adapter *adapter, int address,
		unsigned short flags, int kind)
{
	struct i2c_client *new_client;
	struct maxi_data *data;
	enum maxi_type type = 0;
	int i, j, err = 0;
	const char *type_name = NULL, *client_name = NULL;

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

	/* OK. For now, we presume we have a valid client. We now create the
	   client structure, even though we cannot fill it completely yet.
	   But it allows us to access maxi_{read,write}_value. */
	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct maxi_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}

	/* Fill the new client structure with data */
	data = (struct maxi_data *) (new_client + 1);
	new_client->addr = address;
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &maxi_driver;
	new_client->flags = 0;

	/* Now we do the remaining detection. */
	if (kind < 0) {
		if (i2c_smbus_read_byte_data
		    (new_client, MAXI_REG_MBX_STATUS) < 0)
			goto ERROR2;
	}

	/* Determine the chip type - only one kind supported */
	if (kind <= 0)
		kind = maxilife;

	if (kind == maxilife) {
		/* Detect if the machine has a MaxiLife NBA controller.
		   The right way to perform this check is to do a read/modify/write
		   on register MbxStatus (5A):
		   - Read 5A (value 0 for non-NBA firmware, FF (MbxIdle on NBA-firmware)
		   - Write 55 on 5A, then read back 5A
		   Non-NBA firmware: value is 55 (reg 5A is a standard writable reg)
		   NBA firmaware: value is FF (write-protect on MbxStatus active) */
		int stat;
		i2c_smbus_write_byte_data(new_client, MAXI_REG_MBX_STATUS,
					  0x55);
		stat =
		    i2c_smbus_read_byte_data(new_client,
					     MAXI_REG_MBX_STATUS);

		/*if (stat == MAXI_STAT_IDLE || stat == MAXI_STAT_OK) */
		if (stat != 0x55)
			maxi_version = nba;
#ifdef AUTODETECT
		else {
			/* The right way to get the platform info is to read the firmware
			   revision from serial EEPROM (addr=0x54), at offset 0x0045.
			   This is a string as:
			   "CG 00.04" -> Cristal [XU] / Geronimo [XAs]
			   "CO 00.03" -> Cognac [XU]
			   "AS 00.01" -> Ashaki [XA] */
#if 0
			int biosctl;
			biosctl =
			    i2c_smbus_read_byte_data(new_client,
						     MAXI_REG_BIOS_CTRL);
			i2c_smbus_write_byte_data(new_client,
						  MAXI_REG_BIOS_CTRL,
						  biosctl | 4);
			err = eeprom_read_byte_data(adapter, 0x54, 0x45);
			i2c_smbus_write_byte_data(new_client,
						  MAXI_REG_BIOS_CTRL,
						  biosctl);
#endif
			int i;
			char *biosmem, *bm;
			bm = biosmem = ioremap(0xe0000, 0x20000);
			if (biosmem) {
				printk("begin of bios search\n");
				for (i = 0; i < 0x20000; i++) {
					if (*bm == 'C') {
						char *s = bm;
						while (s && isprint(*s)) {
							printk("%c", *s);
							s++;
						}
						printk("\n");
						if (!strncmp
						    (bm, "CG 00.04", 8)) {
							maxi_version =
							    cristal;
							printk
							    ("maxilife: found MaxiLife Rev CG 00.04\n");
							break;
						}
						if (!strncmp
						    (bm, "CO 00.03", 8)) {
							maxi_version =
							    cognac;
							printk
							    ("maxilife: found MaxiLife Rev CO 00.03\n");
							break;
						}
					}
					if (*bm == 'A' && *(bm + 1) == 'S') {
						char *s = bm;
						while (s && isprint(*s)) {
							printk("%c", *s);
							s++;
						}
						printk("\n");
						if (!strncmp
						    (bm, "AS 00.01", 8)) {
							maxi_version =
							    ashaki;
							printk
							    ("maxilife: found MaxiLife Rev AS 00.01\n");
							break;
						}
					}
					bm++;
				}
				printk("end of bios search\n");
			} else
				printk("could not map bios memory\n");
		}
#endif

		if (maxi_version == cristal) {
			type = cristal;
			type_name = "maxilife-cg";
			client_name = "HP MaxiLife Rev CG 00.04";
			printk
			    ("maxilife: HP KAYAK XU/XAs (Dual Pentium II Slot 1)\n");
		} else if (maxi_version == cognac) {
			type = cognac;
			type_name = "maxilife-co";
			client_name = "HP MaxiLife Rev CO 00.03";
			printk
			    ("maxilife: HP KAYAK XU (Dual Xeon Slot 2 400/450 Mhz)\n");
		} else if (maxi_version == ashaki) {
			type = ashaki;
			type_name = "maxilife-as";
			client_name = "HP MaxiLife Rev AS 00.01";
			printk
			    ("maxilife: HP KAYAK XA (Pentium II Slot 1, monoprocessor)\n");
		} else if (maxi_version == nba) {
			type = nba;
			type_name = "maxilife-nba";
			client_name = "HP MaxiLife NBA";
			printk("maxilife: HP KAYAK XU800/XM600\n");
		} else {
#ifdef AUTODETECT
			printk
			    ("maxilife: Warning: probed non-maxilife chip?!? (%x)\n",
			     err);
#else
			printk
			    ("maxilife: Error: specified wrong maxi_version (%d)\n",
			     maxi_version);
#endif
			goto ERROR2;
		}
	}

	/* Fill in the remaining client fields and put it into the global list */
	strcpy(new_client->name, client_name);
	((struct maxi_data *) (new_client->data))->type = type;

	for (i = 0; i < 4; i++)
		for (j = 0; j < 17; j++)
			    ((struct maxi_data *) (new_client->data))->
			    lcd[i][j] = (u8) 0;

	new_client->id = maxi_id++;

	data->valid = 0;
	init_MUTEX(&data->lock);
	init_MUTEX(&data->update_lock);

	/* Tell i2c-core that a new client has arrived */
	if ((err = i2c_attach_client(new_client)))
		goto ERROR2;

	/* Register a new directory entry with module sensors */
	if ((err = i2c_register_entry(new_client, type_name,
					  maxi_dir_table_template,
					  THIS_MODULE)) < 0)
		goto ERROR4;
	data->sysctl_id = err;

	/* Initialize the MaxiLife chip */
	maxi_init_client(new_client);
	return 0;

	/* OK, this is not exactly good programming practice, usually.
	   But it is very code-efficient in this case. */
      ERROR4:
	i2c_detach_client(new_client);
      ERROR2:
	kfree(new_client);
      ERROR0:
	return err;
}
示例#10
0
/* This function is called by i2c_detect */
int matorb_detect(struct i2c_adapter *adapter, int address,
		  unsigned short flags, int kind)
{
	int i, cur;
	struct i2c_client *new_client;
	struct matorb_data *data;
	int err = 0;
	const char *type_name = "matorb";
	const char *client_name = "matorb";

	/* Make sure we aren't probing the ISA bus!! This is just a safety check
	   at this moment; i2c_detect really won't call us. */
#ifdef DEBUG
	if (i2c_is_isa_adapter(adapter)) {
		printk
		    ("matorb.o: matorb_detect called for an ISA bus adapter?!?\n");
		return 0;
	}
#endif

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE |
				     I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
		    goto ERROR0;


	/* OK. For now, we presume we have a valid client. We now create the
	   client structure, even though we cannot fill it completely yet.
	   But it allows us to access matorb_{read,write}_value. */
	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct matorb_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}

	data = (struct matorb_data *) (new_client + 1);
	new_client->addr = address;
	new_client->data = data;
	new_client->adapter = adapter;
	new_client->driver = &matorb_driver;
	new_client->flags = 0;

	/* Now, we do the remaining detection. It is lousy. */
	cur = i2c_smbus_write_byte_data(new_client, 0x0FE, 0x58);	/* clear screen */

	printk("matorb.o: debug detect 0x%X\n", cur);

	/* Fill in the remaining client fields and put it into the global list */
	strcpy(new_client->name, client_name);

	new_client->id = matorb_id++;
	data->valid = 0;
	init_MUTEX(&data->update_lock);

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

	/* Register a new directory entry with module sensors */
	if ((i = i2c_register_entry(new_client, type_name,
					matorb_dir_table_template,
					THIS_MODULE)) < 0) {
		err = i;
		goto ERROR4;
	}
	data->sysctl_id = i;

	matorb_init_client(new_client);
	return 0;

/* OK, this is not exactly good programming practice, usually. But it is
   very code-efficient in this case. */

      ERROR4:
	i2c_detach_client(new_client);
      ERROR3:
	kfree(new_client);
      ERROR0:
	return err;
}