All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] drivers: nvmem: Export nvmem_add_cells()
@ 2018-05-05 19:11 Andrew Lunn
  2018-05-08  8:35 ` Srinivas Kandagatla
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2018-05-05 19:11 UTC (permalink / raw)
  To: srinivas.kandagatla; +Cc: linux-kernel, andrew.smirnov, Andrew Lunn

Not all platforms use device tree. It is useful to be able to add
cells to a NVMEM device from code. Export nvmem_add_cells() so making
this possible.

This required changing the parameters a bit, so that just the cells
and the number of cells are passed, not the whole nvmem config
structure.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---

This is an RFC.

I have an intel platform with an AT24 EEPROM. I want to make use of
nvmem, but don't have device tree to be able to specify cells. I have
an x86 platform driver which does:

struct nvmem_cell_info nameplate_cells[] = {
       {
               .name = "checksum",
               .offset = 2,
               .bytes = 1,
       },
       {
               .name = "part_number",
               .offset = 11,
               .bytes = 11,
       },
};

       err = nvmem_add_cells(nvmem, nameplate_cells,
                             ARRAY_SIZE(nameplate_cells));
       if (err) {
               dev_err(dev, "Error adding cells to nameplate nvmem device\n");
               return;
       }

       cell = nvmem_cell_get(NULL, "checksum");


drivers/nvmem/core.c           | 15 ++++++++-------
 include/linux/nvmem-provider.h | 11 +++++++++++
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index b05aa8e81303..d1bd43874439 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -353,18 +353,18 @@ static int nvmem_cell_info_to_nvmem_cell(struct nvmem_device *nvmem,
 	return 0;
 }
 
-static int nvmem_add_cells(struct nvmem_device *nvmem,
-			   const struct nvmem_config *cfg)
+int nvmem_add_cells(struct nvmem_device *nvmem,
+		    const struct nvmem_cell_info *info,
+		    int ncells)
 {
 	struct nvmem_cell **cells;
-	const struct nvmem_cell_info *info = cfg->cells;
 	int i, rval;
 
-	cells = kcalloc(cfg->ncells, sizeof(*cells), GFP_KERNEL);
+	cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
 	if (!cells)
 		return -ENOMEM;
 
-	for (i = 0; i < cfg->ncells; i++) {
+	for (i = 0; i < ncells; i++) {
 		cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
 		if (!cells[i]) {
 			rval = -ENOMEM;
@@ -380,7 +380,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 		nvmem_cell_add(cells[i]);
 	}
 
-	nvmem->ncells = cfg->ncells;
+	nvmem->ncells = ncells;
 	/* remove tmp array */
 	kfree(cells);
 
@@ -393,6 +393,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 
 	return rval;
 }
+EXPORT_SYMBOL_GPL(nvmem_add_cells);
 
 /*
  * nvmem_setup_compat() - Create an additional binary entry in
@@ -509,7 +510,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	}
 
 	if (config->cells)
-		nvmem_add_cells(nvmem, config);
+		nvmem_add_cells(nvmem, config->cells, config->ncells);
 
 	return nvmem;
 
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index f89598bc4e1c..24def6ad09bb 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -77,6 +77,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,
 
 int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
 
+int nvmem_add_cells(struct nvmem_device *nvmem,
+		    const struct nvmem_cell_info *info,
+		    int ncells);
 #else
 
 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
@@ -99,6 +102,14 @@ static inline int
 devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
 {
 	return nvmem_unregister(nvmem);
+
+}
+
+static inline int nvmem_add_cells(struct nvmem_device *nvmem,
+				  const struct nvmem_cell_info *info,
+				  int ncells)
+{
+	return -ENOSYS;
 }
 
 #endif /* CONFIG_NVMEM */
-- 
2.17.0

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

* Re: [PATCH RFC] drivers: nvmem: Export nvmem_add_cells()
  2018-05-05 19:11 [PATCH RFC] drivers: nvmem: Export nvmem_add_cells() Andrew Lunn
@ 2018-05-08  8:35 ` Srinivas Kandagatla
  2018-05-08 13:16   ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Srinivas Kandagatla @ 2018-05-08  8:35 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: linux-kernel, andrew.smirnov



On 05/05/18 20:11, Andrew Lunn wrote:
> Not all platforms use device tree. It is useful to be able to add
> cells to a NVMEM device from code. Export nvmem_add_cells() so making
> this possible.
> 
> This required changing the parameters a bit, so that just the cells
> and the number of cells are passed, not the whole nvmem config
> structure.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

> ---
> 
> This is an RFC.
> 
> I have an intel platform with an AT24 EEPROM. I want to make use of
> nvmem, but don't have device tree to be able to specify cells. I have
> an x86 platform driver which does:
> 
> struct nvmem_cell_info nameplate_cells[] = {
>         {
>                 .name = "checksum",
>                 .offset = 2,
>                 .bytes = 1,
>         },
>         {
>                 .name = "part_number",
>                 .offset = 11,
>                 .bytes = 11,
>         },
> };
> 
>         err = nvmem_add_cells(nvmem, nameplate_cells,
>                               ARRAY_SIZE(nameplate_cells));
>         if (err) {
>                 dev_err(dev, "Error adding cells to nameplate nvmem device\n");
>                 return;
>         }
> 
>         cell = nvmem_cell_get(NULL, "checksum");
> 
> 
> drivers/nvmem/core.c           | 15 ++++++++-------
>   include/linux/nvmem-provider.h | 11 +++++++++++
>   2 files changed, 19 insertions(+), 7 deletions(-)
> 


