linux/drivers/isdn/hisax/teles_cs.c
<<
>>
Prefs
   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  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  ======================================================================*/
  18
  19#include <linux/kernel.h>
  20#include <linux/module.h>
  21#include <linux/init.h>
  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
  29#include <pcmcia/cistpl.h>
  30#include <pcmcia/cisreg.h>
  31#include <pcmcia/ds.h>
  32#include "hisax_cfg.h"
  33
  34MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
  35MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
  36MODULE_LICENSE("GPL");
  37
  38
  39/*====================================================================*/
  40
  41/* Parameters that can be set with 'insmod' */
  42
  43static int protocol = 2;        /* EURO-ISDN Default */
  44module_param(protocol, int, 0);
  45
  46static int teles_cs_config(struct pcmcia_device *link);
  47static void teles_cs_release(struct pcmcia_device *link);
  48static void teles_detach(struct pcmcia_device *p_dev);
  49
  50typedef struct local_info_t {
  51        struct pcmcia_device    *p_dev;
  52        int                 busy;
  53        int                     cardnr;
  54} local_info_t;
  55
  56static int teles_probe(struct pcmcia_device *link)
  57{
  58        local_info_t *local;
  59
  60        dev_dbg(&link->dev, "teles_attach()\n");
  61
  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;
  66
  67        local->p_dev = link;
  68        link->priv = local;
  69
  70        link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  71
  72        return teles_cs_config(link);
  73} /* teles_attach */
  74
  75static void teles_detach(struct pcmcia_device *link)
  76{
  77        local_info_t *info = link->priv;
  78
  79        dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
  80
  81        info->busy = 1;
  82        teles_cs_release(link);
  83
  84        kfree(info);
  85} /* teles_detach */
  86
  87static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  88{
  89        int j;
  90
  91        p_dev->io_lines = 5;
  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;
  95
  96        if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
  97                printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
  98                if (!pcmcia_request_io(p_dev))
  99                        return 0;
 100        } else {
 101                printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
 102                for (j = 0x2f0; j > 0x100; j -= 0x10) {
 103                        p_dev->resource[0]->start = j;
 104                        if (!pcmcia_request_io(p_dev))
 105                                return 0;
 106                }
 107        }
 108        return -ENODEV;
 109}
 110
 111static int teles_cs_config(struct pcmcia_device *link)
 112{
 113        int i;
 114        IsdnCard_t icard;
 115
 116        dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
 117
 118        i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
 119        if (i != 0)
 120                goto cs_failed;
 121
 122        if (!link->irq)
 123                goto cs_failed;
 124
 125        i = pcmcia_enable_device(link);
 126        if (i != 0)
 127                goto cs_failed;
 128
 129        icard.para[0] = link->irq;
 130        icard.para[1] = link->resource[0]->start;
 131        icard.protocol = protocol;
 132        icard.typ = ISDN_CTYPE_TELESPCMCIA;
 133
 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;
 144
 145cs_failed:
 146        teles_cs_release(link);
 147        return -ENODEV;
 148} /* teles_cs_config */
 149
 150static void teles_cs_release(struct pcmcia_device *link)
 151{
 152        local_info_t *local = link->priv;
 153
 154        dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
 155
 156        if (local) {
 157                if (local->cardnr >= 0) {
 158                        /* no unregister function with hisax */
 159                        HiSax_closecard(local->cardnr);
 160                }
 161        }
 162
 163        pcmcia_disable_device(link);
 164} /* teles_cs_release */
 165
 166static int teles_suspend(struct pcmcia_device *link)
 167{
 168        local_info_t *dev = link->priv;
 169
 170        dev->busy = 1;
 171
 172        return 0;
 173}
 174
 175static int teles_resume(struct pcmcia_device *link)
 176{
 177        local_info_t *dev = link->priv;
 178
 179        dev->busy = 0;
 180
 181        return 0;
 182}
 183
 184
 185static const struct pcmcia_device_id teles_ids[] = {
 186        PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
 187        PCMCIA_DEVICE_NULL,
 188};
 189MODULE_DEVICE_TABLE(pcmcia, teles_ids);
 190
 191static struct pcmcia_driver teles_cs_driver = {
 192        .owner          = THIS_MODULE,
 193        .name           = "teles_cs",
 194        .probe          = teles_probe,
 195        .remove         = teles_detach,
 196        .id_table       = teles_ids,
 197        .suspend        = teles_suspend,
 198        .resume         = teles_resume,
 199};
 200module_pcmcia_driver(teles_cs_driver);
 201