Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 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) |
Greg Kroah-Hartman | bf3146c | 2010-09-22 08:34:49 -0700 | [diff] [blame] | 16 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 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/ptrace.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/timer.h> |
| 36 | #include <linux/ioport.h> |
| 37 | #include <linux/delay.h> |
| 38 | |
| 39 | #include <linux/netdevice.h> |
| 40 | #include <linux/etherdevice.h> |
| 41 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 42 | #include <pcmcia/cistpl.h> |
| 43 | #include <pcmcia/cisreg.h> |
| 44 | #include <pcmcia/ds.h> |
| 45 | |
| 46 | #include <asm/io.h> |
| 47 | #include <asm/system.h> |
| 48 | #include <asm/byteorder.h> |
| 49 | #include <asm/uaccess.h> |
| 50 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 51 | /*====================================================================*/ |
| 52 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 53 | MODULE_AUTHOR("Wai Chan"); |
| 54 | MODULE_DESCRIPTION("FT1000 PCMCIA driver"); |
| 55 | MODULE_LICENSE("GPL"); |
| 56 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 57 | /*====================================================================*/ |
| 58 | |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 59 | struct net_device *init_ft1000_card(struct pcmcia_device *link, |
| 60 | void *ft1000_reset); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 61 | void stop_ft1000_card(struct net_device *); |
| 62 | |
| 63 | static int ft1000_config(struct pcmcia_device *link); |
| 64 | static void ft1000_release(struct pcmcia_device *link); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 65 | static void ft1000_detach(struct pcmcia_device *link); |
| 66 | static int ft1000_attach(struct pcmcia_device *link); |
| 67 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 68 | /*====================================================================*/ |
| 69 | |
| 70 | static void ft1000_reset(struct pcmcia_device * link) |
| 71 | { |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 72 | pcmcia_reset_card(link->socket); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 75 | static int ft1000_attach(struct pcmcia_device *link) |
| 76 | { |
Ondrej Zary | 4370782 | 2011-07-01 00:03:44 +0200 | [diff] [blame] | 77 | link->priv = NULL; |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 78 | link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 79 | |
| 80 | return ft1000_config(link); |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 81 | |
Ondrej Zary | 3061fab | 2011-07-01 00:03:50 +0200 | [diff] [blame^] | 82 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 83 | |
| 84 | static void ft1000_detach(struct pcmcia_device *link) |
| 85 | { |
Ondrej Zary | 4370782 | 2011-07-01 00:03:44 +0200 | [diff] [blame] | 86 | struct net_device *dev = link->priv; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 87 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 88 | if (dev) { |
| 89 | stop_ft1000_card(dev); |
| 90 | } |
| 91 | |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 92 | pcmcia_disable_device(link); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 93 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 94 | free_netdev(dev); |
| 95 | |
Ondrej Zary | 3061fab | 2011-07-01 00:03:50 +0200 | [diff] [blame^] | 96 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 97 | |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 98 | int ft1000_confcheck(struct pcmcia_device *link, void *priv_data) |
| 99 | { |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 100 | return pcmcia_request_io(link); |
Ondrej Zary | 3061fab | 2011-07-01 00:03:50 +0200 | [diff] [blame^] | 101 | } |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 102 | |
| 103 | /*====================================================================== |
| 104 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 105 | ft1000_config() is scheduled to run after a CARD_INSERTION event |
| 106 | is received, to configure the PCMCIA socket, and to make the |
| 107 | device available to the system. |
Greg Kroah-Hartman | bf3146c | 2010-09-22 08:34:49 -0700 | [diff] [blame] | 108 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 109 | ======================================================================*/ |
| 110 | |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 111 | static int ft1000_config(struct pcmcia_device *link) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 112 | { |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 113 | int ret; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 114 | |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 115 | dev_dbg(&link->dev, "ft1000_cs: ft1000_config(0x%p)\n", link); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 116 | |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 117 | /* setup IO window */ |
| 118 | ret = pcmcia_loop_config(link, ft1000_confcheck, NULL); |
| 119 | if (ret) { |
| 120 | printk(KERN_INFO "ft1000: Could not configure pcmcia\n"); |
| 121 | return -ENODEV; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 122 | } |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 123 | |
| 124 | /* configure device */ |
| 125 | ret = pcmcia_enable_device(link); |
| 126 | if (ret) { |
| 127 | printk(KERN_INFO "ft1000: could not enable pcmcia\n"); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 128 | goto failed; |
Greg Kroah-Hartman | bf3146c | 2010-09-22 08:34:49 -0700 | [diff] [blame] | 129 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 130 | |
Ondrej Zary | 4370782 | 2011-07-01 00:03:44 +0200 | [diff] [blame] | 131 | link->priv = init_ft1000_card(link, &ft1000_reset); |
| 132 | if (link->priv == NULL) { |
Marek Belisko | c331e76 | 2011-01-10 13:14:28 +0100 | [diff] [blame] | 133 | printk(KERN_INFO "ft1000: Could not register as network device\n"); |
| 134 | goto failed; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 135 | } |
| 136 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 137 | /* Finally, report what we've done */ |
| 138 | |
| 139 | return 0; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 140 | failed: |
| 141 | ft1000_release(link); |
| 142 | return -ENODEV; |
| 143 | |
Ondrej Zary | 3061fab | 2011-07-01 00:03:50 +0200 | [diff] [blame^] | 144 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 145 | |
| 146 | /*====================================================================== |
| 147 | |
| 148 | After a card is removed, ft1000_release() will unregister the |
| 149 | device, and release the PCMCIA configuration. If the device is |
| 150 | still open, this will be postponed until it is closed. |
Greg Kroah-Hartman | bf3146c | 2010-09-22 08:34:49 -0700 | [diff] [blame] | 151 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 152 | ======================================================================*/ |
| 153 | |
| 154 | static void ft1000_release(struct pcmcia_device * link) |
| 155 | { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 156 | pcmcia_disable_device(link); |
Ondrej Zary | 3061fab | 2011-07-01 00:03:50 +0200 | [diff] [blame^] | 157 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 158 | |
| 159 | static int ft1000_suspend(struct pcmcia_device *link) |
| 160 | { |
Ondrej Zary | 4370782 | 2011-07-01 00:03:44 +0200 | [diff] [blame] | 161 | struct net_device *dev = link->priv; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 162 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 163 | if (link->open) |
| 164 | netif_device_detach(dev); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static int ft1000_resume(struct pcmcia_device *link) |
| 169 | { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 173 | /*====================================================================*/ |
| 174 | |
Joe Perches | 2202a5a | 2011-05-03 19:29:02 -0700 | [diff] [blame] | 175 | static const struct pcmcia_device_id ft1000_ids[] = { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 176 | PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x0100), |
| 177 | PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x1000), |
| 178 | PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x1300), |
| 179 | PCMCIA_DEVICE_NULL, |
| 180 | }; |
| 181 | |
| 182 | MODULE_DEVICE_TABLE(pcmcia, ft1000_ids); |
| 183 | |
| 184 | static struct pcmcia_driver ft1000_cs_driver = { |
| 185 | .owner = THIS_MODULE, |
Ondrej Zary | 01cafa5 | 2011-07-01 00:03:30 +0200 | [diff] [blame] | 186 | .name = "ft1000_cs", |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 187 | .probe = ft1000_attach, |
| 188 | .remove = ft1000_detach, |
| 189 | .id_table = ft1000_ids, |
| 190 | .suspend = ft1000_suspend, |
| 191 | .resume = ft1000_resume, |
| 192 | }; |
| 193 | |
| 194 | static int __init init_ft1000_cs(void) |
| 195 | { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 196 | return pcmcia_register_driver(&ft1000_cs_driver); |
| 197 | } |
| 198 | |
| 199 | static void __exit exit_ft1000_cs(void) |
| 200 | { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 201 | pcmcia_unregister_driver(&ft1000_cs_driver); |
| 202 | } |
| 203 | |
| 204 | module_init(init_ft1000_cs); |
| 205 | module_exit(exit_ft1000_cs); |