| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* $Id: avm_cs.c,v 1.4.6.3 2001/09/23 22:24:33 kai Exp $
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * A PCMCIA client driver for AVM B1/M1/M2 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 1999 by Carsten Paeth <calle@calle.de> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This software may be used and distributed according to the terms | 
					
						
							|  |  |  |  * of the GNU General Public License, incorporated herein by reference. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | #include <linux/ptrace.h>
 | 
					
						
							|  |  |  | #include <linux/string.h>
 | 
					
						
							|  |  |  | #include <linux/tty.h>
 | 
					
						
							|  |  |  | #include <linux/serial.h>
 | 
					
						
							|  |  |  | #include <linux/major.h>
 | 
					
						
							|  |  |  | #include <asm/io.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <pcmcia/cistpl.h>
 | 
					
						
							|  |  |  | #include <pcmcia/ciscode.h>
 | 
					
						
							|  |  |  | #include <pcmcia/ds.h>
 | 
					
						
							|  |  |  | #include <pcmcia/cisreg.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/skbuff.h>
 | 
					
						
							|  |  |  | #include <linux/capi.h>
 | 
					
						
							|  |  |  | #include <linux/b1lli.h>
 | 
					
						
							|  |  |  | #include <linux/b1pcmcia.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*====================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_DESCRIPTION("CAPI4Linux: PCMCIA client driver for AVM B1/M1/M2"); | 
					
						
							|  |  |  | MODULE_AUTHOR("Carsten Paeth"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*====================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | static int avmcs_config(struct pcmcia_device *link); | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | static void avmcs_release(struct pcmcia_device *link); | 
					
						
							| 
									
										
										
										
											2005-11-14 21:23:14 +01:00
										 |  |  | static void avmcs_detach(struct pcmcia_device *p_dev); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | static int avmcs_probe(struct pcmcia_device *p_dev) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	/* General socket configuration */ | 
					
						
							|  |  |  | 	p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; | 
					
						
							|  |  |  | 	p_dev->config_index = 1; | 
					
						
							|  |  |  | 	p_dev->config_regs = PRESENT_OPTION; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	return avmcs_config(p_dev); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } /* avmcs_attach */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | static void avmcs_detach(struct pcmcia_device *link) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-14 21:23:14 +01:00
										 |  |  | 	avmcs_release(link); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } /* avmcs_detach */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-30 13:13:46 +02:00
										 |  |  | static int avmcs_configcheck(struct pcmcia_device *p_dev, void *priv_data) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-30 13:13:46 +02:00
										 |  |  | 	p_dev->resource[0]->end = 16; | 
					
						
							|  |  |  | 	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; | 
					
						
							|  |  |  | 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; | 
					
						
							| 
									
										
										
										
											2008-07-29 08:38:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-24 17:23:51 +02:00
										 |  |  | 	return pcmcia_request_io(p_dev); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | static int avmcs_config(struct pcmcia_device *link) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	int i = -1; | 
					
						
							|  |  |  | 	char devname[128]; | 
					
						
							|  |  |  | 	int cardtype; | 
					
						
							|  |  |  | 	int (*addcard)(unsigned int port, unsigned irq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	devname[0] = 0; | 
					
						
							|  |  |  | 	if (link->prod_id[1]) | 
					
						
							|  |  |  | 		strlcpy(devname, link->prod_id[1], sizeof(devname)); | 
					
						
							| 
									
										
										
										
											2006-01-15 10:05:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	 * find IO port | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (pcmcia_loop_config(link, avmcs_configcheck, NULL)) | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		if (!link->irq) { | 
					
						
							|  |  |  | 			/* undo */ | 
					
						
							|  |  |  | 			pcmcia_disable_device(link); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * configure the PCMCIA socket | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		i = pcmcia_enable_device(link); | 
					
						
							|  |  |  | 		if (i != 0) { | 
					
						
							|  |  |  | 			pcmcia_disable_device(link); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} while (0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (devname[0]) { | 
					
						
							|  |  |  | 		char *s = strrchr(devname, ' '); | 
					
						
							|  |  |  | 		if (!s) | 
					
						
							|  |  |  | 			s = devname; | 
					
						
							|  |  |  | 		else s++; | 
					
						
							|  |  |  | 		if (strcmp("M1", s) == 0) { | 
					
						
							|  |  |  | 			cardtype = AVM_CARDTYPE_M1; | 
					
						
							|  |  |  | 		} else if (strcmp("M2", s) == 0) { | 
					
						
							|  |  |  | 			cardtype = AVM_CARDTYPE_M2; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			cardtype = AVM_CARDTYPE_B1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		cardtype = AVM_CARDTYPE_B1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If any step failed, release any partially configured state */ | 
					
						
							| 
									
										
										
										
											2008-08-03 10:07:45 +02:00
										 |  |  | 	if (i != 0) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		avmcs_release(link); | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	switch (cardtype) { | 
					
						
							|  |  |  | 	case AVM_CARDTYPE_M1: addcard = b1pcmcia_addcard_m1; break; | 
					
						
							|  |  |  | 	case AVM_CARDTYPE_M2: addcard = b1pcmcia_addcard_m2; break; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ((i = (*addcard)(link->resource[0]->start, link->irq)) < 0) { | 
					
						
							|  |  |  | 		dev_err(&link->dev, | 
					
						
							|  |  |  | 			"avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n", | 
					
						
							|  |  |  | 			(unsigned int) link->resource[0]->start, link->irq); | 
					
						
							|  |  |  | 		avmcs_release(link); | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | } /* avmcs_config */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | static void avmcs_release(struct pcmcia_device *link) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-24 15:58:54 +02:00
										 |  |  | 	b1pcmcia_delcard(link->resource[0]->start, link->irq); | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | 	pcmcia_disable_device(link); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } /* avmcs_release */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 19:29:01 -07:00
										 |  |  | static const struct pcmcia_device_id avmcs_ids[] = { | 
					
						
							| 
									
										
										
										
											2005-06-27 16:28:35 -07:00
										 |  |  | 	PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335), | 
					
						
							|  |  |  | 	PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430), | 
					
						
							|  |  |  | 	PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a), | 
					
						
							|  |  |  | 	PCMCIA_DEVICE_NULL | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | MODULE_DEVICE_TABLE(pcmcia, avmcs_ids); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static struct pcmcia_driver avmcs_driver = { | 
					
						
							|  |  |  | 	.owner	= THIS_MODULE, | 
					
						
							| 
									
										
										
										
											2010-08-08 11:36:26 +02:00
										 |  |  | 	.name		= "avm_cs", | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | 	.probe = avmcs_probe, | 
					
						
							| 
									
										
										
										
											2005-11-14 21:23:14 +01:00
										 |  |  | 	.remove	= avmcs_detach, | 
					
						
							| 
									
										
										
										
											2005-06-27 16:28:35 -07:00
										 |  |  | 	.id_table = avmcs_ids, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-03-06 11:26:50 -07:00
										 |  |  | module_pcmcia_driver(avmcs_driver); |