162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* Freescale Local Bus Controller 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright © 2006-2007, 2010 Freescale Semiconductor 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Authors: Nick Spence <nick.spence@freescale.com>, 762306a36Sopenharmony_ci * Scott Wood <scottwood@freescale.com> 862306a36Sopenharmony_ci * Jack Lan <jack.lan@freescale.com> 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef __ASM_FSL_LBC_H 1262306a36Sopenharmony_ci#define __ASM_FSL_LBC_H 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/compiler.h> 1562306a36Sopenharmony_ci#include <linux/types.h> 1662306a36Sopenharmony_ci#include <linux/io.h> 1762306a36Sopenharmony_ci#include <linux/device.h> 1862306a36Sopenharmony_ci#include <linux/spinlock.h> 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_cistruct fsl_lbc_bank { 2162306a36Sopenharmony_ci __be32 br; /**< Base Register */ 2262306a36Sopenharmony_ci#define BR_BA 0xFFFF8000 2362306a36Sopenharmony_ci#define BR_BA_SHIFT 15 2462306a36Sopenharmony_ci#define BR_PS 0x00001800 2562306a36Sopenharmony_ci#define BR_PS_SHIFT 11 2662306a36Sopenharmony_ci#define BR_PS_8 0x00000800 /* Port Size 8 bit */ 2762306a36Sopenharmony_ci#define BR_PS_16 0x00001000 /* Port Size 16 bit */ 2862306a36Sopenharmony_ci#define BR_PS_32 0x00001800 /* Port Size 32 bit */ 2962306a36Sopenharmony_ci#define BR_DECC 0x00000600 3062306a36Sopenharmony_ci#define BR_DECC_SHIFT 9 3162306a36Sopenharmony_ci#define BR_DECC_OFF 0x00000000 /* HW ECC checking and generation off */ 3262306a36Sopenharmony_ci#define BR_DECC_CHK 0x00000200 /* HW ECC checking on, generation off */ 3362306a36Sopenharmony_ci#define BR_DECC_CHK_GEN 0x00000400 /* HW ECC checking and generation on */ 3462306a36Sopenharmony_ci#define BR_WP 0x00000100 3562306a36Sopenharmony_ci#define BR_WP_SHIFT 8 3662306a36Sopenharmony_ci#define BR_MSEL 0x000000E0 3762306a36Sopenharmony_ci#define BR_MSEL_SHIFT 5 3862306a36Sopenharmony_ci#define BR_MS_GPCM 0x00000000 /* GPCM */ 3962306a36Sopenharmony_ci#define BR_MS_FCM 0x00000020 /* FCM */ 4062306a36Sopenharmony_ci#define BR_MS_SDRAM 0x00000060 /* SDRAM */ 4162306a36Sopenharmony_ci#define BR_MS_UPMA 0x00000080 /* UPMA */ 4262306a36Sopenharmony_ci#define BR_MS_UPMB 0x000000A0 /* UPMB */ 4362306a36Sopenharmony_ci#define BR_MS_UPMC 0x000000C0 /* UPMC */ 4462306a36Sopenharmony_ci#define BR_V 0x00000001 4562306a36Sopenharmony_ci#define BR_V_SHIFT 0 4662306a36Sopenharmony_ci#define BR_RES ~(BR_BA|BR_PS|BR_DECC|BR_WP|BR_MSEL|BR_V) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci __be32 or; /**< Base Register */ 4962306a36Sopenharmony_ci#define OR0 0x5004 5062306a36Sopenharmony_ci#define OR1 0x500C 5162306a36Sopenharmony_ci#define OR2 0x5014 5262306a36Sopenharmony_ci#define OR3 0x501C 5362306a36Sopenharmony_ci#define OR4 0x5024 5462306a36Sopenharmony_ci#define OR5 0x502C 5562306a36Sopenharmony_ci#define OR6 0x5034 5662306a36Sopenharmony_ci#define OR7 0x503C 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define OR_FCM_AM 0xFFFF8000 5962306a36Sopenharmony_ci#define OR_FCM_AM_SHIFT 15 6062306a36Sopenharmony_ci#define OR_FCM_BCTLD 0x00001000 6162306a36Sopenharmony_ci#define OR_FCM_BCTLD_SHIFT 12 6262306a36Sopenharmony_ci#define OR_FCM_PGS 0x00000400 6362306a36Sopenharmony_ci#define OR_FCM_PGS_SHIFT 10 6462306a36Sopenharmony_ci#define OR_FCM_CSCT 0x00000200 6562306a36Sopenharmony_ci#define OR_FCM_CSCT_SHIFT 9 6662306a36Sopenharmony_ci#define OR_FCM_CST 0x00000100 6762306a36Sopenharmony_ci#define OR_FCM_CST_SHIFT 8 6862306a36Sopenharmony_ci#define OR_FCM_CHT 0x00000080 6962306a36Sopenharmony_ci#define OR_FCM_CHT_SHIFT 7 7062306a36Sopenharmony_ci#define OR_FCM_SCY 0x00000070 7162306a36Sopenharmony_ci#define OR_FCM_SCY_SHIFT 4 7262306a36Sopenharmony_ci#define OR_FCM_SCY_1 0x00000010 7362306a36Sopenharmony_ci#define OR_FCM_SCY_2 0x00000020 7462306a36Sopenharmony_ci#define OR_FCM_SCY_3 0x00000030 7562306a36Sopenharmony_ci#define OR_FCM_SCY_4 0x00000040 7662306a36Sopenharmony_ci#define OR_FCM_SCY_5 0x00000050 7762306a36Sopenharmony_ci#define OR_FCM_SCY_6 0x00000060 7862306a36Sopenharmony_ci#define OR_FCM_SCY_7 0x00000070 7962306a36Sopenharmony_ci#define OR_FCM_RST 0x00000008 8062306a36Sopenharmony_ci#define OR_FCM_RST_SHIFT 3 8162306a36Sopenharmony_ci#define OR_FCM_TRLX 0x00000004 8262306a36Sopenharmony_ci#define OR_FCM_TRLX_SHIFT 2 8362306a36Sopenharmony_ci#define OR_FCM_EHTR 0x00000002 8462306a36Sopenharmony_ci#define OR_FCM_EHTR_SHIFT 1 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#define OR_GPCM_AM 0xFFFF8000 8762306a36Sopenharmony_ci#define OR_GPCM_AM_SHIFT 15 8862306a36Sopenharmony_ci}; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_cistruct fsl_lbc_regs { 9162306a36Sopenharmony_ci struct fsl_lbc_bank bank[12]; 9262306a36Sopenharmony_ci u8 res0[0x8]; 9362306a36Sopenharmony_ci __be32 mar; /**< UPM Address Register */ 9462306a36Sopenharmony_ci u8 res1[0x4]; 9562306a36Sopenharmony_ci __be32 mamr; /**< UPMA Mode Register */ 9662306a36Sopenharmony_ci#define MxMR_OP_NO (0 << 28) /**< normal operation */ 9762306a36Sopenharmony_ci#define MxMR_OP_WA (1 << 28) /**< write array */ 9862306a36Sopenharmony_ci#define MxMR_OP_RA (2 << 28) /**< read array */ 9962306a36Sopenharmony_ci#define MxMR_OP_RP (3 << 28) /**< run pattern */ 10062306a36Sopenharmony_ci#define MxMR_MAD 0x3f /**< machine address */ 10162306a36Sopenharmony_ci __be32 mbmr; /**< UPMB Mode Register */ 10262306a36Sopenharmony_ci __be32 mcmr; /**< UPMC Mode Register */ 10362306a36Sopenharmony_ci u8 res2[0x8]; 10462306a36Sopenharmony_ci __be32 mrtpr; /**< Memory Refresh Timer Prescaler Register */ 10562306a36Sopenharmony_ci __be32 mdr; /**< UPM Data Register */ 10662306a36Sopenharmony_ci u8 res3[0x4]; 10762306a36Sopenharmony_ci __be32 lsor; /**< Special Operation Initiation Register */ 10862306a36Sopenharmony_ci __be32 lsdmr; /**< SDRAM Mode Register */ 10962306a36Sopenharmony_ci u8 res4[0x8]; 11062306a36Sopenharmony_ci __be32 lurt; /**< UPM Refresh Timer */ 11162306a36Sopenharmony_ci __be32 lsrt; /**< SDRAM Refresh Timer */ 11262306a36Sopenharmony_ci u8 res5[0x8]; 11362306a36Sopenharmony_ci __be32 ltesr; /**< Transfer Error Status Register */ 11462306a36Sopenharmony_ci#define LTESR_BM 0x80000000 11562306a36Sopenharmony_ci#define LTESR_FCT 0x40000000 11662306a36Sopenharmony_ci#define LTESR_PAR 0x20000000 11762306a36Sopenharmony_ci#define LTESR_WP 0x04000000 11862306a36Sopenharmony_ci#define LTESR_ATMW 0x00800000 11962306a36Sopenharmony_ci#define LTESR_ATMR 0x00400000 12062306a36Sopenharmony_ci#define LTESR_CS 0x00080000 12162306a36Sopenharmony_ci#define LTESR_UPM 0x00000002 12262306a36Sopenharmony_ci#define LTESR_CC 0x00000001 12362306a36Sopenharmony_ci#define LTESR_NAND_MASK (LTESR_FCT | LTESR_PAR | LTESR_CC) 12462306a36Sopenharmony_ci#define LTESR_MASK (LTESR_BM | LTESR_FCT | LTESR_PAR | LTESR_WP \ 12562306a36Sopenharmony_ci | LTESR_ATMW | LTESR_ATMR | LTESR_CS | LTESR_UPM \ 12662306a36Sopenharmony_ci | LTESR_CC) 12762306a36Sopenharmony_ci#define LTESR_CLEAR 0xFFFFFFFF 12862306a36Sopenharmony_ci#define LTECCR_CLEAR 0xFFFFFFFF 12962306a36Sopenharmony_ci#define LTESR_STATUS LTESR_MASK 13062306a36Sopenharmony_ci#define LTEIR_ENABLE LTESR_MASK 13162306a36Sopenharmony_ci#define LTEDR_ENABLE 0x00000000 13262306a36Sopenharmony_ci __be32 ltedr; /**< Transfer Error Disable Register */ 13362306a36Sopenharmony_ci __be32 lteir; /**< Transfer Error Interrupt Register */ 13462306a36Sopenharmony_ci __be32 lteatr; /**< Transfer Error Attributes Register */ 13562306a36Sopenharmony_ci __be32 ltear; /**< Transfer Error Address Register */ 13662306a36Sopenharmony_ci __be32 lteccr; /**< Transfer Error ECC Register */ 13762306a36Sopenharmony_ci u8 res6[0x8]; 13862306a36Sopenharmony_ci __be32 lbcr; /**< Configuration Register */ 13962306a36Sopenharmony_ci#define LBCR_LDIS 0x80000000 14062306a36Sopenharmony_ci#define LBCR_LDIS_SHIFT 31 14162306a36Sopenharmony_ci#define LBCR_BCTLC 0x00C00000 14262306a36Sopenharmony_ci#define LBCR_BCTLC_SHIFT 22 14362306a36Sopenharmony_ci#define LBCR_AHD 0x00200000 14462306a36Sopenharmony_ci#define LBCR_LPBSE 0x00020000 14562306a36Sopenharmony_ci#define LBCR_LPBSE_SHIFT 17 14662306a36Sopenharmony_ci#define LBCR_EPAR 0x00010000 14762306a36Sopenharmony_ci#define LBCR_EPAR_SHIFT 16 14862306a36Sopenharmony_ci#define LBCR_BMT 0x0000FF00 14962306a36Sopenharmony_ci#define LBCR_BMT_SHIFT 8 15062306a36Sopenharmony_ci#define LBCR_BMTPS 0x0000000F 15162306a36Sopenharmony_ci#define LBCR_BMTPS_SHIFT 0 15262306a36Sopenharmony_ci#define LBCR_INIT 0x00040000 15362306a36Sopenharmony_ci __be32 lcrr; /**< Clock Ratio Register */ 15462306a36Sopenharmony_ci#define LCRR_DBYP 0x80000000 15562306a36Sopenharmony_ci#define LCRR_DBYP_SHIFT 31 15662306a36Sopenharmony_ci#define LCRR_BUFCMDC 0x30000000 15762306a36Sopenharmony_ci#define LCRR_BUFCMDC_SHIFT 28 15862306a36Sopenharmony_ci#define LCRR_ECL 0x03000000 15962306a36Sopenharmony_ci#define LCRR_ECL_SHIFT 24 16062306a36Sopenharmony_ci#define LCRR_EADC 0x00030000 16162306a36Sopenharmony_ci#define LCRR_EADC_SHIFT 16 16262306a36Sopenharmony_ci#define LCRR_CLKDIV 0x0000000F 16362306a36Sopenharmony_ci#define LCRR_CLKDIV_SHIFT 0 16462306a36Sopenharmony_ci u8 res7[0x8]; 16562306a36Sopenharmony_ci __be32 fmr; /**< Flash Mode Register */ 16662306a36Sopenharmony_ci#define FMR_CWTO 0x0000F000 16762306a36Sopenharmony_ci#define FMR_CWTO_SHIFT 12 16862306a36Sopenharmony_ci#define FMR_BOOT 0x00000800 16962306a36Sopenharmony_ci#define FMR_ECCM 0x00000100 17062306a36Sopenharmony_ci#define FMR_AL 0x00000030 17162306a36Sopenharmony_ci#define FMR_AL_SHIFT 4 17262306a36Sopenharmony_ci#define FMR_OP 0x00000003 17362306a36Sopenharmony_ci#define FMR_OP_SHIFT 0 17462306a36Sopenharmony_ci __be32 fir; /**< Flash Instruction Register */ 17562306a36Sopenharmony_ci#define FIR_OP0 0xF0000000 17662306a36Sopenharmony_ci#define FIR_OP0_SHIFT 28 17762306a36Sopenharmony_ci#define FIR_OP1 0x0F000000 17862306a36Sopenharmony_ci#define FIR_OP1_SHIFT 24 17962306a36Sopenharmony_ci#define FIR_OP2 0x00F00000 18062306a36Sopenharmony_ci#define FIR_OP2_SHIFT 20 18162306a36Sopenharmony_ci#define FIR_OP3 0x000F0000 18262306a36Sopenharmony_ci#define FIR_OP3_SHIFT 16 18362306a36Sopenharmony_ci#define FIR_OP4 0x0000F000 18462306a36Sopenharmony_ci#define FIR_OP4_SHIFT 12 18562306a36Sopenharmony_ci#define FIR_OP5 0x00000F00 18662306a36Sopenharmony_ci#define FIR_OP5_SHIFT 8 18762306a36Sopenharmony_ci#define FIR_OP6 0x000000F0 18862306a36Sopenharmony_ci#define FIR_OP6_SHIFT 4 18962306a36Sopenharmony_ci#define FIR_OP7 0x0000000F 19062306a36Sopenharmony_ci#define FIR_OP7_SHIFT 0 19162306a36Sopenharmony_ci#define FIR_OP_NOP 0x0 /* No operation and end of sequence */ 19262306a36Sopenharmony_ci#define FIR_OP_CA 0x1 /* Issue current column address */ 19362306a36Sopenharmony_ci#define FIR_OP_PA 0x2 /* Issue current block+page address */ 19462306a36Sopenharmony_ci#define FIR_OP_UA 0x3 /* Issue user defined address */ 19562306a36Sopenharmony_ci#define FIR_OP_CM0 0x4 /* Issue command from FCR[CMD0] */ 19662306a36Sopenharmony_ci#define FIR_OP_CM1 0x5 /* Issue command from FCR[CMD1] */ 19762306a36Sopenharmony_ci#define FIR_OP_CM2 0x6 /* Issue command from FCR[CMD2] */ 19862306a36Sopenharmony_ci#define FIR_OP_CM3 0x7 /* Issue command from FCR[CMD3] */ 19962306a36Sopenharmony_ci#define FIR_OP_WB 0x8 /* Write FBCR bytes from FCM buffer */ 20062306a36Sopenharmony_ci#define FIR_OP_WS 0x9 /* Write 1 or 2 bytes from MDR[AS] */ 20162306a36Sopenharmony_ci#define FIR_OP_RB 0xA /* Read FBCR bytes to FCM buffer */ 20262306a36Sopenharmony_ci#define FIR_OP_RS 0xB /* Read 1 or 2 bytes to MDR[AS] */ 20362306a36Sopenharmony_ci#define FIR_OP_CW0 0xC /* Wait then issue FCR[CMD0] */ 20462306a36Sopenharmony_ci#define FIR_OP_CW1 0xD /* Wait then issue FCR[CMD1] */ 20562306a36Sopenharmony_ci#define FIR_OP_RBW 0xE /* Wait then read FBCR bytes */ 20662306a36Sopenharmony_ci#define FIR_OP_RSW 0xE /* Wait then read 1 or 2 bytes */ 20762306a36Sopenharmony_ci __be32 fcr; /**< Flash Command Register */ 20862306a36Sopenharmony_ci#define FCR_CMD0 0xFF000000 20962306a36Sopenharmony_ci#define FCR_CMD0_SHIFT 24 21062306a36Sopenharmony_ci#define FCR_CMD1 0x00FF0000 21162306a36Sopenharmony_ci#define FCR_CMD1_SHIFT 16 21262306a36Sopenharmony_ci#define FCR_CMD2 0x0000FF00 21362306a36Sopenharmony_ci#define FCR_CMD2_SHIFT 8 21462306a36Sopenharmony_ci#define FCR_CMD3 0x000000FF 21562306a36Sopenharmony_ci#define FCR_CMD3_SHIFT 0 21662306a36Sopenharmony_ci __be32 fbar; /**< Flash Block Address Register */ 21762306a36Sopenharmony_ci#define FBAR_BLK 0x00FFFFFF 21862306a36Sopenharmony_ci __be32 fpar; /**< Flash Page Address Register */ 21962306a36Sopenharmony_ci#define FPAR_SP_PI 0x00007C00 22062306a36Sopenharmony_ci#define FPAR_SP_PI_SHIFT 10 22162306a36Sopenharmony_ci#define FPAR_SP_MS 0x00000200 22262306a36Sopenharmony_ci#define FPAR_SP_CI 0x000001FF 22362306a36Sopenharmony_ci#define FPAR_SP_CI_SHIFT 0 22462306a36Sopenharmony_ci#define FPAR_LP_PI 0x0003F000 22562306a36Sopenharmony_ci#define FPAR_LP_PI_SHIFT 12 22662306a36Sopenharmony_ci#define FPAR_LP_MS 0x00000800 22762306a36Sopenharmony_ci#define FPAR_LP_CI 0x000007FF 22862306a36Sopenharmony_ci#define FPAR_LP_CI_SHIFT 0 22962306a36Sopenharmony_ci __be32 fbcr; /**< Flash Byte Count Register */ 23062306a36Sopenharmony_ci#define FBCR_BC 0x00000FFF 23162306a36Sopenharmony_ci}; 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci/* 23462306a36Sopenharmony_ci * FSL UPM routines 23562306a36Sopenharmony_ci */ 23662306a36Sopenharmony_cistruct fsl_upm { 23762306a36Sopenharmony_ci __be32 __iomem *mxmr; 23862306a36Sopenharmony_ci int width; 23962306a36Sopenharmony_ci}; 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ciextern u32 fsl_lbc_addr(phys_addr_t addr_base); 24262306a36Sopenharmony_ciextern int fsl_lbc_find(phys_addr_t addr_base); 24362306a36Sopenharmony_ciextern int fsl_upm_find(phys_addr_t addr_base, struct fsl_upm *upm); 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci/** 24662306a36Sopenharmony_ci * fsl_upm_start_pattern - start UPM patterns execution 24762306a36Sopenharmony_ci * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find 24862306a36Sopenharmony_ci * @pat_offset: UPM pattern offset for the command to be executed 24962306a36Sopenharmony_ci * 25062306a36Sopenharmony_ci * This routine programmes UPM so the next memory access that hits an UPM 25162306a36Sopenharmony_ci * will trigger pattern execution, starting at pat_offset. 25262306a36Sopenharmony_ci */ 25362306a36Sopenharmony_cistatic inline void fsl_upm_start_pattern(struct fsl_upm *upm, u8 pat_offset) 25462306a36Sopenharmony_ci{ 25562306a36Sopenharmony_ci clrsetbits_be32(upm->mxmr, MxMR_MAD, MxMR_OP_RP | pat_offset); 25662306a36Sopenharmony_ci} 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci/** 25962306a36Sopenharmony_ci * fsl_upm_end_pattern - end UPM patterns execution 26062306a36Sopenharmony_ci * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find 26162306a36Sopenharmony_ci * 26262306a36Sopenharmony_ci * This routine reverts UPM to normal operation mode. 26362306a36Sopenharmony_ci */ 26462306a36Sopenharmony_cistatic inline void fsl_upm_end_pattern(struct fsl_upm *upm) 26562306a36Sopenharmony_ci{ 26662306a36Sopenharmony_ci clrbits32(upm->mxmr, MxMR_OP_RP); 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci while (in_be32(upm->mxmr) & MxMR_OP_RP) 26962306a36Sopenharmony_ci cpu_relax(); 27062306a36Sopenharmony_ci} 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci/* overview of the fsl lbc controller */ 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_cistruct fsl_lbc_ctrl { 27562306a36Sopenharmony_ci /* device info */ 27662306a36Sopenharmony_ci struct device *dev; 27762306a36Sopenharmony_ci struct fsl_lbc_regs __iomem *regs; 27862306a36Sopenharmony_ci int irq[2]; 27962306a36Sopenharmony_ci wait_queue_head_t irq_wait; 28062306a36Sopenharmony_ci spinlock_t lock; 28162306a36Sopenharmony_ci void *nand; 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci /* status read from LTESR by irq handler */ 28462306a36Sopenharmony_ci unsigned int irq_status; 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_ci#ifdef CONFIG_SUSPEND 28762306a36Sopenharmony_ci /* save regs when system go to deep-sleep */ 28862306a36Sopenharmony_ci struct fsl_lbc_regs *saved_regs; 28962306a36Sopenharmony_ci#endif 29062306a36Sopenharmony_ci}; 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ciextern int fsl_upm_run_pattern(struct fsl_upm *upm, void __iomem *io_base, 29362306a36Sopenharmony_ci u32 mar); 29462306a36Sopenharmony_ciextern struct fsl_lbc_ctrl *fsl_lbc_ctrl_dev; 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci#endif /* __ASM_FSL_LBC_H */ 297