* [PATCH/RFC 0/2] Add power supply switch in platform data @ 2011-08-25 13:29 ` Stanimir Varbanov 0 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-25 13:29 UTC (permalink / raw) To: spi-devel-general, linux-mtd Cc: grant.likely, Stanimir Varbanov, artem.bityutskiy, dwmw2 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(-) -- 1.7.4.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH/RFC 0/2] Add power supply switch in platform data @ 2011-08-25 13:29 ` Stanimir Varbanov 0 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-25 13:29 UTC (permalink / raw) To: spi-devel-general, linux-mtd Cc: grant.likely, Stanimir Varbanov, artem.bityutskiy, dwmw2 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(-) -- 1.7.4.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH/RFC 1/2] spi: flash: Add power method into flash platform data 2011-08-25 13:29 ` Stanimir Varbanov @ 2011-08-25 13:29 ` Stanimir Varbanov -1 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-25 13:29 UTC (permalink / raw) To: spi-devel-general, linux-mtd Cc: grant.likely, Stanimir Varbanov, artem.bityutskiy, dwmw2 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. Signed-off-by: Stanimir Varbanov <svarbanov@mm-sol.com> --- include/linux/spi/flash.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/include/linux/spi/flash.h b/include/linux/spi/flash.h index 3f22932..045a6fc 100644 --- a/include/linux/spi/flash.h +++ b/include/linux/spi/flash.h @@ -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 -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH/RFC 1/2] spi: flash: Add power method into flash platform data @ 2011-08-25 13:29 ` Stanimir Varbanov 0 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-25 13:29 UTC (permalink / raw) To: spi-devel-general, linux-mtd Cc: grant.likely, Stanimir Varbanov, artem.bityutskiy, dwmw2 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. Signed-off-by: Stanimir Varbanov <svarbanov@mm-sol.com> --- include/linux/spi/flash.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/include/linux/spi/flash.h b/include/linux/spi/flash.h index 3f22932..045a6fc 100644 --- a/include/linux/spi/flash.h +++ b/include/linux/spi/flash.h @@ -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 -- 1.7.4.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver 2011-08-25 13:29 ` Stanimir Varbanov @ 2011-08-25 13:29 ` Stanimir Varbanov -1 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-25 13:29 UTC (permalink / raw) To: spi-devel-general, linux-mtd Cc: grant.likely, Stanimir Varbanov, artem.bityutskiy, dwmw2 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_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. Signed-off-by: Stanimir Varbanov <svarbanov@mm-sol.com> --- drivers/mtd/devices/m25p80.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index e6ba034..6ab5896 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -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). -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver @ 2011-08-25 13:29 ` Stanimir Varbanov 0 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-25 13:29 UTC (permalink / raw) To: spi-devel-general, linux-mtd Cc: grant.likely, Stanimir Varbanov, artem.bityutskiy, dwmw2 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_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. Signed-off-by: Stanimir Varbanov <svarbanov@mm-sol.com> --- drivers/mtd/devices/m25p80.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index e6ba034..6ab5896 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -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). -- 1.7.4.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver 2011-08-25 13:29 ` Stanimir Varbanov @ 2011-08-28 5:22 ` Baruch Siach -1 siblings, 0 replies; 10+ messages in thread From: Baruch Siach @ 2011-08-28 5:22 UTC (permalink / raw) To: Stanimir Varbanov; +Cc: spi-devel-general, artem.bityutskiy, linux-mtd, dwmw2 Hi Stanimir, On Thu, Aug 25, 2011 at 04:29:12PM +0300, Stanimir Varbanov wrote: > 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_probe to switch on the power by > platform data. The power will be turned off at the probe end. [snip] > + /* power on device while probing */ > + m25p_power(data, 1); [snip] > +out: > + m25p_power(data, 0); Shouldn't you power off in m25p_remove() as well? baruch -- ~. .~ Tk Open Systems =}------------------------------------------------ooO--U--Ooo------------{= - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il - ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver @ 2011-08-28 5:22 ` Baruch Siach 0 siblings, 0 replies; 10+ messages in thread From: Baruch Siach @ 2011-08-28 5:22 UTC (permalink / raw) To: Stanimir Varbanov; +Cc: spi-devel-general, artem.bityutskiy, linux-mtd, dwmw2 Hi Stanimir, On Thu, Aug 25, 2011 at 04:29:12PM +0300, Stanimir Varbanov wrote: > 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_probe to switch on the power by > platform data. The power will be turned off at the probe end. [snip] > + /* power on device while probing */ > + m25p_power(data, 1); [snip] > +out: > + m25p_power(data, 0); Shouldn't you power off in m25p_remove() as well? baruch -- ~. .~ Tk Open Systems =}------------------------------------------------ooO--U--Ooo------------{= - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il - ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver 2011-08-28 5:22 ` Baruch Siach @ 2011-08-28 10:29 ` Stanimir Varbanov -1 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-28 10:29 UTC (permalink / raw) To: Baruch Siach; +Cc: spi-devel-general, linux-mtd Hi, Baruch Thanks for the comments ! Baruch Siach wrote: > Hi Stanimir, > > On Thu, Aug 25, 2011 at 04:29:12PM +0300, Stanimir Varbanov wrote: >> 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_probe to switch on the power by >> platform data. The power will be turned off at the probe end. > > [snip] > >> + /* power on device while probing */ >> + m25p_power(data, 1); > > [snip] > >> +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. > baruch > regards, Stan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver @ 2011-08-28 10:29 ` Stanimir Varbanov 0 siblings, 0 replies; 10+ messages in thread From: Stanimir Varbanov @ 2011-08-28 10:29 UTC (permalink / raw) To: Baruch Siach; +Cc: spi-devel-general, linux-mtd Hi, Baruch Thanks for the comments ! Baruch Siach wrote: > Hi Stanimir, > > On Thu, Aug 25, 2011 at 04:29:12PM +0300, Stanimir Varbanov wrote: >> 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_probe to switch on the power by >> platform data. The power will be turned off at the probe end. > > [snip] > >> + /* power on device while probing */ >> + m25p_power(data, 1); > > [snip] > >> +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. > baruch > regards, Stan ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-08-28 10:29 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-08-25 13:29 [PATCH/RFC 0/2] Add power supply switch in platform data Stanimir Varbanov 2011-08-25 13:29 ` Stanimir Varbanov 2011-08-25 13:29 ` [PATCH/RFC 1/2] spi: flash: Add power method into flash " Stanimir Varbanov 2011-08-25 13:29 ` Stanimir Varbanov 2011-08-25 13:29 ` [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver Stanimir Varbanov 2011-08-25 13:29 ` Stanimir Varbanov 2011-08-28 5:22 ` Baruch Siach 2011-08-28 5:22 ` Baruch Siach 2011-08-28 10:29 ` Stanimir Varbanov 2011-08-28 10:29 ` Stanimir Varbanov
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.