POSTING_READ(bus->gpio_reg);
}
-static struct i2c_adapter *
-intel_gpio_create(struct intel_gmbus *bus, u32 pin)
+static bool
+intel_gpio_setup(struct intel_gmbus *bus, u32 pin)
{
struct drm_i915_private *dev_priv = bus->dev_priv;
static const int map_pin_to_reg[] = {
struct i2c_algo_bit_data *algo;
if (pin >= ARRAY_SIZE(map_pin_to_reg) || !map_pin_to_reg[pin])
- return NULL;
+ return false;
algo = &bus->bit_algo;
algo->timeout = usecs_to_jiffies(2200);
algo->data = bus;
- return &bus->adapter;
+ return true;
}
static int
intel_i2c_quirk_xfer(struct intel_gmbus *bus,
- struct i2c_adapter *adapter,
struct i2c_msg *msgs,
int num)
{
set_clock(bus, 1);
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_clock(bus, 1);
mutex_lock(&dev_priv->gmbus_mutex);
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;
}
I915_WRITE(GMBUS0 + reg_offset, 0);
/* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */
- bus->force_bit = intel_gpio_create(bus, bus->reg0 & 0xff);
- if (!bus->force_bit)
- ret = -ENOMEM;
- else
- ret = intel_i2c_quirk_xfer(bus, bus->force_bit, msgs, num);
+ if (!bus->has_gpio) {
+ ret = -EIO;
+ } else {
+ bus->force_bit = true;
+ ret = intel_i2c_quirk_xfer(bus, msgs, num);
+ }
out:
mutex_unlock(&dev_priv->gmbus_mutex);
return ret;
static u32 gmbus_func(struct i2c_adapter *adapter)
{
- struct intel_gmbus *bus = container_of(adapter,
- struct intel_gmbus,
- adapter);
-
- if (bus->force_bit)
- i2c_bit_algo.functionality(bus->force_bit);
-
- return (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
+ return i2c_bit_algo.functionality(adapter) &
+ (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
/* I2C_FUNC_10BIT_ADDR | */
I2C_FUNC_SMBUS_READ_BLOCK_DATA |
I2C_FUNC_SMBUS_BLOCK_PROC_CALL);
/* By default use a conservative clock rate */
bus->reg0 = i | GMBUS_RATE_100KHZ;
+ bus->has_gpio = intel_gpio_setup(bus, i);
+
/* 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);
{
struct intel_gmbus *bus = to_intel_gmbus(adapter);
- if (force_bit) {
- if (bus->force_bit == NULL) {
- bus->force_bit = intel_gpio_create(bus,
- bus->reg0 & 0xff);
- }
- } else {
- if (bus->force_bit) {
- bus->force_bit = NULL;
- }
- }
+ if (bus->has_gpio)
+ bus->force_bit = force_bit;
}
void intel_teardown_gmbus(struct drm_device *dev)