Commit 7c73537e8e4a296bb2780c1fadb2b82cd2c38185

Authored by Simon Glass
1 parent b382e02124

tpm: tpm_tis_i2c: Drop struct tpm_vendor_specific

This function is misnamed since it only applies to a single driver. Merge
its fields into its parent.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>

Showing 2 changed files with 35 additions and 60 deletions Side-by-side Diff

drivers/tpm/tpm_tis_i2c.c
... ... @@ -531,7 +531,7 @@
531 531 return rc;
532 532  
533 533 if ((buf & mask) == mask) {
534   - chip->vendor.locality = loc;
  534 + chip->locality = loc;
535 535 return loc;
536 536 }
537 537  
... ... @@ -567,7 +567,7 @@
567 567  
568 568 /* Wait for burstcount */
569 569 start = get_timer(0);
570   - stop = chip->vendor.timeout_a;
  570 + stop = chip->timeout_a;
571 571 do {
572 572 if (check_locality(chip, loc) >= 0)
573 573 return loc;
... ... @@ -582,7 +582,7 @@
582 582 /* NOTE: Since i2c read may fail, return 0 in this case --> time-out */
583 583 u8 buf;
584 584  
585   - if (iic_tpm_read(TPM_STS(chip->vendor.locality), &buf, 1) < 0)
  585 + if (iic_tpm_read(TPM_STS(chip->locality), &buf, 1) < 0)
586 586 return 0;
587 587 else
588 588 return buf;
... ... @@ -596,7 +596,7 @@
596 596 u8 buf = TPM_STS_COMMAND_READY;
597 597  
598 598 debug("%s\n", __func__);
599   - rc = iic_tpm_write_long(TPM_STS(chip->vendor.locality), &buf, 1);
  599 + rc = iic_tpm_write_long(TPM_STS(chip->locality), &buf, 1);
600 600 if (rc)
601 601 debug("%s: rc=%d\n", __func__, rc);
602 602 }
603 603  
... ... @@ -610,10 +610,10 @@
610 610 /* Wait for burstcount */
611 611 /* XXX: Which timeout value? Spec has 2 answers (c & d) */
612 612 start = get_timer(0);
613   - stop = chip->vendor.timeout_d;
  613 + stop = chip->timeout_d;
614 614 do {
615 615 /* Note: STS is little endian */
616   - addr = TPM_STS(chip->vendor.locality) + 1;
  616 + addr = TPM_STS(chip->locality) + 1;
617 617 if (iic_tpm_read(addr, buf, 3) < 0)
618 618 burstcnt = 0;
619 619 else
... ... @@ -666,7 +666,7 @@
666 666 if (burstcnt > (count - size))
667 667 burstcnt = count - size;
668 668  
669   - rc = iic_tpm_read(TPM_DATA_FIFO(chip->vendor.locality),
  669 + rc = iic_tpm_read(TPM_DATA_FIFO(chip->locality),
670 670 &(buf[size]), burstcnt);
671 671 if (rc == 0)
672 672 size += burstcnt;
... ... @@ -708,7 +708,7 @@
708 708 goto out;
709 709 }
710 710  
711   - wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, &status);
  711 + wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c, &status);
712 712 if (status & TPM_STS_DATA_AVAIL) { /* Retry? */
713 713 error("Error left over data\n");
714 714 size = -EIO;
... ... @@ -722,7 +722,7 @@
722 722 * so we sleep rather than keeping the bus busy
723 723 */
724 724 udelay(2000);
725   - release_locality(chip, chip->vendor.locality, 0);
  725 + release_locality(chip, chip->locality, 0);
726 726  
727 727 return size;
728 728 }
... ... @@ -746,7 +746,7 @@
746 746 if ((status & TPM_STS_COMMAND_READY) == 0) {
747 747 tpm_tis_i2c_ready(chip);
748 748 if (wait_for_stat(chip, TPM_STS_COMMAND_READY,
749   - chip->vendor.timeout_b, &status) < 0) {
  749 + chip->timeout_b, &status) < 0) {
750 750 rc = -ETIME;
751 751 goto out_err;
752 752 }
... ... @@ -768,7 +768,7 @@
768 768 burstcnt = CONFIG_TPM_TIS_I2C_BURST_LIMITATION;
769 769 #endif /* CONFIG_TPM_TIS_I2C_BURST_LIMITATION */
770 770  
771   - rc = iic_tpm_write(TPM_DATA_FIFO(chip->vendor.locality),
  771 + rc = iic_tpm_write(TPM_DATA_FIFO(chip->locality),
772 772 &(buf[count]), burstcnt);
773 773 if (rc == 0)
774 774 count += burstcnt;
... ... @@ -779,7 +779,7 @@
779 779 goto out_err;
780 780 }
781 781 rc = wait_for_stat(chip, TPM_STS_VALID,
782   - chip->vendor.timeout_c, &status);
  782 + chip->timeout_c, &status);
783 783 if (rc)
784 784 goto out_err;
785 785  
... ... @@ -791,7 +791,7 @@
791 791 }
792 792  
793 793 /* Go and do it */
794   - iic_tpm_write(TPM_STS(chip->vendor.locality), &sts, 1);
  794 + iic_tpm_write(TPM_STS(chip->locality), &sts, 1);
795 795 debug("done\n");
796 796  
797 797 return len;
798 798  
... ... @@ -804,18 +804,11 @@
804 804 * so we sleep rather than keeping the bus busy
805 805 */
806 806 udelay(2000);
807   - release_locality(chip, chip->vendor.locality, 0);
  807 + release_locality(chip, chip->locality, 0);
