diff options
Diffstat (limited to 'drivers/i2c/busses/i2c-designware-baytrail.c')
-rw-r--r-- | drivers/i2c/busses/i2c-designware-baytrail.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/drivers/i2c/busses/i2c-designware-baytrail.c b/drivers/i2c/busses/i2c-designware-baytrail.c index 5f1ff4cc5c34..7d7ae97476e2 100644 --- a/drivers/i2c/busses/i2c-designware-baytrail.c +++ b/drivers/i2c/busses/i2c-designware-baytrail.c | |||
@@ -17,27 +17,31 @@ | |||
17 | #include <linux/acpi.h> | 17 | #include <linux/acpi.h> |
18 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
20 | |||
20 | #include <asm/iosf_mbi.h> | 21 | #include <asm/iosf_mbi.h> |
22 | |||
21 | #include "i2c-designware-core.h" | 23 | #include "i2c-designware-core.h" |
22 | 24 | ||
23 | #define SEMAPHORE_TIMEOUT 100 | 25 | #define SEMAPHORE_TIMEOUT 100 |
24 | #define PUNIT_SEMAPHORE 0x7 | 26 | #define PUNIT_SEMAPHORE 0x7 |
27 | #define PUNIT_SEMAPHORE_BIT BIT(0) | ||
28 | #define PUNIT_SEMAPHORE_ACQUIRE BIT(1) | ||
25 | 29 | ||
26 | static unsigned long acquired; | 30 | static unsigned long acquired; |
27 | 31 | ||
28 | static int get_sem(struct device *dev, u32 *sem) | 32 | static int get_sem(struct device *dev, u32 *sem) |
29 | { | 33 | { |
30 | u32 reg_val; | 34 | u32 data; |
31 | int ret; | 35 | int ret; |
32 | 36 | ||
33 | ret = iosf_mbi_read(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_READ, PUNIT_SEMAPHORE, | 37 | ret = iosf_mbi_read(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_READ, PUNIT_SEMAPHORE, |
34 | ®_val); | 38 | &data); |
35 | if (ret) { | 39 | if (ret) { |
36 | dev_err(dev, "iosf failed to read punit semaphore\n"); | 40 | dev_err(dev, "iosf failed to read punit semaphore\n"); |
37 | return ret; | 41 | return ret; |
38 | } | 42 | } |
39 | 43 | ||
40 | *sem = reg_val & 0x1; | 44 | *sem = data & PUNIT_SEMAPHORE_BIT; |
41 | 45 | ||
42 | return 0; | 46 | return 0; |
43 | } | 47 | } |
@@ -52,27 +56,29 @@ static void reset_semaphore(struct device *dev) | |||
52 | return; | 56 | return; |
53 | } | 57 | } |
54 | 58 | ||
55 | data = data & 0xfffffffe; | 59 | data &= ~PUNIT_SEMAPHORE_BIT; |
56 | if (iosf_mbi_write(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_WRITE, | 60 | if (iosf_mbi_write(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_WRITE, |
57 | PUNIT_SEMAPHORE, data)) | 61 | PUNIT_SEMAPHORE, data)) |
58 | dev_err(dev, "iosf failed to reset punit semaphore during write\n"); | 62 | dev_err(dev, "iosf failed to reset punit semaphore during write\n"); |
59 | } | 63 | } |
60 | 64 | ||
61 | int baytrail_i2c_acquire(struct dw_i2c_dev *dev) | 65 | static int baytrail_i2c_acquire(struct dw_i2c_dev *dev) |
62 | { | 66 | { |
63 | u32 sem = 0; | 67 | u32 sem; |
64 | int ret; | 68 | int ret; |
65 | unsigned long start, end; | 69 | unsigned long start, end; |
66 | 70 | ||
71 | might_sleep(); | ||
72 | |||
67 | if (!dev || !dev->dev) | 73 | if (!dev || !dev->dev) |
68 | return -ENODEV; | 74 | return -ENODEV; |
69 | 75 | ||
70 | if (!dev->acquire_lock) | 76 | if (!dev->release_lock) |
71 | return 0; | 77 | return 0; |
72 | 78 | ||
73 | /* host driver writes 0x2 to side band semaphore register */ | 79 | /* host driver writes to side band semaphore register */ |
74 | ret = iosf_mbi_write(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_WRITE, | 80 | ret = iosf_mbi_write(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_WRITE, |
75 | PUNIT_SEMAPHORE, 0x2); | 81 | PUNIT_SEMAPHORE, PUNIT_SEMAPHORE_ACQUIRE); |
76 | if (ret) { | 82 | if (ret) { |
77 | dev_err(dev->dev, "iosf punit semaphore request failed\n"); | 83 | dev_err(dev->dev, "iosf punit semaphore request failed\n"); |
78 | return ret; | 84 | return ret; |
@@ -81,7 +87,7 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev) | |||
81 | /* host driver waits for bit 0 to be set in semaphore register */ | 87 | /* host driver waits for bit 0 to be set in semaphore register */ |
82 | start = jiffies; | 88 | start = jiffies; |
83 | end = start + msecs_to_jiffies(SEMAPHORE_TIMEOUT); | 89 | end = start + msecs_to_jiffies(SEMAPHORE_TIMEOUT); |
84 | while (!time_after(jiffies, end)) { | 90 | do { |
85 | ret = get_sem(dev->dev, &sem); | 91 | ret = get_sem(dev->dev, &sem); |
86 | if (!ret && sem) { | 92 | if (!ret && sem) { |
87 | acquired = jiffies; | 93 | acquired = jiffies; |
@@ -91,14 +97,14 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev) | |||
91 | } | 97 | } |
92 | 98 | ||
93 | usleep_range(1000, 2000); | 99 | usleep_range(1000, 2000); |
94 | } | 100 | } while (time_before(jiffies, end)); |
95 | 101 | ||
96 | dev_err(dev->dev, "punit semaphore timed out, resetting\n"); | 102 | dev_err(dev->dev, "punit semaphore timed out, resetting\n"); |
97 | reset_semaphore(dev->dev); | 103 | reset_semaphore(dev->dev); |
98 | 104 | ||
99 | ret = iosf_mbi_read(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_READ, | 105 | ret = iosf_mbi_read(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_READ, |
100 | PUNIT_SEMAPHORE, &sem); | 106 | PUNIT_SEMAPHORE, &sem); |
101 | if (!ret) | 107 | if (ret) |
102 | dev_err(dev->dev, "iosf failed to read punit semaphore\n"); | 108 | dev_err(dev->dev, "iosf failed to read punit semaphore\n"); |
103 | else | 109 | else |
104 | dev_err(dev->dev, "PUNIT SEM: %d\n", sem); | 110 | dev_err(dev->dev, "PUNIT SEM: %d\n", sem); |
@@ -107,9 +113,8 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev) | |||
107 | 113 | ||
108 | return -ETIMEDOUT; | 114 | return -ETIMEDOUT; |
109 | } | 115 | } |
110 | EXPORT_SYMBOL(baytrail_i2c_acquire); | ||
111 | 116 | ||
112 | void baytrail_i2c_release(struct dw_i2c_dev *dev) | 117 | static void baytrail_i2c_release(struct dw_i2c_dev *dev) |
113 | { | 118 | { |
114 | if (!dev || !dev->dev) | 119 | if (!dev || !dev->dev) |
115 | return; | 120 | return; |
@@ -121,7 +126,6 @@ void baytrail_i2c_release(struct dw_i2c_dev *dev) | |||
121 | dev_dbg(dev->dev, "punit semaphore held for %ums\n", | 126 | dev_dbg(dev->dev, "punit semaphore held for %ums\n", |
122 | jiffies_to_msecs(jiffies - acquired)); | 127 | jiffies_to_msecs(jiffies - acquired)); |
123 | } | 128 | } |
124 | EXPORT_SYMBOL(baytrail_i2c_release); | ||
125 | 129 | ||
126 | int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev) | 130 | int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev) |
127 | { | 131 | { |
@@ -137,7 +141,6 @@ int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev) | |||
137 | return 0; | 141 | return 0; |
138 | 142 | ||
139 | status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host); | 143 | status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host); |
140 | |||
141 | if (ACPI_FAILURE(status)) | 144 | if (ACPI_FAILURE(status)) |
142 | return 0; | 145 | return 0; |
143 | 146 | ||
@@ -153,7 +156,6 @@ int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev) | |||
153 | 156 | ||
154 | return 0; | 157 | return 0; |
155 | } | 158 | } |
156 | EXPORT_SYMBOL(i2c_dw_eval_lock_support); | ||
157 | 159 | ||
158 | MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>"); | 160 | MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>"); |
159 | MODULE_DESCRIPTION("Baytrail I2C Semaphore driver"); | 161 | MODULE_DESCRIPTION("Baytrail I2C Semaphore driver"); |