0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "dibusb.h"
0010
0011
0012 #define MAX_XFER_SIZE 64
0013
0014 static int debug;
0015 module_param(debug, int, 0644);
0016 MODULE_PARM_DESC(debug, "set debugging level (1=info (|-able))." DVB_USB_DEBUG_STATUS);
0017 MODULE_LICENSE("GPL");
0018
0019 #define deb_info(args...) dprintk(debug,0x01,args)
0020
0021
0022 int dibusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
0023 {
0024 if (adap->priv != NULL) {
0025 struct dibusb_state *st = adap->priv;
0026 if (st->ops.fifo_ctrl != NULL)
0027 if (st->ops.fifo_ctrl(adap->fe_adap[0].fe, onoff)) {
0028 err("error while controlling the fifo of the demod.");
0029 return -ENODEV;
0030 }
0031 }
0032 return 0;
0033 }
0034 EXPORT_SYMBOL(dibusb_streaming_ctrl);
0035
0036 int dibusb_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
0037 {
0038 if (adap->priv != NULL) {
0039 struct dibusb_state *st = adap->priv;
0040 if (st->ops.pid_ctrl != NULL)
0041 st->ops.pid_ctrl(adap->fe_adap[0].fe,
0042 index, pid, onoff);
0043 }
0044 return 0;
0045 }
0046 EXPORT_SYMBOL(dibusb_pid_filter);
0047
0048 int dibusb_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
0049 {
0050 if (adap->priv != NULL) {
0051 struct dibusb_state *st = adap->priv;
0052 if (st->ops.pid_parse != NULL)
0053 if (st->ops.pid_parse(adap->fe_adap[0].fe, onoff) < 0)
0054 err("could not handle pid_parser");
0055 }
0056 return 0;
0057 }
0058 EXPORT_SYMBOL(dibusb_pid_filter_ctrl);
0059
0060 int dibusb_power_ctrl(struct dvb_usb_device *d, int onoff)
0061 {
0062 u8 *b;
0063 int ret;
0064
0065 b = kmalloc(3, GFP_KERNEL);
0066 if (!b)
0067 return -ENOMEM;
0068
0069 b[0] = DIBUSB_REQ_SET_IOCTL;
0070 b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
0071 b[2] = onoff ? DIBUSB_IOCTL_POWER_WAKEUP : DIBUSB_IOCTL_POWER_SLEEP;
0072
0073 ret = dvb_usb_generic_write(d, b, 3);
0074
0075 kfree(b);
0076
0077 msleep(10);
0078
0079 return ret;
0080 }
0081 EXPORT_SYMBOL(dibusb_power_ctrl);
0082
0083 int dibusb2_0_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
0084 {
0085 int ret;
0086 u8 *b;
0087
0088 b = kmalloc(3, GFP_KERNEL);
0089 if (!b)
0090 return -ENOMEM;
0091
0092 if ((ret = dibusb_streaming_ctrl(adap,onoff)) < 0)
0093 goto ret;
0094
0095 if (onoff) {
0096 b[0] = DIBUSB_REQ_SET_STREAMING_MODE;
0097 b[1] = 0x00;
0098 ret = dvb_usb_generic_write(adap->dev, b, 2);
0099 if (ret < 0)
0100 goto ret;
0101 }
0102
0103 b[0] = DIBUSB_REQ_SET_IOCTL;
0104 b[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM : DIBUSB_IOCTL_CMD_DISABLE_STREAM;
0105 ret = dvb_usb_generic_write(adap->dev, b, 3);
0106
0107 ret:
0108 kfree(b);
0109 return ret;
0110 }
0111 EXPORT_SYMBOL(dibusb2_0_streaming_ctrl);
0112
0113 int dibusb2_0_power_ctrl(struct dvb_usb_device *d, int onoff)
0114 {
0115 u8 *b;
0116 int ret;
0117
0118 if (!onoff)
0119 return 0;
0120
0121 b = kmalloc(3, GFP_KERNEL);
0122 if (!b)
0123 return -ENOMEM;
0124
0125 b[0] = DIBUSB_REQ_SET_IOCTL;
0126 b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
0127 b[2] = DIBUSB_IOCTL_POWER_WAKEUP;
0128
0129 ret = dvb_usb_generic_write(d, b, 3);
0130
0131 kfree(b);
0132
0133 return ret;
0134 }
0135 EXPORT_SYMBOL(dibusb2_0_power_ctrl);
0136
0137 static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr,
0138 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
0139 {
0140 u8 *sndbuf;
0141 int ret, wo, len;
0142
0143
0144 wo = (rbuf == NULL || rlen == 0);
0145
0146 len = 2 + wlen + (wo ? 0 : 2);
0147
0148 sndbuf = kmalloc(MAX_XFER_SIZE, GFP_KERNEL);
0149 if (!sndbuf)
0150 return -ENOMEM;
0151
0152 if (4 + wlen > MAX_XFER_SIZE) {
0153 warn("i2c wr: len=%d is too big!\n", wlen);
0154 ret = -EOPNOTSUPP;
0155 goto ret;
0156 }
0157
0158 sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
0159 sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
0160
0161 memcpy(&sndbuf[2], wbuf, wlen);
0162
0163 if (!wo) {
0164 sndbuf[wlen + 2] = (rlen >> 8) & 0xff;
0165 sndbuf[wlen + 3] = rlen & 0xff;
0166 }
0167
0168 ret = dvb_usb_generic_rw(d, sndbuf, len, rbuf, rlen, 0);
0169
0170 ret:
0171 kfree(sndbuf);
0172 return ret;
0173 }
0174
0175
0176
0177
0178 static int dibusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
0179 {
0180 struct dvb_usb_device *d = i2c_get_adapdata(adap);
0181 int i;
0182
0183 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0184 return -EAGAIN;
0185
0186 for (i = 0; i < num; i++) {
0187
0188 if (i+1 < num && (msg[i].flags & I2C_M_RD) == 0
0189 && (msg[i+1].flags & I2C_M_RD)) {
0190 if (dibusb_i2c_msg(d, msg[i].addr, msg[i].buf,msg[i].len,
0191 msg[i+1].buf,msg[i+1].len) < 0)
0192 break;
0193 i++;
0194 } else if ((msg[i].flags & I2C_M_RD) == 0) {
0195 if (dibusb_i2c_msg(d, msg[i].addr, msg[i].buf,msg[i].len,NULL,0) < 0)
0196 break;
0197 } else if (msg[i].addr != 0x50) {
0198
0199
0200
0201 if (dibusb_i2c_msg(d, msg[i].addr, NULL, 0, msg[i].buf, msg[i].len) < 0)
0202 break;
0203 }
0204 }
0205
0206 mutex_unlock(&d->i2c_mutex);
0207 return i;
0208 }
0209
0210 static u32 dibusb_i2c_func(struct i2c_adapter *adapter)
0211 {
0212 return I2C_FUNC_I2C;
0213 }
0214
0215 struct i2c_algorithm dibusb_i2c_algo = {
0216 .master_xfer = dibusb_i2c_xfer,
0217 .functionality = dibusb_i2c_func,
0218 };
0219 EXPORT_SYMBOL(dibusb_i2c_algo);
0220
0221 int dibusb_read_eeprom_byte(struct dvb_usb_device *d, u8 offs, u8 *val)
0222 {
0223 u8 *buf;
0224 int rc;
0225
0226 buf = kzalloc(2, GFP_KERNEL);
0227 if (!buf)
0228 return -ENOMEM;
0229
0230 buf[0] = offs;
0231
0232 rc = dibusb_i2c_msg(d, 0x50, &buf[0], 1, &buf[1], 1);
0233 *val = buf[1];
0234 kfree(buf);
0235
0236 return rc;
0237 }
0238 EXPORT_SYMBOL(dibusb_read_eeprom_byte);
0239
0240
0241
0242
0243 struct rc_map_table rc_map_dibusb_table[] = {
0244
0245 { 0x0016, KEY_POWER },
0246 { 0x0010, KEY_MUTE },
0247 { 0x0003, KEY_1 },
0248 { 0x0001, KEY_2 },
0249 { 0x0006, KEY_3 },
0250 { 0x0009, KEY_4 },
0251 { 0x001d, KEY_5 },
0252 { 0x001f, KEY_6 },
0253 { 0x000d, KEY_7 },
0254 { 0x0019, KEY_8 },
0255 { 0x001b, KEY_9 },
0256 { 0x0015, KEY_0 },
0257 { 0x0005, KEY_CHANNELUP },
0258 { 0x0002, KEY_CHANNELDOWN },
0259 { 0x001e, KEY_VOLUMEUP },
0260 { 0x000a, KEY_VOLUMEDOWN },
0261 { 0x0011, KEY_RECORD },
0262 { 0x0017, KEY_FAVORITES },
0263 { 0x0014, KEY_PLAY },
0264 { 0x001a, KEY_STOP },
0265 { 0x0040, KEY_REWIND },
0266 { 0x0012, KEY_FASTFORWARD },
0267 { 0x000e, KEY_PREVIOUS },
0268 { 0x004c, KEY_PAUSE },
0269 { 0x004d, KEY_SCREEN },
0270 { 0x0054, KEY_AUDIO },
0271
0272 { 0x000c, KEY_CANCEL },
0273 { 0x001c, KEY_EPG },
0274 { 0x0000, KEY_TAB },
0275 { 0x0048, KEY_INFO },
0276 { 0x0004, KEY_LIST },
0277 { 0x000f, KEY_TEXT },
0278
0279 { 0x8612, KEY_POWER },
0280 { 0x860f, KEY_SELECT },
0281 { 0x860c, KEY_UNKNOWN },
0282 { 0x860b, KEY_EPG },
0283 { 0x8610, KEY_MUTE },
0284 { 0x8601, KEY_1 },
0285 { 0x8602, KEY_2 },
0286 { 0x8603, KEY_3 },
0287 { 0x8604, KEY_4 },
0288 { 0x8605, KEY_5 },
0289 { 0x8606, KEY_6 },
0290 { 0x8607, KEY_7 },
0291 { 0x8608, KEY_8 },
0292 { 0x8609, KEY_9 },
0293 { 0x860a, KEY_0 },
0294 { 0x8618, KEY_ZOOM },
0295 { 0x861c, KEY_UNKNOWN },
0296 { 0x8613, KEY_UNKNOWN },
0297 { 0x8600, KEY_UNDO },
0298 { 0x861d, KEY_RECORD },
0299 { 0x860d, KEY_STOP },
0300 { 0x860e, KEY_PAUSE },
0301 { 0x8616, KEY_PLAY },
0302 { 0x8611, KEY_BACK },
0303 { 0x8619, KEY_FORWARD },
0304 { 0x8614, KEY_UNKNOWN },
0305 { 0x8615, KEY_ESC },
0306 { 0x861a, KEY_UP },
0307 { 0x861e, KEY_DOWN },
0308 { 0x861f, KEY_LEFT },
0309 { 0x861b, KEY_RIGHT },
0310
0311
0312 { 0x8000, KEY_MUTE },
0313 { 0x8001, KEY_TEXT },
0314 { 0x8002, KEY_HOME },
0315 { 0x8003, KEY_POWER },
0316
0317 { 0x8004, KEY_RED },
0318 { 0x8005, KEY_GREEN },
0319 { 0x8006, KEY_YELLOW },
0320 { 0x8007, KEY_BLUE },
0321
0322 { 0x8008, KEY_DVD },
0323 { 0x8009, KEY_AUDIO },
0324 { 0x800a, KEY_IMAGES },
0325 { 0x800b, KEY_VIDEO },
0326
0327 { 0x800c, KEY_BACK },
0328 { 0x800d, KEY_UP },
0329 { 0x800e, KEY_RADIO },
0330 { 0x800f, KEY_EPG },
0331
0332 { 0x8010, KEY_LEFT },
0333 { 0x8011, KEY_OK },
0334 { 0x8012, KEY_RIGHT },
0335 { 0x8013, KEY_UNKNOWN },
0336
0337 { 0x8014, KEY_TV },
0338 { 0x8015, KEY_DOWN },
0339 { 0x8016, KEY_MENU },
0340 { 0x8017, KEY_LAST },
0341
0342 { 0x8018, KEY_RECORD },
0343 { 0x8019, KEY_STOP },
0344 { 0x801a, KEY_PAUSE },
0345 { 0x801b, KEY_PLAY },
0346
0347 { 0x801c, KEY_PREVIOUS },
0348 { 0x801d, KEY_REWIND },
0349 { 0x801e, KEY_FASTFORWARD },
0350 { 0x801f, KEY_NEXT},
0351
0352 { 0x8040, KEY_1 },
0353 { 0x8041, KEY_2 },
0354 { 0x8042, KEY_3 },
0355 { 0x8043, KEY_CHANNELUP },
0356
0357 { 0x8044, KEY_4 },
0358 { 0x8045, KEY_5 },
0359 { 0x8046, KEY_6 },
0360 { 0x8047, KEY_CHANNELDOWN },
0361
0362 { 0x8048, KEY_7 },
0363 { 0x8049, KEY_8 },
0364 { 0x804a, KEY_9 },
0365 { 0x804b, KEY_VOLUMEUP },
0366
0367 { 0x804c, KEY_CLEAR },
0368 { 0x804d, KEY_0 },
0369 { 0x804e, KEY_ENTER },
0370 { 0x804f, KEY_VOLUMEDOWN },
0371 };
0372 EXPORT_SYMBOL(rc_map_dibusb_table);
0373
0374 int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
0375 {
0376 u8 *buf;
0377 int ret;
0378
0379 buf = kmalloc(5, GFP_KERNEL);
0380 if (!buf)
0381 return -ENOMEM;
0382
0383 buf[0] = DIBUSB_REQ_POLL_REMOTE;
0384
0385 ret = dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
0386 if (ret < 0)
0387 goto ret;
0388
0389 dvb_usb_nec_rc_key_to_event(d, buf, event, state);
0390
0391 if (buf[0] != 0)
0392 deb_info("key: %*ph\n", 5, buf);
0393
0394 ret:
0395 kfree(buf);
0396
0397 return ret;
0398 }
0399 EXPORT_SYMBOL(dibusb_rc_query);