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>
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 /***********************************************************************************
37 ***********************************************************************************/
39 struct mtd_info
*g_asset_mtd
;
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
)
49 u_char buf
[DUMP_BUF_SIZE
];
50 u_char pbuf
[DUMP_BUF_SIZE
+ 1];
56 printk(__FUNCTION__
": dumping 0x%08X, len %dd\n", from
, count
);
59 if ( len
> DUMP_BUF_SIZE
)
62 ret
= mtd
->read( mtd
, from
, len
, &retlen
, buf
);
64 for ( i
= 0 ; i
< retlen
; i
++ ) {
65 printk(" %02x", buf
[i
]);
66 pbuf
[i
] = ( MYPRINTABLE(buf
[i
]) ? buf
[i
] : '.' );
69 if ( (from
% DUMP_BUF_SIZE
) == 0 ) {
71 printk(" %s\n", pbuf
);
76 printk(__FUNCTION__
": error %d reading at %d, count=%d", ret
,from
,count
);
82 #endif /* dead code */
85 static int copytchar( struct mtd_info
*mtd
, unsigned char *dest
, loff_t from
, size_t count
)
89 if (0) printk("%s: %p %lld %u\n", __FUNCTION__
, dest
, from
, count
);
92 int ret
= mtd
->read( mtd
, from
, count
, &retlen
, dest
);
99 printk("%s: error %d reading at %lld, count=%d\n", __FUNCTION__
, ret
, from
, count
);
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 );
112 *dest
= (((unsigned short) buf
[1]) << 8 | (unsigned short) buf
[0]);
116 #define COPYTCHAR(_p,_offset,_len) \
118 copytchar( g_asset_mtd, _p, _offset + 0x30000, _len ) \
121 #define COPYWORD(_w,_offset) \
123 copyword( g_asset_mtd, &_w, _offset + 0x30000 ) \
126 int ipaq_mtd_asset_read( struct h3600_asset
*asset
)
130 if (0) printk("%s\n", __FUNCTION__
);
132 switch (asset
->type
) {
133 case ASSET_HM_VERSION
:
134 retval
= COPYTCHAR( asset
->a
.tchar
, 0, 10 );
136 case ASSET_SERIAL_NUMBER
:
137 retval
= COPYTCHAR( asset
->a
.tchar
, 10, 40 );
139 case ASSET_MODULE_ID
:
140 retval
= COPYTCHAR( asset
->a
.tchar
, 152, 20 );
142 case ASSET_PRODUCT_REVISION
:
143 retval
= COPYTCHAR( asset
->a
.tchar
, 182, 10 );
145 case ASSET_PRODUCT_ID
:
146 retval
= COPYWORD( asset
->a
.vshort
, 110 );
148 case ASSET_FRAME_RATE
:
149 retval
= COPYWORD( asset
->a
.vshort
, 966 );
151 case ASSET_PAGE_MODE
:
152 retval
= COPYWORD( asset
->a
.vshort
, 976 );
154 case ASSET_COUNTRY_ID
:
155 retval
= COPYWORD( asset
->a
.vshort
, 980 );
157 case ASSET_IS_COLOR_DISPLAY
:
158 retval
= COPYWORD( asset
->a
.vshort
, 292 );
161 retval
= COPYWORD( asset
->a
.vshort
, 1514 );
167 case ASSET_HORIZONTAL_PIXELS
:
168 retval
= COPYWORD( asset
->a
.vshort
, 276 );
170 case ASSET_VERTICAL_PIXELS
:
171 retval
= COPYWORD( asset
->a
.vshort
, 278 );
179 int ipaq_mtd_asset_init( void )
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" )) {
198 void ipaq_mtd_asset_cleanup( void )
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");