cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

bcm63138_nand.c (2377B)


      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
     17struct 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
     25enum {
     26	BCM63138_CTLRDY		= BIT(4),
     27};
     28
     29static 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
     44static 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
     59static 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	struct resource *res;
     65
     66	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
     67	if (!priv)
     68		return -ENOMEM;
     69	soc = &priv->soc;
     70
     71	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand-int-base");
     72	priv->base = devm_ioremap_resource(dev, res);
     73	if (IS_ERR(priv->base))
     74		return PTR_ERR(priv->base);
     75
     76	soc->ctlrdy_ack = bcm63138_nand_intc_ack;
     77	soc->ctlrdy_set_enabled = bcm63138_nand_intc_set;
     78
     79	return brcmnand_probe(pdev, soc);
     80}
     81
     82static const struct of_device_id bcm63138_nand_of_match[] = {
     83	{ .compatible = "brcm,nand-bcm63138" },
     84	{},
     85};
     86MODULE_DEVICE_TABLE(of, bcm63138_nand_of_match);
     87
     88static struct platform_driver bcm63138_nand_driver = {
     89	.probe			= bcm63138_nand_probe,
     90	.remove			= brcmnand_remove,
     91	.driver = {
     92		.name		= "bcm63138_nand",
     93		.pm		= &brcmnand_pm_ops,
     94		.of_match_table	= bcm63138_nand_of_match,
     95	}
     96};
     97module_platform_driver(bcm63138_nand_driver);
     98
     99MODULE_LICENSE("GPL v2");
    100MODULE_AUTHOR("Brian Norris");
    101MODULE_DESCRIPTION("NAND driver for BCM63138");