Skip to content
Snippets Groups Projects
Commit d2ecde50 authored by Dimitris Lampridis's avatar Dimitris Lampridis
Browse files

[fmc] make it build with post v5 kernels, even if it does not actually work (no access to EEPROM)

parent a98642b1
No related branches found
No related tags found
No related merge requests found
diff --git a/drivers/fmc/fmc-eeprom.c b/drivers/fmc/fmc-eeprom.c
index a000a0d..64fb6b6 100644
index a000a0d..e5f96b2 100644
--- a/drivers/fmc/fmc-eeprom.c
+++ b/drivers/fmc/fmc-eeprom.c
@@ -22,7 +22,11 @@
@@ -10,6 +10,10 @@
#include "fmc-internal.h"
#include "fmc-compat.h"
+#if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
+#include <linux/nvmem-consumer.h>
+#endif
+
#define FRU_EEPROM_NAME "fru_eeprom"
/**
@@ -17,12 +21,37 @@
*/
#define FMC_EEPROM_TYPE_DEFAULT "24c02"
+#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE
+/* static int fmc_slot_eeprom_setup(struct notifier_block *nb, */
+/* unsigned long event, void *data) */
+/* { */
+/* struct nvmem_device *nvmem = data; */
+
+/* //dev_err(&nvmem->dev, "friendly notifier, action %ld\n", event); */
+/* if (strcmp(nvmem_dev_name(nvmem), "1-00500") != 0) */
+/* return NOTIFY_DONE; */
+
+/* return NOTIFY_OK; */
+/* }; */
+
+/* static struct notifier_block fmc_eeprom_nvmem_notifier = { */
+/* .notifier_call = fmc_slot_eeprom_setup, */
+/* }; */
+struct property_entry at24_properties[] = {
+ PROPERTY_ENTRY_U32("pagesize", 8),
+ { }
+};
+#else
/**
* Setup function for the AT24C02 EEPROM. What we need to do here is to
* quickly validate the EEPROM content. The EEPROM should contain a valid
* FRU.
*/
......@@ -14,7 +51,48 @@ index a000a0d..64fb6b6 100644
{
struct fmc_slot *slot = context;
@@ -70,9 +74,15 @@ ssize_t fmc_slot_eeprom_read(struct fmc_slot *slot,
@@ -38,17 +67,26 @@ static const struct at24_platform_data at24_24c02 = {
.flags = 0,
.setup = fmc_slot_eeprom_setup,
};
+#endif /* KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE */
/**
- * Initialize I2C EEPROM info with standad values
+ * Initialize I2C EEPROM info with standard values
*/
static void fmc_slot_eeprom_init(struct fmc_slot *slot,
struct i2c_board_info *info,
const char *name)
{
+#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE
+ struct property_entry **p_entry;
+#endif
strncpy(info->type, name, I2C_NAME_SIZE);
info->addr = FMC_EEPROM_ADDR_SPACE;
+#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE
+ p_entry = (struct property_entry **)&info->properties;
+ *p_entry = at24_properties;
+#else
info->platform_data = &slot->at24_data;
+#endif
}
static void fmc_slot_eeprom_init_default(struct fmc_slot *slot,
@@ -56,8 +94,12 @@ static void fmc_slot_eeprom_init_default(struct fmc_slot *slot,
{
memset(info, 0, sizeof(*info));
fmc_slot_eeprom_init(slot, info, FMC_EEPROM_TYPE_DEFAULT);
+#if KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE
memcpy(&slot->at24_data, &at24_24c02, sizeof(slot->at24_data));
slot->at24_data.context = slot;
+/* #else */
+/* nvmem_register_notifier(&fmc_eeprom_nvmem_notifier); */
+#endif
}
/**
@@ -70,9 +112,15 @@ ssize_t fmc_slot_eeprom_read(struct fmc_slot *slot,
* TODO if we export this function, do we have to lock it when we
* use it? Think about it
*/
......@@ -31,6 +109,58 @@ index a000a0d..64fb6b6 100644
}
EXPORT_SYMBOL(fmc_slot_eeprom_read);
@@ -176,6 +224,9 @@ int fmc_slot_eeprom_type_set(struct fmc_slot *slot, const char *type)
struct i2c_board_info i2c_info;
unsigned int len;
int ret;
+#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE
+ struct property_entry *p_entry;
+#endif
if (strncmp(type, "24c", 3)) {
if (strncmp(type, "at24c", 5)) {
@@ -197,19 +248,24 @@ int fmc_slot_eeprom_type_set(struct fmc_slot *slot, const char *type)
memset(&i2c_info, 0, sizeof(i2c_info));
+#if KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE
memset(&slot->at24_data, 0, sizeof(slot->at24_data));
+#endif
len = (len * 1024) / 8;
/*
* For sizes between 1K and 16K the EEPROM uses part of the device
* address as internal memory address
*/
- if (len > 4096) /* 32K 4KiB */
- slot->at24_data.flags = AT24_FLAG_ADDR16;
- else if (len > 131072) /* 1024K 128KiB */
+ if (len > 131072) /* 1024K 128KiB */
return -EINVAL;
+#if KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE
+ else if (len > 4096) /* 32K 4KiB */
+ slot->at24_data.flags = AT24_FLAG_ADDR16;
+#endif
fmc_slot_eeprom_init(slot, &i2c_info, type);
+#if KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE
slot->at24_data.byte_len = len;
slot->at24_data.page_size = 1; /* 1Byte page to play safe */
slot->at24_data.setup = fmc_slot_eeprom_setup;
@@ -219,7 +275,12 @@ int fmc_slot_eeprom_type_set(struct fmc_slot *slot, const char *type)
i2c_info.type, i2c_info.addr,
slot->at24_data.byte_len, slot->at24_data.page_size,
slot->at24_data.flags);
-
+#else
+ p_entry = (struct property_entry *)i2c_info.properties;
+ p_entry[0] = PROPERTY_ENTRY_U32("pagesize", 1);
+ dev_dbg(&slot->dev, "%s 0x%x\n",
+ i2c_info.type, i2c_info.addr);
+#endif
return fmc_slot_eeprom_replace(slot, &i2c_info);
}
EXPORT_SYMBOL(fmc_slot_eeprom_type_set);
diff --git a/drivers/fmc/fru-parse.c b/drivers/fmc/fru-parse.c
index 35a1380..2fd95eb 100644
--- a/drivers/fmc/fru-parse.c
......@@ -55,10 +185,26 @@ index 35a1380..2fd95eb 100644
-
-#endif
diff --git a/include/linux/fmc.h b/include/linux/fmc.h
index 3bc5c12..22bb0a7 100644
index 3bc5c12..f99886c 100644
--- a/include/linux/fmc.h
+++ b/include/linux/fmc.h
@@ -84,7 +84,11 @@ struct fmc_slot {
@@ -11,13 +11,13 @@
#include <linux/spinlock.h>
#include <linux/version.h>
+#if KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE
#if KERNEL_VERSION(3, 10, 0) <= LINUX_VERSION_CODE
#include <linux/platform_data/at24.h>
#else
#include <linux/i2c/at24.h>
#endif
-
-
+#endif
#ifndef _LINUX_FMC_H
#define _LINUX_FMC_H
@@ -84,8 +84,14 @@ struct fmc_slot {
struct i2c_client *eeprom;
......@@ -67,6 +213,9 @@ index 3bc5c12..22bb0a7 100644
+#else
struct memory_accessor *macc;
+#endif
+#if KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE
struct at24_platform_data at24_data;
+#endif
};
/**
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment