hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
add stmac read mac form eeprom
5 files modified
213 ■■■■■ changed files
kernel/drivers/misc/eeprom/at24.c 147 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c 27 ●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 22 ●●●●● patch | view | raw | blame | history
kernel/include/linux/device/driver.h 12 ●●●●● patch | view | raw | blame | history
kernel/include/linux/platform_device.h 5 ●●●●● patch | view | raw | blame | history
kernel/drivers/misc/eeprom/at24.c
....@@ -120,6 +120,8 @@
120120 module_param_named(write_timeout, at24_write_timeout, uint, 0);
121121 MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
122122
123
+struct at24_data *at24_private=NULL;
124
+
123125 struct at24_chip_data {
124126 u32 byte_len;
125127 u8 flags;
....@@ -464,6 +466,147 @@
464466 return 0;
465467 }
466468
469
+
470
+
471
+static ssize_t at24_read_private(struct at24_data *at24,
472
+ char *buf, loff_t off, size_t count)
473
+{
474
+ ssize_t retval = 0;
475
+
476
+ if (unlikely(!count))
477
+ return count;
478
+
479
+ if (off + count > at24->byte_len)
480
+ return -EINVAL;
481
+
482
+ /*
483
+ * Read data from chip, protecting against concurrent updates
484
+ * from this host, but not from other I2C masters.
485
+ */
486
+ mutex_lock(&at24->lock);
487
+
488
+ while (count) {
489
+ ssize_t status;
490
+
491
+ //status = at24_eeprom_read_i2c(at24, buf, off, count);
492
+ status = at24_regmap_read(at24, buf, off, count);
493
+ if (status <= 0) {
494
+ if (retval == 0)
495
+ retval = status;
496
+ break;
497
+ }
498
+ buf += status;
499
+ off += status;
500
+ count -= status;
501
+ retval += status;
502
+ }
503
+
504
+ mutex_unlock(&at24->lock);
505
+
506
+ return retval;
507
+}
508
+
509
+#if 0
510
+static unsigned char AscToHex(unsigned char aChar)
511
+{
512
+ if((aChar>=0x30)&&(aChar<=0x39))
513
+ aChar -= 0x30;
514
+ else if((aChar>=0x41)&&(aChar<=0x46))
515
+ aChar -= 0x37;
516
+ else if((aChar>=0x61)&&(aChar<=0x66))
517
+ aChar -= 0x57;
518
+ else aChar = 0xff;
519
+
520
+ return aChar;
521
+}
522
+#endif
523
+
524
+#if 0
525
+ssize_t at24_mac_read(unsigned char* addr)
526
+{
527
+ char buf[20];
528
+ char buf_tmp[12];
529
+ int i;
530
+ ssize_t ret;
531
+ if (at24_private == NULL)
532
+ {
533
+ printk("ben %s: at24_private==null error\n", __func__);
534
+ return 0;
535
+ }
536
+ memset(buf, 0x00, 20);
537
+ memset(buf_tmp, 0x00, 12);
538
+ ret = at24_read(at24_private, 0, buf, 12);
539
+ if (ret > 0)
540
+ {
541
+ for(i=0; i<12; i++)
542
+ {
543
+ buf_tmp[i] = AscToHex(buf[i]);
544
+ }
545
+ addr[0] = (buf_tmp[0] << 4) | buf_tmp[1];
546
+ addr[1] = (buf_tmp[2] << 4) | buf_tmp[3];
547
+ addr[2] = (buf_tmp[4] << 4) | buf_tmp[5];
548
+ addr[3] = (buf_tmp[6] << 4) | buf_tmp[7];
549
+ addr[4] = (buf_tmp[8] << 4) | buf_tmp[9];
550
+ addr[5] = (buf_tmp[10] << 4) | buf_tmp[11];
551
+ }
552
+ return ret;
553
+}
554
+#endif
555
+
556
+ssize_t at24_mac_read(unsigned char* addr)
557
+{
558
+ char buf[20];
559
+ char buf_tmp[12];
560
+ ssize_t ret;
561
+ if (at24_private == NULL)
562
+ {
563
+ printk("ben: at24_mac_read at24_private==null error");
564
+ return 0;
565
+ }
566
+ memset(buf, 0x00, 20);
567
+ memset(buf_tmp, 0x00, 12);
568
+ ret = at24_read_private(at24_private, buf, 0, 6);
569
+ if (ret > 0)
570
+ {
571
+ addr[0] = buf[0];
572
+ addr[1] = buf[1];
573
+ addr[2] = buf[2];
574
+ addr[3] = buf[3];
575
+ addr[4] = buf[4];
576
+ addr[5] = buf[5];
577
+ }
578
+ printk("at24_mac_read ...............\n");
579
+ return ret;
580
+}
581
+EXPORT_SYMBOL(at24_mac_read);
582
+
583
+ssize_t at24_mac1_read(unsigned char* mac)
584
+{
585
+ char buf[20];
586
+ char buf_tmp[12];
587
+ ssize_t ret;
588
+ if (at24_private == NULL)
589
+ {
590
+ printk("zcl: at24_mac_read at24_private==null error");
591
+ return 0;
592
+ }
593
+ memset(buf, 0x00, 20);
594
+ memset(buf_tmp, 0x00, 12);
595
+ ret = at24_read_private(at24_private, buf, 0x10, 6);
596
+ if (ret > 0)
597
+ {
598
+ *mac = buf[0];
599
+ *(mac + 1) = buf[1];
600
+ *(mac + 2) = buf[2];
601
+ *(mac + 3) = buf[3];
602
+ *(mac + 4) = buf[4];
603
+ *(mac + 5) = buf[5];
604
+ }
605
+ printk("at24_mac1_read ...............\n");
606
+ return ret;
607
+}
608
+EXPORT_SYMBOL(at24_mac1_read);
609
+
467610 static int at24_write(void *priv, unsigned int off, void *val, size_t count)
468611 {
469612 struct at24_data *at24;
....@@ -684,6 +827,7 @@
684827 if (!at24)
685828 return -ENOMEM;
686829
830
+ at24_private = at24;
687831 mutex_init(&at24->lock);
688832 at24->byte_len = byte_len;
689833 at24->page_size = page_size;
....@@ -845,7 +989,8 @@
845989 at24_io_limit = rounddown_pow_of_two(at24_io_limit);
846990 return i2c_add_driver(&at24_driver);
847991 }
848
-module_init(at24_init);
992
+//module_init(at24_init);
993
+postcore_initcall_sync(at24_init);
849994
850995 static void __exit at24_exit(void)
851996 {
kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
....@@ -2711,13 +2711,17 @@
27112711 }
27122712 EXPORT_SYMBOL(dwmac_rk_get_phy_interface);
27132713
2714
+static unsigned char macaddr[6];
2715
+extern ssize_t at24_mac_read(unsigned char* addr);
27142716 static void rk_get_eth_addr(void *priv, unsigned char *addr)
27152717 {
27162718 struct rk_priv_data *bsp_priv = priv;
27172719 struct device *dev = &bsp_priv->pdev->dev;
2718
- unsigned char ethaddr[ETH_ALEN * MAX_ETH] = {0};
2719
- int ret, id = bsp_priv->bus_id;
2720
+ //unsigned char ethaddr[ETH_ALEN * MAX_ETH] = {0};
2721
+ //int ret, id = bsp_priv->bus_id;
2722
+ int i;
27202723
2724
+#if 0
27212725 if (is_valid_ether_addr(addr))
27222726 goto out;
27232727
....@@ -2747,7 +2751,23 @@
27472751 } else {
27482752 memcpy(addr, &ethaddr[id * ETH_ALEN], ETH_ALEN);
27492753 }
2754
+#endif
2755
+
2756
+ #if 1
2757
+ if (at24_mac_read(macaddr) > 0) {
2758
+ printk("ben %s: at24_mac_read Success!! \n", __func__);
2759
+ memcpy(addr, macaddr, 6);
27502760
2761
+ printk("Read the Ethernet MAC address from :");
2762
+ for (i = 0; i < 5; i++)
2763
+ printk("%2.2x:", addr[i]);
2764
+
2765
+ printk("%2.2x\n", addr[i]);
2766
+ } else {
2767
+ printk("ben %s: at24_mac_read Failed!! \n", __func__);
2768
+ goto out;
2769
+ }
2770
+ #endif
27512771 out:
27522772 dev_err(dev, "%s: mac address: %pM\n", __func__, addr);
27532773 }
....@@ -2920,7 +2940,8 @@
29202940 .of_match_table = rk_gmac_dwmac_match,
29212941 },
29222942 };
2923
-module_platform_driver(rk_gmac_dwmac_driver);
2943
+//module_platform_driver(rk_gmac_dwmac_driver);
2944
+module_platform_driver1(rk_gmac_dwmac_driver);
29242945
29252946 MODULE_AUTHOR("Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>");
29262947 MODULE_DESCRIPTION("Rockchip RK3288 DWMAC specific glue layer");
kernel/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
....@@ -1101,6 +1101,23 @@
11011101 }
11021102 }
11031103
1104
+static void rtl8211F_led_control(struct phy_device *phydev)
1105
+{
1106
+ printk("ben debug:rtl8211F_led_control...1 \n");
1107
+
1108
+ if(!phydev) return;
1109
+ if(phydev->phy_id!=0x001cc916) return; /* only for 8211E*/
1110
+
1111
+ /*switch to extension page44*/
1112
+ phy_write(phydev, 31, 0x0d04);
1113
+//add hc 1000M --> orange
1114
+// 100M --> green
1115
+ phy_write(phydev, 16, 0x6D02);
1116
+//add hc 1000M&100M --> green
1117
+// phy_write(phydev, 16, 0x6C0A);
1118
+ printk("ben debug:rtl8211F_led_control...2 \n");
1119
+}
1120
+
11041121 /**
11051122 * stmmac_init_phy - PHY initialization
11061123 * @dev: net device structure
....@@ -1136,6 +1153,7 @@
11361153 return -ENODEV;
11371154 }
11381155
1156
+ rtl8211F_led_control(phydev);
11391157 ret = phylink_connect_phy(priv->phylink, phydev);
11401158 }
11411159
....@@ -1145,7 +1163,6 @@
11451163 phylink_ethtool_get_wol(priv->phylink, &wol);
11461164 device_set_wakeup_capable(priv->device, !!wol.supported);
11471165 }
1148
-
11491166 return ret;
11501167 }
11511168
....@@ -2345,7 +2362,8 @@
23452362 */
23462363 static void stmmac_check_ether_addr(struct stmmac_priv *priv)
23472364 {
2348
- if (!is_valid_ether_addr(priv->dev->dev_addr)) {
2365
+// if (!is_valid_ether_addr(priv->dev->dev_addr)) {
2366
+ if (1) {
23492367 stmmac_get_umac_addr(priv, priv->hw, priv->dev->dev_addr, 0);
23502368 if (likely(priv->plat->get_eth_addr))
23512369 priv->plat->get_eth_addr(priv->plat->bsp_priv,
kernel/include/linux/device/driver.h
....@@ -272,6 +272,18 @@
272272 } \
273273 module_exit(__driver##_exit);
274274
275
+#define module_driver1(__driver, __register, __unregister, ...) \
276
+static int __init __driver##_init(void) \
277
+{ \
278
+ return __register(&(__driver) , ##__VA_ARGS__); \
279
+} \
280
+arch_initcall(__driver##_init); \
281
+static void __exit __driver##_exit(void) \
282
+{ \
283
+ __unregister(&(__driver) , ##__VA_ARGS__); \
284
+} \
285
+module_exit(__driver##_exit);
286
+
275287 /**
276288 * builtin_driver() - Helper macro for drivers that don't do anything
277289 * special in init and have no exit. This eliminates some boilerplate.
kernel/include/linux/platform_device.h
....@@ -256,6 +256,11 @@
256256 module_driver(__platform_driver, platform_driver_register, \
257257 platform_driver_unregister)
258258
259
+
260
+#define module_platform_driver1(__platform_driver) \
261
+ module_driver1(__platform_driver, platform_driver_register, \
262
+ platform_driver_unregister)
263
+
259264 /* builtin_platform_driver() - Helper macro for builtin drivers that
260265 * don't do anything special in driver init. This eliminates some
261266 * boilerplate. Each driver may only use this macro once, and