Skip to contentSkip to conversation

mtd: hisilicon: add a new driver for NAND controller of hisilicon hip04 Soc

PATCH Superseded Zhou Wang 2 participants 5 messages Oct 28, 2014 – Oct 30, 2014

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zhou Wang

author
#0 lore raw

v3 cover mtd: hisilicon: add a new driver for NAND controller of hisilicon hip04 Soc

This patchset adds the support for NAND controller of hisilicon hip04 Soc. The NAND controller IP was developed by hisilicon and needs a new driver to support it. This patchset is based on v3.18-rc1. I have tested that NAND flash controller works fine in Hip04 D01 board.

Changes in v3:
- Modify code to eliminate some code style warnings.
- add ecc-bits input check.
- avoid using waterfall style in hisi_nfc_cmdfunc().
Changes in v2:
- Remove the patch for device tree, now patchset only has the driver and its device tree binding documentation.
- Change the file name: hisi_nand.c to hisi504_nand.c.
Changes in v1:
- Remove callback functions out of struct hinfc_host, and call them directly in relative functions.
- Change hinfc_read and hinfc_write from macros to inline functions.
- Instead of putting pointers, embed struct nand_chip and struct mtd_info in struct hinfc_host directly.
- rewrite some unclear lines in device tree binding document, correct some code style error.

Link on v2:
- https://www.mail-archive.com/[email protected]/msg750071.html
Link on v1:
- https://lkml.org/lkml/2014/7/15/198

Zhou Wang (2):
mtd: hisilicon: add a new NAND controller driver for hisilicon hip04 Soc
mtd: hisilicon: add device tree binding documentation

 .../devicetree/bindings/mtd/hisi504-nand.txt       |   40 +
 drivers/mtd/nand/Kconfig                           |    5 +
 drivers/mtd/nand/Makefile                          |    1 +
 drivers/mtd/nand/hisi504_nand.c                    |  845 ++++++++++++++++++++
 4 files changed, 891 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/hisi504-nand.txt
 create mode 100644 drivers/mtd/nand/hisi504_nand.c
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v3 1/2 mtd: hisilicon: add a new NAND controller driver for hisilicon hip04 Soc

---
 drivers/mtd/nand/Kconfig        |    5 +
 drivers/mtd/nand/Makefile       |    1 +
 drivers/mtd/nand/hisi504_nand.c |  845 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 851 insertions(+)
 create mode 100644 drivers/mtd/nand/hisi504_nand.c
drivers/mtd/nand/Kconfig +5 -0
index dd10646..e451a08 100644
@@ -516,4 +516,9 @@ config MTD_NAND_XWAY
 	  Enables support for NAND Flash chips on Lantiq XWAY SoCs. NAND is attached
 	  to the External Bus Unit (EBU).
 
+config MTD_NAND_HISI504
+	tristate "Support for NAND controller on Hisilicon SoC Hip04"
+	help
+	  Enables support for NAND controller on Hisilicon SoC Hip04.
+
 endif # MTD_NAND
drivers/mtd/nand/Makefile +1 -0
index 9c847e4..fb1b2e4 100644
@@ -50,5 +50,6 @@ obj-$(CONFIG_MTD_NAND_JZ4740)		+= jz4740_nand.o
 obj-$(CONFIG_MTD_NAND_GPMI_NAND)	+= gpmi-nand/
 obj-$(CONFIG_MTD_NAND_XWAY)		+= xway_nand.o
 obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH)	+= bcm47xxnflash/
+obj-$(CONFIG_MTD_NAND_HISI504)	        += hisi504_nand.o
 
 nand-objs := nand_base.o nand_bbt.o nand_timings.o
drivers/mtd/nand/hisi504_nand.c new file +845 -0

845 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v3 1/2] mtd: hisilicon: add a new NAND controller driver for hisilicon hip04 Soc

