kernel: Remove most definitions of CDEV_MAJOR.
[dragonfly.git] / sys / platform / pc32 / i386 / elan-mmcr.c
1 /*
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  * ----------------------------------------------------------------------------
8  *
9  * $FreeBSD: src/sys/i386/i386/elan-mmcr.c,v 1.6.2.1 2002/09/17 22:39:53 sam Exp $
10  * The AMD Elan sc520 is a system-on-chip gadget which is used in embedded
11  * kind of things, see www.soekris.com for instance, and it has a few quirks
12  * we need to deal with.
13  * Unfortunately we cannot identify the gadget by CPUID output because it
14  * depends on strapping options and only the stepping field may be useful
15  * and those are undocumented from AMDs side.
16  *
17  * So instead we recognize the on-chip host-PCI bridge and call back from
18  * sys/i386/pci/pci_bus.c to here if we find it.
19  */
20
21 #include <sys/param.h>
22 #include <sys/systm.h>
23 #include <sys/kernel.h>
24 #include <sys/conf.h>
25 #include <sys/device.h>
26 #include <sys/proc.h>
27 #include <sys/sysctl.h>
28 #include <sys/time.h>
29
30 #include <machine/md_var.h>
31
32 #include <vm/vm.h>
33 #include <vm/pmap.h>
34
35 uint16_t *elan_mmcr;
36
37 #if 0
38
39 static unsigned
40 elan_get_timecount(struct timecounter *tc)
41 {
42         return (elan_mmcr[0xc84 / 2]);
43 }
44
45 static struct timecounter elan_timecounter = {
46         elan_get_timecount,
47         0,
48         0xffff,
49         33333333 / 4,
50         "ELAN"
51 };
52
53 #endif
54
55 void
56 init_AMD_Elan_sc520(void)
57 {
58         u_int new;
59         int i;
60
61         if (bootverbose)
62                 kprintf("Doing h0h0magic for AMD Elan sc520\n");
63         elan_mmcr = pmap_mapdev(0xfffef000, 0x1000);
64
65         /*-
66          * The i8254 is driven with a nonstandard frequency which is
67          * derived thusly:
68          *   f = 32768 * 45 * 25 / 31 = 1189161.29...
69          * We use the sysctl to get the timecounter etc into whack.
70          */
71         
72         new = 1189161;
73         i = kernel_sysctlbyname("machdep.i8254_freq", 
74             NULL, 0, 
75             &new, sizeof new, 
76             NULL);
77         if (bootverbose)
78                 kprintf("sysctl machdep.i8254_freq=%d returns %d\n", new, i);
79
80 #if 0
81         /* Start GP timer #2 and use it as timecounter, hz permitting */
82         elan_mmcr[0xc82 / 2] = 0xc001;
83         init_timecounter(&elan_timecounter);
84 #endif
85 }
86
87
88 /*
89  * Device driver initialization stuff
90  */
91
92 static d_open_t elan_open;
93 static d_close_t elan_close;
94 static d_ioctl_t elan_ioctl;
95 static d_mmap_t elan_mmap;
96
97 #define CDEV_MAJOR 100
98 static struct dev_ops elan_ops = {
99         { "elan", 0, 0 },
100         .d_open =       elan_open,
101         .d_close =      elan_close,
102         .d_ioctl =      elan_ioctl,
103         .d_mmap =       elan_mmap,
104 };
105
106 static int
107 elan_open(struct dev_open_args *ap)
108 {
109         return (0);
110 }
111
112 static int
113 elan_close(struct dev_close_args *ap)
114
115         return (0);
116 }
117
118 static int
119 elan_mmap(struct dev_mmap_args *ap)
120 {
121         if (ap->a_offset >= 0x1000) 
122                 return (EINVAL);
123         ap->a_result = i386_btop(0xfffef000);
124         return(0);
125 }
126
127 static int
128 elan_ioctl(struct dev_ioctl_args *ap)
129 {
130         return(ENOENT);
131 }
132
133 static void
134 elan_drvinit(void)
135 {
136
137         if (elan_mmcr == NULL)
138                 return;
139         kprintf("Elan-mmcr driver: MMCR at %p\n", elan_mmcr);
140         make_dev(&elan_ops, 0, UID_ROOT, GID_WHEEL, 0600, "elan-mmcr");
141 }
142
143 SYSINIT(elan, SI_SUB_PSEUDO, SI_ORDER_MIDDLE+CDEV_MAJOR,elan_drvinit,NULL);