Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp277060pxm; Fri, 25 Feb 2022 07:50:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzewqyxFcjptGPb/ULrFz3SeF7rrE+EnpyXjxRaQv/BELQoRjO+oLVks5GPFyed2tQ75Wis X-Received: by 2002:a17:90a:3d45:b0:1bc:b597:94bd with SMTP id o5-20020a17090a3d4500b001bcb59794bdmr3770677pjf.158.1645804250906; Fri, 25 Feb 2022 07:50:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1645804250; cv=pass; d=google.com; s=arc-20160816; b=crPHIme+RTv8YBltQpJyEk56JVbBKTYjV8lMAFwMnccJmjPNGYpXN1JXshTWWCV+MD xpvUdTFtZY/MpdheiV5i0UiYyMlqpsCAUHbC1rtC4kI4MjM6xUlEmXFoRVsV0ekiz6au 8oqFCX2Nwv8Wew6yJzXDbyn0OW3RnvjNo8IhEENOwyHosI404Y+q9n0E3w4D8HCQQzPn Z0efW+ZxJej+2TvxfEj+dAPIr1CHVI5M7YPOJHaO9AU4dWFDbgTsrIKPjUZTmd8OoLv+ 1zSCiuxmGBfatMqA8Bp1CkA8VGF9dbm4FGQivFqeH+cYC2cW588lbt64DduQ0ZS4Pe1O ZNhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gQL3lJTAk3YtI0VvJzj1nN5q4+4iHZhkRQtY8Rg5EXQ=; b=dDYfzon1456PARLDcoIelUmB+8H+ATumgNGScATPNu5EopLbmOy6bHft4NMtTecINT cE0EMLf23qhmt8uuityWdMP/tbYgh5KdM11okEGuFEkDgvA04eqPZHA1q1B6mnkBjXE0 dJF7jAQlSKovCfDrjnPAT1wXymMiB9j8pr1O3aE01I78dJMvvWh0fk42M/x0vHJ60PN1 JN1urZkqyz8MqM0XKFoJ8G5D9JRl/3Iqz0n7Fx+V2Yygs+be3zOaoV6ePgcVD70g5GoX e4meT0R23dWBotOZyUidWWcaYIo2zCnwPJwYTiU2Af6ZzxDbOm3VcBlwoKrgg/8/KpXt 9AEg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=j67P1uJC; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x13-20020a65414d000000b00370c2186a9esi2142910pgp.507.2022.02.25.07.50.33; Fri, 25 Feb 2022 07:50:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=j67P1uJC; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241080AbiBYNSz (ORCPT + 99 others); Fri, 25 Feb 2022 08:18:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231594AbiBYNSx (ORCPT ); Fri, 25 Feb 2022 08:18:53 -0500 Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [IPv6:2a0b:5c81:1c1::37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CE761CF0A6; Fri, 25 Feb 2022 05:18:16 -0800 (PST) Received: from hillosipuli.retiisi.eu (dkvn5pty0gzs3nltj987t-3.rev.dnainternet.fi [IPv6:2001:14ba:4457:9640:1e2d:1f75:a607:ef37]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sailus) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 922BC1B0004B; Fri, 25 Feb 2022 15:18:11 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1645795091; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gQL3lJTAk3YtI0VvJzj1nN5q4+4iHZhkRQtY8Rg5EXQ=; b=j67P1uJCWcjbrCk9L6TAP4pZoda8RtJ9zxg4X1y9UtD4YQW88Ikp9P/mBfQwcjLJUN7V8A o3GXXh5G9Qoc6IcvEnPRwOP75j5Ba30vLs3qc5YctMuvTKzgKrKggRob3Wg2QIqpbOVs6D hO6I+KrwRhzD376gPUmnqr9cvBmkxM+j+89XDyKOHbzFzeXZEmgrZ1iKQY8i0aEkG005CD Z1Ol0a8Z/rUbKJQ11pkoIlpp+tsdOJpPSJ84CDq+LEbpEZRlZS7ipIE3OlkvlYCHvlBX8D LYTgL7ypMKFG/jjF8lkxyqeZeIV8VzsUGx/qgrrVIi1wpw+JwNM6tze/9flPrg== Received: from valkosipuli.retiisi.eu (valkosipuli.localdomain [192.168.4.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by hillosipuli.retiisi.eu (Postfix) with ESMTPS id 5BF5B634C90; Fri, 25 Feb 2022 15:18:10 +0200 (EET) Date: Fri, 25 Feb 2022 15:18:10 +0200 From: Sakari Ailus To: Krzysztof =?utf-8?Q?Ha=C5=82asa?= Cc: Jacopo Mondi , Mauro Carvalho Chehab , Rob Herring , devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Laurent Pinchart , Joe Perches Subject: Re: [PATCH v7 2/2] Driver for ON Semi AR0521 camera sensor Message-ID: References: <20220109153439.bfnfigocaeeeghmp@uno.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sailus smtp.mailfrom=sakari.ailus@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1645795091; a=rsa-sha256; cv=none; b=vjgP/AeYybEzuLQZdgwt7d4o9rjt+v1wTpFtVx9aWhdA2dfouLcEOoN7M2S8jzJbtwC2Oq DxccSFwAitVYYt9DXycjN/J6P81ClwgiB7d1aIgP1xUrISOhtEofj6k1KP6Dgb9cz3MAcL kNc8ujE9mENGqPC+pZ9HyDXu3I5o33yznQEhdNO82lFVc1tSuJpLnWJoDkZ5rfjCR301p/ yXNmN0Z9fAeqV4V1Sa1g+692gx+lkdJKsy2MsHk1FGCO7P8rfjULTjbY6aMAgPqmWoz/RW ThdLlY/duHH9z/bYCvl8ah0MunC6vvpe5UAEpv/MRYZA27V/ZWZ/m5Kv11IP4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1645795091; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gQL3lJTAk3YtI0VvJzj1nN5q4+4iHZhkRQtY8Rg5EXQ=; b=Bbpv6y82yujcWT3KMtsp8/Z3s9Lg4FGLJwzQg//WP4hiRQObln/kbafLVg+DJV0rMmpGwe 9MwWIQusavjqlzENTb8y5vFqXdMPa5246iPLf1r+aPJHuvZrvX5khI1+nuRGFZt0KjlBBp YKBJ1SGOoWKV4V49urItF+b+HwBfA/82RAb8wMNUuslSdkq0dkQN0QkixUxGX65KprkilY VMjs20nGJyd5FrDsKGeupm7W9Bykg+YP5/m+Ih+kTLdIFqsUSlZdriLRLd8F4MGi0TmXOc CjdwuN8hSnmz4ZU4SrQEo3vL88Hi/1KLFmKa5Rk/F/C30Pp4EKPDWIaSBBe1LA== X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Krysztof, On Fri, Feb 25, 2022 at 01:15:11PM +0100, Krzysztof HaƂasa wrote: > Hi Jacopo, > > Sorry it took that long. Unfortunately I no longer have much time to > work on this, thus the delays. > > Jacopo Mondi writes: > > >> +static int ar0521_s_ctrl(struct v4l2_ctrl *ctrl) > >> +{ > >> + struct v4l2_subdev *sd = ctrl_to_sd(ctrl); > >> + struct ar0521_dev *sensor = to_ar0521_dev(sd); > >> + int ret; > >> + > >> + /* v4l2_ctrl_lock() locks our own mutex */ > >> + > >> + dev_dbg(&sensor->i2c_client->dev, "%s(0x%X)\n", __func__, ctrl->id); > >> + > >> + switch (ctrl->id) { > >> + case V4L2_CID_HBLANK: > >> + case V4L2_CID_VBLANK: > >> + sensor->total_width = sensor->fmt.width + > >> + sensor->ctrls.hblank->val; > >> + sensor->total_height = sensor->fmt.width + > >> + sensor->ctrls.vblank->val; > >> + break; > >> + default: > >> + ret = -EINVAL; > >> + break; > >> + } > >> + > >> + // access the sensor only if it's powered up /* This is the preferred comment style */ > >> + if (!pm_runtime_get_if_in_use(&sensor->i2c_client->dev)) > > > > As you correctly do not access the chip's registers if it's powered > > off, you have to call __v4l2_ctrl_handler_setup() at power on time to > > make sure controls are actually set. > > These registers are also written in ar0521_set_stream(), isn't it > enough? > > >> + ctrls->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, > >> + AR0521_WIDTH_BLANKING_MIN, 4094, 1, > >> + AR0521_WIDTH_BLANKING_MIN); > >> + ctrls->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, > >> + AR0521_HEIGHT_BLANKING_MIN, 4094, 2, > >> + AR0521_HEIGHT_BLANKING_MIN); > >> + v4l2_ctrl_cluster(2, &ctrls->hblank); > > > > Is it intended to have vblank and hblank as cluster, can't they change > > independently ? > > They can. It appears, though, that clusters aren't about controls which > can't change independently. Both of the two are written to the hardware > at the same time, which appears to be a valid reason to combine them > into a cluster. > This is similar to the gain/balance controls, and BTW the use of > clusters there was suggested by you. > > Please correct me if I'm wrong. > > >> + /* Read-only */ > >> + ctrls->pixrate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE, > >> + AR0521_PIXEL_CLOCK_MIN, > >> + AR0521_PIXEL_CLOCK_MAX, 1, > >> + AR0521_PIXEL_CLOCK_RATE); > > > > so you have to mark it as read-only > > Oh, I'd be happy for this control to be R/W. Unfortunately the core > media core enforces R/O. This is only a comment about what the core code > does, currently at least. > > >> + dev_dbg(dev, "%s()\n", __func__); > > > > Rather useless, please drop. Same for all other debug functions that > > just print the current function name in other parts of the driver. > > While maybe useful when developing, they're mostly noise for users > > imo. > > Fine, will drop the rest of the debug. In fact, I already dropped the > most useful parts (I2C register access debugging). > > >> + endpoint = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, > >> + FWNODE_GRAPH_ENDPOINT_NEXT); > > > > The drivers supports a single endpoint right ? Then > > fwnode_graph_get_next_enpoint() can be used > > Well, I originally used > fwnode_graph_get_next_endpoint(of_fwnode_handle(dev->of_node), NULL). > Sakari suggested I should use the above > fwnode_graph_get_endpoint_by_id(). > It could be a good idea to agree on this. Not sure about the difference. The OF folks have shunned to the use of the iterative varants as that can often lead to complicated parsing of the endpoints. As obtaining the endpoint based on port and endpoint IDs works well in all cases I've suggested people to use that. But as the backend, at least currently, uses iterative functions, they're unlikely to disappear in the future. > > >> + for (cnt = 0; cnt < ARRAY_SIZE(ar0521_supply_names); cnt++) { > >> + struct regulator *supply = devm_regulator_get(dev, > >> + ar0521_supply_names[cnt]); > >> + > >> + if (IS_ERR(supply)) { > >> + dev_info(dev, "no %s regulator found: %li\n", > >> + ar0521_supply_names[cnt], PTR_ERR(supply)); > >> + return PTR_ERR(supply); > >> + } > >> + sensor->supplies[cnt] = supply; > >> + } > > > > Using the regulator bulk api would simplify this. > > See drivers/media/i2c/ccs/ccs-core.c > > The bulk API doesn't allow for delays between individual supplies, does it? > The delays are mandated by the manufacturer. If that is the case, then you can't use the bulk API. That also requires the board to be wired in such a way that these regulators have no other users. > > >> + > >> + mutex_init(&sensor->lock); > >> + > >> + ret = ar0521_init_controls(sensor); > >> + if (ret) > >> + goto entity_cleanup; > >> + > >> + ar0521_adj_fmt(&sensor->fmt); > > > > Called already here above. > > Right, I will remove the first one. > > >> + ret = v4l2_async_register_subdev(&sensor->sd); > >> + if (ret) > >> + goto free_ctrls; > >> + > >> + /* Turn on the device and enable runtime PM */ > >> + ret = ar0521_power_on(&client->dev); > >> + if (ret) > >> + goto disable; > > > > Does the device stay powered all the time ? > > Depends on the hw, but the power could be disabled, yes. > > > Doesn't your resume callback call power_on() already ? > > It does, when the PM is enabled. > > Should the above code be changed? I think you'll need pm_runtime_idle() call after enabling runtime PM. > > >> +static struct i2c_driver ar0521_i2c_driver = { > >> + .driver = { > >> + .name = "ar0521", > >> + .pm = &ar0521_pm_ops, > >> + .of_match_table = ar0521_dt_ids, > >> + }, > >> + .probe = ar0521_probe, > > > > You could use probe_new and drop the "const struct i2c_device_id *id" > > argument to probe() > > You are right again. > > That said, I wonder if it would be better (like easier) to have this > driver added to the staging area instead. -- Regard,s Sakari Ailus