Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf2af2a2 authored by Bastiaan Jacques's avatar Bastiaan Jacques Committed by Jeff Garzik
Browse files

[PATCH] ahci: add support for VIA VT8251



Adds AHCI support for the VIA VT8251.

Includes a workaround for a hardware bug which requires a Command List
Override before softreset.

Signed-off-by: default avatarBastiaan Jacques <b.jacques@planet.nl>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent 857c68f7
Loading
Loading
Loading
Loading
+49 −15
Original line number Original line Diff line number Diff line
@@ -73,6 +73,7 @@ enum {
	RX_FIS_D2H_REG		= 0x40,	/* offset of D2H Register FIS data */
	RX_FIS_D2H_REG		= 0x40,	/* offset of D2H Register FIS data */


	board_ahci		= 0,
	board_ahci		= 0,
	board_ahci_vt8251	= 1,


	/* global controller registers */
	/* global controller registers */
	HOST_CAP		= 0x00, /* host capabilities */
	HOST_CAP		= 0x00, /* host capabilities */
@@ -153,6 +154,9 @@ enum {


	/* hpriv->flags bits */
	/* hpriv->flags bits */
	AHCI_FLAG_MSI		= (1 << 0),
	AHCI_FLAG_MSI		= (1 << 0),

	/* ap->flags bits */
	AHCI_FLAG_RESET_NEEDS_CLO	= (1 << 24),
};
};


struct ahci_cmd_hdr {
struct ahci_cmd_hdr {
@@ -255,6 +259,16 @@ static const struct ata_port_info ahci_port_info[] = {
		.udma_mask	= 0x7f, /* udma0-6 ; FIXME */
		.udma_mask	= 0x7f, /* udma0-6 ; FIXME */
		.port_ops	= &ahci_ops,
		.port_ops	= &ahci_ops,
	},
	},
	/* board_ahci_vt8251 */
	{
		.sht		= &ahci_sht,
		.host_flags	= ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
				  ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
				  AHCI_FLAG_RESET_NEEDS_CLO,
		.pio_mask	= 0x1f, /* pio0-4 */
		.udma_mask	= 0x7f, /* udma0-6 ; FIXME */
		.port_ops	= &ahci_ops,
	},
};
};


static const struct pci_device_id ahci_pci_tbl[] = {
static const struct pci_device_id ahci_pci_tbl[] = {
@@ -296,6 +310,8 @@ static const struct pci_device_id ahci_pci_tbl[] = {
	  board_ahci }, /* ATI SB600 non-raid */
	  board_ahci }, /* ATI SB600 non-raid */
	{ PCI_VENDOR_ID_ATI, 0x4381, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
	{ PCI_VENDOR_ID_ATI, 0x4381, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
	  board_ahci }, /* ATI SB600 raid */
	  board_ahci }, /* ATI SB600 raid */
	{ PCI_VENDOR_ID_VIA, 0x3349, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
	  board_ahci_vt8251 }, /* VIA VT8251 */
	{ }	/* terminate list */
	{ }	/* terminate list */
};
};


@@ -516,9 +532,29 @@ static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, u32 opts)
	pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16);
	pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16);
}
}


static int ahci_softreset(struct ata_port *ap, unsigned int *class)
static int ahci_clo(struct ata_port *ap)
{
{
	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
	struct ahci_host_priv *hpriv = ap->host_set->private_data;
	struct ahci_host_priv *hpriv = ap->host_set->private_data;
	u32 tmp;

	if (!(hpriv->cap & HOST_CAP_CLO))
		return -EOPNOTSUPP;

	tmp = readl(port_mmio + PORT_CMD);
	tmp |= PORT_CMD_CLO;
	writel(tmp, port_mmio + PORT_CMD);

	tmp = ata_wait_register(port_mmio + PORT_CMD,
				PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
	if (tmp & PORT_CMD_CLO)
		return -EIO;

	return 0;
}

static int ahci_softreset(struct ata_port *ap, unsigned int *class)
{
	struct ahci_port_priv *pp = ap->private_data;
	struct ahci_port_priv *pp = ap->private_data;
	void __iomem *mmio = ap->host_set->mmio_base;
	void __iomem *mmio = ap->host_set->mmio_base;
	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
@@ -547,21 +583,13 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
	/* check BUSY/DRQ, perform Command List Override if necessary */
	/* check BUSY/DRQ, perform Command List Override if necessary */
	ahci_tf_read(ap, &tf);
	ahci_tf_read(ap, &tf);
	if (tf.command & (ATA_BUSY | ATA_DRQ)) {
	if (tf.command & (ATA_BUSY | ATA_DRQ)) {
		if (!(hpriv->cap & HOST_CAP_CLO)) {
		rc = ahci_clo(ap);
			rc = -EIO;
			reason = "port busy but no CLO";
			goto fail_restart;
		}


		tmp = readl(port_mmio + PORT_CMD);
		if (rc == -EOPNOTSUPP) {
		tmp |= PORT_CMD_CLO;
			reason = "port busy but CLO unavailable";
		writel(tmp, port_mmio + PORT_CMD);
			goto fail_restart;

		} else if (rc) {
		tmp = ata_wait_register(port_mmio + PORT_CMD,
			reason = "port busy but CLO failed";
					PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
		if (tmp & PORT_CMD_CLO) {
			rc = -EIO;
			reason = "CLO failed";
			goto fail_restart;
			goto fail_restart;
		}
		}
	}
	}
@@ -672,6 +700,12 @@ static void ahci_postreset(struct ata_port *ap, unsigned int *class)


static int ahci_probe_reset(struct ata_port *ap, unsigned int *classes)
static int ahci_probe_reset(struct ata_port *ap, unsigned int *classes)
{
{
	if ((ap->flags & AHCI_FLAG_RESET_NEEDS_CLO) &&
	    (ata_busy_wait(ap, ATA_BUSY, 1000) & ATA_BUSY)) {
		/* ATA_BUSY hasn't cleared, so send a CLO */
		ahci_clo(ap);
	}

	return ata_drive_probe_reset(ap, ata_std_probeinit,
	return ata_drive_probe_reset(ap, ata_std_probeinit,
				     ahci_softreset, ahci_hardreset,
				     ahci_softreset, ahci_hardreset,
				     ahci_postreset, classes);
				     ahci_postreset, classes);