Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1087421imm; Wed, 8 Aug 2018 10:30:12 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyAoLnIynrGIeztWqOdz0wR186NFtfMXn+104+trN0aBuD1tSVF/AJALfPckNgzd4oZSr1z X-Received: by 2002:a17:902:262:: with SMTP id 89-v6mr3380532plc.221.1533749412227; Wed, 08 Aug 2018 10:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533749412; cv=none; d=google.com; s=arc-20160816; b=I/V2gxq0qJoT/PXCokCqShgmOqt9dsRnwVe/MVAJAUOyd5p5j/KpN5KALZTv3tUAoA Ysogorm9R8OIUB4cEERwWuPu72RcN6XIGV/+R8PBrRUUGZrPrm7TedDIc7FBRzVQx853 yZrYowPtHXHFJVYGNVDhkQTFmLpwP1BZpLWbghR2FOa2ZSibldWsSSdWC+/zo3dyAxBb k51xN+pgvHJwLkgnaogL84GSP/XkAO5niZErt0rh/+yzHviWopo7c8uU/TXQCg0qeIEW zxWGrGffz6gSX9tX/3K9g+KTAwQII1UX+nG9IWT+vsJVq27EoJ+84qhJyocA5p5eSUQA s1mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=EvbL6rJc5nL6fV3jElhpZrrzcr4VIzP2WBO6uVgHmqU=; b=Nj8LZFMXrjRRP5+WDsgIu2EtFThQj2W7bztQJPK+zqWQAQJJJNKmFbeQCHiHhAGAic nnT1YzSiKfobjP3pVTnRzBMj5I9TB8DhasWXPSab5QiaCtZNR4d6LTX/BqHDgCpB+YhY HTcrZPNeKe+l5BRkqmE2aG35SfZ45onKsztVYWiQupAxGE2x6a5wYCkMmhU44ONIfauK 3Wsur52PytDx3Zi1212h2KYdK+y1lh5HInFXdb5GYqHo6I8W5u0D/oOM58+u6Q73QVot KKDmjKTk2QUzaDc8ObYlHLpxSbp+VkKlb/rGvjJQRpQmOsGWrNaTNkXLJSN88h8rocEE RhVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=DxJWKznK; 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=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24-v6si4785768pgl.452.2018.08.08.10.29.57; Wed, 08 Aug 2018 10:30:12 -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=@synopsys.com header.s=mail header.b=DxJWKznK; 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=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728711AbeHHTtq (ORCPT + 99 others); Wed, 8 Aug 2018 15:49:46 -0400 Received: from smtprelay.synopsys.com ([198.182.47.9]:51628 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727337AbeHHTtq (ORCPT ); Wed, 8 Aug 2018 15:49:46 -0400 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id 155FF24E0513; Wed, 8 Aug 2018 10:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1533749346; bh=isckySDeIk7AP7iRCfgSz6UBAaNYH/Dl/bANN9mk7Q4=; h=Subject:To:CC:References:From:Date:In-Reply-To:From; b=DxJWKznKcqHLOaIyAHXCQWsyA5dDMpBBY8jZaJZ+w6MaN0r/D+jcRQoB7BOLkjaGh YxEKXh81nWN/ydeXnbrWUkFHI8vOKuDQ9KrD5DiwT8d+mA2irOvcFwjzAZAPBaexVz /y7lmog6l1VzIt6MLtBOciHpDmXGp/7PCK9mi2esRMBemmyR8suzGKIQeI/bgCj7tW qJzVeUBlGryAbyuRdwnjP/3MN9GlJPpTOg9ff+equnacUa+3x8Cp8uU5lg4yg4VQXr iFYCF4vwUPz9kCixunw8DzvFgQil5gFm0qGEHW6NruxphIz+Nfc4Aud3grN1tvT3eC YEJtsdkrUQGfA== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) by mailhost.synopsys.com (Postfix) with ESMTP id 1D7CC3707; Wed, 8 Aug 2018 10:29:03 -0700 (PDT) Received: from DE02WEHTCB.internal.synopsys.com (10.225.19.94) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 8 Aug 2018 10:29:02 -0700 Received: from DE02WEHTCA.internal.synopsys.com (10.225.19.92) by DE02WEHTCB.internal.synopsys.com (10.225.19.94) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 8 Aug 2018 19:29:00 +0200 Received: from [10.0.2.15] (10.107.25.93) by DE02WEHTCA.internal.synopsys.com (10.225.19.80) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 8 Aug 2018 19:29:00 +0200 Subject: Re: [PATCH 1/3] i3c: master: Add driver for Synopsys DesignWare IP To: Boris Brezillon , Vitor soares CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <1532120272-17157-1-git-send-email-soares@synopsys.com> <1532120272-17157-2-git-send-email-soares@synopsys.com> <20180727153850.5a8ca75c@bbrezillon> From: vitor Message-ID: <04ae034c-ec6c-ce43-6536-9da9d765d558@synopsys.com> Date: Wed, 8 Aug 2018 18:28:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180727153850.5a8ca75c@bbrezillon> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.107.25.93] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Boris, On 27-07-2018 14:38, Boris Brezillon wrote: > Hi Victor, > > On Fri, 20 Jul 2018 21:57:50 +0100 > Vitor soares wrote: > >> This patch add driver for Synopsys DesignWare IP on top of >> I3C subsystem patchset proposal V6 > The fact that you based your work on v6 of the I3C patchset should be > placed .... > >> Signed-off-by: Vitor soares >> --- > ... here, so that it does not appear in the final commit message. > > > [...] I will do that in the next submission. >> +static int dw_i3c_master_get_free_pos(struct dw_i3c_master *master) >> +{ >> + if (!(master->free_pos & GENMASK(master->maxdevs - 1, 0))) >> + return -ENOSPC; >> + >> + return ffs(master->free_pos) - 1; >> +} > Okay, maybe we can have a generic infrastructure for that part (I have > the same logic in the Cadence driver), but let's keep that for later. I think everyone will need a table (SW or HW) to mask the slots available for DAA. > >> + >> +static void dw_i3c_master_wr_tx_fifo(struct dw_i3c_master *master, >> + const u8 *bytes, int nbytes) >> +{ >> + int i, j; >> + >> + for (i = 0; i < nbytes; i += 4) { >> + u32 data = 0; >> + >> + for (j = 0; j < 4 && (i + j) < nbytes; j++) >> + data |= (u32)bytes[i + j] << (j * 8); >> + >> + writel(data, master->regs + RX_TX_DATA_PORT); > Maybe you can use writesl() as suggested by Arnd in his review of the > Cadence driver. Andy also suggest get_unaligned_le32() / put_unaligned_le32() to read/write from FIFOS. I will try both solutions. > >> + } >> +} >> + > [...] > >> + >> +static void dw_i3c_master_detach_i2c_dev(struct i2c_dev_desc *dev) >> +{ >> + struct dw_i3c_i2c_dev_data *data = i2c_dev_get_master_data(dev); >> + struct i3c_master_controller *m = i2c_dev_get_master(dev); >> + struct dw_i3c_master *master = to_dw_i3c_master(m); >> + >> + writel(NULL, > ^ 0 not NULL I will change it. > >> + master->regs + >> + DEV_ADDR_TABLE_LOC(master->datstartaddr, data->index)); >> + >> + i2c_dev_set_master_data(dev, NULL); >> + master->addrs[data->index] = 0; >> + master->free_pos |= BIT(data->index); >> + kfree(data); >> +} >> + >> +static int dw_i3c_probe(struct platform_device *pdev) >> +{ >> + struct dw_i3c_master *master; >> + struct resource *res; >> + int ret, irq; >> + >> + master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL); >> + if (!master) >> + return -ENOMEM; >> + >> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >> + master->regs = devm_ioremap_resource(&pdev->dev, res); >> + if (IS_ERR(master->regs)) >> + return PTR_ERR(master->regs); >> + >> + master->core_clk = devm_clk_get(&pdev->dev, "core_clk"); >> + if (IS_ERR(master->core_clk)) >> + return PTR_ERR(master->core_clk); >> + >> + master->core_rst = devm_reset_control_get_optional_exclusive(&pdev->dev, >> + "core_rst"); >> + if (IS_ERR(master->core_rst)) >> + return PTR_ERR(master->core_rst); >> + >> + ret = clk_prepare_enable(master->core_clk); >> + if (ret) >> + goto err_disable_core_clk; >> + >> + reset_control_deassert(master->core_rst); >> + >> + spin_lock_init(&master->xferqueue.lock); >> + INIT_LIST_HEAD(&master->xferqueue.list); >> + >> + writel(INTR_ALL, master->regs + INTR_STATUS); >> + irq = platform_get_irq(pdev, 0); >> + ret = devm_request_irq(&pdev->dev, irq, >> + dw_i3c_master_irq_handler, 0, >> + dev_name(&pdev->dev), master); >> + if (ret) >> + goto err_assert_rst; >> + >> + platform_set_drvdata(pdev, master); >> + >> + ret = readl(master->regs + QUEUE_STATUS_LEVEL); >> + master->caps.cmdfifodepth = QUEUE_STATUS_LEVEL_CMD(ret); >> + >> + ret = readl(master->regs + DATA_BUFFER_STATUS_LEVEL); >> + master->caps.datafifodepth = DATA_BUFFER_STATUS_LEVEL_TX(ret); >> + >> + ret = readl(master->regs + DEVICE_ADDR_TABLE_POINTER); >> + master->datstartaddr = ret; >> + master->maxdevs = ret >> 16; >> + master->free_pos = GENMASK(master->maxdevs - 1, 0); >> + >> + /* read controller version */ >> + ret = readl(master->regs + I3C_VER_ID); >> + master->version[0] = (char)(ret >> 24); >> + master->version[1] = '.'; >> + master->version[2] = (char)(ret >> 16); >> + master->version[3] = (char)(ret >> 8); >> + master->version[4] = '\0'; >> + >> + /* read controller type */ >> + ret = readl(master->regs + I3C_VER_TYPE); >> + master->type[0] = (char)(ret >> 24); >> + master->type[1] = (char)(ret >> 16); >> + master->type[2] = (char)(ret >> 8); >> + master->type[3] = (char) ret; >> + master->type[4] = '\0'; > Hm, do you really intend to read these as strings? If you do, maybe you > can use sprintf() here: > > sprintf(master->version, "%c.%c%c", ...) > sprintf(master->type, "%c%c%c%c", ...) Maybe this information is unnecessary. I will remove it. > > >> + >> + ret = i3c_master_register(&master->base, &pdev->dev, >> + &dw_mipi_i3c_ops, false); >> + if (ret) >> + goto err_assert_rst; >> + >> + dev_info(&pdev->dev, "Synopsys DW MIPI I3C Master: version %s-%s\n", >> + master->version, master->type); >> + >> + return 0; >> + >> +err_assert_rst: >> + reset_control_assert(master->core_rst); >> + >> +err_disable_core_clk: >> + clk_disable_unprepare(master->core_clk); >> + >> + return ret; >> +} > The driver looks pretty good already, and I'm pleasantly surprised to > see that the Synopsys IP works pretty much the same way the Cadence one > does. I could find some of the logic I implemented in the Cadence > driver almost directly applied to this one, so I think there's room for > code factorization. Anyway, let's see what the next controller looks > like before doing that. > > Thanks for sharing your work early and for reviewing the previous > versions of the I3C patchset. > > Regards, > > Boris I tried to not reinvent the wheel. Right now the test with I3C devices are running very well. I still have one or another detail that can be optimize. Thanks for your feedback. Best regards, Vitor Soares