Path: blob/master/arch/mips/txx9/generic/spi_eeprom.c
10818 views
/*1* spi_eeprom.c2* Copyright (C) 2000-2001 Toshiba Corporation3*4* 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the5* terms of the GNU General Public License version 2. This program is6* licensed "as is" without any warranty of any kind, whether express7* or implied.8*9* Support for TX4938 in 2.6 - Manish Lachwani ([email protected])10*/11#include <linux/init.h>12#include <linux/slab.h>13#include <linux/device.h>14#include <linux/spi/spi.h>15#include <linux/spi/eeprom.h>16#include <asm/txx9/spi.h>1718#define AT250X0_PAGE_SIZE 81920/* register board information for at25 driver */21int __init spi_eeprom_register(int busid, int chipid, int size)22{23struct spi_board_info info = {24.modalias = "at25",25.max_speed_hz = 1500000, /* 1.5Mbps */26.bus_num = busid,27.chip_select = chipid,28/* Mode 0: High-Active, Sample-Then-Shift */29};30struct spi_eeprom *eeprom;31eeprom = kzalloc(sizeof(*eeprom), GFP_KERNEL);32if (!eeprom)33return -ENOMEM;34strcpy(eeprom->name, "at250x0");35eeprom->byte_len = size;36eeprom->page_size = AT250X0_PAGE_SIZE;37eeprom->flags = EE_ADDR1;38info.platform_data = eeprom;39return spi_register_board_info(&info, 1);40}4142/* simple temporary spi driver to provide early access to seeprom. */4344static struct read_param {45int busid;46int chipid;47int address;48unsigned char *buf;49int len;50} *read_param;5152static int __init early_seeprom_probe(struct spi_device *spi)53{54int stat = 0;55u8 cmd[2];56int len = read_param->len;57char *buf = read_param->buf;58int address = read_param->address;5960dev_info(&spi->dev, "spiclk %u KHz.\n",61(spi->max_speed_hz + 500) / 1000);62if (read_param->busid != spi->master->bus_num ||63read_param->chipid != spi->chip_select)64return -ENODEV;65while (len > 0) {66/* spi_write_then_read can only work with small chunk */67int c = len < AT250X0_PAGE_SIZE ? len : AT250X0_PAGE_SIZE;68cmd[0] = 0x03; /* AT25_READ */69cmd[1] = address;70stat = spi_write_then_read(spi, cmd, sizeof(cmd), buf, c);71buf += c;72len -= c;73address += c;74}75return stat;76}7778static struct spi_driver early_seeprom_driver __initdata = {79.driver = {80.name = "at25",81.owner = THIS_MODULE,82},83.probe = early_seeprom_probe,84};8586int __init spi_eeprom_read(int busid, int chipid, int address,87unsigned char *buf, int len)88{89int ret;90struct read_param param = {91.busid = busid,92.chipid = chipid,93.address = address,94.buf = buf,95.len = len96};9798read_param = ¶m;99ret = spi_register_driver(&early_seeprom_driver);100if (!ret)101spi_unregister_driver(&early_seeprom_driver);102return ret;103}104105106