Device layer rollup commit.
[dragonfly.git] / sys / i386 / i386 / elan-mmcr.c
CommitLineData
984263bc
MD
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 $
e4c9c0c8 10 * $DragonFly: src/sys/i386/i386/Attic/elan-mmcr.c,v 1.7 2004/05/19 22:52:57 dillon Exp $
984263bc
MD
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.
17 *
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.
20 */
21
22#include <sys/param.h>
23#include <sys/systm.h>
24#include <sys/kernel.h>
25#include <sys/conf.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
35uint16_t *elan_mmcr;
36
88c4d2f6 37#if 0
984263bc
MD
38
39static unsigned
40elan_get_timecount(struct timecounter *tc)
41{
42 return (elan_mmcr[0xc84 / 2]);
43}
44
45static struct timecounter elan_timecounter = {
46 elan_get_timecount,
47 0,
48 0xffff,
49 33333333 / 4,
50 "ELAN"
51};
52
88c4d2f6
MD
53#endif
54
984263bc
MD
55void
56init_AMD_Elan_sc520(void)
57{
58 u_int new;
59 int i;
60
61 if (bootverbose)
62 printf("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;
7b95be2a 73 i = kernel_sysctlbyname("machdep.i8254_freq",
984263bc
MD
74 NULL, 0,
75 &new, sizeof new,
76 NULL);
77 if (bootverbose)
78 printf("sysctl machdep.i8254_freq=%d returns %d\n", new, i);
79
88c4d2f6 80#if 0
984263bc
MD
81 /* Start GP timer #2 and use it as timecounter, hz permitting */
82 elan_mmcr[0xc82 / 2] = 0xc001;
83 init_timecounter(&elan_timecounter);
88c4d2f6 84#endif
984263bc
MD
85}
86
87
88/*
89 * Device driver initialization stuff
90 */
91
92static d_open_t elan_open;
93static d_close_t elan_close;
94static d_ioctl_t elan_ioctl;
95static d_mmap_t elan_mmap;
96
97#define CDEV_MAJOR 100 /* Share with xrpu */
98static struct cdevsw elan_cdevsw = {
fabb8ceb
MD
99 /* name */ "elan",
100 /* maj */ CDEV_MAJOR,
101 /* flags */ 0,
102 /* port */ NULL,
455fcd7e 103 /* clone */ NULL,
fabb8ceb 104
984263bc
MD
105 /* open */ elan_open,
106 /* close */ elan_close,
107 /* read */ noread,
108 /* write */ nowrite,
109 /* ioctl */ elan_ioctl,
110 /* poll */ nopoll,
111 /* mmap */ elan_mmap,
112 /* strategy */ nostrategy,
984263bc 113 /* dump */ nodump,
fabb8ceb 114 /* psize */ nopsize
984263bc
MD
115};
116
117static int
7b95be2a 118elan_open(dev_t dev, int flag, int mode, struct thread *td)
984263bc
MD
119{
120 return (0);
121}
122
123static int
7b95be2a 124elan_close(dev_t dev, int flag, int mode, struct thread *td)
984263bc
MD
125{
126 return (0);
127}
128
129static int
130elan_mmap(dev_t dev, vm_offset_t offset, int nprot)
131{
132 if (offset >= 0x1000)
133 return (-1);
134 return (i386_btop(0xfffef000));
135}
136
137static int
7b95be2a 138elan_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
984263bc
MD
139{
140 return(ENOENT);
141}
142
143static void
144elan_drvinit(void)
145{
146
147 if (elan_mmcr == NULL)
148 return;
149 printf("Elan-mmcr driver: MMCR at %p\n", elan_mmcr);
e4c9c0c8 150 cdevsw_add(&elan_cdevsw, 0, 0);
984263bc
MD
151 make_dev(&elan_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "elan-mmcr");
152 return;
153}
154
155SYSINIT(elan, SI_SUB_PSEUDO, SI_ORDER_MIDDLE+CDEV_MAJOR,elan_drvinit,NULL);