A simple driver!

subhash at nmsu.edu subhash at nmsu.edu
Tue Mar 29 16:42:17 EST 2005


Hi,
I'm a master's student and just started to understand the linux pcmcia. I have
written a simple driver which registers as a client driver but the attach
routine is not running after i register the driver. Can u please see my code and
suggest me where did i make a mistake?
Thanks,
subhash.

-------------------------------CODE--------------------------------------
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <asm/io.h>

/* Include the pcmcia specific header files */
#include <pcmcia/version.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ds.h>
#include <pcmcia/cisreg.h>

#define PDBG(fmt,args...) printk(KERN_DEBUG "\nDBG: " fmt, ##args);

static char DRVNAME[]="testdriver";

static struct pcmcia_driver Zdriver = {
	.drv = { 
		.name = DRVNAME,
	},
	.attach = Zattach,
	.detach = Zdetach,
	.owner = THIS_MODULE,
};

static dev_info_t dev_info=DRIVERNAME;

static int pccard_basic_init_module(void)
{
	pcmcia_register_driver(&Zdriver);
	Zattach();
	PDBG("Module %s init",DRIVERNAME );	
	return 0;
}

static void pccard_basic_exit_module(void)
{
	PDBG("Module %s exit",DRIVERNAME );
	pcmcia_unregister_driver(&Zdriver);
}

void Zdetach(struct dev_link_t *link)
{
	int result=0;
	if (link->handle) {
		result=pcmcia_deregister_client((link->handle));
		if(result != 0)
			PDBG("Cannot deregister device!");
	}
}

dev_link_t *Zattach(void)
{
	client_reg_t		client_reg;
	int			result;
	dev_link_t		*link = NULL;
	PDBG("In Zattach");
	link =		kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
	if (!link)
	{
		PDBG("No memory");
		return NULL;
	}
	memset(link,0,sizeof(struct dev_link_t));
	client_reg.dev_info = &dev_info;
	client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
	client_reg.EventMask =
		CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
		CS_EVENT_RESET_REQUEST |
		CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
		CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
	client_reg.event_handler = &Zevent;
	client_reg.Version = 0x0100;
	client_reg.event_callback_args.client_data = link;
	result=pcmcia_register_client((&link->handle),&client_reg);
	if(result != 0)
	{
		PDBG("Cannot register client driver %s",DRIVERNAME);
		kfree(link);
		return NULL; 
	}
	return link;
}




static int Zevent (event_t event, int priority, event_callback_args_t *args)
{
	switch(event)
	{
		case	CS_EVENT_CARD_INSERTION:
			PDBG("Event: CS_EVENT_CARD_INSERTION");
			break;		
		case	CS_EVENT_CARD_REMOVAL:
			PDBG("Event: CS_EVENT_CARD_REMOVAL");
			break;
		case	CS_EVENT_RESET_REQUEST:
			PDBG("Event: CS_EVENT_RESET_REQUEST");	
			break;
		case	CS_EVENT_RESET_PHYSICAL:
			PDBG("Event: CS_EVENT_RESET_PHYSICAL");
			break;
		case	CS_EVENT_CARD_RESET:
			PDBG("Event: CS_EVENT_CARD_RESET");
			break;
		case	CS_EVENT_PM_SUSPEND:
			PDBG("Event: CS_EVENT_PM_SUSPEND");
			break;
		case	CS_EVENT_PM_RESUME:
			PDBG("Event: CS_EVENT_PM_RESUME");
			break;
		default:
			PDBG("Unknown event: %d",event);
			break;
	}
	return 0;
}



module_init(pccard_basic_init_module);
module_exit(pccard_basic_exit_module);








More information about the linux-pcmcia mailing list