Quoted 37 lines · Zhou Wang
drivers/mtd/nand/hisi504_nand.c new file +37 -0
+
+static int hisi_nfc_probe(struct platform_device *pdev)
+{
+       int ret = 0, irq, buswidth, flag, max_chips = HINFC504_MAX_CHIP;
+       struct device *dev = &pdev->dev;
+       struct hinfc_host *host;
+       struct nand_chip  *chip;
+       struct mtd_info   *mtd;
+       struct resource   *res;
+       struct device_node *np = dev->of_node;
+       struct mtd_part_parser_data ppdata;
+
+       host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
+       if (!host)
+               return -ENOMEM;
+       host->dev = dev;
+
+       platform_set_drvdata(pdev, host);
+       chip = &host->chip;
+       mtd  = &host->mtd;
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               dev_err(dev, "no IRQ resource defined\n");
+               ret = -ENXIO;
+               goto err_res;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       host->iobase = devm_ioremap_resource(dev, res);
+       if (IS_ERR(host->iobase)) {
+               ret = PTR_ERR(host->iobase);
+               dev_err(dev, "devm_ioremap_resource[0] fail\n");
+               goto err_res;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

drivers/mtd/nand/hisi504_nand.c line 694

Quoted 10 lines
drivers/mtd/nand/hisi504_nand.c new file +10 -0
+       chip->IO_ADDR_R = chip->IO_ADDR_W = devm_ioremap_resource(dev, res);
+       if (IS_ERR(chip->IO_ADDR_R)) {
+               ret = PTR_ERR(chip->IO_ADDR_R);
+               dev_err(dev, "devm_ioremap_resource[1] fail\n");
+               goto err_res;
+       }
+
+       mtd->priv               = chip;
+       mtd->owner              = THIS_MODULE;
+       mtd->name               = "hisi_nand";

+ mtd->dev.parent = &pdev->dev;

This is a bug that lives in a bunch of other nand drivers as well. add_mtd_device (called by mtd_device_parse_register()) expects dev.parent to be set for properly adding a device reference to the sysfs node.

Frans

author
#3 lore raw

Re: [PATCH v3 1/2] mtd: hisilicon: add a new NAND controller driver for hisilicon hip04 Soc

Quoted 51 lines · Frans Klaver
Quoted 37 lines · Zhou Wang
drivers/mtd/nand/hisi504_nand.c new file +37 -0
+
+static int hisi_nfc_probe(struct platform_device *pdev)
+{
+       int ret = 0, irq, buswidth, flag, max_chips = HINFC504_MAX_CHIP;
+       struct device *dev = &pdev->dev;
+       struct hinfc_host *host;
+       struct nand_chip  *chip;
+       struct mtd_info   *mtd;
+       struct resource   *res;
+       struct device_node *np = dev->of_node;
+       struct mtd_part_parser_data ppdata;
+
+       host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
+       if (!host)
+               return -ENOMEM;
+       host->dev = dev;
+
+       platform_set_drvdata(pdev, host);
+       chip = &host->chip;
+       mtd  = &host->mtd;
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               dev_err(dev, "no IRQ resource defined\n");
+               ret = -ENXIO;
+               goto err_res;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       host->iobase = devm_ioremap_resource(dev, res);
+       if (IS_ERR(host->iobase)) {
+               ret = PTR_ERR(host->iobase);
+               dev_err(dev, "devm_ioremap_resource[0] fail\n");
+               goto err_res;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

drivers/mtd/nand/hisi504_nand.c line 694

Quoted 10 lines
drivers/mtd/nand/hisi504_nand.c new file +10 -0
+       chip->IO_ADDR_R = chip->IO_ADDR_W = devm_ioremap_resource(dev, res);
+       if (IS_ERR(chip->IO_ADDR_R)) {
+               ret = PTR_ERR(chip->IO_ADDR_R);
+               dev_err(dev, "devm_ioremap_resource[1] fail\n");
+               goto err_res;
+       }
+
+       mtd->priv               = chip;
+       mtd->owner              = THIS_MODULE;
+       mtd->name               = "hisi_nand";

+ mtd->dev.parent = &pdev->dev;

Quoted 7 lines

This is a bug that lives in a bunch of other nand drivers as well. add_mtd_device (called by mtd_device_parse_register()) expects dev.parent to be set for properly adding a device reference to the sysfs node.

Frans

My mistake, I will add this line. Thanks a lot for your reminding.

Kind regards,
Zhou Wang

author
#4 lore raw

PATCH v3 2/2 mtd: hisilicon: add device tree binding documentation

In reply to Zhou Wang
---
 .../devicetree/bindings/mtd/hisi504-nand.txt       |   40 ++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/hisi504-nand.txt
Documentation/devicetree/bindings/mtd/hisi504-nand.txt new file +40 -0
new file mode 100644
index 0000000..c8b3988
@@ -0,0 +1,40 @@
+Hisilicon Hip04 Soc NAND controller DT binding
+
+Required properties:
+- compatible:          Should be "hisilicon,504-nfc".
+- reg:                 The first contains base physical address and size of
+                       NAND controller's registers. The second contains base
+                       physical address and size of NAND controller's buffer.
+- interrupts:          Interrupt number for nfc.
+- nand-bus-width:      See nand.txt.
+- nand-ecc-mode:       See nand.txt.
+- hisi,nand-ecc-bits:  ECC bits type support.
+                 <0>:  none ecc
+                 <1>:  Can correct 1bit per 512byte.
+                 <6>:  Can correct 16bits per 1K byte.
+- #address-cells:      partition address, should be set 1.
+- #size-cells:         partition size, should be set 1.
+
+Flash chip may optionally contain additional sub-nodes describing partitions of
+the address space. See partition.txt for more detail.
+
+Example:
+
+	nand: nand@4020000 {
+		compatible = "hisilicon,504-nfc";
+		reg = <0x4020000 0x10000>, <0x5000000 0x1000>;
+		interrupts = <0 379 4>;
+		nand-bus-width = <8>;
+		nand-ecc-mode = "hw";
+		hisi,nand-ecc-bits = <1>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		partition@0 {
+			label = "nand_text";
+			reg = <0x00000000 0x00400000>;
+		};
+
+		...
+
+	};
Signature · 1 line
1.7.9.5