📄 ti113x.c
字号:
/* * (C) Copyright 2003-2005 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * 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 of * the License, 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; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * ******************************************************************** * * Lots of code copied from: * * i82365.c 1.352 - Linux driver for Intel 82365 and compatible * PC Card controllers, and Yenta-compatible PCI-to-CardBus controllers. * (C) 1999 David A. Hinds <dahinds@users.sourceforge.net> */#include <common.h>#ifdef CONFIG_I82365#include <command.h>#include <pci.h>#include <pcmcia.h>#include <asm/io.h>#include <pcmcia/ss.h>#include <pcmcia/i82365.h>#include <pcmcia/yenta.h>#include <pcmcia/ti113x.h>static struct pci_device_id supported[] = { {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510}, {0, 0}};#define CYCLE_TIME 120#ifdef DEBUGstatic void i82365_dump_regions (pci_dev_t dev);#endiftypedef struct socket_info_t { pci_dev_t dev; u_short bcr; u_char pci_lat, cb_lat, sub_bus, cache; u_int cb_phys; socket_cap_t cap; u_short type; u_int flags; ti113x_state_t state;} socket_info_t;static socket_info_t socket;static socket_state_t state;static struct pccard_mem_map mem;static struct pccard_io_map io;/*====================================================================*//* Some PCI shortcuts */static int pci_readb (socket_info_t * s, int r, u_char * v){ return pci_read_config_byte (s->dev, r, v);}static int pci_writeb (socket_info_t * s, int r, u_char v){ return pci_write_config_byte (s->dev, r, v);}static int pci_readw (socket_info_t * s, int r, u_short * v){ return pci_read_config_word (s->dev, r, v);}static int pci_writew (socket_info_t * s, int r, u_short v){ return pci_write_config_word (s->dev, r, v);}static int pci_readl (socket_info_t * s, int r, u_int * v){ return pci_read_config_dword (s->dev, r, v);}static int pci_writel (socket_info_t * s, int r, u_int v){ return pci_write_config_dword (s->dev, r, v);}/*====================================================================*/#define cb_readb(s, r) readb((s)->cb_phys + (r))#define cb_readl(s, r) readl((s)->cb_phys + (r))#define cb_writeb(s, r, v) writeb(v, (s)->cb_phys + (r))#define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r))static u_char i365_get (socket_info_t * s, u_short reg){ return cb_readb (s, 0x0800 + reg);}static void i365_set (socket_info_t * s, u_short reg, u_char data){ cb_writeb (s, 0x0800 + reg, data);}static void i365_bset (socket_info_t * s, u_short reg, u_char mask){ i365_set (s, reg, i365_get (s, reg) | mask);}static void i365_bclr (socket_info_t * s, u_short reg, u_char mask){ i365_set (s, reg, i365_get (s, reg) & ~mask);}#if 0 /* not used */static void i365_bflip (socket_info_t * s, u_short reg, u_char mask, int b){ u_char d = i365_get (s, reg); i365_set (s, reg, (b) ? (d | mask) : (d & ~mask));}static u_short i365_get_pair (socket_info_t * s, u_short reg){ return (i365_get (s, reg) + (i365_get (s, reg + 1) << 8));}#endif /* not used */static void i365_set_pair (socket_info_t * s, u_short reg, u_short data){ i365_set (s, reg, data & 0xff); i365_set (s, reg + 1, data >> 8);}/*====================================================================== Code to save and restore global state information for TI 1130 and TI 1131 controllers, and to set and report global configuration options.======================================================================*/static void ti113x_get_state (socket_info_t * s){ ti113x_state_t *p = &s->state; pci_readl (s, TI113X_SYSTEM_CONTROL, &p->sysctl); pci_readb (s, TI113X_CARD_CONTROL, &p->cardctl); pci_readb (s, TI113X_DEVICE_CONTROL, &p->devctl); pci_readb (s, TI1250_DIAGNOSTIC, &p->diag); pci_readl (s, TI12XX_IRQMUX, &p->irqmux);}static void ti113x_set_state (socket_info_t * s){ ti113x_state_t *p = &s->state; pci_writel (s, TI113X_SYSTEM_CONTROL, p->sysctl); pci_writeb (s, TI113X_CARD_CONTROL, p->cardctl); pci_writeb (s, TI113X_DEVICE_CONTROL, p->devctl); pci_writeb (s, TI1250_MULTIMEDIA_CTL, 0); pci_writeb (s, TI1250_DIAGNOSTIC, p->diag); pci_writel (s, TI12XX_IRQMUX, p->irqmux); i365_set_pair (s, TI113X_IO_OFFSET (0), 0); i365_set_pair (s, TI113X_IO_OFFSET (1), 0);}static u_int ti113x_set_opts (socket_info_t * s){ ti113x_state_t *p = &s->state; u_int mask = 0xffff; p->cardctl &= ~TI113X_CCR_ZVENABLE; p->cardctl |= TI113X_CCR_SPKROUTEN; return mask;}/*====================================================================== Routines to handle common CardBus options======================================================================*//* Default settings for PCI command configuration register */#define CMD_DFLT (PCI_COMMAND_IO|PCI_COMMAND_MEMORY| \ PCI_COMMAND_MASTER|PCI_COMMAND_WAIT)static void cb_get_state (socket_info_t * s){ pci_readb (s, PCI_CACHE_LINE_SIZE, &s->cache); pci_readb (s, PCI_LATENCY_TIMER, &s->pci_lat); pci_readb (s, CB_LATENCY_TIMER, &s->cb_lat); pci_readb (s, CB_CARDBUS_BUS, &s->cap.cardbus); pci_readb (s, CB_SUBORD_BUS, &s->sub_bus); pci_readw (s, CB_BRIDGE_CONTROL, &s->bcr);}static void cb_set_state (socket_info_t * s){ pci_writel (s, CB_LEGACY_MODE_BASE, 0); pci_writel (s, PCI_BASE_ADDRESS_0, s->cb_phys); pci_writew (s, PCI_COMMAND, CMD_DFLT); pci_writeb (s, PCI_CACHE_LINE_SIZE, s->cache); pci_writeb (s, PCI_LATENCY_TIMER, s->pci_lat); pci_writeb (s, CB_LATENCY_TIMER, s->cb_lat); pci_writeb (s, CB_CARDBUS_BUS, s->cap.cardbus); pci_writeb (s, CB_SUBORD_BUS, s->sub_bus); pci_writew (s, CB_BRIDGE_CONTROL, s->bcr);}static void cb_set_opts (socket_info_t * s){ if (s->cache == 0) s->cache = 8; if (s->pci_lat == 0) s->pci_lat = 0xa8; if (s->cb_lat == 0) s->cb_lat = 0xb0;}/*====================================================================== Power control for Cardbus controllers: used both for 16-bit and Cardbus cards.======================================================================*/static int cb_set_power (socket_info_t * s, socket_state_t * state){ u_int reg = 0; /* restart card voltage detection if it seems appropriate */ if ((state->Vcc == 0) && (state->Vpp == 0) && !(cb_readl (s, CB_SOCKET_STATE) & CB_SS_VSENSE)) cb_writel (s, CB_SOCKET_FORCE, CB_SF_CVSTEST); switch (state->Vcc) { case 0: reg = 0; break; case 33: reg = CB_SC_VCC_3V; break; case 50: reg = CB_SC_VCC_5V; break; default: return -1; } switch (state->Vpp) { case 0: break; case 33: reg |= CB_SC_VPP_3V; break; case 50: reg |= CB_SC_VPP_5V; break; case 120: reg |= CB_SC_VPP_12V; break; default: return -1; } if (reg != cb_readl (s, CB_SOCKET_CONTROL)) cb_writel (s, CB_SOCKET_CONTROL, reg); return 0;}/*====================================================================== Generic routines to get and set controller options======================================================================*/static void get_bridge_state (socket_info_t * s){ ti113x_get_state (s); cb_get_state (s);}static void set_bridge_state (socket_info_t * s){ cb_set_state (s); i365_set (s, I365_GBLCTL, 0x00); i365_set (s, I365_GENCTL, 0x00); ti113x_set_state (s);}static void set_bridge_opts (socket_info_t * s){ ti113x_set_opts (s); cb_set_opts (s);}/*====================================================================*/#define PD67_EXT_INDEX 0x2e /* Extension index */#define PD67_EXT_DATA 0x2f /* Extension data */#define PD67_EXD_VS1(s) (0x01 << ((s)<<1))#define pd67_ext_get(s, r) \ (i365_set(s, PD67_EXT_INDEX, r), i365_get(s, PD67_EXT_DATA))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -