1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright © 2015 Broadcom Corporation 4 */ 5 6 #include <linux/device.h> 7 #include <linux/io.h> 8 #include <linux/ioport.h> 9 #include <linux/module.h> 10 #include <linux/of.h> 11 #include <linux/of_address.h> 12 #include <linux/platform_device.h> 13 #include <linux/slab.h> 14 15 #include "brcmnand.h" 16 17 struct bcm63138_nand_soc { 18 struct brcmnand_soc soc; 19 void __iomem *base; 20 }; 21 22 #define BCM63138_NAND_INT_STATUS 0x00 23 #define BCM63138_NAND_INT_EN 0x04 24 25 enum { 26 BCM63138_CTLRDY = BIT(4), 27 }; 28 29 static bool bcm63138_nand_intc_ack(struct brcmnand_soc *soc) 30 { 31 struct bcm63138_nand_soc *priv = 32 container_of(soc, struct bcm63138_nand_soc, soc); 33 void __iomem *mmio = priv->base + BCM63138_NAND_INT_STATUS; 34 u32 val = brcmnand_readl(mmio); 35 36 if (val & BCM63138_CTLRDY) { 37 brcmnand_writel(val & ~BCM63138_CTLRDY, mmio); 38 return true; 39 } 40 41 return false; 42 } 43 44 static void bcm63138_nand_intc_set(struct brcmnand_soc *soc, bool en) 45 { 46 struct bcm63138_nand_soc *priv = 47 container_of(soc, struct bcm63138_nand_soc, soc); 48 void __iomem *mmio = priv->base + BCM63138_NAND_INT_EN; 49 u32 val = brcmnand_readl(mmio); 50 51 if (en) 52 val |= BCM63138_CTLRDY; 53 else 54 val &= ~BCM63138_CTLRDY; 55 56 brcmnand_writel(val, mmio); 57 } 58 59 static int bcm63138_nand_probe(struct platform_device *pdev) 60 { 61 struct device *dev = &pdev->dev; 62 struct bcm63138_nand_soc *priv; 63 struct brcmnand_soc *soc; 64 65 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 66 if (!priv) 67 return -ENOMEM; 68 soc = &priv->soc; 69 70 priv->base = devm_platform_ioremap_resource_byname(pdev, "nand-int-base"); 71 if (IS_ERR(priv->base)) 72 return PTR_ERR(priv->base); 73 74 soc->ctlrdy_ack = bcm63138_nand_intc_ack; 75 soc->ctlrdy_set_enabled = bcm63138_nand_intc_set; 76 77 return brcmnand_probe(pdev, soc); 78 } 79 80 static const struct of_device_id bcm63138_nand_of_match[] = { 81 { .compatible = "brcm,nand-bcm63138" }, 82 {}, 83 }; 84 MODULE_DEVICE_TABLE(of, bcm63138_nand_of_match); 85 86 static struct platform_driver bcm63138_nand_driver = { 87 .probe = bcm63138_nand_probe, 88 .remove = brcmnand_remove, 89 .driver = { 90 .name = "bcm63138_nand", 91 .pm = &brcmnand_pm_ops, 92 .of_match_table = bcm63138_nand_of_match, 93 } 94 }; 95 module_platform_driver(bcm63138_nand_driver); 96 97 MODULE_LICENSE("GPL v2"); 98 MODULE_AUTHOR("Brian Norris"); 99 MODULE_DESCRIPTION("NAND driver for BCM63138"); 100