]> Pileus Git - ~andy/linux/blob - drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c
6a1c1d4dcca29410256bad1734eb0a6f513b29d5
[~andy/linux] / drivers / staging / ft1000 / ft1000-pcmcia / ft1000_cs.c
1 /*---------------------------------------------------------------------------
2    FT1000 driver for Flarion Flash OFDM NIC Device
3
4    Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
5    Copyright (C) 2002 Flarion Technologies, All rights reserved.
6    Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
7    Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
8
9    The initial developer of the original code is David A. Hinds
10    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds.
11
12    This file was modified to support the Flarion Flash OFDM NIC Device
13    by Wai Chan (w.chan@flarion.com).
14
15    Port for kernel 2.6 created by Patrik Ostrihon (patrik.ostrihon@pwc.sk)
16
17    This program is free software; you can redistribute it and/or modify it
18    under the terms of the GNU General Public License as published by the Free
19    Software Foundation; either version 2 of the License, or (at your option) any
20    later version. This program is distributed in the hope that it will be useful,
21    but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
23    more details. You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the
25    Free Software Foundation, Inc., 59 Temple Place -
26    Suite 330, Boston, MA 02111-1307, USA.
27 -----------------------------------------------------------------------------*/
28
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/netdevice.h>
33 #include <pcmcia/cistpl.h>
34 #include <pcmcia/ds.h>
35
36 /*====================================================================*/
37
38 MODULE_AUTHOR("Wai Chan");
39 MODULE_DESCRIPTION("FT1000 PCMCIA driver");
40 MODULE_LICENSE("GPL");
41
42 /*====================================================================*/
43
44 struct net_device *init_ft1000_card(struct pcmcia_device *link,
45                                         void *ft1000_reset);
46 void stop_ft1000_card(struct net_device *);
47
48 static int ft1000_config(struct pcmcia_device *link);
49 static void ft1000_detach(struct pcmcia_device *link);
50 static int ft1000_attach(struct pcmcia_device *link);
51
52 /*====================================================================*/
53
54 static void ft1000_reset(struct pcmcia_device *link)
55 {
56         pcmcia_reset_card(link->socket);
57 }
58
59 static int ft1000_attach(struct pcmcia_device *link)
60 {
61         link->priv = NULL;
62         link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
63
64         return ft1000_config(link);
65 }
66
67 static void ft1000_detach(struct pcmcia_device *link)
68 {
69         struct net_device *dev = link->priv;
70
71         if (dev)
72                 stop_ft1000_card(dev);
73
74         pcmcia_disable_device(link);
75         free_netdev(dev);
76 }
77
78 int ft1000_confcheck(struct pcmcia_device *link, void *priv_data)
79 {
80         return pcmcia_request_io(link);
81 }
82
83 /*======================================================================
84
85     ft1000_config() is scheduled to run after a CARD_INSERTION event
86     is received, to configure the PCMCIA socket, and to make the
87     device available to the system.
88
89 ======================================================================*/
90
91 static int ft1000_config(struct pcmcia_device *link)
92 {
93         int ret;
94
95         dev_dbg(&link->dev, "ft1000_cs: ft1000_config(0x%p)\n", link);
96
97         /* setup IO window */
98         ret = pcmcia_loop_config(link, ft1000_confcheck, NULL);
99         if (ret) {
100                 printk(KERN_INFO "ft1000: Could not configure pcmcia\n");
101                 return -ENODEV;
102         }
103
104         /* configure device */
105         ret = pcmcia_enable_device(link);
106         if (ret) {
107                 printk(KERN_INFO "ft1000: could not enable pcmcia\n");
108                 goto failed;
109         }
110
111         link->priv = init_ft1000_card(link, &ft1000_reset);
112         if (!link->priv) {
113                 printk(KERN_INFO "ft1000: Could not register as network device\n");
114                 goto failed;
115         }
116
117         /* Finally, report what we've done */
118
119         return 0;
120 failed:
121         pcmcia_disable_device(link);
122         return -ENODEV;
123 }
124
125 static int ft1000_suspend(struct pcmcia_device *link)
126 {
127         struct net_device *dev = link->priv;
128
129         if (link->open)
130                 netif_device_detach(dev);
131         return 0;
132 }
133
134 static int ft1000_resume(struct pcmcia_device *link)
135 {
136         return 0;
137 }
138
139 /*====================================================================*/
140
141 static const struct pcmcia_device_id ft1000_ids[] = {
142         PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x0100),
143         PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x1000),
144         PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x1300),
145         PCMCIA_DEVICE_NULL,
146 };
147
148 MODULE_DEVICE_TABLE(pcmcia, ft1000_ids);
149
150 static struct pcmcia_driver ft1000_cs_driver = {
151         .owner          = THIS_MODULE,
152         .name           = "ft1000_cs",
153         .probe          = ft1000_attach,
154         .remove         = ft1000_detach,
155         .id_table       = ft1000_ids,
156         .suspend        = ft1000_suspend,
157         .resume         = ft1000_resume,
158 };
159
160 static int __init init_ft1000_cs(void)
161 {
162         return pcmcia_register_driver(&ft1000_cs_driver);
163 }
164
165 static void __exit exit_ft1000_cs(void)
166 {
167         pcmcia_unregister_driver(&ft1000_cs_driver);
168 }
169
170 module_init(init_ft1000_cs);
171 module_exit(exit_ft1000_cs);