2 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
5 * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
7 /**************************************************************************
9 Copyright © 2006 Dave Airlie
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
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 **************************************************************************/
37 #define CH7xxx_REG_VID 0x4a
38 #define CH7xxx_REG_DID 0x4b
40 #define CH7011_VID 0x83 /* 7010 as well */
41 #define CH7010B_VID 0x05
42 #define CH7009A_VID 0x84
43 #define CH7009B_VID 0x85
44 #define CH7301_VID 0x95
46 #define CH7xxx_VID 0x84
47 #define CH7xxx_DID 0x17
48 #define CH7010_DID 0x16
50 #define CH7xxx_NUM_REGS 0x4c
52 #define CH7xxx_CM 0x1c
53 #define CH7xxx_CM_XCM (1<<0)
54 #define CH7xxx_CM_MCP (1<<2)
55 #define CH7xxx_INPUT_CLOCK 0x1d
56 #define CH7xxx_GPIO 0x1e
57 #define CH7xxx_GPIO_HPIR (1<<3)
58 #define CH7xxx_IDF 0x1f
60 #define CH7xxx_IDF_HSP (1<<3)
61 #define CH7xxx_IDF_VSP (1<<4)
63 #define CH7xxx_CONNECTION_DETECT 0x20
64 #define CH7xxx_CDET_DVI (1<<5)
66 #define CH7301_DAC_CNTL 0x21
67 #define CH7301_HOTPLUG 0x23
68 #define CH7xxx_TCTL 0x31
69 #define CH7xxx_TVCO 0x32
70 #define CH7xxx_TPCP 0x33
71 #define CH7xxx_TPD 0x34
72 #define CH7xxx_TPVT 0x35
73 #define CH7xxx_TLPF 0x36
74 #define CH7xxx_TCT 0x37
75 #define CH7301_TEST_PATTERN 0x48
77 #define CH7xxx_PM 0x49
78 #define CH7xxx_PM_FPD (1<<0)
79 #define CH7301_PM_DACPD0 (1<<1)
80 #define CH7301_PM_DACPD1 (1<<2)
81 #define CH7301_PM_DACPD2 (1<<3)
82 #define CH7xxx_PM_DVIL (1<<6)
83 #define CH7xxx_PM_DVIP (1<<7)
85 #define CH7301_SYNC_POLARITY 0x56
86 #define CH7301_SYNC_RGB_YUV (1<<0)
87 #define CH7301_SYNC_POL_DVI (1<<5)
90 * driver for the Chrontel 7xxx DVI chip over DVO.
93 static struct ch7xxx_id_struct
{
97 { CH7011_VID
, "CH7011" },
98 { CH7010B_VID
, "CH7010B" },
99 { CH7009A_VID
, "CH7009A" },
100 { CH7009B_VID
, "CH7009B" },
101 { CH7301_VID
, "CH7301" },
104 static struct ch7xxx_did_struct
{
108 { CH7xxx_DID
, "CH7XXX" },
109 { CH7010_DID
, "CH7010B" },
116 static char *ch7xxx_get_id(uint8_t vid
)
120 for (i
= 0; i
< ARRAY_SIZE(ch7xxx_ids
); i
++) {
121 if (ch7xxx_ids
[i
].vid
== vid
)
122 return ch7xxx_ids
[i
].name
;
128 static char *ch7xxx_get_did(uint8_t did
)
132 for (i
= 0; i
< ARRAY_SIZE(ch7xxx_dids
); i
++) {
133 if (ch7xxx_dids
[i
].did
== did
)
134 return ch7xxx_dids
[i
].name
;
140 /** Reads an 8 bit register */
141 static bool ch7xxx_readb(struct intel_dvo_device
*dvo
, int addr
, uint8_t *ch
)
143 struct ch7xxx_priv
*ch7xxx
= dvo
->dev_priv
;
144 struct i2c_adapter
*adapter
= dvo
->i2c_bus
;
148 struct i2c_msg msgs
[] = {
150 .addr
= dvo
->slave_addr
,
156 .addr
= dvo
->slave_addr
,
163 out_buf
[0] = (u8
) addr
;
166 if (i2c_transfer(adapter
, msgs
, 2) == 2) {
171 if (!ch7xxx
->quiet
) {
172 DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n",
173 addr
, adapter
->name
, dvo
->slave_addr
);
178 /** Writes an 8 bit register */
179 static bool ch7xxx_writeb(struct intel_dvo_device
*dvo
, int addr
, uint8_t ch
)
181 struct ch7xxx_priv
*ch7xxx
= dvo
->dev_priv
;
182 struct i2c_adapter
*adapter
= dvo
->i2c_bus
;
184 struct i2c_msg msg
= {
185 .addr
= dvo
->slave_addr
,
191 out_buf
[0] = (uint8_t) addr
;
194 if (i2c_transfer(adapter
, &msg
, 1) == 1)
197 if (!ch7xxx
->quiet
) {
198 DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
199 addr
, adapter
->name
, dvo
->slave_addr
);
205 static bool ch7xxx_init(struct intel_dvo_device
*dvo
,
206 struct i2c_adapter
*adapter
)
208 /* this will detect the CH7xxx chip on the specified i2c bus */
209 struct ch7xxx_priv
*ch7xxx
;
210 uint8_t vendor
, device
;
213 ch7xxx
= kzalloc(sizeof(struct ch7xxx_priv
), GFP_KERNEL
);
217 dvo
->i2c_bus
= adapter
;
218 dvo
->dev_priv
= ch7xxx
;
219 ch7xxx
->quiet
= true;
221 if (!ch7xxx_readb(dvo
, CH7xxx_REG_VID
, &vendor
))
224 name
= ch7xxx_get_id(vendor
);
226 DRM_DEBUG_KMS("ch7xxx not detected; got 0x%02x from %s "
228 vendor
, adapter
->name
, dvo
->slave_addr
);
233 if (!ch7xxx_readb(dvo
, CH7xxx_REG_DID
, &device
))
236 devid
= ch7xxx_get_did(device
);
238 DRM_DEBUG_KMS("ch7xxx not detected; got 0x%02x from %s "
240 vendor
, adapter
->name
, dvo
->slave_addr
);
244 ch7xxx
->quiet
= false;
245 DRM_DEBUG_KMS("Detected %s chipset, vendor/device ID 0x%02x/0x%02x\n",
246 name
, vendor
, device
);
249 kfree(ch7xxx
, sizeof (struct ch7xxx_priv
));
253 static enum drm_connector_status
ch7xxx_detect(struct intel_dvo_device
*dvo
)
255 uint8_t cdet
, orig_pm
, pm
;
257 (void) ch7xxx_readb(dvo
, CH7xxx_PM
, &orig_pm
);
260 pm
&= ~CH7xxx_PM_FPD
;
261 pm
|= CH7xxx_PM_DVIL
| CH7xxx_PM_DVIP
;
263 (void) ch7xxx_writeb(dvo
, CH7xxx_PM
, pm
);
265 (void) ch7xxx_readb(dvo
, CH7xxx_CONNECTION_DETECT
, &cdet
);
267 (void) ch7xxx_writeb(dvo
, CH7xxx_PM
, orig_pm
);
269 if (cdet
& CH7xxx_CDET_DVI
)
270 return connector_status_connected
;
271 return connector_status_disconnected
;
275 static int ch7xxx_mode_valid(struct intel_dvo_device
*dvo
,
276 struct drm_display_mode
*mode
)
278 if (mode
->clock
> 165000)
279 return MODE_CLOCK_HIGH
;
284 static void ch7xxx_mode_set(struct intel_dvo_device
*dvo
,
285 struct drm_display_mode
*mode
,
287 struct drm_display_mode
*adjusted_mode
)
289 uint8_t tvco
, tpcp
, tpd
, tlpf
, idf
;
291 if (mode
->clock
<= 65000) {
303 (void) ch7xxx_writeb(dvo
, CH7xxx_TCTL
, 0x00);
304 (void) ch7xxx_writeb(dvo
, CH7xxx_TVCO
, tvco
);
305 (void) ch7xxx_writeb(dvo
, CH7xxx_TPCP
, tpcp
);
306 (void) ch7xxx_writeb(dvo
, CH7xxx_TPD
, tpd
);
307 (void) ch7xxx_writeb(dvo
, CH7xxx_TPVT
, 0x30);
308 (void) ch7xxx_writeb(dvo
, CH7xxx_TLPF
, tlpf
);
309 (void) ch7xxx_writeb(dvo
, CH7xxx_TCT
, 0x00);
311 (void) ch7xxx_readb(dvo
, CH7xxx_IDF
, &idf
);
313 idf
&= ~(CH7xxx_IDF_HSP
| CH7xxx_IDF_VSP
);
314 if (mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
315 idf
|= CH7xxx_IDF_HSP
;
317 if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
318 idf
|= CH7xxx_IDF_HSP
;
320 (void) ch7xxx_writeb(dvo
, CH7xxx_IDF
, idf
);
323 /* set the CH7xxx power state */
324 static void ch7xxx_dpms(struct intel_dvo_device
*dvo
, bool enable
)
327 (void) ch7xxx_writeb(dvo
, CH7xxx_PM
, CH7xxx_PM_DVIL
| CH7xxx_PM_DVIP
);
329 (void) ch7xxx_writeb(dvo
, CH7xxx_PM
, CH7xxx_PM_FPD
);
332 static bool ch7xxx_get_hw_state(struct intel_dvo_device
*dvo
)
336 ch7xxx_readb(dvo
, CH7xxx_PM
, &val
);
338 if (val
& (CH7xxx_PM_DVIL
| CH7xxx_PM_DVIP
))
344 static void ch7xxx_dump_regs(struct intel_dvo_device
*dvo
)
348 for (i
= 0; i
< CH7xxx_NUM_REGS
; i
++) {
351 DRM_LOG_KMS("\n %02X: ", i
);
352 (void) ch7xxx_readb(dvo
, i
, &val
);
353 DRM_LOG_KMS("%02X ", val
);
357 static void ch7xxx_destroy(struct intel_dvo_device
*dvo
)
359 struct ch7xxx_priv
*ch7xxx
= dvo
->dev_priv
;
362 kfree(ch7xxx
, sizeof (struct ch7xxx_priv
));
363 dvo
->dev_priv
= NULL
;
367 struct intel_dvo_dev_ops ch7xxx_ops
= {
369 .detect
= ch7xxx_detect
,
370 .mode_valid
= ch7xxx_mode_valid
,
371 .mode_set
= ch7xxx_mode_set
,
373 .get_hw_state
= ch7xxx_get_hw_state
,
374 .dump_regs
= ch7xxx_dump_regs
,
375 .destroy
= ch7xxx_destroy
,