提交 c020c9a8 编写于 作者: B Ben Skeggs

drm/nv50: use custom i2c algo for dp auxch

This makes it easier to see how this is working, and lets us transfer the
EDID in blocks of 16 bytes.

The primary reason for this change is because debug logs are rather hard
to read with the hundreds of single-byte auxch transactions that occur.
Signed-off-by: NBen Skeggs <bskeggs@redhat.com>
上级 96576a9e
...@@ -572,47 +572,64 @@ nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr, ...@@ -572,47 +572,64 @@ nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr,
return ret ? ret : (stat & NV50_AUXCH_STAT_REPLY); return ret ? ret : (stat & NV50_AUXCH_STAT_REPLY);
} }
int static int
nouveau_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
uint8_t write_byte, uint8_t *read_byte)
{ {
struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adap;
struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adapter;
struct drm_device *dev = auxch->dev; struct drm_device *dev = auxch->dev;
int ret = 0, cmd, addr = algo_data->address; struct i2c_msg *msg = msgs;
uint8_t *buf; int ret, mcnt = num;
while (mcnt--) {
u8 remaining = msg->len;
u8 *ptr = msg->buf;
if (mode == MODE_I2C_READ) { while (remaining) {
u8 cnt = (remaining > 16) ? 16 : remaining;
u8 cmd;
if (msg->flags & I2C_M_RD)
cmd = AUX_I2C_READ; cmd = AUX_I2C_READ;
buf = read_byte; else
} else { cmd = AUX_I2C_WRITE;
cmd = (mode & MODE_I2C_READ) ? AUX_I2C_READ : AUX_I2C_WRITE;
buf = &write_byte;
}
if (!(mode & MODE_I2C_STOP)) if (mcnt || remaining > 16)
cmd |= AUX_I2C_MOT; cmd |= AUX_I2C_MOT;
if (mode & MODE_I2C_START) ret = nouveau_dp_auxch(auxch, cmd, msg->addr, ptr, cnt);
return 1;
for (;;) {
ret = nouveau_dp_auxch(auxch, cmd, addr, buf, 1);
if (ret < 0) if (ret < 0)
return ret; return ret;
switch (ret & NV50_AUXCH_STAT_REPLY_I2C) { switch (ret & NV50_AUXCH_STAT_REPLY_I2C) {
case NV50_AUXCH_STAT_REPLY_I2C_ACK: case NV50_AUXCH_STAT_REPLY_I2C_ACK:
return 1; break;
case NV50_AUXCH_STAT_REPLY_I2C_NACK: case NV50_AUXCH_STAT_REPLY_I2C_NACK:
return -EREMOTEIO; return -EREMOTEIO;
case NV50_AUXCH_STAT_REPLY_I2C_DEFER: case NV50_AUXCH_STAT_REPLY_I2C_DEFER:
udelay(100); udelay(100);
break; continue;
default: default:
NV_ERROR(dev, "invalid auxch status: 0x%08x\n", ret); NV_ERROR(dev, "bad auxch reply: 0x%08x\n", ret);
return -EREMOTEIO; return -EREMOTEIO;
} }
ptr += cnt;
remaining -= cnt;
}
msg++;
} }
return num;
}
static u32
nouveau_dp_i2c_func(struct i2c_adapter *adap)
{
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
} }
const struct i2c_algorithm nouveau_dp_i2c_algo = {
.master_xfer = nouveau_dp_i2c_xfer,
.functionality = nouveau_dp_i2c_func
};
...@@ -174,26 +174,26 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index) ...@@ -174,26 +174,26 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
switch (entry->port_type) { switch (entry->port_type) {
case 0: case 0:
i2c->algo.bit.setsda = nv04_i2c_setsda; i2c->bit.setsda = nv04_i2c_setsda;
i2c->algo.bit.setscl = nv04_i2c_setscl; i2c->bit.setscl = nv04_i2c_setscl;
i2c->algo.bit.getsda = nv04_i2c_getsda; i2c->bit.getsda = nv04_i2c_getsda;
i2c->algo.bit.getscl = nv04_i2c_getscl; i2c->bit.getscl = nv04_i2c_getscl;
i2c->rd = entry->read; i2c->rd = entry->read;
i2c->wr = entry->write; i2c->wr = entry->write;
break; break;
case 4: case 4:
i2c->algo.bit.setsda = nv4e_i2c_setsda; i2c->bit.setsda = nv4e_i2c_setsda;
i2c->algo.bit.setscl = nv4e_i2c_setscl; i2c->bit.setscl = nv4e_i2c_setscl;
i2c->algo.bit.getsda = nv4e_i2c_getsda; i2c->bit.getsda = nv4e_i2c_getsda;
i2c->algo.bit.getscl = nv4e_i2c_getscl; i2c->bit.getscl = nv4e_i2c_getscl;
i2c->rd = 0x600800 + entry->read; i2c->rd = 0x600800 + entry->read;
i2c->wr = 0x600800 + entry->write; i2c->wr = 0x600800 + entry->write;
break; break;
case 5: case 5:
i2c->algo.bit.setsda = nv50_i2c_setsda; i2c->bit.setsda = nv50_i2c_setsda;
i2c->algo.bit.setscl = nv50_i2c_setscl; i2c->bit.setscl = nv50_i2c_setscl;
i2c->algo.bit.getsda = nv50_i2c_getsda; i2c->bit.getsda = nv50_i2c_getsda;
i2c->algo.bit.getscl = nv50_i2c_getscl; i2c->bit.getscl = nv50_i2c_getscl;
i2c->rd = nv50_i2c_port[entry->read]; i2c->rd = nv50_i2c_port[entry->read];
i2c->wr = i2c->rd; i2c->wr = i2c->rd;
break; break;
...@@ -216,17 +216,14 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index) ...@@ -216,17 +216,14 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
i2c_set_adapdata(&i2c->adapter, i2c); i2c_set_adapdata(&i2c->adapter, i2c);
if (entry->port_type < 6) { if (entry->port_type < 6) {
i2c->adapter.algo_data = &i2c->algo.bit; i2c->adapter.algo_data = &i2c->bit;
i2c->algo.bit.udelay = 40; i2c->bit.udelay = 40;
i2c->algo.bit.timeout = usecs_to_jiffies(5000); i2c->bit.timeout = usecs_to_jiffies(5000);
i2c->algo.bit.data = i2c; i2c->bit.data = i2c;
ret = i2c_bit_add_bus(&i2c->adapter); ret = i2c_bit_add_bus(&i2c->adapter);
} else { } else {
i2c->adapter.algo_data = &i2c->algo.dp; i2c->adapter.algo = &nouveau_dp_i2c_algo;
i2c->algo.dp.running = false; ret = i2c_add_adapter(&i2c->adapter);
i2c->algo.dp.address = 0;
i2c->algo.dp.aux_ch = nouveau_dp_i2c_aux_ch;
ret = i2c_dp_aux_add_bus(&i2c->adapter);
} }
if (ret) { if (ret) {
......
...@@ -33,10 +33,7 @@ struct dcb_i2c_entry; ...@@ -33,10 +33,7 @@ struct dcb_i2c_entry;
struct nouveau_i2c_chan { struct nouveau_i2c_chan {
struct i2c_adapter adapter; struct i2c_adapter adapter;
struct drm_device *dev; struct drm_device *dev;
union {
struct i2c_algo_bit_data bit; struct i2c_algo_bit_data bit;
struct i2c_algo_dp_aux_data dp;
} algo;
unsigned rd; unsigned rd;
unsigned wr; unsigned wr;
unsigned data; unsigned data;
...@@ -49,7 +46,6 @@ bool nouveau_probe_i2c_addr(struct nouveau_i2c_chan *i2c, int addr); ...@@ -49,7 +46,6 @@ bool nouveau_probe_i2c_addr(struct nouveau_i2c_chan *i2c, int addr);
int nouveau_i2c_identify(struct drm_device *dev, const char *what, int nouveau_i2c_identify(struct drm_device *dev, const char *what,
struct i2c_board_info *info, int index); struct i2c_board_info *info, int index);
int nouveau_dp_i2c_aux_ch(struct i2c_adapter *, int mode, uint8_t write_byte, extern const struct i2c_algorithm nouveau_dp_i2c_algo;
uint8_t *read_byte);
#endif /* __NOUVEAU_I2C_H__ */ #endif /* __NOUVEAU_I2C_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册