X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=drivers%2Fblock%2Ffsl_sata.c;h=ebd626178d098ce2beb4a00221997dc585feb10a;hb=1f2979b99ea4206881f280fe3ed12bc67c36ece7;hp=7436c4d08bc3617fae65a638afe039733534c82b;hpb=fd0b1fe3c388a77e8fe00cdd930ca317a91198d4;p=karo-tx-uboot.git diff --git a/drivers/block/fsl_sata.c b/drivers/block/fsl_sata.c index 7436c4d08b..ebd626178d 100644 --- a/drivers/block/fsl_sata.c +++ b/drivers/block/fsl_sata.c @@ -1,60 +1,41 @@ /* - * Copyright (C) 2008 Freescale Semiconductor, Inc. + * Copyright (C) 2008,2010 Freescale Semiconductor, Inc. * Dave Liu * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ #include #include #include +#include +#include #include #include #include +#include #include "fsl_sata.h" -extern block_dev_desc_t sata_dev_desc[CFG_SATA_MAX_DEVICE]; - -#ifndef CFG_SATA1_FLAGS - #define CFG_SATA1_FLAGS FLAGS_DMA +#ifndef CONFIG_SYS_SATA1_FLAGS + #define CONFIG_SYS_SATA1_FLAGS FLAGS_DMA #endif -#ifndef CFG_SATA2_FLAGS - #define CFG_SATA2_FLAGS FLAGS_DMA +#ifndef CONFIG_SYS_SATA2_FLAGS + #define CONFIG_SYS_SATA2_FLAGS FLAGS_DMA #endif static struct fsl_sata_info fsl_sata_info[] = { #ifdef CONFIG_SATA1 - {CFG_SATA1, CFG_SATA1_FLAGS}, + {CONFIG_SYS_SATA1, CONFIG_SYS_SATA1_FLAGS}, #else {0, 0}, #endif #ifdef CONFIG_SATA2 - {CFG_SATA2, CFG_SATA2_FLAGS}, + {CONFIG_SYS_SATA2, CONFIG_SYS_SATA2_FLAGS}, #else {0, 0}, #endif }; -static inline void mdelay(unsigned long msec) -{ - unsigned long i; - for (i = 0; i < msec; i++) - udelay(1000); -} - static inline void sdelay(unsigned long sec) { unsigned long i; @@ -62,26 +43,7 @@ static inline void sdelay(unsigned long sec) mdelay(1000); } -void dprint_buffer(unsigned char *buf, int len) -{ - int i, j; - - i = 0; - j = 0; - printf("\n\r"); - - for (i = 0; i < len; i++) { - printf("%02x ", *buf++); - j++; - if (j == 16) { - printf("\n\r"); - j = 0; - } - } - printf("\n\r"); -} - -static void fsl_sata_dump_sfis(struct sfis *s) +static void fsl_sata_dump_sfis(struct sata_fis_d2h *s) { printf("Status FIS dump:\n\r"); printf("fis_type: %02x\n\r", s->fis_type); @@ -100,7 +62,7 @@ static void fsl_sata_dump_sfis(struct sfis *s) printf("sector_count_exp: %02x\n\r", s->sector_count_exp); } -static int ata_wait_register(volatile unsigned *addr, u32 mask, +static int ata_wait_register(unsigned __iomem *addr, u32 mask, u32 val, u32 timeout_msec) { int i; @@ -118,16 +80,27 @@ int init_sata(int dev) cmd_hdr_tbl_t *cmd_hdr; u32 cda; u32 val32; - fsl_sata_reg_t *reg; + fsl_sata_reg_t __iomem *reg; u32 sig; int i; fsl_sata_t *sata; - if (dev < 0 || dev > (CFG_SATA_MAX_DEVICE - 1)) { + if (dev < 0 || dev > (CONFIG_SYS_SATA_MAX_DEVICE - 1)) { printf("the sata index %d is out of ranges\n\r", dev); return -1; } +#ifdef CONFIG_MPC85xx + if ((dev == 0) && (!is_serdes_configured(SATA1))) { + printf("SATA%d [dev = %d] is not enabled\n", dev+1, dev); + return -1; + } + if ((dev == 1) && (!is_serdes_configured(SATA2))) { + printf("SATA%d [dev = %d] is not enabled\n", dev+1, dev); + return -1; + } +#endif + /* Allocate SATA device driver struct */ sata = (fsl_sata_t *)malloc(sizeof(fsl_sata_t)); if (!sata) { @@ -248,6 +221,10 @@ int init_sata(int dev) else printf(" %s ", sata->name); + /* Wait PHY RDY signal changed for 500ms */ + ata_wait_register(®->hstatus, HSTATUS_PHY_RDY, + HSTATUS_PHY_RDY, 500); + /* Check PHYRDY */ val32 = in_le32(®->hstatus); if (val32 & HSTATUS_PHY_RDY) { @@ -258,6 +235,10 @@ int init_sata(int dev) return -1; } + /* Wait for signature updated, which is 1st D2H */ + ata_wait_register(®->hstatus, HSTATUS_SIGNATURE, + HSTATUS_SIGNATURE, 10000); + if (val32 & HSTATUS_SIGNATURE) { sig = in_le32(®->sig); debug("Signature updated, the sig =%08x\n\r", sig); @@ -274,42 +255,7 @@ int init_sata(int dev) return 0; } -/* Hardware reset, like Power-on and COMRESET */ -void fsl_sata_hardware_reset(u32 reg_base) -{ - fsl_sata_reg_t *reg = (fsl_sata_reg_t *)reg_base; - u32 scontrol; - - /* Disable the SATA interface and put PHY offline */ - scontrol = in_le32(®->scontrol); - scontrol = (scontrol & 0x0f0) | 0x304; - out_le32(®->scontrol, scontrol); - - /* No speed strict */ - scontrol = in_le32(®->scontrol); - scontrol = scontrol & ~0x0f0; - out_le32(®->scontrol, scontrol); - - /* Issue PHY wake/reset, Hardware_reset_asserted */ - scontrol = in_le32(®->scontrol); - scontrol = (scontrol & 0x0f0) | 0x301; - out_le32(®->scontrol, scontrol); - - mdelay(100); - - /* Resume PHY, COMRESET negated, the device initialize hardware - * and execute diagnostics, send good status-signature to host, - * which is D2H register FIS, and then the device enter idle state. - */ - scontrol = in_le32(®->scontrol); - scontrol = (scontrol & 0x0f0) | 0x300; - out_le32(®->scontrol, scontrol); - - mdelay(100); - return; -} - -static void fsl_sata_dump_regs(fsl_sata_reg_t *reg) +static void fsl_sata_dump_regs(fsl_sata_reg_t __iomem *reg) { printf("\n\rSATA: %08x\n\r", (u32)reg); printf("CQR: %08x\n\r", in_le32(®->cqr)); @@ -339,7 +285,7 @@ static void fsl_sata_dump_regs(fsl_sata_reg_t *reg) printf("SYSPR: %08x\n\r", in_be32(®->syspr)); } -static int fsl_ata_exec_ata_cmd(struct fsl_sata *sata, struct cfis *cfis, +static int fsl_ata_exec_ata_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis, int is_ncq, int tag, u8 *buffer, u32 len) { cmd_hdr_entry_t *cmd_hdr; @@ -350,7 +296,7 @@ static int fsl_ata_exec_ata_cmd(struct fsl_sata *sata, struct cfis *cfis, u32 prde_count; u32 val32; u32 ttl; - fsl_sata_reg_t *reg = sata->reg_base; + fsl_sata_reg_t __iomem *reg = sata->reg_base; int i; /* Check xfer length */ @@ -475,7 +421,7 @@ static int fsl_ata_exec_ata_cmd(struct fsl_sata *sata, struct cfis *cfis, if (val32) { u32 der; - fsl_sata_dump_sfis((struct sfis *)cmd_desc->sfis); + fsl_sata_dump_sfis((struct sata_fis_d2h *)cmd_desc->sfis); printf("CE at device\n\r"); fsl_sata_dump_regs(reg); der = in_le32(®->der); @@ -490,19 +436,19 @@ static int fsl_ata_exec_ata_cmd(struct fsl_sata *sata, struct cfis *cfis, return len; } -static int fsl_ata_exec_reset_cmd(struct fsl_sata *sata, struct cfis *cfis, +static int fsl_ata_exec_reset_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis, int tag, u8 *buffer, u32 len) { return 0; } -static int fsl_sata_exec_cmd(struct fsl_sata *sata, struct cfis *cfis, +static int fsl_sata_exec_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis, enum cmd_type command_type, int tag, u8 *buffer, u32 len) { int rc; if (tag > SATA_HC_MAX_CMD || tag < 0) { - printf("tag is out of range, tag=\n\r", tag); + printf("tag is out of range, tag=%d\n\r", tag); return -1; } @@ -531,11 +477,9 @@ static int fsl_sata_exec_cmd(struct fsl_sata *sata, struct cfis *cfis, static void fsl_sata_identify(int dev, u16 *id) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - struct sata_fis_h2d h2d; - struct cfis *cfis; + struct sata_fis_h2d h2d, *cfis = &h2d; - cfis = (struct cfis *)&h2d; - memset((void *)cfis, 0, sizeof(struct cfis)); + memset(cfis, 0, sizeof(struct sata_fis_h2d)); cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; cfis->pm_port_c = 0x80; /* is command */ @@ -558,12 +502,10 @@ static void fsl_sata_xfer_mode(int dev, u16 *id) static void fsl_sata_set_features(int dev) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - struct sata_fis_h2d h2d; - struct cfis *cfis; + struct sata_fis_h2d h2d, *cfis = &h2d; u8 udma_cap; - cfis = (struct cfis *)&h2d; - memset((void *)cfis, 0, sizeof(struct cfis)); + memset(cfis, 0, sizeof(struct sata_fis_h2d)); cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; cfis->pm_port_c = 0x80; /* is command */ @@ -589,18 +531,16 @@ static void fsl_sata_set_features(int dev) static u32 fsl_sata_rw_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - struct sata_fis_h2d h2d; - struct cfis *cfis; + struct sata_fis_h2d h2d, *cfis = &h2d; u32 block; block = start; - cfis = (struct cfis *)&h2d; - memset((void *)cfis, 0, sizeof(struct cfis)); + memset(cfis, 0, sizeof(struct sata_fis_h2d)); cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; cfis->pm_port_c = 0x80; /* is command */ - cfis->command = (is_write) ? ATA_CMD_WRITE_DMA : ATA_CMD_READ_DMA; + cfis->command = (is_write) ? ATA_CMD_WRITE : ATA_CMD_READ; cfis->device = ATA_LBA; cfis->device |= (block >> 24) & 0xf; @@ -613,19 +553,16 @@ static u32 fsl_sata_rw_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_wr return blkcnt; } -void fsl_sata_flush_cache(int dev) +static void fsl_sata_flush_cache(int dev) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - struct sata_fis_h2d h2d; - struct cfis *cfis; - - cfis = (struct cfis *)&h2d; + struct sata_fis_h2d h2d, *cfis = &h2d; - memset((void *)cfis, 0, sizeof(struct cfis)); + memset(cfis, 0, sizeof(struct sata_fis_h2d)); cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; cfis->pm_port_c = 0x80; /* is command */ - cfis->command = ATA_CMD_FLUSH_CACHE; + cfis->command = ATA_CMD_FLUSH; fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0); } @@ -633,20 +570,18 @@ void fsl_sata_flush_cache(int dev) static u32 fsl_sata_rw_cmd_ext(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - struct sata_fis_h2d h2d; - struct cfis *cfis; + struct sata_fis_h2d h2d, *cfis = &h2d; u64 block; block = (u64)start; - cfis = (struct cfis *)&h2d; - memset((void *)cfis, 0, sizeof(struct cfis)); + memset(cfis, 0, sizeof(struct sata_fis_h2d)); cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; cfis->pm_port_c = 0x80; /* is command */ - cfis->command = (is_write) ? ATA_CMD_WRITE_DMA_EXT - : ATA_CMD_READ_DMA_EXT; + cfis->command = (is_write) ? ATA_CMD_WRITE_EXT + : ATA_CMD_READ_EXT; cfis->lba_high_exp = (block >> 40) & 0xff; cfis->lba_mid_exp = (block >> 32) & 0xff; @@ -662,29 +597,28 @@ static u32 fsl_sata_rw_cmd_ext(int dev, u32 start, u32 blkcnt, u8 *buffer, int i return blkcnt; } -u32 fsl_sata_rw_ncq_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write) +static u32 fsl_sata_rw_ncq_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, + int is_write) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - struct sata_fis_h2d h2d; - struct cfis *cfis; + struct sata_fis_h2d h2d, *cfis = &h2d; int ncq_channel; u64 block; - if (sata_dev_desc[dev].lba48 != 1) { + if (sata->lba48 != 1) { printf("execute FPDMA command on non-LBA48 hard disk\n\r"); return -1; } block = (u64)start; - cfis = (struct cfis *)&h2d; - memset((void *)cfis, 0, sizeof(struct cfis)); + memset(cfis, 0, sizeof(struct sata_fis_h2d)); cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; cfis->pm_port_c = 0x80; /* is command */ - cfis->command = (is_write) ? ATA_CMD_WRITE_FPDMA_QUEUED - : ATA_CMD_READ_FPDMA_QUEUED; + cfis->command = (is_write) ? ATA_CMD_FPDMA_WRITE + : ATA_CMD_FPDMA_READ; cfis->lba_high_exp = (block >> 40) & 0xff; cfis->lba_mid_exp = (block >> 32) & 0xff; @@ -707,29 +641,20 @@ u32 fsl_sata_rw_ncq_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write return blkcnt; } -void fsl_sata_flush_cache_ext(int dev) +static void fsl_sata_flush_cache_ext(int dev) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - struct sata_fis_h2d h2d; - struct cfis *cfis; - - cfis = (struct cfis *)&h2d; + struct sata_fis_h2d h2d, *cfis = &h2d; - memset((void *)cfis, 0, sizeof(struct cfis)); + memset(cfis, 0, sizeof(struct sata_fis_h2d)); cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; cfis->pm_port_c = 0x80; /* is command */ - cfis->command = ATA_CMD_FLUSH_CACHE_EXT; + cfis->command = ATA_CMD_FLUSH_EXT; fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0); } -/* Software reset, set SRST of the Device Control register */ -void fsl_sata_software_reset(int dev) -{ - return; -} - static void fsl_sata_init_wcache(int dev, u16 *id) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; @@ -760,7 +685,8 @@ static int fsl_sata_get_flush_ext(int dev) return sata->flush_ext; } -u32 ata_low_level_rw_lba48(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_write) +static u32 ata_low_level_rw_lba48(int dev, u32 blknr, lbaint_t blkcnt, + const void *buffer, int is_write) { u32 start, blks; u8 *addr; @@ -794,7 +720,8 @@ u32 ata_low_level_rw_lba48(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_ return blkcnt; } -u32 ata_low_level_rw_lba28(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_write) +static u32 ata_low_level_rw_lba28(int dev, u32 blknr, u32 blkcnt, + const void *buffer, int is_write) { u32 start, blks; u8 *addr; @@ -825,22 +752,24 @@ u32 ata_low_level_rw_lba28(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_ /* * SATA interface between low level driver and command layer */ -ulong sata_read(int dev, u32 blknr, u32 blkcnt, void *buffer) +ulong sata_read(int dev, ulong blknr, lbaint_t blkcnt, void *buffer) { u32 rc; + fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - if (sata_dev_desc[dev].lba48) + if (sata->lba48) rc = ata_low_level_rw_lba48(dev, blknr, blkcnt, buffer, READ_CMD); else rc = ata_low_level_rw_lba28(dev, blknr, blkcnt, buffer, READ_CMD); return rc; } -ulong sata_write(int dev, u32 blknr, u32 blkcnt, void *buffer) +ulong sata_write(int dev, ulong blknr, lbaint_t blkcnt, const void *buffer) { u32 rc; + fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; - if (sata_dev_desc[dev].lba48) { + if (sata->lba48) { rc = ata_low_level_rw_lba48(dev, blknr, blkcnt, buffer, WRITE_CMD); if (fsl_sata_get_wcache(dev) && fsl_sata_get_flush_ext(dev)) fsl_sata_flush_cache_ext(dev); @@ -890,11 +819,14 @@ int scan_sata(int dev) n_sectors = ata_id_n_sectors(id); sata_dev_desc[dev].lba = (u32)n_sectors; +#ifdef CONFIG_LBA48 /* Check if support LBA48 */ if (ata_id_has_lba48(id)) { - sata_dev_desc[dev].lba48 = 1; + sata->lba48 = 1; debug("Device support LBA48\n\r"); - } + } else + debug("Device supports LBA28\n\r"); +#endif /* Get the NCQ queue depth from device */ sata->queue_depth = ata_id_queue_depth(id);