]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/media/rc/imon.c
Merge tag 'v2.6.38' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[mv-sheeva.git] / drivers / media / rc / imon.c
similarity index 96%
rename from drivers/media/IR/imon.c
rename to drivers/media/rc/imon.c
index bc118066bc38ba2fd4a0c74c7e7c061de42bed3d..e7dc6b46fdfac2df6f6ead2661d4fed6ea4c4358 100644 (file)
@@ -38,7 +38,7 @@
 #include <linux/input.h>
 #include <linux/usb.h>
 #include <linux/usb/input.h>
-#include <media/ir-core.h>
+#include <media/rc-core.h>
 
 #include <linux/time.h>
 #include <linux/timer.h>
@@ -88,7 +88,6 @@ static ssize_t lcd_write(struct file *file, const char *buf,
 
 struct imon_context {
        struct device *dev;
-       struct ir_dev_props *props;
        /* Newer devices have two interfaces */
        struct usb_device *usbdev_intf0;
        struct usb_device *usbdev_intf1;
@@ -123,7 +122,7 @@ struct imon_context {
        u16 vendor;                     /* usb vendor ID */
        u16 product;                    /* usb product ID */
 
-       struct input_dev *rdev;         /* input device for remote */
+       struct rc_dev *rdev;            /* rc-core device for remote */
        struct input_dev *idev;         /* input device for panel & IR mouse */
        struct input_dev *touch;        /* input device for touchscreen */
 
@@ -132,7 +131,7 @@ struct imon_context {
        u32 last_keycode;               /* last reported input keycode */
        u32 rc_scancode;                /* the computed remote scancode */
        u8 rc_toggle;                   /* the computed remote toggle bit */
-       u64 ir_type;                    /* iMON or MCE (RC6) IR protocol? */
+       u64 rc_type;                    /* iMON or MCE (RC6) IR protocol? */
        bool release_code;              /* some keys send a release code */
 
        u8 display_type;                /* store the display type */
@@ -984,48 +983,38 @@ static void imon_touch_display_timeout(unsigned long data)
  * really just RC-6), but only one or the other at a time, as the signals
  * are decoded onboard the receiver.
  */
-int imon_ir_change_protocol(void *priv, u64 ir_type)
+static int imon_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
 {
        int retval;
-       struct imon_context *ictx = priv;
+       struct imon_context *ictx = rc->priv;
        struct device *dev = ictx->dev;
-       bool pad_mouse;
        unsigned char ir_proto_packet[] = {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
 
-       if (ir_type && !(ir_type & ictx->props->allowed_protos))
+       if (rc_type && !(rc_type & rc->allowed_protos))
                dev_warn(dev, "Looks like you're trying to use an IR protocol "
                         "this device does not support\n");
 
-       switch (ir_type) {
-       case IR_TYPE_RC6:
+       switch (rc_type) {
+       case RC_TYPE_RC6:
                dev_dbg(dev, "Configuring IR receiver for MCE protocol\n");
                ir_proto_packet[0] = 0x01;
-               pad_mouse = false;
                break;
-       case IR_TYPE_UNKNOWN:
-       case IR_TYPE_OTHER:
+       case RC_TYPE_UNKNOWN:
+       case RC_TYPE_OTHER:
                dev_dbg(dev, "Configuring IR receiver for iMON protocol\n");
-               if (pad_stabilize && !nomouse)
-                       pad_mouse = true;
-               else {
+               if (!pad_stabilize)
                        dev_dbg(dev, "PAD stabilize functionality disabled\n");
-                       pad_mouse = false;
-               }
                /* ir_proto_packet[0] = 0x00; // already the default */
-               ir_type = IR_TYPE_OTHER;
+               rc_type = RC_TYPE_OTHER;
                break;
        default:
                dev_warn(dev, "Unsupported IR protocol specified, overriding "
                         "to iMON IR protocol\n");
-               if (pad_stabilize && !nomouse)
-                       pad_mouse = true;
-               else {
+               if (!pad_stabilize)
                        dev_dbg(dev, "PAD stabilize functionality disabled\n");
-                       pad_mouse = false;
-               }
                /* ir_proto_packet[0] = 0x00; // already the default */
-               ir_type = IR_TYPE_OTHER;
+               rc_type = RC_TYPE_OTHER;
                break;
        }
 
@@ -1035,8 +1024,8 @@ int imon_ir_change_protocol(void *priv, u64 ir_type)
        if (retval)
                goto out;
 
-       ictx->ir_type = ir_type;
-       ictx->pad_mouse = pad_mouse;
+       ictx->rc_type = rc_type;
+       ictx->pad_mouse = false;
 
 out:
        return retval;
@@ -1147,14 +1136,14 @@ static u32 imon_remote_key_lookup(struct imon_context *ictx, u32 scancode)
        bool is_release_code = false;
 
        /* Look for the initial press of a button */
-       keycode = ir_g_keycode_from_table(ictx->rdev, scancode);
+       keycode = rc_g_keycode_from_table(ictx->rdev, scancode);
        ictx->rc_toggle = 0x0;
        ictx->rc_scancode = scancode;
 
        /* Look for the release of a button */
        if (keycode == KEY_RESERVED) {
                release = scancode & ~0x4000;
-               keycode = ir_g_keycode_from_table(ictx->rdev, release);
+               keycode = rc_g_keycode_from_table(ictx->rdev, release);
                if (keycode != KEY_RESERVED)
                        is_release_code = true;
        }
@@ -1183,7 +1172,7 @@ static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 scancode)
                scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT;
 
        ictx->rc_scancode = scancode;
-       keycode = ir_g_keycode_from_table(ictx->rdev, scancode);
+       keycode = rc_g_keycode_from_table(ictx->rdev, scancode);
 
        /* not used in mce mode, but make sure we know its false */
        ictx->release_code = false;
@@ -1307,7 +1296,7 @@ static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
                rel_x = buf[2];
                rel_y = buf[3];
 
-               if (ictx->ir_type == IR_TYPE_OTHER && pad_stabilize) {
+               if (ictx->rc_type == RC_TYPE_OTHER && pad_stabilize) {
                        if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) {
                                dir = stabilize((int)rel_x, (int)rel_y,
                                                timeout, threshold);
@@ -1374,7 +1363,7 @@ static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
                buf[0] = 0x01;
                buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0;
 
-               if (ictx->ir_type == IR_TYPE_OTHER && pad_stabilize) {
+               if (ictx->rc_type == RC_TYPE_OTHER && pad_stabilize) {
                        dir = stabilize((int)rel_x, (int)rel_y,
                                        timeout, threshold);
                        if (!dir) {
@@ -1479,17 +1468,12 @@ static void imon_incoming_packet(struct imon_context *ictx,
        bool norelease = false;
        int i;
        u64 scancode;
-       struct input_dev *rdev = NULL;
-       struct ir_input_dev *irdev = NULL;
        int press_type = 0;
        int msec;
        struct timeval t;
        static struct timeval prev_time = { 0, 0 };
        u8 ktype;
 
-       rdev = ictx->rdev;
-       irdev = input_get_drvdata(rdev);
-
        /* filter out junk data on the older 0xffdc imon devices */
        if ((buf[0] == 0xff) && (buf[1] == 0xff) && (buf[2] == 0xff))
                return;
@@ -1501,7 +1485,7 @@ static void imon_incoming_packet(struct imon_context *ictx,
                kc = imon_panel_key_lookup(scancode);
        } else {
                scancode = be32_to_cpu(*((u32 *)buf));
-               if (ictx->ir_type == IR_TYPE_RC6) {
+               if (ictx->rc_type == RC_TYPE_RC6) {
                        ktype = IMON_KEY_IMON;
                        if (buf[0] == 0x80)
                                ktype = IMON_KEY_MCE;
@@ -1523,7 +1507,7 @@ static void imon_incoming_packet(struct imon_context *ictx,
                        spin_unlock_irqrestore(&ictx->kc_lock, flags);
                        return;
                } else {
-                       ictx->pad_mouse = 0;
+                       ictx->pad_mouse = false;
                        dev_dbg(dev, "mouse mode disabled, passing key value\n");
                }
        }
@@ -1570,9 +1554,9 @@ static void imon_incoming_packet(struct imon_context *ictx,
 
        if (ktype != IMON_KEY_PANEL) {
                if (press_type == 0)
-                       ir_keyup(irdev);
+                       rc_keyup(ictx->rdev);
                else {
-                       ir_keydown(rdev, ictx->rc_scancode, ictx->rc_toggle);
+                       rc_keydown(ictx->rdev, ictx->rc_scancode, ictx->rc_toggle);
                        spin_lock_irqsave(&ictx->kc_lock, flags);
                        ictx->last_keycode = ictx->kc;
                        spin_unlock_irqrestore(&ictx->kc_lock, flags);
@@ -1715,7 +1699,7 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
 {
        u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
        u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
-       u64 allowed_protos = IR_TYPE_OTHER;
+       u64 allowed_protos = RC_TYPE_OTHER;
 
        switch (ffdc_cfg_byte) {
        /* iMON Knob, no display, iMON IR + vol knob */
@@ -1744,13 +1728,13 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
        case 0x9e:
                dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR");
                detected_display_type = IMON_DISPLAY_TYPE_VFD;
-               allowed_protos = IR_TYPE_RC6;
+               allowed_protos = RC_TYPE_RC6;
                break;
        /* iMON LCD, MCE IR */
        case 0x9f:
                dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
                detected_display_type = IMON_DISPLAY_TYPE_LCD;
-               allowed_protos = IR_TYPE_RC6;
+               allowed_protos = RC_TYPE_RC6;
                break;
        default:
                dev_info(ictx->dev, "Unknown 0xffdc device, "
@@ -1762,8 +1746,7 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
        printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte);
 
        ictx->display_type = detected_display_type;
-       ictx->props->allowed_protos = allowed_protos;
-       ictx->ir_type = allowed_protos;
+       ictx->rc_type = allowed_protos;
 }
 
 static void imon_set_display_type(struct imon_context *ictx)
@@ -1816,18 +1799,15 @@ static void imon_set_display_type(struct imon_context *ictx)
        ictx->display_type = configured_display_type;
 }
 
-static struct input_dev *imon_init_rdev(struct imon_context *ictx)
+static struct rc_dev *imon_init_rdev(struct imon_context *ictx)
 {
-       struct input_dev *rdev;
-       struct ir_dev_props *props;
+       struct rc_dev *rdev;
        int ret;
-       char *ir_codes = NULL;
        const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
                                            0x00, 0x00, 0x00, 0x88 };
 
-       rdev = input_allocate_device();
-       props = kzalloc(sizeof(*props), GFP_KERNEL);
-       if (!rdev || !props) {
+       rdev = rc_allocate_device();
+       if (!rdev) {
                dev_err(ictx->dev, "remote control dev allocation failed\n");
                goto out;
        }
@@ -1838,18 +1818,16 @@ static struct input_dev *imon_init_rdev(struct imon_context *ictx)
                      sizeof(ictx->phys_rdev));
        strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev));
 
-       rdev->name = ictx->name_rdev;
-       rdev->phys = ictx->phys_rdev;
-       usb_to_input_id(ictx->usbdev_intf0, &rdev->id);
+       rdev->input_name = ictx->name_rdev;
+       rdev->input_phys = ictx->phys_rdev;
+       usb_to_input_id(ictx->usbdev_intf0, &rdev->input_id);
        rdev->dev.parent = ictx->dev;
-       rdev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
-       input_set_drvdata(rdev, ictx);
 
-       props->priv = ictx;
-       props->driver_type = RC_DRIVER_SCANCODE;
-       props->allowed_protos = IR_TYPE_OTHER | IR_TYPE_RC6; /* iMON PAD or MCE */
-       props->change_protocol = imon_ir_change_protocol;
-       ictx->props = props;
+       rdev->priv = ictx;
+       rdev->driver_type = RC_DRIVER_SCANCODE;
+       rdev->allowed_protos = RC_TYPE_OTHER | RC_TYPE_RC6; /* iMON PAD or MCE */
+       rdev->change_protocol = imon_ir_change_protocol;
+       rdev->driver_name = MOD_NAME;
 
        /* Enable front-panel buttons and/or knobs */
        memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet));
@@ -1858,17 +1836,19 @@ static struct input_dev *imon_init_rdev(struct imon_context *ictx)
        if (ret)
                dev_info(ictx->dev, "panel buttons/knobs setup failed\n");
 
-       if (ictx->product == 0xffdc)
+       if (ictx->product == 0xffdc) {
                imon_get_ffdc_type(ictx);
+               rdev->allowed_protos = ictx->rc_type;
+       }
 
        imon_set_display_type(ictx);
 
-       if (ictx->ir_type == IR_TYPE_RC6)
-               ir_codes = RC_MAP_IMON_MCE;
+       if (ictx->rc_type == RC_TYPE_RC6)
+               rdev->map_name = RC_MAP_IMON_MCE;
        else
-               ir_codes = RC_MAP_IMON_PAD;
+               rdev->map_name = RC_MAP_IMON_PAD;
 
-       ret = ir_input_register(rdev, ir_codes, props, MOD_NAME);
+       ret = rc_register_device(rdev);
        if (ret < 0) {
                dev_err(ictx->dev, "remote input dev register failed\n");
                goto out;
@@ -1877,8 +1857,7 @@ static struct input_dev *imon_init_rdev(struct imon_context *ictx)
        return rdev;
 
 out:
-       kfree(props);
-       input_free_device(rdev);
+       rc_free_device(rdev);
        return NULL;
 }
 
@@ -2121,18 +2100,6 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
                goto find_endpoint_failed;
        }
 
-       ictx->idev = imon_init_idev(ictx);
-       if (!ictx->idev) {
-               dev_err(dev, "%s: input device setup failed\n", __func__);
-               goto idev_setup_failed;
-       }
-
-       ictx->rdev = imon_init_rdev(ictx);
-       if (!ictx->rdev) {
-               dev_err(dev, "%s: rc device setup failed\n", __func__);
-               goto rdev_setup_failed;
-       }
-
        usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
                usb_rcvintpipe(ictx->usbdev_intf0,
                        ictx->rx_endpoint_intf0->bEndpointAddress),
@@ -2146,13 +2113,25 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
                goto urb_submit_failed;
        }
 
+       ictx->idev = imon_init_idev(ictx);
+       if (!ictx->idev) {
+               dev_err(dev, "%s: input device setup failed\n", __func__);
+               goto idev_setup_failed;
+       }
+
+       ictx->rdev = imon_init_rdev(ictx);
+       if (!ictx->rdev) {
+               dev_err(dev, "%s: rc device setup failed\n", __func__);
+               goto rdev_setup_failed;
+       }
+
        return ictx;
 
-urb_submit_failed:
-       ir_input_unregister(ictx->rdev);
 rdev_setup_failed:
        input_unregister_device(ictx->idev);
 idev_setup_failed:
+       usb_kill_urb(ictx->rx_urb_intf0);
+urb_submit_failed:
 find_endpoint_failed:
        mutex_unlock(&ictx->lock);
        usb_free_urb(tx_urb);
@@ -2287,7 +2266,7 @@ static int __devinit imon_probe(struct usb_interface *interface,
        mutex_lock(&driver_lock);
 
        first_if = usb_ifnum_to_if(usbdev, 0);
-       first_if_ctx = (struct imon_context *)usb_get_intfdata(first_if);
+       first_if_ctx = usb_get_intfdata(first_if);
 
        if (ifnum == 0) {
                ictx = imon_init_intf0(interface);
@@ -2376,7 +2355,7 @@ static void __devexit imon_disconnect(struct usb_interface *interface)
                ictx->dev_present_intf0 = false;
                usb_kill_urb(ictx->rx_urb_intf0);
                input_unregister_device(ictx->idev);
-               ir_input_unregister(ictx->rdev);
+               rc_unregister_device(ictx->rdev);
                if (ictx->display_supported) {
                        if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
                                usb_deregister_dev(interface, &imon_lcd_class);