* [PATCH 1/3] i2c: core: append hardware lock with bus lock
2015-05-28 13:32 [PATCH 0/3] i2c: core/pxa: Add support for hardware lock Vaibhav Hiremath
@ 2015-05-28 13:32 ` Vaibhav Hiremath
2015-05-28 13:32 ` [PATCH 2/3] i2c: pxa: Add support for hardware lock Vaibhav Hiremath
2015-05-28 13:32 ` [PATCH 3/3] i2c: pxa: Add pin ctrl support for CP core access Vaibhav Hiremath
2 siblings, 0 replies; 4+ messages in thread
From: Vaibhav Hiremath @ 2015-05-28 13:32 UTC (permalink / raw)
To: linux-arm-kernel
To justify the need for hardware lock, lets take a real usecase scenario -
In case of Marvell SoC, PXA910 silicon, both AP and CP are present and
these two ARM cores are sharing one pair of I2C pins.
In order to keep I2C transaction operated with atomic, hardware lock
(RIPC) is required.
This patch extends support for atomic operation by adding hardware lock.
History:
The attempt has been made to push this patch-sets upstream sometime back in
2011, but not sure what happened later. I am making another attempt, hopefully
will conclude it now.
Link to previous patch:
http://marc.info/?l=linux-i2c&m=130432846300735&w=2
Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
---
drivers/i2c/i2c-core.c | 22 ++++++++++++++++++----
include/linux/i2c.h | 5 +++++
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 987c124..daea523 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -868,8 +868,11 @@ void i2c_lock_adapter(struct i2c_adapter *adapter)
if (parent)
i2c_lock_adapter(parent);
- else
+ else {
rt_mutex_lock(&adapter->bus_lock);
+ if (adapter->hardware_lock)
+ adapter->hardware_lock(adapter);
+ }
}
EXPORT_SYMBOL_GPL(i2c_lock_adapter);
@@ -880,11 +883,19 @@ EXPORT_SYMBOL_GPL(i2c_lock_adapter);
static int i2c_trylock_adapter(struct i2c_adapter *adapter)
{
struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
+ int ret = 0;
if (parent)
return i2c_trylock_adapter(parent);
- else
- return rt_mutex_trylock(&adapter->bus_lock);
+ else {
+ ret = rt_mutex_trylock(&adapter->bus_lock);
+ if (ret && adapter->hardware_trylock) {
+ ret = adapter->hardware_trylock(adapter);
+ if (!ret)
+ i2c_unlock_adapter(adapter);
+ }
+ return ret;
+ }
}
/**
@@ -897,8 +908,11 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
if (parent)
i2c_unlock_adapter(parent);
- else
+ else {
+ if (adapter->hardware_unlock)
+ adapter->hardware_unlock(adapter);
rt_mutex_unlock(&adapter->bus_lock);
+ }
}
EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e83a738..0758fb3 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -504,6 +504,11 @@ struct i2c_adapter {
/* data fields that are valid for all devices */
struct rt_mutex bus_lock;
+ /* if hardware lock feature provided */
+ void (*hardware_lock)(struct i2c_adapter *);
+ void (*hardware_unlock)(struct i2c_adapter *);
+ int (*hardware_trylock)(struct i2c_adapter *);
+
int timeout; /* in jiffies */
int retries;
struct device dev; /* the adapter device */
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] i2c: pxa: Add support for hardware lock
2015-05-28 13:32 [PATCH 0/3] i2c: core/pxa: Add support for hardware lock Vaibhav Hiremath
2015-05-28 13:32 ` [PATCH 1/3] i2c: core: append hardware lock with bus lock Vaibhav Hiremath
@ 2015-05-28 13:32 ` Vaibhav Hiremath
2015-05-28 13:32 ` [PATCH 3/3] i2c: pxa: Add pin ctrl support for CP core access Vaibhav Hiremath
2 siblings, 0 replies; 4+ messages in thread
From: Vaibhav Hiremath @ 2015-05-28 13:32 UTC (permalink / raw)
To: linux-arm-kernel
In case of PXA910 silicon, both AP and CP are present and
these two ARM cores are sharing one pair of I2C pins.
In order to keep I2C transaction operated with atomic, hardware lock
(RIPC) is required.
This patch extends support for atomic operation by adding hardware lock.
Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
---
drivers/i2c/busses/i2c-pxa.c | 75 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/i2c/pxa-i2c.h | 4 +++
2 files changed, 79 insertions(+)
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index f51d512..eb26eb1 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -167,6 +167,7 @@ struct pxa_i2c {
void __iomem *reg_isar;
void __iomem *reg_ilcr;
void __iomem *reg_iwcr;
+ void __iomem *hwlock_addr;
unsigned long iobase;
unsigned long iosize;
@@ -368,6 +369,9 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
+spinlock_t lock_for_ripc;
+static int ripc_status;
+
/* enable/disable i2c unit */
static inline void i2c_pxa_enable(struct pxa_i2c *i2c, bool enable)
{
@@ -378,6 +382,57 @@ static inline void i2c_pxa_enable(struct pxa_i2c *i2c, bool enable)
udelay(100);
}
+void mmp_hwlock_lock(struct i2c_adapter *adap)
+{
+ int cnt = 0;
+ unsigned long flags;
+
+ struct pxa_i2c *i2c = adap->algo_data;
+
+ spin_lock_irqsave(&lock_for_ripc, flags);
+ while(__raw_readl(i2c->hwlock_addr)) {
+ ripc_status = false;
+ spin_unlock_irqrestore(&lock_for_ripc, flags);
+ cpu_relax();
+ udelay(50);
+ cnt++;
+ if (cnt >= 10000) {
+ pr_warn("AP: fail to lock ripc!\n");
+ cnt = 0;
+ }
+ }
+ /* sure to hold ripc */
+ ripc_status = true;
+
+ spin_unlock_irqrestore(&lock_for_ripc, flags);
+}
+
+void mmp_hwlock_unlock(struct i2c_adapter *adap)
+{
+ unsigned long flags;
+
+ struct pxa_i2c *i2c = adap->algo_data;
+
+ spin_lock_irqsave(&lock_for_ripc, flags);
+ __raw_writel(1, i2c->hwlock_addr);
+ ripc_status = false;
+
+ spin_unlock_irqrestore(&lock_for_ripc, flags);
+}
+
+int mmp_hwlock_trylock(struct i2c_adapter *adap)
+{
+ unsigned long flags;
+
+ struct pxa_i2c *i2c = adap->algo_data;
+
+ spin_lock_irqsave(&lock_for_ripc, flags);
+ ripc_status = !__raw_readl(i2c->hwlock_addr);
+ spin_unlock_irqrestore(&lock_for_ripc, flags);
+
+ return ripc_status;
+}
+
static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
{
return !(readl(_ICR(i2c)) & ICR_SCLE);
@@ -1347,6 +1402,14 @@ static int i2c_pxa_probe(struct platform_device *dev)
i2c->iobase = res->start;
i2c->iosize = resource_size(res);
+ res = platform_get_resource(dev, IORESOURCE_MEM, 1);
+ if (res) {
+ i2c->hwlock_addr = ioremap(res->start, resource_size(res));
+ dev_info(&dev->dev, "hardware lock address: 0x%p\n",
+ i2c->hwlock_addr);
+ } else
+ dev_dbg(&dev->dev, "no hardware lock used\n");
+
i2c->irq = irq;
i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
@@ -1360,6 +1423,18 @@ static int i2c_pxa_probe(struct platform_device *dev)
i2c->ilcr = plat->ilcr;
i2c->iwcr = plat->iwcr;
i2c->adap.class = plat->class;
+
+ i2c->adap.hardware_lock = plat->hardware_lock;
+ i2c->adap.hardware_unlock = plat->hardware_unlock;
+ i2c->adap.hardware_trylock = plat->hardware_trylock;
+ } else {
+ if (i2c->hwlock_addr) {
+ spin_lock_init(&lock_for_ripc);
+
+ i2c->adap.hardware_lock = mmp_hwlock_lock;
+ i2c->adap.hardware_unlock = mmp_hwlock_unlock;
+ i2c->adap.hardware_trylock = mmp_hwlock_trylock;
+ }
}
if (i2c->high_mode) {
diff --git a/include/linux/i2c/pxa-i2c.h b/include/linux/i2c/pxa-i2c.h
index d1a44e8..e6f5981 100644
--- a/include/linux/i2c/pxa-i2c.h
+++ b/include/linux/i2c/pxa-i2c.h
@@ -72,6 +72,10 @@ struct i2c_pxa_platform_data {
unsigned long rate;
unsigned int ilcr;
unsigned int iwcr;
+ void (*hardware_lock)(struct i2c_adapter *);
+ void (*hardware_unlock)(struct i2c_adapter *);
+ int (*hardware_trylock)(struct i2c_adapter *);
+
};
extern void pxa_set_i2c_info(struct i2c_pxa_platform_data *info);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] i2c: pxa: Add pin ctrl support for CP core access
2015-05-28 13:32 [PATCH 0/3] i2c: core/pxa: Add support for hardware lock Vaibhav Hiremath
2015-05-28 13:32 ` [PATCH 1/3] i2c: core: append hardware lock with bus lock Vaibhav Hiremath
2015-05-28 13:32 ` [PATCH 2/3] i2c: pxa: Add support for hardware lock Vaibhav Hiremath
@ 2015-05-28 13:32 ` Vaibhav Hiremath
2 siblings, 0 replies; 4+ messages in thread
From: Vaibhav Hiremath @ 2015-05-28 13:32 UTC (permalink / raw)
To: linux-arm-kernel
PMIC TWSI pins configuration for AP and CP is different on
eden, it need to be set to function 0 when AP get RIPC lock.
When AP release RIPC lock, it also need configure twsi pins
to other state, otherwise pinctrl will assume pins configration
is not changed even if it is changed by CP, so it will not
change twsi pins configuration to AP state when AP get RIPC
next time.
Signed-off-by: Shouming Wang <wangshm@marvell.com>
Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
---
drivers/i2c/busses/i2c-pxa.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index eb26eb1..1340de1 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -184,6 +184,7 @@ struct pxa_i2c {
struct pinctrl *pinctrl;
struct pinctrl_state *pin_i2c;
struct pinctrl_state *pin_gpio;
+ struct pinctrl_state *pin_i2c_cp;
};
#define _IBMR(i2c) ((i2c)->reg_ibmr)
@@ -405,6 +406,10 @@ void mmp_hwlock_lock(struct i2c_adapter *adap)
ripc_status = true;
spin_unlock_irqrestore(&lock_for_ripc, flags);
+
+ if (pinctrl_select_state(i2c->pinctrl, i2c->pin_i2c) < 0)
+ dev_err(&i2c->adap.dev, "could not set i2c AP pins\n");
+
}
void mmp_hwlock_unlock(struct i2c_adapter *adap)
@@ -413,6 +418,9 @@ void mmp_hwlock_unlock(struct i2c_adapter *adap)
struct pxa_i2c *i2c = adap->algo_data;
+ if (pinctrl_select_state(i2c->pinctrl, i2c->pin_i2c_cp) < 0)
+ dev_err(&i2c->adap.dev, "could not set i2c CP pins\n");
+
spin_lock_irqsave(&lock_for_ripc, flags);
__raw_writel(1, i2c->hwlock_addr);
ripc_status = false;
@@ -430,6 +438,9 @@ int mmp_hwlock_trylock(struct i2c_adapter *adap)
ripc_status = !__raw_readl(i2c->hwlock_addr);
spin_unlock_irqrestore(&lock_for_ripc, flags);
+ if (ripc_status && (pinctrl_select_state(i2c->pinctrl, i2c->pin_i2c) < 0))
+ dev_err(&i2c->adap.dev, "could not set i2c AP pins\n");
+
return ripc_status;
}
@@ -1497,8 +1508,14 @@ static int i2c_pxa_probe(struct platform_device *dev)
ret = IS_ERR(i2c->pin_gpio);
}
+ /* pin ctrl for CP - optional */
+ i2c->pin_i2c_cp = pinctrl_lookup_state(i2c->pinctrl, "i2c_cp");
+ if (IS_ERR(i2c->pin_i2c_cp))
+ dev_err(&dev->dev, "could not get i2c_cp pinstate\n");
+
if (ret) {
i2c->pin_i2c = NULL;
+ i2c->pin_i2c_cp = NULL;
i2c->pin_gpio = NULL;
i2c->pinctrl = NULL;
ret = 0;
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread