162306a36Sopenharmony_ci/*** -*- linux-c -*- ********************************************************** 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci Driver for Atmel at76c502 at76c504 and at76c506 wireless cards. 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci Copyright 2000-2001 ATMEL Corporation. 662306a36Sopenharmony_ci Copyright 2003 Simon Kelley. 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci This code was developed from version 2.1.1 of the Atmel drivers, 962306a36Sopenharmony_ci released by Atmel corp. under the GPL in December 2002. It also 1062306a36Sopenharmony_ci includes code from the Linux aironet drivers (C) Benjamin Reed, 1162306a36Sopenharmony_ci and the Linux PCMCIA package, (C) David Hinds. 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci For all queries about this code, please contact the current author, 1462306a36Sopenharmony_ci Simon Kelley <simon@thekelleys.org.uk> and not Atmel Corporation. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci This program is free software; you can redistribute it and/or modify 1762306a36Sopenharmony_ci it under the terms of the GNU General Public License as published by 1862306a36Sopenharmony_ci the Free Software Foundation; either version 2 of the License, or 1962306a36Sopenharmony_ci (at your option) any later version. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci This software is distributed in the hope that it will be useful, 2262306a36Sopenharmony_ci but WITHOUT ANY WARRANTY; without even the implied warranty of 2362306a36Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2462306a36Sopenharmony_ci GNU General Public License for more details. 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci You should have received a copy of the GNU General Public License 2762306a36Sopenharmony_ci along with Atmel wireless lan drivers; if not, see 2862306a36Sopenharmony_ci <http://www.gnu.org/licenses/>. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci******************************************************************************/ 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#ifdef __IN_PCMCIA_PACKAGE__ 3362306a36Sopenharmony_ci#include <pcmcia/k_compat.h> 3462306a36Sopenharmony_ci#endif 3562306a36Sopenharmony_ci#include <linux/kernel.h> 3662306a36Sopenharmony_ci#include <linux/module.h> 3762306a36Sopenharmony_ci#include <linux/ptrace.h> 3862306a36Sopenharmony_ci#include <linux/slab.h> 3962306a36Sopenharmony_ci#include <linux/string.h> 4062306a36Sopenharmony_ci#include <linux/netdevice.h> 4162306a36Sopenharmony_ci#include <linux/moduleparam.h> 4262306a36Sopenharmony_ci#include <linux/device.h> 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#include <pcmcia/cistpl.h> 4562306a36Sopenharmony_ci#include <pcmcia/cisreg.h> 4662306a36Sopenharmony_ci#include <pcmcia/ds.h> 4762306a36Sopenharmony_ci#include <pcmcia/ciscode.h> 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#include <asm/io.h> 5062306a36Sopenharmony_ci#include <linux/wireless.h> 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#include "atmel.h" 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/*====================================================================*/ 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciMODULE_AUTHOR("Simon Kelley"); 5862306a36Sopenharmony_ciMODULE_DESCRIPTION("Support for Atmel at76c50x 802.11 wireless ethernet cards."); 5962306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci/*====================================================================*/ 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistatic int atmel_config(struct pcmcia_device *link); 6462306a36Sopenharmony_cistatic void atmel_release(struct pcmcia_device *link); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_cistatic void atmel_detach(struct pcmcia_device *p_dev); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_cistruct local_info { 6962306a36Sopenharmony_ci struct net_device *eth_dev; 7062306a36Sopenharmony_ci}; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_cistatic int atmel_probe(struct pcmcia_device *p_dev) 7362306a36Sopenharmony_ci{ 7462306a36Sopenharmony_ci struct local_info *local; 7562306a36Sopenharmony_ci int ret; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci dev_dbg(&p_dev->dev, "atmel_attach()\n"); 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci /* Allocate space for private device-specific data */ 8062306a36Sopenharmony_ci local = kzalloc(sizeof(*local), GFP_KERNEL); 8162306a36Sopenharmony_ci if (!local) 8262306a36Sopenharmony_ci return -ENOMEM; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci p_dev->priv = local; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci ret = atmel_config(p_dev); 8762306a36Sopenharmony_ci if (ret) 8862306a36Sopenharmony_ci goto err_free_priv; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci return 0; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cierr_free_priv: 9362306a36Sopenharmony_ci kfree(p_dev->priv); 9462306a36Sopenharmony_ci return ret; 9562306a36Sopenharmony_ci} 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistatic void atmel_detach(struct pcmcia_device *link) 9862306a36Sopenharmony_ci{ 9962306a36Sopenharmony_ci dev_dbg(&link->dev, "atmel_detach\n"); 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci atmel_release(link); 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci kfree(link->priv); 10462306a36Sopenharmony_ci} 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci/* Call-back function to interrogate PCMCIA-specific information 10762306a36Sopenharmony_ci about the current existence of the card */ 10862306a36Sopenharmony_cistatic int card_present(void *arg) 10962306a36Sopenharmony_ci{ 11062306a36Sopenharmony_ci struct pcmcia_device *link = (struct pcmcia_device *)arg; 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci if (pcmcia_dev_present(link)) 11362306a36Sopenharmony_ci return 1; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci return 0; 11662306a36Sopenharmony_ci} 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cistatic int atmel_config_check(struct pcmcia_device *p_dev, void *priv_data) 11962306a36Sopenharmony_ci{ 12062306a36Sopenharmony_ci if (p_dev->config_index == 0) 12162306a36Sopenharmony_ci return -EINVAL; 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci return pcmcia_request_io(p_dev); 12462306a36Sopenharmony_ci} 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_cistatic int atmel_config(struct pcmcia_device *link) 12762306a36Sopenharmony_ci{ 12862306a36Sopenharmony_ci int ret; 12962306a36Sopenharmony_ci const struct pcmcia_device_id *did; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci did = dev_get_drvdata(&link->dev); 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci dev_dbg(&link->dev, "atmel_config\n"); 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP | 13662306a36Sopenharmony_ci CONF_AUTO_AUDIO | CONF_AUTO_SET_IO; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci if (pcmcia_loop_config(link, atmel_config_check, NULL)) 13962306a36Sopenharmony_ci goto failed; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci if (!link->irq) { 14262306a36Sopenharmony_ci dev_err(&link->dev, "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config."); 14362306a36Sopenharmony_ci goto failed; 14462306a36Sopenharmony_ci } 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci ret = pcmcia_enable_device(link); 14762306a36Sopenharmony_ci if (ret) 14862306a36Sopenharmony_ci goto failed; 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci ((struct local_info *)link->priv)->eth_dev = 15162306a36Sopenharmony_ci init_atmel_card(link->irq, 15262306a36Sopenharmony_ci link->resource[0]->start, 15362306a36Sopenharmony_ci did ? did->driver_info : ATMEL_FW_TYPE_NONE, 15462306a36Sopenharmony_ci &link->dev, 15562306a36Sopenharmony_ci card_present, 15662306a36Sopenharmony_ci link); 15762306a36Sopenharmony_ci if (!((struct local_info *)link->priv)->eth_dev) 15862306a36Sopenharmony_ci goto failed; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci return 0; 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci failed: 16462306a36Sopenharmony_ci atmel_release(link); 16562306a36Sopenharmony_ci return -ENODEV; 16662306a36Sopenharmony_ci} 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_cistatic void atmel_release(struct pcmcia_device *link) 16962306a36Sopenharmony_ci{ 17062306a36Sopenharmony_ci struct net_device *dev = ((struct local_info *)link->priv)->eth_dev; 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci dev_dbg(&link->dev, "atmel_release\n"); 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci if (dev) 17562306a36Sopenharmony_ci stop_atmel_card(dev); 17662306a36Sopenharmony_ci ((struct local_info *)link->priv)->eth_dev = NULL; 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci pcmcia_disable_device(link); 17962306a36Sopenharmony_ci} 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_cistatic int atmel_suspend(struct pcmcia_device *link) 18262306a36Sopenharmony_ci{ 18362306a36Sopenharmony_ci struct local_info *local = link->priv; 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci netif_device_detach(local->eth_dev); 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci return 0; 18862306a36Sopenharmony_ci} 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_cistatic int atmel_resume(struct pcmcia_device *link) 19162306a36Sopenharmony_ci{ 19262306a36Sopenharmony_ci struct local_info *local = link->priv; 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci atmel_open(local->eth_dev); 19562306a36Sopenharmony_ci netif_device_attach(local->eth_dev); 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci return 0; 19862306a36Sopenharmony_ci} 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci/*====================================================================*/ 20162306a36Sopenharmony_ci/* We use the driver_info field to store the correct firmware type for a card. */ 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci#define PCMCIA_DEVICE_MANF_CARD_INFO(manf, card, info) { \ 20462306a36Sopenharmony_ci .match_flags = PCMCIA_DEV_ID_MATCH_MANF_ID| \ 20562306a36Sopenharmony_ci PCMCIA_DEV_ID_MATCH_CARD_ID, \ 20662306a36Sopenharmony_ci .manf_id = (manf), \ 20762306a36Sopenharmony_ci .card_id = (card), \ 20862306a36Sopenharmony_ci .driver_info = (kernel_ulong_t)(info), } 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci#define PCMCIA_DEVICE_PROD_ID12_INFO(v1, v2, vh1, vh2, info) { \ 21162306a36Sopenharmony_ci .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \ 21262306a36Sopenharmony_ci PCMCIA_DEV_ID_MATCH_PROD_ID2, \ 21362306a36Sopenharmony_ci .prod_id = { (v1), (v2), NULL, NULL }, \ 21462306a36Sopenharmony_ci .prod_id_hash = { (vh1), (vh2), 0, 0 }, \ 21562306a36Sopenharmony_ci .driver_info = (kernel_ulong_t)(info), } 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_cistatic const struct pcmcia_device_id atmel_ids[] = { 21862306a36Sopenharmony_ci PCMCIA_DEVICE_MANF_CARD_INFO(0x0101, 0x0620, ATMEL_FW_TYPE_502_3COM), 21962306a36Sopenharmony_ci PCMCIA_DEVICE_MANF_CARD_INFO(0x0101, 0x0696, ATMEL_FW_TYPE_502_3COM), 22062306a36Sopenharmony_ci PCMCIA_DEVICE_MANF_CARD_INFO(0x01bf, 0x3302, ATMEL_FW_TYPE_502E), 22162306a36Sopenharmony_ci PCMCIA_DEVICE_MANF_CARD_INFO(0xd601, 0x0007, ATMEL_FW_TYPE_502), 22262306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("11WAVE", "11WP611AL-E", 0x9eb2da1f, 0xc9a0d3f9, ATMEL_FW_TYPE_502E), 22362306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C502AR", 0xabda4164, 0x41b37e1f, ATMEL_FW_TYPE_502), 22462306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C502AR_D", 0xabda4164, 0x3675d704, ATMEL_FW_TYPE_502D), 22562306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C502AR_E", 0xabda4164, 0x4172e792, ATMEL_FW_TYPE_502E), 22662306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C504_R", 0xabda4164, 0x917f3d72, ATMEL_FW_TYPE_504_2958), 22762306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C504", 0xabda4164, 0x5040670a, ATMEL_FW_TYPE_504), 22862306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C504A", 0xabda4164, 0xe15ed87f, ATMEL_FW_TYPE_504A_2958), 22962306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("BT", "Voyager 1020 Laptop Adapter", 0xae49b86a, 0x1e957cd5, ATMEL_FW_TYPE_502), 23062306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("CNet", "CNWLC 11Mbps Wireless PC Card V-5", 0xbc477dde, 0x502fae6b, ATMEL_FW_TYPE_502E), 23162306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("IEEE 802.11b", "Wireless LAN PC Card", 0x5b878724, 0x122f1df6, ATMEL_FW_TYPE_502), 23262306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("IEEE 802.11b", "Wireless LAN Card S", 0x5b878724, 0x5fba533a, ATMEL_FW_TYPE_504_2958), 23362306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("OEM", "11Mbps Wireless LAN PC Card V-3", 0xfea54c90, 0x1c5b0f68, ATMEL_FW_TYPE_502), 23462306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("SMC", "2632W", 0xc4f8b18b, 0x30f38774, ATMEL_FW_TYPE_502D), 23562306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("SMC", "2632W-V2", 0xc4f8b18b, 0x172d1377, ATMEL_FW_TYPE_502), 23662306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("Wireless", "PC_CARD", 0xa407ecdd, 0x119f6314, ATMEL_FW_TYPE_502D), 23762306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("WLAN", "802.11b PC CARD", 0x575c516c, 0xb1f6dbc4, ATMEL_FW_TYPE_502D), 23862306a36Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12_INFO("LG", "LW2100N", 0xb474d43a, 0x6b1fec94, ATMEL_FW_TYPE_502E), 23962306a36Sopenharmony_ci PCMCIA_DEVICE_NULL 24062306a36Sopenharmony_ci}; 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ciMODULE_DEVICE_TABLE(pcmcia, atmel_ids); 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_cistatic struct pcmcia_driver atmel_driver = { 24562306a36Sopenharmony_ci .owner = THIS_MODULE, 24662306a36Sopenharmony_ci .name = "atmel_cs", 24762306a36Sopenharmony_ci .probe = atmel_probe, 24862306a36Sopenharmony_ci .remove = atmel_detach, 24962306a36Sopenharmony_ci .id_table = atmel_ids, 25062306a36Sopenharmony_ci .suspend = atmel_suspend, 25162306a36Sopenharmony_ci .resume = atmel_resume, 25262306a36Sopenharmony_ci}; 25362306a36Sopenharmony_cimodule_pcmcia_driver(atmel_driver); 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ci/* 25662306a36Sopenharmony_ci This program is free software; you can redistribute it and/or 25762306a36Sopenharmony_ci modify it under the terms of the GNU General Public License 25862306a36Sopenharmony_ci as published by the Free Software Foundation; either version 2 25962306a36Sopenharmony_ci of the License, or (at your option) any later version. 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci This program is distributed in the hope that it will be useful, 26262306a36Sopenharmony_ci but WITHOUT ANY WARRANTY; without even the implied warranty of 26362306a36Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26462306a36Sopenharmony_ci GNU General Public License for more details. 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci In addition: 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci Redistribution and use in source and binary forms, with or without 26962306a36Sopenharmony_ci modification, are permitted provided that the following conditions 27062306a36Sopenharmony_ci are met: 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci 1. Redistributions of source code must retain the above copyright 27362306a36Sopenharmony_ci notice, this list of conditions and the following disclaimer. 27462306a36Sopenharmony_ci 2. Redistributions in binary form must reproduce the above copyright 27562306a36Sopenharmony_ci notice, this list of conditions and the following disclaimer in the 27662306a36Sopenharmony_ci documentation and/or other materials provided with the distribution. 27762306a36Sopenharmony_ci 3. The name of the author may not be used to endorse or promote 27862306a36Sopenharmony_ci products derived from this software without specific prior written 27962306a36Sopenharmony_ci permission. 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 28262306a36Sopenharmony_ci IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28362306a36Sopenharmony_ci WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28462306a36Sopenharmony_ci ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 28562306a36Sopenharmony_ci INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28662306a36Sopenharmony_ci (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28762306a36Sopenharmony_ci SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28862306a36Sopenharmony_ci HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28962306a36Sopenharmony_ci STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29062306a36Sopenharmony_ci IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29162306a36Sopenharmony_ci POSSIBILITY OF SUCH DAMAGE. 29262306a36Sopenharmony_ci*/ 293