Commit f6f808c8 authored by Daniel Vetter's avatar Daniel Vetter

drm/i915: i2c: unconditionally set up gpio fallback

This way we can simplify the setup and teardown a bit.

Because we don't actually allocate anything anymore for the force_bit
case, we can now convert that into a boolean.

Also and the functionality supported by the bit-banging together with
what gmbus can do, so that this doesn't randomly change any more.

v2: Chris Wilson noticed that I've mixed up && and & ...

v3: Clarify an if block as suggested by Eugeni Dodonov.
Reviewed-by: default avatarEugeni Dodonov <eugeni.dodonov@intel.com>
Signed-Off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent c167a6fc
...@@ -301,7 +301,8 @@ struct intel_fbc_work; ...@@ -301,7 +301,8 @@ struct intel_fbc_work;
struct intel_gmbus { struct intel_gmbus {
struct i2c_adapter adapter; struct i2c_adapter adapter;
struct i2c_adapter *force_bit; bool force_bit;
bool has_gpio;
u32 reg0; u32 reg0;
u32 gpio_reg; u32 gpio_reg;
struct i2c_algo_bit_data bit_algo; struct i2c_algo_bit_data bit_algo;
......
...@@ -140,8 +140,8 @@ static void set_data(void *data, int state_high) ...@@ -140,8 +140,8 @@ static void set_data(void *data, int state_high)
POSTING_READ(bus->gpio_reg); POSTING_READ(bus->gpio_reg);
} }
static struct i2c_adapter * static bool
intel_gpio_create(struct intel_gmbus *bus, u32 pin) intel_gpio_setup(struct intel_gmbus *bus, u32 pin)
{ {
struct drm_i915_private *dev_priv = bus->dev_priv; struct drm_i915_private *dev_priv = bus->dev_priv;
static const int map_pin_to_reg[] = { static const int map_pin_to_reg[] = {
...@@ -157,7 +157,7 @@ intel_gpio_create(struct intel_gmbus *bus, u32 pin) ...@@ -157,7 +157,7 @@ intel_gpio_create(struct intel_gmbus *bus, u32 pin)
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 false;
algo = &bus->bit_algo; algo = &bus->bit_algo;
...@@ -174,12 +174,11 @@ intel_gpio_create(struct intel_gmbus *bus, u32 pin) ...@@ -174,12 +174,11 @@ 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;
return &bus->adapter; return true;
} }
static int static int
intel_i2c_quirk_xfer(struct intel_gmbus *bus, intel_i2c_quirk_xfer(struct intel_gmbus *bus,
struct i2c_adapter *adapter,
struct i2c_msg *msgs, struct i2c_msg *msgs,
int num) int num)
{ {
...@@ -193,7 +192,7 @@ intel_i2c_quirk_xfer(struct intel_gmbus *bus, ...@@ -193,7 +192,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 = i2c_bit_algo.master_xfer(adapter, msgs, num); ret = i2c_bit_algo.master_xfer(&bus->adapter, msgs, num);
set_data(bus, 1); set_data(bus, 1);
set_clock(bus, 1); set_clock(bus, 1);
...@@ -216,7 +215,7 @@ gmbus_xfer(struct i2c_adapter *adapter, ...@@ -216,7 +215,7 @@ gmbus_xfer(struct i2c_adapter *adapter,
mutex_lock(&dev_priv->gmbus_mutex); mutex_lock(&dev_priv->gmbus_mutex);
if (bus->force_bit) { if (bus->force_bit) {
ret = intel_i2c_quirk_xfer(bus, bus->force_bit, msgs, num); ret = intel_i2c_quirk_xfer(bus, msgs, num);
goto out; goto out;
} }
...@@ -316,11 +315,12 @@ gmbus_xfer(struct i2c_adapter *adapter, ...@@ -316,11 +315,12 @@ gmbus_xfer(struct i2c_adapter *adapter,
I915_WRITE(GMBUS0 + reg_offset, 0); I915_WRITE(GMBUS0 + reg_offset, 0);
/* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */ /* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */
bus->force_bit = intel_gpio_create(bus, bus->reg0 & 0xff); if (!bus->has_gpio) {
if (!bus->force_bit) ret = -EIO;
ret = -ENOMEM; } else {
else bus->force_bit = true;
ret = intel_i2c_quirk_xfer(bus, bus->force_bit, msgs, num); ret = intel_i2c_quirk_xfer(bus, msgs, num);
}
out: out:
mutex_unlock(&dev_priv->gmbus_mutex); mutex_unlock(&dev_priv->gmbus_mutex);
return ret; return ret;
...@@ -328,14 +328,8 @@ gmbus_xfer(struct i2c_adapter *adapter, ...@@ -328,14 +328,8 @@ gmbus_xfer(struct i2c_adapter *adapter,
static u32 gmbus_func(struct i2c_adapter *adapter) static u32 gmbus_func(struct i2c_adapter *adapter)
{ {
struct intel_gmbus *bus = container_of(adapter, return i2c_bit_algo.functionality(adapter) &
struct intel_gmbus, (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
adapter);
if (bus->force_bit)
i2c_bit_algo.functionality(bus->force_bit);
return (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
/* I2C_FUNC_10BIT_ADDR | */ /* I2C_FUNC_10BIT_ADDR | */
I2C_FUNC_SMBUS_READ_BLOCK_DATA | I2C_FUNC_SMBUS_READ_BLOCK_DATA |
I2C_FUNC_SMBUS_BLOCK_PROC_CALL); I2C_FUNC_SMBUS_BLOCK_PROC_CALL);
...@@ -393,8 +387,11 @@ int intel_setup_gmbus(struct drm_device *dev) ...@@ -393,8 +387,11 @@ int intel_setup_gmbus(struct drm_device *dev)
/* By default use a conservative clock rate */ /* By default use a conservative clock rate */
bus->reg0 = i | GMBUS_RATE_100KHZ; bus->reg0 = i | GMBUS_RATE_100KHZ;
bus->has_gpio = intel_gpio_setup(bus, i);
/* XXX force bit banging until GMBUS is fully debugged */ /* XXX force bit banging until GMBUS is fully debugged */
bus->force_bit = intel_gpio_create(bus, i); if (bus->has_gpio)
bus->force_bit = true;
} }
intel_i2c_reset(dev_priv->dev); intel_i2c_reset(dev_priv->dev);
...@@ -422,16 +419,8 @@ void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit) ...@@ -422,16 +419,8 @@ void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit)
{ {
struct intel_gmbus *bus = to_intel_gmbus(adapter); struct intel_gmbus *bus = to_intel_gmbus(adapter);
if (force_bit) { if (bus->has_gpio)
if (bus->force_bit == NULL) { bus->force_bit = force_bit;
bus->force_bit = intel_gpio_create(bus,
bus->reg0 & 0xff);
}
} else {
if (bus->force_bit) {
bus->force_bit = NULL;
}
}
} }
void intel_teardown_gmbus(struct drm_device *dev) void intel_teardown_gmbus(struct drm_device *dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment