Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2656863pxu; Mon, 14 Dec 2020 07:52:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpiq+DOPMeZl7DlYPXvZZUiAokOs0DBehjurJv8QWMSXNnjTjZffOjulrk8so33QaWdDwK X-Received: by 2002:a17:906:1db2:: with SMTP id u18mr3483368ejh.440.1607961167008; Mon, 14 Dec 2020 07:52:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607961167; cv=none; d=google.com; s=arc-20160816; b=u8L7OdmL54Zy6jsSv5qg4m3EfL1NO/AQqy4H6/V3scF1vZz/kbBdqC7N3PBF6+QKmS /31vB3Df/mzxKRW7pjVUyOtoOm5k3rUQhFY1Ood0EhpxjSqyon9XQhoo1CZb/ByTTOIA IaniNTWeyo3oH/RNLum+Z5BbqCgz1E/8/TF38zdQJHlj3fkcmWBuC2W/6Rg9cIey6GiZ BWJrb8j2bvKzo1UJ//qakoLVRt5JGs0DaV3in/WnYyRQOk/+LvCDZdsM/vILzo6xs1QI rof5TCRaKu7PhzXAQZUGSFnB3wpC/v/R7MDvGVe9ACwXWhko7u0x7BGwYg7veNZbjPI2 +QMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KvO0sb07TDmRwegOoF9S5e6D5LMN7XTNc/ZFX2Y5vi4=; b=ApoEbWHBhPtA6IwxKyf2S7QoHpt5w/L0rOAne8shQniAv6l02G7D3Nly5XD3h83pA2 yI9leavmZleL6oUvm5/2uU88kq1j8KVTY1wl1h9nGalP7hJyCYjLsV9gHCZ+PN6AM2iL pGfGFBljH3tK3WxVx/OThVZAEwzwof8uuEMaLIdJ6AyHKAxkhVE1Xwx8ctDNxMy+t9mM MEG9Hb0efIL7uml0DNaXrvZSNFNzE8QsNofgtQ7mwyMyYFf/f61jMFCVIT88OPolgvQ3 wuhIzMlQ8ST9FMT97ZxvevewLd29Vr/BbcDH622QqbP1WkKWu45HuxXNDqEG/AdFcztV 2dKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e31mRl3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si13129371edi.312.2020.12.14.07.52.21; Mon, 14 Dec 2020 07:52:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e31mRl3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388406AbgLNPuN (ORCPT + 99 others); Mon, 14 Dec 2020 10:50:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732513AbgLNPuN (ORCPT ); Mon, 14 Dec 2020 10:50:13 -0500 Received: from mail-vs1-xe43.google.com (mail-vs1-xe43.google.com [IPv6:2607:f8b0:4864:20::e43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A5CCC061793 for ; Mon, 14 Dec 2020 07:49:33 -0800 (PST) Received: by mail-vs1-xe43.google.com with SMTP id b23so9187862vsp.9 for ; Mon, 14 Dec 2020 07:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KvO0sb07TDmRwegOoF9S5e6D5LMN7XTNc/ZFX2Y5vi4=; b=e31mRl3iGwwoztxn7fB1r+7GX+JZDHiFrSDXcuX2noyakj/Rsa2UQvMZSgpkHhDQhz /OhDQiCjCYyTS8VKtZPO51Rgh7Qhva7khKek+vh24xQuYnVwLPv79B9BbyCFMu2t9tk7 9Di2/3UEkPhrsYi5JUKM3sWSJYVOz9n6B+nSrb2CKYY05eOhx8u9eVLPyDizCsz1hZ28 b5a2lFQN84VYht8a7ZIAyBWqL2voWZ0secptdIDU2brkyUl/fujqriiBs/hPmah1OkR4 Hipxd9oLz3IIZNxqdFOkWE5EctlepAr41yu5ofxtmW0LMJWSdxmcYjv/iFjIf9AbABPh Duhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KvO0sb07TDmRwegOoF9S5e6D5LMN7XTNc/ZFX2Y5vi4=; b=ZFT8jO057Ivkv3x0PYpzN3VOzrIVzfNLBkB6H3r0vMTG11yp90jQiT9SIdv6kxU6+a RaLGqdQSa4i0FLS1Ergx6UA+S7IQPuRiMJ5PCvHzNazq/0OF0pveFDGVE4mY0JPCEoJx 728hjRxELF3WgaaXk43kb05tXgnO9itXyHlDe3l0SO1YGLBc2zfy5lyJfxJZaygQS1Rc 30OCcWhpg1uejKa6KZfWG1Y6svszEuVj1SJeZYrl/ng4OwkDCno+OnRhnNv7eCotQTLt 0KSSYVgxQ5Sifecbjl/zxE6HAt8F0hyBlBIZIuNbbdU0oAKiTh+gzb1QoShsQPxwr1sS 9MvQ== X-Gm-Message-State: AOAM531Y7tmu8cUGny1rpfMEBPREgcW+xw/WCXHoDuHc0pTthCL9ah4l zHBvSAwbP/taUAuGkDeIoaIs/OUCgiE4jCGmTMWn0Q== X-Received: by 2002:a67:70c6:: with SMTP id l189mr23767784vsc.34.1607960971339; Mon, 14 Dec 2020 07:49:31 -0800 (PST) MIME-Version: 1.0 References: <20201208012615.2717412-1-andrew@aj.id.au> <20201208012615.2717412-2-andrew@aj.id.au> In-Reply-To: <20201208012615.2717412-2-andrew@aj.id.au> From: Ulf Hansson Date: Mon, 14 Dec 2020 16:48:54 +0100 Message-ID: Subject: Re: [PATCH v5 1/6] mmc: core: Add helper for parsing clock phase properties To: Andrew Jeffery Cc: "linux-mmc@vger.kernel.org" , Rob Herring , Joel Stanley , Adrian Hunter , Linux Kernel Mailing List , DTML , Linux ARM , linux-aspeed , ryan_chen@aspeedtech.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 8 Dec 2020 at 02:26, Andrew Jeffery wrote: > > Drivers for MMC hosts that accept phase corrections can take advantage > of the helper by embedding a mmc_clk_phase_map_t object in their > private data and invoking mmc_of_parse_clk_phase() to extract phase > parameters. It is the responsibility of the host driver to translate and > apply the extracted values to hardware as required. > > Signed-off-by: Andrew Jeffery > --- > drivers/mmc/core/host.c | 44 ++++++++++++++++++++++++++++++++++++++++ > include/linux/mmc/host.h | 17 ++++++++++++++++ > 2 files changed, 61 insertions(+) > > diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c > index 96b2ca1f1b06..b1697f00c4b5 100644 > --- a/drivers/mmc/core/host.c > +++ b/drivers/mmc/core/host.c > @@ -163,6 +163,50 @@ static void mmc_retune_timer(struct timer_list *t) > mmc_retune_needed(host); > } > > +static void mmc_of_parse_timing_phase(struct device *dev, const char *prop, > + struct mmc_clk_phase *phase) > +{ > + int degrees[2] = {0}; > + int rc; > + > + rc = device_property_read_u32_array(dev, prop, degrees, 2); > + phase->valid = !rc; > + if (phase->valid) { > + phase->in_deg = degrees[0]; > + phase->out_deg = degrees[1]; > + } > +} > + > +void > +mmc_of_parse_clk_phase(struct mmc_host *host, mmc_clk_phase_map_t map) Would you mind to change to pass a "struct mmc_clk_phase_map *map" to this? See more comments below. > +{ > + struct device *dev = host->parent; > + > + mmc_of_parse_timing_phase(dev, "clk-phase-legacy", > + &map[MMC_TIMING_LEGACY]); > + mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs", > + &map[MMC_TIMING_MMC_HS]); > + mmc_of_parse_timing_phase(dev, "clk-phase-sd-hs", > + &map[MMC_TIMING_SD_HS]); > + mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr12", > + &map[MMC_TIMING_UHS_SDR12]); > + mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr25", > + &map[MMC_TIMING_UHS_SDR25]); > + mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr50", > + &map[MMC_TIMING_UHS_SDR50]); > + mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr104", > + &map[MMC_TIMING_UHS_SDR104]); > + mmc_of_parse_timing_phase(dev, "clk-phase-uhs-ddr50", > + &map[MMC_TIMING_UHS_DDR50]); > + mmc_of_parse_timing_phase(dev, "clk-phase-mmc-ddr52", > + &map[MMC_TIMING_MMC_DDR52]); > + mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs200", > + &map[MMC_TIMING_MMC_HS200]); > + mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs400", > + &map[MMC_TIMING_MMC_HS400]); > +} > +EXPORT_SYMBOL(mmc_of_parse_clk_phase); > + > /** > * mmc_of_parse() - parse host's device-tree node > * @host: host whose node should be parsed. > diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h > index 01bba36545c5..bc4731c9738f 100644 > --- a/include/linux/mmc/host.h > +++ b/include/linux/mmc/host.h > @@ -79,6 +79,22 @@ struct mmc_ios { > bool enhanced_strobe; /* hs400es selection */ > }; > > +struct mmc_clk_phase { > + bool valid; > + u16 in_deg; > + u16 out_deg; > +}; > + > +/* > + * Define a type to map between bus timings and phase correction values. To > + * avoid bloat in struct mmc_host we leave it to the host driver to define the > + * phase map object in its private data if it supports phase correction. > + * However, mmc_of_parse_clk_phase() is provided by the mmc core and needs the > + * provided array to be correctly sized, so typedef an appropriately sized > + * array to minimise the chance that the wrong size object is passed. > + */ > +typedef struct mmc_clk_phase mmc_clk_phase_map_t[MMC_TIMING_MMC_HS400 + 1]; > + Nitpick: I would appreciate if we could avoid using "typedefs", as I think they in many cases makes the code harder to read. How about doing this instead? #define MMC_NUM_CLK_PHASES (MMC_TIMING_MMC_HS400 + 1) struct mmc_clk_phase_map { struct mmc_clk_phase phase[MMC_NUM_CLK_PHASES]; }; [...] Kind regards Uffe