Skip to content

Commit e589333

Browse files
maximlevitskyMauro Carvalho Chehab
authored andcommitted
V4L/DVB: IR: extend interfaces to support more device settings
LIRC: add new IOCTL that enables learning mode (wide band receiver) Still missing features: carrier report & timeout reports. Will need to pack these into ir_raw_event Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 4a702eb commit e589333

5 files changed

Lines changed: 125 additions & 21 deletions

File tree

‎Documentation/DocBook/v4l/lirc_device_interface.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ on working with the default settings initially.</para>
229229
and LIRC_SETUP_END. Drivers can also choose to ignore these ioctls.</para>
230230
</listitem>
231231
</varlistentry>
232+
<varlistentry>
233+
<term>LIRC_SET_WIDEBAND_RECEIVER</term>
234+
<listitem>
235+
<para>Some receivers are equipped with special wide band receiver which is intended
236+
to be used to learn output of existing remote.
237+
Calling that ioctl with (1) will enable it, and with (0) disable it.
238+
This might be useful of receivers that have otherwise narrow band receiver
239+
that prevents them to be used with some remotes.
240+
Wide band receiver might also be more precise
241+
On the other hand its disadvantage it usually reduced range of reception.
242+
Note: wide band receiver might be implictly enabled if you enable
243+
carrier reports. In that case it will be disabled as soon as you disable
244+
carrier reports. Trying to disable wide band receiver while carrier
245+
reports are active will do nothing.</para>
246+
</listitem>
247+
</varlistentry>
232248
</variablelist>
233249

234250
</section>

‎drivers/media/IR/ir-core-priv.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct ir_raw_event_ctrl {
7979
struct lirc_codec {
8080
struct ir_input_dev *ir_dev;
8181
struct lirc_driver *drv;
82+
int carrier_low;
8283
} lirc;
8384
};
8485

‎drivers/media/IR/ir-lirc-codec.c‎

Lines changed: 93 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
4646
IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
4747
TO_US(ev.duration), TO_STR(ev.pulse));
4848

49-
5049
sample = ev.duration / 1000;
5150
if (ev.pulse)
5251
sample |= PULSE_BIT;
@@ -96,13 +95,14 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char *buf,
9695
return ret;
9796
}
9897

