From patchwork Tue Sep 15 23:55:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Antognolli X-Patchwork-Id: 7189641 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0F8FA9F380 for ; Tue, 15 Sep 2015 23:54:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B7532073F for ; Tue, 15 Sep 2015 23:54:05 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 158CD2079C for ; Tue, 15 Sep 2015 23:54:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0891D6E4B7; Tue, 15 Sep 2015 16:54:03 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 74A366E445 for ; Tue, 15 Sep 2015 16:54:01 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 15 Sep 2015 16:54:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,537,1437462000"; d="scan'208";a="769823159" Received: from di-604.jf.intel.com (HELO apicaltest.jf.intel.com) ([10.7.199.92]) by orsmga001.jf.intel.com with ESMTP; 15 Sep 2015 16:54:01 -0700 From: Rafael Antognolli To: dri-devel@lists.freedesktop.org Subject: [PATCH RFC v2 1/3] drm/dp: Keep a list of drm_dp_aux helper. Date: Tue, 15 Sep 2015 16:55:02 -0700 Message-Id: <1442361304-16740-2-git-send-email-rafael.antognolli@intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442361304-16740-1-git-send-email-rafael.antognolli@intel.com> References: <1442361304-16740-1-git-send-email-rafael.antognolli@intel.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This list will be used to get the aux channels registered through the helpers. One function is provided to set a callback for added/removed aux channels, and another function to iterate over the list of aux channels. Signed-off-by: Rafael Antognolli --- drivers/gpu/drm/drm_dp_helper.c | 73 +++++++++++++++++++++++++++++++++++++++++ include/drm/drm_dp_helper.h | 5 +++ 2 files changed, 78 insertions(+) diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c index 9535c5b..41bdd93 100644 --- a/drivers/gpu/drm/drm_dp_helper.c +++ b/drivers/gpu/drm/drm_dp_helper.c @@ -746,6 +746,56 @@ static const struct i2c_algorithm drm_dp_i2c_algo = { .master_xfer = drm_dp_i2c_xfer, }; +struct drm_dp_aux_node { + struct klist_node list; + struct drm_dp_aux *aux; +}; + +static DEFINE_KLIST(drm_dp_aux_list, NULL, NULL); + +static int (*aux_dev_cb)(int action, struct drm_dp_aux *aux) = NULL; + +void drm_dp_aux_set_aux_dev(int (*fn)(int, struct drm_dp_aux *)) +{ + aux_dev_cb = fn; +} +EXPORT_SYMBOL(drm_dp_aux_set_aux_dev); + +static struct drm_dp_aux *next_aux(struct klist_iter *i) +{ + struct klist_node *n = klist_next(i); + struct drm_dp_aux *aux = NULL; + struct drm_dp_aux_node *aux_node; + + if (n) { + aux_node = container_of(n, struct drm_dp_aux_node, list); + aux = aux_node->aux; + } + return aux; +} + +int drm_dp_aux_for_each(void *data, int (*fn)(struct drm_dp_aux *, void *)) +{ + struct klist_iter i; + struct drm_dp_aux *aux; + int error = 0; + + klist_iter_init(&drm_dp_aux_list, &i); + while ((aux = next_aux(&i)) && !error) + error = fn(aux, data); + klist_iter_exit(&i); + return error; +} +EXPORT_SYMBOL(drm_dp_aux_for_each); + +static int drm_dp_aux_dev_inform(int action, struct drm_dp_aux *aux) +{ + if (aux_dev_cb) { + return aux_dev_cb(action, aux); + } + return 0; +} + /** * drm_dp_aux_register() - initialise and register aux channel * @aux: DisplayPort AUX channel @@ -754,6 +804,7 @@ static const struct i2c_algorithm drm_dp_i2c_algo = { */ int drm_dp_aux_register(struct drm_dp_aux *aux) { + struct drm_dp_aux_node *aux_node; mutex_init(&aux->hw_mutex); aux->ddc.algo = &drm_dp_i2c_algo; @@ -768,6 +819,14 @@ int drm_dp_aux_register(struct drm_dp_aux *aux) strlcpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), sizeof(aux->ddc.name)); + /* add aux to list and notify listeners */ + aux_node = kzalloc(sizeof(*aux_node), GFP_KERNEL); + if (!aux_node) + return -ENOMEM; + aux_node->aux = aux; + klist_add_tail(&aux_node->list, &drm_dp_aux_list); + drm_dp_aux_dev_inform(DRM_DP_ADD_AUX, aux); + return i2c_add_adapter(&aux->ddc); } EXPORT_SYMBOL(drm_dp_aux_register); @@ -778,6 +837,20 @@ EXPORT_SYMBOL(drm_dp_aux_register); */ void drm_dp_aux_unregister(struct drm_dp_aux *aux) { + struct klist_iter i; + struct klist_node *n; + + klist_iter_init(&drm_dp_aux_list, &i); + while ((n = klist_next(&i))) { + struct drm_dp_aux_node *aux_node = + container_of(n, struct drm_dp_aux_node, list); + if (aux_node->aux == aux) { + klist_del(n); + kfree(aux_node); + break; + } + } + drm_dp_aux_dev_inform(DRM_DP_DEL_AUX, aux); i2c_del_adapter(&aux->ddc); } EXPORT_SYMBOL(drm_dp_aux_unregister); diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index 9ec4716..f92de26 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -763,7 +763,12 @@ int drm_dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link); int drm_dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link); int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link); +#define DRM_DP_ADD_AUX 0x01 +#define DRM_DP_DEL_AUX 0x02 + int drm_dp_aux_register(struct drm_dp_aux *aux); void drm_dp_aux_unregister(struct drm_dp_aux *aux); +void drm_dp_aux_set_aux_dev(int (*fn)(int, struct drm_dp_aux *)); +int drm_dp_aux_for_each(void *data, int (*fn)(struct drm_dp_aux *, void *)); #endif /* _DRM_DP_HELPER_H_ */