fix a kmap leak in virtio_console
[linux/fpc-iii.git] / drivers / video / omap2 / dss / hdmi_phy.c
blobdd376ce8da01960f376ca705cf25cde169e7699f
1 /*
2 * HDMI PHY
4 * Copyright (C) 2013 Texas Instruments Incorporated
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
11 #include <linux/kernel.h>
12 #include <linux/err.h>
13 #include <linux/io.h>
14 #include <linux/platform_device.h>
15 #include <video/omapdss.h>
17 #include "dss.h"
18 #include "hdmi.h"
20 void hdmi_phy_dump(struct hdmi_phy_data *phy, struct seq_file *s)
22 #define DUMPPHY(r) seq_printf(s, "%-35s %08x\n", #r,\
23 hdmi_read_reg(phy->base, r))
25 DUMPPHY(HDMI_TXPHY_TX_CTRL);
26 DUMPPHY(HDMI_TXPHY_DIGITAL_CTRL);
27 DUMPPHY(HDMI_TXPHY_POWER_CTRL);
28 DUMPPHY(HDMI_TXPHY_PAD_CFG_CTRL);
31 static irqreturn_t hdmi_irq_handler(int irq, void *data)
33 struct hdmi_wp_data *wp = data;
34 u32 irqstatus;
36 irqstatus = hdmi_wp_get_irqstatus(wp);
37 hdmi_wp_set_irqstatus(wp, irqstatus);
39 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
40 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
42 * If we get both connect and disconnect interrupts at the same
43 * time, turn off the PHY, clear interrupts, and restart, which
44 * raises connect interrupt if a cable is connected, or nothing
45 * if cable is not connected.
47 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
49 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
50 HDMI_IRQ_LINK_DISCONNECT);
52 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
53 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
54 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
55 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
56 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
59 return IRQ_HANDLED;
62 int hdmi_phy_enable(struct hdmi_phy_data *phy, struct hdmi_wp_data *wp,
63 struct hdmi_config *cfg)
65 u16 r = 0;
66 u32 irqstatus;
68 hdmi_wp_clear_irqenable(wp, 0xffffffff);
70 irqstatus = hdmi_wp_get_irqstatus(wp);
71 hdmi_wp_set_irqstatus(wp, irqstatus);
73 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
74 if (r)
75 return r;
78 * Read address 0 in order to get the SCP reset done completed
79 * Dummy access performed to make sure reset is done
81 hdmi_read_reg(phy->base, HDMI_TXPHY_TX_CTRL);
84 * Write to phy address 0 to configure the clock
85 * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
87 REG_FLD_MOD(phy->base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
89 /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
90 hdmi_write_reg(phy->base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
92 /* Setup max LDO voltage */
93 REG_FLD_MOD(phy->base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
95 /* Write to phy address 3 to change the polarity control */
96 REG_FLD_MOD(phy->base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
98 r = request_threaded_irq(phy->irq, NULL, hdmi_irq_handler,
99 IRQF_ONESHOT, "OMAP HDMI", wp);
100 if (r) {
101 DSSERR("HDMI IRQ request failed\n");
102 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
103 return r;
106 hdmi_wp_set_irqenable(wp,
107 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
109 return 0;
112 void hdmi_phy_disable(struct hdmi_phy_data *phy, struct hdmi_wp_data *wp)
114 free_irq(phy->irq, wp);
116 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
119 #define PHY_OFFSET 0x300
120 #define PHY_SIZE 0x100
122 int hdmi_phy_init(struct platform_device *pdev, struct hdmi_phy_data *phy)
124 struct resource *res;
125 struct resource temp_res;
127 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy");
128 if (!res) {
129 DSSDBG("can't get PHY mem resource by name\n");
131 * if hwmod/DT doesn't have the memory resource information
132 * split into HDMI sub blocks by name, we try again by getting
133 * the platform's first resource. this code will be removed when
134 * the driver can get the mem resources by name
136 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
137 if (!res) {
138 DSSERR("can't get PHY mem resource\n");
139 return -EINVAL;
142 temp_res.start = res->start + PHY_OFFSET;
143 temp_res.end = temp_res.start + PHY_SIZE - 1;
144 res = &temp_res;
147 phy->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
148 if (!phy->base) {
149 DSSERR("can't ioremap TX PHY\n");
150 return -ENOMEM;
153 phy->irq = platform_get_irq(pdev, 0);
154 if (phy->irq < 0) {
155 DSSERR("platform_get_irq failed\n");
156 return -ENODEV;
159 return 0;