forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-04 8a67202f814bbd808484ed00f93ede0531f51506
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,173 @@
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
+
567
+ssize_t at24_mac2_read(unsigned char* mac)
568
+{
569
+ char buf[20];
570
+ char buf_tmp[12];
571
+ ssize_t ret;
572
+ if (at24_private == NULL)
573
+ {
574
+ printk("zcl: at24_mac_read at24_private==null error");
575
+ return 0;
576
+ }
577
+ memset(buf, 0x00, 20);
578
+ memset(buf_tmp, 0x00, 12);
579
+ ret = at24_read_private(at24_private, buf, 0x20, 6);
580
+ if (ret > 0)
581
+ {
582
+ *mac = buf[0];
583
+ *(mac + 1) = buf[1];
584
+ *(mac + 2) = buf[2];
585
+ *(mac + 3) = buf[3];
586
+ *(mac + 4) = buf[4];
587
+ *(mac + 5) = buf[5];
588
+ }
589
+ printk("at24_mac2_read ...............\n");
590
+ return ret;
591
+}
592
+EXPORT_SYMBOL(at24_mac2_read);
593
+
424594 static int at24_write(void *priv, unsigned int off, void *val, size_t count)
425595 {
426596 struct at24_data *at24;
....@@ -630,6 +800,7 @@
630800 u8 test_byte;
631801 int err;
632802
803
+ printk("ben %s ...\n", __func__);
633804 i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
634805 i2c_fn_block = i2c_check_functionality(client->adapter,
635806 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK);
....@@ -674,6 +845,7 @@
674845 if (!at24)
675846 return -ENOMEM;
676847
848
+ at24_private = at24;
677849 mutex_init(&at24->lock);
678850 at24->byte_len = pdata.byte_len;
679851 at24->page_size = pdata.page_size;
....@@ -792,7 +964,8 @@
792964 at24_io_limit = rounddown_pow_of_two(at24_io_limit);
793965 return i2c_add_driver(&at24_driver);
794966 }
795
-module_init(at24_init);
967
+//module_init(at24_init);
968
+postcore_initcall_sync(at24_init);
796969
797970 static void __exit at24_exit(void)
798971 {