Commit 9719afae5e589b409e137c36f89073d134f0de33

Authored by David Härdeman
Committed by Mauro Carvalho Chehab
1 parent efa914d7d0

[media] rc-core: don't treat dev->rc_map.rc_type as a bitmap

store_protocols() treats dev->rc_map.rc_type as a bitmap which is wrong for
two reasons. First of all, it is pretty bogus to change the protocol type of
the keymap just because the hardware has been asked to decode a different
protocol.
Second, dev->rc_map.rc_type is an enum (i.e. a single protocol) as pointed
out by James Hogan <james.hogan@imgtec.com>.
Fix both issues by introducing a separate enabled_protocols member to
struct rc_dev.

Signed-off-by: David Härdeman <david@hardeman.nu>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

Showing 14 changed files with 28 additions and 38 deletions Side-by-side Diff

drivers/media/i2c/ir-kbd-i2c.c
... ... @@ -423,6 +423,7 @@
423 423 */
424 424 rc->map_name = ir->ir_codes;
425 425 rc->allowed_protos = rc_type;
  426 + rc->enabled_protocols = rc_type;
426 427 if (!rc->driver_name)
427 428 rc->driver_name = MODULE_NAME;
428 429  
drivers/media/rc/ir-jvc-decoder.c
... ... @@ -47,7 +47,7 @@
47 47 {
48 48 struct jvc_dec *data = &dev->raw->jvc;
49 49  
50   - if (!(dev->raw->enabled_protocols & RC_BIT_JVC))
  50 + if (!(dev->enabled_protocols & RC_BIT_JVC))
51 51 return 0;
52 52  
53 53 if (!is_timing_event(ev)) {
drivers/media/rc/ir-lirc-codec.c
... ... @@ -35,7 +35,7 @@
35 35 struct lirc_codec *lirc = &dev->raw->lirc;
36 36 int sample;
37 37  
38   - if (!(dev->raw->enabled_protocols & RC_BIT_LIRC))
  38 + if (!(dev->enabled_protocols & RC_BIT_LIRC))
39 39 return 0;
40 40  
41 41 if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf)
drivers/media/rc/ir-mce_kbd-decoder.c
... ... @@ -216,7 +216,7 @@
216 216 u32 scancode;
217 217 unsigned long delay;
218 218  
219   - if (!(dev->raw->enabled_protocols & RC_BIT_MCE_KBD))
  219 + if (!(dev->enabled_protocols & RC_BIT_MCE_KBD))
220 220 return 0;
221 221  
222 222 if (!is_timing_event(ev)) {
drivers/media/rc/ir-nec-decoder.c
... ... @@ -52,7 +52,7 @@
52 52 u8 address, not_address, command, not_command;
53 53 bool send_32bits = false;
54 54  
55   - if (!(dev->raw->enabled_protocols & RC_BIT_NEC))
  55 + if (!(dev->enabled_protocols & RC_BIT_NEC))
56 56 return 0;
57 57  
58 58 if (!is_timing_event(ev)) {
drivers/media/rc/ir-raw.c
... ... @@ -256,7 +256,7 @@
256 256 return -ENOMEM;
257 257  
258 258 dev->raw->dev = dev;
259   - dev->raw->enabled_protocols = ~0;
  259 + dev->enabled_protocols = ~0;
260 260 rc = kfifo_alloc(&dev->raw->kfifo,
261 261 sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE,
262 262 GFP_KERNEL);
drivers/media/rc/ir-rc5-decoder.c
... ... @@ -52,7 +52,7 @@
52 52 u8 toggle;
53 53 u32 scancode;
54 54  
55   - if (!(dev->raw->enabled_protocols & (RC_BIT_RC5 | RC_BIT_RC5X)))
  55 + if (!(dev->enabled_protocols & (RC_BIT_RC5 | RC_BIT_RC5X)))
56 56 return 0;
57 57  
58 58 if (!is_timing_event(ev)) {
... ... @@ -128,7 +128,7 @@
128 128 if (data->wanted_bits == RC5X_NBITS) {
129 129 /* RC5X */
130 130 u8 xdata, command, system;
131   - if (!(dev->raw->enabled_protocols & RC_BIT_RC5X)) {
  131 + if (!(dev->enabled_protocols & RC_BIT_RC5X)) {
132 132 data->state = STATE_INACTIVE;
133 133 return 0;
134 134 }
... ... @@ -145,7 +145,7 @@
145 145 } else {
146 146 /* RC5 */
147 147 u8 command, system;
148   - if (!(dev->raw->enabled_protocols & RC_BIT_RC5)) {
  148 + if (!(dev->enabled_protocols & RC_BIT_RC5)) {
149 149 data->state = STATE_INACTIVE;
150 150 return 0;
151 151 }
drivers/media/rc/ir-rc5-sz-decoder.c
... ... @@ -48,7 +48,7 @@
48 48 u8 toggle, command, system;
49 49 u32 scancode;
50 50  
51   - if (!(dev->raw->enabled_protocols & RC_BIT_RC5_SZ))
  51 + if (!(dev->enabled_protocols & RC_BIT_RC5_SZ))
52 52 return 0;
53 53  
54 54 if (!is_timing_event(ev)) {
drivers/media/rc/ir-rc6-decoder.c
... ... @@ -89,7 +89,7 @@
89 89 u32 scancode;
90 90 u8 toggle;
91 91  
92   - if (!(dev->raw->enabled_protocols &
  92 + if (!(dev->enabled_protocols &
93 93 (RC_BIT_RC6_0 | RC_BIT_RC6_6A_20 | RC_BIT_RC6_6A_24 |
94 94 RC_BIT_RC6_6A_32 | RC_BIT_RC6_MCE)))
95 95 return 0;
drivers/media/rc/ir-sanyo-decoder.c
... ... @@ -58,7 +58,7 @@
58 58 u32 scancode;
59 59 u8 address, command, not_command;
60 60  
61   - if (!(dev->raw->enabled_protocols & RC_BIT_SANYO))
  61 + if (!(dev->enabled_protocols & RC_BIT_SANYO))
62 62 return 0;
63 63  
64 64 if (!is_timing_event(ev)) {
drivers/media/rc/ir-sony-decoder.c
... ... @@ -45,7 +45,7 @@
45 45 u32 scancode;
46 46 u8 device, subdevice, function;
47 47  
48   - if (!(dev->raw->enabled_protocols &
  48 + if (!(dev->enabled_protocols &
49 49 (RC_BIT_SONY12 | RC_BIT_SONY15 | RC_BIT_SONY20)))
50 50 return 0;
51 51  
... ... @@ -124,7 +124,7 @@
124 124  
125 125 switch (data->count) {
126 126 case 12:
127   - if (!(dev->raw->enabled_protocols & RC_BIT_SONY12)) {
  127 + if (!(dev->enabled_protocols & RC_BIT_SONY12)) {
128 128 data->state = STATE_INACTIVE;
129 129 return 0;
130 130 }
... ... @@ -133,7 +133,7 @@
133 133 function = bitrev8((data->bits >> 4) & 0xFE);
134 134 break;
135 135 case 15:
136   - if (!(dev->raw->enabled_protocols & RC_BIT_SONY15)) {
  136 + if (!(dev->enabled_protocols & RC_BIT_SONY15)) {
137 137 data->state = STATE_INACTIVE;
138 138 return 0;
139 139 }
... ... @@ -142,7 +142,7 @@
142 142 function = bitrev8((data->bits >> 7) & 0xFE);
143 143 break;
144 144 case 20:
145   - if (!(dev->raw->enabled_protocols & RC_BIT_SONY20)) {
  145 + if (!(dev->enabled_protocols & RC_BIT_SONY20)) {
146 146 data->state = STATE_INACTIVE;
147 147 return 0;
148 148 }
drivers/media/rc/rc-core-priv.h
... ... @@ -39,7 +39,6 @@
39 39 ktime_t last_event; /* when last event occurred */
40 40 enum raw_event_type last_type; /* last event type */
41 41 struct rc_dev *dev; /* pointer to the parent rc_dev */
42   - u64 enabled_protocols; /* enabled raw protocol decoders */
43 42  
44 43 /* raw decoder state follows */
45 44 struct ir_raw_event prev_ev;
drivers/media/rc/rc-main.c
... ... @@ -783,13 +783,12 @@
783 783  
784 784 mutex_lock(&dev->lock);
785 785  
786   - if (dev->driver_type == RC_DRIVER_SCANCODE) {
787   - enabled = dev->rc_map.rc_type;
  786 + enabled = dev->enabled_protocols;
  787 + if (dev->driver_type == RC_DRIVER_SCANCODE)
788 788 allowed = dev->allowed_protos;
789   - } else if (dev->raw) {
790   - enabled = dev->raw->enabled_protocols;
  789 + else if (dev->raw)
791 790 allowed = ir_raw_get_allowed_protocols();
792   - } else {
  791 + else {
793 792 mutex_unlock(&dev->lock);
794 793 return -ENODEV;
795 794 }
... ... @@ -847,7 +846,6 @@
847 846 u64 type;
848 847 u64 mask;
849 848 int rc, i, count = 0;
850   - unsigned long flags;
851 849 ssize_t ret;
852 850  
853 851 /* Device is being removed */
854 852  
... ... @@ -856,15 +854,12 @@
856 854  
857 855 mutex_lock(&dev->lock);
858 856  
859   - if (dev->driver_type == RC_DRIVER_SCANCODE)
860   - type = dev->rc_map.rc_type;
861   - else if (dev->raw)
862   - type = dev->raw->enabled_protocols;
863   - else {
  857 + if (dev->driver_type != RC_DRIVER_SCANCODE && !dev->raw) {
864 858 IR_dprintk(1, "Protocol switching not supported\n");
865 859 ret = -EINVAL;
866 860 goto out;
867 861 }
  862 + type = dev->enabled_protocols;
868 863  
869 864 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
870 865 if (!*tmp)
... ... @@ -922,14 +917,7 @@
922 917 }
923 918 }
924 919  
925   - if (dev->driver_type == RC_DRIVER_SCANCODE) {
926   - spin_lock_irqsave(&dev->rc_map.lock, flags);
927   - dev->rc_map.rc_type = type;
928   - spin_unlock_irqrestore(&dev->rc_map.lock, flags);
929   - } else {
930   - dev->raw->enabled_protocols = type;
931   - }
932   -
  920 + dev->enabled_protocols = type;
933 921 IR_dprintk(1, "Current protocol(s): 0x%llx\n",
934 922 (long long)type);
935 923  
... ... @@ -1068,9 +1056,8 @@
1068 1056 /*
1069 1057 * Take the lock here, as the device sysfs node will appear
1070 1058 * when device_add() is called, which may trigger an ir-keytable udev
1071   - * rule, which will in turn call show_protocols and access either
1072   - * dev->rc_map.rc_type or dev->raw->enabled_protocols before it has
1073   - * been initialized.
  1059 + * rule, which will in turn call show_protocols and access
  1060 + * dev->enabled_protocols before it has been initialized.
1074 1061 */
1075 1062 mutex_lock(&dev->lock);
1076 1063  
... ... @@ -1132,6 +1119,7 @@
1132 1119 rc = dev->change_protocol(dev, &rc_type);
1133 1120 if (rc < 0)
1134 1121 goto out_raw;
  1122 + dev->enabled_protocols = rc_type;
1135 1123 }
1136 1124  
1137 1125 mutex_unlock(&dev->lock);
include/media/rc-core.h
... ... @@ -51,6 +51,7 @@
51 51 * @driver_type: specifies if protocol decoding is done in hardware or software
52 52 * @idle: used to keep track of RX state
53 53 * @allowed_protos: bitmask with the supported RC_BIT_* protocols
  54 + * @enabled_protocols: bitmask with the enabled RC_BIT_* protocols
54 55 * @scanmask: some hardware decoders are not capable of providing the full
55 56 * scancode to the application. As this is a hardware limit, we can't do
56 57 * anything with it. Yet, as the same keycode table can be used with other
... ... @@ -99,6 +100,7 @@
99 100 enum rc_driver_type driver_type;
100 101 bool idle;
101 102 u64 allowed_protos;
  103 + u64 enabled_protocols;
102 104 u32 scanmask;
103 105 void *priv;
104 106 spinlock_t keylock;