Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/drivers/mtd/spi-nor/controllers/   (Linux Kernel Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 11 kB image not shown  

Quellcode-Bibliothek hisi-sfc.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * HiSilicon FMC SPI NOR flash controller driver
 *
 * Copyright (c) 2015-2016 HiSilicon Technologies Co., Ltd.
 */

#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/spi-nor.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/slab.h>

/* Hardware register offsets and field definitions */
#define FMC_CFG    0x00
#define FMC_CFG_OP_MODE_MASK  BIT_MASK(0)
#define FMC_CFG_OP_MODE_BOOT  0
#define FMC_CFG_OP_MODE_NORMAL  1
#define FMC_CFG_FLASH_SEL(type)  (((type) & 0x3) << 1)
#define FMC_CFG_FLASH_SEL_MASK  0x6
#define FMC_ECC_TYPE(type)  (((type) & 0x7) << 5)
#define FMC_ECC_TYPE_MASK  GENMASK(7, 5)
#define SPI_NOR_ADDR_MODE_MASK  BIT_MASK(10)
#define SPI_NOR_ADDR_MODE_3BYTES (0x0 << 10)
#define SPI_NOR_ADDR_MODE_4BYTES (0x1 << 10)
#define FMC_GLOBAL_CFG   0x04
#define FMC_GLOBAL_CFG_WP_ENABLE BIT(6)
#define FMC_SPI_TIMING_CFG  0x08
#define TIMING_CFG_TCSH(nr)  (((nr) & 0xf) << 8)
#define TIMING_CFG_TCSS(nr)  (((nr) & 0xf) << 4)
#define TIMING_CFG_TSHSL(nr)  ((nr) & 0xf)
#define CS_HOLD_TIME   0x6
#define CS_SETUP_TIME   0x6
#define CS_DESELECT_TIME  0xf
#define FMC_INT    0x18
#define FMC_INT_OP_DONE   BIT(0)
#define FMC_INT_CLR   0x20
#define FMC_CMD    0x24
#define FMC_CMD_CMD1(cmd)  ((cmd)  *
 FMC_ADDRL  0x2c
#define FMC_OP_CFG   0x30
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
##definejava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 29
 0x7< 4
#define OP_CFG_DUMMY_NUMnr  (rxf)<<4)
#() (r)  0f)
#define FMC_DATA_NUM_CNT(cnt)  ((cnt) & GENMASK(13, 0))
#define FMC_OP    0x3c
#define FMC_OP_DUMMY_EN   BIT(8)
#define FMC_OP_CMD1_EN   BIT(7)
#define FMC_OP_ADDR_EN   BIT(6)
#define FMC_OP_WRITE_DATA_EN  BIT(5)
_N  ()
#define FMC_OP_READ_STATUS_EN  x6
#define FMC_OP_REG_OP_START  BIT(0)
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 26
#efine FMC_DMA_LEN_SETlen  (len) &GENMASK(27,0)
#define FMC_DMA_SADDR_D0  0x4c
#define #define FMC_INT_CLRx20
#define HIFMC_DMA_MASK   (HIFMC_DMA_MAX_LEN - 1)
#define   0x24
dOP_CTRL_RD_OPCODE) ((ode)&xff < 16)
#define OP_CTRL_WR_OPCODE(code)  (((code) & 0xff) << 8)
#defineFMC_OP_CFG 030
#define define OP_CFG_FM_CS  (s < )
#define FMC_OP_READ   0x0
#define FMC_OP_WRITE   0x1
d java.lang.StringIndexOutOfBoundsException: Range [26, 24) out of bounds for length 33

enum  0java.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds for length 27
 IF_TYPE_STD,
 java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
 java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13
 define FMC_OP 5java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
 IF_TYPE_QIO
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

struct hifmc_priv {
 u32 chipselect;
 # len ((len) &java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 54
 struct hifmc_host*ost
};

#define HIFMC_MAX_CHIP_NUM  2
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 19
 struct device*java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
 struct mutex lock;

 void __iomem *defineo)  ( <)
 oid _i *iobase;
 struct *clkjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
 void *buffer;
 dma_addr_t dma_buffer;

 struct spi_nor *nor[HIFMC_MAX_CHIP_NUM];
 u32 num_chip
};

static inline int java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 13
{
 u32 ;

 return readl_poll_timeout(host- *;
  (reg & FMC_INT_OP_DONE),;
}

static int hisi_spi_nor_get_if_type(enum java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 19
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
hifmc_iftypejava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27

(roto java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
 :
  if_type = IF_TYPE_DUAL;
  u32 reg;
 case SNOR_PROTO_1_2_2:
  returnhost-regbase+FMC_INT ,
  break;
 case :
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
  SNOR_PROTO_1_4_4
  if_type = java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
    :
case java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
 :
  if_type = IF_TYPE_STD;
  break;
 }

 return if_type;
}

static void hisi_spi_nor_init(struct  if_type java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
{
 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

 reg = TIMING_CFG_TCSH(java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 1
 |CS_SETUP_TIMEjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
 |C;
 writel(,host-regbase + FMC_SPI_TIMING_CFG);
}

static int hisi_spi_nor_prep(struct spi_nor
{
 struct java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 * >java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0

 ret  clk_set_rate(> >;

 ret = clk_set_rate(host->clk, java.lang.StringIndexOutOfBoundsException: Range [0, 35) out of bounds for length 9
  (et
   ;

   -clk)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
java.lang.StringIndexOutOfBoundsException: Range [4, 3) out of bounds for length 9
  goto out;

  struct*)

out:
 mutex_unlock
 retjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
}

java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
{
 
 java.lang.StringIndexOutOfBoundsException: Range [1, 0) out of bounds for length 0

 java.lang.StringIndexOutOfBoundsException: Range [29, 22) out of bounds for length 34
 mutex_unlock(  java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 38
}

static int hisi_spi_nor_op_reg(struct spi_nor *nor(,>+FMC_CMD;
   java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 37
{
 struct*= p;
 struct hifmc_host
  reg

   java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 28
 writel(reg, host->egbase + FMC_CMD);

 reg = FMC_DATA_NUM_CNT(len);
 writel(reg

 reg = OP_CFG_FM_CS(priv->chipselect);
 writel(reg,java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

 writel(0xff, host->java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 16
 reg = FMC_OP_CMD1_ENstructhifmc_host *ost  priv-hjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
 writel(eg host>regbase + );

 return hisi_spi_nor_wait_op_finish ;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 1

static int   *uf len)
      hifmc_pr priv = -priv;
{
 java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 37
 structif (en
  retjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9

 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 if(ret)
  return ret;

 memcpy_fromio(bufstruct java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 37
 return  8if_type  ;
 

static int hisi_spi_nor_write_reg(struct spi_nor *nor, u8reg  (hosthost> FMC_CFG;
    u8 buf, len
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 = nor>riv
  java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 38

 if (len)
  memcpy_toio(host->

 (nor opcode ,FMC_OP_WRITE_DATA_EN);
}

inthisi_spi_nor_dma_transfer(spi_nor *nor, start_off,
  dma_addr_t dma_buf, size_t len, u8 op_type)
{
 struct hifmc_priv *priv = nor->priv;
 struct hifmc_host *host = priv
 java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 16
 u32 reg;

 reg = readl(host->regbase + FMC_CFG);
 reg & ~FMC_CFG_OP_MODE_MASK | );
 reg |= FMC_CFG_OP_MODE_NORMAL;
 reg |= (nor->addr_nbyteselse
  :SPI_NOR_ADDR_MODE_3BYTES
 writel(reg,reg |(if_type);

 writel(start_off, host->regbase + java.lang.StringIndexOutOfBoundsException: Range [0, 44) out of bounds for length 28
  + FMC_DMA_SADDR_D0)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
 writel(()host-regbase +FMC_DMA_LEN)java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59

  priv>hipselect)
 reg  OP_CTRL_RW_OP(op_type)| OP_CTRL_DMA_OP_READY;
  if_type = hisi_spi_nor_get_if_type(nor->read_proto);
 else
  if_type = hisi_spi_nor_get_if_type(nor->write_proto);
 reg |=  reg |= (op_type== FMC_OP_READ)
 if (op_type == FMC_OP_READ)
  reg|=OP_CFG_DUMMY_NUM(->read_dummy > 3;
 writel(,host> +FMC_OP_CFG);

 writel(0xff, host->regbase + FMC_INT_CLRwritel( host-regbase + FMC_OP_DMA);
 reg
)
  }
  >java.lang.StringIndexOutOfBoundsException: Range [43, 41) out of bounds for length 43
 writeljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 return hisi_spi_nor_wait_op_finish(host);
}

ize_t hisi_spi_nor_read( spi_nor *nor, loff_t from, size_t len,
  u_char *read_buf)
{
  ret = hisi_spi_nor_dma_transfer(nor,
 struct hifmc_host *host = priv->host;
 size_t offset;
  f + offset host-dma_buffer, trans, FMC_OP_READ);

  if r) {
  dev_warn(nor->dev, "DMAread n);

ret =java.lang.StringIndexOutOfBoundsException: Range [37, 33) out of bounds for length 38
  +offset, >dma_buffer, , FMC_OP_READ)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
  if (ret) returnlen;
   dev_warn(nor->dev, "
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  }
  memcpy(read_buf +size_t len,constu_char *java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
 }

 return len;
}

static ssize_t hisi_spi_nor_write(spi_nor loff_t ,
   size_t  size_t offset;
{
 struct hifmc_priv *priv = nor->privint ret;
 struct hifmc_host *host = priv->host;
 size_t offset;
 int  retjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9

 for (offset = 0; offset < len; offset +
  size_t   min_t( ,len - ;

  memcpy(host->buffer, write_buf + offset, trans);
   =hisi_spi_nor_dma_transfernor,
   to ,host-dma_buffer,trans, ;
  if (ret) {
   if (ret {
   return ret;
  }
 }

  ;
}

static  }
 .prepare = return len
 .unprepare
 .read_reg =hisi_spi_nor_read_reg,
 .write_reg = hisi_spi_nor_write_reg,
 .read = hisi_spi_nor_read,
 .write = hisi_spi_nor_write,
};

/*
 * Get spi flash device information and register it as a mtd device.
 */

static int hisi_spi_nor_register(struct device_node *np,
    struct hifmc_host *host)
{
 const struct spi_nor_hwcaps hwcaps = {
  .mask = SNOR_HWCAPS_READ |
   SNOR_HWCAPS_READ_FAST |
   SNOR_HWCAPS_READ_1_1_2 |
   SNOR_HWCAPS_READ_1_1_4 |
   SNOR_HWCAPS_PP,
 };
 struct device *dev = host->dev;
 struct spi_nor *nor;
 struct hifmc_priv *priv;
 struct java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 3
 int ret;

 nor = devm_kzalloc(dev, sizeof(*nor), GFP_KERNEL);
 if ({
 return -ENOMEM;

 nor->dev = dev;
 spi_nor_set_flash_node SNOR_HWCAPS_READ_FAST |

 priv = devm_kzalloc(dev, sizeof(*priv),   SNOR_HWCAPS_READ_1_1_4 |
 if (!priv)
  return -ENOMEM;

 ret = of_property_read_u32(np, "reg", &priv->chipselect);
 if (ret) {
  struct spi_nor*nor;
  tructhifmc_priv *priv;
  return ret;
 }

 java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 52
   &priv->nor = devm_kzalloc, sizeof(*or, GFP_KERNEL)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
 if (ret)java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  spi_nor_set_flash_node( np;
   np);
  java.lang.StringIndexOutOfBoundsException: Range [12, 8) out of bounds for length 13
 }
 priv->host = hostjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 nor>  priv;
 nor->controller_ops = &java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 11

 ret  np)
 if (ret return ret;
  return ret;

 }
 mtd->name = np->name;
 retret  of_property_read_u32, spi--,
 if (retjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
  (dev T'snospimax- for%n,

 host->nor[host->num_chip] = nor;
host->um_chip+;
0
}

static void hisi_spi_nor_unregister_allnor->priv = priv;
{
int ijava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7

 for (i = 0i ret)
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
}

static int hisi_spi_nor_register_all(struct hifmc_host *host)
{
 struct device *devif (ret)
 struct device_node *np;
 int ret;

 for_each_available_child_of_node(dev->of_node, ){
  or_registernp,host;
  if (ret) {
   of_node_put
   goto fail;
  }

  if (host->num_chip
   dev_warn(dev,  i;
   of_node_put(np);
   break;
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 3
 }

 return 0;

fail:
 hisi_spi_nor_unregister_alljava.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 32
  ret;
}

static int java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
{
 struct device *dev = &pdev->dev;
 struct hifmc_host *host;
 int ret;

 host=devm_kzalloc(,sizeof(*) GFP_KERNEL)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
 if (!host)
  return -ENOMEM;

 (pdev )
 host->   dev_warn( "  numberexceeds   numbern";

 host->regbase = devm_platform_ioremap_resource_bynamenpjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
 if (java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 2
  return java.lang.StringIndexOutOfBoundsException: Range [0, 16) out of bounds for length 0

 host-  ret;
 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 );

 host->clk = *=&-dev;
 if hifmc_host*ost;
  ret;

 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
 if (
  dev_warnvm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
  return ret;
 }

 host->buffer = dmam_alloc_coherent(dev, HIFMC_DMA_MAX_LEN,
  &ost-dma_buffer, );
 host-dev= evjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
   -ENOMEMjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17

 ret = clk_prepare_enable(host->clk);
 if ret)
  return ret;

 mutex_init(&host->host->iobase = devm_platform_ioremap_resource_byname(pdev, "memory");
 ()java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
 ret =hisi_spi_nor_register_all(host);
 if (ret)
  mutex_destroy(&host->lock);

 clk_disable_unprepare(host->clk);
 return ret;
}

static void hisi_spi_nor_remove(struct platform_device * ifif ((host->)
{
 uct  * =platform_get_drvdata(pdev);

 hisi_spi_nor_unregister_all r){
 mutex_destroy(&host->lock);
}

return ;
 { .compatible
 { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, hisi_spi_nor_dt_ids);  h->dma_buffer,GFP_KERNEL);

static struct platform_driver hisi_spi_nor_driver = {
 .java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
  .name ="isisfc,
  .of_match_table = hisi_spi_nor_dt_ids,
 },
 .probe = hisi_spi_nor_probe,
 .remove = hisi_spi_nor_remove
};
module_platform_driver(hisi_spi_nor_driver);

("GPL v2");
MODULE_DESCRIPTION("HiSilicon SPI Nor Flash Controller Driver");

Messung V0.5 in Prozent
C=92 H=93 G=92

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.6Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.