From 0517ab8c70e05fc5877c0c6dae1a5f42a16dcf88 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Mon, 12 Aug 2024 09:56:44 +0000
Subject: [PATCH] config J_GPIO
---
kernel/drivers/misc/eeprom/at24.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 146 insertions(+), 1 deletions(-)
diff --git a/kernel/drivers/misc/eeprom/at24.c b/kernel/drivers/misc/eeprom/at24.c
index 305ffad..d02bf9c 100644
--- a/kernel/drivers/misc/eeprom/at24.c
+++ b/kernel/drivers/misc/eeprom/at24.c
@@ -120,6 +120,8 @@
module_param_named(write_timeout, at24_write_timeout, uint, 0);
MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
+struct at24_data *at24_private=NULL;
+
struct at24_chip_data {
u32 byte_len;
u8 flags;
@@ -464,6 +466,147 @@
return 0;
}
+
+
+static ssize_t at24_read_private(struct at24_data *at24,
+ char *buf, loff_t off, size_t count)
+{
+ ssize_t retval = 0;
+
+ if (unlikely(!count))
+ return count;
+
+ if (off + count > at24->byte_len)
+ return -EINVAL;
+
+ /*
+ * Read data from chip, protecting against concurrent updates
+ * from this host, but not from other I2C masters.
+ */
+ mutex_lock(&at24->lock);
+
+ while (count) {
+ ssize_t status;
+
+ //status = at24_eeprom_read_i2c(at24, buf, off, count);
+ status = at24_regmap_read(at24, buf, off, count);
+ if (status <= 0) {
+ if (retval == 0)
+ retval = status;
+ break;
+ }
+ buf += status;
+ off += status;
+ count -= status;
+ retval += status;
+ }
+
+ mutex_unlock(&at24->lock);
+
+ return retval;
+}
+
+#if 0
+static unsigned char AscToHex(unsigned char aChar)
+{
+ if((aChar>=0x30)&&(aChar<=0x39))
+ aChar -= 0x30;
+ else if((aChar>=0x41)&&(aChar<=0x46))
+ aChar -= 0x37;
+ else if((aChar>=0x61)&&(aChar<=0x66))
+ aChar -= 0x57;
+ else aChar = 0xff;
+
+ return aChar;
+}
+#endif
+
+#if 0
+ssize_t at24_mac_read(unsigned char* addr)
+{
+ char buf[20];
+ char buf_tmp[12];
+ int i;
+ ssize_t ret;
+ if (at24_private == NULL)
+ {
+ printk("ben %s: at24_private==null error\n", __func__);
+ return 0;
+ }
+ memset(buf, 0x00, 20);
+ memset(buf_tmp, 0x00, 12);
+ ret = at24_read(at24_private, 0, buf, 12);
+ if (ret > 0)
+ {
+ for(i=0; i<12; i++)
+ {
+ buf_tmp[i] = AscToHex(buf[i]);
+ }
+ addr[0] = (buf_tmp[0] << 4) | buf_tmp[1];
+ addr[1] = (buf_tmp[2] << 4) | buf_tmp[3];
+ addr[2] = (buf_tmp[4] << 4) | buf_tmp[5];
+ addr[3] = (buf_tmp[6] << 4) | buf_tmp[7];
+ addr[4] = (buf_tmp[8] << 4) | buf_tmp[9];
+ addr[5] = (buf_tmp[10] << 4) | buf_tmp[11];
+ }
+ return ret;
+}
+#endif
+
+ssize_t at24_mac_read(unsigned char* addr)
+{
+ char buf[20];
+ char buf_tmp[12];
+ ssize_t ret;
+ if (at24_private == NULL)
+ {
+ printk("ben: at24_mac_read at24_private==null error");
+ return 0;
+ }
+ memset(buf, 0x00, 20);
+ memset(buf_tmp, 0x00, 12);
+ ret = at24_read_private(at24_private, buf, 0, 6);
+ if (ret > 0)
+ {
+ addr[0] = buf[0];
+ addr[1] = buf[1];
+ addr[2] = buf[2];
+ addr[3] = buf[3];
+ addr[4] = buf[4];
+ addr[5] = buf[5];
+ }
+ printk("at24_mac_read ...............\n");
+ return ret;
+}
+EXPORT_SYMBOL(at24_mac_read);
+
+ssize_t at24_mac1_read(unsigned char* mac)
+{
+ char buf[20];
+ char buf_tmp[12];
+ ssize_t ret;
+ if (at24_private == NULL)
+ {
+ printk("zcl: at24_mac_read at24_private==null error");
+ return 0;
+ }
+ memset(buf, 0x00, 20);
+ memset(buf_tmp, 0x00, 12);
+ ret = at24_read_private(at24_private, buf, 0x10, 6);
+ if (ret > 0)
+ {
+ *mac = buf[0];
+ *(mac + 1) = buf[1];
+ *(mac + 2) = buf[2];
+ *(mac + 3) = buf[3];
+ *(mac + 4) = buf[4];
+ *(mac + 5) = buf[5];
+ }
+ printk("at24_mac1_read ...............\n");
+ return ret;
+}
+EXPORT_SYMBOL(at24_mac1_read);
+
static int at24_write(void *priv, unsigned int off, void *val, size_t count)
{
struct at24_data *at24;
@@ -684,6 +827,7 @@
if (!at24)
return -ENOMEM;
+ at24_private = at24;
mutex_init(&at24->lock);
at24->byte_len = byte_len;
at24->page_size = page_size;
@@ -845,7 +989,8 @@
at24_io_limit = rounddown_pow_of_two(at24_io_limit);
return i2c_add_driver(&at24_driver);
}
-module_init(at24_init);
+//module_init(at24_init);
+postcore_initcall_sync(at24_init);
static void __exit at24_exit(void)
{
--
Gitblit v1.6.2