99-
static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
98+
static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
99+
unsigned long __user arg)
100100
{
101101
struct lirc_codec *lirc;
102102
struct ir_input_dev *ir_dev;
103103
int ret = 0;
104104
void *drv_data;
105-
unsigned long val;
105+
unsigned long val = 0;
106106

107107
lirc = lirc_get_pdata(filep);
108108
if (!lirc)
@@ -114,47 +114,106 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long ar
114114

115115
drv_data = ir_dev->props->priv;
116116

117-
switch (cmd) {
118-
case LIRC_SET_TRANSMITTER_MASK:
117+
if (_IOC_DIR(cmd) & _IOC_WRITE) {
119118
ret = get_user(val, (unsigned long *)arg);
120119
if (ret)
121120
return ret;
121+
}
122+
123+
switch (cmd) {
124+
125+
/* legacy support */
126+
case LIRC_GET_SEND_MODE:
127+
val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
128+
break;
129+
130+
case LIRC_SET_SEND_MODE:
131+
if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
132+
return -EINVAL;
133+
break;
122134

123-
if (ir_dev->props && ir_dev->props->s_tx_mask)
135+
/* TX settings */
136+
case LIRC_SET_TRANSMITTER_MASK:
137+
if (ir_dev->props->s_tx_mask)
124138
ret = ir_dev->props->s_tx_mask(drv_data, (u32)val);
125139
else
126140
return -EINVAL;
127141
break;
128142

129143
case LIRC_SET_SEND_CARRIER:
130-
ret = get_user(val, (unsigned long *)arg);
131-
if (ret)
132-
return ret;
133-
134-
if (ir_dev->props && ir_dev->props->s_tx_carrier)
144+
if (ir_dev->props->s_tx_carrier)
135145
ir_dev->props->s_tx_carrier(drv_data, (u32)val);
136146
else
137147
return -EINVAL;
138148
break;
139149

140-
case LIRC_GET_SEND_MODE:
141-
val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
142-
ret = put_user(val, (unsigned long *)arg);
150+
case LIRC_SET_SEND_DUTY_CYCLE:
151+
if (!ir_dev->props->s_tx_duty_cycle)
152+
return -ENOSYS;
153+
154+
if (val <= 0 || val >= 100)
155+
return -EINVAL;
156+
157+
ir_dev->props->s_tx_duty_cycle(ir_dev->props->priv, val);
143158
break;
144159

145-
case LIRC_SET_SEND_MODE:
146-
ret = get_user(val, (unsigned long *)arg);
147-
if (ret)
148-
return ret;
160+
/* RX settings */
161+
case LIRC_SET_REC_CARRIER:
162+
if (ir_dev->props->s_rx_carrier_range)
163+
ret = ir_dev->props->s_rx_carrier_range(
164+
ir_dev->props->priv,
165+
ir_dev->raw->lirc.carrier_low, val);
166+
else
167+
return -ENOSYS;
149168

150-
if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
169+
if (!ret)
170+
ir_dev->raw->lirc.carrier_low = 0;
171+
break;
172+
173+
case LIRC_SET_REC_CARRIER_RANGE:
174+
if (val >= 0)
175+
ir_dev->raw->lirc.carrier_low = val;
176+
break;
177+
178+
179+
case LIRC_GET_REC_RESOLUTION:
180+
val = ir_dev->props->rx_resolution;
181+
break;
182+
183+
case LIRC_SET_WIDEBAND_RECEIVER:
184+
if (ir_dev->props->s_learning_mode)
185+
return ir_dev->props->s_learning_mode(
186+
ir_dev->props->priv, !!val);
187+
else
188+
return -ENOSYS;
189+
190+
/* Generic timeout support */
191+
case LIRC_GET_MIN_TIMEOUT:
192+
if (!ir_dev->props->max_timeout)
193+
return -ENOSYS;
194+
val = ir_dev->props->min_timeout / 1000;
195+
break;
196+
197+
case LIRC_GET_MAX_TIMEOUT:
198+
if (!ir_dev->props->max_timeout)
199+
return -ENOSYS;
200+
val = ir_dev->props->max_timeout / 1000;
201+
break;
202+
203+
case LIRC_SET_REC_TIMEOUT:
204+
if (val < ir_dev->props->min_timeout ||
205+
val > ir_dev->props->max_timeout)
151206
return -EINVAL;
207+
ir_dev->props->timeout = val * 1000;
152208
break;
153209

154210
default:
155211
return lirc_dev_fop_ioctl(filep, cmd, arg);
156212
}
157213

214+
if (_IOC_DIR(cmd) & _IOC_READ)
215+
ret = put_user(val, (unsigned long *)arg);
216+
158217
return ret;
159218
}
160219

@@ -200,13 +259,28 @@ static int ir_lirc_register(struct input_dev *input_dev)
200259

201260
features = LIRC_CAN_REC_MODE2;
202261
if (ir_dev->props->tx_ir) {
262+
203263
features |= LIRC_CAN_SEND_PULSE;
204264
if (ir_dev->props->s_tx_mask)
205265
features |= LIRC_CAN_SET_TRANSMITTER_MASK;
206266
if (ir_dev->props->s_tx_carrier)
207267
features |= LIRC_CAN_SET_SEND_CARRIER;
268+
269+
if (ir_dev->props->s_tx_duty_cycle)
270+
features |= LIRC_CAN_SET_REC_DUTY_CYCLE;
208271
}
209272

273+
if (ir_dev->props->s_rx_carrier_range)
274+
features |= LIRC_CAN_SET_REC_CARRIER |
275+
LIRC_CAN_SET_REC_CARRIER_RANGE;
276+
277+
if (ir_dev->props->s_learning_mode)
278+
features |= LIRC_CAN_USE_WIDEBAND_RECEIVER;
279+
280+
if (ir_dev->props->max_timeout)
281+
features |= LIRC_CAN_SET_REC_TIMEOUT;
282+
283+
210284
snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)",
211285
ir_dev->driver_name);
212286
drv->minor = -1;

