Subversion Repositories Kolibri OS

Rev

Rev 5060 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3031 serge 1
/*
2
 *
3
 * Copyright (c) 2012 Gilles Dartiguelongue, Thomas Richter
4
 *
5
 * All Rights Reserved.
6
 *
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:
14
 *
15
 * The above copyright notice and this permission notice (including the
16
 * next paragraph) shall be included in all copies or substantial portions
17
 * of the Software.
18
 *
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.
26
 *
27
 */
28
 
29
#include "dvo.h"
30
#include "i915_reg.h"
31
#include "i915_drv.h"
32
 
33
#define NS2501_VID 0x1305
34
#define NS2501_DID 0x6726
35
 
36
#define NS2501_VID_LO 0x00
37
#define NS2501_VID_HI 0x01
38
#define NS2501_DID_LO 0x02
39
#define NS2501_DID_HI 0x03
40
#define NS2501_REV 0x04
41
#define NS2501_RSVD 0x05
42
#define NS2501_FREQ_LO 0x06
43
#define NS2501_FREQ_HI 0x07
44
 
45
#define NS2501_REG8 0x08
46
#define NS2501_8_VEN (1<<5)
47
#define NS2501_8_HEN (1<<4)
48
#define NS2501_8_DSEL (1<<3)
49
#define NS2501_8_BPAS (1<<2)
50
#define NS2501_8_RSVD (1<<1)
51
#define NS2501_8_PD (1<<0)
52
 
53
#define NS2501_REG9 0x09
54
#define NS2501_9_VLOW (1<<7)
55
#define NS2501_9_MSEL_MASK (0x7<<4)
56
#define NS2501_9_TSEL (1<<3)
57
#define NS2501_9_RSEN (1<<2)
58
#define NS2501_9_RSVD (1<<1)
59
#define NS2501_9_MDI (1<<0)
60
 
61
#define NS2501_REGC 0x0c
62
 
63
struct ns2501_priv {
64
	//I2CDevRec d;
65
	bool quiet;
66
	int reg_8_shadow;
67
	int reg_8_set;
68
	// Shadow registers for i915
69
	int dvoc;
70
	int pll_a;
71
	int srcdim;
72
	int fw_blc;
73
};
74
 
75
#define NSPTR(d) ((NS2501Ptr)(d->DriverPrivate.ptr))
76
 
77
/*
78
 * For reasons unclear to me, the ns2501 at least on the Fujitsu/Siemens
79
 * laptops does not react on the i2c bus unless
80
 * both the PLL is running and the display is configured in its native
81
 * resolution.
82
 * This function forces the DVO on, and stores the registers it touches.
83
 * Afterwards, registers are restored to regular values.
84
 *
85
 * This is pretty much a hack, though it works.
86
 * Without that, ns2501_readb and ns2501_writeb fail
87
 * when switching the resolution.
88
 */
89
 
90
static void enable_dvo(struct intel_dvo_device *dvo)
91
{
92
	struct ns2501_priv *ns = (struct ns2501_priv *)(dvo->dev_priv);
93
	struct i2c_adapter *adapter = dvo->i2c_bus;
94
	struct intel_gmbus *bus = container_of(adapter,
95
					       struct intel_gmbus,
96
					       adapter);
97
	struct drm_i915_private *dev_priv = bus->dev_priv;
98
 
99
	DRM_DEBUG_KMS("%s: Trying to re-enable the DVO\n", __FUNCTION__);
100
 
101
	ns->dvoc = I915_READ(DVO_C);
102
	ns->pll_a = I915_READ(_DPLL_A);
103
	ns->srcdim = I915_READ(DVOC_SRCDIM);
104
	ns->fw_blc = I915_READ(FW_BLC);
105
 
106
	I915_WRITE(DVOC, 0x10004084);
107
	I915_WRITE(_DPLL_A, 0xd0820000);
108
	I915_WRITE(DVOC_SRCDIM, 0x400300);	// 1024x768
109
	I915_WRITE(FW_BLC, 0x1080304);
110
 
111
	I915_WRITE(DVOC, 0x90004084);
112
}
113
 
114
/*
115
 * Restore the I915 registers modified by the above
116
 * trigger function.
117
 */
118
static void restore_dvo(struct intel_dvo_device *dvo)
119
{
120
	struct i2c_adapter *adapter = dvo->i2c_bus;
121
	struct intel_gmbus *bus = container_of(adapter,
122
					       struct intel_gmbus,
123
					       adapter);
124
	struct drm_i915_private *dev_priv = bus->dev_priv;
125
	struct ns2501_priv *ns = (struct ns2501_priv *)(dvo->dev_priv);
126
 
127
	I915_WRITE(DVOC, ns->dvoc);
128
	I915_WRITE(_DPLL_A, ns->pll_a);
129
	I915_WRITE(DVOC_SRCDIM, ns->srcdim);
130
	I915_WRITE(FW_BLC, ns->fw_blc);
131
}
132
 
133
/*
134
** Read a register from the ns2501.
135
** Returns true if successful, false otherwise.
136
** If it returns false, it might be wise to enable the
137
** DVO with the above function.
138
*/
139
static bool ns2501_readb(struct intel_dvo_device *dvo, int addr, uint8_t * ch)
140
{
141
	struct ns2501_priv *ns = dvo->dev_priv;
142
	struct i2c_adapter *adapter = dvo->i2c_bus;
143
	u8 out_buf[2];
144
	u8 in_buf[2];
145
 
146
	struct i2c_msg msgs[] = {
147
		{
148
		 .addr = dvo->slave_addr,
149
		 .flags = 0,
150
		 .len = 1,
151
		 .buf = out_buf,
152
		 },
153
		{
154
		 .addr = dvo->slave_addr,
155
		 .flags = I2C_M_RD,
156
		 .len = 1,
157
		 .buf = in_buf,
158
		 }
159
	};
160
 
161
	out_buf[0] = addr;
162
	out_buf[1] = 0;
163
 
164
	if (i2c_transfer(adapter, msgs, 2) == 2) {
165
		*ch = in_buf[0];
166
		return true;
167
	};
168
 
169
	if (!ns->quiet) {
170
		DRM_DEBUG_KMS
171
		    ("Unable to read register 0x%02x from %s:0x%02x.\n", addr,
172
		     adapter->name, dvo->slave_addr);
173
	}
174
 
175
	return false;
176
}
177
 
178
/*
179
** Write a register to the ns2501.
180
** Returns true if successful, false otherwise.
181
** If it returns false, it might be wise to enable the
182
** DVO with the above function.
183
*/
184
static bool ns2501_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
185
{
186
	struct ns2501_priv *ns = dvo->dev_priv;
187
	struct i2c_adapter *adapter = dvo->i2c_bus;
188
	uint8_t out_buf[2];
189
 
190
	struct i2c_msg msg = {
191
		.addr = dvo->slave_addr,
192
		.flags = 0,
193
		.len = 2,
194
		.buf = out_buf,
195
	};
196
 
197
	out_buf[0] = addr;
198
	out_buf[1] = ch;
199
 
200
	if (i2c_transfer(adapter, &msg, 1) == 1) {
201
		return true;
202
	}
203
 
204
	if (!ns->quiet) {
205
		DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d\n",
206
			      addr, adapter->name, dvo->slave_addr);
207
	}
208
 
209
	return false;
210
}
211
 
212
/* National Semiconductor 2501 driver for chip on i2c bus
213
 * scan for the chip on the bus.
214
 * Hope the VBIOS initialized the PLL correctly so we can
215
 * talk to it. If not, it will not be seen and not detected.
216
 * Bummer!
217
 */
218
static bool ns2501_init(struct intel_dvo_device *dvo,
219
			struct i2c_adapter *adapter)
220
{
221
	/* this will detect the NS2501 chip on the specified i2c bus */
222
	struct ns2501_priv *ns;
223
	unsigned char ch;
224
 
225
	ns = kzalloc(sizeof(struct ns2501_priv), GFP_KERNEL);
226
	if (ns == NULL)
227
		return false;
228
 
229
	dvo->i2c_bus = adapter;
230
	dvo->dev_priv = ns;
231
	ns->quiet = true;
232
 
233
	if (!ns2501_readb(dvo, NS2501_VID_LO, &ch))
234
		goto out;
235
 
236
	if (ch != (NS2501_VID & 0xff)) {
237
		DRM_DEBUG_KMS("ns2501 not detected got %d: from %s Slave %d.\n",
238
			      ch, adapter->name, dvo->slave_addr);
239
		goto out;
240
	}
241
 
242
	if (!ns2501_readb(dvo, NS2501_DID_LO, &ch))
243
		goto out;
244
 
245
	if (ch != (NS2501_DID & 0xff)) {
246
		DRM_DEBUG_KMS("ns2501 not detected got %d: from %s Slave %d.\n",
247
			      ch, adapter->name, dvo->slave_addr);
248
		goto out;
249
	}
250
	ns->quiet = false;
251
	ns->reg_8_set = 0;
252
	ns->reg_8_shadow =
253
	    NS2501_8_PD | NS2501_8_BPAS | NS2501_8_VEN | NS2501_8_HEN;
254
 
255
	DRM_DEBUG_KMS("init ns2501 dvo controller successfully!\n");
256
	return true;
257
 
258
out:
259
	kfree(ns);
260
	return false;
261
}
262
 
263
static enum drm_connector_status ns2501_detect(struct intel_dvo_device *dvo)
264
{
265
	/*
266
	 * This is a Laptop display, it doesn't have hotplugging.
267
	 * Even if not, the detection bit of the 2501 is unreliable as
268
	 * it only works for some display types.
269
	 * It is even more unreliable as the PLL must be active for
270
	 * allowing reading from the chiop.
271
	 */
272
	return connector_status_connected;
273
}
274
 
275
static enum drm_mode_status ns2501_mode_valid(struct intel