// SPDX-License-Identifier: GPL-2.0-only /* * CE4100 PCI-I2C glue code for PXA's driver * Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> * * The CE4100's I2C device is more or less the same one as found on PXA. * It does not support target mode, the register slightly moved. This PCI * device provides three bars, every contains a single I2C controller.
*/ #include <linux/init.h> #include <linux/pci.h> #include <linux/platform_device.h> #include <linux/platform_data/i2c-pxa.h> #include <linux/of.h> #include <linux/of_address.h>
for_each_child_of_node(dev->dev.of_node, child) { constvoid *prop; struct resource r; int ret;
ret = of_address_to_resource(child, 0, &r); if (ret < 0) continue; if (r.start != res[0].start) continue; if (r.end != res[0].end) continue; if (r.flags != res[0].flags) continue;
prop = of_get_property(child, "fast-mode", NULL); if (prop)
pdata.fast_mode = 1;
break;
}
if (!child) {
dev_err(&dev->dev, "failed to match a DT node for bar %d.\n",
bar);
ret = -EINVAL; goto out;
}
pdev = platform_device_alloc("ce4100-i2c", devnum); if (!pdev) {
of_node_put(child);
ret = -ENOMEM; goto out;
}
pdev->dev.parent = &dev->dev;
pdev->dev.of_node = child;
ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res)); if (ret) goto err;
ret = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (ret) goto err;
ret = platform_device_add(pdev); if (ret) goto err;
devnum++; return pdev;
err:
platform_device_put(pdev);
out: return ERR_PTR(ret);
}
staticint ce4100_i2c_probe(struct pci_dev *dev, conststruct pci_device_id *ent)
{ int ret; int i; struct ce4100_devices *sds;
ret = pcim_enable_device(dev); if (ret) return ret;
if (!dev->dev.of_node) {
dev_err(&dev->dev, "Missing device tree node.\n"); return -EINVAL;
}
sds = kzalloc(sizeof(*sds), GFP_KERNEL); if (!sds) return -ENOMEM;
for (i = 0; i < ARRAY_SIZE(sds->pdev); i++) {
sds->pdev[i] = add_i2c_device(dev, i); if (IS_ERR(sds->pdev[i])) {
ret = PTR_ERR(sds->pdev[i]); while (--i >= 0)
platform_device_unregister(sds->pdev[i]); goto err_dev_add;
}
}
pci_set_drvdata(dev, sds); return 0;
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.