switch (size) { case I2C_SMBUS_QUICK:
buf = NULL;
len = 0; break; case I2C_SMBUS_BYTE: case I2C_SMBUS_BYTE_DATA:
buf = &data->byte;
len = 1; break; case I2C_SMBUS_WORD_DATA: if (!read) {
local[0] = data->word & 0xff;
local[1] = (data->word >> 8) & 0xff;
}
buf = local;
len = 2; break;
/* Note that these are broken vs. the expected smbus API where * on reads, the length is actually returned from the function, * but I think the current API makes no sense and I don't want * any driver that I haven't verified for correctness to go * anywhere near a pmac i2c bus anyway ...
*/ case I2C_SMBUS_BLOCK_DATA:
buf = data->block;
len = data->block[0] + 1; break; case I2C_SMBUS_I2C_BLOCK_DATA:
buf = &data->block[1];
len = data->block[0]; break;
default: return -EINVAL;
}
rc = pmac_i2c_open(bus, 0); if (rc) {
dev_err(&adap->dev, "Failed to open I2C, err %d\n", rc); return rc;
}
rc = pmac_i2c_setmode(bus, mode); if (rc) {
dev_err(&adap->dev, "Failed to set I2C mode %d, err %d\n",
mode, rc); goto bail;
}
rc = pmac_i2c_xfer(bus, addrdir, subsize, subaddr, buf, len); if (rc) { if (rc == -ENXIO)
dev_dbg(&adap->dev, "I2C transfer at 0x%02x failed, size %d, " "err %d\n", addrdir >> 1, size, rc); else
dev_err(&adap->dev, "I2C transfer at 0x%02x failed, size %d, " "err %d\n", addrdir >> 1, size, rc); goto bail;
}
/* * Generic i2c transfer entrypoint. This driver only supports single * messages (for "lame i2c" transfers). Anything else should use the smbus * entry point
*/ staticint i2c_powermac_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
{ struct pmac_i2c_bus *bus = i2c_get_adapdata(adap); int rc = 0; int addrdir;
if (msgs->flags & I2C_M_TEN) return -EINVAL;
addrdir = i2c_8bit_addr_from_msg(msgs);
/* First check for valid "reg" */
ret = of_property_read_u32(node, "reg", &prop); if (ret == 0) return (prop & 0xff) >> 1;
/* Then check old-style "i2c-address" */
ret = of_property_read_u32(node, "i2c-address", &prop); if (ret == 0) return (prop & 0xff) >> 1;
/* Now handle some devices with missing "reg" properties */ if (of_node_name_eq(node, "cereal")) return 0x60; elseif (of_node_name_eq(node, "deq")) return 0x34;
dev_warn(&adap->dev, "No i2c address for %pOF\n", node);
/* Check for the onyx audio codec */ #define ONYX_REG_CONTROL 67 if (of_device_is_compatible(busnode, "k2-i2c") && !found_onyx) { union i2c_smbus_data data;
/* * Note: we do _NOT_ want the standard i2c drivers to match with any of * our powermac stuff unless they have been specifically modified to * handle it on a case by case basis. For example, for thermal control, * things like lm75 etc... shall match with their corresponding * windfarm drivers, _NOT_ the generic ones, so we force a prefix of * 'MAC', onto the modalias to make that happen
*/
/* First try proper modalias */ if (of_alias_from_compatible(node, tmp, sizeof(tmp)) >= 0) {
snprintf(type, type_size, "MAC,%s", tmp); returntrue;
}
/* Now look for known workarounds */ if (of_node_name_eq(node, "deq")) { /* Apple uses address 0x34 for TAS3001 and 0x35 for TAS3004 */ if (addr == 0x34) {
snprintf(type, type_size, "MAC,tas3001"); returntrue;
} elseif (addr == 0x35) {
snprintf(type, type_size, "MAC,tas3004"); returntrue;
}
}
dev_err(&adap->dev, "i2c-powermac: modalias failure on %pOF\n", node); returnfalse;
}
/* * In some cases we end up with the via-pmu node itself, in this * case we skip this function completely as the device-tree will * not contain anything useful.
*/ if (of_node_name_eq(adap->dev.of_node, "via-pmu")) return;
for_each_child_of_node(adap->dev.of_node, node) { struct i2c_board_info info = {};
u32 addr;
/* Get address & channel */
addr = i2c_powermac_get_addr(adap, bus, node); if (addr == 0xffffffff) continue;
/* Multibus setup, check channel */ if (!pmac_i2c_match_adapter(node, adap)) continue;
/* * Keep track of some device existence to handle * workarounds later.
*/ if (of_device_is_compatible(node, "pcm3052"))
found_onyx = true;
/* Make up a modalias */ if (!i2c_powermac_get_type(adap, node, addr,
info.type, sizeof(info.type))) { continue;
}
/* Fill out the rest of the info structure */
info.addr = addr;
info.irq = irq_of_parse_and_map(node, 0);
info.fwnode = of_fwnode_handle(of_node_get(node));
newdev = i2c_new_client_device(adap, &info); if (IS_ERR(newdev)) {
dev_err(&adap->dev, "i2c-powermac: Failure to register" " %pOF\n", node);
of_node_put(node); /* We do not dispose of the interrupt mapping on * purpose. It's not necessary (interrupt cannot be * re-used) and somebody else might have grabbed it * via direct DT lookup so let's not bother
*/ continue;
}
}
if (bus == NULL) return -EINVAL;
adapter = pmac_i2c_get_adapter(bus);
/* Ok, now we need to make up a name for the interface that will * match what we used to do in the past, that is basically the * controller's parent device node for keywest. PMU didn't have a * naming convention and SMU has a different one
*/ switch(pmac_i2c_get_type(bus)) { case pmac_i2c_bus_keywest:
parent = of_get_parent(pmac_i2c_get_controller(bus)); if (parent == NULL) return -EINVAL;
snprintf(adapter->name, sizeof(adapter->name), "%pOFn %d",
parent,
pmac_i2c_get_channel(bus));
of_node_put(parent); break; case pmac_i2c_bus_pmu:
snprintf(adapter->name, sizeof(adapter->name), "pmu %d",
pmac_i2c_get_channel(bus)); break; case pmac_i2c_bus_smu: /* This is not what we used to do but I'm fixing drivers at * the same time as this change
*/
snprintf(adapter->name, sizeof(adapter->name), "smu %d",
pmac_i2c_get_channel(bus)); break; default: return -EINVAL;
}
printk(KERN_INFO "PowerMac i2c bus %s registered\n", adapter->name);
/* Use custom child registration due to Apple device-tree funkyness */
adapter->dev.of_node = dev->dev.of_node;
i2c_powermac_register_devices(adapter, bus);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.