Fri Nov 6 12:50:30 2015 UTC ()
Support Armada XP.


(kiyohara)
diff -r1.1 -r1.2 src/sys/arch/arm/marvell/mvsocts.c

cvs diff -r1.1 -r1.2 src/sys/arch/arm/marvell/mvsocts.c (expand / switch to unified diff)

--- src/sys/arch/arm/marvell/mvsocts.c 2012/08/01 10:34:42 1.1
+++ src/sys/arch/arm/marvell/mvsocts.c 2015/11/06 12:50:30 1.2
@@ -1,73 +1,80 @@ @@ -1,73 +1,80 @@
1/* $NetBSD: mvsocts.c,v 1.1 2012/08/01 10:34:42 kiyohara Exp $ */ 1/* $NetBSD: mvsocts.c,v 1.2 2015/11/06 12:50:30 kiyohara Exp $ */
2/* 2/*
3 * Copyright (c) 2012 KIYOHARA Takashi 3 * Copyright (c) 2012, 2015 KIYOHARA Takashi
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27#include <sys/cdefs.h> 27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: mvsocts.c,v 1.1 2012/08/01 10:34:42 kiyohara Exp $"); 28__KERNEL_RCSID(0, "$NetBSD: mvsocts.c,v 1.2 2015/11/06 12:50:30 kiyohara Exp $");
29 29
30#include <sys/param.h> 30#include <sys/param.h>
31#include <sys/bus.h> 31#include <sys/bus.h>
32#include <sys/device.h> 32#include <sys/device.h>
33#include <sys/errno.h> 33#include <sys/errno.h>
34 34
35#include <dev/sysmon/sysmonvar.h> 35#include <dev/sysmon/sysmonvar.h>
36 36
 37#include <dev/marvell/marvellreg.h>
37#include <dev/marvell/marvellvar.h> 38#include <dev/marvell/marvellvar.h>
38 39
39#define TS_STATUS 0x0 40#define TS_STATUS 0x0
40#define STATUS_VALID (1 << 9) 
41#define STATUS_VAL(v) (((v) >> 10) & 0x1ff) 41#define STATUS_VAL(v) (((v) >> 10) & 0x1ff)
42 42
43#define VAL2MCELSIUS(v) (((322 - (v)) * 10000) / 13625) 
44 
45struct mvsocts_softc { 43struct mvsocts_softc {
46 device_t sc_dev; 44 device_t sc_dev;
47 45
 46 bool (*sc_isvalid)(int);
 47 int (*sc_val2uc)(int);
 48
48 struct sysmon_envsys *sc_sme; 49 struct sysmon_envsys *sc_sme;
49 envsys_data_t sc_sensor; 50 envsys_data_t sc_sensor;
50 51
51 bus_space_tag_t sc_iot; 52 bus_space_tag_t sc_iot;
52 bus_space_handle_t sc_ioh; 53 bus_space_handle_t sc_ioh;
53}; 54};
54 55
55 56
56static int mvsocts_match(device_t, struct cfdata *, void *); 57static int mvsocts_match(device_t, struct cfdata *, void *);
57static void mvsocts_attach(device_t, device_t, void *); 58static void mvsocts_attach(device_t, device_t, void *);
58 59
59static void mvsocts_refresh(struct sysmon_envsys *, envsys_data_t *); 60static void mvsocts_refresh(struct sysmon_envsys *, envsys_data_t *);
60 61
 62static bool mvsocts_isvalid_88f6282(int);
 63static int mvsocts_val2uc_88f6282(int);
 64
 65static bool mvsocts_isvalid_armada(int);
 66static int mvsocts_val2uc_armada(int);
 67
61CFATTACH_DECL_NEW(mvsocts, sizeof(struct mvsocts_softc), 68CFATTACH_DECL_NEW(mvsocts, sizeof(struct mvsocts_softc),
62 mvsocts_match, mvsocts_attach, NULL, NULL); 69 mvsocts_match, mvsocts_attach, NULL, NULL);
63 70
64 71
65/* ARGSUSED */ 72/* ARGSUSED */
66static int 73static int
67mvsocts_match(device_t parent, struct cfdata *match, void *aux) 74mvsocts_match(device_t parent, struct cfdata *match, void *aux)
68{ 75{
69 struct marvell_attach_args *mva = aux; 76 struct marvell_attach_args *mva = aux;
70 77
71 if (strcmp(mva->mva_name, match->cf_name) != 0) 78 if (strcmp(mva->mva_name, match->cf_name) != 0)
72 return 0; 79 return 0;
73 return 1; 80 return 1;
@@ -79,51 +86,103 @@ mvsocts_attach(device_t parent, device_t @@ -79,51 +86,103 @@ mvsocts_attach(device_t parent, device_t
79{ 86{
80 struct mvsocts_softc *sc = device_private(self); 87 struct mvsocts_softc *sc = device_private(self);
81 struct marvell_attach_args *mva = aux; 88 struct marvell_attach_args *mva = aux;
82 89
83 aprint_naive("\n"); 90 aprint_naive("\n");
84 aprint_normal(": Marvell SoC Thermal Sensor\n"); 91 aprint_normal(": Marvell SoC Thermal Sensor\n");
85 92
86 sc->sc_dev = self; 93 sc->sc_dev = self;
87 sc->sc_iot = mva->mva_iot; 94 sc->sc_iot = mva->mva_iot;
88 if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, 95 if (bus_space_subregion(mva->mva_iot, mva->mva_ioh,
89 mva->mva_offset, sizeof(uint32_t), &sc->sc_ioh)) 96 mva->mva_offset, sizeof(uint32_t), &sc->sc_ioh))
90 panic("%s: Cannot map registers", device_xname(self)); 97 panic("%s: Cannot map registers", device_xname(self));
91 98
 99 switch (mva->mva_model) {
 100 case MARVELL_KIRKWOOD_88F6282:
 101 sc->sc_isvalid = mvsocts_isvalid_88f6282;
 102 sc->sc_val2uc = mvsocts_val2uc_88f6282;
 103 break;
 104 case MARVELL_ARMADAXP_MV78130:
 105 case MARVELL_ARMADAXP_MV78160:
 106 case MARVELL_ARMADAXP_MV78230:
 107 case MARVELL_ARMADAXP_MV78260:
 108 case MARVELL_ARMADAXP_MV78460:
 109/*
 110 case MARVELL_ARMADA370_MV6707:
 111 case MARVELL_ARMADA370_MV6710:
 112 case MARVELL_ARMADA370_MV6W11:
 113 */
 114 sc->sc_isvalid = mvsocts_isvalid_armada;
 115 sc->sc_val2uc = mvsocts_val2uc_armada;
 116 break;
 117
 118 default:
 119 aprint_error_dev(self, "unknwon model: 0x%x", mva->mva_model);
 120 return;
 121 }
 122
92 sc->sc_sme = sysmon_envsys_create(); 123 sc->sc_sme = sysmon_envsys_create();
93 /* Initialize sensor data. */ 124 /* Initialize sensor data. */
94 sc->sc_sensor.units = ENVSYS_STEMP; 125 sc->sc_sensor.units = ENVSYS_STEMP;
95 sc->sc_sensor.state = ENVSYS_SINVALID; 126 sc->sc_sensor.state = ENVSYS_SINVALID;
96 strlcpy(sc->sc_sensor.desc, device_xname(self), 127 strlcpy(sc->sc_sensor.desc, device_xname(self),
97 sizeof(sc->sc_sensor.desc)); 128 sizeof(sc->sc_sensor.desc));
98 if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor)) { 129 if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor)) {
99 aprint_error_dev(self, "Unable to attach sysmon\n"); 130 aprint_error_dev(self, "Unable to attach sysmon\n");
100 sysmon_envsys_destroy(sc->sc_sme); 131 sysmon_envsys_destroy(sc->sc_sme);
101 return; 132 return;
102 } 133 }
103 134
104 /* Hook into system monitor. */ 135 /* Hook into system monitor. */
105 sc->sc_sme->sme_name = device_xname(self); 136 sc->sc_sme->sme_name = device_xname(self);
106 sc->sc_sme->sme_cookie = sc; 137 sc->sc_sme->sme_cookie = sc;
107 sc->sc_sme->sme_refresh = mvsocts_refresh; 138 sc->sc_sme->sme_refresh = mvsocts_refresh;
108 if (sysmon_envsys_register(sc->sc_sme)) { 139 if (sysmon_envsys_register(sc->sc_sme)) {
109 aprint_error_dev(self, "Unable to register with sysmon\n"); 140 aprint_error_dev(self, "Unable to register with sysmon\n");
110 sysmon_envsys_destroy(sc->sc_sme); 141 sysmon_envsys_destroy(sc->sc_sme);
111 } 142 }
112} 143}
113 144
114static void 145static void
115mvsocts_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) 146mvsocts_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
116{ 147{
117 struct mvsocts_softc *sc = sme->sme_cookie; 148 struct mvsocts_softc *sc = sme->sme_cookie;
118 uint32_t val, uc, uk; 149 uint32_t val, uc, uk;
119 150
120 val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, TS_STATUS); 151 val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, TS_STATUS);
121 if (!(val & STATUS_VALID)) { 152 if (!sc->sc_isvalid(val)) {
122 aprint_error_dev(sc->sc_dev, "status value is invalid\n"); 153 aprint_error_dev(sc->sc_dev, "status value is invalid\n");
123 return; 154 return;
124 } 155 }
125 uc = VAL2MCELSIUS(STATUS_VAL(val)) * 1000000; /* uC */ 156 uc = sc->sc_val2uc(STATUS_VAL(val)); /* uC */
126 uk = uc + 273150000; /* convert to uKelvin */ 157 uk = uc + 273150000; /* convert to uKelvin */
127 sc->sc_sensor.value_cur = uk; 158 sc->sc_sensor.value_cur = uk;
128 sc->sc_sensor.state = ENVSYS_SVALID; 159 sc->sc_sensor.state = ENVSYS_SVALID;
129} 160}
 161
 162static bool
 163mvsocts_isvalid_88f6282(int v)
 164{
 165
 166 return (v & (1 << 9)) != 0;
 167}
 168
 169static int
 170mvsocts_val2uc_88f6282(int v)
 171{
 172
 173 return (322 - v) * 10 * 1000000 / 13625 * 1000;
 174}
 175
 176static bool
 177mvsocts_isvalid_armada(int v)
 178{
 179
 180 return (v & (1 << 0)) != 0;
 181}
 182
 183static int
 184mvsocts_val2uc_armada(int v)
 185{
 186
 187 return (3153 - v * 10) * 1000000 / 13825 * 1000;
 188}