Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: drivers/tpm/slb9635_i2c/compatibility.c

Issue 6683023: Add Infineon v05 TPM driver (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/u-boot-next.git@chromeos-v2010.09
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: drivers/tpm/slb9635_i2c/compatibility.c
diff --git a/drivers/tpm/slb9635_i2c/compatibility.c b/drivers/tpm/slb9635_i2c/compatibility.c
new file mode 100644
index 0000000000000000000000000000000000000000..10ac195a9f4ea5b1172841ac50b6858cf19ca293
--- /dev/null
+++ b/drivers/tpm/slb9635_i2c/compatibility.c
@@ -0,0 +1,134 @@
+/*******************************************************************************
+**
+** FILENAME: $Id$
+** COPYRIGHT: Infineon Technologies
+** DESCRIPTION: I2C TPM - Compatibility layer to port linux driver to U-Boot
+** CREATION DATE: 2010/11/10
+** LAST CHANGE: $Date: 2010-10-20 12:04:48 +0200 (Wed, 20 Oct 2010) $
+** $Author$
+** VERSION: $Revision: 59 $
+**
+*******************************************************************************/
+
+#include <common.h>
+#include "compatibility.h"
+
+struct device_private p = {
Che-Liang Chiou 2011/03/14 08:49:54 Should we add a "static" prefix here?
rongchang 2011/03/23 11:44:57 Same as compatibility.h. But this file was removed
+ .driver_data = NULL,
+};
+
+/* init device structure */
+struct device d = {
Che-Liang Chiou 2011/03/14 08:49:54 Same as above.
+ .parent = NULL,
+ .p = &p,
+};
+
+/* Taken from <linux/time.h> */
+#define LONG_MAX ((long)(~0UL>>1))
+#define MSEC_PER_SEC 1000L
+#define USEC_PER_SEC 1000000L
+#define MAX_JIFFY_OFFSET ((LONG_MAX >> 1)-1)
+#define BITS_PER_LONG 32
+
+/* global time counter */
+unsigned long jiffies;
Che-Liang Chiou 2011/03/14 08:49:54 Same as above.
+
+/*
+ * Convert jiffies to milliseconds and back.
+ *
+ * Avoid unnecessary multiplications/divisions in the
+ * two most common HZ cases:
+ */
+inline unsigned int jiffies_to_msecs(const unsigned long j)
+{
+#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
+ return (MSEC_PER_SEC / HZ) * j;
+#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
+ return (j + (HZ / MSEC_PER_SEC) - 1) / (HZ / MSEC_PER_SEC);
+#else
+# if BITS_PER_LONG == 32
+ return (HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32;
+# else
+ return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN;
+# endif
+#endif
+}
+
+unsigned long msecs_to_jiffies(const unsigned int m)
+{
+ /*
+ * Negative value, means infinite timeout:
+ */
+ if ((int)m < 0)
+ return MAX_JIFFY_OFFSET;
+
+#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
+ /*
+ * HZ is equal to or smaller than 1000, and 1000 is a nice
+ * round multiple of HZ, divide with the factor between them,
+ * but round upwards:
+ */
+ return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
+#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
+ /*
+ * HZ is larger than 1000, and HZ is a nice round multiple of
+ * 1000 - simply multiply with the factor between them.
+ *
+ * But first make sure the multiplication result cannot
+ * overflow:
+ */
+ if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
+ return MAX_JIFFY_OFFSET;
+
+ return m * (HZ / MSEC_PER_SEC);
+#else
+ /*
+ * Generic case - multiply, round and divide. But first
+ * check that if we are doing a net multiplication, that
+ * we wouldn't overflow:
+ */
+ if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
+ return MAX_JIFFY_OFFSET;
+
+ return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
+ >> MSEC_TO_HZ_SHR32;
+#endif
+}
+
+inline unsigned int jiffies_to_usecs(const unsigned long j)
+{
+#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
+ return (USEC_PER_SEC / HZ) * j;
+#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
+ return (j + (HZ / USEC_PER_SEC) - 1) / (HZ / USEC_PER_SEC);
+#else
+# if BITS_PER_LONG == 32
+ return (HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
+# else
+ return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN;
+# endif
+#endif
+}
+
+unsigned long usecs_to_jiffies(const unsigned int u)
+{
+ if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
+ return MAX_JIFFY_OFFSET;
+#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
+ return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ);
+#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
+ return u * (HZ / USEC_PER_SEC);
+#else
+ return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32)
+ >> USEC_TO_HZ_SHR32;
+#endif
+}
+
+/* replacement for msleep() just delaying */
+void msleep2(unsigned int t)
+{
+ dbg_printf("INFO: msleep() %d ms, jiffies=%ld\n", t, jiffies);
+ udelay(t * 1000);
+ jiffies += msecs_to_jiffies(t);
+}
+

Powered by Google App Engine
This is Rietveld 408576698