2014-02-26 22:59:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Google, Inc
|
|
|
|
*
|
|
|
|
* (C) Copyright 2012
|
|
|
|
* Marek Vasut <marex@denx.de>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dm/device.h>
|
|
|
|
#include <dm/device-internal.h>
|
2014-06-25 19:57:45 +00:00
|
|
|
#include <dm/lists.h>
|
2014-02-26 22:59:18 +00:00
|
|
|
#include <dm/platdata.h>
|
|
|
|
#include <dm/uclass.h>
|
|
|
|
#include <dm/util.h>
|
2014-06-12 05:29:48 +00:00
|
|
|
#include <fdtdec.h>
|
2014-02-26 22:59:18 +00:00
|
|
|
#include <linux/compiler.h>
|
|
|
|
|
|
|
|
struct driver *lists_driver_lookup_name(const char *name)
|
|
|
|
{
|
|
|
|
struct driver *drv =
|
|
|
|
ll_entry_start(struct driver, driver);
|
|
|
|
const int n_ents = ll_entry_count(struct driver, driver);
|
|
|
|
struct driver *entry;
|
|
|
|
|
|
|
|
for (entry = drv; entry != drv + n_ents; entry++) {
|
2014-09-28 13:52:27 +00:00
|
|
|
if (!strcmp(name, entry->name))
|
2014-02-26 22:59:18 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not found */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct uclass_driver *lists_uclass_lookup(enum uclass_id id)
|
|
|
|
{
|
|
|
|
struct uclass_driver *uclass =
|
|
|
|
ll_entry_start(struct uclass_driver, uclass);
|
|
|
|
const int n_ents = ll_entry_count(struct uclass_driver, uclass);
|
|
|
|
struct uclass_driver *entry;
|
|
|
|
|
|
|
|
for (entry = uclass; entry != uclass + n_ents; entry++) {
|
|
|
|
if (entry->id == id)
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-23 12:55:03 +00:00
|
|
|
int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)
|
2014-02-26 22:59:18 +00:00
|
|
|
{
|
|
|
|
struct driver_info *info =
|
|
|
|
ll_entry_start(struct driver_info, driver_info);
|
|
|
|
const int n_ents = ll_entry_count(struct driver_info, driver_info);
|
|
|
|
struct driver_info *entry;
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *dev;
|
2014-02-26 22:59:18 +00:00
|
|
|
int result = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for (entry = info; entry != info + n_ents; entry++) {
|
2014-07-23 12:55:03 +00:00
|
|
|
ret = device_bind_by_name(parent, pre_reloc_only, entry, &dev);
|
|
|
|
if (ret && ret != -EPERM) {
|
2014-02-26 22:59:18 +00:00
|
|
|
dm_warn("No match for driver '%s'\n", entry->name);
|
|
|
|
if (!result || ret != -ENOENT)
|
|
|
|
result = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-11-11 17:46:21 +00:00
|
|
|
int device_bind_driver(struct udevice *parent, const char *drv_name,
|
|
|
|
const char *dev_name, struct udevice **devp)
|
2015-04-29 02:25:04 +00:00
|
|
|
{
|
|
|
|
return device_bind_driver_to_node(parent, drv_name, dev_name, -1, devp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int device_bind_driver_to_node(struct udevice *parent, const char *drv_name,
|
|
|
|
const char *dev_name, int node,
|
|
|
|
struct udevice **devp)
|
2014-11-11 17:46:21 +00:00
|
|
|
{
|
|
|
|
struct driver *drv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
drv = lists_driver_lookup_name(drv_name);
|
|
|
|
if (!drv) {
|
2015-06-23 21:38:36 +00:00
|
|
|
debug("Cannot find driver '%s'\n", drv_name);
|
2014-11-11 17:46:21 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
2015-04-29 02:25:04 +00:00
|
|
|
ret = device_bind(parent, drv, dev_name, NULL, node, devp);
|
2014-11-11 17:46:21 +00:00
|
|
|
if (ret) {
|
2015-06-23 21:38:36 +00:00
|
|
|
debug("Cannot create device named '%s' (err=%d)\n",
|
|
|
|
dev_name, ret);
|
2014-11-11 17:46:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-11 22:31:55 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2014-02-26 22:59:18 +00:00
|
|
|
/**
|
|
|
|
* driver_check_compatible() - Check if a driver is compatible with this node
|
|
|
|
*
|
|
|
|
* @param blob: Device tree pointer
|
|
|
|
* @param offset: Offset of node in device tree
|
2014-11-11 17:46:18 +00:00
|
|
|
* @param of_match: List of compatible strings to match
|
|
|
|
* @param of_idp: Returns the match that was found
|
2014-02-26 22:59:18 +00:00
|
|
|
* @return 0 if there is a match, -ENOENT if no match, -ENODEV if the node
|
|
|
|
* does not have a compatible string, other error <0 if there is a device
|
|
|
|
* tree error
|
|
|
|
*/
|
|
|
|
static int driver_check_compatible(const void *blob, int offset,
|
2014-11-11 17:46:18 +00:00
|
|
|
const struct udevice_id *of_match,
|
|
|
|
const struct udevice_id **of_idp)
|
2014-02-26 22:59:18 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2014-11-11 17:46:18 +00:00
|
|
|
*of_idp = NULL;
|
2014-02-26 22:59:18 +00:00
|
|
|
if (!of_match)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
while (of_match->compatible) {
|
|
|
|
ret = fdt_node_check_compatible(blob, offset,
|
|
|
|
of_match->compatible);
|
2014-11-11 17:46:18 +00:00
|
|
|
if (!ret) {
|
|
|
|
*of_idp = of_match;
|
2014-02-26 22:59:18 +00:00
|
|
|
return 0;
|
2014-11-11 17:46:18 +00:00
|
|
|
} else if (ret == -FDT_ERR_NOTFOUND) {
|
2014-02-26 22:59:18 +00:00
|
|
|
return -ENODEV;
|
2014-11-11 17:46:18 +00:00
|
|
|
} else if (ret < 0) {
|
2014-02-26 22:59:18 +00:00
|
|
|
return -EINVAL;
|
2014-11-11 17:46:18 +00:00
|
|
|
}
|
2014-02-26 22:59:18 +00:00
|
|
|
of_match++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2014-09-04 22:27:25 +00:00
|
|
|
int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
|
|
|
|
struct udevice **devp)
|
2014-02-26 22:59:18 +00:00
|
|
|
{
|
|
|
|
struct driver *driver = ll_entry_start(struct driver, driver);
|
|
|
|
const int n_ents = ll_entry_count(struct driver, driver);
|
2014-11-11 17:46:18 +00:00
|
|
|
const struct udevice_id *id;
|
2014-02-26 22:59:18 +00:00
|
|
|
struct driver *entry;
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *dev;
|
2014-07-23 12:55:22 +00:00
|
|
|
bool found = false;
|
2014-02-26 22:59:18 +00:00
|
|
|
const char *name;
|
|
|
|
int result = 0;
|
2014-07-23 12:55:22 +00:00
|
|
|
int ret = 0;
|
2014-02-26 22:59:18 +00:00
|
|
|
|
|
|
|
dm_dbg("bind node %s\n", fdt_get_name(blob, offset, NULL));
|
2014-09-04 22:27:25 +00:00
|
|
|
if (devp)
|
|
|
|
*devp = NULL;
|
2014-02-26 22:59:18 +00:00
|
|
|
for (entry = driver; entry != driver + n_ents; entry++) {
|
2014-11-11 17:46:18 +00:00
|
|
|
ret = driver_check_compatible(blob, offset, entry->of_match,
|
|
|
|
&id);
|
2014-07-23 12:55:22 +00:00
|
|
|
name = fdt_get_name(blob, offset, NULL);
|
2014-02-26 22:59:18 +00:00
|
|
|
if (ret == -ENOENT) {
|
|
|
|
continue;
|
|
|
|
} else if (ret == -ENODEV) {
|
2014-07-23 12:55:22 +00:00
|
|
|
dm_dbg("Device '%s' has no compatible string\n", name);
|
2014-02-26 22:59:18 +00:00
|
|
|
break;
|
|
|
|
} else if (ret) {
|
|
|
|
dm_warn("Device tree error at offset %d\n", offset);
|
2014-11-17 08:19:39 +00:00
|
|
|
result = ret;
|
2014-02-26 22:59:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_dbg(" - found match at '%s'\n", entry->name);
|
|
|
|
ret = device_bind(parent, entry, name, NULL, offset, &dev);
|
2016-04-19 22:19:29 +00:00
|
|
|
if (ret == -ENODEV) {
|
|
|
|
dm_dbg("Driver '%s' refuses to bind\n", entry->name);
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-26 22:59:18 +00:00
|
|
|
if (ret) {
|
2016-01-17 23:11:06 +00:00
|
|
|
dm_warn("Error binding driver '%s': %d\n", entry->name,
|
|
|
|
ret);
|
2014-09-04 22:27:25 +00:00
|
|
|
return ret;
|
2014-07-23 12:55:22 +00:00
|
|
|
} else {
|
2015-03-25 18:21:55 +00:00
|
|
|
dev->driver_data = id->data;
|
2014-07-23 12:55:22 +00:00
|
|
|
found = true;
|
2014-09-04 22:27:25 +00:00
|
|
|
if (devp)
|
|
|
|
*devp = dev;
|
2014-02-26 22:59:18 +00:00
|
|
|
}
|
2014-07-23 12:55:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found && !result && ret != -ENODEV) {
|
|
|
|
dm_dbg("No match for node '%s'\n",
|
|
|
|
fdt_get_name(blob, offset, NULL));
|
2014-02-26 22:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|