Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3046380imm; Fri, 24 Aug 2018 09:35:05 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda2J90tRNmMuBYG/FNtJKmUerWUkOe9LH2SzjdRjRqgvVeLJgziFqeaqxYgQNlU2BiIC8K1 X-Received: by 2002:a63:990a:: with SMTP id d10-v6mr2443256pge.80.1535128505044; Fri, 24 Aug 2018 09:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535128505; cv=none; d=google.com; s=arc-20160816; b=S2UG3TPluYgSlfUTqKY2tPJaygRPo7+qsAog5J60Y0NJrZxNbumPobyBV9yXmU2d7h JONDuQwPD39z4zICDGZl23ljYAv4mq8RWWvBdKtbtsbyzsrRz+7pCefGd8oGPOnfsNvY 3y2bTCGeuv4El745nCyVCiCH0VS5WTHnc/QEbcTBET/oCvCMbg03cKyvwdDf43Mqdj2u LHIta3Zf7JWbXHK+l4Lrc9oT981WXqU443tHjC/6isZpNLuu7IilRxrV81Fa6KZX4a5R /3bldWP4c7w+bfAz7nzXhU0MteU+lzQ0GahuO920Go3zboACqsm1tKVmzM3TFHynrTAw zdPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=Z7lEMdE7h2OhyLpi0dqvwLeYVWwqoUQRJkUEcS7/Fwk=; b=A3WJTU/vor/hLAYBuzJcaJKaDE6fkZdIl4+cZr5K0tPB30jG9oJclQMP2+KxHMrwrH qbZJCx+gzuZNz6KwVhE3n/5awpiosDbYAML+R7bYstC+bXV3TjMt0ommbZ7fdhbuy8cj d9tivFC1sQowU3/e8EtD6ji6PqAY/T1hA+RzXdhN+a6bzaIybWtXzX0DBUWpNU68hznX 7PXnYInKQIJYg9Fa7lVzgtQ3aFqONM9blCdM0QQvDIOtDmcEIw37orDuooQoWXMOTKhX KNGxYzTr2JAM1skDJbJUViEZF5cBWPbVNyZBYL61aHdJHsqgKoLqC0bwM4s/TTpHglmF MQkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=19S9wKO8; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1-v6si6908346pld.424.2018.08.24.09.34.49; Fri, 24 Aug 2018 09:35:05 -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=@kernel.org header.s=default header.b=19S9wKO8; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727430AbeHXUJF (ORCPT + 99 others); Fri, 24 Aug 2018 16:09:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:44102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726511AbeHXUJF (ORCPT ); Fri, 24 Aug 2018 16:09:05 -0400 Received: from mail-qt0-f180.google.com (mail-qt0-f180.google.com [209.85.216.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B1462151C; Fri, 24 Aug 2018 16:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535128420; bh=96ZmoABHwSDkgi5U/Jsp/8a3wEOmFjfxpiKylQsZi1w=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=19S9wKO8EW9QmFjYQ4gaDkKGA3zEpYo7yTM6l5H603me0w1XkSuUHxuzn2qRPlwxL LtFO7Of/03EE+jWr38iRVMW4f7BAn0NIQ7634uJRsf3boJcaWOtsHaJxjUe+h4TNqS ofokS+zgCg+56Fd9+cO1GOAxBgQNhNkBGqpz9HD8= Received: by mail-qt0-f180.google.com with SMTP id r13-v6so10762775qtr.11; Fri, 24 Aug 2018 09:33:40 -0700 (PDT) X-Gm-Message-State: APzg51AnLERoALjS6Cxm9xD2GvczVVqGHz3KNTGr0ADUBD+Ng3ndfCJr FjNDu18WMHUTaHAvzav4JcHxtAFYAbYLs2WfoA== X-Received: by 2002:ac8:1909:: with SMTP id t9-v6mr2548035qtj.327.1535128419759; Fri, 24 Aug 2018 09:33:39 -0700 (PDT) MIME-Version: 1.0 References: <20180810130359.9882-1-peda@axentia.se> <20180810130359.9882-4-peda@axentia.se> <20180813135949.32vrlrevtazr5x7d@apu3b.nibble.pw> <0baac94e-f3d2-53fd-4af9-854bb4498345@axentia.se> <5c9853fc-e2ea-6983-ac88-b52b6e9e6ecd@axentia.se> <56016787-0487-1571-7c28-2767033cda23@axentia.se> <20180824094701.1f17393f@bbrezillon> In-Reply-To: <20180824094701.1f17393f@bbrezillon> From: Rob Herring Date: Fri, 24 Aug 2018 11:33:28 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 3/4] drm/atmel-hlcdc: iterate over all output endpoints To: Boris Brezillon Cc: Peter Rosin , Mark Rutland , devicetree@vger.kernel.org, jmondi , Alexandre Belloni , Andrzej Hajda , David Airlie , "linux-kernel@vger.kernel.org" , dri-devel , Sakari Ailus , Jacopo Mondi , Jyri Sarha , Daniel Vetter , Russell King , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 24, 2018 at 2:47 AM Boris Brezillon wrote: > > On Tue, 14 Aug 2018 17:05:29 +0200 > Peter Rosin wrote: > > > >>>>>> @@ -77,13 +79,29 @@ static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint) > > >>>>>> > > >>>>>> int atmel_hlcdc_create_outputs(struct drm_device *dev) > > >>>>>> { > > >>>>>> - int endpoint, ret = 0; > > >>>>>> - > > >>>>>> - for (endpoint = 0; !ret; endpoint++) > > >>>>>> - ret = atmel_hlcdc_attach_endpoint(dev, endpoint); > > >>>>>> + struct of_endpoint endpoint; > > >>>>>> + struct device_node *node = NULL; > > >>>>>> + int count = 0; > > >>>>>> + int ret = 0; > > >>>>>> + > > >>>>>> + for_each_endpoint_of_node(dev->dev->of_node, node) { > > >>>>>> + of_graph_parse_endpoint(node, &endpoint); > > >>> > > >>> I'd really like to kill off of_graph_parse_endpoint, not add more > > >>> users (check the git history on this code). You should know what are > > >>> possible port and endpoint numbers, so iterate over those. > > >> > > >> So, add a comment to that effect in the docs of the of_graph_parse_endpoint > > >> function. > > >> > > >> How can the hlcdc driver know the actual number of endpoints? It's a > > >> one-way signal path out from that port, and it can easily be routed to > > >> 1, 2, 3 or even more places. As shown above, forcing the endpoint id > > >> to start at zero is a nuisance, and I don't see the point of it. > > >> > > >> But I welcome suggestions on how to arrange the above dtsi/dts fragments > > >> in a world where the endpoint id absolutely has to start at zero. > > > > > > Your dts file arrangement seems fine. Can't you just not exit the loop > > > on -ENODEV? IOW, just iterate til you find an enabled endpoint. > > > > That would regress cases where two (or more) endpoints are enabled > > (which is currently supported). As I see it, the driver will have a > > very hard time knowing when to stop iterating with any solution not > > involving the equivalent of the functions for_each_endpoint_of_node > > and of_graph_parse_endpoint. Open-coding of_graph_parse_endpoint just > > to avoid it is a bit more than silly IMHO... > > I agree, and actually, I think this is Rob who suggested to do what we > do here :-) (iterate from 0 to X, and stop as soon as > -ENODEV is returned). By suggested, you mean implemented because that is what it currently does. My suggestion now is to do this: for (endpoint = 0; endpoint < SOME_REASONABLE_MAX_NUMBER_OF_ENDPOINTS; endpoint++) { ret = atmel_hlcdc_attach_endpoint(dev, endpoint); if (ret == -ENODEV) continue; // handle other errors? } And SOME_REASONABLE_MAX_NUMBER_OF_ENDPOINTS is something you make up based on how many connections any board will have and physics (I suppose you could have trees worth of buffers, but really what is the worst case in an actual board design?). I would think 4 would be plenty. If not, double it to 8. Rob