public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Vitaly Wool <vitalywool@gmail.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [patch] generic nand driver for SoCs
Date: Tue, 01 May 2007 15:00:51 +0200	[thread overview]
Message-ID: <1178024451.5791.299.camel@localhost.localdomain> (raw)
In-Reply-To: <46373163.7060603@gmail.com>

On Tue, 2007-05-01 at 16:24 +0400, Vitaly Wool wrote:
> This is a very first shot on the "generic NAND driver" subject as was 
> discussed by Lennert and Thomas.

> +#include <linux/slab.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/mtd/mtd.h>
> +#include <linux/mtd/nand.h>
> +#include <linux/mtd/partitions.h>
> +#include <linux/io.h>

#include <linux/io.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/partitions.h>

Please

> +struct gen_nand_data {
> +	struct nand_chip	chip;
> +	struct mtd_info		mtd;
> +	void __iomem		*io_base;
> +#ifdef CONFIG_MTD_PARTITIONS
> +	int			nr_parts;
> +	struct mtd_partition	*parts;
> +#endif
> +};
> +
> +#ifdef CONFIG_MTD_PARTITIONS
> +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
> +#endif
> +

Hmm, this should be provided by the platform as well.

> +/*
> + * Probe for the NAND device.
> + */
> +static int __init gen_nand_probe(struct platform_device *pdev)
> +{
> +	struct platform_nand_data *pdata = pdev->dev.platform_data;
> +	struct gen_nand_data *data;
> +	int res;
> +
> +	/* Allocate memory for the device structure (and zero it) */
> +	data = kzalloc(sizeof(struct gen_nand_data), GFP_KERNEL);
> +	if (!data) {
> +		dev_err(&pdev->dev, "failed to allocate device structure.\n");
> +		return -ENOMEM;
> +	}
> +
> +	data->io_base = ioremap(pdev->resource[0].start,
> +				pdev->resource[0].end - pdev->resource[0].start + 1);
> +	if (data->io_base == NULL) {
> +		dev_err(&pdev->dev, "ioremap failed\n");
> +		kfree(data);
> +		return -EIO;
> +	}
> +
> +	data->chip.priv = &data;	/* link the private data structures */

	No comments after code please

> +	data->mtd.priv = &data->chip;
> +	data->mtd.owner = THIS_MODULE;
> +
> +	data->chip.IO_ADDR_R = data->io_base;
> +	data->chip.IO_ADDR_W = data->io_base;
> +	if (pdata->ctrl.cmd_ctrl)
> +		data->chip.cmd_ctrl = pdata->ctrl.cmd_ctrl;
> +	if (pdata->ctrl.dev_ready)
> +		data->chip.dev_ready = pdata->ctrl.dev_ready;
> +	if (pdata->ctrl.select_chip)
> +		data->chip.select_chip = pdata->ctrl.select_chip;
> +	if (pdata->ctrl.hwcontrol)
> +		data->chip.ecc.hwctl = pdata->ctrl.hwcontrol;
> +	if (pdata->chip.ecclayout)
> +		data->chip.ecc.layout = pdata->chip.ecclayout;

	The if(..)s are superfluid. 

> +static int __devexit gen_nand_remove(struct platform_device *pdev)
> +{
> +	struct gen_nand_data *data = platform_get_drvdata(pdev);
> +	struct platform_nand_data *pdata = pdev->dev.platform_data;
> +
> +#ifdef CONFIG_MTD_PARTITIONS
> +	if (data->parts) {
> +		del_mtd_partitions(&data->mtd);
> +		if (data->parts != pdata->chip.partitions)
> +			kfree(data->parts);
> +	} else
> +		del_mtd_device(&data->mtd);
> +#else
> +	del_mtd_device(&data->mtd);
> +#endif

This all except kfree(data->parts) is done in nand_release !

> +	nand_release(&data->mtd);
> +	iounmap(data->io_base);
> +	kfree(data);
> +
> +	return 0;
> +}
> +

Looks good otherwise.

	tglx

  reply	other threads:[~2007-05-01 12:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-01 12:24 [patch] generic nand driver for SoCs Vitaly Wool
2007-05-01 13:00 ` Thomas Gleixner [this message]
2007-05-01 13:03   ` Vitaly Wool
2007-05-01 13:09     ` Thomas Gleixner
2007-05-01 13:11       ` Vitaly Wool
2007-05-01 14:17 ` Stefan Roese

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=1178024451.5791.299.camel@localhost.localdomain \
    --to=tglx@linutronix.de \
    --cc=linux-mtd@lists.infradead.org \
    --cc=vitalywool@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