* [U-Boot] [PATCH 1/6] drivers: of: add support for get device address based on index
2015-09-02 11:15 [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Mugunthan V N
@ 2015-09-02 11:15 ` Mugunthan V N
2015-09-04 0:58 ` Simon Glass
2015-09-02 11:15 ` [U-Boot] [PATCH 2/6] am335x_evm: prepare for eth driver model support Mugunthan V N
` (5 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Mugunthan V N @ 2015-09-02 11:15 UTC (permalink / raw)
To: u-boot
When a device has multiple memory regions, api "dev_get_addr"
doesn't return the address and returns error. So implementing a
new api to get device address based on index.
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
---
drivers/core/device.c | 18 ++++++++++++++++++
include/dm/device.h | 10 ++++++++++
include/fdtdec.h | 14 ++++++++++++++
lib/fdtdec.c | 35 +++++++++++++++++++++++++++++++++++
4 files changed, 77 insertions(+)
diff --git a/drivers/core/device.c b/drivers/core/device.c
index a6cd936..398aad0 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -591,6 +591,24 @@ fdt_addr_t dev_get_addr(struct udevice *dev)
#endif
}
+fdt_addr_t dev_get_addr_index(struct udevice *dev, int index)
+{
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+ fdt_addr_t addr;
+
+ addr = fdtdec_get_addr_size_index(gd->fdt_blob, dev->of_offset,
+ "reg", NULL, index);
+ if (addr != FDT_ADDR_T_NONE) {
+ if (device_get_uclass_id(dev->parent) == UCLASS_SIMPLE_BUS)
+ addr = simple_bus_translate(dev->parent, addr);
+ }
+
+ return addr;
+#else
+ return FDT_ADDR_T_NONE;
+#endif
+}
+
bool device_has_children(struct udevice *dev)
{
return !list_empty(&dev->child_head);
diff --git a/include/dm/device.h b/include/dm/device.h
index a239be6..dea04f8 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -441,6 +441,16 @@ int device_find_next_child(struct udevice **devp);
fdt_addr_t dev_get_addr(struct udevice *dev);
/**
+ * dev_get_addr_index() - Get the index reg property of a device
+ *
+ * @dev: Pointer to a device
+ * @index: reg address index
+ *
+ * @return addr
+ */
+fdt_addr_t dev_get_addr_index(struct udevice *dev, int index);
+
+/**
* device_has_children() - check if a device has any children
*
* @dev: Device to check
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 3e23731..b9e4ac6 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -321,6 +321,20 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
const char *prop_name, fdt_size_t *sizep);
/**
+ * Look up an address property in a node and return it as an address.
+ * The property must hold one address with a length. This is only tested
+ * on 32-bit machines.
+ *
+ * @param blob FDT blob
+ * @param node node to examine
+ * @param prop_name name of property to find
+ * @param index index of the address
+ * @return address, if found, or FDT_ADDR_T_NONE if not
+ */
+fdt_addr_t fdtdec_get_addr_size_index(const void *blob, int node,
+ const char *prop_name, fdt_size_t *sizep, int index);
+
+/**
* Look at an address property in a node and return the pci address which
* corresponds to the given type in the form of fdt_pci_addr.
* The property must hold one fdt_pci_addr with a lengh.
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 29c5ccb..3afcf07 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -119,6 +119,41 @@ fdt_addr_t fdtdec_get_addr(const void *blob, int node,
return fdtdec_get_addr_size(blob, node, prop_name, NULL);
}
+fdt_addr_t fdtdec_get_addr_size_index(const void *blob, int node,
+ const char *prop_name, fdt_size_t *sizep, int index)
+{
+ const fdt_addr_t *cell;
+ int len;
+
+ debug("%s: %s: ", __func__, prop_name);
+ cell = fdt_getprop(blob, node, prop_name, &len);
+ if (len < sizeof(fdt_addr_t) * 2 * (index + 1)) {
+ debug("(not found)\n");
+ return FDT_ADDR_T_NONE;
+ }
+
+ len -= sizeof(fdt_addr_t) * 2 * index;
+ cell += index * 2;
+ if (cell && ((!sizep && len >= sizeof(fdt_addr_t)) ||
+ len >= sizeof(fdt_addr_t) * 2)) {
+ fdt_addr_t addr = fdt_addr_to_cpu(*cell);
+ if (sizep) {
+ const fdt_size_t *size;
+
+ size = (fdt_size_t *)((char *)cell +
+ sizeof(fdt_addr_t));
+ *sizep = fdt_size_to_cpu(*size);
+ debug("addr=%08lx, size=%llx\n",
+ (ulong)addr, (u64)*sizep);
+ } else {
+ debug("%08lx\n", (ulong)addr);
+ }
+ return addr;
+ }
+ debug("(not found)\n");
+ return FDT_ADDR_T_NONE;
+}
+
#ifdef CONFIG_PCI
int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
const char *prop_name, struct fdt_pci_addr *addr)
--
2.5.1.522.g7aa67f6
^ permalink raw reply related [flat|nested] 17+ messages in thread* [U-Boot] [PATCH 1/6] drivers: of: add support for get device address based on index
2015-09-02 11:15 ` [U-Boot] [PATCH 1/6] drivers: of: add support for get device address based on index Mugunthan V N
@ 2015-09-04 0:58 ` Simon Glass
2015-09-06 10:39 ` Mugunthan V N
0 siblings, 1 reply; 17+ messages in thread
From: Simon Glass @ 2015-09-04 0:58 UTC (permalink / raw)
To: u-boot
Hi,
On 2 September 2015 at 05:15, Mugunthan V N <mugunthanvnm@ti.com> wrote:
> When a device has multiple memory regions, api "dev_get_addr"
> doesn't return the address and returns error. So implementing a
> new api to get device address based on index.
>
> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
> ---
> drivers/core/device.c | 18 ++++++++++++++++++
> include/dm/device.h | 10 ++++++++++
> include/fdtdec.h | 14 ++++++++++++++
> lib/fdtdec.c | 35 +++++++++++++++++++++++++++++++++++
> 4 files changed, 77 insertions(+)
I'd like to figure out Stephen Warren's patch before we look too hard
at this one.
http://patchwork.ozlabs.org/patch/504918/
Regards,
Simon
^ permalink raw reply [flat|nested] 17+ messages in thread
* [U-Boot] [PATCH 1/6] drivers: of: add support for get device address based on index
2015-09-04 0:58 ` Simon Glass
@ 2015-09-06 10:39 ` Mugunthan V N
0 siblings, 0 replies; 17+ messages in thread
From: Mugunthan V N @ 2015-09-06 10:39 UTC (permalink / raw)
To: u-boot
On Friday 04 September 2015 06:28 AM, Simon Glass wrote:
> Hi,
>
> On 2 September 2015 at 05:15, Mugunthan V N <mugunthanvnm@ti.com> wrote:
>> When a device has multiple memory regions, api "dev_get_addr"
>> doesn't return the address and returns error. So implementing a
>> new api to get device address based on index.
>>
>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>> ---
>> drivers/core/device.c | 18 ++++++++++++++++++
>> include/dm/device.h | 10 ++++++++++
>> include/fdtdec.h | 14 ++++++++++++++
>> lib/fdtdec.c | 35 +++++++++++++++++++++++++++++++++++
>> 4 files changed, 77 insertions(+)
>
> I'd like to figure out Stephen Warren's patch before we look too hard
> at this one.
>
> http://patchwork.ozlabs.org/patch/504918/
>
The patch looks reasonable. Will test it tomorrow and repost the series
again.
Regards
Mugunthan V N
^ permalink raw reply [flat|nested] 17+ messages in thread
* [U-Boot] [PATCH 2/6] am335x_evm: prepare for eth driver model support
2015-09-02 11:15 [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Mugunthan V N
2015-09-02 11:15 ` [U-Boot] [PATCH 1/6] drivers: of: add support for get device address based on index Mugunthan V N
@ 2015-09-02 11:15 ` Mugunthan V N
2015-09-02 13:15 ` Tom Rini
2015-09-04 15:38 ` Joe Hershberger
2015-09-02 11:15 ` [U-Boot] [PATCH 3/6] am335x_evm: do not define usb ether gadget when Eth DM is defined Mugunthan V N
` (4 subsequent siblings)
6 siblings, 2 replies; 17+ messages in thread
From: Mugunthan V N @ 2015-09-02 11:15 UTC (permalink / raw)
To: u-boot
Prepare board file so that ethernet registration are
commented for DM conversion
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
---
board/ti/am335x/board.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
index 1dc2ed0..f0cb1e2 100644
--- a/board/ti/am335x/board.c
+++ b/board/ti/am335x/board.c
@@ -38,7 +38,10 @@ DECLARE_GLOBAL_DATA_PTR;
/* GPIO that controls power to DDR on EVM-SK */
#define GPIO_DDR_VTT_EN 7
+#if defined(CONFIG_SPL_BUILD) || \
+ (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
+#endif
/*
* Read header information from EEPROM into global structure.
@@ -513,6 +516,8 @@ int board_late_init(void)
}
#endif
+#ifndef CONFIG_DM_ETH
+
#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
(defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
static void cpsw_control(int enabled)
@@ -670,3 +675,5 @@ int board_eth_init(bd_t *bis)
return n;
}
#endif
+
+#endif /* CONFIG_DM_ETH */
--
2.5.1.522.g7aa67f6
^ permalink raw reply related [flat|nested] 17+ messages in thread* [U-Boot] [PATCH 3/6] am335x_evm: do not define usb ether gadget when Eth DM is defined
2015-09-02 11:15 [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Mugunthan V N
2015-09-02 11:15 ` [U-Boot] [PATCH 1/6] drivers: of: add support for get device address based on index Mugunthan V N
2015-09-02 11:15 ` [U-Boot] [PATCH 2/6] am335x_evm: prepare for eth driver model support Mugunthan V N
@ 2015-09-02 11:15 ` Mugunthan V N
2015-09-02 13:15 ` Tom Rini
2015-09-02 11:15 ` [U-Boot] [PATCH 4/6] drivers: net: cpsw: prepare driver for device model migration Mugunthan V N
` (3 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Mugunthan V N @ 2015-09-02 11:15 UTC (permalink / raw)
To: u-boot
Since usb ether gadget doesn't have support for driver model, so
not defining usb ether gadget when ethernet driver model is
defined.
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
---
include/configs/am335x_evm.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
index e89c49e..56de3d4 100644
--- a/include/configs/am335x_evm.h
+++ b/include/configs/am335x_evm.h
@@ -315,9 +315,12 @@
#endif
#ifdef CONFIG_USB_MUSB_GADGET
+/* Removing USB gadget and can be enabled adter adding support usb DM */
+#ifndef CONFIG_DM_ETH
#define CONFIG_USB_ETHER
#define CONFIG_USB_ETH_RNDIS
#define CONFIG_USBNET_HOST_ADDR "de:ad:be:af:00:00"
+#endif /* CONFIG_DM_ETH */
/* USB TI's IDs */
#define CONFIG_G_DNL_VENDOR_NUM 0x0451
--
2.5.1.522.g7aa67f6
^ permalink raw reply related [flat|nested] 17+ messages in thread* [U-Boot] [PATCH 4/6] drivers: net: cpsw: prepare driver for device model migration
2015-09-02 11:15 [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Mugunthan V N
` (2 preceding siblings ...)
2015-09-02 11:15 ` [U-Boot] [PATCH 3/6] am335x_evm: do not define usb ether gadget when Eth DM is defined Mugunthan V N
@ 2015-09-02 11:15 ` Mugunthan V N
2015-09-04 0:58 ` Simon Glass
2015-09-02 11:15 ` [U-Boot] [PATCH 5/6] drivers: net: cpsw: convert driver to adopt device driver model Mugunthan V N
` (2 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Mugunthan V N @ 2015-09-02 11:15 UTC (permalink / raw)
To: u-boot
prepare driver for device model migration
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
---
drivers/net/cpsw.c | 133 +++++++++++++++++++++++++++++++++++------------------
1 file changed, 89 insertions(+), 44 deletions(-)
diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c
index fb4d621..a114d4d 100644
--- a/drivers/net/cpsw.c
+++ b/drivers/net/cpsw.c
@@ -745,9 +745,8 @@ static int cpdma_process(struct cpsw_priv *priv, struct cpdma_chan *chan,
return 0;
}
-static int cpsw_init(struct eth_device *dev, bd_t *bis)
+static int _cpsw_init(struct cpsw_priv *priv, u8 *enetaddr)
{
- struct cpsw_priv *priv = dev->priv;
struct cpsw_slave *slave;
int i, ret;
@@ -772,8 +771,7 @@ static int cpsw_init(struct eth_device *dev, bd_t *bis)
cpsw_ale_port_state(priv, priv->host_port, ALE_PORT_STATE_FORWARD);
- cpsw_ale_add_ucast(priv, priv->dev->enetaddr, priv->host_port,
- ALE_SECURE);
+ cpsw_ale_add_ucast(priv, enetaddr, priv->host_port, ALE_SECURE);
cpsw_ale_add_mcast(priv, net_bcast_ethaddr, 1 << priv->host_port);
for_active_slave(slave, priv)
@@ -857,10 +855,8 @@ static int cpsw_init(struct eth_device *dev, bd_t *bis)
return 0;
}
-static void cpsw_halt(struct eth_device *dev)
+static void _cpsw_halt(struct cpsw_priv *priv)
{
- struct cpsw_priv *priv = dev->priv;
-
writel(0, priv->dma_regs + CPDMA_TXCONTROL);
writel(0, priv->dma_regs + CPDMA_RXCONTROL);
@@ -870,12 +866,10 @@ static void cpsw_halt(struct eth_device *dev)
/* clear dma state */
setbit_and_wait_for_clear32(priv->dma_regs + CPDMA_SOFTRESET);
- priv->data.control(0);
}
-static int cpsw_send(struct eth_device *dev, void *packet, int length)
+static int _cpsw_send(struct cpsw_priv *priv, void *packet, int length)
{
- struct cpsw_priv *priv = dev->priv;
void *buffer;
int len;
int timeout = CPDMA_TIMEOUT;
@@ -896,20 +890,21 @@ static int cpsw_send(struct eth_device *dev, void *packet, int length)
return cpdma_submit(priv, &priv->tx_chan, packet, length);
}
-static int cpsw_recv(struct eth_device *dev)
+static int _cpsw_recv(struct cpsw_priv *priv, uchar **pkt)
{
- struct cpsw_priv *priv = dev->priv;
void *buffer;
int len;
+ int ret = -EAGAIN;
- while (cpdma_process(priv, &priv->rx_chan, &buffer, &len) >= 0) {
- invalidate_dcache_range((unsigned long)buffer,
- (unsigned long)buffer + PKTSIZE_ALIGN);
- net_process_received_packet(buffer, len);
- cpdma_submit(priv, &priv->rx_chan, buffer, PKTSIZE);
- }
+ ret = cpdma_process(priv, &priv->rx_chan, &buffer, &len);
+ if (ret < 0)
+ return ret;
- return 0;
+ invalidate_dcache_range((unsigned long)buffer,
+ (unsigned long)buffer + PKTSIZE_ALIGN);
+ *pkt = buffer;
+
+ return len;
}
static void cpsw_slave_setup(struct cpsw_slave *slave, int slave_num,
@@ -923,15 +918,14 @@ static void cpsw_slave_setup(struct cpsw_slave *slave, int slave_num,
slave->sliver = regs + data->sliver_reg_ofs;
}
-static int cpsw_phy_init(struct eth_device *dev, struct cpsw_slave *slave)
+static int cpsw_phy_init(struct cpsw_priv *priv, struct cpsw_slave *slave)
{
- struct cpsw_priv *priv = (struct cpsw_priv *)dev->priv;
struct phy_device *phydev;
u32 supported = PHY_GBIT_FEATURES;
phydev = phy_connect(priv->bus,
slave->data->phy_addr,
- dev,
+ priv->dev,
slave->data->phy_if);
if (!phydev)
@@ -946,30 +940,14 @@ static int cpsw_phy_init(struct eth_device *dev, struct cpsw_slave *slave)
return 1;
}
-int cpsw_register(struct cpsw_platform_data *data)
+int _cpsw_register(struct cpsw_priv *priv)
{
- struct cpsw_priv *priv;
struct cpsw_slave *slave;
+ struct cpsw_platform_data *data = &priv->data;
void *regs = (void *)data->cpsw_base;
- struct eth_device *dev;
-
- dev = calloc(sizeof(*dev), 1);
- if (!dev)
- return -ENOMEM;
-
- priv = calloc(sizeof(*priv), 1);
- if (!priv) {
- free(dev);
- return -ENOMEM;
- }
-
- priv->data = *data;
- priv->dev = dev;
priv->slaves = malloc(sizeof(struct cpsw_slave) * data->slaves);
if (!priv->slaves) {
- free(dev);
- free(priv);
return -ENOMEM;
}
@@ -987,6 +965,70 @@ int cpsw_register(struct cpsw_platform_data *data)
idx = idx + 1;
}
+ cpsw_mdio_init(priv->dev->name, data->mdio_base, data->mdio_div);
+ priv->bus = miiphy_get_dev_by_name(priv->dev->name);
+ for_active_slave(slave, priv)
+ cpsw_phy_init(priv, slave);
+
+ return 0;
+}
+
+static int cpsw_init(struct eth_device *dev, bd_t *bis)
+{
+ struct cpsw_priv *priv = dev->priv;
+
+ return _cpsw_init(priv, dev->enetaddr);
+}
+
+static void cpsw_halt(struct eth_device *dev)
+{
+ struct cpsw_priv *priv = dev->priv;
+
+ return _cpsw_halt(priv);
+}
+
+static int cpsw_send(struct eth_device *dev, void *packet, int length)
+{
+ struct cpsw_priv *priv = dev->priv;
+
+ return _cpsw_send(priv, packet, length);
+}
+
+static int cpsw_recv(struct eth_device *dev)
+{
+ struct cpsw_priv *priv = dev->priv;
+ uchar *pkt = NULL;
+ int len;
+
+ len = _cpsw_recv(priv, &pkt);
+
+ if (len > 0) {
+ net_process_received_packet(pkt, len);
+ cpdma_submit(priv, &priv->rx_chan, pkt, PKTSIZE);
+ }
+
+ return len;
+}
+
+int cpsw_register(struct cpsw_platform_data *data)
+{
+ struct cpsw_priv *priv;
+ struct eth_device *dev;
+ int ret;
+
+ dev = calloc(sizeof(*dev), 1);
+ if (!dev)
+ return -ENOMEM;
+
+ priv = calloc(sizeof(*priv), 1);
+ if (!priv) {
+ free(dev);
+ return -ENOMEM;
+ }
+
+ priv->dev = dev;
+ priv->data = *data;
+
strcpy(dev->name, "cpsw");
dev->iobase = 0;
dev->init = cpsw_init;
@@ -997,10 +1039,13 @@ int cpsw_register(struct cpsw_platform_data *data)
eth_register(dev);
- cpsw_mdio_init(dev->name, data->mdio_base, data->mdio_div);
- priv->bus = miiphy_get_dev_by_name(dev->name);
- for_active_slave(slave, priv)
- cpsw_phy_init(dev, slave);
+ ret = _cpsw_register(priv);
+ if (ret < 0) {
+ eth_unregister(dev);
+ free(dev);
+ free(priv);
+ return ret;
+ }
return 1;
}
--
2.5.1.522.g7aa67f6
^ permalink raw reply related [flat|nested] 17+ messages in thread* [U-Boot] [PATCH 5/6] drivers: net: cpsw: convert driver to adopt device driver model
2015-09-02 11:15 [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Mugunthan V N
` (3 preceding siblings ...)
2015-09-02 11:15 ` [U-Boot] [PATCH 4/6] drivers: net: cpsw: prepare driver for device model migration Mugunthan V N
@ 2015-09-02 11:15 ` Mugunthan V N
2015-09-04 0:58 ` Simon Glass
2015-09-02 11:15 ` [U-Boot] [PATCH 6/6] defconfig: am335x: bbb: enable ethernet " Mugunthan V N
2015-09-02 13:15 ` [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Tom Rini
6 siblings, 1 reply; 17+ messages in thread
From: Mugunthan V N @ 2015-09-02 11:15 UTC (permalink / raw)
To: u-boot
adopt cpsw driver to device driver model
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
---
drivers/net/cpsw.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
include/cpsw.h | 2 +
2 files changed, 247 insertions(+), 1 deletion(-)
diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c
index a114d4d..f982eb5 100644
--- a/drivers/net/cpsw.c
+++ b/drivers/net/cpsw.c
@@ -25,6 +25,9 @@
#include <asm/io.h>
#include <phy.h>
#include <asm/arch/cpu.h>
+#include <dm.h>
+
+DECLARE_GLOBAL_DATA_PTR;
#define BITMASK(bits) (BIT(bits) - 1)
#define PHY_REG_MASK 0x1f
@@ -37,6 +40,23 @@
#define FULLDUPLEXEN BIT(0)
#define MIIEN BIT(15)
+/* reg offset */
+#define CPSW_HOST_PORT_OFFSET 0x108
+#define CPSW_SLAVE0_OFFSET 0x208
+#define CPSW_SLAVE1_OFFSET 0x308
+#define CPSW_SLAVE_SIZE 0x100
+#define CPSW_CPDMA_OFFSET 0x800
+#define CPSW_HW_STATS 0x900
+#define CPSW_STATERAM_OFFSET 0xa00
+#define CPSW_CPTS_OFFSET 0xc00
+#define CPSW_ALE_OFFSET 0xd00
+#define CPSW_SLIVER0_OFFSET 0xd80
+#define CPSW_SLIVER1_OFFSET 0xdc0
+#define CPSW_BD_OFFSET 0x2000
+#define CPSW_MDIO_DIV 0xff
+
+#define AM335X_GMII_SEL_OFFSET 0x630
+
/* DMA Registers */
#define CPDMA_TXCONTROL 0x004
#define CPDMA_RXCONTROL 0x014
@@ -218,7 +238,11 @@ struct cpdma_chan {
(priv)->data.slaves; slave++)
struct cpsw_priv {
+#ifdef CONFIG_DM_ETH
+ struct udevice *dev;
+#else
struct eth_device *dev;
+#endif
struct cpsw_platform_data data;
int host_port;
@@ -522,7 +546,7 @@ static int cpsw_mdio_write(struct mii_dev *bus, int phy_id, int dev_addr,
return 0;
}
-static void cpsw_mdio_init(char *name, u32 mdio_base, u32 div)
+static void cpsw_mdio_init(const char *name, u32 mdio_base, u32 div)
{
struct mii_dev *bus = mdio_alloc();
@@ -563,8 +587,15 @@ static inline void setbit_and_wait_for_clear32(void *addr)
static void cpsw_set_slave_mac(struct cpsw_slave *slave,
struct cpsw_priv *priv)
{
+#ifdef CONFIG_DM_ETH
+ struct eth_pdata *pdata = dev_get_platdata(priv->dev);
+
+ writel(mac_hi(pdata->enetaddr), &slave->regs->sa_hi);
+ writel(mac_lo(pdata->enetaddr), &slave->regs->sa_lo);
+#else
__raw_writel(mac_hi(priv->dev->enetaddr), &slave->regs->sa_hi);
__raw_writel(mac_lo(priv->dev->enetaddr), &slave->regs->sa_lo);
+#endif
}
static void cpsw_slave_update_link(struct cpsw_slave *slave,
@@ -973,6 +1004,7 @@ int _cpsw_register(struct cpsw_priv *priv)
return 0;
}
+#ifndef CONFIG_DM_ETH
static int cpsw_init(struct eth_device *dev, bd_t *bis)
{
struct cpsw_priv *priv = dev->priv;
@@ -1049,3 +1081,215 @@ int cpsw_register(struct cpsw_platform_data *data)
return 1;
}
+#else
+static int cpsw_eth_start(struct udevice *dev)
+{
+ struct eth_pdata *pdata = dev_get_platdata(dev);
+ struct cpsw_priv *priv = dev_get_priv(dev);
+
+ return _cpsw_init(priv, pdata->enetaddr);
+}
+
+static int cpsw_eth_send(struct udevice *dev, void *packet, int length)
+{
+ struct cpsw_priv *priv = dev_get_priv(dev);
+
+ return _cpsw_send(priv, packet, length);
+}
+
+static int cpsw_eth_recv(struct udevice *dev, int flags, uchar **packetp)
+{
+ struct cpsw_priv *priv = dev_get_priv(dev);
+
+ return _cpsw_recv(priv, packetp);
+}
+
+static int cpsw_eth_free_pkt(struct udevice *dev, uchar *packet,
+ int length)
+{
+ struct cpsw_priv *priv = dev_get_priv(dev);
+
+ return cpdma_submit(priv, &priv->rx_chan, packet, PKTSIZE);
+}
+
+static void cpsw_eth_stop(struct udevice *dev)
+{
+ struct cpsw_priv *priv = dev_get_priv(dev);
+
+ return _cpsw_halt(priv);
+}
+
+
+static int cpsw_eth_probe(struct udevice *dev)
+{
+ struct cpsw_priv *priv = dev_get_priv(dev);
+
+ priv->dev = dev;
+
+ return _cpsw_register(priv);
+}
+
+static const struct eth_ops cpsw_eth_ops = {
+ .start = cpsw_eth_start,
+ .send = cpsw_eth_send,
+ .recv = cpsw_eth_recv,
+ .free_pkt = cpsw_eth_free_pkt,
+ .stop = cpsw_eth_stop,
+};
+
+static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
+{
+ struct eth_pdata *pdata = dev_get_platdata(dev);
+ struct cpsw_priv *priv = dev_get_priv(dev);
+ const char *phy_mode;
+ const void *fdt = gd->fdt_blob;
+ int node = dev->of_offset;
+ int subnode;
+ int slave_index = 0;
+ uint32_t mac_hi, mac_lo;
+ fdt32_t gmii = 0;
+ int active_slave;
+
+ pdata->iobase = dev_get_addr_index(dev, 0);
+ priv->data.version = CPSW_CTRL_VERSION_2;
+ priv->data.bd_ram_ofs = CPSW_BD_OFFSET;
+ priv->data.ale_reg_ofs = CPSW_ALE_OFFSET;
+ priv->data.cpdma_reg_ofs = CPSW_CPDMA_OFFSET;
+ priv->data.mdio_div = CPSW_MDIO_DIV;
+ priv->data.host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
+
+ pdata->phy_interface = -1;
+
+ priv->data.cpsw_base = pdata->iobase;
+ priv->data.mac_id = dev_get_addr_index(dev, 2);
+ priv->data.channels = fdtdec_get_int(fdt, node, "cpdma_channels", -1);
+ if (priv->data.channels <= 0) {
+ printf("error: cpdma_channels not found in dt\n");
+ return -ENOENT;
+ }
+
+ priv->data.slaves = fdtdec_get_int(fdt, node, "slaves", -1);
+ if (priv->data.slaves <= 0) {
+ printf("error: slaves not found in dt\n");
+ return -ENOENT;
+ }
+ priv->data.slave_data = malloc(sizeof(struct cpsw_slave_data) *
+ priv->data.slaves);
+
+ priv->data.ale_entries = fdtdec_get_int(fdt, node, "ale_entries", -1);
+ if (priv->data.ale_entries <= 0) {
+ printf("error: ale_entries not found in dt\n");
+ return -ENOENT;
+ }
+
+ priv->data.bd_ram_ofs = fdtdec_get_int(fdt, node, "bd_ram_size", -1);
+ if (priv->data.bd_ram_ofs <= 0) {
+ printf("error: bd_ram_size not found in dt\n");
+ return -ENOENT;
+ }
+
+ priv->data.mac_control = fdtdec_get_int(fdt, node, "mac_control", -1);
+ if (priv->data.mac_control <= 0) {
+ printf("error: ale_entries not found in dt\n");
+ return -ENOENT;
+ }
+
+ active_slave = fdtdec_get_int(fdt, node, "active_slave", 0);
+ priv->data.active_slave = active_slave;
+
+ fdt_for_each_subnode(fdt, subnode, node) {
+ int len;
+ const char *name;
+
+ name = fdt_get_name(fdt, subnode, &len);
+ if (!strncmp(name, "mdio", 4)) {
+ priv->data.mdio_base = fdtdec_get_addr(fdt, subnode,
+ "reg");
+ }
+
+ if (!strncmp(name, "slave", 5)) {
+ u32 phy_id[2];
+
+ if (slave_index >= priv->data.slaves) {
+ printf("error: num slaves and slave nodes did not match\n");
+ return -EINVAL;
+ }
+ phy_mode = fdt_getprop(fdt, subnode, "phy-mode", NULL);
+ if (phy_mode)
+ priv->data.slave_data[slave_index].phy_if =
+ phy_get_interface_by_name(phy_mode);
+ fdtdec_get_int_array(fdt, subnode, "phy_id", phy_id, 2);
+ priv->data.slave_data[slave_index].phy_addr = phy_id[1];
+ slave_index++;
+ }
+
+ if (!strncmp(name, "cpsw-phy-sel", 12)) {
+ priv->data.gmii_sel = fdtdec_get_addr(fdt, subnode,
+ "reg");
+ }
+ }
+
+ priv->data.slave_data[0].slave_reg_ofs = CPSW_SLAVE0_OFFSET;
+ priv->data.slave_data[0].sliver_reg_ofs = CPSW_SLIVER0_OFFSET;
+
+ if (priv->data.slaves == 2) {
+ priv->data.slave_data[1].slave_reg_ofs = CPSW_SLAVE1_OFFSET;
+ priv->data.slave_data[1].sliver_reg_ofs = CPSW_SLIVER1_OFFSET;
+ }
+
+ subnode = fdtdec_lookup_phandle(fdt, node, "syscon");
+ priv->data.mac_id = fdt_translate_address((void *)fdt, subnode, &gmii);
+ priv->data.mac_id += AM335X_GMII_SEL_OFFSET;
+ priv->data.mac_id += active_slave * 8;
+
+ /* try reading mac address from efuse */
+ mac_lo = readl(priv->data.mac_id);
+ mac_hi = readl(priv->data.mac_id + 4);
+ pdata->enetaddr[0] = mac_hi & 0xFF;
+ pdata->enetaddr[1] = (mac_hi & 0xFF00) >> 8;
+ pdata->enetaddr[2] = (mac_hi & 0xFF0000) >> 16;
+ pdata->enetaddr[3] = (mac_hi & 0xFF000000) >> 24;
+ pdata->enetaddr[4] = mac_lo & 0xFF;
+ pdata->enetaddr[5] = (mac_lo & 0xFF00) >> 8;
+
+ pdata->phy_interface = priv->data.slave_data[active_slave].phy_if;
+ if (pdata->phy_interface == -1) {
+ debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ return -EINVAL;
+ }
+ switch (pdata->phy_interface) {
+ case PHY_INTERFACE_MODE_MII:
+ writel(MII_MODE_ENABLE, priv->data.gmii_sel);
+ break;
+ case PHY_INTERFACE_MODE_RMII:
+ writel(RMII_MODE_ENABLE, priv->data.gmii_sel);
+ break;
+ case PHY_INTERFACE_MODE_RGMII:
+ case PHY_INTERFACE_MODE_RGMII_ID:
+ case PHY_INTERFACE_MODE_RGMII_RXID:
+ case PHY_INTERFACE_MODE_RGMII_TXID:
+ writel(RGMII_MODE_ENABLE, priv->data.gmii_sel);
+ break;
+ }
+ return 0;
+}
+
+
+static const struct udevice_id cpsw_eth_ids[] = {
+ { .compatible = "ti,cpsw" },
+ { .compatible = "ti,am335x-cpsw" },
+ { }
+};
+
+U_BOOT_DRIVER(eth_cpsw) = {
+ .name = "eth_cpsw",
+ .id = UCLASS_ETH,
+ .of_match = cpsw_eth_ids,
+ .ofdata_to_platdata = cpsw_eth_ofdata_to_platdata,
+ .probe = cpsw_eth_probe,
+ .ops = &cpsw_eth_ops,
+ .priv_auto_alloc_size = sizeof(struct cpsw_priv),
+ .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+ .flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
+#endif /* CONFIG_DM_ETH */
diff --git a/include/cpsw.h b/include/cpsw.h
index 547b40c..cf1d30b 100644
--- a/include/cpsw.h
+++ b/include/cpsw.h
@@ -31,6 +31,8 @@ enum {
struct cpsw_platform_data {
u32 mdio_base;
u32 cpsw_base;
+ u32 mac_id;
+ u32 gmii_sel;
int mdio_div;
int channels; /* number of cpdma channels (symmetric) */
u32 cpdma_reg_ofs; /* cpdma register offset */
--
2.5.1.522.g7aa67f6
^ permalink raw reply related [flat|nested] 17+ messages in thread* [U-Boot] [PATCH 5/6] drivers: net: cpsw: convert driver to adopt device driver model
2015-09-02 11:15 ` [U-Boot] [PATCH 5/6] drivers: net: cpsw: convert driver to adopt device driver model Mugunthan V N
@ 2015-09-04 0:58 ` Simon Glass
2015-09-06 11:14 ` Mugunthan V N
0 siblings, 1 reply; 17+ messages in thread
From: Simon Glass @ 2015-09-04 0:58 UTC (permalink / raw)
To: u-boot
Hi,
On 2 September 2015 at 05:15, Mugunthan V N <mugunthanvnm@ti.com> wrote:
> adopt cpsw driver to device driver model
>
> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
> ---
> drivers/net/cpsw.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
> include/cpsw.h | 2 +
> 2 files changed, 247 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
This looks correct. A few thoughts below.
>
> diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c
> index a114d4d..f982eb5 100644
> --- a/drivers/net/cpsw.c
> +++ b/drivers/net/cpsw.c
> @@ -25,6 +25,9 @@
> #include <asm/io.h>
> #include <phy.h>
> #include <asm/arch/cpu.h>
> +#include <dm.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
>
> #define BITMASK(bits) (BIT(bits) - 1)
> #define PHY_REG_MASK 0x1f
> @@ -37,6 +40,23 @@
> #define FULLDUPLEXEN BIT(0)
> #define MIIEN BIT(15)
>
> +/* reg offset */
> +#define CPSW_HOST_PORT_OFFSET 0x108
> +#define CPSW_SLAVE0_OFFSET 0x208
> +#define CPSW_SLAVE1_OFFSET 0x308
> +#define CPSW_SLAVE_SIZE 0x100
> +#define CPSW_CPDMA_OFFSET 0x800
> +#define CPSW_HW_STATS 0x900
> +#define CPSW_STATERAM_OFFSET 0xa00
> +#define CPSW_CPTS_OFFSET 0xc00
> +#define CPSW_ALE_OFFSET 0xd00
> +#define CPSW_SLIVER0_OFFSET 0xd80
> +#define CPSW_SLIVER1_OFFSET 0xdc0
> +#define CPSW_BD_OFFSET 0x2000
> +#define CPSW_MDIO_DIV 0xff
> +
> +#define AM335X_GMII_SEL_OFFSET 0x630
> +
> /* DMA Registers */
> #define CPDMA_TXCONTROL 0x004
> #define CPDMA_RXCONTROL 0x014
> @@ -218,7 +238,11 @@ struct cpdma_chan {
> (priv)->data.slaves; slave++)
>
> struct cpsw_priv {
> +#ifdef CONFIG_DM_ETH
> + struct udevice *dev;
> +#else
> struct eth_device *dev;
> +#endif
> struct cpsw_platform_data data;
> int host_port;
>
> @@ -522,7 +546,7 @@ static int cpsw_mdio_write(struct mii_dev *bus, int phy_id, int dev_addr,
> return 0;
> }
>
> -static void cpsw_mdio_init(char *name, u32 mdio_base, u32 div)
> +static void cpsw_mdio_init(const char *name, u32 mdio_base, u32 div)
> {
> struct mii_dev *bus = mdio_alloc();
>
> @@ -563,8 +587,15 @@ static inline void setbit_and_wait_for_clear32(void *addr)
> static void cpsw_set_slave_mac(struct cpsw_slave *slave,
> struct cpsw_priv *priv)
> {
> +#ifdef CONFIG_DM_ETH
> + struct eth_pdata *pdata = dev_get_platdata(priv->dev);
> +
> + writel(mac_hi(pdata->enetaddr), &slave->regs->sa_hi);
> + writel(mac_lo(pdata->enetaddr), &slave->regs->sa_lo);
> +#else
> __raw_writel(mac_hi(priv->dev->enetaddr), &slave->regs->sa_hi);
> __raw_writel(mac_lo(priv->dev->enetaddr), &slave->regs->sa_lo);
> +#endif
> }
>
> static void cpsw_slave_update_link(struct cpsw_slave *slave,
> @@ -973,6 +1004,7 @@ int _cpsw_register(struct cpsw_priv *priv)
> return 0;
> }
>
> +#ifndef CONFIG_DM_ETH
> static int cpsw_init(struct eth_device *dev, bd_t *bis)
> {
> struct cpsw_priv *priv = dev->priv;
> @@ -1049,3 +1081,215 @@ int cpsw_register(struct cpsw_platform_data *data)
>
> return 1;
> }
> +#else
> +static int cpsw_eth_start(struct udevice *dev)
> +{
> + struct eth_pdata *pdata = dev_get_platdata(dev);
> + struct cpsw_priv *priv = dev_get_priv(dev);
> +
> + return _cpsw_init(priv, pdata->enetaddr);
> +}
> +
> +static int cpsw_eth_send(struct udevice *dev, void *packet, int length)
> +{
> + struct cpsw_priv *priv = dev_get_priv(dev);
> +
> + return _cpsw_send(priv, packet, length);
> +}
> +
> +static int cpsw_eth_recv(struct udevice *dev, int flags, uchar **packetp)
> +{
> + struct cpsw_priv *priv = dev_get_priv(dev);
> +
> + return _cpsw_recv(priv, packetp);
> +}
> +
> +static int cpsw_eth_free_pkt(struct udevice *dev, uchar *packet,
> + int length)
> +{
> + struct cpsw_priv *priv = dev_get_priv(dev);
> +
> + return cpdma_submit(priv, &priv->rx_chan, packet, PKTSIZE);
> +}
> +
> +static void cpsw_eth_stop(struct udevice *dev)
> +{
> + struct cpsw_priv *priv = dev_get_priv(dev);
> +
> + return _cpsw_halt(priv);
> +}
> +
> +
> +static int cpsw_eth_probe(struct udevice *dev)
> +{
> + struct cpsw_priv *priv = dev_get_priv(dev);
> +
> + priv->dev = dev;
> +
> + return _cpsw_register(priv);
> +}
> +
> +static const struct eth_ops cpsw_eth_ops = {
> + .start = cpsw_eth_start,
> + .send = cpsw_eth_send,
> + .recv = cpsw_eth_recv,
> + .free_pkt = cpsw_eth_free_pkt,
> + .stop = cpsw_eth_stop,
> +};
> +
> +static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
> +{
> + struct eth_pdata *pdata = dev_get_platdata(dev);
> + struct cpsw_priv *priv = dev_get_priv(dev);
> + const char *phy_mode;
> + const void *fdt = gd->fdt_blob;
> + int node = dev->of_offset;
> + int subnode;
> + int slave_index = 0;
> + uint32_t mac_hi, mac_lo;
> + fdt32_t gmii = 0;
> + int active_slave;
> +
> + pdata->iobase = dev_get_addr_index(dev, 0);
> + priv->data.version = CPSW_CTRL_VERSION_2;
> + priv->data.bd_ram_ofs = CPSW_BD_OFFSET;
> + priv->data.ale_reg_ofs = CPSW_ALE_OFFSET;
> + priv->data.cpdma_reg_ofs = CPSW_CPDMA_OFFSET;
> + priv->data.mdio_div = CPSW_MDIO_DIV;
> + priv->data.host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
> +
> + pdata->phy_interface = -1;
> +
> + priv->data.cpsw_base = pdata->iobase;
> + priv->data.mac_id = dev_get_addr_index(dev, 2);
> + priv->data.channels = fdtdec_get_int(fdt, node, "cpdma_channels", -1);
> + if (priv->data.channels <= 0) {
> + printf("error: cpdma_channels not found in dt\n");
> + return -ENOENT;
> + }
> +
> + priv->data.slaves = fdtdec_get_int(fdt, node, "slaves", -1);
> + if (priv->data.slaves <= 0) {
> + printf("error: slaves not found in dt\n");
> + return -ENOENT;
> + }
> + priv->data.slave_data = malloc(sizeof(struct cpsw_slave_data) *
> + priv->data.slaves);
> +
> + priv->data.ale_entries = fdtdec_get_int(fdt, node, "ale_entries", -1);
Is this device tree binding documented somewhere? If not, are you
creating a new one?
> + if (priv->data.ale_entries <= 0) {
> + printf("error: ale_entries not found in dt\n");
> + return -ENOENT;
> + }
> +
> + priv->data.bd_ram_ofs = fdtdec_get_int(fdt, node, "bd_ram_size", -1);
> + if (priv->data.bd_ram_ofs <= 0) {
> + printf("error: bd_ram_size not found in dt\n");
> + return -ENOENT;
> + }
> +
> + priv->data.mac_control = fdtdec_get_int(fdt, node, "mac_control", -1);
> + if (priv->data.mac_control <= 0) {
> + printf("error: ale_entries not found in dt\n");
> + return -ENOENT;
> + }
> +
> + active_slave = fdtdec_get_int(fdt, node, "active_slave", 0);
> + priv->data.active_slave = active_slave;
> +
> + fdt_for_each_subnode(fdt, subnode, node) {
> + int len;
> + const char *name;
> +
> + name = fdt_get_name(fdt, subnode, &len);
> + if (!strncmp(name, "mdio", 4)) {
> + priv->data.mdio_base = fdtdec_get_addr(fdt, subnode,
> + "reg");
> + }
> +
> + if (!strncmp(name, "slave", 5)) {
> + u32 phy_id[2];
> +
> + if (slave_index >= priv->data.slaves) {
> + printf("error: num slaves and slave nodes did not match\n");
debug() ?
> + return -EINVAL;
> + }
> + phy_mode = fdt_getprop(fdt, subnode, "phy-mode", NULL);
> + if (phy_mode)
> + priv->data.slave_data[slave_index].phy_if =
> + phy_get_interface_by_name(phy_mode);
> + fdtdec_get_int_array(fdt, subnode, "phy_id", phy_id, 2);
Error check?
> + priv->data.slave_data[slave_index].phy_addr = phy_id[1];
> + slave_index++;
> + }
> +
> + if (!strncmp(name, "cpsw-phy-sel", 12)) {
> + priv->data.gmii_sel = fdtdec_get_addr(fdt, subnode,
> + "reg");
> + }
> + }
> +
> + priv->data.slave_data[0].slave_reg_ofs = CPSW_SLAVE0_OFFSET;
> + priv->data.slave_data[0].sliver_reg_ofs = CPSW_SLIVER0_OFFSET;
> +
> + if (priv->data.slaves == 2) {
> + priv->data.slave_data[1].slave_reg_ofs = CPSW_SLAVE1_OFFSET;
> + priv->data.slave_data[1].sliver_reg_ofs = CPSW_SLIVER1_OFFSET;
> + }
> +
> + subnode = fdtdec_lookup_phandle(fdt, node, "syscon");
> + priv->data.mac_id = fdt_translate_address((void *)fdt, subnode, &gmii);
> + priv->data.mac_id += AM335X_GMII_SEL_OFFSET;
> + priv->data.mac_id += active_slave * 8;
> +
> + /* try reading mac address from efuse */
> + mac_lo = readl(priv->data.mac_id);
> + mac_hi = readl(priv->data.mac_id + 4);
> + pdata->enetaddr[0] = mac_hi & 0xFF;
> + pdata->enetaddr[1] = (mac_hi & 0xFF00) >> 8;
> + pdata->enetaddr[2] = (mac_hi & 0xFF0000) >> 16;
> + pdata->enetaddr[3] = (mac_hi & 0xFF000000) >> 24;
Can you use put_unaligned() or similar?
> + pdata->enetaddr[4] = mac_lo & 0xFF;
> + pdata->enetaddr[5] = (mac_lo & 0xFF00) >> 8;
> +
> + pdata->phy_interface = priv->data.slave_data[active_slave].phy_if;
> + if (pdata->phy_interface == -1) {
> + debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
> + return -EINVAL;
> + }
> + switch (pdata->phy_interface) {
> + case PHY_INTERFACE_MODE_MII:
> + writel(MII_MODE_ENABLE, priv->data.gmii_sel);
> + break;
> + case PHY_INTERFACE_MODE_RMII:
> + writel(RMII_MODE_ENABLE, priv->data.gmii_sel);
> + break;
> + case PHY_INTERFACE_MODE_RGMII:
> + case PHY_INTERFACE_MODE_RGMII_ID:
> + case PHY_INTERFACE_MODE_RGMII_RXID:
> + case PHY_INTERFACE_MODE_RGMII_TXID:
> + writel(RGMII_MODE_ENABLE, priv->data.gmii_sel);
> + break;
> + }
> + return 0;
> +}
> +
> +
> +static const struct udevice_id cpsw_eth_ids[] = {
> + { .compatible = "ti,cpsw" },
> + { .compatible = "ti,am335x-cpsw" },
> + { }
> +};
> +
> +U_BOOT_DRIVER(eth_cpsw) = {
> + .name = "eth_cpsw",
> + .id = UCLASS_ETH,
> + .of_match = cpsw_eth_ids,
> + .ofdata_to_platdata = cpsw_eth_ofdata_to_platdata,
> + .probe = cpsw_eth_probe,
> + .ops = &cpsw_eth_ops,
> + .priv_auto_alloc_size = sizeof(struct cpsw_priv),
> + .platdata_auto_alloc_size = sizeof(struct eth_pdata),
> + .flags = DM_FLAG_ALLOC_PRIV_DMA,
> +};
> +#endif /* CONFIG_DM_ETH */
> diff --git a/include/cpsw.h b/include/cpsw.h
> index 547b40c..cf1d30b 100644
> --- a/include/cpsw.h
> +++ b/include/cpsw.h
> @@ -31,6 +31,8 @@ enum {
> struct cpsw_platform_data {
> u32 mdio_base;
> u32 cpsw_base;
> + u32 mac_id;
> + u32 gmii_sel;
> int mdio_div;
> int channels; /* number of cpdma channels (symmetric) */
> u32 cpdma_reg_ofs; /* cpdma register offset */
> --
> 2.5.1.522.g7aa67f6
>
Regards,
Simon
^ permalink raw reply [flat|nested] 17+ messages in thread* [U-Boot] [PATCH 5/6] drivers: net: cpsw: convert driver to adopt device driver model
2015-09-04 0:58 ` Simon Glass
@ 2015-09-06 11:14 ` Mugunthan V N
0 siblings, 0 replies; 17+ messages in thread
From: Mugunthan V N @ 2015-09-06 11:14 UTC (permalink / raw)
To: u-boot
On Friday 04 September 2015 06:28 AM, Simon Glass wrote:
> Hi,
>
> On 2 September 2015 at 05:15, Mugunthan V N <mugunthanvnm@ti.com> wrote:
>> adopt cpsw driver to device driver model
>>
>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>> ---
>> drivers/net/cpsw.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>> include/cpsw.h | 2 +
>> 2 files changed, 247 insertions(+), 1 deletion(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> This looks correct. A few thoughts below.
>
>>
>> diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c
>> index a114d4d..f982eb5 100644
>> --- a/drivers/net/cpsw.c
>> +++ b/drivers/net/cpsw.c
>> @@ -25,6 +25,9 @@
>> #include <asm/io.h>
>> #include <phy.h>
>> #include <asm/arch/cpu.h>
>> +#include <dm.h>
>> +
>> +DECLARE_GLOBAL_DATA_PTR;
>>
>> #define BITMASK(bits) (BIT(bits) - 1)
>> #define PHY_REG_MASK 0x1f
>> @@ -37,6 +40,23 @@
>> #define FULLDUPLEXEN BIT(0)
>> #define MIIEN BIT(15)
>>
>> +/* reg offset */
>> +#define CPSW_HOST_PORT_OFFSET 0x108
>> +#define CPSW_SLAVE0_OFFSET 0x208
>> +#define CPSW_SLAVE1_OFFSET 0x308
>> +#define CPSW_SLAVE_SIZE 0x100
>> +#define CPSW_CPDMA_OFFSET 0x800
>> +#define CPSW_HW_STATS 0x900
>> +#define CPSW_STATERAM_OFFSET 0xa00
>> +#define CPSW_CPTS_OFFSET 0xc00
>> +#define CPSW_ALE_OFFSET 0xd00
>> +#define CPSW_SLIVER0_OFFSET 0xd80
>> +#define CPSW_SLIVER1_OFFSET 0xdc0
>> +#define CPSW_BD_OFFSET 0x2000
>> +#define CPSW_MDIO_DIV 0xff
>> +
>> +#define AM335X_GMII_SEL_OFFSET 0x630
>> +
>> /* DMA Registers */
>> #define CPDMA_TXCONTROL 0x004
>> #define CPDMA_RXCONTROL 0x014
>> @@ -218,7 +238,11 @@ struct cpdma_chan {
>> (priv)->data.slaves; slave++)
>>
>> struct cpsw_priv {
>> +#ifdef CONFIG_DM_ETH
>> + struct udevice *dev;
>> +#else
>> struct eth_device *dev;
>> +#endif
>> struct cpsw_platform_data data;
>> int host_port;
>>
>> @@ -522,7 +546,7 @@ static int cpsw_mdio_write(struct mii_dev *bus, int phy_id, int dev_addr,
>> return 0;
>> }
>>
>> -static void cpsw_mdio_init(char *name, u32 mdio_base, u32 div)
>> +static void cpsw_mdio_init(const char *name, u32 mdio_base, u32 div)
>> {
>> struct mii_dev *bus = mdio_alloc();
>>
>> @@ -563,8 +587,15 @@ static inline void setbit_and_wait_for_clear32(void *addr)
>> static void cpsw_set_slave_mac(struct cpsw_slave *slave,
>> struct cpsw_priv *priv)
>> {
>> +#ifdef CONFIG_DM_ETH
>> + struct eth_pdata *pdata = dev_get_platdata(priv->dev);
>> +
>> + writel(mac_hi(pdata->enetaddr), &slave->regs->sa_hi);
>> + writel(mac_lo(pdata->enetaddr), &slave->regs->sa_lo);
>> +#else
>> __raw_writel(mac_hi(priv->dev->enetaddr), &slave->regs->sa_hi);
>> __raw_writel(mac_lo(priv->dev->enetaddr), &slave->regs->sa_lo);
>> +#endif
>> }
>>
>> static void cpsw_slave_update_link(struct cpsw_slave *slave,
>> @@ -973,6 +1004,7 @@ int _cpsw_register(struct cpsw_priv *priv)
>> return 0;
>> }
>>
>> +#ifndef CONFIG_DM_ETH
>> static int cpsw_init(struct eth_device *dev, bd_t *bis)
>> {
>> struct cpsw_priv *priv = dev->priv;
>> @@ -1049,3 +1081,215 @@ int cpsw_register(struct cpsw_platform_data *data)
>>
>> return 1;
>> }
>> +#else
>> +static int cpsw_eth_start(struct udevice *dev)
>> +{
>> + struct eth_pdata *pdata = dev_get_platdata(dev);
>> + struct cpsw_priv *priv = dev_get_priv(dev);
>> +
>> + return _cpsw_init(priv, pdata->enetaddr);
>> +}
>> +
>> +static int cpsw_eth_send(struct udevice *dev, void *packet, int length)
>> +{
>> + struct cpsw_priv *priv = dev_get_priv(dev);
>> +
>> + return _cpsw_send(priv, packet, length);
>> +}
>> +
>> +static int cpsw_eth_recv(struct udevice *dev, int flags, uchar **packetp)
>> +{
>> + struct cpsw_priv *priv = dev_get_priv(dev);
>> +
>> + return _cpsw_recv(priv, packetp);
>> +}
>> +
>> +static int cpsw_eth_free_pkt(struct udevice *dev, uchar *packet,
>> + int length)
>> +{
>> + struct cpsw_priv *priv = dev_get_priv(dev);
>> +
>> + return cpdma_submit(priv, &priv->rx_chan, packet, PKTSIZE);
>> +}
>> +
>> +static void cpsw_eth_stop(struct udevice *dev)
>> +{
>> + struct cpsw_priv *priv = dev_get_priv(dev);
>> +
>> + return _cpsw_halt(priv);
>> +}
>> +
>> +
>> +static int cpsw_eth_probe(struct udevice *dev)
>> +{
>> + struct cpsw_priv *priv = dev_get_priv(dev);
>> +
>> + priv->dev = dev;
>> +
>> + return _cpsw_register(priv);
>> +}
>> +
>> +static const struct eth_ops cpsw_eth_ops = {
>> + .start = cpsw_eth_start,
>> + .send = cpsw_eth_send,
>> + .recv = cpsw_eth_recv,
>> + .free_pkt = cpsw_eth_free_pkt,
>> + .stop = cpsw_eth_stop,
>> +};
>> +
>> +static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
>> +{
>> + struct eth_pdata *pdata = dev_get_platdata(dev);
>> + struct cpsw_priv *priv = dev_get_priv(dev);
>> + const char *phy_mode;
>> + const void *fdt = gd->fdt_blob;
>> + int node = dev->of_offset;
>> + int subnode;
>> + int slave_index = 0;
>> + uint32_t mac_hi, mac_lo;
>> + fdt32_t gmii = 0;
>> + int active_slave;
>> +
>> + pdata->iobase = dev_get_addr_index(dev, 0);
>> + priv->data.version = CPSW_CTRL_VERSION_2;
>> + priv->data.bd_ram_ofs = CPSW_BD_OFFSET;
>> + priv->data.ale_reg_ofs = CPSW_ALE_OFFSET;
>> + priv->data.cpdma_reg_ofs = CPSW_CPDMA_OFFSET;
>> + priv->data.mdio_div = CPSW_MDIO_DIV;
>> + priv->data.host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
>> +
>> + pdata->phy_interface = -1;
>> +
>> + priv->data.cpsw_base = pdata->iobase;
>> + priv->data.mac_id = dev_get_addr_index(dev, 2);
>> + priv->data.channels = fdtdec_get_int(fdt, node, "cpdma_channels", -1);
>> + if (priv->data.channels <= 0) {
>> + printf("error: cpdma_channels not found in dt\n");
>> + return -ENOENT;
>> + }
>> +
>> + priv->data.slaves = fdtdec_get_int(fdt, node, "slaves", -1);
>> + if (priv->data.slaves <= 0) {
>> + printf("error: slaves not found in dt\n");
>> + return -ENOENT;
>> + }
>> + priv->data.slave_data = malloc(sizeof(struct cpsw_slave_data) *
>> + priv->data.slaves);
>> +
>> + priv->data.ale_entries = fdtdec_get_int(fdt, node, "ale_entries", -1);
>
> Is this device tree binding documented somewhere? If not, are you
> creating a new one?
It is documented in kernel binding document
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/net/cpsw.txt?id=refs/tags/v4.2
>
>> + if (priv->data.ale_entries <= 0) {
>> + printf("error: ale_entries not found in dt\n");
>> + return -ENOENT;
>> + }
>> +
>> + priv->data.bd_ram_ofs = fdtdec_get_int(fdt, node, "bd_ram_size", -1);
>> + if (priv->data.bd_ram_ofs <= 0) {
>> + printf("error: bd_ram_size not found in dt\n");
>> + return -ENOENT;
>> + }
>> +
>> + priv->data.mac_control = fdtdec_get_int(fdt, node, "mac_control", -1);
>> + if (priv->data.mac_control <= 0) {
>> + printf("error: ale_entries not found in dt\n");
>> + return -ENOENT;
>> + }
>> +
>> + active_slave = fdtdec_get_int(fdt, node, "active_slave", 0);
>> + priv->data.active_slave = active_slave;
>> +
>> + fdt_for_each_subnode(fdt, subnode, node) {
>> + int len;
>> + const char *name;
>> +
>> + name = fdt_get_name(fdt, subnode, &len);
>> + if (!strncmp(name, "mdio", 4)) {
>> + priv->data.mdio_base = fdtdec_get_addr(fdt, subnode,
>> + "reg");
>> + }
>> +
>> + if (!strncmp(name, "slave", 5)) {
>> + u32 phy_id[2];
>> +
>> + if (slave_index >= priv->data.slaves) {
>> + printf("error: num slaves and slave nodes did not match\n");
>
> debug() ?
I wanted this to be error the debug, so used printf.
>
>> + return -EINVAL;
>> + }
>> + phy_mode = fdt_getprop(fdt, subnode, "phy-mode", NULL);
>> + if (phy_mode)
>> + priv->data.slave_data[slave_index].phy_if =
>> + phy_get_interface_by_name(phy_mode);
>> + fdtdec_get_int_array(fdt, subnode, "phy_id", phy_id, 2);
>
> Error check?
phy_id is optional node. It will be populated only when phy is connected
on board.
>
>> + priv->data.slave_data[slave_index].phy_addr = phy_id[1];
>> + slave_index++;
>> + }
>> +
>> + if (!strncmp(name, "cpsw-phy-sel", 12)) {
>> + priv->data.gmii_sel = fdtdec_get_addr(fdt, subnode,
>> + "reg");
>> + }
>> + }
>> +
>> + priv->data.slave_data[0].slave_reg_ofs = CPSW_SLAVE0_OFFSET;
>> + priv->data.slave_data[0].sliver_reg_ofs = CPSW_SLIVER0_OFFSET;
>> +
>> + if (priv->data.slaves == 2) {
>> + priv->data.slave_data[1].slave_reg_ofs = CPSW_SLAVE1_OFFSET;
>> + priv->data.slave_data[1].sliver_reg_ofs = CPSW_SLIVER1_OFFSET;
>> + }
>> +
>> + subnode = fdtdec_lookup_phandle(fdt, node, "syscon");
>> + priv->data.mac_id = fdt_translate_address((void *)fdt, subnode, &gmii);
>> + priv->data.mac_id += AM335X_GMII_SEL_OFFSET;
>> + priv->data.mac_id += active_slave * 8;
>> +
>> + /* try reading mac address from efuse */
>> + mac_lo = readl(priv->data.mac_id);
>> + mac_hi = readl(priv->data.mac_id + 4);
>> + pdata->enetaddr[0] = mac_hi & 0xFF;
>> + pdata->enetaddr[1] = (mac_hi & 0xFF00) >> 8;
>> + pdata->enetaddr[2] = (mac_hi & 0xFF0000) >> 16;
>> + pdata->enetaddr[3] = (mac_hi & 0xFF000000) >> 24;
>
> Can you use put_unaligned() or similar?
This will vary based on platform. In DRA7 mac id combination is different.
Regards
Mugunthan V N
^ permalink raw reply [flat|nested] 17+ messages in thread
* [U-Boot] [PATCH 6/6] defconfig: am335x: bbb: enable ethernet driver model
2015-09-02 11:15 [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Mugunthan V N
` (4 preceding siblings ...)
2015-09-02 11:15 ` [U-Boot] [PATCH 5/6] drivers: net: cpsw: convert driver to adopt device driver model Mugunthan V N
@ 2015-09-02 11:15 ` Mugunthan V N
2015-09-02 13:16 ` Tom Rini
2015-09-02 13:15 ` [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Tom Rini
6 siblings, 1 reply; 17+ messages in thread
From: Mugunthan V N @ 2015-09-02 11:15 UTC (permalink / raw)
To: u-boot
enable ethernet driver model for am335x beagle bone black as cpsw
supports driver model
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
---
configs/am335x_boneblack_vboot_defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/configs/am335x_boneblack_vboot_defconfig b/configs/am335x_boneblack_vboot_defconfig
index b52ddfd..117a146 100644
--- a/configs/am335x_boneblack_vboot_defconfig
+++ b/configs/am335x_boneblack_vboot_defconfig
@@ -13,3 +13,4 @@ CONFIG_SYS_EXTRA_OPTIONS="EMMC_BOOT,ENABLE_VBOOT"
# CONFIG_CMD_SETEXPR is not set
CONFIG_OF_CONTROL=y
CONFIG_SPI_FLASH=y
+CONFIG_DM_ETH=y
--
2.5.1.522.g7aa67f6
^ permalink raw reply related [flat|nested] 17+ messages in thread* [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black
2015-09-02 11:15 [U-Boot] [PATCH 0/6] device model bringup of cpsw on am335x bone black Mugunthan V N
` (5 preceding siblings ...)
2015-09-02 11:15 ` [U-Boot] [PATCH 6/6] defconfig: am335x: bbb: enable ethernet " Mugunthan V N
@ 2015-09-02 13:15 ` Tom Rini
6 siblings, 0 replies; 17+ messages in thread
From: Tom Rini @ 2015-09-02 13:15 UTC (permalink / raw)
To: u-boot
On Wed, Sep 02, 2015 at 04:45:36PM +0530, Mugunthan V N wrote:
> This patch seires enables cpsw to adopt driver model. This has
> been tested on AM335x beagle bone black (logs [1] with
> am335x_boneblack_defconfig and am335x_boneblack_vboot_defconfig.
> Also pushed a branch for testing [2]
>
> [1]: http://pastebin.ubuntu.com/12252448/
> [2]: git://git.ti.com/~mugunthanvnm/ti-u-boot/mugunth-ti-u-boot.git cpsw-dt-conversion
Looks OK overall, and I'll let Simon comment on the DM portions. Can
you please also enable and test am335x_gp_evm? Thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150902/949a9cc2/attachment.sig>
^ permalink raw reply [flat|nested] 17+ messages in thread