Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aad7242 authored by Jarod Wilson's avatar Jarod Wilson Committed by Mauro Carvalho Chehab
Browse files

[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: default avatarDavid Härdeman <david@hardeman.nu>
CC: Maxim Levitsky <maximlevitsky@gmail.com>
Signed-off-by: default avatarJarod Wilson <jarod@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 9ad77eb5
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -446,27 +446,27 @@ static void ene_rx_setup(struct ene_device *dev)


select_timeout:
select_timeout:
	if (dev->rx_fan_input_inuse) {
	if (dev->rx_fan_input_inuse) {
		dev->rdev->rx_resolution = MS_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN);
		dev->rdev->rx_resolution = US_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN);


		/* Fan input doesn't support timeouts, it just ends the
		/* Fan input doesn't support timeouts, it just ends the
			input with a maximum sample */
			input with a maximum sample */
		dev->rdev->min_timeout = dev->rdev->max_timeout =
		dev->rdev->min_timeout = dev->rdev->max_timeout =
			MS_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK *
			US_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK *
				ENE_FW_SAMPLE_PERIOD_FAN);
				ENE_FW_SAMPLE_PERIOD_FAN);
	} else {
	} else {
		dev->rdev->rx_resolution = MS_TO_NS(sample_period);
		dev->rdev->rx_resolution = US_TO_NS(sample_period);


		/* Theoreticly timeout is unlimited, but we cap it
		/* Theoreticly timeout is unlimited, but we cap it
		 * because it was seen that on one device, it
		 * because it was seen that on one device, it
		 * would stop sending spaces after around 250 msec.
		 * would stop sending spaces after around 250 msec.
		 * Besides, this is close to 2^32 anyway and timeout is u32.
		 * Besides, this is close to 2^32 anyway and timeout is u32.
		 */
		 */
		dev->rdev->min_timeout = MS_TO_NS(127 * sample_period);
		dev->rdev->min_timeout = US_TO_NS(127 * sample_period);
		dev->rdev->max_timeout = MS_TO_NS(200000);
		dev->rdev->max_timeout = US_TO_NS(200000);
	}
	}


	if (dev->hw_learning_and_tx_capable)
	if (dev->hw_learning_and_tx_capable)
		dev->rdev->tx_resolution = MS_TO_NS(sample_period);
		dev->rdev->tx_resolution = US_TO_NS(sample_period);


	if (dev->rdev->timeout > dev->rdev->max_timeout)
	if (dev->rdev->timeout > dev->rdev->max_timeout)
		dev->rdev->timeout = dev->rdev->max_timeout;
		dev->rdev->timeout = dev->rdev->max_timeout;
@@ -801,7 +801,7 @@ static irqreturn_t ene_isr(int irq, void *data)


		dbg("RX: %d (%s)", hw_sample, pulse ? "pulse" : "space");
		dbg("RX: %d (%s)", hw_sample, pulse ? "pulse" : "space");


		ev.duration = MS_TO_NS(hw_sample);
		ev.duration = US_TO_NS(hw_sample);
		ev.pulse = pulse;
		ev.pulse = pulse;
		ir_raw_event_store_with_filter(dev->rdev, &ev);
		ir_raw_event_store_with_filter(dev->rdev, &ev);
	}
	}
@@ -821,7 +821,7 @@ static void ene_setup_default_settings(struct ene_device *dev)
	dev->learning_mode_enabled = learning_mode_force;
	dev->learning_mode_enabled = learning_mode_force;


	/* Set reasonable default timeout */
	/* Set reasonable default timeout */
	dev->rdev->timeout = MS_TO_NS(150000);
	dev->rdev->timeout = US_TO_NS(150000);
}
}


/* Upload all hardware settings at once. Used at load and resume time */
/* Upload all hardware settings at once. Used at load and resume time */
+0 −2
Original line number Original line Diff line number Diff line
@@ -201,8 +201,6 @@
#define dbg_verbose(format, ...)	__dbg(2, format, ## __VA_ARGS__)
#define dbg_verbose(format, ...)	__dbg(2, format, ## __VA_ARGS__)
#define dbg_regs(format, ...)		__dbg(3, format, ## __VA_ARGS__)
#define dbg_regs(format, ...)		__dbg(3, format, ## __VA_ARGS__)


