From patchwork Wed Jan 18 05:51:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 716518 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3v3GRC1JwCz9sDF for ; Wed, 18 Jan 2017 16:55:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="GZ0meOJy"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D5DF1B3996; Wed, 18 Jan 2017 06:54:06 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KPZLRWR9Bl3Q; Wed, 18 Jan 2017 06:54:06 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7DECCB3969; Wed, 18 Jan 2017 06:53:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7A403B3958 for ; Wed, 18 Jan 2017 06:53:05 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YSohRU8EyssM for ; Wed, 18 Jan 2017 06:53:05 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ot0-f173.google.com (mail-ot0-f173.google.com [74.125.82.173]) by theia.denx.de (Postfix) with ESMTPS id 3D046B3948 for ; Wed, 18 Jan 2017 06:52:46 +0100 (CET) Received: by mail-ot0-f173.google.com with SMTP id 73so2301213otj.0 for ; Tue, 17 Jan 2017 21:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=rBT/LjT1FK1LGywZN79wA4mITD23UPUz58uGjDoaLf0=; b=GZ0meOJyofQ7yX2bMr2/NWE8vdpYRWvKfUASAkDb0/72I2Mvm175tDzDh1CxlvIEI0 H2daBb7Ypylfdcmep7ylLxzCy03XffsL3X62upezqhQki2NqJLy8pnENZJGITROBmcP6 8sacrMlE0PTvRO/50GVu53li9zzT4/AvgoiQW8vWkMRcSJ+2P52/fJ4/CxMtKr3n6kEx AzF9PMYhxJLSyx0vsykce/SGPW/L3HWk5HHS/4XxicVpMBLihROpgiuVM+MKfxy3M0an CwknBySAGEhvFw4PiyGNjAFSh1fw0Jyy/GwK2teXA+TFWLqwSKkmRnVllJ6oYxGBPr/j jCjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=rBT/LjT1FK1LGywZN79wA4mITD23UPUz58uGjDoaLf0=; b=mOT92e7CfVMz8YPF4el/33HIJUEm6d7tUo+4B2uE9tohZBGzwJ0MFb3yeYWDmgW8Qh woEJbg9hBrTQCs2//UUwFT4hfvqPKzHajcqL846hMeSb6TUbnnUZm7qrb+G7uoMzB86D kKXrV8SKaQ5V5WhUILK7GVtCNqxIgLqtpQPOJABMT38SwrvSqB9RWY9TyqglzDRlB9Tn FUvgRoon+mQ0MdrZ9vM4oCTs+hiIVN3smwSleqvzbcqd929phlsNB4zw1Kr9LQlLHC9B 7jJ5lqqImAAB3y+XDv9YZiSP///vJJ41UhjREpDVQSmX8bRWx81Bk4JX20eoVMBhBgNa vUXg== X-Gm-Message-State: AIkVDXKYl/ssyQXTbOmMDF73XhOqySgfmgmv1tiMCW48fIlkSUVEXHPQS+c+VLH7O7oxMn2p X-Received: by 10.157.12.198 with SMTP id o6mr938602otd.66.1484718764668; Tue, 17 Jan 2017 21:52:44 -0800 (PST) Received: from kaki.bld.corp.google.com ([100.100.197.46]) by smtp.gmail.com with ESMTPSA id w80sm13807284ota.3.2017.01.17.21.52.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2017 21:52:44 -0800 (PST) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 87CEC40487; Tue, 17 Jan 2017 22:52:43 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Tue, 17 Jan 2017 22:51:57 -0700 Message-Id: <20170118055200.6825-22-sjg@chromium.org> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170118055200.6825-6-sjg@chromium.org> References: <20170118055200.6825-6-sjg@chromium.org> Cc: Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH 21/22] cros_ec: Convert to support live tree X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Convert this driver to support the live device tree and remove the old fdtdec support. The keyboard is not yet converted. Signed-off-by: Simon Glass --- drivers/misc/cros_ec.c | 33 +++++++++++++++------------------ drivers/misc/cros_ec_sandbox.c | 2 +- include/cros_ec.h | 8 +++----- include/fdtdec.h | 34 ---------------------------------- lib/fdtdec.c | 32 -------------------------------- 5 files changed, 19 insertions(+), 90 deletions(-) diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index e2027ea5d20..624a9992b91 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include #include #ifdef DEBUG_TRACE @@ -996,15 +999,12 @@ int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state) int cros_ec_register(struct udevice *dev) { struct cros_ec_dev *cdev = dev_get_uclass_priv(dev); - const void *blob = gd->fdt_blob; - int node = dev_of_offset(dev); char id[MSG_BYTES]; cdev->dev = dev; gpio_request_by_name(dev, "ec-interrupt", 0, &cdev->ec_int, GPIOD_IS_IN); - cdev->optimise_flash_write = fdtdec_get_bool(blob, node, - "optimise-flash-write"); + cdev->optimise_flash_write = dev_read_bool(dev, "optimise-flash-write"); if (cros_ec_check_version(cdev)) { debug("%s: Could not detect CROS-EC version\n", __func__); @@ -1023,28 +1023,26 @@ int cros_ec_register(struct udevice *dev) return 0; } -int cros_ec_decode_ec_flash(const void *blob, int node, - struct fdt_cros_ec *config) +int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config) { - int flash_node; + of_node_ref flash_node, node; - flash_node = fdt_subnode_offset(blob, node, "flash"); - if (flash_node < 0) { + flash_node = dev_find_subnode(dev, "flash"); + if (!of_ref_valid(flash_node)) { debug("Failed to find flash node\n"); return -1; } - if (fdtdec_read_fmap_entry(blob, flash_node, "flash", - &config->flash)) { + if (of_read_fmap_entry(flash_node, "flash", &config->flash)) { debug("Failed to decode flash node in chrome-ec'\n"); return -1; } - config->flash_erase_value = fdtdec_get_int(blob, flash_node, - "erase-value", -1); - for (node = fdt_first_subnode(blob, flash_node); node >= 0; - node = fdt_next_subnode(blob, node)) { - const char *name = fdt_get_name(blob, node, NULL); + config->flash_erase_value = of_ref_read_s32_default(flash_node, + "erase-value", -1); + for (node = of_ref_first_subnode(flash_node); of_ref_valid(node); + node = of_ref_next_subnode(node)) { + const char *name = of_ref_get_name(node); enum ec_flash_region region; if (0 == strcmp(name, "ro")) { @@ -1058,8 +1056,7 @@ int cros_ec_decode_ec_flash(const void *blob, int node, return -1; } - if (fdtdec_read_fmap_entry(blob, node, "reg", - &config->region[region])) { + if (of_read_fmap_entry(node, "reg", &config->region[region])) { debug("Failed to decode flash region in chrome-ec'\n"); return -1; } diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 848c67bc230..367e42d4eb3 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -522,7 +522,7 @@ int cros_ec_probe(struct udevice *dev) int err; memcpy(ec, &s_state, sizeof(*ec)); - err = cros_ec_decode_ec_flash(blob, dev_of_offset(dev), &ec->ec_config); + err = cros_ec_decode_ec_flash(dev, &ec->ec_config); if (err) return err; diff --git a/include/cros_ec.h b/include/cros_ec.h index 0271f2b827c..771a176eeab 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -11,9 +11,9 @@ #include #include -#include #include #include +#include /* Our configuration information */ struct cros_ec_dev { @@ -377,12 +377,10 @@ int cros_ec_get_error(void); /** * Returns information from the FDT about the Chrome EC flash * - * @param blob FDT blob to use - * @param node Node offset to read from + * @param dev Device to read from * @param config Structure to use to return information */ -int cros_ec_decode_ec_flash(const void *blob, int node, - struct fdt_cros_ec *config); +int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config); /** * Check the current keyboard state, in case recovery mode is requested. diff --git a/include/fdtdec.h b/include/fdtdec.h index d074478f141..4a0a5f37f3c 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -807,40 +807,6 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node, int fdtdec_decode_region(const void *blob, int node, const char *prop_name, fdt_addr_t *basep, fdt_size_t *sizep); -enum fmap_compress_t { - FMAP_COMPRESS_NONE, - FMAP_COMPRESS_LZO, -}; - -enum fmap_hash_t { - FMAP_HASH_NONE, - FMAP_HASH_SHA1, - FMAP_HASH_SHA256, -}; - -/* A flash map entry, containing an offset and length */ -struct fmap_entry { - uint32_t offset; - uint32_t length; - uint32_t used; /* Number of bytes used in region */ - enum fmap_compress_t compress_algo; /* Compression type */ - enum fmap_hash_t hash_algo; /* Hash algorithm */ - const uint8_t *hash; /* Hash value */ - int hash_size; /* Hash size */ -}; - -/** - * Read a flash entry from the fdt - * - * @param blob FDT blob - * @param node Offset of node to read - * @param name Name of node being read - * @param entry Place to put offset and size of this node - * @return 0 if ok, -ve on error - */ -int fdtdec_read_fmap_entry(const void *blob, int node, const char *name, - struct fmap_entry *entry); - /** * Obtain an indexed resource from a device property. * diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 81f47ef2c7f..30ee56571ba 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -932,38 +932,6 @@ int fdtdec_decode_region(const void *blob, int node, const char *prop_name, return 0; } -/** - * Read a flash entry from the fdt - * - * @param blob FDT blob - * @param node Offset of node to read - * @param name Name of node being read - * @param entry Place to put offset and size of this node - * @return 0 if ok, -ve on error - */ -int fdtdec_read_fmap_entry(const void *blob, int node, const char *name, - struct fmap_entry *entry) -{ - const char *prop; - u32 reg[2]; - - if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) { - debug("Node '%s' has bad/missing 'reg' property\n", name); - return -FDT_ERR_NOTFOUND; - } - entry->offset = reg[0]; - entry->length = reg[1]; - entry->used = fdtdec_get_int(blob, node, "used", entry->length); - prop = fdt_getprop(blob, node, "compress", NULL); - entry->compress_algo = prop && !strcmp(prop, "lzo") ? - FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE; - prop = fdt_getprop(blob, node, "hash", &entry->hash_size); - entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE; - entry->hash = (uint8_t *)prop; - - return 0; -} - u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells) { u64 number = 0;