3 #define __SIMPLE_DEVICE__
23 #define HSFC_FCYCLE_OFF 1
24 #define HSFC_FCYCLE (0x3 << HSFC_FCYCLE_OFF)
25 #define HSFC_FDBC_OFF 8
26 #define HSFC_FDBC (0x3f << HSFC_FDBC_OFF)
154 #if CONFIG(DEBUG_SPI_FLASH)
161 v, ((
unsigned int)
addr & 0xffff) - 0xf020);
170 v, ((
unsigned int)
addr & 0xffff) - 0xf020);
179 v, ((
unsigned int)
addr & 0xffff) - 0xf020);
187 b, ((
unsigned int)
addr & 0xffff) - 0xf020);
194 b, ((
unsigned int)
addr & 0xffff) - 0xf020);
201 b, ((
unsigned int)
addr & 0xffff) - 0xf020);
206 #define readb_(a) read8(a)
207 #define readw_(a) read16(a)
208 #define readl_(a) read32(a)
209 #define writeb_(val, addr) write8(addr, val)
210 #define writew_(val, addr) write16(addr, val)
211 #define writel_(val, addr) write32(addr, val)
222 bdest += 4; bvalue += 4; size -= 4;
226 bdest++; bvalue++; size--;
237 bsrc += 4; bvalue += 4; size -= 4;
241 bsrc++; bvalue++; size--;
247 const uint32_t bbar_mask = 0x00ffff00;
250 minaddr &= bbar_mask;
252 ichspi_bbar |= minaddr;
256 #if CONFIG(SOUTHBRIDGE_INTEL_I82801GX)
257 #define MENU_BYTES member_size(struct ich7_spi_regs, opmenu)
259 #define MENU_BYTES member_size(struct ich9_spi_regs, opmenu)
270 if (
CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
272 return (
void *)((rcba & 0xffffc000) + 0x3020);
274 if (
CONFIG(SOUTHBRIDGE_INTEL_COMMON_SPI_SILVERMONT)) {
277 return (
void *)sbase;
279 if (
CONFIG(SOUTHBRIDGE_INTEL_COMMON_SPI_ICH9)) {
281 return (
void *)((rcba & 0xffffc000) + 0x3800);
293 if (
CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
342 if (
CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
423 optypes = (optypes & 0xfffc) | (trans->
type & 0x3);
437 for (opcode_index = 0; opcode_index <
ARRAY_SIZE(opmenu); opcode_index++) {
438 if (opmenu[opcode_index] == trans->
opcode)
449 optype = (optypes >> (opcode_index * 2)) & 0x3;
467 switch (trans->
type) {
493 int timeout = 600000;
498 if (wait_til_set ^ ((status & bitmask) == 0)) {
519 size_t bytesout,
void *din,
size_t bytesin)
533 if (!bytesout || !dout) {
538 if (bytesin != 0 && !din) {
566 control =
SPIC_SCGO | ((opcode_index & 0x07) << 4);
606 printk(
BIOS_DEBUG,
"ICH SPI: Too much to write. Does your SPI chip driver use"
607 " spi_crop_chunk()?\n");
631 trans.
offset += data_length;
637 control |= (data_length - 1) << 8;
656 trans.
offset += data_length;
698 "0x%08x (= 0x%08x + %d) HSFC=%x HSFS=%x!\n",
709 "0x%08x (= 0x%08x + %d) HSFC=%x HSFS=%x!\n",
720 u32 start, end, erase_size;
726 if (
offset % erase_size || len % erase_size) {
727 printk(
BIOS_ERR,
"SF: Erase offset/length not multiple of erase size\n");
760 printk(
BIOS_DEBUG,
"SF: Successfully erased %zu bytes @ %#x\n", len, start);
772 for (i = 0; i < len; i++) {
776 data[i] = (temp32 >> ((i % 4) * 8)) & 0xff;
789 "Attempt to read %x-%x which is out of chip\n",
791 (
unsigned int)
addr+(
unsigned int) len);
800 if (block_len > (~
addr & 0xff))
801 block_len = (~
addr & 0xff) + 1;
834 for (i = 0; i < len; i++) {
838 temp32 |= ((
uint32_t) data[i]) << ((i % 4) * 8);
858 "Attempt to write 0x%x-0x%x which is out of chip\n",
859 (
unsigned int)
addr, (
unsigned int) (
addr+len));
868 if (block_len > (~
addr & 0xff))
869 block_len = (~
addr & 0xff) + 1;
893 (
unsigned int) (
addr - start), start);
907 if (
CONFIG(SOUTHBRIDGE_INTEL_I82801GX))
949 #define SPI_FPR_SHIFT 12
950 #define ICH7_SPI_FPR_MASK 0xfff
951 #define ICH9_SPI_FPR_MASK 0x1fff
952 #define SPI_FPR_BASE_SHIFT 0
953 #define ICH7_SPI_FPR_LIMIT_SHIFT 12
954 #define ICH9_SPI_FPR_LIMIT_SHIFT 16
955 #define ICH9_SPI_FPR_RPE (1 << 15)
956 #define SPI_FPR_WPE (1 << 31)
963 if (
CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
987 u32 protect_mask = 0;
995 reg =
read32(&fpr_base[fpr]);
1010 if (
CONFIG(SOUTHBRIDGE_INTEL_I82801GX))
1015 if (
CONFIG(SOUTHBRIDGE_INTEL_I82801GX))
1025 reg =
spi_fpr(start, end) | protect_mask;
1029 if (reg !=
read32(&fpr_base[fpr])) {
1035 __func__, fpr, start, end);
1103 #define BIOS_CNTL 0xdc
1104 #define BIOS_CNTL_BIOSWE (1 << 0)
1105 #define BIOS_CNTL_BLE (1 << 1)
1106 #define BIOS_CNTL_SMM_BWP (1 << 5)
1110 if (!(
CONFIG(SOUTHBRIDGE_INTEL_I82801GX) ||
CONFIG(SOUTHBRIDGE_INTEL_COMMON_SPI_ICH9)))
static void write8(void *addr, uint8_t val)
static void write32(void *addr, uint32_t val)
static uint16_t read16(const void *addr)
static uint32_t read32(const void *addr)
static uint8_t read8(const void *addr)
static void write16(void *addr, uint16_t val)
void * memcpy(void *dest, const void *src, size_t n)
const struct spi_flash * boot_device_spi_flash(void)
#define member_size(type, member)
#define printk(level,...)
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
#define BIOS_INFO
BIOS_INFO - Expected events.
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
#define PCI_DEV(SEGBUS, DEV, FN)
static size_t region_sz(const struct region *r)
static size_t region_offset(const struct region *r)
const struct smm_save_state_ops *legacy_ops __weak
const struct spi_ctrlr_buses spi_ctrlr_bus_map[]
void spi_init(void)
Init all SPI controllers with default values and enable all SPI controller.
const size_t spi_ctrlr_bus_map_count
BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, spi_init_cb, NULL)
#define SPI_FPR_BASE_SHIFT
static void spi_use_in(spi_transaction *trans, unsigned int bytes)
static const struct spi_flash_ops spi_flash_ops
static int xfer_vectors(const struct spi_slave *slave, struct spi_op vectors[], size_t count)
#define writel_(val, addr)
static int ich_hwseq_wait_for_cycle_complete(unsigned int timeout, unsigned int len)
static int spi_setup_offset(spi_transaction *trans)
static int spi_is_multichip(void)
static void spi_set_smm_only_flashing(bool enable)
static int spi_locked(void)
#define ICH7_SPI_FPR_MASK
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)
static int ich_status_poll(u16 bitmask, int wait_til_set)
static void spi_use_out(spi_transaction *trans, unsigned int bytes)
static int spi_flash_programmer_probe(const struct spi_slave *spi, struct spi_flash *flash)
static void ich_hwseq_set_addr(uint32_t addr)
static int ich_hwseq_read(const struct spi_flash *flash, u32 addr, size_t len, void *buf)
void spi_finalize_ops(void)
static int ich_hwseq_erase(const struct spi_flash *flash, u32 offset, size_t len)
static void spi_init_cb(void *unused)
struct ich7_spi_regs __packed
static u32 spi_fpr(u32 base, u32 limit)
static void spi_setup_type(spi_transaction *trans)
static struct ich_spi_controller cntlr
static void write_reg(const void *value, void *dest, uint32_t size)
static int spi_setup_opcode(spi_transaction *trans)
@ SPI_OPCODE_TYPE_WRITE_NO_ADDRESS
@ SPI_OPCODE_TYPE_READ_WITH_ADDRESS
@ SPI_OPCODE_TYPE_READ_NO_ADDRESS
@ SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS
#define ICH9_SPI_FPR_LIMIT_SHIFT
static int spi_flash_protect(const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
#define BIOS_CNTL_SMM_BWP
static void ich_read_data(uint8_t *data, int len)
static void * get_spi_bar(pci_devfn_t dev)
#define writeb_(val, addr)
static int ich_hwseq_write(const struct spi_flash *flash, u32 addr, size_t len, const void *buf)
static void ich_set_bbar(uint32_t minaddr)
static void read_reg(const void *src, void *value, uint32_t size)
#define ICH7_SPI_FPR_LIMIT_SHIFT
#define ICH9_SPI_FPR_MASK
__weak void intel_southbridge_override_spi(struct intel_swseq_spi_config *spi_config)
#define writew_(val, addr)
struct spi_transaction spi_transaction
static void ich_fill_data(const uint8_t *data, int len)
int spi_claim_bus(const struct spi_slave *slave)
void spi_release_bus(const struct spi_slave *slave)
int spi_flash_generic_probe(const struct spi_slave *spi, struct spi_flash *flash)
int spi_flash_vector_helper(const struct spi_slave *slave, struct spi_op vectors[], size_t count, int(*func)(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin))
#define SPI_OPCODE_FAST_READ
static struct spi_slave slave
unsigned long long uint64_t
struct ich7_spi_regs * ich7_spi
struct ich9_spi_regs * ich9_spi
const struct spi_ctrlr * ctrlr
int(* xfer_vector)(const struct spi_slave *slave, struct spi_op vectors[], size_t count)
int(* read)(const struct spi_flash *flash, u32 offset, size_t len, void *buf)
const struct spi_flash_ops * ops