FreeBSD/sys/dev/drm2/i915/intel_iic.c
/**
 * intel_gmbus_setup - instantiate all Intel i2c GMBuses
 * @dev: DRM device
 */
instantiate all Intel i2c GMBuses
@dev: DRM device
instantiate all Intel i2c GMBuses @dev : DRM device
int intel_setup_gmbus(struct drm_device *dev)
{
	struct drm_i915_private *dev_priv = dev->dev_private;
	device_t iic_dev;
	int ret, i;
	if (HAS_PCH_SPLIT(dev))
		dev_priv->gpio_mmio_base = PCH_GPIOA - GPIOA;
	else
		dev_priv->gpio_mmio_base = 0;
	sx_init(&dev_priv->gmbus_mutex, "gmbus");
	mtx_lock(&Giant);
	for (i = 0; i < GMBUS_NUM_PORTS; i++) {
		struct intel_gmbus *bus = &dev_priv->gmbus[i];
		u32 port = i + 1; 
		bus->dev_priv = dev_priv;
		bus->reg0 = port | GMBUS_RATE_100KHZ;
		if (IS_I830(dev))
			bus->force_bit = 1;
		intel_gpio_setup(bus, port);
		bus->bbbus_bridge = device_add_child(dev->dev,
		    "intel_iicbb", i);
		if (bus->bbbus_bridge == NULL) {
			DRM_ERROR("bbbus bridge %d creation failed\n", i);
			ret = -ENXIO;
			goto err;
		}
		device_quiet(bus->bbbus_bridge);
		ret = -device_probe_and_attach(bus->bbbus_bridge);
		if (ret != 0) {
			DRM_ERROR("bbbus bridge %d attach failed, %d\n", i,
			    ret);
			goto err;
		}
		iic_dev = device_find_child(bus->bbbus_bridge,
		    "iicbb", -1);
		if (iic_dev == NULL) {
			DRM_ERROR("bbbus bridge doesn't have iicbb child\n");
			goto err;
		}
		iic_dev = device_find_child(iic_dev, "iicbus", -1);
		if (iic_dev == NULL) {
			DRM_ERROR(
		"bbbus bridge doesn't have iicbus grandchild\n");
			goto err;
		}
		bus->bbbus = iic_dev;
		bus->gmbus_bridge = device_add_child(dev->dev,
		    "intel_gmbus", i);
		if (bus->gmbus_bridge == NULL) {
			DRM_ERROR("gmbus bridge %d creation failed\n", i);
			ret = -ENXIO;
			goto err;
		}
		device_quiet(bus->gmbus_bridge);
		ret = -device_probe_and_attach(bus->gmbus_bridge);
		if (ret != 0) {
			DRM_ERROR("gmbus bridge %d attach failed, %d\n", i,
			    ret);
			ret = -ENXIO;
			goto err;
		}
		iic_dev = device_find_child(bus->gmbus_bridge,
		    "iicbus", -1);
		if (iic_dev == NULL) {
			DRM_ERROR("gmbus bridge doesn't have iicbus child\n");
			goto err;
		}
		bus->gmbus = iic_dev;
	}
	mtx_unlock(&Giant);
	intel_i2c_reset(dev_priv->dev);
	return 0;
err:
	while (--i) {
		struct intel_gmbus *bus = &dev_priv->gmbus[i];
		if (bus->gmbus_bridge != NULL)
			device_delete_child(dev->dev, bus->gmbus_bridge);
		if (bus->bbbus_bridge != NULL)
			device_delete_child(dev->dev, bus->bbbus_bridge);
	}
	mtx_unlock(&Giant);
	sx_destroy(&dev_priv->gmbus_mutex);
	return ret;
}
int intel_setup_gmbus ( struct drm_device * dev ) { struct drm_i915_private * dev_priv = dev -> dev_private ; device_t iic_dev ; int ret , i ; if ( HAS_PCH_SPLIT ( dev ) ) dev_priv -> gpio_mmio_base = PCH_GPIOA - GPIOA ; else dev_priv -> gpio_mmio_base = 0 ; sx_init ( & dev_priv -> gmbus_mutex , " " ) ; mtx_lock ( & Giant ) ; for ( i = 0 ; i < GMBUS_NUM_PORTS ; i ++ ) { struct intel_gmbus * bus = & dev_priv -> gmbus [ i ] ; u32 port = i + 1 ; bus -> dev_priv = dev_priv ; bus -> reg0 = port | GMBUS_RATE_100KHZ ; if ( IS_I830 ( dev ) ) bus -> force_bit = 1 ; intel_gpio_setup ( bus , port ) ; bus -> bbbus_bridge = device_add_child ( dev -> dev , " " , i ) ; if ( bus -> bbbus_bridge == NULL ) { DRM_ERROR ( " \n " , i ) ; ret = - ENXIO ; goto err ; } device_quiet ( bus -> bbbus_bridge ) ; ret = - device_probe_and_attach ( bus -> bbbus_bridge ) ; if ( ret != 0 ) { DRM_ERROR ( " \n " , i , ret ) ; goto err ; } iic_dev = device_find_child ( bus -> bbbus_bridge , " " , -1 ) ; if ( iic_dev == NULL ) { DRM_ERROR ( " \n " ) ; goto err ; } iic_dev = device_find_child ( iic_dev , " " , -1 ) ; if ( iic_dev == NULL ) { DRM_ERROR ( " \n " ) ; goto err ; } bus -> bbbus = iic_dev ; bus -> gmbus_bridge = device_add_child ( dev -> dev , " " , i ) ; if ( bus -> gmbus_bridge == NULL ) { DRM_ERROR ( " \n " , i ) ; ret = - ENXIO ; goto err ; } device_quiet ( bus -> gmbus_bridge ) ; ret = - device_probe_and_attach ( bus -> gmbus_bridge ) ; if ( ret != 0 ) { DRM_ERROR ( " \n " , i , ret ) ; ret = - ENXIO ; goto err ; } iic_dev = device_find_child ( bus -> gmbus_bridge , " " , -1 ) ; if ( iic_dev == NULL ) { DRM_ERROR ( " \n " ) ; goto err ; } bus -> gmbus = iic_dev ; } mtx_unlock ( & Giant ) ; intel_i2c_reset ( dev_priv -> dev ) ; return 0 ; err : while ( -- i ) { struct intel_gmbus * bus = & dev_priv -> gmbus [ i ] ; if ( bus -> gmbus_bridge != NULL ) device_delete_child ( dev -> dev , bus -> gmbus_bridge ) ; if ( bus -> bbbus_bridge != NULL ) device_delete_child ( dev -> dev , bus -> bbbus_bridge ) ; } mtx_unlock ( & Giant ) ; sx_destroy ( & dev_priv -> gmbus_mutex ) ; return ret ; }
intel_gmbus_setup - instantiate all Intel i2c GMBuses
 @dev: DRM device
intel_gmbus_setup - instantiate all Intel i2c GMBuses @dev : DRM device
/*
	 * The Giant there is recursed, most likely.  Normally, the
	 * intel_setup_gmbus() is called from the attach method of the
	 * driver.
	 */ /* +1 to map gmbus index to pin pair */ /* By default use a conservative clock rate */ /* gmbus seems to be broken on i830 */ /*
		 * bbbus_bridge
		 *
		 * Initialized bbbus_bridge before gmbus_bridge, since
		 * gmbus may decide to force quirk transfer in the
		 * attachment code.
		 */ /* bbbus */ /* gmbus_bridge */ /* gmbus */