Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: teles_cs.c,v 1.1.2.2 2004/01/25 15:07:06 keil Exp $ */ |
| 2 | /*====================================================================== |
| 3 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 4 | A teles S0 PCMCIA client driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 6 | Based on skeleton by David Hinds, dhinds@allegro.stanford.edu |
| 7 | Written by Christof Petig, christof.petig@wtal.de |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 9 | Also inspired by ELSA PCMCIA driver |
| 10 | by Klaus Lichtenwalder <Lichtenwalder@ACM.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 12 | Extensions to new hisax_pcmcia by Karsten Keil |
| 13 | |
| 14 | minor changes to be compatible with kernel 2.4.x |
| 15 | by Jan.Schubert@GMX.li |
| 16 | |
| 17 | ======================================================================*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/ptrace.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/string.h> |
| 25 | #include <linux/timer.h> |
| 26 | #include <linux/ioport.h> |
| 27 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <pcmcia/cistpl.h> |
| 30 | #include <pcmcia/cisreg.h> |
| 31 | #include <pcmcia/ds.h> |
| 32 | #include "hisax_cfg.h" |
| 33 | |
| 34 | MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards"); |
| 35 | MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de"); |
| 36 | MODULE_LICENSE("GPL"); |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /*====================================================================*/ |
| 40 | |
| 41 | /* Parameters that can be set with 'insmod' */ |
| 42 | |
| 43 | static int protocol = 2; /* EURO-ISDN Default */ |
| 44 | module_param(protocol, int, 0); |
| 45 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 46 | static int teles_cs_config(struct pcmcia_device *link) __devinit; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 47 | static void teles_cs_release(struct pcmcia_device *link); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 48 | static void teles_detach(struct pcmcia_device *p_dev) __devexit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | typedef struct local_info_t { |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 51 | struct pcmcia_device *p_dev; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 52 | int busy; |
| 53 | int cardnr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } local_info_t; |
| 55 | |
Henne | 158e33d | 2010-03-25 12:05:30 +0000 | [diff] [blame] | 56 | static int __devinit teles_probe(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 58 | local_info_t *local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 60 | dev_dbg(&link->dev, "teles_attach()\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 62 | /* Allocate space for private device-specific data */ |
| 63 | local = kzalloc(sizeof(local_info_t), GFP_KERNEL); |
| 64 | if (!local) return -ENOMEM; |
| 65 | local->cardnr = -1; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 66 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 67 | local->p_dev = link; |
| 68 | link->priv = local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 70 | link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 72 | return teles_cs_config(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } /* teles_attach */ |
| 74 | |
Henne | 158e33d | 2010-03-25 12:05:30 +0000 | [diff] [blame] | 75 | static void __devexit teles_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 77 | local_info_t *info = link->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 79 | dev_dbg(&link->dev, "teles_detach(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 81 | info->busy = 1; |
| 82 | teles_cs_release(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 84 | kfree(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } /* teles_detach */ |
| 86 | |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 87 | static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 89 | int j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 91 | p_dev->io_lines = 5; |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 92 | p_dev->resource[0]->end = 96; |
| 93 | p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH; |
| 94 | p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 95 | |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 96 | if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) { |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 97 | printk(KERN_INFO "(teles_cs: looks like the 96 model)\n"); |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 98 | if (!pcmcia_request_io(p_dev)) |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 99 | return 0; |
| 100 | } else { |
| 101 | printk(KERN_INFO "(teles_cs: looks like the 97 model)\n"); |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 102 | for (j = 0x2f0; j > 0x100; j -= 0x10) { |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 103 | p_dev->resource[0]->start = j; |
| 104 | if (!pcmcia_request_io(p_dev)) |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | } |
| 108 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Henne | 158e33d | 2010-03-25 12:05:30 +0000 | [diff] [blame] | 111 | static int __devinit teles_cs_config(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 113 | int i; |
| 114 | IsdnCard_t icard; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 116 | dev_dbg(&link->dev, "teles_config(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 118 | i = pcmcia_loop_config(link, teles_cs_configcheck, NULL); |
| 119 | if (i != 0) |
| 120 | goto cs_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 122 | if (!link->irq) |
| 123 | goto cs_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 125 | i = pcmcia_enable_device(link); |
| 126 | if (i != 0) |
| 127 | goto cs_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 129 | icard.para[0] = link->irq; |
| 130 | icard.para[1] = link->resource[0]->start; |
| 131 | icard.protocol = protocol; |
| 132 | icard.typ = ISDN_CTYPE_TELESPCMCIA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 134 | i = hisax_init_pcmcia(link, &(((local_info_t *)link->priv)->busy), &icard); |
| 135 | if (i < 0) { |
| 136 | printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n", |
| 137 | i, (unsigned int) link->resource[0]->start); |
| 138 | teles_cs_release(link); |
| 139 | return -ENODEV; |
| 140 | } |
| 141 | |
| 142 | ((local_info_t *)link->priv)->cardnr = i; |
| 143 | return 0; |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | cs_failed: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 146 | teles_cs_release(link); |
| 147 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } /* teles_cs_config */ |
| 149 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 150 | static void teles_cs_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 152 | local_info_t *local = link->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 154 | dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 156 | if (local) { |
| 157 | if (local->cardnr >= 0) { |
| 158 | /* no unregister function with hisax */ |
| 159 | HiSax_closecard(local->cardnr); |
| 160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 163 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } /* teles_cs_release */ |
| 165 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 166 | static int teles_suspend(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 167 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 168 | local_info_t *dev = link->priv; |
| 169 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 170 | dev->busy = 1; |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 175 | static int teles_resume(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 176 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 177 | local_info_t *dev = link->priv; |
| 178 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 179 | dev->busy = 0; |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Joe Perches | 25f8f54 | 2011-05-03 19:29:01 -0700 | [diff] [blame] | 185 | static const struct pcmcia_device_id teles_ids[] = { |
Dominik Brodowski | 0a10d73 | 2005-06-27 16:28:24 -0700 | [diff] [blame] | 186 | PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119), |
| 187 | PCMCIA_DEVICE_NULL, |
| 188 | }; |
| 189 | MODULE_DEVICE_TABLE(pcmcia, teles_ids); |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | static struct pcmcia_driver teles_cs_driver = { |
| 192 | .owner = THIS_MODULE, |
Dominik Brodowski | 2e9b981 | 2010-08-08 11:36:26 +0200 | [diff] [blame] | 193 | .name = "teles_cs", |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 194 | .probe = teles_probe, |
Henne | 158e33d | 2010-03-25 12:05:30 +0000 | [diff] [blame] | 195 | .remove = __devexit_p(teles_detach), |
Dominik Brodowski | 0a10d73 | 2005-06-27 16:28:24 -0700 | [diff] [blame] | 196 | .id_table = teles_ids, |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 197 | .suspend = teles_suspend, |
| 198 | .resume = teles_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | static int __init init_teles_cs(void) |
| 202 | { |
| 203 | return pcmcia_register_driver(&teles_cs_driver); |
| 204 | } |
| 205 | |
| 206 | static void __exit exit_teles_cs(void) |
| 207 | { |
| 208 | pcmcia_unregister_driver(&teles_cs_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | module_init(init_teles_cs); |
| 212 | module_exit(exit_teles_cs); |