Commit 81a15b9a authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/mgag200: Embed connector instance in struct mga_device

Storing the connector instance in struct mga_device avoids some
dynamic memory allocation. On errors, the connector's initializer
function now destroys the i2c structure. Done in preparation of
converting mgag200 to simple-KMS helpers.

v2:
	* improved commit message (Michael)
	* fixed error message for mgag200_vga_connector_init() (Sam)
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarMichael J. Ruhl <michael.j.ruhl@intel.com>
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
Tested-by: default avatarJohn Donnelly <John.p.donnelly@oracle.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200507090315.21274-7-tzimmermann@suse.de
parent 30b0c940
...@@ -171,6 +171,7 @@ struct mga_device { ...@@ -171,6 +171,7 @@ struct mga_device {
/* SE model number stored in reg 0x1e24 */ /* SE model number stored in reg 0x1e24 */
u32 unique_rev_id; u32 unique_rev_id;
struct mga_connector connector;
struct drm_encoder encoder; struct drm_encoder encoder;
}; };
......
...@@ -1448,6 +1448,10 @@ static void mga_crtc_init(struct mga_device *mdev) ...@@ -1448,6 +1448,10 @@ static void mga_crtc_init(struct mga_device *mdev)
drm_crtc_helper_add(&mga_crtc->base, &mga_helper_funcs); drm_crtc_helper_add(&mga_crtc->base, &mga_helper_funcs);
} }
/*
* Connector
*/
static int mga_vga_get_modes(struct drm_connector *connector) static int mga_vga_get_modes(struct drm_connector *connector)
{ {
struct mga_connector *mga_connector = to_mga_connector(connector); struct mga_connector *mga_connector = to_mga_connector(connector);
...@@ -1572,7 +1576,6 @@ static void mga_connector_destroy(struct drm_connector *connector) ...@@ -1572,7 +1576,6 @@ static void mga_connector_destroy(struct drm_connector *connector)
struct mga_connector *mga_connector = to_mga_connector(connector); struct mga_connector *mga_connector = to_mga_connector(connector);
mgag200_i2c_destroy(mga_connector->i2c); mgag200_i2c_destroy(mga_connector->i2c);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
kfree(connector);
} }
static const struct drm_connector_helper_funcs mga_vga_connector_helper_funcs = { static const struct drm_connector_helper_funcs mga_vga_connector_helper_funcs = {
...@@ -1586,30 +1589,33 @@ static const struct drm_connector_funcs mga_vga_connector_funcs = { ...@@ -1586,30 +1589,33 @@ static const struct drm_connector_funcs mga_vga_connector_funcs = {
.destroy = mga_connector_destroy, .destroy = mga_connector_destroy,
}; };
static struct drm_connector *mga_vga_init(struct drm_device *dev) static int mgag200_vga_connector_init(struct mga_device *mdev)
{ {
struct drm_connector *connector; struct drm_device *dev = mdev->dev;
struct mga_connector *mga_connector; struct mga_connector *mconnector = &mdev->connector;
struct drm_connector *connector = &mconnector->base;
mga_connector = kzalloc(sizeof(struct mga_connector), GFP_KERNEL); struct mga_i2c_chan *i2c;
if (!mga_connector) int ret;
return NULL;
connector = &mga_connector->base;
mga_connector->i2c = mgag200_i2c_create(dev);
if (!mga_connector->i2c)
DRM_ERROR("failed to add ddc bus\n");
drm_connector_init_with_ddc(dev, connector, i2c = mgag200_i2c_create(dev);
&mga_vga_connector_funcs, if (!i2c)
DRM_MODE_CONNECTOR_VGA, drm_warn(dev, "failed to add DDC bus\n");
&mga_connector->i2c->adapter);
ret = drm_connector_init_with_ddc(dev, connector,
&mga_vga_connector_funcs,
DRM_MODE_CONNECTOR_VGA,
&i2c->adapter);
if (ret)
goto err_mgag200_i2c_destroy;
drm_connector_helper_add(connector, &mga_vga_connector_helper_funcs); drm_connector_helper_add(connector, &mga_vga_connector_helper_funcs);
drm_connector_register(connector); mconnector->i2c = i2c;
return connector; return 0;
err_mgag200_i2c_destroy:
mgag200_i2c_destroy(i2c);
return ret;
} }
static const struct drm_mode_config_funcs mgag200_mode_config_funcs = { static const struct drm_mode_config_funcs mgag200_mode_config_funcs = {
...@@ -1628,7 +1634,7 @@ int mgag200_modeset_init(struct mga_device *mdev) ...@@ -1628,7 +1634,7 @@ int mgag200_modeset_init(struct mga_device *mdev)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = mdev->dev;
struct drm_encoder *encoder = &mdev->encoder; struct drm_encoder *encoder = &mdev->encoder;
struct drm_connector *connector; struct drm_connector *connector = &mdev->connector.base;
int ret; int ret;
mdev->bpp_shifts[0] = 0; mdev->bpp_shifts[0] = 0;
...@@ -1664,10 +1670,12 @@ int mgag200_modeset_init(struct mga_device *mdev) ...@@ -1664,10 +1670,12 @@ int mgag200_modeset_init(struct mga_device *mdev)
} }
encoder->possible_crtcs = 0x1; encoder->possible_crtcs = 0x1;
connector = mga_vga_init(dev); ret = mgag200_vga_connector_init(mdev);
if (!connector) { if (ret) {
DRM_ERROR("mga_vga_init failed\n"); drm_err(dev,
return -1; "mgag200_vga_connector_init() failed, error %d\n",
ret);
return ret;
} }
drm_connector_attach_encoder(connector, encoder); drm_connector_attach_encoder(connector, encoder);
......
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