‎include/media/ir-core.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ enum rc_driver_type {
4444
* @timeout: optional time after which device stops sending data
4545
* @min_timeout: minimum timeout supported by device
4646
* @max_timeout: maximum timeout supported by device
47+
* @rx_resolution : resolution (in ns) of input sampler
48+
* @tx_resolution: resolution (in ns) of output sampler
4749
* @priv: driver-specific data, to be used on the callbacks
4850
* @change_protocol: allow changing the protocol used on hardware decoders
4951
* @open: callback to allow drivers to enable polling/irq when IR input device
@@ -52,9 +54,12 @@ enum rc_driver_type {
5254
* is opened.
5355
* @s_tx_mask: set transmitter mask (for devices with multiple tx outputs)
5456
* @s_tx_carrier: set transmit carrier frequency
57+
* @s_tx_duty_cycle: set transmit duty cycle (0% - 100%)
58+
* @s_rx_carrier: inform driver about carrier it is expected to handle
5559
* @tx_ir: transmit IR
5660
* @s_idle: optional: enable/disable hardware idle mode, upon which,
57-
* device doesn't interrupt host untill it sees IR data
61+
device doesn't interrupt host until it sees IR pulses
62+
* @s_learning_mode: enable wide band receiver used for learning
5863
*/
5964
struct ir_dev_props {
6065
enum rc_driver_type driver_type;
@@ -65,15 +70,20 @@ struct ir_dev_props {
6570
u32 min_timeout;
6671
u32 max_timeout;
6772

73+
u32 rx_resolution;
74+
u32 tx_resolution;
6875

6976
void *priv;
7077
int (*change_protocol)(void *priv, u64 ir_type);
7178
int (*open)(void *priv);
7279
void (*close)(void *priv);
7380
int (*s_tx_mask)(void *priv, u32 mask);
7481
int (*s_tx_carrier)(void *priv, u32 carrier);
82+
int (*s_tx_duty_cycle)(void *priv, u32 duty_cycle);
83+
int (*s_rx_carrier_range)(void *priv, u32 min, u32 max);
7584
int (*tx_ir)(void *priv, int *txbuf, u32 n);
7685
void (*s_idle)(void *priv, int enable);
86+
int (*s_learning_mode)(void *priv, int enable);
7787
};
7888

7989
struct ir_input_dev {

‎include/media/lirc.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#define LIRC_CAN_SET_REC_FILTER 0x08000000
7878

7979
#define LIRC_CAN_MEASURE_CARRIER 0x02000000
80+
#define LIRC_CAN_USE_WIDEBAND_RECEIVER 0x04000000
8081

8182
#define LIRC_CAN_SEND(x) ((x)&LIRC_CAN_SEND_MASK)
8283
#define LIRC_CAN_REC(x) ((x)&LIRC_CAN_REC_MASK)
@@ -145,7 +146,7 @@
145146
* if enabled from the next key press on the driver will send
146147
* LIRC_MODE2_FREQUENCY packets
147148
*/
148-
#define LIRC_SET_MEASURE_CARRIER_MODE _IOW('i', 0x0000001d, __u32)
149+
#define LIRC_SET_MEASURE_CARRIER_MODE _IOW('i', 0x0000001d, __u32)
149150

150151
/*
151152
* to set a range use
@@ -162,4 +163,6 @@
162163
#define LIRC_SETUP_START _IO('i', 0x00000021)
163164
#define LIRC_SETUP_END _IO('i', 0x00000022)
164165

166+
#define LIRC_SET_WIDEBAND_RECEIVER _IOW('i', 0x00000023, __u32)
167+
165168
#endif

0 commit comments

Comments
 (0)