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