Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] rc: fix up and genericize some time unit conversions

The ene_ir driver was using a private define of MS_TO_NS, which is meant
to be microseconds to nanoseconds. The mceusb driver copied it,
intending to use is a milliseconds to microseconds. Lets move the
defines to a common location, expand and standardize them a touch, so
that we now have:

MS_TO_NS - milliseconds to nanoseconds
MS_TO_US - milliseconds to microseconds
US_TO_NS - microseconds to nanoseconds

Reported-by: David Härdeman <david@hardeman.nu>
CC: Maxim Levitsky <maximlevitsky@gmail.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Jarod Wilson and committed by
Mauro Carvalho Chehab
5aad7242 9ad77eb5

+14 -14
+8 -8
drivers/media/rc/ene_ir.c
··· 446 446 447 447 select_timeout: 448 448 if (dev->rx_fan_input_inuse) { 449 - dev->rdev->rx_resolution = MS_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN); 449 + dev->rdev->rx_resolution = US_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN); 450 450 451 451 /* Fan input doesn't support timeouts, it just ends the 452 452 input with a maximum sample */ 453 453 dev->rdev->min_timeout = dev->rdev->max_timeout = 454 - MS_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK * 454 + US_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK * 455 455 ENE_FW_SAMPLE_PERIOD_FAN); 456 456 } else { 457 - dev->rdev->rx_resolution = MS_TO_NS(sample_period); 457 + dev->rdev->rx_resolution = US_TO_NS(sample_period); 458 458 459 459 /* Theoreticly timeout is unlimited, but we cap it 460 460 * because it was seen that on one device, it 461 461 * would stop sending spaces after around 250 msec. 462 462 * Besides, this is close to 2^32 anyway and timeout is u32. 463 463 */ 464 - dev->rdev->min_timeout = MS_TO_NS(127 * sample_period); 465 - dev->rdev->max_timeout = MS_TO_NS(200000); 464 + dev->rdev->min_timeout = US_TO_NS(127 * sample_period); 465 + dev->rdev->max_timeout = US_TO_NS(200000); 466 466 } 467 467 468 468 if (dev->hw_learning_and_tx_capable) 469 - dev->rdev->tx_resolution = MS_TO_NS(sample_period); 469 + dev->rdev->tx_resolution = US_TO_NS(sample_period); 470 470 471 471 if (dev->rdev->timeout > dev->rdev->max_timeout) 472 472 dev->rdev->timeout = dev->rdev->max_timeout; ··· 801 801 802 802 dbg("RX: %d (%s)", hw_sample, pulse ? "pulse" : "space"); 803 803 804 - ev.duration = MS_TO_NS(hw_sample); 804 + ev.duration = US_TO_NS(hw_sample); 805 805 ev.pulse = pulse; 806 806 ir_raw_event_store_with_filter(dev->rdev, &ev); 807 807 } ··· 821 821 dev->learning_mode_enabled = learning_mode_force; 822 822 823 823 /* Set reasonable default timeout */ 824 - dev->rdev->timeout = MS_TO_NS(150000); 824 + dev->rdev->timeout = US_TO_NS(150000); 825 825 } 826 826 827 827 /* Upload all hardware settings at once. Used at load and resume time */
-2
drivers/media/rc/ene_ir.h
··· 201 201 #define dbg_verbose(format, ...) __dbg(2, format, ## __VA_ARGS__) 202 202 #define dbg_regs(format, ...) __dbg(3, format, ## __VA_ARGS__) 203 203 204 - #define MS_TO_NS(msec) ((msec) * 1000) 205 - 206 204 struct ene_device { 207 205 struct pnp_dev *pnp_dev; 208 206 struct rc_dev *rdev;
+3 -4
drivers/media/rc/mceusb.c
··· 48 48 #define USB_BUFLEN 32 /* USB reception buffer length */ 49 49 #define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */ 50 50 #define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */ 51 - #define MS_TO_NS(msec) ((msec) * 1000) 52 51 53 52 /* MCE constants */ 54 53 #define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */ ··· 816 817 switch (ir->buf_in[index]) { 817 818 /* 2-byte return value commands */ 818 819 case MCE_CMD_S_TIMEOUT: 819 - ir->rc->timeout = MS_TO_NS((hi << 8 | lo) / 2); 820 + ir->rc->timeout = MS_TO_US((hi << 8 | lo) / 2); 820 821 break; 821 822 822 823 /* 1-byte return value commands */ ··· 857 858 ir->rem--; 858 859 rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0); 859 860 rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK) 860 - * MS_TO_NS(MCE_TIME_UNIT); 861 + * MS_TO_US(MCE_TIME_UNIT); 861 862 862 863 dev_dbg(ir->dev, "Storing %s with duration %d\n", 863 864 rawir.pulse ? "pulse" : "space", ··· 1060 1061 rc->priv = ir; 1061 1062 rc->driver_type = RC_DRIVER_IR_RAW; 1062 1063 rc->allowed_protos = RC_TYPE_ALL; 1063 - rc->timeout = MS_TO_NS(1000); 1064 + rc->timeout = MS_TO_US(1000); 1064 1065 if (!ir->flags.no_tx) { 1065 1066 rc->s_tx_mask = mceusb_set_tx_mask; 1066 1067 rc->s_tx_carrier = mceusb_set_tx_carrier;
+3
include/media/rc-core.h
··· 183 183 } 184 184 185 185 #define IR_MAX_DURATION 0xFFFFFFFF /* a bit more than 4 seconds */ 186 + #define US_TO_NS(usec) ((usec) * 1000) 187 + #define MS_TO_US(msec) ((msec) * 1000) 188 + #define MS_TO_NS(msec) ((msec) * 1000 * 1000) 186 189 187 190 void ir_raw_event_handle(struct rc_dev *dev); 188 191 int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev);