LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Vadym Kochan <vadym.kochan@plvision.eu>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Vadym Kochan <vadym.kochan@plvision.eu>,
Rob Herring <robh+dt@kernel.org>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
Robert Marko <robert.marko@sartura.hr>
Subject: Re: [PATCH v2 1/3] nvmem: core: introduce cells parser
Date: Mon, 20 Sep 2021 13:24:14 +0300 [thread overview]
Message-ID: <vrcxh2pmt3bl4h.fsf@plvision.eu> (raw)
In-Reply-To: <7e6d75ed-cebc-597f-7062-34261d184968@linaro.org>
Hi Srini,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org> writes:
> Hi Vadym,
>
>
> On 08/09/2021 10:38, Vadym Kochan wrote:
>>
>> Hi Srini,
>>
>> Sorry for such delay in replies, I am still confused how to
>> implement it properly, let me please explain the issues
>> which I faced with:
>
>>
>> Srinivas Kandagatla <srinivas.kandagatla@linaro.org> writes:
>>
>>> On 16/06/2021 13:33, Vadym Kochan wrote:
>>>>>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
>>>>>> index bca671ff4e54..648373ced6d4 100644
>>>>>> --- a/drivers/nvmem/core.c
>>>>>> +++ b/drivers/nvmem/core.c
>>>>>> @@ -39,6 +39,7 @@ struct nvmem_device {
>>>>>> nvmem_reg_read_t reg_read;
>>>>>> nvmem_reg_write_t reg_write;
>>>>>> struct gpio_desc *wp_gpio;
>>>>>> + struct nvmem_parser_data *parser_data;
>>>>> This should be renamed to nvmem_cell_info_parser or something on those lines
>>>>> to avoid any misunderstanding on what exactly this parser is about.
>>>>>
>>>>> May be can totally avoid this by using parser name only during register.
>>>>>
>>>> I added this to keep parsed cells particulary for this nvmem in case
>>>> same parser is used for several nvmem's and mostly because of using also
>>>> cell lookup info. I will try to also answer your below question why do I need
>>>> lookups ?
>>>>
>>>> I use of_get_mac_address() func to fetch mac-address from nvmem cell.
>>>> Eventually this func calls of_get_mac_addr_nvmem() which (as I understand it
>>>> correctly) can find cells via DT by parsing "nvmem-cell-names" or via cell lookup
>>>> info of platform_device. I use the 2nd option with the following sample
>>>> solution:
>>>>
>>>> ## DT ##
>>>> eeprom_at24: at24@56 {
>>>> compatible = "atmel,24c32";
>>>> nvmem-cell-parser-name = "onie-tlv-cells";
>>>> reg = <0x56>;
>>>> };
>>>>
>>>> onie_tlv_parser: onie-tlv-cells {
>>>> compatible = "nvmem-cell-parser";
>>>> status = "okay";
>>>>
>>>> ---> add ability here to map cell con_id to cell_name ?
>>>>
>>>> };
>>>>
>>>> some_dev_node {
>>>> compatible = "xxx";
>>>> base-mac-provider = <&onie_tlv_parser>;
>>>
>>> Real nvmem provider is eeprom_at24, why do you use onie_tlv_parse as
>>> your mac provider?
>>> If you use eeprom_at24 then of_get_mac_address() should get mac-address
>>> directly from cell info.
>>
>> 1) This DT node is a trick to register it as a platform_device because of:
>>
>> static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
>> {
>> struct platform_device *pdev = of_find_device_by_node(np);
>> struct nvmem_cell *cell;
>> const void *mac;
>> size_t len;
>> int ret;
>>
>> /* Try lookup by device first, there might be a nvmem_cell_lookup
>> * associated with a given device.
>> */
>> if (pdev) {
>> ret = nvmem_get_mac_address(&pdev->dev, addr);
>> put_device(&pdev->dev);
>> return ret;
>> }
>>
>> cell = of_nvmem_cell_get(np, "mac-address");
>> if (IS_ERR(cell))
>> return PTR_ERR(cell);
>>
>> ...
>> }
>>
>> I tried to use at24_eeprom as ref in DTS file, but this device is not a
>> platform device but a nvmem bus device, so it fails on:
>>
>> ...
>>
>> struct platform_device *pdev = of_find_device_by_node(np);
>>
>> ...
>>
>> /* Try lookup by device first, there might be a nvmem_cell_lookup
>> * associated with a given device.
>> */
>> if (pdev) {
>> ret = nvmem_get_mac_address(&pdev->dev, addr);
>> put_device(&pdev->dev);
>> return ret;
>> }
>>
>> ...
>>
>> Probably this might be fixed by lookup nvmem device too ?
>
> Honestly, this approach is a total hack to get it working.
>
> This is what Am thinking which should look like:
>
> ## DT ##
> eeprom_at24: at24@56 {
> compatible = "atmel,24c32";
> /* Some way to identify that this is a TLV data */
> nvmem-cell-parser-name = "onie-tlv-cells";
> reg = <0x56>;
>
> mac_address: mac-address {
> /* THIS REG is updated once TLV is parsed */
> reg = <0 0x6>
> };
I assume these cell nodes should be marked with some property that they
should be evaluated later, so the cell will be not read
in case it was not parsed because it may
exist in nvmem device optionally.
Or, treat cells with length "0" in a special way and allow to update
cell info later.
> };
>
> some_dev_node {
> compatible = "xxx";
> nvmem-cells = <&mac_address>;
> nvmem-cell-names = "mac-address";
> };
>
> == CODE ==
> ret = of_get_mac_address(dev->of_node, base_mac);
> ==========
>
>
> If you notice the mac_address node reg is 0.
> This node "reg" property should be updated ( using of_update_property())
> by nvmem-provider driver while tlv parsing and by matching the node name
> with tlv name.
>
I assume parser driver can just invoke add_cell_table (with may be
by adding 'bool update' field to the cell_info struct) and core.c will just
update existing cells parsed from OF.
> That way rest of the code will work as usual.
>
> If this work for you then we can ask Rob if he foresee any issues in
> this approach. I already see similar usage in reserved-memory case.
>
>
> --srini
>
>>
>> 2) Regarding cell lookups registration, I had to use it because
>> of_nvmem_cell_get() will not find parser cells via OF.
>>
>>>
>>>
>>>> status = "okay";
>>>> };
>>>> ########
>>>>
>>>> == CODE ==
>>>> base_mac_np = of_parse_phandle(np, "base-mac-provider", 0);
>>>> ret = of_get_mac_address(base_mac_np, base_mac);
>>>> ==========
>>>>
>>>>
>>>> And it works with this implementation because onie-tlv-cells is
>>>> registered as platform_device which name is the same as parser's name.
>>>> So the really tricky part for me is to make this cells lookup work.
>>>
>>> cell lookups are more of intended for board files, adding them in this
>>> case is really not correct. The whole purpose of this driver is to
>>> parse the tlv cell infos into nvmem cell info.
>>>
>>>
>>> --srini
>>>
>>>
>>>>
>>>> Of course would be great if you can point a way/idea to get rid the need of
>>>> lookups.
>>>>
>>
Regards,
Vadym Kochan
next prev parent reply other threads:[~2021-09-20 10:24 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 19:03 [PATCH v2 0/3] nvmem: add ONIE NVMEM " Vadym Kochan
2021-06-08 19:03 ` [PATCH v2 1/3] nvmem: core: introduce " Vadym Kochan
2021-06-08 22:49 ` kernel test robot
2021-06-09 3:05 ` kernel test robot
2021-06-14 10:44 ` Srinivas Kandagatla
2021-06-16 12:33 ` Vadym Kochan
2021-06-21 11:00 ` Srinivas Kandagatla
2021-09-08 9:38 ` Vadym Kochan
2021-09-13 14:19 ` Srinivas Kandagatla
2021-09-20 10:24 ` Vadym Kochan [this message]
2021-09-20 10:36 ` Srinivas Kandagatla
2021-09-20 11:25 ` Vadym Kochan
2021-09-20 11:32 ` Srinivas Kandagatla
2021-09-20 12:29 ` Vadym Kochan
2021-09-20 12:34 ` Srinivas Kandagatla
2021-09-20 13:29 ` Vadym Kochan
2021-09-20 13:40 ` Srinivas Kandagatla
2021-09-21 5:50 ` John Thomson
2021-09-27 7:50 ` Vadym Kochan
2021-09-27 10:12 ` Srinivas Kandagatla
2021-09-28 13:31 ` Vadym Kochan
2021-09-28 13:51 ` Srinivas Kandagatla
2021-09-28 14:11 ` Vadym Kochan
2021-09-28 14:39 ` Srinivas Kandagatla
2021-09-27 10:12 ` Srinivas Kandagatla
2021-09-27 12:38 ` John Thomson
2021-09-08 9:44 ` Vadym Kochan
2021-06-08 19:03 ` [PATCH v2 2/3] dt-bindings: nvmem: document nvmem-cells-parser-name property Vadym Kochan
2021-06-18 20:59 ` Rob Herring
2021-06-08 19:03 ` [PATCH v2 3/3] nvmem: add ONIE nvmem cells parser Vadym Kochan
2021-08-06 15:39 ` Jan Lübbe
2021-09-08 9:56 ` Vadym Kochan
2021-09-12 21:06 ` John Thomson
2021-09-13 14:20 ` Srinivas Kandagatla
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=vrcxh2pmt3bl4h.fsf@plvision.eu \
--to=vadym.kochan@plvision.eu \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robert.marko@sartura.hr \
--cc=robh+dt@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--subject='Re: [PATCH v2 1/3] nvmem: core: introduce cells parser' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).