[RFC] xenon: add SATA support This adds support for the HDD and DVD SATA controller on the xenon southbridge. It also disables ATA_TFLAG_POLLING in libata-core, which prevented the DVD drive from being detected. It needs to be investigated what exactly is wrong here. Signed-off-by: Felix Domke --- drivers/ata/Kconfig | 8 + drivers/ata/Makefile | 1 drivers/ata/libata-core.c | 3 drivers/ata/sata_xenon.c | 290 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/scsi_scan.c | 1 5 files changed, 302 insertions(+), 1 deletion(-) Index: linux-2.6.21/drivers/ata/Kconfig =================================================================== --- linux-2.6.21.orig/drivers/ata/Kconfig 2007-05-01 14:15:13.000000000 +0200 +++ linux-2.6.21/drivers/ata/Kconfig 2007-05-01 14:16:27.000000000 +0200 @@ -126,6 +126,14 @@ enable the PATA_SIS driver in the config. If unsure, say N. +config SATA_XENON + tristate "Xenon SATA support" + depends on PCI + help + This option enables support for Xenon southbridge. + + If unsure, say N. + config SATA_ULI tristate "ULi Electronics SATA support" depends on PCI Index: linux-2.6.21/drivers/ata/Makefile =================================================================== --- linux-2.6.21.orig/drivers/ata/Makefile 2007-05-01 14:15:13.000000000 +0200 +++ linux-2.6.21/drivers/ata/Makefile 2007-05-01 14:16:27.000000000 +0200 @@ -11,6 +11,7 @@ obj-$(CONFIG_SATA_VIA) += sata_via.o obj-$(CONFIG_SATA_VITESSE) += sata_vsc.o obj-$(CONFIG_SATA_SIS) += sata_sis.o +obj-$(CONFIG_SATA_XENON) += sata_xenon.o obj-$(CONFIG_SATA_SX4) += sata_sx4.o obj-$(CONFIG_SATA_NV) += sata_nv.o obj-$(CONFIG_SATA_ULI) += sata_uli.o Index: linux-2.6.21/drivers/ata/sata_xenon.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.21/drivers/ata/sata_xenon.c 2007-05-01 14:16:27.000000000 +0200 @@ -0,0 +1,290 @@ +/* + * sata_xenon.c - SATA support for xenon southbridge + * + * based on sata_sis.c, modifications by Felix Domke + * + * Please ALWAYS copy linux-ide@vger.kernel.org + * on emails. + * + * 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, 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; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + * + * libata documentation is available via 'make {ps|pdf}docs', + * as Documentation/DocBook/libata.* + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRV_NAME "sata_xenon" +#define DRV_VERSION "0.1" + + /* small note: it's completely unknown whether the xenon southbridge sata + is really based on SiS technology. + Most of SATA is standardized anyway. + + + So, we have these two pci devices, one for each port. + + They have two BARs, one for the IDE registers (0..7, + altstatus/devctl is +0xA), and one for the BMDMA. + + SCR seem to be sis-like in pci config space, but that should + be verified! + + Note on the DVD-ROM part: + + The drives usually require some tweaks to be usable under linux. + + You either need to hack the scsi layer, or, in case of the GDR3120L, + set 'modeB' in the bootloader. + */ + +enum { + /* PCI configuration registers */ + SIS_SCR_BASE = 0xc0, /* sata0 phy SCR registers */ +}; + +static int xenon_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); +static u32 xenon_scr_read (struct ata_port *ap, unsigned int sc_reg); +static void xenon_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); +static void xenon_bmdma_error_handler(struct ata_port *ap); + +static const struct pci_device_id xenon_pci_tbl[] = { + { PCI_VDEVICE(MICROSOFT, 0x5803), 0 }, + { PCI_VDEVICE(MICROSOFT, 0x5802), 0 }, + + { } /* terminate list */ +}; + +static struct pci_driver xenon_pci_driver = { + .name = DRV_NAME, + .id_table = xenon_pci_tbl, + .probe = xenon_init_one, + .remove = ata_pci_remove_one, +}; + +static struct scsi_host_template xenon_sht = { + .module = THIS_MODULE, + .name = DRV_NAME, + .ioctl = ata_scsi_ioctl, + .queuecommand = ata_scsi_queuecmd, + .can_queue = ATA_DEF_QUEUE, + .this_id = ATA_SHT_THIS_ID, + .sg_tablesize = ATA_MAX_PRD, + .cmd_per_lun = ATA_SHT_CMD_PER_LUN, + .emulated = ATA_SHT_EMULATED, + .use_clustering = ATA_SHT_USE_CLUSTERING, + .proc_name = DRV_NAME, + .dma_boundary = ATA_DMA_BOUNDARY, + .slave_configure = ata_scsi_slave_config, + .slave_destroy = ata_scsi_slave_destroy, + .bios_param = ata_std_bios_param, +}; + +static const struct ata_port_operations xenon_ops = { + .port_disable = ata_port_disable, + .tf_load = ata_tf_load, + .tf_read = ata_tf_read, + .check_status = ata_check_status, + .exec_command = ata_exec_command, + .dev_select = ata_std_dev_select, + .bmdma_setup = ata_bmdma_setup, + .bmdma_start = ata_bmdma_start, + .bmdma_stop = ata_bmdma_stop, + .bmdma_status = ata_bmdma_status, + .qc_prep = ata_qc_prep, + .qc_issue = ata_qc_issue_prot, + .data_xfer = ata_data_xfer, + .freeze = ata_bmdma_freeze, + .thaw = ata_bmdma_thaw, + .error_handler = xenon_bmdma_error_handler, + .post_internal_cmd = ata_bmdma_post_internal_cmd, + .irq_handler = ata_interrupt, + .irq_clear = ata_bmdma_irq_clear, + .irq_on = ata_irq_on, + .scr_read = xenon_scr_read, + .scr_write = xenon_scr_write, + .port_start = ata_port_start, +}; + +MODULE_DESCRIPTION("low-level driver for Xenon Southbridge SATA controller"); +MODULE_LICENSE("GPL"); +MODULE_DEVICE_TABLE(pci, xenon_pci_tbl); +MODULE_VERSION(DRV_VERSION); + +static unsigned int get_scr_cfg_addr(unsigned int sc_reg) +{ + if ((sc_reg > SCR_CONTROL) || (sc_reg == SCR_ERROR)) /* doesn't exist in PCI cfg space */ + return -1; + + return SIS_SCR_BASE + (4 * sc_reg); +} + +static u32 xenon_scr_read (struct ata_port *ap, unsigned int sc_reg) +{ + struct pci_dev *pdev = to_pci_dev(ap->host->dev); + unsigned int cfg_addr; + u32 val; + + cfg_addr = get_scr_cfg_addr(sc_reg); + + if (cfg_addr == -1) + return 0; /* assume no error */ + + pci_read_config_dword(pdev, cfg_addr, &val); + + return val; +} + +static void xenon_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) +{ + struct pci_dev *pdev = to_pci_dev(ap->host->dev); + unsigned int cfg_addr; + + cfg_addr = get_scr_cfg_addr(sc_reg); + + if (cfg_addr == -1) + return; + + pci_write_config_dword(pdev, cfg_addr, val); +} + +static int xenon_softreset(struct ata_port *ap, unsigned int *classes) +{ + struct pci_dev *pdev = to_pci_dev(ap->host->dev); + /* Host 0 (used for DVD-ROM) has a quirk when used with + an Toshiba/Samsung drive: It can hang after a device reset. + + While the exact reason is unclear (anyone with a SATA port + analyzer?), this workaround will not let the reset happen, and + emulate the detection of an ATAPI device. + + When the workaround is enabled, only ATAPI devices are supported + on host 0, but on this hardware, nothing else is possible anyway. */ + if (pdev->device == 0x5802) + { + classes[0] = ATA_DEV_ATAPI; + classes[1] = ATA_DEV_NONE; + return 0; + } else + return ata_std_softreset(ap, classes); +} + +static void xenon_bmdma_error_handler(struct ata_port *ap) +{ + ata_bmdma_drive_eh(ap, ata_std_prereset, xenon_softreset, sata_std_hardreset, ata_std_postreset); +} + +static int xenon_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) +{ + static int printed_version; + struct ata_probe_ent *probe_ent = NULL; + int rc; + int pci_dev_busy = 0; + + if (!printed_version++) + dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); + + rc = pci_enable_device(pdev); + if (rc) + return rc; + + rc = pci_request_regions(pdev, DRV_NAME); + if (rc) { + pci_dev_busy = 1; + goto err_out; + } + + rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); + if (rc) + goto err_out_regions; + + rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); + if (rc) + goto err_out_regions; + + probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL); + if (!probe_ent) { + rc = -ENOMEM; + goto err_out_kfree; + } + + probe_ent->dev = pci_dev_to_dev(pdev); + INIT_LIST_HEAD(&probe_ent->node); + + probe_ent->irq = pdev->irq; + probe_ent->irq_flags = IRQF_SHARED; + + probe_ent->sht = &xenon_sht, + probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY; + probe_ent->pio_mask = 0x1f; + probe_ent->mwdma_mask = 0x7; + probe_ent->udma_mask = 0x7F; + probe_ent->port_ops = &xenon_ops; + probe_ent->private_data = 0; + + probe_ent->n_ports = 1; + probe_ent->port->cmd_addr = ioremap(pci_resource_start(pdev, 0), PAGE_SIZE); + probe_ent->port->altstatus_addr = probe_ent->port->cmd_addr + 0xa; + probe_ent->port->ctl_addr = probe_ent->port->cmd_addr + 0xa; + probe_ent->port->bmdma_addr = ioremap(pci_resource_start(pdev, 1), PAGE_SIZE); + ata_std_ports(probe_ent->port); + + if (ata_device_add(probe_ent) != 1) + goto err_out_kfree; + + pci_set_master(pdev); + pci_intx(pdev, 1); + + devm_kfree(&pdev->dev, probe_ent); + + return 0; + +err_out_kfree: + devm_kfree(&pdev->dev, probe_ent); + +err_out_regions: + pci_release_regions(pdev); + +err_out: + if (!pci_dev_busy) + pci_disable_device(pdev); + return rc; + +} + +static int __init xenon_init(void) +{ + return pci_register_driver(&xenon_pci_driver); +} + +static void __exit xenon_exit(void) +{ + pci_unregister_driver(&xenon_pci_driver); +} + +module_init(xenon_init); +module_exit(xenon_exit); + Index: linux-2.6.21/drivers/ata/libata-core.c =================================================================== --- linux-2.6.21.orig/drivers/ata/libata-core.c 2007-05-01 14:15:13.000000000 +0200 +++ linux-2.6.21/drivers/ata/libata-core.c 2007-05-01 14:16:27.000000000 +0200 @@ -1464,7 +1465,7 @@ /* Device presence detection is unreliable on some * controllers. Always poll IDENTIFY if available. */ - tf.flags |= ATA_TFLAG_POLLING; +// tf.flags |= ATA_TFLAG_POLLING; err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, id, sizeof(id[0]) * ATA_ID_WORDS); Index: linux-2.6.21/drivers/scsi/scsi_scan.c =================================================================== --- linux-2.6.21.orig/drivers/scsi/scsi_scan.c 2007-05-01 14:16:38.000000000 +0200 +++ linux-2.6.21/drivers/scsi/scsi_scan.c 2007-05-01 14:16:47.000000000 +0200 @@ -557,6 +557,7 @@ memset(scsi_cmd, 0, 6); scsi_cmd[0] = INQUIRY; scsi_cmd[4] = (unsigned char) try_inquiry_len; + scsi_cmd[5] = 0xc0; /* HACK */ memset(inq_result, 0, try_inquiry_len);