From patchwork Sun Apr 28 20:28:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 334 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 808F13F08F for ; Sun, 28 Apr 2019 22:29:51 +0200 (CEST) Received: by mail-pf1-f197.google.com with SMTP id i23sf6144890pfa.0 for ; Sun, 28 Apr 2019 13:29:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1556483390; cv=pass; d=google.com; s=arc-20160816; b=dZoTboS/6xVXFhm/zxicTAu9JS0+hZTtH6f3VWsxM3dEZv5HIeckBXloSYA7yMlZBr LNjErxyirLAUGUDQgmjFy/qq2wYfEjTzU0xTEpwYjZ/8QuRCVX4IgsvQMT3gg4HtnYqC ioGzWNbNafdesnQF9VwAQ7u3P7N3DeHgcUcgQRpvLiMazv995MOsf9cVGLsp67peh95b 7lVWeMrAPWyZoeFnxqx3ey8shynBffnczEPTiosg3wKbQKtsX5uu3Izy1yK4wSH8E0e0 iXOBQdRATxJIEyw6z5EEjVbVpaKFk95oAfxkT1hXvLFH7poxBfsB1AU7lgmTKkHCn+ls znLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=bfP0/paytEdh2UQwvwobmnMSLuilPn76ORNKNylBbDU=; b=DoMYaVSQUykIC6xhMY6FSF9kjdEPuEBQAVgyilY8Ge00BEadISy3k3/WDkJ8k8mQAU PSiUO716d9y1Rdstm+Na+K93Txs1JcmKQX0j39ecSEN4Lg/9Cd5io9JJ8Eeb4C5wai+p k/01FuHAICPpCoUCK8wW1Ex0CC4xXArBsw+8zdW/Gu5jOFTaIriXyliOQ4hRBiSH867h oWMyqdqOuP+NG60xrbXa5sitL7gSsYj3Tx9NLsuk202a7MH+2drtTcRTeUSoovItWwus QYjZbE+IF2lHDbxfst5Hw1+VPy5XGOKLLK1mEYX/UGOy9BCCXsWy4J4ur0SJ8CRvLmhx cx5w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=N1h6NeEa; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=bfP0/paytEdh2UQwvwobmnMSLuilPn76ORNKNylBbDU=; b=KHgaGweSJj8qgpPvPuyErCVRc7cOqKc4WujkuKe+Kz6q9LH8yitks0kWJkT3+6ID57 E4ephDQ9xdSpGW9uOMx6l29dmhCGi1Ut4FUwbeMWX8aejBwLO3/hCFzpK2ijgBMMyIeN Gn8v1kqBWETARSusFgsDEmlAuINtjeafv09bc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=bfP0/paytEdh2UQwvwobmnMSLuilPn76ORNKNylBbDU=; b=GfzJHEABTUcnJBiCyDZwTgjEjXiDXUEkZ0Ne4o6ARGaWG+l1iik1VtMXcisf2zTzzV MwWbKyoN+9ZzxQ6ztfK76JpDOhNsgF1t7yBDyrtAtTziZ9UBJDrk/TQfN9+p8utWKgYY rePkY3K/RXbVvZxHhYD9gV2nTYX9XoHBp/qfBwHQzCop7ScDCk3SJaahuyQArzTSFYnn V5FjQJ15xBj5pU6p+68IddguQcXqBedPiGkfwEYH9RlpC5nffBPnnXmCGBHjIG/XrXUZ DXK2TCIBvNiaOYratHROBkWxfgSsPOx57e7APb1GkAjYIWX+fOM/uIm7ETczkJt1d4Po yoJg== X-Gm-Message-State: APjAAAVaIZvzVhVOWl9XnXUz9jMIo8nlr4XvW7w1CIzH4sifverxpDJj Jzks+LYgIfWNOtBOzAqMeIoiHKUL X-Google-Smtp-Source: APXvYqyUEKZZyPwkOjjZLzs3yECBMhyIBftTGT1p37qZ4xc8p+27qND6XZ/Z8ypmkygCgZs17Jv4qw== X-Received: by 2002:a63:6604:: with SMTP id a4mr23316487pgc.104.1556483390320; Sun, 28 Apr 2019 13:29:50 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:9f86:: with SMTP id g6ls8388345plq.3.gmail; Sun, 28 Apr 2019 13:29:50 -0700 (PDT) X-Received: by 2002:a17:902:86:: with SMTP id a6mr57642821pla.277.1556483389951; Sun, 28 Apr 2019 13:29:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556483389; cv=none; d=google.com; s=arc-20160816; b=MTLab98tnlo+Q2tCr6QHA/u30AsDkKCQlMKUZWTxYDUJDIsdqND8qLie4iHzuHrvUi WLsPP73FU2tbjoVqs+KkUfMgoXpqryPLry0Twp/lykcMzRyHICmZcz+n29w7wdqaydoj 1VTOMxGLv4VH2tmXksy675nMByWzOfqUWNGiuI9uKeebpl80YxZIE4uoKkwvF6j/ZuWz 12/i08q+uA8zpbnLi4zYkTdo1IYMior16xiFD14pb3c9YPsCJIvDZqGw5OHTlnf7PgH7 edUv7ZsDIkdB/sY4O3FanNZJYdoWaAnbP/dN4RCc9WgdjcX4vFSkHaGo8r1R3R6OYDxx I8wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=VjHrEClNEEFz6xuzS8rY93E6SfSRBp015JRdcaSLA+g=; b=ITCMzctA5rmAlPcieUiyujOxb2vc7eAsZG41UNhis3C1SuZa1olGbt1cjxCPEvZD4K svBHRZlHb2WPtCtfhnhldNBmTxEPNN8cCcdNDvgVZXqb2/xWJJEg1I8PqJ+gzidphxS8 bcWrMjVjBaiayL9aZTurKHOCbWyiG8BnVr6P6H1+nkd2yR8VSYmJfVvn5a8JF1vxyVOe T9ikpSPHRrMEVKiCT494b10VIR9As23Wz8gzXH1k0qqfRBi6HwIAqROzwHwrVy9jlaOj xCNscupmFXrPW2cxiJjOrcgv9rRFRgZVj74dOQoIxkiE6ajRHZ8Dzjst8GX48BW/a2vM k72Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=N1h6NeEa; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id l10sor6701445pgp.56.2019.04.28.13.29.49 for (Google Transport Security); Sun, 28 Apr 2019 13:29:49 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a65:4185:: with SMTP id a5mr54988688pgq.82.1556483389620; Sun, 28 Apr 2019 13:29:49 -0700 (PDT) Received: from localhost.localdomain ([115.97.185.144]) by smtp.gmail.com with ESMTPSA id x66sm68841439pfb.78.2019.04.28.13.29.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Apr 2019 13:29:49 -0700 (PDT) From: Jagan Teki To: Heiko Schocher , Tom Rini Cc: u-boot@lists.denx.de, linux-amarula@amarulasolutions.com, Jagan Teki , Mario Six Subject: [PATCH v2 18/19] spi: mpc8xxx: Convert to DM Date: Mon, 29 Apr 2019 01:58:53 +0530 Message-Id: <20190428202854.8590-19-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190428202854.8590-1-jagan@amarulasolutions.com> References: <20190428202854.8590-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=N1h6NeEa; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Support DM in the MPC8xxx SPI driver, and remove the legacy SPI interface. Signed-off-by: Mario Six Signed-off-by: Jagan Teki --- drivers/spi/Kconfig | 10 +-- drivers/spi/mpc8xxx_spi.c | 144 ++++++++++++++++++++++++++++---------- 2 files changed, 112 insertions(+), 42 deletions(-) diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index fb794adae7..e196f64e2f 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -131,6 +131,11 @@ config MPC8XX_SPI help Enable support for SPI on MPC8XX +config MPC8XXX_SPI + bool "MPC8XXX SPI Driver" + help + Enable support for SPI on the MPC8XXX PowerPC SoCs. + config MT7621_SPI bool "MediaTek MT7621 SPI driver" depends on ARCH_MT7620 @@ -364,11 +369,6 @@ config LPC32XX_SSP help Enable support for SPI on LPC32xx -config MPC8XXX_SPI - bool "MPC8XXX SPI Driver" - help - Enable support for SPI on the MPC8XXX PowerPC SoCs. - config MXC_SPI bool "MXC SPI Driver" help diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c index 63e1a150f8..1c7bf10f91 100644 --- a/drivers/spi/mpc8xxx_spi.c +++ b/drivers/spi/mpc8xxx_spi.c @@ -5,10 +5,12 @@ */ #include - +#include +#include #include #include #include +#include enum { SPI_EV_NE = BIT(31 - 22), /* Receiver Not Empty */ @@ -30,6 +32,12 @@ enum { SPI_COM_LST = BIT(31 - 9), }; +struct mpc8xxx_priv { + spi8xxx_t *spi; + struct gpio_desc gpios[16]; + int max_cs; +}; + static inline u32 to_prescale_mod(u32 val) { return (min(val, (u32)15) << 16); @@ -42,70 +50,90 @@ static void set_char_len(spi8xxx_t *spi, u32 val) #define SPI_TIMEOUT 1000 -struct spi_slave *spi_setup_slave(uint bus, uint cs, uint max_hz, uint mode) +static int __spi_set_speed(spi8xxx_t *spi, uint speed) { - struct spi_slave *slave; + /* TODO(mario.six@gdsys.cc): This only ever sets one fixed speed */ - if (!spi_cs_is_valid(bus, cs)) - return NULL; - - slave = spi_alloc_slave_base(bus, cs); - if (!slave) - return NULL; - - /* - * TODO: Some of the code in spi_init() should probably move - * here, or into spi_claim_bus() below. - */ + /* Use SYSCLK / 8 (16.67MHz typ.) */ + clrsetbits_be32(&spi->mode, SPI_MODE_PM_MASK, to_prescale_mod(1)); - return slave; + return 0; } -void spi_free_slave(struct spi_slave *slave) +static int mpc8xxx_spi_ofdata_to_platdata(struct udevice *dev) { - free(slave); + struct mpc8xxx_priv *priv = dev_get_priv(dev); + int ret; + + priv->spi = (spi8xxx_t *)dev_read_addr(dev); + + /* TODO(mario.six@gdsys.cc): Read clock and save the value */ + + ret = gpio_request_list_by_name(dev, "gpios", priv->gpios, + ARRAY_SIZE(priv->gpios), GPIOD_IS_OUT | GPIOD_ACTIVE_LOW); + if (ret < 0) + return -EINVAL; + + priv->max_cs = ret; + + return 0; } -void spi_init(void) +static int mpc8xxx_spi_probe(struct udevice *dev) { - spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi; + struct mpc8xxx_priv *priv = dev_get_priv(dev); /* * SPI pins on the MPC83xx are not muxed, so all we do is initialize * some registers */ - out_be32(&spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN); - /* Use SYSCLK / 8 (16.67MHz typ.) */ - clrsetbits_be32(&spi->mode, SPI_MODE_PM_MASK, to_prescale_mod(1)); + out_be32(&priv->spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN); + + __spi_set_speed(priv->spi, 16666667); + /* Clear all SPI events */ - setbits_be32(&spi->event, 0xffffffff); + setbits_be32(&priv->spi->event, 0xffffffff); /* Mask all SPI interrupts */ - clrbits_be32(&spi->mask, 0xffffffff); + clrbits_be32(&priv->spi->mask, 0xffffffff); /* LST bit doesn't do anything, so disregard */ - out_be32(&spi->com, 0); + out_be32(&priv->spi->com, 0); + + return 0; } -int spi_claim_bus(struct spi_slave *slave) +static void mpc8xxx_spi_cs_activate(struct udevice *dev) { - return 0; + struct mpc8xxx_priv *priv = dev_get_priv(dev->parent); + struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev); + + dm_gpio_set_dir_flags(&priv->gpios[platdata->cs], GPIOD_IS_OUT); + dm_gpio_set_value(&priv->gpios[platdata->cs], 0); } -void spi_release_bus(struct spi_slave *slave) +static void mpc8xxx_spi_cs_deactivate(struct udevice *dev) { + struct mpc8xxx_priv *priv = dev_get_priv(dev->parent); + struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev); + + dm_gpio_set_dir_flags(&priv->gpios[platdata->cs], GPIOD_IS_OUT); + dm_gpio_set_value(&priv->gpios[platdata->cs], 1); } -int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din, - ulong flags) +static int mpc8xxx_spi_xfer(struct udevice *dev, uint bitlen, + const void *dout, void *din, ulong flags) { - spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi; - u32 tmpdin; + struct udevice *bus = dev->parent; + struct mpc8xxx_priv *priv = dev_get_priv(bus); + spi8xxx_t *spi = priv->spi; + struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev); + u32 tmpdin = 0; int num_blks = DIV_ROUND_UP(bitlen, 32); - debug("%s: slave %u:%u dout %08X din %08X bitlen %u\n", __func__, - slave->bus, slave->cs, *(uint *)dout, *(uint *)din, bitlen); + debug("%s: slave %s:%u dout %08X din %08X bitlen %u\n", __func__, + bus->name, platdata->cs, *(uint *)dout, *(uint *)din, bitlen); if (flags & SPI_XFER_BEGIN) - spi_cs_activate(slave); + mpc8xxx_spi_cs_activate(dev); /* Clear all SPI events */ setbits_be32(&spi->event, 0xffffffff); @@ -178,15 +206,57 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din, mdelay(1); } while (get_timer(start) < SPI_TIMEOUT); - if (get_timer(start) >= SPI_TIMEOUT) + if (get_timer(start) >= SPI_TIMEOUT) { debug("*** %s: Time out during SPI transfer\n", __func__); + return -ETIMEDOUT; + } debug("*** %s: transfer ended. Value=%08x\n", __func__, tmpdin); } if (flags & SPI_XFER_END) - spi_cs_deactivate(slave); + mpc8xxx_spi_cs_deactivate(dev); + + return 0; +} + +static int mpc8xxx_spi_set_speed(struct udevice *dev, uint speed) +{ + struct mpc8xxx_priv *priv = dev_get_priv(dev); + + return __spi_set_speed(priv->spi, speed); +} +static int mpc8xxx_spi_set_mode(struct udevice *dev, uint mode) +{ + /* TODO(mario.six@gdsys.cc): Using SPI_CPHA (for clock phase) and + * SPI_CPOL (for clock polarity) should work + */ return 0; } + +static const struct dm_spi_ops mpc8xxx_spi_ops = { + .xfer = mpc8xxx_spi_xfer, + .set_speed = mpc8xxx_spi_set_speed, + .set_mode = mpc8xxx_spi_set_mode, + /* + * cs_info is not needed, since we require all chip selects to be + * in the device tree explicitly + */ +}; + +static const struct udevice_id mpc8xxx_spi_ids[] = { + { .compatible = "fsl,spi" }, + { } +}; + +U_BOOT_DRIVER(mpc8xxx_spi) = { + .name = "mpc8xxx_spi", + .id = UCLASS_SPI, + .of_match = mpc8xxx_spi_ids, + .ops = &mpc8xxx_spi_ops, + .ofdata_to_platdata = mpc8xxx_spi_ofdata_to_platdata, + .probe = mpc8xxx_spi_probe, + .priv_auto_alloc_size = sizeof(struct mpc8xxx_priv), +};