blob: 8f0ad2a52e8705adf33ca60624e871107918b315 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PCMCIA client driver for AVM A1 / Fritz!PCMCIA
3 *
4 * Author Carsten Paeth
5 * Copyright 1998-2001 by Carsten Paeth <calle@calle.in-berlin.de>
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
9 *
10 */
11
12#include <linux/module.h>
13
14
15#include <linux/kernel.h>
16#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/ptrace.h>
18#include <linux/slab.h>
19#include <linux/string.h>
20#include <asm/io.h>
21#include <asm/system.h>
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <pcmcia/cistpl.h>
24#include <pcmcia/ds.h>
25#include "hisax_cfg.h"
26
27MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
28MODULE_AUTHOR("Carsten Paeth");
29MODULE_LICENSE("GPL");
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*====================================================================*/
33
34/* Parameters that can be set with 'insmod' */
35
36static int isdnprot = 2;
37
38module_param(isdnprot, int, 0);
39
40/*====================================================================*/
41
Hennea4658702010-03-25 12:05:31 +000042static int avma1cs_config(struct pcmcia_device *link) __devinit ;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020043static void avma1cs_release(struct pcmcia_device *link);
Hennea4658702010-03-25 12:05:31 +000044static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Hennea4658702010-03-25 12:05:31 +000046static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020048 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 /* General socket configuration */
Dominik Brodowski00990e72010-07-30 13:13:46 +020051 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
Dominik Brodowski7feabb62010-07-29 18:35:47 +020052 p_dev->config_index = 1;
53 p_dev->config_regs = PRESENT_OPTION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020055 return avma1cs_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056} /* avma1cs_attach */
57
Hennea4658702010-03-25 12:05:31 +000058static void __devexit avma1cs_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020060 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
Dominik Brodowskie2d40962006-03-02 00:09:29 +010061 avma1cs_release(link);
62 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063} /* avma1cs_detach */
64
Dominik Brodowski00990e72010-07-30 13:13:46 +020065static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Dominik Brodowski00990e72010-07-30 13:13:46 +020067 p_dev->resource[0]->end = 16;
68 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
69 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Dominik Brodowski90abdc32010-07-24 17:23:51 +020070 p_dev->io_lines = 5;
Dominik Brodowski00990e72010-07-30 13:13:46 +020071
Dominik Brodowski90abdc32010-07-24 17:23:51 +020072 return pcmcia_request_io(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Hennea4658702010-03-25 12:05:31 +000076static int __devinit avma1cs_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Dominik Brodowskieb141202010-03-07 12:21:16 +010078 int i = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 char devname[128];
80 IsdnCard_t icard;
81 int busy = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020082
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020083 dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +020085 devname[0] = 0;
86 if (link->prod_id[1])
87 strlcpy(devname, link->prod_id[1], sizeof(devname));
88
89 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
90 return -ENODEV;
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 /*
94 * allocate an interrupt line
95 */
Dominik Brodowskieb141202010-03-07 12:21:16 +010096 if (!link->irq) {
Dominik Brodowski50db3fd2006-01-15 10:05:19 +010097 /* undo */
Dominik Brodowskifba395e2006-03-31 17:21:06 +020098 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 break;
100 }
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /*
103 * configure the PCMCIA socket
104 */
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200105 i = pcmcia_enable_device(link);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200106 if (i != 0) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200107 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 break;
109 }
110
111 } while (0);
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 /* If any step failed, release any partially configured state */
114 if (i != 0) {
115 avma1cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200116 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
Dominik Brodowskieb141202010-03-07 12:21:16 +0100119 icard.para[0] = link->irq;
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200120 icard.para[1] = link->resource[0]->start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 icard.protocol = isdnprot;
122 icard.typ = ISDN_CTYPE_A1_PCMCIA;
123
124 i = hisax_init_pcmcia(link, &busy, &icard);
125 if (i < 0) {
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200126 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
127 "PCMCIA %d at i/o %#x\n", i,
128 (unsigned int) link->resource[0]->start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 avma1cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200130 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100132 link->priv = (void *) (unsigned long) i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200134 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135} /* avma1cs_config */
136
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200137static void avma1cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100139 unsigned long minor = (unsigned long) link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200141 dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100143 /* now unregister function with hisax */
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100144 HiSax_closecard(minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200146 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147} /* avma1cs_release */
148
Joe Perches25f8f542011-05-03 19:29:01 -0700149static const struct pcmcia_device_id avma1cs_ids[] = {
Dominik Brodowskic594c122005-06-27 16:28:34 -0700150 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
151 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
152 PCMCIA_DEVICE_NULL
153};
154MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static struct pcmcia_driver avma1cs_driver = {
157 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200158 .name = "avma1_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200159 .probe = avma1cs_probe,
Hennea4658702010-03-25 12:05:31 +0000160 .remove = __devexit_p(avma1cs_detach),
Dominik Brodowskic594c122005-06-27 16:28:34 -0700161 .id_table = avma1cs_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static int __init init_avma1_cs(void)
165{
Dominik Brodowski06b3a1d2010-08-08 12:27:40 +0200166 return pcmcia_register_driver(&avma1cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
169static void __exit exit_avma1_cs(void)
170{
171 pcmcia_unregister_driver(&avma1cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
174module_init(init_avma1_cs);
175module_exit(exit_avma1_cs);