2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
9 * $FreeBSD: src/sys/i386/i386/elan-mmcr.c,v 1.6.2.1 2002/09/17 22:39:53 sam Exp $
10 * $DragonFly: src/sys/platform/pc32/i386/elan-mmcr.c,v 1.9 2006/12/23 00:27:03 swildner Exp $
11 * The AMD Elan sc520 is a system-on-chip gadget which is used in embedded
12 * kind of things, see www.soekris.com for instance, and it has a few quirks
13 * we need to deal with.
14 * Unfortunately we cannot identify the gadget by CPUID output because it
15 * depends on strapping options and only the stepping field may be useful
16 * and those are undocumented from AMDs side.
18 * So instead we recognize the on-chip host-PCI bridge and call back from
19 * sys/i386/pci/pci_bus.c to here if we find it.
22 #include <sys/param.h>
23 #include <sys/systm.h>
24 #include <sys/kernel.h>
26 #include <sys/device.h>
28 #include <sys/sysctl.h>
31 #include <machine/md_var.h>
41 elan_get_timecount(struct timecounter *tc)
43 return (elan_mmcr[0xc84 / 2]);
46 static struct timecounter elan_timecounter = {
57 init_AMD_Elan_sc520(void)
63 kprintf("Doing h0h0magic for AMD Elan sc520\n");
64 elan_mmcr = pmap_mapdev(0xfffef000, 0x1000);
67 * The i8254 is driven with a nonstandard frequency which is
69 * f = 32768 * 45 * 25 / 31 = 1189161.29...
70 * We use the sysctl to get the timecounter etc into whack.
74 i = kernel_sysctlbyname("machdep.i8254_freq",
79 kprintf("sysctl machdep.i8254_freq=%d returns %d\n", new, i);
82 /* Start GP timer #2 and use it as timecounter, hz permitting */
83 elan_mmcr[0xc82 / 2] = 0xc001;
84 init_timecounter(&elan_timecounter);
90 * Device driver initialization stuff
93 static d_open_t elan_open;
94 static d_close_t elan_close;
95 static d_ioctl_t elan_ioctl;
96 static d_mmap_t elan_mmap;
98 #define CDEV_MAJOR 100 /* Share with xrpu */
99 static struct dev_ops elan_ops = {
100 { "elan", CDEV_MAJOR, 0 },
102 .d_close = elan_close,
103 .d_ioctl = elan_ioctl,
108 elan_open(struct dev_open_args *ap)
114 elan_close(struct dev_close_args *ap)
120 elan_mmap(struct dev_mmap_args *ap)
122 if (ap->a_offset >= 0x1000)
124 ap->a_result = i386_btop(0xfffef000);
129 elan_ioctl(struct dev_ioctl_args *ap)
138 if (elan_mmcr == NULL)
140 kprintf("Elan-mmcr driver: MMCR at %p\n", elan_mmcr);
141 dev_ops_add(&elan_ops, 0, 0);
142 make_dev(&elan_ops, 0, UID_ROOT, GID_WHEEL, 0600, "elan-mmcr");
146 SYSINIT(elan, SI_SUB_PSEUDO, SI_ORDER_MIDDLE+CDEV_MAJOR,elan_drvinit,NULL);