irtoy
irtoy->state = STATE_IRDATA;
complete(&irtoy->command_done);
irtoy->in[0] == REPLY_SAMPLEMODEPROTO) {
irtoy->in[LEN_SAMPLEMODEPROTO] = 0;
if (kstrtouint(irtoy->in + 1, 10, &version)) {
dev_err(irtoy->dev, "invalid sample mode response %*phN",
LEN_SAMPLEMODEPROTO, irtoy->in);
dev_dbg(irtoy->dev, "protocol %s\n", irtoy->in);
irtoy->proto_version = version;
irtoy->state = STATE_IRDATA;
complete(&irtoy->command_done);
dev_err(irtoy->dev, "unexpected response to command: %*phN\n",
len, irtoy->in);
struct ir_raw_event rawir = { .pulse = irtoy->pulse };
__be16 *in = (__be16 *)irtoy->in;
ir_raw_event_store_with_timeout(irtoy->rc,
irtoy->pulse = rawir.pulse;
ir_raw_event_handle(irtoy->rc);
if (irtoy->tx_len == 0) {
irtoy->in[0] == REPLY_XMITCOUNT) {
u16 emitted = get_unaligned_be16(irtoy->in + 1);
dev_dbg(irtoy->dev, "emitted:%u\n", emitted);
irtoy->emitted = emitted;
irtoy->in[0] == REPLY_XMITSUCCESS) {
irtoy->state = STATE_IRDATA;
complete(&irtoy->command_done);
uint space = irtoy->in[0];
dev_dbg(irtoy->dev, "packet length expected: %*phN\n",
len, irtoy->in);
buf_len = min(space, irtoy->tx_len);
dev_dbg(irtoy->dev, "remaining:%u sending:%u\n",
irtoy->tx_len, buf_len);
memcpy(irtoy->out, irtoy->tx_buf, buf_len);
irtoy->urb_out->transfer_buffer_length = buf_len;
err = usb_submit_urb(irtoy->urb_out, GFP_ATOMIC);
dev_err(irtoy->dev, "fail to submit tx buf urb: %d\n",
irtoy->state = STATE_IRDATA;
complete(&irtoy->command_done);
irtoy->tx_buf += buf_len;
irtoy->tx_len -= buf_len;
struct irtoy *irtoy = urb->context;
if (irtoy->state == STATE_COMMAND_NO_RESP)
complete(&irtoy->command_done);
dev_warn(irtoy->dev, "out urb status: %d\n", urb->status);
struct irtoy *irtoy = urb->context;
irtoy_response(irtoy, urb->actual_length);
dev_dbg(irtoy->dev, "in urb status: %d\n", urb->status);
dev_warn(irtoy->dev, "failed to resubmit urb: %d\n", ret);
static int irtoy_command(struct irtoy *irtoy, const u8 *cmd, int cmd_len,
init_completion(&irtoy->command_done);
irtoy->state = state;
memcpy(irtoy->out, cmd, cmd_len);
irtoy->urb_out->transfer_buffer_length = cmd_len;
err = usb_submit_urb(irtoy->urb_out, GFP_KERNEL);
if (!wait_for_completion_timeout(&irtoy->command_done,
usb_kill_urb(irtoy->urb_out);
static int irtoy_setup(struct irtoy *irtoy)
err = irtoy_command(irtoy, COMMAND_RESET, sizeof(COMMAND_RESET),
dev_err(irtoy->dev, "could not write reset command: %d\n",
err = irtoy_command(irtoy, COMMAND_VERSION, sizeof(COMMAND_VERSION),
dev_err(irtoy->dev, "could not write version command: %d\n",
err = irtoy_command(irtoy, COMMAND_SMODE_ENTER,
dev_err(irtoy->dev, "could not write sample command: %d\n",
struct irtoy *irtoy = rc->priv;
irtoy->tx_buf = buf;
irtoy->tx_len = size;
irtoy->emitted = 0;
err = irtoy_command(irtoy, COMMAND_SMODE_EXIT,
dev_err(irtoy->dev, "exit sample mode: %d\n", err);
err = irtoy_command(irtoy, COMMAND_SMODE_ENTER,
dev_err(irtoy->dev, "enter sample mode: %d\n", err);
err = irtoy_command(irtoy, COMMAND_TXSTART, sizeof(COMMAND_TXSTART),
dev_err(irtoy->dev, "failed to send tx start command: %d\n",
irtoy_setup(irtoy);
if (size != irtoy->emitted) {
dev_err(irtoy->dev, "expected %u emitted, got %u\n", size,
irtoy->emitted);
irtoy_setup(irtoy);
struct irtoy *irtoy = rc->priv;
err = irtoy_command(irtoy, buf, sizeof(buf), STATE_COMMAND_NO_RESP);
dev_err(irtoy->dev, "could not write carrier command: %d\n",
struct irtoy *irtoy;
irtoy = kzalloc_obj(*irtoy);
if (!irtoy)
irtoy->in = kmalloc(MAX_PACKET, GFP_KERNEL);
if (!irtoy->in)
irtoy->out = kmalloc(MAX_PACKET, GFP_KERNEL);
if (!irtoy->out)
usb_fill_bulk_urb(urb, usbdev, pipe, irtoy->in, MAX_PACKET,
irtoy_in_callback, irtoy);
irtoy->urb_in = urb;
usb_fill_bulk_urb(urb, usbdev, pipe, irtoy->out, MAX_PACKET,
irtoy_out_callback, irtoy);
irtoy->dev = &intf->dev;
irtoy->usbdev = usbdev;
irtoy->rc = rc;
irtoy->urb_out = urb;
irtoy->pulse = true;
err = usb_submit_urb(irtoy->urb_in, GFP_KERNEL);
dev_err(irtoy->dev, "fail to submit in urb: %d\n", err);
err = irtoy_setup(irtoy);
dev_info(irtoy->dev, "version: hardware %u, firmware %u.%u, protocol %u",
irtoy->hw_version, irtoy->sw_version / 10,
irtoy->sw_version % 10, irtoy->proto_version);
if (irtoy->sw_version < MIN_FW_VERSION) {
dev_err(irtoy->dev, "need firmware V%02u or higher",
usb_make_path(usbdev, irtoy->phys, sizeof(irtoy->phys));
rc->input_phys = irtoy->phys;
rc->priv = irtoy;
usb_set_intfdata(intf, irtoy);
usb_kill_urb(irtoy->urb_out);
usb_free_urb(irtoy->urb_out);
usb_kill_urb(irtoy->urb_in);
usb_free_urb(irtoy->urb_in);
kfree(irtoy->in);
kfree(irtoy->out);
kfree(irtoy);
struct irtoy *ir = usb_get_intfdata(intf);
static void irtoy_response(struct irtoy *irtoy, u32 len)
switch (irtoy->state) {
if (len == LEN_VERSION && irtoy->in[0] == REPLY_VERSION) {
irtoy->in[LEN_VERSION] = 0;
if (kstrtouint(irtoy->in + 1, 10, &version)) {
dev_err(irtoy->dev, "invalid version %*phN. Please make sure you are using firmware v20 or higher",
LEN_VERSION, irtoy->in);
dev_dbg(irtoy->dev, "version %s\n", irtoy->in);
irtoy->hw_version = version / 100;
irtoy->sw_version = version % 100;