Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
| 2 | * |
| 3 | * Filename: esi.c |
| 4 | * Version: 1.6 |
| 5 | * Description: Driver for the Extended Systems JetEye PC dongle |
| 6 | * Status: Experimental. |
| 7 | * Author: Dag Brattli <dagb@cs.uit.no> |
| 8 | * Created at: Sat Feb 21 18:54:38 1998 |
| 9 | * Modified at: Sun Oct 27 22:01:04 2002 |
| 10 | * Modified by: Martin Diehl <mad@mdiehl.de> |
| 11 | * |
| 12 | * Copyright (c) 1999 Dag Brattli, <dagb@cs.uit.no>, |
| 13 | * Copyright (c) 1998 Thomas Davis, <ratbert@radiks.net>, |
| 14 | * Copyright (c) 2002 Martin Diehl, <mad@mdiehl.de>, |
| 15 | * All Rights Reserved. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or |
| 18 | * modify it under the terms of the GNU General Public License as |
| 19 | * published by the Free Software Foundation; either version 2 of |
| 20 | * the License, or (at your option) any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
Jeff Kirsher | e8478de | 2013-12-06 06:28:44 -0800 | [diff] [blame] | 28 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * |
| 30 | ********************************************************************/ |
| 31 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/init.h> |
| 35 | |
| 36 | #include <net/irda/irda.h> |
| 37 | |
| 38 | #include "sir-dev.h" |
| 39 | |
| 40 | static int esi_open(struct sir_dev *); |
| 41 | static int esi_close(struct sir_dev *); |
| 42 | static int esi_change_speed(struct sir_dev *, unsigned); |
| 43 | static int esi_reset(struct sir_dev *); |
| 44 | |
| 45 | static struct dongle_driver esi = { |
| 46 | .owner = THIS_MODULE, |
| 47 | .driver_name = "JetEye PC ESI-9680 PC", |
| 48 | .type = IRDA_ESI_DONGLE, |
| 49 | .open = esi_open, |
| 50 | .close = esi_close, |
| 51 | .reset = esi_reset, |
| 52 | .set_speed = esi_change_speed, |
| 53 | }; |
| 54 | |
| 55 | static int __init esi_sir_init(void) |
| 56 | { |
| 57 | return irda_register_dongle(&esi); |
| 58 | } |
| 59 | |
| 60 | static void __exit esi_sir_cleanup(void) |
| 61 | { |
| 62 | irda_unregister_dongle(&esi); |
| 63 | } |
| 64 | |
| 65 | static int esi_open(struct sir_dev *dev) |
| 66 | { |
| 67 | struct qos_info *qos = &dev->qos; |
| 68 | |
| 69 | /* Power up and set dongle to 9600 baud */ |
| 70 | sirdev_set_dtr_rts(dev, FALSE, TRUE); |
| 71 | |
| 72 | qos->baud_rate.bits &= IR_9600|IR_19200|IR_115200; |
| 73 | qos->min_turn_time.bits = 0x01; /* Needs at least 10 ms */ |
| 74 | irda_qos_bits_to_value(qos); |
| 75 | |
| 76 | /* irda thread waits 50 msec for power settling */ |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int esi_close(struct sir_dev *dev) |
| 82 | { |
| 83 | /* Power off dongle */ |
| 84 | sirdev_set_dtr_rts(dev, FALSE, FALSE); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * Function esi_change_speed (task) |
| 91 | * |
| 92 | * Set the speed for the Extended Systems JetEye PC ESI-9680 type dongle |
| 93 | * Apparently (see old esi-driver) no delays are needed here... |
| 94 | * |
| 95 | */ |
| 96 | static int esi_change_speed(struct sir_dev *dev, unsigned speed) |
| 97 | { |
| 98 | int ret = 0; |
| 99 | int dtr, rts; |
| 100 | |
| 101 | switch (speed) { |
| 102 | case 19200: |
| 103 | dtr = TRUE; |
| 104 | rts = FALSE; |
| 105 | break; |
| 106 | case 115200: |
| 107 | dtr = rts = TRUE; |
| 108 | break; |
| 109 | default: |
| 110 | ret = -EINVAL; |
| 111 | speed = 9600; |
| 112 | /* fall through */ |
| 113 | case 9600: |
| 114 | dtr = FALSE; |
| 115 | rts = TRUE; |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | /* Change speed of dongle */ |
| 120 | sirdev_set_dtr_rts(dev, dtr, rts); |
| 121 | dev->speed = speed; |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Function esi_reset (task) |
| 128 | * |
| 129 | * Reset dongle; |
| 130 | * |
| 131 | */ |
| 132 | static int esi_reset(struct sir_dev *dev) |
| 133 | { |
| 134 | sirdev_set_dtr_rts(dev, FALSE, FALSE); |
| 135 | |
| 136 | /* Hm, the old esi-driver left the dongle unpowered relying on |
| 137 | * the following speed change to repower. This might work for |
| 138 | * the esi because we only need the modem lines. However, now the |
| 139 | * general rule is reset must bring the dongle to some working |
| 140 | * well-known state because speed change might write to registers. |
| 141 | * The old esi-driver didn't any delay here - let's hope it' fine. |
| 142 | */ |
| 143 | |
| 144 | sirdev_set_dtr_rts(dev, FALSE, TRUE); |
| 145 | dev->speed = 9600; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>"); |
| 151 | MODULE_DESCRIPTION("Extended Systems JetEye PC dongle driver"); |
| 152 | MODULE_LICENSE("GPL"); |
| 153 | MODULE_ALIAS("irda-dongle-1"); /* IRDA_ESI_DONGLE */ |
| 154 | |
| 155 | module_init(esi_sir_init); |
| 156 | module_exit(esi_sir_cleanup); |
| 157 | |