Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp: idt82p33: use rsmu driver to access i2c/spi bus

rsmu (Renesas Synchronization Management Unit ) driver is located in
drivers/mfd and responsible for creating multiple devices including
idt82p33 phc, which will then use the exposed regmap and mutex
handle to access i2c/spi bus.

Signed-off-by: Min Li <min.li.xe@renesas.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Link: https://lore.kernel.org/r/1646748651-16811-1-git-send-email-min.li.xe@renesas.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Min Li and committed by
Jakub Kicinski
013a3e7c e18058ea

+144 -384
+91 -257
drivers/ptp/ptp_idt82p33.c
··· 6 6 #define pr_fmt(fmt) "IDT_82p33xxx: " fmt 7 7 8 8 #include <linux/firmware.h> 9 - #include <linux/i2c.h> 9 + #include <linux/platform_device.h> 10 10 #include <linux/module.h> 11 11 #include <linux/ptp_clock_kernel.h> 12 12 #include <linux/delay.h> 13 + #include <linux/jiffies.h> 13 14 #include <linux/kernel.h> 14 15 #include <linux/timekeeping.h> 15 16 #include <linux/bitops.h> 17 + #include <linux/of.h> 18 + #include <linux/mfd/rsmu.h> 19 + #include <linux/mfd/idt82p33_reg.h> 16 20 17 21 #include "ptp_private.h" 18 22 #include "ptp_idt82p33.h" ··· 28 24 MODULE_FIRMWARE(FW_FILENAME); 29 25 30 26 /* Module Parameters */ 31 - static u32 sync_tod_timeout = SYNC_TOD_TIMEOUT_SEC; 32 - module_param(sync_tod_timeout, uint, 0); 33 - MODULE_PARM_DESC(sync_tod_timeout, 34 - "duration in second to keep SYNC_TOD on (set to 0 to keep it always on)"); 35 - 36 27 static u32 phase_snap_threshold = SNAP_THRESHOLD_NS; 37 28 module_param(phase_snap_threshold, uint, 0); 38 29 MODULE_PARM_DESC(phase_snap_threshold, 39 - "threshold (150000ns by default) below which adjtime would ignore"); 30 + "threshold (10000ns by default) below which adjtime would use double dco"); 31 + 32 + static char *firmware; 33 + module_param(firmware, charp, 0); 34 + 35 + static inline int idt82p33_read(struct idt82p33 *idt82p33, u16 regaddr, 36 + u8 *buf, u16 count) 37 + { 38 + return regmap_bulk_read(idt82p33->regmap, regaddr, buf, count); 39 + } 40 + 41 + static inline int idt82p33_write(struct idt82p33 *idt82p33, u16 regaddr, 42 + u8 *buf, u16 count) 43 + { 44 + return regmap_bulk_write(idt82p33->regmap, regaddr, buf, count); 45 + } 40 46 41 47 static void idt82p33_byte_array_to_timespec(struct timespec64 *ts, 42 48 u8 buf[TOD_BYTE_COUNT]) ··· 92 78 } 93 79 } 94 80 95 - static int idt82p33_xfer_read(struct idt82p33 *idt82p33, 96 - unsigned char regaddr, 97 - unsigned char *buf, 98 - unsigned int count) 99 - { 100 - struct i2c_client *client = idt82p33->client; 101 - struct i2c_msg msg[2]; 102 - int cnt; 103 - 104 - msg[0].addr = client->addr; 105 - msg[0].flags = 0; 106 - msg[0].len = 1; 107 - msg[0].buf = &regaddr; 108 - 109 - msg[1].addr = client->addr; 110 - msg[1].flags = I2C_M_RD; 111 - msg[1].len = count; 112 - msg[1].buf = buf; 113 - 114 - cnt = i2c_transfer(client->adapter, msg, 2); 115 - if (cnt < 0) { 116 - dev_err(&client->dev, "i2c_transfer returned %d\n", cnt); 117 - return cnt; 118 - } else if (cnt != 2) { 119 - dev_err(&client->dev, 120 - "i2c_transfer sent only %d of %d messages\n", cnt, 2); 121 - return -EIO; 122 - } 123 - return 0; 124 - } 125 - 126 - static int idt82p33_xfer_write(struct idt82p33 *idt82p33, 127 - u8 regaddr, 128 - u8 *buf, 129 - u16 count) 130 - { 131 - struct i2c_client *client = idt82p33->client; 132 - /* we add 1 byte for device register */ 133 - u8 msg[IDT82P33_MAX_WRITE_COUNT + 1]; 134 - int err; 135 - 136 - if (count > IDT82P33_MAX_WRITE_COUNT) 137 - return -EINVAL; 138 - 139 - msg[0] = regaddr; 140 - memcpy(&msg[1], buf, count); 141 - 142 - err = i2c_master_send(client, msg, count + 1); 143 - if (err < 0) { 144 - dev_err(&client->dev, "i2c_master_send returned %d\n", err); 145 - return err; 146 - } 147 - 148 - return 0; 149 - } 150 - 151 - static int idt82p33_page_offset(struct idt82p33 *idt82p33, unsigned char val) 152 - { 153 - int err; 154 - 155 - if (idt82p33->page_offset == val) 156 - return 0; 157 - 158 - err = idt82p33_xfer_write(idt82p33, PAGE_ADDR, &val, sizeof(val)); 159 - if (err) 160 - dev_err(&idt82p33->client->dev, 161 - "failed to set page offset %d\n", val); 162 - else 163 - idt82p33->page_offset = val; 164 - 165 - return err; 166 - } 167 - 168 - static int idt82p33_rdwr(struct idt82p33 *idt82p33, unsigned int regaddr, 169 - unsigned char *buf, unsigned int count, bool write) 170 - { 171 - u8 offset, page; 172 - int err; 173 - 174 - page = _PAGE(regaddr); 175 - offset = _OFFSET(regaddr); 176 - 177 - err = idt82p33_page_offset(idt82p33, page); 178 - if (err) 179 - return err; 180 - 181 - if (write) 182 - return idt82p33_xfer_write(idt82p33, offset, buf, count); 183 - 184 - return idt82p33_xfer_read(idt82p33, offset, buf, count); 185 - } 186 - 187 - static int idt82p33_read(struct idt82p33 *idt82p33, unsigned int regaddr, 188 - unsigned char *buf, unsigned int count) 189 - { 190 - return idt82p33_rdwr(idt82p33, regaddr, buf, count, false); 191 - } 192 - 193 - static int idt82p33_write(struct idt82p33 *idt82p33, unsigned int regaddr, 194 - unsigned char *buf, unsigned int count) 195 - { 196 - return idt82p33_rdwr(idt82p33, regaddr, buf, count, true); 197 - } 198 - 199 81 static int idt82p33_dpll_set_mode(struct idt82p33_channel *channel, 200 82 enum pll_mode mode) 201 83 { ··· 116 206 if (err) 117 207 return err; 118 208 119 - channel->pll_mode = dpll_mode; 209 + channel->pll_mode = mode; 120 210 121 211 return 0; 122 212 } ··· 377 467 err = idt82p33_measure_settime_gettime_gap_overhead(channel, &gap_ns); 378 468 379 469 if (err) { 380 - dev_err(&idt82p33->client->dev, 470 + dev_err(idt82p33->dev, 381 471 "Failed in %s with err %d!\n", __func__, err); 382 472 return err; 383 473 } ··· 409 499 410 500 if (page == PLLMASK_ADDR_HI && offset == PLLMASK_ADDR_LO) { 411 501 if ((val & 0xfc) || !(val & 0x3)) { 412 - dev_err(&idt82p33->client->dev, 413 - "Invalid PLL mask 0x%hhx\n", val); 502 + dev_err(idt82p33->dev, 503 + "Invalid PLL mask 0x%x\n", val); 414 504 err = -EINVAL; 415 505 } else { 416 506 idt82p33->pll_mask = val; ··· 430 520 { 431 521 u8 mask, i; 432 522 433 - dev_info(&idt82p33->client->dev, 523 + dev_info(idt82p33->dev, 434 524 "pllmask = 0x%02x\n", idt82p33->pll_mask); 435 525 436 526 for (i = 0; i < MAX_PHC_PLL; i++) { 437 527 mask = 1 << i; 438 528 439 529 if (mask & idt82p33->pll_mask) 440 - dev_info(&idt82p33->client->dev, 530 + dev_info(idt82p33->dev, 441 531 "PLL%d output_mask = 0x%04x\n", 442 532 i, idt82p33->channel[i].output_mask); 443 533 } ··· 448 538 struct idt82p33 *idt82p33 = channel->idt82p33; 449 539 u8 sync_cnfg; 450 540 int err; 451 - 452 - /* Turn it off after sync_tod_timeout seconds */ 453 - if (enable && sync_tod_timeout) 454 - ptp_schedule_worker(channel->ptp_clock, 455 - sync_tod_timeout * HZ); 456 541 457 542 err = idt82p33_read(idt82p33, channel->dpll_sync_cnfg, 458 543 &sync_cnfg, sizeof(sync_cnfg)); ··· 460 555 461 556 return idt82p33_write(idt82p33, channel->dpll_sync_cnfg, 462 557 &sync_cnfg, sizeof(sync_cnfg)); 463 - } 464 - 465 - static long idt82p33_sync_tod_work_handler(struct ptp_clock_info *ptp) 466 - { 467 - struct idt82p33_channel *channel = 468 - container_of(ptp, struct idt82p33_channel, caps); 469 - struct idt82p33 *idt82p33 = channel->idt82p33; 470 - 471 - mutex_lock(&idt82p33->reg_lock); 472 - 473 - (void)idt82p33_sync_tod(channel, false); 474 - 475 - mutex_unlock(&idt82p33->reg_lock); 476 - 477 - /* Return a negative value here to not reschedule */ 478 - return -1; 479 558 } 480 559 481 560 static int idt82p33_output_enable(struct idt82p33_channel *channel, ··· 523 634 struct idt82p33 *idt82p33 = channel->idt82p33; 524 635 struct timespec64 ts = {0, 0}; 525 636 int err; 526 - u8 val; 527 - 528 - val = 0; 529 - err = idt82p33_write(idt82p33, channel->dpll_input_mode_cnfg, 530 - &val, sizeof(val)); 531 - if (err) 532 - return err; 533 637 534 638 err = idt82p33_measure_tod_write_overhead(channel); 535 639 536 640 if (err) { 537 - dev_err(&idt82p33->client->dev, 641 + dev_err(idt82p33->dev, 538 642 "Failed in %s with err %d!\n", __func__, err); 539 643 return err; 540 644 } ··· 555 673 } 556 674 557 675 static int idt82p33_enable(struct ptp_clock_info *ptp, 558 - struct ptp_clock_request *rq, int on) 676 + struct ptp_clock_request *rq, int on) 559 677 { 560 678 struct idt82p33_channel *channel = 561 679 container_of(ptp, struct idt82p33_channel, caps); 562 680 struct idt82p33 *idt82p33 = channel->idt82p33; 563 - int err; 681 + int err = -EOPNOTSUPP; 564 682 565 - err = -EOPNOTSUPP; 566 - 567 - mutex_lock(&idt82p33->reg_lock); 683 + mutex_lock(idt82p33->lock); 568 684 569 685 if (rq->type == PTP_CLK_REQ_PEROUT) { 570 686 if (!on) ··· 570 690 &rq->perout); 571 691 /* Only accept a 1-PPS aligned to the second. */ 572 692 else if (rq->perout.start.nsec || rq->perout.period.sec != 1 || 573 - rq->perout.period.nsec) { 693 + rq->perout.period.nsec) 574 694 err = -ERANGE; 575 - } else 695 + else 576 696 err = idt82p33_perout_enable(channel, true, 577 697 &rq->perout); 578 698 } 579 699 580 - mutex_unlock(&idt82p33->reg_lock); 700 + mutex_unlock(idt82p33->lock); 581 701 702 + if (err) 703 + dev_err(idt82p33->dev, 704 + "Failed in %s with err %d!\n", __func__, err); 582 705 return err; 583 706 } 584 707 ··· 610 727 val[3] = (offset_regval >> 24) & 0x1F; 611 728 val[3] |= PH_OFFSET_EN; 612 729 613 - mutex_lock(&idt82p33->reg_lock); 730 + mutex_lock(idt82p33->lock); 614 731 615 732 err = idt82p33_dpll_set_mode(channel, PLL_MODE_WPH); 616 733 if (err) { 617 - dev_err(&idt82p33->client->dev, 734 + dev_err(idt82p33->dev, 618 735 "Failed in %s with err %d!\n", __func__, err); 619 736 goto out; 620 737 } ··· 623 740 sizeof(val)); 624 741 625 742 out: 626 - mutex_unlock(&idt82p33->reg_lock); 743 + mutex_unlock(idt82p33->lock); 627 744 return err; 628 745 } 629 746 ··· 634 751 struct idt82p33 *idt82p33 = channel->idt82p33; 635 752 int err; 636 753 637 - mutex_lock(&idt82p33->reg_lock); 754 + mutex_lock(idt82p33->lock); 638 755 err = _idt82p33_adjfine(channel, scaled_ppm); 756 + mutex_unlock(idt82p33->lock); 639 757 if (err) 640 - dev_err(&idt82p33->client->dev, 758 + dev_err(idt82p33->dev, 641 759 "Failed in %s with err %d!\n", __func__, err); 642 - mutex_unlock(&idt82p33->reg_lock); 643 760 644 761 return err; 645 762 } ··· 651 768 struct idt82p33 *idt82p33 = channel->idt82p33; 652 769 int err; 653 770 654 - mutex_lock(&idt82p33->reg_lock); 771 + mutex_lock(idt82p33->lock); 655 772 656 773 if (abs(delta_ns) < phase_snap_threshold) { 657 - mutex_unlock(&idt82p33->reg_lock); 774 + mutex_unlock(idt82p33->lock); 658 775 return 0; 659 776 } 660 777 661 778 err = _idt82p33_adjtime(channel, delta_ns); 662 779 663 - if (err) { 664 - mutex_unlock(&idt82p33->reg_lock); 665 - dev_err(&idt82p33->client->dev, 666 - "Adjtime failed in %s with err %d!\n", __func__, err); 667 - return err; 668 - } 780 + mutex_unlock(idt82p33->lock); 669 781 670 - err = idt82p33_sync_tod(channel, true); 671 782 if (err) 672 - dev_err(&idt82p33->client->dev, 673 - "Sync_tod failed in %s with err %d!\n", __func__, err); 674 - 675 - mutex_unlock(&idt82p33->reg_lock); 676 - 783 + dev_err(idt82p33->dev, 784 + "Failed in %s with err %d!\n", __func__, err); 677 785 return err; 678 786 } 679 787 ··· 675 801 struct idt82p33 *idt82p33 = channel->idt82p33; 676 802 int err; 677 803 678 - mutex_lock(&idt82p33->reg_lock); 804 + mutex_lock(idt82p33->lock); 679 805 err = _idt82p33_gettime(channel, ts); 680 - if (err) 681 - dev_err(&idt82p33->client->dev, 682 - "Failed in %s with err %d!\n", __func__, err); 683 - mutex_unlock(&idt82p33->reg_lock); 806 + mutex_unlock(idt82p33->lock); 684 807 808 + if (err) 809 + dev_err(idt82p33->dev, 810 + "Failed in %s with err %d!\n", __func__, err); 685 811 return err; 686 812 } 687 813 688 814 static int idt82p33_settime(struct ptp_clock_info *ptp, 689 - const struct timespec64 *ts) 815 + const struct timespec64 *ts) 690 816 { 691 817 struct idt82p33_channel *channel = 692 818 container_of(ptp, struct idt82p33_channel, caps); 693 819 struct idt82p33 *idt82p33 = channel->idt82p33; 694 820 int err; 695 821 696 - mutex_lock(&idt82p33->reg_lock); 822 + mutex_lock(idt82p33->lock); 697 823 err = _idt82p33_settime(channel, ts); 698 - if (err) 699 - dev_err(&idt82p33->client->dev, 700 - "Failed in %s with err %d!\n", __func__, err); 701 - mutex_unlock(&idt82p33->reg_lock); 824 + mutex_unlock(idt82p33->lock); 702 825 826 + if (err) 827 + dev_err(idt82p33->dev, 828 + "Failed in %s with err %d!\n", __func__, err); 703 829 return err; 704 830 } 705 831 ··· 738 864 static void idt82p33_caps_init(struct ptp_clock_info *caps) 739 865 { 740 866 caps->owner = THIS_MODULE; 741 - caps->max_adj = 92000; 867 + caps->max_adj = DCO_MAX_PPB; 742 868 caps->n_per_out = 11; 743 869 caps->adjphase = idt82p33_adjwritephase; 744 870 caps->adjfine = idt82p33_adjfine; ··· 746 872 caps->gettime64 = idt82p33_gettime; 747 873 caps->settime64 = idt82p33_settime; 748 874 caps->enable = idt82p33_enable; 749 - caps->do_aux_work = idt82p33_sync_tod_work_handler; 750 875 } 751 876 752 877 static int idt82p33_enable_channel(struct idt82p33 *idt82p33, u32 index) ··· 760 887 761 888 err = idt82p33_channel_init(channel, index); 762 889 if (err) { 763 - dev_err(&idt82p33->client->dev, 890 + dev_err(idt82p33->dev, 764 891 "Channel_init failed in %s with err %d!\n", 765 892 __func__, err); 766 893 return err; ··· 785 912 786 913 err = idt82p33_dpll_set_mode(channel, PLL_MODE_DCO); 787 914 if (err) { 788 - dev_err(&idt82p33->client->dev, 915 + dev_err(idt82p33->dev, 789 916 "Dpll_set_mode failed in %s with err %d!\n", 790 917 __func__, err); 791 918 return err; ··· 793 920 794 921 err = idt82p33_enable_tod(channel); 795 922 if (err) { 796 - dev_err(&idt82p33->client->dev, 923 + dev_err(idt82p33->dev, 797 924 "Enable_tod failed in %s with err %d!\n", 798 925 __func__, err); 799 926 return err; 800 927 } 801 928 802 - dev_info(&idt82p33->client->dev, "PLL%d registered as ptp%d\n", 929 + dev_info(idt82p33->dev, "PLL%d registered as ptp%d\n", 803 930 index, channel->ptp_clock->index); 804 931 805 932 return 0; ··· 813 940 int err; 814 941 s32 len; 815 942 816 - dev_dbg(&idt82p33->client->dev, 817 - "requesting firmware '%s'\n", FW_FILENAME); 943 + dev_dbg(idt82p33->dev, "requesting firmware '%s'\n", FW_FILENAME); 818 944 819 - err = request_firmware(&fw, FW_FILENAME, &idt82p33->client->dev); 945 + err = request_firmware(&fw, FW_FILENAME, idt82p33->dev); 820 946 821 947 if (err) { 822 - dev_err(&idt82p33->client->dev, 948 + dev_err(idt82p33->dev, 823 949 "Failed in %s with err %d!\n", __func__, err); 824 950 return err; 825 951 } 826 952 827 - dev_dbg(&idt82p33->client->dev, "firmware size %zu bytes\n", fw->size); 953 + dev_dbg(idt82p33->dev, "firmware size %zu bytes\n", fw->size); 828 954 829 955 rec = (struct idt82p33_fwrc *) fw->data; 830 956 831 957 for (len = fw->size; len > 0; len -= sizeof(*rec)) { 832 958 833 959 if (rec->reserved) { 834 - dev_err(&idt82p33->client->dev, 960 + dev_err(idt82p33->dev, 835 961 "bad firmware, reserved field non-zero\n"); 836 962 err = -EINVAL; 837 963 } else { ··· 845 973 } 846 974 847 975 if (err == 0) { 848 - /* maximum 8 pages */ 849 - if (page >= PAGE_NUM) 850 - continue; 851 - 852 976 /* Page size 128, last 4 bytes of page skipped */ 853 - if (((loaddr > 0x7b) && (loaddr <= 0x7f)) 854 - || loaddr > 0xfb) 977 + if (loaddr > 0x7b) 855 978 continue; 856 979 857 - err = idt82p33_write(idt82p33, _ADDR(page, loaddr), 980 + err = idt82p33_write(idt82p33, REG_ADDR(page, loaddr), 858 981 &val, sizeof(val)); 859 982 } 860 983 ··· 864 997 } 865 998 866 999 867 - static int idt82p33_probe(struct i2c_client *client, 868 - const struct i2c_device_id *id) 1000 + static int idt82p33_probe(struct platform_device *pdev) 869 1001 { 1002 + struct rsmu_ddata *ddata = dev_get_drvdata(pdev->dev.parent); 870 1003 struct idt82p33 *idt82p33; 871 1004 int err; 872 1005 u8 i; 873 1006 874 - (void)id; 875 - 876 - idt82p33 = devm_kzalloc(&client->dev, 1007 + idt82p33 = devm_kzalloc(&pdev->dev, 877 1008 sizeof(struct idt82p33), GFP_KERNEL); 878 1009 if (!idt82p33) 879 1010 return -ENOMEM; 880 1011 881 - mutex_init(&idt82p33->reg_lock); 882 - 883 - idt82p33->client = client; 884 - idt82p33->page_offset = 0xff; 1012 + idt82p33->dev = &pdev->dev; 1013 + idt82p33->mfd = pdev->dev.parent; 1014 + idt82p33->lock = &ddata->lock; 1015 + idt82p33->regmap = ddata->regmap; 885 1016 idt82p33->tod_write_overhead_ns = 0; 886 1017 idt82p33->calculate_overhead_flag = 0; 887 1018 idt82p33->pll_mask = DEFAULT_PLL_MASK; 888 1019 idt82p33->channel[0].output_mask = DEFAULT_OUTPUT_MASK_PLL0; 889 1020 idt82p33->channel[1].output_mask = DEFAULT_OUTPUT_MASK_PLL1; 890 1021 891 - mutex_lock(&idt82p33->reg_lock); 1022 + mutex_lock(idt82p33->lock); 892 1023 893 1024 err = idt82p33_load_firmware(idt82p33); 894 1025 895 1026 if (err) 896 - dev_warn(&idt82p33->client->dev, 1027 + dev_warn(idt82p33->dev, 897 1028 "loading firmware failed with %d\n", err); 898 1029 899 1030 if (idt82p33->pll_mask) { ··· 899 1034 if (idt82p33->pll_mask & (1 << i)) { 900 1035 err = idt82p33_enable_channel(idt82p33, i); 901 1036 if (err) { 902 - dev_err(&idt82p33->client->dev, 1037 + dev_err(idt82p33->dev, 903 1038 "Failed in %s with err %d!\n", 904 1039 __func__, err); 905 1040 break; ··· 907 1042 } 908 1043 } 909 1044 } else { 910 - dev_err(&idt82p33->client->dev, 1045 + dev_err(idt82p33->dev, 911 1046 "no PLLs flagged as PHCs, nothing to do\n"); 912 1047 err = -ENODEV; 913 1048 } 914 1049 915 - mutex_unlock(&idt82p33->reg_lock); 1050 + mutex_unlock(idt82p33->lock); 916 1051 917 1052 if (err) { 918 1053 idt82p33_ptp_clock_unregister_all(idt82p33); 919 1054 return err; 920 1055 } 921 1056 922 - i2c_set_clientdata(client, idt82p33); 1057 + platform_set_drvdata(pdev, idt82p33); 923 1058 924 1059 return 0; 925 1060 } 926 1061 927 - static int idt82p33_remove(struct i2c_client *client) 1062 + static int idt82p33_remove(struct platform_device *pdev) 928 1063 { 929 - struct idt82p33 *idt82p33 = i2c_get_clientdata(client); 1064 + struct idt82p33 *idt82p33 = platform_get_drvdata(pdev); 930 1065 931 1066 idt82p33_ptp_clock_unregister_all(idt82p33); 932 - mutex_destroy(&idt82p33->reg_lock); 933 1067 934 1068 return 0; 935 1069 } 936 1070 937 - #ifdef CONFIG_OF 938 - static const struct of_device_id idt82p33_dt_id[] = { 939 - { .compatible = "idt,82p33810" }, 940 - { .compatible = "idt,82p33813" }, 941 - { .compatible = "idt,82p33814" }, 942 - { .compatible = "idt,82p33831" }, 943 - { .compatible = "idt,82p33910" }, 944 - { .compatible = "idt,82p33913" }, 945 - { .compatible = "idt,82p33914" }, 946 - { .compatible = "idt,82p33931" }, 947 - {}, 948 - }; 949 - MODULE_DEVICE_TABLE(of, idt82p33_dt_id); 950 - #endif 951 - 952 - static const struct i2c_device_id idt82p33_i2c_id[] = { 953 - { "idt82p33810", }, 954 - { "idt82p33813", }, 955 - { "idt82p33814", }, 956 - { "idt82p33831", }, 957 - { "idt82p33910", }, 958 - { "idt82p33913", }, 959 - { "idt82p33914", }, 960 - { "idt82p33931", }, 961 - {}, 962 - }; 963 - MODULE_DEVICE_TABLE(i2c, idt82p33_i2c_id); 964 - 965 - static struct i2c_driver idt82p33_driver = { 1071 + static struct platform_driver idt82p33_driver = { 966 1072 .driver = { 967 - .of_match_table = of_match_ptr(idt82p33_dt_id), 968 - .name = "idt82p33", 1073 + .name = "82p33x1x-phc", 969 1074 }, 970 - .probe = idt82p33_probe, 971 - .remove = idt82p33_remove, 972 - .id_table = idt82p33_i2c_id, 1075 + .probe = idt82p33_probe, 1076 + .remove = idt82p33_remove, 973 1077 }; 974 1078 975 - module_i2c_driver(idt82p33_driver); 1079 + module_platform_driver(idt82p33_driver);
+50 -127
drivers/ptp/ptp_idt82p33.h
··· 8 8 #define PTP_IDT82P33_H 9 9 10 10 #include <linux/ktime.h> 11 - #include <linux/workqueue.h> 11 + #include <linux/mfd/idt82p33_reg.h> 12 + #include <linux/regmap.h> 12 13 13 - 14 - /* Register Map - AN888_SMUforIEEE_SynchEther_82P33xxx_RevH.pdf */ 15 - #define PAGE_NUM (8) 16 - #define _ADDR(page, offset) (((page) << 0x7) | ((offset) & 0x7f)) 17 - #define _PAGE(addr) (((addr) >> 0x7) & 0x7) 18 - #define _OFFSET(addr) ((addr) & 0x7f) 19 - 20 - #define DPLL1_TOD_CNFG 0x134 21 - #define DPLL2_TOD_CNFG 0x1B4 22 - 23 - #define DPLL1_TOD_STS 0x10B 24 - #define DPLL2_TOD_STS 0x18B 25 - 26 - #define DPLL1_TOD_TRIGGER 0x115 27 - #define DPLL2_TOD_TRIGGER 0x195 28 - 29 - #define DPLL1_OPERATING_MODE_CNFG 0x120 30 - #define DPLL2_OPERATING_MODE_CNFG 0x1A0 31 - 32 - #define DPLL1_HOLDOVER_FREQ_CNFG 0x12C 33 - #define DPLL2_HOLDOVER_FREQ_CNFG 0x1AC 34 - 35 - #define DPLL1_PHASE_OFFSET_CNFG 0x143 36 - #define DPLL2_PHASE_OFFSET_CNFG 0x1C3 37 - 38 - #define DPLL1_SYNC_EDGE_CNFG 0X140 39 - #define DPLL2_SYNC_EDGE_CNFG 0X1C0 40 - 41 - #define DPLL1_INPUT_MODE_CNFG 0X116 42 - #define DPLL2_INPUT_MODE_CNFG 0X196 43 - 44 - #define OUT_MUX_CNFG(outn) _ADDR(0x6, (0xC * (outn))) 45 - 46 - #define PAGE_ADDR 0x7F 47 - /* Register Map end */ 48 - 49 - /* Register definitions - AN888_SMUforIEEE_SynchEther_82P33xxx_RevH.pdf*/ 50 - #define TOD_TRIGGER(wr_trig, rd_trig) ((wr_trig & 0xf) << 4 | (rd_trig & 0xf)) 51 - #define SYNC_TOD BIT(1) 52 - #define PH_OFFSET_EN BIT(7) 53 - #define SQUELCH_ENABLE BIT(5) 54 - 55 - /* Bit definitions for the DPLL_MODE register */ 56 - #define PLL_MODE_SHIFT (0) 57 - #define PLL_MODE_MASK (0x1F) 58 - 59 - #define PEROUT_ENABLE_OUTPUT_MASK (0xdeadbeef) 60 - 61 - enum pll_mode { 62 - PLL_MODE_MIN = 0, 63 - PLL_MODE_AUTOMATIC = PLL_MODE_MIN, 64 - PLL_MODE_FORCE_FREERUN = 1, 65 - PLL_MODE_FORCE_HOLDOVER = 2, 66 - PLL_MODE_FORCE_LOCKED = 4, 67 - PLL_MODE_FORCE_PRE_LOCKED2 = 5, 68 - PLL_MODE_FORCE_PRE_LOCKED = 6, 69 - PLL_MODE_FORCE_LOST_PHASE = 7, 70 - PLL_MODE_DCO = 10, 71 - PLL_MODE_WPH = 18, 72 - PLL_MODE_MAX = PLL_MODE_WPH, 73 - }; 74 - 75 - enum hw_tod_trig_sel { 76 - HW_TOD_TRIG_SEL_MIN = 0, 77 - HW_TOD_TRIG_SEL_NO_WRITE = HW_TOD_TRIG_SEL_MIN, 78 - HW_TOD_TRIG_SEL_SYNC_SEL = 1, 79 - HW_TOD_TRIG_SEL_IN12 = 2, 80 - HW_TOD_TRIG_SEL_IN13 = 3, 81 - HW_TOD_TRIG_SEL_IN14 = 4, 82 - HW_TOD_TRIG_SEL_TOD_PPS = 5, 83 - HW_TOD_TRIG_SEL_TIMER_INTERVAL = 6, 84 - HW_TOD_TRIG_SEL_MSB_PHASE_OFFSET_CNFG = 7, 85 - HW_TOD_TRIG_SEL_MSB_HOLDOVER_FREQ_CNFG = 8, 86 - HW_TOD_WR_TRIG_SEL_MSB_TOD_CNFG = 9, 87 - HW_TOD_RD_TRIG_SEL_LSB_TOD_STS = HW_TOD_WR_TRIG_SEL_MSB_TOD_CNFG, 88 - WR_TRIG_SEL_MAX = HW_TOD_WR_TRIG_SEL_MSB_TOD_CNFG, 89 - }; 90 - 91 - /* Register bit definitions end */ 92 14 #define FW_FILENAME "idt82p33xxx.bin" 93 - #define MAX_PHC_PLL (2) 94 - #define TOD_BYTE_COUNT (10) 95 - #define MAX_MEASURMENT_COUNT (5) 96 - #define SNAP_THRESHOLD_NS (150000) 97 - #define SYNC_TOD_TIMEOUT_SEC (5) 98 - #define IDT82P33_MAX_WRITE_COUNT (512) 15 + #define MAX_PHC_PLL (2) 16 + #define TOD_BYTE_COUNT (10) 17 + #define DCO_MAX_PPB (92000) 18 + #define MAX_MEASURMENT_COUNT (5) 19 + #define SNAP_THRESHOLD_NS (10000) 20 + #define IMMEDIATE_SNAP_THRESHOLD_NS (50000) 21 + #define DDCO_THRESHOLD_NS (5) 22 + #define IDT82P33_MAX_WRITE_COUNT (512) 23 + #define PEROUT_ENABLE_OUTPUT_MASK (0xdeadbeef) 99 24 100 25 #define PLLMASK_ADDR_HI 0xFF 101 26 #define PLLMASK_ADDR_LO 0xA5 ··· 41 116 #define DEFAULT_OUTPUT_MASK_PLL0 (0xc0) 42 117 #define DEFAULT_OUTPUT_MASK_PLL1 DEFAULT_OUTPUT_MASK_PLL0 43 118 44 - /* PTP Hardware Clock interface */ 45 - struct idt82p33_channel { 46 - struct ptp_clock_info caps; 47 - struct ptp_clock *ptp_clock; 48 - struct idt82p33 *idt82p33; 49 - enum pll_mode pll_mode; 50 - /* task to turn off SYNC_TOD bit after pps sync */ 51 - struct delayed_work sync_tod_work; 52 - bool sync_tod_on; 53 - s32 current_freq_ppb; 54 - u8 output_mask; 55 - u16 dpll_tod_cnfg; 56 - u16 dpll_tod_trigger; 57 - u16 dpll_tod_sts; 58 - u16 dpll_mode_cnfg; 59 - u16 dpll_freq_cnfg; 60 - u16 dpll_phase_cnfg; 61 - u16 dpll_sync_cnfg; 62 - u16 dpll_input_mode_cnfg; 63 - }; 64 - 65 - struct idt82p33 { 66 - struct idt82p33_channel channel[MAX_PHC_PLL]; 67 - struct i2c_client *client; 68 - u8 page_offset; 69 - u8 pll_mask; 70 - ktime_t start_time; 71 - int calculate_overhead_flag; 72 - s64 tod_write_overhead_ns; 73 - /* Protects I2C read/modify/write registers from concurrent access */ 74 - struct mutex reg_lock; 75 - }; 76 - 77 - /* firmware interface */ 78 - struct idt82p33_fwrc { 79 - u8 hiaddr; 80 - u8 loaddr; 81 - u8 value; 82 - u8 reserved; 83 - } __packed; 84 - 85 119 /** 86 120 * @brief Maximum absolute value for write phase offset in femtoseconds 87 121 */ ··· 54 170 */ 55 171 #define IDT_T0DPLL_PHASE_RESOL 74506 56 172 173 + /* PTP Hardware Clock interface */ 174 + struct idt82p33_channel { 175 + struct ptp_clock_info caps; 176 + struct ptp_clock *ptp_clock; 177 + struct idt82p33 *idt82p33; 178 + enum pll_mode pll_mode; 179 + s32 current_freq_ppb; 180 + u8 output_mask; 181 + u16 dpll_tod_cnfg; 182 + u16 dpll_tod_trigger; 183 + u16 dpll_tod_sts; 184 + u16 dpll_mode_cnfg; 185 + u16 dpll_freq_cnfg; 186 + u16 dpll_phase_cnfg; 187 + u16 dpll_sync_cnfg; 188 + u16 dpll_input_mode_cnfg; 189 + }; 190 + 191 + struct idt82p33 { 192 + struct idt82p33_channel channel[MAX_PHC_PLL]; 193 + struct device *dev; 194 + u8 pll_mask; 195 + /* Mutex to protect operations from being interrupted */ 196 + struct mutex *lock; 197 + struct regmap *regmap; 198 + struct device *mfd; 199 + /* Overhead calculation for adjtime */ 200 + ktime_t start_time; 201 + int calculate_overhead_flag; 202 + s64 tod_write_overhead_ns; 203 + }; 204 + 205 + /* firmware interface */ 206 + struct idt82p33_fwrc { 207 + u8 hiaddr; 208 + u8 loaddr; 209 + u8 value; 210 + u8 reserved; 211 + } __packed; 57 212 58 213 #endif /* PTP_IDT82P33_H */
+3
include/linux/mfd/idt82p33_reg.h
··· 7 7 #ifndef HAVE_IDT82P33_REG 8 8 #define HAVE_IDT82P33_REG 9 9 10 + #define REG_ADDR(page, offset) (((page) << 0x7) | ((offset) & 0x7f)) 11 + 10 12 /* Register address */ 11 13 #define DPLL1_TOD_CNFG 0x134 12 14 #define DPLL2_TOD_CNFG 0x1B4 ··· 43 41 #define REG_SOFT_RESET 0X381 44 42 45 43 #define OUT_MUX_CNFG(outn) REG_ADDR(0x6, (0xC * (outn))) 44 + #define TOD_TRIGGER(wr_trig, rd_trig) ((wr_trig & 0xf) << 4 | (rd_trig & 0xf)) 46 45 47 46 /* Register bit definitions */ 48 47 #define SYNC_TOD BIT(1)