Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'spi-nor/for-4.11-v2' of git://github.com/spi-nor/linux

From Cyrille:

"""
This pull request contains the following notable changes:
- add support to the 4-byte address instruction set.
- add support to new memory parts.
- add support to S3AN memories.
- add support to the Intel SPI controller.
- add support to the Aspeed AST2400 and AST2550 controllers.
- fix max SPI transfer and message sizes in m25p80_read().
- fix the Candence QSPI driver.
- fix the Freescale QSPI driver.
"""

+2278 -100
+51
Documentation/devicetree/bindings/mtd/aspeed-smc.txt
··· 1 + * Aspeed Firmware Memory controller 2 + * Aspeed SPI Flash Memory Controller 3 + 4 + The Firmware Memory Controller in the Aspeed AST2500 SoC supports 5 + three chip selects, two of which are always of SPI type and the third 6 + can be SPI or NOR type flash. These bindings only describe SPI. 7 + 8 + The two SPI flash memory controllers in the AST2500 each support two 9 + chip selects. 10 + 11 + Required properties: 12 + - compatible : Should be one of 13 + "aspeed,ast2400-fmc" for the AST2400 Firmware Memory Controller 14 + "aspeed,ast2400-spi" for the AST2400 SPI Flash memory Controller 15 + "aspeed,ast2500-fmc" for the AST2500 Firmware Memory Controller 16 + "aspeed,ast2500-spi" for the AST2500 SPI flash memory controllers 17 + 18 + - reg : the first contains the control register location and length, 19 + the second contains the memory window mapping address and length 20 + - #address-cells : must be 1 corresponding to chip select child binding 21 + - #size-cells : must be 0 corresponding to chip select child binding 22 + 23 + Optional properties: 24 + - interrupts : Should contain the interrupt for the dma device if an 25 + FMC 26 + 27 + The child nodes are the SPI flash modules which must have a compatible 28 + property as specified in bindings/mtd/jedec,spi-nor.txt 29 + 30 + Optionally, the child node can contain properties for SPI mode (may be 31 + ignored): 32 + - spi-max-frequency - max frequency of spi bus 33 + 34 + 35 + Example: 36 + fmc: fmc@1e620000 { 37 + compatible = "aspeed,ast2500-fmc"; 38 + reg = < 0x1e620000 0x94 39 + 0x20000000 0x02000000 >; 40 + #address-cells = <1>; 41 + #size-cells = <0>; 42 + interrupts = <19>; 43 + flash@0 { 44 + reg = < 0 >; 45 + compatible = "jedec,spi-nor"; 46 + /* spi-max-frequency = <>; */ 47 + /* m25p,fast-read; */ 48 + #address-cells = <1>; 49 + #size-cells = <1>; 50 + }; 51 + };
+2
Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt
··· 14 14 at25df641 15 15 at26df081a 16 16 mr25h256 17 + mr25h10 18 + mr25h40 17 19 mx25l4005a 18 20 mx25l1606e 19 21 mx25l6405d
+7 -1
Documentation/devicetree/bindings/mtd/mtk-quadspi.txt
··· 1 1 * Serial NOR flash controller for MTK MT81xx (and similar) 2 2 3 3 Required properties: 4 - - compatible: should be "mediatek,mt8173-nor"; 4 + - compatible: The possible values are: 5 + "mediatek,mt2701-nor" 6 + "mediatek,mt7623-nor" 7 + "mediatek,mt8173-nor" 8 + For mt8173, compatible should be "mediatek,mt8173-nor". 9 + For every other SoC, should contain both the SoC-specific compatible string 10 + and "mediatek,mt8173-nor". 5 11 - reg: physical base address and length of the controller's register 6 12 - clocks: the phandle of the clocks needed by the nor controller 7 13 - clock-names: the names of the clocks
+88
Documentation/mtd/intel-spi.txt
··· 1 + Upgrading BIOS using intel-spi 2 + ------------------------------ 3 + 4 + Many Intel CPUs like Baytrail and Braswell include SPI serial flash host 5 + controller which is used to hold BIOS and other platform specific data. 6 + Since contents of the SPI serial flash is crucial for machine to function, 7 + it is typically protected by different hardware protection mechanisms to 8 + avoid accidental (or on purpose) overwrite of the content. 9 + 10 + Not all manufacturers protect the SPI serial flash, mainly because it 11 + allows upgrading the BIOS image directly from an OS. 12 + 13 + The intel-spi driver makes it possible to read and write the SPI serial 14 + flash, if certain protection bits are not set and locked. If it finds 15 + any of them set, the whole MTD device is made read-only to prevent 16 + partial overwrites. By default the driver exposes SPI serial flash 17 + contents as read-only but it can be changed from kernel command line, 18 + passing "intel-spi.writeable=1". 19 + 20 + Please keep in mind that overwriting the BIOS image on SPI serial flash 21 + might render the machine unbootable and requires special equipment like 22 + Dediprog to revive. You have been warned! 23 + 24 + Below are the steps how to upgrade MinnowBoard MAX BIOS directly from 25 + Linux. 26 + 27 + 1) Download and extract the latest Minnowboard MAX BIOS SPI image 28 + [1]. At the time writing this the latest image is v92. 29 + 30 + 2) Install mtd-utils package [2]. We need this in order to erase the SPI 31 + serial flash. Distros like Debian and Fedora have this prepackaged with 32 + name "mtd-utils". 33 + 34 + 3) Add "intel-spi.writeable=1" to the kernel command line and reboot 35 + the board (you can also reload the driver passing "writeable=1" as 36 + module parameter to modprobe). 37 + 38 + 4) Once the board is up and running again, find the right MTD partition 39 + (it is named as "BIOS"): 40 + 41 + # cat /proc/mtd 42 + dev: size erasesize name 43 + mtd0: 00800000 00001000 "BIOS" 44 + 45 + So here it will be /dev/mtd0 but it may vary. 46 + 47 + 5) Make backup of the existing image first: 48 + 49 + # dd if=/dev/mtd0ro of=bios.bak 50 + 16384+0 records in 51 + 16384+0 records out 52 + 8388608 bytes (8.4 MB) copied, 10.0269 s, 837 kB/s 53 + 54 + 6) Verify the backup 55 + 56 + # sha1sum /dev/mtd0ro bios.bak 57 + fdbb011920572ca6c991377c4b418a0502668b73 /dev/mtd0ro 58 + fdbb011920572ca6c991377c4b418a0502668b73 bios.bak 59 + 60 + The SHA1 sums must match. Otherwise do not continue any further! 61 + 62 + 7) Erase the SPI serial flash. After this step, do not reboot the 63 + board! Otherwise it will not start anymore. 64 + 65 + # flash_erase /dev/mtd0 0 0 66 + Erasing 4 Kibyte @ 7ff000 -- 100 % complete 67 + 68 + 8) Once completed without errors you can write the new BIOS image: 69 + 70 + # dd if=MNW2MAX1.X64.0092.R01.1605221712.bin of=/dev/mtd0 71 + 72 + 9) Verify that the new content of the SPI serial flash matches the new 73 + BIOS image: 74 + 75 + # sha1sum /dev/mtd0ro MNW2MAX1.X64.0092.R01.1605221712.bin 76 + 9b4df9e4be2057fceec3a5529ec3d950836c87a2 /dev/mtd0ro 77 + 9b4df9e4be2057fceec3a5529ec3d950836c87a2 MNW2MAX1.X64.0092.R01.1605221712.bin 78 + 79 + The SHA1 sums should match. 80 + 81 + 10) Now you can reboot your board and observe the new BIOS starting up 82 + properly. 83 + 84 + References 85 + ---------- 86 + 87 + [1] https://firmware.intel.com/sites/default/files/MinnowBoard.MAX_.X64.92.R01.zip 88 + [2] http://www.linux-mtd.infradead.org/
+131
drivers/mfd/lpc_ich.c
··· 56 56 * document number TBD : Wildcat Point-LP 57 57 * document number TBD : 9 Series 58 58 * document number TBD : Lewisburg 59 + * document number TBD : Apollo Lake SoC 59 60 */ 60 61 61 62 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt ··· 83 82 84 83 #define ACPIBASE_GCS_OFF 0x3410 85 84 #define ACPIBASE_GCS_END 0x3414 85 + 86 + #define SPIBASE_BYT 0x54 87 + #define SPIBASE_BYT_SZ 512 88 + #define SPIBASE_BYT_EN BIT(1) 89 + 90 + #define SPIBASE_LPT 0x3800 91 + #define SPIBASE_LPT_SZ 512 92 + #define BCR 0xdc 93 + #define BCR_WPD BIT(0) 94 + 95 + #define SPIBASE_APL_SZ 4096 86 96 87 97 #define GPIOBASE_ICH0 0x58 88 98 #define GPIOCTRL_ICH0 0x5C ··· 145 133 }, 146 134 }; 147 135 136 + static struct resource intel_spi_res[] = { 137 + { 138 + .flags = IORESOURCE_MEM, 139 + } 140 + }; 141 + 148 142 static struct mfd_cell lpc_ich_wdt_cell = { 149 143 .name = "iTCO_wdt", 150 144 .num_resources = ARRAY_SIZE(wdt_ich_res), ··· 162 144 .name = "gpio_ich", 163 145 .num_resources = ARRAY_SIZE(gpio_ich_res), 164 146 .resources = gpio_ich_res, 147 + .ignore_resource_conflicts = true, 148 + }; 149 + 150 + 151 + static struct mfd_cell lpc_ich_spi_cell = { 152 + .name = "intel-spi", 153 + .num_resources = ARRAY_SIZE(intel_spi_res), 154 + .resources = intel_spi_res, 165 155 .ignore_resource_conflicts = true, 166 156 }; 167 157 ··· 242 216 LPC_BRASWELL, /* Braswell SoC */ 243 217 LPC_LEWISBURG, /* Lewisburg */ 244 218 LPC_9S, /* 9 Series */ 219 + LPC_APL, /* Apollo Lake SoC */ 245 220 }; 246 221 247 222 static struct lpc_ich_info lpc_chipset_info[] = { ··· 521 494 .name = "Lynx Point", 522 495 .iTCO_version = 2, 523 496 .gpio_version = ICH_V5_GPIO, 497 + .spi_type = INTEL_SPI_LPT, 524 498 }, 525 499 [LPC_LPT_LP] = { 526 500 .name = "Lynx Point_LP", 527 501 .iTCO_version = 2, 502 + .spi_type = INTEL_SPI_LPT, 528 503 }, 529 504 [LPC_WBG] = { 530 505 .name = "Wellsburg", ··· 540 511 [LPC_BAYTRAIL] = { 541 512 .name = "Bay Trail SoC", 542 513 .iTCO_version = 3, 514 + .spi_type = INTEL_SPI_BYT, 543 515 }, 544 516 [LPC_COLETO] = { 545 517 .name = "Coleto Creek", ··· 549 519 [LPC_WPT_LP] = { 550 520 .name = "Wildcat Point_LP", 551 521 .iTCO_version = 2, 522 + .spi_type = INTEL_SPI_LPT, 552 523 }, 553 524 [LPC_BRASWELL] = { 554 525 .name = "Braswell SoC", 555 526 .iTCO_version = 3, 527 + .spi_type = INTEL_SPI_BYT, 556 528 }, 557 529 [LPC_LEWISBURG] = { 558 530 .name = "Lewisburg", ··· 564 532 .name = "9 Series", 565 533 .iTCO_version = 2, 566 534 .gpio_version = ICH_V5_GPIO, 535 + }, 536 + [LPC_APL] = { 537 + .name = "Apollo Lake SoC", 538 + .spi_type = INTEL_SPI_BXT, 567 539 }, 568 540 }; 569 541 ··· 717 681 { PCI_VDEVICE(INTEL, 0x3b14), LPC_3420}, 718 682 { PCI_VDEVICE(INTEL, 0x3b16), LPC_3450}, 719 683 { PCI_VDEVICE(INTEL, 0x5031), LPC_EP80579}, 684 + { PCI_VDEVICE(INTEL, 0x5ae8), LPC_APL}, 720 685 { PCI_VDEVICE(INTEL, 0x8c40), LPC_LPT}, 721 686 { PCI_VDEVICE(INTEL, 0x8c41), LPC_LPT}, 722 687 { PCI_VDEVICE(INTEL, 0x8c42), LPC_LPT}, ··· 1093 1056 return ret; 1094 1057 } 1095 1058 1059 + static int lpc_ich_init_spi(struct pci_dev *dev) 1060 + { 1061 + struct lpc_ich_priv *priv = pci_get_drvdata(dev); 1062 + struct resource *res = &intel_spi_res[0]; 1063 + struct intel_spi_boardinfo *info; 1064 + u32 spi_base, rcba, bcr; 1065 + 1066 + info = devm_kzalloc(&dev->dev, sizeof(*info), GFP_KERNEL); 1067 + if (!info) 1068 + return -ENOMEM; 1069 + 1070 + info->type = lpc_chipset_info[priv->chipset].spi_type; 1071 + 1072 + switch (info->type) { 1073 + case INTEL_SPI_BYT: 1074 + pci_read_config_dword(dev, SPIBASE_BYT, &spi_base); 1075 + if (spi_base & SPIBASE_BYT_EN) { 1076 + res->start = spi_base & ~(SPIBASE_BYT_SZ - 1); 1077 + res->end = res->start + SPIBASE_BYT_SZ - 1; 1078 + } 1079 + break; 1080 + 1081 + case INTEL_SPI_LPT: 1082 + pci_read_config_dword(dev, RCBABASE, &rcba); 1083 + if (rcba & 1) { 1084 + spi_base = round_down(rcba, SPIBASE_LPT_SZ); 1085 + res->start = spi_base + SPIBASE_LPT; 1086 + res->end = res->start + SPIBASE_LPT_SZ - 1; 1087 + 1088 + /* 1089 + * Try to make the flash chip writeable now by 1090 + * setting BCR_WPD. It it fails we tell the driver 1091 + * that it can only read the chip. 1092 + */ 1093 + pci_read_config_dword(dev, BCR, &bcr); 1094 + if (!(bcr & BCR_WPD)) { 1095 + bcr |= BCR_WPD; 1096 + pci_write_config_dword(dev, BCR, bcr); 1097 + pci_read_config_dword(dev, BCR, &bcr); 1098 + } 1099 + info->writeable = !!(bcr & BCR_WPD); 1100 + } 1101 + break; 1102 + 1103 + case INTEL_SPI_BXT: { 1104 + unsigned int p2sb = PCI_DEVFN(13, 0); 1105 + unsigned int spi = PCI_DEVFN(13, 2); 1106 + struct pci_bus *bus = dev->bus; 1107 + 1108 + /* 1109 + * The P2SB is hidden by BIOS and we need to unhide it in 1110 + * order to read BAR of the SPI flash device. Once that is 1111 + * done we hide it again. 1112 + */ 1113 + pci_bus_write_config_byte(bus, p2sb, 0xe1, 0x0); 1114 + pci_bus_read_config_dword(bus, spi, PCI_BASE_ADDRESS_0, 1115 + &spi_base); 1116 + if (spi_base != ~0) { 1117 + res->start = spi_base & 0xfffffff0; 1118 + res->end = res->start + SPIBASE_APL_SZ - 1; 1119 + 1120 + pci_bus_read_config_dword(bus, spi, BCR, &bcr); 1121 + if (!(bcr & BCR_WPD)) { 1122 + bcr |= BCR_WPD; 1123 + pci_bus_write_config_dword(bus, spi, BCR, bcr); 1124 + pci_bus_read_config_dword(bus, spi, BCR, &bcr); 1125 + } 1126 + info->writeable = !!(bcr & BCR_WPD); 1127 + } 1128 + 1129 + pci_bus_write_config_byte(bus, p2sb, 0xe1, 0x1); 1130 + break; 1131 + } 1132 + 1133 + default: 1134 + return -EINVAL; 1135 + } 1136 + 1137 + if (!res->start) 1138 + return -ENODEV; 1139 + 1140 + lpc_ich_spi_cell.platform_data = info; 1141 + lpc_ich_spi_cell.pdata_size = sizeof(*info); 1142 + 1143 + return mfd_add_devices(&dev->dev, PLATFORM_DEVID_NONE, 1144 + &lpc_ich_spi_cell, 1, NULL, 0, NULL); 1145 + } 1146 + 1096 1147 static int lpc_ich_probe(struct pci_dev *dev, 1097 1148 const struct pci_device_id *id) 1098 1149 { ··· 1220 1095 1221 1096 if (lpc_chipset_info[priv->chipset].gpio_version) { 1222 1097 ret = lpc_ich_init_gpio(dev); 1098 + if (!ret) 1099 + cell_added = true; 1100 + } 1101 + 1102 + if (lpc_chipset_info[priv->chipset].spi_type) { 1103 + ret = lpc_ich_init_spi(dev); 1223 1104 if (!ret) 1224 1105 cell_added = true; 1225 1106 }
+7 -2
drivers/mtd/devices/m25p80.c
··· 172 172 173 173 t[1].rx_buf = buf; 174 174 t[1].rx_nbits = m25p80_rx_nbits(nor); 175 - t[1].len = min(len, spi_max_transfer_size(spi)); 175 + t[1].len = min3(len, spi_max_transfer_size(spi), 176 + spi_max_message_size(spi) - t[0].len); 176 177 spi_message_add_tail(&t[1], &m); 177 178 178 179 ret = spi_sync(spi, &m); ··· 289 288 * should be kept for backward compatibility. 290 289 */ 291 290 {"at25df321a"}, {"at25df641"}, {"at26df081a"}, 292 - {"mr25h256"}, 293 291 {"mx25l4005a"}, {"mx25l1606e"}, {"mx25l6405d"}, {"mx25l12805d"}, 294 292 {"mx25l25635e"},{"mx66l51235l"}, 295 293 {"n25q064"}, {"n25q128a11"}, {"n25q128a13"}, {"n25q512a"}, ··· 304 304 {"m25p05-nonjedec"}, {"m25p10-nonjedec"}, {"m25p20-nonjedec"}, 305 305 {"m25p40-nonjedec"}, {"m25p80-nonjedec"}, {"m25p16-nonjedec"}, 306 306 {"m25p32-nonjedec"}, {"m25p64-nonjedec"}, {"m25p128-nonjedec"}, 307 + 308 + /* Everspin MRAMs (non-JEDEC) */ 309 + { "mr25h256" }, /* 256 Kib, 40 MHz */ 310 + { "mr25h10" }, /* 1 Mib, 40 MHz */ 311 + { "mr25h40" }, /* 4 Mib, 40 MHz */ 307 312 308 313 { }, 309 314 };
-7
drivers/mtd/devices/serial_flash_cmds.h
··· 18 18 #define SPINOR_OP_RDVCR 0x85 19 19 20 20 /* JEDEC Standard - Serial Flash Discoverable Parmeters (SFDP) Commands */ 21 - #define SPINOR_OP_READ_1_2_2 0xbb /* DUAL I/O READ */ 22 - #define SPINOR_OP_READ_1_4_4 0xeb /* QUAD I/O READ */ 23 - 24 21 #define SPINOR_OP_WRITE 0x02 /* PAGE PROGRAM */ 25 22 #define SPINOR_OP_WRITE_1_1_2 0xa2 /* DUAL INPUT PROGRAM */ 26 23 #define SPINOR_OP_WRITE_1_2_2 0xd2 /* DUAL INPUT EXT PROGRAM */ 27 24 #define SPINOR_OP_WRITE_1_1_4 0x32 /* QUAD INPUT PROGRAM */ 28 25 #define SPINOR_OP_WRITE_1_4_4 0x12 /* QUAD INPUT EXT PROGRAM */ 29 - 30 - /* READ commands with 32-bit addressing */ 31 - #define SPINOR_OP_READ4_1_2_2 0xbc 32 - #define SPINOR_OP_READ4_1_4_4 0xec 33 26 34 27 /* Configuration flags */ 35 28 #define FLASH_FLAG_SINGLE 0x000000ff
+14 -14
drivers/mtd/devices/st_spi_fsm.c
··· 507 507 * - 'FAST' variants configured for 8 dummy cycles (see note above.) 508 508 */ 509 509 static struct seq_rw_config n25q_read4_configs[] = { 510 - {FLASH_FLAG_READ_1_4_4, SPINOR_OP_READ4_1_4_4, 0, 4, 4, 0x00, 0, 8}, 511 - {FLASH_FLAG_READ_1_1_4, SPINOR_OP_READ4_1_1_4, 0, 1, 4, 0x00, 0, 8}, 512 - {FLASH_FLAG_READ_1_2_2, SPINOR_OP_READ4_1_2_2, 0, 2, 2, 0x00, 0, 8}, 513 - {FLASH_FLAG_READ_1_1_2, SPINOR_OP_READ4_1_1_2, 0, 1, 2, 0x00, 0, 8}, 514 - {FLASH_FLAG_READ_FAST, SPINOR_OP_READ4_FAST, 0, 1, 1, 0x00, 0, 8}, 515 - {FLASH_FLAG_READ_WRITE, SPINOR_OP_READ4, 0, 1, 1, 0x00, 0, 0}, 516 - {0x00, 0, 0, 0, 0, 0x00, 0, 0}, 510 + {FLASH_FLAG_READ_1_4_4, SPINOR_OP_READ_1_4_4_4B, 0, 4, 4, 0x00, 0, 8}, 511 + {FLASH_FLAG_READ_1_1_4, SPINOR_OP_READ_1_1_4_4B, 0, 1, 4, 0x00, 0, 8}, 512 + {FLASH_FLAG_READ_1_2_2, SPINOR_OP_READ_1_2_2_4B, 0, 2, 2, 0x00, 0, 8}, 513 + {FLASH_FLAG_READ_1_1_2, SPINOR_OP_READ_1_1_2_4B, 0, 1, 2, 0x00, 0, 8}, 514 + {FLASH_FLAG_READ_FAST, SPINOR_OP_READ_FAST_4B, 0, 1, 1, 0x00, 0, 8}, 515 + {FLASH_FLAG_READ_WRITE, SPINOR_OP_READ_4B, 0, 1, 1, 0x00, 0, 0}, 516 + {0x00, 0, 0, 0, 0, 0x00, 0, 0}, 517 517 }; 518 518 519 519 /* ··· 553 553 * entering a state that is incompatible with the SPIBoot Controller. 554 554 */ 555 555 static struct seq_rw_config stfsm_s25fl_read4_configs[] = { 556 - {FLASH_FLAG_READ_1_4_4, SPINOR_OP_READ4_1_4_4, 0, 4, 4, 0x00, 2, 4}, 557 - {FLASH_FLAG_READ_1_1_4, SPINOR_OP_READ4_1_1_4, 0, 1, 4, 0x00, 0, 8}, 558 - {FLASH_FLAG_READ_1_2_2, SPINOR_OP_READ4_1_2_2, 0, 2, 2, 0x00, 4, 0}, 559 - {FLASH_FLAG_READ_1_1_2, SPINOR_OP_READ4_1_1_2, 0, 1, 2, 0x00, 0, 8}, 560 - {FLASH_FLAG_READ_FAST, SPINOR_OP_READ4_FAST, 0, 1, 1, 0x00, 0, 8}, 561 - {FLASH_FLAG_READ_WRITE, SPINOR_OP_READ4, 0, 1, 1, 0x00, 0, 0}, 562 - {0x00, 0, 0, 0, 0, 0x00, 0, 0}, 556 + {FLASH_FLAG_READ_1_4_4, SPINOR_OP_READ_1_4_4_4B, 0, 4, 4, 0x00, 2, 4}, 557 + {FLASH_FLAG_READ_1_1_4, SPINOR_OP_READ_1_1_4_4B, 0, 1, 4, 0x00, 0, 8}, 558 + {FLASH_FLAG_READ_1_2_2, SPINOR_OP_READ_1_2_2_4B, 0, 2, 2, 0x00, 4, 0}, 559 + {FLASH_FLAG_READ_1_1_2, SPINOR_OP_READ_1_1_2_4B, 0, 1, 2, 0x00, 0, 8}, 560 + {FLASH_FLAG_READ_FAST, SPINOR_OP_READ_FAST_4B, 0, 1, 1, 0x00, 0, 8}, 561 + {FLASH_FLAG_READ_WRITE, SPINOR_OP_READ_4B, 0, 1, 1, 0x00, 0, 0}, 562 + {0x00, 0, 0, 0, 0, 0x00, 0, 0}, 563 563 }; 564 564 565 565 static struct seq_rw_config stfsm_s25fl_write4_configs[] = {
+31 -1
drivers/mtd/spi-nor/Kconfig
··· 29 29 Please note that some tools/drivers/filesystems may not work with 30 30 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum). 31 31 32 + config SPI_ASPEED_SMC 33 + tristate "Aspeed flash controllers in SPI mode" 34 + depends on ARCH_ASPEED || COMPILE_TEST 35 + depends on HAS_IOMEM && OF 36 + help 37 + This enables support for the Firmware Memory controller (FMC) 38 + in the Aspeed AST2500/AST2400 SoCs when attached to SPI NOR chips, 39 + and support for the SPI flash memory controller (SPI) for 40 + the host firmware. The implementation only supports SPI NOR. 41 + 32 42 config SPI_ATMEL_QUADSPI 33 43 tristate "Atmel Quad SPI Controller" 34 44 depends on ARCH_AT91 || (ARM && COMPILE_TEST) ··· 50 40 51 41 config SPI_CADENCE_QUADSPI 52 42 tristate "Cadence Quad SPI controller" 53 - depends on OF && ARM 43 + depends on OF && (ARM || COMPILE_TEST) 54 44 help 55 45 Enable support for the Cadence Quad SPI Flash controller. 56 46 ··· 85 75 SPIFI is a specialized controller for connecting serial SPI 86 76 Flash. Enable this option if you have a device with a SPIFI 87 77 controller and want to access the Flash as a mtd device. 78 + 79 + config SPI_INTEL_SPI 80 + tristate 81 + 82 + config SPI_INTEL_SPI_PLATFORM 83 + tristate "Intel PCH/PCU SPI flash platform driver" if EXPERT 84 + depends on X86 85 + select SPI_INTEL_SPI 86 + help 87 + This enables platform support for the Intel PCH/PCU SPI 88 + controller in master mode. This controller is present in modern 89 + Intel hardware and is used to hold BIOS and other persistent 90 + settings. Using this driver it is possible to upgrade BIOS 91 + directly from Linux. 92 + 93 + Say N here unless you know what you are doing. Overwriting the 94 + SPI flash may render the system unbootable. 95 + 96 + To compile this driver as a module, choose M here: the module 97 + will be called intel-spi-platform. 88 98 89 99 endif # MTD_SPI_NOR
+3
drivers/mtd/spi-nor/Makefile
··· 1 1 obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o 2 + obj-$(CONFIG_SPI_ASPEED_SMC) += aspeed-smc.o 2 3 obj-$(CONFIG_SPI_ATMEL_QUADSPI) += atmel-quadspi.o 3 4 obj-$(CONFIG_SPI_CADENCE_QUADSPI) += cadence-quadspi.o 4 5 obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-quadspi.o 5 6 obj-$(CONFIG_SPI_HISI_SFC) += hisi-sfc.o 6 7 obj-$(CONFIG_MTD_MT81xx_NOR) += mtk-quadspi.o 7 8 obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o 9 + obj-$(CONFIG_SPI_INTEL_SPI) += intel-spi.o 10 + obj-$(CONFIG_SPI_INTEL_SPI_PLATFORM) += intel-spi-platform.o
+758
drivers/mtd/spi-nor/aspeed-smc.c
··· 1 + /* 2 + * ASPEED Static Memory Controller driver 3 + * 4 + * Copyright (c) 2015-2016, IBM Corporation. 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License 8 + * as published by the Free Software Foundation; either version 9 + * 2 of the License, or (at your option) any later version. 10 + */ 11 + 12 + #include <linux/bug.h> 13 + #include <linux/device.h> 14 + #include <linux/io.h> 15 + #include <linux/module.h> 16 + #include <linux/mutex.h> 17 + #include <linux/mtd/mtd.h> 18 + #include <linux/mtd/partitions.h> 19 + #include <linux/mtd/spi-nor.h> 20 + #include <linux/of.h> 21 + #include <linux/of_platform.h> 22 + #include <linux/sysfs.h> 23 + 24 + #define DEVICE_NAME "aspeed-smc" 25 + 26 + /* 27 + * The driver only support SPI flash 28 + */ 29 + enum aspeed_smc_flash_type { 30 + smc_type_nor = 0, 31 + smc_type_nand = 1, 32 + smc_type_spi = 2, 33 + }; 34 + 35 + struct aspeed_smc_chip; 36 + 37 + struct aspeed_smc_info { 38 + u32 maxsize; /* maximum size of chip window */ 39 + u8 nce; /* number of chip enables */ 40 + bool hastype; /* flash type field exists in config reg */ 41 + u8 we0; /* shift for write enable bit for CE0 */ 42 + u8 ctl0; /* offset in regs of ctl for CE0 */ 43 + 44 + void (*set_4b)(struct aspeed_smc_chip *chip); 45 + }; 46 + 47 + static void aspeed_smc_chip_set_4b_spi_2400(struct aspeed_smc_chip *chip); 48 + static void aspeed_smc_chip_set_4b(struct aspeed_smc_chip *chip); 49 + 50 + static const struct aspeed_smc_info fmc_2400_info = { 51 + .maxsize = 64 * 1024 * 1024, 52 + .nce = 5, 53 + .hastype = true, 54 + .we0 = 16, 55 + .ctl0 = 0x10, 56 + .set_4b = aspeed_smc_chip_set_4b, 57 + }; 58 + 59 + static const struct aspeed_smc_info spi_2400_info = { 60 + .maxsize = 64 * 1024 * 1024, 61 + .nce = 1, 62 + .hastype = false, 63 + .we0 = 0, 64 + .ctl0 = 0x04, 65 + .set_4b = aspeed_smc_chip_set_4b_spi_2400, 66 + }; 67 + 68 + static const struct aspeed_smc_info fmc_2500_info = { 69 + .maxsize = 256 * 1024 * 1024, 70 + .nce = 3, 71 + .hastype = true, 72 + .we0 = 16, 73 + .ctl0 = 0x10, 74 + .set_4b = aspeed_smc_chip_set_4b, 75 + }; 76 + 77 + static const struct aspeed_smc_info spi_2500_info = { 78 + .maxsize = 128 * 1024 * 1024, 79 + .nce = 2, 80 + .hastype = false, 81 + .we0 = 16, 82 + .ctl0 = 0x10, 83 + .set_4b = aspeed_smc_chip_set_4b, 84 + }; 85 + 86 + enum aspeed_smc_ctl_reg_value { 87 + smc_base, /* base value without mode for other commands */ 88 + smc_read, /* command reg for (maybe fast) reads */ 89 + smc_write, /* command reg for writes */ 90 + smc_max, 91 + }; 92 + 93 + struct aspeed_smc_controller; 94 + 95 + struct aspeed_smc_chip { 96 + int cs; 97 + struct aspeed_smc_controller *controller; 98 + void __iomem *ctl; /* control register */ 99 + void __iomem *ahb_base; /* base of chip window */ 100 + u32 ctl_val[smc_max]; /* control settings */ 101 + enum aspeed_smc_flash_type type; /* what type of flash */ 102 + struct spi_nor nor; 103 + }; 104 + 105 + struct aspeed_smc_controller { 106 + struct device *dev; 107 + 108 + struct mutex mutex; /* controller access mutex */ 109 + const struct aspeed_smc_info *info; /* type info of controller */ 110 + void __iomem *regs; /* controller registers */ 111 + void __iomem *ahb_base; /* per-chip windows resource */ 112 + 113 + struct aspeed_smc_chip *chips[0]; /* pointers to attached chips */ 114 + }; 115 + 116 + /* 117 + * SPI Flash Configuration Register (AST2500 SPI) 118 + * or 119 + * Type setting Register (AST2500 FMC). 120 + * CE0 and CE1 can only be of type SPI. CE2 can be of type NOR but the 121 + * driver does not support it. 122 + */ 123 + #define CONFIG_REG 0x0 124 + #define CONFIG_DISABLE_LEGACY BIT(31) /* 1 */ 125 + 126 + #define CONFIG_CE2_WRITE BIT(18) 127 + #define CONFIG_CE1_WRITE BIT(17) 128 + #define CONFIG_CE0_WRITE BIT(16) 129 + 130 + #define CONFIG_CE2_TYPE BIT(4) /* AST2500 FMC only */ 131 + #define CONFIG_CE1_TYPE BIT(2) /* AST2500 FMC only */ 132 + #define CONFIG_CE0_TYPE BIT(0) /* AST2500 FMC only */ 133 + 134 + /* 135 + * CE Control Register 136 + */ 137 + #define CE_CONTROL_REG 0x4 138 + 139 + /* 140 + * CEx Control Register 141 + */ 142 + #define CONTROL_AAF_MODE BIT(31) 143 + #define CONTROL_IO_MODE_MASK GENMASK(30, 28) 144 + #define CONTROL_IO_DUAL_DATA BIT(29) 145 + #define CONTROL_IO_DUAL_ADDR_DATA (BIT(29) | BIT(28)) 146 + #define CONTROL_IO_QUAD_DATA BIT(30) 147 + #define CONTROL_IO_QUAD_ADDR_DATA (BIT(30) | BIT(28)) 148 + #define CONTROL_CE_INACTIVE_SHIFT 24 149 + #define CONTROL_CE_INACTIVE_MASK GENMASK(27, \ 150 + CONTROL_CE_INACTIVE_SHIFT) 151 + /* 0 = 16T ... 15 = 1T T=HCLK */ 152 + #define CONTROL_COMMAND_SHIFT 16 153 + #define CONTROL_DUMMY_COMMAND_OUT BIT(15) 154 + #define CONTROL_IO_DUMMY_HI BIT(14) 155 + #define CONTROL_IO_DUMMY_HI_SHIFT 14 156 + #define CONTROL_CLK_DIV4 BIT(13) /* others */ 157 + #define CONTROL_IO_ADDRESS_4B BIT(13) /* AST2400 SPI */ 158 + #define CONTROL_RW_MERGE BIT(12) 159 + #define CONTROL_IO_DUMMY_LO_SHIFT 6 160 + #define CONTROL_IO_DUMMY_LO GENMASK(7, \ 161 + CONTROL_IO_DUMMY_LO_SHIFT) 162 + #define CONTROL_IO_DUMMY_MASK (CONTROL_IO_DUMMY_HI | \ 163 + CONTROL_IO_DUMMY_LO) 164 + #define CONTROL_IO_DUMMY_SET(dummy) \ 165 + (((((dummy) >> 2) & 0x1) << CONTROL_IO_DUMMY_HI_SHIFT) | \ 166 + (((dummy) & 0x3) << CONTROL_IO_DUMMY_LO_SHIFT)) 167 + 168 + #define CONTROL_CLOCK_FREQ_SEL_SHIFT 8 169 + #define CONTROL_CLOCK_FREQ_SEL_MASK GENMASK(11, \ 170 + CONTROL_CLOCK_FREQ_SEL_SHIFT) 171 + #define CONTROL_LSB_FIRST BIT(5) 172 + #define CONTROL_CLOCK_MODE_3 BIT(4) 173 + #define CONTROL_IN_DUAL_DATA BIT(3) 174 + #define CONTROL_CE_STOP_ACTIVE_CONTROL BIT(2) 175 + #define CONTROL_COMMAND_MODE_MASK GENMASK(1, 0) 176 + #define CONTROL_COMMAND_MODE_NORMAL 0 177 + #define CONTROL_COMMAND_MODE_FREAD 1 178 + #define CONTROL_COMMAND_MODE_WRITE 2 179 + #define CONTROL_COMMAND_MODE_USER 3 180 + 181 + #define CONTROL_KEEP_MASK \ 182 + (CONTROL_AAF_MODE | CONTROL_CE_INACTIVE_MASK | CONTROL_CLK_DIV4 | \ 183 + CONTROL_IO_DUMMY_MASK | CONTROL_CLOCK_FREQ_SEL_MASK | \ 184 + CONTROL_LSB_FIRST | CONTROL_CLOCK_MODE_3) 185 + 186 + /* 187 + * The Segment Register uses a 8MB unit to encode the start address 188 + * and the end address of the mapping window of a flash SPI slave : 189 + * 190 + * | byte 1 | byte 2 | byte 3 | byte 4 | 191 + * +--------+--------+--------+--------+ 192 + * | end | start | 0 | 0 | 193 + */ 194 + #define SEGMENT_ADDR_REG0 0x30 195 + #define SEGMENT_ADDR_START(_r) ((((_r) >> 16) & 0xFF) << 23) 196 + #define SEGMENT_ADDR_END(_r) ((((_r) >> 24) & 0xFF) << 23) 197 + 198 + /* 199 + * In user mode all data bytes read or written to the chip decode address 200 + * range are transferred to or from the SPI bus. The range is treated as a 201 + * fifo of arbitratry 1, 2, or 4 byte width but each write has to be aligned 202 + * to its size. The address within the multiple 8kB range is ignored when 203 + * sending bytes to the SPI bus. 204 + * 205 + * On the arm architecture, as of Linux version 4.3, memcpy_fromio and 206 + * memcpy_toio on little endian targets use the optimized memcpy routines 207 + * that were designed for well behavied memory storage. These routines 208 + * have a stutter if the source and destination are not both word aligned, 209 + * once with a duplicate access to the source after aligning to the 210 + * destination to a word boundary, and again with a duplicate access to 211 + * the source when the final byte count is not word aligned. 212 + * 213 + * When writing or reading the fifo this stutter discards data or sends 214 + * too much data to the fifo and can not be used by this driver. 215 + * 216 + * While the low level io string routines that implement the insl family do 217 + * the desired accesses and memory increments, the cross architecture io 218 + * macros make them essentially impossible to use on a memory mapped address 219 + * instead of a a token from the call to iomap of an io port. 220 + * 221 + * These fifo routines use readl and friends to a constant io port and update 222 + * the memory buffer pointer and count via explicit code. The final updates 223 + * to len are optimistically suppressed. 224 + */ 225 + static int aspeed_smc_read_from_ahb(void *buf, void __iomem *src, size_t len) 226 + { 227 + size_t offset = 0; 228 + 229 + if (IS_ALIGNED((uintptr_t)src, sizeof(uintptr_t)) && 230 + IS_ALIGNED((uintptr_t)buf, sizeof(uintptr_t))) { 231 + ioread32_rep(src, buf, len >> 2); 232 + offset = len & ~0x3; 233 + len -= offset; 234 + } 235 + ioread8_rep(src, (u8 *)buf + offset, len); 236 + return 0; 237 + } 238 + 239 + static int aspeed_smc_write_to_ahb(void __iomem *dst, const void *buf, 240 + size_t len) 241 + { 242 + size_t offset = 0; 243 + 244 + if (IS_ALIGNED((uintptr_t)dst, sizeof(uintptr_t)) && 245 + IS_ALIGNED((uintptr_t)buf, sizeof(uintptr_t))) { 246 + iowrite32_rep(dst, buf, len >> 2); 247 + offset = len & ~0x3; 248 + len -= offset; 249 + } 250 + iowrite8_rep(dst, (const u8 *)buf + offset, len); 251 + return 0; 252 + } 253 + 254 + static inline u32 aspeed_smc_chip_write_bit(struct aspeed_smc_chip *chip) 255 + { 256 + return BIT(chip->controller->info->we0 + chip->cs); 257 + } 258 + 259 + static void aspeed_smc_chip_check_config(struct aspeed_smc_chip *chip) 260 + { 261 + struct aspeed_smc_controller *controller = chip->controller; 262 + u32 reg; 263 + 264 + reg = readl(controller->regs + CONFIG_REG); 265 + 266 + if (reg & aspeed_smc_chip_write_bit(chip)) 267 + return; 268 + 269 + dev_dbg(controller->dev, "config write is not set ! @%p: 0x%08x\n", 270 + controller->regs + CONFIG_REG, reg); 271 + reg |= aspeed_smc_chip_write_bit(chip); 272 + writel(reg, controller->regs + CONFIG_REG); 273 + } 274 + 275 + static void aspeed_smc_start_user(struct spi_nor *nor) 276 + { 277 + struct aspeed_smc_chip *chip = nor->priv; 278 + u32 ctl = chip->ctl_val[smc_base]; 279 + 280 + /* 281 + * When the chip is controlled in user mode, we need write 282 + * access to send the opcodes to it. So check the config. 283 + */ 284 + aspeed_smc_chip_check_config(chip); 285 + 286 + ctl |= CONTROL_COMMAND_MODE_USER | 287 + CONTROL_CE_STOP_ACTIVE_CONTROL; 288 + writel(ctl, chip->ctl); 289 + 290 + ctl &= ~CONTROL_CE_STOP_ACTIVE_CONTROL; 291 + writel(ctl, chip->ctl); 292 + } 293 + 294 + static void aspeed_smc_stop_user(struct spi_nor *nor) 295 + { 296 + struct aspeed_smc_chip *chip = nor->priv; 297 + 298 + u32 ctl = chip->ctl_val[smc_read]; 299 + u32 ctl2 = ctl | CONTROL_COMMAND_MODE_USER | 300 + CONTROL_CE_STOP_ACTIVE_CONTROL; 301 + 302 + writel(ctl2, chip->ctl); /* stop user CE control */ 303 + writel(ctl, chip->ctl); /* default to fread or read mode */ 304 + } 305 + 306 + static int aspeed_smc_prep(struct spi_nor *nor, enum spi_nor_ops ops) 307 + { 308 + struct aspeed_smc_chip *chip = nor->priv; 309 + 310 + mutex_lock(&chip->controller->mutex); 311 + return 0; 312 + } 313 + 314 + static void aspeed_smc_unprep(struct spi_nor *nor, enum spi_nor_ops ops) 315 + { 316 + struct aspeed_smc_chip *chip = nor->priv; 317 + 318 + mutex_unlock(&chip->controller->mutex); 319 + } 320 + 321 + static int aspeed_smc_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) 322 + { 323 + struct aspeed_smc_chip *chip = nor->priv; 324 + 325 + aspeed_smc_start_user(nor); 326 + aspeed_smc_write_to_ahb(chip->ahb_base, &opcode, 1); 327 + aspeed_smc_read_from_ahb(buf, chip->ahb_base, len); 328 + aspeed_smc_stop_user(nor); 329 + return 0; 330 + } 331 + 332 + static int aspeed_smc_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, 333 + int len) 334 + { 335 + struct aspeed_smc_chip *chip = nor->priv; 336 + 337 + aspeed_smc_start_user(nor); 338 + aspeed_smc_write_to_ahb(chip->ahb_base, &opcode, 1); 339 + aspeed_smc_write_to_ahb(chip->ahb_base, buf, len); 340 + aspeed_smc_stop_user(nor); 341 + return 0; 342 + } 343 + 344 + static void aspeed_smc_send_cmd_addr(struct spi_nor *nor, u8 cmd, u32 addr) 345 + { 346 + struct aspeed_smc_chip *chip = nor->priv; 347 + __be32 temp; 348 + u32 cmdaddr; 349 + 350 + switch (nor->addr_width) { 351 + default: 352 + WARN_ONCE(1, "Unexpected address width %u, defaulting to 3\n", 353 + nor->addr_width); 354 + /* FALLTHROUGH */ 355 + case 3: 356 + cmdaddr = addr & 0xFFFFFF; 357 + cmdaddr |= cmd << 24; 358 + 359 + temp = cpu_to_be32(cmdaddr); 360 + aspeed_smc_write_to_ahb(chip->ahb_base, &temp, 4); 361 + break; 362 + case 4: 363 + temp = cpu_to_be32(addr); 364 + aspeed_smc_write_to_ahb(chip->ahb_base, &cmd, 1); 365 + aspeed_smc_write_to_ahb(chip->ahb_base, &temp, 4); 366 + break; 367 + } 368 + } 369 + 370 + static ssize_t aspeed_smc_read_user(struct spi_nor *nor, loff_t from, 371 + size_t len, u_char *read_buf) 372 + { 373 + struct aspeed_smc_chip *chip = nor->priv; 374 + int i; 375 + u8 dummy = 0xFF; 376 + 377 + aspeed_smc_start_user(nor); 378 + aspeed_smc_send_cmd_addr(nor, nor->read_opcode, from); 379 + for (i = 0; i < chip->nor.read_dummy / 8; i++) 380 + aspeed_smc_write_to_ahb(chip->ahb_base, &dummy, sizeof(dummy)); 381 + 382 + aspeed_smc_read_from_ahb(read_buf, chip->ahb_base, len); 383 + aspeed_smc_stop_user(nor); 384 + return len; 385 + } 386 + 387 + static ssize_t aspeed_smc_write_user(struct spi_nor *nor, loff_t to, 388 + size_t len, const u_char *write_buf) 389 + { 390 + struct aspeed_smc_chip *chip = nor->priv; 391 + 392 + aspeed_smc_start_user(nor); 393 + aspeed_smc_send_cmd_addr(nor, nor->program_opcode, to); 394 + aspeed_smc_write_to_ahb(chip->ahb_base, write_buf, len); 395 + aspeed_smc_stop_user(nor); 396 + return len; 397 + } 398 + 399 + static int aspeed_smc_unregister(struct aspeed_smc_controller *controller) 400 + { 401 + struct aspeed_smc_chip *chip; 402 + int n; 403 + 404 + for (n = 0; n < controller->info->nce; n++) { 405 + chip = controller->chips[n]; 406 + if (chip) 407 + mtd_device_unregister(&chip->nor.mtd); 408 + } 409 + 410 + return 0; 411 + } 412 + 413 + static int aspeed_smc_remove(struct platform_device *dev) 414 + { 415 + return aspeed_smc_unregister(platform_get_drvdata(dev)); 416 + } 417 + 418 + static const struct of_device_id aspeed_smc_matches[] = { 419 + { .compatible = "aspeed,ast2400-fmc", .data = &fmc_2400_info }, 420 + { .compatible = "aspeed,ast2400-spi", .data = &spi_2400_info }, 421 + { .compatible = "aspeed,ast2500-fmc", .data = &fmc_2500_info }, 422 + { .compatible = "aspeed,ast2500-spi", .data = &spi_2500_info }, 423 + { } 424 + }; 425 + MODULE_DEVICE_TABLE(of, aspeed_smc_matches); 426 + 427 + /* 428 + * Each chip has a mapping window defined by a segment address 429 + * register defining a start and an end address on the AHB bus. These 430 + * addresses can be configured to fit the chip size and offer a 431 + * contiguous memory region across chips. For the moment, we only 432 + * check that each chip segment is valid. 433 + */ 434 + static void __iomem *aspeed_smc_chip_base(struct aspeed_smc_chip *chip, 435 + struct resource *res) 436 + { 437 + struct aspeed_smc_controller *controller = chip->controller; 438 + u32 offset = 0; 439 + u32 reg; 440 + 441 + if (controller->info->nce > 1) { 442 + reg = readl(controller->regs + SEGMENT_ADDR_REG0 + 443 + chip->cs * 4); 444 + 445 + if (SEGMENT_ADDR_START(reg) >= SEGMENT_ADDR_END(reg)) 446 + return NULL; 447 + 448 + offset = SEGMENT_ADDR_START(reg) - res->start; 449 + } 450 + 451 + return controller->ahb_base + offset; 452 + } 453 + 454 + static void aspeed_smc_chip_enable_write(struct aspeed_smc_chip *chip) 455 + { 456 + struct aspeed_smc_controller *controller = chip->controller; 457 + u32 reg; 458 + 459 + reg = readl(controller->regs + CONFIG_REG); 460 + 461 + reg |= aspeed_smc_chip_write_bit(chip); 462 + writel(reg, controller->regs + CONFIG_REG); 463 + } 464 + 465 + static void aspeed_smc_chip_set_type(struct aspeed_smc_chip *chip, int type) 466 + { 467 + struct aspeed_smc_controller *controller = chip->controller; 468 + u32 reg; 469 + 470 + chip->type = type; 471 + 472 + reg = readl(controller->regs + CONFIG_REG); 473 + reg &= ~(3 << (chip->cs * 2)); 474 + reg |= chip->type << (chip->cs * 2); 475 + writel(reg, controller->regs + CONFIG_REG); 476 + } 477 + 478 + /* 479 + * The AST2500 FMC flash controller should be strapped by hardware, or 480 + * autodetected, but the AST2500 SPI flash needs to be set. 481 + */ 482 + static void aspeed_smc_chip_set_4b(struct aspeed_smc_chip *chip) 483 + { 484 + struct aspeed_smc_controller *controller = chip->controller; 485 + u32 reg; 486 + 487 + if (chip->controller->info == &spi_2500_info) { 488 + reg = readl(controller->regs + CE_CONTROL_REG); 489 + reg |= 1 << chip->cs; 490 + writel(reg, controller->regs + CE_CONTROL_REG); 491 + } 492 + } 493 + 494 + /* 495 + * The AST2400 SPI flash controller does not have a CE Control 496 + * register. It uses the CE0 control register to set 4Byte mode at the 497 + * controller level. 498 + */ 499 + static void aspeed_smc_chip_set_4b_spi_2400(struct aspeed_smc_chip *chip) 500 + { 501 + chip->ctl_val[smc_base] |= CONTROL_IO_ADDRESS_4B; 502 + chip->ctl_val[smc_read] |= CONTROL_IO_ADDRESS_4B; 503 + } 504 + 505 + static int aspeed_smc_chip_setup_init(struct aspeed_smc_chip *chip, 506 + struct resource *res) 507 + { 508 + struct aspeed_smc_controller *controller = chip->controller; 509 + const struct aspeed_smc_info *info = controller->info; 510 + u32 reg, base_reg; 511 + 512 + /* 513 + * Always turn on the write enable bit to allow opcodes to be 514 + * sent in user mode. 515 + */ 516 + aspeed_smc_chip_enable_write(chip); 517 + 518 + /* The driver only supports SPI type flash */ 519 + if (info->hastype) 520 + aspeed_smc_chip_set_type(chip, smc_type_spi); 521 + 522 + /* 523 + * Configure chip base address in memory 524 + */ 525 + chip->ahb_base = aspeed_smc_chip_base(chip, res); 526 + if (!chip->ahb_base) { 527 + dev_warn(chip->nor.dev, "CE segment window closed.\n"); 528 + return -EINVAL; 529 + } 530 + 531 + /* 532 + * Get value of the inherited control register. U-Boot usually 533 + * does some timing calibration on the FMC chip, so it's good 534 + * to keep them. In the future, we should handle calibration 535 + * from Linux. 536 + */ 537 + reg = readl(chip->ctl); 538 + dev_dbg(controller->dev, "control register: %08x\n", reg); 539 + 540 + base_reg = reg & CONTROL_KEEP_MASK; 541 + if (base_reg != reg) { 542 + dev_dbg(controller->dev, 543 + "control register changed to: %08x\n", 544 + base_reg); 545 + } 546 + chip->ctl_val[smc_base] = base_reg; 547 + 548 + /* 549 + * Retain the prior value of the control register as the 550 + * default if it was normal access mode. Otherwise start with 551 + * the sanitized base value set to read mode. 552 + */ 553 + if ((reg & CONTROL_COMMAND_MODE_MASK) == 554 + CONTROL_COMMAND_MODE_NORMAL) 555 + chip->ctl_val[smc_read] = reg; 556 + else 557 + chip->ctl_val[smc_read] = chip->ctl_val[smc_base] | 558 + CONTROL_COMMAND_MODE_NORMAL; 559 + 560 + dev_dbg(controller->dev, "default control register: %08x\n", 561 + chip->ctl_val[smc_read]); 562 + return 0; 563 + } 564 + 565 + static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip) 566 + { 567 + struct aspeed_smc_controller *controller = chip->controller; 568 + const struct aspeed_smc_info *info = controller->info; 569 + u32 cmd; 570 + 571 + if (chip->nor.addr_width == 4 && info->set_4b) 572 + info->set_4b(chip); 573 + 574 + /* 575 + * base mode has not been optimized yet. use it for writes. 576 + */ 577 + chip->ctl_val[smc_write] = chip->ctl_val[smc_base] | 578 + chip->nor.program_opcode << CONTROL_COMMAND_SHIFT | 579 + CONTROL_COMMAND_MODE_WRITE; 580 + 581 + dev_dbg(controller->dev, "write control register: %08x\n", 582 + chip->ctl_val[smc_write]); 583 + 584 + /* 585 + * TODO: Adjust clocks if fast read is supported and interpret 586 + * SPI-NOR flags to adjust controller settings. 587 + */ 588 + switch (chip->nor.flash_read) { 589 + case SPI_NOR_NORMAL: 590 + cmd = CONTROL_COMMAND_MODE_NORMAL; 591 + break; 592 + case SPI_NOR_FAST: 593 + cmd = CONTROL_COMMAND_MODE_FREAD; 594 + break; 595 + default: 596 + dev_err(chip->nor.dev, "unsupported SPI read mode\n"); 597 + return -EINVAL; 598 + } 599 + 600 + chip->ctl_val[smc_read] |= cmd | 601 + CONTROL_IO_DUMMY_SET(chip->nor.read_dummy / 8); 602 + 603 + dev_dbg(controller->dev, "base control register: %08x\n", 604 + chip->ctl_val[smc_read]); 605 + return 0; 606 + } 607 + 608 + static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, 609 + struct device_node *np, struct resource *r) 610 + { 611 + const struct aspeed_smc_info *info = controller->info; 612 + struct device *dev = controller->dev; 613 + struct device_node *child; 614 + unsigned int cs; 615 + int ret = -ENODEV; 616 + 617 + for_each_available_child_of_node(np, child) { 618 + struct aspeed_smc_chip *chip; 619 + struct spi_nor *nor; 620 + struct mtd_info *mtd; 621 + 622 + /* This driver does not support NAND or NOR flash devices. */ 623 + if (!of_device_is_compatible(child, "jedec,spi-nor")) 624 + continue; 625 + 626 + ret = of_property_read_u32(child, "reg", &cs); 627 + if (ret) { 628 + dev_err(dev, "Couldn't not read chip select.\n"); 629 + break; 630 + } 631 + 632 + if (cs >= info->nce) { 633 + dev_err(dev, "Chip select %d out of range.\n", 634 + cs); 635 + ret = -ERANGE; 636 + break; 637 + } 638 + 639 + if (controller->chips[cs]) { 640 + dev_err(dev, "Chip select %d already in use by %s\n", 641 + cs, dev_name(controller->chips[cs]->nor.dev)); 642 + ret = -EBUSY; 643 + break; 644 + } 645 + 646 + chip = devm_kzalloc(controller->dev, sizeof(*chip), GFP_KERNEL); 647 + if (!chip) { 648 + ret = -ENOMEM; 649 + break; 650 + } 651 + 652 + chip->controller = controller; 653 + chip->ctl = controller->regs + info->ctl0 + cs * 4; 654 + chip->cs = cs; 655 + 656 + nor = &chip->nor; 657 + mtd = &nor->mtd; 658 + 659 + nor->dev = dev; 660 + nor->priv = chip; 661 + spi_nor_set_flash_node(nor, child); 662 + nor->read = aspeed_smc_read_user; 663 + nor->write = aspeed_smc_write_user; 664 + nor->read_reg = aspeed_smc_read_reg; 665 + nor->write_reg = aspeed_smc_write_reg; 666 + nor->prepare = aspeed_smc_prep; 667 + nor->unprepare = aspeed_smc_unprep; 668 + 669 + ret = aspeed_smc_chip_setup_init(chip, r); 670 + if (ret) 671 + break; 672 + 673 + /* 674 + * TODO: Add support for SPI_NOR_QUAD and SPI_NOR_DUAL 675 + * attach when board support is present as determined 676 + * by of property. 677 + */ 678 + ret = spi_nor_scan(nor, NULL, SPI_NOR_NORMAL); 679 + if (ret) 680 + break; 681 + 682 + ret = aspeed_smc_chip_setup_finish(chip); 683 + if (ret) 684 + break; 685 + 686 + ret = mtd_device_register(mtd, NULL, 0); 687 + if (ret) 688 + break; 689 + 690 + controller->chips[cs] = chip; 691 + } 692 + 693 + if (ret) 694 + aspeed_smc_unregister(controller); 695 + 696 + return ret; 697 + } 698 + 699 + static int aspeed_smc_probe(struct platform_device *pdev) 700 + { 701 + struct device_node *np = pdev->dev.of_node; 702 + struct device *dev = &pdev->dev; 703 + struct aspeed_smc_controller *controller; 704 + const struct of_device_id *match; 705 + const struct aspeed_smc_info *info; 706 + struct resource *res; 707 + int ret; 708 + 709 + match = of_match_device(aspeed_smc_matches, &pdev->dev); 710 + if (!match || !match->data) 711 + return -ENODEV; 712 + info = match->data; 713 + 714 + controller = devm_kzalloc(&pdev->dev, sizeof(*controller) + 715 + info->nce * sizeof(controller->chips[0]), GFP_KERNEL); 716 + if (!controller) 717 + return -ENOMEM; 718 + controller->info = info; 719 + controller->dev = dev; 720 + 721 + mutex_init(&controller->mutex); 722 + platform_set_drvdata(pdev, controller); 723 + 724 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 725 + controller->regs = devm_ioremap_resource(dev, res); 726 + if (IS_ERR(controller->regs)) { 727 + dev_err(dev, "Cannot remap controller address.\n"); 728 + return PTR_ERR(controller->regs); 729 + } 730 + 731 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 732 + controller->ahb_base = devm_ioremap_resource(dev, res); 733 + if (IS_ERR(controller->ahb_base)) { 734 + dev_err(dev, "Cannot remap controller address.\n"); 735 + return PTR_ERR(controller->ahb_base); 736 + } 737 + 738 + ret = aspeed_smc_setup_flash(controller, np, res); 739 + if (ret) 740 + dev_err(dev, "Aspeed SMC probe failed %d\n", ret); 741 + 742 + return ret; 743 + } 744 + 745 + static struct platform_driver aspeed_smc_driver = { 746 + .probe = aspeed_smc_probe, 747 + .remove = aspeed_smc_remove, 748 + .driver = { 749 + .name = DEVICE_NAME, 750 + .of_match_table = aspeed_smc_matches, 751 + } 752 + }; 753 + 754 + module_platform_driver(aspeed_smc_driver); 755 + 756 + MODULE_DESCRIPTION("ASPEED Static Memory Controller Driver"); 757 + MODULE_AUTHOR("Cedric Le Goater <clg@kaod.org>"); 758 + MODULE_LICENSE("GPL v2");
+6 -4
drivers/mtd/spi-nor/cadence-quadspi.c
··· 526 526 bytes_to_read *= cqspi->fifo_width; 527 527 bytes_to_read = bytes_to_read > remaining ? 528 528 remaining : bytes_to_read; 529 - readsl(ahb_base, rxbuf, DIV_ROUND_UP(bytes_to_read, 4)); 529 + ioread32_rep(ahb_base, rxbuf, 530 + DIV_ROUND_UP(bytes_to_read, 4)); 530 531 rxbuf += bytes_to_read; 531 532 remaining -= bytes_to_read; 532 533 bytes_to_read = cqspi_get_rd_sram_level(cqspi); ··· 611 610 612 611 while (remaining > 0) { 613 612 write_bytes = remaining > page_size ? page_size : remaining; 614 - writesl(cqspi->ahb_base, txbuf, DIV_ROUND_UP(write_bytes, 4)); 613 + iowrite32_rep(cqspi->ahb_base, txbuf, 614 + DIV_ROUND_UP(write_bytes, 4)); 615 615 616 616 ret = wait_for_completion_timeout(&cqspi->transfer_complete, 617 617 msecs_to_jiffies ··· 893 891 if (ret) 894 892 return ret; 895 893 896 - return (ret < 0) ? ret : len; 894 + return len; 897 895 } 898 896 899 897 static ssize_t cqspi_read(struct spi_nor *nor, loff_t from, ··· 913 911 if (ret) 914 912 return ret; 915 913 916 - return (ret < 0) ? ret : len; 914 + return len; 917 915 } 918 916 919 917 static int cqspi_erase(struct spi_nor *nor, loff_t offs)
+16 -32
drivers/mtd/spi-nor/fsl-quadspi.c
··· 193 193 #define QUADSPI_LUT_NUM 64 194 194 195 195 /* SEQID -- we can have 16 seqids at most. */ 196 - #define SEQID_QUAD_READ 0 196 + #define SEQID_READ 0 197 197 #define SEQID_WREN 1 198 198 #define SEQID_WRDI 2 199 199 #define SEQID_RDSR 3 ··· 373 373 void __iomem *base = q->iobase; 374 374 int rxfifo = q->devtype_data->rxfifo; 375 375 u32 lut_base; 376 - u8 cmd, addrlen, dummy; 377 376 int i; 377 + 378 + struct spi_nor *nor = &q->nor[0]; 379 + u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT; 380 + u8 read_op = nor->read_opcode; 381 + u8 read_dm = nor->read_dummy; 378 382 379 383 fsl_qspi_unlock_lut(q); 380 384 ··· 386 382 for (i = 0; i < QUADSPI_LUT_NUM; i++) 387 383 qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4); 388 384 389 - /* Quad Read */ 390 - lut_base = SEQID_QUAD_READ * 4; 385 + /* Read */ 386 + lut_base = SEQID_READ * 4; 391 387 392 - if (q->nor_size <= SZ_16M) { 393 - cmd = SPINOR_OP_READ_1_1_4; 394 - addrlen = ADDR24BIT; 395 - dummy = 8; 396 - } else { 397 - /* use the 4-byte address */ 398 - cmd = SPINOR_OP_READ_1_1_4; 399 - addrlen = ADDR32BIT; 400 - dummy = 8; 401 - } 402 - 403 - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen), 388 + qspi_writel(q, LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD1, addrlen), 404 389 base + QUADSPI_LUT(lut_base)); 405 - qspi_writel(q, LUT0(DUMMY, PAD1, dummy) | LUT1(FSL_READ, PAD4, rxfifo), 390 + qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) | 391 + LUT1(FSL_READ, PAD4, rxfifo), 406 392 base + QUADSPI_LUT(lut_base + 1)); 407 393 408 394 /* Write enable */ ··· 403 409 /* Page Program */ 404 410 lut_base = SEQID_PP * 4; 405 411 406 - if (q->nor_size <= SZ_16M) { 407 - cmd = SPINOR_OP_PP; 408 - addrlen = ADDR24BIT; 409 - } else { 410 - /* use the 4-byte address */ 411 - cmd = SPINOR_OP_PP; 412 - addrlen = ADDR32BIT; 413 - } 414 - 415 - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen), 412 + qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) | 413 + LUT1(ADDR, PAD1, addrlen), 416 414 base + QUADSPI_LUT(lut_base)); 417 415 qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0), 418 416 base + QUADSPI_LUT(lut_base + 1)); ··· 418 432 /* Erase a sector */ 419 433 lut_base = SEQID_SE * 4; 420 434 421 - cmd = q->nor[0].erase_opcode; 422 - addrlen = q->nor_size <= SZ_16M ? ADDR24BIT : ADDR32BIT; 423 - 424 - qspi_writel(q, LUT0(CMD, PAD1, cmd) | LUT1(ADDR, PAD1, addrlen), 435 + qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) | 436 + LUT1(ADDR, PAD1, addrlen), 425 437 base + QUADSPI_LUT(lut_base)); 426 438 427 439 /* Erase the whole chip */ ··· 468 484 { 469 485 switch (cmd) { 470 486 case SPINOR_OP_READ_1_1_4: 471 - return SEQID_QUAD_READ; 487 + return SEQID_READ; 472 488 case SPINOR_OP_WREN: 473 489 return SEQID_WREN; 474 490 case SPINOR_OP_WRDI:
+57
drivers/mtd/spi-nor/intel-spi-platform.c
··· 1 + /* 2 + * Intel PCH/PCU SPI flash platform driver. 3 + * 4 + * Copyright (C) 2016, Intel Corporation 5 + * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/ioport.h> 13 + #include <linux/module.h> 14 + #include <linux/platform_device.h> 15 + 16 + #include "intel-spi.h" 17 + 18 + static int intel_spi_platform_probe(struct platform_device *pdev) 19 + { 20 + struct intel_spi_boardinfo *info; 21 + struct intel_spi *ispi; 22 + struct resource *mem; 23 + 24 + info = dev_get_platdata(&pdev->dev); 25 + if (!info) 26 + return -EINVAL; 27 + 28 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 29 + ispi = intel_spi_probe(&pdev->dev, mem, info); 30 + if (IS_ERR(ispi)) 31 + return PTR_ERR(ispi); 32 + 33 + platform_set_drvdata(pdev, ispi); 34 + return 0; 35 + } 36 + 37 + static int intel_spi_platform_remove(struct platform_device *pdev) 38 + { 39 + struct intel_spi *ispi = platform_get_drvdata(pdev); 40 + 41 + return intel_spi_remove(ispi); 42 + } 43 + 44 + static struct platform_driver intel_spi_platform_driver = { 45 + .probe = intel_spi_platform_probe, 46 + .remove = intel_spi_platform_remove, 47 + .driver = { 48 + .name = "intel-spi", 49 + }, 50 + }; 51 + 52 + module_platform_driver(intel_spi_platform_driver); 53 + 54 + MODULE_DESCRIPTION("Intel PCH/PCU SPI flash platform driver"); 55 + MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); 56 + MODULE_LICENSE("GPL v2"); 57 + MODULE_ALIAS("platform:intel-spi");
+777
drivers/mtd/spi-nor/intel-spi.c
··· 1 + /* 2 + * Intel PCH/PCU SPI flash driver. 3 + * 4 + * Copyright (C) 2016, Intel Corporation 5 + * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/err.h> 13 + #include <linux/io.h> 14 + #include <linux/iopoll.h> 15 + #include <linux/module.h> 16 + #include <linux/sched.h> 17 + #include <linux/sizes.h> 18 + #include <linux/mtd/mtd.h> 19 + #include <linux/mtd/partitions.h> 20 + #include <linux/mtd/spi-nor.h> 21 + #include <linux/platform_data/intel-spi.h> 22 + 23 + #include "intel-spi.h" 24 + 25 + /* Offsets are from @ispi->base */ 26 + #define BFPREG 0x00 27 + 28 + #define HSFSTS_CTL 0x04 29 + #define HSFSTS_CTL_FSMIE BIT(31) 30 + #define HSFSTS_CTL_FDBC_SHIFT 24 31 + #define HSFSTS_CTL_FDBC_MASK (0x3f << HSFSTS_CTL_FDBC_SHIFT) 32 + 33 + #define HSFSTS_CTL_FCYCLE_SHIFT 17 34 + #define HSFSTS_CTL_FCYCLE_MASK (0x0f << HSFSTS_CTL_FCYCLE_SHIFT) 35 + /* HW sequencer opcodes */ 36 + #define HSFSTS_CTL_FCYCLE_READ (0x00 << HSFSTS_CTL_FCYCLE_SHIFT) 37 + #define HSFSTS_CTL_FCYCLE_WRITE (0x02 << HSFSTS_CTL_FCYCLE_SHIFT) 38 + #define HSFSTS_CTL_FCYCLE_ERASE (0x03 << HSFSTS_CTL_FCYCLE_SHIFT) 39 + #define HSFSTS_CTL_FCYCLE_ERASE_64K (0x04 << HSFSTS_CTL_FCYCLE_SHIFT) 40 + #define HSFSTS_CTL_FCYCLE_RDID (0x06 << HSFSTS_CTL_FCYCLE_SHIFT) 41 + #define HSFSTS_CTL_FCYCLE_WRSR (0x07 << HSFSTS_CTL_FCYCLE_SHIFT) 42 + #define HSFSTS_CTL_FCYCLE_RDSR (0x08 << HSFSTS_CTL_FCYCLE_SHIFT) 43 + 44 + #define HSFSTS_CTL_FGO BIT(16) 45 + #define HSFSTS_CTL_FLOCKDN BIT(15) 46 + #define HSFSTS_CTL_FDV BIT(14) 47 + #define HSFSTS_CTL_SCIP BIT(5) 48 + #define HSFSTS_CTL_AEL BIT(2) 49 + #define HSFSTS_CTL_FCERR BIT(1) 50 + #define HSFSTS_CTL_FDONE BIT(0) 51 + 52 + #define FADDR 0x08 53 + #define DLOCK 0x0c 54 + #define FDATA(n) (0x10 + ((n) * 4)) 55 + 56 + #define FRACC 0x50 57 + 58 + #define FREG(n) (0x54 + ((n) * 4)) 59 + #define FREG_BASE_MASK 0x3fff 60 + #define FREG_LIMIT_SHIFT 16 61 + #define FREG_LIMIT_MASK (0x03fff << FREG_LIMIT_SHIFT) 62 + 63 + /* Offset is from @ispi->pregs */ 64 + #define PR(n) ((n) * 4) 65 + #define PR_WPE BIT(31) 66 + #define PR_LIMIT_SHIFT 16 67 + #define PR_LIMIT_MASK (0x3fff << PR_LIMIT_SHIFT) 68 + #define PR_RPE BIT(15) 69 + #define PR_BASE_MASK 0x3fff 70 + /* Last PR is GPR0 */ 71 + #define PR_NUM (5 + 1) 72 + 73 + /* Offsets are from @ispi->sregs */ 74 + #define SSFSTS_CTL 0x00 75 + #define SSFSTS_CTL_FSMIE BIT(23) 76 + #define SSFSTS_CTL_DS BIT(22) 77 + #define SSFSTS_CTL_DBC_SHIFT 16 78 + #define SSFSTS_CTL_SPOP BIT(11) 79 + #define SSFSTS_CTL_ACS BIT(10) 80 + #define SSFSTS_CTL_SCGO BIT(9) 81 + #define SSFSTS_CTL_COP_SHIFT 12 82 + #define SSFSTS_CTL_FRS BIT(7) 83 + #define SSFSTS_CTL_DOFRS BIT(6) 84 + #define SSFSTS_CTL_AEL BIT(4) 85 + #define SSFSTS_CTL_FCERR BIT(3) 86 + #define SSFSTS_CTL_FDONE BIT(2) 87 + #define SSFSTS_CTL_SCIP BIT(0) 88 + 89 + #define PREOP_OPTYPE 0x04 90 + #define OPMENU0 0x08 91 + #define OPMENU1 0x0c 92 + 93 + /* CPU specifics */ 94 + #define BYT_PR 0x74 95 + #define BYT_SSFSTS_CTL 0x90 96 + #define BYT_BCR 0xfc 97 + #define BYT_BCR_WPD BIT(0) 98 + #define BYT_FREG_NUM 5 99 + 100 + #define LPT_PR 0x74 101 + #define LPT_SSFSTS_CTL 0x90 102 + #define LPT_FREG_NUM 5 103 + 104 + #define BXT_PR 0x84 105 + #define BXT_SSFSTS_CTL 0xa0 106 + #define BXT_FREG_NUM 12 107 + 108 + #define INTEL_SPI_TIMEOUT 5000 /* ms */ 109 + #define INTEL_SPI_FIFO_SZ 64 110 + 111 + /** 112 + * struct intel_spi - Driver private data 113 + * @dev: Device pointer 114 + * @info: Pointer to board specific info 115 + * @nor: SPI NOR layer structure 116 + * @base: Beginning of MMIO space 117 + * @pregs: Start of protection registers 118 + * @sregs: Start of software sequencer registers 119 + * @nregions: Maximum number of regions 120 + * @writeable: Is the chip writeable 121 + * @swseq: Use SW sequencer in register reads/writes 122 + * @erase_64k: 64k erase supported 123 + * @opcodes: Opcodes which are supported. This are programmed by BIOS 124 + * before it locks down the controller. 125 + * @preopcodes: Preopcodes which are supported. 126 + */ 127 + struct intel_spi { 128 + struct device *dev; 129 + const struct intel_spi_boardinfo *info; 130 + struct spi_nor nor; 131 + void __iomem *base; 132 + void __iomem *pregs; 133 + void __iomem *sregs; 134 + size_t nregions; 135 + bool writeable; 136 + bool swseq; 137 + bool erase_64k; 138 + u8 opcodes[8]; 139 + u8 preopcodes[2]; 140 + }; 141 + 142 + static bool writeable; 143 + module_param(writeable, bool, 0); 144 + MODULE_PARM_DESC(writeable, "Enable write access to SPI flash chip (default=0)"); 145 + 146 + static void intel_spi_dump_regs(struct intel_spi *ispi) 147 + { 148 + u32 value; 149 + int i; 150 + 151 + dev_dbg(ispi->dev, "BFPREG=0x%08x\n", readl(ispi->base + BFPREG)); 152 + 153 + value = readl(ispi->base + HSFSTS_CTL); 154 + dev_dbg(ispi->dev, "HSFSTS_CTL=0x%08x\n", value); 155 + if (value & HSFSTS_CTL_FLOCKDN) 156 + dev_dbg(ispi->dev, "-> Locked\n"); 157 + 158 + dev_dbg(ispi->dev, "FADDR=0x%08x\n", readl(ispi->base + FADDR)); 159 + dev_dbg(ispi->dev, "DLOCK=0x%08x\n", readl(ispi->base + DLOCK)); 160 + 161 + for (i = 0; i < 16; i++) 162 + dev_dbg(ispi->dev, "FDATA(%d)=0x%08x\n", 163 + i, readl(ispi->base + FDATA(i))); 164 + 165 + dev_dbg(ispi->dev, "FRACC=0x%08x\n", readl(ispi->base + FRACC)); 166 + 167 + for (i = 0; i < ispi->nregions; i++) 168 + dev_dbg(ispi->dev, "FREG(%d)=0x%08x\n", i, 169 + readl(ispi->base + FREG(i))); 170 + for (i = 0; i < PR_NUM; i++) 171 + dev_dbg(ispi->dev, "PR(%d)=0x%08x\n", i, 172 + readl(ispi->pregs + PR(i))); 173 + 174 + value = readl(ispi->sregs + SSFSTS_CTL); 175 + dev_dbg(ispi->dev, "SSFSTS_CTL=0x%08x\n", value); 176 + dev_dbg(ispi->dev, "PREOP_OPTYPE=0x%08x\n", 177 + readl(ispi->sregs + PREOP_OPTYPE)); 178 + dev_dbg(ispi->dev, "OPMENU0=0x%08x\n", readl(ispi->sregs + OPMENU0)); 179 + dev_dbg(ispi->dev, "OPMENU1=0x%08x\n", readl(ispi->sregs + OPMENU1)); 180 + 181 + if (ispi->info->type == INTEL_SPI_BYT) 182 + dev_dbg(ispi->dev, "BCR=0x%08x\n", readl(ispi->base + BYT_BCR)); 183 + 184 + dev_dbg(ispi->dev, "Protected regions:\n"); 185 + for (i = 0; i < PR_NUM; i++) { 186 + u32 base, limit; 187 + 188 + value = readl(ispi->pregs + PR(i)); 189 + if (!(value & (PR_WPE | PR_RPE))) 190 + continue; 191 + 192 + limit = (value & PR_LIMIT_MASK) >> PR_LIMIT_SHIFT; 193 + base = value & PR_BASE_MASK; 194 + 195 + dev_dbg(ispi->dev, " %02d base: 0x%08x limit: 0x%08x [%c%c]\n", 196 + i, base << 12, (limit << 12) | 0xfff, 197 + value & PR_WPE ? 'W' : '.', 198 + value & PR_RPE ? 'R' : '.'); 199 + } 200 + 201 + dev_dbg(ispi->dev, "Flash regions:\n"); 202 + for (i = 0; i < ispi->nregions; i++) { 203 + u32 region, base, limit; 204 + 205 + region = readl(ispi->base + FREG(i)); 206 + base = region & FREG_BASE_MASK; 207 + limit = (region & FREG_LIMIT_MASK) >> FREG_LIMIT_SHIFT; 208 + 209 + if (base >= limit || (i > 0 && limit == 0)) 210 + dev_dbg(ispi->dev, " %02d disabled\n", i); 211 + else 212 + dev_dbg(ispi->dev, " %02d base: 0x%08x limit: 0x%08x\n", 213 + i, base << 12, (limit << 12) | 0xfff); 214 + } 215 + 216 + dev_dbg(ispi->dev, "Using %cW sequencer for register access\n", 217 + ispi->swseq ? 'S' : 'H'); 218 + } 219 + 220 + /* Reads max INTEL_SPI_FIFO_SZ bytes from the device fifo */ 221 + static int intel_spi_read_block(struct intel_spi *ispi, void *buf, size_t size) 222 + { 223 + size_t bytes; 224 + int i = 0; 225 + 226 + if (size > INTEL_SPI_FIFO_SZ) 227 + return -EINVAL; 228 + 229 + while (size > 0) { 230 + bytes = min_t(size_t, size, 4); 231 + memcpy_fromio(buf, ispi->base + FDATA(i), bytes); 232 + size -= bytes; 233 + buf += bytes; 234 + i++; 235 + } 236 + 237 + return 0; 238 + } 239 + 240 + /* Writes max INTEL_SPI_FIFO_SZ bytes to the device fifo */ 241 + static int intel_spi_write_block(struct intel_spi *ispi, const void *buf, 242 + size_t size) 243 + { 244 + size_t bytes; 245 + int i = 0; 246 + 247 + if (size > INTEL_SPI_FIFO_SZ) 248 + return -EINVAL; 249 + 250 + while (size > 0) { 251 + bytes = min_t(size_t, size, 4); 252 + memcpy_toio(ispi->base + FDATA(i), buf, bytes); 253 + size -= bytes; 254 + buf += bytes; 255 + i++; 256 + } 257 + 258 + return 0; 259 + } 260 + 261 + static int intel_spi_wait_hw_busy(struct intel_spi *ispi) 262 + { 263 + u32 val; 264 + 265 + return readl_poll_timeout(ispi->base + HSFSTS_CTL, val, 266 + !(val & HSFSTS_CTL_SCIP), 0, 267 + INTEL_SPI_TIMEOUT * 1000); 268 + } 269 + 270 + static int intel_spi_wait_sw_busy(struct intel_spi *ispi) 271 + { 272 + u32 val; 273 + 274 + return readl_poll_timeout(ispi->sregs + SSFSTS_CTL, val, 275 + !(val & SSFSTS_CTL_SCIP), 0, 276 + INTEL_SPI_TIMEOUT * 1000); 277 + } 278 + 279 + static int intel_spi_init(struct intel_spi *ispi) 280 + { 281 + u32 opmenu0, opmenu1, val; 282 + int i; 283 + 284 + switch (ispi->info->type) { 285 + case INTEL_SPI_BYT: 286 + ispi->sregs = ispi->base + BYT_SSFSTS_CTL; 287 + ispi->pregs = ispi->base + BYT_PR; 288 + ispi->nregions = BYT_FREG_NUM; 289 + 290 + if (writeable) { 291 + /* Disable write protection */ 292 + val = readl(ispi->base + BYT_BCR); 293 + if (!(val & BYT_BCR_WPD)) { 294 + val |= BYT_BCR_WPD; 295 + writel(val, ispi->base + BYT_BCR); 296 + val = readl(ispi->base + BYT_BCR); 297 + } 298 + 299 + ispi->writeable = !!(val & BYT_BCR_WPD); 300 + } 301 + 302 + break; 303 + 304 + case INTEL_SPI_LPT: 305 + ispi->sregs = ispi->base + LPT_SSFSTS_CTL; 306 + ispi->pregs = ispi->base + LPT_PR; 307 + ispi->nregions = LPT_FREG_NUM; 308 + break; 309 + 310 + case INTEL_SPI_BXT: 311 + ispi->sregs = ispi->base + BXT_SSFSTS_CTL; 312 + ispi->pregs = ispi->base + BXT_PR; 313 + ispi->nregions = BXT_FREG_NUM; 314 + ispi->erase_64k = true; 315 + break; 316 + 317 + default: 318 + return -EINVAL; 319 + } 320 + 321 + /* Disable #SMI generation */ 322 + val = readl(ispi->base + HSFSTS_CTL); 323 + val &= ~HSFSTS_CTL_FSMIE; 324 + writel(val, ispi->base + HSFSTS_CTL); 325 + 326 + /* 327 + * BIOS programs allowed opcodes and then locks down the register. 328 + * So read back what opcodes it decided to support. That's the set 329 + * we are going to support as well. 330 + */ 331 + opmenu0 = readl(ispi->sregs + OPMENU0); 332 + opmenu1 = readl(ispi->sregs + OPMENU1); 333 + 334 + /* 335 + * Some controllers can only do basic operations using hardware 336 + * sequencer. All other operations are supposed to be carried out 337 + * using software sequencer. If we find that BIOS has programmed 338 + * opcodes for the software sequencer we use that over the hardware 339 + * sequencer. 340 + */ 341 + if (opmenu0 && opmenu1) { 342 + for (i = 0; i < ARRAY_SIZE(ispi->opcodes) / 2; i++) { 343 + ispi->opcodes[i] = opmenu0 >> i * 8; 344 + ispi->opcodes[i + 4] = opmenu1 >> i * 8; 345 + } 346 + 347 + val = readl(ispi->sregs + PREOP_OPTYPE); 348 + ispi->preopcodes[0] = val; 349 + ispi->preopcodes[1] = val >> 8; 350 + 351 + /* Disable #SMI generation from SW sequencer */ 352 + val = readl(ispi->sregs + SSFSTS_CTL); 353 + val &= ~SSFSTS_CTL_FSMIE; 354 + writel(val, ispi->sregs + SSFSTS_CTL); 355 + 356 + ispi->swseq = true; 357 + } 358 + 359 + intel_spi_dump_regs(ispi); 360 + 361 + return 0; 362 + } 363 + 364 + static int intel_spi_opcode_index(struct intel_spi *ispi, u8 opcode) 365 + { 366 + int i; 367 + 368 + for (i = 0; i < ARRAY_SIZE(ispi->opcodes); i++) 369 + if (ispi->opcodes[i] == opcode) 370 + return i; 371 + return -EINVAL; 372 + } 373 + 374 + static int intel_spi_hw_cycle(struct intel_spi *ispi, u8 opcode, u8 *buf, 375 + int len) 376 + { 377 + u32 val, status; 378 + int ret; 379 + 380 + val = readl(ispi->base + HSFSTS_CTL); 381 + val &= ~(HSFSTS_CTL_FCYCLE_MASK | HSFSTS_CTL_FDBC_MASK); 382 + 383 + switch (opcode) { 384 + case SPINOR_OP_RDID: 385 + val |= HSFSTS_CTL_FCYCLE_RDID; 386 + break; 387 + case SPINOR_OP_WRSR: 388 + val |= HSFSTS_CTL_FCYCLE_WRSR; 389 + break; 390 + case SPINOR_OP_RDSR: 391 + val |= HSFSTS_CTL_FCYCLE_RDSR; 392 + break; 393 + default: 394 + return -EINVAL; 395 + } 396 + 397 + val |= (len - 1) << HSFSTS_CTL_FDBC_SHIFT; 398 + val |= HSFSTS_CTL_FCERR | HSFSTS_CTL_FDONE; 399 + val |= HSFSTS_CTL_FGO; 400 + writel(val, ispi->base + HSFSTS_CTL); 401 + 402 + ret = intel_spi_wait_hw_busy(ispi); 403 + if (ret) 404 + return ret; 405 + 406 + status = readl(ispi->base + HSFSTS_CTL); 407 + if (status & HSFSTS_CTL_FCERR) 408 + return -EIO; 409 + else if (status & HSFSTS_CTL_AEL) 410 + return -EACCES; 411 + 412 + return 0; 413 + } 414 + 415 + static int intel_spi_sw_cycle(struct intel_spi *ispi, u8 opcode, u8 *buf, 416 + int len) 417 + { 418 + u32 val, status; 419 + int ret; 420 + 421 + ret = intel_spi_opcode_index(ispi, opcode); 422 + if (ret < 0) 423 + return ret; 424 + 425 + val = (len << SSFSTS_CTL_DBC_SHIFT) | SSFSTS_CTL_DS; 426 + val |= ret << SSFSTS_CTL_COP_SHIFT; 427 + val |= SSFSTS_CTL_FCERR | SSFSTS_CTL_FDONE; 428 + val |= SSFSTS_CTL_SCGO; 429 + writel(val, ispi->sregs + SSFSTS_CTL); 430 + 431 + ret = intel_spi_wait_sw_busy(ispi); 432 + if (ret) 433 + return ret; 434 + 435 + status = readl(ispi->base + SSFSTS_CTL); 436 + if (status & SSFSTS_CTL_FCERR) 437 + return -EIO; 438 + else if (status & SSFSTS_CTL_AEL) 439 + return -EACCES; 440 + 441 + return 0; 442 + } 443 + 444 + static int intel_spi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) 445 + { 446 + struct intel_spi *ispi = nor->priv; 447 + int ret; 448 + 449 + /* Address of the first chip */ 450 + writel(0, ispi->base + FADDR); 451 + 452 + if (ispi->swseq) 453 + ret = intel_spi_sw_cycle(ispi, opcode, buf, len); 454 + else 455 + ret = intel_spi_hw_cycle(ispi, opcode, buf, len); 456 + 457 + if (ret) 458 + return ret; 459 + 460 + return intel_spi_read_block(ispi, buf, len); 461 + } 462 + 463 + static int intel_spi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) 464 + { 465 + struct intel_spi *ispi = nor->priv; 466 + int ret; 467 + 468 + /* 469 + * This is handled with atomic operation and preop code in Intel 470 + * controller so skip it here now. 471 + */ 472 + if (opcode == SPINOR_OP_WREN) 473 + return 0; 474 + 475 + writel(0, ispi->base + FADDR); 476 + 477 + /* Write the value beforehand */ 478 + ret = intel_spi_write_block(ispi, buf, len); 479 + if (ret) 480 + return ret; 481 + 482 + if (ispi->swseq) 483 + return intel_spi_sw_cycle(ispi, opcode, buf, len); 484 + return intel_spi_hw_cycle(ispi, opcode, buf, len); 485 + } 486 + 487 + static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len, 488 + u_char *read_buf) 489 + { 490 + struct intel_spi *ispi = nor->priv; 491 + size_t block_size, retlen = 0; 492 + u32 val, status; 493 + ssize_t ret; 494 + 495 + switch (nor->read_opcode) { 496 + case SPINOR_OP_READ: 497 + case SPINOR_OP_READ_FAST: 498 + break; 499 + default: 500 + return -EINVAL; 501 + } 502 + 503 + while (len > 0) { 504 + block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ); 505 + 506 + writel(from, ispi->base + FADDR); 507 + 508 + val = readl(ispi->base + HSFSTS_CTL); 509 + val &= ~(HSFSTS_CTL_FDBC_MASK | HSFSTS_CTL_FCYCLE_MASK); 510 + val |= HSFSTS_CTL_AEL | HSFSTS_CTL_FCERR | HSFSTS_CTL_FDONE; 511 + val |= (block_size - 1) << HSFSTS_CTL_FDBC_SHIFT; 512 + val |= HSFSTS_CTL_FCYCLE_READ; 513 + val |= HSFSTS_CTL_FGO; 514 + writel(val, ispi->base + HSFSTS_CTL); 515 + 516 + ret = intel_spi_wait_hw_busy(ispi); 517 + if (ret) 518 + return ret; 519 + 520 + status = readl(ispi->base + HSFSTS_CTL); 521 + if (status & HSFSTS_CTL_FCERR) 522 + ret = -EIO; 523 + else if (status & HSFSTS_CTL_AEL) 524 + ret = -EACCES; 525 + 526 + if (ret < 0) { 527 + dev_err(ispi->dev, "read error: %llx: %#x\n", from, 528 + status); 529 + return ret; 530 + } 531 + 532 + ret = intel_spi_read_block(ispi, read_buf, block_size); 533 + if (ret) 534 + return ret; 535 + 536 + len -= block_size; 537 + from += block_size; 538 + retlen += block_size; 539 + read_buf += block_size; 540 + } 541 + 542 + return retlen; 543 + } 544 + 545 + static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, 546 + const u_char *write_buf) 547 + { 548 + struct intel_spi *ispi = nor->priv; 549 + size_t block_size, retlen = 0; 550 + u32 val, status; 551 + ssize_t ret; 552 + 553 + while (len > 0) { 554 + block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ); 555 + 556 + writel(to, ispi->base + FADDR); 557 + 558 + val = readl(ispi->base + HSFSTS_CTL); 559 + val &= ~(HSFSTS_CTL_FDBC_MASK | HSFSTS_CTL_FCYCLE_MASK); 560 + val |= HSFSTS_CTL_AEL | HSFSTS_CTL_FCERR | HSFSTS_CTL_FDONE; 561 + val |= (block_size - 1) << HSFSTS_CTL_FDBC_SHIFT; 562 + val |= HSFSTS_CTL_FCYCLE_WRITE; 563 + 564 + /* Write enable */ 565 + if (ispi->preopcodes[1] == SPINOR_OP_WREN) 566 + val |= SSFSTS_CTL_SPOP; 567 + val |= SSFSTS_CTL_ACS; 568 + writel(val, ispi->base + HSFSTS_CTL); 569 + 570 + ret = intel_spi_write_block(ispi, write_buf, block_size); 571 + if (ret) { 572 + dev_err(ispi->dev, "failed to write block\n"); 573 + return ret; 574 + } 575 + 576 + /* Start the write now */ 577 + val = readl(ispi->base + HSFSTS_CTL); 578 + writel(val | HSFSTS_CTL_FGO, ispi->base + HSFSTS_CTL); 579 + 580 + ret = intel_spi_wait_hw_busy(ispi); 581 + if (ret) { 582 + dev_err(ispi->dev, "timeout\n"); 583 + return ret; 584 + } 585 + 586 + status = readl(ispi->base + HSFSTS_CTL); 587 + if (status & HSFSTS_CTL_FCERR) 588 + ret = -EIO; 589 + else if (status & HSFSTS_CTL_AEL) 590 + ret = -EACCES; 591 + 592 + if (ret < 0) { 593 + dev_err(ispi->dev, "write error: %llx: %#x\n", to, 594 + status); 595 + return ret; 596 + } 597 + 598 + len -= block_size; 599 + to += block_size; 600 + retlen += block_size; 601 + write_buf += block_size; 602 + } 603 + 604 + return retlen; 605 + } 606 + 607 + static int intel_spi_erase(struct spi_nor *nor, loff_t offs) 608 + { 609 + size_t erase_size, len = nor->mtd.erasesize; 610 + struct intel_spi *ispi = nor->priv; 611 + u32 val, status, cmd; 612 + int ret; 613 + 614 + /* If the hardware can do 64k erase use that when possible */ 615 + if (len >= SZ_64K && ispi->erase_64k) { 616 + cmd = HSFSTS_CTL_FCYCLE_ERASE_64K; 617 + erase_size = SZ_64K; 618 + } else { 619 + cmd = HSFSTS_CTL_FCYCLE_ERASE; 620 + erase_size = SZ_4K; 621 + } 622 + 623 + while (len > 0) { 624 + writel(offs, ispi->base + FADDR); 625 + 626 + val = readl(ispi->base + HSFSTS_CTL); 627 + val &= ~(HSFSTS_CTL_FDBC_MASK | HSFSTS_CTL_FCYCLE_MASK); 628 + val |= HSFSTS_CTL_AEL | HSFSTS_CTL_FCERR | HSFSTS_CTL_FDONE; 629 + val |= cmd; 630 + val |= HSFSTS_CTL_FGO; 631 + writel(val, ispi->base + HSFSTS_CTL); 632 + 633 + ret = intel_spi_wait_hw_busy(ispi); 634 + if (ret) 635 + return ret; 636 + 637 + status = readl(ispi->base + HSFSTS_CTL); 638 + if (status & HSFSTS_CTL_FCERR) 639 + return -EIO; 640 + else if (status & HSFSTS_CTL_AEL) 641 + return -EACCES; 642 + 643 + offs += erase_size; 644 + len -= erase_size; 645 + } 646 + 647 + return 0; 648 + } 649 + 650 + static bool intel_spi_is_protected(const struct intel_spi *ispi, 651 + unsigned int base, unsigned int limit) 652 + { 653 + int i; 654 + 655 + for (i = 0; i < PR_NUM; i++) { 656 + u32 pr_base, pr_limit, pr_value; 657 + 658 + pr_value = readl(ispi->pregs + PR(i)); 659 + if (!(pr_value & (PR_WPE | PR_RPE))) 660 + continue; 661 + 662 + pr_limit = (pr_value & PR_LIMIT_MASK) >> PR_LIMIT_SHIFT; 663 + pr_base = pr_value & PR_BASE_MASK; 664 + 665 + if (pr_base >= base && pr_limit <= limit) 666 + return true; 667 + } 668 + 669 + return false; 670 + } 671 + 672 + /* 673 + * There will be a single partition holding all enabled flash regions. We 674 + * call this "BIOS". 675 + */ 676 + static void intel_spi_fill_partition(struct intel_spi *ispi, 677 + struct mtd_partition *part) 678 + { 679 + u64 end; 680 + int i; 681 + 682 + memset(part, 0, sizeof(*part)); 683 + 684 + /* Start from the mandatory descriptor region */ 685 + part->size = 4096; 686 + part->name = "BIOS"; 687 + 688 + /* 689 + * Now try to find where this partition ends based on the flash 690 + * region registers. 691 + */ 692 + for (i = 1; i < ispi->nregions; i++) { 693 + u32 region, base, limit; 694 + 695 + region = readl(ispi->base + FREG(i)); 696 + base = region & FREG_BASE_MASK; 697 + limit = (region & FREG_LIMIT_MASK) >> FREG_LIMIT_SHIFT; 698 + 699 + if (base >= limit || limit == 0) 700 + continue; 701 + 702 + /* 703 + * If any of the regions have protection bits set, make the 704 + * whole partition read-only to be on the safe side. 705 + */ 706 + if (intel_spi_is_protected(ispi, base, limit)) 707 + ispi->writeable = 0; 708 + 709 + end = (limit << 12) + 4096; 710 + if (end > part->size) 711 + part->size = end; 712 + } 713 + } 714 + 715 + struct intel_spi *intel_spi_probe(struct device *dev, 716 + struct resource *mem, const struct intel_spi_boardinfo *info) 717 + { 718 + struct mtd_partition part; 719 + struct intel_spi *ispi; 720 + int ret; 721 + 722 + if (!info || !mem) 723 + return ERR_PTR(-EINVAL); 724 + 725 + ispi = devm_kzalloc(dev, sizeof(*ispi), GFP_KERNEL); 726 + if (!ispi) 727 + return ERR_PTR(-ENOMEM); 728 + 729 + ispi->base = devm_ioremap_resource(dev, mem); 730 + if (IS_ERR(ispi->base)) 731 + return ispi->base; 732 + 733 + ispi->dev = dev; 734 + ispi->info = info; 735 + ispi->writeable = info->writeable; 736 + 737 + ret = intel_spi_init(ispi); 738 + if (ret) 739 + return ERR_PTR(ret); 740 + 741 + ispi->nor.dev = ispi->dev; 742 + ispi->nor.priv = ispi; 743 + ispi->nor.read_reg = intel_spi_read_reg; 744 + ispi->nor.write_reg = intel_spi_write_reg; 745 + ispi->nor.read = intel_spi_read; 746 + ispi->nor.write = intel_spi_write; 747 + ispi->nor.erase = intel_spi_erase; 748 + 749 + ret = spi_nor_scan(&ispi->nor, NULL, SPI_NOR_NORMAL); 750 + if (ret) { 751 + dev_info(dev, "failed to locate the chip\n"); 752 + return ERR_PTR(ret); 753 + } 754 + 755 + intel_spi_fill_partition(ispi, &part); 756 + 757 + /* Prevent writes if not explicitly enabled */ 758 + if (!ispi->writeable || !writeable) 759 + ispi->nor.mtd.flags &= ~MTD_WRITEABLE; 760 + 761 + ret = mtd_device_parse_register(&ispi->nor.mtd, NULL, NULL, &part, 1); 762 + if (ret) 763 + return ERR_PTR(ret); 764 + 765 + return ispi; 766 + } 767 + EXPORT_SYMBOL_GPL(intel_spi_probe); 768 + 769 + int intel_spi_remove(struct intel_spi *ispi) 770 + { 771 + return mtd_device_unregister(&ispi->nor.mtd); 772 + } 773 + EXPORT_SYMBOL_GPL(intel_spi_remove); 774 + 775 + MODULE_DESCRIPTION("Intel PCH/PCU SPI flash core driver"); 776 + MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); 777 + MODULE_LICENSE("GPL v2");
+24
drivers/mtd/spi-nor/intel-spi.h
··· 1 + /* 2 + * Intel PCH/PCU SPI flash driver. 3 + * 4 + * Copyright (C) 2016, Intel Corporation 5 + * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #ifndef INTEL_SPI_H 13 + #define INTEL_SPI_H 14 + 15 + #include <linux/platform_data/intel-spi.h> 16 + 17 + struct intel_spi; 18 + struct resource; 19 + 20 + struct intel_spi *intel_spi_probe(struct device *dev, 21 + struct resource *mem, const struct intel_spi_boardinfo *info); 22 + int intel_spi_remove(struct intel_spi *ispi); 23 + 24 + #endif /* INTEL_SPI_H */
+241 -30
drivers/mtd/spi-nor/spi-nor.c
··· 75 75 * bit. Must be used with 76 76 * SPI_NOR_HAS_LOCK. 77 77 */ 78 + #define SPI_S3AN BIT(10) /* 79 + * Xilinx Spartan 3AN In-System Flash 80 + * (MFR cannot be used for probing 81 + * because it has the same value as 82 + * ATMEL flashes) 83 + */ 84 + #define SPI_NOR_4B_OPCODES BIT(11) /* 85 + * Use dedicated 4byte address op codes 86 + * to support memory size above 128Mib. 87 + */ 78 88 }; 79 89 80 90 #define JEDEC_MFR(info) ((info)->id[0]) ··· 198 188 return mtd->priv; 199 189 } 200 190 191 + 192 + static u8 spi_nor_convert_opcode(u8 opcode, const u8 table[][2], size_t size) 193 + { 194 + size_t i; 195 + 196 + for (i = 0; i < size; i++) 197 + if (table[i][0] == opcode) 198 + return table[i][1]; 199 + 200 + /* No conversion found, keep input op code. */ 201 + return opcode; 202 + } 203 + 204 + static inline u8 spi_nor_convert_3to4_read(u8 opcode) 205 + { 206 + static const u8 spi_nor_3to4_read[][2] = { 207 + { SPINOR_OP_READ, SPINOR_OP_READ_4B }, 208 + { SPINOR_OP_READ_FAST, SPINOR_OP_READ_FAST_4B }, 209 + { SPINOR_OP_READ_1_1_2, SPINOR_OP_READ_1_1_2_4B }, 210 + { SPINOR_OP_READ_1_2_2, SPINOR_OP_READ_1_2_2_4B }, 211 + { SPINOR_OP_READ_1_1_4, SPINOR_OP_READ_1_1_4_4B }, 212 + { SPINOR_OP_READ_1_4_4, SPINOR_OP_READ_1_4_4_4B }, 213 + }; 214 + 215 + return spi_nor_convert_opcode(opcode, spi_nor_3to4_read, 216 + ARRAY_SIZE(spi_nor_3to4_read)); 217 + } 218 + 219 + static inline u8 spi_nor_convert_3to4_program(u8 opcode) 220 + { 221 + static const u8 spi_nor_3to4_program[][2] = { 222 + { SPINOR_OP_PP, SPINOR_OP_PP_4B }, 223 + { SPINOR_OP_PP_1_1_4, SPINOR_OP_PP_1_1_4_4B }, 224 + { SPINOR_OP_PP_1_4_4, SPINOR_OP_PP_1_4_4_4B }, 225 + }; 226 + 227 + return spi_nor_convert_opcode(opcode, spi_nor_3to4_program, 228 + ARRAY_SIZE(spi_nor_3to4_program)); 229 + } 230 + 231 + static inline u8 spi_nor_convert_3to4_erase(u8 opcode) 232 + { 233 + static const u8 spi_nor_3to4_erase[][2] = { 234 + { SPINOR_OP_BE_4K, SPINOR_OP_BE_4K_4B }, 235 + { SPINOR_OP_BE_32K, SPINOR_OP_BE_32K_4B }, 236 + { SPINOR_OP_SE, SPINOR_OP_SE_4B }, 237 + }; 238 + 239 + return spi_nor_convert_opcode(opcode, spi_nor_3to4_erase, 240 + ARRAY_SIZE(spi_nor_3to4_erase)); 241 + } 242 + 243 + static void spi_nor_set_4byte_opcodes(struct spi_nor *nor, 244 + const struct flash_info *info) 245 + { 246 + /* Do some manufacturer fixups first */ 247 + switch (JEDEC_MFR(info)) { 248 + case SNOR_MFR_SPANSION: 249 + /* No small sector erase for 4-byte command set */ 250 + nor->erase_opcode = SPINOR_OP_SE; 251 + nor->mtd.erasesize = info->sector_size; 252 + break; 253 + 254 + default: 255 + break; 256 + } 257 + 258 + nor->read_opcode = spi_nor_convert_3to4_read(nor->read_opcode); 259 + nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode); 260 + nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode); 261 + } 262 + 201 263 /* Enable/disable 4-byte addressing mode. */ 202 264 static inline int set_4byte(struct spi_nor *nor, const struct flash_info *info, 203 265 int enable) ··· 299 217 return nor->write_reg(nor, SPINOR_OP_BRWR, nor->cmd_buf, 1); 300 218 } 301 219 } 220 + 221 + static int s3an_sr_ready(struct spi_nor *nor) 222 + { 223 + int ret; 224 + u8 val; 225 + 226 + ret = nor->read_reg(nor, SPINOR_OP_XRDSR, &val, 1); 227 + if (ret < 0) { 228 + dev_err(nor->dev, "error %d reading XRDSR\n", (int) ret); 229 + return ret; 230 + } 231 + 232 + return !!(val & XSR_RDY); 233 + } 234 + 302 235 static inline int spi_nor_sr_ready(struct spi_nor *nor) 303 236 { 304 237 int sr = read_sr(nor); ··· 335 238 static int spi_nor_ready(struct spi_nor *nor) 336 239 { 337 240 int sr, fsr; 338 - sr = spi_nor_sr_ready(nor); 241 + 242 + if (nor->flags & SNOR_F_READY_XSR_RDY) 243 + sr = s3an_sr_ready(nor); 244 + else 245 + sr = spi_nor_sr_ready(nor); 339 246 if (sr < 0) 340 247 return sr; 341 248 fsr = nor->flags & SNOR_F_USE_FSR ? spi_nor_fsr_ready(nor) : 1; ··· 421 320 } 422 321 423 322 /* 323 + * This code converts an address to the Default Address Mode, that has non 324 + * power of two page sizes. We must support this mode because it is the default 325 + * mode supported by Xilinx tools, it can access the whole flash area and 326 + * changing over to the Power-of-two mode is irreversible and corrupts the 327 + * original data. 328 + * Addr can safely be unsigned int, the biggest S3AN device is smaller than 329 + * 4 MiB. 330 + */ 331 + static loff_t spi_nor_s3an_addr_convert(struct spi_nor *nor, unsigned int addr) 332 + { 333 + unsigned int offset; 334 + unsigned int page; 335 + 336 + offset = addr % nor->page_size; 337 + page = addr / nor->page_size; 338 + page <<= (nor->page_size > 512) ? 10 : 9; 339 + 340 + return page | offset; 341 + } 342 + 343 + /* 424 344 * Initiate the erasure of a single sector 425 345 */ 426 346 static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) 427 347 { 428 348 u8 buf[SPI_NOR_MAX_ADDR_WIDTH]; 429 349 int i; 350 + 351 + if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT) 352 + addr = spi_nor_s3an_addr_convert(nor, addr); 430 353 431 354 if (nor->erase) 432 355 return nor->erase(nor, addr); ··· 493 368 return ret; 494 369 495 370 /* whole-chip erase? */ 496 - if (len == mtd->size) { 371 + if (len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) { 497 372 unsigned long timeout; 498 373 499 374 write_enable(nor); ··· 907 782 .addr_width = (_addr_width), \ 908 783 .flags = (_flags), 909 784 785 + #define S3AN_INFO(_jedec_id, _n_sectors, _page_size) \ 786 + .id = { \ 787 + ((_jedec_id) >> 16) & 0xff, \ 788 + ((_jedec_id) >> 8) & 0xff, \ 789 + (_jedec_id) & 0xff \ 790 + }, \ 791 + .id_len = 3, \ 792 + .sector_size = (8*_page_size), \ 793 + .n_sectors = (_n_sectors), \ 794 + .page_size = _page_size, \ 795 + .addr_width = 3, \ 796 + .flags = SPI_NOR_NO_FR | SPI_S3AN, 797 + 910 798 /* NOTE: double check command sets and memory organization when you add 911 799 * more nor chips. This current list focusses on newer chips, which 912 800 * have been converging on command sets which including JEDEC ID. ··· 959 821 { "en25s64", INFO(0x1c3817, 0, 64 * 1024, 128, SECT_4K) }, 960 822 961 823 /* ESMT */ 962 - { "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K) }, 824 + { "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) }, 963 825 964 826 /* Everspin */ 965 827 { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, ··· 970 832 { "mb85rs1mt", INFO(0x047f27, 0, 128 * 1024, 1, SPI_NOR_NO_ERASE) }, 971 833 972 834 /* GigaDevice */ 835 + { 836 + "gd25q16", INFO(0xc84015, 0, 64 * 1024, 32, 837 + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 838 + SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) 839 + }, 973 840 { 974 841 "gd25q32", INFO(0xc84016, 0, 64 * 1024, 64, 975 842 SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | ··· 1157 1014 { "cat25c09", CAT25_INFO( 128, 8, 32, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, 1158 1015 { "cat25c17", CAT25_INFO( 256, 8, 32, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, 1159 1016 { "cat25128", CAT25_INFO(2048, 8, 64, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, 1017 + 1018 + /* Xilinx S3AN Internal Flash */ 1019 + { "3S50AN", S3AN_INFO(0x1f2200, 64, 264) }, 1020 + { "3S200AN", S3AN_INFO(0x1f2400, 256, 264) }, 1021 + { "3S400AN", S3AN_INFO(0x1f2400, 256, 264) }, 1022 + { "3S700AN", S3AN_INFO(0x1f2500, 512, 264) }, 1023 + { "3S1400AN", S3AN_INFO(0x1f2600, 512, 528) }, 1160 1024 { }, 1161 1025 }; 1162 1026 ··· 1204 1054 return ret; 1205 1055 1206 1056 while (len) { 1207 - ret = nor->read(nor, from, len, buf); 1057 + loff_t addr = from; 1058 + 1059 + if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT) 1060 + addr = spi_nor_s3an_addr_convert(nor, addr); 1061 + 1062 + ret = nor->read(nor, addr, len, buf); 1208 1063 if (ret == 0) { 1209 1064 /* We shouldn't see 0-length reads */ 1210 1065 ret = -EIO; ··· 1330 1175 1331 1176 for (i = 0; i < len; ) { 1332 1177 ssize_t written; 1178 + loff_t addr = to + i; 1333 1179 1334 - page_offset = (to + i) & (nor->page_size - 1); 1335 - WARN_ONCE(page_offset, 1336 - "Writing at offset %zu into a NOR page. Writing partial pages may decrease reliability and increase wear of NOR flash.", 1337 - page_offset); 1180 + /* 1181 + * If page_size is a power of two, the offset can be quickly 1182 + * calculated with an AND operation. On the other cases we 1183 + * need to do a modulus operation (more expensive). 1184 + * Power of two numbers have only one bit set and we can use 1185 + * the instruction hweight32 to detect if we need to do a 1186 + * modulus (do_div()) or not. 1187 + */ 1188 + if (hweight32(nor->page_size) == 1) { 1189 + page_offset = addr & (nor->page_size - 1); 1190 + } else { 1191 + uint64_t aux = addr; 1192 + 1193 + page_offset = do_div(aux, nor->page_size); 1194 + } 1338 1195 /* the size of data remaining on the first page */ 1339 1196 page_remain = min_t(size_t, 1340 1197 nor->page_size - page_offset, len - i); 1341 1198 1199 + if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT) 1200 + addr = spi_nor_s3an_addr_convert(nor, addr); 1201 + 1342 1202 write_enable(nor); 1343 - ret = nor->write(nor, to + i, page_remain, buf + i); 1203 + ret = nor->write(nor, addr, page_remain, buf + i); 1344 1204 if (ret < 0) 1345 1205 goto write_err; 1346 1206 written = ret; ··· 1386 1216 val = read_sr(nor); 1387 1217 if (val < 0) 1388 1218 return val; 1219 + if (val & SR_QUAD_EN_MX) 1220 + return 0; 1221 + 1389 1222 write_enable(nor); 1390 1223 1391 1224 write_sr(nor, val | SR_QUAD_EN_MX); ··· 1485 1312 return 0; 1486 1313 } 1487 1314 1315 + static int s3an_nor_scan(const struct flash_info *info, struct spi_nor *nor) 1316 + { 1317 + int ret; 1318 + u8 val; 1319 + 1320 + ret = nor->read_reg(nor, SPINOR_OP_XRDSR, &val, 1); 1321 + if (ret < 0) { 1322 + dev_err(nor->dev, "error %d reading XRDSR\n", (int) ret); 1323 + return ret; 1324 + } 1325 + 1326 + nor->erase_opcode = SPINOR_OP_XSE; 1327 + nor->program_opcode = SPINOR_OP_XPP; 1328 + nor->read_opcode = SPINOR_OP_READ; 1329 + nor->flags |= SNOR_F_NO_OP_CHIP_ERASE; 1330 + 1331 + /* 1332 + * This flashes have a page size of 264 or 528 bytes (known as 1333 + * Default addressing mode). It can be changed to a more standard 1334 + * Power of two mode where the page size is 256/512. This comes 1335 + * with a price: there is 3% less of space, the data is corrupted 1336 + * and the page size cannot be changed back to default addressing 1337 + * mode. 1338 + * 1339 + * The current addressing mode can be read from the XRDSR register 1340 + * and should not be changed, because is a destructive operation. 1341 + */ 1342 + if (val & XSR_PAGESIZE) { 1343 + /* Flash in Power of 2 mode */ 1344 + nor->page_size = (nor->page_size == 264) ? 256 : 512; 1345 + nor->mtd.writebufsize = nor->page_size; 1346 + nor->mtd.size = 8 * nor->page_size * info->n_sectors; 1347 + nor->mtd.erasesize = 8 * nor->page_size; 1348 + } else { 1349 + /* Flash in Default addressing mode */ 1350 + nor->flags |= SNOR_F_S3AN_ADDR_DEFAULT; 1351 + } 1352 + 1353 + return 0; 1354 + } 1355 + 1488 1356 int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) 1489 1357 { 1490 1358 const struct flash_info *info = NULL; ··· 1572 1358 } 1573 1359 1574 1360 mutex_init(&nor->lock); 1361 + 1362 + /* 1363 + * Make sure the XSR_RDY flag is set before calling 1364 + * spi_nor_wait_till_ready(). Xilinx S3AN share MFR 1365 + * with Atmel spi-nor 1366 + */ 1367 + if (info->flags & SPI_S3AN) 1368 + nor->flags |= SNOR_F_READY_XSR_RDY; 1575 1369 1576 1370 /* 1577 1371 * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up ··· 1705 1483 else if (mtd->size > 0x1000000) { 1706 1484 /* enable 4-byte addressing if the device exceeds 16MiB */ 1707 1485 nor->addr_width = 4; 1708 - if (JEDEC_MFR(info) == SNOR_MFR_SPANSION) { 1709 - /* Dedicated 4-byte command set */ 1710 - switch (nor->flash_read) { 1711 - case SPI_NOR_QUAD: 1712 - nor->read_opcode = SPINOR_OP_READ4_1_1_4; 1713 - break; 1714 - case SPI_NOR_DUAL: 1715 - nor->read_opcode = SPINOR_OP_READ4_1_1_2; 1716 - break; 1717 - case SPI_NOR_FAST: 1718 - nor->read_opcode = SPINOR_OP_READ4_FAST; 1719 - break; 1720 - case SPI_NOR_NORMAL: 1721 - nor->read_opcode = SPINOR_OP_READ4; 1722 - break; 1723 - } 1724 - nor->program_opcode = SPINOR_OP_PP_4B; 1725 - /* No small sector erase for 4-byte command set */ 1726 - nor->erase_opcode = SPINOR_OP_SE_4B; 1727 - mtd->erasesize = info->sector_size; 1728 - } else 1486 + if (JEDEC_MFR(info) == SNOR_MFR_SPANSION || 1487 + info->flags & SPI_NOR_4B_OPCODES) 1488 + spi_nor_set_4byte_opcodes(nor, info); 1489 + else 1729 1490 set_4byte(nor, info, 1); 1730 1491 } else { 1731 1492 nor->addr_width = 3; ··· 1721 1516 } 1722 1517 1723 1518 nor->read_dummy = spi_nor_read_dummy_cycles(nor); 1519 + 1520 + if (info->flags & SPI_S3AN) { 1521 + ret = s3an_nor_scan(info, nor); 1522 + if (ret) 1523 + return ret; 1524 + } 1724 1525 1725 1526 dev_info(dev, "%s (%lld Kbytes)\n", info->name, 1726 1527 (long long)mtd->size >> 10);
+3 -3
drivers/spi/spi-bcm-qspi.c
··· 371 371 /* default mode, does not need flex_cmd */ 372 372 flex_mode = 0; 373 373 else 374 - command = SPINOR_OP_READ4_FAST; 374 + command = SPINOR_OP_READ_FAST_4B; 375 375 break; 376 376 case SPI_NBITS_DUAL: 377 377 bpc = 0x00000001; ··· 384 384 } else { 385 385 command = SPINOR_OP_READ_1_1_2; 386 386 if (spans_4byte) 387 - command = SPINOR_OP_READ4_1_1_2; 387 + command = SPINOR_OP_READ_1_1_2_4B; 388 388 } 389 389 break; 390 390 case SPI_NBITS_QUAD: ··· 399 399 } else { 400 400 command = SPINOR_OP_READ_1_1_4; 401 401 if (spans_4byte) 402 - command = SPINOR_OP_READ4_1_1_4; 402 + command = SPINOR_OP_READ_1_1_4_4B; 403 403 } 404 404 break; 405 405 default:
+3
include/linux/mfd/lpc_ich.h
··· 20 20 #ifndef LPC_ICH_H 21 21 #define LPC_ICH_H 22 22 23 + #include <linux/platform_data/intel-spi.h> 24 + 23 25 /* GPIO resources */ 24 26 #define ICH_RES_GPIO 0 25 27 #define ICH_RES_GPE0 1 ··· 42 40 char name[32]; 43 41 unsigned int iTCO_version; 44 42 unsigned int gpio_version; 43 + enum intel_spi_type spi_type; 45 44 u8 use_gpio; 46 45 }; 47 46
+28 -6
include/linux/mtd/spi-nor.h
··· 43 43 #define SPINOR_OP_WRSR 0x01 /* Write status register 1 byte */ 44 44 #define SPINOR_OP_READ 0x03 /* Read data bytes (low frequency) */ 45 45 #define SPINOR_OP_READ_FAST 0x0b /* Read data bytes (high frequency) */ 46 - #define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual SPI) */ 47 - #define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad SPI) */ 46 + #define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */ 47 + #define SPINOR_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */ 48 + #define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */ 49 + #define SPINOR_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */ 48 50 #define SPINOR_OP_PP 0x02 /* Page program (up to 256 bytes) */ 51 + #define SPINOR_OP_PP_1_1_4 0x32 /* Quad page program */ 52 + #define SPINOR_OP_PP_1_4_4 0x38 /* Quad page program */ 49 53 #define SPINOR_OP_BE_4K 0x20 /* Erase 4KiB block */ 50 54 #define SPINOR_OP_BE_4K_PMC 0xd7 /* Erase 4KiB block on PMC chips */ 51 55 #define SPINOR_OP_BE_32K 0x52 /* Erase 32KiB block */ ··· 60 56 #define SPINOR_OP_RDFSR 0x70 /* Read flag status register */ 61 57 62 58 /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */ 63 - #define SPINOR_OP_READ4 0x13 /* Read data bytes (low frequency) */ 64 - #define SPINOR_OP_READ4_FAST 0x0c /* Read data bytes (high frequency) */ 65 - #define SPINOR_OP_READ4_1_1_2 0x3c /* Read data bytes (Dual SPI) */ 66 - #define SPINOR_OP_READ4_1_1_4 0x6c /* Read data bytes (Quad SPI) */ 59 + #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */ 60 + #define SPINOR_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */ 61 + #define SPINOR_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */ 62 + #define SPINOR_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */ 63 + #define SPINOR_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */ 64 + #define SPINOR_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */ 67 65 #define SPINOR_OP_PP_4B 0x12 /* Page program (up to 256 bytes) */ 66 + #define SPINOR_OP_PP_1_1_4_4B 0x34 /* Quad page program */ 67 + #define SPINOR_OP_PP_1_4_4_4B 0x3e /* Quad page program */ 68 + #define SPINOR_OP_BE_4K_4B 0x21 /* Erase 4KiB block */ 69 + #define SPINOR_OP_BE_32K_4B 0x5c /* Erase 32KiB block */ 68 70 #define SPINOR_OP_SE_4B 0xdc /* Sector erase (usually 64KiB) */ 69 71 70 72 /* Used for SST flashes only. */ 71 73 #define SPINOR_OP_BP 0x02 /* Byte program */ 72 74 #define SPINOR_OP_WRDI 0x04 /* Write disable */ 73 75 #define SPINOR_OP_AAI_WP 0xad /* Auto address increment word program */ 76 + 77 + /* Used for S3AN flashes only */ 78 + #define SPINOR_OP_XSE 0x50 /* Sector erase */ 79 + #define SPINOR_OP_XPP 0x82 /* Page program */ 80 + #define SPINOR_OP_XRDSR 0xd7 /* Read status register */ 81 + 82 + #define XSR_PAGESIZE BIT(0) /* Page size in Po2 or Linear */ 83 + #define XSR_RDY BIT(7) /* Ready */ 84 + 74 85 75 86 /* Used for Macronix and Winbond flashes. */ 76 87 #define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */ ··· 138 119 enum spi_nor_option_flags { 139 120 SNOR_F_USE_FSR = BIT(0), 140 121 SNOR_F_HAS_SR_TB = BIT(1), 122 + SNOR_F_NO_OP_CHIP_ERASE = BIT(2), 123 + SNOR_F_S3AN_ADDR_DEFAULT = BIT(3), 124 + SNOR_F_READY_XSR_RDY = BIT(4), 141 125 }; 142 126 143 127 /**
+31
include/linux/platform_data/intel-spi.h
··· 1 + /* 2 + * Intel PCH/PCU SPI flash driver. 3 + * 4 + * Copyright (C) 2016, Intel Corporation 5 + * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #ifndef INTEL_SPI_PDATA_H 13 + #define INTEL_SPI_PDATA_H 14 + 15 + enum intel_spi_type { 16 + INTEL_SPI_BYT = 1, 17 + INTEL_SPI_LPT, 18 + INTEL_SPI_BXT, 19 + }; 20 + 21 + /** 22 + * struct intel_spi_boardinfo - Board specific data for Intel SPI driver 23 + * @type: Type which this controller is compatible with 24 + * @writeable: The chip is writeable 25 + */ 26 + struct intel_spi_boardinfo { 27 + enum intel_spi_type type; 28 + bool writeable; 29 + }; 30 + 31 + #endif /* INTEL_SPI_PDATA_H */