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.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/ioport.h>
16 #include <asm/geode.h>
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)
35 for (i = 0; i < ARRAY_SIZE(lbars); i++) {
36 rdmsr(lbars[i].msr, lo, hi);
38 lbars[i].base = lo & 0x0000ffff;
40 if (lbars[i].base == 0)
41 printk(KERN_ERR "geode: Couldn't initialize '%s'\n",
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);
62 /* low bank register */
64 outl(gpio & 0xFFFF, base + reg);
65 /* high bank register */
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);
79 /* low bank register */
81 outl((gpio & 0xFFFF) << 16, base + reg);
82 /* high bank register */
83 gpio &= (0xFFFF << 16);
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);
97 /* low bank register */
99 val = inl(base + reg) & (gpio & 0xFFFF);
100 if ((gpio & 0xFFFF) == val)
103 /* high bank register */
106 val = inl(base + 0x80 + reg) & gpio;
112 EXPORT_SYMBOL_GPL(geode_gpio_isset);
114 void geode_gpio_set_irq(unsigned int group, unsigned int irq)
118 if (group > 7 || irq > 15)
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;
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 */
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) {
172 * The VSA has virtual registers that we can query for a
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);
184 EXPORT_SYMBOL_GPL(geode_has_vsa2);
186 static int __init geode_southbridge_init(void)
192 (void) mfgpt_timer_setup();
196 postcore_initcall(geode_southbridge_init);