Home | History | Annotate | Line # | Download | only in pci
pciide_opti_reg.h revision 1.11.10.1
      1  1.11.10.1     yamt /*	$NetBSD: pciide_opti_reg.h,v 1.11.10.1 2008/05/16 02:24:45 yamt Exp $	*/
      2        1.1      scw 
      3        1.1      scw /*-
      4        1.1      scw  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5        1.1      scw  * All rights reserved.
      6        1.1      scw  *
      7        1.1      scw  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1      scw  * by Steve C. Woodford.
      9        1.1      scw  *
     10        1.1      scw  * Redistribution and use in source and binary forms, with or without
     11        1.1      scw  * modification, are permitted provided that the following conditions
     12        1.1      scw  * are met:
     13        1.1      scw  * 1. Redistributions of source code must retain the above copyright
     14        1.1      scw  *    notice, this list of conditions and the following disclaimer.
     15        1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     17        1.1      scw  *    documentation and/or other materials provided with the distribution.
     18        1.1      scw  *
     19        1.1      scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1      scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1      scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1      scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1      scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1      scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1      scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1      scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1      scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1      scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1      scw  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1      scw  */
     31        1.1      scw 
     32        1.1      scw /*
     33        1.1      scw  * Register definitions for OPTi PCIIDE controllers based on
     34        1.1      scw  * their 82c621 chip.
     35        1.1      scw  */
     36        1.1      scw 
     37        1.1      scw /* IDE Initialization Control Register */
     38        1.1      scw #define OPTI_REG_INIT_CONTROL		0x40
     39        1.1      scw #define  OPTI_INIT_CONTROL_MODE_PIO_0	0
     40        1.1      scw #define  OPTI_INIT_CONTROL_MODE_PIO_1	2
     41        1.1      scw #define  OPTI_INIT_CONTROL_MODE_PIO_2	1
     42        1.1      scw #define  OPTI_INIT_CONTROL_MODE_PIO_3	3
     43        1.1      scw #define  OPTI_INIT_CONTROL_ADDR_RELOC	(1u << 2)
     44        1.1      scw #define  OPTI_INIT_CONTROL_CH2_ENABLE	0
     45        1.1      scw #define  OPTI_INIT_CONTROL_CH2_DISABLE	(1u << 3)
     46        1.1      scw #define  OPTI_INIT_CONTROL_FIFO_16	0
     47        1.1      scw #define  OPTI_INIT_CONTROL_FIFO_32	(1u << 5)
     48        1.1      scw #define  OPTI_INIT_CONTROL_FIFO_REQ_32	0
     49        1.1      scw #define  OPTI_INIT_CONTROL_FIFO_REQ_30	(1u << 6)
     50        1.1      scw #define  OPTI_INIT_CONTROL_FIFO_REQ_28	(2u << 6)
     51        1.1      scw #define  OPTI_INIT_CONTROL_FIFO_REQ_26	(3u << 6)
     52        1.1      scw 
     53        1.1      scw /* IDE Enhanced Features Register */
     54        1.1      scw #define OPTI_REG_ENH_FEAT		0x42
     55        1.1      scw #define  OPTI_ENH_FEAT_X111_ENABLE	(1u << 1)
     56        1.1      scw #define  OPTI_ENH_FEAT_CONCURRENT_MAST	(1u << 2)
     57        1.1      scw #define  OPTI_ENH_FEAT_PCI_INVALIDATE	(1u << 3)
     58        1.1      scw #define  OPTI_ENH_FEAT_IDE_CONCUR	(1u << 4)
     59        1.1      scw #define  OPTI_ENH_FEAT_SLAVE_FIFO_ISA	(1u << 5)
     60        1.1      scw 
     61        1.1      scw /* IDE Enhanced Mode Register */
     62        1.1      scw #define OPTI_REG_ENH_MODE		0x43
     63        1.1      scw #define  OPTI_ENH_MODE_MASK(c,d)	(3u << (((c) * 4) + ((d) * 2)))
     64        1.1      scw #define  OPTI_ENH_MODE_USE_TIMING(c,d)	0
     65        1.1      scw #define  OPTI_ENH_MODE(c,d,m)		((m) << (((c) * 4) + ((d) * 2)))
     66        1.1      scw 
     67        1.1      scw /* Timing registers */
     68        1.1      scw #define OPTI_REG_READ_CYCLE_TIMING	0x00
     69        1.1      scw #define OPTI_REG_WRITE_CYCLE_TIMING	0x01
     70        1.1      scw #define  OPTI_RECOVERY_TIME_SHIFT	0
     71        1.1      scw #define  OPTI_PULSE_WIDTH_SHIFT		4
     72        1.1      scw 
     73        1.1      scw /*
     74        1.1      scw  * Control register.
     75        1.1      scw  */
     76        1.1      scw #define OPTI_REG_CONTROL		0x03
     77        1.1      scw #define  OPTI_CONTROL_DISABLE		0x11
     78        1.1      scw #define  OPTI_CONTROL_ENABLE		0x95
     79        1.1      scw 
     80        1.1      scw /* Strap register */
     81        1.1      scw #define OPTI_REG_STRAP			0x05
     82        1.1      scw #define  OPTI_STRAP_PCI_SPEED_MASK	0x1u
     83        1.1      scw #define  OPTI_STRAP_PCI_33		0
     84        1.1      scw #define  OPTI_STRAP_PCI_25		1
     85        1.1      scw 
     86        1.1      scw /* Miscellaneous register */
     87        1.1      scw #define OPTI_REG_MISC			0x06
     88        1.1      scw #define  OPTI_MISC_INDEX(d)		((unsigned)(d))
     89        1.1      scw #define  OPTI_MISC_INDEX_MASK		0x01u
     90        1.1      scw #define  OPTI_MISC_DELAY_MASK		0x07u
     91        1.1      scw #define  OPTI_MISC_DELAY_SHIFT		1
     92        1.1      scw #define  OPTI_MISC_ADDR_SETUP_MASK	0x3u
     93        1.1      scw #define  OPTI_MISC_ADDR_SETUP_SHIFT	4
     94        1.1      scw #define  OPTI_MISC_READ_PREFETCH_ENABLE	(1u << 6)
     95        1.1      scw #define  OPTI_MISC_ADDR_SETUP_MASK	0x3u
     96        1.1      scw #define  OPTI_MISC_WRITE_MASK		0x7fu
     97        1.1      scw 
     98        1.1      scw 
     99        1.1      scw /*
    100        1.1      scw  * Inline functions for accessing the timing registers of the
    101        1.1      scw  * OPTi controller.
    102        1.1      scw  *
    103        1.1      scw  * These *MUST* disable interrupts as they need atomic access to
    104        1.1      scw  * certain magic registers. Failure to adhere to this *will*
    105        1.1      scw  * break things in subtle ways if the wdc registers are accessed
    106        1.1      scw  * by an interrupt routine while this magic sequence is executing.
    107        1.1      scw  */
    108       1.11    perry static __inline u_int8_t __unused
    109        1.6  thorpej opti_read_config(struct ata_channel *chp, int reg)
    110        1.1      scw {
    111        1.7  thorpej 	struct wdc_regs *wdr = CHAN_TO_WDC_REGS(chp);
    112        1.1      scw 	u_int8_t rv;
    113        1.1      scw 	int s = splhigh();
    114        1.1      scw 
    115        1.1      scw 	/* Two consecutive 16-bit reads from register #1 (0x1f1/0x171) */
    116        1.6  thorpej 	(void) bus_space_read_2(wdr->cmd_iot, wdr->cmd_iohs[wd_features], 0);
    117        1.6  thorpej 	(void) bus_space_read_2(wdr->cmd_iot, wdr->cmd_iohs[wd_features], 0);
    118        1.1      scw 
    119        1.1      scw 	/* Followed by an 8-bit write of 0x3 to register #2 */
    120        1.6  thorpej 	bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_seccnt], 0, 0x03u);
    121        1.1      scw 
    122        1.1      scw 	/* Now we can read the required register */
    123        1.6  thorpej 	rv = bus_space_read_1(wdr->cmd_iot, wdr->cmd_iohs[reg], 0);
    124        1.1      scw 
    125        1.1      scw 	/* Restore the real registers */
    126        1.6  thorpej 	bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_seccnt], 0, 0x83u);
    127        1.1      scw 
    128        1.1      scw 	splx(s);
    129        1.1      scw 
    130        1.1      scw 	return rv;
    131        1.1      scw }
    132        1.1      scw 
    133       1.11    perry static __inline void __unused
    134        1.6  thorpej opti_write_config(struct ata_channel *chp, int reg, u_int8_t val)
    135        1.1      scw {
    136        1.7  thorpej 	struct wdc_regs *wdr = CHAN_TO_WDC_REGS(chp);
    137        1.1      scw 	int s = splhigh();
    138        1.1      scw 
    139        1.1      scw 	/* Two consecutive 16-bit reads from register #1 (0x1f1/0x171) */
    140        1.6  thorpej 	(void) bus_space_read_2(wdr->cmd_iot, wdr->cmd_iohs[wd_features], 0);
    141        1.6  thorpej 	(void) bus_space_read_2(wdr->cmd_iot, wdr->cmd_iohs[wd_features], 0);
    142        1.1      scw 
    143        1.1      scw 	/* Followed by an 8-bit write of 0x3 to register #2 */
    144        1.6  thorpej 	bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_seccnt], 0, 0x03u);
    145        1.1      scw 
    146        1.1      scw 	/* Now we can write the required register */
    147        1.6  thorpej 	bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[reg], 0, val);
    148        1.1      scw 
    149        1.1      scw 	/* Restore the real registers */
    150        1.6  thorpej 	bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_seccnt], 0, 0x83u);
    151        1.1      scw 
    152        1.1      scw 	splx(s);
    153        1.1      scw }
    154        1.1      scw 
    155        1.1      scw /*
    156        1.1      scw  * These are the timing register values for the various IDE modes
    157        1.2      scw  * supported by the OPTi chip. The first index of the two-dimensional
    158        1.2      scw  * arrays is used for a 33MHz PCIbus, the second for a 25MHz PCIbus.
    159        1.1      scw  */
    160       1.11    perry static const u_int8_t opti_tim_cp[2][8] __unused = {
    161        1.3  thorpej 	/* Command Pulse */
    162        1.2      scw 	{5, 4, 3, 2, 2, 7, 2, 2},
    163        1.2      scw 	{4, 3, 2, 2, 1, 5, 2, 1}
    164        1.2      scw };
    165        1.2      scw 
    166       1.11    perry static const u_int8_t opti_tim_rt[2][8] __unused = {
    167        1.3  thorpej 	/* Recovery Time */
    168        1.2      scw 	{9, 4, 0, 0, 0, 6, 0, 0},
    169        1.2      scw 	{6, 2, 0, 0, 0, 4, 0, 0}
    170        1.2      scw };
    171        1.2      scw 
    172       1.11    perry static const u_int8_t opti_tim_as[2][8] __unused = {
    173        1.3  thorpej 	/* Address Setup */
    174        1.2      scw 	{2, 1, 1, 1, 0, 0, 0, 0},
    175        1.2      scw 	{1, 1, 0, 0, 0, 0, 0, 0}
    176        1.2      scw };
    177        1.2      scw 
    178       1.11    perry static const u_int8_t opti_tim_em[8] __unused = {
    179        1.3  thorpej 	/* Enhanced Mode */
    180        1.2      scw 	0, 0, 0, 1, 2, 0, 1 ,2
    181        1.2      scw };
    182