Lines Matching defs:irtoy

9  * https://sourceforge.net/p/lirc/git/ci/master/tree/plugins/irtoy.c
54 struct irtoy {
79 static void irtoy_response(struct irtoy *irtoy, u32 len)
81 switch (irtoy->state) {
83 if (len == LEN_VERSION && irtoy->in[0] == REPLY_VERSION) {
86 irtoy->in[LEN_VERSION] = 0;
88 if (kstrtouint(irtoy->in + 1, 10, &version)) {
89 dev_err(irtoy->dev, "invalid version %*phN. Please make sure you are using firmware v20 or higher",
90 LEN_VERSION, irtoy->in);
94 dev_dbg(irtoy->dev, "version %s\n", irtoy->in);
96 irtoy->hw_version = version / 100;
97 irtoy->sw_version = version % 100;
99 irtoy->state = STATE_IRDATA;
100 complete(&irtoy->command_done);
102 irtoy->in[0] == REPLY_SAMPLEMODEPROTO) {
105 irtoy->in[LEN_SAMPLEMODEPROTO] = 0;
107 if (kstrtouint(irtoy->in + 1, 10, &version)) {
108 dev_err(irtoy->dev, "invalid sample mode response %*phN",
109 LEN_SAMPLEMODEPROTO, irtoy->in);
113 dev_dbg(irtoy->dev, "protocol %s\n", irtoy->in);
115 irtoy->proto_version = version;
117 irtoy->state = STATE_IRDATA;
118 complete(&irtoy->command_done);
120 dev_err(irtoy->dev, "unexpected response to command: %*phN\n",
121 len, irtoy->in);
125 struct ir_raw_event rawir = { .pulse = irtoy->pulse };
126 __be16 *in = (__be16 *)irtoy->in;
136 ir_raw_event_store_with_timeout(irtoy->rc,
143 irtoy->pulse = rawir.pulse;
145 ir_raw_event_handle(irtoy->rc);
149 if (irtoy->tx_len == 0) {
151 irtoy->in[0] == REPLY_XMITCOUNT) {
152 u16 emitted = get_unaligned_be16(irtoy->in + 1);
154 dev_dbg(irtoy->dev, "emitted:%u\n", emitted);
156 irtoy->emitted = emitted;
158 irtoy->in[0] == REPLY_XMITSUCCESS) {
159 irtoy->state = STATE_IRDATA;
160 complete(&irtoy->command_done);
164 uint space = irtoy->in[0];
169 dev_err(irtoy->dev, "packet length expected: %*phN\n",
170 len, irtoy->in);
171 irtoy->state = STATE_IRDATA;
172 complete(&irtoy->command_done);
176 buf_len = min(space, irtoy->tx_len);
178 dev_dbg(irtoy->dev, "remaining:%u sending:%u\n",
179 irtoy->tx_len, buf_len);
181 memcpy(irtoy->out, irtoy->tx_buf, buf_len);
182 irtoy->urb_out->transfer_buffer_length = buf_len;
183 err = usb_submit_urb(irtoy->urb_out, GFP_ATOMIC);
185 dev_err(irtoy->dev, "fail to submit tx buf urb: %d\n",
187 irtoy->state = STATE_IRDATA;
188 complete(&irtoy->command_done);
192 irtoy->tx_buf += buf_len;
193 irtoy->tx_len -= buf_len;
197 dev_err(irtoy->dev, "unexpected response to reset: %*phN\n",
198 len, irtoy->in);
204 struct irtoy *irtoy = urb->context;
207 if (irtoy->state == STATE_RESET)
208 complete(&irtoy->command_done);
210 dev_warn(irtoy->dev, "out urb status: %d\n", urb->status);
216 struct irtoy *irtoy = urb->context;
220 irtoy_response(irtoy, urb->actual_length);
222 dev_dbg(irtoy->dev, "in urb status: %d\n", urb->status);
226 dev_warn(irtoy->dev, "failed to resubmit urb: %d\n", ret);
229 static int irtoy_command(struct irtoy *irtoy, const u8 *cmd, int cmd_len,
234 init_completion(&irtoy->command_done);
236 irtoy->state = state;
238 memcpy(irtoy->out, cmd, cmd_len);
239 irtoy->urb_out->transfer_buffer_length = cmd_len;
241 err = usb_submit_urb(irtoy->urb_out, GFP_KERNEL);
245 if (!wait_for_completion_timeout(&irtoy->command_done,
247 usb_kill_urb(irtoy->urb_out);
254 static int irtoy_setup(struct irtoy *irtoy)
258 err = irtoy_command(irtoy, COMMAND_RESET, sizeof(COMMAND_RESET),
261 dev_err(irtoy->dev, "could not write reset command: %d\n",
269 err = irtoy_command(irtoy, COMMAND_VERSION, sizeof(COMMAND_VERSION),
272 dev_err(irtoy->dev, "could not write version command: %d\n",
278 err = irtoy_command(irtoy, COMMAND_SMODE_ENTER,
281 dev_err(irtoy->dev, "could not write sample command: %d\n",
295 struct irtoy *irtoy = rc->priv;
315 irtoy->tx_buf = buf;
316 irtoy->tx_len = size;
317 irtoy->emitted = 0;
323 err = irtoy_command(irtoy, COMMAND_SMODE_EXIT,
326 dev_err(irtoy->dev, "exit sample mode: %d\n", err);
331 err = irtoy_command(irtoy, COMMAND_SMODE_ENTER,
334 dev_err(irtoy->dev, "enter sample mode: %d\n", err);
339 err = irtoy_command(irtoy, COMMAND_TXSTART, sizeof(COMMAND_TXSTART),
344 dev_err(irtoy->dev, "failed to send tx start command: %d\n",
347 irtoy_setup(irtoy);
351 if (size != irtoy->emitted) {
352 dev_err(irtoy->dev, "expected %u emitted, got %u\n", size,
353 irtoy->emitted);
355 irtoy_setup(irtoy);
370 struct irtoy *irtoy;
392 irtoy = kzalloc(sizeof(*irtoy), GFP_KERNEL);
393 if (!irtoy)
396 irtoy->in = kmalloc(MAX_PACKET, GFP_KERNEL);
397 if (!irtoy->in)
400 irtoy->out = kmalloc(MAX_PACKET, GFP_KERNEL);
401 if (!irtoy->out)
413 usb_fill_bulk_urb(urb, usbdev, pipe, irtoy->in, MAX_PACKET,
414 irtoy_in_callback, irtoy);
415 irtoy->urb_in = urb;
422 usb_fill_bulk_urb(urb, usbdev, pipe, irtoy->out, MAX_PACKET,
423 irtoy_out_callback, irtoy);
425 irtoy->dev = &intf->dev;
426 irtoy->usbdev = usbdev;
427 irtoy->rc = rc;
428 irtoy->urb_out = urb;
429 irtoy->pulse = true;
431 err = usb_submit_urb(irtoy->urb_in, GFP_KERNEL);
433 dev_err(irtoy->dev, "fail to submit in urb: %d\n", err);
437 err = irtoy_setup(irtoy);
441 dev_info(irtoy->dev, "version: hardware %u, firmware %u, protocol %u",
442 irtoy->hw_version, irtoy->sw_version, irtoy->proto_version);
444 if (irtoy->sw_version < MIN_FW_VERSION) {
445 dev_err(irtoy->dev, "need firmware V%02u or higher",
451 usb_make_path(usbdev, irtoy->phys, sizeof(irtoy->phys));
455 rc->input_phys = irtoy->phys;
458 rc->priv = irtoy;
481 usb_set_intfdata(intf, irtoy);
486 usb_kill_urb(irtoy->urb_out);
487 usb_free_urb(irtoy->urb_out);
488 usb_kill_urb(irtoy->urb_in);
489 usb_free_urb(irtoy->urb_in);
492 kfree(irtoy->in);
493 kfree(irtoy->out);
494 kfree(irtoy);
500 struct irtoy *ir = usb_get_intfdata(intf);