From patchwork Fri Nov 29 12:18:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 295282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 306A32C00DE for ; Fri, 29 Nov 2013 23:21:10 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmN3x-00014v-EQ; Fri, 29 Nov 2013 12:20:49 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmN3r-0006vS-Qm; Fri, 29 Nov 2013 12:20:43 +0000 Received: from mail-yh0-f49.google.com ([209.85.213.49]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmN37-0006hP-6m for linux-mtd@lists.infradead.org; Fri, 29 Nov 2013 12:19:59 +0000 Received: by mail-yh0-f49.google.com with SMTP id z20so6635325yhz.8 for ; Fri, 29 Nov 2013 04:19:37 -0800 (PST) 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=iaQ7wfinojitbefuZitHDKPdDGDUjh2iI4OnYm1MJOs=; b=ignjLl9kL67WMHb3KP5RUIhlkuBkCXiuIxvMKE901o1GvT80kB9Nx/LNNCuf8OVIbg 3utFGAutpTEwOV7QksKiaM28KEV8ltvUCYbgDgIfqVTS4MNGH7IXR7kzKdJYflqE0G/l FaxGQ9Iddki6e6j9wVYTYj/NeUFNNwYZ/CEkCndUm+y/QE8JmCCs/nLw/0ebjLwBj//9 X+h6+ZNzLx0pHYz65fNeXxFxJOUzRPzpFK5ZVi6rs7XqzQRLkT2vtcdZksbRFL6GcSQm +AUVqXSsno1v/VN8UNSJGj52IZZz3xpZ3TuxX/jgVoUU6UnXq1bZoeUUQbILQQaaA5pD 7dvA== X-Gm-Message-State: ALoCoQmSys2tfQ2ZZWNGazbc3S9vMdigi86ZlFu6S9ecffYEG67zXIVBdY/wXwVRTegK+BnBPZkX X-Received: by 10.236.139.198 with SMTP id c46mr1947214yhj.78.1385727577833; Fri, 29 Nov 2013 04:19:37 -0800 (PST) Received: from localhost.localdomain (cpc15-aztw25-2-0-cust493.aztw.cable.virginm.net. [92.233.57.238]) by mx.google.com with ESMTPSA id m29sm101911689yho.14.2013.11.29.04.19.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:37 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org Subject: [PATCH v3 01/36] mtd: st_spi_fsm: Allocate resources and register with MTD framework Date: Fri, 29 Nov 2013 12:18:50 +0000 Message-Id: <1385727565-25794-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1385727565-25794-1-git-send-email-lee.jones@linaro.org> References: <1385727565-25794-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131129_071957_407657_B7EF0C9D X-CRM114-Status: GOOD ( 18.26 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.213.49 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: angus.clark@st.com, linus.walleij@linaro.org, Lee Jones , linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This is a new driver. It's used to communicate with a special type of optimised Serial Flash Controller called the FSM. The FSM uses a subset of the SPI protocol to communicate with supported NOR-Flash devices. Signed-off-by: Lee Jones --- drivers/mtd/devices/Kconfig | 7 +++ drivers/mtd/devices/Makefile | 1 + drivers/mtd/devices/st_spi_fsm.c | 111 +++++++++++++++++++++++++++++++++++++++ drivers/mtd/devices/st_spi_fsm.h | 27 ++++++++++ 4 files changed, 146 insertions(+) create mode 100644 drivers/mtd/devices/st_spi_fsm.c create mode 100644 drivers/mtd/devices/st_spi_fsm.h diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index 74ab4b7..d977281 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig @@ -217,6 +217,13 @@ config MTD_DOCG3 M-Systems and now Sandisk. The support is very experimental, and doesn't give access to any write operations. +config MTD_ST_SPI_FSM + tristate "ST Microelectronics SPI FSM Serial Flash Controller" + help + This provides an MTD device driver for the ST Microelectronics + SPI FSM Serial Flash Controller and support for a subset of + connected Serial Flash devices. + if MTD_DOCG3 config BCH_CONST_M default 14 diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile index d83bd73..c68868f 100644 --- a/drivers/mtd/devices/Makefile +++ b/drivers/mtd/devices/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_MTD_NAND_OMAP_BCH) += elm.o obj-$(CONFIG_MTD_SPEAR_SMI) += spear_smi.o obj-$(CONFIG_MTD_SST25L) += sst25l.o obj-$(CONFIG_MTD_BCM47XXSFLASH) += bcm47xxsflash.o +obj-$(CONFIG_MTD_ST_SPI_FSM) += st_spi_fsm.o CFLAGS_docg3.o += -I$(src) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c new file mode 100644 index 0000000..1e3abde --- /dev/null +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -0,0 +1,111 @@ +/* + * st_spi_fsm.c Support for ST Serial Flash Controller + * + * Author: Angus Clark + * + * Copyright (C) 2010-2013 STicroelectronics Limited + * + * JEDEC probe based on drivers/mtd/devices/m25p80.c + * + * This code is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "st_spi_fsm.h" + +static int stfsm_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct resource *res; + struct stfsm *fsm; + + if (!np) { + dev_err(&pdev->dev, "No DT found\n"); + return -EINVAL; + } + + fsm = devm_kzalloc(&pdev->dev, sizeof(*fsm), GFP_KERNEL); + if (!fsm) + return -ENOMEM; + + fsm->dev = &pdev->dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "Resource not found\n"); + return -ENODEV; + } + + fsm->region = devm_request_mem_region(&pdev->dev, res->start, + resource_size(res), pdev->name); + if (!fsm->region) { + dev_err(&pdev->dev, + "Failed to reserve memory region [0x%08x-0x%08x]\n", + res->start, res->end); + return -EBUSY; + } + + fsm->base = devm_ioremap_nocache(&pdev->dev, + res->start, resource_size(res)); + if (!fsm->base) { + dev_err(&pdev->dev, "Failed to ioremap [0x%08x]\n", res->start); + return -EINVAL; + } + + mutex_init(&fsm->lock); + + platform_set_drvdata(pdev, fsm); + + fsm->mtd.dev.parent = &pdev->dev; + fsm->mtd.type = MTD_NORFLASH; + fsm->mtd.writesize = 4; + fsm->mtd.writebufsize = fsm->mtd.writesize; + fsm->mtd.flags = MTD_CAP_NORFLASH; + + return mtd_device_parse_register(&fsm->mtd, NULL, NULL, NULL, 0); +} + +static int stfsm_remove(struct platform_device *pdev) +{ + struct stfsm *fsm = platform_get_drvdata(pdev); + int err; + + err = mtd_device_unregister(&fsm->mtd); + if (err) + return err; + + return 0; +} + +static struct of_device_id stfsm_match[] = { + { .compatible = "st,spi-fsm", }, + {}, +}; +MODULE_DEVICE_TABLE(of, spi_fsm_match); + +static struct platform_driver stfsm_driver = { + .probe = stfsm_probe, + .remove = stfsm_remove, + .driver = { + .name = "st-spi-fsm", + .owner = THIS_MODULE, + .of_match_table = stfsm_match, + }, +}; +module_platform_driver(stfsm_driver); + +MODULE_AUTHOR("Angus Clark "); +MODULE_DESCRIPTION("ST SPI FSM driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/mtd/devices/st_spi_fsm.h b/drivers/mtd/devices/st_spi_fsm.h new file mode 100644 index 0000000..df45e1a --- /dev/null +++ b/drivers/mtd/devices/st_spi_fsm.h @@ -0,0 +1,27 @@ +/* + * st_spi_fsm.c Support for ST Serial Flash Controller + * + * Author: Angus Clark + * + * Copyright (C) 2010-2013 STicroelectronics Limited + * + * JEDEC probe based on drivers/mtd/devices/m25p80.c + * + * This code is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#ifndef ST_SPI_FSM_H +#define ST_SPI_FSM_H + +struct stfsm { + struct device *dev; + void __iomem *base; + struct resource *region; + struct mtd_info mtd; + struct mutex lock; +}; + +#endif /* ST_SPI_FSM_H */