2 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2008,2010 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Eric Anholt <eric@anholt.net>
27 * Chris Wilson <chris@chris-wilson.co.uk>
29 * Copyright (c) 2011 The FreeBSD Foundation
30 * All rights reserved.
32 * This software was developed by Konstantin Belousov under sponsorship from
33 * the FreeBSD Foundation.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 #include <sys/mplock2.h>
59 #include <linux/i2c.h>
60 #include <linux/export.h>
62 #include "intel_drv.h"
63 #include <drm/i915_drm.h>
66 #include <bus/iicbus/iic.h>
67 #include <bus/iicbus/iiconf.h>
68 #include <bus/iicbus/iicbus.h>
69 #include "iicbus_if.h"
77 static const struct gmbus_port gmbus_ports[] = {
86 /* Intel GPIO access functions */
88 #define I2C_RISEFALL_TIME 10
91 intel_i2c_reset(struct drm_device *dev)
93 struct drm_i915_private *dev_priv = dev->dev_private;
94 I915_WRITE(dev_priv->gpio_mmio_base + GMBUS0, 0);
95 I915_WRITE(dev_priv->gpio_mmio_base + GMBUS4, 0);
98 static void intel_i2c_quirk_set(struct drm_i915_private *dev_priv, bool enable)
102 /* When using bit bashing for I2C, this bit needs to be set to 1 */
103 if (!IS_PINEVIEW(dev_priv->dev))
106 val = I915_READ(DSPCLK_GATE_D);
108 val |= DPCUNIT_CLOCK_GATE_DISABLE;
110 val &= ~DPCUNIT_CLOCK_GATE_DISABLE;
111 I915_WRITE(DSPCLK_GATE_D, val);
114 static u32 get_reserved(device_t idev)
116 struct intel_iic_softc *sc = device_get_softc(idev);
117 struct drm_device *dev = sc->drm_dev;
118 struct drm_i915_private *dev_priv;
121 dev_priv = dev->dev_private;
123 /* On most chips, these bits must be preserved in software. */
124 if (!IS_I830(dev) && !IS_845G(dev))
125 reserved = I915_READ_NOTRACE(sc->reg) &
126 (GPIO_DATA_PULLUP_DISABLE |
127 GPIO_CLOCK_PULLUP_DISABLE);
132 static int get_clock(device_t idev)
134 struct intel_iic_softc *sc;
135 struct drm_i915_private *dev_priv;
138 sc = device_get_softc(idev);
139 dev_priv = sc->drm_dev->dev_private;
141 reserved = get_reserved(idev);
143 I915_WRITE_NOTRACE(sc->reg, reserved | GPIO_CLOCK_DIR_MASK);
144 I915_WRITE_NOTRACE(sc->reg, reserved);
145 return ((I915_READ_NOTRACE(sc->reg) & GPIO_CLOCK_VAL_IN) != 0);
148 static int get_data(device_t idev)
150 struct intel_iic_softc *sc;
151 struct drm_i915_private *dev_priv;
154 sc = device_get_softc(idev);
155 dev_priv = sc->drm_dev->dev_private;
157 reserved = get_reserved(idev);
159 I915_WRITE_NOTRACE(sc->reg, reserved | GPIO_DATA_DIR_MASK);
160 I915_WRITE_NOTRACE(sc->reg, reserved);
161 return ((I915_READ_NOTRACE(sc->reg) & GPIO_DATA_VAL_IN) != 0);
165 intel_iicbus_reset(device_t idev, u_char speed, u_char addr, u_char *oldaddr)
167 struct intel_iic_softc *sc;
168 struct drm_device *dev;
170 sc = device_get_softc(idev);
173 intel_i2c_reset(dev);
177 static void set_clock(device_t idev, int val)
179 struct intel_iic_softc *sc;
180 struct drm_i915_private *dev_priv;
181 u32 clock_bits, reserved;
183 sc = device_get_softc(idev);
184 dev_priv = sc->drm_dev->dev_private;
186 reserved = get_reserved(idev);
188 clock_bits = GPIO_CLOCK_DIR_IN | GPIO_CLOCK_DIR_MASK;
190 clock_bits = GPIO_CLOCK_DIR_OUT | GPIO_CLOCK_DIR_MASK |
193 I915_WRITE_NOTRACE(sc->reg, reserved | clock_bits);
194 POSTING_READ(sc->reg);
197 static void set_data(device_t idev, int val)
199 struct intel_iic_softc *sc;
200 struct drm_i915_private *dev_priv;
204 sc = device_get_softc(idev);
205 dev_priv = sc->drm_dev->dev_private;
207 reserved = get_reserved(idev);
209 data_bits = GPIO_DATA_DIR_IN | GPIO_DATA_DIR_MASK;
211 data_bits = GPIO_DATA_DIR_OUT | GPIO_DATA_DIR_MASK |
214 I915_WRITE_NOTRACE(sc->reg, reserved | data_bits);
215 POSTING_READ(sc->reg);
218 static const char *gpio_names[GMBUS_NUM_PORTS] = {
228 intel_gpio_setup(device_t idev)
230 static const int map_pin_to_reg[] = {
241 struct intel_iic_softc *sc;
242 struct drm_i915_private *dev_priv;
245 sc = device_get_softc(idev);
246 sc->drm_dev = device_get_softc(device_get_parent(idev));
247 dev_priv = sc->drm_dev->dev_private;
248 pin = device_get_unit(idev);
250 ksnprintf(sc->name, sizeof(sc->name), "i915 iicbb %s", gpio_names[pin]);
251 device_set_desc(idev, sc->name);
253 sc->reg0 = (pin + 1) | GMBUS_RATE_100KHZ;
254 sc->reg = map_pin_to_reg[pin + 1];
255 if (HAS_PCH_SPLIT(dev_priv->dev))
256 sc->reg += PCH_GPIOA - GPIOA;
258 /* add generic bit-banging code */
259 sc->iic_dev = device_add_child(idev, "iicbb", -1);
260 if (sc->iic_dev == NULL)
262 device_quiet(sc->iic_dev);
263 bus_generic_attach(idev);
269 intel_i2c_quirk_xfer(device_t idev, struct iic_msg *msgs, int nmsgs)
272 struct intel_iic_softc *sc;
273 struct drm_i915_private *dev_priv;
277 bridge_dev = device_get_parent(device_get_parent(idev));
278 sc = device_get_softc(bridge_dev);
279 dev_priv = sc->drm_dev->dev_private;
281 intel_i2c_reset(sc->drm_dev);
282 intel_i2c_quirk_set(dev_priv, true);
283 IICBB_SETSDA(bridge_dev, 1);
284 IICBB_SETSCL(bridge_dev, 1);
285 DELAY(I2C_RISEFALL_TIME);
287 for (i = 0; i < nmsgs - 1; i++) {
288 /* force use of repeated start instead of default stop+start */
289 msgs[i].flags |= IIC_M_NOSTOP;
291 ret = iicbus_transfer(idev, msgs, nmsgs);
292 IICBB_SETSDA(bridge_dev, 1);
293 IICBB_SETSCL(bridge_dev, 1);
294 intel_i2c_quirk_set(dev_priv, false);
300 * gmbus on gen4 seems to be able to generate legacy interrupts even when in MSI
301 * mode. This results in spurious interrupt warnings if the legacy irq no. is
302 * shared with another device. The kernel then disables that interrupt source
303 * and so prevents the other device from working properly.
305 #define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
307 gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
312 int reg_offset = dev_priv->gpio_mmio_base;
316 if (!HAS_GMBUS_IRQ(dev_priv->dev))
319 /* Important: The hw handles only the first bit, so set only one! Since
320 * we also need to check for NAKs besides the hw ready/idle signal, we
321 * need to wake up periodically and check that ourselves. */
322 I915_WRITE(GMBUS4 + reg_offset, gmbus4_irq_en);
324 for (i = 0; i < msecs_to_jiffies_timeout(50); i++) {
325 prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait,
326 TASK_UNINTERRUPTIBLE);
328 gmbus2 = I915_READ_NOTRACE(GMBUS2 + reg_offset);
329 if (gmbus2 & (GMBUS_SATOER | gmbus2_status))
334 finish_wait(&dev_priv->gmbus_wait_queue, &wait);
336 I915_WRITE(GMBUS4 + reg_offset, 0);
338 if (gmbus2 & GMBUS_SATOER)
340 if (gmbus2 & gmbus2_status)
346 gmbus_wait_idle(struct drm_i915_private *dev_priv)
349 int reg_offset = dev_priv->gpio_mmio_base;
351 #define C ((I915_READ_NOTRACE(GMBUS2 + reg_offset) & GMBUS_ACTIVE) == 0)
353 if (!HAS_GMBUS_IRQ(dev_priv->dev))
354 return wait_for(C, 10);
356 /* Important: The hw handles only the first bit, so set only one! */
357 I915_WRITE(GMBUS4 + reg_offset, GMBUS_IDLE_EN);
359 ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
360 msecs_to_jiffies_timeout(10));
362 I915_WRITE(GMBUS4 + reg_offset, 0);
372 gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg,
375 int reg_offset = dev_priv->gpio_mmio_base;
379 I915_WRITE(GMBUS1 + reg_offset,
382 (len << GMBUS_BYTE_COUNT_SHIFT) |
383 (msg->slave << (GMBUS_SLAVE_ADDR_SHIFT - 1)) |
384 GMBUS_SLAVE_READ | GMBUS_SW_RDY);
389 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY,
394 val = I915_READ(GMBUS3 + reg_offset);
398 } while (--len && ++loop < 4);
405 gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg)
407 int reg_offset = dev_priv->gpio_mmio_base;
413 while (len && loop < 4) {
414 val |= *buf++ << (8 * loop++);
418 I915_WRITE(GMBUS3 + reg_offset, val);
419 I915_WRITE(GMBUS1 + reg_offset,
421 (msg->len << GMBUS_BYTE_COUNT_SHIFT) |
422 (msg->slave << (GMBUS_SLAVE_ADDR_SHIFT - 1)) |
423 GMBUS_SLAVE_WRITE | GMBUS_SW_RDY);
429 val |= *buf++ << (8 * loop);
430 } while (--len && ++loop < 4);
432 I915_WRITE(GMBUS3 + reg_offset, val);
434 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY,
443 * The gmbus controller can combine a 1 or 2 byte write with a read that
444 * immediately follows it by using an "INDEX" cycle.
447 gmbus_is_index_read(struct i2c_msg *msgs, int i, int num)
449 return (i + 1 < num &&
450 !(msgs[i].flags & I2C_M_RD) && msgs[i].len <= 2 &&
451 (msgs[i + 1].flags & I2C_M_RD));
455 gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs)
457 int reg_offset = dev_priv->gpio_mmio_base;
458 u32 gmbus1_index = 0;
462 if (msgs[0].len == 2)
463 gmbus5 = GMBUS_2BYTE_INDEX_EN |
464 msgs[0].buf[1] | (msgs[0].buf[0] << 8);
465 if (msgs[0].len == 1)
466 gmbus1_index = GMBUS_CYCLE_INDEX |
467 (msgs[0].buf[0] << GMBUS_SLAVE_INDEX_SHIFT);
469 /* GMBUS5 holds 16-bit index */
471 I915_WRITE(GMBUS5 + reg_offset, gmbus5);
473 ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index);
475 /* Clear GMBUS5 after each index transfer */
477 I915_WRITE(GMBUS5 + reg_offset, 0);
483 gmbus_xfer(struct device *adapter,
484 struct i2c_msg *msgs,
487 struct intel_iic_softc *sc;
488 struct drm_i915_private *dev_priv;
489 int i, reg_offset, unit;
492 sc = device_get_softc(adapter);
493 dev_priv = sc->drm_dev->dev_private;
494 unit = device_get_unit(adapter);
496 mutex_lock(&dev_priv->gmbus_mutex);
498 if (sc->force_bit_dev) {
499 ret = intel_i2c_quirk_xfer(dev_priv->bbbus[unit], msgs, num);
503 reg_offset = HAS_PCH_SPLIT(dev_priv->dev) ? PCH_GMBUS0 - GMBUS0 : 0;
505 I915_WRITE(GMBUS0 + reg_offset, sc->reg0);
507 for (i = 0; i < num; i++) {
508 if (gmbus_is_index_read(msgs, i, num)) {
509 ret = gmbus_xfer_index_read(dev_priv, &msgs[i]);
510 i += 1; /* set i to the index of the read xfer */
511 } else if (msgs[i].flags & I2C_M_RD) {
512 ret = gmbus_xfer_read(dev_priv, &msgs[i], 0);
514 ret = gmbus_xfer_write(dev_priv, &msgs[i]);
517 if (ret == -ETIMEDOUT)
522 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_WAIT_PHASE,
530 /* Generate a STOP condition on the bus. Note that gmbus can't generata
531 * a STOP on the very first cycle. To simplify the code we
532 * unconditionally generate the STOP condition with an additional gmbus
534 I915_WRITE(GMBUS1 + reg_offset, GMBUS_CYCLE_STOP | GMBUS_SW_RDY);
536 /* Mark the GMBUS interface as disabled after waiting for idle.
537 * We will re-enable it at the start of the next xfer,
538 * till then let it sleep.
540 if (gmbus_wait_idle(dev_priv)) {
541 DRM_DEBUG_KMS("GMBUS [%s] timed out waiting for idle\n",
545 I915_WRITE(GMBUS0 + reg_offset, 0);
547 goto timeout; /* XXX: should be out */
551 * Wait for bus to IDLE before clearing NAK.
552 * If we clear the NAK while bus is still active, then it will stay
553 * active and the next transaction may fail.
555 * If no ACK is received during the address phase of a transaction, the
556 * adapter must report -ENXIO. It is not clear what to return if no ACK
557 * is received at other times. But we have to be careful to not return
558 * spurious -ENXIO because that will prevent i2c and drm edid functions
559 * from retrying. So return -ENXIO only when gmbus properly quiescents -
560 * timing out seems to happen when there _is_ a ddc chip present, but
561 * it's slow responding and only answers on the 2nd retry.
564 if (gmbus_wait_idle(dev_priv)) {
565 DRM_DEBUG_KMS("GMBUS [%s] timed out after NAK\n",
570 /* Toggle the Software Clear Interrupt bit. This has the effect
571 * of resetting the GMBUS controller and so clearing the
572 * BUS_ERROR raised by the slave's NAK.
574 I915_WRITE(GMBUS1 + reg_offset, GMBUS_SW_CLR_INT);
575 I915_WRITE(GMBUS1 + reg_offset, 0);
576 I915_WRITE(GMBUS0 + reg_offset, 0);
578 DRM_DEBUG_KMS("GMBUS [%s] NAK for addr: %04x %c(%d)\n",
579 sc->name, msgs[i].slave,
580 (msgs[i].flags & I2C_M_RD) ? 'r' : 'w', msgs[i].len);
585 DRM_INFO("GMBUS [%s] timed out, falling back to bit banging on pin %d\n",
586 sc->name, sc->reg0 & 0xff);
587 I915_WRITE(GMBUS0 + reg_offset, 0);
589 /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */
590 sc->force_bit_dev = true;
591 ret = intel_i2c_quirk_xfer(dev_priv->bbbus[unit], msgs, num);
594 mutex_unlock(&dev_priv->gmbus_mutex);
598 struct device *intel_gmbus_get_adapter(struct drm_i915_private *dev_priv,
601 WARN_ON(!intel_gmbus_is_port_valid(port));
602 /* -1 to map pin pair to gmbus index */
603 return (intel_gmbus_is_port_valid(port)) ?
604 dev_priv->gmbus[port-1] : NULL;
608 intel_gmbus_set_speed(device_t idev, int speed)
610 struct intel_iic_softc *sc;
612 sc = device_get_softc(device_get_parent(idev));
614 sc->reg0 = (sc->reg0 & ~(0x3 << 8)) | speed;
618 intel_gmbus_force_bit(device_t idev, bool force_bit)
620 struct intel_iic_softc *sc;
622 sc = device_get_softc(device_get_parent(idev));
623 sc->force_bit_dev += force_bit ? 1 : -1;
624 DRM_DEBUG_KMS("%sabling bit-banging on %s. force bit now %d\n",
625 force_bit ? "en" : "dis", sc->name,
630 intel_gmbus_probe(device_t dev)
633 return (BUS_PROBE_SPECIFIC);
637 intel_gmbus_attach(device_t idev)
639 struct drm_i915_private *dev_priv;
640 struct intel_iic_softc *sc;
643 sc = device_get_softc(idev);
644 sc->drm_dev = device_get_softc(device_get_parent(idev));
645 dev_priv = sc->drm_dev->dev_private;
646 pin = device_get_unit(idev);
648 ksnprintf(sc->name, sizeof(sc->name), "gmbus bus %s", gpio_names[pin]);
649 device_set_desc(idev, sc->name);
651 /* By default use a conservative clock rate */
652 sc->reg0 = (pin + 1) | GMBUS_RATE_100KHZ;
654 /* XXX force bit banging until GMBUS is fully debugged */
655 if (IS_GEN2(sc->drm_dev)) {
656 sc->force_bit_dev = true;
659 /* add bus interface device */
660 sc->iic_dev = device_add_child(idev, "iicbus", -1);
661 if (sc->iic_dev == NULL)
663 device_quiet(sc->iic_dev);
664 bus_generic_attach(idev);
670 intel_gmbus_detach(device_t idev)
672 struct intel_iic_softc *sc;
673 struct drm_i915_private *dev_priv;
677 sc = device_get_softc(idev);
678 u = device_get_unit(idev);
679 dev_priv = sc->drm_dev->dev_private;
682 bus_generic_detach(idev);
684 device_delete_child(idev, child);
690 intel_iicbb_probe(device_t dev)
693 return (BUS_PROBE_DEFAULT);
697 intel_iicbb_detach(device_t idev)
699 struct intel_iic_softc *sc;
702 sc = device_get_softc(idev);
704 bus_generic_detach(idev);
706 device_delete_child(idev, child);
710 static device_method_t intel_gmbus_methods[] = {
711 DEVMETHOD(device_probe, intel_gmbus_probe),
712 DEVMETHOD(device_attach, intel_gmbus_attach),
713 DEVMETHOD(device_detach, intel_gmbus_detach),
714 DEVMETHOD(iicbus_reset, intel_iicbus_reset),
715 DEVMETHOD(iicbus_transfer, gmbus_xfer),
718 static driver_t intel_gmbus_driver = {
721 sizeof(struct intel_iic_softc)
723 static devclass_t intel_gmbus_devclass;
724 DRIVER_MODULE_ORDERED(intel_gmbus, drm, intel_gmbus_driver,
725 intel_gmbus_devclass, 0, 0, SI_ORDER_FIRST);
726 DRIVER_MODULE(iicbus, intel_gmbus, iicbus_driver, iicbus_devclass, NULL, NULL);
728 static device_method_t intel_iicbb_methods[] = {
729 DEVMETHOD(device_probe, intel_iicbb_probe),
730 DEVMETHOD(device_attach, intel_gpio_setup),
731 DEVMETHOD(device_detach, intel_iicbb_detach),
733 DEVMETHOD(bus_add_child, bus_generic_add_child),
734 DEVMETHOD(bus_print_child, bus_generic_print_child),
736 DEVMETHOD(iicbb_callback, iicbus_null_callback),
737 DEVMETHOD(iicbb_reset, intel_iicbus_reset),
738 DEVMETHOD(iicbb_setsda, set_data),
739 DEVMETHOD(iicbb_setscl, set_clock),
740 DEVMETHOD(iicbb_getsda, get_data),
741 DEVMETHOD(iicbb_getscl, get_clock),
744 static driver_t intel_iicbb_driver = {
747 sizeof(struct intel_iic_softc)
749 static devclass_t intel_iicbb_devclass;
750 DRIVER_MODULE_ORDERED(intel_iicbb, drm, intel_iicbb_driver,
751 intel_iicbb_devclass, 0, 0, SI_ORDER_FIRST);
752 DRIVER_MODULE(iicbb, intel_iicbb, iicbb_driver, iicbb_devclass, NULL, NULL);
754 static void intel_teardown_gmbus_m(struct drm_device *dev, int m);
757 intel_setup_gmbus(struct drm_device *dev)
759 struct drm_i915_private *dev_priv = dev->dev_private;
763 if (HAS_PCH_NOP(dev))
765 else if (HAS_PCH_SPLIT(dev))
766 dev_priv->gpio_mmio_base = PCH_GPIOA - GPIOA;
767 else if (IS_VALLEYVIEW(dev))
768 dev_priv->gpio_mmio_base = VLV_DISPLAY_BASE;
770 dev_priv->gpio_mmio_base = 0;
772 lockinit(&dev_priv->gmbus_mutex, "gmbus", 0, LK_CANRECURSE);
773 init_waitqueue_head(&dev_priv->gmbus_wait_queue);
775 dev_priv->gmbus_bridge = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
776 M_DRM, M_WAITOK | M_ZERO);
777 dev_priv->bbbus_bridge = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
778 M_DRM, M_WAITOK | M_ZERO);
779 dev_priv->gmbus = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
780 M_DRM, M_WAITOK | M_ZERO);
781 dev_priv->bbbus = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
782 M_DRM, M_WAITOK | M_ZERO);
784 for (i = 0; i < GMBUS_NUM_PORTS; i++) {
786 * Initialized bbbus_bridge before gmbus_bridge, since
787 * gmbus may decide to force quirk transfer in the
790 dev_priv->bbbus_bridge[i] = device_add_child(dev->dev,
792 if (dev_priv->bbbus_bridge[i] == NULL) {
793 DRM_ERROR("bbbus bridge %d creation failed\n", i);
797 device_quiet(dev_priv->bbbus_bridge[i]);
798 ret = device_probe_and_attach(dev_priv->bbbus_bridge[i]);
800 DRM_ERROR("bbbus bridge %d attach failed, %d\n", i,
805 iic_dev = device_find_child(dev_priv->bbbus_bridge[i], "iicbb",
807 if (iic_dev == NULL) {
808 DRM_ERROR("bbbus bridge doesn't have iicbb child\n");
811 iic_dev = device_find_child(iic_dev, "iicbus", -1);
812 if (iic_dev == NULL) {
814 "bbbus bridge doesn't have iicbus grandchild\n");
818 dev_priv->bbbus[i] = iic_dev;
820 dev_priv->gmbus_bridge[i] = device_add_child(dev->dev,
822 if (dev_priv->gmbus_bridge[i] == NULL) {
823 DRM_ERROR("gmbus bridge %d creation failed\n", i);
827 device_quiet(dev_priv->gmbus_bridge[i]);
828 ret = device_probe_and_attach(dev_priv->gmbus_bridge[i]);
830 DRM_ERROR("gmbus bridge %d attach failed, %d\n", i,
836 iic_dev = device_find_child(dev_priv->gmbus_bridge[i],
838 if (iic_dev == NULL) {
839 DRM_ERROR("gmbus bridge doesn't have iicbus child\n");
842 dev_priv->gmbus[i] = iic_dev;
844 intel_i2c_reset(dev);
850 intel_teardown_gmbus_m(dev, i);
855 intel_teardown_gmbus_m(struct drm_device *dev, int m)
857 struct drm_i915_private *dev_priv;
859 dev_priv = dev->dev_private;
861 drm_free(dev_priv->gmbus, M_DRM);
862 dev_priv->gmbus = NULL;
863 drm_free(dev_priv->bbbus, M_DRM);
864 dev_priv->bbbus = NULL;
865 drm_free(dev_priv->gmbus_bridge, M_DRM);
866 dev_priv->gmbus_bridge = NULL;
867 drm_free(dev_priv->bbbus_bridge, M_DRM);
868 dev_priv->bbbus_bridge = NULL;
869 lockuninit(&dev_priv->gmbus_mutex);
873 intel_teardown_gmbus(struct drm_device *dev)
877 intel_teardown_gmbus_m(dev, GMBUS_NUM_PORTS);