x86: make 32bit support per_cpu vector
[linux-2.6/mini2440.git] / arch / x86 / kernel / geode_32.c
blob9b08e852fd1ae63d3312552dd6898622ee4fd73b
1 /*
2 * AMD Geode southbridge support code
3 * Copyright (C) 2006, Advanced Micro Devices, Inc.
4 * Copyright (C) 2007, Andres Salomon <dilinger@debian.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
9 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/ioport.h>
14 #include <linux/io.h>
15 #include <asm/msr.h>
16 #include <asm/geode.h>
18 static struct {
19 char *name;
20 u32 msr;
21 int size;
22 u32 base;
23 } lbars[] = {
24 { "geode-pms", MSR_LBAR_PMS, LBAR_PMS_SIZE, 0 },
25 { "geode-acpi", MSR_LBAR_ACPI, LBAR_ACPI_SIZE, 0 },
26 { "geode-gpio", MSR_LBAR_GPIO, LBAR_GPIO_SIZE, 0 },
27 { "geode-mfgpt", MSR_LBAR_MFGPT, LBAR_MFGPT_SIZE, 0 }
30 static void __init init_lbars(void)
32 u32 lo, hi;
33 int i;
35 for (i = 0; i < ARRAY_SIZE(lbars); i++) {
36 rdmsr(lbars[i].msr, lo, hi);
37 if (hi & 0x01)
38 lbars[i].base = lo & 0x0000ffff;
40 if (lbars[i].base == 0)
41 printk(KERN_ERR "geode: Couldn't initialize '%s'\n",
42 lbars[i].name);
46 int geode_get_dev_base(unsigned int dev)
48 BUG_ON(dev >= ARRAY_SIZE(lbars));
49 return lbars[dev].base;
51 EXPORT_SYMBOL_GPL(geode_get_dev_base);
53 /* === GPIO API === */
55 void geode_gpio_set(u32 gpio, unsigned int reg)
57 u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
59 if (!base)
60 return;
62 /* low bank register */
63 if (gpio & 0xFFFF)
64 outl(gpio & 0xFFFF, base + reg);
65 /* high bank register */
66 gpio >>= 16;
67 if (gpio)
68 outl(gpio, base + 0x80 + reg);
70 EXPORT_SYMBOL_GPL(geode_gpio_set);
72 void geode_gpio_clear(u32 gpio, unsigned int reg)
74 u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
76 if (!base)
77 return;
79 /* low bank register */
80 if (gpio & 0xFFFF)
81 outl((gpio & 0xFFFF) << 16, base + reg);
82 /* high bank register */
83 gpio &= (0xFFFF << 16);
84 if (gpio)
85 outl(gpio, base + 0x80 + reg);
87 EXPORT_SYMBOL_GPL(geode_gpio_clear);
89 int geode_gpio_isset(u32 gpio, unsigned int reg)
91 u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
92 u32 val;
94 if (!base)
95 return 0;
97 /* low bank register */
98 if (gpio & 0xFFFF) {
99 val = inl(base + reg) & (gpio & 0xFFFF);
100 if ((gpio & 0xFFFF) == val)
101 return 1;
103 /* high bank register */
104 gpio >>= 16;
105 if (gpio) {
106 val = inl(base + 0x80 + reg) & gpio;
107 if (gpio == val)
108 return 1;
110 return 0;
112 EXPORT_SYMBOL_GPL(geode_gpio_isset);
114 void geode_gpio_set_irq(unsigned int group, unsigned int irq)
116 u32 lo, hi;
118 if (group > 7 || irq > 15)
119 return;
121 rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
123 lo &= ~(0xF << (group * 4));
124 lo |= (irq & 0xF) << (group * 4);
126 wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
128 EXPORT_SYMBOL_GPL(geode_gpio_set_irq);
130 void geode_gpio_setup_event(unsigned int gpio, int pair, int pme)
132 u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
133 u32 offset, shift, val;
135 if (gpio >= 24)
136 offset = GPIO_MAP_W;
137 else if (gpio >= 16)
138 offset = GPIO_MAP_Z;
139 else if (gpio >= 8)
140 offset = GPIO_MAP_Y;
141 else
142 offset = GPIO_MAP_X;
144 shift = (gpio % 8) * 4;
146 val = inl(base + offset);
148 /* Clear whatever was there before */
149 val &= ~(0xF << shift);
151 /* And set the new value */
153 val |= ((pair & 7) << shift);
155 /* Set the PME bit if this is a PME event */
157 if (pme)
158 val |= (1 << (shift + 3));
160 outl(val, base + offset);
162 EXPORT_SYMBOL_GPL(geode_gpio_setup_event);
164 int geode_has_vsa2(void)
166 static int has_vsa2 = -1;
168 if (has_vsa2 == -1) {
169 u16 val;
172 * The VSA has virtual registers that we can query for a
173 * signature.
175 outw(VSA_VR_UNLOCK, VSA_VRC_INDEX);
176 outw(VSA_VR_SIGNATURE, VSA_VRC_INDEX);
178 val = inw(VSA_VRC_DATA);
179 has_vsa2 = (val == AMD_VSA_SIG || val == GSW_VSA_SIG);
182 return has_vsa2;
184 EXPORT_SYMBOL_GPL(geode_has_vsa2);
186 static int __init geode_southbridge_init(void)
188 if (!is_geode())
189 return -ENODEV;
191 init_lbars();
192 (void) mfgpt_timer_setup();
193 return 0;
196 postcore_initcall(geode_southbridge_init);