diff mbox series

[3/5] MTD: chips/map_rom.c: implement point and unpoint methods

Message ID 20171011032621.26979-4-nicolas.pitre@linaro.org
State Superseded
Headers show
Series unconfuse get_unmapped_area and point/unpoint driver methods | expand

Commit Message

Nicolas Pitre Oct. 11, 2017, 3:26 a.m. UTC
Signed-off-by: Nicolas Pitre <nico@linaro.org>

---
 drivers/mtd/chips/map_rom.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

-- 
2.9.5


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Comments

Richard Weinberger Oct. 11, 2017, 8:49 p.m. UTC | #1
On Wed, Oct 11, 2017 at 5:26 AM, Nicolas Pitre <nicolas.pitre@linaro.org> wrote:
> Signed-off-by: Nicolas Pitre <nico@linaro.org>

> ---

>  drivers/mtd/chips/map_rom.c | 24 ++++++++++++++++++++++++

>  1 file changed, 24 insertions(+)

>

> diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c

> index e67f73ab44..722afb1cf4 100644

> --- a/drivers/mtd/chips/map_rom.c

> +++ b/drivers/mtd/chips/map_rom.c

> @@ -22,6 +22,10 @@ static struct mtd_info *map_rom_probe(struct map_info *map);

>  static int maprom_erase (struct mtd_info *mtd, struct erase_info *info);

>  static unsigned long maprom_unmapped_area(struct mtd_info *, unsigned long,

>                                           unsigned long, unsigned long);

> +static int maprom_point (struct mtd_info *mtd, loff_t from, size_t len,

> +                        size_t *retlen, void **virt, resource_size_t *phys);

> +static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len);

> +

>

