From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] Add driver for the ST M95xxx SPI EEPROM
Date: Wed, 5 Aug 2009 21:24:43 +0200 [thread overview]
Message-ID: <20090805192443.GC13346@game.jcrosoft.org> (raw)
In-Reply-To: <1249492602-5725-1-git-send-email-albin.tonnerre@free-electrons.com>
On 19:16 Wed 05 Aug , Albin Tonnerre wrote:
> This chip is used in a number of boards manufactured by Calao-Systems
> which should be supported soon. This driver provides the necessary
> spi_read and spi_write functions necessary to communicate with the chip.
>
> Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>
> ---
> drivers/spi/Makefile | 1 +
> drivers/spi/eeprom_m95xxx.c | 115 +++++++++++++++++++++++++++++++++++++++++++
not sure it's the right place
drivers mtd will better IMHO
as in drivers/spi it will more for spi host drivers
and not eeprom
> 2 files changed, 116 insertions(+), 0 deletions(-)
> create mode 100644 drivers/spi/eeprom_m95xxx.c
>
> diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
> index a9f67a0..35c9e02 100644
> --- a/drivers/spi/Makefile
> +++ b/drivers/spi/Makefile
> @@ -33,6 +33,7 @@ COBJS-$(CONFIG_MPC52XX_SPI) += mpc52xx_spi.o
> COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
> COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o
> COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
> +COBJS-$(CONFIG_M95XXX_SPI) += eeprom_m95xxx.o
>
> COBJS := $(COBJS-y)
> SRCS := $(COBJS:.o=.c)
> diff --git a/drivers/spi/eeprom_m95xxx.c b/drivers/spi/eeprom_m95xxx.c
> new file mode 100644
> index 0000000..9298c9f
> --- /dev/null
> +++ b/drivers/spi/eeprom_m95xxx.c
> @@ -0,0 +1,115 @@
> +/*
> + * Copyright (C) 2009
> + * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <common.h>
> +#include <spi.h>
> +
> +#define SPI_EEPROM_WREN 0x06
> +#define SPI_EEPROM_RDSR 0x05
> +#define SPI_EEPROM_READ 0x03
> +#define SPI_EEPROM_WRITE 0x02
> +
> +#ifndef CONFIG_DEFAULT_SPI_BUS
> +#define CONFIG_DEFAULT_SPI_BUS 0
> +#endif
> +
> +#ifndef CONFIG_DEFAULT_SPI_MODE
> +#define CONFIG_DEFAULT_SPI_MODE SPI_MODE_0
> +#endif
> +
> +ssize_t spi_read (uchar *addr, int alen, uchar *buffer, int len)
> +{
> + struct spi_slave *slave;
> + u8 cmd = SPI_EEPROM_READ;
> +
> + slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, 1, 1000000,
> + CONFIG_DEFAULT_SPI_MODE);
> + spi_claim_bus(slave);
> +
> + /* command */
> + if(spi_xfer(slave, 8, &cmd, NULL, SPI_XFER_BEGIN))
> + return -1;
> +
> + /* if alen == 3, addr[0] is the block number, we never use it here. All we
> + * need are the lower 16 bits*/
please use the syle of comment
/*
*
*/
> + if (alen == 3)
> + addr++;
> +
> + /* address, and data */
> + if(spi_xfer(slave, 16, addr, NULL, 0))
> + return -1;
> + if(spi_xfer(slave, 8*len, NULL, buffer, SPI_XFER_END))
please add a space before and after the '*'
> + return -1;
> +
> + spi_release_bus(slave);
> + spi_free_slave(slave);
> + return len;
> +}
> +
> +ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len)
> +{
> + struct spi_slave *slave;
> + int i;
> + char buf[3];
> +
> + slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, 1, 1000000,
> + CONFIG_DEFAULT_SPI_MODE);
> + spi_claim_bus(slave);
> +
> + buf[0] = SPI_EEPROM_WREN;
> + if(spi_xfer(slave, 8, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END))
> + return -1;
> +
> + buf[0] = SPI_EEPROM_WRITE;
> +
> + /* As for reading, drop addr[0] if alen is 3 */
> + if (alen == 3) {
> + alen--;
> + addr++;
> + }
> +
> + memcpy(buf+1, addr, alen);
please add a space before and after the '+'
> + /* command + addr, then data */
> + if(spi_xfer(slave, 24, buf, NULL, SPI_XFER_BEGIN))
> + return -1;
> + if(spi_xfer(slave, len*8, buffer, NULL, SPI_XFER_END))
please add a space before and after the '*'
> + return -1;
> +
> + for (i = 0; i < 1000; i++) {
why 1000?
> + buf[0] = SPI_EEPROM_RDSR;
> + buf[1] = 0;
> + spi_xfer(slave, 16, buf, buf, SPI_XFER_BEGIN | SPI_XFER_END);
> +
Best Regards,
J.
next prev parent reply other threads:[~2009-08-05 19:24 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-21 15:53 [U-Boot] [PATCH] Support for the Calao TNY-A9260 board Albin Tonnerre
2009-07-21 17:40 ` Wolfgang Denk
2009-07-21 18:02 ` Albin Tonnerre
2009-07-22 7:33 ` Wolfgang Denk
2009-07-22 8:16 ` Albin Tonnerre
2009-07-22 9:47 ` Wolfgang Denk
2009-07-22 11:03 ` Albin Tonnerre
2009-07-22 11:13 ` Wolfgang Denk
2009-07-24 8:32 ` [U-Boot] [PATCH] Support for the Calao TNY-A9260/TNY-A9G20 boards Albin Tonnerre
2009-08-01 14:15 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-03 7:54 ` Albin Tonnerre
2009-08-04 19:45 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-05 17:16 ` [U-Boot] [PATCH 1/2] Add driver for the ST M95xxx SPI EEPROM Albin Tonnerre
2009-08-05 17:16 ` [U-Boot] [PATCH 2/2] Support for the Calao TNY-A9260/TNY-A9G20 boards Albin Tonnerre
2009-08-05 19:30 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-05 19:45 ` Albin Tonnerre
2009-08-05 19:58 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-07 10:37 ` [U-Boot] [PATCH 1/2] Add driver for the ST M95xxx SPI EEPROM Albin Tonnerre
2009-08-07 10:37 ` [U-Boot] [PATCH 2/2] Support for the Calao TNY-A9260/TNY-A9G20 boards Albin Tonnerre
2009-08-07 10:54 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-09 20:38 ` Wolfgang Denk
2009-08-09 22:40 ` Albin Tonnerre
2009-08-11 10:44 ` [U-Boot] [PATCH] " Albin Tonnerre
2009-08-17 21:41 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-17 22:13 ` Albin Tonnerre
2009-08-17 22:48 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-18 8:26 ` Albin Tonnerre
2009-08-19 19:14 ` Albin Tonnerre
2009-08-19 21:30 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-20 13:43 ` Albin Tonnerre
2009-08-20 14:44 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-20 14:04 ` [U-Boot] [PATCH v8] " Albin Tonnerre
2009-09-01 20:53 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-07 10:52 ` [U-Boot] [PATCH 1/2] Add driver for the ST M95xxx SPI EEPROM Jean-Christophe PLAGNIOL-VILLARD
2009-08-05 19:24 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2009-08-07 10:40 ` Albin Tonnerre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090805192443.GC13346@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.