2 * Intel BayTrail PMIC I2C bus semaphore implementaion
3 * Copyright (c) 2014, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #include <linux/module.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/acpi.h>
18 #include <linux/i2c.h>
19 #include <linux/interrupt.h>
21 #include <asm/iosf_mbi.h>
23 #include "i2c-designware-core.h"
25 #define SEMAPHORE_TIMEOUT 100
26 #define PUNIT_SEMAPHORE 0x7
27 #define PUNIT_SEMAPHORE_BIT BIT(0)
28 #define PUNIT_SEMAPHORE_ACQUIRE BIT(1)
30 static unsigned long acquired
;
32 static int get_sem(struct device
*dev
, u32
*sem
)
37 ret
= iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, PUNIT_SEMAPHORE
, &data
);
39 dev_err(dev
, "iosf failed to read punit semaphore\n");
43 *sem
= data
& PUNIT_SEMAPHORE_BIT
;
48 static void reset_semaphore(struct device
*dev
)
52 if (iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, PUNIT_SEMAPHORE
, &data
)) {
53 dev_err(dev
, "iosf failed to reset punit semaphore during read\n");
57 data
&= ~PUNIT_SEMAPHORE_BIT
;
58 if (iosf_mbi_write(BT_MBI_UNIT_PMC
, MBI_REG_WRITE
, PUNIT_SEMAPHORE
, data
))
59 dev_err(dev
, "iosf failed to reset punit semaphore during write\n");
62 static int baytrail_i2c_acquire(struct dw_i2c_dev
*dev
)
64 u32 sem
= PUNIT_SEMAPHORE_ACQUIRE
;
66 unsigned long start
, end
;
70 if (!dev
|| !dev
->dev
)
73 if (!dev
->release_lock
)
76 /* host driver writes to side band semaphore register */
77 ret
= iosf_mbi_write(BT_MBI_UNIT_PMC
, MBI_REG_WRITE
, PUNIT_SEMAPHORE
, sem
);
79 dev_err(dev
->dev
, "iosf punit semaphore request failed\n");
83 /* host driver waits for bit 0 to be set in semaphore register */
85 end
= start
+ msecs_to_jiffies(SEMAPHORE_TIMEOUT
);
87 ret
= get_sem(dev
->dev
, &sem
);
90 dev_dbg(dev
->dev
, "punit semaphore acquired after %ums\n",
91 jiffies_to_msecs(jiffies
- start
));
95 usleep_range(1000, 2000);
96 } while (time_before(jiffies
, end
));
98 dev_err(dev
->dev
, "punit semaphore timed out, resetting\n");
99 reset_semaphore(dev
->dev
);
101 ret
= iosf_mbi_read(BT_MBI_UNIT_PMC
, MBI_REG_READ
, PUNIT_SEMAPHORE
, &sem
);
103 dev_err(dev
->dev
, "iosf failed to read punit semaphore\n");
105 dev_err(dev
->dev
, "PUNIT SEM: %d\n", sem
);
112 static void baytrail_i2c_release(struct dw_i2c_dev
*dev
)
114 if (!dev
|| !dev
->dev
)
117 if (!dev
->acquire_lock
)
120 reset_semaphore(dev
->dev
);
121 dev_dbg(dev
->dev
, "punit semaphore held for %ums\n",
122 jiffies_to_msecs(jiffies
- acquired
));
125 int i2c_dw_eval_lock_support(struct dw_i2c_dev
*dev
)
128 unsigned long long shared_host
= 0;
131 if (!dev
|| !dev
->dev
)
134 handle
= ACPI_HANDLE(dev
->dev
);
138 status
= acpi_evaluate_integer(handle
, "_SEM", NULL
, &shared_host
);
139 if (ACPI_FAILURE(status
))
143 dev_info(dev
->dev
, "I2C bus managed by PUNIT\n");
144 dev
->acquire_lock
= baytrail_i2c_acquire
;
145 dev
->release_lock
= baytrail_i2c_release
;
146 dev
->pm_runtime_disabled
= true;
149 if (!iosf_mbi_available())
150 return -EPROBE_DEFER
;
155 MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>");
156 MODULE_DESCRIPTION("Baytrail I2C Semaphore driver");
157 MODULE_LICENSE("GPL v2");
This page took 0.055142 seconds and 5 git commands to generate.