Example #1
0
int sms_ir_init(struct smscore_device_t *coredev)
{
	struct input_dev *input_dev;
	int board_id = smscore_get_board_id(coredev);

	sms_log("Allocating input device");
	input_dev = input_allocate_device();
	if (!input_dev)	{
		sms_err("Not enough memory");
		return -ENOMEM;
	}

	coredev->ir.input_dev = input_dev;

	coredev->ir.controller = 0;	/* Todo: vega/nova SPI number */
	coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
	sms_log("IR port %d, timeout %d ms",
			coredev->ir.controller, coredev->ir.timeout);

	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
		 "SMS IR (%s)", sms_get_board(board_id)->name);

	strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));

	input_dev->name = coredev->ir.name;
	input_dev->phys = coredev->ir.phys;
	input_dev->dev.parent = coredev->device;


	coredev->ir.props.priv = coredev;
	coredev->ir.props.driver_type = RC_DRIVER_IR_RAW;
	coredev->ir.props.allowed_protos = IR_TYPE_ALL;

	sms_log("Input device (IR) %s is set for key events", input_dev->name);

	if (ir_input_register(input_dev, sms_get_board(board_id)->rc_codes,
			      &coredev->ir.props, MODULE_NAME)) {
		sms_err("Failed to register device");
		input_free_device(input_dev);
		return -EACCES;
	}

	return 0;
}
int cx231xx_ir_init(struct cx231xx *dev)
{
	struct cx231xx_IR *ir;
	struct input_dev *input_dev;
	u8 ir_config;
	int err = -ENOMEM;

	if (dev->board.ir_codes == NULL) {
		/* No remote control support */
		return 0;
	}

	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!ir || !input_dev)
		goto err_out_free;

	ir->input = input_dev;

	/* Setup the proper handler based on the chip */
	switch (dev->chip_id) {
	default:
		printk("Unrecognized cx231xx chip id: IR not supported\n");
		goto err_out_free;
	}

	/* This is how often we ask the chip for IR information */
	ir->polling = 100;	/* ms */

	/* init input device */
	snprintf(ir->name, sizeof(ir->name), "cx231xx IR (%s)", dev->name);

	usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
	strlcat(ir->phys, "/input0", sizeof(ir->phys));

	err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER);
	if (err < 0)
		goto err_out_free;

	input_dev->name = ir->name;
	input_dev->phys = ir->phys;
	input_dev->id.bustype = BUS_USB;
	input_dev->id.version = 1;
	input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
	input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);

	input_dev->dev.parent = &dev->udev->dev;
	/* record handles to ourself */
	ir->dev = dev;
	dev->ir = ir;

	cx231xx_ir_start(ir);

	/* all done */
	err = ir_input_register(ir->input, dev->board.ir_codes);
	if (err)
		goto err_out_stop;

	return 0;
err_out_stop:
	cx231xx_ir_stop(ir);
	dev->ir = NULL;
