Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
| 2 | * |
| 3 | * Filename: act200l.c |
| 4 | * Version: 0.8 |
| 5 | * Description: Implementation for the ACTiSYS ACT-IR200L dongle |
| 6 | * Status: Experimental. |
| 7 | * Author: SHIMIZU Takuya <tshimizu@ga2.so-net.ne.jp> |
| 8 | * Created at: Fri Aug 3 17:35:42 2001 |
| 9 | * Modified at: Fri Aug 17 10:22:40 2001 |
| 10 | * Modified by: SHIMIZU Takuya <tshimizu@ga2.so-net.ne.jp> |
| 11 | * |
| 12 | * Copyright (c) 2001 SHIMIZU Takuya, All Rights Reserved. |
| 13 | * |
| 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. |
| 18 | * |
| 19 | ********************************************************************/ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/init.h> |
| 24 | |
| 25 | #include <net/irda/irda.h> |
| 26 | |
| 27 | #include "sir-dev.h" |
| 28 | |
| 29 | static int act200l_reset(struct sir_dev *dev); |
| 30 | static int act200l_open(struct sir_dev *dev); |
| 31 | static int act200l_close(struct sir_dev *dev); |
| 32 | static int act200l_change_speed(struct sir_dev *dev, unsigned speed); |
| 33 | |
| 34 | /* Regsiter 0: Control register #1 */ |
| 35 | #define ACT200L_REG0 0x00 |
| 36 | #define ACT200L_TXEN 0x01 /* Enable transmitter */ |
| 37 | #define ACT200L_RXEN 0x02 /* Enable receiver */ |
| 38 | |
| 39 | /* Register 1: Control register #2 */ |
| 40 | #define ACT200L_REG1 0x10 |
| 41 | #define ACT200L_LODB 0x01 /* Load new baud rate count value */ |
| 42 | #define ACT200L_WIDE 0x04 /* Expand the maximum allowable pulse */ |
| 43 | |
| 44 | /* Register 4: Output Power register */ |
| 45 | #define ACT200L_REG4 0x40 |
| 46 | #define ACT200L_OP0 0x01 /* Enable LED1C output */ |
| 47 | #define ACT200L_OP1 0x02 /* Enable LED2C output */ |
| 48 | #define ACT200L_BLKR 0x04 |
| 49 | |
| 50 | /* Register 5: Receive Mode register */ |
| 51 | #define ACT200L_REG5 0x50 |
| 52 | #define ACT200L_RWIDL 0x01 /* fixed 1.6us pulse mode */ |
| 53 | |
| 54 | /* Register 6: Receive Sensitivity register #1 */ |
| 55 | #define ACT200L_REG6 0x60 |
| 56 | #define ACT200L_RS0 0x01 /* receive threshold bit 0 */ |
| 57 | #define ACT200L_RS1 0x02 /* receive threshold bit 1 */ |
| 58 | |
| 59 | /* Register 7: Receive Sensitivity register #2 */ |
| 60 | #define ACT200L_REG7 0x70 |
| 61 | #define ACT200L_ENPOS 0x04 /* Ignore the falling edge */ |
| 62 | |
| 63 | /* Register 8,9: Baud Rate Dvider register #1,#2 */ |
| 64 | #define ACT200L_REG8 0x80 |
| 65 | #define ACT200L_REG9 0x90 |
| 66 | |
| 67 | #define ACT200L_2400 0x5f |
| 68 | #define ACT200L_9600 0x17 |
| 69 | #define ACT200L_19200 0x0b |
| 70 | #define ACT200L_38400 0x05 |
| 71 | #define ACT200L_57600 0x03 |
| 72 | #define ACT200L_115200 0x01 |
| 73 | |
| 74 | /* Register 13: Control register #3 */ |
| 75 | #define ACT200L_REG13 0xd0 |
| 76 | #define ACT200L_SHDW 0x01 /* Enable access to shadow registers */ |
| 77 | |
| 78 | /* Register 15: Status register */ |
| 79 | #define ACT200L_REG15 0xf0 |
| 80 | |
| 81 | /* Register 21: Control register #4 */ |
| 82 | #define ACT200L_REG21 0x50 |
| 83 | #define ACT200L_EXCK 0x02 /* Disable clock output driver */ |
| 84 | #define ACT200L_OSCL 0x04 /* oscillator in low power, medium accuracy mode */ |
| 85 | |
| 86 | static struct dongle_driver act200l = { |
| 87 | .owner = THIS_MODULE, |
| 88 | .driver_name = "ACTiSYS ACT-IR200L", |
| 89 | .type = IRDA_ACT200L_DONGLE, |
| 90 | .open = act200l_open, |
| 91 | .close = act200l_close, |
| 92 | .reset = act200l_reset, |
| 93 | .set_speed = act200l_change_speed, |
| 94 | }; |
| 95 | |
| 96 | static int __init act200l_sir_init(void) |
| 97 | { |
| 98 | return irda_register_dongle(&act200l); |
| 99 | } |
| 100 | |
| 101 | static void __exit act200l_sir_cleanup(void) |
| 102 | { |
| 103 | irda_unregister_dongle(&act200l); |
| 104 | } |
| 105 | |
| 106 | static int act200l_open(struct sir_dev *dev) |
| 107 | { |
| 108 | struct qos_info *qos = &dev->qos; |
| 109 | |
Harvey Harrison | a97a6f1 | 2008-07-30 17:20:18 -0700 | [diff] [blame] | 110 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | /* Power on the dongle */ |
| 113 | sirdev_set_dtr_rts(dev, TRUE, TRUE); |
| 114 | |
| 115 | /* Set the speeds we can accept */ |
| 116 | qos->baud_rate.bits &= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200; |
| 117 | qos->min_turn_time.bits = 0x03; |
| 118 | irda_qos_bits_to_value(qos); |
| 119 | |
| 120 | /* irda thread waits 50 msec for power settling */ |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static int act200l_close(struct sir_dev *dev) |
| 126 | { |
Harvey Harrison | a97a6f1 | 2008-07-30 17:20:18 -0700 | [diff] [blame] | 127 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* Power off the dongle */ |
| 130 | sirdev_set_dtr_rts(dev, FALSE, FALSE); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Function act200l_change_speed (dev, speed) |
| 137 | * |
| 138 | * Set the speed for the ACTiSYS ACT-IR200L type dongle. |
| 139 | * |
| 140 | */ |
| 141 | static int act200l_change_speed(struct sir_dev *dev, unsigned speed) |
| 142 | { |
| 143 | u8 control[3]; |
| 144 | int ret = 0; |
| 145 | |
Harvey Harrison | a97a6f1 | 2008-07-30 17:20:18 -0700 | [diff] [blame] | 146 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | /* Clear DTR and set RTS to enter command mode */ |
| 149 | sirdev_set_dtr_rts(dev, FALSE, TRUE); |
| 150 | |
| 151 | switch (speed) { |
| 152 | default: |
| 153 | ret = -EINVAL; |
| 154 | /* fall through */ |
| 155 | case 9600: |
| 156 | control[0] = ACT200L_REG8 | (ACT200L_9600 & 0x0f); |
| 157 | control[1] = ACT200L_REG9 | ((ACT200L_9600 >> 4) & 0x0f); |
| 158 | break; |
| 159 | case 19200: |
| 160 | control[0] = ACT200L_REG8 | (ACT200L_19200 & 0x0f); |
| 161 | control[1] = ACT200L_REG9 | ((ACT200L_19200 >> 4) & 0x0f); |
| 162 | break; |
| 163 | case 38400: |
| 164 | control[0] = ACT200L_REG8 | (ACT200L_38400 & 0x0f); |
| 165 | control[1] = ACT200L_REG9 | ((ACT200L_38400 >> 4) & 0x0f); |
| 166 | break; |
| 167 | case 57600: |
| 168 | control[0] = ACT200L_REG8 | (ACT200L_57600 & 0x0f); |
| 169 | control[1] = ACT200L_REG9 | ((ACT200L_57600 >> 4) & 0x0f); |
| 170 | break; |
| 171 | case 115200: |
| 172 | control[0] = ACT200L_REG8 | (ACT200L_115200 & 0x0f); |
| 173 | control[1] = ACT200L_REG9 | ((ACT200L_115200 >> 4) & 0x0f); |
| 174 | break; |
| 175 | } |
| 176 | control[2] = ACT200L_REG1 | ACT200L_LODB | ACT200L_WIDE; |
| 177 | |
| 178 | /* Write control bytes */ |
| 179 | sirdev_raw_write(dev, control, 3); |
| 180 | msleep(5); |
| 181 | |
| 182 | /* Go back to normal mode */ |
| 183 | sirdev_set_dtr_rts(dev, TRUE, TRUE); |
| 184 | |
| 185 | dev->speed = speed; |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Function act200l_reset (driver) |
| 191 | * |
| 192 | * Reset the ACTiSYS ACT-IR200L type dongle. |
| 193 | */ |
| 194 | |
| 195 | #define ACT200L_STATE_WAIT1_RESET (SIRDEV_STATE_DONGLE_RESET+1) |
| 196 | #define ACT200L_STATE_WAIT2_RESET (SIRDEV_STATE_DONGLE_RESET+2) |
| 197 | |
| 198 | static int act200l_reset(struct sir_dev *dev) |
| 199 | { |
| 200 | unsigned state = dev->fsm.substate; |
| 201 | unsigned delay = 0; |
| 202 | u8 control[9] = { |
| 203 | ACT200L_REG15, |
| 204 | ACT200L_REG13 | ACT200L_SHDW, |
| 205 | ACT200L_REG21 | ACT200L_EXCK | ACT200L_OSCL, |
| 206 | ACT200L_REG13, |
| 207 | ACT200L_REG7 | ACT200L_ENPOS, |
| 208 | ACT200L_REG6 | ACT200L_RS0 | ACT200L_RS1, |
| 209 | ACT200L_REG5 | ACT200L_RWIDL, |
| 210 | ACT200L_REG4 | ACT200L_OP0 | ACT200L_OP1 | ACT200L_BLKR, |
| 211 | ACT200L_REG0 | ACT200L_TXEN | ACT200L_RXEN |
| 212 | }; |
| 213 | int ret = 0; |
| 214 | |
Harvey Harrison | a97a6f1 | 2008-07-30 17:20:18 -0700 | [diff] [blame] | 215 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | switch (state) { |
| 218 | case SIRDEV_STATE_DONGLE_RESET: |
| 219 | /* Reset the dongle : set RTS low for 25 ms */ |
| 220 | sirdev_set_dtr_rts(dev, TRUE, FALSE); |
| 221 | state = ACT200L_STATE_WAIT1_RESET; |
| 222 | delay = 50; |
| 223 | break; |
| 224 | |
| 225 | case ACT200L_STATE_WAIT1_RESET: |
| 226 | /* Clear DTR and set RTS to enter command mode */ |
| 227 | sirdev_set_dtr_rts(dev, FALSE, TRUE); |
| 228 | |
| 229 | udelay(25); /* better wait for some short while */ |
| 230 | |
| 231 | /* Write control bytes */ |
| 232 | sirdev_raw_write(dev, control, sizeof(control)); |
| 233 | state = ACT200L_STATE_WAIT2_RESET; |
| 234 | delay = 15; |
| 235 | break; |
| 236 | |
| 237 | case ACT200L_STATE_WAIT2_RESET: |
| 238 | /* Go back to normal mode */ |
| 239 | sirdev_set_dtr_rts(dev, TRUE, TRUE); |
| 240 | dev->speed = 9600; |
| 241 | break; |
| 242 | default: |
Harvey Harrison | a97a6f1 | 2008-07-30 17:20:18 -0700 | [diff] [blame] | 243 | IRDA_ERROR("%s(), unknown state %d\n", __func__, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | ret = -1; |
| 245 | break; |
| 246 | } |
| 247 | dev->fsm.substate = state; |
| 248 | return (delay > 0) ? delay : ret; |
| 249 | } |
| 250 | |
| 251 | MODULE_AUTHOR("SHIMIZU Takuya <tshimizu@ga2.so-net.ne.jp>"); |
| 252 | MODULE_DESCRIPTION("ACTiSYS ACT-IR200L dongle driver"); |
| 253 | MODULE_LICENSE("GPL"); |
| 254 | MODULE_ALIAS("irda-dongle-10"); /* IRDA_ACT200L_DONGLE */ |
| 255 | |
| 256 | module_init(act200l_sir_init); |
| 257 | module_exit(act200l_sir_cleanup); |