#define SST49LF008A            0x005a
 #define AT49BV6416             0x00d6
 
+/*
+ * Status Register bit description. Used by flash devices that don't
+ * support DQ polling (e.g. HyperFlash)
+ */
+#define CFI_SR_DRB             BIT(7)
+#define CFI_SR_ESB             BIT(5)
+#define CFI_SR_PSB             BIT(4)
+#define CFI_SR_WBASB           BIT(3)
+#define CFI_SR_SLSB            BIT(1)
+
 static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
 static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
 static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
        .module         = THIS_MODULE
 };
 
+/*
+ * Use status register to poll for Erase/write completion when DQ is not
+ * supported. This is indicated by Bit[1:0] of SoftwareFeatures field in
+ * CFI Primary Vendor-Specific Extended Query table 1.5
+ */
+static int cfi_use_status_reg(struct cfi_private *cfi)
+{
+       struct cfi_pri_amdstd *extp = cfi->cmdset_priv;
+       u8 poll_mask = CFI_POLL_STATUS_REG | CFI_POLL_DQ;
+
+       return extp->MinorVersion >= '5' &&
+               (extp->SoftwareFeatures & poll_mask) == CFI_POLL_STATUS_REG;
+}
+
+static void cfi_check_err_status(struct map_info *map, struct flchip *chip,
+                                unsigned long adr)
+{
+       struct cfi_private *cfi = map->fldrv_priv;
+       map_word status;
+
+       if (!cfi_use_status_reg(cfi))
+               return;
+
+       cfi_send_gen_cmd(0x70, cfi->addr_unlock1, chip->start, map, cfi,
+                        cfi->device_type, NULL);
+       status = map_read(map, adr);
+
+       if (map_word_bitsset(map, status, CMD(0x3a))) {
+               unsigned long chipstatus = MERGESTATUS(status);
+
+               if (chipstatus & CFI_SR_ESB)
+                       pr_err("%s erase operation failed, status %lx\n",
+                              map->name, chipstatus);
+               if (chipstatus & CFI_SR_PSB)
+                       pr_err("%s program operation failed, status %lx\n",
+                              map->name, chipstatus);
+               if (chipstatus & CFI_SR_WBASB)
+                       pr_err("%s buffer program command aborted, status %lx\n",
+                              map->name, chipstatus);
+               if (chipstatus & CFI_SR_SLSB)
+                       pr_err("%s sector write protected, status %lx\n",
+                              map->name, chipstatus);
+       }
+}
 
 /* #define DEBUG_CFI_FEATURES */
 
  * correctly and is therefore not done (particularly with interleaved chips
  * as each chip must be checked independently of the others).
  */
-static int __xipram chip_ready(struct map_info *map, unsigned long addr)
+static int __xipram chip_ready(struct map_info *map, struct flchip *chip,
+                              unsigned long addr)
 {
+       struct cfi_private *cfi = map->fldrv_priv;
        map_word d, t;
 
+       if (cfi_use_status_reg(cfi)) {
+               map_word ready = CMD(CFI_SR_DRB);
+               /*
+                * For chips that support status register, check device
+                * ready bit
+                */
+               cfi_send_gen_cmd(0x70, cfi->addr_unlock1, chip->start, map, cfi,
+                                cfi->device_type, NULL);
+               d = map_read(map, addr);
+
+               return map_word_andequal(map, d, ready, ready);
+       }
+
        d = map_read(map, addr);
        t = map_read(map, addr);
 
  * as each chip must be checked independently of the others).
  *
  */