err_out_free:
	kfree(ir);
	return err;
}
Example #3
0
int cx23885_input_init(struct cx23885_dev *dev)
{
	struct cx23885_kernel_ir *kernel_ir;
	struct input_dev *inp_dev;
	struct ir_dev_props *props;

	char *rc_map;
	enum rc_driver_type driver_type;
	unsigned long allowed_protos;

	int ret;

	/*
	 * If the IR device (hardware registers, chip, GPIO lines, etc.) isn't
	 * encapsulated in a v4l2_subdev, then I'm not going to deal with it.
	 */
	if (dev->sd_ir == NULL)
		return -ENODEV;

	switch (dev->board) {
	case CX23885_BOARD_HAUPPAUGE_HVR1850:
	case CX23885_BOARD_HAUPPAUGE_HVR1290:
	case CX23885_BOARD_HAUPPAUGE_HVR1250:
		/* Integrated CX2388[58] IR controller */
		driver_type = RC_DRIVER_IR_RAW;
		allowed_protos = IR_TYPE_ALL;
		/* The grey Hauppauge RC-5 remote */
		rc_map = RC_MAP_RC5_HAUPPAUGE_NEW;
		break;
	case CX23885_BOARD_TEVII_S470:
		/* Integrated CX23885 IR controller */
		driver_type = RC_DRIVER_IR_RAW;
		allowed_protos = IR_TYPE_ALL;
		/* A guess at the remote */
		rc_map = RC_MAP_TEVII_NEC;
		break;
	default:
		return -ENODEV;
	}

	/* cx23885 board instance kernel IR state */
	kernel_ir = kzalloc(sizeof(struct cx23885_kernel_ir), GFP_KERNEL);
	if (kernel_ir == NULL)
		return -ENOMEM;

	kernel_ir->cx = dev;
	kernel_ir->name = kasprintf(GFP_KERNEL, "cx23885 IR (%s)",
				    cx23885_boards[dev->board].name);
	kernel_ir->phys = kasprintf(GFP_KERNEL, "pci-%s/ir0",
				    pci_name(dev->pci));

	/* input device */
	inp_dev = input_allocate_device();
	if (inp_dev == NULL) {
		ret = -ENOMEM;
		goto err_out_free;
	}

	kernel_ir->inp_dev = inp_dev;
	inp_dev->name = kernel_ir->name;
	inp_dev->phys = kernel_ir->phys;
	inp_dev->id.bustype = BUS_PCI;
	inp_dev->id.version = 1;
	if (dev->pci->subsystem_vendor) {
		inp_dev->id.vendor  = dev->pci->subsystem_vendor;
		inp_dev->id.product = dev->pci->subsystem_device;
	} else {
		inp_dev->id.vendor  = dev->pci->vendor;
		inp_dev->id.product = dev->pci->device;
	}
	inp_dev->dev.parent = &dev->pci->dev;

	/* kernel ir device properties */
	props = &kernel_ir->props;
	props->driver_type = driver_type;
	props->allowed_protos = allowed_protos;
	props->priv = kernel_ir;
	props->open = cx23885_input_ir_open;
	props->close = cx23885_input_ir_close;

	/* Go */
	dev->kernel_ir = kernel_ir;
	ret = ir_input_register(inp_dev, rc_map, props, MODULE_NAME);
	if (ret)
		goto err_out_stop;

	return 0;

err_out_stop:
	cx23885_input_ir_stop(dev);
	dev->kernel_ir = NULL;
	/* TODO: double check clean-up of kernel_ir->inp_dev */
err_out_free:
	kfree(kernel_ir->phys);
	kfree(kernel_ir->name);
	kfree(kernel_ir);
	return ret;
}
Example #4
0
int tm6000_ir_init(struct tm6000_core *dev)
{
	struct tm6000_IR *ir;
	struct ir_input_dev *ir_input_dev;
	int err = -ENOMEM;
	int pipe, size, rc;

	if (!enable_ir)
		return -ENODEV;

	if (!dev->caps.has_remote)
		return 0;

	if (!dev->ir_codes)
		return 0;

	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
	ir_input_dev = kzalloc(sizeof(*ir_input_dev), GFP_KERNEL);
	ir_input_dev->input_dev = input_allocate_device();
	if (!ir || !ir_input_dev || !ir_input_dev->input_dev)
		goto err_out_free;

	/* record handles to ourself */
	ir->dev = dev;
	dev->ir = ir;

	ir->input = ir_input_dev;

	/* input einrichten */
	ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
	ir->props.priv = ir;
	ir->props.change_protocol = tm6000_ir_change_protocol;
	ir->props.open = tm6000_ir_start;
	ir->props.close = tm6000_ir_stop;
	ir->props.driver_type = RC_DRIVER_SCANCODE;

	ir->polling = 50;

	snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)",
						dev->name);

	usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
	strlcat(ir->phys, "/input0", sizeof(ir->phys));

	tm6000_ir_change_protocol(ir, IR_TYPE_UNKNOWN);
	err = ir_input_init(ir_input_dev->input_dev, &ir->ir, IR_TYPE_OTHER);
	if (err < 0)
		goto err_out_free;

	ir_input_dev->input_dev->name = ir->name;
	ir_input_dev->input_dev->phys = ir->phys;
	ir_input_dev->input_dev->id.bustype = BUS_USB;
	ir_input_dev->input_dev->id.version = 1;
	ir_input_dev->input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
	ir_input_dev->input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);

	ir_input_dev->input_dev->dev.parent = &dev->udev->dev;

	if (&dev->int_in) {
		dprintk("IR over int\n");

		ir->int_urb = usb_alloc_urb(0, GFP_KERNEL);

		pipe = usb_rcvintpipe(dev->udev,
			dev->int_in.endp->desc.bEndpointAddress
			& USB_ENDPOINT_NUMBER_MASK);

		size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
		dprintk("IR max size: %d\n", size);

		ir->int_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
		if (ir->int_urb->transfer_buffer == NULL) {
			usb_free_urb(ir->int_urb);
			goto err_out_stop;
		}
		dprintk("int interval: %d\n", dev->int_in.endp->desc.bInterval);
		usb_fill_int_urb(ir->int_urb, dev->udev, pipe,
			ir->int_urb->transfer_buffer, size,
			tm6000_ir_urb_received, dev,
			dev->int_in.endp->desc.bInterval);
		rc = usb_submit_urb(ir->int_urb, GFP_KERNEL);
		if (rc) {
			kfree(ir->int_urb->transfer_buffer);
			usb_free_urb(ir->int_urb);
			err = rc;
			goto err_out_stop;
		}
		ir->urb_data = kzalloc(size, GFP_KERNEL);
	}

	/* ir register */
	err = ir_input_register(ir->input->input_dev, dev->ir_codes,
		&ir->props, "tm6000");
	if (err)
		goto err_out_stop;

	return 0;

