Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
| 2 | * $Id: smsc-ircc2.c,v 1.19.2.5 2002/10/27 11:34:26 dip Exp $ |
| 3 | * |
| 4 | * Description: Driver for the SMC Infrared Communications Controller |
| 5 | * Status: Experimental. |
| 6 | * Author: Daniele Peri (peri@csai.unipa.it) |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 7 | * Created at: |
| 8 | * Modified at: |
| 9 | * Modified by: |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Copyright (c) 2002 Daniele Peri |
| 12 | * All Rights Reserved. |
| 13 | * Copyright (c) 2002 Jean Tourrilhes |
| 14 | * |
| 15 | * |
| 16 | * Based on smc-ircc.c: |
| 17 | * |
| 18 | * Copyright (c) 2001 Stefani Seibold |
| 19 | * Copyright (c) 1999-2001 Dag Brattli |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 20 | * Copyright (c) 1998-1999 Thomas Davis, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * |
| 22 | * and irport.c: |
| 23 | * |
| 24 | * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved. |
| 25 | * |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 26 | * |
| 27 | * This program is free software; you can redistribute it and/or |
| 28 | * modify it under the terms of the GNU General Public License as |
| 29 | * published by the Free Software Foundation; either version 2 of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * the License, or (at your option) any later version. |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 31 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * This program is distributed in the hope that it will be useful, |
| 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 35 | * GNU General Public License for more details. |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 36 | * |
| 37 | * You should have received a copy of the GNU General Public License |
| 38 | * along with this program; if not, write to the Free Software |
| 39 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * MA 02111-1307 USA |
| 41 | * |
| 42 | ********************************************************************/ |
| 43 | |
| 44 | #include <linux/module.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/types.h> |
| 47 | #include <linux/skbuff.h> |
| 48 | #include <linux/netdevice.h> |
| 49 | #include <linux/ioport.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/slab.h> |
| 52 | #include <linux/init.h> |
| 53 | #include <linux/rtnetlink.h> |
| 54 | #include <linux/serial_reg.h> |
| 55 | #include <linux/dma-mapping.h> |
| 56 | |
| 57 | #include <asm/io.h> |
| 58 | #include <asm/dma.h> |
| 59 | #include <asm/byteorder.h> |
| 60 | |
| 61 | #include <linux/spinlock.h> |
| 62 | #include <linux/pm.h> |
| 63 | |
| 64 | #include <net/irda/wrapper.h> |
| 65 | #include <net/irda/irda.h> |
| 66 | #include <net/irda/irda_device.h> |
| 67 | |
| 68 | #include "smsc-ircc2.h" |
| 69 | #include "smsc-sio.h" |
| 70 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 71 | |
| 72 | MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>"); |
| 73 | MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver"); |
| 74 | MODULE_LICENSE("GPL"); |
| 75 | |
| 76 | |
| 77 | static int ircc_dma = 255; |
| 78 | module_param(ircc_dma, int, 0); |
| 79 | MODULE_PARM_DESC(ircc_dma, "DMA channel"); |
| 80 | |
| 81 | static int ircc_irq = 255; |
| 82 | module_param(ircc_irq, int, 0); |
| 83 | MODULE_PARM_DESC(ircc_irq, "IRQ line"); |
| 84 | |
| 85 | static int ircc_fir; |
| 86 | module_param(ircc_fir, int, 0); |
| 87 | MODULE_PARM_DESC(ircc_fir, "FIR Base Address"); |
| 88 | |
| 89 | static int ircc_sir; |
| 90 | module_param(ircc_sir, int, 0); |
| 91 | MODULE_PARM_DESC(ircc_sir, "SIR Base Address"); |
| 92 | |
| 93 | static int ircc_cfg; |
| 94 | module_param(ircc_cfg, int, 0); |
| 95 | MODULE_PARM_DESC(ircc_cfg, "Configuration register base address"); |
| 96 | |
| 97 | static int ircc_transceiver; |
| 98 | module_param(ircc_transceiver, int, 0); |
| 99 | MODULE_PARM_DESC(ircc_transceiver, "Transceiver type"); |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* Types */ |
| 102 | |
| 103 | struct smsc_transceiver { |
| 104 | char *name; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 105 | void (*set_for_speed)(int fir_base, u32 speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | int (*probe)(int fir_base); |
| 107 | }; |
| 108 | typedef struct smsc_transceiver smsc_transceiver_t; |
| 109 | |
| 110 | #if 0 |
| 111 | struct smc_chip { |
| 112 | char *name; |
| 113 | u16 flags; |
| 114 | u8 devid; |
| 115 | u8 rev; |
| 116 | }; |
| 117 | typedef struct smc_chip smc_chip_t; |
| 118 | #endif |
| 119 | |
| 120 | struct smsc_chip { |
| 121 | char *name; |
| 122 | #if 0 |
| 123 | u8 type; |
| 124 | #endif |
| 125 | u16 flags; |
| 126 | u8 devid; |
| 127 | u8 rev; |
| 128 | }; |
| 129 | typedef struct smsc_chip smsc_chip_t; |
| 130 | |
| 131 | struct smsc_chip_address { |
| 132 | unsigned int cfg_base; |
| 133 | unsigned int type; |
| 134 | }; |
| 135 | typedef struct smsc_chip_address smsc_chip_address_t; |
| 136 | |
| 137 | /* Private data for each instance */ |
| 138 | struct smsc_ircc_cb { |
| 139 | struct net_device *netdev; /* Yes! we are some kind of netdevice */ |
| 140 | struct net_device_stats stats; |
| 141 | struct irlap_cb *irlap; /* The link layer we are binded to */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | chipio_t io; /* IrDA controller information */ |
| 144 | iobuff_t tx_buff; /* Transmit buffer */ |
| 145 | iobuff_t rx_buff; /* Receive buffer */ |
| 146 | dma_addr_t tx_buff_dma; |
| 147 | dma_addr_t rx_buff_dma; |
| 148 | |
| 149 | struct qos_info qos; /* QoS capabilities for this device */ |
| 150 | |
| 151 | spinlock_t lock; /* For serializing operations */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | __u32 new_speed; |
| 154 | __u32 flags; /* Interface flags */ |
| 155 | |
| 156 | int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */ |
| 157 | int tx_len; /* Number of frames in tx_buff */ |
| 158 | |
| 159 | int transceiver; |
| 160 | struct pm_dev *pmdev; |
| 161 | }; |
| 162 | |
| 163 | /* Constants */ |
| 164 | |
| 165 | static const char *driver_name = "smsc-ircc2"; |
| 166 | #define DIM(x) (sizeof(x)/(sizeof(*(x)))) |
| 167 | #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600 |
| 168 | #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1 |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 169 | #define SMSC_IRCC2_C_NET_TIMEOUT 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | #define SMSC_IRCC2_C_SIR_STOP 0 |
| 171 | |
| 172 | /* Prototypes */ |
| 173 | |
| 174 | static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq); |
| 175 | static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base); |
| 176 | static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq); |
| 177 | static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self); |
| 178 | static void smsc_ircc_init_chip(struct smsc_ircc_cb *self); |
| 179 | static int __exit smsc_ircc_close(struct smsc_ircc_cb *self); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 180 | static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase); |
| 182 | static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self); |
| 183 | static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev); |
| 184 | static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev); |
| 185 | static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs); |
| 186 | static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase); |
| 187 | static void smsc_ircc_change_speed(void *priv, u32 speed); |
| 188 | static void smsc_ircc_set_sir_speed(void *priv, u32 speed); |
| 189 | static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs); |
| 190 | static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev); |
| 191 | static void smsc_ircc_sir_start(struct smsc_ircc_cb *self); |
| 192 | #if SMSC_IRCC2_C_SIR_STOP |
| 193 | static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self); |
| 194 | #endif |
| 195 | static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self); |
| 196 | static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len); |
| 197 | static int smsc_ircc_net_open(struct net_device *dev); |
| 198 | static int smsc_ircc_net_close(struct net_device *dev); |
| 199 | static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
| 200 | #if SMSC_IRCC2_C_NET_TIMEOUT |
| 201 | static void smsc_ircc_timeout(struct net_device *dev); |
| 202 | #endif |
| 203 | static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev); |
| 204 | static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data); |
| 205 | static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self); |
| 206 | static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self); |
| 207 | static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed); |
| 208 | static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self); |
| 209 | |
| 210 | /* Probing */ |
| 211 | static int __init smsc_ircc_look_for_chips(void); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 212 | static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const smsc_chip_t *chip, char *type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfg_base, char *type); |
| 214 | static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cfg_base, char *type); |
| 215 | static int __init smsc_superio_fdc(unsigned short cfg_base); |
| 216 | static int __init smsc_superio_lpc(unsigned short cfg_base); |
| 217 | |
| 218 | /* Transceivers specific functions */ |
| 219 | |
| 220 | static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed); |
| 221 | static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base); |
| 222 | static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed); |
| 223 | static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base); |
| 224 | static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed); |
| 225 | static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base); |
| 226 | |
| 227 | /* Power Management */ |
| 228 | |
| 229 | static void smsc_ircc_suspend(struct smsc_ircc_cb *self); |
| 230 | static void smsc_ircc_wakeup(struct smsc_ircc_cb *self); |
| 231 | static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data); |
| 232 | |
| 233 | |
| 234 | /* Transceivers for SMSC-ircc */ |
| 235 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 236 | static smsc_transceiver_t smsc_transceivers[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 238 | { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 }, |
| 239 | { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select }, |
| 240 | { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc }, |
| 241 | { NULL, NULL } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (DIM(smsc_transceivers)-1) |
| 244 | |
| 245 | /* SMC SuperIO chipsets definitions */ |
| 246 | |
| 247 | #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */ |
| 248 | #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */ |
| 249 | #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */ |
| 250 | #define SIR 0 /* SuperIO Chip has only slow IRDA */ |
| 251 | #define FIR 4 /* SuperIO Chip has fast IRDA */ |
| 252 | #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */ |
| 253 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 254 | static smsc_chip_t __initdata fdc_chips_flat[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
| 256 | /* Base address 0x3f0 or 0x370 */ |
| 257 | { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */ |
| 258 | { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 }, |
| 259 | { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 }, |
| 260 | { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 }, |
| 261 | { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */ |
| 262 | { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 }, |
| 263 | { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 }, |
| 264 | { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 }, |
| 265 | { NULL } |
| 266 | }; |
| 267 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 268 | static smsc_chip_t __initdata fdc_chips_paged[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
| 270 | /* Base address 0x3f0 or 0x370 */ |
| 271 | { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 }, |
| 272 | { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 }, |
| 273 | { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 }, |
| 274 | { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 }, |
| 275 | { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 }, |
| 276 | { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 }, |
| 277 | { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 }, |
| 278 | { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 }, |
| 279 | { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 }, |
| 280 | { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 }, |
| 281 | { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 }, |
| 282 | { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 }, |
| 283 | { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 }, |
| 284 | { NULL } |
| 285 | }; |
| 286 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 287 | static smsc_chip_t __initdata lpc_chips_flat[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
| 289 | /* Base address 0x2E or 0x4E */ |
| 290 | { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 }, |
| 291 | { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 }, |
| 292 | { NULL } |
| 293 | }; |
| 294 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 295 | static smsc_chip_t __initdata lpc_chips_paged[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | /* Base address 0x2E or 0x4E */ |
| 298 | { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 }, |
| 299 | { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 }, |
| 300 | { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 }, |
| 301 | { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 }, |
| 302 | { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 }, |
| 303 | { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 }, |
| 304 | { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 }, |
| 305 | { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 }, |
| 306 | { NULL } |
| 307 | }; |
| 308 | |
| 309 | #define SMSCSIO_TYPE_FDC 1 |
| 310 | #define SMSCSIO_TYPE_LPC 2 |
| 311 | #define SMSCSIO_TYPE_FLAT 4 |
| 312 | #define SMSCSIO_TYPE_PAGED 8 |
| 313 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 314 | static smsc_chip_address_t __initdata possible_addresses[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 316 | { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED }, |
| 317 | { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED }, |
| 318 | { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED }, |
| 319 | { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED }, |
| 320 | { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED }, |
| 321 | { 0, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | /* Globals */ |
| 325 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 326 | static struct smsc_ircc_cb *dev_self[] = { NULL, NULL }; |
| 327 | static unsigned short dev_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | static inline void register_bank(int iobase, int bank) |
| 330 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 331 | outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)), |
| 332 | iobase + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | |
| 336 | /******************************************************************************* |
| 337 | * |
| 338 | * |
| 339 | * SMSC-ircc stuff |
| 340 | * |
| 341 | * |
| 342 | *******************************************************************************/ |
| 343 | |
| 344 | /* |
| 345 | * Function smsc_ircc_init () |
| 346 | * |
| 347 | * Initialize chip. Just try to find out how many chips we are dealing with |
| 348 | * and where they are |
| 349 | */ |
| 350 | static int __init smsc_ircc_init(void) |
| 351 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 352 | int ret = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 355 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 356 | dev_count = 0; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 357 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 358 | if (ircc_fir > 0 && ircc_sir > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir); |
| 360 | IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir); |
| 361 | |
| 362 | if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq) == 0) |
| 363 | return 0; |
| 364 | |
| 365 | return -ENODEV; |
| 366 | } |
| 367 | |
| 368 | /* try user provided configuration register base address */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 369 | if (ircc_cfg > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | IRDA_MESSAGE(" Overriding configuration address 0x%04x\n", |
| 371 | ircc_cfg); |
| 372 | if (!smsc_superio_fdc(ircc_cfg)) |
| 373 | ret = 0; |
| 374 | if (!smsc_superio_lpc(ircc_cfg)) |
| 375 | ret = 0; |
| 376 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 377 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 378 | if (smsc_ircc_look_for_chips() > 0) |
| 379 | ret = 0; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Function smsc_ircc_open (firbase, sirbase, dma, irq) |
| 386 | * |
| 387 | * Try to open driver instance |
| 388 | * |
| 389 | */ |
| 390 | static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq) |
| 391 | { |
| 392 | struct smsc_ircc_cb *self; |
| 393 | struct net_device *dev; |
| 394 | int err; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 397 | |
| 398 | err = smsc_ircc_present(fir_base, sir_base); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 399 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | goto err_out; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | err = -ENOMEM; |
| 403 | if (dev_count > DIM(dev_self)) { |
| 404 | IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__); |
| 405 | goto err_out1; |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * Allocate new instance of the driver |
| 410 | */ |
| 411 | dev = alloc_irdadev(sizeof(struct smsc_ircc_cb)); |
| 412 | if (!dev) { |
| 413 | IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__); |
| 414 | goto err_out1; |
| 415 | } |
| 416 | |
| 417 | SET_MODULE_OWNER(dev); |
| 418 | |
| 419 | dev->hard_start_xmit = smsc_ircc_hard_xmit_sir; |
| 420 | #if SMSC_IRCC2_C_NET_TIMEOUT |
| 421 | dev->tx_timeout = smsc_ircc_timeout; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 422 | dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | #endif |
| 424 | dev->open = smsc_ircc_net_open; |
| 425 | dev->stop = smsc_ircc_net_close; |
| 426 | dev->do_ioctl = smsc_ircc_net_ioctl; |
| 427 | dev->get_stats = smsc_ircc_net_get_stats; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | self = dev->priv; |
| 430 | self->netdev = dev; |
| 431 | |
| 432 | /* Make ifconfig display some details */ |
| 433 | dev->base_addr = self->io.fir_base = fir_base; |
| 434 | dev->irq = self->io.irq = irq; |
| 435 | |
| 436 | /* Need to store self somewhere */ |
| 437 | dev_self[dev_count++] = self; |
| 438 | spin_lock_init(&self->lock); |
| 439 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 440 | self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE; |
| 442 | |
| 443 | self->rx_buff.head = |
| 444 | dma_alloc_coherent(NULL, self->rx_buff.truesize, |
| 445 | &self->rx_buff_dma, GFP_KERNEL); |
| 446 | if (self->rx_buff.head == NULL) { |
| 447 | IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n", |
| 448 | driver_name); |
| 449 | goto err_out2; |
| 450 | } |
| 451 | |
| 452 | self->tx_buff.head = |
| 453 | dma_alloc_coherent(NULL, self->tx_buff.truesize, |
| 454 | &self->tx_buff_dma, GFP_KERNEL); |
| 455 | if (self->tx_buff.head == NULL) { |
| 456 | IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n", |
| 457 | driver_name); |
| 458 | goto err_out3; |
| 459 | } |
| 460 | |
| 461 | memset(self->rx_buff.head, 0, self->rx_buff.truesize); |
| 462 | memset(self->tx_buff.head, 0, self->tx_buff.truesize); |
| 463 | |
| 464 | self->rx_buff.in_frame = FALSE; |
| 465 | self->rx_buff.state = OUTSIDE_FRAME; |
| 466 | self->tx_buff.data = self->tx_buff.head; |
| 467 | self->rx_buff.data = self->rx_buff.head; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | smsc_ircc_setup_qos(self); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | smsc_ircc_init_chip(self); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 472 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 473 | if (ircc_transceiver > 0 && |
| 474 | ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | self->transceiver = ircc_transceiver; |
| 476 | else |
| 477 | smsc_ircc_probe_transceiver(self); |
| 478 | |
| 479 | err = register_netdev(self->netdev); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 480 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | IRDA_ERROR("%s, Network device registration failed!\n", |
| 482 | driver_name); |
| 483 | goto err_out4; |
| 484 | } |
| 485 | |
| 486 | self->pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, smsc_ircc_pmproc); |
| 487 | if (self->pmdev) |
| 488 | self->pmdev->data = self; |
| 489 | |
| 490 | IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name); |
| 491 | |
| 492 | return 0; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | err_out4: |
| 495 | dma_free_coherent(NULL, self->tx_buff.truesize, |
| 496 | self->tx_buff.head, self->tx_buff_dma); |
| 497 | err_out3: |
| 498 | dma_free_coherent(NULL, self->rx_buff.truesize, |
| 499 | self->rx_buff.head, self->rx_buff_dma); |
| 500 | err_out2: |
| 501 | free_netdev(self->netdev); |
| 502 | dev_self[--dev_count] = NULL; |
| 503 | err_out1: |
| 504 | release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT); |
| 505 | release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT); |
| 506 | err_out: |
| 507 | return err; |
| 508 | } |
| 509 | |
| 510 | /* |
| 511 | * Function smsc_ircc_present(fir_base, sir_base) |
| 512 | * |
| 513 | * Check the smsc-ircc chip presence |
| 514 | * |
| 515 | */ |
| 516 | static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base) |
| 517 | { |
| 518 | unsigned char low, high, chip, config, dma, irq, version; |
| 519 | |
| 520 | if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT, |
| 521 | driver_name)) { |
| 522 | IRDA_WARNING("%s: can't get fir_base of 0x%03x\n", |
| 523 | __FUNCTION__, fir_base); |
| 524 | goto out1; |
| 525 | } |
| 526 | |
| 527 | if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT, |
| 528 | driver_name)) { |
| 529 | IRDA_WARNING("%s: can't get sir_base of 0x%03x\n", |
| 530 | __FUNCTION__, sir_base); |
| 531 | goto out2; |
| 532 | } |
| 533 | |
| 534 | register_bank(fir_base, 3); |
| 535 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 536 | high = inb(fir_base + IRCC_ID_HIGH); |
| 537 | low = inb(fir_base + IRCC_ID_LOW); |
| 538 | chip = inb(fir_base + IRCC_CHIP_ID); |
| 539 | version = inb(fir_base + IRCC_VERSION); |
| 540 | config = inb(fir_base + IRCC_INTERFACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | dma = config & IRCC_INTERFACE_DMA_MASK; |
| 542 | irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4; |
| 543 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 544 | if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 545 | IRDA_WARNING("%s(), addr 0x%04x - no device found!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | __FUNCTION__, fir_base); |
| 547 | goto out3; |
| 548 | } |
| 549 | IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, " |
| 550 | "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n", |
| 551 | chip & 0x0f, version, fir_base, sir_base, dma, irq); |
| 552 | |
| 553 | return 0; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | out3: |
| 556 | release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT); |
| 557 | out2: |
| 558 | release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT); |
| 559 | out1: |
| 560 | return -ENODEV; |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq) |
| 565 | * |
| 566 | * Setup I/O |
| 567 | * |
| 568 | */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 569 | static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, |
| 570 | unsigned int fir_base, unsigned int sir_base, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | u8 dma, u8 irq) |
| 572 | { |
| 573 | unsigned char config, chip_dma, chip_irq; |
| 574 | |
| 575 | register_bank(fir_base, 3); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 576 | config = inb(fir_base + IRCC_INTERFACE); |
| 577 | chip_dma = config & IRCC_INTERFACE_DMA_MASK; |
| 578 | chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | self->io.fir_base = fir_base; |
| 581 | self->io.sir_base = sir_base; |
| 582 | self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT; |
| 583 | self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT; |
| 584 | self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE; |
| 585 | self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED; |
| 586 | |
| 587 | if (irq < 255) { |
| 588 | if (irq != chip_irq) |
| 589 | IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n", |
| 590 | driver_name, chip_irq, irq); |
| 591 | self->io.irq = irq; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 592 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | self->io.irq = chip_irq; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | if (dma < 255) { |
| 596 | if (dma != chip_dma) |
| 597 | IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n", |
| 598 | driver_name, chip_dma, dma); |
| 599 | self->io.dma = dma; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 600 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | self->io.dma = chip_dma; |
| 602 | |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * Function smsc_ircc_setup_qos(self) |
| 607 | * |
| 608 | * Setup qos |
| 609 | * |
| 610 | */ |
| 611 | static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self) |
| 612 | { |
| 613 | /* Initialize QoS for this device */ |
| 614 | irda_init_max_qos_capabilies(&self->qos); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600| |
| 617 | IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); |
| 618 | |
| 619 | self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME; |
| 620 | self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE; |
| 621 | irda_qos_bits_to_value(&self->qos); |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * Function smsc_ircc_init_chip(self) |
| 626 | * |
| 627 | * Init chip |
| 628 | * |
| 629 | */ |
| 630 | static void smsc_ircc_init_chip(struct smsc_ircc_cb *self) |
| 631 | { |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 632 | int iobase, ir_mode, ctrl, fast; |
| 633 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 634 | IRDA_ASSERT(self != NULL, return;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 636 | iobase = self->io.fir_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | ir_mode = IRCC_CFGA_IRDA_SIR_A; |
| 638 | ctrl = 0; |
| 639 | fast = 0; |
| 640 | |
| 641 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 642 | outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER); |
| 643 | outb(0x00, iobase + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | register_bank(iobase, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 646 | outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode), |
| 647 | iobase + IRCC_SCE_CFGA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
| 649 | #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 650 | outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM), |
| 651 | iobase + IRCC_SCE_CFGB); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 652 | #else |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 653 | outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR), |
| 654 | iobase + IRCC_SCE_CFGB); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 655 | #endif |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 656 | (void) inb(iobase + IRCC_FIFO_THRESHOLD); |
| 657 | outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | register_bank(iobase, 4); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 660 | outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 663 | outb(fast, iobase + IRCC_LCR_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
| 665 | smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | /* Power on device */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 668 | outb(0x00, iobase + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /* |
| 672 | * Function smsc_ircc_net_ioctl (dev, rq, cmd) |
| 673 | * |
| 674 | * Process IOCTL commands for this device |
| 675 | * |
| 676 | */ |
| 677 | static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 678 | { |
| 679 | struct if_irda_req *irq = (struct if_irda_req *) rq; |
| 680 | struct smsc_ircc_cb *self; |
| 681 | unsigned long flags; |
| 682 | int ret = 0; |
| 683 | |
| 684 | IRDA_ASSERT(dev != NULL, return -1;); |
| 685 | |
| 686 | self = dev->priv; |
| 687 | |
| 688 | IRDA_ASSERT(self != NULL, return -1;); |
| 689 | |
| 690 | IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | switch (cmd) { |
| 693 | case SIOCSBANDWIDTH: /* Set bandwidth */ |
| 694 | if (!capable(CAP_NET_ADMIN)) |
| 695 | ret = -EPERM; |
| 696 | else { |
| 697 | /* Make sure we are the only one touching |
| 698 | * self->io.speed and the hardware - Jean II */ |
| 699 | spin_lock_irqsave(&self->lock, flags); |
| 700 | smsc_ircc_change_speed(self, irq->ifr_baudrate); |
| 701 | spin_unlock_irqrestore(&self->lock, flags); |
| 702 | } |
| 703 | break; |
| 704 | case SIOCSMEDIABUSY: /* Set media busy */ |
| 705 | if (!capable(CAP_NET_ADMIN)) { |
| 706 | ret = -EPERM; |
| 707 | break; |
| 708 | } |
| 709 | |
| 710 | irda_device_set_media_busy(self->netdev, TRUE); |
| 711 | break; |
| 712 | case SIOCGRECEIVING: /* Check if we are receiving right now */ |
| 713 | irq->ifr_receiving = smsc_ircc_is_receiving(self); |
| 714 | break; |
| 715 | #if 0 |
| 716 | case SIOCSDTRRTS: |
| 717 | if (!capable(CAP_NET_ADMIN)) { |
| 718 | ret = -EPERM; |
| 719 | break; |
| 720 | } |
| 721 | smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts); |
| 722 | break; |
| 723 | #endif |
| 724 | default: |
| 725 | ret = -EOPNOTSUPP; |
| 726 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | return ret; |
| 729 | } |
| 730 | |
| 731 | static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev) |
| 732 | { |
| 733 | struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) dev->priv; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return &self->stats; |
| 736 | } |
| 737 | |
| 738 | #if SMSC_IRCC2_C_NET_TIMEOUT |
| 739 | /* |
| 740 | * Function smsc_ircc_timeout (struct net_device *dev) |
| 741 | * |
| 742 | * The networking timeout management. |
| 743 | * |
| 744 | */ |
| 745 | |
| 746 | static void smsc_ircc_timeout(struct net_device *dev) |
| 747 | { |
| 748 | struct smsc_ircc_cb *self; |
| 749 | unsigned long flags; |
| 750 | |
| 751 | self = (struct smsc_ircc_cb *) dev->priv; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n", |
| 754 | dev->name, self->io.speed); |
| 755 | spin_lock_irqsave(&self->lock, flags); |
| 756 | smsc_ircc_sir_start(self); |
| 757 | smsc_ircc_change_speed(self, self->io.speed); |
| 758 | dev->trans_start = jiffies; |
| 759 | netif_wake_queue(dev); |
| 760 | spin_unlock_irqrestore(&self->lock, flags); |
| 761 | } |
| 762 | #endif |
| 763 | |
| 764 | /* |
| 765 | * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev) |
| 766 | * |
| 767 | * Transmits the current frame until FIFO is full, then |
| 768 | * waits until the next transmit interrupt, and continues until the |
| 769 | * frame is transmitted. |
| 770 | */ |
| 771 | int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev) |
| 772 | { |
| 773 | struct smsc_ircc_cb *self; |
| 774 | unsigned long flags; |
| 775 | int iobase; |
| 776 | s32 speed; |
| 777 | |
| 778 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 779 | |
| 780 | IRDA_ASSERT(dev != NULL, return 0;); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | self = (struct smsc_ircc_cb *) dev->priv; |
| 783 | IRDA_ASSERT(self != NULL, return 0;); |
| 784 | |
| 785 | iobase = self->io.sir_base; |
| 786 | |
| 787 | netif_stop_queue(dev); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /* Make sure test of self->io.speed & speed change are atomic */ |
| 790 | spin_lock_irqsave(&self->lock, flags); |
| 791 | |
| 792 | /* Check if we need to change the speed */ |
| 793 | speed = irda_get_next_speed(skb); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 794 | if (speed != self->io.speed && speed != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | /* Check for empty frame */ |
| 796 | if (!skb->len) { |
| 797 | /* |
| 798 | * We send frames one by one in SIR mode (no |
| 799 | * pipelining), so at this point, if we were sending |
| 800 | * a previous frame, we just received the interrupt |
| 801 | * telling us it is finished (UART_IIR_THRI). |
| 802 | * Therefore, waiting for the transmitter to really |
| 803 | * finish draining the fifo won't take too long. |
| 804 | * And the interrupt handler is not expected to run. |
| 805 | * - Jean II */ |
| 806 | smsc_ircc_sir_wait_hw_transmitter_finish(self); |
| 807 | smsc_ircc_change_speed(self, speed); |
| 808 | spin_unlock_irqrestore(&self->lock, flags); |
| 809 | dev_kfree_skb(skb); |
| 810 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 812 | self->new_speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /* Init tx buffer */ |
| 816 | self->tx_buff.data = self->tx_buff.head; |
| 817 | |
| 818 | /* Copy skb to tx_buff while wrapping, stuffing and making CRC */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 819 | self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | self->tx_buff.truesize); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | self->stats.tx_bytes += self->tx_buff.len; |
| 823 | |
| 824 | /* Turn on transmit finished interrupt. Will fire immediately! */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 825 | outb(UART_IER_THRI, iobase + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | spin_unlock_irqrestore(&self->lock, flags); |
| 828 | |
| 829 | dev_kfree_skb(skb); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | * Function smsc_ircc_set_fir_speed (self, baud) |
| 836 | * |
| 837 | * Change the speed of the device |
| 838 | * |
| 839 | */ |
| 840 | static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed) |
| 841 | { |
| 842 | int fir_base, ir_mode, ctrl, fast; |
| 843 | |
| 844 | IRDA_ASSERT(self != NULL, return;); |
| 845 | fir_base = self->io.fir_base; |
| 846 | |
| 847 | self->io.speed = speed; |
| 848 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 849 | switch (speed) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | default: |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 851 | case 576000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | ir_mode = IRCC_CFGA_IRDA_HDLC; |
| 853 | ctrl = IRCC_CRC; |
| 854 | fast = 0; |
| 855 | IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__); |
| 856 | break; |
| 857 | case 1152000: |
| 858 | ir_mode = IRCC_CFGA_IRDA_HDLC; |
| 859 | ctrl = IRCC_1152 | IRCC_CRC; |
| 860 | fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA; |
| 861 | IRDA_DEBUG(0, "%s(), handling baud of 1152000\n", |
| 862 | __FUNCTION__); |
| 863 | break; |
| 864 | case 4000000: |
| 865 | ir_mode = IRCC_CFGA_IRDA_4PPM; |
| 866 | ctrl = IRCC_CRC; |
| 867 | fast = IRCC_LCR_A_FAST; |
| 868 | IRDA_DEBUG(0, "%s(), handling baud of 4000000\n", |
| 869 | __FUNCTION__); |
| 870 | break; |
| 871 | } |
| 872 | #if 0 |
| 873 | Now in tranceiver! |
| 874 | /* This causes an interrupt */ |
| 875 | register_bank(fir_base, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 876 | outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | #endif |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | register_bank(fir_base, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 880 | outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | register_bank(fir_base, 4); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 883 | outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /* |
| 887 | * Function smsc_ircc_fir_start(self) |
| 888 | * |
| 889 | * Change the speed of the device |
| 890 | * |
| 891 | */ |
| 892 | static void smsc_ircc_fir_start(struct smsc_ircc_cb *self) |
| 893 | { |
| 894 | struct net_device *dev; |
| 895 | int fir_base; |
| 896 | |
| 897 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 898 | |
| 899 | IRDA_ASSERT(self != NULL, return;); |
| 900 | dev = self->netdev; |
| 901 | IRDA_ASSERT(dev != NULL, return;); |
| 902 | |
| 903 | fir_base = self->io.fir_base; |
| 904 | |
| 905 | /* Reset everything */ |
| 906 | |
| 907 | /* Install FIR transmit handler */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 908 | dev->hard_start_xmit = smsc_ircc_hard_xmit_fir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
| 910 | /* Clear FIFO */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 911 | outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | /* Enable interrupt */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 914 | /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | register_bank(fir_base, 1); |
| 917 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 918 | /* Select the TX/RX interface */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 920 | outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM), |
| 921 | fir_base + IRCC_SCE_CFGB); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 922 | #else |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 923 | outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR), |
| 924 | fir_base + IRCC_SCE_CFGB); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 925 | #endif |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 926 | (void) inb(fir_base + IRCC_FIFO_THRESHOLD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | /* Enable SCE interrupts */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 929 | outb(0, fir_base + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | register_bank(fir_base, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 931 | outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER); |
| 932 | outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* |
| 936 | * Function smsc_ircc_fir_stop(self, baud) |
| 937 | * |
| 938 | * Change the speed of the device |
| 939 | * |
| 940 | */ |
| 941 | static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self) |
| 942 | { |
| 943 | int fir_base; |
| 944 | |
| 945 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | IRDA_ASSERT(self != NULL, return;); |
| 948 | |
| 949 | fir_base = self->io.fir_base; |
| 950 | register_bank(fir_base, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 951 | /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/ |
| 952 | outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | |
| 956 | /* |
| 957 | * Function smsc_ircc_change_speed(self, baud) |
| 958 | * |
| 959 | * Change the speed of the device |
| 960 | * |
| 961 | * This function *must* be called with spinlock held, because it may |
| 962 | * be called from the irq handler. - Jean II |
| 963 | */ |
| 964 | static void smsc_ircc_change_speed(void *priv, u32 speed) |
| 965 | { |
| 966 | struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv; |
| 967 | struct net_device *dev; |
| 968 | int iobase; |
| 969 | int last_speed_was_sir; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed); |
| 972 | |
| 973 | IRDA_ASSERT(self != NULL, return;); |
| 974 | dev = self->netdev; |
| 975 | iobase = self->io.fir_base; |
| 976 | |
| 977 | last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED; |
| 978 | |
| 979 | #if 0 |
| 980 | /* Temp Hack */ |
| 981 | speed= 1152000; |
| 982 | self->io.speed = speed; |
| 983 | last_speed_was_sir = 0; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 984 | smsc_ircc_fir_start(self); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | #endif |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 986 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 987 | if (self->io.speed == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | smsc_ircc_sir_start(self); |
| 989 | |
| 990 | #if 0 |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 991 | if (!last_speed_was_sir) speed = self->io.speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | #endif |
| 993 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 994 | if (self->io.speed != speed) |
| 995 | smsc_ircc_set_transceiver_for_speed(self, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
| 997 | self->io.speed = speed; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 998 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 999 | if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) { |
| 1000 | if (!last_speed_was_sir) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | smsc_ircc_fir_stop(self); |
| 1002 | smsc_ircc_sir_start(self); |
| 1003 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1004 | smsc_ircc_set_sir_speed(self, speed); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1005 | } else { |
| 1006 | if (last_speed_was_sir) { |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1007 | #if SMSC_IRCC2_C_SIR_STOP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | smsc_ircc_sir_stop(self); |
| 1009 | #endif |
| 1010 | smsc_ircc_fir_start(self); |
| 1011 | } |
| 1012 | smsc_ircc_set_fir_speed(self, speed); |
| 1013 | |
| 1014 | #if 0 |
| 1015 | self->tx_buff.len = 10; |
| 1016 | self->tx_buff.data = self->tx_buff.head; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | smsc_ircc_dma_xmit(self, iobase, 4000); |
| 1019 | #endif |
| 1020 | /* Be ready for incoming frames */ |
| 1021 | smsc_ircc_dma_receive(self, iobase); |
| 1022 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | netif_wake_queue(dev); |
| 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | * Function smsc_ircc_set_sir_speed (self, speed) |
| 1029 | * |
| 1030 | * Set speed of IrDA port to specified baudrate |
| 1031 | * |
| 1032 | */ |
| 1033 | void smsc_ircc_set_sir_speed(void *priv, __u32 speed) |
| 1034 | { |
| 1035 | struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1036 | int iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | int fcr; /* FIFO control reg */ |
| 1038 | int lcr; /* Line control reg */ |
| 1039 | int divisor; |
| 1040 | |
| 1041 | IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed); |
| 1042 | |
| 1043 | IRDA_ASSERT(self != NULL, return;); |
| 1044 | iobase = self->io.sir_base; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | /* Update accounting for new speed */ |
| 1047 | self->io.speed = speed; |
| 1048 | |
| 1049 | /* Turn off interrupts */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1050 | outb(0, iobase + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1052 | divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | fcr = UART_FCR_ENABLE_FIFO; |
| 1055 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1056 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and |
| 1058 | * almost 1,7 ms at 19200 bps. At speeds above that we can just forget |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1059 | * about this timeout since it will always be fast enough. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1061 | fcr |= self->io.speed < 38400 ? |
| 1062 | UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | /* IrDA ports use 8N1 */ |
| 1065 | lcr = UART_LCR_WLEN8; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1066 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1067 | outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */ |
| 1068 | outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */ |
| 1069 | outb(divisor >> 8, iobase + UART_DLM); |
| 1070 | outb(lcr, iobase + UART_LCR); /* Set 8N1 */ |
| 1071 | outb(fcr, iobase + UART_FCR); /* Enable FIFO's */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | /* Turn on interrups */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1074 | outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
| 1076 | IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed); |
| 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | /* |
| 1081 | * Function smsc_ircc_hard_xmit_fir (skb, dev) |
| 1082 | * |
| 1083 | * Transmit the frame! |
| 1084 | * |
| 1085 | */ |
| 1086 | static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev) |
| 1087 | { |
| 1088 | struct smsc_ircc_cb *self; |
| 1089 | unsigned long flags; |
| 1090 | s32 speed; |
| 1091 | int iobase; |
| 1092 | int mtt; |
| 1093 | |
| 1094 | IRDA_ASSERT(dev != NULL, return 0;); |
| 1095 | self = (struct smsc_ircc_cb *) dev->priv; |
| 1096 | IRDA_ASSERT(self != NULL, return 0;); |
| 1097 | |
| 1098 | iobase = self->io.fir_base; |
| 1099 | |
| 1100 | netif_stop_queue(dev); |
| 1101 | |
| 1102 | /* Make sure test of self->io.speed & speed change are atomic */ |
| 1103 | spin_lock_irqsave(&self->lock, flags); |
| 1104 | |
| 1105 | /* Check if we need to change the speed after this frame */ |
| 1106 | speed = irda_get_next_speed(skb); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1107 | if (speed != self->io.speed && speed != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | /* Check for empty frame */ |
| 1109 | if (!skb->len) { |
| 1110 | /* Note : you should make sure that speed changes |
| 1111 | * are not going to corrupt any outgoing frame. |
| 1112 | * Look at nsc-ircc for the gory details - Jean II */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1113 | smsc_ircc_change_speed(self, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | spin_unlock_irqrestore(&self->lock, flags); |
| 1115 | dev_kfree_skb(skb); |
| 1116 | return 0; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1117 | } |
| 1118 | |
| 1119 | self->new_speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | memcpy(self->tx_buff.head, skb->data, skb->len); |
| 1123 | |
| 1124 | self->tx_buff.len = skb->len; |
| 1125 | self->tx_buff.data = self->tx_buff.head; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1126 | |
| 1127 | mtt = irda_get_mtt(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | if (mtt) { |
| 1129 | int bofs; |
| 1130 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1131 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | * Compute how many BOFs (STA or PA's) we need to waste the |
| 1133 | * min turn time given the speed of the link. |
| 1134 | */ |
| 1135 | bofs = mtt * (self->io.speed / 1000) / 8000; |
| 1136 | if (bofs > 4095) |
| 1137 | bofs = 4095; |
| 1138 | |
| 1139 | smsc_ircc_dma_xmit(self, iobase, bofs); |
| 1140 | } else { |
| 1141 | /* Transmit frame */ |
| 1142 | smsc_ircc_dma_xmit(self, iobase, 0); |
| 1143 | } |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | spin_unlock_irqrestore(&self->lock, flags); |
| 1146 | dev_kfree_skb(skb); |
| 1147 | |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * Function smsc_ircc_dma_xmit (self, iobase) |
| 1153 | * |
| 1154 | * Transmit data using DMA |
| 1155 | * |
| 1156 | */ |
| 1157 | static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs) |
| 1158 | { |
| 1159 | u8 ctrl; |
| 1160 | |
| 1161 | IRDA_DEBUG(3, "%s\n", __FUNCTION__); |
| 1162 | #if 1 |
| 1163 | /* Disable Rx */ |
| 1164 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1165 | outb(0x00, iobase + IRCC_LCR_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | #endif |
| 1167 | register_bank(iobase, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1168 | outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, |
| 1169 | iobase + IRCC_SCE_CFGB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
| 1171 | self->io.direction = IO_XMIT; |
| 1172 | |
| 1173 | /* Set BOF additional count for generating the min turn time */ |
| 1174 | register_bank(iobase, 4); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1175 | outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO); |
| 1176 | ctrl = inb(iobase + IRCC_CONTROL) & 0xf0; |
| 1177 | outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
| 1179 | /* Set max Tx frame size */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1180 | outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI); |
| 1181 | outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
| 1183 | /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | /* Enable burst mode chip Tx DMA */ |
| 1186 | register_bank(iobase, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1187 | outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE | |
| 1188 | IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
| 1190 | /* Setup DMA controller (must be done after enabling chip DMA) */ |
| 1191 | irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len, |
| 1192 | DMA_TX_MODE); |
| 1193 | |
| 1194 | /* Enable interrupt */ |
| 1195 | |
| 1196 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1197 | outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER); |
| 1198 | outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | /* Enable transmit */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1201 | outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 | * Function smsc_ircc_dma_xmit_complete (self) |
| 1206 | * |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1207 | * The transfer of a frame in finished. This function will only be called |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | * by the interrupt handler |
| 1209 | * |
| 1210 | */ |
| 1211 | static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase) |
| 1212 | { |
| 1213 | IRDA_DEBUG(3, "%s\n", __FUNCTION__); |
| 1214 | #if 0 |
| 1215 | /* Disable Tx */ |
| 1216 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1217 | outb(0x00, iobase + IRCC_LCR_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | #endif |
| 1219 | register_bank(self->io.fir_base, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1220 | outb(inb(self->io.fir_base + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, |
| 1221 | self->io.fir_base + IRCC_SCE_CFGB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
| 1223 | /* Check for underrun! */ |
| 1224 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1225 | if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | self->stats.tx_errors++; |
| 1227 | self->stats.tx_fifo_errors++; |
| 1228 | |
| 1229 | /* Reset error condition */ |
| 1230 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1231 | outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER); |
| 1232 | outb(0x00, iobase + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | } else { |
| 1234 | self->stats.tx_packets++; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1235 | self->stats.tx_bytes += self->tx_buff.len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | /* Check if it's time to change the speed */ |
| 1239 | if (self->new_speed) { |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1240 | smsc_ircc_change_speed(self, self->new_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | self->new_speed = 0; |
| 1242 | } |
| 1243 | |
| 1244 | netif_wake_queue(self->netdev); |
| 1245 | } |
| 1246 | |
| 1247 | /* |
| 1248 | * Function smsc_ircc_dma_receive(self) |
| 1249 | * |
| 1250 | * Get ready for receiving a frame. The device will initiate a DMA |
| 1251 | * if it starts to receive a frame. |
| 1252 | * |
| 1253 | */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1254 | static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | { |
| 1256 | #if 0 |
| 1257 | /* Turn off chip DMA */ |
| 1258 | register_bank(iobase, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1259 | outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, |
| 1260 | iobase + IRCC_SCE_CFGB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | #endif |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | /* Disable Tx */ |
| 1264 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1265 | outb(0x00, iobase + IRCC_LCR_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
| 1267 | /* Turn off chip DMA */ |
| 1268 | register_bank(iobase, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1269 | outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, |
| 1270 | iobase + IRCC_SCE_CFGB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | |
| 1272 | self->io.direction = IO_RECV; |
| 1273 | self->rx_buff.data = self->rx_buff.head; |
| 1274 | |
| 1275 | /* Set max Rx frame size */ |
| 1276 | register_bank(iobase, 4); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1277 | outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI); |
| 1278 | outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
| 1280 | /* Setup DMA controller */ |
| 1281 | irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize, |
| 1282 | DMA_RX_MODE); |
| 1283 | |
| 1284 | /* Enable burst mode chip Rx DMA */ |
| 1285 | register_bank(iobase, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1286 | outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE | |
| 1287 | IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
| 1289 | /* Enable interrupt */ |
| 1290 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1291 | outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER); |
| 1292 | outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* Enable receiver */ |
| 1295 | register_bank(iobase, 0); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1296 | outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE, |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1297 | iobase + IRCC_LCR_B); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | /* |
| 1303 | * Function smsc_ircc_dma_receive_complete(self, iobase) |
| 1304 | * |
| 1305 | * Finished with receiving frames |
| 1306 | * |
| 1307 | */ |
| 1308 | static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase) |
| 1309 | { |
| 1310 | struct sk_buff *skb; |
| 1311 | int len, msgcnt, lsr; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | register_bank(iobase, 0); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | IRDA_DEBUG(3, "%s\n", __FUNCTION__); |
| 1316 | #if 0 |
| 1317 | /* Disable Rx */ |
| 1318 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1319 | outb(0x00, iobase + IRCC_LCR_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | #endif |
| 1321 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1322 | outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR); |
| 1323 | lsr= inb(iobase + IRCC_LSR); |
| 1324 | msgcnt = inb(iobase + IRCC_LCR_B) & 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
| 1326 | IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__, |
| 1327 | get_dma_residue(self->io.dma)); |
| 1328 | |
| 1329 | len = self->rx_buff.truesize - get_dma_residue(self->io.dma); |
| 1330 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1331 | /* Look for errors */ |
| 1332 | if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | self->stats.rx_errors++; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1334 | if (lsr & IRCC_LSR_FRAME_ERROR) |
| 1335 | self->stats.rx_frame_errors++; |
| 1336 | if (lsr & IRCC_LSR_CRC_ERROR) |
| 1337 | self->stats.rx_crc_errors++; |
| 1338 | if (lsr & IRCC_LSR_SIZE_ERROR) |
| 1339 | self->stats.rx_length_errors++; |
| 1340 | if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN)) |
| 1341 | self->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | return; |
| 1343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1345 | /* Remove CRC */ |
| 1346 | len -= self->io.speed < 4000000 ? 2 : 4; |
| 1347 | |
| 1348 | if (len < 2 || len > 2050) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len); |
| 1350 | return; |
| 1351 | } |
| 1352 | IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len); |
| 1353 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1354 | skb = dev_alloc_skb(len + 1); |
| 1355 | if (!skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | IRDA_WARNING("%s(), memory squeeze, dropping frame.\n", |
| 1357 | __FUNCTION__); |
| 1358 | return; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | /* Make sure IP header gets aligned */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1361 | skb_reserve(skb, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
| 1363 | memcpy(skb_put(skb, len), self->rx_buff.data, len); |
| 1364 | self->stats.rx_packets++; |
| 1365 | self->stats.rx_bytes += len; |
| 1366 | |
| 1367 | skb->dev = self->netdev; |
| 1368 | skb->mac.raw = skb->data; |
| 1369 | skb->protocol = htons(ETH_P_IRDA); |
| 1370 | netif_rx(skb); |
| 1371 | } |
| 1372 | |
| 1373 | /* |
| 1374 | * Function smsc_ircc_sir_receive (self) |
| 1375 | * |
| 1376 | * Receive one frame from the infrared port |
| 1377 | * |
| 1378 | */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1379 | static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | { |
| 1381 | int boguscount = 0; |
| 1382 | int iobase; |
| 1383 | |
| 1384 | IRDA_ASSERT(self != NULL, return;); |
| 1385 | |
| 1386 | iobase = self->io.sir_base; |
| 1387 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1388 | /* |
| 1389 | * Receive all characters in Rx FIFO, unwrap and unstuff them. |
| 1390 | * async_unwrap_char will deliver all found frames |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | */ |
| 1392 | do { |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1393 | async_unwrap_char(self->netdev, &self->stats, &self->rx_buff, |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1394 | inb(iobase + UART_RX)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
| 1396 | /* Make sure we don't stay here to long */ |
| 1397 | if (boguscount++ > 32) { |
| 1398 | IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__); |
| 1399 | break; |
| 1400 | } |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1401 | } while (inb(iobase + UART_LSR) & UART_LSR_DR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | |
| 1405 | /* |
| 1406 | * Function smsc_ircc_interrupt (irq, dev_id, regs) |
| 1407 | * |
| 1408 | * An interrupt from the chip has arrived. Time to do some work |
| 1409 | * |
| 1410 | */ |
| 1411 | static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 1412 | { |
| 1413 | struct net_device *dev = (struct net_device *) dev_id; |
| 1414 | struct smsc_ircc_cb *self; |
| 1415 | int iobase, iir, lcra, lsr; |
| 1416 | irqreturn_t ret = IRQ_NONE; |
| 1417 | |
| 1418 | if (dev == NULL) { |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1419 | printk(KERN_WARNING "%s: irq %d for unknown device.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | driver_name, irq); |
| 1421 | goto irq_ret; |
| 1422 | } |
| 1423 | self = (struct smsc_ircc_cb *) dev->priv; |
| 1424 | IRDA_ASSERT(self != NULL, return IRQ_NONE;); |
| 1425 | |
| 1426 | /* Serialise the interrupt handler in various CPUs, stop Tx path */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1427 | spin_lock(&self->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
| 1429 | /* Check if we should use the SIR interrupt handler */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1430 | if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | ret = smsc_ircc_interrupt_sir(dev); |
| 1432 | goto irq_ret_unlock; |
| 1433 | } |
| 1434 | |
| 1435 | iobase = self->io.fir_base; |
| 1436 | |
| 1437 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1438 | iir = inb(iobase + IRCC_IIR); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1439 | if (iir == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | goto irq_ret_unlock; |
| 1441 | ret = IRQ_HANDLED; |
| 1442 | |
| 1443 | /* Disable interrupts */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1444 | outb(0, iobase + IRCC_IER); |
| 1445 | lcra = inb(iobase + IRCC_LCR_A); |
| 1446 | lsr = inb(iobase + IRCC_LSR); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir); |
| 1449 | |
| 1450 | if (iir & IRCC_IIR_EOM) { |
| 1451 | if (self->io.direction == IO_RECV) |
| 1452 | smsc_ircc_dma_receive_complete(self, iobase); |
| 1453 | else |
| 1454 | smsc_ircc_dma_xmit_complete(self, iobase); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | smsc_ircc_dma_receive(self, iobase); |
| 1457 | } |
| 1458 | |
| 1459 | if (iir & IRCC_IIR_ACTIVE_FRAME) { |
| 1460 | /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/ |
| 1461 | } |
| 1462 | |
| 1463 | /* Enable interrupts again */ |
| 1464 | |
| 1465 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1466 | outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
| 1468 | irq_ret_unlock: |
| 1469 | spin_unlock(&self->lock); |
| 1470 | irq_ret: |
| 1471 | return ret; |
| 1472 | } |
| 1473 | |
| 1474 | /* |
| 1475 | * Function irport_interrupt_sir (irq, dev_id, regs) |
| 1476 | * |
| 1477 | * Interrupt handler for SIR modes |
| 1478 | */ |
| 1479 | static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev) |
| 1480 | { |
| 1481 | struct smsc_ircc_cb *self = dev->priv; |
| 1482 | int boguscount = 0; |
| 1483 | int iobase; |
| 1484 | int iir, lsr; |
| 1485 | |
| 1486 | /* Already locked comming here in smsc_ircc_interrupt() */ |
| 1487 | /*spin_lock(&self->lock);*/ |
| 1488 | |
| 1489 | iobase = self->io.sir_base; |
| 1490 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1491 | iir = inb(iobase + UART_IIR) & UART_IIR_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | if (iir == 0) |
| 1493 | return IRQ_NONE; |
| 1494 | while (iir) { |
| 1495 | /* Clear interrupt */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1496 | lsr = inb(iobase + UART_LSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1498 | IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | __FUNCTION__, iir, lsr, iobase); |
| 1500 | |
| 1501 | switch (iir) { |
| 1502 | case UART_IIR_RLSI: |
| 1503 | IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__); |
| 1504 | break; |
| 1505 | case UART_IIR_RDI: |
| 1506 | /* Receive interrupt */ |
| 1507 | smsc_ircc_sir_receive(self); |
| 1508 | break; |
| 1509 | case UART_IIR_THRI: |
| 1510 | if (lsr & UART_LSR_THRE) |
| 1511 | /* Transmitter ready for data */ |
| 1512 | smsc_ircc_sir_write_wakeup(self); |
| 1513 | break; |
| 1514 | default: |
| 1515 | IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", |
| 1516 | __FUNCTION__, iir); |
| 1517 | break; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | /* Make sure we don't stay here to long */ |
| 1521 | if (boguscount++ > 100) |
| 1522 | break; |
| 1523 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1524 | iir = inb(iobase + UART_IIR) & UART_IIR_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | } |
| 1526 | /*spin_unlock(&self->lock);*/ |
| 1527 | return IRQ_HANDLED; |
| 1528 | } |
| 1529 | |
| 1530 | |
| 1531 | #if 0 /* unused */ |
| 1532 | /* |
| 1533 | * Function ircc_is_receiving (self) |
| 1534 | * |
| 1535 | * Return TRUE is we are currently receiving a frame |
| 1536 | * |
| 1537 | */ |
| 1538 | static int ircc_is_receiving(struct smsc_ircc_cb *self) |
| 1539 | { |
| 1540 | int status = FALSE; |
| 1541 | /* int iobase; */ |
| 1542 | |
| 1543 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 1544 | |
| 1545 | IRDA_ASSERT(self != NULL, return FALSE;); |
| 1546 | |
| 1547 | IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__, |
| 1548 | get_dma_residue(self->io.dma)); |
| 1549 | |
| 1550 | status = (self->rx_buff.state != OUTSIDE_FRAME); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | return status; |
| 1553 | } |
| 1554 | #endif /* unused */ |
| 1555 | |
| 1556 | |
| 1557 | /* |
| 1558 | * Function smsc_ircc_net_open (dev) |
| 1559 | * |
| 1560 | * Start the device |
| 1561 | * |
| 1562 | */ |
| 1563 | static int smsc_ircc_net_open(struct net_device *dev) |
| 1564 | { |
| 1565 | struct smsc_ircc_cb *self; |
| 1566 | int iobase; |
| 1567 | char hwname[16]; |
| 1568 | unsigned long flags; |
| 1569 | |
| 1570 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | IRDA_ASSERT(dev != NULL, return -1;); |
| 1573 | self = (struct smsc_ircc_cb *) dev->priv; |
| 1574 | IRDA_ASSERT(self != NULL, return 0;); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | iobase = self->io.fir_base; |
| 1577 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1578 | if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | (void *) dev)) { |
| 1580 | IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n", |
| 1581 | __FUNCTION__, self->io.irq); |
| 1582 | return -EAGAIN; |
| 1583 | } |
| 1584 | |
| 1585 | spin_lock_irqsave(&self->lock, flags); |
| 1586 | /*smsc_ircc_sir_start(self);*/ |
| 1587 | self->io.speed = 0; |
| 1588 | smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED); |
| 1589 | spin_unlock_irqrestore(&self->lock, flags); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | /* Give self a hardware name */ |
| 1592 | /* It would be cool to offer the chip revision here - Jean II */ |
| 1593 | sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base); |
| 1594 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1595 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | * Open new IrLAP layer instance, now that everything should be |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1597 | * initialized properly |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | */ |
| 1599 | self->irlap = irlap_open(dev, &self->qos, hwname); |
| 1600 | |
| 1601 | /* |
| 1602 | * Always allocate the DMA channel after the IRQ, |
| 1603 | * and clean up on failure. |
| 1604 | */ |
| 1605 | if (request_dma(self->io.dma, dev->name)) { |
| 1606 | smsc_ircc_net_close(dev); |
| 1607 | |
| 1608 | IRDA_WARNING("%s(), unable to allocate DMA=%d\n", |
| 1609 | __FUNCTION__, self->io.dma); |
| 1610 | return -EAGAIN; |
| 1611 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | netif_start_queue(dev); |
| 1614 | |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
| 1618 | /* |
| 1619 | * Function smsc_ircc_net_close (dev) |
| 1620 | * |
| 1621 | * Stop the device |
| 1622 | * |
| 1623 | */ |
| 1624 | static int smsc_ircc_net_close(struct net_device *dev) |
| 1625 | { |
| 1626 | struct smsc_ircc_cb *self; |
| 1627 | int iobase; |
| 1628 | |
| 1629 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | IRDA_ASSERT(dev != NULL, return -1;); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1632 | self = (struct smsc_ircc_cb *) dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | IRDA_ASSERT(self != NULL, return 0;); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | iobase = self->io.fir_base; |
| 1636 | |
| 1637 | /* Stop device */ |
| 1638 | netif_stop_queue(dev); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | /* Stop and remove instance of IrLAP */ |
| 1641 | if (self->irlap) |
| 1642 | irlap_close(self->irlap); |
| 1643 | self->irlap = NULL; |
| 1644 | |
| 1645 | free_irq(self->io.irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | disable_dma(self->io.dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | free_dma(self->io.dma); |
| 1648 | |
| 1649 | return 0; |
| 1650 | } |
| 1651 | |
| 1652 | |
| 1653 | static void smsc_ircc_suspend(struct smsc_ircc_cb *self) |
| 1654 | { |
| 1655 | IRDA_MESSAGE("%s, Suspending\n", driver_name); |
| 1656 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1657 | if (!self->io.suspended) { |
| 1658 | smsc_ircc_net_close(self->netdev); |
| 1659 | self->io.suspended = 1; |
| 1660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | static void smsc_ircc_wakeup(struct smsc_ircc_cb *self) |
| 1664 | { |
| 1665 | if (!self->io.suspended) |
| 1666 | return; |
| 1667 | |
| 1668 | /* The code was doing a "cli()" here, but this can't be right. |
| 1669 | * If you need protection, do it in net_open with a spinlock |
| 1670 | * or give a good reason. - Jean II */ |
| 1671 | |
| 1672 | smsc_ircc_net_open(self->netdev); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | IRDA_MESSAGE("%s, Waking up\n", driver_name); |
| 1675 | } |
| 1676 | |
| 1677 | static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data) |
| 1678 | { |
| 1679 | struct smsc_ircc_cb *self = (struct smsc_ircc_cb*) dev->data; |
| 1680 | if (self) { |
| 1681 | switch (rqst) { |
| 1682 | case PM_SUSPEND: |
| 1683 | smsc_ircc_suspend(self); |
| 1684 | break; |
| 1685 | case PM_RESUME: |
| 1686 | smsc_ircc_wakeup(self); |
| 1687 | break; |
| 1688 | } |
| 1689 | } |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | /* |
| 1694 | * Function smsc_ircc_close (self) |
| 1695 | * |
| 1696 | * Close driver instance |
| 1697 | * |
| 1698 | */ |
| 1699 | static int __exit smsc_ircc_close(struct smsc_ircc_cb *self) |
| 1700 | { |
| 1701 | int iobase; |
| 1702 | unsigned long flags; |
| 1703 | |
| 1704 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 1705 | |
| 1706 | IRDA_ASSERT(self != NULL, return -1;); |
| 1707 | |
| 1708 | iobase = self->io.fir_base; |
| 1709 | |
| 1710 | if (self->pmdev) |
| 1711 | pm_unregister(self->pmdev); |
| 1712 | |
| 1713 | /* Remove netdevice */ |
| 1714 | unregister_netdev(self->netdev); |
| 1715 | |
| 1716 | /* Make sure the irq handler is not exectuting */ |
| 1717 | spin_lock_irqsave(&self->lock, flags); |
| 1718 | |
| 1719 | /* Stop interrupts */ |
| 1720 | register_bank(iobase, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1721 | outb(0, iobase + IRCC_IER); |
| 1722 | outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER); |
| 1723 | outb(0x00, iobase + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | #if 0 |
| 1725 | /* Reset to SIR mode */ |
| 1726 | register_bank(iobase, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1727 | outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA); |
| 1728 | outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | #endif |
| 1730 | spin_unlock_irqrestore(&self->lock, flags); |
| 1731 | |
| 1732 | /* Release the PORTS that this driver is using */ |
| 1733 | IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__, |
| 1734 | self->io.fir_base); |
| 1735 | |
| 1736 | release_region(self->io.fir_base, self->io.fir_ext); |
| 1737 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1738 | IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | self->io.sir_base); |
| 1740 | |
| 1741 | release_region(self->io.sir_base, self->io.sir_ext); |
| 1742 | |
| 1743 | if (self->tx_buff.head) |
| 1744 | dma_free_coherent(NULL, self->tx_buff.truesize, |
| 1745 | self->tx_buff.head, self->tx_buff_dma); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | if (self->rx_buff.head) |
| 1748 | dma_free_coherent(NULL, self->rx_buff.truesize, |
| 1749 | self->rx_buff.head, self->rx_buff_dma); |
| 1750 | |
| 1751 | free_netdev(self->netdev); |
| 1752 | |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
| 1756 | static void __exit smsc_ircc_cleanup(void) |
| 1757 | { |
| 1758 | int i; |
| 1759 | |
| 1760 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 1761 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1762 | for (i = 0; i < 2; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | if (dev_self[i]) |
| 1764 | smsc_ircc_close(dev_self[i]); |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | /* |
| 1769 | * Start SIR operations |
| 1770 | * |
| 1771 | * This function *must* be called with spinlock held, because it may |
| 1772 | * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II |
| 1773 | */ |
| 1774 | void smsc_ircc_sir_start(struct smsc_ircc_cb *self) |
| 1775 | { |
| 1776 | struct net_device *dev; |
| 1777 | int fir_base, sir_base; |
| 1778 | |
| 1779 | IRDA_DEBUG(3, "%s\n", __FUNCTION__); |
| 1780 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1781 | IRDA_ASSERT(self != NULL, return;); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1782 | dev = self->netdev; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1783 | IRDA_ASSERT(dev != NULL, return;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir; |
| 1785 | |
| 1786 | fir_base = self->io.fir_base; |
| 1787 | sir_base = self->io.sir_base; |
| 1788 | |
| 1789 | /* Reset everything */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1790 | outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
| 1792 | #if SMSC_IRCC2_C_SIR_STOP |
| 1793 | /*smsc_ircc_sir_stop(self);*/ |
| 1794 | #endif |
| 1795 | |
| 1796 | register_bank(fir_base, 1); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1797 | outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | |
| 1799 | /* Initialize UART */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1800 | outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */ |
| 1801 | outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | /* Turn on interrups */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1804 | outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
| 1806 | IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__); |
| 1807 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1808 | outb(0x00, fir_base + IRCC_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | #if SMSC_IRCC2_C_SIR_STOP |
| 1812 | void smsc_ircc_sir_stop(struct smsc_ircc_cb *self) |
| 1813 | { |
| 1814 | int iobase; |
| 1815 | |
| 1816 | IRDA_DEBUG(3, "%s\n", __FUNCTION__); |
| 1817 | iobase = self->io.sir_base; |
| 1818 | |
| 1819 | /* Reset UART */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1820 | outb(0, iobase + UART_MCR); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | /* Turn off interrupts */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1823 | outb(0, iobase + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | } |
| 1825 | #endif |
| 1826 | |
| 1827 | /* |
| 1828 | * Function smsc_sir_write_wakeup (self) |
| 1829 | * |
| 1830 | * Called by the SIR interrupt handler when there's room for more data. |
| 1831 | * If we have more packets to send, we send them here. |
| 1832 | * |
| 1833 | */ |
| 1834 | static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self) |
| 1835 | { |
| 1836 | int actual = 0; |
| 1837 | int iobase; |
| 1838 | int fcr; |
| 1839 | |
| 1840 | IRDA_ASSERT(self != NULL, return;); |
| 1841 | |
| 1842 | IRDA_DEBUG(4, "%s\n", __FUNCTION__); |
| 1843 | |
| 1844 | iobase = self->io.sir_base; |
| 1845 | |
| 1846 | /* Finished with frame? */ |
| 1847 | if (self->tx_buff.len > 0) { |
| 1848 | /* Write data left in transmit buffer */ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1849 | actual = smsc_ircc_sir_write(iobase, self->io.fifo_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | self->tx_buff.data, self->tx_buff.len); |
| 1851 | self->tx_buff.data += actual; |
| 1852 | self->tx_buff.len -= actual; |
| 1853 | } else { |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | /*if (self->tx_buff.len ==0) {*/ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1856 | |
| 1857 | /* |
| 1858 | * Now serial buffer is almost free & we can start |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | * transmission of another packet. But first we must check |
| 1860 | * if we need to change the speed of the hardware |
| 1861 | */ |
| 1862 | if (self->new_speed) { |
| 1863 | IRDA_DEBUG(5, "%s(), Changing speed to %d.\n", |
| 1864 | __FUNCTION__, self->new_speed); |
| 1865 | smsc_ircc_sir_wait_hw_transmitter_finish(self); |
| 1866 | smsc_ircc_change_speed(self, self->new_speed); |
| 1867 | self->new_speed = 0; |
| 1868 | } else { |
| 1869 | /* Tell network layer that we want more frames */ |
| 1870 | netif_wake_queue(self->netdev); |
| 1871 | } |
| 1872 | self->stats.tx_packets++; |
| 1873 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1874 | if (self->io.speed <= 115200) { |
| 1875 | /* |
| 1876 | * Reset Rx FIFO to make sure that all reflected transmit data |
| 1877 | * is discarded. This is needed for half duplex operation |
| 1878 | */ |
| 1879 | fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR; |
| 1880 | fcr |= self->io.speed < 38400 ? |
| 1881 | UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1883 | outb(fcr, iobase + UART_FCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1885 | /* Turn on receive interrupts */ |
| 1886 | outb(UART_IER_RDI, iobase + UART_IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | } |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | /* |
| 1892 | * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len) |
| 1893 | * |
| 1894 | * Fill Tx FIFO with transmit data |
| 1895 | * |
| 1896 | */ |
| 1897 | static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len) |
| 1898 | { |
| 1899 | int actual = 0; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | /* Tx FIFO should be empty! */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1902 | if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__); |
| 1904 | return 0; |
| 1905 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | /* Fill FIFO with current frame */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1908 | while (fifo_size-- > 0 && actual < len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | /* Transmit next byte */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1910 | outb(buf[actual], iobase + UART_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | actual++; |
| 1912 | } |
| 1913 | return actual; |
| 1914 | } |
| 1915 | |
| 1916 | /* |
| 1917 | * Function smsc_ircc_is_receiving (self) |
| 1918 | * |
| 1919 | * Returns true is we are currently receiving data |
| 1920 | * |
| 1921 | */ |
| 1922 | static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self) |
| 1923 | { |
| 1924 | return (self->rx_buff.state != OUTSIDE_FRAME); |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | /* |
| 1929 | * Function smsc_ircc_probe_transceiver(self) |
| 1930 | * |
| 1931 | * Tries to find the used Transceiver |
| 1932 | * |
| 1933 | */ |
| 1934 | static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self) |
| 1935 | { |
| 1936 | unsigned int i; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | IRDA_ASSERT(self != NULL, return;); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1939 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1940 | for (i = 0; smsc_transceivers[i].name != NULL; i++) |
| 1941 | if (smsc_transceivers[i].probe(self->io.fir_base)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | IRDA_MESSAGE(" %s transceiver found\n", |
| 1943 | smsc_transceivers[i].name); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1944 | self->transceiver= i + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | return; |
| 1946 | } |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | IRDA_MESSAGE("No transceiver found. Defaulting to %s\n", |
| 1949 | smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1950 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1951 | self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | |
| 1955 | /* |
| 1956 | * Function smsc_ircc_set_transceiver_for_speed(self, speed) |
| 1957 | * |
| 1958 | * Set the transceiver according to the speed |
| 1959 | * |
| 1960 | */ |
| 1961 | static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed) |
| 1962 | { |
| 1963 | unsigned int trx; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | trx = self->transceiver; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1966 | if (trx > 0) |
| 1967 | smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | /* |
| 1971 | * Function smsc_ircc_wait_hw_transmitter_finish () |
| 1972 | * |
| 1973 | * Wait for the real end of HW transmission |
| 1974 | * |
| 1975 | * The UART is a strict FIFO, and we get called only when we have finished |
| 1976 | * pushing data to the FIFO, so the maximum amount of time we must wait |
| 1977 | * is only for the FIFO to drain out. |
| 1978 | * |
| 1979 | * We use a simple calibrated loop. We may need to adjust the loop |
| 1980 | * delay (udelay) to balance I/O traffic and latency. And we also need to |
| 1981 | * adjust the maximum timeout. |
| 1982 | * It would probably be better to wait for the proper interrupt, |
| 1983 | * but it doesn't seem to be available. |
| 1984 | * |
| 1985 | * We can't use jiffies or kernel timers because : |
| 1986 | * 1) We are called from the interrupt handler, which disable softirqs, |
| 1987 | * so jiffies won't be increased |
| 1988 | * 2) Jiffies granularity is usually very coarse (10ms), and we don't |
| 1989 | * want to wait that long to detect stuck hardware. |
| 1990 | * Jean II |
| 1991 | */ |
| 1992 | |
| 1993 | static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self) |
| 1994 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1995 | int iobase = self->io.sir_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 1997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | /* Calibrated busy loop */ |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 1999 | while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | udelay(1); |
| 2001 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2002 | if (count == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__); |
| 2004 | } |
| 2005 | |
| 2006 | |
| 2007 | /* PROBING |
| 2008 | * |
| 2009 | * |
| 2010 | */ |
| 2011 | |
| 2012 | static int __init smsc_ircc_look_for_chips(void) |
| 2013 | { |
| 2014 | smsc_chip_address_t *address; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2015 | char *type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | unsigned int cfg_base, found; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | found = 0; |
| 2019 | address = possible_addresses; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2020 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2021 | while (address->cfg_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | cfg_base = address->cfg_base; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2025 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2026 | if (address->type & SMSCSIO_TYPE_FDC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | type = "FDC"; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2028 | if (address->type & SMSCSIO_TYPE_FLAT) |
| 2029 | if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type)) |
| 2030 | found++; |
| 2031 | |
| 2032 | if (address->type & SMSCSIO_TYPE_PAGED) |
| 2033 | if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type)) |
| 2034 | found++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2036 | if (address->type & SMSCSIO_TYPE_LPC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | type = "LPC"; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2038 | if (address->type & SMSCSIO_TYPE_FLAT) |
| 2039 | if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type)) |
| 2040 | found++; |
| 2041 | |
| 2042 | if (address->type & SMSCSIO_TYPE_PAGED) |
| 2043 | if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type)) |
| 2044 | found++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | } |
| 2046 | address++; |
| 2047 | } |
| 2048 | return found; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2049 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
| 2051 | /* |
| 2052 | * Function smsc_superio_flat (chip, base, type) |
| 2053 | * |
| 2054 | * Try to get configuration of a smc SuperIO chip with flat register model |
| 2055 | * |
| 2056 | */ |
| 2057 | static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfgbase, char *type) |
| 2058 | { |
| 2059 | unsigned short firbase, sirbase; |
| 2060 | u8 mode, dma, irq; |
| 2061 | int ret = -ENODEV; |
| 2062 | |
| 2063 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 2064 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2065 | if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | return ret; |
| 2067 | |
| 2068 | outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2069 | mode = inb(cfgbase + 1); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/ |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2072 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2073 | if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__); |
| 2075 | |
| 2076 | outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2077 | sirbase = inb(cfgbase + 1) << 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2079 | /* FIR iobase */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2081 | firbase = inb(cfgbase + 1) << 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | |
| 2083 | /* DMA */ |
| 2084 | outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2085 | dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | /* IRQ */ |
| 2088 | outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2089 | irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | |
| 2091 | IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode); |
| 2092 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2093 | if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0) |
| 2094 | ret = 0; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | /* Exit configuration */ |
| 2097 | outb(SMSCSIO_CFGEXITKEY, cfgbase); |
| 2098 | |
| 2099 | return ret; |
| 2100 | } |
| 2101 | |
| 2102 | /* |
| 2103 | * Function smsc_superio_paged (chip, base, type) |
| 2104 | * |
| 2105 | * Try to get configuration of a smc SuperIO chip with paged register model |
| 2106 | * |
| 2107 | */ |
| 2108 | static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cfg_base, char *type) |
| 2109 | { |
| 2110 | unsigned short fir_io, sir_io; |
| 2111 | int ret = -ENODEV; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 2114 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2115 | if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | return ret; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | /* Select logical device (UART2) */ |
| 2119 | outb(0x07, cfg_base); |
| 2120 | outb(0x05, cfg_base + 1); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | /* SIR iobase */ |
| 2123 | outb(0x60, cfg_base); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2124 | sir_io = inb(cfg_base + 1) << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | outb(0x61, cfg_base); |
| 2126 | sir_io |= inb(cfg_base + 1); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | /* Read FIR base */ |
| 2129 | outb(0x62, cfg_base); |
| 2130 | fir_io = inb(cfg_base + 1) << 8; |
| 2131 | outb(0x63, cfg_base); |
| 2132 | fir_io |= inb(cfg_base + 1); |
| 2133 | outb(0x2b, cfg_base); /* ??? */ |
| 2134 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2135 | if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0) |
| 2136 | ret = 0; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | /* Exit configuration */ |
| 2139 | outb(SMSCSIO_CFGEXITKEY, cfg_base); |
| 2140 | |
| 2141 | return ret; |
| 2142 | } |
| 2143 | |
| 2144 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2145 | static int __init smsc_access(unsigned short cfg_base, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | { |
| 2147 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 2148 | |
| 2149 | outb(reg, cfg_base); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2150 | return inb(cfg_base) != reg ? -1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2153 | static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const smsc_chip_t *chip, char *type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2155 | u8 devid, xdevid, rev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
| 2157 | IRDA_DEBUG(1, "%s\n", __FUNCTION__); |
| 2158 | |
| 2159 | /* Leave configuration */ |
| 2160 | |
| 2161 | outb(SMSCSIO_CFGEXITKEY, cfg_base); |
| 2162 | |
| 2163 | if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */ |
| 2164 | return NULL; |
| 2165 | |
| 2166 | outb(reg, cfg_base); |
| 2167 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2168 | xdevid = inb(cfg_base + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
| 2170 | /* Enter configuration */ |
| 2171 | |
| 2172 | outb(SMSCSIO_CFGACCESSKEY, cfg_base); |
| 2173 | |
| 2174 | #if 0 |
| 2175 | if (smsc_access(cfg_base,0x55)) /* send second key and check */ |
| 2176 | return NULL; |
| 2177 | #endif |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | /* probe device ID */ |
| 2180 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2181 | if (smsc_access(cfg_base, reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | return NULL; |
| 2183 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2184 | devid = inb(cfg_base + 1); |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2185 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2186 | if (devid == 0 || devid == 0xff) /* typical values for unused port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | return NULL; |
| 2188 | |
| 2189 | /* probe revision ID */ |
| 2190 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2191 | if (smsc_access(cfg_base, reg + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | return NULL; |
| 2193 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2194 | rev = inb(cfg_base + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2196 | if (rev >= 128) /* i think this will make no sense */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | return NULL; |
| 2198 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2199 | if (devid == xdevid) /* protection against false positives */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | return NULL; |
| 2201 | |
| 2202 | /* Check for expected device ID; are there others? */ |
| 2203 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2204 | while (chip->devid != devid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | |
| 2206 | chip++; |
| 2207 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2208 | if (chip->name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | return NULL; |
| 2210 | } |
| 2211 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2212 | IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n", |
| 2213 | devid, rev, cfg_base, type, chip->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2215 | if (chip->rev > rev) { |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2216 | IRDA_MESSAGE("Revision higher than expected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | return NULL; |
| 2218 | } |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2219 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2220 | if (chip->flags & NoIRDA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | IRDA_MESSAGE("chipset does not support IRDA\n"); |
| 2222 | |
| 2223 | return chip; |
| 2224 | } |
| 2225 | |
| 2226 | static int __init smsc_superio_fdc(unsigned short cfg_base) |
| 2227 | { |
| 2228 | int ret = -1; |
| 2229 | |
| 2230 | if (!request_region(cfg_base, 2, driver_name)) { |
| 2231 | IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n", |
| 2232 | __FUNCTION__, cfg_base); |
| 2233 | } else { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2234 | if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") || |
| 2235 | !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | ret = 0; |
| 2237 | |
| 2238 | release_region(cfg_base, 2); |
| 2239 | } |
| 2240 | |
| 2241 | return ret; |
| 2242 | } |
| 2243 | |
| 2244 | static int __init smsc_superio_lpc(unsigned short cfg_base) |
| 2245 | { |
| 2246 | int ret = -1; |
| 2247 | |
| 2248 | if (!request_region(cfg_base, 2, driver_name)) { |
| 2249 | IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n", |
| 2250 | __FUNCTION__, cfg_base); |
| 2251 | } else { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2252 | if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") || |
| 2253 | !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | ret = 0; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | release_region(cfg_base, 2); |
| 2257 | } |
| 2258 | return ret; |
| 2259 | } |
| 2260 | |
| 2261 | /************************************************ |
| 2262 | * |
| 2263 | * Transceivers specific functions |
| 2264 | * |
| 2265 | ************************************************/ |
| 2266 | |
| 2267 | |
| 2268 | /* |
| 2269 | * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed) |
| 2270 | * |
| 2271 | * Program transceiver through smsc-ircc ATC circuitry |
| 2272 | * |
| 2273 | */ |
| 2274 | |
| 2275 | static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed) |
| 2276 | { |
| 2277 | unsigned long jiffies_now, jiffies_timeout; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2278 | u8 val; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2279 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2280 | jiffies_now = jiffies; |
| 2281 | jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | /* ATC */ |
| 2284 | register_bank(fir_base, 4); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2285 | outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE, |
| 2286 | fir_base + IRCC_ATC); |
| 2287 | |
| 2288 | while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) && |
| 2289 | !time_after(jiffies, jiffies_timeout)) |
| 2290 | /* empty */; |
| 2291 | |
| 2292 | if (val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__, |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2294 | inb(fir_base + IRCC_ATC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | /* |
| 2298 | * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base) |
| 2299 | * |
| 2300 | * Probe transceiver smsc-ircc ATC circuitry |
| 2301 | * |
| 2302 | */ |
| 2303 | |
| 2304 | static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base) |
| 2305 | { |
| 2306 | return 0; |
| 2307 | } |
| 2308 | |
| 2309 | /* |
| 2310 | * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed) |
| 2311 | * |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2312 | * Set transceiver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | * |
| 2314 | */ |
| 2315 | |
| 2316 | static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed) |
| 2317 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2318 | u8 fast_mode; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2319 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2320 | switch (speed) { |
| 2321 | default: |
| 2322 | case 576000 : |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2323 | fast_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | break; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2325 | case 1152000 : |
| 2326 | case 4000000 : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | fast_mode = IRCC_LCR_A_FAST; |
| 2328 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | } |
| 2330 | register_bank(fir_base, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2331 | outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | /* |
| 2335 | * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base) |
| 2336 | * |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2337 | * Probe transceiver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | * |
| 2339 | */ |
| 2340 | |
| 2341 | static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base) |
| 2342 | { |
| 2343 | return 0; |
| 2344 | } |
| 2345 | |
| 2346 | /* |
| 2347 | * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed) |
| 2348 | * |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2349 | * Set transceiver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | * |
| 2351 | */ |
| 2352 | |
| 2353 | static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed) |
| 2354 | { |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2355 | u8 fast_mode; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2356 | |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2357 | switch (speed) { |
| 2358 | default: |
| 2359 | case 576000 : |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2360 | fast_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | break; |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2362 | case 1152000 : |
| 2363 | case 4000000 : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA; |
| 2365 | break; |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
| 2368 | /* This causes an interrupt */ |
| 2369 | register_bank(fir_base, 0); |
Dmitry Torokhov | 98b7777 | 2005-09-06 15:19:19 -0700 | [diff] [blame^] | 2370 | outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | /* |
| 2374 | * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base) |
| 2375 | * |
Dmitry Torokhov | 527b6af | 2005-09-06 15:19:17 -0700 | [diff] [blame] | 2376 | * Probe transceiver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | * |
| 2378 | */ |
| 2379 | |
| 2380 | static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base) |
| 2381 | { |
| 2382 | return 0; |
| 2383 | } |
| 2384 | |
| 2385 | |
| 2386 | module_init(smsc_ircc_init); |
| 2387 | module_exit(smsc_ircc_cleanup); |