Blackfin BF5xx Maps: Handle the case where flash memory and ethernet mac/phy are mapped onto the same async bank
PATCH 1/1 Blackfin BF5xx Maps: Handle the case where flash memory and ethernet mac/phy are mapped onto the same async bank
Quoted 1 line
From
974192a0bf168e84370377b835a2858948789088Mon Sep 17 00:00:00 2001
From: Bryan Wu <[email protected]>
Date: Sun, 3 Feb 2008 14:27:09 +0800
Subject: [PATCH] [MTD/MAPS] Blackfin BF5xx Maps: Handle the case where flash memory and ethernet mac/phy are mapped onto the same async bank
[try #1]
The BF533-STAMP does this for example.
All board-specific configuration goes in your board resources file.
[try #2]
Remove useless SSYNC() as Will said
--- drivers/mtd/maps/Kconfig | 45 ++++++++ drivers/mtd/maps/Makefile | 1 + drivers/mtd/maps/bf5xx-flash.c | 227 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 273 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/maps/bf5xx-flash.c
drivers/mtd/maps/Kconfig +45 -0
@@ -528,6 +528,51 @@ config MTD_PCMCIA_ANONYMOUS If unsure, say N. +config MTD_BF5xx + tristate "Blackfin BF533-STAMP Flash Chip Support" + depends on BFIN533_STAMP && MTD_CFI + select MTD_PARTITIONS + help + Map driver which allows for simultaneous utilization of + ethernet and CFI parallel flash. + +config BFIN_FLASH_BANK_0 + hex "EBIU_AMBCTL For Flash (Bank 0)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. +config BFIN_FLASH_BANK_1 + hex "EBIU_AMBCTL For Flash (Bank 1)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. +config BFIN_FLASH_BANK_2 + hex "EBIU_AMBCTL For Flash (Bank 2)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. +config BFIN_FLASH_BANK_3 + hex "EBIU_AMBCTL For Flash (Bank 3)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. + config MTD_UCLINUX tristate "Generic uClinux RAM/ROM filesystem support" depends on MTD_PARTITIONS && !MMU
drivers/mtd/maps/Makefile +1 -0
@@ -69,3 +69,4 @@ obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o obj-$(CONFIG_MTD_MTX1) += mtx-1_flash.o obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o +obj-$(CONFIG_MTD_BF5xx) += bf5xx-flash.o
drivers/mtd/maps/bf5xx-flash.c new file +227 -0
227 lines not on this page · raw message
Signature · 1 line
1.5.3.4
Hi David and Will,
Is this patch OK for you? Thanks a lot
Regards,
-Bryan
Quoted 328 lines · Bryan Wu
Quoted 1 line
From
974192a0bf168e84370377b835a2858948789088Mon Sep 17 00:00:00 2001From: Bryan Wu <[email protected]>
Date: Sun, 3 Feb 2008 14:27:09 +0800
Subject: [PATCH] [MTD/MAPS] Blackfin BF5xx Maps: Handle the case where flash memory and ethernet mac/phy are mapped onto the same async bank[try #1]
The BF533-STAMP does this for example.
All board-specific configuration goes in your board resources file.[try #2]
Remove uselessSSYNC()as Will saidSigned-off-by Mike Frysinger <[email protected]>Signed-off-by Bryan Wu <[email protected]>--- drivers/mtd/maps/Kconfig | 45 ++++++++ drivers/mtd/maps/Makefile | 1 + drivers/mtd/maps/bf5xx-flash.c | 227 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 273 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/maps/bf5xx-flash.cdrivers/mtd/maps/Kconfig +45
-0@@ -528,6 +528,51 @@ config MTD_PCMCIA_ANONYMOUS If unsure, say N. +config MTD_BF5xx + tristate "Blackfin BF533-STAMP Flash Chip Support" + depends on BFIN533_STAMP && MTD_CFI + select MTD_PARTITIONS + help + Map driver which allows for simultaneous utilization of + ethernet and CFI parallel flash. + +config BFIN_FLASH_BANK_0 + hex "EBIU_AMBCTL For Flash (Bank 0)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. +config BFIN_FLASH_BANK_1 + hex "EBIU_AMBCTL For Flash (Bank 1)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. +config BFIN_FLASH_BANK_2 + hex "EBIU_AMBCTL For Flash (Bank 2)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. +config BFIN_FLASH_BANK_3 + hex "EBIU_AMBCTL For Flash (Bank 3)" + depends on MTD_BF5xx + default 0x7BB0 + help + For boards that share the async memory bank with both Flash and + the Ethernet, these settings allow you to have EBIU settings just + when the Flash is active. The other EBIU settings in the main + Blackfin menu will be utilized when the Flash is not active. + config MTD_UCLINUX tristate "Generic uClinux RAM/ROM filesystem support" depends on MTD_PARTITIONS && !MMUdrivers/mtd/maps/Makefile +1
-0@@ -69,3 +69,4 @@ obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o obj-$(CONFIG_MTD_MTX1) += mtx-1_flash.o obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o +obj-$(CONFIG_MTD_BF5xx) += bf5xx-flash.odrivers/mtd/maps/bf5xx-flash.c new file +227
-1@@ -0,0 +1,227 @@ +/* +* drivers/mtd/maps/bf5xx-flash.c +* +* Handle the case where flash memory and ethernet mac/phy are +* mapped onto the same async bank. The BF533-STAMP does this +* for example. All board-specific configuration goes in your +* board resources file. +* +* Copyright 2000 Nicolas Pitre <[email protected]> +* Copyright 2005-2008 Analog Devices Inc. +* +* Enter bugs at http://blackfin.uclinux.org/ +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mtd/mtd.h> +#include <linux/mtd/map.h> +#include <linux/mtd/partitions.h> +#include <linux/mtd/physmap.h> +#include <linux/platform_device.h> +#include <linux/types.h> + +#include <asm/blackfin.h> +#include <asm/gpio.h> +#include <asm/io.h> +#include <asm/unaligned.h> + +#define pr_init(fmt, args...) ({ static const __initdata char __fmt[] = fmt; printk(__fmt, ## args); }) + +#define DRIVER_NAME "BF5xx-Flash" + +#define BFIN_FLASH_AMBCTL0VAL ((CONFIG_BFIN_FLASH_BANK_1 << 16) | CONFIG_BFIN_FLASH_BANK_0) +#define BFIN_FLASH_AMBCTL1VAL ((CONFIG_BFIN_FLASH_BANK_3 << 16) | CONFIG_BFIN_FLASH_BANK_2) + +/* Should add a per-device structure and track this there ... */ +static int enet_flash_pin; +static struct mtd_info *bf5xx_mtd; + +struct flash_save { +u32 ambctl0; +u32 ambctl1; +unsigned long flags; +}; + +static void switch_to_flash (struct flash_save *save) +{ +local_irq_save (save->flags); + +gpio_set_value (enet_flash_pin,0 ); + + save->ambctl0 =bfin_read_EBIU_AMBCTL0 (); + save->ambctl1 =bfin_read_EBIU_AMBCTL1 (); +bfin_write_EBIU_AMBCTL0 (BFIN_FLASH_AMBCTL0VAL ); +bfin_write_EBIU_AMBCTL1 (BFIN_FLASH_AMBCTL1VAL ); +SSYNC (); +} + +static void switch_back (struct flash_save *save) +{ +bfin_write_EBIU_AMBCTL0 (save->ambctl0); +bfin_write_EBIU_AMBCTL1 (save->ambctl1); +SSYNC (); + +gpio_set_value (enet_flash_pin,1 ); + +local_irq_restore (save->flags); +} + +static map_word bf5xx_read (struct map_info *map,unsigned long ofs) +{ +int nValue =0x0 ; +map_word test; +struct flash_save save; + +switch_to_flash (&save); + + nValue =readw (map->virt + ofs); +SSYNC (); + +switch_back (&save); + + test.x[0 ] = (u16 )nValue; +return test; +} + +static void bf5xx_copy_from (struct map_info *map,void *to,unsigned long from,ssize_t len) +{ +unsigned long i; +map_word test; + +if ((unsigned long )to &0x1 ) { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); +put_unaligned (test.x[0 ], (__le16 *)(to + i)); + } + }else { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); + *((u16 *)(to + i)) = test.x[0 ]; + } + } + +if (len &0x1 ) { + test =bf5xx_read (map, from + i); + *((u8 *)(to + i)) = (u8 )test.x[0 ]; + } +} + +static void bf5xx_write (struct map_info *map,map_word d1,unsigned long ofs) +{ +u16 d; +struct flash_save save; + + d = (u16 )d1.x[0 ]; + +switch_to_flash (&save); + +writew (d, map->virt + ofs); +SSYNC (); + +switch_back (&save); +} + +static void bf5xx_copy_to (struct map_info *map,unsigned long to,const void *from,ssize_t len) +{ +struct flash_save save; + +switch_to_flash (&save); + +memcpy (map->virt + to, from, len); +SSYNC (); + +switch_back (&save); +} + +static struct map_info bf5xx_map = { + .name =DRIVER_NAME , + .read = bf5xx_read, + .copy_from = bf5xx_copy_from, + .write = bf5xx_write, + .copy_to = bf5xx_copy_to, +}; + +#ifdef CONFIG_MTD_PARTITIONS +static const char *part_probe_types[] = {"cmdlinepart" ,"RedBoot" ,NULL }; +#endif + +static int __init bf5xx_flash_probe (struct platform_device *dev) +{ +int ret; +struct physmap_flash_data *pdata = dev->dev.platform_data; +struct resource *memory =platform_get_resource (dev,IORESOURCE_MEM ,0 ); + + enet_flash_pin =platform_get_irq (dev,0 ); + + bf5xx_map.bankwidth = pdata->width; + bf5xx_map.size = memory->end - memory->start +1 ; + bf5xx_map.virt = (void __iomem *)memory->start; + bf5xx_map.phys = memory->start; + +if (gpio_request (enet_flash_pin,DRIVER_NAME )) { + pr_init(KERN_ERR DRIVER_NAME ": Failed to request gpio %d\n", enet_flash_pin); +return -EBUSY ; + } +gpio_direction_output (enet_flash_pin,1 ); + + pr_init(KERN_NOTICE DRIVER_NAME ": probing %d-bit flash bus\n", bf5xx_map.bankwidth * 8); + bf5xx_mtd =do_map_probe (memory->name, &bf5xx_map); +if (!bf5xx_mtd) +return -ENXIO ; + +#ifdef CONFIG_MTD_PARTITIONS + ret =parse_mtd_partitions (bf5xx_mtd, part_probe_types, &pdata->parts,0 ); +if (ret >0 ) { + pr_init(KERN_NOTICE DRIVER_NAME ": Using commandline partition definition\n"); +add_mtd_partitions (bf5xx_mtd, pdata->parts, ret); + + }else if (pdata->nr_parts) { + pr_init(KERN_NOTICE DRIVER_NAME ": Using board partition definition\n"); +add_mtd_partitions (bf5xx_mtd, pdata->parts, pdata->nr_parts); + + } else +#endif + { + pr_init(KERN_NOTICE DRIVER_NAME ": no partition info available, registering whole flash at once\n"); +add_mtd_device (bf5xx_mtd); + } + +return 0 ; +} + +static int __devexit bf5xx_flash_remove(struct platform_device *dev) +{ +gpio_free (enet_flash_pin); +#ifdef CONFIG_MTD_PARTITIONS +del_mtd_partitions (bf5xx_mtd); +#endif +map_destroy (bf5xx_mtd); +return 0 ; +} + +static struct platform_driver bf5xx_flash_driver = { + .probe = bf5xx_flash_probe, + .remove =__devexit_p (bf5xx_flash_remove), + .driver = { + .name =DRIVER_NAME , + }, +}; + +static int __init bf5xx_flash_init (void ) +{ +return platform_driver_register (&bf5xx_flash_driver); +} +module_init (bf5xx_flash_init); + +static void __exit bf5xx_flash_exit(void) +{ +platform_driver_unregister (&bf5xx_flash_driver); +} +module_exit (bf5xx_flash_exit); + +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MTD map driver for Blackfins with flash/ethernet on same async bank" ); --1.5.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 5 lines · Bryan Wu
drivers/mtd/maps/bf5xx-flash.c new file +5
-0+ +static void bf5xx_copy_from (struct map_info *map,void *to,unsigned long from,ssize_t len) +{ +unsigned long i; +map_word test;
drivers/mtd/maps/bf5xx-flash.c line 103
Quoted 10 lines
drivers/mtd/maps/bf5xx-flash.c new file +10
-0+ +if ((unsigned long )to &0x1 ) { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); +put_unaligned (test.x[0 ], (__le16 *)(to + i)); + } + }else { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); + *((u16 *)(to + i)) = test.x[0 ];
^^^^^^^^^^^^^^^^^
I'm not particularly fond of such constructs, maybe because I have such a hard time understanding what the code actually does.
How about:
u16 *foo = to;
for (i = 0; i < (len & ~1); i++) {
test = bf5xx_read(map, from + 2 * i);
foo[i] = test.x[0];
}With perhaps a better name than "foo" and the same conversion in the rest of the function as well?
drivers/mtd/maps/bf5xx-flash.c line 111
Quoted 8 lines
drivers/mtd/maps/bf5xx-flash.c new file +8
-0+ } + } + +if (len &0x1 ) { + test =bf5xx_read (map, from + i); + *((u8 *)(to + i)) = (u8 )test.x[0 ]; + } +}
Jörn
Signature · 3 lines
There's nothing better for promoting creativity in a medium than making an audience feel "Hmm I could do better than that!" -- Douglas Adams in a slashdot interview
Quoted 2 lines · Jörn Engel
Quoted 1 line · Bryan Wu
+static void bf5xx_copy_from(struct
map_info*map, void *to,
unsigned long from, ssize_t len)
Quoted 26 lines
drivers/mtd/maps/bf5xx-flash.c line 103
Quoted 13 lines
drivers/mtd/maps/bf5xx-flash.c new file +13
-0+{ +unsigned long i; +map_word test; + +if ((unsigned long )to &0x1 ) { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); +put_unaligned (test.x[0 ], (__le16 *)(to + i)); + } + }else { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); + *((u16 *)(to + i)) = test.x[0 ];^^^^^^^^^^^^^^^^^I'm not particularly fond of such constructs, maybe because I have such a hard time understanding what the code actually does.
How about:
u16 *foo = to; for (i = 0; i < (len & ~1); i++) { test = bf5xx_read(map, from + 2 * i); foo[i] = test.x[0]; }
Quoted 2 lines
With perhaps a better name than "foo" and the same conversion in the rest of the function as well?
indeed. Bryan: i can take care of this as there's a few other pieces i want to fiddle first (like getting rid of "bf5xx")
-mike
Quoted 30 lines · Mike Frysinger
Quoted 2 lines · Jörn Engel
Quoted 1 line · Bryan Wu
+static void bf5xx_copy_from(struct
map_info*map, void *to,unsigned long from,
ssize_tlen)Quoted 26 lines
drivers/mtd/maps/bf5xx-flash.c line 103
Quoted 13 lines
drivers/mtd/maps/bf5xx-flash.c new file +13
-0+{ +unsigned long i; +map_word test; + +if ((unsigned long )to &0x1 ) { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); +put_unaligned (test.x[0 ], (__le16 *)(to + i)); + } + }else { +for (i =0 ; i < len /2 *2 ; i +=2 ) { + test =bf5xx_read (map, from + i); + *((u16 *)(to + i)) = test.x[0 ];^^^^^^^^^^^^^^^^^I'm not particularly fond of such constructs, maybe because I have such a hard time understanding what the code actually does.
How about:
u16 *foo = to; for (i = 0; i < (len & ~1); i++) { test = bf5xx_read(map, from + 2 * i); foo[i] = test.x[0]; }
Quoted 7 lines
Quoted 2 lines
With perhaps a better name than "foo" and the same conversion in the rest of the function as well?
indeed. Bryan: i can take care of this as there's a few other pieces i want to fiddle first (like getting rid of "bf5xx")
-mike
My pleasure. Thanks.
This patch has been in my queue for a long time
-Bryan