Skip to content

Commit f3e3692

Browse files
warped-rudijnettlet
authored andcommitted
MXC-CEC: Reorder functions for better readability and more logical flow
Signed-off-by: Rudi <[email protected]>
1 parent e48d93a commit f3e3692

File tree

1 file changed

+108
-108
lines changed

1 file changed

+108
-108
lines changed

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

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,83 @@ static void mxc_hdmi_cec_worker(struct work_struct *work)
329329
spin_unlock_irqrestore(&priv->irq_lock, flags);
330330
}
331331

332+
void hdmi_cec_hpd_changed(unsigned int state)
333+
{
334+
u32 cec_stat0;
335+
unsigned long flags;
336+
struct hdmi_cec_priv *priv = &hdmi_cec_data;
337+
338+
link_status = state & 1;
339+
340+
if (is_initialized) {
341+
spin_lock_irqsave(&priv->irq_lock, flags);
342+
cec_stat0 = get_hpd_stat(priv);
343+
spin_unlock_irqrestore(&priv->irq_lock, flags);
344+
345+
if (cec_stat0)
346+
mxc_hdmi_cec_handle(priv, cec_stat0);
347+
}
348+
}
349+
EXPORT_SYMBOL(hdmi_cec_hpd_changed);
350+
351+
static void hdmi_cec_start_device(void)
352+
{
353+
u8 val;
354+
unsigned long flags;
355+
356+
if (!is_initialized) {
357+
want_start = 1;
358+
return;
359+
}
360+
361+
spin_lock_irqsave(&hdmi_cec_data.irq_lock, flags);
362+
363+
val = hdmi_readb(HDMI_MC_CLKDIS);
364+
val &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE;
365+
hdmi_writeb(val, HDMI_MC_CLKDIS);
366+
hdmi_writeb(0x02, HDMI_CEC_CTRL);
367+
/* Force read unlock */
368+
hdmi_writeb(0x0, HDMI_CEC_LOCK);
369+
370+
val = HDMI_IH_CEC_STAT0_ERROR_INIT | HDMI_IH_CEC_STAT0_NACK |
371+
HDMI_IH_CEC_STAT0_EOM | HDMI_IH_CEC_STAT0_DONE;
372+
hdmi_writeb(val, HDMI_CEC_POLARITY);
373+
374+
val = CEC_STAT0_MASK_DEFAULT;
375+
hdmi_writeb(val, HDMI_CEC_MASK);
376+
hdmi_writeb(val, HDMI_IH_MUTE_CEC_STAT0);
377+
hdmi_cec_data.link_status = link_status;
378+
hdmi_cec_data.is_started = true;
379+
380+
spin_unlock_irqrestore(&hdmi_cec_data.irq_lock, flags);
381+
}
382+
383+
static void hdmi_cec_stop_device(void)
384+
{
385+
u8 val;
386+
unsigned long flags;
387+
388+
if (!is_initialized) {
389+
want_start = 0;
390+
return;
391+
}
392+
393+
spin_lock_irqsave(&hdmi_cec_data.irq_lock, flags);
394+
395+
hdmi_cec_data.is_started = false;
396+
hdmi_writeb(0x10, HDMI_CEC_CTRL);
397+
val = CEC_STAT0_MASK_ALL;
398+
hdmi_writeb(val, HDMI_CEC_MASK);
399+
hdmi_writeb(val, HDMI_IH_MUTE_CEC_STAT0);
400+
401+
hdmi_writeb(0x0, HDMI_CEC_POLARITY);
402+
val = hdmi_readb(HDMI_MC_CLKDIS);
403+
val |= HDMI_MC_CLKDIS_CECCLK_DISABLE;
404+
hdmi_writeb(val, HDMI_MC_CLKDIS);
405+
406+
spin_unlock_irqrestore(&hdmi_cec_data.irq_lock, flags);
407+
}
408+
332409
static int hdmi_cec_open(struct inode *inode, struct file *file)
333410
{
334411
struct hdmi_cec_priv *priv = &hdmi_cec_data;
@@ -348,6 +425,24 @@ static int hdmi_cec_open(struct inode *inode, struct file *file)
348425
return 0;
349426
}
350427

428+
static int hdmi_cec_release(struct inode *inode, struct file *file)
429+
{
430+
struct hdmi_cec_priv *priv = file->private_data;
431+
432+
mutex_lock(&priv->lock);
433+
if (priv->open_count) {
434+
priv->open_count = 0;
435+
priv->is_started = false;
436+
priv->logical_address = 15;
437+
priv->tx_answer = CEC_TX_AVAIL;
438+
439+
free_events();
440+
}
441+
mutex_unlock(&priv->lock);
442+
443+
return 0;
444+
}
445+
351446
static ssize_t hdmi_cec_read(struct file *file, char __user *buf, size_t count,
352447
loff_t *ppos)
353448
{
@@ -465,81 +560,24 @@ static ssize_t hdmi_cec_write(struct file *file, const char __user *buf,
465560
return ret;
466561
}
467562

468-
void hdmi_cec_hpd_changed(unsigned int state)
469-
{
470-
u32 cec_stat0;
471-
unsigned long flags;
472-
struct hdmi_cec_priv *priv = &hdmi_cec_data;
473-
474-
link_status = state & 1;
475-
476-
if (is_initialized) {
477-
spin_lock_irqsave(&priv->irq_lock, flags);
478-
cec_stat0 = get_hpd_stat(priv);
479-
spin_unlock_irqrestore(&priv->irq_lock, flags);
480-
481-
if (cec_stat0)
482-
mxc_hdmi_cec_handle(priv, cec_stat0);
483-
}
484-
}
485-
EXPORT_SYMBOL(hdmi_cec_hpd_changed);
486-
487-
static void hdmi_cec_start_device(void)
488-
{
489-
u8 val;
490-
unsigned long flags;
491-
492-
if (!is_initialized) {
493-
want_start = 1;
494-
return;
495-
}
496-
497-
spin_lock_irqsave(&hdmi_cec_data.irq_lock, flags);
498-
499-
val = hdmi_readb(HDMI_MC_CLKDIS);
500-
val &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE;
501-
hdmi_writeb(val, HDMI_MC_CLKDIS);
502-
hdmi_writeb(0x02, HDMI_CEC_CTRL);
503-
/* Force read unlock */
504-
hdmi_writeb(0x0, HDMI_CEC_LOCK);
505-
506-
val = HDMI_IH_CEC_STAT0_ERROR_INIT | HDMI_IH_CEC_STAT0_NACK |
507-
HDMI_IH_CEC_STAT0_EOM | HDMI_IH_CEC_STAT0_DONE;
508-
hdmi_writeb(val, HDMI_CEC_POLARITY);
509-
510-
val = CEC_STAT0_MASK_DEFAULT;
511-
hdmi_writeb(val, HDMI_CEC_MASK);
512-
hdmi_writeb(val, HDMI_IH_MUTE_CEC_STAT0);
513-
hdmi_cec_data.link_status = link_status;
514-
hdmi_cec_data.is_started = true;
515-
516-
spin_unlock_irqrestore(&hdmi_cec_data.irq_lock, flags);
517-
}
518-
519-
static void hdmi_cec_stop_device(void)
563+
static unsigned int hdmi_cec_poll(struct file *file, poll_table *wait)
520564
{
521-
u8 val;
522-
unsigned long flags;
523-
524-
if (!is_initialized) {
525-
want_start = 0;
526-
return;
527-
}
565+
unsigned int mask = 0;
566+
struct hdmi_cec_priv *priv = file->private_data;
528567

529-
spin_lock_irqsave(&hdmi_cec_data.irq_lock, flags);
568+
poll_wait(file, &rx_queue, wait);
569+
poll_wait(file, &tx_queue, wait);
530570

531-
hdmi_cec_data.is_started = false;
532-
hdmi_writeb(0x10, HDMI_CEC_CTRL);
533-
val = CEC_STAT0_MASK_ALL;
534-
hdmi_writeb(val, HDMI_CEC_MASK);
535-
hdmi_writeb(val, HDMI_IH_MUTE_CEC_STAT0);
571+
if (priv->link_status == 0 ||
572+
priv->tx_answer == CEC_TX_AVAIL)
573+
mask |= POLLOUT | POLLWRNORM;
536574

537-
hdmi_writeb(0x0, HDMI_CEC_POLARITY);
538-
val = hdmi_readb(HDMI_MC_CLKDIS);
539-
val |= HDMI_MC_CLKDIS_CECCLK_DISABLE;
540-
hdmi_writeb(val, HDMI_MC_CLKDIS);
575+
mutex_lock(&priv->lock);
576+
if (!list_empty(&ev_pending))
577+
mask |= POLLIN | POLLRDNORM;
578+
mutex_unlock(&priv->lock);
541579

542-
spin_unlock_irqrestore(&hdmi_cec_data.irq_lock, flags);
580+
return mask;
543581
}
544582

545583
static long hdmi_cec_ioctl(struct file *file, u_int cmd, u_long arg)
@@ -590,44 +628,6 @@ static long hdmi_cec_ioctl(struct file *file, u_int cmd, u_long arg)
590628
return ret;
591629
}
592630

593-
static int hdmi_cec_release(struct inode *inode, struct file *file)
594-
{
595-
struct hdmi_cec_priv *priv = file->private_data;
596-
597-
mutex_lock(&priv->lock);
598-
if (priv->open_count) {
599-
priv->open_count = 0;
600-
priv->is_started = false;
601-
priv->logical_address = 15;
602-
priv->tx_answer = CEC_TX_AVAIL;
603-
604-
free_events();
605-
}
606-
mutex_unlock(&priv->lock);
607-
608-
return 0;
609-
}
610-
611-
static unsigned int hdmi_cec_poll(struct file *file, poll_table *wait)
612-
{
613-
unsigned int mask = 0;
614-
struct hdmi_cec_priv *priv = file->private_data;
615-
616-
poll_wait(file, &rx_queue, wait);
617-
poll_wait(file, &tx_queue, wait);
618-
619-
if (priv->link_status == 0 ||
620-
priv->tx_answer == CEC_TX_AVAIL)
621-
mask |= POLLOUT | POLLWRNORM;
622-
623-
mutex_lock(&priv->lock);
624-
if (!list_empty(&ev_pending))
625-
mask |= POLLIN | POLLRDNORM;
626-
mutex_unlock(&priv->lock);
627-
628-
return mask;
629-
}
630-
631631

632632
const struct file_operations hdmi_cec_fops = {
633633
.owner = THIS_MODULE,

0 commit comments

Comments
 (0)