| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include "ixj-ver.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | #include <linux/kernel.h>	/* printk() */
 | 
					
						
							|  |  |  | #include <linux/fs.h>		/* everything... */
 | 
					
						
							|  |  |  | #include <linux/errno.h>	/* error codes */
 | 
					
						
							|  |  |  | #include <linux/slab.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <pcmcia/cistpl.h>
 | 
					
						
							|  |  |  | #include <pcmcia/ds.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ixj.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  *	PCMCIA service support for Quicknet cards | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct ixj_info_t { | 
					
						
							|  |  |  | 	int ndev; | 
					
						
							|  |  |  | 	struct ixj *port; | 
					
						
							|  |  |  | } ixj_info_t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-14 21:23:14 +01:00
										 |  |  | static void ixj_detach(struct pcmcia_device *p_dev); | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | static int ixj_config(struct pcmcia_device * link); | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | static void ixj_cs_release(struct pcmcia_device * link); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | static int ixj_probe(struct pcmcia_device *p_dev) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 	dev_dbg(&p_dev->dev, "ixj_attach()\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* Create new ixj device */ | 
					
						
							| 
									
										
											  
											
												some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
 x =
- kmalloc
+ kzalloc
  (E1,E2)
  ...  when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
											
										 
											2007-07-19 01:49:03 -07:00
										 |  |  | 	p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2006-03-05 10:45:09 +01:00
										 |  |  | 	if (!p_dev->priv) { | 
					
						
							| 
									
										
										
										
											2005-11-14 21:25:51 +01:00
										 |  |  | 		return -ENOMEM; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-14 21:25:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | 	return ixj_config(p_dev); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | static void ixj_detach(struct pcmcia_device *link) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 	dev_dbg(&link->dev, "ixj_detach\n"); | 
					
						
							| 
									
										
										
										
											2005-11-14 21:25:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-02 00:09:29 +01:00
										 |  |  | 	ixj_cs_release(link); | 
					
						
							| 
									
										
										
										
											2005-11-14 21:23:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |         kfree(link->priv); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | static void ixj_get_serial(struct pcmcia_device * link, IXJ * j) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *str; | 
					
						
							| 
									
										
										
										
											2006-06-04 18:06:13 +02:00
										 |  |  | 	int i, place; | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 	dev_dbg(&link->dev, "ixj_get_serial\n"); | 
					
						
							| 
									
										
										
										
											2006-06-04 18:06:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	str = link->prod_id[0]; | 
					
						
							|  |  |  | 	if (!str) | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 		goto failed; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	printk("%s", str); | 
					
						
							| 
									
										
										
										
											2006-06-04 18:06:13 +02:00
										 |  |  | 	str = link->prod_id[1]; | 
					
						
							|  |  |  | 	if (!str) | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 		goto failed; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	printk(" %s", str); | 
					
						
							| 
									
										
										
										
											2006-06-04 18:06:13 +02:00
										 |  |  | 	str = link->prod_id[2]; | 
					
						
							|  |  |  | 	if (!str) | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 		goto failed; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	place = 1; | 
					
						
							|  |  |  | 	for (i = strlen(str) - 1; i >= 0; i--) { | 
					
						
							|  |  |  | 		switch (str[i]) { | 
					
						
							|  |  |  | 		case '0': | 
					
						
							|  |  |  | 		case '1': | 
					
						
							|  |  |  | 		case '2': | 
					
						
							|  |  |  | 		case '3': | 
					
						
							|  |  |  | 		case '4': | 
					
						
							|  |  |  | 		case '5': | 
					
						
							|  |  |  | 		case '6': | 
					
						
							|  |  |  | 		case '7': | 
					
						
							|  |  |  | 		case '8': | 
					
						
							|  |  |  | 		case '9': | 
					
						
							|  |  |  | 			j->serial += (str[i] - 48) * place; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'A': | 
					
						
							|  |  |  | 		case 'B': | 
					
						
							|  |  |  | 		case 'C': | 
					
						
							|  |  |  | 		case 'D': | 
					
						
							|  |  |  | 		case 'E': | 
					
						
							|  |  |  | 		case 'F': | 
					
						
							|  |  |  | 			j->serial += (str[i] - 55) * place; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 'a': | 
					
						
							|  |  |  | 		case 'b': | 
					
						
							|  |  |  | 		case 'c': | 
					
						
							|  |  |  | 		case 'd': | 
					
						
							|  |  |  | 		case 'e': | 
					
						
							|  |  |  | 		case 'f': | 
					
						
							|  |  |  | 			j->serial += (str[i] - 87) * place; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		place = place * 0x10; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-04 18:06:13 +02:00
										 |  |  | 	str = link->prod_id[3]; | 
					
						
							|  |  |  | 	if (!str) | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 		goto failed; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	printk(" version %s\n", str); | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | failed: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-30 13:13:46 +02:00
										 |  |  | static int ixj_config_check(struct pcmcia_device *p_dev, void *priv_data) | 
					
						
							| 
									
										
										
										
											2008-07-29 08:38:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-30 13:13:46 +02:00
										 |  |  | 	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; | 
					
						
							|  |  |  | 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; | 
					
						
							|  |  |  | 	p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH; | 
					
						
							|  |  |  | 	p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; | 
					
						
							|  |  |  | 	p_dev->io_lines = 3; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return pcmcia_request_io(p_dev); | 
					
						
							| 
									
										
										
										
											2008-07-29 08:38:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | static int ixj_config(struct pcmcia_device * link) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	IXJ *j; | 
					
						
							|  |  |  | 	ixj_info_t *info; | 
					
						
							| 
									
										
										
										
											2008-07-29 08:38:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	info = link->priv; | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 	dev_dbg(&link->dev, "ixj_config\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-30 13:13:46 +02:00
										 |  |  | 	link->config_flags = CONF_AUTO_SET_IO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (pcmcia_loop_config(link, ixj_config_check, NULL)) | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 		goto failed; | 
					
						
							| 
									
										
										
										
											2008-07-29 08:38:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-29 19:27:09 +02:00
										 |  |  | 	if (pcmcia_enable_device(link)) | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 		goto failed; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  |  	 *	Register the card with the core. | 
					
						
							| 
									
										
										
										
											2008-07-29 08:38:55 +02:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-07-24 15:58:54 +02:00
										 |  |  | 	j = ixj_pcmcia_probe(link->resource[0]->start, | 
					
						
							|  |  |  | 			     link->resource[0]->start + 0x10); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	info->ndev = 1; | 
					
						
							|  |  |  | 	ixj_get_serial(link, j); | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2008-07-29 08:38:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | failed: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	ixj_cs_release(link); | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | 	return -ENODEV; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | static void ixj_cs_release(struct pcmcia_device *link) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	ixj_info_t *info = link->priv; | 
					
						
							| 
									
										
										
										
											2009-10-24 15:55:39 +02:00
										 |  |  | 	dev_dbg(&link->dev, "ixj_cs_release\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	info->ndev = 0; | 
					
						
							| 
									
										
										
										
											2006-03-31 17:21:06 +02:00
										 |  |  | 	pcmcia_disable_device(link); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 19:29:01 -07:00
										 |  |  | static const struct pcmcia_device_id ixj_ids[] = { | 
					
						
							| 
									
										
										
										
											2005-06-27 16:28:40 -07:00
										 |  |  | 	PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600), | 
					
						
							|  |  |  | 	PCMCIA_DEVICE_NULL | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | MODULE_DEVICE_TABLE(pcmcia, ixj_ids); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static struct pcmcia_driver ixj_driver = { | 
					
						
							|  |  |  | 	.owner		= THIS_MODULE, | 
					
						
							| 
									
										
										
										
											2010-08-08 11:36:26 +02:00
										 |  |  | 	.name		= "ixj_cs", | 
					
						
							| 
									
										
										
										
											2006-03-31 17:26:06 +02:00
										 |  |  | 	.probe		= ixj_probe, | 
					
						
							| 
									
										
										
										
											2005-11-14 21:23:14 +01:00
										 |  |  | 	.remove		= ixj_detach, | 
					
						
							| 
									
										
										
										
											2005-06-27 16:28:40 -07:00
										 |  |  | 	.id_table	= ixj_ids, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int __init ixj_pcmcia_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return pcmcia_register_driver(&ixj_driver); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ixj_pcmcia_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pcmcia_unregister_driver(&ixj_driver); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module_init(ixj_pcmcia_init); | 
					
						
							|  |  |  | module_exit(ixj_pcmcia_exit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); |