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.
11 #include <linux/kernel.h>
12 #include <linux/delay.h>
13 #include <linux/err.h>
15 #include <linux/platform_device.h>
16 #include <video/omapdss.h>
20 #include "ti_hdmi_4xxx_ip.h"
22 #define HDMI_IRQ_LINK_CONNECT (1 << 25)
23 #define HDMI_IRQ_LINK_DISCONNECT (1 << 26)
25 static inline void hdmi_write_reg(void __iomem *base_addr, const u16 idx,
28 __raw_writel(val, base_addr + idx);
31 static inline u32 hdmi_read_reg(void __iomem *base_addr, const u16 idx)
33 return __raw_readl(base_addr + idx);
36 #define REG_FLD_MOD(base, idx, val, start, end) \
37 hdmi_write_reg(base, idx, FLD_MOD(hdmi_read_reg(base, idx),\
39 #define REG_GET(base, idx, start, end) \
40 FLD_GET(hdmi_read_reg(base, idx), start, end)
42 static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
43 const u16 idx, int b2, int b1, u32 val)
46 while (val != REG_GET(base_addr, idx, b2, b1)) {
54 void hdmi_phy_dump(struct hdmi_phy_data *phy, struct seq_file *s)
56 #define DUMPPHY(r) seq_printf(s, "%-35s %08x\n", #r,\
57 hdmi_read_reg(phy->base, r))
59 DUMPPHY(HDMI_TXPHY_TX_CTRL);
60 DUMPPHY(HDMI_TXPHY_DIGITAL_CTRL);
61 DUMPPHY(HDMI_TXPHY_POWER_CTRL);
62 DUMPPHY(HDMI_TXPHY_PAD_CFG_CTRL);
65 static irqreturn_t hdmi_irq_handler(int irq, void *data)
67 struct hdmi_wp_data *wp = data;
70 irqstatus = hdmi_wp_get_irqstatus(wp);
71 hdmi_wp_set_irqstatus(wp, irqstatus);
73 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
74 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
76 * If we get both connect and disconnect interrupts at the same
77 * time, turn off the PHY, clear interrupts, and restart, which
78 * raises connect interrupt if a cable is connected, or nothing
79 * if cable is not connected.
81 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
83 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
84 HDMI_IRQ_LINK_DISCONNECT);
86 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
87 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
88 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
89 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
90 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
96 int hdmi_phy_enable(struct hdmi_phy_data *phy, struct hdmi_wp_data *wp,
97 struct hdmi_config *cfg)
102 hdmi_wp_clear_irqenable(wp, 0xffffffff);
104 irqstatus = hdmi_wp_get_irqstatus(wp);
105 hdmi_wp_set_irqstatus(wp, irqstatus);
107 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
112 * Read address 0 in order to get the SCP reset done completed
113 * Dummy access performed to make sure reset is done
115 hdmi_read_reg(phy->base, HDMI_TXPHY_TX_CTRL);
118 * Write to phy address 0 to configure the clock
119 * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
121 REG_FLD_MOD(phy->base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
123 /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
124 hdmi_write_reg(phy->base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
126 /* Setup max LDO voltage */
127 REG_FLD_MOD(phy->base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
129 /* Write to phy address 3 to change the polarity control */
130 REG_FLD_MOD(phy->base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
132 r = request_threaded_irq(phy->irq, NULL, hdmi_irq_handler,
133 IRQF_ONESHOT, "OMAP HDMI", wp);
135 DSSERR("HDMI IRQ request failed\n");
136 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
140 hdmi_wp_set_irqenable(wp,
141 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
146 void hdmi_phy_disable(struct hdmi_phy_data *phy, struct hdmi_wp_data *wp)
148 free_irq(phy->irq, wp);
150 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
153 #define PHY_OFFSET 0x300
154 #define PHY_SIZE 0x100
156 int hdmi_phy_init(struct platform_device *pdev, struct hdmi_phy_data *phy)
158 struct resource *res;
159 struct resource temp_res;
161 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hdmi_txphy");
163 DSSDBG("can't get PHY mem resource by name\n");
165 * if hwmod/DT doesn't have the memory resource information
166 * split into HDMI sub blocks by name, we try again by getting
167 * the platform's first resource. this code will be removed when
168 * the driver can get the mem resources by name
170 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
172 DSSERR("can't get PHY mem resource\n");
176 temp_res.start = res->start + PHY_OFFSET;
177 temp_res.end = temp_res.start + PHY_SIZE - 1;
181 phy->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
183 DSSERR("can't ioremap TX PHY\n");
187 phy->irq = platform_get_irq(pdev, 0);
189 DSSERR("platform_get_irq failed\n");