.. | .. |
---|
120 | 120 | module_param_named(write_timeout, at24_write_timeout, uint, 0); |
---|
121 | 121 | MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)"); |
---|
122 | 122 | |
---|
| 123 | +struct at24_data *at24_private=NULL; |
---|
| 124 | + |
---|
123 | 125 | struct at24_chip_data { |
---|
124 | 126 | u32 byte_len; |
---|
125 | 127 | u8 flags; |
---|
.. | .. |
---|
464 | 466 | return 0; |
---|
465 | 467 | } |
---|
466 | 468 | |
---|
| 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 | + |
---|
467 | 610 | static int at24_write(void *priv, unsigned int off, void *val, size_t count) |
---|
468 | 611 | { |
---|
469 | 612 | struct at24_data *at24; |
---|
.. | .. |
---|
684 | 827 | if (!at24) |
---|
685 | 828 | return -ENOMEM; |
---|
686 | 829 | |
---|
| 830 | + at24_private = at24; |
---|
687 | 831 | mutex_init(&at24->lock); |
---|
688 | 832 | at24->byte_len = byte_len; |
---|
689 | 833 | at24->page_size = page_size; |
---|
.. | .. |
---|
845 | 989 | at24_io_limit = rounddown_pow_of_two(at24_io_limit); |
---|
846 | 990 | return i2c_add_driver(&at24_driver); |
---|
847 | 991 | } |
---|
848 | | -module_init(at24_init); |
---|
| 992 | +//module_init(at24_init); |
---|
| 993 | +postcore_initcall_sync(at24_init); |
---|
849 | 994 | |
---|
850 | 995 | static void __exit at24_exit(void) |
---|
851 | 996 | { |
---|