Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 002176db authored by Alexandre Pereira da Silva's avatar Alexandre Pereira da Silva Committed by Greg Kroah-Hartman
Browse files

misc: at25: Parse dt settings



This adds dt support to the at25 eeprom driver.

Signed-off-by: default avatarAlexandre Pereira da Silva <aletes.xgr@gmail.com>
Tested-by: default avatarRoland Stigge <stigge@antcom.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 98dcd59d
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
Atmel AT25 eeprom

Required properties:
- compatible : "atmel,at25".
- reg : chip select number
- spi-max-frequency : max spi frequency to use

- at25,byte-len : total eeprom size in bytes
- at25,addr-mode : addr-mode flags, as defined in include/linux/spi/eeprom.h
- at25,page-size : size of the eeprom page

Examples:
at25@0 {
	compatible = "atmel,at25";
	reg = <0>
	spi-max-frequency = <5000000>;

	at25,byte-len = <0x8000>;
	at25,addr-mode = <2>;
	at25,page-size = <64>;
};
+45 −16
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@

#include <linux/spi/spi.h>
#include <linux/spi/eeprom.h>

#include <linux/of.h>

/*
 * NOTE: this is an *EEPROM* driver.  The vagaries of product naming
@@ -305,25 +305,54 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf,
static int at25_probe(struct spi_device *spi)
{
	struct at25_data	*at25 = NULL;
	const struct spi_eeprom *chip;
	struct spi_eeprom	chip;
	struct device_node	*np = spi->dev.of_node;
	int			err;
	int			sr;
	int			addrlen;

	/* Chip description */
	chip = spi->dev.platform_data;
	if (!chip) {
	if (!spi->dev.platform_data) {
		if (np) {
			u32 val;

			memset(&chip, 0, sizeof(chip));
			strncpy(chip.name, np->name, 10);

			err = of_property_read_u32(np, "at25,byte-len", &val);
			if (err) {
				dev_dbg(&spi->dev, "invalid chip dt description\n");
				goto fail;
			}
			chip.byte_len = val;

			err = of_property_read_u32(np, "at25,addr-mode", &val);
			if (err) {
				dev_dbg(&spi->dev, "invalid chip dt description\n");
				goto fail;
			}
			chip.flags = (u16)val;

			err = of_property_read_u32(np, "at25,page-size", &val);
			if (err) {
				dev_dbg(&spi->dev, "invalid chip dt description\n");
				goto fail;
			}
			chip.page_size = (u16)val;
		} else {
			dev_dbg(&spi->dev, "no chip description\n");
			err = -ENODEV;
			goto fail;
		}
	} else
		chip = *(struct spi_eeprom *)spi->dev.platform_data;

	/* For now we only support 8/16/24 bit addressing */
	if (chip->flags & EE_ADDR1)
	if (chip.flags & EE_ADDR1)
		addrlen = 1;
	else if (chip->flags & EE_ADDR2)
	else if (chip.flags & EE_ADDR2)
		addrlen = 2;
	else if (chip->flags & EE_ADDR3)
	else if (chip.flags & EE_ADDR3)
		addrlen = 3;
	else {
		dev_dbg(&spi->dev, "unsupported address type\n");
@@ -348,7 +377,7 @@ static int at25_probe(struct spi_device *spi)
	}

	mutex_init(&at25->lock);
	at25->chip = *chip;
	at25->chip = chip;
	at25->spi = spi_dev_get(spi);
	dev_set_drvdata(&spi->dev, at25);
	at25->addrlen = addrlen;
@@ -369,7 +398,7 @@ static int at25_probe(struct spi_device *spi)
	at25->mem.read = at25_mem_read;

	at25->bin.size = at25->chip.byte_len;
	if (!(chip->flags & EE_READONLY)) {
	if (!(chip.flags & EE_READONLY)) {
		at25->bin.write = at25_bin_write;
		at25->bin.attr.mode |= S_IWUSR;
		at25->mem.write = at25_mem_write;
@@ -379,8 +408,8 @@ static int at25_probe(struct spi_device *spi)
	if (err)
		goto fail;

	if (chip->setup)
		chip->setup(&at25->mem, chip->context);
	if (chip.setup)
		chip.setup(&at25->mem, chip.context);

	dev_info(&spi->dev, "%Zd %s %s eeprom%s, pagesize %u\n",
		(at25->bin.size < 1024)
@@ -388,7 +417,7 @@ static int at25_probe(struct spi_device *spi)
			: (at25->bin.size / 1024),
		(at25->bin.size < 1024) ? "Byte" : "KByte",
		at25->chip.name,
		(chip->flags & EE_READONLY) ? " (readonly)" : "",
		(chip.flags & EE_READONLY) ? " (readonly)" : "",
		at25->chip.page_size);
	return 0;
fail: