^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // cx231xx IR glue driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // Copyright (c) 2010 Mauro Carvalho Chehab <mchehab@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Polaris (cx231xx) has its support for IR's with a design close to MCE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // however, a few designs are using an external I2C chip for IR, instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // of using the one provided by the chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // This driver provides support for those extra devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "cx231xx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/bitrev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define MODULE_NAME "cx231xx-input"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static int get_key_isdbt(struct IR_i2c *ir, enum rc_proto *protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) u32 *pscancode, u8 *toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) u8 cmd, scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) dev_dbg(&ir->rc->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* poll IR chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) rc = i2c_master_recv(ir->c, &cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (rc != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* it seems that 0xFE indicates that a button is still hold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) down, while 0xff indicates that no button is hold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) down. 0xfe sequences are sometimes interrupted by 0xFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (cmd == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) scancode = bitrev8(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) dev_dbg(&ir->rc->dev, "cmd %02x, scan = %02x\n", cmd, scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *protocol = RC_PROTO_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *pscancode = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *toggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int cx231xx_ir_init(struct cx231xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct i2c_board_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 ir_i2c_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) dev_dbg(dev->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* Only initialize if a rc keycode map is defined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (!cx231xx_boards[dev->model].rc_map_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) request_module("ir-kbd-i2c");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) memset(&info, 0, sizeof(struct i2c_board_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) memset(&dev->init_data, 0, sizeof(dev->init_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) dev->init_data.rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (!dev->init_data.rc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) dev->init_data.name = cx231xx_boards[dev->model].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) strscpy(info.type, "ir_video", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) info.platform_data = &dev->init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * Board-dependent values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * For now, there's just one type of hardware design using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * an i2c device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dev->init_data.get_key = get_key_isdbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* The i2c micro-controller only outputs the cmd part of NEC protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) dev->init_data.rc_dev->scancode_mask = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) dev->init_data.rc_dev->driver_name = "cx231xx";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) dev->init_data.type = RC_PROTO_BIT_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) info.addr = 0x30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* Load and bind ir-kbd-i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) dev_dbg(dev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ir_i2c_bus, info.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) dev->ir_i2c_client = i2c_new_client_device(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) cx231xx_get_i2c_adap(dev, ir_i2c_bus), &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) void cx231xx_ir_exit(struct cx231xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) i2c_unregister_device(dev->ir_i2c_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) dev->ir_i2c_client = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }