0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include <linux/kernel.h>
0036 #include <linux/errno.h>
0037 #include <linux/slab.h>
0038 #include <linux/tty.h>
0039 #include <linux/tty_flip.h>
0040 #include <linux/module.h>
0041 #include <linux/spinlock.h>
0042 #include <linux/usb.h>
0043 #include <linux/usb/serial.h>
0044 #include <linux/uaccess.h>
0045 #include "usb-wwan.h"
0046
0047 #define DRIVER_AUTHOR "Roelf Diedericks"
0048 #define DRIVER_DESC "IPWireless tty driver"
0049
0050 #define IPW_TTY_MAJOR 240
0051 #define IPW_TTY_MINORS 256
0052
0053 #define USB_IPW_MAGIC 0x6d02
0054
0055
0056
0057 #define EVENT_BUFFER_SIZE 0xFF
0058 #define CHAR2INT16(c1, c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff))
0059
0060
0061 #define IPW_VID 0x0bc3
0062 #define IPW_PID 0x0001
0063
0064
0065
0066
0067
0068 enum {
0069 ipw_sio_b256000 = 0x000e,
0070 ipw_sio_b128000 = 0x001d,
0071 ipw_sio_b115200 = 0x0020,
0072 ipw_sio_b57600 = 0x0040,
0073 ipw_sio_b56000 = 0x0042,
0074 ipw_sio_b38400 = 0x0060,
0075 ipw_sio_b19200 = 0x00c0,
0076 ipw_sio_b14400 = 0x0100,
0077 ipw_sio_b9600 = 0x0180,
0078 ipw_sio_b4800 = 0x0300,
0079 ipw_sio_b2400 = 0x0600,
0080 ipw_sio_b1200 = 0x0c00,
0081 ipw_sio_b600 = 0x1800
0082 };
0083
0084
0085 #define ipw_dtb_7 0x700
0086 #define ipw_dtb_8 0x810
0087
0088
0089
0090 #define IPW_SIO_RXCTL 0x00
0091 #define IPW_SIO_SET_BAUD 0x01
0092 #define IPW_SIO_SET_LINE 0x03
0093 #define IPW_SIO_SET_PIN 0x03
0094 #define IPW_SIO_POLL 0x08
0095 #define IPW_SIO_INIT 0x11
0096 #define IPW_SIO_PURGE 0x12
0097 #define IPW_SIO_HANDFLOW 0x13
0098 #define IPW_SIO_SETCHARS 0x13
0099
0100
0101
0102 #define IPW_PIN_SETDTR 0x101
0103 #define IPW_PIN_SETRTS 0x202
0104 #define IPW_PIN_CLRDTR 0x100
0105 #define IPW_PIN_CLRRTS 0x200
0106
0107
0108 #define IPW_RXBULK_ON 1
0109 #define IPW_RXBULK_OFF 0
0110
0111
0112 #define IPW_BYTES_FLOWINIT { 0x01, 0, 0, 0, 0x40, 0, 0, 0, \
0113 0, 0, 0, 0, 0, 0, 0, 0 }
0114
0115
0116
0117
0118
0119
0120
0121 #define IPW_DSR ((1<<4) | (1<<5))
0122 #define IPW_CTS ((1<<5) | (1<<4))
0123
0124 #define IPW_WANTS_TO_SEND 0x30
0125
0126 static const struct usb_device_id id_table[] = {
0127 { USB_DEVICE(IPW_VID, IPW_PID) },
0128 { },
0129 };
0130 MODULE_DEVICE_TABLE(usb, id_table);
0131
0132 static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port)
0133 {
0134 struct usb_device *udev = port->serial->dev;
0135 struct device *dev = &port->dev;
0136 u8 buf_flow_static[16] = IPW_BYTES_FLOWINIT;
0137 u8 *buf_flow_init;
0138 int result;
0139
0140 buf_flow_init = kmemdup(buf_flow_static, 16, GFP_KERNEL);
0141 if (!buf_flow_init)
0142 return -ENOMEM;
0143
0144
0145
0146
0147 dev_dbg(dev, "%s: Sending SIO_INIT (we guess)\n", __func__);
0148 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0149 IPW_SIO_INIT,
0150 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
0151 0,
0152 0,
0153 NULL,
0154 0,
0155 100000);
0156 if (result < 0)
0157 dev_err(dev, "Init of modem failed (error = %d)\n", result);
0158
0159
0160 usb_clear_halt(udev, usb_rcvbulkpipe(udev, port->bulk_in_endpointAddress));
0161 usb_clear_halt(udev, usb_sndbulkpipe(udev, port->bulk_out_endpointAddress));
0162
0163
0164 dev_dbg(dev, "%s: setting up bulk read callback\n", __func__);
0165 usb_wwan_open(tty, port);
0166
0167
0168 dev_dbg(dev, "%s:asking modem for RxRead (RXBULK_ON)\n", __func__);
0169 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0170 IPW_SIO_RXCTL,
0171 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
0172 IPW_RXBULK_ON,
0173 0,
0174 NULL,
0175 0,
0176 100000);
0177 if (result < 0)
0178 dev_err(dev, "Enabling bulk RxRead failed (error = %d)\n", result);
0179
0180
0181 dev_dbg(dev, "%s:setting init flowcontrol (%s)\n", __func__, buf_flow_init);
0182 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0183 IPW_SIO_HANDFLOW,
0184 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
0185 0,
0186 0,
0187 buf_flow_init,
0188 0x10,
0189 200000);
0190 if (result < 0)
0191 dev_err(dev, "initial flowcontrol failed (error = %d)\n", result);
0192
0193 kfree(buf_flow_init);
0194 return 0;
0195 }
0196
0197 static int ipw_attach(struct usb_serial *serial)
0198 {
0199 struct usb_wwan_intf_private *data;
0200
0201 data = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL);
0202 if (!data)
0203 return -ENOMEM;
0204
0205 spin_lock_init(&data->susp_lock);
0206 usb_set_serial_data(serial, data);
0207 return 0;
0208 }
0209
0210 static void ipw_release(struct usb_serial *serial)
0211 {
0212 struct usb_wwan_intf_private *data = usb_get_serial_data(serial);
0213
0214 usb_set_serial_data(serial, NULL);
0215 kfree(data);
0216 }
0217
0218 static void ipw_dtr_rts(struct usb_serial_port *port, int on)
0219 {
0220 struct usb_device *udev = port->serial->dev;
0221 struct device *dev = &port->dev;
0222 int result;
0223
0224 dev_dbg(dev, "%s: on = %d\n", __func__, on);
0225
0226 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0227 IPW_SIO_SET_PIN,
0228 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
0229 on ? IPW_PIN_SETDTR : IPW_PIN_CLRDTR,
0230 0,
0231 NULL,
0232 0,
0233 200000);
0234 if (result < 0)
0235 dev_err(dev, "setting dtr failed (error = %d)\n", result);
0236
0237 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0238 IPW_SIO_SET_PIN, USB_TYPE_VENDOR |
0239 USB_RECIP_INTERFACE | USB_DIR_OUT,
0240 on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS,
0241 0,
0242 NULL,
0243 0,
0244 200000);
0245 if (result < 0)
0246 dev_err(dev, "setting rts failed (error = %d)\n", result);
0247 }
0248
0249 static void ipw_close(struct usb_serial_port *port)
0250 {
0251 struct usb_device *udev = port->serial->dev;
0252 struct device *dev = &port->dev;
0253 int result;
0254
0255
0256 dev_dbg(dev, "%s:sending purge\n", __func__);
0257 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0258 IPW_SIO_PURGE, USB_TYPE_VENDOR |
0259 USB_RECIP_INTERFACE | USB_DIR_OUT,
0260 0x03,
0261 0,
0262 NULL,
0263 0,
0264 200000);
0265 if (result < 0)
0266 dev_err(dev, "purge failed (error = %d)\n", result);
0267
0268
0269
0270
0271 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0272 IPW_SIO_RXCTL,
0273 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
0274 IPW_RXBULK_OFF,
0275 0,
0276 NULL,
0277 0,
0278 100000);
0279
0280 if (result < 0)
0281 dev_err(dev, "Disabling bulk RxRead failed (error = %d)\n", result);
0282
0283 usb_wwan_close(port);
0284 }
0285
0286 static struct usb_serial_driver ipw_device = {
0287 .driver = {
0288 .owner = THIS_MODULE,
0289 .name = "ipw",
0290 },
0291 .description = "IPWireless converter",
0292 .id_table = id_table,
0293 .num_ports = 1,
0294 .open = ipw_open,
0295 .close = ipw_close,
0296 .attach = ipw_attach,
0297 .release = ipw_release,
0298 .port_probe = usb_wwan_port_probe,
0299 .port_remove = usb_wwan_port_remove,
0300 .dtr_rts = ipw_dtr_rts,
0301 .write = usb_wwan_write,
0302 };
0303
0304 static struct usb_serial_driver * const serial_drivers[] = {
0305 &ipw_device, NULL
0306 };
0307
0308 module_usb_serial_driver(serial_drivers, id_table);
0309
0310
0311 MODULE_AUTHOR(DRIVER_AUTHOR);
0312 MODULE_DESCRIPTION(DRIVER_DESC);
0313 MODULE_LICENSE("GPL");