Merge tag 'chrome-platform-for-linus-4.13' of git://git.kernel.org/pub/scm/linux...
[linux/fpc-iii.git] / drivers / net / irda / girbil-sir.c
blob7e0a5b8c6d53fd14a95b6c6507c69da57af2b7a9
1 /*********************************************************************
3 * Filename: girbil.c
4 * Version: 1.2
5 * Description: Implementation for the Greenwich GIrBIL dongle
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sat Feb 6 21:02:33 1999
9 * Modified at: Fri Dec 17 09:13:20 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * Neither Dag Brattli nor University of Tromsø admit liability nor
20 * provide warranty for any of this software. This material is
21 * provided "AS-IS" and at no charge.
23 ********************************************************************/
25 #include <linux/module.h>
26 #include <linux/delay.h>
27 #include <linux/init.h>
29 #include <net/irda/irda.h>
31 #include "sir-dev.h"
33 static int girbil_reset(struct sir_dev *dev);
34 static int girbil_open(struct sir_dev *dev);
35 static int girbil_close(struct sir_dev *dev);
36 static int girbil_change_speed(struct sir_dev *dev, unsigned speed);
38 /* Control register 1 */
39 #define GIRBIL_TXEN 0x01 /* Enable transmitter */
40 #define GIRBIL_RXEN 0x02 /* Enable receiver */
41 #define GIRBIL_ECAN 0x04 /* Cancel self emitted data */
42 #define GIRBIL_ECHO 0x08 /* Echo control characters */
44 /* LED Current Register (0x2) */
45 #define GIRBIL_HIGH 0x20
46 #define GIRBIL_MEDIUM 0x21
47 #define GIRBIL_LOW 0x22
49 /* Baud register (0x3) */
50 #define GIRBIL_2400 0x30
51 #define GIRBIL_4800 0x31
52 #define GIRBIL_9600 0x32
53 #define GIRBIL_19200 0x33
54 #define GIRBIL_38400 0x34
55 #define GIRBIL_57600 0x35
56 #define GIRBIL_115200 0x36
58 /* Mode register (0x4) */
59 #define GIRBIL_IRDA 0x40
60 #define GIRBIL_ASK 0x41
62 /* Control register 2 (0x5) */
63 #define GIRBIL_LOAD 0x51 /* Load the new baud rate value */
65 static struct dongle_driver girbil = {
66 .owner = THIS_MODULE,
67 .driver_name = "Greenwich GIrBIL",
68 .type = IRDA_GIRBIL_DONGLE,
69 .open = girbil_open,
70 .close = girbil_close,
71 .reset = girbil_reset,
72 .set_speed = girbil_change_speed,
75 static int __init girbil_sir_init(void)
77 return irda_register_dongle(&girbil);
80 static void __exit girbil_sir_cleanup(void)
82 irda_unregister_dongle(&girbil);
85 static int girbil_open(struct sir_dev *dev)
87 struct qos_info *qos = &dev->qos;
89 /* Power on dongle */
90 sirdev_set_dtr_rts(dev, TRUE, TRUE);
92 qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
93 qos->min_turn_time.bits = 0x03;
94 irda_qos_bits_to_value(qos);
96 /* irda thread waits 50 msec for power settling */
98 return 0;
101 static int girbil_close(struct sir_dev *dev)
103 /* Power off dongle */
104 sirdev_set_dtr_rts(dev, FALSE, FALSE);
106 return 0;
110 * Function girbil_change_speed (dev, speed)
112 * Set the speed for the Girbil type dongle.
116 #define GIRBIL_STATE_WAIT_SPEED (SIRDEV_STATE_DONGLE_SPEED + 1)
118 static int girbil_change_speed(struct sir_dev *dev, unsigned speed)
120 unsigned state = dev->fsm.substate;
121 unsigned delay = 0;
122 u8 control[2];
123 static int ret = 0;
125 /* dongle alread reset - port and dongle at default speed */
127 switch(state) {
129 case SIRDEV_STATE_DONGLE_SPEED:
131 /* Set DTR and Clear RTS to enter command mode */
132 sirdev_set_dtr_rts(dev, FALSE, TRUE);
134 udelay(25); /* better wait a little while */
136 ret = 0;
137 switch (speed) {
138 default:
139 ret = -EINVAL;
140 /* fall through */
141 case 9600:
142 control[0] = GIRBIL_9600;
143 break;
144 case 19200:
145 control[0] = GIRBIL_19200;
146 break;
147 case 34800:
148 control[0] = GIRBIL_38400;
149 break;
150 case 57600:
151 control[0] = GIRBIL_57600;
152 break;
153 case 115200:
154 control[0] = GIRBIL_115200;
155 break;
157 control[1] = GIRBIL_LOAD;
159 /* Write control bytes */
160 sirdev_raw_write(dev, control, 2);
162 dev->speed = speed;
164 state = GIRBIL_STATE_WAIT_SPEED;
165 delay = 100;
166 break;
168 case GIRBIL_STATE_WAIT_SPEED:
169 /* Go back to normal mode */
170 sirdev_set_dtr_rts(dev, TRUE, TRUE);
172 udelay(25); /* better wait a little while */
173 break;
175 default:
176 net_err_ratelimited("%s - undefined state %d\n",
177 __func__, state);
178 ret = -EINVAL;
179 break;
181 dev->fsm.substate = state;
182 return (delay > 0) ? delay : ret;
186 * Function girbil_reset (driver)
188 * This function resets the girbil dongle.
190 * Algorithm:
191 * 0. set RTS, and wait at least 5 ms
192 * 1. clear RTS
196 #define GIRBIL_STATE_WAIT1_RESET (SIRDEV_STATE_DONGLE_RESET + 1)
197 #define GIRBIL_STATE_WAIT2_RESET (SIRDEV_STATE_DONGLE_RESET + 2)
198 #define GIRBIL_STATE_WAIT3_RESET (SIRDEV_STATE_DONGLE_RESET + 3)
200 static int girbil_reset(struct sir_dev *dev)
202 unsigned state = dev->fsm.substate;
203 unsigned delay = 0;
204 u8 control = GIRBIL_TXEN | GIRBIL_RXEN;
205 int ret = 0;
207 switch (state) {
208 case SIRDEV_STATE_DONGLE_RESET:
209 /* Reset dongle */
210 sirdev_set_dtr_rts(dev, TRUE, FALSE);
211 /* Sleep at least 5 ms */
212 delay = 20;
213 state = GIRBIL_STATE_WAIT1_RESET;
214 break;
216 case GIRBIL_STATE_WAIT1_RESET:
217 /* Set DTR and clear RTS to enter command mode */
218 sirdev_set_dtr_rts(dev, FALSE, TRUE);
219 delay = 20;
220 state = GIRBIL_STATE_WAIT2_RESET;
221 break;
223 case GIRBIL_STATE_WAIT2_RESET:
224 /* Write control byte */
225 sirdev_raw_write(dev, &control, 1);
226 delay = 20;
227 state = GIRBIL_STATE_WAIT3_RESET;
228 break;
230 case GIRBIL_STATE_WAIT3_RESET:
231 /* Go back to normal mode */
232 sirdev_set_dtr_rts(dev, TRUE, TRUE);
233 dev->speed = 9600;
234 break;
236 default:
237 net_err_ratelimited("%s(), undefined state %d\n",
238 __func__, state);
239 ret = -1;
240 break;
242 dev->fsm.substate = state;
243 return (delay > 0) ? delay : ret;
246 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
247 MODULE_DESCRIPTION("Greenwich GIrBIL dongle driver");
248 MODULE_LICENSE("GPL");
249 MODULE_ALIAS("irda-dongle-4"); /* IRDA_GIRBIL_DONGLE */
251 module_init(girbil_sir_init);
252 module_exit(girbil_sir_cleanup);