Lines Matching +full:nvmem +full:- +full:layout
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ONIE tlv NVMEM cells provider
7 * Based on the nvmem driver written by: Vadym Kochan <vadym.kochan@plvision.eu>
8 * Inspired by the first layout written by: Rafał Miłecki <rafal@milecki.pl>
13 #include <linux/nvmem-consumer.h>
14 #include <linux/nvmem-provider.h>
37 return "product-name"; in onie_tlv_cell_name()
39 return "part-number"; in onie_tlv_cell_name()
41 return "serial-number"; in onie_tlv_cell_name()
43 return "mac-address"; in onie_tlv_cell_name()
45 return "manufacture-date"; in onie_tlv_cell_name()
47 return "device-version"; in onie_tlv_cell_name()
49 return "label-revision"; in onie_tlv_cell_name()
51 return "platform-name"; in onie_tlv_cell_name()
53 return "onie-version"; in onie_tlv_cell_name()
55 return "num-macs"; in onie_tlv_cell_name()
59 return "country-code"; in onie_tlv_cell_name()
63 return "diag-version"; in onie_tlv_cell_name()
65 return "service-tag"; in onie_tlv_cell_name()
67 return "vendor-extension"; in onie_tlv_cell_name()
98 static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem, in onie_tlv_add_cells() argument
102 struct device_node *layout; in onie_tlv_add_cells() local
108 layout = of_nvmem_layout_get_container(nvmem); in onie_tlv_add_cells()
109 if (!layout) in onie_tlv_add_cells()
110 return -ENOENT; in onie_tlv_add_cells()
126 cell.np = of_get_child_by_name(layout, cell.name); in onie_tlv_add_cells()
129 ret = nvmem_add_one_cell(nvmem, &cell); in onie_tlv_add_cells()
131 of_node_put(layout); in onie_tlv_add_cells()
138 of_node_put(layout); in onie_tlv_add_cells()
145 if (memcmp(hdr->id, ONIE_TLV_HDR_ID, sizeof(hdr->id))) { in onie_tlv_hdr_is_valid()
150 if (hdr->version != 0x1) { in onie_tlv_hdr_is_valid()
164 memcpy(&crc_hdr, table + table_len - ONIE_TLV_CRC_FIELD_SZ, sizeof(crc_hdr)); in onie_tlv_crc_is_valid()
173 memcpy(&crc_be, table + table_len - ONIE_TLV_CRC_SZ, ONIE_TLV_CRC_SZ); in onie_tlv_crc_is_valid()
175 calc_crc = crc32(~0, table, table_len - ONIE_TLV_CRC_SZ) ^ 0xFFFFFFFF; in onie_tlv_crc_is_valid()
185 static int onie_tlv_parse_table(struct nvmem_layout *layout) in onie_tlv_parse_table() argument
187 struct nvmem_device *nvmem = layout->nvmem; in onie_tlv_parse_table() local
188 struct device *dev = &layout->dev; in onie_tlv_parse_table()
194 ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr); in onie_tlv_parse_table()
200 return -EINVAL; in onie_tlv_parse_table()
208 return -EINVAL; in onie_tlv_parse_table()
213 return -ENOMEM; in onie_tlv_parse_table()
215 ret = nvmem_device_read(nvmem, 0, table_len, table); in onie_tlv_parse_table()
220 return -EINVAL; in onie_tlv_parse_table()
223 ret = onie_tlv_add_cells(dev, nvmem, data_len, data); in onie_tlv_parse_table()
230 static int onie_tlv_probe(struct nvmem_layout *layout) in onie_tlv_probe() argument
232 layout->add_cells = onie_tlv_parse_table; in onie_tlv_probe()
234 return nvmem_layout_register(layout); in onie_tlv_probe()
237 static void onie_tlv_remove(struct nvmem_layout *layout) in onie_tlv_remove() argument
239 nvmem_layout_unregister(layout); in onie_tlv_remove()
243 { .compatible = "onie,tlv-layout", },
250 .name = "onie-tlv-layout",
260 MODULE_DESCRIPTION("NVMEM layout driver for Onie TLV table parsing");