Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3329080ybh; Mon, 5 Aug 2019 16:36:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzv4fyN7mPU6b4wA8+hSIjNI4gkCkvgwJ0e8uAS55UGTm4hox6JOp0URpJRLlZW+HNtyR9p X-Received: by 2002:a17:902:bcc4:: with SMTP id o4mr276332pls.90.1565048175095; Mon, 05 Aug 2019 16:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565048175; cv=none; d=google.com; s=arc-20160816; b=w0w96fmVpAI8lYxm8EhfdyknDUQ3Q6fRq6eKeD2sLEQC6ChpqFM4ZNxviNjkoVMrP/ CEVhmlSf32emchDHRc7luKvzSq1IycsQIGFPCBi6GZtItXiBPC+lKtSLPRPBn0hHb8WO Yb0rXTXLlt6eAJ4nL13rRNeiuATjLrqgBqfLePv1MV3EnuDxeqHC9pmNHTBbPb78imQ4 vnK4ucZqOltpgfgB0KY4B+l/Qxczytca1e7jqn7nAgrzLvuLfu1DecgGAsaGZ74CkJTc Z8Uw2e153n+/Rhkx2V/1dv6Z1zFAzeotIPlwXY4rI2BFzPdI5uvGmspYsuQAirQHEcDG Zq3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=u/PbVO0GF+3G1LmQDJT1XFH8AmJHxoqEkGwCBY/zSdU=; b=TeU7JtwRVt9Ph1IxooEsmpJLc9Yz81BI1ai4mEY/WPxyum9rEC59bEtkVzfY90Sxql Cpcni2OkXm7kzUTu48ZW/8sdLk8gP0aToaqMxbckaR5dYW44SH4OZM9g0ByuN9q8ShDn 9BNwFyWWuk69GCLvoJsI+O94XSYSHlGtDiqUi31CuwrqvT12e4Ni6hMINuHerEhVBTmz R1MDC9wd69GRBQdSg3Nuup/jmvhKe9Q7VmgkL6vDGBtNY7OmuP/kAcK/1zEfVyim33HG sZltba+6oWWbpsYbwO8SF2HL5cabSeWKFhKF7Xp/FhMuXzQHmVGKNG8qrUeur98vhYQ7 8lbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Rmd3ZzYT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k21si41595083pls.202.2019.08.05.16.35.58; Mon, 05 Aug 2019 16:36:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Rmd3ZzYT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731068AbfHEXfR (ORCPT + 99 others); Mon, 5 Aug 2019 19:35:17 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34406 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728483AbfHEXfO (ORCPT ); Mon, 5 Aug 2019 19:35:14 -0400 Received: by mail-pf1-f195.google.com with SMTP id b13so40420175pfo.1; Mon, 05 Aug 2019 16:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u/PbVO0GF+3G1LmQDJT1XFH8AmJHxoqEkGwCBY/zSdU=; b=Rmd3ZzYTRxOqchGIwYWUUpvkDRr5s2EsB6qEHX67RjuuYAkgUxfHqcpfewJ5S5O4eQ k8DQmrLg75em+CJxBjHeBnEeALQ5SigD8WnXOQLEPs//SPHJw5zl76YW7Fl4K7L51ozW 3l4On5GCQL+29WIbp9xAsazY3623XLv/FjDk+dCHNz1vDewNvawXYzg2cZptdCMhJqwd yeOec5NwL44JOspgc8abBqdBwLYIFd+xlv86dmjRUv4eUOzCQfiBzI5jPsKkPbbNRG+W o1DPw3xYd9+iPnyLnHhJmlOa01gNx2Vs4CoeFGyNlf36x8qz0EbATkdgj+B28034OWJ8 wyCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u/PbVO0GF+3G1LmQDJT1XFH8AmJHxoqEkGwCBY/zSdU=; b=ENI+HzFyvCJArc9TJw3EMspfNdbLiLf6uObnMnYxOGskSODjEjy3VYaDE25VRPauMp Nw/h2OgFWmdBXwh/ukQ9nKqHUZ4aC8Af9TDxS1s5Kpc6wi5GbAk+ODvYcszcMwFmDaOr lP5ZpGPYQbBCURucdSr0TgJpaJxjT6g0h3ehaUJQZvSSuRmTJUTUenujvI1l9iJ+wYWe K/KzMZoi3UBue4ipihjWMZL3SFhXY+Xag+JMBPntEhv3L1R5hfX7A2/+Lnq7MWBvr+Oo 5kGj2+IPRTq7VygHk/j0YmjlQtz/Krd90Ue+eF0UyIrVd+OihbZnK+OLEX7KMwU0XNm0 hOWg== X-Gm-Message-State: APjAAAXzBAhn5GD5XVkhmREY3EEGiGcu0q20STKMNgzfE8Cvt2ipO4TY /SH0VNSBnPdCnoW6uvK67dU+pkER X-Received: by 2002:a62:7a8a:: with SMTP id v132mr509377pfc.103.1565048113505; Mon, 05 Aug 2019 16:35:13 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id 30sm31296349pjk.17.2019.08.05.16.35.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 16:35:12 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 02/22] media: entity: Modify default behavior of media_entity_get_fwnode_pad Date: Mon, 5 Aug 2019 16:34:45 -0700 Message-Id: <20190805233505.21167-3-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190805233505.21167-1-slongerbeam@gmail.com> References: <20190805233505.21167-1-slongerbeam@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Modify the default behavior of media_entity_get_fwnode_pad() (when the entity does not provide the get_fwnode_pad op) to first assume the entity implements a 1:1 mapping between fwnode port number and media pad index. If the 1:1 mapping is not valid, e.g. the port number falls outside the entity's pad index range, or the pad at that port number doesn't match the given direction_flags, fall-back to the previous behavior that searches the entity for the first pad that matches the given direction_flags. The previous default behavior can choose the wrong pad for entities with multiple sink or source pads. With this change the function will choose the correct pad index if the entity implements a 1:1 port to pad mapping at that port. Add some comments to the @get_fwnode_pad operation to make it more clear under what conditions entities must implement the operation. Signed-off-by: Steve Longerbeam --- drivers/media/mc/mc-entity.c | 25 ++++++++++++++++++++----- include/media/media-entity.h | 21 +++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index c333320f790a..47a39d9383d8 100644 --- a/drivers/media/mc/mc-entity.c +++ b/drivers/media/mc/mc-entity.c @@ -370,22 +370,37 @@ int media_entity_get_fwnode_pad(struct media_entity *entity, unsigned long direction_flags) { struct fwnode_endpoint endpoint; - unsigned int i; int ret; + ret = fwnode_graph_parse_endpoint(fwnode, &endpoint); + if (ret) + return ret; + if (!entity->ops || !entity->ops->get_fwnode_pad) { + unsigned int i; + + /* + * for the default case, first try a 1:1 mapping between + * fwnode port number and pad index. + */ + ret = endpoint.port; + if (ret < entity->num_pads && + (entity->pads[ret].flags & direction_flags)) + return ret; + + /* + * if that didn't work search the entity for the first + * pad that matches the @direction_flags. + */ for (i = 0; i < entity->num_pads; i++) { if (entity->pads[i].flags & direction_flags) return i; } + /* else fail */ return -ENXIO; } - ret = fwnode_graph_parse_endpoint(fwnode, &endpoint); - if (ret) - return ret; - ret = entity->ops->get_fwnode_pad(entity, &endpoint); if (ret < 0) return ret; diff --git a/include/media/media-entity.h b/include/media/media-entity.h index cde80ad029b7..ed00adb4313b 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -199,6 +199,12 @@ struct media_pad { * @get_fwnode_pad: Return the pad number based on a fwnode endpoint or * a negative value on error. This operation can be used * to map a fwnode to a media pad number. Optional. + * Entities do not need to implement this operation + * unless two conditions are met: + * - the entity has more than one sink and/or source + * pad, _and_ + * - the entity does not implement a 1:1 mapping of + * fwnode port numbers to pad indexes. * @link_setup: Notify the entity of link changes. The operation can * return an error, in which case link setup will be * cancelled. Optional. @@ -858,21 +864,24 @@ struct media_link *media_entity_find_link(struct media_pad *source, struct media_pad *media_entity_remote_pad(const struct media_pad *pad); /** - * media_entity_get_fwnode_pad - Get pad number from fwnode + * media_entity_get_fwnode_pad - Get pad number from an endpoint fwnode * * @entity: The entity - * @fwnode: Pointer to the fwnode_handle which should be used to find the pad + * @fwnode: Pointer to the endpoint fwnode_handle which should be used to + * find the pad * @direction_flags: Expected direction of the pad, as defined in * :ref:`include/uapi/linux/media.h ` * (seek for ``MEDIA_PAD_FL_*``) * * This function can be used to resolve the media pad number from - * a fwnode. This is useful for devices which use more complex - * mappings of media pads. + * an endpoint fwnode. This is useful for devices which use more + * complex mappings of media pads. * * If the entity does not implement the get_fwnode_pad() operation - * then this function searches the entity for the first pad that - * matches the @direction_flags. + * then this function first assumes the entity implements a 1:1 mapping + * between fwnode port number and media pad index. If the 1:1 mapping + * is not valid, then the function searches the entity for the first pad + * that matches the @direction_flags. * * Return: returns the pad number on success or a negative error code. */ -- 2.17.1