Revert "Fix issue in gfx-drm integration" & "drm: illumos/gfx-drm integration"
[unleashed-userland.git] / components / openindiana / drm / drm / i915 / src / dvo_sil164.c
blobc9c7c08748286d31a89182cfea6dd9d87307a3b3
1 /*
2 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
3 */
4 /*
5 * Copyright (c) 2012, 2013, Intel Corporation. All rights reserved.
6 */
7 /**************************************************************************
9 Copyright © 2006 Dave Airlie
11 All Rights Reserved.
13 Permission is hereby granted, free of charge, to any person obtaining a
14 copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sub license, and/or sell copies of the Software, and to
18 permit persons to whom the Software is furnished to do so, subject to
19 the following conditions:
21 The above copyright notice and this permission notice (including the
22 next paragraph) shall be included in all copies or substantial portions
23 of the Software.
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
28 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
30 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 **************************************************************************/
35 #include "dvo.h"
37 #define SIL164_VID 0x0001
38 #define SIL164_DID 0x0006
40 #define SIL164_VID_LO 0x00
41 #define SIL164_VID_HI 0x01
42 #define SIL164_DID_LO 0x02
43 #define SIL164_DID_HI 0x03
44 #define SIL164_REV 0x04
45 #define SIL164_RSVD 0x05
46 #define SIL164_FREQ_LO 0x06
47 #define SIL164_FREQ_HI 0x07
49 #define SIL164_REG8 0x08
50 #define SIL164_8_VEN (1<<5)
51 #define SIL164_8_HEN (1<<4)
52 #define SIL164_8_DSEL (1<<3)
53 #define SIL164_8_BSEL (1<<2)
54 #define SIL164_8_EDGE (1<<1)
55 #define SIL164_8_PD (1<<0)
57 #define SIL164_REG9 0x09
58 #define SIL164_9_VLOW (1<<7)
59 #define SIL164_9_MSEL_MASK (0x7<<4)
60 #define SIL164_9_TSEL (1<<3)
61 #define SIL164_9_RSEN (1<<2)
62 #define SIL164_9_HTPLG (1<<1)
63 #define SIL164_9_MDI (1<<0)
65 #define SIL164_REGC 0x0c
67 struct sil164_priv {
68 //I2CDevRec d;
69 bool quiet;
72 #define SILPTR(d) ((SIL164Ptr)(d->DriverPrivate.ptr))
74 static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
76 struct sil164_priv *sil = dvo->dev_priv;
77 struct i2c_adapter *adapter = dvo->i2c_bus;
78 u8 out_buf[2];
79 u8 in_buf[2];
81 struct i2c_msg msgs[] = {
83 .addr = dvo->slave_addr,
84 .flags = 0,
85 .len = 1,
86 .buf = out_buf,
89 .addr = dvo->slave_addr,
90 .flags = I2C_M_RD,
91 .len = 1,
92 .buf = in_buf,
96 out_buf[0] = (u8) addr;
97 out_buf[1] = 0;
99 if (i2c_transfer(adapter, msgs, 2) == 2) {
100 *ch = in_buf[0];
101 return true;
104 if (!sil->quiet) {
105 DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n",
106 addr, adapter->name, dvo->slave_addr);
108 return false;
111 static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
113 struct sil164_priv *sil= dvo->dev_priv;
114 struct i2c_adapter *adapter = dvo->i2c_bus;
115 uint8_t out_buf[2];
116 struct i2c_msg msg = {
117 .addr = dvo->slave_addr,
118 .flags = 0,
119 .len = 2,
120 .buf = out_buf,
123 out_buf[0] = (uint8_t) addr;
124 out_buf[1] = ch;
126 if (i2c_transfer(adapter, &msg, 1) == 1)
127 return true;
129 if (!sil->quiet) {
130 DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
131 addr, adapter->name, dvo->slave_addr);
134 return false;
137 /* Silicon Image 164 driver for chip on i2c bus */
138 static bool sil164_init(struct intel_dvo_device *dvo,
139 struct i2c_adapter *adapter)
141 /* this will detect the SIL164 chip on the specified i2c bus */
142 struct sil164_priv *sil;
143 unsigned char ch;
145 sil = kzalloc(sizeof(struct sil164_priv), GFP_KERNEL);
146 if (sil == NULL)
147 return false;
149 dvo->i2c_bus = adapter;
150 dvo->dev_priv = sil;
151 sil->quiet = true;
153 if (!sil164_readb(dvo, SIL164_VID_LO, &ch))
154 goto out;
156 if (ch != (SIL164_VID & 0xff)) {
157 DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n",
158 ch, adapter->name, dvo->slave_addr);
159 goto out;
162 if (!sil164_readb(dvo, SIL164_DID_LO, &ch))
163 goto out;
165 if (ch != (SIL164_DID & 0xff)) {
166 DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n",
167 ch, adapter->name, dvo->slave_addr);
168 goto out;
170 sil->quiet = false;
172 DRM_DEBUG_KMS("init sil164 dvo controller successfully!\n");
173 return true;
175 out:
176 kfree(sil, sizeof(struct sil164_priv));
177 return false;
180 static enum drm_connector_status sil164_detect(struct intel_dvo_device *dvo)
182 uint8_t reg9;
184 (void) sil164_readb(dvo, SIL164_REG9, &reg9);
186 if (reg9 & SIL164_9_HTPLG)
187 return connector_status_connected;
188 else
189 return connector_status_disconnected;
192 /* LINTED */
193 static int sil164_mode_valid(struct intel_dvo_device *dvo,
194 /* LINTED */
195 struct drm_display_mode *mode)
197 return MODE_OK;
200 /* LINTED */
201 static void sil164_mode_set(struct intel_dvo_device *dvo,
202 /* LINTED */
203 struct drm_display_mode *mode,
204 /* LINTED */
205 struct drm_display_mode *adjusted_mode)
207 /* As long as the basics are set up, since we don't have clock
208 * dependencies in the mode setup, we can just leave the
209 * registers alone and everything will work fine.
211 /* recommended programming sequence from doc */
212 /*sil164_writeb(sil, 0x08, 0x30);
213 sil164_writeb(sil, 0x09, 0x00);
214 sil164_writeb(sil, 0x0a, 0x90);
215 sil164_writeb(sil, 0x0c, 0x89);
216 sil164_writeb(sil, 0x08, 0x31);*/
217 /* don't do much */
218 return;
221 /* set the SIL164 power state */
222 static void sil164_dpms(struct intel_dvo_device *dvo, bool enable)
224 int ret;
225 unsigned char ch;
227 ret = sil164_readb(dvo, SIL164_REG8, &ch);
228 if (ret == false)
229 return;
231 if (enable)
232 ch |= SIL164_8_PD;
233 else
234 ch &= ~SIL164_8_PD;
236 (void) sil164_writeb(dvo, SIL164_REG8, ch);
237 return;
240 static bool sil164_get_hw_state(struct intel_dvo_device *dvo)
242 int ret;
243 unsigned char ch;
245 ret = sil164_readb(dvo, SIL164_REG8, &ch);
246 if (ret == false)
247 return false;
249 if (ch & SIL164_8_PD)
250 return true;
251 else
252 return false;
254 static void sil164_dump_regs(struct intel_dvo_device *dvo)
256 uint8_t val;
258 (void) sil164_readb(dvo, SIL164_FREQ_LO, &val);
259 DRM_LOG_KMS("SIL164_FREQ_LO: 0x%02x\n", val);
260 (void) sil164_readb(dvo, SIL164_FREQ_HI, &val);
261 DRM_LOG_KMS("SIL164_FREQ_HI: 0x%02x\n", val);
262 (void) sil164_readb(dvo, SIL164_REG8, &val);
263 DRM_LOG_KMS("SIL164_REG8: 0x%02x\n", val);
264 (void) sil164_readb(dvo, SIL164_REG9, &val);
265 DRM_LOG_KMS("SIL164_REG9: 0x%02x\n", val);
266 (void) sil164_readb(dvo, SIL164_REGC, &val);
267 DRM_LOG_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;
274 if (sil) {
275 kfree(sil, sizeof (struct sil164_priv));
276 dvo->dev_priv = NULL;
280 struct intel_dvo_dev_ops sil164_ops = {
281 .init = sil164_init,
282 .detect = sil164_detect,
283 .mode_valid = sil164_mode_valid,
284 .mode_set = sil164_mode_set,
285 .dpms = sil164_dpms,
286 .get_hw_state = sil164_get_hw_state,
287 .dump_regs = sil164_dump_regs,
288 .destroy = sil164_destroy,