From patchwork Mon Sep 15 12:33:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 389339 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 EBB9F14013A for ; Mon, 15 Sep 2014 22:43:18 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9E3B3A7737; Mon, 15 Sep 2014 14:42:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 Ph7qSiNPfwMx; Mon, 15 Sep 2014 14:42:58 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 44965A7A2E; Mon, 15 Sep 2014 14:42:55 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5011AA7A45 for ; Mon, 15 Sep 2014 14:42:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 AGQO6wWXAZaD for ; Mon, 15 Sep 2014 14:42:51 +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-qa0-f73.google.com (mail-qa0-f73.google.com [209.85.216.73]) by theia.denx.de (Postfix) with ESMTPS id 20FD0A7A78 for ; Mon, 15 Sep 2014 14:42:09 +0200 (CEST) Received: by mail-qa0-f73.google.com with SMTP id v10so374765qac.0 for ; Mon, 15 Sep 2014 05:42:06 -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=pBNDelTiG/v4PtlZZV6zQ0NbHBgK729T/tBHwSH0smY=; b=QBonf6NiAbojB58hPltc1Kzf+dmBiTiPIfHJZB8hjgEpc+P0K5gefmNfSlB0qaB4Vb vGoMlIZT3zRaWR/okkwrkofEnBTCqzlVJmc2WwQkcvnNbRLmNwMfSRFGqVfGzNh8MoGu yMJ6IoqHXp5YO2L+ecLBlwB+b3URPqBkHRqzVQ32ktxSWpPtBWBbXh2B8z4+dGbVx5xY EW/yPZQBjmbBo9KrWGM1e34IjuibwmmVF+BNzbmu+g1ti8GWEhavm7tk6xTgMBsinJlj 6jghKvSFtWmrZTKqc51buf+u8497IVWl1xrtqvcaZ7hae/nnQEoLdOXN9fPMds4Vj8mk UWBg== X-Gm-Message-State: ALoCoQk0tjMSuTus+Bn3/LTOvErIy7R2f8TpTtKTHsi2G+RkI38+NAAXQ/gbkI9Qg3c2BMmOICCO X-Received: by 10.236.222.166 with SMTP id t36mr15108982yhp.24.1410784449162; Mon, 15 Sep 2014 05:34:09 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n24si531530yha.6.2014.09.15.05.34.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Sep 2014 05:34:09 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id oeo5ry3n.3; Mon, 15 Sep 2014 05:34:09 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 2F756224A38; Mon, 15 Sep 2014 06:34:08 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 15 Sep 2014 06:33:47 -0600 Message-Id: <1410784427-23909-31-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1410784427-23909-1-git-send-email-sjg@chromium.org> References: <1410784427-23909-1-git-send-email-sjg@chromium.org> Cc: u-boot-review@google.com, Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v2 30/30] dm: exynos: cros_ec: Move cros_ec_spi to driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 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 this driver to use driver model and move smdk5420 boards over to use it. Signed-off-by: Simon Glass --- Changes in v2: None drivers/misc/cros_ec_spi.c | 68 +++++++++++++++++++++++++++++++++++++++------ include/configs/peach-pit.h | 1 + 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/drivers/misc/cros_ec_spi.c b/drivers/misc/cros_ec_spi.c index 015333f..89616ce 100644 --- a/drivers/misc/cros_ec_spi.c +++ b/drivers/misc/cros_ec_spi.c @@ -15,23 +15,34 @@ #include #include +#include +#include #include +DECLARE_GLOBAL_DATA_PTR; + +#ifdef CONFIG_DM_CROS_EC +int cros_ec_spi_packet(struct udevice *udev, int out_bytes, int in_bytes) +{ + struct cros_ec_dev *dev = udev->uclass_priv; +#else int cros_ec_spi_packet(struct cros_ec_dev *dev, int out_bytes, int in_bytes) { +#endif + struct spi_slave *slave = dev_get_parentdata(dev->dev); int rv; /* Do the transfer */ - if (spi_claim_bus(dev->spi)) { + if (spi_claim_bus(slave)) { debug("%s: Cannot claim SPI bus\n", __func__); return -1; } - rv = spi_xfer(dev->spi, max(out_bytes, in_bytes) * 8, + rv = spi_xfer(slave, max(out_bytes, in_bytes) * 8, dev->dout, dev->din, SPI_XFER_BEGIN | SPI_XFER_END); - spi_release_bus(dev->spi); + spi_release_bus(slave); if (rv) { debug("%s: Cannot complete SPI transfer\n", __func__); @@ -56,10 +67,19 @@ int cros_ec_spi_packet(struct cros_ec_dev *dev, int out_bytes, int in_bytes) * @param din_len Maximum size of response in bytes * @return number of bytes in response, or -1 on error */ +#ifdef CONFIG_DM_CROS_EC +int cros_ec_spi_command(struct udevice *udev, uint8_t cmd, int cmd_version, + const uint8_t *dout, int dout_len, + uint8_t **dinp, int din_len) +{ + struct cros_ec_dev *dev = udev->uclass_priv; +#else int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, const uint8_t *dout, int dout_len, uint8_t **dinp, int din_len) { +#endif + struct spi_slave *slave = dev_get_parentdata(dev->dev); int in_bytes = din_len + 4; /* status, length, checksum, trailer */ uint8_t *out; uint8_t *p; @@ -92,7 +112,7 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, */ memset(dev->din, '\0', in_bytes); - if (spi_claim_bus(dev->spi)) { + if (spi_claim_bus(slave)) { debug("%s: Cannot claim SPI bus\n", __func__); return -1; } @@ -113,10 +133,10 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, p = dev->din + sizeof(int64_t) - 2; len = dout_len + 4; cros_ec_dump_data("out", cmd, out, len); - rv = spi_xfer(dev->spi, max(len, in_bytes) * 8, out, p, + rv = spi_xfer(slave, max(len, in_bytes) * 8, out, p, SPI_XFER_BEGIN | SPI_XFER_END); - spi_release_bus(dev->spi); + spi_release_bus(slave); if (rv) { debug("%s: Cannot complete SPI transfer\n", __func__); @@ -146,6 +166,7 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, return len; } +#ifndef CONFIG_DM_CROS_EC int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob) { /* Decode interface-specific FDT params */ @@ -165,11 +186,40 @@ int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob) */ int cros_ec_spi_init(struct cros_ec_dev *dev, const void *blob) { - dev->spi = spi_setup_slave_fdt(blob, dev->node, dev->parent_node); - if (!dev->spi) { + int ret; + + ret = spi_setup_slave_fdt(blob, dev->node, dev->parent_node, + &slave); + if (ret) { debug("%s: Could not setup SPI slave\n", __func__); - return -1; + return ret; } return 0; } +#endif + +#ifdef CONFIG_DM_CROS_EC +int cros_ec_probe(struct udevice *dev) +{ + return cros_ec_register(dev); +} + +struct dm_cros_ec_ops cros_ec_ops = { + .packet = cros_ec_spi_packet, + .command = cros_ec_spi_command, +}; + +static const struct udevice_id cros_ec_ids[] = { + { .compatible = "google,cros-ec" }, + { } +}; + +U_BOOT_DRIVER(cros_ec_spi) = { + .name = "cros_ec", + .id = UCLASS_CROS_EC, + .of_match = cros_ec_ids, + .probe = cros_ec_probe, + .ops = &cros_ec_ops, +}; +#endif diff --git a/include/configs/peach-pit.h b/include/configs/peach-pit.h index 0bf9e53..9df8538 100644 --- a/include/configs/peach-pit.h +++ b/include/configs/peach-pit.h @@ -41,6 +41,7 @@ #define CONFIG_POWER_TPS65090_EC #define CONFIG_CROS_EC_SPI /* Support CROS_EC over SPI */ +#define CONFIG_DM_CROS_EC #define CONFIG_USB_XHCI #define CONFIG_USB_XHCI_EXYNOS