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"
82 static const struct gmbus_port gmbus_ports[] = {
91 /* Intel GPIO access functions */
93 #define I2C_RISEFALL_TIME 10
95 static int get_disp_clk_div(struct drm_i915_private *dev_priv,
101 reg_val = I915_READ(CZCLK_CDCLK_FREQ_RATIO);
105 ((reg_val & CDCLK_FREQ_MASK) >> CDCLK_FREQ_SHIFT) + 1;
107 clk_ratio = (reg_val & CZCLK_FREQ_MASK) + 1;
112 static void gmbus_set_freq(struct drm_i915_private *dev_priv)
114 int vco, gmbus_freq = 0, cdclk_div;
116 BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
118 vco = valleyview_get_vco(dev_priv);
120 /* Get the CDCLK divide ratio */
121 cdclk_div = get_disp_clk_div(dev_priv, CDCLK);
124 * Program the gmbus_freq based on the cdclk frequency.
125 * BSpec erroneously claims we should aim for 4MHz, but
126 * in fact 1MHz is the correct frequency.
129 gmbus_freq = (vco << 1) / cdclk_div;
131 if (WARN_ON(gmbus_freq == 0))
134 I915_WRITE(GMBUSFREQ_VLV, gmbus_freq);
138 intel_i2c_reset(struct drm_device *dev)
140 struct drm_i915_private *dev_priv = dev->dev_private;
143 * In BIOS-less system, program the correct gmbus frequency
144 * before reading edid.
146 if (IS_VALLEYVIEW(dev))
147 gmbus_set_freq(dev_priv);
149 I915_WRITE(dev_priv->gpio_mmio_base + GMBUS0, 0);
150 I915_WRITE(dev_priv->gpio_mmio_base + GMBUS4, 0);
153 static void intel_i2c_quirk_set(struct drm_i915_private *dev_priv, bool enable)
157 /* When using bit bashing for I2C, this bit needs to be set to 1 */
158 if (!IS_PINEVIEW(dev_priv->dev))
161 val = I915_READ(DSPCLK_GATE_D);
163 val |= DPCUNIT_CLOCK_GATE_DISABLE;
165 val &= ~DPCUNIT_CLOCK_GATE_DISABLE;
166 I915_WRITE(DSPCLK_GATE_D, val);
169 static u32 get_reserved(device_t idev)
171 struct intel_iic_softc *sc = device_get_softc(idev);
172 struct drm_device *dev = sc->drm_dev;
173 struct drm_i915_private *dev_priv;
176 dev_priv = dev->dev_private;
178 /* On most chips, these bits must be preserved in software. */
179 if (!IS_I830(dev) && !IS_845G(dev))
180 reserved = I915_READ_NOTRACE(sc->reg) &
181 (GPIO_DATA_PULLUP_DISABLE |
182 GPIO_CLOCK_PULLUP_DISABLE);
187 static int get_clock(device_t idev)
189 struct intel_iic_softc *sc;
190 struct drm_i915_private *dev_priv;
193 sc = device_get_softc(idev);
194 dev_priv = sc->drm_dev->dev_private;
196 reserved = get_reserved(idev);
198 I915_WRITE_NOTRACE(sc->reg, reserved | GPIO_CLOCK_DIR_MASK);
199 I915_WRITE_NOTRACE(sc->reg, reserved);
200 return ((I915_READ_NOTRACE(sc->reg) & GPIO_CLOCK_VAL_IN) != 0);
203 static int get_data(device_t idev)
205 struct intel_iic_softc *sc;
206 struct drm_i915_private *dev_priv;
209 sc = device_get_softc(idev);
210 dev_priv = sc->drm_dev->dev_private;
212 reserved = get_reserved(idev);
214 I915_WRITE_NOTRACE(sc->reg, reserved | GPIO_DATA_DIR_MASK);
215 I915_WRITE_NOTRACE(sc->reg, reserved);
216 return ((I915_READ_NOTRACE(sc->reg) & GPIO_DATA_VAL_IN) != 0);
220 intel_iicbus_reset(device_t idev, u_char speed, u_char addr, u_char *oldaddr)
222 struct intel_iic_softc *sc;
223 struct drm_device *dev;
225 sc = device_get_softc(idev);
228 intel_i2c_reset(dev);
232 static void set_clock(device_t idev, int val)
234 struct intel_iic_softc *sc;
235 struct drm_i915_private *dev_priv;
236 u32 clock_bits, reserved;
238 sc = device_get_softc(idev);
239 dev_priv = sc->drm_dev->dev_private;
241 reserved = get_reserved(idev);
243 clock_bits = GPIO_CLOCK_DIR_IN | GPIO_CLOCK_DIR_MASK;
245 clock_bits = GPIO_CLOCK_DIR_OUT | GPIO_CLOCK_DIR_MASK |
248 I915_WRITE_NOTRACE(sc->reg, reserved | clock_bits);
249 POSTING_READ(sc->reg);
252 static void set_data(device_t idev, int val)
254 struct intel_iic_softc *sc;
255 struct drm_i915_private *dev_priv;
259 sc = device_get_softc(idev);
260 dev_priv = sc->drm_dev->dev_private;
262 reserved = get_reserved(idev);
265 data_bits = GPIO_DATA_DIR_IN | GPIO_DATA_DIR_MASK;
267 data_bits = GPIO_DATA_DIR_OUT | GPIO_DATA_DIR_MASK |
270 I915_WRITE_NOTRACE(sc->reg, reserved | data_bits);
271 POSTING_READ(sc->reg);
274 static const char *gpio_names[GMBUS_NUM_PORTS] = {
284 intel_gpio_setup(device_t idev)
286 static const int map_pin_to_reg[] = {
297 struct intel_iic_softc *sc;
298 struct drm_i915_private *dev_priv;
301 sc = device_get_softc(idev);
302 sc->drm_dev = device_get_softc(device_get_parent(idev));
303 dev_priv = sc->drm_dev->dev_private;
304 pin = device_get_unit(idev);
306 ksnprintf(sc->name, sizeof(sc->name), "i915 iicbb %s", gpio_names[pin]);
307 device_set_desc(idev, sc->name);
309 sc->reg0 = (pin + 1) | GMBUS_RATE_100KHZ;
310 sc->reg = dev_priv->gpio_mmio_base + map_pin_to_reg[pin + 1];
312 /* add generic bit-banging code */
313 sc->iic_dev = device_add_child(idev, "iicbb", -1);
314 if (sc->iic_dev == NULL)
316 device_quiet(sc->iic_dev);
317 bus_generic_attach(idev);
323 intel_i2c_quirk_xfer(device_t idev, struct iic_msg *msgs, int nmsgs)
326 struct intel_iic_softc *sc;
327 struct drm_i915_private *dev_priv;
331 bridge_dev = device_get_parent(device_get_parent(idev));
332 sc = device_get_softc(bridge_dev);
333 dev_priv = sc->drm_dev->dev_private;
335 intel_i2c_reset(sc->drm_dev);
336 intel_i2c_quirk_set(dev_priv, true);
337 IICBB_SETSDA(bridge_dev, 1);
338 IICBB_SETSCL(bridge_dev, 1);
339 DELAY(I2C_RISEFALL_TIME);
341 for (i = 0; i < nmsgs - 1; i++) {
342 /* force use of repeated start instead of default stop+start */
343 msgs[i].flags |= IIC_M_NOSTOP;
345 ret = iicbus_transfer(idev, msgs, nmsgs);
346 IICBB_SETSDA(bridge_dev, 1);
347 IICBB_SETSCL(bridge_dev, 1);
348 intel_i2c_quirk_set(dev_priv, false);
354 gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
359 int reg_offset = dev_priv->gpio_mmio_base;
363 if (!HAS_GMBUS_IRQ(dev_priv->dev))
366 /* Important: The hw handles only the first bit, so set only one! Since
367 * we also need to check for NAKs besides the hw ready/idle signal, we
368 * need to wake up periodically and check that ourselves. */
369 I915_WRITE(GMBUS4 + reg_offset, gmbus4_irq_en);
371 for (i = 0; i < msecs_to_jiffies_timeout(50); i++) {
372 prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait,
373 TASK_UNINTERRUPTIBLE);
375 gmbus2 = I915_READ_NOTRACE(GMBUS2 + reg_offset);
376 if (gmbus2 & (GMBUS_SATOER | gmbus2_status))
381 finish_wait(&dev_priv->gmbus_wait_queue, &wait);
383 I915_WRITE(GMBUS4 + reg_offset, 0);
385 if (gmbus2 & GMBUS_SATOER)
387 if (gmbus2 & gmbus2_status)
393 gmbus_wait_idle(struct drm_i915_private *dev_priv)
396 int reg_offset = dev_priv->gpio_mmio_base;
398 #define C ((I915_READ_NOTRACE(GMBUS2 + reg_offset) & GMBUS_ACTIVE) == 0)
400 if (!HAS_GMBUS_IRQ(dev_priv->dev))
401 return wait_for(C, 10);
403 /* Important: The hw handles only the first bit, so set only one! */
404 I915_WRITE(GMBUS4 + reg_offset, GMBUS_IDLE_EN);
406 ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
407 msecs_to_jiffies_timeout(10));
409 I915_WRITE(GMBUS4 + reg_offset, 0);
419 gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg,
422 int reg_offset = dev_priv->gpio_mmio_base;
426 I915_WRITE(GMBUS1 + reg_offset,
429 (len << GMBUS_BYTE_COUNT_SHIFT) |
430 (msg->slave << (GMBUS_SLAVE_ADDR_SHIFT - 1)) |
431 GMBUS_SLAVE_READ | GMBUS_SW_RDY);
436 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY,
441 val = I915_READ(GMBUS3 + reg_offset);
445 } while (--len && ++loop < 4);
452 gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg)
454 int reg_offset = dev_priv->gpio_mmio_base;
460 while (len && loop < 4) {
461 val |= *buf++ << (8 * loop++);
465 I915_WRITE(GMBUS3 + reg_offset, val);
466 I915_WRITE(GMBUS1 + reg_offset,
468 (msg->len << GMBUS_BYTE_COUNT_SHIFT) |
469 (msg->slave << (GMBUS_SLAVE_ADDR_SHIFT - 1)) |
470 GMBUS_SLAVE_WRITE | GMBUS_SW_RDY);
476 val |= *buf++ << (8 * loop);
477 } while (--len && ++loop < 4);
479 I915_WRITE(GMBUS3 + reg_offset, val);
481 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_RDY,
490 * The gmbus controller can combine a 1 or 2 byte write with a read that
491 * immediately follows it by using an "INDEX" cycle.
494 gmbus_is_index_read(struct i2c_msg *msgs, int i, int num)
496 return (i + 1 < num &&
497 !(msgs[i].flags & I2C_M_RD) && msgs[i].len <= 2 &&
498 (msgs[i + 1].flags & I2C_M_RD));
502 gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs)
504 int reg_offset = dev_priv->gpio_mmio_base;
505 u32 gmbus1_index = 0;
509 if (msgs[0].len == 2)
510 gmbus5 = GMBUS_2BYTE_INDEX_EN |
511 msgs[0].buf[1] | (msgs[0].buf[0] << 8);
512 if (msgs[0].len == 1)
513 gmbus1_index = GMBUS_CYCLE_INDEX |
514 (msgs[0].buf[0] << GMBUS_SLAVE_INDEX_SHIFT);
516 /* GMBUS5 holds 16-bit index */
518 I915_WRITE(GMBUS5 + reg_offset, gmbus5);
520 ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index);
522 /* Clear GMBUS5 after each index transfer */
524 I915_WRITE(GMBUS5 + reg_offset, 0);
530 gmbus_xfer(struct device *adapter,
531 struct i2c_msg *msgs,
534 struct intel_iic_softc *sc;
535 struct drm_i915_private *dev_priv;
536 int i, reg_offset, unit;
539 sc = device_get_softc(adapter);
540 dev_priv = sc->drm_dev->dev_private;
541 unit = device_get_unit(adapter);
543 mutex_lock(&dev_priv->gmbus_mutex);
545 if (sc->force_bit_dev) {
546 ret = intel_i2c_quirk_xfer(dev_priv->bbbus[unit], msgs, num);
550 reg_offset = HAS_PCH_SPLIT(dev_priv->dev) ? PCH_GMBUS0 - GMBUS0 : 0;
552 I915_WRITE(GMBUS0 + reg_offset, sc->reg0);
554 for (i = 0; i < num; i++) {
555 if (gmbus_is_index_read(msgs, i, num)) {
556 ret = gmbus_xfer_index_read(dev_priv, &msgs[i]);
557 i += 1; /* set i to the index of the read xfer */
558 } else if (msgs[i].flags & I2C_M_RD) {
559 ret = gmbus_xfer_read(dev_priv, &msgs[i], 0);
561 ret = gmbus_xfer_write(dev_priv, &msgs[i]);
564 if (ret == -ETIMEDOUT)
569 ret = gmbus_wait_hw_status(dev_priv, GMBUS_HW_WAIT_PHASE,
577 /* Generate a STOP condition on the bus. Note that gmbus can't generata
578 * a STOP on the very first cycle. To simplify the code we
579 * unconditionally generate the STOP condition with an additional gmbus
581 I915_WRITE(GMBUS1 + reg_offset, GMBUS_CYCLE_STOP | GMBUS_SW_RDY);
583 /* Mark the GMBUS interface as disabled after waiting for idle.
584 * We will re-enable it at the start of the next xfer,
585 * till then let it sleep.
587 if (gmbus_wait_idle(dev_priv)) {
588 DRM_DEBUG_KMS("GMBUS [%s] timed out waiting for idle\n",
592 I915_WRITE(GMBUS0 + reg_offset, 0);
594 goto timeout; /* XXX: should be out */
598 * Wait for bus to IDLE before clearing NAK.
599 * If we clear the NAK while bus is still active, then it will stay
600 * active and the next transaction may fail.
602 * If no ACK is received during the address phase of a transaction, the
603 * adapter must report -ENXIO. It is not clear what to return if no ACK
604 * is received at other times. But we have to be careful to not return
605 * spurious -ENXIO because that will prevent i2c and drm edid functions
606 * from retrying. So return -ENXIO only when gmbus properly quiescents -
607 * timing out seems to happen when there _is_ a ddc chip present, but
608 * it's slow responding and only answers on the 2nd retry.
611 if (gmbus_wait_idle(dev_priv)) {
612 DRM_DEBUG_KMS("GMBUS [%s] timed out after NAK\n",
617 /* Toggle the Software Clear Interrupt bit. This has the effect
618 * of resetting the GMBUS controller and so clearing the
619 * BUS_ERROR raised by the slave's NAK.
621 I915_WRITE(GMBUS1 + reg_offset, GMBUS_SW_CLR_INT);
622 I915_WRITE(GMBUS1 + reg_offset, 0);
623 I915_WRITE(GMBUS0 + reg_offset, 0);
625 DRM_DEBUG_KMS("GMBUS [%s] NAK for addr: %04x %c(%d)\n",
626 sc->name, msgs[i].slave,
627 (msgs[i].flags & I2C_M_RD) ? 'r' : 'w', msgs[i].len);
632 DRM_INFO("GMBUS [%s] timed out, falling back to bit banging on pin %d\n",
633 sc->name, sc->reg0 & 0xff);
634 I915_WRITE(GMBUS0 + reg_offset, 0);
636 /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */
637 sc->force_bit_dev = true;
638 ret = intel_i2c_quirk_xfer(dev_priv->bbbus[unit], msgs, num);
641 mutex_unlock(&dev_priv->gmbus_mutex);
645 struct device *intel_gmbus_get_adapter(struct drm_i915_private *dev_priv,
648 WARN_ON(!intel_gmbus_is_port_valid(port));
649 /* -1 to map pin pair to gmbus index */
650 return (intel_gmbus_is_port_valid(port)) ?
651 dev_priv->gmbus[port-1] : NULL;
655 intel_gmbus_set_speed(device_t idev, int speed)
657 struct intel_iic_softc *sc;
659 sc = device_get_softc(device_get_parent(idev));
661 sc->reg0 = (sc->reg0 & ~(0x3 << 8)) | speed;
665 intel_gmbus_force_bit(device_t idev, bool force_bit)
667 struct intel_iic_softc *sc;
669 sc = device_get_softc(device_get_parent(idev));
670 sc->force_bit_dev += force_bit ? 1 : -1;
671 DRM_DEBUG_KMS("%sabling bit-banging on %s. force bit now %d\n",
672 force_bit ? "en" : "dis", sc->name,
677 intel_gmbus_probe(device_t dev)
680 return (BUS_PROBE_SPECIFIC);
684 intel_gmbus_attach(device_t idev)
686 struct drm_i915_private *dev_priv;
687 struct intel_iic_softc *sc;
690 sc = device_get_softc(idev);
691 sc->drm_dev = device_get_softc(device_get_parent(idev));
692 dev_priv = sc->drm_dev->dev_private;
693 pin = device_get_unit(idev);
695 ksnprintf(sc->name, sizeof(sc->name), "gmbus bus %s", gpio_names[pin]);
696 device_set_desc(idev, sc->name);
698 /* By default use a conservative clock rate */
699 sc->reg0 = (pin + 1) | GMBUS_RATE_100KHZ;
701 /* XXX force bit banging until GMBUS is fully debugged */
702 if (IS_GEN2(sc->drm_dev)) {
703 sc->force_bit_dev = true;
706 /* add bus interface device */
707 sc->iic_dev = device_add_child(idev, "iicbus", -1);
708 if (sc->iic_dev == NULL)
710 device_quiet(sc->iic_dev);
711 bus_generic_attach(idev);
717 intel_gmbus_detach(device_t idev)
719 struct intel_iic_softc *sc;
720 struct drm_i915_private *dev_priv;
724 sc = device_get_softc(idev);
725 u = device_get_unit(idev);
726 dev_priv = sc->drm_dev->dev_private;
729 bus_generic_detach(idev);
731 device_delete_child(idev, child);
737 intel_iicbb_probe(device_t dev)
740 return (BUS_PROBE_DEFAULT);
744 intel_iicbb_detach(device_t idev)
746 struct intel_iic_softc *sc;
749 sc = device_get_softc(idev);
751 bus_generic_detach(idev);
753 device_delete_child(idev, child);
757 static device_method_t intel_gmbus_methods[] = {
758 DEVMETHOD(device_probe, intel_gmbus_probe),
759 DEVMETHOD(device_attach, intel_gmbus_attach),
760 DEVMETHOD(device_detach, intel_gmbus_detach),
761 DEVMETHOD(iicbus_reset, intel_iicbus_reset),
762 DEVMETHOD(iicbus_transfer, gmbus_xfer),
765 static driver_t intel_gmbus_driver = {
768 sizeof(struct intel_iic_softc)
770 static devclass_t intel_gmbus_devclass;
771 DRIVER_MODULE_ORDERED(intel_gmbus, drm, intel_gmbus_driver,
772 intel_gmbus_devclass, 0, 0, SI_ORDER_FIRST);
773 DRIVER_MODULE(iicbus, intel_gmbus, iicbus_driver, iicbus_devclass, NULL, NULL);
775 static device_method_t intel_iicbb_methods[] = {
776 DEVMETHOD(device_probe, intel_iicbb_probe),
777 DEVMETHOD(device_attach, intel_gpio_setup),
778 DEVMETHOD(device_detach, intel_iicbb_detach),
780 DEVMETHOD(bus_add_child, bus_generic_add_child),
781 DEVMETHOD(bus_print_child, bus_generic_print_child),
783 DEVMETHOD(iicbb_callback, iicbus_null_callback),
784 DEVMETHOD(iicbb_reset, intel_iicbus_reset),
785 DEVMETHOD(iicbb_setsda, set_data),
786 DEVMETHOD(iicbb_setscl, set_clock),
787 DEVMETHOD(iicbb_getsda, get_data),
788 DEVMETHOD(iicbb_getscl, get_clock),
791 static driver_t intel_iicbb_driver = {
794 sizeof(struct intel_iic_softc)
796 static devclass_t intel_iicbb_devclass;
797 DRIVER_MODULE_ORDERED(intel_iicbb, drm, intel_iicbb_driver,
798 intel_iicbb_devclass, 0, 0, SI_ORDER_FIRST);
799 DRIVER_MODULE(iicbb, intel_iicbb, iicbb_driver, iicbb_devclass, NULL, NULL);
801 static void intel_teardown_gmbus_m(struct drm_device *dev, int m);
804 intel_setup_gmbus(struct drm_device *dev)
806 struct drm_i915_private *dev_priv = dev->dev_private;
810 if (HAS_PCH_NOP(dev))
812 else if (HAS_PCH_SPLIT(dev))
813 dev_priv->gpio_mmio_base = PCH_GPIOA - GPIOA;
814 else if (IS_VALLEYVIEW(dev))
815 dev_priv->gpio_mmio_base = VLV_DISPLAY_BASE;
817 dev_priv->gpio_mmio_base = 0;
819 lockinit(&dev_priv->gmbus_mutex, "gmbus", 0, LK_CANRECURSE);
820 init_waitqueue_head(&dev_priv->gmbus_wait_queue);
822 dev_priv->gmbus_bridge = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
823 M_DRM, M_WAITOK | M_ZERO);
824 dev_priv->bbbus_bridge = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
825 M_DRM, M_WAITOK | M_ZERO);
826 dev_priv->gmbus = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
827 M_DRM, M_WAITOK | M_ZERO);
828 dev_priv->bbbus = kmalloc(sizeof(device_t) * GMBUS_NUM_PORTS,
829 M_DRM, M_WAITOK | M_ZERO);
831 for (i = 0; i < GMBUS_NUM_PORTS; i++) {
833 * Initialized bbbus_bridge before gmbus_bridge, since
834 * gmbus may decide to force quirk transfer in the
837 dev_priv->bbbus_bridge[i] = device_add_child(dev->dev,
839 if (dev_priv->bbbus_bridge[i] == NULL) {
840 DRM_ERROR("bbbus bridge %d creation failed\n", i);
844 device_quiet(dev_priv->bbbus_bridge[i]);
845 ret = device_probe_and_attach(dev_priv->bbbus_bridge[i]);
847 DRM_ERROR("bbbus bridge %d attach failed, %d\n", i,
852 iic_dev = device_find_child(dev_priv->bbbus_bridge[i], "iicbb",
854 if (iic_dev == NULL) {
855 DRM_ERROR("bbbus bridge doesn't have iicbb child\n");
858 iic_dev = device_find_child(iic_dev, "iicbus", -1);
859 if (iic_dev == NULL) {
861 "bbbus bridge doesn't have iicbus grandchild\n");
865 dev_priv->bbbus[i] = iic_dev;
867 dev_priv->gmbus_bridge[i] = device_add_child(dev->dev,
869 if (dev_priv->gmbus_bridge[i] == NULL) {
870 DRM_ERROR("gmbus bridge %d creation failed\n", i);
874 device_quiet(dev_priv->gmbus_bridge[i]);
875 ret = device_probe_and_attach(dev_priv->gmbus_bridge[i]);
877 DRM_ERROR("gmbus bridge %d attach failed, %d\n", i,
883 iic_dev = device_find_child(dev_priv->gmbus_bridge[i],
885 if (iic_dev == NULL) {
886 DRM_ERROR("gmbus bridge doesn't have iicbus child\n");
889 dev_priv->gmbus[i] = iic_dev;
891 intel_i2c_reset(dev);
897 intel_teardown_gmbus_m(dev, i);
902 intel_teardown_gmbus_m(struct drm_device *dev, int m)
904 struct drm_i915_private *dev_priv;
906 dev_priv = dev->dev_private;
908 drm_free(dev_priv->gmbus, M_DRM);
909 dev_priv->gmbus = NULL;
910 drm_free(dev_priv->bbbus, M_DRM);
911 dev_priv->bbbus = NULL;
912 drm_free(dev_priv->gmbus_bridge, M_DRM);
913 dev_priv->gmbus_bridge = NULL;
914 drm_free(dev_priv->bbbus_bridge, M_DRM);
915 dev_priv->bbbus_bridge = NULL;
916 lockuninit(&dev_priv->gmbus_mutex);
920 intel_teardown_gmbus(struct drm_device *dev)
924 intel_teardown_gmbus_m(dev, GMBUS_NUM_PORTS);