-static int __xipram chip_good(struct map_info *map, unsigned long addr, map_word expected)
+static int __xipram chip_good(struct map_info *map, struct flchip *chip,
+                             unsigned long addr, map_word expected)
 {
+       struct cfi_private *cfi = map->fldrv_priv;
        map_word oldd, curd;
 
+       if (cfi_use_status_reg(cfi)) {
+               map_word ready = CMD(CFI_SR_DRB);
+               map_word err = CMD(CFI_SR_PSB | CFI_SR_ESB);
+               /*
+                * For chips that support status register, check device
+                * ready bit and Erase/Program status bit to know if
+                * operation succeeded.
+                */
+               cfi_send_gen_cmd(0x70, cfi->addr_unlock1, chip->start, map, cfi,
+                                cfi->device_type, NULL);
+               curd = map_read(map, addr);
+
+               if (map_word_andequal(map, curd, ready, ready))
+                       return !map_word_bitsset(map, curd, err);
+
+               return 0;
+       }
+
        oldd = map_read(map, addr);
        curd = map_read(map, addr);
 
 
        case FL_STATUS:
                for (;;) {
-                       if (chip_ready(map, adr))
+                       if (chip_ready(map, chip, adr))
                                break;
 
                        if (time_after(jiffies, timeo)) {
                chip->state = FL_ERASE_SUSPENDING;
                chip->erase_suspended = 1;
                for (;;) {
-                       if (chip_ready(map, adr))
+                       if (chip_ready(map, chip, adr))
                                break;
 
                        if (time_after(jiffies, timeo)) {
        /* wait for chip to become ready */
        timeo = jiffies + msecs_to_jiffies(2);
        for (;;) {
-               if (chip_ready(map, adr))
+               if (chip_ready(map, chip, adr))
                        break;
 
                if (time_after(jiffies, timeo)) {
                        continue;
                }
 
-               if (time_after(jiffies, timeo) && !chip_ready(map, adr)){
+               if (time_after(jiffies, timeo) &&
+                   !chip_ready(map, chip, adr)) {
                        xip_enable(map, chip, adr);
                        printk(KERN_WARNING "MTD %s(): software timeout\n", __func__);
                        xip_disable(map, chip, adr);
                        break;
                }
 
-               if (chip_ready(map, adr))
+               if (chip_ready(map, chip, adr))
                        break;
 
                /* Latency issues. Drop the lock, wait a while and retry */
                UDELAY(map, chip, adr, 1);
        }
        /* Did we succeed? */
-       if (!chip_good(map, adr, datum)) {
+       if (!chip_good(map, chip, adr, datum)) {
                /* reset on all failures. */
+               cfi_check_err_status(map, chip, adr);
                map_write(map, CMD(0xF0), chip->start);
                /* FIXME - should have reset delay before continuing */
 
                 * We check "time_after" and "!chip_good" before checking "chip_good" to avoid
                 * the failure due to scheduling.
                 */
-               if (time_after(jiffies, timeo) && !chip_good(map, adr, datum))
+               if (time_after(jiffies, timeo) &&
+                   !chip_good(map, chip, adr, datum))
                        break;
 
-               if (chip_good(map, adr, datum)) {
+               if (chip_good(map, chip, adr, datum)) {
                        xip_enable(map, chip, adr);
                        goto op_done;
                }
         * See e.g.
         * http://www.spansion.com/Support/Application%20Notes/MirrorBit_Write_Buffer_Prog_Page_Buffer_Read_AN.pdf
         */
+       cfi_check_err_status(map, chip, adr);
        cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi,
                         cfi->device_type, NULL);
        cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi,
         * If the driver thinks the chip is idle, and no toggle bits
         * are changing, then the chip is actually idle for sure.
         */
-       if (chip->state == FL_READY && chip_ready(map, adr))
+       if (chip->state == FL_READY && chip_ready(map, chip, adr))
                return 0;
 
        /*
 
                /* wait for the chip to become ready */
                for (i = 0; i < jiffies_to_usecs(timeo); i++) {
-                       if (chip_ready(map, adr))
+                       if (chip_ready(map, chip, adr))
                                return 0;
 
                        udelay(1);
        map_write(map, datum, adr);
 
        for (i = 0; i < jiffies_to_usecs(uWriteTimeout); i++) {
-               if (chip_ready(map, adr))
+               if (chip_ready(map, chip, adr))
                        break;
 
                udelay(1);
        }
 
-       if (!chip_good(map, adr, datum)) {
+       if (!chip_good(map, chip, adr, datum)) {
                /* reset on all failures. */
+               cfi_check_err_status(map, chip, adr);
                map_write(map, CMD(0xF0), chip->start);
                /* FIXME - should have reset delay before continuing */
 
                        chip->erase_suspended = 0;
                }
 
-               if (chip_good(map, adr, map_word_ff(map)))
+               if (chip_good(map, chip, adr, map_word_ff(map)))
                        break;
 
                if (time_after(jiffies, timeo)) {
        /* Did we succeed? */
        if (ret) {
                /* reset on all failures. */
+               cfi_check_err_status(map, chip, adr);
                map_write(map, CMD(0xF0), chip->start);
                /* FIXME - should have reset delay before continuing */
 
                        chip->erase_suspended = 0;
                }
 
-               if (chip_good(map, adr, map_word_ff(map)))
+               if (chip_good(map, chip, adr, map_word_ff(map)))
                        break;
 
                if (time_after(jiffies, timeo)) {
        /* Did we succeed? */
        if (ret) {
                /* reset on all failures. */
+               cfi_check_err_status(map, chip, adr);
                map_write(map, CMD(0xF0), chip->start);
                /* FIXME - should have reset delay before continuing */
 
         */
        timeo = jiffies + msecs_to_jiffies(2000);       /* 2s max (un)locking */
        for (;;) {
-               if (chip_ready(map, adr))
+               if (chip_ready(map, chip, adr))
                        break;
 
                if (time_after(jiffies, timeo)) {