Add power supply switch in platform data
Subsystems (2)
cover Add power supply switch in platform data
Hi,
Here are two patches that add a power method in flash platform data for chips power control. The first patch adding this function and the second use it in m25p driver.
Comments are welcome !
Stanimir Varbanov (2):
spi: flash: Add power method into flash platform data
mtd: m25p80: Call a platform power method in the driver
drivers/mtd/devices/m25p80.c | 41 +++++++++++++++++++++++++++++++++++++---- include/linux/spi/flash.h | 4 ++++ 2 files changed, 41 insertions(+), 4 deletions(-)
Signature · 6 lines
1.7.4.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 1/2 spi: flash: Add power method into flash platform data
For embedded devices or devices sensible to the power consumption is reasonable to have a way to control the flash chips power. This change in flash_platform_data makes possible to control the power supply of the flash memory chip by adding a "power" method to it.
The platform then could attach a callback and control power supply by it's choice. For example by other regulator driver, GPIO or do nothing.
--- include/linux/spi/flash.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
include/linux/spi/flash.h +4 -0
@@ -10,6 +10,7 @@ struct mtd_partition;* @nr_parts: number of mtd_partitions for static partitoning * @type: optional flash device type (e.g. m25p80 vs m25p64), for use * with chips that can't be queried for JEDEC or other IDs +* @power: method called to enable or disable Vcc * * Board init code (in arch/.../mach-xxx/board-yyy.c files) can * provide information about SPI flash parts (such as DataFlash) to
@@ -26,6 +27,9 @@ struct flash_platform_data {char *type;/* we'll likely add more ... use JEDEC IDs, etc */ + +/* on = 0 disable Vcc, on != 0 enable Vcc */ + void (*power)(int on); };#endif
Signature · 6 lines
1.7.4.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 2/2 mtd: m25p80: Call a platform power method in the driver
In reply to Stanimir VarbanovOn some devices the flash chip could be powered off when m25p driver is probed. To avoid erroneous detection the power of the chip must be turn on, add a power function in m25p_probe to switch on the power by platform data. The power will be turned off at the probe end.
Also implement a get/put_device callbacks to power on/off the flash chip.
--- drivers/mtd/devices/m25p80.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 37 insertions(+), 4 deletions(-)
drivers/mtd/devices/m25p80.c +37 -4
@@ -806,6 +806,27 @@ static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi)return ERR_PTR (-ENODEV ); } +static void m25p_power (struct flash_platform_data *pdata,int on) +{ +if (pdata && pdata->power) + pdata->power (on); +} + +static int m25p_get_device (struct mtd_info *mtd) +{ +struct flash_platform_data *pdata = mtd->dev.parent->platform_data; + +m25p_power (pdata,1 ); + +return 0 ; +} + +static void m25p_put_device (struct mtd_info *mtd) +{ +struct flash_platform_data *pdata = mtd->dev.parent->platform_data; + +m25p_power (pdata,0 ); +}/* * board specific setup should have ensured the SPI clock used here
@@ -820,6 +841,7 @@ static int __devinit m25p_probe(struct spi_device *spi)struct flash_info *info;unsigned i;struct mtd_part_parser_data ppdata; +int ret;/* Platform data helps sort out which chip type we have, as * well as how this board partitions it. If we don't have
@@ -845,12 +867,16 @@ static int __devinit m25p_probe(struct spi_device *spi) info = (void *)id->driver_data; +/* power on device while probing */ +m25p_power (data,1 ); +if (info->jedec_id) {const struct spi_device_id *jid; jid =jedec_probe (spi);if (IS_ERR (jid)) { -return PTR_ERR (jid); + ret =PTR_ERR (jid); + goto out; }else if (jid != id) {/* * JEDEC knows better, so overwrite platform ID. We
@@ -867,12 +893,15 @@ static int __devinit m25p_probe(struct spi_device *spi) } flash =kzalloc (sizeof *flash,GFP_KERNEL ); -if (!flash) -return -ENOMEM ; +if (!flash) { + ret = -ENOMEM ; + goto out; + } flash->command =kmalloc (MAX_CMD_SIZE +FAST_READ_DUMMY_BYTE ,GFP_KERNEL );if (!flash->command) {kfree (flash); -return -ENOMEM ; + ret = -ENOMEM ; + goto out; } flash->spi = spi;
@@ -902,6 +931,8 @@ static int __devinit m25p_probe(struct spi_device *spi) flash->mtd.size = info->sector_size * info->n_sectors; flash->mtd.erase = m25p80_erase; flash->mtd.read = m25p80_read; + flash->mtd.get_device = m25p_get_device; + flash->mtd.put_device = m25p_put_device;/* sst flash chips use AAI word program */ if (JEDEC_MFR (info->jedec_id) ==CFI_MFR_SST )
@@ -956,6 +987,8 @@ static int __devinit m25p_probe(struct spi_device *spi) flash->mtd.eraseregions[i].erasesize /1024 , flash->mtd.eraseregions[i].numblocks); +out: +m25p_power (data,0 );/* partitions should match sector boundaries; and it may be good to * use readonly partitions for writeprotected sectors (BP2..BP0).
Signature · 6 lines
1.7.4.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver
Hi Stanimir,
Quoted 4 lines · Stanimir Varbanov
On some devices the flash chip could be powered off when m25p driver is probed. To avoid erroneous detection the power of the chip must be turn on, add a power function in
m25p_probeto switch on the power by platform data. The power will be turned off at the probe end.
[snip]
Quoted 2 lines
drivers/mtd/devices/m25p80.c +2
-0+/* power on device while probing */ +m25p_power (data,1 );
[snip]
drivers/mtd/devices/m25p80.c static int __devinit m25p_probe(struct spi_device *spi) · line 991
Quoted 2 lines
drivers/mtd/devices/m25p80.c +2
-0+out: +m25p_power (data,0 );
Shouldn't you power off in m25p_remove() as well?
baruch
Signature · 7 lines
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/Re: [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver
Hi, Baruch
Thanks for the comments !
Quoted 15 lines · Baruch Siach
Hi Stanimir,
Quoted 4 lines · Stanimir Varbanov
On some devices the flash chip could be powered off when m25p driver is probed. To avoid erroneous detection the power of the chip must be turn on, add a power function in
m25p_probeto switch on the power by platform data. The power will be turned off at the probe end.[snip]
Quoted 2 lines
drivers/mtd/devices/m25p80.c +2
-0+/* power on device while probing */ +m25p_power (data,1 );[snip]
Quoted 5 lines
drivers/mtd/devices/m25p80.c static int __devinit m25p_probe(struct spi_device *spi) · line 991
Quoted 2 lines
drivers/mtd/devices/m25p80.c +2
-0+out: +m25p_power (data,0 );Shouldn't you power off in
m25p_remove()as well?
IMO, no, because m25p_power(off) is called from m25p_put_device(). Then m25p_put_device() is called from mtdchar::mtd_close(). m25p_remove must fail if user didn't close mtdchar /dev/mtdX device.
The motivation to use power on/off in m25p_probe is because the flash chip might be not powered when driver probe is called. The chip is powered on on the probe begging and powered off after JEDEC probe pass.
Quoted 2 lines
baruch
regards,
Stan
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/