18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright (C) 1995-1998  Linus Torvalds & author (see below)
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/*
78c2ecf20Sopenharmony_ci *  Principal Author:  mlord@pobox.com (Mark Lord)
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *  See linux/MAINTAINERS for address of current maintainer.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *  This file provides support for disabling the buggy read-ahead
128c2ecf20Sopenharmony_ci *  mode of the RZ1000 IDE chipset, commonly used on Intel motherboards.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *  Dunno if this fixes both ports, or only the primary port (?).
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci#include <linux/module.h>
198c2ecf20Sopenharmony_ci#include <linux/kernel.h>
208c2ecf20Sopenharmony_ci#include <linux/pci.h>
218c2ecf20Sopenharmony_ci#include <linux/ide.h>
228c2ecf20Sopenharmony_ci#include <linux/init.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define DRV_NAME "rz1000"
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic int rz1000_disable_readahead(struct pci_dev *dev)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	u16 reg;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	if (!pci_read_config_word (dev, 0x40, &reg) &&
318c2ecf20Sopenharmony_ci	    !pci_write_config_word(dev, 0x40, reg & 0xdfff)) {
328c2ecf20Sopenharmony_ci		printk(KERN_INFO "%s: disabled chipset read-ahead "
338c2ecf20Sopenharmony_ci			"(buggy RZ1000/RZ1001)\n", pci_name(dev));
348c2ecf20Sopenharmony_ci		return 0;
358c2ecf20Sopenharmony_ci	} else {
368c2ecf20Sopenharmony_ci		printk(KERN_INFO "%s: serialized, disabled unmasking "
378c2ecf20Sopenharmony_ci			"(buggy RZ1000/RZ1001)\n", pci_name(dev));
388c2ecf20Sopenharmony_ci		return 1;
398c2ecf20Sopenharmony_ci	}
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic const struct ide_port_info rz1000_chipset = {
438c2ecf20Sopenharmony_ci	.name		= DRV_NAME,
448c2ecf20Sopenharmony_ci	.host_flags	= IDE_HFLAG_NO_DMA,
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic int rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	struct ide_port_info d = rz1000_chipset;
508c2ecf20Sopenharmony_ci	int rc;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	rc = pci_enable_device(dev);
538c2ecf20Sopenharmony_ci	if (rc)
548c2ecf20Sopenharmony_ci		return rc;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	if (rz1000_disable_readahead(dev)) {
578c2ecf20Sopenharmony_ci		d.host_flags |= IDE_HFLAG_SERIALIZE;
588c2ecf20Sopenharmony_ci		d.host_flags |= IDE_HFLAG_NO_UNMASK_IRQS;
598c2ecf20Sopenharmony_ci	}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	return ide_pci_init_one(dev, &d, NULL);
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic void rz1000_remove(struct pci_dev *dev)
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci	ide_pci_remove(dev);
678c2ecf20Sopenharmony_ci	pci_disable_device(dev);
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic const struct pci_device_id rz1000_pci_tbl[] = {
718c2ecf20Sopenharmony_ci	{ PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1000), 0 },
728c2ecf20Sopenharmony_ci	{ PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1001), 0 },
738c2ecf20Sopenharmony_ci	{ 0, },
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, rz1000_pci_tbl);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic struct pci_driver rz1000_pci_driver = {
788c2ecf20Sopenharmony_ci	.name		= "RZ1000_IDE",
798c2ecf20Sopenharmony_ci	.id_table	= rz1000_pci_tbl,
808c2ecf20Sopenharmony_ci	.probe		= rz1000_init_one,
818c2ecf20Sopenharmony_ci	.remove		= rz1000_remove,
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic int __init rz1000_ide_init(void)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	return ide_pci_register_driver(&rz1000_pci_driver);
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic void __exit rz1000_ide_exit(void)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	pci_unregister_driver(&rz1000_pci_driver);
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cimodule_init(rz1000_ide_init);
958c2ecf20Sopenharmony_cimodule_exit(rz1000_ide_exit);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciMODULE_AUTHOR("Andre Hedrick");
988c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PCI driver module for RZ1000 IDE");
998c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1008c2ecf20Sopenharmony_ci
101