i2c-designware-baytrail: describe magic numbers
Subsystems (3)
PATCH 1/5 i2c-designware-baytrail: describe magic numbers
The patch converts hardcoded numerical constants to a named ones.
While here, align the variable name in get_sem() and reset_semaphore().
--- drivers/i2c/busses/i2c-designware-baytrail.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-designware-baytrail.c +9 -7
@@ -22,22 +22,24 @@#define SEMAPHORE_TIMEOUT 100#define PUNIT_SEMAPHORE 0x7 +#define PUNIT_SEMAPHORE_BIT BIT(0) +#define PUNIT_SEMAPHORE_ACQUIRE BIT(1)static unsigned long acquired;static int get_sem (struct device *dev,u32 *sem) { -u32 reg_val; +u32 data;int ret; ret =iosf_mbi_read (BT_MBI_UNIT_PMC ,BT_MBI_BUNIT_READ ,PUNIT_SEMAPHORE , - ®_val); + &data);if (ret) {dev_err (dev,"iosf failed to read punit semaphore\n" );return ret; } - *sem = reg_val &0x1 ; + *sem = data &PUNIT_SEMAPHORE_BIT ;return 0 ; }
@@ -52,9 +54,9 @@ static void reset_semaphore(struct device *dev)return ; } - data = data &0xfffffffe ; + data &= ~PUNIT_SEMAPHORE_BIT ;if (iosf_mbi_write (BT_MBI_UNIT_PMC ,BT_MBI_BUNIT_WRITE , -PUNIT_SEMAPHORE , data)) +PUNIT_SEMAPHORE , data))dev_err (dev,"iosf failed to reset punit semaphore during write\n" ); }
@@ -70,9 +72,9 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev)if (!dev->acquire_lock)return 0 ; -/* host driver writes 0x2 to side band semaphore register */ +/* host driver writes to side band semaphore register */ ret =iosf_mbi_write (BT_MBI_UNIT_PMC ,BT_MBI_BUNIT_WRITE , -PUNIT_SEMAPHORE ,0x2 ); +PUNIT_SEMAPHORE ,PUNIT_SEMAPHORE_ACQUIRE );if (ret) {dev_err (dev->dev,"iosf punit semaphore request failed\n" );return ret;
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 1423587970-19136-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]
PATCH 2/5 i2c-designware-baytrail: fix typo in error path
It seems we have same message for different return values in get_sem() and baytrail_i2c_acquire(). I suspect this is just a typo, so this patch fixes it.
--- drivers/i2c/busses/i2c-designware-baytrail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-baytrail.c +2 -2
@@ -99,8 +99,8 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev)reset_semaphore (dev->dev); ret =iosf_mbi_read (BT_MBI_UNIT_PMC ,BT_MBI_BUNIT_READ , -PUNIT_SEMAPHORE , &sem); -if (!ret) +PUNIT_SEMAPHORE , &sem); +if (ret)dev_err (dev->dev,"iosf failed to read punit semaphore\n" );else dev_err (dev->dev,"PUNIT SEM: %d\n" , sem);
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 1423587970-19136-2-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]
David E. Box
Acked-byRe: [PATCH v1 2/5] i2c-designware-baytrail: fix typo in error path
Quoted 4 lines · Andy Shevchenko
It seems we have same message for different return values in
get_sem()andbaytrail_i2c_acquire(). I suspect this is just a typo, so this patch fixes it.
Thanks for spotting this. Timeouts are infrequent and I didn't notice the error here.
Dave
Quoted 22 lines
--- drivers/i2c/busses/i2c-designware-baytrail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-baytrail.c +2
-2@@ -99,8 +99,8 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev)reset_semaphore (dev->dev); ret =iosf_mbi_read (BT_MBI_UNIT_PMC ,BT_MBI_BUNIT_READ , -PUNIT_SEMAPHORE , &sem); -if (!ret) +PUNIT_SEMAPHORE , &sem); +if (ret)dev_err (dev->dev,"iosf failed to read punit semaphore\n" );else dev_err (dev->dev,"PUNIT SEM: %d\n" , sem);Signature · 1 line
2.1.4
Re: [PATCH v1 2/5] i2c-designware-baytrail: fix typo in error path
In reply to a message not in the archivedrivers/i2c/busses/i2c-designware-baytrail.c int baytrail_i2c_acquire(struct dw_i2c_dev *dev) · line 106
Quoted 6 lines
drivers/i2c/busses/i2c-designware-baytrail.c +2
-0+ PUNIT_SEMAPHORE, &sem); +if (ret)dev_err (dev->dev,"iosf failed to read punit semaphore\n" );else dev_err (dev->dev,"PUNIT SEM: %d\n" , sem);
Shouldn't the latter be a dev_dbg?
Re: [PATCH v1 2/5] i2c-designware-baytrail: fix typo in error path
Quoted 7 lines · Wolfram Sang
drivers/i2c/busses/i2c-designware-baytrail.c int baytrail_i2c_acquire(struct dw_i2c_dev *dev) · line 106
Quoted 5 lines
drivers/i2c/busses/i2c-designware-baytrail.c +2
-0+ PUNIT_SEMAPHORE, &sem); +if (ret)dev_err (dev->dev,"iosf failed to read punit semaphore\n" );else dev_err (dev->dev,"PUNIT SEM: %d\n" , sem);Shouldn't the latter be a
dev_dbg?
For me it seems not. Here is error patch and we have already in error recovery, so, intention to see if the semaphore becomes alive after reset. Am I right, David?
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
A message that is not in the archive (sent off-list or not yet received): 1423673991.31903.535.camel-VuQAYsv1563Yd54FQh9/[email protected]
Re: [PATCH v1 2/5] i2c-designware-baytrail: fix typo in error path
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Wolfram Sang
drivers/i2c/busses/i2c-designware-baytrail.c int baytrail_i2c_acquire(struct dw_i2c_dev *dev) · line 106
Quoted 5 lines
drivers/i2c/busses/i2c-designware-baytrail.c +2
-0+ PUNIT_SEMAPHORE, &sem); +if (ret)dev_err (dev->dev,"iosf failed to read punit semaphore\n" );else dev_err (dev->dev,"PUNIT SEM: %d\n" , sem);Shouldn't the latter be a
dev_dbg?
Quoted 3 lines
For me it seems not. Here is error patch and we have already in error recovery, so, intention to see if the semaphore becomes alive after reset. Am I right, David?
Yes. We've timed out by this section of code so we want to verify the semaphore was reset. Failure to read the semaphore though is a separate error as well.
Dave
Quoted 6 lines
Signature · 3 lines
-- Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v1 2/5] i2c-designware-baytrail: fix typo in error path
In reply to Wolfram SangQuoted 7 lines · Wolfram Sang
drivers/i2c/busses/i2c-designware-baytrail.c int baytrail_i2c_acquire(struct dw_i2c_dev *dev) · line 106
Quoted 5 lines
drivers/i2c/busses/i2c-designware-baytrail.c +2
-0+ PUNIT_SEMAPHORE, &sem); +if (ret)dev_err (dev->dev,"iosf failed to read punit semaphore\n" );else dev_err (dev->dev,"PUNIT SEM: %d\n" , sem);Shouldn't the latter be a
dev_dbg?
Wolfram, do we agree on this as states in the patch? Maybe you have more comments, questions?
Otherwise, should I rebase this on top of 4.0-rc1 or you will be okay with current version?
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
A message that is not in the archive (sent off-list or not yet received): 1424696051.14897.13.camel-VuQAYsv1563Yd54FQh9/[email protected]
Re: [PATCH v1 2/5] i2c-designware-baytrail: fix typo in error path
Quoted 5 lines
Quoted 2 lines
Shouldn't the latter be a
dev_dbg?Wolfram, do we agree on this as states in the patch? Maybe you have more comments, questions?
Yes, it is fine this way.
Quoted 2 lines
Otherwise, should I rebase this on top of 4.0-rc1 or you will be okay with current version?
Well, if it needs rebasing, please do. If not, please say so, too :)
Re: [PATCH v1 2/5] i2c-designware-baytrail: fix typo in error path
Quoted 11 lines · Wolfram Sang
Quoted 4 lines
Quoted 1 line
Shouldn't the latter be a
dev_dbg?Wolfram, do we agree on this as states in the patch? Maybe you have more comments, questions?
Yes, it is fine this way.
Quoted 2 lines
Otherwise, should I rebase this on top of 4.0-rc1 or you will be okay with current version?
Well, if it needs rebasing, please do. If not, please say so, too :)
It applies clearly on top of current linux-next without any changes from my side. So, no rebase is needed.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
PATCH 3/5 i2c-designware-baytrail: fix sparse warnings
In reply to a message not in the archiveThere is no need to export functions that are used as the callbacks in the struct dw_i2c_dev. Otherwise we get the following warnings:
drivers/i2c/busses/i2c-designware-baytrail.c:63:5: warning: symbol 'baytrail_i2c_acquire' was not declared. Should it be static? drivers/i2c/busses/i2c-designware-baytrail.c:114:6: warning: symbol 'baytrail_i2c_release' was not declared. Should it be static?
While here, do few indentation fixes, remove i2c_dw_eval_lock_support() from functions exported to the modules and redundant assignment of local sem variable.
--- drivers/i2c/busses/i2c-designware-baytrail.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-designware-baytrail.c +5 -7
@@ -17,7 +17,9 @@#include <linux/acpi.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <asm/iosf_mbi.h> +#include "i2c-designware-core.h" #define SEMAPHORE_TIMEOUT 100
@@ -60,9 +62,9 @@ static void reset_semaphore(struct device *dev)dev_err (dev,"iosf failed to reset punit semaphore during write\n" ); } -int baytrail_i2c_acquire (struct dw_i2c_dev *dev) +static int baytrail_i2c_acquire (struct dw_i2c_dev *dev) { -u32 sem =0 ; +u32 sem;int ret;unsigned long start, end;
@@ -109,9 +111,8 @@ int baytrail_i2c_acquire(struct dw_i2c_dev *dev)return -ETIMEDOUT ; } -EXPORT_SYMBOL (baytrail_i2c_acquire); -void baytrail_i2c_release (struct dw_i2c_dev *dev) +static void baytrail_i2c_release (struct dw_i2c_dev *dev) {if (!dev || !dev->dev)return ;
@@ -123,7 +124,6 @@ void baytrail_i2c_release(struct dw_i2c_dev *dev)dev_dbg (dev->dev,"punit semaphore held for %ums\n" ,jiffies_to_msecs (jiffies - acquired)); } -EXPORT_SYMBOL (baytrail_i2c_release);int i2c_dw_eval_lock_support (struct dw_i2c_dev *dev) {
@@ -139,7 +139,6 @@ int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev)return 0 ; status =acpi_evaluate_integer (handle,"_SEM" ,NULL , &shared_host); -if (ACPI_FAILURE (status))return 0 ;
@@ -155,7 +154,6 @@ int i2c_dw_eval_lock_support(struct dw_i2c_dev *dev)return 0 ; } -EXPORT_SYMBOL (i2c_dw_eval_lock_support);MODULE_AUTHOR ("David E. Box <david.e.box-VuQAYsv1563Yd54FQh9/[email protected]>" );MODULE_DESCRIPTION ("Baytrail I2C Semaphore driver" );
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 1423587970-19136-3-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]
David E. Box
Acked-byRe: [PATCH v1 3/5] i2c-designware-baytrail: fix sparse warnings
Quoted 11 lines · Andy Shevchenko
There is no need to export functions that are used as the callbacks in the struct
dw_i2c_dev. Otherwise we get the following warnings:
drivers/i2c/busses/i2c-designware-baytrail.c:63:5: warning: symbol 'baytrail_i2c_acquire' was not declared. Should it be static?drivers/i2c/busses/i2c-designware-baytrail.c:114:6: warning: symbol 'baytrail_i2c_release' was not declared. Should it be static?While here, do few indentation fixes, remove
i2c_dw_eval_lock_support()from functions exported to the modules and redundant assignment of local sem variable.
Yep. These remained from original versions of the patch that did use them as callbacks in struct dw_i2c_dev. Thanks.
PATCH 4/5 i2c-designware-baytrail: cross-check lock functions
In reply to a message not in the archiveIt seems the idea behind the cross-check is to prevent acquire semaphore when there is no release callback and vice versa. Thus, patch fixes a typo.
--- drivers/i2c/busses/i2c-designware-baytrail.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-baytrail.c +1 -1
@@ -71,7 +71,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)if (!dev || !dev->dev)return -ENODEV ; -if (!dev->acquire_lock) +if (!dev->release_lock)return 0 ;/* host driver writes to side band semaphore register */
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 1423587970-19136-4-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]
David E. Box
Acked-byRe: [PATCH v1 4/5] i2c-designware-baytrail: cross-check lock functions
Quoted 4 lines · Andy Shevchenko
It seems the idea behind the cross-check is to prevent acquire semaphore when there is no release callback and vice versa. Thus, patch fixes a typo.
Quoted 20 lines
--- drivers/i2c/busses/i2c-designware-baytrail.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-designware-baytrail.c +1
-1@@ -71,7 +71,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)if (!dev || !dev->dev)return -ENODEV ; -if (!dev->acquire_lock) +if (!dev->release_lock)return 0 ;/* host driver writes to side band semaphore register */ Signature · 1 line
2.1.4
PATCH 5/5 i2c-designware-baytrail: baytrail_i2c_acquire() might sleep
In reply to a message not in the archiveThis patch marks baytrail_i2c_acquire() that it might sleep. Also it chages while-loop to do-while and, though it is matter of taste, gives a chance to check one more time before report a timeout.
--- drivers/i2c/busses/i2c-designware-baytrail.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-baytrail.c +4 -2
@@ -68,6 +68,8 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)int ret;unsigned long start, end; +might_sleep (); +if (!dev || !dev->dev)return -ENODEV ;
@@ -85,7 +87,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)/* host driver waits for bit 0 to be set in semaphore register */ start = jiffies; end = start +msecs_to_jiffies (SEMAPHORE_TIMEOUT ); -while (!time_after (jiffies, end)) { + do { ret = get_sem(dev->dev, &sem); if (!ret && sem) { acquired = jiffies;
@@ -95,7 +97,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev) }usleep_range (1000 ,2000 ); - } + }while (time_before (jiffies, end));dev_err (dev->dev,"punit semaphore timed out, resetting\n" );reset_semaphore (dev->dev);
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 1423587970-19136-5-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]
David E. Box
Acked-byRe: [PATCH v1 5/5] i2c-designware-baytrail: baytrail_i2c_acquire() might sleep
Quoted 5 lines · Andy Shevchenko
This patch marks
baytrail_i2c_acquire()that it might sleep. Also it chages while-loop to do-while and, though it is matter of taste, gives a chance to check one more time before report a timeout.
Quoted 38 lines
--- drivers/i2c/busses/i2c-designware-baytrail.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-baytrail.c +4
-2@@ -68,6 +68,8 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)int ret;unsigned long start, end; +might_sleep (); +if (!dev || !dev->dev)return -ENODEV ;@@ -85,7 +87,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)/* host driver waits for bit 0 to be set in semaphore register */ start = jiffies; end = start +msecs_to_jiffies (SEMAPHORE_TIMEOUT ); -while (!time_after (jiffies, end)) { + do { ret = get_sem(dev->dev, &sem); if (!ret && sem) { acquired = jiffies;@@ -95,7 +97,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev) }usleep_range (1000 ,2000 ); - } + }while (time_before (jiffies, end));dev_err (dev->dev,"punit semaphore timed out, resetting\n" );reset_semaphore (dev->dev);Signature · 1 line
2.1.4
David E. Box
Acked-byQuoted 5 lines · Andy Shevchenko
The patch converts hardcoded numerical constants to a named ones.
While here, align the variable name in
get_sem()andreset_semaphore().
Quoted 5 lines · Andy Shevchenko
The patch converts hardcoded numerical constants to a named ones.
While here, align the variable name in
get_sem()andreset_semaphore().
Applied the whole series to for-current, thanks!