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(50) + 1; 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, 10);
361 I915_WRITE(GMBUS4 + reg_offset, 0);
371 gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg,
374 int reg_offset = dev_priv->gpio_mmio_base;
378 I915_WRITE(GMBUS1 + reg_offset,
381 (len << GMBUS_BYTE_COUNT_SHIFT) |
382 (msg->slave << (GMBUS_SLAVE_ADDR_SHIFT - 1)) |
383 GMBUS_SLAVE_READ | GMBUS_SW_RDY);
388 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY,
393 val = I915_READ(GMBUS3 + reg_offset);
397 } while (--len && ++loop < 4);
404 gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg)
406 int reg_offset = dev_priv->gpio_mmio_base;
412 while (len && loop < 4) {
413 val |= *buf++ << (8 * loop++);
417 I915_WRITE(GMBUS3 + reg_offset, val);
418 I915_WRITE(GMBUS1 + reg_offset,
420 (msg->len << GMBUS_BYTE_COUNT_SHIFT) |
421 (msg->slave << (GMBUS_SLAVE_ADDR_SHIFT - 1)) |
422 GMBUS_SLAVE_WRITE | GMBUS_SW_RDY);
428 val |= *buf++ << (8 * loop);
429 } while (--len && ++loop < 4);
431 I915_WRITE(GMBUS3 + reg_offset, val);
433 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY,
442 * The gmbus controller can combine a 1 or 2 byte write with a read that
443 * immediately follows it by using an "INDEX" cycle.
446 gmbus_is_index_read(struct i2c_msg *msgs, int i, int num)
448 return (i + 1 < num &&
449 !(msgs[i].flags & I2C_M_RD) && msgs[i].len <= 2 &&
450 (msgs[i + 1].flags & I2C_M_RD));
454 gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs)
456 int reg_offset = dev_priv->gpio_mmio_base;
457 u32 gmbus1_index = 0;
461 if (msgs[0].len == 2)
462 gmbus5 = GMBUS_2BYTE_INDEX_EN |
463 msgs[0].buf[1] | (msgs[0].buf[0] << 8);
464 if (msgs[0].len == 1)
465 gmbus1_index = GMBUS_CYCLE_INDEX |
466 (msgs[0].buf[0] << GMBUS_SLAVE_INDEX_SHIFT);
468 /* GMBUS5 holds 16-bit index */
470 I915_WRITE(GMBUS5 + reg_offset, gmbus5);
472 ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index);
474 /* Clear GMBUS5 after each index transfer */
476 I915_WRITE(GMBUS5 + reg_offset, 0);
482 gmbus_xfer(struct device *adapter,
483 struct i2c_msg *msgs,
486 struct intel_iic_softc *sc;
487 struct drm_i915_private *dev_priv;
488 int i, reg_offset, unit;
491 sc = device_get_softc(adapter);
492 dev_priv = sc->drm_dev->dev_private;
493 unit = device_get_unit(adapter);
495 mutex_lock(&dev_priv->gmbus_mutex);
497 if (sc->force_bit_dev) {
498 ret = intel_i2c_quirk_xfer(dev_priv->bbbus[unit], msgs, num);
502 reg_offset = HAS_PCH_SPLIT(dev_priv->dev) ? PCH_GMBUS0 - GMBUS0 : 0;
504 I915_WRITE(GMBUS0 + reg_offset, sc->reg0);
506 for (i = 0; i < num; i++) {
507 if (gmbus_is_index_read(msgs, i, num)) {
508 ret = gmbus_xfer_index_read(dev_priv, &msgs[i]);
509 i += 1; /* set i to the index of the read xfer */
510 } else if (msgs[i].flags & I2C_M_RD) {
511 ret = gmbus_xfer_read(dev_priv, &msgs[i], 0);
513 ret = gmbus_xfer_write(dev_priv, &msgs[i]);
516 if (ret == -ETIMEDOUT)
521 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_WAIT_PHASE,
529 /* Generate a STOP condition on the bus. Note that gmbus can't generata
530 * a STOP on the very first cycle. To simplify the code we
531 * unconditionally generate the STOP condition with an additional gmbus
533 I915_WRITE(GMBUS1 + reg_offset, GMBUS_CYCLE_STOP | GMBUS_SW_RDY);
535 /* Mark the GMBUS interface as disabled after waiting for idle.
536 * We will re-enable it at the start of the next xfer,
537 * till then let it sleep.
539 if (gmbus_wait_idle(dev_priv)) {
540 DRM_DEBUG_KMS("GMBUS [%s] timed out waiting for idle\n",
544 I915_WRITE(GMBUS0 + reg_offset, 0);
546 goto timeout; /* XXX: should be out */
550 * Wait for bus to IDLE before clearing NAK.
551 * If we clear the NAK while bus is still active, then it will stay
552 * active and the next transaction may fail.
554 * If no ACK is received during the address phase of a transaction, the
555 * adapter must report -ENXIO. It is not clear what to return if no ACK
556 * is received at other times. But we have to be careful to not return
557 * spurious -ENXIO because that will prevent i2c and drm edid functions
558 * from retrying. So return -ENXIO only when gmbus properly quiescents -
559 * timing out seems to happen when there _is_ a ddc chip present, but
560 * it's slow responding and only answers on the 2nd retry.
563 if (gmbus_wait_idle(dev_priv)) {
564 DRM_DEBUG_KMS("GMBUS [%s] timed out after NAK\n",
569 /* Toggle the Software Clear Interrupt bit. This has the effect
570 * of resetting the GMBUS controller and so clearing the
571 * BUS_ERROR raised by the slave's NAK.
573 I915_WRITE(GMBUS1 + reg_offset, GMBUS_SW_CLR_INT);
574 I915_WRITE(GMBUS1 + reg_offset, 0);
575 I915_WRITE(GMBUS0 + reg_offset, 0);
577 DRM_DEBUG_KMS("GMBUS [%s] NAK for addr: %04x %c(%d)\n",
578 sc->name, msgs[i].slave,
579 (msgs[i].flags & I2C_M_RD) ? 'r' : 'w', msgs[i].len);
584 DRM_INFO("GMBUS [%s] timed out, falling back to bit banging on pin %d\n",
585 sc->name, sc->reg0 & 0xff);
586 I915_WRITE(GMBUS0 + reg_offset, 0);
588 /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */
589 sc->force_bit_dev = true;
590 ret = intel_i2c_quirk_xfer(dev_priv->bbbus[unit], msgs, num);
593 mutex_unlock(&dev_priv->gmbus_mutex);
597 struct device *intel_gmbus_get_adapter(struct drm_i915_private *dev_priv,
600 WARN_ON(!intel_gmbus_is_port_valid(port));
601 /* -1 to map pin pair to gmbus index */
602 return (intel_gmbus_is_port_valid(port)) ?
603 dev_priv->gmbus[port-1] : NULL;
607 intel_gmbus_set_speed(device_t idev, int speed)
609 struct intel_iic_softc *sc;
611 sc = device_get_softc(device_get_parent(idev));
613 sc->reg0 = (sc->reg0 & ~(0x3 << 8)) | speed;
617 intel_gmbus_force_bit(device_t idev, bool force_bit)
619 struct intel_iic_softc *sc;
621 sc = device_get_softc(device_get_parent(idev));
622 sc->force_bit_dev += force_bit ? 1 : -1;
623 DRM_DEBUG_KMS("%sabling bit-banging on %s. force bit now %d\n",
624 force_bit ? "en" : "dis", sc->name,
629 intel_gmbus_probe(device_t dev)
632 return (BUS_PROBE_SPECIFIC);
636 intel_gmbus_attach(device_t idev)
638 struct drm_i915_private *dev_priv;
639 struct intel_iic_softc *sc;
642 sc = device_get_softc(idev);
643 sc->drm_dev = device_get_softc(device_get_parent(idev));
644 dev_priv = sc->drm_dev->dev_private;
645 pin = device_get_unit(idev);
647 ksnprintf(sc->name, sizeof(sc->name), "gmbus bus %s", gpio_names[pin]);
648 device_set_desc(idev, sc->name);
650 /* By default use a conservative clock rate */
651 sc->reg0 = (pin + 1) | GMBUS_RATE_100KHZ;
653 /* XXX force bit banging until GMBUS is fully debugged */
654 if (IS_GEN2(sc->drm_dev)) {
655 sc->force_bit_dev = true;
658 /* add bus interface device */
659 sc->iic_dev = device_add_child(idev, "iicbus", -1);
660 if (sc->iic_dev == NULL)
662 device_quiet(sc->iic_dev);
663 bus_generic_attach(idev);
669 intel_gmbus_detach(device_t idev)
671 struct intel_iic_softc *sc;
672 struct drm_i915_private *dev_priv;
676 sc = device_get_softc(idev);
677 u = device_get_unit(idev);
678 dev_priv = sc->drm_dev->dev_private;
681 bus_generic_detach(idev);
683 device_delete_child(idev, child);
689 intel_iicbb_probe(device_t dev)
692 return (BUS_PROBE_DEFAULT);
696 intel_iicbb_detach(device_t idev)
698 struct intel_iic_softc *sc;
701 sc = device_get_softc(idev);
703 bus_generic_detach(idev);
705 device_delete_child(idev, child);
709 static device_method_t intel_gmbus_methods[] = {
710 DEVMETHOD(device_probe, intel_gmbus_probe),
711 DEVMETHOD(device_attach, intel_gmbus_attach),
712 DEVMETHOD(device_detach, intel_gmbus_detach),
713 DEVMETHOD(iicbus_reset, intel_iicbus_reset),
714 DEVMETHOD(iicbus_transfer, gmbus_xfer),
717 static driver_t intel_gmbus_driver = {
720 sizeof(struct intel_iic_softc)
722 static devclass_t intel_gmbus_devclass;
723 DRIVER_MODULE_ORDERED(intel_gmbus, drm, intel_gmbus_driver,
724 intel_gmbus_devclass, 0, 0, SI_ORDER_FIRST);
725 DRIVER_MODULE(iicbus, intel_gmbus, iicbus_driver, iicbus_devclass, NULL, NULL);
727 static device_method_t intel_iicbb_methods[] = {
728 DEVMETHOD(device_probe, intel_iicbb_probe),
729 DEVMETHOD(device_attach, intel_gpio_setup),
730 DEVMETHOD(device_detach, intel_iicbb_detach),
732 DEVMETHOD(bus_add_child, bus_generic_add_child),
733 DEVMETHOD(bus_print_child, bus_generic_print_child),
735 DEVMETHOD(iicbb_callback, iicbus_null_callback),
736 DEVMETHOD(iicbb_reset, intel_iicbus_reset),
737 DEVMETHOD(iicbb_setsda, set_data),
738 DEVMETHOD(iicbb_setscl, set_clock),
739 DEVMETHOD(iicbb_getsda, get_data),
740 DEVMETHOD(iicbb_getscl, get_clock),
743 static driver_t intel_iicbb_driver = {
746 sizeof(struct intel_iic_softc)
748 static devclass_t intel_iicbb_devclass;
749 DRIVER_MODULE_ORDERED(intel_iicbb, drm, intel_iicbb_driver,
750 intel_iicbb_devclass, 0, 0, SI_ORDER_FIRST);
751 DRIVER_MODULE(iicbb, intel_iicbb, iicbb_driver, iicbb_devclass, NULL, NULL);
753 static void intel_teardown_gmbus_m(struct drm_device *dev, int m);
756 intel_setup_gmbus(struct drm_device *dev)
758 struct drm_i915_private *dev_priv = dev->dev_private;
762 if (HAS_PCH_SPLIT(dev))
763 dev_priv->gpio_mmio_base = PCH_GPIOA - GPIOA;
764 else if (IS_VALLEYVIEW(dev))
765 dev_priv->gpio_mmio_base = VLV_DISPLAY_BASE;
767 dev_priv->gpio_mmio_base = 0;
769 lockinit(&dev_priv->gmbus_mutex, "gmbus", 0, LK_CANRECURSE);
770 init_waitqueue_head(&dev_priv->gmbus_wait_queue);
772 dev_priv->gmbus_bridge = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
773 M_DRM, M_WAITOK | M_ZERO);
774 dev_priv->bbbus_bridge = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
775 M_DRM, M_WAITOK | M_ZERO);
776 dev_priv->gmbus = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
777 M_DRM, M_WAITOK | M_ZERO);
778 dev_priv->bbbus = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
779 M_DRM, M_WAITOK | M_ZERO);
781 for (i = 0; i < GMBUS_NUM_PORTS; i++) {
783 * Initialized bbbus_bridge before gmbus_bridge, since
784 * gmbus may decide to force quirk transfer in the
787 dev_priv->bbbus_bridge[i] = device_add_child(dev->dev,
789 if (dev_priv->bbbus_bridge[i] == NULL) {
790 DRM_ERROR("bbbus bridge %d creation failed\n", i);
794 device_quiet(dev_priv->bbbus_bridge[i]);
795 ret = device_probe_and_attach(dev_priv->bbbus_bridge[i]);
797 DRM_ERROR("bbbus bridge %d attach failed, %d\n", i,
802 iic_dev = device_find_child(dev_priv->bbbus_bridge[i], "iicbb",
804 if (iic_dev == NULL) {
805 DRM_ERROR("bbbus bridge doesn't have iicbb child\n");
808 iic_dev = device_find_child(iic_dev, "iicbus", -1);
809 if (iic_dev == NULL) {
811 "bbbus bridge doesn't have iicbus grandchild\n");
815 dev_priv->bbbus[i] = iic_dev;
817 dev_priv->gmbus_bridge[i] = device_add_child(dev->dev,
819 if (dev_priv->gmbus_bridge[i] == NULL) {
820 DRM_ERROR("gmbus bridge %d creation failed\n", i);
824 device_quiet(dev_priv->gmbus_bridge[i]);
825 ret = device_probe_and_attach(dev_priv->gmbus_bridge[i]);
827 DRM_ERROR("gmbus bridge %d attach failed, %d\n", i,
833 iic_dev = device_find_child(dev_priv->gmbus_bridge[i],
835 if (iic_dev == NULL) {
836 DRM_ERROR("gmbus bridge doesn't have iicbus child\n");
839 dev_priv->gmbus[i] = iic_dev;
841 intel_i2c_reset(dev);
847 intel_teardown_gmbus_m(dev, i);
852 intel_teardown_gmbus_m(struct drm_device *dev, int m)
854 struct drm_i915_private *dev_priv;
856 dev_priv = dev->dev_private;
858 drm_free(dev_priv->gmbus, M_DRM);
859 dev_priv->gmbus = NULL;
860 drm_free(dev_priv->bbbus, M_DRM);
861 dev_priv->bbbus = NULL;
862 drm_free(dev_priv->gmbus_bridge, M_DRM);
863 dev_priv->gmbus_bridge = NULL;
864 drm_free(dev_priv->bbbus_bridge, M_DRM);
865 dev_priv->bbbus_bridge = NULL;
866 lockuninit(&dev_priv->gmbus_mutex);
870 intel_teardown_gmbus(struct drm_device *dev)
874 intel_teardown_gmbus_m(dev, GMBUS_NUM_PORTS);