#define MS_TO_NS(msec) ((msec) * 1000)

struct ene_device {
struct ene_device {
	struct pnp_dev *pnp_dev;
	struct pnp_dev *pnp_dev;
	struct rc_dev *rdev;
	struct rc_dev *rdev;
+3 −4
Original line number Original line Diff line number Diff line
@@ -48,7 +48,6 @@
#define USB_BUFLEN		32 /* USB reception buffer length */
#define USB_BUFLEN		32 /* USB reception buffer length */
#define USB_CTRL_MSG_SZ		2  /* Size of usb ctrl msg on gen1 hw */
#define USB_CTRL_MSG_SZ		2  /* Size of usb ctrl msg on gen1 hw */
#define MCE_G1_INIT_MSGS	40 /* Init messages on gen1 hw to throw out */
#define MCE_G1_INIT_MSGS	40 /* Init messages on gen1 hw to throw out */
#define MS_TO_NS(msec)		((msec) * 1000)


/* MCE constants */
/* MCE constants */
#define MCE_CMDBUF_SIZE		384  /* MCE Command buffer length */
#define MCE_CMDBUF_SIZE		384  /* MCE Command buffer length */
@@ -817,7 +816,7 @@ static void mceusb_handle_command(struct mceusb_dev *ir, int index)
	switch (ir->buf_in[index]) {
	switch (ir->buf_in[index]) {
	/* 2-byte return value commands */
	/* 2-byte return value commands */
	case MCE_CMD_S_TIMEOUT:
	case MCE_CMD_S_TIMEOUT:
		ir->rc->timeout = MS_TO_NS((hi << 8 | lo) / 2);
		ir->rc->timeout = MS_TO_US((hi << 8 | lo) / 2);
		break;
		break;


	/* 1-byte return value commands */
	/* 1-byte return value commands */
@@ -858,7 +857,7 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
			ir->rem--;
			ir->rem--;
			rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0);
			rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0);
			rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK)
			rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK)
					 * MS_TO_NS(MCE_TIME_UNIT);
					 * MS_TO_US(MCE_TIME_UNIT);


			dev_dbg(ir->dev, "Storing %s with duration %d\n",
			dev_dbg(ir->dev, "Storing %s with duration %d\n",
				rawir.pulse ? "pulse" : "space",
				rawir.pulse ? "pulse" : "space",
@@ -1061,7 +1060,7 @@ static struct rc_dev *mceusb_init_rc_dev(struct mceusb_dev *ir)
	rc->priv = ir;
	rc->priv = ir;
	rc->driver_type = RC_DRIVER_IR_RAW;
	rc->driver_type = RC_DRIVER_IR_RAW;
	rc->allowed_protos = RC_TYPE_ALL;
	rc->allowed_protos = RC_TYPE_ALL;
	rc->timeout = MS_TO_NS(1000);
	rc->timeout = MS_TO_US(1000);
	if (!ir->flags.no_tx) {
	if (!ir->flags.no_tx) {
		rc->s_tx_mask = mceusb_set_tx_mask;
		rc->s_tx_mask = mceusb_set_tx_mask;
		rc->s_tx_carrier = mceusb_set_tx_carrier;
		rc->s_tx_carrier = mceusb_set_tx_carrier;
+3 −0
Original line number Original line Diff line number Diff line
@@ -183,6 +183,9 @@ static inline void init_ir_raw_event(struct ir_raw_event *ev)
}
}


#define IR_MAX_DURATION         0xFFFFFFFF      /* a bit more than 4 seconds */
#define IR_MAX_DURATION         0xFFFFFFFF      /* a bit more than 4 seconds */
#define US_TO_NS(usec)		((usec) * 1000)
#define MS_TO_US(msec)		((msec) * 1000)
#define MS_TO_NS(msec)		((msec) * 1000 * 1000)


void ir_raw_event_handle(struct rc_dev *dev);
void ir_raw_event_handle(struct rc_dev *dev);
int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev);
int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev);