2 * Copyright (c) 2014 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <spi_flash.h>
11 #include <dm/device-internal.h>
12 #include "sf_internal.h"
14 int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf)
16 return sf_get_ops(dev)->read(dev, offset, len, buf);
19 int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
22 return sf_get_ops(dev)->write(dev, offset, len, buf);
25 int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
27 return sf_get_ops(dev)->erase(dev, offset, len);
31 * TODO(sjg@chromium.org): This is an old-style function. We should remove
32 * it when all SPI flash drivers use dm
34 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
35 unsigned int max_hz, unsigned int spi_mode)
39 if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev))
42 return dev_get_uclass_priv(dev);
45 void spi_flash_free(struct spi_flash *flash)
47 spi_flash_remove(flash->spi->dev);
50 int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
51 unsigned int max_hz, unsigned int spi_mode,
52 struct udevice **devp)
54 struct spi_slave *slave;
59 snprintf(name, sizeof(name), "%d:%d", busnum, cs);
61 ret = spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode,
62 "spi_flash_std", str, &bus, &slave);
70 int spi_flash_remove(struct udevice *dev)
72 return device_remove(dev);
75 UCLASS_DRIVER(spi_flash) = {
76 .id = UCLASS_SPI_FLASH,
78 .per_device_auto_alloc_size = sizeof(struct spi_flash),