Explorar o código

drm/i915: merge gmbus and gpio i2c adpater into one

... and directly call the newly exported i2c bit-banging functions.

The code is still pretty convoluted because we only set up the gpio
i2c stuff when actually falling back, resulting in more complexity
than necessary. This will be fixed up in the next patch.

v2: Use exported i2c_bit_algo vtable instead of exported functions.

Reviewed-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Daniel Vetter %!s(int64=13) %!d(string=hai) anos
pai
achega
c167a6fc6e
Modificáronse 2 ficheiros con 7 adicións e 33 borrados
  1. 2 0
      drivers/gpu/drm/i915/i915_drv.h
  2. 5 33
      drivers/gpu/drm/i915/intel_i2c.c

+ 2 - 0
drivers/gpu/drm/i915/i915_drv.h

@@ -35,6 +35,7 @@
 #include "intel_ringbuffer.h"
 #include "intel_ringbuffer.h"
 #include <linux/io-mapping.h>
 #include <linux/io-mapping.h>
 #include <linux/i2c.h>
 #include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
 #include <drm/intel-gtt.h>
 #include <drm/intel-gtt.h>
 #include <linux/backlight.h>
 #include <linux/backlight.h>
 
 
@@ -303,6 +304,7 @@ struct intel_gmbus {
 	struct i2c_adapter *force_bit;
 	struct i2c_adapter *force_bit;
 	u32 reg0;
 	u32 reg0;
 	u32 gpio_reg;
 	u32 gpio_reg;
+	struct i2c_algo_bit_data bit_algo;
 	struct drm_i915_private *dev_priv;
 	struct drm_i915_private *dev_priv;
 };
 };
 
 

+ 5 - 33
drivers/gpu/drm/i915/intel_i2c.c

@@ -154,29 +154,18 @@ intel_gpio_create(struct intel_gmbus *bus, u32 pin)
 		0,
 		0,
 		GPIOF,
 		GPIOF,
 	};
 	};
-	struct i2c_adapter *adapter;
 	struct i2c_algo_bit_data *algo;
 	struct i2c_algo_bit_data *algo;
 
 
 	if (pin >= ARRAY_SIZE(map_pin_to_reg) || !map_pin_to_reg[pin])
 	if (pin >= ARRAY_SIZE(map_pin_to_reg) || !map_pin_to_reg[pin])
 		return NULL;
 		return NULL;
 
 
-	adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
-	if (adapter == NULL)
-		return NULL;
-
-	algo = kzalloc(sizeof(struct i2c_algo_bit_data), GFP_KERNEL);
-	if (algo == NULL)
-		goto out_adap;
+	algo = &bus->bit_algo;
 
 
 	bus->gpio_reg = map_pin_to_reg[pin];
 	bus->gpio_reg = map_pin_to_reg[pin];
 	if (HAS_PCH_SPLIT(dev_priv->dev))
 	if (HAS_PCH_SPLIT(dev_priv->dev))
 		bus->gpio_reg += PCH_GPIOA - GPIOA;
 		bus->gpio_reg += PCH_GPIOA - GPIOA;
 
 
-	snprintf(adapter->name, sizeof(adapter->name),
-		 "i915 GPIO%c", "?BACDE?F"[pin]);
-	adapter->owner = THIS_MODULE;
-	adapter->algo_data = algo;
-	adapter->dev.parent = &dev_priv->dev->pdev->dev;
+	bus->adapter.algo_data = algo;
 	algo->setsda = set_data;
 	algo->setsda = set_data;
 	algo->setscl = set_clock;
 	algo->setscl = set_clock;
 	algo->getsda = get_data;
 	algo->getsda = get_data;
@@ -185,16 +174,7 @@ intel_gpio_create(struct intel_gmbus *bus, u32 pin)
 	algo->timeout = usecs_to_jiffies(2200);
 	algo->timeout = usecs_to_jiffies(2200);
 	algo->data = bus;
 	algo->data = bus;
 
 
-	if (i2c_bit_add_bus(adapter))
-		goto out_algo;
-
-	return adapter;
-
-out_algo:
-	kfree(algo);
-out_adap:
-	kfree(adapter);
-	return NULL;
+	return &bus->adapter;
 }
 }
 
 
 static int
 static int
@@ -213,7 +193,7 @@ intel_i2c_quirk_xfer(struct intel_gmbus *bus,
 	set_clock(bus, 1);
 	set_clock(bus, 1);
 	udelay(I2C_RISEFALL_TIME);
 	udelay(I2C_RISEFALL_TIME);
 
 
-	ret = adapter->algo->master_xfer(adapter, msgs, num);
+	ret = i2c_bit_algo.master_xfer(adapter, msgs, num);
 
 
 	set_data(bus, 1);
 	set_data(bus, 1);
 	set_clock(bus, 1);
 	set_clock(bus, 1);
@@ -353,7 +333,7 @@ static u32 gmbus_func(struct i2c_adapter *adapter)
 					       adapter);
 					       adapter);
 
 
 	if (bus->force_bit)
 	if (bus->force_bit)
-		bus->force_bit->algo->functionality(bus->force_bit);
+		i2c_bit_algo.functionality(bus->force_bit);
 
 
 	return (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
 	return (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
 		/* I2C_FUNC_10BIT_ADDR | */
 		/* I2C_FUNC_10BIT_ADDR | */
@@ -449,9 +429,6 @@ void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit)
 		}
 		}
 	} else {
 	} else {
 		if (bus->force_bit) {
 		if (bus->force_bit) {
-			i2c_del_adapter(bus->force_bit);
-			kfree(bus->force_bit->algo);
-			kfree(bus->force_bit);
 			bus->force_bit = NULL;
 			bus->force_bit = NULL;
 		}
 		}
 	}
 	}
@@ -467,11 +444,6 @@ void intel_teardown_gmbus(struct drm_device *dev)
 
 
 	for (i = 0; i < GMBUS_NUM_PORTS; i++) {
 	for (i = 0; i < GMBUS_NUM_PORTS; i++) {
 		struct intel_gmbus *bus = &dev_priv->gmbus[i];
 		struct intel_gmbus *bus = &dev_priv->gmbus[i];
-		if (bus->force_bit) {
-			i2c_del_adapter(bus->force_bit);
-			kfree(bus->force_bit->algo);
-			kfree(bus->force_bit);
-		}
 		i2c_del_adapter(&bus->adapter);
 		i2c_del_adapter(&bus->adapter);
 	}
 	}