Lines Matching defs:irtoy

11  * https://sourceforge.net/p/lirc/git/ci/master/tree/plugins/irtoy.c
56 struct irtoy {
81 static void irtoy_response(struct irtoy *irtoy, u32 len)
83 switch (irtoy->state) {
85 if (len == LEN_VERSION && irtoy->in[0] == REPLY_VERSION) {
88 irtoy->in[LEN_VERSION] = 0;
90 if (kstrtouint(irtoy->in + 1, 10, &version)) {
91 dev_err(irtoy->dev, "invalid version %*phN. Please make sure you are using firmware v20 or higher",
92 LEN_VERSION, irtoy->in);
96 dev_dbg(irtoy->dev, "version %s\n", irtoy->in);
98 irtoy->hw_version = version / 100;
99 irtoy->sw_version = version % 100;
101 irtoy->state = STATE_IRDATA;
102 complete(&irtoy->command_done);
104 irtoy->in[0] == REPLY_SAMPLEMODEPROTO) {
107 irtoy->in[LEN_SAMPLEMODEPROTO] = 0;
109 if (kstrtouint(irtoy->in + 1, 10, &version)) {
110 dev_err(irtoy->dev, "invalid sample mode response %*phN",
111 LEN_SAMPLEMODEPROTO, irtoy->in);
115 dev_dbg(irtoy->dev, "protocol %s\n", irtoy->in);
117 irtoy->proto_version = version;
119 irtoy->state = STATE_IRDATA;
120 complete(&irtoy->command_done);
122 dev_err(irtoy->dev, "unexpected response to command: %*phN\n",
123 len, irtoy->in);
128 struct ir_raw_event rawir = { .pulse = irtoy->pulse };
129 __be16 *in = (__be16 *)irtoy->in;
139 ir_raw_event_store_with_timeout(irtoy->rc,
146 irtoy->pulse = rawir.pulse;
148 ir_raw_event_handle(irtoy->rc);
152 if (irtoy->tx_len == 0) {
154 irtoy->in[0] == REPLY_XMITCOUNT) {
155 u16 emitted = get_unaligned_be16(irtoy->in + 1);
157 dev_dbg(irtoy->dev, "emitted:%u\n", emitted);
159 irtoy->emitted = emitted;
161 irtoy->in[0] == REPLY_XMITSUCCESS) {
162 irtoy->state = STATE_IRDATA;
163 complete(&irtoy->command_done);
167 uint space = irtoy->in[0];
172 dev_dbg(irtoy->dev, "packet length expected: %*phN\n",
173 len, irtoy->in);
177 buf_len = min(space, irtoy->tx_len);
179 dev_dbg(irtoy->dev, "remaining:%u sending:%u\n",
180 irtoy->tx_len, buf_len);
182 memcpy(irtoy->out, irtoy->tx_buf, buf_len);
183 irtoy->urb_out->transfer_buffer_length = buf_len;
184 err = usb_submit_urb(irtoy->urb_out, GFP_ATOMIC);
186 dev_err(irtoy->dev, "fail to submit tx buf urb: %d\n",
188 irtoy->state = STATE_IRDATA;
189 complete(&irtoy->command_done);
193 irtoy->tx_buf += buf_len;
194 irtoy->tx_len -= buf_len;
202 struct irtoy *irtoy = urb->context;
205 if (irtoy->state == STATE_COMMAND_NO_RESP)
206 complete(&irtoy->command_done);
208 dev_warn(irtoy->dev, "out urb status: %d\n", urb->status);
214 struct irtoy *irtoy = urb->context;
219 irtoy_response(irtoy, urb->actual_length);
229 dev_dbg(irtoy->dev, "in urb status: %d\n", urb->status);
234 dev_warn(irtoy->dev, "failed to resubmit urb: %d\n", ret);
237 static int irtoy_command(struct irtoy *irtoy, const u8 *cmd, int cmd_len,
242 init_completion(&irtoy->command_done);
244 irtoy->state = state;
246 memcpy(irtoy->out, cmd, cmd_len);
247 irtoy->urb_out->transfer_buffer_length = cmd_len;
249 err = usb_submit_urb(irtoy->urb_out, GFP_KERNEL);
253 if (!wait_for_completion_timeout(&irtoy->command_done,
255 usb_kill_urb(irtoy->urb_out);
262 static int irtoy_setup(struct irtoy *irtoy)
266 err = irtoy_command(irtoy, COMMAND_RESET, sizeof(COMMAND_RESET),
269 dev_err(irtoy->dev, "could not write reset command: %d\n",
277 err = irtoy_command(irtoy, COMMAND_VERSION, sizeof(COMMAND_VERSION),
280 dev_err(irtoy->dev, "could not write version command: %d\n",
286 err = irtoy_command(irtoy, COMMAND_SMODE_ENTER,
289 dev_err(irtoy->dev, "could not write sample command: %d\n",
303 struct irtoy *irtoy = rc->priv;
323 irtoy->tx_buf = buf;
324 irtoy->tx_len = size;
325 irtoy->emitted = 0;
331 err = irtoy_command(irtoy, COMMAND_SMODE_EXIT,
334 dev_err(irtoy->dev, "exit sample mode: %d\n", err);
339 err = irtoy_command(irtoy, COMMAND_SMODE_ENTER,
342 dev_err(irtoy->dev, "enter sample mode: %d\n", err);
347 err = irtoy_command(irtoy, COMMAND_TXSTART, sizeof(COMMAND_TXSTART),
352 dev_err(irtoy->dev, "failed to send tx start command: %d\n",
355 irtoy_setup(irtoy);
359 if (size != irtoy->emitted) {
360 dev_err(irtoy->dev, "expected %u emitted, got %u\n", size,
361 irtoy->emitted);
363 irtoy_setup(irtoy);
372 struct irtoy *irtoy = rc->priv;
383 err = irtoy_command(irtoy, buf, sizeof(buf), STATE_COMMAND_NO_RESP);
385 dev_err(irtoy->dev, "could not write carrier command: %d\n",
399 struct irtoy *irtoy;
421 irtoy = kzalloc(sizeof(*irtoy), GFP_KERNEL);
422 if (!irtoy)
425 irtoy->in = kmalloc(MAX_PACKET, GFP_KERNEL);
426 if (!irtoy->in)
429 irtoy->out = kmalloc(MAX_PACKET, GFP_KERNEL);
430 if (!irtoy->out)
442 usb_fill_bulk_urb(urb, usbdev, pipe, irtoy->in, MAX_PACKET,
443 irtoy_in_callback, irtoy);
444 irtoy->urb_in = urb;
451 usb_fill_bulk_urb(urb, usbdev, pipe, irtoy->out, MAX_PACKET,
452 irtoy_out_callback, irtoy);
454 irtoy->dev = &intf->dev;
455 irtoy->usbdev = usbdev;
456 irtoy->rc = rc;
457 irtoy->urb_out = urb;
458 irtoy->pulse = true;
460 err = usb_submit_urb(irtoy->urb_in, GFP_KERNEL);
462 dev_err(irtoy->dev, "fail to submit in urb: %d\n", err);
466 err = irtoy_setup(irtoy);
470 dev_info(irtoy->dev, "version: hardware %u, firmware %u.%u, protocol %u",
471 irtoy->hw_version, irtoy->sw_version / 10,
472 irtoy->sw_version % 10, irtoy->proto_version);
474 if (irtoy->sw_version < MIN_FW_VERSION) {
475 dev_err(irtoy->dev, "need firmware V%02u or higher",
481 usb_make_path(usbdev, irtoy->phys, sizeof(irtoy->phys));
485 rc->input_phys = irtoy->phys;
488 rc->priv = irtoy;
512 usb_set_intfdata(intf, irtoy);
517 usb_kill_urb(irtoy->urb_out);
518 usb_free_urb(irtoy->urb_out);
519 usb_kill_urb(irtoy->urb_in);
520 usb_free_urb(irtoy->urb_in);
523 kfree(irtoy->in);
524 kfree(irtoy->out);
525 kfree(irtoy);
531 struct irtoy *ir = usb_get_intfdata(intf);