blob: 4e676bcf85062c1049077fa6d724a6bef5e2a804 [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>
Joe Perches475be4d2012-02-19 19:52:38 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <pcmcia/cistpl.h>
23#include <pcmcia/ds.h>
24#include "hisax_cfg.h"
25
26MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
27MODULE_AUTHOR("Carsten Paeth");
28MODULE_LICENSE("GPL");
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/*====================================================================*/
32
33/* Parameters that can be set with 'insmod' */
34
35static int isdnprot = 2;
36
37module_param(isdnprot, int, 0);
38
39/*====================================================================*/
40
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080041static int avma1cs_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020042static void avma1cs_release(struct pcmcia_device *link);
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080043static void avma1cs_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080045static int avma1cs_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Joe Perches475be4d2012-02-19 19:52:38 -080047 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Joe Perches475be4d2012-02-19 19:52:38 -080049 /* General socket configuration */
50 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
51 p_dev->config_index = 1;
52 p_dev->config_regs = PRESENT_OPTION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Joe Perches475be4d2012-02-19 19:52:38 -080054 return avma1cs_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055} /* avma1cs_attach */
56
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080057static void avma1cs_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020059 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
Dominik Brodowskie2d40962006-03-02 00:09:29 +010060 avma1cs_release(link);
61 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062} /* avma1cs_detach */
63
Dominik Brodowski00990e72010-07-30 13:13:46 +020064static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Dominik Brodowski00990e72010-07-30 13:13:46 +020066 p_dev->resource[0]->end = 16;
67 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
68 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Dominik Brodowski90abdc32010-07-24 17:23:51 +020069 p_dev->io_lines = 5;
Dominik Brodowski00990e72010-07-30 13:13:46 +020070
Dominik Brodowski90abdc32010-07-24 17:23:51 +020071 return pcmcia_request_io(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080075static int avma1cs_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Joe Perches475be4d2012-02-19 19:52:38 -080077 int i = -1;
78 char devname[128];
79 IsdnCard_t icard;
80 int busy = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020081
Joe Perches475be4d2012-02-19 19:52:38 -080082 dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Joe Perches475be4d2012-02-19 19:52:38 -080084 devname[0] = 0;
85 if (link->prod_id[1])
86 strlcpy(devname, link->prod_id[1], sizeof(devname));
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +020087
Joe Perches475be4d2012-02-19 19:52:38 -080088 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
89 return -ENODEV;
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +020090
Joe Perches475be4d2012-02-19 19:52:38 -080091 do {
92 /*
93 * allocate an interrupt line
94 */
95 if (!link->irq) {
96 /* undo */
97 pcmcia_disable_device(link);
98 break;
99 }
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100100
Joe Perches475be4d2012-02-19 19:52:38 -0800101 /*
102 * configure the PCMCIA socket
103 */
104 i = pcmcia_enable_device(link);
105 if (i != 0) {
106 pcmcia_disable_device(link);
107 break;
108 }
109
110 } while (0);
111
112 /* If any step failed, release any partially configured state */
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200113 if (i != 0) {
Joe Perches475be4d2012-02-19 19:52:38 -0800114 avma1cs_release(link);
115 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117
Joe Perches475be4d2012-02-19 19:52:38 -0800118 icard.para[0] = link->irq;
119 icard.para[1] = link->resource[0]->start;
120 icard.protocol = isdnprot;
121 icard.typ = ISDN_CTYPE_A1_PCMCIA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Joe Perches475be4d2012-02-19 19:52:38 -0800123 i = hisax_init_pcmcia(link, &busy, &icard);
124 if (i < 0) {
125 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
126 "PCMCIA %d at i/o %#x\n", i,
127 (unsigned int) link->resource[0]->start);
128 avma1cs_release(link);
129 return -ENODEV;
130 }
131 link->priv = (void *) (unsigned long) i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Joe Perches475be4d2012-02-19 19:52:38 -0800133 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134} /* avma1cs_config */
135
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200136static void avma1cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100138 unsigned long minor = (unsigned long) link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200140 dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100142 /* now unregister function with hisax */
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100143 HiSax_closecard(minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200145 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146} /* avma1cs_release */
147
Joe Perches25f8f542011-05-03 19:29:01 -0700148static const struct pcmcia_device_id avma1cs_ids[] = {
Dominik Brodowskic594c122005-06-27 16:28:34 -0700149 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
150 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
151 PCMCIA_DEVICE_NULL
152};
153MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155static struct pcmcia_driver avma1cs_driver = {
156 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200157 .name = "avma1_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200158 .probe = avma1cs_probe,
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -0800159 .remove = avma1cs_detach,
Dominik Brodowskic594c122005-06-27 16:28:34 -0700160 .id_table = avma1cs_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161};
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static int __init init_avma1_cs(void)
164{
Dominik Brodowski06b3a1d2010-08-08 12:27:40 +0200165 return pcmcia_register_driver(&avma1cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
168static void __exit exit_avma1_cs(void)
169{
170 pcmcia_unregister_driver(&avma1cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
173module_init(init_avma1_cs);
174module_exit(exit_avma1_cs);