* [PATCH 1/4] nios2/generic.c: Add resources for altera TSE
2011-07-26 20:07 [PATCH v2] Switch nios2 devices to resources franck.jullien
@ 2011-07-26 20:07 ` franck.jullien
2011-07-26 20:07 ` [PATCH 2/4] nios2/altera_tse: Switch to resources franck.jullien
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: franck.jullien @ 2011-07-26 20:07 UTC (permalink / raw)
To: barebox
From: Franck Jullien <franck.jullien@gmail.com>
This patch adds resources for the Altera TSE driver as
this driver has been moved to resources usage.
The serial device also uses resources declared with the helps
of add_generic_device.
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
---
arch/nios2/boards/generic/generic.c | 31 ++++++++++++++++++++++---------
1 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/arch/nios2/boards/generic/generic.c b/arch/nios2/boards/generic/generic.c
index 089715b..49c1d7c 100644
--- a/arch/nios2/boards/generic/generic.c
+++ b/arch/nios2/boards/generic/generic.c
@@ -6,20 +6,32 @@
static int phy_address = 1;
+static struct resource mac_resources[] = {
+ [0] = {
+ .start = NIOS_SOPC_TSE_BASE,
+ .size = 0x400,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = NIOS_SOPC_SGDMA_RX_BASE,
+ .size = 0x40,
+ .flags = IORESOURCE_MEM,
+ },
+ [2] = {
+ .start = NIOS_SOPC_SGDMA_TX_BASE,
+ .size = 0x40,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
static struct device_d mac_dev = {
.id = -1,
.name = "altera_tse",
- .map_base = NIOS_SOPC_TSE_BASE,
- .size = 0x00000400,
+ .num_resources = ARRAY_SIZE(mac_resources),
+ .resource = mac_resources,
.platform_data = &phy_address,
};
-static struct device_d altera_serial_device = {
- .id = -1,
- .name = "altera_serial",
- .map_base = NIOS_SOPC_UART_BASE,
-};
-
/*
static struct device_d epcs_flash_device = {
.id = -1,
@@ -49,7 +61,8 @@ device_initcall(generic_devices_init);
static int altera_console_init(void)
{
- register_device(&altera_serial_device);
+ add_generic_device("altera_serial", -1, NULL, NIOS_SOPC_UART_BASE, 0x20,
+ IORESOURCE_MEM, NULL);
return 0;
}
--
1.7.6
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] nios2/altera_tse: Switch to resources
2011-07-26 20:07 [PATCH v2] Switch nios2 devices to resources franck.jullien
2011-07-26 20:07 ` [PATCH 1/4] nios2/generic.c: Add resources for altera TSE franck.jullien
@ 2011-07-26 20:07 ` franck.jullien
2011-07-26 20:07 ` [PATCH 3/4] nios2/serial_altera: " franck.jullien
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: franck.jullien @ 2011-07-26 20:07 UTC (permalink / raw)
To: barebox
From: Franck Jullien <franck.jullien@gmail.com>
Switch to resources usage. Cleanup of the code.
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
---
drivers/net/altera_tse.c | 63 ++++++++++++++++++++++------------------------
drivers/net/altera_tse.h | 15 +++-------
2 files changed, 35 insertions(+), 43 deletions(-)
diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c
index ac8cd2d..e7dabda 100644
--- a/drivers/net/altera_tse.c
+++ b/drivers/net/altera_tse.c
@@ -221,7 +221,7 @@ static int alt_sgdma_do_async_transfer(struct alt_sgdma_registers *dev,
static int tse_get_ethaddr(struct eth_device *edev, unsigned char *m)
{
struct altera_tse_priv *priv = edev->priv;
- struct alt_tse_mac *mac_dev = priv->mac_dev;
+ struct alt_tse_mac *mac_dev = priv->tse_regs;
m[5] = (readl(&mac_dev->mac_addr_1) >> 8) && 0xFF;
m[4] = (readl(&mac_dev->mac_addr_1)) && 0xFF;
@@ -236,7 +236,7 @@ static int tse_get_ethaddr(struct eth_device *edev, unsigned char *m)
static int tse_set_ethaddr(struct eth_device *edev, unsigned char *m)
{
struct altera_tse_priv *priv = edev->priv;
- struct alt_tse_mac *mac_dev = priv->mac_dev;
+ struct alt_tse_mac *mac_dev = priv->tse_regs;
debug("Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n",
m[0], m[1], m[2], m[3], m[4], m[5]);
@@ -250,10 +250,10 @@ static int tse_set_ethaddr(struct eth_device *edev, unsigned char *m)
static int tse_phy_read(struct mii_device *mdev, int phy_addr, int reg)
{
struct eth_device *edev = mdev->edev;
- struct alt_tse_mac *mac_dev;
+ struct altera_tse_priv *priv = edev->priv;
+ struct alt_tse_mac *mac_dev = priv->tse_regs;
uint32_t *mdio_regs;
- mac_dev = (struct alt_tse_mac *)edev->iobase;
writel(phy_addr, &mac_dev->mdio_phy1_addr);
mdio_regs = (uint32_t *)&mac_dev->mdio_phy1;
@@ -264,10 +264,10 @@ static int tse_phy_read(struct mii_device *mdev, int phy_addr, int reg)
static int tse_phy_write(struct mii_device *mdev, int phy_addr, int reg, int val)
{
struct eth_device *edev = mdev->edev;
- struct alt_tse_mac *mac_dev;
+ struct altera_tse_priv *priv = edev->priv;
+ struct alt_tse_mac *mac_dev = priv->tse_regs;
uint32_t *mdio_regs;
- mac_dev = (struct alt_tse_mac *)edev->iobase;
writel(phy_addr, &mac_dev->mdio_phy1_addr);
mdio_regs = (uint32_t *)&mac_dev->mdio_phy1;
@@ -281,11 +281,11 @@ static void tse_reset(struct eth_device *edev)
{
/* stop sgdmas, disable tse receive */
struct altera_tse_priv *priv = edev->priv;
- struct alt_tse_mac *mac_dev = priv->mac_dev;
- struct alt_sgdma_registers *rx_sgdma = priv->sgdma_rx;
- struct alt_sgdma_registers *tx_sgdma = priv->sgdma_tx;
- struct alt_sgdma_descriptor *rx_desc = (struct alt_sgdma_descriptor *)&priv->rx_desc[0];
- struct alt_sgdma_descriptor *tx_desc = (struct alt_sgdma_descriptor *)&priv->tx_desc[0];
+ struct alt_tse_mac *mac_dev = priv->tse_regs;
+ struct alt_sgdma_registers *rx_sgdma = priv->sgdma_rx_regs;
+ struct alt_sgdma_registers *tx_sgdma = priv->sgdma_tx_regs;
+ struct alt_sgdma_descriptor *rx_desc = priv->rx_desc;
+ struct alt_sgdma_descriptor *tx_desc = priv->tx_desc;
uint64_t start;
uint64_t tout;
@@ -358,10 +358,9 @@ static int tse_eth_send(struct eth_device *edev, void *packet, int length)
{
struct altera_tse_priv *priv = edev->priv;
- struct alt_sgdma_registers *tx_sgdma = priv->sgdma_tx;
- struct alt_sgdma_descriptor *tx_desc = (struct alt_sgdma_descriptor *)priv->tx_desc;
-
- struct alt_sgdma_descriptor *tx_desc_cur = (struct alt_sgdma_descriptor *)&tx_desc[0];
+ struct alt_sgdma_registers *tx_sgdma = priv->sgdma_tx_regs;
+ struct alt_sgdma_descriptor *tx_desc = priv->tx_desc;
+ struct alt_sgdma_descriptor *tx_desc_cur = tx_desc;
flush_dcache_range((uint32_t)packet, (uint32_t)packet + length);
alt_sgdma_construct_descriptor_burst(
@@ -386,8 +385,8 @@ static int tse_eth_send(struct eth_device *edev, void *packet, int length)
static void tse_eth_halt(struct eth_device *edev)
{
struct altera_tse_priv *priv = edev->priv;
- struct alt_sgdma_registers *rx_sgdma = priv->sgdma_rx;
- struct alt_sgdma_registers *tx_sgdma = priv->sgdma_tx;
+ struct alt_sgdma_registers *rx_sgdma = priv->sgdma_rx_regs;
+ struct alt_sgdma_registers *tx_sgdma = priv->sgdma_tx_regs;
writel(0, &rx_sgdma->control); /* Stop the controller and reset settings */
writel(0, &tx_sgdma->control); /* Stop the controller and reset settings */
@@ -398,9 +397,9 @@ static int tse_eth_rx(struct eth_device *edev)
uint16_t packet_length = 0;
struct altera_tse_priv *priv = edev->priv;
- struct alt_sgdma_descriptor *rx_desc = (struct alt_sgdma_descriptor *)priv->rx_desc;
- struct alt_sgdma_descriptor *rx_desc_cur = &rx_desc[0];
- struct alt_sgdma_registers *rx_sgdma = priv->sgdma_rx;
+ struct alt_sgdma_descriptor *rx_desc = priv->rx_desc;
+ struct alt_sgdma_descriptor *rx_desc_cur = rx_desc;
+ struct alt_sgdma_registers *rx_sgdma = priv->sgdma_rx_regs;
if (rx_desc_cur->descriptor_status &
ALT_SGDMA_DESCRIPTOR_STATUS_TERMINATED_BY_EOP_MSK) {
@@ -428,7 +427,7 @@ static int tse_eth_rx(struct eth_device *edev)
);
/* setup the sgdma */
- alt_sgdma_do_async_transfer(priv->sgdma_rx, &rx_desc[0]);
+ alt_sgdma_do_async_transfer(priv->sgdma_rx_regs, rx_desc);
}
return 0;
@@ -437,12 +436,12 @@ static int tse_eth_rx(struct eth_device *edev)
static int tse_init_dev(struct eth_device *edev)
{
struct altera_tse_priv *priv = edev->priv;
- struct alt_tse_mac *mac_dev = priv->mac_dev;
+ struct alt_tse_mac *mac_dev = priv->tse_regs;
struct alt_sgdma_descriptor *tx_desc = priv->tx_desc;
struct alt_sgdma_descriptor *rx_desc = priv->rx_desc;
struct alt_sgdma_descriptor *rx_desc_cur;
- rx_desc_cur = (struct alt_sgdma_descriptor *)&rx_desc[0];
+ rx_desc_cur = rx_desc;
tse_reset(edev);
@@ -477,7 +476,7 @@ static int tse_init_dev(struct eth_device *edev)
);
/* start rx async transfer */
- alt_sgdma_do_async_transfer(priv->sgdma_rx, rx_desc_cur);
+ alt_sgdma_do_async_transfer(priv->sgdma_rx_regs, rx_desc_cur);
/* Initialize MAC registers */
writel(PKTSIZE, &mac_dev->max_frame_length);
@@ -504,15 +503,13 @@ static int tse_probe(struct device_d *dev)
#ifndef CONFIG_TSE_USE_DEDICATED_DESC_MEM
uint32_t dma_handle;
#endif
- edev = xzalloc(sizeof(struct eth_device) + sizeof(struct altera_tse_priv));
+ edev = xzalloc(sizeof(struct eth_device));
+ priv = xzalloc(sizeof(struct altera_tse_priv));
miidev = xzalloc(sizeof(struct mii_device));
dev->type_data = edev;
- edev->priv = (struct altera_tse_priv *)(edev + 1);
-
- edev->iobase = dev->map_base;
- priv = edev->priv;
+ edev->priv = priv;
edev->init = tse_init_dev;
edev->open = tse_eth_open;
@@ -523,7 +520,7 @@ static int tse_probe(struct device_d *dev)
edev->set_ethaddr = tse_set_ethaddr;
#ifdef CONFIG_TSE_USE_DEDICATED_DESC_MEM
- tx_desc = (struct alt_sgdma_descriptor *)NIOS_SOPC_TSE_DESC_MEM_BASE;
+ tx_desc = dev_request_mem_region(dev, 3);
rx_desc = tx_desc + 2;
#else
tx_desc = dma_alloc_coherent(sizeof(*tx_desc) * (3 + PKTBUFSRX), (unsigned long *)&dma_handle);
@@ -539,9 +536,9 @@ static int tse_probe(struct device_d *dev)
memset(rx_desc, 0, (sizeof *rx_desc) * (PKTBUFSRX + 1));
memset(tx_desc, 0, (sizeof *tx_desc) * 2);
- priv->mac_dev = (struct alt_tse_mac *)dev->map_base;
- priv->sgdma_rx = (struct alt_sgdma_registers *)NIOS_SOPC_SGDMA_RX_BASE;
- priv->sgdma_tx = (struct alt_sgdma_registers *)NIOS_SOPC_SGDMA_TX_BASE;
+ priv->tse_regs = dev_request_mem_region(dev, 0);
+ priv->sgdma_rx_regs = dev_request_mem_region(dev, 1);
+ priv->sgdma_tx_regs = dev_request_mem_region(dev, 2);
priv->rx_desc = rx_desc;
priv->tx_desc = tx_desc;
diff --git a/drivers/net/altera_tse.h b/drivers/net/altera_tse.h
index c907c74..866dbce 100644
--- a/drivers/net/altera_tse.h
+++ b/drivers/net/altera_tse.h
@@ -287,16 +287,11 @@ struct alt_tse_mac {
};
struct altera_tse_priv {
- struct alt_tse_mac *mac_dev;
- struct alt_sgdma_registers *sgdma_rx;
- struct alt_sgdma_registers *sgdma_tx;
- unsigned int rx_sgdma_irq;
- unsigned int tx_sgdma_irq;
- unsigned int has_descriptor_mem;
- unsigned int descriptor_mem_base;
- unsigned int descriptor_mem_size;
- struct alt_sgdma_descriptor *rx_desc;
- struct alt_sgdma_descriptor *tx_desc;
+ void __iomem *tse_regs;
+ void __iomem *sgdma_rx_regs;
+ void __iomem *sgdma_tx_regs;
+ void __iomem *rx_desc;
+ void __iomem *tx_desc;
struct mii_device *miidev;
};
--
1.7.6
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] nios2/serial_altera: Switch to resources
2011-07-26 20:07 [PATCH v2] Switch nios2 devices to resources franck.jullien
2011-07-26 20:07 ` [PATCH 1/4] nios2/generic.c: Add resources for altera TSE franck.jullien
2011-07-26 20:07 ` [PATCH 2/4] nios2/altera_tse: Switch to resources franck.jullien
@ 2011-07-26 20:07 ` franck.jullien
2011-07-26 20:07 ` [PATCH 4/4] nios2/altera_serial_jtag: " franck.jullien
2011-07-27 8:56 ` [PATCH v2] Switch nios2 devices " Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: franck.jullien @ 2011-07-26 20:07 UTC (permalink / raw)
To: barebox
From: Franck Jullien <franck.jullien@gmail.com>
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
---
drivers/serial/serial_altera.c | 31 ++++++++++++++++++++++++++-----
1 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/drivers/serial/serial_altera.c b/drivers/serial/serial_altera.c
index 54c7178..1148564 100644
--- a/drivers/serial/serial_altera.c
+++ b/drivers/serial/serial_altera.c
@@ -27,9 +27,17 @@
#include <asm/io.h>
#include <asm/nios2-io.h>
+struct altera_serial_priv {
+ struct console_device cdev;
+ void __iomem *regs;
+};
+
static int altera_serial_setbaudrate(struct console_device *cdev, int baudrate)
{
- struct nios_uart *uart = (struct nios_uart *)cdev->dev->map_base;
+ struct altera_serial_priv *priv = container_of(cdev,
+ struct altera_serial_priv, cdev);
+
+ struct nios_uart *uart = priv->regs;
uint16_t div;
div = (CPU_FREQ / baudrate) - 1;
@@ -40,7 +48,10 @@ static int altera_serial_setbaudrate(struct console_device *cdev, int baudrate)
static void altera_serial_putc(struct console_device *cdev, char c)
{
- struct nios_uart *uart = (struct nios_uart *)cdev->dev->map_base;
+ struct altera_serial_priv *priv = container_of(cdev,
+ struct altera_serial_priv, cdev);
+
+ struct nios_uart *uart = priv->regs;
while ((readw(&uart->status) & NIOS_UART_TRDY) == 0);
@@ -49,14 +60,20 @@ static void altera_serial_putc(struct console_device *cdev, char c)
static int altera_serial_tstc(struct console_device *cdev)
{
- struct nios_uart *uart = (struct nios_uart *)cdev->dev->map_base;
+ struct altera_serial_priv *priv = container_of(cdev,
+ struct altera_serial_priv, cdev);
+
+ struct nios_uart *uart = priv->regs;
return readw(&uart->status) & NIOS_UART_RRDY;
}
static int altera_serial_getc(struct console_device *cdev)
{
- struct nios_uart *uart = (struct nios_uart *)cdev->dev->map_base;
+ struct altera_serial_priv *priv = container_of(cdev,
+ struct altera_serial_priv, cdev);
+
+ struct nios_uart *uart = priv->regs;
while (altera_serial_tstc(cdev) == 0);
@@ -66,8 +83,12 @@ static int altera_serial_getc(struct console_device *cdev)
static int altera_serial_probe(struct device_d *dev)
{
struct console_device *cdev;
+ struct altera_serial_priv *priv;
+
+ priv = xmalloc(sizeof(*priv));
+ cdev = &priv->cdev;
- cdev = xmalloc(sizeof(struct console_device));
+ priv->regs = dev_request_mem_region(dev, 0);
dev->type_data = cdev;
cdev->dev = dev;
cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
--
1.7.6
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] nios2/altera_serial_jtag: Switch to resources
2011-07-26 20:07 [PATCH v2] Switch nios2 devices to resources franck.jullien
` (2 preceding siblings ...)
2011-07-26 20:07 ` [PATCH 3/4] nios2/serial_altera: " franck.jullien
@ 2011-07-26 20:07 ` franck.jullien
2011-07-27 8:56 ` [PATCH v2] Switch nios2 devices " Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: franck.jullien @ 2011-07-26 20:07 UTC (permalink / raw)
To: barebox
From: Franck Jullien <franck.jullien@gmail.com>
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
---
drivers/serial/serial_altera_jtag.c | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/drivers/serial/serial_altera_jtag.c b/drivers/serial/serial_altera_jtag.c
index 322f9e9..2e34c89 100644
--- a/drivers/serial/serial_altera_jtag.c
+++ b/drivers/serial/serial_altera_jtag.c
@@ -30,6 +30,12 @@
#include <asm/io.h>
#include <asm/nios2-io.h>
+struct altera_serial_jtag_priv {
+ struct console_device cdev;
+ void __iomem *regs;
+};
+
+
static int altera_serial_jtag_setbaudrate(struct console_device *cdev, int baudrate)
{
return 0;
@@ -37,7 +43,10 @@ static int altera_serial_jtag_setbaudrate(struct console_device *cdev, int baudr
static void altera_serial_jtag_putc(struct console_device *cdev, char c)
{
- struct nios_jtag *jtag = (struct nios_jtag *)cdev->dev->map_base;
+ struct altera_serial_jtag_priv *priv = container_of(cdev,
+ struct altera_serial_jtag_priv, cdev);
+
+ struct nios_jtag *jtag = priv->regs;
uint32_t st;
while (1) {
@@ -51,14 +60,20 @@ static void altera_serial_jtag_putc(struct console_device *cdev, char c)
static int altera_serial_jtag_tstc(struct console_device *cdev)
{
- struct nios_jtag *jtag = (struct nios_jtag *)cdev->dev->map_base;
+ struct altera_serial_jtag_priv *priv = container_of(cdev,
+ struct altera_serial_jtag_priv, cdev);
+
+ struct nios_jtag *jtag = priv->regs;
return readl(&jtag->control) & NIOS_JTAG_RRDY;
}
static int altera_serial_jtag_getc(struct console_device *cdev)
{
- struct nios_jtag *jtag = (struct nios_jtag *)cdev->dev->map_base;
+ struct altera_serial_jtag_priv *priv = container_of(cdev,
+ struct altera_serial_jtag_priv, cdev);
+
+ struct nios_jtag *jtag = priv->regs;
uint32_t val;
while (1) {
@@ -73,8 +88,12 @@ static int altera_serial_jtag_getc(struct console_device *cdev)
static int altera_serial_jtag_probe(struct device_d *dev) {
struct console_device *cdev;
+ struct altera_serial_jtag_priv *priv;
+
+ priv = xmalloc(sizeof(*priv));
+ cdev = &priv->cdev;
- cdev = malloc(sizeof(struct console_device));
+ priv->regs = dev_request_mem_region(dev, 0);
dev->type_data = cdev;
cdev->dev = dev;
cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
--
1.7.6
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] Switch nios2 devices to resources
2011-07-26 20:07 [PATCH v2] Switch nios2 devices to resources franck.jullien
` (3 preceding siblings ...)
2011-07-26 20:07 ` [PATCH 4/4] nios2/altera_serial_jtag: " franck.jullien
@ 2011-07-27 8:56 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-27 8:56 UTC (permalink / raw)
To: franck.jullien; +Cc: barebox
On Tue, Jul 26, 2011 at 10:07:53PM +0200, franck.jullien@gmail.com wrote:
> From: Franck Jullien <franck.jullien@gmail.com>
>
> Switch nios2 devices to resources usage.
Applied to -next.
Thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread