From patchwork Thu Jan 23 10:30:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 23572 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EA394218BD for ; Thu, 23 Jan 2014 10:31:42 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id rd3sf4027648pab.11 for ; Thu, 23 Jan 2014 02:31:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=2JSJTWpU+ObdNpSYcmA+D/X6dvi8NpDmqyb6KW/3o0Q=; b=QpIvawRa9YP7ibm50eyJCy0eCvk1LpL+Q0OEAXN76KuKCcA3Aq5Yz3/7VOXsT0NLZ7 vELdrnC3cZQQTzqzKJyq3+LSmvyCkV1c4SW4BYIwAQgQ/SZcjuKVPQc7HlTrSiny6pvx lmcL65Fe2YIFoqEUHGng9GswrplAFn+AXstuIwor+xc3JLqGgXkTEZAz+mXl1VSMmZNX mi4gVTgIRGiQkJxbv9katkmOKzSPjLHtk7yKTkHTl+jBuv/nQWCBRLt1UjDuyp4aKIzf 1Fxky4eWIxvwYB4IoYhmUfVtUol/tkFVBn5ifubH3B1IYaTwYz6L6/l+3Hd+yU/S0+Dn VMQw== X-Gm-Message-State: ALoCoQnO2iwrENP1KFXQUpKFn11Rka/In0fFwUFMh8fRC/56Y0Uj5GEFT8a8NaafzOJchFEMePYE X-Received: by 10.66.138.79 with SMTP id qo15mr2636786pab.34.1390473102201; Thu, 23 Jan 2014 02:31:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.71 with SMTP id c65ls292317qge.4.gmail; Thu, 23 Jan 2014 02:31:42 -0800 (PST) X-Received: by 10.58.187.98 with SMTP id fr2mr55562vec.38.1390473102069; Thu, 23 Jan 2014 02:31:42 -0800 (PST) Received: from mail-vb0-f51.google.com (mail-vb0-f51.google.com [209.85.212.51]) by mx.google.com with ESMTPS id sj10si6433914vcb.15.2014.01.23.02.31.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:31:42 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.51 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.51; Received: by mail-vb0-f51.google.com with SMTP id 11so938492vbe.10 for ; Thu, 23 Jan 2014 02:31:42 -0800 (PST) X-Received: by 10.58.75.6 with SMTP id y6mr4156014vev.23.1390473101988; Thu, 23 Jan 2014 02:31:41 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp15892vcz; Thu, 23 Jan 2014 02:31:41 -0800 (PST) X-Received: by 10.180.93.169 with SMTP id cv9mr24138245wib.3.1390473100883; Thu, 23 Jan 2014 02:31:40 -0800 (PST) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by mx.google.com with ESMTPS id kq4si8791302wjb.0.2014.01.23.02.31.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:31:40 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.172 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.172; Received: by mail-wi0-f172.google.com with SMTP id ex4so6615920wid.17 for ; Thu, 23 Jan 2014 02:31:40 -0800 (PST) X-Received: by 10.195.13.234 with SMTP id fb10mr6057652wjd.50.1390473100436; Thu, 23 Jan 2014 02:31:40 -0800 (PST) Received: from localhost.localdomain ([80.76.198.141]) by mx.google.com with ESMTPSA id ay6sm21257831wjb.23.2014.01.23.02.31.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:31:39 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, dwmw2@infradead.org, linux-mtd@lists.infradead.org, computersforpeace@gmail.com, Angus.Clark@st.com, DCG_UPD_stlinux_kernel@list.st.com, olivier.clergeaud@st.com, Lee Jones Subject: [PATCH RESEND v4 01/37] mtd: st_spi_fsm: Allocate resources and register with MTD framework Date: Thu, 23 Jan 2014 10:30:49 +0000 Message-Id: <1390473085-24626-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390473085-24626-1-git-send-email-lee.jones@linaro.org> References: <1390473085-24626-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.51 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 | 8 +++ drivers/mtd/devices/Makefile | 1 + drivers/mtd/devices/st_spi_fsm.c | 109 +++++++++++++++++++++++++++++++++++++++ drivers/mtd/devices/st_spi_fsm.h | 27 ++++++++++ 4 files changed, 145 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..0cf48ac 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig @@ -217,6 +217,14 @@ 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" + depends on ARM || SH + 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..fe66342 --- /dev/null +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -0,0 +1,109 @@ +/* + * 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 "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, stfsm_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 */