public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Hauke Mehrtens <hauke@hauke-m.de>
Cc: devicetree@vger.kernel.org, f.fainelli@gmail.com,
	rjui@broadcom.com, zajec5@gmail.com,
	linux-mtd@lists.infradead.org,
	bcm-kernel-feedback-list@broadcom.com
Subject: Re: [PATCH 5/7] mtd: brcmnand: add bcma driver
Date: Tue, 19 May 2015 17:34:02 -0700	[thread overview]
Message-ID: <20150520003402.GC11598@ld-irv-0074> (raw)
In-Reply-To: <1431877266-28566-6-git-send-email-hauke@hauke-m.de>

On Sun, May 17, 2015 at 05:41:04PM +0200, Hauke Mehrtens wrote:
> This driver registers at the bcma bus and drives the NAND core if it
> was found on this bus. The bcma bus with this NAND core is used on the
> bcm53xx and bcm47xx Northstar SoC with ARM CPU cores. The memory ranges
> are automatically detected by bcma and the irq numbers read from device
> tree by bcma bus driver.

If you're going to use device tree for part of it (IRQs) why not the
whole thing?

> This is based on the iproc driver.

This looks like you could probably get by with just using iproc_nand.c
as-is. The main NAND core is apparently MMIO-accessible on your chips,
so aren't the BCMA bits you're touching also?

> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>  drivers/mtd/nand/Kconfig              |   8 ++
>  drivers/mtd/nand/brcmnand/Makefile    |   1 +
>  drivers/mtd/nand/brcmnand/bcma_nand.c | 153 ++++++++++++++++++++++++++++++++++
>  3 files changed, 162 insertions(+)
>  create mode 100644 drivers/mtd/nand/brcmnand/bcma_nand.c
> 
> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
> index 376b538..b698212 100644
> --- a/drivers/mtd/nand/Kconfig
> +++ b/drivers/mtd/nand/Kconfig
> @@ -402,6 +402,14 @@ config MTD_NAND_BRCMNAND
>  	  originally designed for Set-Top Box but is used on various BCM7xxx,
>  	  BCM3xxx, BCM63xxx, iProc/Cygnus and more.
>  
> +config MTD_NAND_BRCMNAND_BCMA
> +	tristate "Broadcom BCMA NAND controller"
> +	depends on ARM || MIPS

depends on BCMA ?

> +	select MTD_NAND_BRCMNAND
> +	help
> +	  Enables the driver which registers Broadcom NAND controller against
> +	  bcma.

If you're going to add new Kconfigs for brcmnand, let's add a Kconfig
file under drivers/mtd/nand/brcmnand/.

Brian

> +
>  config MTD_NAND_BCM47XXNFLASH
>  	tristate "Support for NAND flash on BCM4706 BCMA bus"
>  	depends on BCMA_NFLASH
> diff --git a/drivers/mtd/nand/brcmnand/Makefile b/drivers/mtd/nand/brcmnand/Makefile
> index 3b1fbfd..8483984 100644
> --- a/drivers/mtd/nand/brcmnand/Makefile
> +++ b/drivers/mtd/nand/brcmnand/Makefile
> @@ -1,6 +1,7 @@
>  # link order matters; don't link the more generic brcmstb_nand.o before the
>  # more specific iproc_nand.o, for instance
>  obj-$(CONFIG_MTD_NAND_BRCMNAND)		+= iproc_nand.o
> +obj-$(CONFIG_MTD_NAND_BRCMNAND_BCMA)	+= bcma_nand.o
>  obj-$(CONFIG_MTD_NAND_BRCMNAND)		+= bcm63138_nand.o
>  obj-$(CONFIG_MTD_NAND_BRCMNAND)		+= brcmstb_nand.o
>  obj-$(CONFIG_MTD_NAND_BRCMNAND)		+= brcmnand.o
> diff --git a/drivers/mtd/nand/brcmnand/bcma_nand.c b/drivers/mtd/nand/brcmnand/bcma_nand.c
> new file mode 100644
> index 0000000..58380bd
> --- /dev/null
> +++ b/drivers/mtd/nand/brcmnand/bcma_nand.c
> @@ -0,0 +1,153 @@
> +/*
> + * Copyright © 2015 Broadcom Corporation
> + * Copyright 2015 Hauke Mehrtens <hauke@hauke-m.de>
> + *
> + * This program 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.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/device.h>
> +#include <linux/io.h>
> +#include <linux/ioport.h>
> +#include <linux/module.h>
> +#include <linux/bcma/bcma.h>
> +#include <linux/slab.h>
> +
> +#include "brcmnand.h"
> +
> +struct bcma_nand_soc_priv {
> +	struct brcmnand_soc soc;
> +	struct bcma_device *core;
> +	spinlock_t idm_lock;
> +};
> +
> +#define BCMA_NAND_CTLR_READY_OFFSET       0x0f10
> +#define BCMA_NAND_CTLR_READY              BIT(0)
> +
> +#define BCMA_NAND_APB_LE_MODE             BIT(24)
> +#define BCMA_NAND_INT_CTRL_READ_ENABLE    BIT(6)
> +
> +static bool bcma_nand_intc_ack(struct brcmnand_soc *soc)
> +{
> +	struct bcma_nand_soc_priv *priv = soc->priv;
> +	struct bcma_device *core = priv->core;
> +
> +	u32 val = bcma_read32(core, BCMA_NAND_CTLR_READY_OFFSET);
> +
> +	if (val & BCMA_NAND_CTLR_READY) {
> +		bcma_write32(core, BCMA_NAND_CTLR_READY_OFFSET,
> +			     BCMA_NAND_CTLR_READY);
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
> +static void bcma_nand_intc_set(struct brcmnand_soc *soc, bool en)
> +{
> +	struct bcma_nand_soc_priv *priv = soc->priv;
> +	struct bcma_device *core = priv->core;
> +	u32 val;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&priv->idm_lock, flags);
> +
> +	val = bcma_aread32(core, BCMA_IOCTL);
> +
> +	if (en)
> +		val |= BCMA_NAND_INT_CTRL_READ_ENABLE;
> +	else
> +		val &= ~BCMA_NAND_INT_CTRL_READ_ENABLE;
> +
> +	bcma_awrite32(core, BCMA_IOCTL, val);
> +
> +	spin_unlock_irqrestore(&priv->idm_lock, flags);
> +}
> +
> +static void bcma_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
> +{
> +	struct bcma_nand_soc_priv *priv = soc->priv;
> +	struct bcma_device *core = priv->core;
> +	u32 val;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&priv->idm_lock, flags);
> +
> +	val = bcma_aread32(core, BCMA_IOCTL);
> +
> +	if (prepare)
> +		val |= BCMA_NAND_APB_LE_MODE;
> +	else
> +		val &= ~BCMA_NAND_APB_LE_MODE;
> +
> +	bcma_awrite32(core, BCMA_IOCTL, val);
> +
> +	spin_unlock_irqrestore(&priv->idm_lock, flags);
> +}
> +
> +static int bcma_nand_probe(struct bcma_device *core)
> +{
> +	struct device *dev = &core->dev;
> +	struct bcma_nand_soc_priv *priv;
> +	struct brcmnand_soc *soc;
> +
> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	priv->core = core;
> +
> +	soc = &priv->soc;
> +	soc->nand_base = core->io_addr;
> +	soc->irq = bcma_core_irq(core, 4);
> +
> +	soc->dev = dev;
> +	soc->priv = priv;
> +	soc->ctlrdy_ack = bcma_nand_intc_ack;
> +	soc->ctlrdy_set_enabled = bcma_nand_intc_set;
> +	soc->prepare_data_bus = bcma_nand_apb_access;
> +
> +	bcma_core_enable(core, 0);
> +	return brcmnand_probe_dev(dev, soc);
> +}
> +
> +static void bcma_nand_remove(struct bcma_device *core)
> +{
> +	brcmnand_remove_dev(&core->dev);
> +}
> +
> +static const struct bcma_device_id bcma_nand_tbl[] = {
> +	BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_NAND, BCMA_ANY_REV, BCMA_ANY_CLASS),
> +	{},
> +};
> +MODULE_DEVICE_TABLE(bcma, bcma_nand_tbl);
> +
> +static struct bcma_driver bcma_nand_driver = {
> +	.name		= KBUILD_MODNAME,
> +	.id_table	= bcma_nand_tbl,
> +	.probe		= bcma_nand_probe,
> +	.remove		= bcma_nand_remove,
> +};
> +
> +static int __init bcma_nand_init(void)
> +{
> +	return bcma_driver_register(&bcma_nand_driver);
> +}
> +
> +static void __exit bcma_nand_exit(void)
> +{
> +	bcma_driver_unregister(&bcma_nand_driver);
> +}
> +
> +module_init(bcma_nand_init)
> +module_exit(bcma_nand_exit)
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_AUTHOR("Hauke Mehrtens");
> +MODULE_DESCRIPTION("NAND driver for Broadcom bcma based SoCs");
> -- 
> 2.1.4
> 

  reply	other threads:[~2015-05-20  0:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-17 15:40 [PATCH 0/7] mtd: brcmnand: add support for NAND core on bcma bus Hauke Mehrtens
2015-05-17 15:41 ` [PATCH 1/7] mtd: brcmnand: remove double new line from print Hauke Mehrtens
2015-05-18 18:09   ` Brian Norris
2015-05-17 15:41 ` [PATCH 2/7] mtd: brcmnand: do not make local variable static Hauke Mehrtens
2015-05-18 18:13   ` Brian Norris
2015-05-17 15:41 ` [PATCH 3/7] mtd: brcmnand: use struct device and not platform_device Hauke Mehrtens
2015-05-17 15:41 ` [PATCH 4/7] mtd: brcmnand: add methods to register struct device Hauke Mehrtens
2015-05-17 15:41 ` [PATCH 5/7] mtd: brcmnand: add bcma driver Hauke Mehrtens
2015-05-20  0:34   ` Brian Norris [this message]
2015-05-20  6:39     ` Rafał Miłecki
2015-05-20 18:40       ` Brian Norris
2015-05-20 22:10         ` Hauke Mehrtens
2015-05-20 22:48           ` Ray Jui
2015-05-21  7:51         ` Rafał Miłecki
2015-05-27  0:18           ` Brian Norris
2015-05-27 22:18             ` Hauke Mehrtens
2015-05-17 15:41 ` [PATCH 6/7] mtd: brcmnand: run bcm47xxpart part parser in addition Hauke Mehrtens
2015-05-17 16:05   ` Jonas Gorski
2015-05-17 16:14     ` Hauke Mehrtens
2015-05-17 15:41 ` [PATCH 7/7] ARM: BCM5301X: add NAND flash chip description Hauke Mehrtens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150520003402.GC11598@ld-irv-0074 \
    --to=computersforpeace@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=hauke@hauke-m.de \
    --cc=linux-mtd@lists.infradead.org \
    --cc=rjui@broadcom.com \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox