hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
add at24 driver
3 files modified
155 ■■■■■ changed files
kernel/arch/arm64/configs/rockchip_linux_defconfig 6 ●●●● patch | view | raw | blame | history
kernel/drivers/misc/Makefile 1 ●●●● patch | view | raw | blame | history
kernel/drivers/misc/eeprom/at24.c 148 ●●●●● patch | view | raw | blame | history
kernel/arch/arm64/configs/rockchip_linux_defconfig
....@@ -4,10 +4,10 @@
44 #
55
66 #
7
-# Compiler: aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)) 10.3.1 20210621
7
+# Compiler: aarch64-linux-gnu-gcc (Linaro GCC 6.3-2017.05) 6.3.1 20170404
88 #
99 CONFIG_CC_IS_GCC=y
10
-CONFIG_GCC_VERSION=100301
10
+CONFIG_GCC_VERSION=60301
1111 CONFIG_CLANG_VERSION=0
1212 CONFIG_LLD_VERSION=0
1313 CONFIG_CC_HAS_ASM_GOTO=y
....@@ -1311,7 +1311,7 @@
13111311 #
13121312 # EEPROM support
13131313 #
1314
-# CONFIG_EEPROM_AT24 is not set
1314
+CONFIG_EEPROM_AT24=y
13151315 # CONFIG_EEPROM_AT25 is not set
13161316 # CONFIG_EEPROM_LEGACY is not set
13171317 # CONFIG_EEPROM_MAX6875 is not set
kernel/drivers/misc/Makefile
....@@ -63,3 +63,4 @@
6363 obj-$(CONFIG_PIR_ASCHIP) += pir-aschip.o
6464 obj-$(CONFIG_RK803) += rk803.o
6565 obj-y += nkio/
66
+obj-y += nkmcu/
kernel/drivers/misc/eeprom/at24.c
....@@ -6,6 +6,7 @@
66 * Copyright (C) 2008 Wolfram Sang, Pengutronix
77 */
88
9
+#define DEBUG
910 #include <linux/kernel.h>
1011 #include <linux/init.h>
1112 #include <linux/module.h>
....@@ -106,6 +107,8 @@
106107 module_param_named(write_timeout, at24_write_timeout, uint, 0);
107108 MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
108109
110
+//Ben
111
+struct at24_data *at24_private=NULL;
109112 struct at24_chip_data {
110113 /*
111114 * these fields mirror their equivalents in
....@@ -421,6 +424,146 @@
421424 return 0;
422425 }
423426
427
+//add ben
428
+static ssize_t at24_read_private(struct at24_data *at24,
429
+ char *buf, loff_t off, size_t count)
430
+{
431
+ ssize_t retval = 0;
432
+
433
+ if (unlikely(!count))
434
+ return count;
435
+
436
+ if (off + count > at24->byte_len)
437
+ return -EINVAL;
438
+
439
+ /*
440
+ * Read data from chip, protecting against concurrent updates
441
+ * from this host, but not from other I2C masters.
442
+ */
443
+ mutex_lock(&at24->lock);
444
+
445
+ while (count) {
446
+ ssize_t status;
447
+
448
+ //status = at24_eeprom_read_i2c(at24, buf, off, count);
449
+ status = at24_regmap_read(at24, buf, off, count);
450
+ if (status <= 0) {
451
+ if (retval == 0)
452
+ retval = status;
453
+ break;
454
+ }
455
+ buf += status;
456
+ off += status;
457
+ count -= status;
458
+ retval += status;
459
+ }
460
+
461
+ mutex_unlock(&at24->lock);
462
+
463
+ return retval;
464
+}
465
+
466
+#if 0
467
+static unsigned char AscToHex(unsigned char aChar)
468
+{
469
+ if((aChar>=0x30)&&(aChar<=0x39))
470
+ aChar -= 0x30;
471
+ else if((aChar>=0x41)&&(aChar<=0x46))
472
+ aChar -= 0x37;
473
+ else if((aChar>=0x61)&&(aChar<=0x66))
474
+ aChar -= 0x57;
475
+ else aChar = 0xff;
476
+
477
+ return aChar;
478
+}
479
+#endif
480
+
481
+#if 0
482
+ssize_t at24_mac_read(unsigned char* addr)
483
+{
484
+ char buf[20];
485
+ char buf_tmp[12];
486
+ int i;
487
+ ssize_t ret;
488
+ if (at24_private == NULL)
489
+ {
490
+ printk("ben %s: at24_private==null error\n", __func__);
491
+ return 0;
492
+ }
493
+ memset(buf, 0x00, 20);
494
+ memset(buf_tmp, 0x00, 12);
495
+ ret = at24_read(at24_private, 0, buf, 12);
496
+ if (ret > 0)
497
+ {
498
+ for(i=0; i<12; i++)
499
+ {
500
+ buf_tmp[i] = AscToHex(buf[i]);
501
+ }
502
+ addr[0] = (buf_tmp[0] << 4) | buf_tmp[1];
503
+ addr[1] = (buf_tmp[2] << 4) | buf_tmp[3];
504
+ addr[2] = (buf_tmp[4] << 4) | buf_tmp[5];
505
+ addr[3] = (buf_tmp[6] << 4) | buf_tmp[7];
506
+ addr[4] = (buf_tmp[8] << 4) | buf_tmp[9];
507
+ addr[5] = (buf_tmp[10] << 4) | buf_tmp[11];
508
+ }
509
+ return ret;
510
+}
511
+#endif
512
+
513
+ssize_t at24_mac_read(unsigned char* addr)
514
+{
515
+ char buf[20];
516
+ char buf_tmp[12];
517
+ ssize_t ret;
518
+ if (at24_private == NULL)
519
+ {
520
+ printk("ben: at24_mac_read at24_private==null error");
521
+ return 0;
522
+ }
523
+ memset(buf, 0x00, 20);
524
+ memset(buf_tmp, 0x00, 12);
525
+ ret = at24_read_private(at24_private, buf, 0, 6);
526
+ if (ret > 0)
527
+ {
528
+ addr[0] = buf[0];
529
+ addr[1] = buf[1];
530
+ addr[2] = buf[2];
531
+ addr[3] = buf[3];
532
+ addr[4] = buf[4];
533
+ addr[5] = buf[5];
534
+ }
535
+ printk("at24_mac_read ...............\n");
536
+ return ret;
537
+}
538
+EXPORT_SYMBOL(at24_mac_read);
539
+
540
+ssize_t at24_mac1_read(unsigned char* mac)
541
+{
542
+ char buf[20];
543
+ char buf_tmp[12];
544
+ ssize_t ret;
545
+ if (at24_private == NULL)
546
+ {
547
+ printk("zcl: at24_mac_read at24_private==null error");
548
+ return 0;
549
+ }
550
+ memset(buf, 0x00, 20);
551
+ memset(buf_tmp, 0x00, 12);
552
+ ret = at24_read_private(at24_private, buf, 0x10, 6);
553
+ if (ret > 0)
554
+ {
555
+ *mac = buf[0];
556
+ *(mac + 1) = buf[1];
557
+ *(mac + 2) = buf[2];
558
+ *(mac + 3) = buf[3];
559
+ *(mac + 4) = buf[4];
560
+ *(mac + 5) = buf[5];
561
+ }
562
+ printk("at24_mac1_read ...............\n");
563
+ return ret;
564
+}
565
+EXPORT_SYMBOL(at24_mac1_read);
566
+
424567 static int at24_write(void *priv, unsigned int off, void *val, size_t count)
425568 {
426569 struct at24_data *at24;
....@@ -630,6 +773,7 @@
630773 u8 test_byte;
631774 int err;
632775
776
+ printk("ben %s ...\n", __func__);
633777 i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
634778 i2c_fn_block = i2c_check_functionality(client->adapter,
635779 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK);
....@@ -674,6 +818,7 @@
674818 if (!at24)
675819 return -ENOMEM;
676820
821
+ at24_private = at24;
677822 mutex_init(&at24->lock);
678823 at24->byte_len = pdata.byte_len;
679824 at24->page_size = pdata.page_size;
....@@ -792,7 +937,8 @@
792937 at24_io_limit = rounddown_pow_of_two(at24_io_limit);
793938 return i2c_add_driver(&at24_driver);
794939 }
795
-module_init(at24_init);
940
+//module_init(at24_init);
941
+postcore_initcall_sync(at24_init);
796942
797943 static void __exit at24_exit(void)
798944 {