aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhenyu Wang <zhenyuw@linux.intel.com>2010-03-30 02:06:33 -0400
committerEric Anholt <eric@anholt.net>2010-04-12 12:23:57 -0400
commit14571b4c1ac9c109f5d6d6e95cfdb92339151fe0 (patch)
tree49cab6f749f6cf31b649f11fdf08b158fe7e57ba
parent409608b391994c3ac2abe0d9ca50c3d163faafe1 (diff)
drm/i915: implement multifunction SDVO device support
With new intel_encoder/intel_connector structure change, each supported connector type on SDVO device will be created as a new 'intel_connector', and all attached to one 'intel_encoder' for its SDVO port. The SDVO encoder will handle SDVO protocol stuff, and each connector does its own part of work now, like detection is only to check if current active output is itself, etc. Update since last submit: - Fixed SDVO TV property creation failure by incorrect set target output call Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c611
1 files changed, 375 insertions, 236 deletions
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 602056a88dd0..5628de27538c 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -37,6 +37,18 @@
37#include "intel_sdvo_regs.h" 37#include "intel_sdvo_regs.h"
38#include <linux/dmi.h> 38#include <linux/dmi.h>
39 39
40#define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
41#define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
42#define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
43#define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0)
44
45#define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
46 SDVO_TV_MASK)
47
48#define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
49#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
50
51
40static char *tv_format_names[] = { 52static char *tv_format_names[] = {
41 "NTSC_M" , "NTSC_J" , "NTSC_443", 53 "NTSC_M" , "NTSC_J" , "NTSC_443",
42 "PAL_B" , "PAL_D" , "PAL_G" , 54 "PAL_B" , "PAL_D" , "PAL_G" ,
@@ -85,12 +97,6 @@ struct intel_sdvo_priv {
85 /* This is for current tv format name */ 97 /* This is for current tv format name */
86 char *tv_format_name; 98 char *tv_format_name;
87 99
88 /* This contains all current supported TV format */
89 char *tv_format_supported[TV_FORMAT_NUM];
90 int format_supported_num;
91 struct drm_property *tv_format_property;
92 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
93
94 /** 100 /**
95 * This is set if we treat the device as HDMI, instead of DVI. 101 * This is set if we treat the device as HDMI, instead of DVI.
96 */ 102 */
@@ -111,12 +117,6 @@ struct intel_sdvo_priv {
111 */ 117 */
112 struct drm_display_mode *sdvo_lvds_fixed_mode; 118 struct drm_display_mode *sdvo_lvds_fixed_mode;
113 119
114 /**
115 * Returned SDTV resolutions allowed for the current format, if the
116 * device reported it.
117 */
118 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
119
120 /* 120 /*
121 * supported encoding mode, used to determine whether HDMI is 121 * supported encoding mode, used to determine whether HDMI is
122 * supported 122 * supported
@@ -129,6 +129,24 @@ struct intel_sdvo_priv {
129 /* Mac mini hack -- use the same DDC as the analog connector */ 129 /* Mac mini hack -- use the same DDC as the analog connector */
130 struct i2c_adapter *analog_ddc_bus; 130 struct i2c_adapter *analog_ddc_bus;
131 131
132};
133
134struct intel_sdvo_connector {
135 /* Mark the type of connector */
136 uint16_t output_flag;
137
138 /* This contains all current supported TV format */
139 char *tv_format_supported[TV_FORMAT_NUM];
140 int format_supported_num;
141 struct drm_property *tv_format_property;
142 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
143
144 /**
145 * Returned SDTV resolutions allowed for the current format, if the
146 * device reported it.
147 */
148 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
149
132 /* add the property for the SDVO-TV */ 150 /* add the property for the SDVO-TV */
133 struct drm_property *left_property; 151 struct drm_property *left_property;
134 struct drm_property *right_property; 152 struct drm_property *right_property;
@@ -157,8 +175,11 @@ struct intel_sdvo_priv {
157 175
158static bool 176static bool
159intel_sdvo_output_setup(struct intel_encoder *intel_encoder, 177intel_sdvo_output_setup(struct intel_encoder *intel_encoder,
160 struct intel_connector *intel_connector,
161 uint16_t flags); 178 uint16_t flags);
179static void
180intel_sdvo_tv_create_property(struct drm_connector *connector, int type);
181static void
182intel_sdvo_create_enhance_property(struct drm_connector *connector);
162 183
163/** 184/**
164 * Writes the SDVOB or SDVOC with the given value, but always writes both 185 * Writes the SDVOB or SDVOC with the given value, but always writes both
@@ -1035,7 +1056,7 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1035 /* Set output timings */ 1056 /* Set output timings */
1036 intel_sdvo_get_dtd_from_mode(&output_dtd, mode); 1057 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1037 intel_sdvo_set_target_output(intel_encoder, 1058 intel_sdvo_set_target_output(intel_encoder,
1038 dev_priv->controlled_output); 1059 dev_priv->attached_output);
1039 intel_sdvo_set_output_timing(intel_encoder, &output_dtd); 1060 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
1040 1061
1041 /* Set the input timing to the screen. Assume always input 0. */ 1062 /* Set the input timing to the screen. Assume always input 0. */
@@ -1073,7 +1094,7 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1073 dev_priv->sdvo_lvds_fixed_mode); 1094 dev_priv->sdvo_lvds_fixed_mode);
1074 1095
1075 intel_sdvo_set_target_output(intel_encoder, 1096 intel_sdvo_set_target_output(intel_encoder,
1076 dev_priv->controlled_output); 1097 dev_priv->attached_output);
1077 intel_sdvo_set_output_timing(intel_encoder, &output_dtd); 1098 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
1078 1099
1079 /* Set the input timing to the screen. Assume always input 0. */ 1100 /* Set the input timing to the screen. Assume always input 0. */
@@ -1138,7 +1159,7 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1138 * channel on the motherboard. In a two-input device, the first input 1159 * channel on the motherboard. In a two-input device, the first input
1139 * will be SDVOB and the second SDVOC. 1160 * will be SDVOB and the second SDVOC.
1140 */ 1161 */
1141 in_out.in0 = sdvo_priv->controlled_output; 1162 in_out.in0 = sdvo_priv->attached_output;
1142 in_out.in1 = 0; 1163 in_out.in1 = 0;
1143 1164
1144 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP, 1165 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP,
@@ -1164,7 +1185,7 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1164 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) { 1185 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
1165 /* Set the output timing to the screen */ 1186 /* Set the output timing to the screen */
1166 intel_sdvo_set_target_output(intel_encoder, 1187 intel_sdvo_set_target_output(intel_encoder,
1167 sdvo_priv->controlled_output); 1188 sdvo_priv->attached_output);
1168 intel_sdvo_set_output_timing(intel_encoder, &input_dtd); 1189 intel_sdvo_set_output_timing(intel_encoder, &input_dtd);
1169 } 1190 }
1170 1191
@@ -1286,7 +1307,7 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1286 1307
1287 if (0) 1308 if (0)
1288 intel_sdvo_set_encoder_power_state(intel_encoder, mode); 1309 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
1289 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->controlled_output); 1310 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->attached_output);
1290 } 1311 }
1291 return; 1312 return;
1292} 1313}
@@ -1550,6 +1571,8 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect
1550 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1571 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1551 struct intel_connector *intel_connector = to_intel_connector(connector); 1572 struct intel_connector *intel_connector = to_intel_connector(connector);
1552 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 1573 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1574 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1575 enum drm_connector_status ret;
1553 1576
1554 intel_sdvo_write_cmd(intel_encoder, 1577 intel_sdvo_write_cmd(intel_encoder,
1555 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0); 1578 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
@@ -1567,15 +1590,30 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect
1567 if (response == 0) 1590 if (response == 0)
1568 return connector_status_disconnected; 1591 return connector_status_disconnected;
1569 1592
1570 if (intel_sdvo_multifunc_encoder(intel_encoder) && 1593 sdvo_priv->attached_output = response;
1571 sdvo_priv->attached_output != response) { 1594
1572 if (sdvo_priv->controlled_output != response && 1595 if ((sdvo_connector->output_flag & response) == 0)
1573 intel_sdvo_output_setup(intel_encoder, intel_connector, 1596 ret = connector_status_disconnected;
1574 response) != true) 1597 else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1575 return connector_status_unknown; 1598 ret = intel_sdvo_hdmi_sink_detect(connector, response);
1576 sdvo_priv->attached_output = response; 1599 else
1600 ret = connector_status_connected;
1601
1602 /* May update encoder flag for like clock for SDVO TV, etc.*/
1603 if (ret == connector_status_connected) {
1604 sdvo_priv->is_tv = false;
1605 sdvo_priv->is_lvds = false;
1606 intel_encoder->needs_tv_clock = false;
1607
1608 if (response & SDVO_TV_MASK) {
1609 sdvo_priv->is_tv = true;
1610 intel_encoder->needs_tv_clock = true;
1611 }
1612 if (response & SDVO_LVDS_MASK)
1613 sdvo_priv->is_lvds = true;
1577 } 1614 }
1578 return intel_sdvo_hdmi_sink_detect(connector, response); 1615
1616 return ret;
1579} 1617}
1580 1618
1581static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) 1619static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
@@ -1692,7 +1730,7 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1692 sizeof(format_map) ? sizeof(format_map) : 1730 sizeof(format_map) ? sizeof(format_map) :
1693 sizeof(struct intel_sdvo_sdtv_resolution_request)); 1731 sizeof(struct intel_sdvo_sdtv_resolution_request));
1694 1732
1695 intel_sdvo_set_target_output(intel_encoder, sdvo_priv->controlled_output); 1733 intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output);
1696 1734
1697 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, 1735 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
1698 &tv_res, sizeof(tv_res)); 1736 &tv_res, sizeof(tv_res));
@@ -1753,13 +1791,12 @@ end:
1753 1791
1754static int intel_sdvo_get_modes(struct drm_connector *connector) 1792static int intel_sdvo_get_modes(struct drm_connector *connector)
1755{ 1793{
1756 struct drm_encoder *encoder = intel_attached_encoder(connector); 1794 struct intel_connector *intel_connector = to_intel_connector(connector);
1757 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1795 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1758 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1759 1796
1760 if (sdvo_priv->is_tv) 1797 if (IS_TV(sdvo_connector))
1761 intel_sdvo_get_tv_modes(connector); 1798 intel_sdvo_get_tv_modes(connector);
1762 else if (sdvo_priv->is_lvds == true) 1799 else if (IS_LVDS(sdvo_connector))
1763 intel_sdvo_get_lvds_modes(connector); 1800 intel_sdvo_get_lvds_modes(connector);
1764 else 1801 else
1765 intel_sdvo_get_ddc_modes(connector); 1802 intel_sdvo_get_ddc_modes(connector);
@@ -1772,12 +1809,11 @@ static int intel_sdvo_get_modes(struct drm_connector *connector)
1772static 1809static
1773void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) 1810void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1774{ 1811{
1775 struct drm_encoder *encoder = intel_attached_encoder(connector); 1812 struct intel_connector *intel_connector = to_intel_connector(connector);
1776 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1813 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
1777 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 1814 struct drm_device *dev = connector->dev;
1778 struct drm_device *dev = encoder->dev;
1779 1815
1780 if (sdvo_priv->is_tv) { 1816 if (IS_TV(sdvo_priv)) {
1781 if (sdvo_priv->left_property) 1817 if (sdvo_priv->left_property)
1782 drm_property_destroy(dev, sdvo_priv->left_property); 1818 drm_property_destroy(dev, sdvo_priv->left_property);
1783 if (sdvo_priv->right_property) 1819 if (sdvo_priv->right_property)
@@ -1790,8 +1826,6 @@ void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1790 drm_property_destroy(dev, sdvo_priv->hpos_property); 1826 drm_property_destroy(dev, sdvo_priv->hpos_property);
1791 if (sdvo_priv->vpos_property) 1827 if (sdvo_priv->vpos_property)
1792 drm_property_destroy(dev, sdvo_priv->vpos_property); 1828 drm_property_destroy(dev, sdvo_priv->vpos_property);
1793 }
1794 if (sdvo_priv->is_tv) {
1795 if (sdvo_priv->saturation_property) 1829 if (sdvo_priv->saturation_property)
1796 drm_property_destroy(dev, 1830 drm_property_destroy(dev,
1797 sdvo_priv->saturation_property); 1831 sdvo_priv->saturation_property);
@@ -1801,7 +1835,7 @@ void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1801 if (sdvo_priv->hue_property) 1835 if (sdvo_priv->hue_property)
1802 drm_property_destroy(dev, sdvo_priv->hue_property); 1836 drm_property_destroy(dev, sdvo_priv->hue_property);
1803 } 1837 }
1804 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { 1838 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
1805 if (sdvo_priv->brightness_property) 1839 if (sdvo_priv->brightness_property)
1806 drm_property_destroy(dev, 1840 drm_property_destroy(dev,
1807 sdvo_priv->brightness_property); 1841 sdvo_priv->brightness_property);
@@ -1811,6 +1845,13 @@ void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1811 1845
1812static void intel_sdvo_destroy(struct drm_connector *connector) 1846static void intel_sdvo_destroy(struct drm_connector *connector)
1813{ 1847{
1848 struct intel_connector *intel_connector = to_intel_connector(connector);
1849 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1850
1851 if (sdvo_connector->tv_format_property)
1852 drm_property_destroy(connector->dev,
1853 sdvo_connector->tv_format_property);
1854
1814 intel_sdvo_destroy_enhance_property(connector); 1855 intel_sdvo_destroy_enhance_property(connector);
1815 drm_sysfs_connector_remove(connector); 1856 drm_sysfs_connector_remove(connector);
1816 drm_connector_cleanup(connector); 1857 drm_connector_cleanup(connector);
@@ -1825,6 +1866,8 @@ intel_sdvo_set_property(struct drm_connector *connector,
1825 struct drm_encoder *encoder = intel_attached_encoder(connector); 1866 struct drm_encoder *encoder = intel_attached_encoder(connector);
1826 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1867 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1827 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 1868 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1869 struct intel_connector *intel_connector = to_intel_connector(connector);
1870 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1828 struct drm_crtc *crtc = encoder->crtc; 1871 struct drm_crtc *crtc = encoder->crtc;
1829 int ret = 0; 1872 int ret = 0;
1830 bool changed = false; 1873 bool changed = false;
@@ -1835,101 +1878,101 @@ intel_sdvo_set_property(struct drm_connector *connector,
1835 if (ret < 0) 1878 if (ret < 0)
1836 goto out; 1879 goto out;
1837 1880
1838 if (property == sdvo_priv->tv_format_property) { 1881 if (property == sdvo_connector->tv_format_property) {
1839 if (val >= TV_FORMAT_NUM) { 1882 if (val >= TV_FORMAT_NUM) {
1840 ret = -EINVAL; 1883 ret = -EINVAL;
1841 goto out; 1884 goto out;
1842 } 1885 }
1843 if (sdvo_priv->tv_format_name == 1886 if (sdvo_priv->tv_format_name ==
1844 sdvo_priv->tv_format_supported[val]) 1887 sdvo_connector->tv_format_supported[val])
1845 goto out; 1888 goto out;
1846 1889
1847 sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[val]; 1890 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[val];
1848 changed = true; 1891 changed = true;
1849 } 1892 }
1850 1893
1851 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { 1894 if (IS_TV(sdvo_connector) || IS_LVDS(sdvo_connector)) {
1852 cmd = 0; 1895 cmd = 0;
1853 temp_value = val; 1896 temp_value = val;
1854 if (sdvo_priv->left_property == property) { 1897 if (sdvo_connector->left_property == property) {
1855 drm_connector_property_set_value(connector, 1898 drm_connector_property_set_value(connector,
1856 sdvo_priv->right_property, val); 1899 sdvo_connector->right_property, val);
1857 if (sdvo_priv->left_margin == temp_value) 1900 if (sdvo_connector->left_margin == temp_value)
1858 goto out; 1901 goto out;
1859 1902
1860 sdvo_priv->left_margin = temp_value; 1903 sdvo_connector->left_margin = temp_value;
1861 sdvo_priv->right_margin = temp_value; 1904 sdvo_connector->right_margin = temp_value;
1862 temp_value = sdvo_priv->max_hscan - 1905 temp_value = sdvo_connector->max_hscan -
1863 sdvo_priv->left_margin; 1906 sdvo_connector->left_margin;
1864 cmd = SDVO_CMD_SET_OVERSCAN_H; 1907 cmd = SDVO_CMD_SET_OVERSCAN_H;
1865 } else if (sdvo_priv->right_property == property) { 1908 } else if (sdvo_connector->right_property == property) {
1866 drm_connector_property_set_value(connector, 1909 drm_connector_property_set_value(connector,
1867 sdvo_priv->left_property, val); 1910 sdvo_connector->left_property, val);
1868 if (sdvo_priv->right_margin == temp_value) 1911 if (sdvo_connector->right_margin == temp_value)
1869 goto out; 1912 goto out;
1870 1913
1871 sdvo_priv->left_margin = temp_value; 1914 sdvo_connector->left_margin = temp_value;
1872 sdvo_priv->right_margin = temp_value; 1915 sdvo_connector->right_margin = temp_value;
1873 temp_value = sdvo_priv->max_hscan - 1916 temp_value = sdvo_connector->max_hscan -
1874 sdvo_priv->left_margin; 1917 sdvo_connector->left_margin;
1875 cmd = SDVO_CMD_SET_OVERSCAN_H; 1918 cmd = SDVO_CMD_SET_OVERSCAN_H;
1876 } else if (sdvo_priv->top_property == property) { 1919 } else if (sdvo_connector->top_property == property) {
1877 drm_connector_property_set_value(connector, 1920 drm_connector_property_set_value(connector,
1878 sdvo_priv->bottom_property, val); 1921 sdvo_connector->bottom_property, val);
1879 if (sdvo_priv->top_margin == temp_value) 1922 if (sdvo_connector->top_margin == temp_value)
1880 goto out; 1923 goto out;
1881 1924
1882 sdvo_priv->top_margin = temp_value; 1925 sdvo_connector->top_margin = temp_value;
1883 sdvo_priv->bottom_margin = temp_value; 1926 sdvo_connector->bottom_margin = temp_value;
1884 temp_value = sdvo_priv->max_vscan - 1927 temp_value = sdvo_connector->max_vscan -
1885 sdvo_priv->top_margin; 1928 sdvo_connector->top_margin;
1886 cmd = SDVO_CMD_SET_OVERSCAN_V; 1929 cmd = SDVO_CMD_SET_OVERSCAN_V;
1887 } else if (sdvo_priv->bottom_property == property) { 1930 } else if (sdvo_connector->bottom_property == property) {
1888 drm_connector_property_set_value(connector, 1931 drm_connector_property_set_value(connector,
1889 sdvo_priv->top_property, val); 1932 sdvo_connector->top_property, val);
1890 if (sdvo_priv->bottom_margin == temp_value) 1933 if (sdvo_connector->bottom_margin == temp_value)
1891 goto out; 1934 goto out;
1892 sdvo_priv->top_margin = temp_value; 1935 sdvo_connector->top_margin = temp_value;
1893 sdvo_priv->bottom_margin = temp_value; 1936 sdvo_connector->bottom_margin = temp_value;
1894 temp_value = sdvo_priv->max_vscan - 1937 temp_value = sdvo_connector->max_vscan -
1895 sdvo_priv->top_margin; 1938 sdvo_connector->top_margin;
1896 cmd = SDVO_CMD_SET_OVERSCAN_V; 1939 cmd = SDVO_CMD_SET_OVERSCAN_V;
1897 } else if (sdvo_priv->hpos_property == property) { 1940 } else if (sdvo_connector->hpos_property == property) {
1898 if (sdvo_priv->cur_hpos == temp_value) 1941 if (sdvo_connector->cur_hpos == temp_value)
1899 goto out; 1942 goto out;
1900 1943
1901 cmd = SDVO_CMD_SET_POSITION_H; 1944 cmd = SDVO_CMD_SET_POSITION_H;
1902 sdvo_priv->cur_hpos = temp_value; 1945 sdvo_connector->cur_hpos = temp_value;
1903 } else if (sdvo_priv->vpos_property == property) { 1946 } else if (sdvo_connector->vpos_property == property) {
1904 if (sdvo_priv->cur_vpos == temp_value) 1947 if (sdvo_connector->cur_vpos == temp_value)
1905 goto out; 1948 goto out;
1906 1949
1907 cmd = SDVO_CMD_SET_POSITION_V; 1950 cmd = SDVO_CMD_SET_POSITION_V;
1908 sdvo_priv->cur_vpos = temp_value; 1951 sdvo_connector->cur_vpos = temp_value;
1909 } else if (sdvo_priv->saturation_property == property) { 1952 } else if (sdvo_connector->saturation_property == property) {
1910 if (sdvo_priv->cur_saturation == temp_value) 1953 if (sdvo_connector->cur_saturation == temp_value)
1911 goto out; 1954 goto out;
1912 1955
1913 cmd = SDVO_CMD_SET_SATURATION; 1956 cmd = SDVO_CMD_SET_SATURATION;
1914 sdvo_priv->cur_saturation = temp_value; 1957 sdvo_connector->cur_saturation = temp_value;
1915 } else if (sdvo_priv->contrast_property == property) { 1958 } else if (sdvo_connector->contrast_property == property) {
1916 if (sdvo_priv->cur_contrast == temp_value) 1959 if (sdvo_connector->cur_contrast == temp_value)
1917 goto out; 1960 goto out;
1918 1961
1919 cmd = SDVO_CMD_SET_CONTRAST; 1962 cmd = SDVO_CMD_SET_CONTRAST;
1920 sdvo_priv->cur_contrast = temp_value; 1963 sdvo_connector->cur_contrast = temp_value;
1921 } else if (sdvo_priv->hue_property == property) { 1964 } else if (sdvo_connector->hue_property == property) {
1922 if (sdvo_priv->cur_hue == temp_value) 1965 if (sdvo_connector->cur_hue == temp_value)
1923 goto out; 1966 goto out;
1924 1967
1925 cmd = SDVO_CMD_SET_HUE; 1968 cmd = SDVO_CMD_SET_HUE;
1926 sdvo_priv->cur_hue = temp_value; 1969 sdvo_connector->cur_hue = temp_value;
1927 } else if (sdvo_priv->brightness_property == property) { 1970 } else if (sdvo_connector->brightness_property == property) {
1928 if (sdvo_priv->cur_brightness == temp_value) 1971 if (sdvo_connector->cur_brightness == temp_value)
1929 goto out; 1972 goto out;
1930 1973
1931 cmd = SDVO_CMD_SET_BRIGHTNESS; 1974 cmd = SDVO_CMD_SET_BRIGHTNESS;
1932 sdvo_priv->cur_brightness = temp_value; 1975 sdvo_connector->cur_brightness = temp_value;
1933 } 1976 }
1934 if (cmd) { 1977 if (cmd) {
1935 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2); 1978 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2);
@@ -1987,10 +2030,6 @@ static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
1987 drm_mode_destroy(encoder->dev, 2030 drm_mode_destroy(encoder->dev,
1988 sdvo_priv->sdvo_lvds_fixed_mode); 2031 sdvo_priv->sdvo_lvds_fixed_mode);
1989 2032
1990 if (sdvo_priv->tv_format_property)
1991 drm_property_destroy(encoder->dev,
1992 sdvo_priv->tv_format_property);
1993
1994 drm_encoder_cleanup(encoder); 2033 drm_encoder_cleanup(encoder);
1995 kfree(intel_encoder); 2034 kfree(intel_encoder);
1996} 2035}
@@ -2045,12 +2084,15 @@ intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
2045} 2084}
2046 2085
2047static bool 2086static bool
2048intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output) 2087intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output, int device)
2049{ 2088{
2050 struct intel_sdvo_priv *sdvo_priv = output->dev_priv; 2089 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
2051 uint8_t status; 2090 uint8_t status;
2052 2091
2053 intel_sdvo_set_target_output(output, sdvo_priv->controlled_output); 2092 if (device == 0)
2093 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS0);
2094 else
2095 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS1);
2054 2096
2055 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0); 2097 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
2056 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1); 2098 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
@@ -2157,96 +2199,228 @@ static struct dmi_system_id intel_sdvo_bad_tv[] = {
2157}; 2199};
2158 2200
2159static bool 2201static bool
2160intel_sdvo_output_setup(struct intel_encoder *intel_encoder, 2202intel_sdvo_connector_alloc (struct intel_connector **ret)
2161 struct intel_connector *intel_connector, 2203{
2162 uint16_t flags) 2204 struct intel_connector *intel_connector;
2205 struct intel_sdvo_connector *sdvo_connector;
2206
2207 *ret = kzalloc(sizeof(*intel_connector) +
2208 sizeof(*sdvo_connector), GFP_KERNEL);
2209 if (!*ret)
2210 return false;
2211
2212 intel_connector = *ret;
2213 sdvo_connector = (struct intel_sdvo_connector *)(intel_connector + 1);
2214 intel_connector->dev_priv = sdvo_connector;
2215
2216 return true;
2217}
2218
2219static void
2220intel_sdvo_connector_create (struct drm_encoder *encoder,
2221 struct drm_connector *connector)
2222{
2223 drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs,
2224 connector->connector_type);
2225
2226 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2227
2228 connector->interlace_allowed = 0;
2229 connector->doublescan_allowed = 0;
2230 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2231
2232 drm_mode_connector_attach_encoder(connector, encoder);
2233 drm_sysfs_connector_add(connector);
2234}
2235
2236static bool
2237intel_sdvo_dvi_init(struct intel_encoder *intel_encoder, int device)
2163{ 2238{
2164 struct drm_connector *connector = &intel_connector->base;
2165 struct drm_encoder *encoder = &intel_encoder->enc; 2239 struct drm_encoder *encoder = &intel_encoder->enc;
2166 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 2240 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2167 bool ret = true, registered = false; 2241 struct drm_connector *connector;
2242 struct intel_connector *intel_connector;
2243 struct intel_sdvo_connector *sdvo_connector;
2244
2245 if (!intel_sdvo_connector_alloc(&intel_connector))
2246 return false;
2247
2248 sdvo_connector = intel_connector->dev_priv;
2249
2250 if (device == 0) {
2251 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS0;
2252 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2253 } else if (device == 1) {
2254 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS1;
2255 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2256 }
2257
2258 connector = &intel_connector->base;
2259 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2260 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2261
2262 if (intel_sdvo_get_supp_encode(intel_encoder, &sdvo_priv->encode)
2263 && intel_sdvo_get_digital_encoding_mode(intel_encoder, device)
2264 && sdvo_priv->is_hdmi) {
2265 /* enable hdmi encoding mode if supported */
2266 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI);
2267 intel_sdvo_set_colorimetry(intel_encoder,
2268 SDVO_COLORIMETRY_RGB256);
2269 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2270 }
2271 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2272 (1 << INTEL_ANALOG_CLONE_BIT);
2273
2274 intel_sdvo_connector_create(encoder, connector);
2275
2276 return true;
2277}
2278
2279static bool
2280intel_sdvo_tv_init(struct intel_encoder *intel_encoder, int type)
2281{
2282 struct drm_encoder *encoder = &intel_encoder->enc;
2283 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2284 struct drm_connector *connector;
2285 struct intel_connector *intel_connector;
2286 struct intel_sdvo_connector *sdvo_connector;
2287
2288 if (!intel_sdvo_connector_alloc(&intel_connector))
2289 return false;
2290
2291 connector = &intel_connector->base;
2292 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2293 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2294 sdvo_connector = intel_connector->dev_priv;
2295
2296 sdvo_priv->controlled_output |= type;
2297 sdvo_connector->output_flag = type;
2298
2299 sdvo_priv->is_tv = true;
2300 intel_encoder->needs_tv_clock = true;
2301 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
2302
2303 intel_sdvo_connector_create(encoder, connector);
2304
2305 intel_sdvo_tv_create_property(connector, type);
2306
2307 intel_sdvo_create_enhance_property(connector);
2308
2309 return true;
2310}
2311
2312static bool
2313intel_sdvo_analog_init(struct intel_encoder *intel_encoder, int device)
2314{
2315 struct drm_encoder *encoder = &intel_encoder->enc;
2316 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2317 struct drm_connector *connector;
2318 struct intel_connector *intel_connector;
2319 struct intel_sdvo_connector *sdvo_connector;
2320
2321 if (!intel_sdvo_connector_alloc(&intel_connector))
2322 return false;
2323
2324 connector = &intel_connector->base;
2325 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2326 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2327 sdvo_connector = intel_connector->dev_priv;
2328
2329 if (device == 0) {
2330 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB0;
2331 sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2332 } else if (device == 1) {
2333 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB1;
2334 sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2335 }
2336
2337 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2338 (1 << INTEL_ANALOG_CLONE_BIT);
2339
2340 intel_sdvo_connector_create(encoder, connector);
2341 return true;
2342}
2343
2344static bool
2345intel_sdvo_lvds_init(struct intel_encoder *intel_encoder, int device)
2346{
2347 struct drm_encoder *encoder = &intel_encoder->enc;
2348 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2349 struct drm_connector *connector;
2350 struct intel_connector *intel_connector;
2351 struct intel_sdvo_connector *sdvo_connector;
2352
2353 if (!intel_sdvo_connector_alloc(&intel_connector))
2354 return false;
2355
2356 connector = &intel_connector->base;
2357 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2358 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2359 sdvo_connector = intel_connector->dev_priv;
2360
2361 sdvo_priv->is_lvds = true;
2362
2363 if (device == 0) {
2364 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS0;
2365 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2366 } else if (device == 1) {
2367 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS1;
2368 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2369 }
2370
2371 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
2372 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
2373
2374 intel_sdvo_connector_create(encoder, connector);
2375 intel_sdvo_create_enhance_property(connector);
2376 return true;
2377}
2378
2379static bool
2380intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags)
2381{
2382 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2168 2383
2169 sdvo_priv->is_tv = false; 2384 sdvo_priv->is_tv = false;
2170 intel_encoder->needs_tv_clock = false; 2385 intel_encoder->needs_tv_clock = false;
2171 sdvo_priv->is_lvds = false; 2386 sdvo_priv->is_lvds = false;
2172 2387
2173 if (device_is_registered(&connector->kdev)) { 2388 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2174 drm_sysfs_connector_remove(connector);
2175 registered = true;
2176 }
2177 2389
2178 if (flags & 2390 if (flags & SDVO_OUTPUT_TMDS0)
2179 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) { 2391 if (!intel_sdvo_dvi_init(intel_encoder, 0))
2180 if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0) 2392 return false;
2181 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0; 2393
2182 else 2394 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2183 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1; 2395 if (!intel_sdvo_dvi_init(intel_encoder, 1))
2184 2396 return false;
2185 encoder->encoder_type = DRM_MODE_ENCODER_TMDS; 2397
2186 connector->connector_type = DRM_MODE_CONNECTOR_DVID; 2398 /* TV has no XXX1 function block */
2187 2399 if ((flags & SDVO_OUTPUT_SVID0) && !dmi_check_system(intel_sdvo_bad_tv))
2188 if (intel_sdvo_get_supp_encode(intel_encoder, 2400 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_SVID0))
2189 &sdvo_priv->encode) && 2401 return false;
2190 intel_sdvo_get_digital_encoding_mode(intel_encoder) && 2402
2191 sdvo_priv->is_hdmi) { 2403 if (flags & SDVO_OUTPUT_CVBS0)
2192 /* enable hdmi encoding mode if supported */ 2404 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_CVBS0))
2193 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI); 2405 return false;
2194 intel_sdvo_set_colorimetry(intel_encoder, 2406
2195 SDVO_COLORIMETRY_RGB256); 2407 if (flags & SDVO_OUTPUT_RGB0)
2196 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; 2408 if (!intel_sdvo_analog_init(intel_encoder, 0))
2197 intel_encoder->clone_mask = 2409 return false;
2198 (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | 2410
2199 (1 << INTEL_ANALOG_CLONE_BIT); 2411 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2200 } 2412 if (!intel_sdvo_analog_init(intel_encoder, 1))
2201 } else if ((flags & SDVO_OUTPUT_SVID0) && 2413 return false;
2202 !dmi_check_system(intel_sdvo_bad_tv)) { 2414
2203 2415 if (flags & SDVO_OUTPUT_LVDS0)
2204 sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0; 2416 if (!intel_sdvo_lvds_init(intel_encoder, 0))
2205 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; 2417 return false;
2206 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; 2418
2207 sdvo_priv->is_tv = true; 2419 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2208 intel_encoder->needs_tv_clock = true; 2420 if (!intel_sdvo_lvds_init(intel_encoder, 1))
2209 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; 2421 return false;
2210 } else if (flags & SDVO_OUTPUT_RGB0) {
2211
2212 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0;
2213 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2214 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2215 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2216 (1 << INTEL_ANALOG_CLONE_BIT);
2217 } else if (flags & SDVO_OUTPUT_RGB1) {
2218
2219 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1;
2220 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2221 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2222 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2223 (1 << INTEL_ANALOG_CLONE_BIT);
2224 } else if (flags & SDVO_OUTPUT_CVBS0) {
2225
2226 sdvo_priv->controlled_output = SDVO_OUTPUT_CVBS0;
2227 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2228 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2229 sdvo_priv->is_tv = true;
2230 intel_encoder->needs_tv_clock = true;
2231 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
2232 } else if (flags & SDVO_OUTPUT_LVDS0) {
2233
2234 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0;
2235 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2236 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2237 sdvo_priv->is_lvds = true;
2238 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
2239 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
2240 } else if (flags & SDVO_OUTPUT_LVDS1) {
2241
2242 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1;
2243 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2244 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2245 sdvo_priv->is_lvds = true;
2246 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
2247 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
2248 } else {
2249 2422
2423 if ((flags & SDVO_OUTPUT_MASK) == 0) {
2250 unsigned char bytes[2]; 2424 unsigned char bytes[2];
2251 2425
2252 sdvo_priv->controlled_output = 0; 2426 sdvo_priv->controlled_output = 0;
@@ -2254,29 +2428,25 @@ intel_sdvo_output_setup(struct intel_encoder *intel_encoder,
2254 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n", 2428 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2255 SDVO_NAME(sdvo_priv), 2429 SDVO_NAME(sdvo_priv),
2256 bytes[0], bytes[1]); 2430 bytes[0], bytes[1]);
2257 ret = false; 2431 return false;
2258 } 2432 }
2259 intel_encoder->crtc_mask = (1 << 0) | (1 << 1); 2433 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
2260 2434
2261 if (ret && registered) 2435 return true;
2262 ret = drm_sysfs_connector_add(connector) == 0 ? true : false;
2263
2264
2265 return ret;
2266
2267} 2436}
2268 2437
2269static void intel_sdvo_tv_create_property(struct drm_connector *connector) 2438static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type)
2270{ 2439{
2271 struct drm_encoder *encoder = intel_attached_encoder(connector); 2440 struct drm_encoder *encoder = intel_attached_encoder(connector);
2272 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 2441 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
2273 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 2442 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2443 struct intel_connector *intel_connector = to_intel_connector(connector);
2444 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
2274 struct intel_sdvo_tv_format format; 2445 struct intel_sdvo_tv_format format;
2275 uint32_t format_map, i; 2446 uint32_t format_map, i;
2276 uint8_t status; 2447 uint8_t status;
2277 2448
2278 intel_sdvo_set_target_output(intel_encoder, 2449 intel_sdvo_set_target_output(intel_encoder, type);
2279 sdvo_priv->controlled_output);
2280 2450
2281 intel_sdvo_write_cmd(intel_encoder, 2451 intel_sdvo_write_cmd(intel_encoder,
2282 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0); 2452 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
@@ -2291,28 +2461,28 @@ static void intel_sdvo_tv_create_property(struct drm_connector *connector)
2291 if (format_map == 0) 2461 if (format_map == 0)
2292 return; 2462 return;
2293 2463
2294 sdvo_priv->format_supported_num = 0; 2464 sdvo_connector->format_supported_num = 0;
2295 for (i = 0 ; i < TV_FORMAT_NUM; i++) 2465 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2296 if (format_map & (1 << i)) { 2466 if (format_map & (1 << i)) {
2297 sdvo_priv->tv_format_supported 2467 sdvo_connector->tv_format_supported
2298 [sdvo_priv->format_supported_num++] = 2468 [sdvo_connector->format_supported_num++] =
2299 tv_format_names[i]; 2469 tv_format_names[i];
2300 } 2470 }
2301 2471
2302 2472
2303 sdvo_priv->tv_format_property = 2473 sdvo_connector->tv_format_property =
2304 drm_property_create( 2474 drm_property_create(
2305 connector->dev, DRM_MODE_PROP_ENUM, 2475 connector->dev, DRM_MODE_PROP_ENUM,
2306 "mode", sdvo_priv->format_supported_num); 2476 "mode", sdvo_connector->format_supported_num);
2307 2477
2308 for (i = 0; i < sdvo_priv->format_supported_num; i++) 2478 for (i = 0; i < sdvo_connector->format_supported_num; i++)
2309 drm_property_add_enum( 2479 drm_property_add_enum(
2310 sdvo_priv->tv_format_property, i, 2480 sdvo_connector->tv_format_property, i,
2311 i, sdvo_priv->tv_format_supported[i]); 2481 i, sdvo_connector->tv_format_supported[i]);
2312 2482
2313 sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[0]; 2483 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[0];
2314 drm_connector_attach_property( 2484 drm_connector_attach_property(
2315 connector, sdvo_priv->tv_format_property, 0); 2485 connector, sdvo_connector->tv_format_property, 0);
2316 2486
2317} 2487}
2318 2488
@@ -2320,7 +2490,8 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2320{ 2490{
2321 struct drm_encoder *encoder = intel_attached_encoder(connector); 2491 struct drm_encoder *encoder = intel_attached_encoder(connector);
2322 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 2492 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
2323 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 2493 struct intel_connector *intel_connector = to_intel_connector(connector);
2494 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
2324 struct intel_sdvo_enhancements_reply sdvo_data; 2495 struct intel_sdvo_enhancements_reply sdvo_data;
2325 struct drm_device *dev = connector->dev; 2496 struct drm_device *dev = connector->dev;
2326 uint8_t status; 2497 uint8_t status;
@@ -2339,7 +2510,7 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2339 DRM_DEBUG_KMS("No enhancement is supported\n"); 2510 DRM_DEBUG_KMS("No enhancement is supported\n");
2340 return; 2511 return;
2341 } 2512 }
2342 if (sdvo_priv->is_tv) { 2513 if (IS_TV(sdvo_priv)) {
2343 /* when horizontal overscan is supported, Add the left/right 2514 /* when horizontal overscan is supported, Add the left/right
2344 * property 2515 * property
2345 */ 2516 */
@@ -2487,8 +2658,6 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2487 "default %d, current %d\n", 2658 "default %d, current %d\n",
2488 data_value[0], data_value[1], response); 2659 data_value[0], data_value[1], response);
2489 } 2660 }
2490 }
2491 if (sdvo_priv->is_tv) {
2492 if (sdvo_data.saturation) { 2661 if (sdvo_data.saturation) {
2493 intel_sdvo_write_cmd(intel_encoder, 2662 intel_sdvo_write_cmd(intel_encoder,
2494 SDVO_CMD_GET_MAX_SATURATION, NULL, 0); 2663 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
@@ -2584,7 +2753,7 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2584 data_value[0], data_value[1], response); 2753 data_value[0], data_value[1], response);
2585 } 2754 }
2586 } 2755 }
2587 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { 2756 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
2588 if (sdvo_data.brightness) { 2757 if (sdvo_data.brightness) {
2589 intel_sdvo_write_cmd(intel_encoder, 2758 intel_sdvo_write_cmd(intel_encoder,
2590 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0); 2759 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
@@ -2624,11 +2793,8 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2624bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) 2793bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
2625{ 2794{
2626 struct drm_i915_private *dev_priv = dev->dev_private; 2795 struct drm_i915_private *dev_priv = dev->dev_private;
2627 struct drm_connector *connector;
2628 struct intel_encoder *intel_encoder; 2796 struct intel_encoder *intel_encoder;
2629 struct intel_connector *intel_connector;
2630 struct intel_sdvo_priv *sdvo_priv; 2797 struct intel_sdvo_priv *sdvo_priv;
2631
2632 u8 ch[0x40]; 2798 u8 ch[0x40];
2633 int i; 2799 int i;
2634 2800
@@ -2637,12 +2803,6 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
2637 return false; 2803 return false;
2638 } 2804 }
2639 2805
2640 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2641 if (!intel_connector) {
2642 kfree(intel_encoder);
2643 return false;
2644 }
2645
2646 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1); 2806 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1);
2647 sdvo_priv->sdvo_reg = sdvo_reg; 2807 sdvo_priv->sdvo_reg = sdvo_reg;
2648 2808
@@ -2691,40 +2851,20 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
2691 /* Wrap with our custom algo which switches to DDC mode */ 2851 /* Wrap with our custom algo which switches to DDC mode */
2692 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo; 2852 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
2693 2853
2854 /* encoder type will be decided later */
2855 drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0);
2856 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
2857
2694 /* In default case sdvo lvds is false */ 2858 /* In default case sdvo lvds is false */
2695 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps); 2859 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps);
2696 2860
2697 if (intel_sdvo_output_setup(intel_encoder, intel_connector, 2861 if (intel_sdvo_output_setup(intel_encoder,
2698 sdvo_priv->caps.output_flags) != true) { 2862 sdvo_priv->caps.output_flags) != true) {
2699 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", 2863 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
2700 sdvo_reg == SDVOB ? 'B' : 'C'); 2864 sdvo_reg == SDVOB ? 'B' : 'C');
2701 goto err_i2c; 2865 goto err_i2c;
2702 } 2866 }
2703 2867
2704
2705 connector = &intel_connector->base;
2706 drm_connector_init(dev, connector, &intel_sdvo_connector_funcs,
2707 connector->connector_type);
2708
2709 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2710 connector->interlace_allowed = 0;
2711 connector->doublescan_allowed = 0;
2712 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2713
2714 drm_encoder_init(dev, &intel_encoder->enc,
2715 &intel_sdvo_enc_funcs, intel_encoder->enc.encoder_type);
2716
2717 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
2718
2719 drm_mode_connector_attach_encoder(&intel_connector->base, &intel_encoder->enc);
2720 if (sdvo_priv->is_tv)
2721 intel_sdvo_tv_create_property(connector);
2722
2723 if (sdvo_priv->is_tv || sdvo_priv->is_lvds)
2724 intel_sdvo_create_enhance_property(connector);
2725
2726 drm_sysfs_connector_add(connector);
2727
2728 intel_sdvo_select_ddc_bus(sdvo_priv); 2868 intel_sdvo_select_ddc_bus(sdvo_priv);
2729 2869
2730 /* Set the input timing to the screen. Assume always input 0. */ 2870 /* Set the input timing to the screen. Assume always input 0. */
@@ -2763,7 +2903,6 @@ err_i2c:
2763 intel_i2c_destroy(intel_encoder->i2c_bus); 2903 intel_i2c_destroy(intel_encoder->i2c_bus);
2764err_inteloutput: 2904err_inteloutput:
2765 kfree(intel_encoder); 2905 kfree(intel_encoder);
2766 kfree(intel_connector);
2767 2906
2768 return false; 2907 return false;
2769} 2908}