From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 05/23] dm9000: introduce add_dm9000_device to register dm9000 device
Date: Fri, 29 Jul 2011 17:59:46 +0200 [thread overview]
Message-ID: <1311955207-22372-9-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20110729155356.GF25658@game.jcrosoft.org>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
arch/arm/boards/at91sam9261ek/init.c | 25 +-------------
arch/arm/boards/mini2440/mini2440.c | 24 +-------------
arch/arm/boards/pm9261/init.c | 26 ++-------------
arch/arm/boards/scb9328/scb9328.c | 25 +-------------
drivers/base/resource.c | 57 +++++++++++++++++++++++++++++++--
drivers/net/dm9000.c | 3 +-
include/dm9000.h | 1 -
include/driver.h | 11 ++++++
8 files changed, 75 insertions(+), 97 deletions(-)
diff --git a/arch/arm/boards/at91sam9261ek/init.c b/arch/arm/boards/at91sam9261ek/init.c
index 812b399..627202f 100644
--- a/arch/arm/boards/at91sam9261ek/init.c
+++ b/arch/arm/boards/at91sam9261ek/init.c
@@ -89,31 +89,9 @@ static void ek_add_device_nand(void)
*/
#if defined(CONFIG_DRIVER_NET_DM9000)
static struct dm9000_platform_data dm9000_data = {
- .buswidth = IORESOURCE_MEM_16BIT,
.srom = 0,
};
-static struct resource dm9000_resources[] = {
- [0] = {
- .start = AT91_CHIPSELECT_2,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
- [1] = {
- .start = AT91_CHIPSELECT_2 + 4,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
-};
-
-static struct device_d dm9000_dev = {
- .id = 0,
- .name = "dm9000",
- .num_resources = ARRAY_SIZE(dm9000_resources),
- .resource = dm9000_resources,
- .platform_data = &dm9000_data,
-};
-
/*
* SMC timings for the DM9000.
* Note: These timings were calculated for MASTER_CLOCK = 100000000 according to the DM9000 timings.
@@ -147,7 +125,8 @@ static void __init ek_add_device_dm9000(void)
/* Configure Interrupt pin as input, no pull-up */
at91_set_gpio_input(AT91_PIN_PC11, 0);
- register_device(&dm9000_dev);
+ add_dm9000_device(0, AT91_CHIPSELECT_2, AT91_CHIPSELECT_2 + 4,
+ IORESOURCE_MEM_16BIT, &dm9000_data);
}
#else
static void __init ek_add_device_dm9000(void) {}
diff --git a/arch/arm/boards/mini2440/mini2440.c b/arch/arm/boards/mini2440/mini2440.c
index 634e035..dbf7503 100644
--- a/arch/arm/boards/mini2440/mini2440.c
+++ b/arch/arm/boards/mini2440/mini2440.c
@@ -63,30 +63,9 @@ static struct device_d nand_dev = {
* Area 2: Offset 0x304...0x307
*/
static struct dm9000_platform_data dm9000_data = {
- .buswidth = IORESOURCE_MEM_16BIT,
.srom = 1,
};
-static struct resource dm9000_resources[] = {
- [0] = {
- .start = CS4_BASE + 0x300,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
- [1] = {
- .start = CS4_BASE + 0x304,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
-};
-
-static struct device_d dm9000_dev = {
- .name = "dm9000",
- .num_resources = ARRAY_SIZE(dm9000_resources),
- .resource = dm9000_resources,
- .platform_data = &dm9000_data,
-};
-
static struct s3c_mci_platform_data mci_data = {
.caps = MMC_MODE_4BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz,
.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
@@ -332,7 +311,8 @@ static int mini2440_devices_init(void)
IORESOURCE_MEM_WRITEABLE);
armlinux_add_dram(sdram_dev);
- register_device(&dm9000_dev);
+ add_dm9000_device(0, CS4_BASE + 0x300, CS4_BASE + 0x304,
+ IORESOURCE_MEM_16BIT, &dm9000_data);
#ifdef CONFIG_NAND
/* ----------- add some vital partitions -------- */
devfs_del_partition("self_raw");
diff --git a/arch/arm/boards/pm9261/init.c b/arch/arm/boards/pm9261/init.c
index fa21e24..783a404 100644
--- a/arch/arm/boards/pm9261/init.c
+++ b/arch/arm/boards/pm9261/init.c
@@ -89,31 +89,9 @@ static void pm_add_device_nand(void)
*/
#if defined(CONFIG_DRIVER_NET_DM9000)
static struct dm9000_platform_data dm9000_data = {
- .buswidth = IORESOURCE_MEM_16BIT,
.srom = 1,
};
-static struct resource dm9000_resources[] = {
- [0] = {
- .start = AT91_CHIPSELECT_2,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
- [1] = {
- .start = AT91_CHIPSELECT_2 + 4,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
-};
-
-static struct device_d dm9000_dev = {
- .id = 0,
- .name = "dm9000",
- .num_resources = ARRAY_SIZE(dm9000_resources),
- .resource = dm9000_resources,
- .platform_data = &dm9000_data,
-};
-
/*
* SMC timings for the DM9000.
* Note: These timings were calculated for MASTER_CLOCK = 100000000 according to the DM9000 timings.
@@ -141,7 +119,8 @@ static void __init pm_add_device_dm9000(void)
/* Configure chip-select 2 (DM9000) */
sam9_smc_configure(2, &dm9000_smc_config);
- register_device(&dm9000_dev);
+ add_dm9000_device(0, AT91_CHIPSELECT_2, AT91_CHIPSELECT_2 + 4,
+ IORESOURCE_MEM_16BIT, &dm9000_data);
}
#else
static void __init ek_add_device_dm9000(void) {}
@@ -151,6 +130,7 @@ static int pm9261_devices_init(void)
{
at91_add_device_sdram(64 * 1024 * 1024);
pm_add_device_nand();
+ pm_add_device_dm9000();
add_cfi_flash_device(0, AT91_CHIPSELECT_0, 4 * 1024 * 1024, 0);
devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self");
diff --git a/arch/arm/boards/scb9328/scb9328.c b/arch/arm/boards/scb9328/scb9328.c
index 4c0ed02..5c52af9 100644
--- a/arch/arm/boards/scb9328/scb9328.c
+++ b/arch/arm/boards/scb9328/scb9328.c
@@ -35,31 +35,9 @@
#include <mach/devices-imx1.h>
static struct dm9000_platform_data dm9000_data = {
- .buswidth = IORESOURCE_MEM_16BIT,
.srom = 1,
};
-static struct resource dm9000_resources[] = {
- [0] = {
- .start = 0x16000000,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
- [1] = {
- .start = 0x16000004,
- .size = 4,
- .flags = IORESOURCE_MEM,
- },
-};
-
-static struct device_d dm9000_dev = {
- .id = -1,
- .name = "dm9000",
- .num_resources = ARRAY_SIZE(dm9000_resources),
- .resource = dm9000_resources,
- .platform_data = &dm9000_data,
-};
-
struct gpio_led leds[] = {
{
.gpio = 32 + 21,
@@ -107,7 +85,8 @@ static int scb9328_devices_init(void)
sdram_dev = add_mem_device("ram0", 0x08000000, 16 * 1024 * 1024,
IORESOURCE_MEM_WRITEABLE);
armlinux_add_dram(sdram_dev);
- register_device(&dm9000_dev);
+ add_dm9000_device(-1, 0x16000000, 0x16000004,
+ IORESOURCE_MEM_16BIT, &dm9000_data);
devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self0");
devfs_add_partition("nor0", 0x40000, 0x20000, PARTITION_FIXED, "env0");
diff --git a/drivers/base/resource.c b/drivers/base/resource.c
index f0450d3..98fc68a 100644
--- a/drivers/base/resource.c
+++ b/drivers/base/resource.c
@@ -25,15 +25,25 @@
#include <driver.h>
#include <xfuncs.h>
-struct device_d *add_generic_device(const char* devname, int id, const char *resname,
- resource_size_t start, resource_size_t size, unsigned int flags,
- void *pdata)
+static struct device_d *alloc_device(const char* devname, int id, void *pdata)
{
struct device_d *dev;
dev = xzalloc(sizeof(*dev));
strcpy(dev->name, devname);
dev->id = id;
+ dev->platform_data = pdata;
+
+ return dev;
+}
+
+struct device_d *add_generic_device(const char* devname, int id, const char *resname,
+ resource_size_t start, resource_size_t size, unsigned int flags,
+ void *pdata)
+{
+ struct device_d *dev;
+
+ dev = alloc_device(devname, id, pdata);
dev->resource = xzalloc(sizeof(struct resource));
dev->num_resources = 1;
if (resname)
@@ -41,10 +51,49 @@ struct device_d *add_generic_device(const char* devname, int id, const char *res
dev->resource[0].start = start;
dev->resource[0].size = size;
dev->resource[0].flags = flags;
- dev->platform_data = pdata;
register_device(dev);
return dev;
}
EXPORT_SYMBOL(add_generic_device);
+
+#ifdef CONFIG_DRIVER_NET_DM9000
+struct device_d *add_dm9000_device(int id, resource_size_t base,
+ resource_size_t data, int flags, void *pdata)
+{
+ struct device_d *dev;
+ resource_size_t size;
+
+ dev = alloc_device("dm9000", id, pdata);
+ dev->resource = xzalloc(sizeof(struct resource) * 2);
+ dev->num_resources = 2;
+
+ switch (flags) {
+ case IORESOURCE_MEM_32BIT:
+ size = 8;
+ break;
+ case IORESOURCE_MEM_16BIT:
+ size = 4;
+ break;
+ case IORESOURCE_MEM_8BIT:
+ size = 2;
+ break;
+ default:
+ printf("dm9000: memory width flag missing\n");
+ return NULL;
+ }
+
+ dev->resource[0].start = base;
+ dev->resource[0].size = size;
+ dev->resource[0].flags = IORESOURCE_MEM | flags;
+ dev->resource[1].start = data;
+ dev->resource[1].size = size;
+ dev->resource[1].flags = IORESOURCE_MEM | flags;
+
+ register_device(dev);
+
+ return dev;
+}
+EXPORT_SYMBOL(add_dm9000_device);
+#endif
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 691d877..be14317 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -500,7 +500,8 @@ static int dm9000_probe(struct device_d *dev)
pdata = dev->platform_data;
priv = edev->priv;
- priv->buswidth = pdata->buswidth;
+
+ priv->buswidth = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
priv->iodata = dev_request_mem_region(dev, 1);
priv->iobase = dev_request_mem_region(dev, 0);
priv->srom = pdata->srom;
diff --git a/include/dm9000.h b/include/dm9000.h
index c4618f1..a9a4635 100644
--- a/include/dm9000.h
+++ b/include/dm9000.h
@@ -3,7 +3,6 @@
#define __DM9000_H__
struct dm9000_platform_data {
- int buswidth;
int srom;
};
diff --git a/include/driver.h b/include/driver.h
index 9f00754..38c0bca 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -235,6 +235,17 @@ static inline struct device_d *add_ns16550_device(int id, resource_size_t start,
IORESOURCE_MEM, pdata);
}
+#ifdef CONFIG_DRIVER_NET_DM9000
+struct device_d *add_dm9000_device(int id, resource_size_t base,
+ resource_size_t data, int flags, void *pdata);
+#else
+static inline struct device_d *add_dm9000_device(int id, resource_size_t base,
+ resource_size_t data, int flags, void *pdata)
+{
+ return NULL;
+}
+#endif
+
/* linear list over all available devices
*/
extern struct list_head device_list;
--
1.7.5.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2011-07-29 16:17 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-29 15:53 [PULL] final switch to resoruce Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 01/23] eukrea_cpuimx35: fix warning: 'usbotg_dev' defined but not used Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 1/7] generic_memmap_ro/rw: switch to resource Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 2/7] devinfo: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 02/23] generic_memmap_ro/rw: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 03/23] devinfo: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 3/7] dm9000: replace DM9000_WIDTH_8/16/32 by IORESOURCE_MEM_8/16/32BIT Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 4/7] dm9000: introduce add_dm9000_device to register dm9000 device Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 04/23] dm9000: replace DM9000_WIDTH_8/16/32 by IORESOURCE_MEM_8/16/32BIT Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2011-07-29 15:59 ` [PATCH 5/7] resource: introduce add_usb_ehci_device to register echi device Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 6/7] omap: switch to add_generic_device Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 06/23] resource: introduce add_usb_ehci_device to register echi device Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 7/7] fb: switch to "struct resource" Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 07/23] omap: switch to add_generic_device Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 08/23] fb: switch to "struct resource" Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 09/23] cfi_flash: convert missing map_base Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 10/23] fsl_udc: switch to resource Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 11/23] pcm030: switch to resources Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 12/23] ipe337: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-29 15:59 ` [PATCH 13/23] s3c/boards: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 14/23] ns16550: if not specific f_caps defined use default stdin, stdout, stderr Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 15/23] edb93xx: switch to resource Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 16/23] netx: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 17/23] fs: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 18/23] ata: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 19/23] sandbox: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 20/23] imx: switch remaing board " Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 21/23] mci-core: switch " Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 7:32 ` Sascha Hauer
2011-08-01 7:47 ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 8:09 ` Sascha Hauer
2011-08-01 8:03 ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 8:21 ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 8:53 ` Sascha Hauer
2011-07-30 3:17 ` [PATCH 22/23] nios2: remove dead code in generic board Jean-Christophe PLAGNIOL-VILLARD
2011-07-30 3:17 ` [PATCH 23/23] driver: remove map_base Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 10:45 ` [PULL] final switch to resoruce Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 12:11 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1311955207-22372-9-git-send-email-plagnioj@jcrosoft.com \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox