qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Alistair Francis <alistair.francis@xilinx.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Andrey Smirnov <andrew.smirnov@gmail.com>,
	Igor Mitsyanko <i.mitsyanko@gmail.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org,
	"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>,
	"Sai Pavan Boddu" <saipava@xilinx.com>,
	"Clement Deschamps" <clement.deschamps@antfield.fr>,
	"Jean-Christophe Dubois" <jcd@tribudubois.net>,
	"Grégory Estrade" <gregory.estrade@gmail.com>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Andrew Baumann" <Andrew.Baumann@microsoft.com>,
	"Prasad J Pandit" <pjp@fedoraproject.org>,
	"Peter Crosthwaite" <crosthwaite.peter@gmail.com>,
	qemu-arm@nongnu.org
Subject: [Qemu-devel] [PATCH v6 04/21] sdhci: add clock capabilities (Spec v1)
Date: Thu, 11 Jan 2018 17:56:09 -0300	[thread overview]
Message-ID: <20180111205626.23291-5-f4bug@amsat.org> (raw)
In-Reply-To: <20180111205626.23291-1-f4bug@amsat.org>

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/sd/sdhci.h |  2 ++
 hw/sd/sdhci.c         | 53 ++++++++++++++++++++++++++++++++-------------------
 2 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h
index b61953f7c5..b5b4e411ff 100644
--- a/include/hw/sd/sdhci.h
+++ b/include/hw/sd/sdhci.h
@@ -93,6 +93,8 @@ typedef struct SDHCIState {
     bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */
     uint8_t spec_version;
     struct {
+        uint8_t timeout_clk_freq, base_clk_freq_mhz;
+        bool timeout_clk_in_mhz;
         uint16_t max_blk_len;
         bool suspend;
         bool high_speed;
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 54c1411d19..4c1fcf2c32 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -46,36 +46,32 @@
 #define SDHC_CAPAB_64BITBUS       0ul        /* 64-bit System Bus Support */
 #define SDHC_CAPAB_ADMA1          1ul        /* ADMA1 support */
 #define SDHC_CAPAB_ADMA2          1ul        /* ADMA2 support */
-/* Maximum clock frequency for SDclock in MHz
- * value in range 10-63 MHz, 0 - not defined */
-#define SDHC_CAPAB_BASECLKFREQ    52ul
-#define SDHC_CAPAB_TOUNIT         1ul  /* Timeout clock unit 0 - kHz, 1 - MHz */
-/* Timeout clock frequency 1-63, 0 - not defined */
-#define SDHC_CAPAB_TOCLKFREQ      52ul
 
 /* Now check all parameters and calculate CAPABILITIES REGISTER value */
-#if SDHC_CAPAB_64BITBUS > 1 || SDHC_CAPAB_ADMA2 > 1 || SDHC_CAPAB_ADMA1 > 1 || \
-    SDHC_CAPAB_TOUNIT > 1
+#if SDHC_CAPAB_64BITBUS > 1 || SDHC_CAPAB_ADMA2 > 1 || SDHC_CAPAB_ADMA1 > 1
 #error Capabilities features can have value 0 or 1 only!
 #endif
 
-#if (SDHC_CAPAB_BASECLKFREQ > 0 && SDHC_CAPAB_BASECLKFREQ < 10) || \
-    SDHC_CAPAB_BASECLKFREQ > 63
-#error SDclock frequency can have value in range 0, 10-63 only!
-#endif
-
-#if SDHC_CAPAB_TOCLKFREQ > 63
-#error Timeout clock frequency can have value in range 0-63 only!
-#endif
-
 #define SDHC_CAPAB_REG_DEFAULT                                 \
    ((SDHC_CAPAB_64BITBUS << 28) | (SDHC_CAPAB_ADMA1 << 20) |   \
-    (SDHC_CAPAB_ADMA2 << 19) |                                 \
-    (SDHC_CAPAB_BASECLKFREQ << 8) | (SDHC_CAPAB_TOUNIT << 7) | \
-    (SDHC_CAPAB_TOCLKFREQ))
+    (SDHC_CAPAB_ADMA2 << 19))
 
 #define MASKED_WRITE(reg, mask, val)  (reg = (reg & (mask)) | (val))
 
+static void sdhci_check_capab_freq_range(SDHCIState *s, const char *desc,
+                                         uint8_t freq, Error **errp)
+{
+    switch (freq) {
+    case 0:
+    case 10 ... 63:
+        break;
+    default:
+        error_setg(errp, "SD %s clock frequency can have value"
+                   "in range 0-63 only", desc);
+        return;
+    }
+}
+
 static void sdhci_init_capareg(SDHCIState *s, Error **errp)
 {
     uint64_t capareg = 0;
@@ -86,6 +82,16 @@ static void sdhci_init_capareg(SDHCIState *s, Error **errp)
 
     /* fallback */
     case 1:
+        sdhci_check_capab_freq_range(s, "Timeout", s->cap.timeout_clk_freq,
+                                     errp);
+        capareg = FIELD_DP64(capareg, SDHC_CAPAB, TOCLKFREQ,
+                             s->cap.timeout_clk_freq);
+        sdhci_check_capab_freq_range(s, "Base", s->cap.base_clk_freq_mhz, errp);
+        capareg = FIELD_DP64(capareg, SDHC_CAPAB, BASECLKFREQ,
+                             s->cap.base_clk_freq_mhz);
+        capareg = FIELD_DP64(capareg, SDHC_CAPAB, TOUNIT,
+                             s->cap.timeout_clk_in_mhz);
+
         val = ctz32(s->cap.max_blk_len >> 9);
         if (val >= 0b11) {
             error_setg(errp, "block size can be 512, 1024 or 2048 only");
@@ -1299,6 +1305,13 @@ const VMStateDescription sdhci_vmstate = {
 static Property sdhci_properties[] = {
     DEFINE_PROP_UINT8("sd-spec-version", SDHCIState, spec_version, 2),
 
+    /* Timeout clock frequency 1-63, 0 - not defined */
+    DEFINE_PROP_UINT8("timeout-freq", SDHCIState, cap.timeout_clk_freq, 0),
+    /* Timeout clock unit 0 - kHz, 1 - MHz */
+    DEFINE_PROP_BOOL("freq-in-mhz", SDHCIState, cap.timeout_clk_in_mhz, true),
+    /* Maximum base clock frequency for SD clock in MHz (range 10-63 MHz, 0) */
+    DEFINE_PROP_UINT8("max-frequency", SDHCIState, cap.base_clk_freq_mhz, 0),
+
     /* Maximum host controller R/W buffers size
      * Possible values: 512, 1024, 2048 bytes */
     DEFINE_PROP_UINT16("max-block-length", SDHCIState, cap.max_blk_len, 512),
-- 
2.15.1

  parent reply	other threads:[~2018-01-11 20:57 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-11 20:56 [Qemu-devel] [PATCH v6 00/21] SDHCI: clean Specs v1/v2, implement Spec v3 Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 01/21] sdhci: add a 'spec_version property' (default to v2) Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 02/21] sdhci: add basic Spec v1 capabilities Philippe Mathieu-Daudé
2018-01-13  0:00   ` Alistair Francis
2018-01-13  1:56     ` Philippe Mathieu-Daudé
2018-01-13  2:37       ` [Qemu-devel] [PATCH v6 02/21] sdhci: add basic Spec v1capabilities Alistair
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 03/21] sdhci: add max-block-length capability (Spec v1) Philippe Mathieu-Daudé
2018-01-11 20:56 ` Philippe Mathieu-Daudé [this message]
2018-01-12 23:55   ` [Qemu-devel] [PATCH v6 04/21] sdhci: add clock capabilities " Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 05/21] sdhci: add DMA and 64-bit capabilities (Spec v2) Philippe Mathieu-Daudé
2018-01-13  0:34   ` Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 07/21] sdhci: Fix 64-bit ADMA2 Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 08/21] sdhci: add v3 capabilities Philippe Mathieu-Daudé
     [not found]   ` <CAKmqyKOJ2eL--7o2UyptujNDxHwVVbmG50K39rZAA+VJgxML8w@mail.gmail.com>
2018-01-15  2:43     ` Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 09/21] sdhci: rename the hostctl1 register Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 10/21] hw/arm/exynos4210: implement SDHCI Spec v2 Philippe Mathieu-Daudé
2018-01-13  1:01   ` Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 11/21] hw/arm/xilinx_zynq: " Philippe Mathieu-Daudé
2018-01-16 23:11   ` Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 12/21] hw/arm/bcm2835_peripherals: implement SDHCI Spec v3 Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 13/21] hw/arm/bcm2835_peripherals: change maximum block size to 1kB Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 14/21] hw/arm/fsl-imx6: implement SDHCI Spec v3 Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 15/21] hw/arm/xilinx_zynqmp: " Philippe Mathieu-Daudé
2018-01-13  0:51   ` Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 16/21] sdhci: remove the deprecated 'capareg' property Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 17/21] sdhci: add Spec v4.2 register definitions Philippe Mathieu-Daudé
2018-01-13  1:10   ` Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 18/21] sdhci: implement the Host Control 2 register for the tunning sequence Philippe Mathieu-Daudé
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 19/21] sdbus: add trace events Philippe Mathieu-Daudé
2018-01-13  0:09   ` Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 20/21] sdhci: implement UHS-I voltage switch Philippe Mathieu-Daudé
2018-01-16 23:13   ` Alistair Francis
2018-01-11 20:56 ` [Qemu-devel] [PATCH v6 21/21] sdhci: implement CMD/DAT[] fields in the Present State register Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180111205626.23291-5-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=Andrew.Baumann@microsoft.com \
    --cc=alistair.francis@xilinx.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=clement.deschamps@antfield.fr \
    --cc=crosthwaite.peter@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=gregory.estrade@gmail.com \
    --cc=i.mitsyanko@gmail.com \
    --cc=jcd@tribudubois.net \
    --cc=krzk@kernel.org \
    --cc=peter.maydell@linaro.org \
    --cc=pjp@fedoraproject.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=saipava@xilinx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).