Received: by 2002:ac2:4c26:0:0:0:0:0 with SMTP id u6csp3260626lfq; Sat, 10 Oct 2020 08:53:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVCyMEx8BAaAb7vVl6l998vuJH8OQ7uUU8PjOfSc1LQbEBiVf0uIkpluZ0FZ5PUTa3miBp X-Received: by 2002:a25:c42:: with SMTP id 63mr22291708ybm.1.1602345199864; Sat, 10 Oct 2020 08:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602345199; cv=none; d=google.com; s=arc-20160816; b=0+x/akHWzyhWhCEb/Tfml7uC+04VZ2EKC0ZcbmYDgoIHSUYek2LC0+WcgCbbiuh3SG D3npY7gwUAiDhctwXpTgaYO1ZD2MxWgBgawwwQPvQyc3H2FjfyQl+rwqqTQrkJzB3ULH fxjfp6ctFJgTuAPyRRAzyAv8Cx4hQlRoq3VuOjqMHdlA8BmMU3YPNLnpYvPKGJy4zG5B 1yqi68A3xL8dr9QN3bW8iKhgR/oTkrM9roCd2t6SqvhrLz5JlE3zJ0jJW54atGiIZ0p+ Mzufw3hZ1RWaLKxM4HBhadermAIBMY2FwGqEQ1DhtXK/oSu9cnU7eVy6jIZQgl8oduVN h2tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=/QHDCV4CWgR0KOs1XcYCTat3K8XrMJmcbkD0TAxTnDY=; b=hcTH+ThIiPzqURkEA/oneMx2KFLeE7OzR/BRgSJY4Jueepm0XiwTnqQmrhkCCPBdww 06NcST6nB15srkPdL9R6EFtZA2ph0iwtMZac6/LMknRJbUoEoggUf1ijf4nBjTt3s6NM VV+rjRI/RLDiY46nwlJVHeIAyzw1e5Gdy5nl3ucUYPzD0Gk4Wk85CZijt1YwZ5sWlMiO RadI4rNkzUXz5sZNmeaJUHd1J16zv77iAJtTrqgE4VauQguDudfj/IfuMDkIHvsYSfcu 9bG9F+bjdL3pEjgDoV7s4SdIHrq5Z4a7CdoNqHOET6HDajXJaLzNtxoBH+hK35vV4Xu/ DwTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=c1qLZlLx; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amsat.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s126si738336ybc.95.2020.10.10.08.53.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 10 Oct 2020 08:53:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=c1qLZlLx; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amsat.org Received: from localhost ([::1]:34914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRHBP-0008CK-AZ for alex.bennee@linaro.org; Sat, 10 Oct 2020 11:53:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRHBA-0008C1-2P; Sat, 10 Oct 2020 11:53:04 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:40177) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kRHB5-0001rL-Kt; Sat, 10 Oct 2020 11:53:03 -0400 Received: by mail-wr1-x441.google.com with SMTP id h5so3403318wrv.7; Sat, 10 Oct 2020 08:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/QHDCV4CWgR0KOs1XcYCTat3K8XrMJmcbkD0TAxTnDY=; b=c1qLZlLxT9hjTX4mDSBonTbec1o+lAyJG0zd3pyrptnouLbMVXEgJyp/si14+tpQgU 2zroSP7o64bV7n0VPqTf4qaIm8H7ImcGhFxbODpvD8rcsPk8EsgkI4I9eE1u2yAV2F/J 6lQrMRNNe4q0DnJcBTwrutkiikN5q9AG3Lm84sRCv0fgcod/2Ot6wh9+iZWqF8ANymC5 W8wVAHKdGkOYYyv2AUMmx8IwhfbJ+uNz+TFLaZcMS4OcbkSy8XOZIH2tnbtTOSzse3Jf /5j97zwVnM0zo4rPCaTtiOGk0wJoAoTdLTakT7z/JWx9fC0AG6gmCnmMsITb17ScDGvX KWwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/QHDCV4CWgR0KOs1XcYCTat3K8XrMJmcbkD0TAxTnDY=; b=N3X/1et9Q6IpAFpwci8EVBl30X0yVgITpGRMwlJ4icsOJC76t+x307moW0Il3WWlcm WKv6wMzoCyL7Am8nZuT5fmM1DfCjdf4H4Ic8AKif5g4lFjs+PT5Z1B/Qx5AwAFNhtys4 ZmA/JM/2u6JMWbXSoHp8ejerrzLdTESS3t2JNj5+rZzLSlW3amZM4QBYuNxJqzq+rxgX 6u3zPLUQGyno8kxoOTGmuZmdta+oEGa0+bYDmk8mUQQ28EgP9fd0ldcEeETrojxsS6iF WEwo3t8R58BuqACgUpUxiehnIBiHPEjcg4vEha1aWqntrg+alBZsRYuzr/l6B3ORjOOg YHIw== X-Gm-Message-State: AOAM530DsEJaqzovOFBJzP0Ml4ZufXMvz2Wx5OAtdSYGfNVPjIyV4w1P /2v5PCzmkQVc51lrZl6RfwY= X-Received: by 2002:adf:e94b:: with SMTP id m11mr20026163wrn.35.1602345177946; Sat, 10 Oct 2020 08:52:57 -0700 (PDT) Received: from [192.168.1.36] (106.red-83-59-162.dynamicip.rima-tde.net. [83.59.162.106]) by smtp.gmail.com with ESMTPSA id c1sm17196460wru.49.2020.10.10.08.52.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Oct 2020 08:52:57 -0700 (PDT) Subject: Re: [PATCH v3 11/15] hw/misc/bcm2835_cprman: implement clock mux behaviour To: Luc Michel , qemu-devel@nongnu.org References: <20201010135759.437903-1-luc@lmichel.fr> <20201010135759.437903-12-luc@lmichel.fr> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: <6982aced-ca14-73bf-48ff-7f739f2c389a@amsat.org> Date: Sat, 10 Oct 2020 17:52:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20201010135759.437903-12-luc@lmichel.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.207, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Havard Skinnemoen , Andrew Baumann , Paul Zimmerman , Niek Linnenbank , qemu-arm@nongnu.org Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: 6DR5QIirehPv On 10/10/20 3:57 PM, Luc Michel wrote: > A clock mux can be configured to select one of its 10 sources through > the CM_CTL register. It also embeds yet another clock divider, composed > of an integer part and a fractional part. The number of bits of each > part is mux dependent. > > Tested-by: Philippe Mathieu-Daudé > Signed-off-by: Luc Michel > --- > hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- > 1 file changed, 52 insertions(+), 1 deletion(-) > > diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c > index b22170f3bc..919a55aa23 100644 > --- a/hw/misc/bcm2835_cprman.c > +++ b/hw/misc/bcm2835_cprman.c > @@ -229,19 +229,70 @@ static const TypeInfo cprman_pll_channel_info = { > }; > > > /* clock mux */ > > +static bool clock_mux_is_enabled(CprmanClockMuxState *mux) > +{ > + return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE); > +} > + > static void clock_mux_update(CprmanClockMuxState *mux) > { > - clock_update(mux->out, 0); > + uint64_t freq; > + uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC); > + bool enabled = clock_mux_is_enabled(mux); > + > + *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled); > + > + if (!enabled) { > + clock_update(mux->out, 0); > + return; > + } > + > + freq = clock_get_hz(mux->srcs[src]); > + > + if (mux->int_bits == 0 && mux->frac_bits == 0) { > + clock_update_hz(mux->out, freq); > + return; > + } > + > + /* > + * The divider has an integer and a fractional part. The size of each part > + * varies with the muxes (int_bits and frac_bits). Both parts are > + * concatenated, with the integer part always starting at bit 12. > + * > + * 31 12 11 0 > + * ------------------------------ > + * CM_DIV | | int | frac | | > + * ------------------------------ > + * <-----> <------> > + * int_bits frac_bits > + */ > + div = extract32(*mux->reg_div, > + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, > + mux->int_bits + mux->frac_bits); > + > + if (!div) { > + clock_update(mux->out, 0); > + return; > + } > + > + freq = muldiv64(freq, 1 << mux->frac_bits, div); > + > + clock_update_hz(mux->out, freq); > } Much nicer now, thanks :) Reviewed-by: Philippe Mathieu-Daudé > > static void clock_mux_src_update(void *opaque) > { > CprmanClockMuxState **backref = opaque; > CprmanClockMuxState *s = *backref; > + CprmanClockMuxSource src = backref - s->backref; > + > + if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) { > + return; > + } > > clock_mux_update(s); > } > > static void clock_mux_init(Object *obj) >