From def2367077573b56f9fc4f824e5c0377a3a4175a Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Mon, 16 Oct 2023 02:45:46 +0000
Subject: [PATCH] 修改DO2-DO4初始为低
---
kernel/drivers/misc/eeprom/at24.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 147 insertions(+), 1 deletions(-)
diff --git a/kernel/drivers/misc/eeprom/at24.c b/kernel/drivers/misc/eeprom/at24.c
index dc35376..dde0b45 100644
--- a/kernel/drivers/misc/eeprom/at24.c
+++ b/kernel/drivers/misc/eeprom/at24.c
@@ -6,6 +6,7 @@
* Copyright (C) 2008 Wolfram Sang, Pengutronix
*/
+#define DEBUG
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
@@ -106,6 +107,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)");
+//Ben
+struct at24_data *at24_private=NULL;
struct at24_chip_data {
/*
* these fields mirror their equivalents in
@@ -421,6 +424,146 @@
return 0;
}
+//add ben
+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;
@@ -630,6 +773,7 @@
u8 test_byte;
int err;
+ printk("ben %s ...\n", __func__);
i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
i2c_fn_block = i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK);
@@ -674,6 +818,7 @@
if (!at24)
return -ENOMEM;
+ at24_private = at24;
mutex_init(&at24->lock);
at24->byte_len = pdata.byte_len;
at24->page_size = pdata.page_size;
@@ -792,7 +937,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