From patchwork Mon Sep 29 19:35:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 394600 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 A5ECA1400D5 for ; Tue, 30 Sep 2014 05:39:49 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 70741A7404; Mon, 29 Sep 2014 21:38:59 +0200 (CEST) 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 AGVbuCFzY+nW; Mon, 29 Sep 2014 21:38:59 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7E5E6A746B; Mon, 29 Sep 2014 21:38:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 65BE5A73ED for ; Mon, 29 Sep 2014 21:37:34 +0200 (CEST) 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 SNDT6kJ62PN0 for ; Mon, 29 Sep 2014 21:37:34 +0200 (CEST) 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-ig0-f201.google.com (mail-ig0-f201.google.com [209.85.213.201]) by theia.denx.de (Postfix) with ESMTPS id 7793AA73EF for ; Mon, 29 Sep 2014 21:37:30 +0200 (CEST) Received: by mail-ig0-f201.google.com with SMTP id r10so119719igi.0 for ; Mon, 29 Sep 2014 12:37:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fIHDFYEDUQwCtqrBW1kTO3BKzuSGuSFKNfhhT9WtjBU=; b=cyF5SKQ+E55OWFs53AX8P3tTuj3pQCJY75wVKnj4mhKHscLdQhCdE/Vid9EKioMmf0 6/SEZFZ9HCCElZV5pRmakP8gxcV7TnCAe1SE0Do488r4jKzTTrYyG2hkUQjw94LUK7P4 Ebg8WpKHNJfMEMsaPFsPHt75cCI5h1zUQ5OFm508dCtsFjMN4SkrSWNfditJb1wZZKtd 52kW9/+SH0OmRjC8UUmWArqtK6en7P+O06dkopGzMgkUC8ugaxApnGwPFkSxoqMHeU9g +XLlceuNUQpIKHfep2YJlp1YGfOAbvBbMnYNtN4qvYJgAQ4O4K3nMjmPcA8Tod+443kL 7spw== X-Gm-Message-State: ALoCoQmbszHqypZ7XDjSUa382dMaUCiBwV1BN0v4koJNXHTK09f4i1QqWW4+Yd593GAbZUubLfCD X-Received: by 10.182.251.135 with SMTP id zk7mr36244523obc.14.1412019449610; Mon, 29 Sep 2014 12:37:29 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id t28si771038yhb.4.2014.09.29.12.37.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Sep 2014 12:37:29 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id BH8M62IJ.3; Mon, 29 Sep 2014 12:37:29 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 9CDA822103D; Mon, 29 Sep 2014 13:37:28 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 29 Sep 2014 13:35:25 -0600 Message-Id: <1412019326-6721-29-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1412019326-6721-1-git-send-email-sjg@chromium.org> References: <1412019326-6721-1-git-send-email-sjg@chromium.org> Cc: u-boot-review@google.com, Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v3 28/29] dm: sandbox: cros_ec: Move sandbox cros_ec to driver module X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Adjust the sandbox cros_ec emulation driver to work with driver model, and switch over to driver model for sandbox cros_ec. Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None drivers/misc/cros_ec_sandbox.c | 90 +++++++++++++++++++++++++++++++++++++++--- include/configs/sandbox.h | 1 + 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index 431cf26..99cc529 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -85,7 +86,7 @@ struct ec_state { struct ec_keymatrix_entry *matrix; /* the key matrix info */ uint8_t keyscan[KEYBOARD_COLS]; bool recovery_req; -} s_state, *state; +} s_state, *g_state; /** * cros_ec_read_state() - read the sandbox EC state from the state file @@ -138,7 +139,7 @@ static int cros_ec_read_state(const void *blob, int node) */ static int cros_ec_write_state(void *blob, int node) { - struct ec_state *ec = &s_state; + struct ec_state *ec = g_state; /* We are guaranteed enough space to write basic properties */ fdt_setprop_u32(blob, node, "current-image", ec->current_image); @@ -369,7 +370,7 @@ static int process_cmd(struct ec_state *ec, struct fmap_entry *entry; int ret, size; - entry = &state->ec_config.region[EC_FLASH_REGION_RW]; + entry = &ec->ec_config.region[EC_FLASH_REGION_RW]; switch (req->cmd) { case EC_VBOOT_HASH_RECALC: @@ -426,7 +427,7 @@ static int process_cmd(struct ec_state *ec, case EC_FLASH_REGION_RO: case EC_FLASH_REGION_RW: case EC_FLASH_REGION_WP_RO: - entry = &state->ec_config.region[req->region]; + entry = &ec->ec_config.region[req->region]; resp->offset = entry->offset; resp->size = entry->length; len = sizeof(*resp); @@ -466,16 +467,24 @@ static int process_cmd(struct ec_state *ec, return len; } +#ifdef CONFIG_DM_CROS_EC +int cros_ec_sandbox_packet(struct udevice *udev, int out_bytes, int in_bytes) +{ + struct cros_ec_dev *dev = udev->uclass_priv; + struct ec_state *ec = dev_get_priv(dev->dev); +#else int cros_ec_sandbox_packet(struct cros_ec_dev *dev, int out_bytes, int in_bytes) { + struct ec_state *ec = &s_state; +#endif struct ec_host_request *req_hdr = (struct ec_host_request *)dev->dout; const void *req_data = req_hdr + 1; struct ec_host_response *resp_hdr = (struct ec_host_response *)dev->din; void *resp_data = resp_hdr + 1; int len; - len = process_cmd(&s_state, req_hdr, req_data, resp_hdr, resp_data); + len = process_cmd(ec, req_hdr, req_data, resp_hdr, resp_data); if (len < 0) return len; @@ -498,7 +507,11 @@ int cros_ec_sandbox_decode_fdt(struct cros_ec_dev *dev, const void *blob) void cros_ec_check_keyboard(struct cros_ec_dev *dev) { +#ifdef CONFIG_DM_CROS_EC + struct ec_state *ec = dev_get_priv(dev->dev); +#else struct ec_state *ec = &s_state; +#endif ulong start; printf("Press keys for EC to detect on reset (ESC=recovery)..."); @@ -512,6 +525,52 @@ void cros_ec_check_keyboard(struct cros_ec_dev *dev) } } +#ifdef CONFIG_DM_CROS_EC +int cros_ec_probe(struct udevice *dev) +{ + struct ec_state *ec = dev->priv; + struct cros_ec_dev *cdev = dev->uclass_priv; + const void *blob = gd->fdt_blob; + int node; + int err; + + memcpy(ec, &s_state, sizeof(*ec)); + err = cros_ec_decode_ec_flash(blob, dev->of_offset, &ec->ec_config); + if (err) + return err; + + node = fdtdec_next_compatible(blob, 0, COMPAT_GOOGLE_CROS_EC_KEYB); + if (node < 0) { + debug("%s: No cros_ec keyboard found\n", __func__); + } else if (keyscan_read_fdt_matrix(ec, blob, node)) { + debug("%s: Could not read key matrix\n", __func__); + return -1; + } + + /* If we loaded EC data, check that the length matches */ + if (ec->flash_data && + ec->flash_data_len != ec->ec_config.flash.length) { + printf("EC data length is %x, expected %x, discarding data\n", + ec->flash_data_len, ec->ec_config.flash.length); + os_free(ec->flash_data); + ec->flash_data = NULL; + } + + /* Otherwise allocate the memory */ + if (!ec->flash_data) { + ec->flash_data_len = ec->ec_config.flash.length; + ec->flash_data = os_malloc(ec->flash_data_len); + if (!ec->flash_data) + return -ENOMEM; + } + + cdev->dev = dev; + g_state = ec; + return cros_ec_register(dev); +} + +#else + /** * Initialize sandbox EC emulation. * @@ -562,3 +621,24 @@ int cros_ec_sandbox_init(struct cros_ec_dev *dev, const void *blob) return 0; } +#endif + +#ifdef CONFIG_DM_CROS_EC +struct dm_cros_ec_ops cros_ec_ops = { + .packet = cros_ec_sandbox_packet, +}; + +static const struct udevice_id cros_ec_ids[] = { + { .compatible = "google,cros-ec" }, + { } +}; + +U_BOOT_DRIVER(cros_ec_sandbox) = { + .name = "cros_ec", + .id = UCLASS_CROS_EC, + .of_match = cros_ec_ids, + .probe = cros_ec_probe, + .priv_auto_alloc_size = sizeof(struct ec_state), + .ops = &cros_ec_ops, +}; +#endif diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 9adc5cc..2fd2c64 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -32,6 +32,7 @@ #define CONFIG_DM_GPIO #define CONFIG_DM_TEST #define CONFIG_DM_SERIAL +#define CONFIG_DM_CROS_EC #define CONFIG_SYS_STDIO_DEREGISTER