Re: [PATCH 1/3] i2c: append hardware lock with bus lock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 28, 2011 at 4:22 PM, Jean Delvare <khali@xxxxxxxxxxxx> wrote:
> Hi Haojian,
>
> On Thu, 28 Apr 2011 12:02:36 +0800, Haojian Zhuang wrote:
>> Both AP and CP are contained in Marvell PXA910 silicon. 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. Because of this, bus lock in AP side can't afford
>> this requirement. Now hardware lock is appended.
>
> I have no objection to the idea, but one question: when using the
> hardware lock, isn't the software mutex redundant? I would expect that
> you call the hardware_lock/unlock functions _instead_ of
> rt_mutex_lock/unlock, rather than in addition to it. Or do you still
> need the rt_mutex to prevent priority inversion?
>

Jean,

It's actually not redundant. The hardware lock is used to protect
access to the same register regions between two processors (AP
and CP so called), while the software lock is used to protect
access from within the AP side.

>>
>> Signed-off-by: Haojian Zhuang <haojian.zhuang@xxxxxxxxxxx>
>> Cc: Ben Dooks <ben-linux@xxxxxxxxx>
>> ---
>> Âdrivers/i2c/i2c-core.c | Â 22 ++++++++++++++++++----
>> Âinclude/linux/i2c.h  Â|  Â3 +++
>> Â2 files changed, 21 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
>> index 045ba6e..412c7a5 100644
>> --- a/drivers/i2c/i2c-core.c
>> +++ b/drivers/i2c/i2c-core.c
>> @@ -448,8 +448,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();
>> + Â Â }
>> Â}
>> ÂEXPORT_SYMBOL_GPL(i2c_lock_adapter);
>>
>> @@ -460,11 +463,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();
>> + Â Â Â Â Â Â Â Â Â Â if (!ret)
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â i2c_unlock_adapter(adapter);
>> + Â Â Â Â Â Â }
>> + Â Â Â Â Â Â return ret;
>> + Â Â }
>> Â}
>>
>> Â/**
>> @@ -477,8 +488,11 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
>>
>> Â Â Â if (parent)
>> Â Â Â Â Â Â Â i2c_unlock_adapter(parent);
>> - Â Â else
>> + Â Â else {
>> + Â Â Â Â Â Â if (adapter->hardware_unlock)
>> + Â Â Â Â Â Â Â Â Â Â adapter->hardware_unlock();
>> Â Â Â Â Â Â Â 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 06a8d9c..b283b4e 100644
>> --- a/include/linux/i2c.h
>> +++ b/include/linux/i2c.h
>> @@ -361,6 +361,9 @@ struct i2c_adapter {
>>
>>    /* data fields that are valid for all devices  */
>> Â Â Â struct rt_mutex bus_lock;
>> + Â Â void (*hardware_lock)(void);
>> + Â Â void (*hardware_unlock)(void);
>> + Â Â int (*hardware_trylock)(void);
>>
>> Â Â Â int timeout; Â Â Â Â Â Â Â Â Â Â/* in jiffies */
>> Â Â Â int retries;
>
>
> --
> Jean Delvare
>
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux