static int m920x_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct dvb_usb_device *d; struct usb_host_interface *alt; int ret; if ((ret = dvb_usb_device_init(intf, &megasky_properties, THIS_MODULE, &d)) == 0) { deb_rc("probed!\n"); alt = usb_altnum_to_altsetting(intf, 1); if (alt == NULL) { deb_rc("not alt found!\n"); return -ENODEV; } ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber, alt->desc.bAlternateSetting); if (ret < 0) return ret; deb_rc("Changed to alternate setting!\n"); if ((ret = m9206_rc_init(d->udev)) != 0) return ret; } return ret; }
static int friio_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct dvb_usb_device *d; struct usb_host_interface *alt; int ret; if (intf->num_altsetting < GL861_ALTSETTING_COUNT) return -ENODEV; alt = usb_altnum_to_altsetting(intf, FRIIO_BULK_ALTSETTING); if (alt == NULL) { deb_rc("not alt found!\n"); return -ENODEV; } ret = usb_set_interface(interface_to_usbdev(intf), alt->desc.bInterfaceNumber, alt->desc.bAlternateSetting); if (ret != 0) { deb_rc("failed to set alt-setting!\n"); return ret; } ret = dvb_usb_device_init(intf, &friio_properties, THIS_MODULE, &d, adapter_nr); if (ret == 0) friio_streaming_ctrl(&d->adapter[0], 1); return ret; }
static int frt2(u8* rt_uccode,u8 byte_num,u8 *p_uccode) { u8 *pCode = rt_uccode; u8 i=0; u32 scancode=0; u8 out_io=0; int ret= RC_FUNCTION_SUCCESS; deb_rc("+rc_%s \n", __FUNCTION__); if(byte_num < frt2_para1) goto error; if(pCode[0] != frt2_para2) goto error; if((pCode[1] <frt2_para3 )||(pCode[1] >frt2_para4)) goto error; if( (pCode[2] <frt2_para5 ) && (pCode[2] >frt2_para6) ) { if( (pCode[3] <frt2_para7 ) && (pCode[3] >frt2_para8 ) &&(pCode[4]==frt2_para9 )) scancode=0xffff; else goto error; } else if( (pCode[2] <frt2_para10 ) && (pCode[2] >frt2_para11 ) ) { for (i = 3; i <68; i++) { if ((i% 2)==1) { if( (pCode[i]>frt2_para7 ) || (pCode[i] <frt2_para8 ) ) { deb_rc("Bad rt uc code received[4]\n"); ret= RC_FUNCTION_UNSUCCESS; goto error; } } else { if(pCode[i]<frt2_para12 ) out_io=0; else out_io=1; scancode |= (out_io << (31 -(i-4)/2) ); } } } else goto error; deb_rc("-rc_%s nec:%x\n", __FUNCTION__,scancode); p_uccode[0]=(u8)((scancode>>24) & frt2_bits_mask0); p_uccode[1]=(u8)((scancode>>16) & frt2_bits_mask1); p_uccode[2]=(u8)((scancode>>8) & frt2_bits_mask2); p_uccode[3]=(u8)((scancode>>0) & frt2_bits_mask3); ret= RC_FUNCTION_SUCCESS; error: return ret; }
int dvb_usb_remote_init(struct dvb_usb_device *d) { struct input_dev *input_dev; int i; int err; if (d->props.rc_key_map == NULL || d->props.rc_query == NULL || dvb_usb_disable_rc_polling) return 0; usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); input_dev = input_allocate_device(); if (!input_dev) return -ENOMEM; input_dev->evbit[0] = BIT_MASK(EV_KEY); input_dev->name = "IR-receiver inside an USB DVB receiver"; input_dev->phys = d->rc_phys; usb_to_input_id(d->udev, &input_dev->id); input_dev->cdev.dev = &d->udev->dev; /* set the bits for the keys */ deb_rc("key map size: %d\n", d->props.rc_key_map_size); for (i = 0; i < d->props.rc_key_map_size; i++) { deb_rc("setting bit for event %d item %d\n", d->props.rc_key_map[i].event, i); set_bit(d->props.rc_key_map[i].event, input_dev->keybit); } /* Start the remote-control polling. */ if (d->props.rc_interval < 40) d->props.rc_interval = 100; /* default */ /* setting these two values to non-zero, we have to manage key repeats */ input_dev->rep[REP_PERIOD] = d->props.rc_interval; input_dev->rep[REP_DELAY] = d->props.rc_interval + 150; err = input_register_device(input_dev); if (err) { input_free_device(input_dev); return err; } d->rc_input_dev = input_dev; INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control); info("schedule remote query interval to %d msecs.", d->props.rc_interval); schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval)); d->state |= DVB_USB_STATE_REMOTE; return 0; }
static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { struct m9206_state *m = d->priv; int i, ret = 0; u8 rc_state[2]; if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0) goto unlock; if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0) goto unlock; for (i = 0; i < ARRAY_SIZE(megasky_rc_keys); i++) if (megasky_rc_keys[i].data == rc_state[1]) { *event = megasky_rc_keys[i].event; switch(rc_state[0]) { case 0x80: *state = REMOTE_NO_KEY_PRESSED; goto unlock; case 0x93: case 0x92: m->rep_count = 0; *state = REMOTE_KEY_PRESSED; goto unlock; case 0x91: /* For comfort. */ if (++m->rep_count > 2) *state = REMOTE_KEY_REPEAT; goto unlock; default: deb_rc("Unexpected rc response %x\n", rc_state[0]); *state = REMOTE_NO_KEY_PRESSED; goto unlock; } } if (rc_state[1] != 0) deb_rc("Unknown rc key %x\n", rc_state[1]); *state = REMOTE_NO_KEY_PRESSED; unlock: return ret; }
static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d) { int i, err, rc_interval; struct input_dev *input_dev; input_dev = input_allocate_device(); if (!input_dev) return -ENOMEM; input_dev->evbit[0] = BIT_MASK(EV_KEY); input_dev->name = "IR-receiver inside an USB DVB receiver"; input_dev->phys = d->rc_phys; usb_to_input_id(d->udev, &input_dev->id); input_dev->dev.parent = &d->udev->dev; d->input_dev = input_dev; d->rc_dev = NULL; input_dev->getkeycode = legacy_dvb_usb_getkeycode; input_dev->setkeycode = legacy_dvb_usb_setkeycode; /* set the bits for the keys */ deb_rc("key map size: %d\n", d->props.rc.legacy.rc_map_size); for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) { deb_rc("setting bit for event %d item %d\n", d->props.rc.legacy.rc_map_table[i].keycode, i); set_bit(d->props.rc.legacy.rc_map_table[i].keycode, input_dev->keybit); } /* setting these two values to non-zero, we have to manage key repeats */ input_dev->rep[REP_PERIOD] = d->props.rc.legacy.rc_interval; input_dev->rep[REP_DELAY] = d->props.rc.legacy.rc_interval + 150; input_set_drvdata(input_dev, d); err = input_register_device(input_dev); if (err) input_free_device(input_dev); rc_interval = d->props.rc.legacy.rc_interval; INIT_DELAYED_WORK(&d->rc_query_work, legacy_dvb_usb_read_remote_control); info("schedule remote query interval to %d msecs.", rc_interval); schedule_delayed_work(&d->rc_query_work, msecs_to_jiffies(rc_interval)); d->state |= DVB_USB_STATE_REMOTE; return err; }
static int gl861_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct dvb_usb_device *d; struct usb_host_interface *alt; int ret; if (intf->num_altsetting < 2) return -ENODEV; ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d, adapter_nr); if (ret == 0) { alt = usb_altnum_to_altsetting(intf, 0); if (alt == NULL) { deb_rc("not alt found!\n"); return -ENODEV; } ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber, alt->desc.bAlternateSetting); } return ret; }
static int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { int i; u8 key[5]; u8 b[4] = { 0 }; *event = 0; *state = REMOTE_NO_KEY_PRESSED; digitv_ctrl_msg(d,USB_READ_REMOTE,0,NULL,0,&key[1],4); /* Tell the device we've read the remote. Not sure how necessary this is, but the Nebula SDK does it. */ digitv_ctrl_msg(d,USB_WRITE_REMOTE,0,b,4,NULL,0); /* if something is inside the buffer, simulate key press */ if (key[1] != 0) { for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) { if (rc5_custom(&d->props.rc.legacy.rc_map_table[i]) == key[1] && rc5_data(&d->props.rc.legacy.rc_map_table[i]) == key[2]) { *event = d->props.rc.legacy.rc_map_table[i].keycode; *state = REMOTE_KEY_PRESSED; return 0; } } } if (key[0] != 0) deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]); return 0; }
/* remote control stuff (does not work with my box) */ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { u8 key[10]; int i; /* remove the following return to enabled remote querying */ return 0; vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10); deb_rc("remote query key: %x %d\n",key[1],key[1]); if (key[1] == 0x44) { *state = REMOTE_NO_KEY_PRESSED; return 0; } for (i = 0; i < ARRAY_SIZE(ir_codes_vp702x_table); i++) if (rc5_custom(&ir_codes_vp702x_table[i]) == key[1]) { *state = REMOTE_KEY_PRESSED; *event = ir_codes_vp702x_table[i].event; break; } return 0; }
static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { u8 key[10]; int i; return 0; vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10); deb_rc("remote query key: %x %d\n",key[1],key[1]); if (key[1] == 0x44) { *state = REMOTE_NO_KEY_PRESSED; return 0; } for (i = 0; i < ARRAY_SIZE(vp702x_rc_keys); i++) if (rc5_custom(&vp702x_rc_keys[i]) == key[1]) { *state = REMOTE_KEY_PRESSED; *event = vp702x_rc_keys[i].event; break; } return 0; }
/* remote control stuff (does not work with my box) */ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { u8 *key; int i; /* remove the following return to enabled remote querying */ return 0; key = kmalloc(10, GFP_KERNEL); if (!key) return -ENOMEM; vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10); deb_rc("remote query key: %x %d\n",key[1],key[1]); if (key[1] == 0x44) { *state = REMOTE_NO_KEY_PRESSED; kfree(key); return 0; } for (i = 0; i < ARRAY_SIZE(rc_map_vp702x_table); i++) if (rc5_custom(&rc_map_vp702x_table[i]) == key[1]) { *state = REMOTE_KEY_PRESSED; *event = rc_map_vp702x_table[i].keycode; break; } kfree(key); return 0; }
static int anysee_rc_query(struct dvb_usb_device *d) { u8 buf[] = {CMD_GET_IR_CODE}; u8 ircode[2]; int ret; /* Remote controller is basic NEC using address byte 0x08. Anysee device RC query returns only two bytes, status and code, address byte is dropped. Also it does not return any value for NEC RCs having address byte other than 0x08. Due to that, we cannot use that device as standard NEC receiver. It could be possible make hack which reads whole code directly from device memory... */ ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode)); if (ret) return ret; if (ircode[0]) { deb_rc("%s: key pressed %02x\n", __func__, ircode[1]); rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0); } return 0; }
static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { struct cinergyt2_state *st = d->priv; int i, ret; *state = REMOTE_NO_KEY_PRESSED; mutex_lock(&st->data_mutex); st->data[0] = CINERGYT2_EP1_GET_RC_EVENTS; ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0); if (ret < 0) goto ret; if (st->data[4] == 0xff) { /* key repeat */ st->rc_counter++; if (st->rc_counter > RC_REPEAT_DELAY) { for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) { if (d->last_event == repeatable_keys[i]) { *state = REMOTE_KEY_REPEAT; *event = d->last_event; deb_rc("repeat key, event %x\n", *event); goto ret; } } deb_rc("repeated key (non repeatable)\n"); } goto ret; } /* hack to pass checksum on the custom field */ st->data[2] = ~st->data[1]; dvb_usb_nec_rc_key_to_event(d, st->data, event, state); if (st->data[0] != 0) { if (*event != d->last_event) st->rc_counter = 0; deb_rc("key: %*ph\n", 5, st->data); } ret: mutex_unlock(&st->data_mutex); return ret; }
/* I2C */ static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) { struct dvb_usb_device *d = i2c_get_adapdata(adap); struct m9206_state *m = d->priv; int i; int ret = 0; if (mutex_lock_interruptible(&d->i2c_mutex) < 0) return -EAGAIN; if (num > 2) return -EINVAL; for (i = 0; i < num; i++) { if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].addr, 0x80)) != 0) goto unlock; if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[0], 0x0)) != 0) goto unlock; if (i + 1 < num && msg[i + 1].flags & I2C_M_RD) { int i2c_i; for (i2c_i = 0; i2c_i < M9206_I2C_MAX; i2c_i++) if (msg[i].addr == m->i2c_r[i2c_i].addr) break; if (i2c_i >= M9206_I2C_MAX) { deb_rc("No magic for i2c addr!\n"); ret = -EINVAL; goto unlock; } if ((ret = m9206_write(d->udev, M9206_I2C, m->i2c_r[i2c_i].magic, 0x80)) != 0) goto unlock; if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x60, msg[i + 1].buf, msg[i + 1].len)) != 0) goto unlock; i++; } else { if (msg[i].len != 2) return -EINVAL; if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[1], 0x40)) != 0) goto unlock; } } ret = i; unlock: mutex_unlock(&d->i2c_mutex); return ret; }
int dvb_usb_remote_init(struct dvb_usb_device *d) { int i; if (d->props.rc_key_map == NULL || d->props.rc_query == NULL || dvb_usb_disable_rc_polling) return 0; /* Initialise the remote-control structures.*/ init_input_dev(&d->rc_input_dev); d->rc_input_dev.evbit[0] = BIT(EV_KEY); d->rc_input_dev.keycodesize = sizeof(unsigned char); d->rc_input_dev.keycodemax = KEY_MAX; d->rc_input_dev.name = "IR-receiver inside an USB DVB receiver"; /* set the bits for the keys */ deb_rc("key map size: %d\n",d->props.rc_key_map_size); for (i = 0; i < d->props.rc_key_map_size; i++) { deb_rc("setting bit for event %d item %d\n",d->props.rc_key_map[i].event, i); set_bit(d->props.rc_key_map[i].event, d->rc_input_dev.keybit); } /* Start the remote-control polling. */ if (d->props.rc_interval < 40) d->props.rc_interval = 100; /* default */ /* setting these two values to non-zero, we have to manage key repeats */ d->rc_input_dev.rep[REP_PERIOD] = d->props.rc_interval; d->rc_input_dev.rep[REP_DELAY] = d->props.rc_interval + 150; input_register_device(&d->rc_input_dev); INIT_WORK(&d->rc_query_work, dvb_usb_read_remote_control, d); info("schedule remote query interval to %d msecs.",d->props.rc_interval); schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval)); d->state |= DVB_USB_STATE_REMOTE; return 0; }
static void dvb_usb_read_remote_control(struct work_struct *work) { struct dvb_usb_device *d = container_of(work, struct dvb_usb_device, rc_query_work.work); u32 event; int state; /* TODO: need a lock here. We can simply skip checking for the remote control if we're busy. */ /* when the parameter has been set to 1 via sysfs while the driver was running */ if (dvb_usb_disable_rc_polling) return; if (d->props.rc_query(d,&event,&state)) { err("error while querying for an remote control event."); goto schedule; } switch (state) { case REMOTE_NO_KEY_PRESSED: break; case REMOTE_KEY_PRESSED: deb_rc("key pressed\n"); d->last_event = event; case REMOTE_KEY_REPEAT: deb_rc("key repeated\n"); input_event(d->rc_input_dev, EV_KEY, event, 1); input_sync(d->rc_input_dev); input_event(d->rc_input_dev, EV_KEY, d->last_event, 0); input_sync(d->rc_input_dev); break; default: break; } schedule: schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval)); }
static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { struct cinergyt2_state *st = d->priv; u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS; int i; *state = REMOTE_NO_KEY_PRESSED; dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0); if (key[4] == 0xff) { /* key repeat */ st->rc_counter++; if (st->rc_counter > RC_REPEAT_DELAY) { for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) { if (d->last_event == repeatable_keys[i]) { *state = REMOTE_KEY_REPEAT; *event = d->last_event; deb_rc("repeat key, event %x\n", *event); return 0; } } deb_rc("repeated key (non repeatable)\n"); } return 0; } /* hack to pass checksum on the custom field */ key[2] = ~key[1]; dvb_usb_nec_rc_key_to_event(d, key, event, state); if (key[0] != 0) { if (*event != d->last_event) st->rc_counter = 0; deb_rc("key: %x %x %x %x %x\n", key[0], key[1], key[2], key[3], key[4]); } return 0; }
static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap) { struct m9206_state *m = adap->dev->priv; deb_rc("megasky_frontend_attach!\n"); m->i2c_r[M9206_I2C_DEMOD].addr = megasky_mt352_config.demod_address; m->i2c_r[M9206_I2C_DEMOD].magic = 0x1f; if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL) return -EIO; return 0; }
static int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { u8 key[5]; if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0), 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5, 2000) != 5) return -ENODEV; /* call the universal NEC remote processor, to find out the key's state and event */ dvb_usb_nec_rc_key_to_event(d,key,event,state); if (key[0] != 0) deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]); return 0; }
/* TODO is it really the NEC protocol ? */ int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { u8 key[5]; digitv_ctrl_msg(d,USB_READ_REMOTE,0,NULL,0,&key[1],4); /* TODO state, maybe it is VV ? */ if (key[1] != 0) key[0] = 0x01; /* if something is inside the buffer, simulate key press */ /* call the universal NEC remote processor, to find out the key's state and event */ dvb_usb_nec_rc_key_to_event(d,key,event,state); if (key[0] != 0) deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]); return 0; }
static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap) { char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION }; char state[3]; int ret; adap->fe = cinergyt2_fe_attach(adap->dev); ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state, sizeof(state), 0); if (ret < 0) { deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep " "state info\n"); } /* Copy this pointer as we are gonna need it in the release phase */ cinergyt2_usb_device = adap->dev; return 0; }
static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { u8 key; int i; vp7045_usb_op(d,RC_VAL_READ,NULL,0,&key,1,20); deb_rc("remote query key: %x %d\n",key,key); if (key == 0x44) { *state = REMOTE_NO_KEY_PRESSED; return 0; } for (i = 0; i < ARRAY_SIZE(rc_map_vp7045_table); i++) if (rc5_data(&rc_map_vp7045_table[i]) == key) { *state = REMOTE_KEY_PRESSED; *event = rc_map_vp7045_table[i].keycode; break; } return 0; }
static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { u8 key; int i; vp7045_usb_op(d,RC_VAL_READ,NULL,0,&key,1,20); deb_rc("remote query key: %x %d\n",key,key); if (key == 0x44) { *state = REMOTE_NO_KEY_PRESSED; return 0; } for (i = 0; i < ARRAY_SIZE(vp7045_rc_keys); i++) if (vp7045_rc_keys[i].data == key) { *state = REMOTE_KEY_PRESSED; *event = vp7045_rc_keys[i].event; break; } return 0; }
static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap) { struct dvb_usb_device *d = adap->dev; struct cinergyt2_state *st = d->priv; int ret; adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev); mutex_lock(&st->data_mutex); st->data[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION; ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 3, 0); if (ret < 0) { deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep state info\n"); } mutex_unlock(&st->data_mutex); /* Copy this pointer as we are gonna need it in the release phase */ cinergyt2_usb_device = adap->dev; return ret; }
static int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { int ret; u8 *key = kmalloc(5, GFP_KERNEL); if (!key) return -ENOMEM; if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0), 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5, 2000) != 5) { ret = -ENODEV; goto out; } /* call the universal NEC remote processor, to find out the key's state and event */ dvb_usb_nec_rc_key_to_event(d,key,event,state); if (key[0] != 0) deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]); ret = 0; out: kfree(key); return ret; }
static int megasky_mt352_demod_init(struct dvb_frontend *fe) { u8 config[] = { CONFIG, 0x3d }; u8 clock[] = { CLOCK_CTL, 0x30 }; u8 reset[] = { RESET, 0x80 }; u8 adc_ctl[] = { ADC_CTL_1, 0x40 }; u8 agc[] = { AGC_TARGET, 0x1c, 0x20 }; u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 }; u8 unk1[] = { 0x93, 0x1a }; u8 unk2[] = { 0xb5, 0x7a }; mt352_write(fe, config, ARRAY_SIZE(config)); mt352_write(fe, clock, ARRAY_SIZE(clock)); mt352_write(fe, reset, ARRAY_SIZE(reset)); mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl)); mt352_write(fe, agc, ARRAY_SIZE(agc)); mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc)); mt352_write(fe, unk1, ARRAY_SIZE(unk1)); mt352_write(fe, unk2, ARRAY_SIZE(unk2)); deb_rc("Demod init!\n"); return 0; }
static int af9015_rc_query(struct dvb_usb_device *d) { struct af9015_state *priv = d->priv; int ret; u8 buf[17]; /* read registers needed to detect remote controller code */ ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf)); if (ret) goto error; /* If any of these are non-zero, assume invalid data */ if (buf[1] || buf[2] || buf[3]) return ret; /* Check for repeat of previous code */ if ((priv->rc_repeat != buf[6] || buf[0]) && !memcmp(&buf[12], priv->rc_last, 4)) { deb_rc("%s: key repeated\n", __func__); rc_keydown(d->rc_dev, priv->rc_keycode, 0); priv->rc_repeat = buf[6]; return ret; } /* Only process key if canary killed */ if (buf[16] != 0xff && buf[0] != 0x01) { deb_rc("%s: key pressed %02x %02x %02x %02x\n", __func__, buf[12], buf[13], buf[14], buf[15]); /* Reset the canary */ ret = af9015_write_reg(d, 0x98e9, 0xff); if (ret) goto error; /* Remember this key */ memcpy(priv->rc_last, &buf[12], 4); if (buf[14] == (u8) ~buf[15]) { if (buf[12] == (u8) ~buf[13]) { /* NEC */ priv->rc_keycode = buf[12] << 8 | buf[14]; } else { /* NEC extended*/ priv->rc_keycode = buf[12] << 16 | buf[13] << 8 | buf[14]; } } else { /* 32 bit NEC */ priv->rc_keycode = buf[12] << 24 | buf[13] << 16 | buf[14] << 8 | buf[15]; } rc_keydown(d->rc_dev, priv->rc_keycode, 0); } else { deb_rc("%s: no key press\n", __func__); /* Invalidate last keypress */ /* Not really needed, but helps with debug */ priv->rc_last[2] = priv->rc_last[3]; } priv->rc_repeat = buf[6]; error: if (ret) err("%s: failed:%d", __func__, ret); return ret; }
static int m9206_firmware_download(struct usb_device *udev, const struct firmware *fw) { u16 value, index, size; u8 read[4], *buff; int i, pass, ret = 0; buff = kmalloc(65536, GFP_KERNEL); if ((ret = m9206_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0) goto done; deb_rc("%x %x %x %x\n", read[0], read[1], read[2], read[3]); if ((ret = m9206_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0) goto done; deb_rc("%x\n", read[0]); for (pass = 0; pass < 2; pass++) { for (i = 0; i + (sizeof(u16) * 3) < fw->size;) { value = le16_to_cpu(*(u16 *)(fw->data + i)); i += sizeof(u16); index = le16_to_cpu(*(u16 *)(fw->data + i)); i += sizeof(u16); size = le16_to_cpu(*(u16 *)(fw->data + i)); i += sizeof(u16); if (pass == 1) { /* Will stall if using fw->data ... */ memcpy(buff, fw->data + i, size); ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0), M9206_FW, USB_TYPE_VENDOR | USB_DIR_OUT, value, index, buff, size, 20); if (ret != size) { deb_rc("error while uploading fw!\n"); ret = -EIO; goto done; } msleep(3); } i += size; } if (i != fw->size) { ret = -EINVAL; goto done; } } msleep(36); /* m9206 will disconnect itself from the bus after this. */ (void) m9206_write(udev, M9206_CORE, 0x01, M9206_FW_GO); deb_rc("firmware uploaded!\n"); done: kfree(buff); return ret; }
static int rtl2832u_rc_query(struct dvb_usb_device *d, u32 *event, int *state) { static const RT_rc_set_reg_struct p_flush_table1[]={ {RTD2832U_RC,IR_RX_CTRL ,0x20,OP_NO ,0xff}, {RTD2832U_RC,IR_RX_BUFFER_CTRL ,0x80,OP_NO ,0xff}, {RTD2832U_RC,IR_RX_IF ,0xff,OP_NO ,0xff}, {RTD2832U_RC,IR_RX_IE ,0xff,OP_NO ,0xff}, {RTD2832U_RC,IR_RX_CTRL ,0x80,OP_NO ,0xff} }; static const RT_rc_set_reg_struct p_flush_table2[]={ {RTD2832U_RC,IR_RX_IF ,0x03,OP_NO ,0xff}, {RTD2832U_RC,IR_RX_BUFFER_CTRL ,0x80,OP_NO ,0xff}, {RTD2832U_RC,IR_RX_CTRL ,0x80,OP_NO ,0xff} }; u8 data=0,i=0,byte_count=0,tableSize; int ret=0; u8 rt_u8_code[rt_code_len]; u8 ucode[4]; u16 scancode=0; deb_rc("+%s \n", __FUNCTION__); if (dvb_use_rtl2832u_rc_mode >= MAX_RC_PROTOCOL_NUM) { deb_rc("%s : dvb_use_rtl2832u_rc_mode=%d \n", __FUNCTION__,dvb_use_rtl2832u_rc_mode); return 0; } if(rtl2832u_remote_control_state == RC_NO_SETTING) { deb_rc("%s : IrDA Initial Setting rtl2832u_remote_control_state=%d\n", __FUNCTION__,rtl2832u_remote_control_state); ret=rtl2832u_remoto_control_initial_setting(d); } if ( read_rc_char_bytes( d ,RTD2832U_RC, IR_RX_IF,&data ,LEN_1) ) { ret=-1; deb_rc("%s : Read IrDA IF is failed\n", __FUNCTION__); goto error; } /* debug */ if (data != 0) { deb_rc("%s : IR_RX_IF= 0x%x\n", __FUNCTION__,data); } if (!(data & receiveMaskFlag1)) { ret =0 ; goto error; } if (data & receiveMaskFlag2) { /* delay */ msleep(287); if ( read_rc_char_bytes( d ,RTD2832U_RC,IR_RX_BC,&byte_count ,LEN_1) ) { deb_rc("%s : rc -ir register read error! \n", __FUNCTION__); ret=-1; goto error; } if (byte_count == 0 ) { //ret=0; goto error; } if ((byte_count%LEN_2) == 1) byte_count+=LEN_1; if (byte_count > rt_code_len) byte_count=rt_code_len; memset(rt_u8_code,0,rt_code_len); deb_rc("%s : byte_count= %d type = %d \n", __FUNCTION__,byte_count,dvb_use_rtl2832u_rc_mode); if ( read_rc_char_bytes( d ,RTD2832U_RC,IR_RX_BUF,rt_u8_code ,0x80) ) { deb_rc("%s : rc -ir register read error! \n", __FUNCTION__); ret=-1; goto error; } memset(ucode,0,4); ret=0; if (dvb_use_rtl2832u_rc_mode == 0) ret =frt0(rt_u8_code,byte_count,ucode); else if (dvb_use_rtl2832u_rc_mode == 1) ret =frt1(rt_u8_code,byte_count,ucode); else if (dvb_use_rtl2832u_rc_mode== 2) ret =frt2(rt_u8_code,byte_count,ucode); else { deb_rc("%s : rc - unknow rc protocol set ! \n", __FUNCTION__); ret=-1; goto error; } if((ret != RC_FUNCTION_SUCCESS) || (ucode[0] ==0 && ucode[1] ==0 && ucode[2] ==0 && ucode[3] ==0)) { deb_rc("%s : rc-rc is error scan code ! %x %x %x %x \n", __FUNCTION__,ucode[0],ucode[1],ucode[2],ucode[3]); ret=-1; goto error; } scancode=(ucode[2]<<8) | ucode[3] ; deb_info("-%s scan code %x %x %x %x,(0x%x) -- len=%d\n", __FUNCTION__,ucode[0],ucode[1],ucode[2],ucode[3],scancode,byte_count); ////////// map///////////////////////////////////////////////////////////////////////////////////////////////////// tableSize = ARRAY_SIZE(rtl2832u_rc_keys_map_table); for (i = 0; i < tableSize; i++) { if(rtl2832u_rc_keys_map_table[i].scancode == scancode ){ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0) *event = rtl2832u_rc_keys_map_table[i].keycode; #else *event = rtl2832u_rc_keys_map_table[i].event; #endif *state = REMOTE_KEY_PRESSED; deb_rc("%s : map number = %d \n", __FUNCTION__,i); break; } } if (i == tableSize) deb_rc("%s : rc - scancode 0x%x NOT found!\n", __FUNCTION__, scancode); memset(rt_u8_code,0,rt_code_len); byte_count=0; for (i=0;i<3;i++){ data= p_flush_table2[i].data; if ( write_rc_char_bytes( d ,RTD2832U_RC, p_flush_table2[i].address,&data,LEN_1) ) { deb_rc("+%s : rc -ir register write error! \n", __FUNCTION__); ret=-1; goto error; } } ret =0; return ret; } error: memset(rt_u8_code,0,rt_code_len); byte_count=0; for (i=0;i<flush_step_Number;i++){ data= p_flush_table1[i].data; if ( write_rc_char_bytes( d ,RTD2832U_RC, p_flush_table1[i].address,&data,LEN_1) ) { deb_rc("+%s : rc -ir register write error! \n", __FUNCTION__); ret=-1; break; } } ret =0; //must return 0 return ret; }
/* Remote-control poll function - called every dib->rc_query_interval ms to see * whether the remote control has received anything. * * TODO: Fix the repeat rate of the input device. */ static void dvb_usb_read_remote_control(void *data) { struct dvb_usb_device *d = data; u32 event; int state; /* TODO: need a lock here. We can simply skip checking for the remote control if we're busy. */ /* when the parameter has been set to 1 via sysfs while the driver was running */ if (dvb_usb_disable_rc_polling) return; if (d->props.rc_query(d,&event,&state)) { err("error while querying for an remote control event."); goto schedule; } switch (state) { case REMOTE_NO_KEY_PRESSED: break; case REMOTE_KEY_PRESSED: deb_rc("key pressed\n"); d->last_event = event; case REMOTE_KEY_REPEAT: deb_rc("key repeated\n"); input_event(&d->rc_input_dev, EV_KEY, d->last_event, 1); input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0); input_sync(&d->rc_input_dev); break; default: break; } /* improved repeat handling ??? switch (state) { case REMOTE_NO_KEY_PRESSED: deb_rc("NO KEY PRESSED\n"); if (d->last_state != REMOTE_NO_KEY_PRESSED) { deb_rc("releasing event %d\n",d->last_event); input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0); input_sync(&d->rc_input_dev); } d->last_state = REMOTE_NO_KEY_PRESSED; d->last_event = 0; break; case REMOTE_KEY_PRESSED: deb_rc("KEY PRESSED\n"); deb_rc("pressing event %d\n",event); input_event(&d->rc_input_dev, EV_KEY, event, 1); input_sync(&d->rc_input_dev); d->last_event = event; d->last_state = REMOTE_KEY_PRESSED; break; case REMOTE_KEY_REPEAT: deb_rc("KEY_REPEAT\n"); if (d->last_state != REMOTE_NO_KEY_PRESSED) { deb_rc("repeating event %d\n",d->last_event); input_event(&d->rc_input_dev, EV_KEY, d->last_event, 2); input_sync(&d->rc_input_dev); d->last_state = REMOTE_KEY_REPEAT; } default: break; } */ schedule: schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval)); }