aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/intel_i2c.c
diff options
context:
space:
mode:
authorDaniel Kurtz <djkurtz@chromium.org>2012-03-27 14:36:13 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2012-03-28 03:45:52 -0400
commit489fbc107f5fb041d598f30f367ea3ca714ff133 (patch)
treeb365944f499a729f28441e99ba797d7bdcbaf230 /drivers/gpu/drm/i915/intel_i2c.c
parente4fd17af6156b46fae3f9115830e1a35a62cd8e7 (diff)
drm/i915/intel_i2c: use i2c pre/post_xfer functions to setup gpio xfers
Instead of rolling our own custom quirk_xfer function, use the bit_algo pre_xfer and post_xfer functions to setup and teardown bit-banged i2c transactions. Signed-off-by: Daniel Kurtz <djkurtz@chromium.org> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/gpu/drm/i915/intel_i2c.c')
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index 9347281633f5..1bb63624a793 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -137,6 +137,35 @@ static void set_data(void *data, int state_high)
137 POSTING_READ(bus->gpio_reg); 137 POSTING_READ(bus->gpio_reg);
138} 138}
139 139
140static int
141intel_gpio_pre_xfer(struct i2c_adapter *adapter)
142{
143 struct intel_gmbus *bus = container_of(adapter,
144 struct intel_gmbus,
145 adapter);
146 struct drm_i915_private *dev_priv = bus->dev_priv;
147
148 intel_i2c_reset(dev_priv->dev);
149 intel_i2c_quirk_set(dev_priv, true);
150 set_data(bus, 1);
151 set_clock(bus, 1);
152 udelay(I2C_RISEFALL_TIME);
153 return 0;
154}
155
156static void
157intel_gpio_post_xfer(struct i2c_adapter *adapter)
158{
159 struct intel_gmbus *bus = container_of(adapter,
160 struct intel_gmbus,
161 adapter);
162 struct drm_i915_private *dev_priv = bus->dev_priv;
163
164 set_data(bus, 1);
165 set_clock(bus, 1);
166 intel_i2c_quirk_set(dev_priv, false);
167}
168
140static bool 169static bool
141intel_gpio_setup(struct intel_gmbus *bus, u32 pin) 170intel_gpio_setup(struct intel_gmbus *bus, u32 pin)
142{ 171{
@@ -166,6 +195,8 @@ intel_gpio_setup(struct intel_gmbus *bus, u32 pin)
166 algo->setscl = set_clock; 195 algo->setscl = set_clock;
167 algo->getsda = get_data; 196 algo->getsda = get_data;
168 algo->getscl = get_clock; 197 algo->getscl = get_clock;
198 algo->pre_xfer = intel_gpio_pre_xfer;
199 algo->post_xfer = intel_gpio_post_xfer;
169 algo->udelay = I2C_RISEFALL_TIME; 200 algo->udelay = I2C_RISEFALL_TIME;
170 algo->timeout = usecs_to_jiffies(2200); 201 algo->timeout = usecs_to_jiffies(2200);
171 algo->data = bus; 202 algo->data = bus;
@@ -174,30 +205,6 @@ intel_gpio_setup(struct intel_gmbus *bus, u32 pin)
174} 205}
175 206
176static int 207static int
177intel_i2c_quirk_xfer(struct intel_gmbus *bus,
178 struct i2c_msg *msgs,
179 int num)
180{
181 struct drm_i915_private *dev_priv = bus->dev_priv;
182 int ret;
183
184 intel_i2c_reset(dev_priv->dev);
185
186 intel_i2c_quirk_set(dev_priv, true);
187 set_data(bus, 1);
188 set_clock(bus, 1);
189 udelay(I2C_RISEFALL_TIME);
190
191 ret = i2c_bit_algo.master_xfer(&bus->adapter, msgs, num);
192
193 set_data(bus, 1);
194 set_clock(bus, 1);
195 intel_i2c_quirk_set(dev_priv, false);
196
197 return ret;
198}
199
200static int
201gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg, 208gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg,
202 bool last) 209 bool last)
203{ 210{
@@ -287,7 +294,7 @@ gmbus_xfer(struct i2c_adapter *adapter,
287 mutex_lock(&dev_priv->gmbus_mutex); 294 mutex_lock(&dev_priv->gmbus_mutex);
288 295
289 if (bus->force_bit) { 296 if (bus->force_bit) {
290 ret = intel_i2c_quirk_xfer(bus, msgs, num); 297 ret = i2c_bit_algo.master_xfer(adapter, msgs, num);
291 goto out; 298 goto out;
292 } 299 }
293 300
@@ -351,8 +358,9 @@ timeout:
351 ret = -EIO; 358 ret = -EIO;
352 } else { 359 } else {
353 bus->force_bit = true; 360 bus->force_bit = true;
354 ret = intel_i2c_quirk_xfer(bus, msgs, num); 361 ret = i2c_bit_algo.master_xfer(adapter, msgs, num);
355 } 362 }
363
356out: 364out:
357 mutex_unlock(&dev_priv->gmbus_mutex); 365 mutex_unlock(&dev_priv->gmbus_mutex);
358 return ret; 366 return ret;