Skip to content

Commit 2cf3afc

Browse files
committed
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "A set of updates and bugfixes for the new designware-baytrail driver. And a documentation bugfix" * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: imx: add required clocks property to binding i2c: designware-baytrail: baytrail_i2c_acquire() might sleep i2c: designware-baytrail: cross-check lock functions i2c: designware-baytrail: fix sparse warnings i2c: designware-baytrail: fix typo in error path i2c: designware-baytrail: describe magic numbers
2 parents 374dab2 + 5d23211 commit 2cf3afc

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

Documentation/devicetree/bindings/i2c/i2c-imx.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Required properties:
77
- "fsl,vf610-i2c" for I2C compatible with the one integrated on Vybrid vf610 SoC
88
- reg : Should contain I2C/HS-I2C registers location and length
99
- interrupts : Should contain I2C/HS-I2C interrupt
10+
- clocks : Should contain the I2C/HS-I2C clock specifier
1011

1112
Optional properties:
1213
- clock-frequency : Constains desired I2C/HS-I2C bus clock frequency in Hz.

drivers/i2c/busses/i2c-designware-baytrail.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,31 @@
1717
#include <linux/acpi.h>
1818
#include <linux/i2c.h>
1919
#include <linux/interrupt.h>
20+
2021
#include <asm/iosf_mbi.h>
22+
2123
#include "i2c-designware-core.h"
2224

2325
#define SEMAPHORE_TIMEOUT 100
2426
#define PUNIT_SEMAPHORE 0x7
27+
#define PUNIT_SEMAPHORE_BIT BIT(0)
28+
#define PUNIT_SEMAPHORE_ACQUIRE BIT(1)
2529

2630
static unsigned long acquired;
2731

2832
static int get_sem(struct device *dev, u32 *sem)
2933
{
30-
u32 reg_val;
34+
u32 data;
3135
int ret;
3236

3337
ret = iosf_mbi_read(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_READ, PUNIT_SEMAPHORE,
34-
&reg_val);
38+
&data);
3539
if (ret) {
3640
dev_err(dev, "iosf failed to read punit semaphore\n");
3741
return ret;
3842
}
3943

40-
*sem = reg_val & 0x1;
44+
*sem = data & PUNIT_SEMAPHORE_BIT;
4145

4246
return 0;
4347
}
@@ -52,27 +56,29 @@ static void reset_semaphore(struct device *dev)
5256
return;
5357
}
5458

55-
data = data & 0xfffffffe;
59+
data &= ~PUNIT_SEMAPHORE_BIT;
5660
if (iosf_mbi_write(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_WRITE,
57-
PUNIT_SEMAPHORE, data))
61+
PUNIT_SEMAPHORE, data))
5862
dev_err(dev, "iosf failed to reset punit semaphore during write\n");
5963
}
6064

61-
int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
65+
static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
6266
{
63-
u32 sem = 0;
67+
u32 sem;
6468
int ret;
6569
unsigned long start, end;
6670

71+
might_sleep();
72+
6773
if (!dev || !dev->dev)
6874
return -ENODEV;
6975

70-
if (!dev->acquire_lock)
76+
if (!dev->release_lock)
7177
return 0;
7278

73-
/* host driver writes 0x2 to side band semaphore register */
79+
/* host driver writes to side band semaphore register */
7480
ret = iosf_mbi_write(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_WRITE,
75-
PUNIT_SEMAPHORE, 0x2);
81+
PUNIT_SEMAPHORE, PUNIT_SEMAPHORE_ACQUIRE);
7682
if (ret) {
7783
dev_err(dev->dev, "iosf punit semaphore request failed\n");
7884
return ret;
@@ -81,7 +87,7 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
8187
/* host driver waits for bit 0 to be set in semaphore register */
8288
start = jiffies;
8389
end = start + msecs_to_jiffies(SEMAPHORE_TIMEOUT);
84-
while (!time_after(jiffies, end)) {
90+
do {
8591
ret = get_sem(dev->dev, &sem);
8692
if (!ret && sem) {
8793
acquired = jiffies;
@@ -91,14 +97,14 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
9197
}
9298

9399
usleep_range(1000, 2000);
94-
}
100+
} while (time_before(jiffies, end));
95101

96102
dev_err(dev->dev, "punit semaphore timed out, resetting\n");
97103
reset_semaphore(dev->dev);
98104

99105
ret = iosf_mbi_read(BT_MBI_UNIT_PMC, BT_MBI_BUNIT_READ,
100-
PUNIT_SEMAPHORE, &sem);
101-
if (!ret)
106+
PUNIT_SEMAPHORE, &sem);
107+
if (ret)
102108
dev_err(dev->dev, "iosf failed to read punit semaphore\n");
103109
else
104110
dev_err(dev->dev, "PUNIT SEM: %d\n", sem);
@@ -107,9 +113,8 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
107113

108114
return -ETIMEDOUT;
109115
}
110-
EXPORT_SYMBOL(baytrail_i2c_acquire);
111116

112-
void baytrail_i2c_release(struct dw_i2c_dev *dev)
117+
static void baytrail_i2c_release(struct dw_i2c_dev *dev)
113118
{
114119
if (!dev || !dev->dev)
115120
return;
@@ -121,7 +126,6 @@ void baytrail_i2c_release(struct dw_i2c_dev *dev)
121126
dev_dbg(dev->dev, "punit semaphore held for %ums\n",
122127
jiffies_to_msecs(jiffies - acquired));
123128
}
124-
EXPORT_SYMBOL(baytrail_i2c_release);
125129

126130
int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev)
127131
{
@@ -137,7 +141,6 @@ int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev)
137141
return 0;
138142

139143
status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host);
140-
141144
if (ACPI_FAILURE(status))
142145
return 0;
143146

@@ -153,7 +156,6 @@ int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev)
153156

154157
return 0;
155158
}
156-
EXPORT_SYMBOL(i2c_dw_eval_lock_support);
157159

158160
MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>");
159161
MODULE_DESCRIPTION("Baytrail I2C Semaphore driver");

0 commit comments

Comments
 (0)