Commit 68e6f221ed08674374dc397fe52a64817599fce7

Authored by Bin Meng
Committed by Tom Rini
1 parent eb81b1a4d3

block: ide: Fix block read/write with driver model

This converts the IDE driver to driver model so that block read and
write are fully functional.

Fixes: b7c6baef ("x86: Convert MMC to driver model")
Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Showing 3 changed files with 75 additions and 1 deletions Side-by-side Diff

drivers/block/blk-uclass.c
... ... @@ -26,7 +26,7 @@
26 26 };
27 27  
28 28 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
29   - [IF_TYPE_IDE] = UCLASS_INVALID,
  29 + [IF_TYPE_IDE] = UCLASS_IDE,
30 30 [IF_TYPE_SCSI] = UCLASS_SCSI,
31 31 [IF_TYPE_ATAPI] = UCLASS_INVALID,
32 32 [IF_TYPE_USB] = UCLASS_MASS_STORAGE,
... ... @@ -827,12 +827,20 @@
827 827 ide_ident(&ide_dev_desc[i]);
828 828 dev_print(&ide_dev_desc[i]);
829 829  
  830 +#ifndef CONFIG_BLK
830 831 if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) {
831 832 /* initialize partition type */
832 833 part_init(&ide_dev_desc[i]);
833 834 }
  835 +#endif
834 836 }
835 837 WATCHDOG_RESET();
  838 +
  839 +#ifdef CONFIG_BLK
  840 + struct udevice *dev;
  841 +
  842 + uclass_first_device(UCLASS_IDE, &dev);
  843 +#endif
836 844 }
837 845  
838 846 /* We only need to swap data if we are running on a big endian cpu. */
... ... @@ -1147,6 +1155,26 @@
1147 1155 #endif
1148 1156  
1149 1157 #ifdef CONFIG_BLK
  1158 +static int ide_blk_probe(struct udevice *udev)
  1159 +{
  1160 + struct blk_desc *desc = dev_get_uclass_platdata(udev);
  1161 +
  1162 + /* fill in device vendor/product/rev strings */
  1163 + strncpy(desc->vendor, ide_dev_desc[desc->devnum].vendor,
  1164 + BLK_VEN_SIZE);
  1165 + desc->vendor[BLK_VEN_SIZE] = '\0';
  1166 + strncpy(desc->product, ide_dev_desc[desc->devnum].product,
  1167 + BLK_PRD_SIZE);
  1168 + desc->product[BLK_PRD_SIZE] = '\0';
  1169 + strncpy(desc->revision, ide_dev_desc[desc->devnum].revision,
  1170 + BLK_REV_SIZE);
  1171 + desc->revision[BLK_REV_SIZE] = '\0';
  1172 +
  1173 + part_init(desc);
  1174 +
  1175 + return 0;
  1176 +}
  1177 +
1150 1178 static const struct blk_ops ide_blk_ops = {
1151 1179 .read = ide_read,
1152 1180 .write = ide_write,
... ... @@ -1156,6 +1184,51 @@
1156 1184 .name = "ide_blk",
1157 1185 .id = UCLASS_BLK,
1158 1186 .ops = &ide_blk_ops,
  1187 + .probe = ide_blk_probe,
  1188 +};
  1189 +
  1190 +static int ide_probe(struct udevice *udev)
  1191 +{
  1192 + struct udevice *blk_dev;
  1193 + char name[20];
  1194 + int blksz;
  1195 + lbaint_t size;
  1196 + int i;
  1197 + int ret;
  1198 +
  1199 + for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
  1200 + if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) {
  1201 + sprintf(name, "blk#%d", i);
  1202 +
  1203 + blksz = ide_dev_desc[i].blksz;
  1204 + size = blksz * ide_dev_desc[i].lba;
  1205 + ret = blk_create_devicef(udev, "ide_blk", name,
  1206 + IF_TYPE_IDE, i,
  1207 + blksz, size, &blk_dev);
  1208 + if (ret)
  1209 + return ret;
  1210 + }
  1211 + }
  1212 +
  1213 + return 0;
  1214 +}
  1215 +
  1216 +U_BOOT_DRIVER(ide) = {
  1217 + .name = "ide",
  1218 + .id = UCLASS_IDE,
  1219 + .probe = ide_probe,
  1220 +};
  1221 +
  1222 +struct pci_device_id ide_supported[] = {
  1223 + { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xffff00) },
  1224 + { }
  1225 +};
  1226 +
  1227 +U_BOOT_PCI_DEVICE(ide, ide_supported);
  1228 +
  1229 +UCLASS_DRIVER(ide) = {
  1230 + .name = "ide",
  1231 + .id = UCLASS_IDE,
1159 1232 };
1160 1233 #else
1161 1234 U_BOOT_LEGACY_BLK(ide) = {
include/dm/uclass-id.h
... ... @@ -41,6 +41,7 @@
41 41 UCLASS_I2C_EEPROM, /* I2C EEPROM device */
42 42 UCLASS_I2C_GENERIC, /* Generic I2C device */
43 43 UCLASS_I2C_MUX, /* I2C multiplexer */
  44 + UCLASS_IDE, /* IDE device */
44 45 UCLASS_IRQ, /* Interrupt controller */
45 46 UCLASS_KEYBOARD, /* Keyboard input device */
46 47 UCLASS_LED, /* Light-emitting diode (LED) */