1 /* 2 * Copyright (C) 2013 Red Hat 3 * Author: Rob Clark <robdclark@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 as published by 7 * the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 * You should have received a copy of the GNU General Public License along with 15 * this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef __HDMI_CONNECTOR_H__ 19 #define __HDMI_CONNECTOR_H__ 20 21 #include <linux/i2c.h> 22 #include <linux/clk.h> 23 #include <linux/platform_device.h> 24 #include <linux/regulator/consumer.h> 25 26 #include "msm_drv.h" 27 #include "hdmi.xml.h" 28 29 30 struct hdmi_phy; 31 32 struct hdmi { 33 struct kref refcount; 34 35 struct drm_device *dev; 36 struct platform_device *pdev; 37 38 void __iomem *mmio; 39 40 struct regulator *mvs; /* HDMI_5V */ 41 struct regulator *mpp0; /* External 5V */ 42 43 struct clk *clk; 44 struct clk *m_pclk; 45 struct clk *s_pclk; 46 47 struct hdmi_phy *phy; 48 struct i2c_adapter *i2c; 49 struct drm_connector *connector; 50 struct drm_bridge *bridge; 51 52 /* the encoder we are hooked to (outside of hdmi block) */ 53 struct drm_encoder *encoder; 54 55 bool hdmi_mode; /* are we in hdmi mode? */ 56 57 int irq; 58 }; 59 60 /* platform config data (ie. from DT, or pdata) */ 61 struct hdmi_platform_config { 62 struct hdmi_phy *(*phy_init)(struct hdmi *hdmi); 63 int ddc_clk_gpio, ddc_data_gpio, hpd_gpio, pmic_gpio; 64 }; 65 66 void hdmi_set_mode(struct hdmi *hdmi, bool power_on); 67 void hdmi_destroy(struct kref *kref); 68 69 static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data) 70 { 71 msm_writel(data, hdmi->mmio + reg); 72 } 73 74 static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg) 75 { 76 return msm_readl(hdmi->mmio + reg); 77 } 78 79 static inline struct hdmi * hdmi_reference(struct hdmi *hdmi) 80 { 81 kref_get(&hdmi->refcount); 82 return hdmi; 83 } 84 85 static inline void hdmi_unreference(struct hdmi *hdmi) 86 { 87 kref_put(&hdmi->refcount, hdmi_destroy); 88 } 89 90 /* 91 * The phy appears to be different, for example between 8960 and 8x60, 92 * so split the phy related functions out and load the correct one at 93 * runtime: 94 */ 95 96 struct hdmi_phy_funcs { 97 void (*destroy)(struct hdmi_phy *phy); 98 void (*reset)(struct hdmi_phy *phy); 99 void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock); 100 void (*powerdown)(struct hdmi_phy *phy); 101 }; 102 103 struct hdmi_phy { 104 const struct hdmi_phy_funcs *funcs; 105 }; 106 107 struct hdmi_phy *hdmi_phy_8960_init(struct hdmi *hdmi); 108 struct hdmi_phy *hdmi_phy_8x60_init(struct hdmi *hdmi); 109 110 /* 111 * hdmi bridge: 112 */ 113 114 struct drm_bridge *hdmi_bridge_init(struct hdmi *hdmi); 115 116 /* 117 * hdmi connector: 118 */ 119 120 void hdmi_connector_irq(struct drm_connector *connector); 121 struct drm_connector *hdmi_connector_init(struct hdmi *hdmi); 122 123 /* 124 * i2c adapter for ddc: 125 */ 126 127 void hdmi_i2c_irq(struct i2c_adapter *i2c); 128 void hdmi_i2c_destroy(struct i2c_adapter *i2c); 129 struct i2c_adapter *hdmi_i2c_init(struct hdmi *hdmi); 130 131 #endif /* __HDMI_CONNECTOR_H__ */ 132