808 808  
809 809 return rc;
810 810 }
811 811  
812   -static struct tpm_vendor_specific tpm_tis_i2c = {
813   - .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
814   - .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
815   - .req_canceled = TPM_STS_COMMAND_READY,
816   -};
817   -
818   -
819 812 static enum i2c_chip_type tpm_vendor_chip_type(void)
820 813 {
821 814 #if CONFIG_IS_ENABLED(OF_CONTROL)
822 815  
823 816  
824 817  
825 818  
... ... @@ -832,25 +825,25 @@
832 825  
833 826 int tpm_vendor_init(struct udevice *dev)
834 827 {
835   - struct tpm_chip *chip;
  828 + struct tpm_chip *chip = &g_chip;
836 829 u32 vendor;
837 830 u32 expected_did_vid;
838 831  
839 832 tpm_dev.dev = dev;
840 833 tpm_dev.chip_type = tpm_vendor_chip_type();
  834 + chip->is_open = 1;
841 835  
842   - chip = tpm_register_hardware(&tpm_tis_i2c);
843   - if (chip < 0)
844   - return -ENODEV;
845   -
846 836 /* Disable interrupts (not supported) */
847   - chip->vendor.irq = 0;
  837 + chip->irq = 0;
848 838  
849 839 /* Default timeouts */
850   - chip->vendor.timeout_a = TIS_SHORT_TIMEOUT;
851   - chip->vendor.timeout_b = TIS_LONG_TIMEOUT;
852   - chip->vendor.timeout_c = TIS_SHORT_TIMEOUT;
853   - chip->vendor.timeout_d = TIS_SHORT_TIMEOUT;
  840 + chip->timeout_a = TIS_SHORT_TIMEOUT;
  841 + chip->timeout_b = TIS_LONG_TIMEOUT;
  842 + chip->timeout_c = TIS_SHORT_TIMEOUT;
  843 + chip->timeout_d = TIS_SHORT_TIMEOUT;
  844 + chip->req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID;
  845 + chip->req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID;
  846 + chip->req_canceled = TPM_STS_COMMAND_READY;
854 847  
855 848 if (request_locality(chip, 0) < 0)
856 849 return -ENODEV;
... ... @@ -887,7 +880,7 @@
887 880  
888 881 void tpm_vendor_cleanup(struct tpm_chip *chip)
889 882 {
890   - release_locality(chip, chip->vendor.locality, 1);
  883 + release_locality(chip, chip->locality, 1);
891 884 }
892 885  
893 886 /* Returns max number of milliseconds to wait */
... ... @@ -906,7 +899,7 @@
906 899 }
907 900  
908 901 if (duration_idx != TPM_UNDEFINED)
909   - duration = chip->vendor.duration[duration_idx];
  902 + duration = chip->duration[duration_idx];
910 903  
911 904 if (duration <= 0)
912 905 return 2 * 60 * HZ; /* Two minutes timeout */
... ... @@ -943,7 +936,7 @@
943 936 goto out;
944 937 }
945 938  
946   - if (chip->vendor.irq)
  939 + if (chip->irq)
947 940 goto out_recv;
948 941  
949 942 start = get_timer(0);
950 943  
... ... @@ -951,13 +944,13 @@
951 944 do {
952 945 debug("waiting for status... %ld %ld\n", start, stop);
953 946 u8 status = tpm_tis_i2c_status(chip);
954   - if ((status & chip->vendor.req_complete_mask) ==
955   - chip->vendor.req_complete_val) {
  947 + if ((status & chip->req_complete_mask) ==
  948 + chip->req_complete_val) {
956 949 debug("...got it;\n");
957 950 goto out_recv;
958 951 }
959 952  
960   - if (status == chip->vendor.req_canceled) {
  953 + if (status == chip->req_canceled) {
961 954 error("Operation Canceled\n");
962 955 rc = -ECANCELED;
963 956 goto out;
... ... @@ -1060,18 +1053,6 @@
1060 1053 }
1061 1054  
1062 1055 return 0;
1063   -}
1064   -
1065   -struct tpm_chip *tpm_register_hardware(const struct tpm_vendor_specific *entry)
1066   -{
1067   - struct tpm_chip *chip;
1068   -
1069   - /* Driver specific per-device data */
1070   - chip = &g_chip;
1071   - memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
1072   - chip->is_open = 1;
1073   -
1074   - return chip;
1075 1056 }
1076 1057  
1077 1058 int tis_init(void)
drivers/tpm/tpm_tis_i2c.h
... ... @@ -35,21 +35,17 @@
35 35  
36 36 struct tpm_chip;
37 37  
38   -struct tpm_vendor_specific {
39   - const u8 req_complete_mask;
40   - const u8 req_complete_val;
41   - const u8 req_canceled;
  38 +struct tpm_chip {
  39 + int is_open;
  40 + u8 req_complete_mask;
  41 + u8 req_complete_val;
  42 + u8 req_canceled;
42 43 int irq;
43 44 int locality;
44 45 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
45 46 unsigned long duration[3]; /* msec */
46 47 };
47 48  
48   -struct tpm_chip {
49   - int is_open;
50   - struct tpm_vendor_specific vendor;
51   -};
52   -
53 49 struct tpm_input_header {
54 50 __be16 tag;
55 51 __be32 length;
... ... @@ -105,8 +101,6 @@
105 101 union tpm_cmd_header header;
106 102 union tpm_cmd_params params;
107 103 } __packed;
108   -
109   -struct tpm_chip *tpm_register_hardware(const struct tpm_vendor_specific *);
110 104  
111 105 struct udevice;
112 106 int tpm_vendor_init(struct udevice *dev);