Rev 5060 | Rev 6320 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5060 | Rev 6084 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | #include |
32 | #include |
33 | #include "intel_drv.h" |
33 | #include "intel_drv.h" |
34 | #include |
34 | #include |
35 | #include "i915_drv.h" |
35 | #include "i915_drv.h" |
Line 36... | Line 36... | ||
36 | 36 | ||
37 | struct gmbus_port { |
37 | struct gmbus_pin { |
38 | const char *name; |
38 | const char *name; |
39 | int reg; |
39 | int reg; |
Line -... | Line 40... | ||
- | 40 | }; |
|
40 | }; |
41 | |
41 | 42 | /* Map gmbus pin pairs to names and registers. */ |
|
42 | static const struct gmbus_port gmbus_ports[] = { |
43 | static const struct gmbus_pin gmbus_pins[] = { |
43 | { "ssc", GPIOB }, |
44 | [GMBUS_PIN_SSC] = { "ssc", GPIOB }, |
44 | { "vga", GPIOA }, |
45 | [GMBUS_PIN_VGADDC] = { "vga", GPIOA }, |
45 | { "panel", GPIOC }, |
46 | [GMBUS_PIN_PANEL] = { "panel", GPIOC }, |
46 | { "dpc", GPIOD }, |
47 | [GMBUS_PIN_DPC] = { "dpc", GPIOD }, |
47 | { "dpb", GPIOE }, |
48 | [GMBUS_PIN_DPB] = { "dpb", GPIOE }, |
Line -... | Line 49... | ||
- | 49 | [GMBUS_PIN_DPD] = { "dpd", GPIOF }, |
|
- | 50 | }; |
|
- | 51 | ||
- | 52 | static const struct gmbus_pin gmbus_pins_bdw[] = { |
|
- | 53 | [GMBUS_PIN_VGADDC] = { "vga", GPIOA }, |
|
- | 54 | [GMBUS_PIN_DPC] = { "dpc", GPIOD }, |
|
- | 55 | [GMBUS_PIN_DPB] = { "dpb", GPIOE }, |
|
- | 56 | [GMBUS_PIN_DPD] = { "dpd", GPIOF }, |
|
- | 57 | }; |
|
- | 58 | ||
- | 59 | static const struct gmbus_pin gmbus_pins_skl[] = { |
|
- | 60 | [GMBUS_PIN_DPC] = { "dpc", GPIOD }, |
|
- | 61 | [GMBUS_PIN_DPB] = { "dpb", GPIOE }, |
|
- | 62 | [GMBUS_PIN_DPD] = { "dpd", GPIOF }, |
|
- | 63 | }; |
|
- | 64 | ||
- | 65 | static const struct gmbus_pin gmbus_pins_bxt[] = { |
|
- | 66 | [GMBUS_PIN_1_BXT] = { "dpb", PCH_GPIOB }, |
|
- | 67 | [GMBUS_PIN_2_BXT] = { "dpc", PCH_GPIOC }, |
|
- | 68 | [GMBUS_PIN_3_BXT] = { "misc", PCH_GPIOD }, |
|
- | 69 | }; |
|
- | 70 | ||
- | 71 | /* pin is expected to be valid */ |
|
- | 72 | static const struct gmbus_pin *get_gmbus_pin(struct drm_i915_private *dev_priv, |
|
- | 73 | unsigned int pin) |
|
- | 74 | { |
|
- | 75 | if (IS_BROXTON(dev_priv)) |
|
- | 76 | return &gmbus_pins_bxt[pin]; |
|
- | 77 | else if (IS_SKYLAKE(dev_priv)) |
|
- | 78 | return &gmbus_pins_skl[pin]; |
|
- | 79 | else if (IS_BROADWELL(dev_priv)) |
|
- | 80 | return &gmbus_pins_bdw[pin]; |
|
- | 81 | else |
|
- | 82 | return &gmbus_pins[pin]; |
|
- | 83 | } |
|
- | 84 | ||
- | 85 | bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv, |
|
- | 86 | unsigned int pin) |
|
- | 87 | { |
|
- | 88 | unsigned int size; |
|
- | 89 | ||
- | 90 | if (IS_BROXTON(dev_priv)) |
|
- | 91 | size = ARRAY_SIZE(gmbus_pins_bxt); |
|
- | 92 | else if (IS_SKYLAKE(dev_priv)) |
|
- | 93 | size = ARRAY_SIZE(gmbus_pins_skl); |
|
- | 94 | else if (IS_BROADWELL(dev_priv)) |
|
- | 95 | size = ARRAY_SIZE(gmbus_pins_bdw); |
|
- | 96 | else |
|
- | 97 | size = ARRAY_SIZE(gmbus_pins); |
|
- | 98 | ||
48 | { "dpd", GPIOF }, |
99 | return pin < size && get_gmbus_pin(dev_priv, pin)->reg; |
Line 49... | Line 100... | ||
49 | }; |
100 | } |
Line 50... | Line 101... | ||
50 | 101 | ||
Line 61... | Line 112... | ||
61 | void |
112 | void |
62 | intel_i2c_reset(struct drm_device *dev) |
113 | intel_i2c_reset(struct drm_device *dev) |
63 | { |
114 | { |
64 | struct drm_i915_private *dev_priv = dev->dev_private; |
115 | struct drm_i915_private *dev_priv = dev->dev_private; |
Line 65... | Line 116... | ||
65 | 116 | ||
66 | I915_WRITE(dev_priv->gpio_mmio_base + GMBUS0, 0); |
117 | I915_WRITE(GMBUS0, 0); |
67 | I915_WRITE(dev_priv->gpio_mmio_base + GMBUS4, 0); |
118 | I915_WRITE(GMBUS4, 0); |
Line 68... | Line 119... | ||
68 | } |
119 | } |
69 | 120 | ||
70 | static void intel_i2c_quirk_set(struct drm_i915_private *dev_priv, bool enable) |
121 | static void intel_i2c_quirk_set(struct drm_i915_private *dev_priv, bool enable) |
Line 180... | Line 231... | ||
180 | set_clock(bus, 1); |
231 | set_clock(bus, 1); |
181 | intel_i2c_quirk_set(dev_priv, false); |
232 | intel_i2c_quirk_set(dev_priv, false); |
182 | } |
233 | } |
Line 183... | Line 234... | ||
183 | 234 | ||
184 | static void |
235 | static void |
185 | intel_gpio_setup(struct intel_gmbus *bus, u32 pin) |
236 | intel_gpio_setup(struct intel_gmbus *bus, unsigned int pin) |
186 | { |
237 | { |
187 | struct drm_i915_private *dev_priv = bus->dev_priv; |
238 | struct drm_i915_private *dev_priv = bus->dev_priv; |
Line 188... | Line 239... | ||
188 | struct i2c_algo_bit_data *algo; |
239 | struct i2c_algo_bit_data *algo; |
Line 189... | Line 240... | ||
189 | 240 | ||
190 | algo = &bus->bit_algo; |
241 | algo = &bus->bit_algo; |
Line 191... | Line 242... | ||
191 | 242 | ||
192 | /* -1 to map pin pair to gmbus index */ |
243 | bus->gpio_reg = dev_priv->gpio_mmio_base + |
193 | bus->gpio_reg = dev_priv->gpio_mmio_base + gmbus_ports[pin - 1].reg; |
244 | get_gmbus_pin(dev_priv, pin)->reg; |
194 | 245 | ||
Line 208... | Line 259... | ||
208 | gmbus_wait_hw_status(struct drm_i915_private *dev_priv, |
259 | gmbus_wait_hw_status(struct drm_i915_private *dev_priv, |
209 | u32 gmbus2_status, |
260 | u32 gmbus2_status, |
210 | u32 gmbus4_irq_en) |
261 | u32 gmbus4_irq_en) |
211 | { |
262 | { |
212 | int i; |
263 | int i; |
213 | int reg_offset = dev_priv->gpio_mmio_base; |
- | |
214 | u32 gmbus2 = 0; |
264 | u32 gmbus2 = 0; |
215 | DEFINE_WAIT(wait); |
265 | DEFINE_WAIT(wait); |
Line 216... | Line 266... | ||
216 | 266 | ||
217 | if (!HAS_GMBUS_IRQ(dev_priv->dev)) |
267 | if (!HAS_GMBUS_IRQ(dev_priv->dev)) |
Line 218... | Line 268... | ||
218 | gmbus4_irq_en = 0; |
268 | gmbus4_irq_en = 0; |
219 | 269 | ||
220 | /* Important: The hw handles only the first bit, so set only one! Since |
270 | /* Important: The hw handles only the first bit, so set only one! Since |
221 | * we also need to check for NAKs besides the hw ready/idle signal, we |
271 | * we also need to check for NAKs besides the hw ready/idle signal, we |
Line 222... | Line 272... | ||
222 | * need to wake up periodically and check that ourselves. */ |
272 | * need to wake up periodically and check that ourselves. */ |
223 | I915_WRITE(GMBUS4 + reg_offset, gmbus4_irq_en); |
273 | I915_WRITE(GMBUS4, gmbus4_irq_en); |
224 | 274 | ||
Line 225... | Line 275... | ||
225 | for (i = 0; i < msecs_to_jiffies_timeout(50); i++) { |
275 | for (i = 0; i < msecs_to_jiffies_timeout(50); i++) { |
226 | prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait, |
276 | prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait, |
227 | TASK_UNINTERRUPTIBLE); |
277 | TASK_UNINTERRUPTIBLE); |
Line 228... | Line 278... | ||
228 | 278 | ||
229 | gmbus2 = I915_READ_NOTRACE(GMBUS2 + reg_offset); |
279 | gmbus2 = I915_READ_NOTRACE(GMBUS2); |
230 | if (gmbus2 & (GMBUS_SATOER | gmbus2_status)) |
280 | if (gmbus2 & (GMBUS_SATOER | gmbus2_status)) |
Line 231... | Line 281... | ||
231 | break; |
281 | break; |
Line 232... | Line 282... | ||
232 | 282 | ||
233 | schedule_timeout(1); |
283 | schedule_timeout(1); |
234 | } |
284 | } |
235 | finish_wait(&dev_priv->gmbus_wait_queue, &wait); |
285 | finish_wait(&dev_priv->gmbus_wait_queue, &wait); |
Line 245... | Line 295... | ||
245 | 295 | ||
246 | static int |
296 | static int |
247 | gmbus_wait_idle(struct drm_i915_private *dev_priv) |
297 | gmbus_wait_idle(struct drm_i915_private *dev_priv) |
248 | { |
298 | { |
249 | int ret; |
- | |
Line 250... | Line 299... | ||
250 | int reg_offset = dev_priv->gpio_mmio_base; |
299 | int ret; |
Line 251... | Line 300... | ||
251 | 300 | ||
252 | #define C ((I915_READ_NOTRACE(GMBUS2 + reg_offset) & GMBUS_ACTIVE) == 0) |
301 | #define C ((I915_READ_NOTRACE(GMBUS2) & GMBUS_ACTIVE) == 0) |
Line 253... | Line 302... | ||
253 | 302 | ||
254 | if (!HAS_GMBUS_IRQ(dev_priv->dev)) |
303 | if (!HAS_GMBUS_IRQ(dev_priv->dev)) |
Line 255... | Line 304... | ||
255 | return wait_for(C, 10); |
304 | return wait_for(C, 10); |
256 | 305 | ||
Line 257... | Line 306... | ||
257 | /* Important: The hw handles only the first bit, so set only one! */ |
306 | /* Important: The hw handles only the first bit, so set only one! */ |
Line 258... | Line 307... | ||
258 | I915_WRITE(GMBUS4 + reg_offset, GMBUS_IDLE_EN); |
307 | I915_WRITE(GMBUS4, GMBUS_IDLE_EN); |
259 | 308 | ||
260 | ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
309 | ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
261 | msecs_to_jiffies_timeout(10)); |
310 | msecs_to_jiffies_timeout(10)); |
262 | 311 | ||
263 | I915_WRITE(GMBUS4 + reg_offset, 0); |
312 | I915_WRITE(GMBUS4, 0); |
Line 264... | Line 313... | ||
264 | 313 | ||
265 | if (ret) |
314 | if (ret) |
- | 315 | return 0; |
|
266 | return 0; |
316 | else |
267 | else |
317 | return -ETIMEDOUT; |
268 | return -ETIMEDOUT; |
- | |
269 | #undef C |
- | |
270 | } |
- | |
271 | - | ||
272 | static int |
318 | #undef C |
273 | gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg, |
319 | } |
274 | u32 gmbus1_index) |
320 | |
275 | { |
321 | static int |
276 | int reg_offset = dev_priv->gpio_mmio_base; |
322 | gmbus_xfer_read_chunk(struct drm_i915_private *dev_priv, |
277 | u16 len = msg->len; |
323 | unsigned short addr, u8 *buf, unsigned int len, |
278 | u8 *buf = msg->buf; |
324 | u32 gmbus1_index) |
279 | 325 | { |
|
280 | I915_WRITE(GMBUS1 + reg_offset, |
326 | I915_WRITE(GMBUS1, |
Line 281... | Line 327... | ||
281 | gmbus1_index | |
327 | gmbus1_index | |
282 | GMBUS_CYCLE_WAIT | |
328 | GMBUS_CYCLE_WAIT | |
283 | (len << GMBUS_BYTE_COUNT_SHIFT) | |
329 | (len << GMBUS_BYTE_COUNT_SHIFT) | |
284 | (msg->addr << GMBUS_SLAVE_ADDR_SHIFT) | |
330 | (addr << GMBUS_SLAVE_ADDR_SHIFT) | |
Line 285... | Line 331... | ||
285 | GMBUS_SLAVE_READ | GMBUS_SW_RDY); |
331 | GMBUS_SLAVE_READ | GMBUS_SW_RDY); |
286 | while (len) { |
332 | while (len) { |
287 | int ret; |
333 | int ret; |
288 | u32 val, loop = 0; |
334 | u32 val, loop = 0; |
289 | 335 | ||
290 | ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY, |
336 | ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY, |
Line 291... | Line 337... | ||
291 | GMBUS_HW_RDY_EN); |
337 | GMBUS_HW_RDY_EN); |
292 | if (ret) |
338 | if (ret) |
Line 293... | Line 339... | ||
293 | return ret; |
339 | return ret; |
294 | 340 | ||
- | 341 | val = I915_READ(GMBUS3); |
|
295 | val = I915_READ(GMBUS3 + reg_offset); |
342 | do { |
296 | do { |
- | |
297 | *buf++ = val & 0xff; |
- | |
298 | val >>= 8; |
343 | *buf++ = val & 0xff; |
- | 344 | val >>= 8; |
|
- | 345 | } while (--len && ++loop < 4); |
|
- | 346 | } |
|
- | 347 | ||
- | 348 | return 0; |
|
- | 349 | } |
|
- | 350 | ||
- | 351 | static int |
|
- | 352 | gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg, |
|
- | 353 | u32 gmbus1_index) |
|
- | 354 | { |
|
- | 355 | u8 *buf = msg->buf; |
|
- | 356 | unsigned int rx_size = msg->len; |
|
- | 357 | unsigned int len; |
|
- | 358 | int ret; |
|
- | 359 | ||
- | 360 | do { |
|
- | 361 | len = min(rx_size, GMBUS_BYTE_COUNT_MAX); |
|
- | 362 | ||
- | 363 | ret = gmbus_xfer_read_chunk(dev_priv, msg->addr, |
|
- | 364 | buf, len, gmbus1_index); |
|
- | 365 | if (ret) |
|
- | 366 | return ret; |
|
- | 367 | ||
299 | } while (--len && ++loop < 4); |
368 | rx_size -= len; |
Line 300... | Line 369... | ||
300 | } |
369 | buf += len; |
301 | 370 | } while (rx_size != 0); |
|
302 | return 0; |
371 | |
303 | } |
372 | return 0; |
304 | 373 | } |
|
Line 305... | Line 374... | ||
305 | static int |
374 | |
306 | gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg) |
375 | static int |
307 | { |
376 | gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv, |
308 | int reg_offset = dev_priv->gpio_mmio_base; |
377 | unsigned short addr, u8 *buf, unsigned int len) |
309 | u16 len = msg->len; |
378 | { |
310 | u8 *buf = msg->buf; |
379 | unsigned int chunk_size = len; |
311 | u32 val, loop; |
380 | u32 val, loop; |
312 | 381 | ||
Line 313... | Line 382... | ||
313 | val = loop = 0; |
382 | val = loop = 0; |
314 | while (len && loop < 4) { |
383 | while (len && loop < 4) { |
315 | val |= *buf++ << (8 * loop++); |
384 | val |= *buf++ << (8 * loop++); |
316 | len -= 1; |
385 | len -= 1; |
Line 317... | Line 386... | ||
317 | } |
386 | } |
Line 318... | Line 387... | ||
318 | 387 | ||
319 | I915_WRITE(GMBUS3 + reg_offset, val); |
388 | I915_WRITE(GMBUS3, val); |
320 | I915_WRITE(GMBUS1 + reg_offset, |
389 | I915_WRITE(GMBUS1, |
321 | GMBUS_CYCLE_WAIT | |
390 | GMBUS_CYCLE_WAIT | |
322 | (msg->len << GMBUS_BYTE_COUNT_SHIFT) | |
391 | (chunk_size << GMBUS_BYTE_COUNT_SHIFT) | |
- | 392 | (addr << GMBUS_SLAVE_ADDR_SHIFT) | |
|
- | 393 | GMBUS_SLAVE_WRITE | GMBUS_SW_RDY); |
|
- | 394 | while (len) { |
|
- | 395 | int ret; |
|
- | 396 | ||
- | 397 | val = loop = 0; |
|
- | 398 | do { |
|
- | 399 | val |= *buf++ << (8 * loop); |
|
- | 400 | } while (--len && ++loop < 4); |
|
- | 401 | ||
- | 402 | I915_WRITE(GMBUS3, val); |
|
- | 403 | ||
- | 404 | ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY, |
|
- | 405 | GMBUS_HW_RDY_EN); |
|
- | 406 | if (ret) |
|
- | 407 | return ret; |
|
- | 408 | } |
|
- | 409 | ||
- | 410 | return 0; |
|
- | 411 | } |
|
- | 412 | ||
- | 413 | static int |
|
- | 414 | gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg) |
|
323 | (msg->addr << GMBUS_SLAVE_ADDR_SHIFT) | |
415 | { |
324 | GMBUS_SLAVE_WRITE | GMBUS_SW_RDY); |
416 | u8 *buf = msg->buf; |
Line 325... | Line 417... | ||
325 | while (len) { |
417 | unsigned int tx_size = msg->len; |
326 | int ret; |
418 | unsigned int len; |
Line 353... | Line 445... | ||
353 | } |
445 | } |
Line 354... | Line 446... | ||
354 | 446 | ||
355 | static int |
447 | static int |
356 | gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs) |
448 | gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs) |
357 | { |
- | |
358 | int reg_offset = dev_priv->gpio_mmio_base; |
449 | { |
359 | u32 gmbus1_index = 0; |
450 | u32 gmbus1_index = 0; |
360 | u32 gmbus5 = 0; |
451 | u32 gmbus5 = 0; |
Line 361... | Line 452... | ||
361 | int ret; |
452 | int ret; |
Line 367... | Line 458... | ||
367 | gmbus1_index = GMBUS_CYCLE_INDEX | |
458 | gmbus1_index = GMBUS_CYCLE_INDEX | |
368 | (msgs[0].buf[0] << GMBUS_SLAVE_INDEX_SHIFT); |
459 | (msgs[0].buf[0] << GMBUS_SLAVE_INDEX_SHIFT); |
Line 369... | Line 460... | ||
369 | 460 | ||
370 | /* GMBUS5 holds 16-bit index */ |
461 | /* GMBUS5 holds 16-bit index */ |
371 | if (gmbus5) |
462 | if (gmbus5) |
Line 372... | Line 463... | ||
372 | I915_WRITE(GMBUS5 + reg_offset, gmbus5); |
463 | I915_WRITE(GMBUS5, gmbus5); |
Line 373... | Line 464... | ||
373 | 464 | ||
374 | ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index); |
465 | ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index); |
375 | 466 | ||
Line 376... | Line 467... | ||
376 | /* Clear GMBUS5 after each index transfer */ |
467 | /* Clear GMBUS5 after each index transfer */ |
377 | if (gmbus5) |
468 | if (gmbus5) |
Line 378... | Line 469... | ||
378 | I915_WRITE(GMBUS5 + reg_offset, 0); |
469 | I915_WRITE(GMBUS5, 0); |
Line 387... | Line 478... | ||
387 | { |
478 | { |
388 | struct intel_gmbus *bus = container_of(adapter, |
479 | struct intel_gmbus *bus = container_of(adapter, |
389 | struct intel_gmbus, |
480 | struct intel_gmbus, |
390 | adapter); |
481 | adapter); |
391 | struct drm_i915_private *dev_priv = bus->dev_priv; |
482 | struct drm_i915_private *dev_priv = bus->dev_priv; |
392 | int i, reg_offset; |
483 | int i = 0, inc, try = 0; |
393 | int ret = 0; |
484 | int ret = 0; |
Line 394... | Line 485... | ||
394 | 485 | ||
395 | intel_aux_display_runtime_get(dev_priv); |
486 | intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS); |
Line 396... | Line 487... | ||
396 | mutex_lock(&dev_priv->gmbus_mutex); |
487 | mutex_lock(&dev_priv->gmbus_mutex); |
397 | 488 | ||
398 | if (bus->force_bit) { |
489 | if (bus->force_bit) { |
399 | ret = i2c_bit_algo.master_xfer(adapter, msgs, num); |
490 | ret = i2c_bit_algo.master_xfer(adapter, msgs, num); |
Line -... | Line 491... | ||
- | 491 | goto out; |
|
400 | goto out; |
492 | } |
Line 401... | Line -... | ||
401 | } |
- | |
402 | - | ||
403 | reg_offset = dev_priv->gpio_mmio_base; |
493 | |
- | 494 | retry: |
|
404 | 495 | I915_WRITE(GMBUS0, bus->reg0); |
|
405 | I915_WRITE(GMBUS0 + reg_offset, bus->reg0); |
496 | |
406 | 497 | for (; i < num; i += inc) { |
|
407 | for (i = 0; i < num; i++) { |
498 | inc = 1; |
408 | if (gmbus_is_index_read(msgs, i, num)) { |
499 | if (gmbus_is_index_read(msgs, i, num)) { |
409 | ret = gmbus_xfer_index_read(dev_priv, &msgs[i]); |
500 | ret = gmbus_xfer_index_read(dev_priv, &msgs[i]); |
410 | i += 1; /* set i to the index of the read xfer */ |
501 | inc = 2; /* an index read is two msgs */ |
411 | } else if (msgs[i].flags & I2C_M_RD) { |
502 | } else if (msgs[i].flags & I2C_M_RD) { |
Line 429... | Line 520... | ||
429 | 520 | ||
430 | /* Generate a STOP condition on the bus. Note that gmbus can't generata |
521 | /* Generate a STOP condition on the bus. Note that gmbus can't generata |
431 | * a STOP on the very first cycle. To simplify the code we |
522 | * a STOP on the very first cycle. To simplify the code we |
432 | * unconditionally generate the STOP condition with an additional gmbus |
523 | * unconditionally generate the STOP condition with an additional gmbus |
433 | * cycle. */ |
524 | * cycle. */ |
Line 434... | Line 525... | ||
434 | I915_WRITE(GMBUS1 + reg_offset, GMBUS_CYCLE_STOP | GMBUS_SW_RDY); |
525 | I915_WRITE(GMBUS1, GMBUS_CYCLE_STOP | GMBUS_SW_RDY); |
435 | 526 | ||
436 | /* Mark the GMBUS interface as disabled after waiting for idle. |
527 | /* Mark the GMBUS interface as disabled after waiting for idle. |
437 | * We will re-enable it at the start of the next xfer, |
528 | * We will re-enable it at the start of the next xfer, |
438 | * till then let it sleep. |
529 | * till then let it sleep. |
439 | */ |
530 | */ |
440 | if (gmbus_wait_idle(dev_priv)) { |
531 | if (gmbus_wait_idle(dev_priv)) { |
441 | DRM_DEBUG_KMS("GMBUS [%s] timed out waiting for idle\n", |
532 | DRM_DEBUG_KMS("GMBUS [%s] timed out waiting for idle\n", |
442 | adapter->name); |
533 | adapter->name); |
443 | ret = -ETIMEDOUT; |
534 | ret = -ETIMEDOUT; |
444 | } |
535 | } |
445 | I915_WRITE(GMBUS0 + reg_offset, 0); |
536 | I915_WRITE(GMBUS0, 0); |
Line 446... | Line 537... | ||
446 | ret = ret ?: i; |
537 | ret = ret ?: i; |
447 | goto out; |
538 | goto out; |
Line 469... | Line 560... | ||
469 | 560 | ||
470 | /* Toggle the Software Clear Interrupt bit. This has the effect |
561 | /* Toggle the Software Clear Interrupt bit. This has the effect |
471 | * of resetting the GMBUS controller and so clearing the |
562 | * of resetting the GMBUS controller and so clearing the |
472 | * BUS_ERROR raised by the slave's NAK. |
563 | * BUS_ERROR raised by the slave's NAK. |
473 | */ |
564 | */ |
474 | I915_WRITE(GMBUS1 + reg_offset, GMBUS_SW_CLR_INT); |
565 | I915_WRITE(GMBUS1, GMBUS_SW_CLR_INT); |
475 | I915_WRITE(GMBUS1 + reg_offset, 0); |
566 | I915_WRITE(GMBUS1, 0); |
Line 476... | Line 567... | ||
476 | I915_WRITE(GMBUS0 + reg_offset, 0); |
567 | I915_WRITE(GMBUS0, 0); |
477 | 568 | ||
478 | DRM_DEBUG_KMS("GMBUS [%s] NAK for addr: %04x %c(%d)\n", |
569 | DRM_DEBUG_KMS("GMBUS [%s] NAK for addr: %04x %c(%d)\n", |
Line -... | Line 570... | ||
- | 570 | adapter->name, msgs[i].addr, |
|
- | 571 | (msgs[i].flags & I2C_M_RD) ? 'r' : 'w', msgs[i].len); |
|
- | 572 | ||
- | 573 | /* |
|
- | 574 | * Passive adapters sometimes NAK the first probe. Retry the first |
|
- | 575 | * message once on -ENXIO for GMBUS transfers; the bit banging algorithm |
|
- | 576 | * has retries internally. See also the retry loop in |
|
- | 577 | * drm_do_probe_ddc_edid, which bails out on the first -ENXIO. |
|
- | 578 | */ |
|
- | 579 | if (ret == -ENXIO && i == 0 && try++ == 0) { |
|
- | 580 | DRM_DEBUG_KMS("GMBUS [%s] NAK on first message, retry\n", |
|
- | 581 | adapter->name); |
|
479 | adapter->name, msgs[i].addr, |
582 | goto retry; |
Line 480... | Line 583... | ||
480 | (msgs[i].flags & I2C_M_RD) ? 'r' : 'w', msgs[i].len); |
583 | } |
481 | 584 | ||
482 | goto out; |
585 | goto out; |
483 | 586 | ||
Line 484... | Line 587... | ||
484 | timeout: |
587 | timeout: |
485 | DRM_INFO("GMBUS [%s] timed out, falling back to bit banging on pin %d\n", |
588 | DRM_INFO("GMBUS [%s] timed out, falling back to bit banging on pin %d\n", |
486 | bus->adapter.name, bus->reg0 & 0xff); |
589 | bus->adapter.name, bus->reg0 & 0xff); |
Line 487... | Line 590... | ||
487 | I915_WRITE(GMBUS0 + reg_offset, 0); |
590 | I915_WRITE(GMBUS0, 0); |
488 | 591 | ||
- | 592 | /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */ |
|
489 | /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */ |
593 | bus->force_bit = 1; |
- | 594 | ret = i2c_bit_algo.master_xfer(adapter, msgs, num); |
|
490 | bus->force_bit = 1; |
595 | |
491 | ret = i2c_bit_algo.master_xfer(adapter, msgs, num); |
596 | out: |
Line 492... | Line 597... | ||
492 | 597 | mutex_unlock(&dev_priv->gmbus_mutex); |
|
493 | out: |
598 | |
Line 515... | Line 620... | ||
515 | * @dev: DRM device |
620 | * @dev: DRM device |
516 | */ |
621 | */ |
517 | int intel_setup_gmbus(struct drm_device *dev) |
622 | int intel_setup_gmbus(struct drm_device *dev) |
518 | { |
623 | { |
519 | struct drm_i915_private *dev_priv = dev->dev_private; |
624 | struct drm_i915_private *dev_priv = dev->dev_private; |
- | 625 | struct intel_gmbus *bus; |
|
- | 626 | unsigned int pin; |
|
520 | int ret, i; |
627 | int ret; |
Line 521... | Line 628... | ||
521 | 628 | ||
522 | if (HAS_PCH_NOP(dev)) |
629 | if (HAS_PCH_NOP(dev)) |
523 | return 0; |
630 | return 0; |
524 | else if (HAS_PCH_SPLIT(dev)) |
631 | else if (HAS_PCH_SPLIT(dev)) |
Line 529... | Line 636... | ||
529 | dev_priv->gpio_mmio_base = 0; |
636 | dev_priv->gpio_mmio_base = 0; |
Line 530... | Line 637... | ||
530 | 637 | ||
531 | mutex_init(&dev_priv->gmbus_mutex); |
638 | mutex_init(&dev_priv->gmbus_mutex); |
Line 532... | Line 639... | ||
532 | init_waitqueue_head(&dev_priv->gmbus_wait_queue); |
639 | init_waitqueue_head(&dev_priv->gmbus_wait_queue); |
533 | 640 | ||
- | 641 | for (pin = 0; pin < ARRAY_SIZE(dev_priv->gmbus); pin++) { |
|
- | 642 | if (!intel_gmbus_is_valid_pin(dev_priv, pin)) |
|
534 | for (i = 0; i < GMBUS_NUM_PORTS; i++) { |
643 | continue; |
Line 535... | Line 644... | ||
535 | struct intel_gmbus *bus = &dev_priv->gmbus[i]; |
644 | |
536 | u32 port = i + 1; /* +1 to map gmbus index to pin pair */ |
645 | bus = &dev_priv->gmbus[pin]; |
537 | 646 | ||
538 | bus->adapter.owner = THIS_MODULE; |
647 | bus->adapter.owner = THIS_MODULE; |
539 | bus->adapter.class = I2C_CLASS_DDC; |
648 | bus->adapter.class = I2C_CLASS_DDC; |
540 | snprintf(bus->adapter.name, |
649 | snprintf(bus->adapter.name, |
Line 541... | Line 650... | ||
541 | sizeof(bus->adapter.name), |
650 | sizeof(bus->adapter.name), |
542 | "i915 gmbus %s", |
651 | "i915 gmbus %s", |
Line 543... | Line 652... | ||
543 | gmbus_ports[i].name); |
652 | get_gmbus_pin(dev_priv, pin)->name); |
Line 544... | Line 653... | ||
544 | 653 | ||
545 | bus->adapter.dev.parent = &dev->pdev->dev; |
654 | bus->adapter.dev.parent = &dev->pdev->dev; |
Line 546... | Line 655... | ||
546 | bus->dev_priv = dev_priv; |
655 | bus->dev_priv = dev_priv; |
547 | 656 | ||
548 | bus->adapter.algo = &gmbus_algorithm; |
657 | bus->adapter.algo = &gmbus_algorithm; |
Line 549... | Line 658... | ||
549 | 658 | ||
Line 550... | Line 659... | ||
550 | /* By default use a conservative clock rate */ |
659 | /* By default use a conservative clock rate */ |
551 | bus->reg0 = port | GMBUS_RATE_100KHZ; |
660 | bus->reg0 = pin | GMBUS_RATE_100KHZ; |
552 | 661 | ||
553 | /* gmbus seems to be broken on i830 */ |
662 | /* gmbus seems to be broken on i830 */ |
Line 564... | Line 673... | ||
564 | intel_i2c_reset(dev_priv->dev); |
673 | intel_i2c_reset(dev_priv->dev); |
Line 565... | Line 674... | ||
565 | 674 | ||
Line 566... | Line 675... | ||
566 | return 0; |
675 | return 0; |
567 | 676 | ||
- | 677 | err: |
|
- | 678 | while (--pin) { |
|
- | 679 | if (!intel_gmbus_is_valid_pin(dev_priv, pin)) |
|
568 | err: |
680 | continue; |
569 | while (--i) { |
681 | |
570 | struct intel_gmbus *bus = &dev_priv->gmbus[i]; |
682 | bus = &dev_priv->gmbus[pin]; |
571 | i2c_del_adapter(&bus->adapter); |
683 | i2c_del_adapter(&bus->adapter); |
572 | } |
684 | } |
Line 573... | Line 685... | ||
573 | return ret; |
685 | return ret; |
574 | } |
686 | } |
575 | 687 | ||
576 | struct i2c_adapter *intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, |
688 | struct i2c_adapter *intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, |
577 | unsigned port) |
- | |
578 | { |
689 | unsigned int pin) |
- | 690 | { |
|
579 | WARN_ON(!intel_gmbus_is_port_valid(port)); |
691 | if (WARN_ON(!intel_gmbus_is_valid_pin(dev_priv, pin))) |
580 | /* -1 to map pin pair to gmbus index */ |
692 | return NULL; |
Line 581... | Line 693... | ||
581 | return (intel_gmbus_is_port_valid(port)) ? |
693 | |
582 | &dev_priv->gmbus[port - 1].adapter : NULL; |
694 | return &dev_priv->gmbus[pin].adapter; |
583 | } |
695 | } |
Line 600... | Line 712... | ||
600 | } |
712 | } |
Line 601... | Line 713... | ||
601 | 713 | ||
602 | void intel_teardown_gmbus(struct drm_device *dev) |
714 | void intel_teardown_gmbus(struct drm_device *dev) |
603 | { |
715 | { |
- | 716 | struct drm_i915_private *dev_priv = dev->dev_private; |
|
- | 717 | struct intel_gmbus *bus; |
|
- | 718 | unsigned int pin; |
|
- | 719 | ||
- | 720 | for (pin = 0; pin < ARRAY_SIZE(dev_priv->gmbus); pin++) { |
|
604 | struct drm_i915_private *dev_priv = dev->dev_private; |
721 | if (!intel_gmbus_is_valid_pin(dev_priv, pin)) |
Line 605... | Line -... | ||
605 | int i; |
- | |
606 | 722 | continue; |
|
607 | for (i = 0; i < GMBUS_NUM_PORTS; i++) { |
723 | |
608 | struct intel_gmbus *bus = &dev_priv->gmbus[i]; |
724 | bus = &dev_priv->gmbus[pin]; |
609 | i2c_del_adapter(&bus->adapter); |
725 | i2c_del_adapter(&bus->adapter); |