3 * Copyright (C) 2000-2001 Toshiba Corporation
5 * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
6 * terms of the GNU General Public License version 2. This program is
7 * licensed "as is" without any warranty of any kind, whether express
10 * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/device.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/eeprom.h>
17 #include <asm/txx9/spi.h>
19 #define AT250X0_PAGE_SIZE 8
21 /* register board information for at25 driver */
22 int __init
spi_eeprom_register(int busid
, int chipid
, int size
)
24 struct spi_board_info info
= {
26 .max_speed_hz
= 1500000, /* 1.5Mbps */
28 .chip_select
= chipid
,
29 /* Mode 0: High-Active, Sample-Then-Shift */
31 struct spi_eeprom
*eeprom
;
32 eeprom
= kzalloc(sizeof(*eeprom
), GFP_KERNEL
);
35 strcpy(eeprom
->name
, "at250x0");
36 eeprom
->byte_len
= size
;
37 eeprom
->page_size
= AT250X0_PAGE_SIZE
;
38 eeprom
->flags
= EE_ADDR1
;
39 info
.platform_data
= eeprom
;
40 return spi_register_board_info(&info
, 1);
43 /* simple temporary spi driver to provide early access to seeprom. */
45 static struct read_param
{
53 static int __init
early_seeprom_probe(struct spi_device
*spi
)
57 int len
= read_param
->len
;
58 char *buf
= read_param
->buf
;
59 int address
= read_param
->address
;
61 dev_info(&spi
->dev
, "spiclk %u KHz.\n",
62 (spi
->max_speed_hz
+ 500) / 1000);
63 if (read_param
->busid
!= spi
->master
->bus_num
||
64 read_param
->chipid
!= spi
->chip_select
)
67 /* spi_write_then_read can only work with small chunk */
68 int c
= len
< AT250X0_PAGE_SIZE
? len
: AT250X0_PAGE_SIZE
;
69 cmd
[0] = 0x03; /* AT25_READ */
71 stat
= spi_write_then_read(spi
, cmd
, sizeof(cmd
), buf
, c
);
79 static struct spi_driver early_seeprom_driver __initdata
= {
84 .probe
= early_seeprom_probe
,
87 int __init
spi_eeprom_read(int busid
, int chipid
, int address
,
88 unsigned char *buf
, int len
)
91 struct read_param param
= {
100 ret
= spi_register_driver(&early_seeprom_driver
);
102 spi_unregister_driver(&early_seeprom_driver
);