Skip to content

Commit

Permalink
mtd: spi-nor: make spi_nor_scan() take a chip type name, not spi_devi…
Browse files Browse the repository at this point in the history
…ce_id

Drivers currently call spi_nor_match_id() and then spi_nor_scan().
This adds a dependency on struct spi_device_id which we want to
avoid.  Make spi_nor_scan() do it for them.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  • Loading branch information
Ben Hutchings authored and Brian Norris committed Oct 17, 2014
1 parent 90e55b3 commit 70f3ce0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
4 changes: 1 addition & 3 deletions drivers/mtd/devices/m25p80.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ static int m25p_probe(struct spi_device *spi)
{
struct mtd_part_parser_data ppdata;
struct flash_platform_data *data;
const struct spi_device_id *id = NULL;
struct m25p *flash;
struct spi_nor *nor;
enum read_mode mode = SPI_NOR_NORMAL;
Expand Down Expand Up @@ -241,8 +240,7 @@ static int m25p_probe(struct spi_device *spi)
else
flash_name = spi->modalias;

id = spi_nor_match_id(flash_name);
ret = spi_nor_scan(nor, id, mode);
ret = spi_nor_scan(nor, flash_name, mode);
if (ret)
return ret;

Expand Down
7 changes: 1 addition & 6 deletions drivers/mtd/spi-nor/fsl-quadspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,6 @@ static int fsl_qspi_probe(struct platform_device *pdev)

/* iterate the subnodes. */
for_each_available_child_of_node(dev->of_node, np) {
const struct spi_device_id *id;
char modalias[40];

/* skip the holes */
Expand Down Expand Up @@ -909,10 +908,6 @@ static int fsl_qspi_probe(struct platform_device *pdev)
if (of_modalias_node(np, modalias, sizeof(modalias)) < 0)
goto map_failed;

id = spi_nor_match_id(modalias);
if (!id)
goto map_failed;

ret = of_property_read_u32(np, "spi-max-frequency",
&q->clk_rate);
if (ret < 0)
Expand All @@ -921,7 +916,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
/* set the chip address for READID */
fsl_qspi_set_base_addr(q, nor);

ret = spi_nor_scan(nor, id, SPI_NOR_QUAD);
ret = spi_nor_scan(nor, modalias, SPI_NOR_QUAD);
if (ret)
goto map_failed;

Expand Down
13 changes: 9 additions & 4 deletions drivers/mtd/spi-nor/spi-nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#define JEDEC_MFR(_jedec_id) ((_jedec_id) >> 16)

static const struct spi_device_id *spi_nor_match_id(const char *name);

/*
* Read the status register, returning its value in the location
* Return the status register value.
Expand Down Expand Up @@ -911,9 +913,9 @@ static int spi_nor_check(struct spi_nor *nor)
return 0;
}

int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
enum read_mode mode)
int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
{
const struct spi_device_id *id = NULL;
struct flash_info *info;
struct device *dev = nor->dev;
struct mtd_info *mtd = nor->mtd;
Expand All @@ -925,6 +927,10 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
if (ret)
return ret;

id = spi_nor_match_id(name);
if (!id)
return -ENOENT;

info = (void *)id->driver_data;

if (info->jedec_id) {
Expand Down Expand Up @@ -1113,7 +1119,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
}
EXPORT_SYMBOL_GPL(spi_nor_scan);

const struct spi_device_id *spi_nor_match_id(char *name)
static const struct spi_device_id *spi_nor_match_id(const char *name)
{
const struct spi_device_id *id = spi_nor_ids;

Expand All @@ -1124,7 +1130,6 @@ const struct spi_device_id *spi_nor_match_id(char *name)
}
return NULL;
}
EXPORT_SYMBOL_GPL(spi_nor_match_id);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Huang Shijie <shijie8@gmail.com>");
Expand Down
20 changes: 3 additions & 17 deletions include/linux/mtd/spi-nor.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,32 +187,18 @@ struct spi_nor {
/**
* spi_nor_scan() - scan the SPI NOR
* @nor: the spi_nor structure
* @id: the spi_device_id provided by the driver
* @name: the chip type name
* @mode: the read mode supported by the driver
*
* The drivers can use this fuction to scan the SPI NOR.
* In the scanning, it will try to get all the necessary information to
* fill the mtd_info{} and the spi_nor{}.
*
* The board may assigns a spi_device_id with @id which be used to compared with
* the spi_device_id detected by the scanning.
* The chip type name can be provided through the @name parameter.
*
* Return: 0 for success, others for failure.
*/
int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
enum read_mode mode);
int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode);
extern const struct spi_device_id spi_nor_ids[];

/**
* spi_nor_match_id() - find the spi_device_id by the name
* @name: the name of the spi_device_id
*
* The drivers use this function to find the spi_device_id
* specified by the @name.
*
* Return: returns the right spi_device_id pointer on success,
* and returns NULL on failure.
*/
const struct spi_device_id *spi_nor_match_id(char *name);

#endif

0 comments on commit 70f3ce0

Please sign in to comment.