Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2437022ybb; Sun, 5 Apr 2020 07:31:42 -0700 (PDT) X-Google-Smtp-Source: APiQypIe6Y0DEPpKiocXi4sKLAwwC8/YFi2Hrung85sXRa0tJYhV7BaI2gvhVzekxrCeX8AIxQSV X-Received: by 2002:aca:b5c3:: with SMTP id e186mr9311028oif.114.1586097102193; Sun, 05 Apr 2020 07:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586097102; cv=none; d=google.com; s=arc-20160816; b=aZQzKjTXCNhBV+TPBpH2QhoQlMxZy7ef5EzB9+8wzmMa5KvYhNbx3pYfns8vdwGLv4 8SgZzXgvzG3LnqRMlZJXBOjFgljnpevTFM6mH3hW9zBMQLIWPRLuFY2aX0j7rT0rAWYf 7ZdLpJqhTvYkuwCJ/os4qE+cSWOK9AHQQWlRu4EU1enlMfHzbwkw+guVAAYeSUEYILzR /dqrrDjH6WNCAYl6k6C2ihsm/6olqltxNmD0PQ8LK9blHROu2ywjAARyC39UuWeNC6Mn sexTz7zequHq5VnsFGqUTFy0VT8k6ZFivC8zLq+EPJYp1RF/810DjDgUi1iBUp2j4GXc CTgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=8TVAWIxErALuq3DVBNmBz7EdoGGQJ1wlwqQV03JCNk8=; b=EBNPfceMZXXVctKHJBZyS8e63whFBHok00U2eCKWO/tC/9JoSIQsmS3VRFLpfWX2DB SaXC51m7MfszZhmpIZ0DCASYSyqQJpZTE1e7FL/N58Nuh5on7eLz3OUa92mtDAq4Pxkg tEF7BOecYTLw2IQ+r7/qj+ZTRGN7aXU3QCM9qvjjNuuv0kOLnvGgwBtR/uKnCiIkz6qq 0ZBqJca9xAgnGV1AHO9fZckkMwkxRDmmRBOY/AJnv+xcgWuqNELXoGfo3AGL1v9I9AI/ XGXf2IqRDy/LyuhxE+rbHqhvA8FoH8WCaRbJ9XbtLxU0H95dmVUZ0KWC0K/EVgEKX5nB vQqA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j25si5963919oii.86.2020.04.05.07.31.29; Sun, 05 Apr 2020 07:31:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726812AbgDEO1X (ORCPT + 99 others); Sun, 5 Apr 2020 10:27:23 -0400 Received: from asavdk3.altibox.net ([109.247.116.14]:37452 "EHLO asavdk3.altibox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726674AbgDEO1X (ORCPT ); Sun, 5 Apr 2020 10:27:23 -0400 Received: from ravnborg.org (unknown [158.248.194.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by asavdk3.altibox.net (Postfix) with ESMTPS id D742320160; Sun, 5 Apr 2020 16:27:17 +0200 (CEST) Date: Sun, 5 Apr 2020 16:27:15 +0200 From: Sam Ravnborg To: Joonas =?iso-8859-1?Q?Kylm=E4l=E4?= Cc: Andrzej Hajda , Thierry Reding , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, paul.kocialkowski@bootlin.com, GNUtoo@cyberdimension.org Subject: Re: [PATCH] drm/panel: samsung: s6e8aa0: Add backlight control support Message-ID: <20200405142715.GA28291@ravnborg.org> References: <20190921124843.6967-1-joonas.kylmala@iki.fi> <53385e44-1847-ace0-cd87-5571f6acd3f2@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <53385e44-1847-ace0-cd87-5571f6acd3f2@iki.fi> User-Agent: Mutt/1.10.1 (2018-07-13) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=eMA9ckh1 c=1 sm=1 tr=0 a=UWs3HLbX/2nnQ3s7vZ42gw==:117 a=UWs3HLbX/2nnQ3s7vZ42gw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=8nJEP1OIZ-IA:10 a=8Bv4S_VrHzWzl_PHQgMA:9 a=wPNLvfGTeEIA:10 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Joonas. On Sat, Apr 04, 2020 at 04:27:02PM +0300, Joonas Kylm?l? wrote: > Hi, > > addressing this email to you all since there might be widespread race > condition issue in the DRM panel drivers that are using MIPI DSI. See > below for my message. > > Andrzej Hajda: > >> +static int s6e8aa0_set_brightness(struct backlight_device *bd) > >> +{ > >> + struct s6e8aa0 *ctx = bl_get_data(bd); > >> + const u8 *gamma; > >> + > >> + if (ctx->error) > >> + return; > >> + > >> + gamma = ctx->variant->gamma_tables[bd->props.brightness]; > >> + > >> + if (ctx->version >= 142) > >> + s6e8aa0_elvss_nvm_set(ctx); > >> + > >> + s6e8aa0_dcs_write(ctx, gamma, GAMMA_TABLE_LEN); > >> + > >> + /* update gamma table. */ > >> + s6e8aa0_dcs_write_seq_static(ctx, 0xf7, 0x03); > >> + > >> + return s6e8aa0_clear_error(ctx); > >> +} > >> + > >> +static const struct backlight_ops s6e8aa0_backlight_ops = { > >> + .update_status = s6e8aa0_set_brightness, > > > > > > This is racy, update_status can be called in any time between probe and > > remove, particularly: > > > > a) before panel enable, > > > > b) during panel enable, > > > > c) when panel is enabled, > > > > d) during panel disable, > > > > e) after panel disable, > > > > > > b and d are racy for sure - backlight and drm callbacks are async. > > > > IMO the best solution would be to register backlight after attaching > > panel to drm, but for this drm_panel_funcs should have attach/detach > > callbacks (like drm_bridge_funcs), > > > > then update_status callback should take some drm_connector lock to > > synchronize with drm, and write to hw only when pipe is enabled. > > I have done now research and if I understand right one issue here might > be with setting the backlight brightness if the DSI device is not > attached before calling update_status() since calling it would call > subsequently s6e8aa0_set_brightness() -> s6e8aa0_dcs_write() -> > mipi_dsi_dcs_write_buffer(), which then requires DSI to be attached. Not directly related to your comments above. But I have looked at the backlight support for the various samsung panels. None of them are good examples to follow. Please have a look at for example panel-novatek-nt35510.c which is a good example how to have a local backligth and tie it into the general way it is used by drm_panel. I have typed patches to fix all three samsung panels, will post patches later when I get more time. If we are concerned with set_brightness() being called while not ready, this can be checked in the set_brightness() function and return error if not OK. As the the race concerns see Daniel's reply. Sam