Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / i2c / xbseeprom.c
blob122e11d1326e49d4af91011b86ba85ff636890c1
1 /* $NetBSD: xbseeprom.c,v 1.5 2008/05/04 15:26:29 xtraeme Exp $ */
3 /*-
4 * Copyright (c) 2007, 2008 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Microsoft XBOX Serial EEPROM
32 * Documentation lives here:
33 * http://www.xbox-linux.org/wiki/Xbox_Serial_EEPROM
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: xbseeprom.c,v 1.5 2008/05/04 15:26:29 xtraeme Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/kmem.h>
43 #include <sys/sysctl.h>
45 #include <dev/i2c/i2cvar.h>
47 static int xbseeprom_match(device_t, cfdata_t, void *);
48 static void xbseeprom_attach(device_t, device_t, void *);
50 struct xbseeprom_data {
51 /* factory settings */
52 uint8_t HMAC_SHA1_Hash[20];
53 uint8_t Confounder[8];
54 uint8_t HDDKkey[16];
55 uint8_t XBERegion[4];
56 uint8_t Checksum2[4];
57 uint8_t SerialNumber[12];
58 uint8_t MACAddress[6];
59 uint8_t UNKNOWN2[2];
60 uint8_t OnlineKey[16];
61 uint8_t VideoStandard[4];
62 uint8_t UNKNOWN3[4];
63 /* user settings */
64 uint8_t Checksum3[4];
65 uint8_t TimeZoneBias[4];
66 uint8_t TimeZoneStdName[4];
67 uint8_t TimeZoneDltName[4];
68 uint8_t UNKNOWN4[8];
69 uint8_t TimeZoneStdDate[4];
70 uint8_t TimeZoneDltDate[4];
71 uint8_t UNKNOWN5[8];
72 uint8_t TimeZoneStdBias[4];
73 uint8_t TimeZoneDltBias[4];
74 uint8_t LanguageID[4];
75 uint8_t VideoFlags[4];
76 uint8_t AudioFlags[4];
77 uint8_t ParentalControlGames[4];
78 uint8_t ParentalControlPwd[4];
79 uint8_t ParentalControlMovies[4];
80 uint8_t XBOXLiveIPAddress[4];
81 uint8_t XBOXLiveDNS[4];
82 uint8_t XBOXLiveGateway[4];
83 uint8_t XBOXLiveSubnetMask[4];
84 uint8_t OtherSettings[4];
85 uint8_t DVDPlaybackKitZone[4];
86 uint8_t UNKNOWN6[64];
89 #define XBSEEPROM_SIZE (sizeof(struct xbseeprom_data))
91 struct xbseeprom_softc {
92 device_t sc_dev;
94 i2c_tag_t sc_tag;
95 i2c_addr_t sc_addr;
97 struct xbseeprom_data *sc_data;
100 static void xbseeprom_read_1(struct xbseeprom_softc *, uint8_t, uint8_t *);
102 static char xbseeprom_serial[17];
104 CFATTACH_DECL_NEW(xbseeprom, sizeof(struct xbseeprom_softc),
105 xbseeprom_match, xbseeprom_attach, NULL, NULL);
107 static int
108 xbseeprom_match(device_t parent, cfdata_t cf, void *opaque)
110 struct i2c_attach_args *ia = opaque;
112 /* Serial EEPROM always lives at 0x54 on Xbox */
113 if (ia->ia_addr == 0x54)
114 return 1;
116 return 0;
119 static void
120 xbseeprom_attach(device_t parent, device_t self, void *opaque)
122 struct xbseeprom_softc *sc = device_private(self);
123 struct i2c_attach_args *ia = opaque;
124 uint8_t *ptr;
125 int i;
127 sc->sc_dev = self;
128 sc->sc_tag = ia->ia_tag;
129 sc->sc_addr = ia->ia_addr;
131 sc->sc_data = kmem_alloc(XBSEEPROM_SIZE, KM_SLEEP);
132 if (sc->sc_data == NULL) {
133 aprint_error(": Not enough memory to copy EEPROM\n");
134 return;
137 aprint_normal(": Xbox Serial EEPROM\n");
139 /* Read in EEPROM contents */
140 ptr = (uint8_t *)sc->sc_data;
141 for (i = 0; i < XBSEEPROM_SIZE; i++, ptr++)
142 xbseeprom_read_1(sc, i, ptr);
144 #if 0
145 /* Display some interesting information */
146 aprint_normal_dev(self, "MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
147 sc->sc_data->MACAddress[0], sc->sc_data->MACAddress[1],
148 sc->sc_data->MACAddress[2], sc->sc_data->MACAddress[3],
149 sc->sc_data->MACAddress[4], sc->sc_data->MACAddress[5]
151 #endif
153 /* Setup sysctl subtree */
154 memset(xbseeprom_serial, 0, sizeof(xbseeprom_serial));
155 memcpy(xbseeprom_serial, sc->sc_data->SerialNumber, 16);
157 sysctl_createv(NULL, 0, NULL, NULL,
158 0, CTLTYPE_STRING, "xbox_serial",
159 SYSCTL_DESCR("Xbox serial number"),
160 NULL, 0, &xbseeprom_serial, 0,
161 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
163 return;
166 static void
167 xbseeprom_read_1(struct xbseeprom_softc *sc, uint8_t cmd, uint8_t *valp)
169 iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
170 sc->sc_addr, &cmd, 1, valp, 1, I2C_F_POLL);