mtd/drivers/mtd/maps pcmciamtd.c,1.45,1.46
David Woodhouse
dwmw2 at infradead.org
Wed May 28 08:50:54 EDT 2003
- Previous message: mtd/include/linux/mtd map.h,1.33,1.34
- Next message: mtd/drivers/mtd/chips cfi_cmdset_0001.c,1.122,1.123
cfi_cmdset_0002.c,1.73,1.74 cfi_cmdset_0020.c,1.5,1.6
cfi_probe.c,1.70,1.71 jedec.c,1.17,1.18 jedec_probe.c,1.27,1.28
map_absent.c,1.3,1.4 map_ram.c,1.16,1.17 map_rom.c,1.19,1.20
sharp.c,1.10,1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/mtd/drivers/mtd/maps
In directory phoenix.infradead.org:/tmp/cvs-serv30964
Modified Files:
pcmciamtd.c
Log Message:
Merge changes from 2.5
Index: pcmciamtd.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/pcmciamtd.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- pcmciamtd.c 21 May 2003 15:15:07 -0000 1.45
+++ pcmciamtd.c 28 May 2003 12:50:51 -0000 1.46
@@ -43,9 +43,9 @@
static const int debug = 0;
#endif
-#define err(format, arg...) printk(KERN_ERR "pcmciamtd: " format "\n" , ## arg)
-#define info(format, arg...) printk(KERN_INFO "pcmciamtd: " format "\n" , ## arg)
-#define warn(format, arg...) printk(KERN_WARNING "pcmciamtd: " format "\n" , ## arg)
+#define err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , ## arg)
#define DRIVER_DESC "PCMCIA Flash memory card driver"
@@ -55,20 +55,21 @@
#define MAX_PCMCIA_ADDR 0x4000000
struct pcmciamtd_dev {
+ struct list_head list;
dev_link_t link; /* PCMCIA link */
- dev_node_t node; /* device node */
caddr_t win_base; /* ioremapped address of PCMCIA window */
unsigned int win_size; /* size of window */
+ unsigned int cardsize; /* size of whole card */
unsigned int offset; /* offset into card the window currently points at */
struct map_info pcmcia_map;
struct mtd_info *mtd_info;
- int vpp;
+ u8 vpp;
char mtd_name[sizeof(struct cistpl_vers_1_t)];
};
static dev_info_t dev_info = "pcmciamtd";
-static dev_link_t *dev_list;
+static LIST_HEAD(dev_list);
/* Module parameters */
@@ -107,18 +108,7 @@
MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)");
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,69)
-static inline void cs_error(client_handle_t handle, int func, int ret)
-{
- error_info_t err = { func, ret };
- CardServices(ReportError, handle, &err);
-}
-#endif
-
-
/* read/write{8,16} copy_{from,to} routines with window remapping to access whole card */
-
static caddr_t remap_window(struct map_info *map, unsigned long to)
{
struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
@@ -126,11 +116,6 @@
memreq_t mrq;
int ret;
- if(!(dev->link.state & DEV_PRESENT)) {
- DEBUG(1, "device removed state = 0x%4.4X", dev->link.state);
- return 0;
- }
-
mrq.CardOffset = to & ~(dev->win_size-1);
if(mrq.CardOffset != dev->offset) {
DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x",
@@ -253,16 +238,11 @@
/* read/write{8,16} copy_{from,to} routines with direct access */
-#define DEV_REMOVED(x) (!(*(u_int *)x->map_priv_1 & DEV_PRESENT))
-
static u8 pcmcia_read8(struct map_info *map, unsigned long ofs)
{
caddr_t win_base = (caddr_t)map->map_priv_2;
u8 d;
- if(DEV_REMOVED(map))
- return 0;
-
d = readb(win_base + ofs);
DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02x", ofs, win_base + ofs, d);
return d;
@@ -274,9 +254,6 @@
caddr_t win_base = (caddr_t)map->map_priv_2;
u16 d;
- if(DEV_REMOVED(map))
- return 0;
-
d = readw(win_base + ofs);
DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04x", ofs, win_base + ofs, d);
return d;
@@ -287,9 +264,6 @@
{
caddr_t win_base = (caddr_t)map->map_priv_2;
- if(DEV_REMOVED(map))
- return;
-
DEBUG(3, "to = %p from = %lu len = %u", to, from, len);
memcpy_fromio(to, win_base + from, len);
}
@@ -299,9 +273,6 @@
{
caddr_t win_base = (caddr_t)map->map_priv_2;
- if(DEV_REMOVED(map))
- return;
-
DEBUG(3, "adr = 0x%08lx (%p) data = 0x%02x", adr, win_base + adr, d);
writeb(d, win_base + adr);
}
@@ -311,9 +282,6 @@
{
caddr_t win_base = (caddr_t)map->map_priv_2;
- if(DEV_REMOVED(map))
- return;
-
DEBUG(3, "adr = 0x%08lx (%p) data = 0x%04x", adr, win_base + adr, d);
writew(d, win_base + adr);
}
@@ -323,9 +291,6 @@
{
caddr_t win_base = (caddr_t)map->map_priv_2;
- if(DEV_REMOVED(map))
- return;
-
DEBUG(3, "to = %lu from = %p len = %u", to, from, len);
memcpy_toio(win_base + to, from, len);
}
@@ -358,18 +323,40 @@
static void pcmciamtd_release(u_long arg)
{
dev_link_t *link = (dev_link_t *)arg;
- struct pcmciamtd_dev *dev = link->priv;
+ struct pcmciamtd_dev *dev = NULL;
+ int ret;
+ struct list_head *temp1, *temp2;
DEBUG(3, "link = 0x%p", link);
+ /* Find device in list */
+ list_for_each_safe(temp1, temp2, &dev_list) {
+ dev = list_entry(temp1, struct pcmciamtd_dev, list);
+ if(link == &dev->link)
+ break;
+ }
+ if(link != &dev->link) {
+ DEBUG(1, "Cant find %p in dev_list", link);
+ return;
+ }
- if (link->win) {
- if(dev->win_base) {
- iounmap(dev->win_base);
- dev->win_base = NULL;
+ if(dev) {
+ if(dev->mtd_info) {
+ del_mtd_device(dev->mtd_info);
+ dev->mtd_info = NULL;
+ MOD_DEC_USE_COUNT;
+ }
+ if (link->win) {
+ if(dev->win_base) {
+ iounmap(dev->win_base);
+ dev->win_base = NULL;
+ }
+ CardServices(ReleaseWindow, link->win);
}
- CardServices(ReleaseWindow, link->win);
+ ret = CardServices(ReleaseConfiguration, link->handle);
+ if(ret != CS_SUCCESS)
+ cs_error(link->handle, ReleaseConfiguration, ret);
+
}
- CardServices(ReleaseConfiguration, link->handle);
link->state &= ~DEV_CONFIG;
}
@@ -478,6 +465,7 @@
if(force_size) {
dev->pcmcia_map.size = force_size << 20;
DEBUG(2, "size forced to %dM", force_size);
+
}
if(buswidth) {
@@ -592,8 +580,9 @@
}
DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x",
dev, req.Base, dev->win_base, req.Size);
-
+ dev->cardsize = 0;
dev->offset = 0;
+
dev->pcmcia_map.map_priv_1 = (unsigned long)dev;
dev->pcmcia_map.map_priv_2 = (unsigned long)link->win;
@@ -625,6 +614,9 @@
cs_error(link->handle, RequestConfiguration, ret);
}
+ link->dev = NULL;
+ link->state &= ~DEV_CONFIG_PENDING;
+
if(mem_type == 1) {
mtd = do_map_probe("map_ram", &dev->pcmcia_map);
} else if(mem_type == 2) {
@@ -648,6 +640,7 @@
dev->mtd_info = mtd;
mtd->owner = THIS_MODULE;
+ dev->cardsize = mtd->size;
if(new_name) {
int size = 0;
@@ -656,19 +649,19 @@
size */
if(mtd->size < 1048576) { /* <1MB in size, show size in K */
size = mtd->size >> 10;
- unit = 'K';
+ unit = 'K';
} else {
size = mtd->size >> 20;
unit = 'M';
}
- snprintf(dev->mtd_name, sizeof(dev->mtd_name), "%d%cB %s", size, unit, "PCMCIA Memory card");
+ sprintf(mtd->name, "%d%cB %s", size, unit, "PCMCIA Memory card");
}
/* If the memory found is fits completely into the mapped PCMCIA window,
use the faster non-remapping read/write functions */
- if(mtd->size <= dev->win_size) {
+ if(dev->cardsize <= dev->win_size) {
DEBUG(1, "Using non remapping memory functions");
- dev->pcmcia_map.map_priv_1 = (unsigned long)&(dev->link.state);
+
dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base;
dev->pcmcia_map.read8 = pcmcia_read8;
dev->pcmcia_map.read16 = pcmcia_read16;
@@ -678,17 +671,16 @@
dev->pcmcia_map.copy_to = pcmcia_copy_to;
}
+ MOD_INC_USE_COUNT;
if(add_mtd_device(mtd)) {
- map_destroy(mtd);
dev->mtd_info = NULL;
+ MOD_DEC_USE_COUNT;
err("Couldnt register MTD device");
pcmciamtd_release((u_long)link);
return;
}
- snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index);
- info("mtd%d: %s", mtd->index, mtd->name);
- link->state &= ~DEV_CONFIG_PENDING;
- link->dev = &dev->node;
+ DEBUG(1, "mtd added @ %p mtd->priv = %p", mtd, mtd->priv);
+
return;
cs_failed:
@@ -715,14 +707,8 @@
case CS_EVENT_CARD_REMOVAL:
DEBUG(2, "EVENT_CARD_REMOVAL");
link->state &= ~DEV_PRESENT;
- if (link->state & DEV_CONFIG) {
- struct pcmciamtd_dev *dev = link->priv;
- if(dev->mtd_info) {
- del_mtd_device(dev->mtd_info);
- info("mtd%d: Removed", dev->mtd_info->index);
- }
+ if (link->state & DEV_CONFIG)
mod_timer(&link->release, jiffies + HZ/20);
- }
break;
case CS_EVENT_CARD_INSERTION:
DEBUG(2, "EVENT_CARD_INSERTION");
@@ -760,23 +746,47 @@
static void pcmciamtd_detach(dev_link_t *link)
{
+ int ret;
+ struct pcmciamtd_dev *dev = NULL;
+ struct list_head *temp1, *temp2;
+
DEBUG(3, "link=0x%p", link);
+ /* Find device in list */
+ list_for_each_safe(temp1, temp2, &dev_list) {
+ dev = list_entry(temp1, struct pcmciamtd_dev, list);
+ if(link == &dev->link)
+ break;
+ }
+ if(link != &dev->link) {
+ DEBUG(1, "Cant find %p in dev_list", link);
+ return;
+ }
+
del_timer(&link->release);
- if(link->state & DEV_CONFIG) {
- pcmciamtd_release((u_long)link);
+ if(!dev) {
+ DEBUG(3, "dev is NULL");
+ return;
+ }
+
+ if (link->state & DEV_CONFIG) {
+ //pcmciamtd_release((u_long)link);
+ DEBUG(3, "DEV_CONFIG set");
+ link->state |= DEV_STALE_LINK;
+ return;
}
if (link->handle) {
- int ret;
DEBUG(2, "Deregistering with card services");
ret = CardServices(DeregisterClient, link->handle);
if (ret != CS_SUCCESS)
cs_error(link->handle, DeregisterClient, ret);
}
-
- link->state |= DEV_STALE_LINK;
+ DEBUG(3, "Freeing dev (%p)", dev);
+ list_del(&dev->list);
+ link->priv = NULL;
+ kfree(dev);
}
@@ -798,18 +808,15 @@
DEBUG(1, "dev=0x%p", dev);
memset(dev, 0, sizeof(*dev));
- link = &dev->link;
- link->priv = dev;
+ link = &dev->link; link->priv = dev;
- init_timer(&link->release);
link->release.function = &pcmciamtd_release;
link->release.data = (u_long)link;
link->conf.Attributes = 0;
link->conf.IntType = INT_MEMORY;
- link->next = dev_list;
- dev_list = link;
+ list_add(&dev->list, &dev_list);
/* Register with Card Services */
client_reg.dev_info = &dev_info;
@@ -828,23 +835,11 @@
pcmciamtd_detach(link);
return NULL;
}
- DEBUG(2, "link = %p", link);
+
return link;
}
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,68)
-static struct pcmcia_driver pcmciamtd_driver = {
- .drv = {
- .name = "pcmciamtd"
- },
- .attach = pcmciamtd_attach,
- .detach = pcmciamtd_detach,
- .owner = THIS_MODULE
-};
-#endif
-
-
static int __init init_pcmciamtd(void)
{
servinfo_t serv;
@@ -868,51 +863,22 @@
info("bad mem_type (%d), using default", mem_type);
mem_type = 0;
}
-
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,68)
- return pcmcia_register_driver(&pcmciamtd_driver);
-#else
register_pccard_driver(&dev_info, &pcmciamtd_attach, &pcmciamtd_detach);
return 0;
-#endif
}
static void __exit exit_pcmciamtd(void)
{
+ struct list_head *temp1, *temp2;
+
DEBUG(1, DRIVER_DESC " unloading");
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,68)
- pcmcia_unregister_driver(&pcmciamtd_driver);
-#else
unregister_pccard_driver(&dev_info);
-#endif
-
- while(dev_list) {
- dev_link_t *link = dev_list;
-
- dev_list = link->next;
- if (link) {
- struct pcmciamtd_dev *dev = link->priv;
-
- if(dev) {
- if(link->state & DEV_PRESENT) {
- if (!(link->state & DEV_STALE_LINK)) {
- pcmciamtd_detach(link);
- }
- link->state &= ~DEV_PRESENT;
- if(dev->mtd_info) {
- del_mtd_device(dev->mtd_info);
- info("mtd%d: Removed",
- dev->mtd_info->index);
- }
- }
- if(dev->mtd_info) {
- DEBUG(2, "Destroying map for mtd%d",
- dev->mtd_info->index);
- map_destroy(dev->mtd_info);
- }
- kfree(dev);
- }
+ list_for_each_safe(temp1, temp2, &dev_list) {
+ dev_link_t *link = &list_entry(temp1, struct pcmciamtd_dev, list)->link;
+ if (link && (link->state & DEV_CONFIG)) {
+ pcmciamtd_release((u_long)link);
+ pcmciamtd_detach(link);
}
}
}
- Previous message: mtd/include/linux/mtd map.h,1.33,1.34
- Next message: mtd/drivers/mtd/chips cfi_cmdset_0001.c,1.122,1.123
cfi_cmdset_0002.c,1.73,1.74 cfi_cmdset_0020.c,1.5,1.6
cfi_probe.c,1.70,1.71 jedec.c,1.17,1.18 jedec_probe.c,1.27,1.28
map_absent.c,1.3,1.4 map_ram.c,1.16,1.17 map_rom.c,1.19,1.20
sharp.c,1.10,1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the linux-mtd-cvs
mailing list