| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: awin_sysconfig.c,v 1.2 2015/10/25 20:46:46 bouyer Exp $ */ | | 1 | /* $NetBSD: awin_sysconfig.c,v 1.3 2017/03/08 17:06:35 jakllsch Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -19,27 +19,27 @@ | | | @@ -19,27 +19,27 @@ |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include "opt_allwinner.h" | | 29 | #include "opt_allwinner.h" |
30 | | | 30 | |
31 | #include <sys/cdefs.h> | | 31 | #include <sys/cdefs.h> |
32 | __KERNEL_RCSID(0, "$NetBSD: awin_sysconfig.c,v 1.2 2015/10/25 20:46:46 bouyer Exp $"); | | 32 | __KERNEL_RCSID(0, "$NetBSD: awin_sysconfig.c,v 1.3 2017/03/08 17:06:35 jakllsch Exp $"); |
33 | | | 33 | |
34 | #include <sys/param.h> | | 34 | #include <sys/param.h> |
35 | #include <sys/bus.h> | | 35 | #include <sys/bus.h> |
36 | #include <sys/device.h> | | 36 | #include <sys/device.h> |
37 | #include <sys/intr.h> | | 37 | #include <sys/intr.h> |
38 | #include <sys/systm.h> | | 38 | #include <sys/systm.h> |
39 | #include <sys/kernel.h> | | 39 | #include <sys/kernel.h> |
40 | | | 40 | |
41 | #include <machine/bootconfig.h> | | 41 | #include <machine/bootconfig.h> |
42 | | | 42 | |
43 | #include <arm/allwinner/awin_reg.h> | | 43 | #include <arm/allwinner/awin_reg.h> |
44 | #include <arm/allwinner/awin_var.h> | | 44 | #include <arm/allwinner/awin_var.h> |
45 | | | 45 | |
| @@ -80,38 +80,47 @@ struct awin_sysconfig_gpio { | | | @@ -80,38 +80,47 @@ struct awin_sysconfig_gpio { |
80 | uint32_t port_num; | | 80 | uint32_t port_num; |
81 | int32_t mul_sel; | | 81 | int32_t mul_sel; |
82 | int32_t pull; | | 82 | int32_t pull; |
83 | int32_t drv_level; | | 83 | int32_t drv_level; |
84 | int32_t data; | | 84 | int32_t data; |
85 | } __packed; | | 85 | } __packed; |
86 | | | 86 | |
87 | static bool awin_sysconfig_parse(const char *, const char *, | | 87 | static bool awin_sysconfig_parse(const char *, const char *, |
88 | struct awin_sysconfig_sub_key *); | | 88 | struct awin_sysconfig_sub_key *); |
89 | | | 89 | |
90 | bool | | 90 | bool |
91 | awin_sysconfig_init(void) | | 91 | awin_sysconfig_init(void) |
92 | { | | 92 | { |
| | | 93 | struct awin_sysconfig_head head; |
| | | 94 | |
93 | if (get_bootconf_option(boot_args, "sysconfig", | | 95 | if (get_bootconf_option(boot_args, "sysconfig", |
94 | BOOTOPT_TYPE_HEXINT, &awin_sysconfig_base) == 0) { | | 96 | BOOTOPT_TYPE_HEXINT, &awin_sysconfig_base) == 0) { |
95 | return false; | | 97 | return false; |
96 | } | | 98 | } |
97 | if (awin_sysconfig_base == 0) { | | 99 | if (awin_sysconfig_base == 0) { |
98 | return false; | | 100 | return false; |
99 | } | | 101 | } |
100 | | | 102 | |
101 | const uint8_t * const sysconfig = (const uint8_t *) | | 103 | const uint8_t * const sysconfig = (const uint8_t *) |
102 | (awin_sysconfig_base + KERNEL_BASE_VOFFSET); | | 104 | (awin_sysconfig_base + KERNEL_BASE_VOFFSET); |
103 | memcpy(awin_sysconfig, sysconfig, AWIN_SYSCONFIG_SIZE); | | 105 | memcpy(awin_sysconfig, sysconfig, AWIN_SYSCONFIG_SIZE); |
104 | | | 106 | |
| | | 107 | memcpy(&head, &awin_sysconfig[0], sizeof(head)); |
| | | 108 | if (head.count >= 0x01000000) { |
| | | 109 | printf("%s(): 0x%x entries in sysconfig, ignoring.\n", |
| | | 110 | __func__, head.count); |
| | | 111 | return false; |
| | | 112 | } |
| | | 113 | |
105 | return true; | | 114 | return true; |
106 | } | | 115 | } |
107 | | | 116 | |
108 | static bool | | 117 | static bool |
109 | awin_sysconfig_parse(const char *key, const char *subkey, | | 118 | awin_sysconfig_parse(const char *key, const char *subkey, |
110 | struct awin_sysconfig_sub_key *value) | | 119 | struct awin_sysconfig_sub_key *value) |
111 | { | | 120 | { |
112 | struct awin_sysconfig_head head; | | 121 | struct awin_sysconfig_head head; |
113 | struct awin_sysconfig_main_key main_key; | | 122 | struct awin_sysconfig_main_key main_key; |
114 | struct awin_sysconfig_sub_key sub_key; | | 123 | struct awin_sysconfig_sub_key sub_key; |
115 | unsigned int off, n; | | 124 | unsigned int off, n; |
116 | | | 125 | |
117 | KASSERT(awin_sysconfig_base != 0); | | 126 | KASSERT(awin_sysconfig_base != 0); |