Thanks Andrew for the patch,

Overall the patch looks good to me,
I would like to see some kernel doc for this new exported function

Thanks,
srini

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

* Re: [PATCH RFC] drivers: nvmem: Export nvmem_add_cells()
  2018-05-08  8:35 ` Srinivas Kandagatla
@ 2018-05-08 13:16   ` Andrew Lunn
  2018-05-08 19:36     ` Srinivas Kandagatla
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2018-05-08 13:16 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-kernel, andrew.smirnov

On Tue, May 08, 2018 at 09:35:55AM +0100, Srinivas Kandagatla wrote:
> 
> 
> On 05/05/18 20:11, Andrew Lunn wrote:
> >Not all platforms use device tree. It is useful to be able to add
> >cells to a NVMEM device from code. Export nvmem_add_cells() so making
> >this possible.
> >
> >This required changing the parameters a bit, so that just the cells
> >and the number of cells are passed, not the whole nvmem config
> >structure.
> >
> >Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> 
> >---
> >
> >This is an RFC.
> >
> >I have an intel platform with an AT24 EEPROM. I want to make use of
> >nvmem, but don't have device tree to be able to specify cells. I have
> >an x86 platform driver which does:
> >
> >struct nvmem_cell_info nameplate_cells[] = {
> >        {
> >                .name = "checksum",
> >                .offset = 2,
> >                .bytes = 1,
> >        },
> >        {
> >                .name = "part_number",
> >                .offset = 11,
> >                .bytes = 11,
> >        },
> >};
> >
> >        err = nvmem_add_cells(nvmem, nameplate_cells,
> >                              ARRAY_SIZE(nameplate_cells));
> >        if (err) {
> >                dev_err(dev, "Error adding cells to nameplate nvmem device\n");
> >                return;
> >        }
> >
> >        cell = nvmem_cell_get(NULL, "checksum");
> >
> >
> >drivers/nvmem/core.c           | 15 ++++++++-------
> >  include/linux/nvmem-provider.h | 11 +++++++++++
> >  2 files changed, 19 insertions(+), 7 deletions(-)
> >
> 
> 
> Thanks Andrew for the patch,
> 
> Overall the patch looks good to me,
> I would like to see some kernel doc for this new exported function

Hi Srini

O.K. I can do that.

Will you accept the patch without a user of this API? The driver which
needs it is not yet up to mainline quality. I doubt it will be ready
for this merge window. But having this patch applied soon will remove
a dependency when i do submit it.

Thanks
	Andrew

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

* Re: [PATCH RFC] drivers: nvmem: Export nvmem_add_cells()
  2018-05-08 13:16   ` Andrew Lunn
@ 2018-05-08 19:36     ` Srinivas Kandagatla
  0 siblings, 0 replies; 4+ messages in thread
From: Srinivas Kandagatla @ 2018-05-08 19:36 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: linux-kernel, andrew.smirnov



On 08/05/18 14:16, Andrew Lunn wrote:
> On Tue, May 08, 2018 at 09:35:55AM +0100, Srinivas Kandagatla wrote:
>>
>>
>> On 05/05/18 20:11, Andrew Lunn wrote:
>>> Not all platforms use device tree. It is useful to be able to add
>>> cells to a NVMEM device from code. Export nvmem_add_cells() so making
>>> this possible.
>>>
>>> This required changing the parameters a bit, so that just the cells
>>> and the number of cells are passed, not the whole nvmem config
>>> structure.
>>>
>>> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
>>
>>> ---
>>>
>>> This is an RFC.
>>>
>>> I have an intel platform with an AT24 EEPROM. I want to make use of
>>> nvmem, but don't have device tree to be able to specify cells. I have
>>> an x86 platform driver which does:
>>>
>>> struct nvmem_cell_info nameplate_cells[] = {
>>>         {
>>>                 .name = "checksum",
>>>                 .offset = 2,
>>>                 .bytes = 1,
>>>         },
>>>         {
>>>                 .name = "part_number",
>>>                 .offset = 11,
>>>                 .bytes = 11,
>>>         },
>>> };
>>>
>>>         err = nvmem_add_cells(nvmem, nameplate_cells,
>>>                               ARRAY_SIZE(nameplate_cells));
>>>         if (err) {
>>>                 dev_err(dev, "Error adding cells to nameplate nvmem device\n");
>>>                 return;
>>>         }
>>>
>>>         cell = nvmem_cell_get(NULL, "checksum");
>>>
>>>
>>> drivers/nvmem/core.c           | 15 ++++++++-------
>>>   include/linux/nvmem-provider.h | 11 +++++++++++
>>>   2 files changed, 19 insertions(+), 7 deletions(-)
>>>
>>
>>
>> Thanks Andrew for the patch,
>>
>> Overall the patch looks good to me,
>> I would like to see some kernel doc for this new exported function
> 
> Hi Srini
> 
> O.K. I can do that.
> 
> Will you accept the patch without a user of this API? The driver which

That should be okay!, there are other users who can potentially benefit 
from this.

Thanks,
srini

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

end of thread, other threads:[~2018-05-08 19:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-05 19:11 [PATCH RFC] drivers: nvmem: Export nvmem_add_cells() Andrew Lunn
2018-05-08  8:35 ` Srinivas Kandagatla
2018-05-08 13:16   ` Andrew Lunn
2018-05-08 19:36     ` Srinivas Kandagatla

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.