Commit 5a6f98f5 authored by Alex Deucher's avatar Alex Deucher Committed by Dave Airlie

drm/radeon/kms: add radeon i2c algo

Currently just a wrapper around bit algo
Signed-off-by: default avatarAlex Deucher <alexdeucher@gmail.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 5ff55717
...@@ -2289,23 +2289,21 @@ void radeon_external_tmds_setup(struct drm_encoder *encoder) ...@@ -2289,23 +2289,21 @@ void radeon_external_tmds_setup(struct drm_encoder *encoder)
switch (tmds->dvo_chip) { switch (tmds->dvo_chip) {
case DVO_SIL164: case DVO_SIL164:
/* sil 164 */ /* sil 164 */
radeon_i2c_do_lock(tmds->i2c_bus, 1); radeon_i2c_put_byte(tmds->i2c_bus,
radeon_i2c_sw_put_byte(tmds->i2c_bus,
tmds->slave_addr, tmds->slave_addr,
0x08, 0x30); 0x08, 0x30);
radeon_i2c_sw_put_byte(tmds->i2c_bus, radeon_i2c_put_byte(tmds->i2c_bus,
tmds->slave_addr, tmds->slave_addr,
0x09, 0x00); 0x09, 0x00);
radeon_i2c_sw_put_byte(tmds->i2c_bus, radeon_i2c_put_byte(tmds->i2c_bus,
tmds->slave_addr, tmds->slave_addr,
0x0a, 0x90); 0x0a, 0x90);
radeon_i2c_sw_put_byte(tmds->i2c_bus, radeon_i2c_put_byte(tmds->i2c_bus,
tmds->slave_addr, tmds->slave_addr,
0x0c, 0x89); 0x0c, 0x89);
radeon_i2c_sw_put_byte(tmds->i2c_bus, radeon_i2c_put_byte(tmds->i2c_bus,
tmds->slave_addr, tmds->slave_addr,
0x08, 0x3b); 0x08, 0x3b);
radeon_i2c_do_lock(tmds->i2c_bus, 0);
break; break;
case DVO_SIL1178: case DVO_SIL1178:
/* sil 1178 - untested */ /* sil 1178 - untested */
...@@ -2390,11 +2388,9 @@ bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder) ...@@ -2390,11 +2388,9 @@ bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
index++; index++;
val = RBIOS8(index); val = RBIOS8(index);
index++; index++;
radeon_i2c_do_lock(tmds->i2c_bus, 1); radeon_i2c_put_byte(tmds->i2c_bus,
radeon_i2c_sw_put_byte(tmds->i2c_bus,
slave_addr, slave_addr,
reg, val); reg, val);
radeon_i2c_do_lock(tmds->i2c_bus, 0);
break; break;
default: default:
DRM_ERROR("Unknown id %d\n", id >> 13); DRM_ERROR("Unknown id %d\n", id >> 13);
...@@ -2447,11 +2443,9 @@ bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder) ...@@ -2447,11 +2443,9 @@ bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
reg = id & 0x1fff; reg = id & 0x1fff;
val = RBIOS8(index); val = RBIOS8(index);
index += 1; index += 1;
radeon_i2c_do_lock(tmds->i2c_bus, 1); radeon_i2c_put_byte(tmds->i2c_bus,
radeon_i2c_sw_put_byte(tmds->i2c_bus,
tmds->slave_addr, tmds->slave_addr,
reg, val); reg, val);
radeon_i2c_do_lock(tmds->i2c_bus, 0);
break; break;
default: default:
DRM_ERROR("Unknown id %d\n", id >> 13); DRM_ERROR("Unknown id %d\n", id >> 13);
......
...@@ -479,10 +479,8 @@ static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connec ...@@ -479,10 +479,8 @@ static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connec
ret = connector_status_connected; ret = connector_status_connected;
else { else {
if (radeon_connector->ddc_bus) { if (radeon_connector->ddc_bus) {
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
radeon_connector->edid = drm_get_edid(&radeon_connector->base, radeon_connector->edid = drm_get_edid(&radeon_connector->base,
&radeon_connector->ddc_bus->adapter); &radeon_connector->ddc_bus->adapter);
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
if (radeon_connector->edid) if (radeon_connector->edid)
ret = connector_status_connected; ret = connector_status_connected;
} }
...@@ -587,17 +585,13 @@ static enum drm_connector_status radeon_vga_detect(struct drm_connector *connect ...@@ -587,17 +585,13 @@ static enum drm_connector_status radeon_vga_detect(struct drm_connector *connect
if (!encoder) if (!encoder)
ret = connector_status_disconnected; ret = connector_status_disconnected;
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
dret = radeon_ddc_probe(radeon_connector); dret = radeon_ddc_probe(radeon_connector);
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
if (dret) { if (dret) {
if (radeon_connector->edid) { if (radeon_connector->edid) {
kfree(radeon_connector->edid); kfree(radeon_connector->edid);
radeon_connector->edid = NULL; radeon_connector->edid = NULL;
} }
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
if (!radeon_connector->edid) { if (!radeon_connector->edid) {
DRM_ERROR("%s: probed a monitor but no|invalid EDID\n", DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
...@@ -742,17 +736,13 @@ static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connect ...@@ -742,17 +736,13 @@ static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connect
enum drm_connector_status ret = connector_status_disconnected; enum drm_connector_status ret = connector_status_disconnected;
bool dret; bool dret;
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
dret = radeon_ddc_probe(radeon_connector); dret = radeon_ddc_probe(radeon_connector);
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
if (dret) { if (dret) {
if (radeon_connector->edid) { if (radeon_connector->edid) {
kfree(radeon_connector->edid); kfree(radeon_connector->edid);
radeon_connector->edid = NULL; radeon_connector->edid = NULL;
} }
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
if (!radeon_connector->edid) { if (!radeon_connector->edid) {
DRM_ERROR("%s: probed a monitor but no|invalid EDID\n", DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
...@@ -948,7 +938,7 @@ static void radeon_dp_connector_destroy(struct drm_connector *connector) ...@@ -948,7 +938,7 @@ static void radeon_dp_connector_destroy(struct drm_connector *connector)
if (radeon_connector->edid) if (radeon_connector->edid)
kfree(radeon_connector->edid); kfree(radeon_connector->edid);
if (radeon_dig_connector->dp_i2c_bus) if (radeon_dig_connector->dp_i2c_bus)
radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus); radeon_i2c_destroy_dp(radeon_dig_connector->dp_i2c_bus);
kfree(radeon_connector->con_priv); kfree(radeon_connector->con_priv);
drm_sysfs_connector_remove(connector); drm_sysfs_connector_remove(connector);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
...@@ -984,12 +974,10 @@ static enum drm_connector_status radeon_dp_detect(struct drm_connector *connecto ...@@ -984,12 +974,10 @@ static enum drm_connector_status radeon_dp_detect(struct drm_connector *connecto
ret = connector_status_connected; ret = connector_status_connected;
} }
} else { } else {
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
if (radeon_ddc_probe(radeon_connector)) { if (radeon_ddc_probe(radeon_connector)) {
radeon_dig_connector->dp_sink_type = sink_type; radeon_dig_connector->dp_sink_type = sink_type;
ret = connector_status_connected; ret = connector_status_connected;
} }
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
} }
return ret; return ret;
......
...@@ -364,9 +364,7 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector) ...@@ -364,9 +364,7 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
if (!radeon_connector->ddc_bus) if (!radeon_connector->ddc_bus)
return -1; return -1;
if (!radeon_connector->edid) { if (!radeon_connector->edid) {
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
} }
if (radeon_connector->edid) { if (radeon_connector->edid) {
...@@ -386,9 +384,7 @@ static int radeon_ddc_dump(struct drm_connector *connector) ...@@ -386,9 +384,7 @@ static int radeon_ddc_dump(struct drm_connector *connector)
if (!radeon_connector->ddc_bus) if (!radeon_connector->ddc_bus)
return -1; return -1;
radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter); edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter);
radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
if (edid) { if (edid) {
kfree(edid); kfree(edid);
} }
......
...@@ -59,7 +59,7 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector) ...@@ -59,7 +59,7 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector)
} }
void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state) static void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state)
{ {
struct radeon_device *rdev = i2c->dev->dev_private; struct radeon_device *rdev = i2c->dev->dev_private;
struct radeon_i2c_bus_rec *rec = &i2c->rec; struct radeon_i2c_bus_rec *rec = &i2c->rec;
...@@ -168,6 +168,32 @@ static void set_data(void *i2c_priv, int data) ...@@ -168,6 +168,32 @@ static void set_data(void *i2c_priv, int data)
WREG32(rec->en_data_reg, val); WREG32(rec->en_data_reg, val);
} }
static int radeon_i2c_xfer(struct i2c_adapter *i2c_adap,
struct i2c_msg *msgs, int num)
{
struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap);
int ret;
radeon_i2c_do_lock(i2c, 1);
if (i2c_transfer(&i2c->algo.radeon.bit_adapter, msgs, num) == num)
ret = num;
else
ret = -1;
radeon_i2c_do_lock(i2c, 0);
return ret;
}
static u32 radeon_i2c_func(struct i2c_adapter *adap)
{
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
}
static const struct i2c_algorithm radeon_i2c_algo = {
.master_xfer = radeon_i2c_xfer,
.functionality = radeon_i2c_func,
};
struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev, struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
struct radeon_i2c_bus_rec *rec, struct radeon_i2c_bus_rec *rec,
const char *name) const char *name)
...@@ -179,21 +205,34 @@ struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev, ...@@ -179,21 +205,34 @@ struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
if (i2c == NULL) if (i2c == NULL)
return NULL; return NULL;
i2c->adapter.owner = THIS_MODULE;
i2c->dev = dev; i2c->dev = dev;
i2c_set_adapdata(&i2c->adapter, i2c); i2c->rec = *rec;
i2c->adapter.algo_data = &i2c->algo.bit; /* set the internal bit adapter */
i2c->algo.bit.setsda = set_data; i2c->algo.radeon.bit_adapter.owner = THIS_MODULE;
i2c->algo.bit.setscl = set_clock; i2c_set_adapdata(&i2c->algo.radeon.bit_adapter, i2c);
i2c->algo.bit.getsda = get_data; sprintf(i2c->algo.radeon.bit_adapter.name, "Radeon internal i2c bit bus %s", name);
i2c->algo.bit.getscl = get_clock; i2c->algo.radeon.bit_adapter.algo_data = &i2c->algo.radeon.bit_data;
i2c->algo.bit.udelay = 20; i2c->algo.radeon.bit_data.setsda = set_data;
i2c->algo.radeon.bit_data.setscl = set_clock;
i2c->algo.radeon.bit_data.getsda = get_data;
i2c->algo.radeon.bit_data.getscl = get_clock;
i2c->algo.radeon.bit_data.udelay = 20;
/* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always
* make this, 2 jiffies is a lot more reliable */ * make this, 2 jiffies is a lot more reliable */
i2c->algo.bit.timeout = 2; i2c->algo.radeon.bit_data.timeout = 2;
i2c->algo.bit.data = i2c; i2c->algo.radeon.bit_data.data = i2c;
i2c->rec = *rec; ret = i2c_bit_add_bus(&i2c->algo.radeon.bit_adapter);
ret = i2c_bit_add_bus(&i2c->adapter); if (ret) {
DRM_INFO("Failed to register internal bit i2c %s\n", name);
goto out_free;
}
/* set the radeon i2c adapter */
i2c->adapter.owner = THIS_MODULE;
i2c_set_adapdata(&i2c->adapter, i2c);
sprintf(i2c->adapter.name, "Radeon i2c %s", name);
i2c->adapter.algo_data = &i2c->algo.radeon;
i2c->adapter.algo = &radeon_i2c_algo;
ret = i2c_add_adapter(&i2c->adapter);
if (ret) { if (ret) {
DRM_INFO("Failed to register i2c %s\n", name); DRM_INFO("Failed to register i2c %s\n", name);
goto out_free; goto out_free;
...@@ -237,8 +276,16 @@ struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev, ...@@ -237,8 +276,16 @@ struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
} }
void radeon_i2c_destroy(struct radeon_i2c_chan *i2c) void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
{
if (!i2c)
return;
i2c_del_adapter(&i2c->algo.radeon.bit_adapter);
i2c_del_adapter(&i2c->adapter);
kfree(i2c);
}
void radeon_i2c_destroy_dp(struct radeon_i2c_chan *i2c)
{ {
if (!i2c) if (!i2c)
return; return;
...@@ -252,7 +299,7 @@ struct drm_encoder *radeon_best_encoder(struct drm_connector *connector) ...@@ -252,7 +299,7 @@ struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)
return NULL; return NULL;
} }
void radeon_i2c_sw_get_byte(struct radeon_i2c_chan *i2c_bus, void radeon_i2c_get_byte(struct radeon_i2c_chan *i2c_bus,
u8 slave_addr, u8 slave_addr,
u8 addr, u8 addr,
u8 *val) u8 *val)
...@@ -286,7 +333,7 @@ void radeon_i2c_sw_get_byte(struct radeon_i2c_chan *i2c_bus, ...@@ -286,7 +333,7 @@ void radeon_i2c_sw_get_byte(struct radeon_i2c_chan *i2c_bus,
} }
} }
void radeon_i2c_sw_put_byte(struct radeon_i2c_chan *i2c_bus, void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c_bus,
u8 slave_addr, u8 slave_addr,
u8 addr, u8 addr,
u8 val) u8 val)
......
...@@ -159,12 +159,17 @@ struct radeon_pll { ...@@ -159,12 +159,17 @@ struct radeon_pll {
uint32_t id; uint32_t id;
}; };
struct i2c_algo_radeon_data {
struct i2c_adapter bit_adapter;
struct i2c_algo_bit_data bit_data;
};
struct radeon_i2c_chan { struct radeon_i2c_chan {
struct i2c_adapter adapter; struct i2c_adapter adapter;
struct drm_device *dev; struct drm_device *dev;
union { union {
struct i2c_algo_dp_aux_data dp; struct i2c_algo_dp_aux_data dp;
struct i2c_algo_bit_data bit; struct i2c_algo_radeon_data radeon;
} algo; } algo;
struct radeon_i2c_bus_rec rec; struct radeon_i2c_bus_rec rec;
}; };
...@@ -411,11 +416,12 @@ extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev, ...@@ -411,11 +416,12 @@ extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
struct radeon_i2c_bus_rec *rec, struct radeon_i2c_bus_rec *rec,
const char *name); const char *name);
extern void radeon_i2c_destroy(struct radeon_i2c_chan *i2c); extern void radeon_i2c_destroy(struct radeon_i2c_chan *i2c);
extern void radeon_i2c_sw_get_byte(struct radeon_i2c_chan *i2c_bus, extern void radeon_i2c_destroy_dp(struct radeon_i2c_chan *i2c);
extern void radeon_i2c_get_byte(struct radeon_i2c_chan *i2c_bus,
u8 slave_addr, u8 slave_addr,
u8 addr, u8 addr,
u8 *val); u8 *val);
extern void radeon_i2c_sw_put_byte(struct radeon_i2c_chan *i2c, extern void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c,
u8 slave_addr, u8 slave_addr,
u8 addr, u8 addr,
u8 val); u8 val);
...@@ -531,7 +537,6 @@ void radeon_atombios_init_crtc(struct drm_device *dev, ...@@ -531,7 +537,6 @@ void radeon_atombios_init_crtc(struct drm_device *dev,
struct radeon_crtc *radeon_crtc); struct radeon_crtc *radeon_crtc);
void radeon_legacy_init_crtc(struct drm_device *dev, void radeon_legacy_init_crtc(struct drm_device *dev,
struct radeon_crtc *radeon_crtc); struct radeon_crtc *radeon_crtc);
extern void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state);
void radeon_get_clock_info(struct drm_device *dev); void radeon_get_clock_info(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