29 #include <linux/i2c.h>
31 #include <linux/export.h>
34 #include <drm/i915_drm.h>
42 static const struct gmbus_port gmbus_ports[] = {
53 #define I2C_RISEFALL_TIME 10
103 u32 reserved = get_reserved(bus);
109 static int get_data(
void *data)
113 u32 reserved = get_reserved(bus);
119 static void set_clock(
void *data,
int state_high)
123 u32 reserved = get_reserved(bus);
136 static void set_data(
void *data,
int state_high)
140 u32 reserved = get_reserved(bus);
162 intel_i2c_quirk_set(dev_priv,
true);
179 intel_i2c_quirk_set(dev_priv,
false);
198 algo->
pre_xfer = intel_gpio_pre_xfer;
236 }
while (--len && ++loop < 4);
251 while (len && loop < 4) {
252 val |= *buf++ << (8 * loop++);
268 val |= *buf++ << (8 * loop);
269 }
while (--len && ++loop < 4);
289 gmbus_is_index_read(
struct i2c_msg *msgs,
int i,
int num)
291 return (i + 1 < num &&
293 (msgs[i + 1].
flags & I2C_M_RD));
300 u32 gmbus1_index = 0;
304 if (msgs[0].len == 2)
306 msgs[0].
buf[1] | (msgs[0].
buf[0] << 8);
307 if (msgs[0].len == 1)
315 ret = gmbus_xfer_read(dev_priv, &msgs[1], gmbus1_index);
347 for (i = 0; i < num; i++) {
350 if (gmbus_is_index_read(msgs, i, num)) {
351 ret = gmbus_xfer_index_read(dev_priv, &msgs[i]);
353 }
else if (msgs[i].
flags & I2C_M_RD) {
354 ret = gmbus_xfer_read(dev_priv, &msgs[i], 0);
356 ret = gmbus_xfer_write(dev_priv, &msgs[i]);
385 DRM_DEBUG_KMS(
"GMBUS [%s] timed out waiting for idle\n",
410 DRM_DEBUG_KMS(
"GMBUS [%s] timed out after NAK\n",
423 DRM_DEBUG_KMS(
"GMBUS [%s] NAK for addr: %04x %c(%d)\n",
425 (msgs[i].
flags & I2C_M_RD) ?
'r' :
'w', msgs[i].
len);
430 DRM_INFO(
"GMBUS [%s] timed out, falling back to bit banging on pin %d\n",
453 .master_xfer = gmbus_xfer,
454 .functionality = gmbus_func
482 gmbus_ports[i].
name);
484 bus->
adapter.dev.parent = &dev->pdev->dev;
487 bus->
adapter.algo = &gmbus_algorithm;
496 intel_gpio_setup(bus, port);
521 &dev_priv->
gmbus[port - 1].adapter :
NULL;
528 bus->
reg0 = (bus->
reg0 & ~(0x3 << 8)) | speed;