From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42B32C4CECE for ; Thu, 12 Mar 2020 08:11:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B90F20650 for ; Thu, 12 Mar 2020 08:11:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B90F20650 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CADE76EA63; Thu, 12 Mar 2020 08:09:14 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id DEDDF6E98C for ; Wed, 11 Mar 2020 13:55:40 +0000 (UTC) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2020 06:55:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,541,1574150400"; d="scan'208";a="242688236" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga003.jf.intel.com with ESMTP; 11 Mar 2020 06:55:34 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jC1pf-008kO4-Aj; Wed, 11 Mar 2020 15:55:35 +0200 Date: Wed, 11 Mar 2020 15:55:35 +0200 From: Andy Shevchenko To: Phong LE Subject: Re: [PATCH v2 3/4] drm: bridge: add it66121 driver Message-ID: <20200311135535.GQ1922688@smile.fi.intel.com> References: <20200311125135.30832-1-ple@baylibre.com> <20200311125135.30832-4-ple@baylibre.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200311125135.30832-4-ple@baylibre.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, narmstrong@baylibre.com, airlied@linux.ie, dri-devel@lists.freedesktop.org, a.hajda@samsung.com, Laurent.pinchart@ideasonboard.com, mchehab+samsung@kernel.org, sam@ravnborg.org, heiko.stuebner@theobroma-systems.com, icenowy@aosc.io, devicetree@vger.kernel.org, stephan@gerhold.net, jonas@kwiboo.se, robh+dt@kernel.org, Jonathan.Cameron@huawei.com, jernej.skrabec@siol.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, broonie@kernel.org, davem@davemloft.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, Mar 11, 2020 at 01:51:34PM +0100, Phong LE wrote: > This commit is a simple driver for bridge HMDI it66121. > The input format is RBG and there is no color conversion. > Audio, HDCP and CEC are not supported yet. I guess you should have been told in your company how to use get_maintainer.pl to avoid spamming people. Hint: scripts/get_maintainer.pl --git --git-min-percent=67 ... ... > + * Copyright (C) 2020 BayLibre, SAS > + * Author: Phong LE > + * Copyright (C) 2018-2019, Artem Mygaiev > + * Copyright (C) 2017, Fresco Logic, Incorporated. This too compact to read, perhaps squeeze blank line after your (c) note followed by description how the rest (c) appear in the file. > + * Redundant line. > + */ ... > +#include This can be replaced with property.h, see comments against ->probe(). > +#include > +#include I didn't find evidence of use of any of those. ... > +#define IT66121_MASTER_SEL_REG 0x10 > +#define IT66121_AFE_DRV_REG 0x61 > +#define IT66121_INPUT_MODE_REG 0x70 > +#define IT66121_INPUT_CSC_REG 0x72 > +#define IT66121_AFE_XP_REG 0x62 > +#define IT66121_AFE_IP_REG 0x64 > +#define IT66121_AFE_XP_EC1_REG 0x68 > +#define IT66121_SW_RST_REG 0x04 > +#define IT66121_DDC_COMMAND_REG 0x15 > +#define IT66121_HDCP_REG 0x20 > +#define IT66121_INT_STATUS1_REG 0x06 > +#define IT66121_DDC_HEADER_REG 0x11 > +#define IT66121_DDC_OFFSET_REG 0x12 > +#define IT66121_DDC_BYTE_REG 0x13 > +#define IT66121_DDC_SEGMENT_REG 0x14 > +#define IT66121_DDC_RD_FIFO_REG 0x17 > +#define IT66121_CLK_BANK_REG 0x0F > +#define IT66121_INT_REG 0x05 > +#define IT66121_INT_MASK1_REG 0x09 > +#define IT66121_INT_CLR1_REG 0x0C > +#define IT66121_AV_MUTE_REG 0xC1 > +#define IT66121_PKT_GEN_CTRL_REG 0xC6 > +#define IT66121_AVIINFO_DB1_REG 0x158 > +#define IT66121_AVIINFO_DB2_REG 0x159 > +#define IT66121_AVIINFO_DB3_REG 0x15A > +#define IT66121_AVIINFO_DB4_REG 0x15B > +#define IT66121_AVIINFO_DB5_REG 0x15C > +#define IT66121_AVIINFO_CSUM_REG 0x15D > +#define IT66121_AVIINFO_DB6_REG 0x15E > +#define IT66121_AVIINFO_DB7_REG 0x15F > +#define IT66121_AVIINFO_DB8_REG 0x160 > +#define IT66121_AVIINFO_DB9_REG 0x161 > +#define IT66121_AVIINFO_DB10_REG 0x162 > +#define IT66121_AVIINFO_DB11_REG 0x163 > +#define IT66121_AVIINFO_DB12_REG 0x164 > +#define IT66121_AVIINFO_DB13_REG 0x165 > + > +#define IT66121_AVI_INFO_PKT_REG 0xCD > +#define IT66121_HDMI_MODE_REG 0xC0 > +#define IT66121_SYS_STATUS_REG 0x0E > +#define IT66121_DDC_STATUS_REG 0x16 It's better to a) keep register sorted by value (easy to be oriented); b) have them in fixed width, e.g. 0x0CD. ... > +#define IT66121_DEVICE_MASK 0x0F GENMASK() ? > +#define IT66121_EDID_SLEEP 20000 > +#define IT66121_EDID_TIMEOUT 200000 Care to add units? > +#define IT66121_AFE_CLK_HIGH 80000 Also, what is the unit of this? ... > + return regmap_write(ctx->regmap, IT66121_MASTER_SEL_REG, > + IT66121_MASTER_SEL_HOST); Indentation? Same for other similar places. ... > +static int it66121_configure_afe(struct it66121_ctx *ctx, > + const struct drm_display_mode *mode) ...like this. ... > + if (val & (IT66121_DDC_STATUS_NOACK | IT66121_DDC_STATUS_WAIT_BUS | > + IT66121_DDC_STATUS_ARBI_LOSE)) > + return -EAGAIN; Perhaps better to u32 busy = IT66121_DDC_STATUS_NOACK | IT66121_DDC_STATUS_WAIT_BUS | IT66121_DDC_STATUS_ARBI_LOSE; if (val & busy) return -EAGAIN; ? > + > + return 0; > +} ... > +static int it66121_abort_ddc_ops(struct it66121_ctx *ctx) > +{ > + int ret; > + unsigned int swreset, cpdesire; > + > + ret = regmap_read(ctx->regmap, IT66121_SW_RST_REG, &swreset); > + if (ret) > + return ret; > + > + ret = regmap_read(ctx->regmap, IT66121_HDCP_REG, &cpdesire); > + if (ret) > + return ret; > + > + ret = regmap_write(ctx->regmap, IT66121_HDCP_REG, > + cpdesire & (~IT66121_HDCP_CPDESIRED & 0xFF)); > + if (ret) > + return ret; regmap_update_bits() ? > + > + ret = regmap_write(ctx->regmap, IT66121_SW_RST_REG, > + swreset | IT66121_SW_RST_HDCP); > + if (ret) > + return ret; This should surround the inner update, correct? Otherwise, regmap_update_bits() can be used as well. > +} ... > +static int it66121_get_edid_block(void *context, u8 *buf, > + unsigned int block, size_t len) > +{ > + ret = regmap_write(ctx->regmap, IT66121_DDC_COMMAND_REG, > + IT66121_DDC_COMMAND_EDID_READ); > + if (ret) > + return ret; > + > + offset += cnt; > + remain -= cnt; > + msleep(20); Should be explained. > + > + ret = it66121_wait_ddc_ready(ctx); > + if (ret) > + return ret; > + > + do { > + ret = regmap_read(ctx->regmap, > + IT66121_DDC_RD_FIFO_REG, &val); > + if (ret) > + return ret; > + *(buf++) = val; > + cnt--; > + } while (cnt > 0); I'm wondering if regmap API has a helper for above like cases. > + } > + > + return 0; > +} ... > +static int it66121_connector_get_modes(struct drm_connector *connector) > +{ > + struct it66121_ctx *ctx = container_of(connector, struct it66121_ctx, > + connector); Seems like it can be an inline helper and in all places you can use struct it66121_ctx *ctx = to_it66121_ctx(connector); > + ret = drm_connector_update_edid_property(connector, > + ctx->edid); It quite fits one line, perhaps configure your editor to see 80 limit sharp? Applies to all similar cases as well. > + if (ret) { > + DRM_ERROR("Failed to update EDID property: %d\n", ret); > + goto unlock; > + } > +} ... > + return (val & IT66121_SYS_STATUS_HPDETECT); Too many parentheses. ... > + max_clock = ctx->dual_edge ? 74250 : 148500; Magic numbers? Also, It seems one definition is enough. ... > + msleep(50); Should be explained. ... > + val = mute ? IT66121_AV_MUTE_ON : (~IT66121_AV_MUTE_ON & 0xFF); val = mute ? IT66121_AV_MUTE_ON : 0; > + ret = regmap_write_bits(ctx->regmap, IT66121_AV_MUTE_REG, > + IT66121_AV_MUTE_ON, val); ...or even mask = IT66121_AV_MUTE_ON; val = mute ? mask : 0; ret = regmap_write_bits(ctx->regmap, IT66121_AV_MUTE_REG, mask, val); > + if (ret) > + return ret; ... > + regmap_write_bits(ctx->regmap, IT66121_CLK_BANK_REG, > + IT66121_CLK_BANK_PWROFF_TXCLK, > + ~IT66121_CLK_BANK_PWROFF_TXCLK & 0xFF); Same idea. What the point of all this operations in the value parameter? Please, fix over the code. ... > + if (val & IT66121_SYS_STATUS_ACTIVE_IRQ) { if (!(val & IT66121_SYS_STATUS_ACTIVE_IRQ)) goto unlock; > + ret = regmap_read(ctx->regmap, IT66121_INT_STATUS1_REG, &val); > + if (ret) { > + dev_err(dev, "Cannot read STATUS1_REG %d\n", ret); > + } else { > + if (val & IT66121_INT_STATUS1_DDC_FIFOERR) > + it66121_clear_ddc_fifo(ctx); > + if (val & (IT66121_INT_STATUS1_DDC_BUSHANG | > + IT66121_INT_STATUS1_DDC_NOACK)) Indentation. > + it66121_abort_ddc_ops(ctx); > + if (val & IT66121_INT_STATUS1_HPD_STATUS) { > + regmap_write_bits(ctx->regmap, > + IT66121_INT_CLR1_REG, > + IT66121_INT_CLR1_HPD, > + IT66121_INT_CLR1_HPD); > + > + if (!it66121_is_hpd_detect(ctx)) { > + kfree(ctx->edid); > + ctx->edid = NULL; > + } > + event = true; > + } > + } > + > + regmap_write_bits(ctx->regmap, IT66121_SYS_STATUS_REG, > + IT66121_SYS_STATUS_CLEAR_IRQ, > + IT66121_SYS_STATUS_CLEAR_IRQ); > + } > + > +unlock: > + mutex_unlock(&ctx->lock); ... > +static int it66121_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + u8 ids[4]; Magic, also see below. > + int i, ret; > + struct it66121_ctx *ctx; > + struct device *dev = &client->dev; > + ctx->conf = (struct it66121_conf *)of_device_get_match_data(dev); device_get_match_data() In any case why explicit casting? > + if (!ctx->conf) > + return -ENODEV; > + > + ctx->dual_edge = of_property_read_bool(dev->of_node, "pclk-dual-edge"); device_property_read_bool() > + for (i = 0; i < 4; i++) { Magic. > + regmap_read(ctx->regmap, i, &ret); > + ids[i] = ret; > + } > + > + if (ids[0] != IT66121_VENDOR_ID0 || > + ids[1] != IT66121_VENDOR_ID1 || > + ids[2] != IT66121_DEVICE_ID0 || > + ((ids[3] & IT66121_DEVICE_MASK) != IT66121_DEVICE_ID1)) { > + ite66121_power_off(ctx); > + return -ENODEV; > + } > + > + ctx->bridge.funcs = &it66121_bridge_funcs; > + ctx->bridge.of_node = dev->of_node; > + > + ret = devm_request_threaded_irq(dev, client->irq, NULL, > + it66121_irq_threaded_handler, > + IRQF_SHARED | IRQF_TRIGGER_LOW | > + IRQF_ONESHOT, Shouldn't flags come from appropriate resource provider (DT / ACPI / etc)? > + dev_name(dev), > + ctx); > + if (ret < 0) { > + dev_err(dev, "Failed to request irq %d:%d\n", client->irq, ret); > + ite66121_power_off(ctx); > + return ret; > + } > + > + drm_bridge_add(&ctx->bridge); > + > + return 0; > +} ... > +static const struct of_device_id it66121_dt_match[] = { > + { .compatible = "ite,it66121", > + .data = &it66121_conf_simple, > + }, > + { }, Terminator line doesn't need comma. > +}; ... > +static const struct i2c_device_id it66121_id[] = { > + { "it66121", 0 }, > + { }, Ditto. > +}; -- With Best Regards, Andy Shevchenko _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel