From: Artem Bityutskiy <dedekind1@gmail.com>
To: John Crispin <blogic@openwrt.org>
Cc: Ralf Baechle <ralf@linux-mips.org>,
linux-mips@linux-mips.org, Ralph Hempel <ralph.hempel@lantiq.com>,
linux-mtd@lists.infradead.org,
Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>,
David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH V5 06/10] MIPS: lantiq: add NOR flash support
Date: Fri, 01 Apr 2011 15:43:52 +0300 [thread overview]
Message-ID: <1301661832.2789.56.camel@localhost> (raw)
In-Reply-To: <1301470076-17279-7-git-send-email-blogic@openwrt.org>
Hi,
just few minor things.
On Wed, 2011-03-30 at 09:27 +0200, John Crispin wrote:
> +/* the NOR flash is connected to the same external bus unit (EBU) as PCI.
> + * To make PCI work we need to enable the endianess swapping of the addr
> + * written to the EBU. this however has some limitations and breaks when
> + * using NOR. it does not really matter if the onflash data is in a swapped
> + * order, however cfi sequences also fail. to workaround this we need to use
> + * a complex map. We essentially software swap all addresses during probe
> + * and then swizzle the unlock addresses.
> + */
Would be nice to clean-up the comment a little bit and use capital
letters at the start of the sentences. Also, I think the style for
multi-line comments is:
/*
* bla
* bla
*/
> +static void
> +ltq_copy_from(struct map_info *map, void *to,
> + unsigned long from, ssize_t len)
> +{
> + unsigned char *f = (unsigned char *) (map->virt + from);
> + unsigned char *t = (unsigned char *) to;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ebu_lock, flags);
> + while (len--)
> + *t++ = *f++;
> + spin_unlock_irqrestore(&ebu_lock, flags);
Can you use memcpy here instead?
> +}
> +
> +static void
> +ltq_copy_to(struct map_info *map, unsigned long to,
> + const void *from, ssize_t len)
> +{
> + unsigned char *f = (unsigned char *) from;
> + unsigned char *t = (unsigned char *) (map->virt + to);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ebu_lock, flags);
> + while (len--)
> + *t++ = *f++;
Can you use memcpy here instead?
> + spin_unlock_irqrestore(&ebu_lock, flags);
> +}
> +
> +static const char const *part_probe_types[] = {
> + "cmdlinepart", NULL };
This can be one-liner, no need to make 2 lines.
> +
> +static struct map_info ltq_map = {
> + .name = "ltq_nor",
> + .bankwidth = 2,
> + .read = ltq_read16,
> + .write = ltq_write16,
> + .copy_from = ltq_copy_from,
> + .copy_to = ltq_copy_to,
> +};
> +
> +static int __init
> +ltq_mtd_probe(struct platform_device *pdev)
> +{
> + struct physmap_flash_data *ltq_mtd_data =
> + dev_get_platdata(&pdev->dev);
This can be one line - it takes only 79 characters.
> + struct mtd_info *ltq_mtd = NULL;
> + struct mtd_partition *parts = NULL;
> + struct resource *res = 0;
You do not need this initialization.
> + int nr_parts = 0;
> + struct cfi_private *cfi;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!res) {
> + dev_err(&pdev->dev, "failed to get memory resource");
> + return -ENOENT;
> + }
> + res = devm_request_mem_region(&pdev->dev, res->start,
> + resource_size(res), dev_name(&pdev->dev));
> + if (!res) {
> + dev_err(&pdev->dev, "failed to request mem resource");
> + return -EBUSY;
> + }
> +
> + ltq_map.phys = res->start;
> + ltq_map.size = resource_size(res);
> + ltq_map.virt = devm_ioremap_nocache(&pdev->dev, ltq_map.phys,
> + ltq_map.size);
> + if (!ltq_map.virt) {
> + dev_err(&pdev->dev, "failed to ioremap!\n");
> + return -EIO;
> + }
> +
> + ltq_mtd_probing = 1;
> + ltq_mtd = do_map_probe("cfi_probe", <q_map);
> + ltq_mtd_probing = 0;
> + if (!ltq_mtd) {
> + iounmap(ltq_map.virt);
> + dev_err(&pdev->dev, "probing failed\n");
> + return -ENXIO;
> + }
> + ltq_mtd->owner = THIS_MODULE;
> +
> + cfi = ltq_map.fldrv_priv;
> + cfi->addr_unlock1 ^= 1;
> + cfi->addr_unlock2 ^= 1;
> +
> + nr_parts = parse_mtd_partitions(ltq_mtd, part_probe_types, &parts, 0);
> + if (nr_parts > 0) {
> + dev_info(&pdev->dev,
> + "using %d partitions from cmdline", nr_parts);
> + } else {
> + nr_parts = ltq_mtd_data->nr_parts;
> + parts = ltq_mtd_data->parts;
> + }
> +
> + add_mtd_partitions(ltq_mtd, parts, nr_parts);
This function may return an error.
> + return 0;
> +}
> +
> +static struct platform_driver ltq_mtd_driver = {
> + .driver = {
> + .name = "ltq_nor",
> + .owner = THIS_MODULE,
> + },
> +};
> +
> +int __init
> +init_ltq_mtd(void)
> +{
> + int ret = platform_driver_probe(<q_mtd_driver, ltq_mtd_probe);
> +
> + if (ret)
> + printk(KERN_INFO "ltq_nor: error registering platfom driver");
I think errors should be printed with KERN_ERR level. Anyway, use
pr_err() here instead pleas.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
WARNING: multiple messages have this Message-ID (diff)
From: Artem Bityutskiy <dedekind1@gmail.com>
To: John Crispin <blogic@openwrt.org>
Cc: linux-mips@linux-mips.org, Ralf Baechle <ralf@linux-mips.org>,
Ralph Hempel <ralph.hempel@lantiq.com>,
linux-mtd@lists.infradead.org,
Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>,
David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH V5 06/10] MIPS: lantiq: add NOR flash support
Date: Fri, 01 Apr 2011 15:43:52 +0300 [thread overview]
Message-ID: <1301661832.2789.56.camel@localhost> (raw)
In-Reply-To: <1301470076-17279-7-git-send-email-blogic@openwrt.org>
Hi,
just few minor things.
On Wed, 2011-03-30 at 09:27 +0200, John Crispin wrote:
> +/* the NOR flash is connected to the same external bus unit (EBU) as PCI.
> + * To make PCI work we need to enable the endianess swapping of the addr
> + * written to the EBU. this however has some limitations and breaks when
> + * using NOR. it does not really matter if the onflash data is in a swapped
> + * order, however cfi sequences also fail. to workaround this we need to use
> + * a complex map. We essentially software swap all addresses during probe
> + * and then swizzle the unlock addresses.
> + */
Would be nice to clean-up the comment a little bit and use capital
letters at the start of the sentences. Also, I think the style for
multi-line comments is:
/*
* bla
* bla
*/
> +static void
> +ltq_copy_from(struct map_info *map, void *to,
> + unsigned long from, ssize_t len)
> +{
> + unsigned char *f = (unsigned char *) (map->virt + from);
> + unsigned char *t = (unsigned char *) to;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ebu_lock, flags);
> + while (len--)
> + *t++ = *f++;
> + spin_unlock_irqrestore(&ebu_lock, flags);
Can you use memcpy here instead?
> +}
> +
> +static void
> +ltq_copy_to(struct map_info *map, unsigned long to,
> + const void *from, ssize_t len)
> +{
> + unsigned char *f = (unsigned char *) from;
> + unsigned char *t = (unsigned char *) (map->virt + to);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ebu_lock, flags);
> + while (len--)
> + *t++ = *f++;
Can you use memcpy here instead?
> + spin_unlock_irqrestore(&ebu_lock, flags);
> +}
> +
> +static const char const *part_probe_types[] = {
> + "cmdlinepart", NULL };
This can be one-liner, no need to make 2 lines.
> +
> +static struct map_info ltq_map = {
> + .name = "ltq_nor",
> + .bankwidth = 2,
> + .read = ltq_read16,
> + .write = ltq_write16,
> + .copy_from = ltq_copy_from,
> + .copy_to = ltq_copy_to,
> +};
> +
> +static int __init
> +ltq_mtd_probe(struct platform_device *pdev)
> +{
> + struct physmap_flash_data *ltq_mtd_data =
> + dev_get_platdata(&pdev->dev);
This can be one line - it takes only 79 characters.
> + struct mtd_info *ltq_mtd = NULL;
> + struct mtd_partition *parts = NULL;
> + struct resource *res = 0;
You do not need this initialization.
> + int nr_parts = 0;
> + struct cfi_private *cfi;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!res) {
> + dev_err(&pdev->dev, "failed to get memory resource");
> + return -ENOENT;
> + }
> + res = devm_request_mem_region(&pdev->dev, res->start,
> + resource_size(res), dev_name(&pdev->dev));
> + if (!res) {
> + dev_err(&pdev->dev, "failed to request mem resource");
> + return -EBUSY;
> + }
> +
> + ltq_map.phys = res->start;
> + ltq_map.size = resource_size(res);
> + ltq_map.virt = devm_ioremap_nocache(&pdev->dev, ltq_map.phys,
> + ltq_map.size);
> + if (!ltq_map.virt) {
> + dev_err(&pdev->dev, "failed to ioremap!\n");
> + return -EIO;
> + }
> +
> + ltq_mtd_probing = 1;
> + ltq_mtd = do_map_probe("cfi_probe", <q_map);
> + ltq_mtd_probing = 0;
> + if (!ltq_mtd) {
> + iounmap(ltq_map.virt);
> + dev_err(&pdev->dev, "probing failed\n");
> + return -ENXIO;
> + }
> + ltq_mtd->owner = THIS_MODULE;
> +
> + cfi = ltq_map.fldrv_priv;
> + cfi->addr_unlock1 ^= 1;
> + cfi->addr_unlock2 ^= 1;
> +
> + nr_parts = parse_mtd_partitions(ltq_mtd, part_probe_types, &parts, 0);
> + if (nr_parts > 0) {
> + dev_info(&pdev->dev,
> + "using %d partitions from cmdline", nr_parts);
> + } else {
> + nr_parts = ltq_mtd_data->nr_parts;
> + parts = ltq_mtd_data->parts;
> + }
> +
> + add_mtd_partitions(ltq_mtd, parts, nr_parts);
This function may return an error.
> + return 0;
> +}
> +
> +static struct platform_driver ltq_mtd_driver = {
> + .driver = {
> + .name = "ltq_nor",
> + .owner = THIS_MODULE,
> + },
> +};
> +
> +int __init
> +init_ltq_mtd(void)
> +{
> + int ret = platform_driver_probe(<q_mtd_driver, ltq_mtd_probe);
> +
> + if (ret)
> + printk(KERN_INFO "ltq_nor: error registering platfom driver");
I think errors should be printed with KERN_ERR level. Anyway, use
pr_err() here instead pleas.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
next prev parent reply other threads:[~2011-04-01 12:46 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-30 7:27 [PATCH V5 00/10] MIPS: lantiq: add initial support for Lantiq SoCs John Crispin
2011-03-30 7:27 ` [PATCH V5 01/10] " John Crispin
2011-03-31 13:01 ` Ralf Baechle
2011-03-31 13:35 ` John Crispin
2011-03-30 7:27 ` [PATCH V5 02/10] MIPS: lantiq: add SoC specific code for XWAY family John Crispin
2011-03-31 13:01 ` Ralf Baechle
2011-03-30 7:27 ` [PATCH V5 03/10] MIPS: lantiq: add PCI controller support John Crispin
2011-03-31 13:01 ` Ralf Baechle
2011-03-30 7:27 ` [PATCH V5 04/10] MIPS: lantiq: add serial port support John Crispin
2011-03-30 9:33 ` Alan Cox
2011-03-30 7:27 ` [PATCH V5 05/10] MIPS: lantiq: add watchdog support John Crispin
2011-03-30 9:36 ` Wim Van Sebroeck
2011-03-30 9:41 ` John Crispin
2011-04-04 9:24 ` John Crispin
2011-04-07 14:31 ` Sergei Shtylyov
2011-03-30 7:27 ` [PATCH V5 06/10] MIPS: lantiq: add NOR flash support John Crispin
2011-03-30 7:27 ` John Crispin
2011-04-01 12:43 ` Artem Bityutskiy [this message]
2011-04-01 12:43 ` Artem Bityutskiy
2011-04-04 13:36 ` John Crispin
2011-04-04 13:36 ` John Crispin
2011-04-04 14:07 ` Artem Bityutskiy
2011-04-04 14:07 ` Artem Bityutskiy
2011-03-30 7:27 ` [PATCH V5 07/10] MIPS: lantiq: add platform device support John Crispin
2011-03-31 13:01 ` Ralf Baechle
2011-03-30 7:27 ` [PATCH V5 08/10] MIPS: lantiq: add mips_machine support John Crispin
2011-03-31 13:01 ` Ralf Baechle
2011-03-30 7:27 ` [PATCH V5 09/10] MIPS: lantiq: add machtypes for lantiq eval kits John Crispin
2011-03-31 13:02 ` Ralf Baechle
2011-03-30 7:27 ` [PATCH V5 10/10] MIPS: lantiq: add more gpio drivers John Crispin
2011-03-31 13:02 ` Ralf Baechle
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=1301661832.2789.56.camel@localhost \
--to=dedekind1@gmail.com \
--cc=blogic@openwrt.org \
--cc=daniel.schwierzeck@googlemail.com \
--cc=dwmw2@infradead.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-mtd@lists.infradead.org \
--cc=ralf@linux-mips.org \
--cc=ralph.hempel@lantiq.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.