xref: /openbsd/sys/arch/loongson/dev/leioc.c (revision e5dd7070)
1 /*	$OpenBSD: leioc.c,v 1.1 2016/11/17 14:41:21 visa Exp $	*/
2 
3 /*
4  * Copyright (c) 2016 Visa Hankala
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * Driver for the Loongson 3A low-end IO controller.
21  *
22  * Each Loongson 3A CPU package has a built-in `low-end' IO controller.
23  * The controller provides GPIO, LPCI, PCI, SPI, and UART interfaces.
24  */
25 
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/device.h>
29 #include <sys/kernel.h>
30 
31 #include <machine/autoconf.h>
32 
33 #include <loongson/dev/leiocreg.h>
34 #include <loongson/dev/leiocvar.h>
35 
36 int	leioc_match(struct device *, void *, void*);
37 void	leioc_attach(struct device *, struct device *, void *);
38 
39 const struct cfattach leioc_ca = {
40 	sizeof(struct device), leioc_match, leioc_attach
41 };
42 
43 struct cfdriver leioc_cd = {
44 	NULL, "leioc", DV_DULL
45 };
46 
47 struct mips_bus_space leioc_io_space_tag = {
48 	.bus_base = PHYS_TO_XKPHYS(0, CCA_NC),
49 	._space_read_1 = generic_space_read_1,
50 	._space_write_1 = generic_space_write_1,
51 	._space_map = generic_space_map,
52 	._space_unmap = generic_space_unmap
53 };
54 
55 int
56 leioc_match(struct device *parent, void *cfg, void *aux)
57 {
58 	struct mainbus_attach_args *maa = aux;
59 
60 	if (loongson_ver != 0x3a && loongson_ver != 0x3b)
61 		return 0;
62 
63 	if (strcmp(maa->maa_name, leioc_cd.cd_name) != 0)
64 		return 0;
65 
66 	return 1;
67 }
68 
69 void
70 leioc_attach(struct device *parent, struct device *self, void *aux)
71 {
72 	struct leioc_attach_args laa;
73 
74 	printf("\n");
75 
76 	laa.laa_name = "com";
77 	laa.laa_iot = &leioc_io_space_tag;
78 	laa.laa_base = LEIOC_UART0_BASE;
79 	config_found(self, &laa, NULL);
80 	laa.laa_base = LEIOC_UART1_BASE;
81 	config_found(self, &laa, NULL);
82 }
83