1 /**************************************************************************
3 Copyright © 2006 Dave Airlie
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sub license, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice (including the
16 next paragraph) shall be included in all copies or substantial portions
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
23 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "intel_display_types.h"
30 #include "intel_dvo_dev.h"
32 #define SIL164_VID 0x0001
33 #define SIL164_DID 0x0006
35 #define SIL164_VID_LO 0x00
36 #define SIL164_VID_HI 0x01
37 #define SIL164_DID_LO 0x02
38 #define SIL164_DID_HI 0x03
39 #define SIL164_REV 0x04
40 #define SIL164_RSVD 0x05
41 #define SIL164_FREQ_LO 0x06
42 #define SIL164_FREQ_HI 0x07
44 #define SIL164_REG8 0x08
45 #define SIL164_8_VEN (1<<5)
46 #define SIL164_8_HEN (1<<4)
47 #define SIL164_8_DSEL (1<<3)
48 #define SIL164_8_BSEL (1<<2)
49 #define SIL164_8_EDGE (1<<1)
50 #define SIL164_8_PD (1<<0)
52 #define SIL164_REG9 0x09
53 #define SIL164_9_VLOW (1<<7)
54 #define SIL164_9_MSEL_MASK (0x7<<4)
55 #define SIL164_9_TSEL (1<<3)
56 #define SIL164_9_RSEN (1<<2)
57 #define SIL164_9_HTPLG (1<<1)
58 #define SIL164_9_MDI (1<<0)
60 #define SIL164_REGC 0x0c
61 #define SIL164_C_SCNT (1<<7)
62 #define SIL164_C_PLLF_MASK (0xf<<1)
63 #define SIL164_C_PLLF_REC (4<<1)
64 #define SIL164_C_PFEN (1<<0)
71 #define SILPTR(d) ((SIL164Ptr)(d->DriverPrivate.ptr))
73 static bool sil164_readb(struct intel_dvo_device *dvo, int addr, u8 *ch)
75 struct sil164_priv *sil = dvo->dev_priv;
76 struct i2c_adapter *adapter = dvo->i2c_bus;
80 struct i2c_msg msgs[] = {
82 .addr = dvo->slave_addr,
88 .addr = dvo->slave_addr,
98 if (i2c_transfer(adapter, msgs, 2) == 2) {
104 DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n",
105 addr, adapter->name, dvo->slave_addr);
110 static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, u8 ch)
112 struct sil164_priv *sil = dvo->dev_priv;
113 struct i2c_adapter *adapter = dvo->i2c_bus;
115 struct i2c_msg msg = {
116 .addr = dvo->slave_addr,
125 if (i2c_transfer(adapter, &msg, 1) == 1)
129 DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
130 addr, adapter->name, dvo->slave_addr);
136 /* Silicon Image 164 driver for chip on i2c bus */
137 static bool sil164_init(struct intel_dvo_device *dvo,
138 struct i2c_adapter *adapter)
140 /* this will detect the SIL164 chip on the specified i2c bus */
141 struct sil164_priv *sil;
144 sil = kzalloc(sizeof(*sil), GFP_KERNEL);
148 dvo->i2c_bus = adapter;
152 if (!sil164_readb(dvo, SIL164_VID_LO, &ch))
155 if (ch != (SIL164_VID & 0xff)) {
156 DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n",
157 ch, adapter->name, dvo->slave_addr);
161 if (!sil164_readb(dvo, SIL164_DID_LO, &ch))
164 if (ch != (SIL164_DID & 0xff)) {
165 DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n",
166 ch, adapter->name, dvo->slave_addr);
171 DRM_DEBUG_KMS("init sil164 dvo controller successfully!\n");
179 static enum drm_connector_status sil164_detect(struct intel_dvo_device *dvo)
183 sil164_readb(dvo, SIL164_REG9, ®9);
185 if (reg9 & SIL164_9_HTPLG)
186 return connector_status_connected;
188 return connector_status_disconnected;
191 static enum drm_mode_status sil164_mode_valid(struct intel_dvo_device *dvo,
192 struct drm_display_mode *mode)
197 static void sil164_mode_set(struct intel_dvo_device *dvo,
198 const struct drm_display_mode *mode,
199 const struct drm_display_mode *adjusted_mode)
201 /* As long as the basics are set up, since we don't have clock
202 * dependencies in the mode setup, we can just leave the
203 * registers alone and everything will work fine.
205 /* recommended programming sequence from doc */
206 /*sil164_writeb(sil, 0x08, 0x30);
207 sil164_writeb(sil, 0x09, 0x00);
208 sil164_writeb(sil, 0x0a, 0x90);
209 sil164_writeb(sil, 0x0c, 0x89);
210 sil164_writeb(sil, 0x08, 0x31);*/
213 sil164_writeb(dvo, SIL164_REG8,
214 SIL164_8_VEN | SIL164_8_HEN);
215 sil164_writeb(dvo, SIL164_REG9,
217 sil164_writeb(dvo, SIL164_REGC,
218 SIL164_C_PLLF_REC | SIL164_C_PFEN);
221 /* set the SIL164 power state */
222 static void sil164_dpms(struct intel_dvo_device *dvo, bool enable)
227 ret = sil164_readb(dvo, SIL164_REG8, &ch);
236 sil164_writeb(dvo, SIL164_REG8, ch);
239 static bool sil164_get_hw_state(struct intel_dvo_device *dvo)
244 ret = sil164_readb(dvo, SIL164_REG8, &ch);
248 if (ch & SIL164_8_PD)
254 static void sil164_dump_regs(struct intel_dvo_device *dvo)
258 sil164_readb(dvo, SIL164_FREQ_LO, &val);
259 DRM_DEBUG_KMS("SIL164_FREQ_LO: 0x%02x\n", val);
260 sil164_readb(dvo, SIL164_FREQ_HI, &val);
261 DRM_DEBUG_KMS("SIL164_FREQ_HI: 0x%02x\n", val);
262 sil164_readb(dvo, SIL164_REG8, &val);
263 DRM_DEBUG_KMS("SIL164_REG8: 0x%02x\n", val);
264 sil164_readb(dvo, SIL164_REG9, &val);
265 DRM_DEBUG_KMS("SIL164_REG9: 0x%02x\n", val);
266 sil164_readb(dvo, SIL164_REGC, &val);
267 DRM_DEBUG_KMS("SIL164_REGC: 0x%02x\n", val);
270 static void sil164_destroy(struct intel_dvo_device *dvo)
272 struct sil164_priv *sil = dvo->dev_priv;
276 dvo->dev_priv = NULL;
280 const struct intel_dvo_dev_ops sil164_ops = {
282 .detect = sil164_detect,
283 .mode_valid = sil164_mode_valid,
284 .mode_set = sil164_mode_set,
286 .get_hw_state = sil164_get_hw_state,
287 .dump_regs = sil164_dump_regs,
288 .destroy = sil164_destroy,