err_out_stop:
	dev->ir = NULL;
err_out_free:
	kfree(ir_input_dev);
	kfree(ir);
	return err;
}
int cx23885_input_init(struct cx23885_dev *dev)
{
	struct card_ir *ir;
	struct input_dev *input_dev;
	struct ir_scancode_table *ir_codes = NULL;
	int ir_type, ir_addr, ir_start;
	int ret;

	/*
	 * If the IR device (hardware registers, chip, GPIO lines, etc.) isn't
	 * encapsulated in a v4l2_subdev, then I'm not going to deal with it.
	 */
	if (dev->sd_ir == NULL)
		return -ENODEV;

	switch (dev->board) {
	case CX23885_BOARD_HAUPPAUGE_HVR1850:
	case CX23885_BOARD_HAUPPAUGE_HVR1290:
		/* Parameters for the grey Hauppauge remote for the HVR-1850 */
		ir_codes = &ir_codes_hauppauge_new_table;
		ir_type = IR_TYPE_RC5;
		ir_addr = 0x1e; /* RC-5 system bits emitted by the remote */
		ir_start = RC5_START_BITS_NORMAL; /* A basic RC-5 remote */
		break;
	}
	if (ir_codes == NULL)
		return -ENODEV;

	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!ir || !input_dev) {
		ret = -ENOMEM;
		goto err_out_free;
	}

	ir->dev = input_dev;
	ir->addr = ir_addr;
	ir->start = ir_start;

	/* init input device */
	snprintf(ir->name, sizeof(ir->name), "cx23885 IR (%s)",
		 cx23885_boards[dev->board].name);
	snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(dev->pci));

	ret = ir_input_init(input_dev, &ir->ir, ir_type);
	if (ret < 0)
		goto err_out_free;

	input_dev->name = ir->name;
	input_dev->phys = ir->phys;
	input_dev->id.bustype = BUS_PCI;
	input_dev->id.version = 1;
	if (dev->pci->subsystem_vendor) {
		input_dev->id.vendor  = dev->pci->subsystem_vendor;
		input_dev->id.product = dev->pci->subsystem_device;
	} else {
		input_dev->id.vendor  = dev->pci->vendor;
		input_dev->id.product = dev->pci->device;
	}
	input_dev->dev.parent = &dev->pci->dev;

	dev->ir_input = ir;
	cx23885_input_ir_start(dev);

	ret = ir_input_register(ir->dev, ir_codes, NULL);
	if (ret)
		goto err_out_stop;

	return 0;

err_out_stop:
	cx23885_input_ir_stop(dev);
	dev->ir_input = NULL;
err_out_free:
	kfree(ir);
	return ret;
}
int em28xx_ir_init(struct em28xx *dev)
{
	struct em28xx_IR *ir;
	struct input_dev *input_dev;
	u8 ir_config;
	int err = -ENOMEM;

	if (dev->board.ir_codes == NULL) {
		/* No remote control support */
		return 0;
	}

	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!ir || !input_dev)
		goto err_out_free;

	ir->input = input_dev;
	ir_config = EM2874_IR_RC5;

	/* Adjust xclk based o IR table for RC5/NEC tables */
	if (dev->board.ir_codes->ir_type == IR_TYPE_RC5) {
		dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
		ir->full_code = 1;
	} else  if (dev->board.ir_codes->ir_type == IR_TYPE_NEC) {
		dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
		ir_config = EM2874_IR_NEC;
		ir->full_code = 1;
	}
	em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
			      EM28XX_XCLK_IR_RC5_MODE);

	/* Setup the proper handler based on the chip */
	switch (dev->chip_id) {
	case CHIP_ID_EM2860:
	case CHIP_ID_EM2883:
		ir->get_key = default_polling_getkey;
		break;
	case CHIP_ID_EM2874:
		ir->get_key = em2874_polling_getkey;
		em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
		break;
	default:
		printk("Unrecognized em28xx chip id: IR not supported\n");
		goto err_out_free;
	}

	/* This is how often we ask the chip for IR information */
	ir->polling = 100; /* ms */

	/* init input device */
	snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)",
						dev->name);

	usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
	strlcat(ir->phys, "/input0", sizeof(ir->phys));

	err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER);
	if (err < 0)
		goto err_out_free;

	input_dev->name = ir->name;
	input_dev->phys = ir->phys;
	input_dev->id.bustype = BUS_USB;
	input_dev->id.version = 1;
	input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
	input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);

	input_dev->dev.parent = &dev->udev->dev;
	/* record handles to ourself */
	ir->dev = dev;
	dev->ir = ir;

	em28xx_ir_start(ir);

	/* all done */
	err = ir_input_register(ir->input, dev->board.ir_codes);
	if (err)
		goto err_out_stop;

	return 0;
 err_out_stop:
	em28xx_ir_stop(ir);
	dev->ir = NULL;
 err_out_free:
	kfree(ir);
	return err;
}