sync hh.org
[hh.org.git] / arch / arm / mach-sa1100 / ipaq-mtd-asset.c
blob3b530722090fe6728b6eba70f5b5aeb7412e88ae
1 /*
2 * Access to iPAQ Asset Information store in flash
4 * Copyright 2001,2002,2003 Compaq Computer Corporation.
6 * Use consistent with the GNU GPL is permitted,
7 * provided that this copyright notice is
8 * preserved in its entirety in all copies and derived works.
10 * COMPAQ COMPUTER CORPORATION MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
11 * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
12 * FITNESS FOR ANY PARTICULAR PURPOSE.
14 * Author: Andrew Christian
15 * <Andrew.Christian@compaq.com>
16 * October 2001
18 * Restrutured June 2002
20 * Moved into separate modules March 2003
21 * Jamey Hicks <jamey.hicks@hp.com>
24 #include <linux/module.h>
25 #include <linux/version.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/mtd/mtd.h>
30 #include <linux/ctype.h>
31 #include <asm/arch/hardware.h>
32 #include <asm/arch-sa1100/h3600_hal.h>
33 #include <asm/arch-sa1100/h3600_asic.h>
35 /***********************************************************************************
36 * Assets
37 ***********************************************************************************/
39 struct mtd_info *g_asset_mtd;
41 #if 0 /* dead code */
42 #define DUMP_BUF_SIZE 16
43 #define MYPRINTABLE(x) \
44 ( ((x)<='z' && (x)>='a') || ((x)<='Z' && (x)>='A') || isdigit(x))
46 static void dump_mem( struct mtd_info *mtd, loff_t from, size_t count )
48 size_t retlen;
49 u_char buf[DUMP_BUF_SIZE];
50 u_char pbuf[DUMP_BUF_SIZE + 1];
52 int ret;
53 size_t len;
54 int i;
56 printk(__FUNCTION__ ": dumping 0x%08X, len %dd\n", from, count);
57 while ( count ) {
58 len = count;
59 if ( len > DUMP_BUF_SIZE )
60 len = DUMP_BUF_SIZE;
62 ret = mtd->read( mtd, from, len, &retlen, buf );
63 if (!ret) {
64 for ( i = 0 ; i < retlen ; i++ ) {
65 printk(" %02x", buf[i]);
66 pbuf[i] = ( MYPRINTABLE(buf[i]) ? buf[i] : '.' );
67 from++;
68 count--;
69 if ( (from % DUMP_BUF_SIZE) == 0 ) {
70 pbuf[i+1] = '\0';
71 printk(" %s\n", pbuf);
75 else {
76 printk(__FUNCTION__ ": error %d reading at %d, count=%d", ret,from,count);
77 return;
82 #endif /* dead code */
85 static int copytchar( struct mtd_info *mtd, unsigned char *dest, loff_t from, size_t count )
87 size_t retlen;
89 if (0) printk("%s: %p %lld %u\n", __FUNCTION__, dest, from, count );
91 while ( count ) {
92 int ret = mtd->read( mtd, from, count, &retlen, dest );
93 if (!ret) {
94 count -= retlen;
95 dest += retlen;
96 from += retlen;
98 else {
99 printk("%s: error %d reading at %lld, count=%d\n", __FUNCTION__, ret, from, count );
100 return ret;
103 return 0;
106 static int copyword( struct mtd_info *mtd, unsigned short *dest, loff_t from )
108 unsigned char buf[2];
109 int ret = copytchar( mtd, buf, from, 2 );
110 if ( ret )
111 return ret;
112 *dest = (((unsigned short) buf[1]) << 8 | (unsigned short) buf[0]);
113 return 0;
116 #define COPYTCHAR(_p,_offset,_len) \
117 ( g_asset_mtd ? \
118 copytchar( g_asset_mtd, _p, _offset + 0x30000, _len ) \
119 : 0)
121 #define COPYWORD(_w,_offset) \
122 ( g_asset_mtd ? \
123 copyword( g_asset_mtd, &_w, _offset + 0x30000 ) \
124 : 0)
126 int ipaq_mtd_asset_read( struct h3600_asset *asset )
128 int retval = -1;
130 if (0) printk("%s\n", __FUNCTION__);
132 switch (asset->type) {
133 case ASSET_HM_VERSION:
134 retval = COPYTCHAR( asset->a.tchar, 0, 10 );
135 break;
136 case ASSET_SERIAL_NUMBER:
137 retval = COPYTCHAR( asset->a.tchar, 10, 40 );
138 break;
139 case ASSET_MODULE_ID:
140 retval = COPYTCHAR( asset->a.tchar, 152, 20 );
141 break;
142 case ASSET_PRODUCT_REVISION:
143 retval = COPYTCHAR( asset->a.tchar, 182, 10 );
144 break;
145 case ASSET_PRODUCT_ID:
146 retval = COPYWORD( asset->a.vshort, 110 );
147 break;
148 case ASSET_FRAME_RATE:
149 retval = COPYWORD( asset->a.vshort, 966 );
150 break;
151 case ASSET_PAGE_MODE:
152 retval = COPYWORD( asset->a.vshort, 976 );
153 break;
154 case ASSET_COUNTRY_ID:
155 retval = COPYWORD( asset->a.vshort, 980 );
156 break;
157 case ASSET_IS_COLOR_DISPLAY:
158 retval = COPYWORD( asset->a.vshort, 292 );
159 break;
160 case ASSET_ROM_SIZE:
161 retval = COPYWORD( asset->a.vshort, 1514 );
162 break;
163 case ASSET_RAM_SIZE:
164 asset->a.vshort = 0;
165 retval = 0;
166 break;
167 case ASSET_HORIZONTAL_PIXELS:
168 retval = COPYWORD( asset->a.vshort, 276 );
169 break;
170 case ASSET_VERTICAL_PIXELS:
171 retval = COPYWORD( asset->a.vshort, 278 );
172 break;
175 return retval;
179 int ipaq_mtd_asset_init( void )
181 int i;
182 struct mtd_info *mtd;
184 for ( i = MAX_MTD_DEVICES-1 ; i >= 0 ; i-- ) {
185 if ( (mtd = get_mtd_device( NULL, i )) != NULL ) {
186 if (strstr(mtd->name, "asset" )) {
187 g_asset_mtd = mtd;
188 return 0;
190 else {
191 put_mtd_device(mtd);
195 return 0;
198 void ipaq_mtd_asset_cleanup( void )
200 if ( g_asset_mtd )
201 put_mtd_device(g_asset_mtd);
204 module_init(ipaq_mtd_asset_init)
205 module_exit(ipaq_mtd_asset_cleanup)
207 MODULE_AUTHOR("Andrew Christian <andyc@handhelds.org>, Jamey Hicks <jamey@handhelds.org>");
208 MODULE_DESCRIPTION("Driver for Compaq iPAQ asset tags stored in MTD flash partitions");
209 MODULE_LICENSE("Dual BSD/GPL");