>  static struct mtd_chip_driver maprom_chipdrv = {

>         .probe  = map_rom_probe,

> @@ -52,6 +56,8 @@ static struct mtd_info *map_rom_probe(struct map_info *map)

>         mtd->type = MTD_ROM;

>         mtd->size = map->size;

>         mtd->_get_unmapped_area = maprom_unmapped_area;

> +       mtd->_point = maprom_point;

> +       mtd->_unpoint = maprom_unpoint;

>         mtd->_read = maprom_read;

>         mtd->_write = maprom_write;

>         mtd->_sync = maprom_nop;

> @@ -78,6 +84,24 @@ static unsigned long maprom_unmapped_area(struct mtd_info *mtd,

>  {

>         struct map_info *map = mtd->priv;

>         return (unsigned long) map->virt + offset;

> +

> +static int maprom_point(struct mtd_info *mtd, loff_t from, size_t len,

> +                       size_t *retlen, void **virt, resource_size_t *phys)

> +{

> +       struct map_info *map = mtd->priv;

> +

> +       if (!map->virt)

> +               return -EINVAL;

> +       *virt = map->virt + from;

> +       if (phys)

> +               *phys = map->phys + from;

> +       *retlen = len;

> +       return 0;

> +}

> +

> +static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len)

> +{

> +       return 0;

>  }


Can we please have a generic helper function for un/point instead of
copy&pasting?

-- 
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Nicolas Pitre Oct. 11, 2017, 8:56 p.m. UTC | #2
On Wed, 11 Oct 2017, Richard Weinberger wrote:

> On Wed, Oct 11, 2017 at 5:26 AM, Nicolas Pitre <nicolas.pitre@linaro.org> wrote:

> > Signed-off-by: Nicolas Pitre <nico@linaro.org>

> > ---

> >  drivers/mtd/chips/map_rom.c | 24 ++++++++++++++++++++++++

> >  1 file changed, 24 insertions(+)

> >

> > diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c

> > index e67f73ab44..722afb1cf4 100644

> > --- a/drivers/mtd/chips/map_rom.c

> > +++ b/drivers/mtd/chips/map_rom.c

> > @@ -22,6 +22,10 @@ static struct mtd_info *map_rom_probe(struct map_info *map);

> >  static int maprom_erase (struct mtd_info *mtd, struct erase_info *info);

> >  static unsigned long maprom_unmapped_area(struct mtd_info *, unsigned long,

> >                                           unsigned long, unsigned long);

> > +static int maprom_point (struct mtd_info *mtd, loff_t from, size_t len,

> > +                        size_t *retlen, void **virt, resource_size_t *phys);

> > +static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len);

> > +

> >

> >  static struct mtd_chip_driver maprom_chipdrv = {

> >         .probe  = map_rom_probe,

> > @@ -52,6 +56,8 @@ static struct mtd_info *map_rom_probe(struct map_info *map)

> >         mtd->type = MTD_ROM;

> >         mtd->size = map->size;

> >         mtd->_get_unmapped_area = maprom_unmapped_area;

> > +       mtd->_point = maprom_point;

> > +       mtd->_unpoint = maprom_unpoint;

> >         mtd->_read = maprom_read;

> >         mtd->_write = maprom_write;

> >         mtd->_sync = maprom_nop;

> > @@ -78,6 +84,24 @@ static unsigned long maprom_unmapped_area(struct mtd_info *mtd,

> >  {

> >         struct map_info *map = mtd->priv;

> >         return (unsigned long) map->virt + offset;

> > +

> > +static int maprom_point(struct mtd_info *mtd, loff_t from, size_t len,

> > +                       size_t *retlen, void **virt, resource_size_t *phys)

> > +{

> > +       struct map_info *map = mtd->priv;

> > +

> > +       if (!map->virt)

> > +               return -EINVAL;

> > +       *virt = map->virt + from;

> > +       if (phys)

> > +               *phys = map->phys + from;

> > +       *retlen = len;

> > +       return 0;

> > +}

> > +

> > +static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len)

> > +{

> > +       return 0;

> >  }

> 

> Can we please have a generic helper function for un/point instead of

> copy&pasting?


I'd prefer not. In this case (and the mapram case) the point/unpoint 
code is unusuably simple.  I don't want people to think that such 
simpleness is expected by making this into a common or generic function. 
Normally this ought to be more involved (see cfi_cmdset_0001 for 
a real example).


Nicolas

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
diff mbox series

Patch

diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index e67f73ab44..722afb1cf4 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -22,6 +22,10 @@  static struct mtd_info *map_rom_probe(struct map_info *map);
 static int maprom_erase (struct mtd_info *mtd, struct erase_info *info);
 static unsigned long maprom_unmapped_area(struct mtd_info *, unsigned long,
 					  unsigned long, unsigned long);
+static int maprom_point (struct mtd_info *mtd, loff_t from, size_t len,
+			 size_t *retlen, void **virt, resource_size_t *phys);
+static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
+
 
 static struct mtd_chip_driver maprom_chipdrv = {
 	.probe	= map_rom_probe,
@@ -52,6 +56,8 @@  static struct mtd_info *map_rom_probe(struct map_info *map)
 	mtd->type = MTD_ROM;
 	mtd->size = map->size;
 	mtd->_get_unmapped_area = maprom_unmapped_area;
+	mtd->_point = maprom_point;
+	mtd->_unpoint = maprom_unpoint;
 	mtd->_read = maprom_read;
 	mtd->_write = maprom_write;
 	mtd->_sync = maprom_nop;
@@ -78,6 +84,24 @@  static unsigned long maprom_unmapped_area(struct mtd_info *mtd,
 {
 	struct map_info *map = mtd->priv;
 	return (unsigned long) map->virt + offset;
+
+static int maprom_point(struct mtd_info *mtd, loff_t from, size_t len,
+			size_t *retlen, void **virt, resource_size_t *phys)
+{
+	struct map_info *map = mtd->priv;
+
+	if (!map->virt)
+		return -EINVAL;
+	*virt = map->virt + from;
+	if (phys)
+		*phys = map->phys + from;
+	*retlen = len;
+	return 0;
+}
+
+static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
+{
+	return 0;
 }
 
 static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)