public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: Expose partition offset to the drivers
@ 2015-02-02 16:22 Ricardo Ribalda Delgado
  2015-02-02 19:17 ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-02-02 16:22 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, linux-mtd, linux-kernel
  Cc: Ricardo Ribalda Delgado

Currently, there is no way to find out the offset of an mtd partition by
a driver. This might be needed by external hardware.

For example, a flash containing the firmware of an external device that
is also accessible by the main cpu/kernel.

The flash is big enough to have two partitions with 2 versions of the
firmware, so we can have a safe upgrade.

Once the flash has been updated we need the real offset, so we can write
it on the external device registers.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/mtd/mtdpart.c          | 8 ++++++++
 include/linux/mtd/partitions.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index a3e3a7d..8047e74 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -784,3 +784,11 @@ uint64_t mtd_get_device_size(const struct mtd_info *mtd)
 	return PART(mtd)->master->size;
 }
 EXPORT_SYMBOL_GPL(mtd_get_device_size);
+
+uint64_t mtd_get_device_offset(const struct mtd_info *mtd){
+	if (!mtd_is_partition(mtd))
+		return 0;
+
+	return PART(mtd)->offset;
+}
+EXPORT_SYMBOL_GPL(mtd_get_device_offset);
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 6a35e6d..2b953b4 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -84,5 +84,6 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
 		      long long offset, long long length);
 int mtd_del_partition(struct mtd_info *master, int partno);
 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
+uint64_t mtd_get_device_offset(const struct mtd_info *mtd);
 
 #endif
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Expose partition offset to the drivers
  2015-02-02 16:22 [PATCH] mtd: Expose partition offset to the drivers Ricardo Ribalda Delgado
@ 2015-02-02 19:17 ` Richard Weinberger
  2015-02-02 19:33   ` Ricardo Ribalda Delgado
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2015-02-02 19:17 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado
  Cc: linux-mtd@lists.infradead.org, Brian Norris, David Woodhouse,
	LKML

On Mon, Feb 2, 2015 at 5:22 PM, Ricardo Ribalda Delgado
<ricardo.ribalda@gmail.com> wrote:
> Currently, there is no way to find out the offset of an mtd partition by
> a driver. This might be needed by external hardware.
>
> For example, a flash containing the firmware of an external device that
> is also accessible by the main cpu/kernel.
>
> The flash is big enough to have two partitions with 2 versions of the
> firmware, so we can have a safe upgrade.
>
> Once the flash has been updated we need the real offset, so we can write
> it on the external device registers.

Can you please also send a patch which shows the usage of this new function
by a driver?

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Expose partition offset to the drivers
  2015-02-02 19:17 ` Richard Weinberger
@ 2015-02-02 19:33   ` Ricardo Ribalda Delgado
  2015-02-02 19:37     ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-02-02 19:33 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd@lists.infradead.org, Brian Norris, David Woodhouse,
	LKML

Hello

On Mon, Feb 2, 2015 at 8:17 PM, Richard Weinberger
<richard.weinberger@gmail.com> wrote:
> On Mon, Feb 2, 2015 at 5:22 PM, Ricardo Ribalda Delgado
>
> Can you please also send a patch which shows the usage of this new function
> by a driver?

It is currently out of tree, but here you can see the relevant code:

mtd_offset=mtd_get_device_offset(mtd);
put_mtd_device(mtd);
if (do_jmp){
    ret=qt5023_hwicap_reset(head,mtd_offset);
    if (ret){
        dev_err(&head->pci_dev->dev,"error: Failed to jump to new bitfile\n");
        vfree(buffer);
        release_firmware(firmware);
        return -EIO;
    }
    qt5023_spi_restart(head);
}

Thanks

-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Expose partition offset to the drivers
  2015-02-02 19:33   ` Ricardo Ribalda Delgado
@ 2015-02-02 19:37     ` Richard Weinberger
  2015-02-02 19:51       ` Ricardo Ribalda Delgado
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2015-02-02 19:37 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado, Richard Weinberger
  Cc: linux-mtd@lists.infradead.org, Brian Norris, David Woodhouse,
	LKML

Hi!

Am 02.02.2015 um 20:33 schrieb Ricardo Ribalda Delgado:
> Hello
> 
> On Mon, Feb 2, 2015 at 8:17 PM, Richard Weinberger
> <richard.weinberger@gmail.com> wrote:
>> On Mon, Feb 2, 2015 at 5:22 PM, Ricardo Ribalda Delgado
>>
>> Can you please also send a patch which shows the usage of this new function
>> by a driver?
> 
> It is currently out of tree, but here you can see the relevant code:
> 
> mtd_offset=mtd_get_device_offset(mtd);
> put_mtd_device(mtd);
> if (do_jmp){
>     ret=qt5023_hwicap_reset(head,mtd_offset);
>     if (ret){
>         dev_err(&head->pci_dev->dev,"error: Failed to jump to new bitfile\n");
>         vfree(buffer);
>         release_firmware(firmware);
>         return -EIO;
>     }
>     qt5023_spi_restart(head);
> }

Hmm, will we ever need the new function for in-tree drivers?
In general we add new functions only if they have an in-tree user
for it.

Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Expose partition offset to the drivers
  2015-02-02 19:37     ` Richard Weinberger
@ 2015-02-02 19:51       ` Ricardo Ribalda Delgado
  0 siblings, 0 replies; 5+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-02-02 19:51 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Richard Weinberger, linux-mtd@lists.infradead.org, Brian Norris,
	David Woodhouse, LKML

Hello Richard

>
> Hmm, will we ever need the new function for in-tree drivers?
> In general we add new functions only if they have an in-tree user
> for it.

It is part of a driver for a camera at qtec.com .

The policy so far has been that we offer the code to our clients but
we cannot afford to push all the drivers to upstream, not because we
don't want to, but because it is very time consuming and we are
constantly improving the devices. Once there is a higher number of
cameras on the field, I am pretty sure that there will be a group of
people just pushing the drivers upstream.

What we can afford now is trying to push the changes/improvement that
we do the infrastructures, hoping that it will be useful for somebody
else.

So in the short term there will be no driver using the function but if
we had that need I guess there is somebody else needing it.

Regards!


-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-02 19:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-02 16:22 [PATCH] mtd: Expose partition offset to the drivers Ricardo Ribalda Delgado
2015-02-02 19:17 ` Richard Weinberger
2015-02-02 19:33   ` Ricardo Ribalda Delgado
2015-02-02 19:37     ` Richard Weinberger
2015-02-02 19:51       ` Ricardo Ribalda Delgado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox