예제 #1
0
static int wf_lm75_attach(struct i2c_adapter *adapter)
{
	struct device_node *busnode, *dev;
	struct pmac_i2c_bus *bus;

	DBG("wf_lm75: adapter %s detected\n", adapter->name);

	bus = pmac_i2c_adapter_to_bus(adapter);
	if (bus == NULL)
		return -ENODEV;
	busnode = pmac_i2c_get_bus_node(bus);

	DBG("wf_lm75: bus found, looking for device...\n");

	/* Now look for lm75(s) in there */
	for (dev = NULL;
	     (dev = of_get_next_child(busnode, dev)) != NULL;) {
		const char *loc =
			of_get_property(dev, "hwsensor-location", NULL);
		u8 addr;

		/* We must re-match the adapter in order to properly check
		 * the channel on multibus setups
		 */
		if (!pmac_i2c_match_adapter(dev, adapter))
			continue;
		addr = pmac_i2c_get_dev_addr(dev);
		if (loc == NULL || addr == 0)
			continue;
		/* real lm75 */
		if (of_device_is_compatible(dev, "lm75"))
			wf_lm75_create(adapter, addr, 0, loc);
		/* ds1775 (compatible, better resolution */
		else if (of_device_is_compatible(dev, "ds1775"))
			wf_lm75_create(adapter, addr, 1, loc);
	}
	return 0;
}
static int wf_lm75_attach(struct i2c_adapter *adapter)
{
	u8 bus_id;
	struct device_node *smu, *bus, *dev;

	/* We currently only deal with LM75's hanging off the SMU
	 * i2c busses. If we extend that driver to other/older
	 * machines, we should split this function into SMU-i2c,
	 * keywest-i2c, PMU-i2c, ...
	 */

	DBG("wf_lm75: adapter %s detected\n", adapter->name);

	if (strncmp(adapter->name, "smu-i2c-", 8) != 0)
		return 0;
	smu = of_find_node_by_type(NULL, "smu");
	if (smu == NULL)
		return 0;

	/* Look for the bus in the device-tree */
	bus_id = (u8)simple_strtoul(adapter->name + 8, NULL, 16);

	DBG("wf_lm75: bus ID is %x\n", bus_id);

	/* Look for sensors subdir */
	for (bus = NULL;
	     (bus = of_get_next_child(smu, bus)) != NULL;) {
		u32 *reg;

		if (strcmp(bus->name, "i2c"))
			continue;
		reg = (u32 *)get_property(bus, "reg", NULL);
		if (reg == NULL)
			continue;
		if (bus_id == *reg)
			break;
	}
	of_node_put(smu);
	if (bus == NULL) {
		printk(KERN_WARNING "windfarm: SMU i2c bus 0x%x not found"
		       " in device-tree !\n", bus_id);
		return 0;
	}

	DBG("wf_lm75: bus found, looking for device...\n");

	/* Now look for lm75(s) in there */
	for (dev = NULL;
	     (dev = of_get_next_child(bus, dev)) != NULL;) {
		const char *loc =
			get_property(dev, "hwsensor-location", NULL);
		u32 *reg = (u32 *)get_property(dev, "reg", NULL);
		DBG(" dev: %s... (loc: %p, reg: %p)\n", dev->name, loc, reg);
		if (loc == NULL || reg == NULL)
			continue;
		/* real lm75 */
		if (device_is_compatible(dev, "lm75"))
			wf_lm75_create(adapter, *reg, 0, loc);
		/* ds1775 (compatible, better resolution */
		else if (device_is_compatible(dev, "ds1775"))
			wf_lm75_create(adapter, *reg, 1, loc);
	}

	of_node_put(bus);

	return 0;
}