Skip to content

Commit d71f787

Browse files
warped-rudijnettlet
authored andcommitted
MXC-CEC: Change return codes and add poll support for write function
Allow userland to distinguish between a NAKs and real error conditions. Return EAGAIN in case no monitor is plugged in or a previous transmission is still pending. Signed-off-by: Rudi <[email protected]>
1 parent 9512229 commit d71f787

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

drivers/mxc/hdmi-cec/mxc_hdmi-cec.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ static int hdmi_cec_open(struct inode *inode, struct file *file)
334334
}
335335
hdmi_cec_data.open_count = 1;
336336
file->private_data = (void *)(&hdmi_cec_data);
337+
hdmi_cec_data.tx_answer = CEC_TX_AVAIL;
337338
hdmi_cec_data.logical_address = 15;
338339
hdmi_cec_data.is_started = false;
339340
mutex_unlock(&hdmi_cec_data.lock);
@@ -399,7 +400,9 @@ static ssize_t hdmi_cec_write(struct file *file, const char __user *buf,
399400
if (!hdmi_cec_data.is_started)
400401
ret = -EACCES;
401402
else if (hdmi_cec_data.tx_answer != CEC_TX_AVAIL)
402-
ret = -EBUSY;
403+
ret = -EAGAIN;
404+
else if (hdmi_cec_data.link_status != 1)
405+
ret = -EAGAIN;
403406
else if (count > MAX_MESSAGE_LEN)
404407
ret = -EINVAL;
405408
else if (copy_from_user(msg, buf, count))
@@ -426,18 +429,15 @@ static ssize_t hdmi_cec_write(struct file *file, const char __user *buf,
426429
ret = wait_event_interruptible_timeout(
427430
tx_queue, hdmi_cec_data.tx_answer != CEC_TX_INPROGRESS, HZ);
428431

429-
if (ret < 0) {
432+
if (ret < 0)
430433
ret = -ERESTARTSYS;
431-
goto tx_out;
432-
}
433-
434-
if (hdmi_cec_data.tx_answer & HDMI_IH_CEC_STAT0_DONE)
435-
/* msg correctly sent */
436-
ret = msg_len;
434+
else if (hdmi_cec_data.tx_answer & HDMI_IH_CEC_STAT0_DONE)
435+
ret = msg_len; /* msg sent, ACK received */
436+
else if (hdmi_cec_data.tx_answer & HDMI_IH_CEC_STAT0_NACK)
437+
ret = -EIO; /* msg sent, NACK received */
437438
else
438-
ret = -EIO;
439+
ret = -EPIPE; /* other error */
439440

440-
tx_out:
441441
hdmi_cec_data.tx_answer = CEC_TX_AVAIL;
442442
return ret;
443443
}
@@ -580,6 +580,7 @@ static int hdmi_cec_release(struct inode *inode, struct file *file)
580580
hdmi_cec_data.open_count = 0;
581581
hdmi_cec_data.is_started = false;
582582
hdmi_cec_data.logical_address = 15;
583+
hdmi_cec_data.tx_answer = CEC_TX_AVAIL;
583584

584585
free_events();
585586
}
@@ -595,13 +596,17 @@ static unsigned int hdmi_cec_poll(struct file *file, poll_table *wait)
595596
pr_debug("function : %s\n", __func__);
596597

597598
poll_wait(file, &rx_queue, wait);
599+
poll_wait(file, &tx_queue, wait);
600+
601+
if (hdmi_cec_data.link_status == 1 &&
602+
hdmi_cec_data.tx_answer == CEC_TX_AVAIL)
603+
mask |= POLLOUT | POLLWRNORM;
598604

599605
mutex_lock(&hdmi_cec_data.lock);
600-
if (hdmi_cec_data.tx_answer == CEC_TX_AVAIL)
601-
mask = (POLLOUT | POLLWRNORM);
602606
if (!list_empty(&ev_pending))
603-
mask |= (POLLIN | POLLRDNORM);
607+
mask |= POLLIN | POLLRDNORM;
604608
mutex_unlock(&hdmi_cec_data.lock);
609+
605610
return mask;
606611
}
607612

0 commit comments

Comments
 (0)