From: Maarten Maathuis Subject: Re: [PATCH] drm: Add a generic function to change connector type/id of connector dynamically Date: Wed, 27 Jan 2010 10:07:47 +0100 Message-ID: <6d4bc9fc1001270107k13fcf021v79912f2a3212be4e@mail.gmail.com> References: <1264576567-11236-1-git-send-email-yakui.zhao@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <1264576567-11236-1-git-send-email-yakui.zhao@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.sourceforge.net To: yakui.zhao@intel.com Cc: airlied@redhat.com, intel-gfx@lists.freedesktop.org, dri-devel@lists.sourceforge.net List-Id: dri-devel@lists.freedesktop.org On Wed, Jan 27, 2010 at 8:16 AM, wrote: > From: Zhao Yakui > > Sometimes one connector can support more than one connector type. And it > will switch the connector type/id dynamically according to the external > connected device. I very much doubt it's the connector that is physically changing. It's a plug, a piece of metal with connection points/wires. What you want is multiple connectors with the same encoder, to accurately reflect what is happening. > > Add a generic function to change connector type/id of the connector > dynamically. > > Signed-off-by: Zhao Yakui > --- > One multi-function SDVO card device can support SDVO-VGA/SDVO-TV(S-Video/ > Composite). We should give them the correct connector type according > to the external connected device. For example: VGA/TV. The connector id > should be re-initialized when connector type is changed. Otherwise we will > get one conflict connector id. > > One list is added to save the connector type/id that is already used by t= he > connector. If the target type is already in the list, we can change the > connector type/ide directly by using the saved result. > If the new connector type is not in the list, we will dynamically > allocate the connector id for it and then save the connector type/id to t= he > list. > > =A0drivers/gpu/drm/drm_crtc.c | =A0 81 ++++++++++++++++++++++++++++++++++= ++++++++++ > =A0include/drm/drm_crtc.h =A0 =A0 | =A0 =A05 +++ > =A02 files changed, 86 insertions(+), 0 deletions(-) > > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c > index 5124401..a64e389 100644 > --- a/drivers/gpu/drm/drm_crtc.c > +++ b/drivers/gpu/drm/drm_crtc.c > @@ -39,6 +39,11 @@ struct drm_prop_enum_list { > =A0 =A0 =A0 =A0char *name; > =A0}; > > +struct connector_type_id { > + =A0 =A0 =A0 struct list_head head; > + =A0 =A0 =A0 int connector_type; > + =A0 =A0 =A0 int connector_id; > +}; > =A0/* Avoid boilerplate. =A0I'm tired of typing. */ > =A0#define DRM_ENUM_NAME_FN(fnname, list) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 \ > =A0 =A0 =A0 =A0char *fnname(int val) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ > @@ -443,6 +448,13 @@ void drm_connector_init(struct drm_device *dev, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct drm_connector_funcs = *funcs, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int connector_type) > =A0{ > + =A0 =A0 =A0 struct connector_type_id *p_type_id =3D NULL; > + > + =A0 =A0 =A0 p_type_id =3D kzalloc(sizeof(*p_type_id), GFP_KERNEL); > + > + =A0 =A0 =A0 if (!p_type_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 DRM_DEBUG_KMS("Can't allocate the memory\n"= ); > + > =A0 =A0 =A0 =A0mutex_lock(&dev->mode_config.mutex); > > =A0 =A0 =A0 =A0connector->dev =3D dev; > @@ -465,11 +477,73 @@ void drm_connector_init(struct drm_device *dev, > =A0 =A0 =A0 =A0drm_connector_attach_property(connector, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0dev->mode_config.dpms_property, 0); > > + =A0 =A0 =A0 INIT_LIST_HEAD(&connector->connector_type_list); > + =A0 =A0 =A0 if (p_type_id) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 p_type_id->connector_type =3D connector_typ= e; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 p_type_id->connector_id =3D connector->conn= ector_type_id; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 list_add_tail(&p_type_id->head, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 &connector->connector_type_list); > + =A0 =A0 =A0 } > =A0 =A0 =A0 =A0mutex_unlock(&dev->mode_config.mutex); > =A0} > =A0EXPORT_SYMBOL(drm_connector_init); > > =A0/** > + * drm_rename_connector_type - Rename the connector type for one connect= or > + * @connector: the connector to be named > + * @target_type: the renamed target connector type > + * > + * Rename the connector type for one connector. Sometimes we will > + * need get a new connector type id. > + * > + * RETURNS: > + * Zero on success, errno on failure. > + */ > + > +int drm_rename_connector_type(struct drm_connector *connector, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int target_type) > +{ > + =A0 =A0 =A0 struct connector_type_id *type_id, *temp; > + =A0 =A0 =A0 int connector_id, found =3D 0; > + =A0 =A0 =A0 struct drm_device *dev =3D connector->dev; > + > + =A0 =A0 =A0 if (connector->connector_type =3D=3D target_type) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0; > + > + =A0 =A0 =A0 list_for_each_entry_safe(type_id, temp, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &connector->connector_type_= list, head) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (type_id->connector_type =3D=3D target_t= ype) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 connector_id =3D type_id->c= onnector_id; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 found =3D 1; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 } > + =A0 =A0 =A0 if (found) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 connector->connector_type =3D target_type; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 connector->connector_type_id =3D connector_= id; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 type_id =3D kzalloc(sizeof(*type_id), GFP_KERNEL); > + > + =A0 =A0 =A0 if (!type_id) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 DRM_DEBUG_KMS("Can't allocate the memory\n"= ); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 connector->connector_type =3D target_type; > + =A0 =A0 =A0 connector->connector_type_id =3D > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ++drm_connector_enum_list[target_type].coun= t; > + > + =A0 =A0 =A0 type_id->connector_type =3D target_type; > + =A0 =A0 =A0 type_id->connector_id =3D connector->connector_type_id; > + =A0 =A0 =A0 list_add_tail(&type_id->head, &connector->connector_type_li= st); > + > + =A0 =A0 =A0 return 0; > +} > +EXPORT_SYMBOL(drm_rename_connector_type); > + > +/** > =A0* drm_connector_cleanup - cleans up an initialised connector > =A0* @connector: connector to cleanup > =A0* > @@ -482,6 +556,7 @@ void drm_connector_cleanup(struct drm_connector *conn= ector) > =A0{ > =A0 =A0 =A0 =A0struct drm_device *dev =3D connector->dev; > =A0 =A0 =A0 =A0struct drm_display_mode *mode, *t; > + =A0 =A0 =A0 struct connector_type_id *type_id, *temp; > > =A0 =A0 =A0 =A0list_for_each_entry_safe(mode, t, &connector->probed_modes= , head) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0drm_mode_remove(connector, mode); > @@ -492,6 +567,12 @@ void drm_connector_cleanup(struct drm_connector *con= nector) > =A0 =A0 =A0 =A0list_for_each_entry_safe(mode, t, &connector->user_modes, = head) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0drm_mode_remove(connector, mode); > > + =A0 =A0 =A0 list_for_each_entry_safe(type_id, temp, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &connector->connector_type_= list, head) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 list_del(&type_id->head); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 kfree(type_id); > + =A0 =A0 =A0 } > + > =A0 =A0 =A0 =A0kfree(connector->fb_helper_private); > =A0 =A0 =A0 =A0mutex_lock(&dev->mode_config.mutex); > =A0 =A0 =A0 =A0drm_mode_object_put(dev, &connector->base); > diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h > index fdf43ab..3862e32 100644 > --- a/include/drm/drm_crtc.h > +++ b/include/drm/drm_crtc.h > @@ -521,6 +521,8 @@ struct drm_connector { > =A0 =A0 =A0 =A0uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER]; > =A0 =A0 =A0 =A0uint32_t force_encoder_id; > =A0 =A0 =A0 =A0struct drm_encoder *encoder; /* currently active encoder */ > + =A0 =A0 =A0 /* the list of possible connector type/id for this connecto= r */ > + =A0 =A0 =A0 struct list_head connector_type_list; > =A0 =A0 =A0 =A0void *fb_helper_private; > =A0}; > > @@ -647,6 +649,9 @@ extern void drm_connector_init(struct drm_device *dev, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const struct drm_c= onnector_funcs *funcs, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int connector_type= ); > > +extern int drm_rename_connector_type(struct drm_connector *connector, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int target_type); > + > =A0extern void drm_connector_cleanup(struct drm_connector *connector); > > =A0extern void drm_encoder_init(struct drm_device *dev, > -- > 1.5.4.5 > > > -------------------------------------------------------------------------= ----- > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the busi= ness > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > -- > _______________________________________________ > Dri-devel mailing list > Dri-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/dri-devel > ---------------------------------------------------------------------------= --- The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the busine= ss Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com --