Lines Matching +full:rc +full:- +full:rc6 +full:- +full:mce
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org>
23 * - drivers/char/pctv_zilogir.[ch] from Hauppauge Broadway product
25 * - drivers/staging/media/lirc/lirc_zilog.c
26 * Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
50 #include <media/rc-core.h>
51 #include <media/i2c/ir-kbd-i2c.h>
66 if (size != i2c_master_recv(ir->c, buf, size)) in get_key_haup_common()
67 return -EIO; in get_key_haup_common()
82 * 1 = 0-63, 0 = 64 - 127 in get_key_haup_common()
96 dev_dbg(&ir->rc->dev, in get_key_haup_common()
114 dev_dbg(&ir->rc->dev, in get_key_haup_common()
115 "ir hauppauge (rc6-mce): t%d vendor=%d dev=%d code=%d\n", in get_key_haup_common()
120 dev_dbg(&ir->rc->dev, in get_key_haup_common()
121 "ir hauppauge (rc6-6a-32): vendor=%d dev=%d code=%d\n", in get_key_haup_common()
151 ret = i2c_master_send(ir->c, buf, 1); in get_key_haup_xvr()
153 return (ret < 0) ? ret : -EINVAL; in get_key_haup_xvr()
161 int rc; in get_key_pixelview() local
165 rc = i2c_master_recv(ir->c, &b, 1); in get_key_pixelview()
166 if (rc != 1) { in get_key_pixelview()
167 dev_dbg(&ir->rc->dev, "read error\n"); in get_key_pixelview()
168 if (rc < 0) in get_key_pixelview()
169 return rc; in get_key_pixelview()
170 return -EIO; in get_key_pixelview()
182 int rc; in get_key_fusionhdtv() local
186 rc = i2c_master_recv(ir->c, buf, 4); in get_key_fusionhdtv()
187 if (rc != 4) { in get_key_fusionhdtv()
188 dev_dbg(&ir->rc->dev, "read error\n"); in get_key_fusionhdtv()
189 if (rc < 0) in get_key_fusionhdtv()
190 return rc; in get_key_fusionhdtv()
191 return -EIO; in get_key_fusionhdtv()
195 dev_dbg(&ir->rc->dev, "%s: %*ph\n", __func__, 4, buf); in get_key_fusionhdtv()
210 int rc; in get_key_knc1() local
214 rc = i2c_master_recv(ir->c, &b, 1); in get_key_knc1()
215 if (rc != 1) { in get_key_knc1()
216 dev_dbg(&ir->rc->dev, "read error\n"); in get_key_knc1()
217 if (rc < 0) in get_key_knc1()
218 return rc; in get_key_knc1()
219 return -EIO; in get_key_knc1()
226 dev_dbg(&ir->rc->dev, "key %02x\n", b); in get_key_knc1()
244 int i, rc; in get_key_geniatech() local
249 rc = i2c_master_recv(ir->c, &b, 1); in get_key_geniatech()
250 if (rc == 1) in get_key_geniatech()
254 if (rc != 1) { in get_key_geniatech()
255 dev_dbg(&ir->rc->dev, "read error\n"); in get_key_geniatech()
256 if (rc < 0) in get_key_geniatech()
257 return rc; in get_key_geniatech()
258 return -EIO; in get_key_geniatech()
262 if (ir->old == b) in get_key_geniatech()
264 ir->old = b; in get_key_geniatech()
268 b = (b - 1) / 2; in get_key_geniatech()
270 dev_dbg(&ir->rc->dev, "key %02x\n", b); in get_key_geniatech()
274 *toggle = ir->old >> 7; in get_key_geniatech()
282 struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0, in get_key_avermedia_cardbus()
284 { .addr = ir->c->addr, .flags = I2C_M_RD, in get_key_avermedia_cardbus()
287 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { in get_key_avermedia_cardbus()
288 dev_dbg(&ir->rc->dev, "read error\n"); in get_key_avermedia_cardbus()
289 return -EIO; in get_key_avermedia_cardbus()
297 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { in get_key_avermedia_cardbus()
298 dev_dbg(&ir->rc->dev, "read error\n"); in get_key_avermedia_cardbus()
299 return -EIO; in get_key_avermedia_cardbus()
305 dev_dbg(&ir->rc->dev, "read key 0x%02x/0x%02x\n", key, keygroup); in get_key_avermedia_cardbus()
307 dev_warn(&ir->rc->dev, "warning: invalid key group 0x%02x for key 0x%02x\n", in get_key_avermedia_cardbus()
314 if (ir->c->addr == 0x41) /* AVerMedia EM78P153 */ in get_key_avermedia_cardbus()
320 /* ----------------------------------------------------------------------- */
327 int rc; in ir_key_poll() local
329 dev_dbg(&ir->rc->dev, "%s\n", __func__); in ir_key_poll()
330 rc = ir->get_key(ir, &protocol, &scancode, &toggle); in ir_key_poll()
331 if (rc < 0) { in ir_key_poll()
332 dev_warn(&ir->rc->dev, "error %d\n", rc); in ir_key_poll()
333 return rc; in ir_key_poll()
336 if (rc) { in ir_key_poll()
337 dev_dbg(&ir->rc->dev, "%s: proto = 0x%04x, scancode = 0x%08x\n", in ir_key_poll()
339 rc_keydown(ir->rc, protocol, scancode, toggle); in ir_key_poll()
346 int rc; in ir_work() local
353 if (mutex_trylock(&ir->lock)) { in ir_work()
354 rc = ir_key_poll(ir); in ir_work()
355 mutex_unlock(&ir->lock); in ir_work()
356 if (rc == -ENODEV) { in ir_work()
357 rc_unregister_device(ir->rc); in ir_work()
358 ir->rc = NULL; in ir_work()
363 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling_interval)); in ir_work()
368 struct IR_i2c *ir = dev->priv; in ir_open()
370 schedule_delayed_work(&ir->work, 0); in ir_open()
377 struct IR_i2c *ir = dev->priv; in ir_close()
379 cancel_delayed_work_sync(&ir->work); in ir_close()
397 * recorded IR. It's best to work with generated IR, like from ir-ctl or
398 * the in-kernel encoders.
416 p = &code_block->length; in send_data_block()
417 for (i = 0; p < code_block->csum; i++) in send_data_block()
418 code_block->csum[i & 1] ^= *p++; in send_data_block()
420 p = &code_block->length; in send_data_block()
423 int tosend = sizeof(*code_block) - i; in send_data_block()
430 dev_dbg(&ir->rc->dev, "%*ph", tosend + 1, buf); in send_data_block()
431 ret = i2c_master_send(ir->tx_c, buf, tosend + 1); in send_data_block()
433 dev_dbg(&ir->rc->dev, in send_data_block()
435 return ret < 0 ? ret : -EIO; in send_data_block()
442 ret = i2c_master_send(ir->tx_c, buf, 2); in send_data_block()
444 dev_err(&ir->rc->dev, "i2c_master_send failed with %d\n", ret); in send_data_block()
445 return ret < 0 ? ret : -EIO; in send_data_block()
450 ret = i2c_master_send(ir->tx_c, buf, 1); in send_data_block()
452 dev_err(&ir->rc->dev, "i2c_master_send failed with %d\n", ret); in send_data_block()
453 return ret < 0 ? ret : -EIO; in send_data_block()
471 ret = i2c_master_recv(ir->tx_c, buf, 4); in zilog_init()
473 dev_err(&ir->c->dev, "failed to retrieve firmware version: %d\n", in zilog_init()
475 return ret < 0 ? ret : -EIO; in zilog_init()
478 dev_info(&ir->c->dev, "Zilog/Hauppauge IR blaster firmware version %d.%d.%d\n", in zilog_init()
492 while (count--) { in copy_codes()
509 while (--count) { in cmp_no_trail()
514 return (*a & 0xf0) - (*b & 0xf0); in cmp_no_trail()
530 return -1; in find_slot()
536 struct IR_i2c *ir = rcdev->priv; in zilog_ir_format()
541 code_block->carrier_pulse = DIV_ROUND_CLOSEST( in zilog_ir_format()
542 ir->duty_cycle * XTAL_FREQ / 1000, ir->carrier); in zilog_ir_format()
543 code_block->carrier_space = DIV_ROUND_CLOSEST( in zilog_ir_format()
544 (100 - ir->duty_cycle) * XTAL_FREQ / 1000, ir->carrier); in zilog_ir_format()
547 if (c >= ARRAY_SIZE(codes) - 1) { in zilog_ir_format()
548 dev_warn(&rcdev->dev, "IR too long, cannot transmit\n"); in zilog_ir_format()
549 return -EINVAL; in zilog_ir_format()
557 return -EINVAL; in zilog_ir_format()
562 s = find_slot(code_block->space, in zilog_ir_format()
563 ARRAY_SIZE(code_block->space), l); in zilog_ir_format()
564 if (s == -1) { in zilog_ir_format()
565 dev_warn(&rcdev->dev, "Too many different lengths spaces, cannot transmit"); in zilog_ir_format()
566 return -EINVAL; in zilog_ir_format()
572 p = find_slot(code_block->pulse, in zilog_ir_format()
573 ARRAY_SIZE(code_block->pulse), l); in zilog_ir_format()
574 if (p == -1) { in zilog_ir_format()
575 dev_warn(&rcdev->dev, "Too many different lengths pulses, cannot transmit"); in zilog_ir_format()
576 return -EINVAL; in zilog_ir_format()
583 for (i = 1; i < ARRAY_SIZE(code_block->space); i++) { in zilog_ir_format()
584 u16 d = get_unaligned_be16(&code_block->space[i]); in zilog_ir_format()
586 if (get_unaligned_be16(&code_block->space[s]) > d) in zilog_ir_format()
592 dev_dbg(&rcdev->dev, "generated %d codes\n", c); in zilog_ir_format()
601 for (rep = c / 3; rep >= 1; rep--) { in zilog_ir_format()
602 if (!memcmp(&codes[c - rep * 3], &codes[c - rep * 2], rep) && in zilog_ir_format()
603 !cmp_no_trail(&codes[c - rep], &codes[c - rep * 2], rep)) { in zilog_ir_format()
610 /* first copy any leading non-repeating */ in zilog_ir_format()
611 int leading = c - rep * 3; in zilog_ir_format()
613 if (leading >= ARRAY_SIZE(code_block->codes) - 3 - rep) { in zilog_ir_format()
614 dev_warn(&rcdev->dev, "IR too long, cannot transmit\n"); in zilog_ir_format()
615 return -EINVAL; in zilog_ir_format()
618 dev_dbg(&rcdev->dev, "found trailing %d repeat\n", rep); in zilog_ir_format()
619 copy_codes(code_block->codes, codes, leading); in zilog_ir_format()
620 code_block->codes[leading] = 0x82; in zilog_ir_format()
621 copy_codes(code_block->codes + leading + 1, codes + leading, in zilog_ir_format()
624 code_block->codes[c++] = 0xc0; in zilog_ir_format()
626 if (c >= ARRAY_SIZE(code_block->codes) - 3) { in zilog_ir_format()
627 dev_warn(&rcdev->dev, "IR too long, cannot transmit\n"); in zilog_ir_format()
628 return -EINVAL; in zilog_ir_format()
631 dev_dbg(&rcdev->dev, "found no trailing repeat\n"); in zilog_ir_format()
632 code_block->codes[0] = 0x82; in zilog_ir_format()
633 copy_codes(code_block->codes + 1, codes, c); in zilog_ir_format()
635 code_block->codes[c++] = 0xc4; in zilog_ir_format()
638 while (c < ARRAY_SIZE(code_block->codes)) in zilog_ir_format()
639 code_block->codes[c++] = 0x83; in zilog_ir_format()
647 struct IR_i2c *ir = rcdev->priv; in zilog_tx()
656 ret = mutex_lock_interruptible(&ir->lock); in zilog_tx()
664 ret = i2c_master_recv(ir->tx_c, buf, 1); in zilog_tx()
666 dev_err(&ir->rc->dev, "i2c_master_recv failed with %d\n", ret); in zilog_tx()
670 dev_dbg(&ir->rc->dev, "code set status: %02x\n", buf[0]); in zilog_tx()
673 dev_err(&ir->rc->dev, "unexpected IR TX response %02x\n", in zilog_tx()
675 ret = -EIO; in zilog_tx()
682 ret = i2c_master_send(ir->tx_c, buf, 2); in zilog_tx()
684 dev_err(&ir->rc->dev, "i2c_master_send failed with %d\n", ret); in zilog_tx()
686 ret = -EIO; in zilog_tx()
690 dev_dbg(&ir->rc->dev, "send command sent\n"); in zilog_tx()
701 ret = i2c_master_send(ir->tx_c, buf, 1); in zilog_tx()
704 dev_dbg(&ir->rc->dev, in zilog_tx()
710 dev_err(&ir->rc->dev, in zilog_tx()
714 ret = -EIO; in zilog_tx()
718 ret = i2c_master_recv(ir->tx_c, buf, 1); in zilog_tx()
720 dev_err(&ir->rc->dev, "i2c_master_recv failed with %d\n", ret); in zilog_tx()
721 ret = -EIO; in zilog_tx()
724 dev_err(&ir->rc->dev, "unexpected IR TX response #2: %02x\n", in zilog_tx()
726 ret = -EIO; in zilog_tx()
729 dev_dbg(&ir->rc->dev, "transmit complete\n"); in zilog_tx()
734 mutex_unlock(&ir->lock); in zilog_tx()
741 struct IR_i2c *ir = dev->priv; in zilog_tx_carrier()
744 return -EINVAL; in zilog_tx_carrier()
746 ir->carrier = carrier; in zilog_tx_carrier()
753 struct IR_i2c *ir = dev->priv; in zilog_tx_duty_cycle()
755 ir->duty_cycle = duty_cycle; in zilog_tx_duty_cycle()
767 struct rc_dev *rc = NULL; in ir_probe() local
768 struct i2c_adapter *adap = client->adapter; in ir_probe()
769 unsigned short addr = client->addr; in ir_probe()
770 bool probe_tx = (id->driver_data & FLAG_TX) != 0; in ir_probe()
773 if ((id->driver_data & FLAG_HDPVR) && !enable_hdpvr) { in ir_probe()
774 …dev_err(&client->dev, "IR for HDPVR is known to cause problems during recording, use enable_hdpvr … in ir_probe()
775 return -ENODEV; in ir_probe()
778 ir = devm_kzalloc(&client->dev, sizeof(*ir), GFP_KERNEL); in ir_probe()
780 return -ENOMEM; in ir_probe()
782 ir->c = client; in ir_probe()
783 ir->polling_interval = DEFAULT_POLLING_INTERVAL; in ir_probe()
789 ir->get_key = get_key_pixelview; in ir_probe()
797 ir->get_key = get_key_haup; in ir_probe()
803 ir->get_key = get_key_knc1; in ir_probe()
809 ir->get_key = get_key_geniatech; in ir_probe()
812 ir->old = 0xfc; in ir_probe()
816 ir->get_key = get_key_fusionhdtv; in ir_probe()
822 ir->get_key = get_key_avermedia_cardbus; in ir_probe()
828 ir->get_key = get_key_avermedia_cardbus; in ir_probe()
830 /* RM-KV remote, seems to be same as RM-K6 */ in ir_probe()
835 ir->get_key = get_key_haup_xvr; in ir_probe()
839 ir->polling_interval = 125; in ir_probe()
845 if (client->dev.platform_data) { in ir_probe()
847 client->dev.platform_data; in ir_probe()
849 ir_codes = init_data->ir_codes; in ir_probe()
850 rc = init_data->rc_dev; in ir_probe()
852 name = init_data->name; in ir_probe()
853 if (init_data->type) in ir_probe()
854 rc_proto = init_data->type; in ir_probe()
856 if (init_data->polling_interval) in ir_probe()
857 ir->polling_interval = init_data->polling_interval; in ir_probe()
859 switch (init_data->internal_get_key_func) { in ir_probe()
862 ir->get_key = init_data->get_key; in ir_probe()
865 ir->get_key = get_key_pixelview; in ir_probe()
868 ir->get_key = get_key_haup; in ir_probe()
871 ir->get_key = get_key_knc1; in ir_probe()
874 ir->get_key = get_key_geniatech; in ir_probe()
877 ir->get_key = get_key_fusionhdtv; in ir_probe()
880 ir->get_key = get_key_haup_xvr; in ir_probe()
883 ir->get_key = get_key_avermedia_cardbus; in ir_probe()
888 if (!rc) { in ir_probe()
893 rc = rc_allocate_device(RC_DRIVER_SCANCODE); in ir_probe()
894 if (!rc) in ir_probe()
895 return -ENOMEM; in ir_probe()
897 ir->rc = rc; in ir_probe()
900 if (!name || !ir->get_key || !rc_proto || !ir_codes) { in ir_probe()
901 dev_warn(&client->dev, "Unsupported device at address 0x%02x\n", in ir_probe()
903 err = -ENODEV; in ir_probe()
907 ir->ir_codes = ir_codes; in ir_probe()
909 snprintf(ir->phys, sizeof(ir->phys), "%s/%s", dev_name(&adap->dev), in ir_probe()
910 dev_name(&client->dev)); in ir_probe()
916 rc->input_id.bustype = BUS_I2C; in ir_probe()
917 rc->input_phys = ir->phys; in ir_probe()
918 rc->device_name = name; in ir_probe()
919 rc->dev.parent = &client->dev; in ir_probe()
920 rc->priv = ir; in ir_probe()
921 rc->open = ir_open; in ir_probe()
922 rc->close = ir_close; in ir_probe()
927 rc->map_name = ir->ir_codes; in ir_probe()
928 rc->allowed_protocols = rc_proto; in ir_probe()
929 if (!rc->driver_name) in ir_probe()
930 rc->driver_name = KBUILD_MODNAME; in ir_probe()
932 mutex_init(&ir->lock); in ir_probe()
934 INIT_DELAYED_WORK(&ir->work, ir_work); in ir_probe()
937 ir->tx_c = i2c_new_dummy_device(client->adapter, 0x70); in ir_probe()
938 if (IS_ERR(ir->tx_c)) { in ir_probe()
939 dev_err(&client->dev, "failed to setup tx i2c address"); in ir_probe()
940 err = PTR_ERR(ir->tx_c); in ir_probe()
943 ir->carrier = 38000; in ir_probe()
944 ir->duty_cycle = 40; in ir_probe()
945 rc->tx_ir = zilog_tx; in ir_probe()
946 rc->s_tx_carrier = zilog_tx_carrier; in ir_probe()
947 rc->s_tx_duty_cycle = zilog_tx_duty_cycle; in ir_probe()
951 err = rc_register_device(rc); in ir_probe()
958 if (!IS_ERR(ir->tx_c)) in ir_probe()
959 i2c_unregister_device(ir->tx_c); in ir_probe()
961 /* Only frees rc if it were allocated internally */ in ir_probe()
962 rc_free_device(rc); in ir_probe()
970 cancel_delayed_work_sync(&ir->work); in ir_remove()
972 i2c_unregister_device(ir->tx_c); in ir_remove()
974 rc_unregister_device(ir->rc); in ir_remove()
989 .name = "ir-kbd-i2c",
998 /* ----------------------------------------------------------------------- */