FROMLIST: usb: Migrate to support live DT for some driver
Use ofnode_ instead of fdt_ APIs so that the drivers can support live DT. This patch updates usb_get_dr_mode() and usb_get_maximum_speed() to use ofnode as parameter instead of fdt offset. And all the drivers who use these APIs update to use live dt APIs at the same time. Change-Id: I41a3fa52e8fdb99f7fc36b1bc0eb21ae82f90e63 Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Frank Wang <frank.wang@rock-chips.com> (am from http://patchwork.ozlabs.org/patch/1248682/)
This commit is contained in:
parent
d4f9534982
commit
ef78966da5
|
|
@ -106,7 +106,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
|
||||||
enum usb_dr_mode dr_mode;
|
enum usb_dr_mode dr_mode;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
dr_mode = usb_get_dr_mode(dev_of_offset(dev));
|
dr_mode = usb_get_dr_mode(dev->node);
|
||||||
cdns->role = USB_ROLE_NONE;
|
cdns->role = USB_ROLE_NONE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -382,22 +382,20 @@ static const struct udevice_id cdns3_ids[] = {
|
||||||
|
|
||||||
int cdns3_bind(struct udevice *parent)
|
int cdns3_bind(struct udevice *parent)
|
||||||
{
|
{
|
||||||
int from = dev_of_offset(parent);
|
|
||||||
const void *fdt = gd->fdt_blob;
|
|
||||||
enum usb_dr_mode dr_mode;
|
enum usb_dr_mode dr_mode;
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
const char *driver;
|
const char *driver;
|
||||||
const char *name;
|
const char *name;
|
||||||
int node;
|
ofnode node;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
node = fdt_node_offset_by_compatible(fdt, from, "cdns,usb3");
|
node = ofnode_by_compatible(parent->node, "cdns,usb3");
|
||||||
if (node < 0) {
|
if (!ofnode_valid(node)) {
|
||||||
ret = -ENODEV;
|
ret = -ENODEV;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = fdt_get_name(fdt, node, NULL);
|
name = ofnode_get_name(node);
|
||||||
dr_mode = usb_get_dr_mode(node);
|
dr_mode = usb_get_dr_mode(node);
|
||||||
|
|
||||||
switch (dr_mode) {
|
switch (dr_mode) {
|
||||||
|
|
@ -420,8 +418,7 @@ int cdns3_bind(struct udevice *parent)
|
||||||
goto fail;
|
goto fail;
|
||||||
};
|
};
|
||||||
|
|
||||||
ret = device_bind_driver_to_node(parent, driver, name,
|
ret = device_bind_driver_to_node(parent, driver, name, node, &dev);
|
||||||
offset_to_ofnode(node), &dev);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("%s: not able to bind usb device mode\n",
|
printf("%s: not able to bind usb device mode\n",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
|
||||||
|
|
@ -2576,7 +2576,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns)
|
||||||
if (!priv_dev->onchip_buffers)
|
if (!priv_dev->onchip_buffers)
|
||||||
priv_dev->onchip_buffers = 256;
|
priv_dev->onchip_buffers = 256;
|
||||||
|
|
||||||
max_speed = usb_get_maximum_speed(dev_of_offset(cdns->dev));
|
max_speed = usb_get_maximum_speed(dev_ofnode(cdns->dev));
|
||||||
|
|
||||||
/* Check the maximum_speed parameter */
|
/* Check the maximum_speed parameter */
|
||||||
switch (max_speed) {
|
switch (max_speed) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <linux/libfdt.h>
|
#include <dm.h>
|
||||||
#include <linux/usb/otg.h>
|
#include <linux/usb/otg.h>
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
#include <linux/usb/phy.h>
|
#include <linux/usb/phy.h>
|
||||||
|
|
@ -22,13 +22,12 @@ static const char *const usb_dr_modes[] = {
|
||||||
[USB_DR_MODE_OTG] = "otg",
|
[USB_DR_MODE_OTG] = "otg",
|
||||||
};
|
};
|
||||||
|
|
||||||
enum usb_dr_mode usb_get_dr_mode(int node)
|
enum usb_dr_mode usb_get_dr_mode(ofnode node)
|
||||||
{
|
{
|
||||||
const void *fdt = gd->fdt_blob;
|
|
||||||
const char *dr_mode;
|
const char *dr_mode;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL);
|
dr_mode = ofnode_read_string(node, "dr_mode");
|
||||||
if (!dr_mode) {
|
if (!dr_mode) {
|
||||||
pr_err("usb dr_mode not found\n");
|
pr_err("usb dr_mode not found\n");
|
||||||
return USB_DR_MODE_UNKNOWN;
|
return USB_DR_MODE_UNKNOWN;
|
||||||
|
|
@ -50,13 +49,12 @@ static const char *const speed_names[] = {
|
||||||
[USB_SPEED_SUPER] = "super-speed",
|
[USB_SPEED_SUPER] = "super-speed",
|
||||||
};
|
};
|
||||||
|
|
||||||
enum usb_device_speed usb_get_maximum_speed(int node)
|
enum usb_device_speed usb_get_maximum_speed(ofnode node)
|
||||||
{
|
{
|
||||||
const void *fdt = gd->fdt_blob;
|
|
||||||
const char *max_speed;
|
const char *max_speed;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
max_speed = fdt_getprop(fdt, node, "maximum-speed", NULL);
|
max_speed = ofnode_read_string(node, "maximum-speed");
|
||||||
if (!max_speed) {
|
if (!max_speed) {
|
||||||
pr_err("usb maximum-speed not found\n");
|
pr_err("usb maximum-speed not found\n");
|
||||||
return USB_SPEED_UNKNOWN;
|
return USB_SPEED_UNKNOWN;
|
||||||
|
|
|
||||||
|
|
@ -87,9 +87,9 @@ static int dwc3_generic_remove(struct udevice *dev,
|
||||||
static int dwc3_generic_ofdata_to_platdata(struct udevice *dev)
|
static int dwc3_generic_ofdata_to_platdata(struct udevice *dev)
|
||||||
{
|
{
|
||||||
struct dwc3_generic_plat *plat = dev_get_platdata(dev);
|
struct dwc3_generic_plat *plat = dev_get_platdata(dev);
|
||||||
int node = dev_of_offset(dev);
|
ofnode node = dev->node;
|
||||||
|
|
||||||
plat->base = devfdt_get_addr(dev);
|
plat->base = dev_read_addr(dev);
|
||||||
|
|
||||||
plat->maximum_speed = usb_get_maximum_speed(node);
|
plat->maximum_speed = usb_get_maximum_speed(node);
|
||||||
if (plat->maximum_speed == USB_SPEED_UNKNOWN) {
|
if (plat->maximum_speed == USB_SPEED_UNKNOWN) {
|
||||||
|
|
@ -283,13 +283,11 @@ struct dwc3_glue_ops ti_ops = {
|
||||||
|
|
||||||
static int dwc3_glue_bind(struct udevice *parent)
|
static int dwc3_glue_bind(struct udevice *parent)
|
||||||
{
|
{
|
||||||
const void *fdt = gd->fdt_blob;
|
ofnode node;
|
||||||
int node;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
|
ofnode_for_each_subnode(node, parent->node) {
|
||||||
node = fdt_next_subnode(fdt, node)) {
|
const char *name = ofnode_get_name(node);
|
||||||
const char *name = fdt_get_name(fdt, node, NULL);
|
|
||||||
enum usb_dr_mode dr_mode;
|
enum usb_dr_mode dr_mode;
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
const char *driver = NULL;
|
const char *driver = NULL;
|
||||||
|
|
@ -321,7 +319,7 @@ static int dwc3_glue_bind(struct udevice *parent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ret = device_bind_driver_to_node(parent, driver, name,
|
ret = device_bind_driver_to_node(parent, driver, name,
|
||||||
offset_to_ofnode(node), &dev);
|
node, &dev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
debug("%s: not able to bind usb device mode\n",
|
debug("%s: not able to bind usb device mode\n",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
@ -399,7 +397,7 @@ static int dwc3_glue_probe(struct udevice *dev)
|
||||||
while (child) {
|
while (child) {
|
||||||
enum usb_dr_mode dr_mode;
|
enum usb_dr_mode dr_mode;
|
||||||
|
|
||||||
dr_mode = usb_get_dr_mode(dev_of_offset(child));
|
dr_mode = usb_get_dr_mode(child->node);
|
||||||
device_find_next_child(&child);
|
device_find_next_child(&child);
|
||||||
if (ops && ops->select_dr_mode)
|
if (ops && ops->select_dr_mode)
|
||||||
ops->select_dr_mode(dev, index, dr_mode);
|
ops->select_dr_mode(dev, index, dr_mode);
|
||||||
|
|
|
||||||
|
|
@ -393,7 +393,7 @@ static int dwc3_meson_g12a_probe(struct udevice *dev)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
priv->otg_mode = usb_get_dr_mode(dev_of_offset(dev));
|
priv->otg_mode = usb_get_dr_mode(dev->node);
|
||||||
|
|
||||||
ret = dwc3_meson_g12a_usb_init(priv);
|
ret = dwc3_meson_g12a_usb_init(priv);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|
|
||||||
|
|
@ -1038,13 +1038,12 @@ void dwc2_phy_shutdown(struct udevice *dev, struct phy *usb_phys, int num_phys)
|
||||||
static int dwc2_udc_otg_ofdata_to_platdata(struct udevice *dev)
|
static int dwc2_udc_otg_ofdata_to_platdata(struct udevice *dev)
|
||||||
{
|
{
|
||||||
struct dwc2_plat_otg_data *platdata = dev_get_platdata(dev);
|
struct dwc2_plat_otg_data *platdata = dev_get_platdata(dev);
|
||||||
int node = dev_of_offset(dev);
|
|
||||||
ulong drvdata;
|
ulong drvdata;
|
||||||
void (*set_params)(struct dwc2_plat_otg_data *data);
|
void (*set_params)(struct dwc2_plat_otg_data *data);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (usb_get_dr_mode(node) != USB_DR_MODE_PERIPHERAL &&
|
if (usb_get_dr_mode(dev->node) != USB_DR_MODE_PERIPHERAL &&
|
||||||
usb_get_dr_mode(node) != USB_DR_MODE_OTG) {
|
usb_get_dr_mode(dev->node) != USB_DR_MODE_OTG) {
|
||||||
dev_dbg(dev, "Invalid mode\n");
|
dev_dbg(dev, "Invalid mode\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <dm.h>
|
#include <dm.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fdtdec.h>
|
|
||||||
#include <linux/libfdt.h>
|
|
||||||
#include <dm/lists.h>
|
#include <dm/lists.h>
|
||||||
#include <regmap.h>
|
#include <regmap.h>
|
||||||
#include <reset-uclass.h>
|
#include <reset-uclass.h>
|
||||||
|
|
@ -110,8 +108,7 @@ static int sti_dwc3_glue_ofdata_to_platdata(struct udevice *dev)
|
||||||
int ret;
|
int ret;
|
||||||
u32 reg[4];
|
u32 reg[4];
|
||||||
|
|
||||||
ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
|
ret = ofnode_read_u32_array(dev->node, "reg", reg, ARRAY_SIZE(reg));
|
||||||
"reg", reg, ARRAY_SIZE(reg));
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("unable to find st,stih407-dwc3 reg property(%d)\n", ret);
|
pr_err("unable to find st,stih407-dwc3 reg property(%d)\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -154,18 +151,15 @@ static int sti_dwc3_glue_ofdata_to_platdata(struct udevice *dev)
|
||||||
static int sti_dwc3_glue_bind(struct udevice *dev)
|
static int sti_dwc3_glue_bind(struct udevice *dev)
|
||||||
{
|
{
|
||||||
struct sti_dwc3_glue_platdata *plat = dev_get_platdata(dev);
|
struct sti_dwc3_glue_platdata *plat = dev_get_platdata(dev);
|
||||||
int dwc3_node;
|
ofnode node, dwc3_node;
|
||||||
|
|
||||||
/* check if one subnode is present */
|
/* Find snps,dwc3 node from subnode */
|
||||||
dwc3_node = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
|
ofnode_for_each_subnode(node, dev->node) {
|
||||||
if (dwc3_node <= 0) {
|
if (ofnode_device_is_compatible(node, "snps,dwc3"))
|
||||||
pr_err("Can't find subnode for %s\n", dev->name);
|
dwc3_node = node;
|
||||||
return -ENODEV;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if the subnode compatible string is the dwc3 one*/
|
if (!ofnode_valid(node)) {
|
||||||
if (fdt_node_check_compatible(gd->fdt_blob, dwc3_node,
|
|
||||||
"snps,dwc3") != 0) {
|
|
||||||
pr_err("Can't find dwc3 subnode for %s\n", dev->name);
|
pr_err("Can't find dwc3 subnode for %s\n", dev->name);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -514,7 +514,7 @@ static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
|
||||||
struct usb_platdata *plat = dev_get_platdata(dev);
|
struct usb_platdata *plat = dev_get_platdata(dev);
|
||||||
enum usb_dr_mode dr_mode;
|
enum usb_dr_mode dr_mode;
|
||||||
|
|
||||||
dr_mode = usb_get_dr_mode(dev_of_offset(dev));
|
dr_mode = usb_get_dr_mode(dev->node);
|
||||||
|
|
||||||
switch (dr_mode) {
|
switch (dr_mode) {
|
||||||
case USB_DR_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <dm.h>
|
#include <dm.h>
|
||||||
#include <fdtdec.h>
|
|
||||||
#include <generic-phy.h>
|
#include <generic-phy.h>
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#include <dwc3-uboot.h>
|
#include <dwc3-uboot.h>
|
||||||
|
|
@ -158,7 +157,7 @@ static int xhci_dwc3_probe(struct udevice *dev)
|
||||||
|
|
||||||
writel(reg, &dwc3_reg->g_usb2phycfg[0]);
|
writel(reg, &dwc3_reg->g_usb2phycfg[0]);
|
||||||
|
|
||||||
dr_mode = usb_get_dr_mode(dev_of_offset(dev));
|
dr_mode = usb_get_dr_mode(dev->node);
|
||||||
if (dr_mode == USB_DR_MODE_UNKNOWN)
|
if (dr_mode == USB_DR_MODE_UNKNOWN)
|
||||||
/* by default set dual role mode to HOST */
|
/* by default set dual role mode to HOST */
|
||||||
dr_mode = USB_DR_MODE_HOST;
|
dr_mode = USB_DR_MODE_HOST;
|
||||||
|
|
|
||||||
|
|
@ -205,14 +205,12 @@ U_BOOT_DRIVER(ti_musb_host) = {
|
||||||
|
|
||||||
static int ti_musb_wrapper_bind(struct udevice *parent)
|
static int ti_musb_wrapper_bind(struct udevice *parent)
|
||||||
{
|
{
|
||||||
const void *fdt = gd->fdt_blob;
|
ofnode node;
|
||||||
int node;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
|
ofnode_for_each_subnode(node, parent->node) {
|
||||||
node = fdt_next_subnode(fdt, node)) {
|
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
const char *name = fdt_get_name(fdt, node, NULL);
|
const char *name = ofnode_get_name(node);
|
||||||
enum usb_dr_mode dr_mode;
|
enum usb_dr_mode dr_mode;
|
||||||
struct driver *drv;
|
struct driver *drv;
|
||||||
|
|
||||||
|
|
@ -226,8 +224,11 @@ static int ti_musb_wrapper_bind(struct udevice *parent)
|
||||||
break;
|
break;
|
||||||
case USB_DR_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
/* Bind MUSB host */
|
/* Bind MUSB host */
|
||||||
ret = device_bind_driver_to_node(parent, "ti-musb-host",
|
ret = device_bind_driver_to_node(parent,
|
||||||
name, offset_to_ofnode(node), &dev);
|
"ti-musb-host",
|
||||||
|
name,
|
||||||
|
node,
|
||||||
|
&dev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("musb - not able to bind usb host node\n");
|
pr_err("musb - not able to bind usb host node\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@
|
||||||
#ifndef __LINUX_USB_OTG_H
|
#ifndef __LINUX_USB_OTG_H
|
||||||
#define __LINUX_USB_OTG_H
|
#define __LINUX_USB_OTG_H
|
||||||
|
|
||||||
|
#include <dm/ofnode.h>
|
||||||
|
|
||||||
enum usb_dr_mode {
|
enum usb_dr_mode {
|
||||||
USB_DR_MODE_UNKNOWN,
|
USB_DR_MODE_UNKNOWN,
|
||||||
USB_DR_MODE_HOST,
|
USB_DR_MODE_HOST,
|
||||||
|
|
@ -19,20 +21,20 @@ enum usb_dr_mode {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* usb_get_dr_mode() - Get dual role mode for given device
|
* usb_get_dr_mode() - Get dual role mode for given device
|
||||||
* @node: Node offset to the given device
|
* @node: ofnode of the given device
|
||||||
*
|
*
|
||||||
* The function gets phy interface string from property 'dr_mode',
|
* The function gets phy interface string from property 'dr_mode',
|
||||||
* and returns the correspondig enum usb_dr_mode
|
* and returns the correspondig enum usb_dr_mode
|
||||||
*/
|
*/
|
||||||
enum usb_dr_mode usb_get_dr_mode(int node);
|
enum usb_dr_mode usb_get_dr_mode(ofnode node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* usb_get_maximum_speed() - Get maximum speed for given device
|
* usb_get_maximum_speed() - Get maximum speed for given device
|
||||||
* @node: Node offset to the given device
|
* @node: ofnode of the given device
|
||||||
*
|
*
|
||||||
* The function gets phy interface string from property 'maximum-speed',
|
* The function gets phy interface string from property 'maximum-speed',
|
||||||
* and returns the correspondig enum usb_device_speed
|
* and returns the correspondig enum usb_device_speed
|
||||||
*/
|
*/
|
||||||
enum usb_device_speed usb_get_maximum_speed(int node);
|
enum usb_device_speed usb_get_maximum_speed(ofnode node);
|
||||||
|
|
||||||
#endif /* __LINUX_USB_OTG_H */
|
#endif /* __LINUX_USB_OTG_H */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue