1749af7cdSPeter Pan /* SPDX-License-Identifier: GPL-2.0 */ 2749af7cdSPeter Pan /* 3749af7cdSPeter Pan * Copyright (c) 2016-2017 Micron Technology, Inc. 4749af7cdSPeter Pan * 5749af7cdSPeter Pan * Authors: 6749af7cdSPeter Pan * Peter Pan <peterpandong@micron.com> 7749af7cdSPeter Pan */ 8749af7cdSPeter Pan #ifndef __LINUX_MTD_SPINAND_H 9749af7cdSPeter Pan #define __LINUX_MTD_SPINAND_H 10749af7cdSPeter Pan 11749af7cdSPeter Pan #ifndef __UBOOT__ 12749af7cdSPeter Pan #include <linux/mutex.h> 13749af7cdSPeter Pan #include <linux/bitops.h> 14749af7cdSPeter Pan #include <linux/device.h> 15749af7cdSPeter Pan #include <linux/mtd/mtd.h> 16749af7cdSPeter Pan #include <linux/mtd/nand.h> 17749af7cdSPeter Pan #include <linux/spi/spi.h> 18749af7cdSPeter Pan #include <linux/spi/spi-mem.h> 19749af7cdSPeter Pan #else 20749af7cdSPeter Pan #include <common.h> 21749af7cdSPeter Pan #include <spi.h> 22749af7cdSPeter Pan #include <spi-mem.h> 23749af7cdSPeter Pan #include <linux/mtd/nand.h> 24749af7cdSPeter Pan #endif 25749af7cdSPeter Pan 26749af7cdSPeter Pan /** 27749af7cdSPeter Pan * Standard SPI NAND flash operations 28749af7cdSPeter Pan */ 29749af7cdSPeter Pan 30749af7cdSPeter Pan #define SPINAND_RESET_OP \ 31749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0xff, 1), \ 32749af7cdSPeter Pan SPI_MEM_OP_NO_ADDR, \ 33749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 34749af7cdSPeter Pan SPI_MEM_OP_NO_DATA) 35749af7cdSPeter Pan 36749af7cdSPeter Pan #define SPINAND_WR_EN_DIS_OP(enable) \ 37749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD((enable) ? 0x06 : 0x04, 1), \ 38749af7cdSPeter Pan SPI_MEM_OP_NO_ADDR, \ 39749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 40749af7cdSPeter Pan SPI_MEM_OP_NO_DATA) 41749af7cdSPeter Pan 42749af7cdSPeter Pan #define SPINAND_READID_OP(ndummy, buf, len) \ 43749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0x9f, 1), \ 44749af7cdSPeter Pan SPI_MEM_OP_NO_ADDR, \ 45749af7cdSPeter Pan SPI_MEM_OP_DUMMY(ndummy, 1), \ 46749af7cdSPeter Pan SPI_MEM_OP_DATA_IN(len, buf, 1)) 47749af7cdSPeter Pan 48749af7cdSPeter Pan #define SPINAND_SET_FEATURE_OP(reg, valptr) \ 49749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0x1f, 1), \ 50749af7cdSPeter Pan SPI_MEM_OP_ADDR(1, reg, 1), \ 51749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 52749af7cdSPeter Pan SPI_MEM_OP_DATA_OUT(1, valptr, 1)) 53749af7cdSPeter Pan 54749af7cdSPeter Pan #define SPINAND_GET_FEATURE_OP(reg, valptr) \ 55749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0x0f, 1), \ 56749af7cdSPeter Pan SPI_MEM_OP_ADDR(1, reg, 1), \ 57749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 58749af7cdSPeter Pan SPI_MEM_OP_DATA_IN(1, valptr, 1)) 59749af7cdSPeter Pan 60749af7cdSPeter Pan #define SPINAND_BLK_ERASE_OP(addr) \ 61749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0xd8, 1), \ 62749af7cdSPeter Pan SPI_MEM_OP_ADDR(3, addr, 1), \ 63749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 64749af7cdSPeter Pan SPI_MEM_OP_NO_DATA) 65749af7cdSPeter Pan 66749af7cdSPeter Pan #define SPINAND_PAGE_READ_OP(addr) \ 67749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0x13, 1), \ 68749af7cdSPeter Pan SPI_MEM_OP_ADDR(3, addr, 1), \ 69749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 70749af7cdSPeter Pan SPI_MEM_OP_NO_DATA) 71749af7cdSPeter Pan 72749af7cdSPeter Pan #define SPINAND_PAGE_READ_FROM_CACHE_OP(fast, addr, ndummy, buf, len) \ 73749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(fast ? 0x0b : 0x03, 1), \ 74749af7cdSPeter Pan SPI_MEM_OP_ADDR(2, addr, 1), \ 75749af7cdSPeter Pan SPI_MEM_OP_DUMMY(ndummy, 1), \ 76749af7cdSPeter Pan SPI_MEM_OP_DATA_IN(len, buf, 1)) 77749af7cdSPeter Pan 78749af7cdSPeter Pan #define SPINAND_PAGE_READ_FROM_CACHE_X2_OP(addr, ndummy, buf, len) \ 79749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0x3b, 1), \ 80749af7cdSPeter Pan SPI_MEM_OP_ADDR(2, addr, 1), \ 81749af7cdSPeter Pan SPI_MEM_OP_DUMMY(ndummy, 1), \ 82749af7cdSPeter Pan SPI_MEM_OP_DATA_IN(len, buf, 2)) 83749af7cdSPeter Pan 84749af7cdSPeter Pan #define SPINAND_PAGE_READ_FROM_CACHE_X4_OP(addr, ndummy, buf, len) \ 85749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0x6b, 1), \ 86749af7cdSPeter Pan SPI_MEM_OP_ADDR(2, addr, 1), \ 87749af7cdSPeter Pan SPI_MEM_OP_DUMMY(ndummy, 1), \ 88749af7cdSPeter Pan SPI_MEM_OP_DATA_IN(len, buf, 4)) 89749af7cdSPeter Pan 90749af7cdSPeter Pan #define SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(addr, ndummy, buf, len) \ 91749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0xbb, 1), \ 92749af7cdSPeter Pan SPI_MEM_OP_ADDR(2, addr, 2), \ 93749af7cdSPeter Pan SPI_MEM_OP_DUMMY(ndummy, 2), \ 94749af7cdSPeter Pan SPI_MEM_OP_DATA_IN(len, buf, 2)) 95749af7cdSPeter Pan 96749af7cdSPeter Pan #define SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(addr, ndummy, buf, len) \ 97749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0xeb, 1), \ 98749af7cdSPeter Pan SPI_MEM_OP_ADDR(2, addr, 4), \ 99749af7cdSPeter Pan SPI_MEM_OP_DUMMY(ndummy, 4), \ 100749af7cdSPeter Pan SPI_MEM_OP_DATA_IN(len, buf, 4)) 101749af7cdSPeter Pan 102749af7cdSPeter Pan #define SPINAND_PROG_EXEC_OP(addr) \ 103749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(0x10, 1), \ 104749af7cdSPeter Pan SPI_MEM_OP_ADDR(3, addr, 1), \ 105749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 106749af7cdSPeter Pan SPI_MEM_OP_NO_DATA) 107749af7cdSPeter Pan 108749af7cdSPeter Pan #define SPINAND_PROG_LOAD(reset, addr, buf, len) \ 109749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(reset ? 0x02 : 0x84, 1), \ 110749af7cdSPeter Pan SPI_MEM_OP_ADDR(2, addr, 1), \ 111749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 112749af7cdSPeter Pan SPI_MEM_OP_DATA_OUT(len, buf, 1)) 113749af7cdSPeter Pan 114749af7cdSPeter Pan #define SPINAND_PROG_LOAD_X4(reset, addr, buf, len) \ 115749af7cdSPeter Pan SPI_MEM_OP(SPI_MEM_OP_CMD(reset ? 0x32 : 0x34, 1), \ 116749af7cdSPeter Pan SPI_MEM_OP_ADDR(2, addr, 1), \ 117749af7cdSPeter Pan SPI_MEM_OP_NO_DUMMY, \ 118749af7cdSPeter Pan SPI_MEM_OP_DATA_OUT(len, buf, 4)) 119749af7cdSPeter Pan 120749af7cdSPeter Pan /** 121749af7cdSPeter Pan * Standard SPI NAND flash commands 122749af7cdSPeter Pan */ 123749af7cdSPeter Pan #define SPINAND_CMD_PROG_LOAD_X4 0x32 124749af7cdSPeter Pan #define SPINAND_CMD_PROG_LOAD_RDM_DATA_X4 0x34 125749af7cdSPeter Pan 126749af7cdSPeter Pan /* feature register */ 127749af7cdSPeter Pan #define REG_BLOCK_LOCK 0xa0 128749af7cdSPeter Pan #define BL_ALL_UNLOCKED 0x00 129749af7cdSPeter Pan 130749af7cdSPeter Pan /* configuration register */ 131749af7cdSPeter Pan #define REG_CFG 0xb0 132749af7cdSPeter Pan #define CFG_OTP_ENABLE BIT(6) 133749af7cdSPeter Pan #define CFG_ECC_ENABLE BIT(4) 134749af7cdSPeter Pan #define CFG_QUAD_ENABLE BIT(0) 135749af7cdSPeter Pan 136749af7cdSPeter Pan /* status register */ 137749af7cdSPeter Pan #define REG_STATUS 0xc0 138749af7cdSPeter Pan #define STATUS_BUSY BIT(0) 139749af7cdSPeter Pan #define STATUS_ERASE_FAILED BIT(2) 140749af7cdSPeter Pan #define STATUS_PROG_FAILED BIT(3) 141749af7cdSPeter Pan #define STATUS_ECC_MASK GENMASK(5, 4) 142749af7cdSPeter Pan #define STATUS_ECC_NO_BITFLIPS (0 << 4) 143749af7cdSPeter Pan #define STATUS_ECC_HAS_BITFLIPS (1 << 4) 144749af7cdSPeter Pan #define STATUS_ECC_UNCOR_ERROR (2 << 4) 145749af7cdSPeter Pan 146749af7cdSPeter Pan struct spinand_op; 147749af7cdSPeter Pan struct spinand_device; 148749af7cdSPeter Pan 149749af7cdSPeter Pan #define SPINAND_MAX_ID_LEN 4 150749af7cdSPeter Pan 151749af7cdSPeter Pan /** 152749af7cdSPeter Pan * struct spinand_id - SPI NAND id structure 153749af7cdSPeter Pan * @data: buffer containing the id bytes. Currently 4 bytes large, but can 154749af7cdSPeter Pan * be extended if required 155749af7cdSPeter Pan * @len: ID length 156749af7cdSPeter Pan * 157749af7cdSPeter Pan * struct_spinand_id->data contains all bytes returned after a READ_ID command, 158749af7cdSPeter Pan * including dummy bytes if the chip does not emit ID bytes right after the 159749af7cdSPeter Pan * READ_ID command. The responsibility to extract real ID bytes is left to 160749af7cdSPeter Pan * struct_manufacurer_ops->detect(). 161749af7cdSPeter Pan */ 162749af7cdSPeter Pan struct spinand_id { 163749af7cdSPeter Pan u8 data[SPINAND_MAX_ID_LEN]; 164749af7cdSPeter Pan int len; 165749af7cdSPeter Pan }; 166749af7cdSPeter Pan 167749af7cdSPeter Pan /** 168749af7cdSPeter Pan * struct manufacurer_ops - SPI NAND manufacturer specific operations 169749af7cdSPeter Pan * @detect: detect a SPI NAND device. Every time a SPI NAND device is probed 170749af7cdSPeter Pan * the core calls the struct_manufacurer_ops->detect() hook of each 171749af7cdSPeter Pan * registered manufacturer until one of them return 1. Note that 172749af7cdSPeter Pan * the first thing to check in this hook is that the manufacturer ID 173749af7cdSPeter Pan * in struct_spinand_device->id matches the manufacturer whose 174749af7cdSPeter Pan * ->detect() hook has been called. Should return 1 if there's a 175749af7cdSPeter Pan * match, 0 if the manufacturer ID does not match and a negative 176749af7cdSPeter Pan * error code otherwise. When true is returned, the core assumes 177749af7cdSPeter Pan * that properties of the NAND chip (spinand->base.memorg and 178749af7cdSPeter Pan * spinand->base.eccreq) have been filled 179749af7cdSPeter Pan * @init: initialize a SPI NAND device 180749af7cdSPeter Pan * @cleanup: cleanup a SPI NAND device 181749af7cdSPeter Pan * 182749af7cdSPeter Pan * Each SPI NAND manufacturer driver should implement this interface so that 183749af7cdSPeter Pan * NAND chips coming from this vendor can be detected and initialized properly. 184749af7cdSPeter Pan */ 185749af7cdSPeter Pan struct spinand_manufacturer_ops { 186749af7cdSPeter Pan int (*detect)(struct spinand_device *spinand); 187749af7cdSPeter Pan int (*init)(struct spinand_device *spinand); 188749af7cdSPeter Pan void (*cleanup)(struct spinand_device *spinand); 189749af7cdSPeter Pan }; 190749af7cdSPeter Pan 191749af7cdSPeter Pan /** 192749af7cdSPeter Pan * struct spinand_manufacturer - SPI NAND manufacturer instance 193749af7cdSPeter Pan * @id: manufacturer ID 194749af7cdSPeter Pan * @name: manufacturer name 195749af7cdSPeter Pan * @ops: manufacturer operations 196749af7cdSPeter Pan */ 197749af7cdSPeter Pan struct spinand_manufacturer { 198749af7cdSPeter Pan u8 id; 199749af7cdSPeter Pan char *name; 200749af7cdSPeter Pan const struct spinand_manufacturer_ops *ops; 201749af7cdSPeter Pan }; 202749af7cdSPeter Pan 203ed13557fSPeter Pan /* SPI NAND manufacturers */ 2046eb4b036SStefan Roese extern const struct spinand_manufacturer gigadevice_spinand_manufacturer; 20580c0c832SBoris Brezillon extern const struct spinand_manufacturer macronix_spinand_manufacturer; 206ed13557fSPeter Pan extern const struct spinand_manufacturer micron_spinand_manufacturer; 207e0242cafSRobert Marko extern const struct spinand_manufacturer toshiba_spinand_manufacturer; 208b98ac5e2SFrieder Schrempf extern const struct spinand_manufacturer winbond_spinand_manufacturer; 209c219aedbSJon Lin extern const struct spinand_manufacturer dosilicon_spinand_manufacturer; 21052b00601SJon Lin extern const struct spinand_manufacturer esmt_spinand_manufacturer; 211fc656fc3SJon Lin extern const struct spinand_manufacturer xtx_spinand_manufacturer; 212b66d41c2SJon Lin extern const struct spinand_manufacturer hyf_spinand_manufacturer; 21303d86fc3SJon Lin extern const struct spinand_manufacturer fmsh_spinand_manufacturer; 214*e336ce4eSJon Lin extern const struct spinand_manufacturer foresee_spinand_manufacturer; 215ed13557fSPeter Pan 216749af7cdSPeter Pan /** 217749af7cdSPeter Pan * struct spinand_op_variants - SPI NAND operation variants 218749af7cdSPeter Pan * @ops: the list of variants for a given operation 219749af7cdSPeter Pan * @nops: the number of variants 220749af7cdSPeter Pan * 221749af7cdSPeter Pan * Some operations like read-from-cache/write-to-cache have several variants 222749af7cdSPeter Pan * depending on the number of IO lines you use to transfer data or address 223749af7cdSPeter Pan * cycles. This structure is a way to describe the different variants supported 224749af7cdSPeter Pan * by a chip and let the core pick the best one based on the SPI mem controller 225749af7cdSPeter Pan * capabilities. 226749af7cdSPeter Pan */ 227749af7cdSPeter Pan struct spinand_op_variants { 228749af7cdSPeter Pan const struct spi_mem_op *ops; 229749af7cdSPeter Pan unsigned int nops; 230749af7cdSPeter Pan }; 231749af7cdSPeter Pan 232749af7cdSPeter Pan #define SPINAND_OP_VARIANTS(name, ...) \ 233749af7cdSPeter Pan const struct spinand_op_variants name = { \ 234749af7cdSPeter Pan .ops = (struct spi_mem_op[]) { __VA_ARGS__ }, \ 235749af7cdSPeter Pan .nops = sizeof((struct spi_mem_op[]){ __VA_ARGS__ }) / \ 236749af7cdSPeter Pan sizeof(struct spi_mem_op), \ 237749af7cdSPeter Pan } 238749af7cdSPeter Pan 239749af7cdSPeter Pan /** 240749af7cdSPeter Pan * spinand_ecc_info - description of the on-die ECC implemented by a SPI NAND 241749af7cdSPeter Pan * chip 242749af7cdSPeter Pan * @get_status: get the ECC status. Should return a positive number encoding 243749af7cdSPeter Pan * the number of corrected bitflips if correction was possible or 244749af7cdSPeter Pan * -EBADMSG if there are uncorrectable errors. I can also return 245749af7cdSPeter Pan * other negative error codes if the error is not caused by 246749af7cdSPeter Pan * uncorrectable bitflips 247749af7cdSPeter Pan * @ooblayout: the OOB layout used by the on-die ECC implementation 248749af7cdSPeter Pan */ 249749af7cdSPeter Pan struct spinand_ecc_info { 250749af7cdSPeter Pan int (*get_status)(struct spinand_device *spinand, u8 status); 251749af7cdSPeter Pan const struct mtd_ooblayout_ops *ooblayout; 252749af7cdSPeter Pan }; 253749af7cdSPeter Pan 254749af7cdSPeter Pan #define SPINAND_HAS_QE_BIT BIT(0) 255749af7cdSPeter Pan 256749af7cdSPeter Pan /** 257749af7cdSPeter Pan * struct spinand_info - Structure used to describe SPI NAND chips 258749af7cdSPeter Pan * @model: model name 259749af7cdSPeter Pan * @devid: device ID 260749af7cdSPeter Pan * @flags: OR-ing of the SPINAND_XXX flags 261749af7cdSPeter Pan * @memorg: memory organization 262749af7cdSPeter Pan * @eccreq: ECC requirements 263749af7cdSPeter Pan * @eccinfo: on-die ECC info 264749af7cdSPeter Pan * @op_variants: operations variants 265749af7cdSPeter Pan * @op_variants.read_cache: variants of the read-cache operation 266749af7cdSPeter Pan * @op_variants.write_cache: variants of the write-cache operation 267749af7cdSPeter Pan * @op_variants.update_cache: variants of the update-cache operation 268749af7cdSPeter Pan * @select_target: function used to select a target/die. Required only for 269749af7cdSPeter Pan * multi-die chips 270749af7cdSPeter Pan * 271749af7cdSPeter Pan * Each SPI NAND manufacturer driver should have a spinand_info table 272749af7cdSPeter Pan * describing all the chips supported by the driver. 273749af7cdSPeter Pan */ 274749af7cdSPeter Pan struct spinand_info { 275749af7cdSPeter Pan const char *model; 276749af7cdSPeter Pan u8 devid; 277749af7cdSPeter Pan u32 flags; 278749af7cdSPeter Pan struct nand_memory_organization memorg; 279749af7cdSPeter Pan struct nand_ecc_req eccreq; 280749af7cdSPeter Pan struct spinand_ecc_info eccinfo; 281749af7cdSPeter Pan struct { 282749af7cdSPeter Pan const struct spinand_op_variants *read_cache; 283749af7cdSPeter Pan const struct spinand_op_variants *write_cache; 284749af7cdSPeter Pan const struct spinand_op_variants *update_cache; 285749af7cdSPeter Pan } op_variants; 286749af7cdSPeter Pan int (*select_target)(struct spinand_device *spinand, 287749af7cdSPeter Pan unsigned int target); 288749af7cdSPeter Pan }; 289749af7cdSPeter Pan 290749af7cdSPeter Pan #define SPINAND_INFO_OP_VARIANTS(__read, __write, __update) \ 291749af7cdSPeter Pan { \ 292749af7cdSPeter Pan .read_cache = __read, \ 293749af7cdSPeter Pan .write_cache = __write, \ 294749af7cdSPeter Pan .update_cache = __update, \ 295749af7cdSPeter Pan } 296749af7cdSPeter Pan 297749af7cdSPeter Pan #define SPINAND_ECCINFO(__ooblayout, __get_status) \ 298749af7cdSPeter Pan .eccinfo = { \ 299749af7cdSPeter Pan .ooblayout = __ooblayout, \ 300749af7cdSPeter Pan .get_status = __get_status, \ 301749af7cdSPeter Pan } 302749af7cdSPeter Pan 303749af7cdSPeter Pan #define SPINAND_SELECT_TARGET(__func) \ 304749af7cdSPeter Pan .select_target = __func, 305749af7cdSPeter Pan 306749af7cdSPeter Pan #define SPINAND_INFO(__model, __id, __memorg, __eccreq, __op_variants, \ 307749af7cdSPeter Pan __flags, ...) \ 308749af7cdSPeter Pan { \ 309749af7cdSPeter Pan .model = __model, \ 310749af7cdSPeter Pan .devid = __id, \ 311749af7cdSPeter Pan .memorg = __memorg, \ 312749af7cdSPeter Pan .eccreq = __eccreq, \ 313749af7cdSPeter Pan .op_variants = __op_variants, \ 314749af7cdSPeter Pan .flags = __flags, \ 315749af7cdSPeter Pan __VA_ARGS__ \ 316749af7cdSPeter Pan } 317749af7cdSPeter Pan 318749af7cdSPeter Pan /** 319749af7cdSPeter Pan * struct spinand_device - SPI NAND device instance 320749af7cdSPeter Pan * @base: NAND device instance 321749af7cdSPeter Pan * @slave: pointer to the SPI slave object 322749af7cdSPeter Pan * @lock: lock used to serialize accesses to the NAND 323749af7cdSPeter Pan * @id: NAND ID as returned by READ_ID 324749af7cdSPeter Pan * @flags: NAND flags 325749af7cdSPeter Pan * @op_templates: various SPI mem op templates 326749af7cdSPeter Pan * @op_templates.read_cache: read cache op template 327749af7cdSPeter Pan * @op_templates.write_cache: write cache op template 328749af7cdSPeter Pan * @op_templates.update_cache: update cache op template 329749af7cdSPeter Pan * @select_target: select a specific target/die. Usually called before sending 330749af7cdSPeter Pan * a command addressing a page or an eraseblock embedded in 331749af7cdSPeter Pan * this die. Only required if your chip exposes several dies 332749af7cdSPeter Pan * @cur_target: currently selected target/die 333749af7cdSPeter Pan * @eccinfo: on-die ECC information 334749af7cdSPeter Pan * @cfg_cache: config register cache. One entry per die 335749af7cdSPeter Pan * @databuf: bounce buffer for data 336749af7cdSPeter Pan * @oobbuf: bounce buffer for OOB data 337749af7cdSPeter Pan * @scratchbuf: buffer used for everything but page accesses. This is needed 338749af7cdSPeter Pan * because the spi-mem interface explicitly requests that buffers 339749af7cdSPeter Pan * passed in spi_mem_op be DMA-able, so we can't based the bufs on 340749af7cdSPeter Pan * the stack 341749af7cdSPeter Pan * @manufacturer: SPI NAND manufacturer information 342749af7cdSPeter Pan * @priv: manufacturer private data 343749af7cdSPeter Pan */ 344749af7cdSPeter Pan struct spinand_device { 345749af7cdSPeter Pan struct nand_device base; 346749af7cdSPeter Pan #ifndef __UBOOT__ 347749af7cdSPeter Pan struct spi_mem *spimem; 348749af7cdSPeter Pan struct mutex lock; 349749af7cdSPeter Pan #else 350749af7cdSPeter Pan struct spi_slave *slave; 351749af7cdSPeter Pan #endif 352749af7cdSPeter Pan struct spinand_id id; 353749af7cdSPeter Pan u32 flags; 354749af7cdSPeter Pan 355749af7cdSPeter Pan struct { 356749af7cdSPeter Pan const struct spi_mem_op *read_cache; 357749af7cdSPeter Pan const struct spi_mem_op *write_cache; 358749af7cdSPeter Pan const struct spi_mem_op *update_cache; 359749af7cdSPeter Pan } op_templates; 360749af7cdSPeter Pan 361749af7cdSPeter Pan int (*select_target)(struct spinand_device *spinand, 362749af7cdSPeter Pan unsigned int target); 363749af7cdSPeter Pan unsigned int cur_target; 364749af7cdSPeter Pan 365749af7cdSPeter Pan struct spinand_ecc_info eccinfo; 366749af7cdSPeter Pan 367749af7cdSPeter Pan u8 *cfg_cache; 368749af7cdSPeter Pan u8 *databuf; 369749af7cdSPeter Pan u8 *oobbuf; 370749af7cdSPeter Pan u8 *scratchbuf; 371749af7cdSPeter Pan const struct spinand_manufacturer *manufacturer; 372749af7cdSPeter Pan void *priv; 373749af7cdSPeter Pan }; 374749af7cdSPeter Pan 375749af7cdSPeter Pan /** 376749af7cdSPeter Pan * mtd_to_spinand() - Get the SPI NAND device attached to an MTD instance 377749af7cdSPeter Pan * @mtd: MTD instance 378749af7cdSPeter Pan * 379749af7cdSPeter Pan * Return: the SPI NAND device attached to @mtd. 380749af7cdSPeter Pan */ 381749af7cdSPeter Pan static inline struct spinand_device *mtd_to_spinand(struct mtd_info *mtd) 382749af7cdSPeter Pan { 383749af7cdSPeter Pan return container_of(mtd_to_nanddev(mtd), struct spinand_device, base); 384749af7cdSPeter Pan } 385749af7cdSPeter Pan 386749af7cdSPeter Pan /** 387749af7cdSPeter Pan * spinand_to_mtd() - Get the MTD device embedded in a SPI NAND device 388749af7cdSPeter Pan * @spinand: SPI NAND device 389749af7cdSPeter Pan * 390749af7cdSPeter Pan * Return: the MTD device embedded in @spinand. 391749af7cdSPeter Pan */ 392749af7cdSPeter Pan static inline struct mtd_info *spinand_to_mtd(struct spinand_device *spinand) 393749af7cdSPeter Pan { 394749af7cdSPeter Pan return nanddev_to_mtd(&spinand->base); 395749af7cdSPeter Pan } 396749af7cdSPeter Pan 397749af7cdSPeter Pan /** 398749af7cdSPeter Pan * nand_to_spinand() - Get the SPI NAND device embedding an NAND object 399749af7cdSPeter Pan * @nand: NAND object 400749af7cdSPeter Pan * 401749af7cdSPeter Pan * Return: the SPI NAND device embedding @nand. 402749af7cdSPeter Pan */ 403749af7cdSPeter Pan static inline struct spinand_device *nand_to_spinand(struct nand_device *nand) 404749af7cdSPeter Pan { 405749af7cdSPeter Pan return container_of(nand, struct spinand_device, base); 406749af7cdSPeter Pan } 407749af7cdSPeter Pan 408749af7cdSPeter Pan /** 409749af7cdSPeter Pan * spinand_to_nand() - Get the NAND device embedded in a SPI NAND object 410749af7cdSPeter Pan * @spinand: SPI NAND device 411749af7cdSPeter Pan * 412749af7cdSPeter Pan * Return: the NAND device embedded in @spinand. 413749af7cdSPeter Pan */ 414749af7cdSPeter Pan static inline struct nand_device * 415749af7cdSPeter Pan spinand_to_nand(struct spinand_device *spinand) 416749af7cdSPeter Pan { 417749af7cdSPeter Pan return &spinand->base; 418749af7cdSPeter Pan } 419749af7cdSPeter Pan 420749af7cdSPeter Pan /** 421749af7cdSPeter Pan * spinand_set_of_node - Attach a DT node to a SPI NAND device 422749af7cdSPeter Pan * @spinand: SPI NAND device 423749af7cdSPeter Pan * @np: DT node 424749af7cdSPeter Pan * 425749af7cdSPeter Pan * Attach a DT node to a SPI NAND device. 426749af7cdSPeter Pan */ 427749af7cdSPeter Pan static inline void spinand_set_of_node(struct spinand_device *spinand, 428749af7cdSPeter Pan const struct device_node *np) 429749af7cdSPeter Pan { 430749af7cdSPeter Pan nanddev_set_of_node(&spinand->base, np); 431749af7cdSPeter Pan } 432749af7cdSPeter Pan 433749af7cdSPeter Pan int spinand_match_and_init(struct spinand_device *dev, 434749af7cdSPeter Pan const struct spinand_info *table, 435749af7cdSPeter Pan unsigned int table_size, u8 devid); 436749af7cdSPeter Pan 437749af7cdSPeter Pan int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val); 438749af7cdSPeter Pan int spinand_select_target(struct spinand_device *spinand, unsigned int target); 439749af7cdSPeter Pan 440749af7cdSPeter Pan #endif /* __LINUX_MTD_SPINAND_H */ 441