2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1998-2000 Michel Aubry, Maintainer
|
|
|
|
* Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer
|
|
|
|
* Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998-2000 Andre Hedrick (andre@linux-ide.org)
|
|
|
|
* May be copied or modified under the terms of the GNU General Public License
|
2008-11-02 23:40:08 +03:00
|
|
|
* Copyright (C) 2002 Alan Cox
|
2005-04-17 02:20:36 +04:00
|
|
|
* ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw>
|
2007-03-03 19:48:52 +03:00
|
|
|
* Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
|
2010-01-18 10:17:37 +03:00
|
|
|
* Copyright (C) 2007-2010 Bartlomiej Zolnierkiewicz
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* (U)DMA capable version of ali 1533/1543(C), 1535(D)
|
|
|
|
*
|
|
|
|
**********************************************************************
|
|
|
|
* 9/7/99 --Parts from the above author are included and need to be
|
|
|
|
* converted into standard interface, once I finish the thought.
|
|
|
|
*
|
|
|
|
* Recent changes
|
|
|
|
* Don't use LBA48 mode on ALi <= 0xC4
|
|
|
|
* Don't poke 0x79 with a non ALi northbridge
|
|
|
|
* Don't flip undefined bits on newer chipsets (fix Fujitsu laptop hang)
|
|
|
|
* Allow UDMA6 on revisions > 0xC4
|
|
|
|
*
|
|
|
|
* Documentation
|
|
|
|
* Chipset documentation available under NDA only
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/ide.h>
|
|
|
|
#include <linux/init.h>
|
2007-07-10 01:17:58 +04:00
|
|
|
#include <linux/dmi.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
2008-07-25 00:53:32 +04:00
|
|
|
#define DRV_NAME "alim15x3"
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* ALi devices are not plug in. Otherwise these static values would
|
|
|
|
* need to go. They ought to go away anyway
|
|
|
|
*/
|
|
|
|
|
|
|
|
static u8 m5229_revision;
|
|
|
|
static u8 chip_is_1543c_e;
|
|
|
|
static struct pci_dev *isa_dev;
|
|
|
|
|
2010-01-18 10:17:50 +03:00
|
|
|
static void ali_fifo_control(ide_hwif_t *hwif, ide_drive_t *drive, int on)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(hwif->dev);
|
|
|
|
int pio_fifo = 0x54 + hwif->channel;
|
|
|
|
u8 fifo;
|
|
|
|
int shift = 4 * (drive->dn & 1);
|
|
|
|
|
|
|
|
pci_read_config_byte(pdev, pio_fifo, &fifo);
|
|
|
|
fifo &= ~(0x0F << shift);
|
|
|
|
fifo |= (on << shift);
|
|
|
|
pci_write_config_byte(pdev, pio_fifo, fifo);
|
|
|
|
}
|
|
|
|
|
2010-01-18 10:21:19 +03:00
|
|
|
static void ali_program_timings(ide_hwif_t *hwif, ide_drive_t *drive,
|
2010-01-18 10:21:26 +03:00
|
|
|
struct ide_timing *t, u8 ultra)
|
2010-01-18 10:21:19 +03:00
|
|
|
{
|
|
|
|
struct pci_dev *dev = to_pci_dev(hwif->dev);
|
|
|
|
int port = hwif->channel ? 0x5c : 0x58;
|
2010-01-18 10:21:26 +03:00
|
|
|
int udmat = 0x56 + hwif->channel;
|
|
|
|
u8 unit = drive->dn & 1, udma;
|
|
|
|
int shift = 4 * unit;
|
|
|
|
|
|
|
|
/* Set up the UDMA */
|
|
|
|
pci_read_config_byte(dev, udmat, &udma);
|
|
|
|
udma &= ~(0x0F << shift);
|
|
|
|
udma |= ultra << shift;
|
|
|
|
pci_write_config_byte(dev, udmat, udma);
|
|
|
|
|
|
|
|
if (t == NULL)
|
|
|
|
return;
|
2010-01-18 10:21:19 +03:00
|
|
|
|
|
|
|
t->setup = clamp_val(t->setup, 1, 8) & 7;
|
|
|
|
t->act8b = clamp_val(t->act8b, 1, 8) & 7;
|
|
|
|
t->rec8b = clamp_val(t->rec8b, 1, 16) & 15;
|
|
|
|
t->active = clamp_val(t->active, 1, 8) & 7;
|
|
|
|
t->recover = clamp_val(t->recover, 1, 16) & 15;
|
|
|
|
|
|
|
|
pci_write_config_byte(dev, port, t->setup);
|
|
|
|
pci_write_config_byte(dev, port + 1, (t->act8b << 4) | t->rec8b);
|
|
|
|
pci_write_config_byte(dev, port + unit + 2,
|
|
|
|
(t->active << 4) | t->recover);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
ide: move ide_config_drive_speed() calls to upper layers (take 2)
* Convert {ide_hwif_t,ide_pci_device_t}->host_flag to be u16.
* Add IDE_HFLAG_POST_SET_MODE host flag to indicate the need to program
the host for the transfer mode after programming the device. Set it
in au1xxx-ide, amd74xx, cs5530, cs5535, pdc202xx_new, sc1200, pmac
and via82cxxx host drivers.
* Add IDE_HFLAG_NO_SET_MODE host flag to indicate the need to completely
skip programming of host/device for the transfer mode ("smart" hosts).
Set it in it821x host driver and check it in ide_tune_dma().
* Add ide_set_pio_mode()/ide_set_dma_mode() helpers and convert all
direct ->set_pio_mode/->speedproc users to use these helpers.
* Move ide_config_drive_speed() calls from ->set_pio_mode/->speedproc
methods to callers.
* Rename ->speedproc method to ->set_dma_mode, make it void and update
all implementations accordingly.
* Update ide_set_xfer_rate() comments.
* Unexport ide_config_drive_speed().
v2:
* Fix issues noticed by Sergei:
- export ide_set_dma_mode() instead of moving ->set_pio_mode abuse wrt
to setting DMA modes from sc1200_set_pio_mode() to do_special()
- check IDE_HFLAG_NO_SET_MODE in ide_tune_dma()
- check for (hwif->set_pio_mode) == NULL in ide_set_pio_mode()
- check for (hwif->set_dma_mode) == NULL in ide_set_dma_mode()
- return -1 from ide_set_{pio,dma}_mode() if ->set_{pio,dma}_mode == NULL
- don't set ->set_{pio,dma}_mode on it821x in "smart" mode
- fix build problem in pmac.c
- minor fixes in au1xxx-ide.c/cs5530.c/siimage.c
- improve patch description
Changes in behavior caused by this patch:
- HDIO_SET_PIO_MODE ioctl would now return -ENOSYS for attempts to change
PIO mode if it821x controller is in "smart" mode
- removal of two debugging printk-s (from cs5530.c and sc1200.c)
- transfer modes 0x00-0x07 passed from user space may be programmed twice on
the device (not really an issue since 0x00 is not supported correctly by
any host driver ATM, 0x01 is not supported at all and 0x02-0x07 are invalid)
Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
2007-10-13 19:47:51 +04:00
|
|
|
* ali_set_pio_mode - set host controller for PIO mode
|
2010-01-19 12:44:41 +03:00
|
|
|
* @hwif: port
|
2007-10-12 01:54:00 +04:00
|
|
|
* @drive: drive
|
2007-03-03 19:48:52 +03:00
|
|
|
*
|
2007-10-12 01:54:00 +04:00
|
|
|
* Program the controller for the given PIO mode.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2007-10-12 01:54:00 +04:00
|
|
|
|
2010-01-19 12:44:41 +03:00
|
|
|
static void ali_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2010-01-18 10:21:05 +03:00
|
|
|
ide_drive_t *pair = ide_get_pair_dev(drive);
|
2008-07-15 23:21:46 +04:00
|
|
|
int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
|
2010-01-18 10:17:37 +03:00
|
|
|
unsigned long T = 1000000 / bus_speed; /* PCI clock based */
|
|
|
|
struct ide_timing t;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-01-19 12:44:41 +03:00
|
|
|
ide_timing_compute(drive, drive->pio_mode, &t, T, 1);
|
2010-01-18 10:21:05 +03:00
|
|
|
if (pair) {
|
|
|
|
struct ide_timing p;
|
|
|
|
|
|
|
|
ide_timing_compute(pair, pair->pio_mode, &p, T, 1);
|
2010-01-18 10:21:12 +03:00
|
|
|
ide_timing_merge(&p, &t, &t,
|
|
|
|
IDE_TIMING_SETUP | IDE_TIMING_8BIT);
|
2010-01-18 10:21:05 +03:00
|
|
|
if (pair->dma_mode) {
|
|
|
|
ide_timing_compute(pair, pair->dma_mode, &p, T, 1);
|
2010-01-18 10:21:12 +03:00
|
|
|
ide_timing_merge(&p, &t, &t,
|
|
|
|
IDE_TIMING_SETUP | IDE_TIMING_8BIT);
|
2010-01-18 10:21:05 +03:00
|
|
|
}
|
|
|
|
}
|
2010-01-18 10:17:37 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* PIO mode => ATA FIFO on, ATAPI FIFO off
|
|
|
|
*/
|
2010-01-18 10:17:50 +03:00
|
|
|
ali_fifo_control(hwif, drive, (drive->media == ide_disk) ? 0x05 : 0x00);
|
2010-01-18 10:17:37 +03:00
|
|
|
|
2010-01-18 10:21:26 +03:00
|
|
|
ali_program_timings(hwif, drive, &t, 0);
|
2007-03-03 19:48:52 +03:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
2007-05-10 02:01:08 +04:00
|
|
|
* ali_udma_filter - compute UDMA mask
|
|
|
|
* @drive: IDE device
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
2007-05-10 02:01:08 +04:00
|
|
|
* Return available UDMA modes.
|
|
|
|
*
|
|
|
|
* The actual rules for the ALi are:
|
2005-04-17 02:20:36 +04:00
|
|
|
* No UDMA on revisions <= 0x20
|
|
|
|
* Disk only for revisions < 0xC2
|
2008-05-15 01:06:16 +04:00
|
|
|
* Not WDC drives on M1543C-E (?)
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
2007-05-10 02:01:08 +04:00
|
|
|
static u8 ali_udma_filter(ide_drive_t *drive)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-05-10 02:01:08 +04:00
|
|
|
if (m5229_revision > 0x20 && m5229_revision < 0xC2) {
|
|
|
|
if (drive->media != ide_disk)
|
|
|
|
return 0;
|
2009-12-03 19:25:57 +03:00
|
|
|
if (chip_is_1543c_e &&
|
2008-10-11 00:39:19 +04:00
|
|
|
strstr((char *)&drive->id[ATA_ID_PROD], "WDC "))
|
2007-05-10 02:01:08 +04:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-05-10 02:01:08 +04:00
|
|
|
return drive->hwif->ultra_mask;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
ide: move ide_config_drive_speed() calls to upper layers (take 2)
* Convert {ide_hwif_t,ide_pci_device_t}->host_flag to be u16.
* Add IDE_HFLAG_POST_SET_MODE host flag to indicate the need to program
the host for the transfer mode after programming the device. Set it
in au1xxx-ide, amd74xx, cs5530, cs5535, pdc202xx_new, sc1200, pmac
and via82cxxx host drivers.
* Add IDE_HFLAG_NO_SET_MODE host flag to indicate the need to completely
skip programming of host/device for the transfer mode ("smart" hosts).
Set it in it821x host driver and check it in ide_tune_dma().
* Add ide_set_pio_mode()/ide_set_dma_mode() helpers and convert all
direct ->set_pio_mode/->speedproc users to use these helpers.
* Move ide_config_drive_speed() calls from ->set_pio_mode/->speedproc
methods to callers.
* Rename ->speedproc method to ->set_dma_mode, make it void and update
all implementations accordingly.
* Update ide_set_xfer_rate() comments.
* Unexport ide_config_drive_speed().
v2:
* Fix issues noticed by Sergei:
- export ide_set_dma_mode() instead of moving ->set_pio_mode abuse wrt
to setting DMA modes from sc1200_set_pio_mode() to do_special()
- check IDE_HFLAG_NO_SET_MODE in ide_tune_dma()
- check for (hwif->set_pio_mode) == NULL in ide_set_pio_mode()
- check for (hwif->set_dma_mode) == NULL in ide_set_dma_mode()
- return -1 from ide_set_{pio,dma}_mode() if ->set_{pio,dma}_mode == NULL
- don't set ->set_{pio,dma}_mode on it821x in "smart" mode
- fix build problem in pmac.c
- minor fixes in au1xxx-ide.c/cs5530.c/siimage.c
- improve patch description
Changes in behavior caused by this patch:
- HDIO_SET_PIO_MODE ioctl would now return -ENOSYS for attempts to change
PIO mode if it821x controller is in "smart" mode
- removal of two debugging printk-s (from cs5530.c and sc1200.c)
- transfer modes 0x00-0x07 passed from user space may be programmed twice on
the device (not really an issue since 0x00 is not supported correctly by
any host driver ATM, 0x01 is not supported at all and 0x02-0x07 are invalid)
Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
2007-10-13 19:47:51 +04:00
|
|
|
* ali_set_dma_mode - set host controller for DMA mode
|
2010-01-19 12:45:29 +03:00
|
|
|
* @hwif: port
|
ide: move ide_config_drive_speed() calls to upper layers (take 2)
* Convert {ide_hwif_t,ide_pci_device_t}->host_flag to be u16.
* Add IDE_HFLAG_POST_SET_MODE host flag to indicate the need to program
the host for the transfer mode after programming the device. Set it
in au1xxx-ide, amd74xx, cs5530, cs5535, pdc202xx_new, sc1200, pmac
and via82cxxx host drivers.
* Add IDE_HFLAG_NO_SET_MODE host flag to indicate the need to completely
skip programming of host/device for the transfer mode ("smart" hosts).
Set it in it821x host driver and check it in ide_tune_dma().
* Add ide_set_pio_mode()/ide_set_dma_mode() helpers and convert all
direct ->set_pio_mode/->speedproc users to use these helpers.
* Move ide_config_drive_speed() calls from ->set_pio_mode/->speedproc
methods to callers.
* Rename ->speedproc method to ->set_dma_mode, make it void and update
all implementations accordingly.
* Update ide_set_xfer_rate() comments.
* Unexport ide_config_drive_speed().
v2:
* Fix issues noticed by Sergei:
- export ide_set_dma_mode() instead of moving ->set_pio_mode abuse wrt
to setting DMA modes from sc1200_set_pio_mode() to do_special()
- check IDE_HFLAG_NO_SET_MODE in ide_tune_dma()
- check for (hwif->set_pio_mode) == NULL in ide_set_pio_mode()
- check for (hwif->set_dma_mode) == NULL in ide_set_dma_mode()
- return -1 from ide_set_{pio,dma}_mode() if ->set_{pio,dma}_mode == NULL
- don't set ->set_{pio,dma}_mode on it821x in "smart" mode
- fix build problem in pmac.c
- minor fixes in au1xxx-ide.c/cs5530.c/siimage.c
- improve patch description
Changes in behavior caused by this patch:
- HDIO_SET_PIO_MODE ioctl would now return -ENOSYS for attempts to change
PIO mode if it821x controller is in "smart" mode
- removal of two debugging printk-s (from cs5530.c and sc1200.c)
- transfer modes 0x00-0x07 passed from user space may be programmed twice on
the device (not really an issue since 0x00 is not supported correctly by
any host driver ATM, 0x01 is not supported at all and 0x02-0x07 are invalid)
Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
2007-10-13 19:47:51 +04:00
|
|
|
* @drive: drive
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Configure the hardware for the desired IDE transfer mode.
|
|
|
|
*/
|
2007-10-12 01:53:59 +04:00
|
|
|
|
2010-01-19 12:45:29 +03:00
|
|
|
static void ali_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2010-01-18 10:21:26 +03:00
|
|
|
static u8 udma_timing[7] = { 0xC, 0xB, 0xA, 0x9, 0x8, 0xF, 0xD };
|
2008-02-02 01:09:31 +03:00
|
|
|
struct pci_dev *dev = to_pci_dev(hwif->dev);
|
2010-01-18 10:21:19 +03:00
|
|
|
ide_drive_t *pair = ide_get_pair_dev(drive);
|
|
|
|
int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
|
|
|
|
unsigned long T = 1000000 / bus_speed; /* PCI clock based */
|
2010-01-19 12:45:29 +03:00
|
|
|
const u8 speed = drive->dma_mode;
|
2005-04-17 02:20:36 +04:00
|
|
|
u8 tmpbyte = 0x00;
|
2010-01-18 10:21:19 +03:00
|
|
|
struct ide_timing t;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (speed < XFER_UDMA_0) {
|
2010-01-18 10:21:19 +03:00
|
|
|
ide_timing_compute(drive, drive->dma_mode, &t, T, 1);
|
|
|
|
if (pair) {
|
|
|
|
struct ide_timing p;
|
|
|
|
|
|
|
|
ide_timing_compute(pair, pair->pio_mode, &p, T, 1);
|
|
|
|
ide_timing_merge(&p, &t, &t,
|
|
|
|
IDE_TIMING_SETUP | IDE_TIMING_8BIT);
|
|
|
|
if (pair->dma_mode) {
|
|
|
|
ide_timing_compute(pair, pair->dma_mode,
|
|
|
|
&p, T, 1);
|
|
|
|
ide_timing_merge(&p, &t, &t,
|
|
|
|
IDE_TIMING_SETUP | IDE_TIMING_8BIT);
|
|
|
|
}
|
|
|
|
}
|
2010-01-18 10:21:26 +03:00
|
|
|
ali_program_timings(hwif, drive, &t, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
2010-01-18 10:21:26 +03:00
|
|
|
ali_program_timings(hwif, drive, NULL,
|
|
|
|
udma_timing[speed - XFER_UDMA_0]);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (speed >= XFER_UDMA_3) {
|
|
|
|
pci_read_config_byte(dev, 0x4b, &tmpbyte);
|
|
|
|
tmpbyte |= 1;
|
|
|
|
pci_write_config_byte(dev, 0x4b, tmpbyte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-03-31 22:15:21 +04:00
|
|
|
* ali_dma_check - DMA check
|
2005-04-17 02:20:36 +04:00
|
|
|
* @drive: target device
|
2009-03-27 14:46:46 +03:00
|
|
|
* @cmd: command
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Returns 1 if the DMA cannot be performed, zero on success.
|
|
|
|
*/
|
|
|
|
|
2009-03-31 22:15:21 +04:00
|
|
|
static int ali_dma_check(ide_drive_t *drive, struct ide_cmd *cmd)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
if (m5229_revision < 0xC2 && drive->media != ide_disk) {
|
2009-03-27 14:46:46 +03:00
|
|
|
if (cmd->tf_flags & IDE_TFLAG_WRITE)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1; /* try PIO instead of DMA */
|
|
|
|
}
|
2009-03-31 22:15:21 +04:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* init_chipset_ali15x3 - Initialise an ALi IDE controller
|
|
|
|
* @dev: PCI device
|
|
|
|
*
|
|
|
|
* This function initializes the ALI IDE controller and where
|
|
|
|
* appropriate also sets up the 1533 southbridge.
|
|
|
|
*/
|
2008-07-25 00:53:33 +04:00
|
|
|
|
2009-03-25 01:22:53 +03:00
|
|
|
static int init_chipset_ali15x3(struct pci_dev *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u8 tmpbyte;
|
2006-12-08 13:39:58 +03:00
|
|
|
struct pci_dev *north = pci_get_slot(dev->bus, PCI_DEVFN(0,0));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-06-09 02:46:36 +04:00
|
|
|
m5229_revision = dev->revision;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-12-08 13:39:58 +03:00
|
|
|
isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
if (m5229_revision < 0xC2) {
|
|
|
|
/*
|
|
|
|
* revision 0x20 (1543-E, 1543-F)
|
|
|
|
* revision 0xC0, 0xC1 (1543C-C, 1543C-D, 1543C-E)
|
|
|
|
* clear CD-ROM DMA write bit, m5229, 0x4b, bit 7
|
|
|
|
*/
|
|
|
|
pci_read_config_byte(dev, 0x4b, &tmpbyte);
|
|
|
|
/*
|
|
|
|
* clear bit 7
|
|
|
|
*/
|
|
|
|
pci_write_config_byte(dev, 0x4b, tmpbyte & 0x7F);
|
2007-10-20 02:32:30 +04:00
|
|
|
/*
|
|
|
|
* check m1533, 0x5e, bit 1~4 == 1001 => & 00011110 = 00010010
|
|
|
|
*/
|
|
|
|
if (m5229_revision >= 0x20 && isa_dev) {
|
|
|
|
pci_read_config_byte(isa_dev, 0x5e, &tmpbyte);
|
|
|
|
chip_is_1543c_e = ((tmpbyte & 0x1e) == 0x12) ? 1: 0;
|
|
|
|
}
|
2006-12-08 13:39:58 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1543C-B?, 1535, 1535D, 1553
|
|
|
|
* Note 1: not all "motherboard" support this detection
|
|
|
|
* Note 2: if no udma 66 device, the detection may "error".
|
|
|
|
* but in this case, we will not set the device to
|
|
|
|
* ultra 66, the detection result is not important
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enable "Cable Detection", m5229, 0x4b, bit3
|
|
|
|
*/
|
|
|
|
pci_read_config_byte(dev, 0x4b, &tmpbyte);
|
|
|
|
pci_write_config_byte(dev, 0x4b, tmpbyte | 0x08);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We should only tune the 1533 enable if we are using an ALi
|
|
|
|
* North bridge. We might have no north found on some zany
|
|
|
|
* box without a device at 0:0.0. The ALi bridge will be at
|
|
|
|
* 0:0.0 so if we didn't find one we know what is cooking.
|
|
|
|
*/
|
2006-12-08 13:39:58 +03:00
|
|
|
if (north && north->vendor != PCI_VENDOR_ID_AL)
|
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (m5229_revision < 0xC5 && isa_dev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* set south-bridge's enable bit, m1533, 0x79
|
|
|
|
*/
|
|
|
|
|
|
|
|
pci_read_config_byte(isa_dev, 0x79, &tmpbyte);
|
|
|
|
if (m5229_revision == 0xC2) {
|
|
|
|
/*
|
|
|
|
* 1543C-B0 (m1533, 0x79, bit 2)
|
|
|
|
*/
|
|
|
|
pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x04);
|
|
|
|
} else if (m5229_revision >= 0xC3) {
|
|
|
|
/*
|
|
|
|
* 1553/1535 (m1533, 0x79, bit 1)
|
|
|
|
*/
|
|
|
|
pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x02);
|
|
|
|
}
|
|
|
|
}
|
2007-10-20 02:32:30 +04:00
|
|
|
|
2006-12-08 13:39:58 +03:00
|
|
|
out:
|
2007-10-20 02:32:30 +04:00
|
|
|
/*
|
|
|
|
* CD_ROM DMA on (m5229, 0x53, bit0)
|
|
|
|
* Enable this bit even if we want to use PIO.
|
|
|
|
* PIO FIFO off (m5229, 0x53, bit1)
|
|
|
|
* The hardware will use 0x54h and 0x55h to control PIO FIFO.
|
|
|
|
* (Not on later devices it seems)
|
|
|
|
*
|
|
|
|
* 0x53 changes meaning on later revs - we must no touch
|
|
|
|
* bit 1 on them. Need to check if 0x20 is the right break.
|
|
|
|
*/
|
|
|
|
if (m5229_revision >= 0x20) {
|
|
|
|
pci_read_config_byte(dev, 0x53, &tmpbyte);
|
|
|
|
|
|
|
|
if (m5229_revision <= 0x20)
|
|
|
|
tmpbyte = (tmpbyte & (~0x02)) | 0x01;
|
|
|
|
else if (m5229_revision == 0xc7 || m5229_revision == 0xc8)
|
|
|
|
tmpbyte |= 0x03;
|
|
|
|
else
|
|
|
|
tmpbyte |= 0x01;
|
|
|
|
|
|
|
|
pci_write_config_byte(dev, 0x53, tmpbyte);
|
|
|
|
}
|
2006-12-08 13:39:58 +03:00
|
|
|
pci_dev_put(north);
|
|
|
|
pci_dev_put(isa_dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
local_irq_restore(flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-10 01:17:58 +04:00
|
|
|
/*
|
|
|
|
* Cable special cases
|
|
|
|
*/
|
|
|
|
|
2007-10-03 23:15:40 +04:00
|
|
|
static const struct dmi_system_id cable_dmi_table[] = {
|
2007-07-10 01:17:58 +04:00
|
|
|
{
|
|
|
|
.ident = "HP Pavilion N5430",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
|
2007-08-02 01:46:43 +04:00
|
|
|
DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
|
2007-07-10 01:17:58 +04:00
|
|
|
},
|
|
|
|
},
|
2007-09-12 00:28:36 +04:00
|
|
|
{
|
|
|
|
.ident = "Toshiba Satellite S1800-814",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
|
|
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "S1800-814"),
|
|
|
|
},
|
|
|
|
},
|
2007-07-10 01:17:58 +04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ali_cable_override(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
/* Fujitsu P2000 */
|
|
|
|
if (pdev->subsystem_vendor == 0x10CF &&
|
|
|
|
pdev->subsystem_device == 0x10AF)
|
|
|
|
return 1;
|
|
|
|
|
2007-11-27 23:35:56 +03:00
|
|
|
/* Mitac 8317 (Winbook-A) and relatives */
|
|
|
|
if (pdev->subsystem_vendor == 0x1071 &&
|
|
|
|
pdev->subsystem_device == 0x8317)
|
|
|
|
return 1;
|
|
|
|
|
2007-07-10 01:17:58 +04:00
|
|
|
/* Systems by DMI */
|
|
|
|
if (dmi_check_system(cable_dmi_table))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
2008-04-27 00:25:14 +04:00
|
|
|
* ali_cable_detect - cable detection
|
2005-04-17 02:20:36 +04:00
|
|
|
* @hwif: IDE interface
|
|
|
|
*
|
|
|
|
* This checks if the controller and the cable are capable
|
|
|
|
* of UDMA66 transfers. It doesn't check the drives.
|
|
|
|
*/
|
|
|
|
|
2008-08-05 20:17:04 +04:00
|
|
|
static u8 ali_cable_detect(ide_hwif_t *hwif)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-02-02 01:09:31 +03:00
|
|
|
struct pci_dev *dev = to_pci_dev(hwif->dev);
|
2007-07-10 01:17:58 +04:00
|
|
|
u8 cbl = ATA_CBL_PATA40, tmpbyte;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (m5229_revision >= 0xC2) {
|
|
|
|
/*
|
2007-07-10 01:17:58 +04:00
|
|
|
* m5229 80-pin cable detection (from Host View)
|
|
|
|
*
|
|
|
|
* 0x4a bit0 is 0 => primary channel has 80-pin
|
|
|
|
* 0x4a bit1 is 0 => secondary channel has 80-pin
|
|
|
|
*
|
|
|
|
* Certain laptops use short but suitable cables
|
|
|
|
* and don't implement the detect logic.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2007-07-10 01:17:58 +04:00
|
|
|
if (ali_cable_override(dev))
|
|
|
|
cbl = ATA_CBL_PATA40_SHORT;
|
|
|
|
else {
|
|
|
|
pci_read_config_byte(dev, 0x4a, &tmpbyte);
|
|
|
|
if ((tmpbyte & (1 << hwif->channel)) == 0)
|
|
|
|
cbl = ATA_CBL_PATA80;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-07-10 01:17:58 +04:00
|
|
|
return cbl;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2009-04-30 20:38:01 +04:00
|
|
|
#ifndef CONFIG_SPARC64
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff
|
|
|
|
* @hwif: interface to configure
|
|
|
|
*
|
|
|
|
* Obtain the IRQ tables for an ALi based IDE solution on the PC
|
|
|
|
* class platforms. This part of the code isn't applicable to the
|
2009-04-30 20:38:01 +04:00
|
|
|
* Sparc systems.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
2012-12-22 01:21:03 +04:00
|
|
|
static void init_hwif_ali15x3(ide_hwif_t *hwif)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
u8 ideic, inmir;
|
|
|
|
s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6,
|
|
|
|
1, 11, 0, 12, 0, 14, 0, 15 };
|
|
|
|
int irq = -1;
|
|
|
|
|
|
|
|
if (isa_dev) {
|
|
|
|
/*
|
|
|
|
* read IDE interface control
|
|
|
|
*/
|
|
|
|
pci_read_config_byte(isa_dev, 0x58, &ideic);
|
|
|
|
|
|
|
|
/* bit0, bit1 */
|
|
|
|
ideic = ideic & 0x03;
|
|
|
|
|
|
|
|
/* get IRQ for IDE Controller */
|
|
|
|
if ((hwif->channel && ideic == 0x03) ||
|
|
|
|
(!hwif->channel && !ideic)) {
|
|
|
|
/*
|
|
|
|
* get SIRQ1 routing table
|
|
|
|
*/
|
|
|
|
pci_read_config_byte(isa_dev, 0x44, &inmir);
|
|
|
|
inmir = inmir & 0x0f;
|
|
|
|
irq = irq_routing_table[inmir];
|
|
|
|
} else if (hwif->channel && !(ideic & 0x01)) {
|
|
|
|
/*
|
|
|
|
* get SIRQ2 routing table
|
|
|
|
*/
|
|
|
|
pci_read_config_byte(isa_dev, 0x75, &inmir);
|
|
|
|
inmir = inmir & 0x0f;
|
|
|
|
irq = irq_routing_table[inmir];
|
|
|
|
}
|
|
|
|
if(irq >= 0)
|
|
|
|
hwif->irq = irq;
|
|
|
|
}
|
|
|
|
}
|
2008-04-30 00:57:38 +04:00
|
|
|
#else
|
|
|
|
#define init_hwif_ali15x3 NULL
|
2009-04-30 20:38:01 +04:00
|
|
|
#endif /* CONFIG_SPARC64 */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* init_dma_ali15x3 - set up DMA on ALi15x3
|
|
|
|
* @hwif: IDE interface
|
2008-04-27 00:25:22 +04:00
|
|
|
* @d: IDE port info
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
2008-04-27 00:25:22 +04:00
|
|
|
* Set up the DMA functionality on the ALi 15x3.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
2012-12-22 01:21:03 +04:00
|
|
|
static int init_dma_ali15x3(ide_hwif_t *hwif, const struct ide_port_info *d)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-04-27 00:25:22 +04:00
|
|
|
struct pci_dev *dev = to_pci_dev(hwif->dev);
|
|
|
|
unsigned long base = ide_pci_dma_base(hwif, d);
|
|
|
|
|
2008-07-23 21:55:51 +04:00
|
|
|
if (base == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
hwif->dma_base = base;
|
|
|
|
|
|
|
|
if (ide_pci_check_simplex(hwif, d) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (ide_pci_set_master(dev, d->name) < 0)
|
2008-04-27 00:25:22 +04:00
|
|
|
return -1;
|
|
|
|
|
2007-02-17 04:40:25 +03:00
|
|
|
if (!hwif->channel)
|
2008-04-27 00:25:22 +04:00
|
|
|
outb(inb(base + 2) & 0x60, base + 2);
|
|
|
|
|
|
|
|
printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n",
|
|
|
|
hwif->name, base, base + 7);
|
|
|
|
|
|
|
|
if (ide_allocate_dma_engine(hwif))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-04-27 00:25:14 +04:00
|
|
|
static const struct ide_port_ops ali_port_ops = {
|
|
|
|
.set_pio_mode = ali_set_pio_mode,
|
|
|
|
.set_dma_mode = ali_set_dma_mode,
|
|
|
|
.udma_filter = ali_udma_filter,
|
|
|
|
.cable_detect = ali_cable_detect,
|
|
|
|
};
|
|
|
|
|
2008-04-27 00:25:24 +04:00
|
|
|
static const struct ide_dma_ops ali_dma_ops = {
|
|
|
|
.dma_host_set = ide_dma_host_set,
|
2009-03-31 22:15:21 +04:00
|
|
|
.dma_setup = ide_dma_setup,
|
2008-04-27 00:25:24 +04:00
|
|
|
.dma_start = ide_dma_start,
|
2008-10-13 23:39:46 +04:00
|
|
|
.dma_end = ide_dma_end,
|
2008-04-27 00:25:24 +04:00
|
|
|
.dma_test_irq = ide_dma_test_irq,
|
|
|
|
.dma_lost_irq = ide_dma_lost_irq,
|
2009-03-31 22:15:21 +04:00
|
|
|
.dma_check = ali_dma_check,
|
2009-03-27 14:46:47 +03:00
|
|
|
.dma_timer_expiry = ide_dma_sff_timer_expiry,
|
2009-01-06 19:21:02 +03:00
|
|
|
.dma_sff_read_status = ide_dma_sff_read_status,
|
2008-04-27 00:25:24 +04:00
|
|
|
};
|
|
|
|
|
2012-12-22 01:21:03 +04:00
|
|
|
static const struct ide_port_info ali15x3_chipset = {
|
2008-07-25 00:53:32 +04:00
|
|
|
.name = DRV_NAME,
|
2005-04-17 02:20:36 +04:00
|
|
|
.init_chipset = init_chipset_ali15x3,
|
|
|
|
.init_hwif = init_hwif_ali15x3,
|
|
|
|
.init_dma = init_dma_ali15x3,
|
2008-04-27 00:25:14 +04:00
|
|
|
.port_ops = &ali_port_ops,
|
2009-01-06 19:21:01 +03:00
|
|
|
.dma_ops = &sff_dma_ops,
|
2007-07-20 03:11:59 +04:00
|
|
|
.pio_mask = ATA_PIO5,
|
2007-10-19 02:30:07 +04:00
|
|
|
.swdma_mask = ATA_SWDMA2,
|
|
|
|
.mwdma_mask = ATA_MWDMA2,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* alim15x3_init_one - set up an ALi15x3 IDE controller
|
|
|
|
* @dev: PCI device to set up
|
|
|
|
*
|
|
|
|
* Perform the actual set up for an ALi15x3 that has been found by the
|
|
|
|
* hot plug layer.
|
|
|
|
*/
|
|
|
|
|
2012-12-22 01:21:03 +04:00
|
|
|
static int alim15x3_init_one(struct pci_dev *dev,
|
|
|
|
const struct pci_device_id *id)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-10-20 02:32:34 +04:00
|
|
|
struct ide_port_info d = ali15x3_chipset;
|
2008-02-02 01:09:30 +03:00
|
|
|
u8 rev = dev->revision, idx = id->driver_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-10-20 02:32:30 +04:00
|
|
|
/* don't use LBA48 DMA on ALi devices before rev 0xC5 */
|
|
|
|
if (rev <= 0xC4)
|
|
|
|
d.host_flags |= IDE_HFLAG_NO_LBA48_DMA;
|
|
|
|
|
|
|
|
if (rev >= 0x20) {
|
|
|
|
if (rev == 0x20)
|
|
|
|
d.host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
|
|
|
|
|
|
|
|
if (rev < 0xC2)
|
|
|
|
d.udma_mask = ATA_UDMA2;
|
|
|
|
else if (rev == 0xC2 || rev == 0xC3)
|
|
|
|
d.udma_mask = ATA_UDMA4;
|
|
|
|
else if (rev == 0xC4)
|
|
|
|
d.udma_mask = ATA_UDMA5;
|
|
|
|
else
|
|
|
|
d.udma_mask = ATA_UDMA6;
|
2008-04-27 00:25:24 +04:00
|
|
|
|
|
|
|
d.dma_ops = &ali_dma_ops;
|
2008-04-27 00:25:21 +04:00
|
|
|
} else {
|
|
|
|
d.host_flags |= IDE_HFLAG_NO_DMA;
|
|
|
|
|
|
|
|
d.mwdma_mask = d.swdma_mask = 0;
|
2007-10-20 02:32:30 +04:00
|
|
|
}
|
|
|
|
|
2008-02-02 01:09:30 +03:00
|
|
|
if (idx == 0)
|
|
|
|
d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
|
|
|
|
|
2008-07-25 00:53:14 +04:00
|
|
|
return ide_pci_init_one(dev, &d, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-17 00:29:56 +04:00
|
|
|
static const struct pci_device_id alim15x3_pci_tbl[] = {
|
|
|
|
{ PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), 0 },
|
2008-02-02 01:09:30 +03:00
|
|
|
{ PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), 1 },
|
2005-04-17 02:20:36 +04:00
|
|
|
{ 0, },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl);
|
|
|
|
|
2008-10-13 23:39:41 +04:00
|
|
|
static struct pci_driver alim15x3_pci_driver = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "ALI15x3_IDE",
|
|
|
|
.id_table = alim15x3_pci_tbl,
|
|
|
|
.probe = alim15x3_init_one,
|
2008-07-25 00:53:19 +04:00
|
|
|
.remove = ide_pci_remove,
|
2008-10-11 00:39:32 +04:00
|
|
|
.suspend = ide_pci_suspend,
|
|
|
|
.resume = ide_pci_resume,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2007-01-27 15:46:56 +03:00
|
|
|
static int __init ali15x3_ide_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-10-13 23:39:41 +04:00
|
|
|
return ide_pci_register_driver(&alim15x3_pci_driver);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-07-25 00:53:19 +04:00
|
|
|
static void __exit ali15x3_ide_exit(void)
|
|
|
|
{
|
2008-12-02 22:40:04 +03:00
|
|
|
pci_unregister_driver(&alim15x3_pci_driver);
|
2008-07-25 00:53:19 +04:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
module_init(ali15x3_ide_init);
|
2008-07-25 00:53:19 +04:00
|
|
|
module_exit(ali15x3_ide_exit);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-01-18 10:17:37 +03:00
|
|
|
MODULE_AUTHOR("Michael Aubry, Andrzej Krzysztofowicz, CJ, Andre Hedrick, Alan Cox, Bartlomiej Zolnierkiewicz");
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_DESCRIPTION("PCI driver module for ALi 15x3 IDE");
|
|
|
|
MODULE_LICENSE("GPL");
|