aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/rc/mceusb.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2010-10-29 15:08:23 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-12-29 05:16:37 -0500
commitd8b4b5822f51e2142b731b42c81e3f03eec475b2 (patch)
treefce9a9b7ca5031adc95fbd6be118352fb2527da5 /drivers/media/rc/mceusb.c
parent4c7b355df6e7f05304e05f6b7a286e59a5f1cc54 (diff)
[media] ir-core: make struct rc_dev the primary interface
This patch merges the ir_input_dev and ir_dev_props structs into a single struct called rc_dev. The drivers and various functions in rc-core used by the drivers are also changed to use rc_dev as the primary interface when dealing with rc-core. This means that the input_dev is abstracted away from the drivers which is necessary if we ever want to support multiple input devs per rc device. The new API is similar to what the input subsystem uses, i.e: rc_device_alloc() rc_device_free() rc_device_register() rc_device_unregister() [mchehab@redhat.com: Fix compilation on mceusb and cx231xx, due to merge conflicts] Signed-off-by: David Härdeman <david@hardeman.nu> Acked-by: Jarod Wilson <jarod@redhat.com> Tested-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/rc/mceusb.c')
-rw-r--r--drivers/media/rc/mceusb.c112
1 files changed, 46 insertions, 66 deletions
diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
index 392ca24132da..539bec2974b7 100644
--- a/drivers/media/rc/mceusb.c
+++ b/drivers/media/rc/mceusb.c
@@ -35,7 +35,6 @@
35#include <linux/device.h> 35#include <linux/device.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/input.h>
39#include <linux/usb.h> 38#include <linux/usb.h>
40#include <linux/usb/input.h> 39#include <linux/usb/input.h>
41#include <media/ir-core.h> 40#include <media/ir-core.h>
@@ -317,7 +316,7 @@ static struct usb_device_id mceusb_dev_table[] = {
317/* data structure for each usb transceiver */ 316/* data structure for each usb transceiver */
318struct mceusb_dev { 317struct mceusb_dev {
319 /* ir-core bits */ 318 /* ir-core bits */
320 struct ir_dev_props *props; 319 struct rc_dev *rc;
321 320
322 /* optional features we can enable */ 321 /* optional features we can enable */
323 bool carrier_report_enabled; 322 bool carrier_report_enabled;
@@ -325,7 +324,6 @@ struct mceusb_dev {
325 324
326 /* core device bits */ 325 /* core device bits */
327 struct device *dev; 326 struct device *dev;
328 struct input_dev *idev;
329 327
330 /* usb */ 328 /* usb */
331 struct usb_device *usbdev; 329 struct usb_device *usbdev;
@@ -663,9 +661,9 @@ static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size)
663} 661}
664 662
665/* Send data out the IR blaster port(s) */ 663/* Send data out the IR blaster port(s) */
666static int mceusb_tx_ir(void *priv, int *txbuf, u32 n) 664static int mceusb_tx_ir(struct rc_dev *dev, int *txbuf, u32 n)
667{ 665{
668 struct mceusb_dev *ir = priv; 666 struct mceusb_dev *ir = dev->priv;
669 int i, ret = 0; 667 int i, ret = 0;
670 int count, cmdcount = 0; 668 int count, cmdcount = 0;
671 unsigned char *cmdbuf; /* MCE command buffer */ 669 unsigned char *cmdbuf; /* MCE command buffer */
@@ -749,9 +747,9 @@ out:
749} 747}
750 748
751/* Sets active IR outputs -- mce devices typically have two */ 749/* Sets active IR outputs -- mce devices typically have two */
752static int mceusb_set_tx_mask(void *priv, u32 mask) 750static int mceusb_set_tx_mask(struct rc_dev *dev, u32 mask)
753{ 751{
754 struct mceusb_dev *ir = priv; 752 struct mceusb_dev *ir = dev->priv;
755 753
756 if (ir->flags.tx_mask_normal) 754 if (ir->flags.tx_mask_normal)
757 ir->tx_mask = mask; 755 ir->tx_mask = mask;
@@ -763,9 +761,9 @@ static int mceusb_set_tx_mask(void *priv, u32 mask)
763} 761}
764 762
765/* Sets the send carrier frequency and mode */ 763/* Sets the send carrier frequency and mode */
766static int mceusb_set_tx_carrier(void *priv, u32 carrier) 764static int mceusb_set_tx_carrier(struct rc_dev *dev, u32 carrier)
767{ 765{
768 struct mceusb_dev *ir = priv; 766 struct mceusb_dev *ir = dev->priv;
769 int clk = 10000000; 767 int clk = 10000000;
770 int prescaler = 0, divisor = 0; 768 int prescaler = 0, divisor = 0;
771 unsigned char cmdbuf[4] = { MCE_COMMAND_HEADER, 769 unsigned char cmdbuf[4] = { MCE_COMMAND_HEADER,
@@ -819,7 +817,7 @@ static void mceusb_handle_command(struct mceusb_dev *ir, int index)
819 switch (ir->buf_in[index]) { 817 switch (ir->buf_in[index]) {
820 /* 2-byte return value commands */ 818 /* 2-byte return value commands */
821 case MCE_CMD_S_TIMEOUT: 819 case MCE_CMD_S_TIMEOUT:
822 ir->props->timeout = MS_TO_NS((hi << 8 | lo) / 2); 820 ir->rc->timeout = MS_TO_NS((hi << 8 | lo) / 2);
823 break; 821 break;
824 822
825 /* 1-byte return value commands */ 823 /* 1-byte return value commands */
@@ -866,7 +864,7 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
866 rawir.pulse ? "pulse" : "space", 864 rawir.pulse ? "pulse" : "space",
867 rawir.duration); 865 rawir.duration);
868 866
869 ir_raw_event_store_with_filter(ir->idev, &rawir); 867 ir_raw_event_store_with_filter(ir->rc, &rawir);
870 break; 868 break;
871 case CMD_DATA: 869 case CMD_DATA:
872 ir->rem--; 870 ir->rem--;
@@ -893,7 +891,7 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
893 ir->parser_state = CMD_HEADER; 891 ir->parser_state = CMD_HEADER;
894 } 892 }
895 dev_dbg(ir->dev, "processed IR data, calling ir_raw_event_handle\n"); 893 dev_dbg(ir->dev, "processed IR data, calling ir_raw_event_handle\n");
896 ir_raw_event_handle(ir->idev); 894 ir_raw_event_handle(ir->rc);
897} 895}
898 896
899static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs) 897static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs)
@@ -1035,72 +1033,54 @@ static void mceusb_get_parameters(struct mceusb_dev *ir)
1035 mce_sync_in(ir, NULL, maxp); 1033 mce_sync_in(ir, NULL, maxp);
1036} 1034}
1037 1035
1038static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir) 1036static struct rc_dev *mceusb_init_rc_dev(struct mceusb_dev *ir)
1039{ 1037{
1040 struct input_dev *idev;
1041 struct ir_dev_props *props;
1042 struct device *dev = ir->dev; 1038 struct device *dev = ir->dev;
1043 const char *rc_map = RC_MAP_RC6_MCE; 1039 struct rc_dev *rc;
1044 const char *name = "Media Center Ed. eHome Infrared Remote Transceiver"; 1040 int ret;
1045 int ret = -ENODEV;
1046
1047 idev = input_allocate_device();
1048 if (!idev) {
1049 dev_err(dev, "remote input dev allocation failed\n");
1050 goto idev_alloc_failed;
1051 }
1052 1041
1053 ret = -ENOMEM; 1042 rc = rc_allocate_device();
1054 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL); 1043 if (!rc) {
1055 if (!props) { 1044 dev_err(dev, "remote dev allocation failed\n");
1056 dev_err(dev, "remote ir dev props allocation failed\n"); 1045 goto out;
1057 goto props_alloc_failed;
1058 } 1046 }
1059 1047
1060 if (mceusb_model[ir->model].name)
1061 name = mceusb_model[ir->model].name;
1062
1063 snprintf(ir->name, sizeof(ir->name), "%s (%04x:%04x)", 1048 snprintf(ir->name, sizeof(ir->name), "%s (%04x:%04x)",
1064 name, 1049 mceusb_model[ir->model].name ?
1050 mceusb_model[ir->model].name :
1051 "Media Center Ed. eHome Infrared Remote Transceiver",
1065 le16_to_cpu(ir->usbdev->descriptor.idVendor), 1052 le16_to_cpu(ir->usbdev->descriptor.idVendor),
1066 le16_to_cpu(ir->usbdev->descriptor.idProduct)); 1053 le16_to_cpu(ir->usbdev->descriptor.idProduct));
1067 1054
1068 idev->name = ir->name;
1069 usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys)); 1055 usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys));
1070 strlcat(ir->phys, "/input0", sizeof(ir->phys));
1071 idev->phys = ir->phys;
1072 1056
1073 props->priv = ir; 1057 rc->input_name = ir->name;
1074 props->driver_type = RC_DRIVER_IR_RAW; 1058 rc->input_phys = ir->phys;
1075 props->allowed_protos = IR_TYPE_ALL; 1059 usb_to_input_id(ir->usbdev, &rc->input_id);
1076 props->timeout = MS_TO_NS(1000); 1060 rc->dev.parent = dev;
1061 rc->priv = ir;
1062 rc->driver_type = RC_DRIVER_IR_RAW;
1063 rc->allowed_protos = IR_TYPE_ALL;
1064 rc->timeout = MS_TO_NS(1000);
1077 if (!ir->flags.no_tx) { 1065 if (!ir->flags.no_tx) {
1078 props->s_tx_mask = mceusb_set_tx_mask; 1066 rc->s_tx_mask = mceusb_set_tx_mask;
1079 props->s_tx_carrier = mceusb_set_tx_carrier; 1067 rc->s_tx_carrier = mceusb_set_tx_carrier;
1080 props->tx_ir = mceusb_tx_ir; 1068 rc->tx_ir = mceusb_tx_ir;
1081 } 1069 }
1070 rc->driver_name = DRIVER_NAME;
1071 rc->map_name = mceusb_model[ir->model].rc_map ?
1072 mceusb_model[ir->model].rc_map : RC_MAP_RC6_MCE;
1082 1073
1083 ir->props = props; 1074 ret = rc_register_device(rc);
1084
1085 usb_to_input_id(ir->usbdev, &idev->id);
1086 idev->dev.parent = ir->dev;
1087
1088 if (mceusb_model[ir->model].rc_map)
1089 rc_map = mceusb_model[ir->model].rc_map;
1090
1091 ret = ir_input_register(idev, rc_map, props, DRIVER_NAME);
1092 if (ret < 0) { 1075 if (ret < 0) {
1093 dev_err(dev, "remote input device register failed\n"); 1076 dev_err(dev, "remote dev registration failed\n");
1094 goto irdev_failed; 1077 goto out;
1095 } 1078 }
1096 1079
1097 return idev; 1080 return rc;
1098 1081
1099irdev_failed: 1082out:
1100 kfree(props); 1083 rc_free_device(rc);
1101props_alloc_failed:
1102 input_free_device(idev);
1103idev_alloc_failed:
1104 return NULL; 1084 return NULL;
1105} 1085}
1106 1086
@@ -1212,9 +1192,9 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
1212 snprintf(name + strlen(name), sizeof(name) - strlen(name), 1192 snprintf(name + strlen(name), sizeof(name) - strlen(name),
1213 " %s", buf); 1193 " %s", buf);
1214 1194
1215 ir->idev = mceusb_init_input_dev(ir); 1195 ir->rc = mceusb_init_rc_dev(ir);
1216 if (!ir->idev) 1196 if (!ir->rc)
1217 goto input_dev_fail; 1197 goto rc_dev_fail;
1218 1198
1219 /* flush buffers on the device */ 1199 /* flush buffers on the device */
1220 mce_sync_in(ir, NULL, maxp); 1200 mce_sync_in(ir, NULL, maxp);
@@ -1235,7 +1215,7 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
1235 mceusb_get_parameters(ir); 1215 mceusb_get_parameters(ir);
1236 1216
1237 if (!ir->flags.no_tx) 1217 if (!ir->flags.no_tx)
1238 mceusb_set_tx_mask(ir, MCE_DEFAULT_TX_MASK); 1218 mceusb_set_tx_mask(ir->rc, MCE_DEFAULT_TX_MASK);
1239 1219
1240 usb_set_intfdata(intf, ir); 1220 usb_set_intfdata(intf, ir);
1241 1221
@@ -1245,7 +1225,7 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
1245 return 0; 1225 return 0;
1246 1226
1247 /* Error-handling path */ 1227 /* Error-handling path */
1248input_dev_fail: 1228rc_dev_fail:
1249 usb_free_urb(ir->urb_in); 1229 usb_free_urb(ir->urb_in);
1250urb_in_alloc_fail: 1230urb_in_alloc_fail:
1251 usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in); 1231 usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in);
@@ -1269,7 +1249,7 @@ static void __devexit mceusb_dev_disconnect(struct usb_interface *intf)
1269 return; 1249 return;
1270 1250
1271 ir->usbdev = NULL; 1251 ir->usbdev = NULL;
1272 ir_input_unregister(ir->idev); 1252 rc_unregister_device(ir->rc);
1273 usb_kill_urb(ir->urb_in); 1253 usb_kill_urb(ir->urb_in);
1274 usb_free_urb(ir->urb_in); 1254 usb_free_urb(ir->urb_in);
1275 usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in); 1255 usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);