From: Simon Glass Date: Sat, 29 Jul 2017 17:35:25 +0000 (-0600) Subject: dm: imx: cm_fx6: Support driver model for SATA X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=8d331e38e056542399f8453141b42eb725edae37;p=u-boot.git dm: imx: cm_fx6: Support driver model for SATA Add support for using driver model for SATA with the cm_fx6 board. The old code remains for now to permit testing. Signed-off-by: Simon Glass --- diff --git a/board/compulab/cm_fx6/cm_fx6.c b/board/compulab/cm_fx6/cm_fx6.c index c59884a8c3..ecefe394f1 100644 --- a/board/compulab/cm_fx6/cm_fx6.c +++ b/board/compulab/cm_fx6/cm_fx6.c @@ -9,7 +9,9 @@ */ #include +#include #include +#include #include #include #include @@ -29,6 +31,7 @@ #include #include #include +#include #include #include "common.h" #include "../common/eeprom.h" @@ -206,6 +209,8 @@ static int cm_fx6_setup_issd(void) } #define CM_FX6_SATA_INIT_RETRIES 10 + +# if !CONFIG_IS_ENABLED(AHCI) int sata_initialize(void) { int err, i; @@ -246,6 +251,7 @@ int sata_stop(void) return 0; } +# endif #else static int cm_fx6_setup_issd(void) { return 0; } #endif @@ -757,3 +763,66 @@ U_BOOT_DEVICE(cm_fx6_serial) = { .name = "serial_mxc", .platdata = &cm_fx6_mxc_serial_plat, }; + +#if CONFIG_IS_ENABLED(AHCI) +static int sata_imx_probe(struct udevice *dev) +{ + int i, err; + + /* Make sure this gpio has logical 0 value */ + gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0); + udelay(100); + cm_fx6_sata_power(1); + + for (i = 0; i < CM_FX6_SATA_INIT_RETRIES; i++) { + err = setup_sata(); + if (err) { + printf("SATA setup failed: %d\n", err); + return err; + } + + udelay(100); + + err = dwc_ahsata_probe(dev); + if (!err) + break; + + /* There is no device on the SATA port */ + if (sata_dm_port_status(0, 0) == 0) + break; + + /* There's a device, but link not established. Retry */ + device_remove(dev, DM_REMOVE_NORMAL); + } + + return 0; +} + +static int sata_imx_remove(struct udevice *dev) +{ + cm_fx6_sata_power(0); + mdelay(250); + + return 0; +} + +struct ahci_ops sata_imx_ops = { + .port_status = dwc_ahsata_port_status, + .reset = dwc_ahsata_bus_reset, + .scan = dwc_ahsata_scan, +}; + +static const struct udevice_id sata_imx_ids[] = { + { .compatible = "fsl,imx6q-ahci" }, + { } +}; + +U_BOOT_DRIVER(sata_imx) = { + .name = "dwc_ahci", + .id = UCLASS_AHCI, + .of_match = sata_imx_ids, + .ops = &sata_imx_ops, + .probe = sata_imx_probe, + .remove = sata_imx_remove, /* reset bus to stop it */ +}; +#endif /* AHCI */