aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2018-07-25 09:31:41 -0400
committerMiquel Raynal <miquel.raynal@bootlin.com>2018-07-31 03:46:09 -0400
commit577e010c24bceb80dbbc146b2a4bd7ff0527fa9b (patch)
tree9ebc735e41e2f563a8ede81f45107e9abaa6a9f6
parent7928225ffcb3d01c424983af30aba3c16ab5a585 (diff)
mtd: rawnand: atmel: convert driver to nand_scan()
Two helpers have been added to the core to do all kind of controller side configuration/initialization between the detection phase and the final NAND scan. Implement these hooks so that we can convert the driver to just use nand_scan() instead of the nand_scan_ident() + nand_scan_tail() pair. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
-rw-r--r--drivers/mtd/nand/raw/atmel/nand-controller.c113
1 files changed, 54 insertions, 59 deletions
diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c
index 143d029710f0..a068b214ebaa 100644
--- a/drivers/mtd/nand/raw/atmel/nand-controller.c
+++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
@@ -201,7 +201,7 @@ struct atmel_nand_controller_ops {
201 int (*remove)(struct atmel_nand_controller *nc); 201 int (*remove)(struct atmel_nand_controller *nc);
202 void (*nand_init)(struct atmel_nand_controller *nc, 202 void (*nand_init)(struct atmel_nand_controller *nc,
203 struct atmel_nand *nand); 203 struct atmel_nand *nand);
204 int (*ecc_init)(struct atmel_nand *nand); 204 int (*ecc_init)(struct nand_chip *chip);
205 int (*setup_data_interface)(struct atmel_nand *nand, int csline, 205 int (*setup_data_interface)(struct atmel_nand *nand, int csline,
206 const struct nand_data_interface *conf); 206 const struct nand_data_interface *conf);
207}; 207};
@@ -1132,9 +1132,8 @@ static int atmel_nand_pmecc_init(struct nand_chip *chip)
1132 return 0; 1132 return 0;
1133} 1133}
1134 1134
1135static int atmel_nand_ecc_init(struct atmel_nand *nand) 1135static int atmel_nand_ecc_init(struct nand_chip *chip)
1136{ 1136{
1137 struct nand_chip *chip = &nand->base;
1138 struct atmel_nand_controller *nc; 1137 struct atmel_nand_controller *nc;
1139 int ret; 1138 int ret;
1140 1139
@@ -1169,12 +1168,11 @@ static int atmel_nand_ecc_init(struct atmel_nand *nand)
1169 return 0; 1168 return 0;
1170} 1169}
1171 1170
1172static int atmel_hsmc_nand_ecc_init(struct atmel_nand *nand) 1171static int atmel_hsmc_nand_ecc_init(struct nand_chip *chip)
1173{ 1172{
1174 struct nand_chip *chip = &nand->base;
1175 int ret; 1173 int ret;
1176 1174
1177 ret = atmel_nand_ecc_init(nand); 1175 ret = atmel_nand_ecc_init(chip);
1178 if (ret) 1176 if (ret)
1179 return ret; 1177 return ret;
1180 1178
@@ -1557,22 +1555,6 @@ static void atmel_hsmc_nand_init(struct atmel_nand_controller *nc,
1557 chip->select_chip = atmel_hsmc_nand_select_chip; 1555 chip->select_chip = atmel_hsmc_nand_select_chip;
1558} 1556}
1559 1557
1560static int atmel_nand_detect(struct atmel_nand *nand)
1561{
1562 struct nand_chip *chip = &nand->base;
1563 struct mtd_info *mtd = nand_to_mtd(chip);
1564 struct atmel_nand_controller *nc;
1565 int ret;
1566
1567 nc = to_nand_controller(chip->controller);
1568
1569 ret = nand_scan_ident(mtd, nand->numcs, NULL);
1570 if (ret)
1571 dev_err(nc->dev, "nand_scan_ident() failed: %d\n", ret);
1572
1573 return ret;
1574}
1575
1576static int atmel_nand_controller_remove_nand(struct atmel_nand *nand) 1558static int atmel_nand_controller_remove_nand(struct atmel_nand *nand)
1577{ 1559{
1578 struct nand_chip *chip = &nand->base; 1560 struct nand_chip *chip = &nand->base;
@@ -1700,6 +1682,8 @@ static int
1700atmel_nand_controller_add_nand(struct atmel_nand_controller *nc, 1682atmel_nand_controller_add_nand(struct atmel_nand_controller *nc,
1701 struct atmel_nand *nand) 1683 struct atmel_nand *nand)
1702{ 1684{
1685 struct nand_chip *chip = &nand->base;
1686 struct mtd_info *mtd = nand_to_mtd(chip);
1703 int ret; 1687 int ret;
1704 1688
1705 /* No card inserted, skip this NAND. */ 1689 /* No card inserted, skip this NAND. */
@@ -1710,44 +1694,9 @@ atmel_nand_controller_add_nand(struct atmel_nand_controller *nc,
1710 1694
1711 nc->caps->ops->nand_init(nc, nand); 1695 nc->caps->ops->nand_init(nc, nand);
1712 1696
1713 ret = atmel_nand_detect(nand); 1697 ret = nand_scan(mtd, nand->numcs);
1714 if (ret)
1715 return ret;
1716
1717 ret = nc->caps->ops->ecc_init(nand);
1718 if (ret)
1719 return ret;
1720
1721 if (nc->caps->legacy_of_bindings || !nc->dev->of_node) {
1722 /*
1723 * We keep the MTD name unchanged to avoid breaking platforms
1724 * where the MTD cmdline parser is used and the bootloader
1725 * has not been updated to use the new naming scheme.
1726 */
1727 mtd->name = "atmel_nand";
1728 } else if (!mtd->name) {
1729 /*
1730 * If the new bindings are used and the bootloader has not been
1731 * updated to pass a new mtdparts parameter on the cmdline, you
1732 * should define the following property in your nand node:
1733 *
1734 * label = "atmel_nand";
1735 *
1736 * This way, mtd->name will be set by the core when
1737 * nand_set_flash_node() is called.
1738 */
1739 mtd->name = devm_kasprintf(nc->dev, GFP_KERNEL,
1740 "%s:nand.%d", dev_name(nc->dev),
1741 nand->cs[0].id);
1742 if (!mtd->name) {
1743 dev_err(nc->dev, "Failed to allocate mtd->name\n");
1744 return -ENOMEM;
1745 }
1746 }
1747
1748 ret = nand_scan_tail(mtd);
1749 if (ret) { 1698 if (ret) {
1750 dev_err(nc->dev, "nand_scan_tail() failed: %d\n", ret); 1699 dev_err(nc->dev, "NAND scan failed: %d\n", ret);
1751 return ret; 1700 return ret;
1752 } 1701 }
1753 1702
@@ -1945,6 +1894,51 @@ static const struct of_device_id atmel_matrix_of_ids[] = {
1945 { /* sentinel */ }, 1894 { /* sentinel */ },
1946}; 1895};
1947 1896
1897static int atmel_nand_attach_chip(struct nand_chip *chip)
1898{
1899 struct atmel_nand_controller *nc = to_nand_controller(chip->controller);
1900 struct atmel_nand *nand = to_atmel_nand(chip);
1901 struct mtd_info *mtd = nand_to_mtd(chip);
1902 int ret;
1903
1904 ret = nc->caps->ops->ecc_init(chip);
1905 if (ret)
1906 return ret;
1907
1908 if (nc->caps->legacy_of_bindings || !nc->dev->of_node) {
1909 /*
1910 * We keep the MTD name unchanged to avoid breaking platforms
1911 * where the MTD cmdline parser is used and the bootloader
1912 * has not been updated to use the new naming scheme.
1913 */
1914 mtd->name = "atmel_nand";
1915 } else if (!mtd->name) {
1916 /*
1917 * If the new bindings are used and the bootloader has not been
1918 * updated to pass a new mtdparts parameter on the cmdline, you
1919 * should define the following property in your nand node:
1920 *
1921 * label = "atmel_nand";
1922 *
1923 * This way, mtd->name will be set by the core when
1924 * nand_set_flash_node() is called.
1925 */
1926 mtd->name = devm_kasprintf(nc->dev, GFP_KERNEL,
1927 "%s:nand.%d", dev_name(nc->dev),
1928 nand->cs[0].id);
1929 if (!mtd->name) {
1930 dev_err(nc->dev, "Failed to allocate mtd->name\n");
1931 return -ENOMEM;
1932 }
1933 }
1934
1935 return 0;
1936}
1937
1938static const struct nand_controller_ops atmel_nand_controller_ops = {
1939 .attach_chip = atmel_nand_attach_chip,
1940};
1941
1948static int atmel_nand_controller_init(struct atmel_nand_controller *nc, 1942static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
1949 struct platform_device *pdev, 1943 struct platform_device *pdev,
1950 const struct atmel_nand_controller_caps *caps) 1944 const struct atmel_nand_controller_caps *caps)
@@ -1954,6 +1948,7 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
1954 int ret; 1948 int ret;
1955 1949
1956 nand_controller_init(&nc->base); 1950 nand_controller_init(&nc->base);
1951 nc->base.ops = &atmel_nand_controller_ops;
1957 INIT_LIST_HEAD(&nc->chips); 1952 INIT_LIST_HEAD(&nc->chips);
1958 nc->dev = dev; 1953 nc->dev = dev;
1959 nc->caps = caps; 1954 nc->caps = caps;