All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/10] rtc: max77686: Extend driver and add max77802 support
@ 2016-01-26 19:20 ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas, Arnd Bergmann, Olof Johansson,
	linux-arm-kernel

Hello,

On a recent disussion [0] with Krzysztof Kozlowski and Laxman Dewangan,
we came to the conclusion that the max77686 and max77802 RTC are almost
the same with only a few differences so there shouldn't be two separate
drivers and is better to extend max77686 driver and delete rtc-max77802.

By making the driver more generic, other RTC IP blocks from Maxim PMICs
could be supported as well like the max77620.

This is a v3 of a series that do this, that address issues pointed out
by Krzysztof Kozlowski. The v1 and v2 can be found at [1] and [2].

I've tested this patch-set on an Exynos5800 Peach Pi Chromebook that has
a max77802 PMIC and the RTC was working correctly but I don't have a
machine with max77686 so I will really appreaciate if someone can test
that no regressions were introduced.

[0]: http://www.spinics.net/lists/devicetree/msg110348.html
[1]: https://lwn.net/Articles/672568/
[2]: https://lkml.org/lkml/2016/1/25/767

Changes in v3:
- Add Krzysztof Kozlowski's Reviewed-by and Tested-by to patch #1.
- Add Laxman Dewangan's Acked-by tag to patch #1.
- Add Krzysztof Kozlowski's Tested-by tag to patch #2.
- Add Laxman Dewangan's Acked-by tag to patch #2.
- Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.
- Add Krzysztof Kozlowski's Tested-by tag to patch #3.
- Add Laxman Dewangan's Acked-by tag to patch #3.
- Fix max77686 delay. Suggested by Krzysztof Kozlowski.
- Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
- Add Laxman Dewangan's Acked-by tag to patch #4.
- Add Laxman Dewangan's Acked-by tag to patch #5.
- Add Laxman Dewangan's Acked-by tag to patch #6.
- Add Laxman Dewangan's Acked-by tag to patch #7.
- Add Laxman Dewangan's Acked-by tag to patch #8.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #3.
- Fix typo error in changelog. Suggested by Krzysztof Kozlowski.
- Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
- Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
- Change .mask type to u8. Suggested by Krzysztof Kozlowski.
- Make .drv_data field const. Suggested by Krzysztof Kozlowski.
- Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
- Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.
- Rename rtc_reg to max77686_rtc_reg_offset. Suggested by Krzysztof Kozlowski.
- Comment what's mapped by max77686_map. Suggested by Krzysztof Kozlowski.
- Use max77686_map array indexes in init. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_UPDATE1 since is not used by neither max77686 nor max77802.
- Add a MAX77802 prefix to ALARM_ENABLE_VALUE. Suggested by Krzysztof Kozlowski.
- Rename .rtcae to .alarm_enable_reg and .rtcrm to .separate_i2c_addr.
  Suggested by Krzysztof Kozlowski.
- Don't use func and LINE in error messages. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_AE2 since is not used by neither max77686 nor max77802.
- Check if REG_RTC_AE1 has a valid address before accessing it.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #9.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #10.

Javier Martinez Canillas (10):
  rtc: max77686: Fix max77686_rtc_read_alarm() return value
  rtc: max77686: Use ARRAY_SIZE() instead of current array length
  rtc: max77686: Use usleep_range() instead of msleep()
  rtc: max77686: Use a driver data struct instead hard-coded values
  rtc: max77686: Add an indirection level to access RTC registers
  rtc: max77686: Add max77802 support
  rtc: max77686: Use dev_warn() instead of pr_warn()
  rtc: Remove Maxim 77802 driver
  ARM: exynos_defconfig: Remove MAX77802 RTC Kconfig symbol
  ARM: multi_v7_defconfig: Remove MAX77802 RTC Kconfig symbol

 arch/arm/configs/exynos_defconfig   |   1 -
 arch/arm/configs/multi_v7_defconfig |   1 -
 drivers/rtc/Kconfig                 |  10 -
 drivers/rtc/Makefile                |   1 -
 drivers/rtc/rtc-max77686.c          | 336 +++++++++++++++++++-----
 drivers/rtc/rtc-max77802.c          | 502 ------------------------------------
 6 files changed, 270 insertions(+), 581 deletions(-)
 delete mode 100644 drivers/rtc/rtc-max77802.c

-- 
2.5.0

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 00/10] rtc: max77686: Extend driver and add max77802 support
@ 2016-01-26 19:20 ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas, Arnd Bergmann, Olof Johansson,
	linux-arm-kernel

Hello,

On a recent disussion [0] with Krzysztof Kozlowski and Laxman Dewangan,
we came to the conclusion that the max77686 and max77802 RTC are almost
the same with only a few differences so there shouldn't be two separate
drivers and is better to extend max77686 driver and delete rtc-max77802.

By making the driver more generic, other RTC IP blocks from Maxim PMICs
could be supported as well like the max77620.

This is a v3 of a series that do this, that address issues pointed out
by Krzysztof Kozlowski. The v1 and v2 can be found at [1] and [2].

I've tested this patch-set on an Exynos5800 Peach Pi Chromebook that has
a max77802 PMIC and the RTC was working correctly but I don't have a
machine with max77686 so I will really appreaciate if someone can test
that no regressions were introduced.

[0]: http://www.spinics.net/lists/devicetree/msg110348.html
[1]: https://lwn.net/Articles/672568/
[2]: https://lkml.org/lkml/2016/1/25/767

Changes in v3:
- Add Krzysztof Kozlowski's Reviewed-by and Tested-by to patch #1.
- Add Laxman Dewangan's Acked-by tag to patch #1.
- Add Krzysztof Kozlowski's Tested-by tag to patch #2.
- Add Laxman Dewangan's Acked-by tag to patch #2.
- Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.
- Add Krzysztof Kozlowski's Tested-by tag to patch #3.
- Add Laxman Dewangan's Acked-by tag to patch #3.
- Fix max77686 delay. Suggested by Krzysztof Kozlowski.
- Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
- Add Laxman Dewangan's Acked-by tag to patch #4.
- Add Laxman Dewangan's Acked-by tag to patch #5.
- Add Laxman Dewangan's Acked-by tag to patch #6.
- Add Laxman Dewangan's Acked-by tag to patch #7.
- Add Laxman Dewangan's Acked-by tag to patch #8.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #3.
- Fix typo error in changelog. Suggested by Krzysztof Kozlowski.
- Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
- Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
- Change .mask type to u8. Suggested by Krzysztof Kozlowski.
- Make .drv_data field const. Suggested by Krzysztof Kozlowski.
- Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
- Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.
- Rename rtc_reg to max77686_rtc_reg_offset. Suggested by Krzysztof Kozlowski.
- Comment what's mapped by max77686_map. Suggested by Krzysztof Kozlowski.
- Use max77686_map array indexes in init. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_UPDATE1 since is not used by neither max77686 nor max77802.
- Add a MAX77802 prefix to ALARM_ENABLE_VALUE. Suggested by Krzysztof Kozlowski.
- Rename .rtcae to .alarm_enable_reg and .rtcrm to .separate_i2c_addr.
  Suggested by Krzysztof Kozlowski.
- Don't use func and LINE in error messages. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_AE2 since is not used by neither max77686 nor max77802.
- Check if REG_RTC_AE1 has a valid address before accessing it.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #9.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #10.

Javier Martinez Canillas (10):
  rtc: max77686: Fix max77686_rtc_read_alarm() return value
  rtc: max77686: Use ARRAY_SIZE() instead of current array length
  rtc: max77686: Use usleep_range() instead of msleep()
  rtc: max77686: Use a driver data struct instead hard-coded values
  rtc: max77686: Add an indirection level to access RTC registers
  rtc: max77686: Add max77802 support
  rtc: max77686: Use dev_warn() instead of pr_warn()
  rtc: Remove Maxim 77802 driver
  ARM: exynos_defconfig: Remove MAX77802 RTC Kconfig symbol
  ARM: multi_v7_defconfig: Remove MAX77802 RTC Kconfig symbol

 arch/arm/configs/exynos_defconfig   |   1 -
 arch/arm/configs/multi_v7_defconfig |   1 -
 drivers/rtc/Kconfig                 |  10 -
 drivers/rtc/Makefile                |   1 -
 drivers/rtc/rtc-max77686.c          | 336 +++++++++++++++++++-----
 drivers/rtc/rtc-max77802.c          | 502 ------------------------------------
 6 files changed, 270 insertions(+), 581 deletions(-)
 delete mode 100644 drivers/rtc/rtc-max77802.c

-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [PATCH v3 00/10] rtc: max77686: Extend driver and add max77802 support
@ 2016-01-26 19:20 ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

On a recent disussion [0] with Krzysztof Kozlowski and Laxman Dewangan,
we came to the conclusion that the max77686 and max77802 RTC are almost
the same with only a few differences so there shouldn't be two separate
drivers and is better to extend max77686 driver and delete rtc-max77802.

By making the driver more generic, other RTC IP blocks from Maxim PMICs
could be supported as well like the max77620.

This is a v3 of a series that do this, that address issues pointed out
by Krzysztof Kozlowski. The v1 and v2 can be found at [1] and [2].

I've tested this patch-set on an Exynos5800 Peach Pi Chromebook that has
a max77802 PMIC and the RTC was working correctly but I don't have a
machine with max77686 so I will really appreaciate if someone can test
that no regressions were introduced.

[0]: http://www.spinics.net/lists/devicetree/msg110348.html
[1]: https://lwn.net/Articles/672568/
[2]: https://lkml.org/lkml/2016/1/25/767

Changes in v3:
- Add Krzysztof Kozlowski's Reviewed-by and Tested-by to patch #1.
- Add Laxman Dewangan's Acked-by tag to patch #1.
- Add Krzysztof Kozlowski's Tested-by tag to patch #2.
- Add Laxman Dewangan's Acked-by tag to patch #2.
- Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.
- Add Krzysztof Kozlowski's Tested-by tag to patch #3.
- Add Laxman Dewangan's Acked-by tag to patch #3.
- Fix max77686 delay. Suggested by Krzysztof Kozlowski.
- Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
- Add Laxman Dewangan's Acked-by tag to patch #4.
- Add Laxman Dewangan's Acked-by tag to patch #5.
- Add Laxman Dewangan's Acked-by tag to patch #6.
- Add Laxman Dewangan's Acked-by tag to patch #7.
- Add Laxman Dewangan's Acked-by tag to patch #8.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #3.
- Fix typo error in changelog. Suggested by Krzysztof Kozlowski.
- Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
- Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
- Change .mask type to u8. Suggested by Krzysztof Kozlowski.
- Make .drv_data field const. Suggested by Krzysztof Kozlowski.
- Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
- Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.
- Rename rtc_reg to max77686_rtc_reg_offset. Suggested by Krzysztof Kozlowski.
- Comment what's mapped by max77686_map. Suggested by Krzysztof Kozlowski.
- Use max77686_map array indexes in init. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_UPDATE1 since is not used by neither max77686 nor max77802.
- Add a MAX77802 prefix to ALARM_ENABLE_VALUE. Suggested by Krzysztof Kozlowski.
- Rename .rtcae to .alarm_enable_reg and .rtcrm to .separate_i2c_addr.
  Suggested by Krzysztof Kozlowski.
- Don't use func and LINE in error messages. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_AE2 since is not used by neither max77686 nor max77802.
- Check if REG_RTC_AE1 has a valid address before accessing it.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #9.
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #10.

Javier Martinez Canillas (10):
  rtc: max77686: Fix max77686_rtc_read_alarm() return value
  rtc: max77686: Use ARRAY_SIZE() instead of current array length
  rtc: max77686: Use usleep_range() instead of msleep()
  rtc: max77686: Use a driver data struct instead hard-coded values
  rtc: max77686: Add an indirection level to access RTC registers
  rtc: max77686: Add max77802 support
  rtc: max77686: Use dev_warn() instead of pr_warn()
  rtc: Remove Maxim 77802 driver
  ARM: exynos_defconfig: Remove MAX77802 RTC Kconfig symbol
  ARM: multi_v7_defconfig: Remove MAX77802 RTC Kconfig symbol

 arch/arm/configs/exynos_defconfig   |   1 -
 arch/arm/configs/multi_v7_defconfig |   1 -
 drivers/rtc/Kconfig                 |  10 -
 drivers/rtc/Makefile                |   1 -
 drivers/rtc/rtc-max77686.c          | 336 +++++++++++++++++++-----
 drivers/rtc/rtc-max77802.c          | 502 ------------------------------------
 6 files changed, 270 insertions(+), 581 deletions(-)
 delete mode 100644 drivers/rtc/rtc-max77802.c

-- 
2.5.0

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [PATCH v3 01/10] rtc: max77686: Fix max77686_rtc_read_alarm() return value
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The function is always returning zero even in case of failures since
the ret value was not propagated to the callers. Fix the error path.

Reported-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Krzysztof Kozlowski's Reviewed-by and Tested-by to patch #1.
- Add Laxman Dewangan's Acked-by tag to patch #1.

Changes in v2: None

 drivers/rtc/rtc-max77686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 7184a0eda793..6653c3d11b66 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -235,7 +235,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 
 out:
 	mutex_unlock(&info->lock);
-	return 0;
+	return ret;
 }
 
 static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 01/10] rtc: max77686: Fix max77686_rtc_read_alarm() return value
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The function is always returning zero even in case of failures since
the ret value was not propagated to the callers. Fix the error path.

Reported-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Krzysztof Kozlowski's Reviewed-by and Tested-by to patch #1.
- Add Laxman Dewangan's Acked-by tag to patch #1.

Changes in v2: None

 drivers/rtc/rtc-max77686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 7184a0eda793..6653c3d11b66 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -235,7 +235,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 
 out:
 	mutex_unlock(&info->lock);
-	return 0;
+	return ret;
 }
 
 static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 02/10] rtc: max77686: Use ARRAY_SIZE() instead of current array length
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

It is better to use the ARRAY_SIZE() macro instead of the array length
to avoid bugs if the array is later changed and the length not updated.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

---

Changes in v3:
- Add Krzysztof Kozlowski's Tested-by tag to patch #2.
- Add Laxman Dewangan's Acked-by tag to patch #2.
- Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.

 drivers/rtc/rtc-max77686.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 6653c3d11b66..d84a50c9f7f7 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -149,7 +149,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				MAX77686_RTC_SEC, data, RTC_NR_TIME);
+				MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,	ret);
 		goto out;
@@ -177,7 +177,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	mutex_lock(&info->lock);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_RTC_SEC, data, RTC_NR_TIME);
+				 MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
 				ret);
@@ -205,7 +205,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
 				__func__, __LINE__, ret);
@@ -215,7 +215,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
 
 	alrm->enabled = 0;
-	for (i = 0; i < RTC_NR_TIME; i++) {
+	for (i = 0; i < ARRAY_SIZE(data); i++) {
 		if (data[i] & ALARM_ENABLE_MASK) {
 			alrm->enabled = 1;
 			break;
@@ -252,7 +252,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -261,11 +261,11 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 
 	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
 
-	for (i = 0; i < RTC_NR_TIME; i++)
+	for (i = 0; i < ARRAY_SIZE(data); i++)
 		data[i] &= ~ALARM_ENABLE_MASK;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -291,7 +291,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -312,7 +312,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -341,7 +341,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
@@ -406,7 +406,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
 
 	info->rtc_24hr_mode = 1;
 
-	ret = regmap_bulk_write(info->max77686->rtc_regmap, MAX77686_RTC_CONTROLM, data, 2);
+	ret = regmap_bulk_write(info->max77686->rtc_regmap,
+				MAX77686_RTC_CONTROLM, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
 				__func__, ret);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 02/10] rtc: max77686: Use ARRAY_SIZE() instead of current array length
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

It is better to use the ARRAY_SIZE() macro instead of the array length
to avoid bugs if the array is later changed and the length not updated.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

---

Changes in v3:
- Add Krzysztof Kozlowski's Tested-by tag to patch #2.
- Add Laxman Dewangan's Acked-by tag to patch #2.
- Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.

 drivers/rtc/rtc-max77686.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 6653c3d11b66..d84a50c9f7f7 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -149,7 +149,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				MAX77686_RTC_SEC, data, RTC_NR_TIME);
+				MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,	ret);
 		goto out;
@@ -177,7 +177,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	mutex_lock(&info->lock);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_RTC_SEC, data, RTC_NR_TIME);
+				 MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
 				ret);
@@ -205,7 +205,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
 				__func__, __LINE__, ret);
@@ -215,7 +215,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
 
 	alrm->enabled = 0;
-	for (i = 0; i < RTC_NR_TIME; i++) {
+	for (i = 0; i < ARRAY_SIZE(data); i++) {
 		if (data[i] & ALARM_ENABLE_MASK) {
 			alrm->enabled = 1;
 			break;
@@ -252,7 +252,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -261,11 +261,11 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 
 	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
 
-	for (i = 0; i < RTC_NR_TIME; i++)
+	for (i = 0; i < ARRAY_SIZE(data); i++)
 		data[i] &= ~ALARM_ENABLE_MASK;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -291,7 +291,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -312,7 +312,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -341,7 +341,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
+				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
 
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
@@ -406,7 +406,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
 
 	info->rtc_24hr_mode = 1;
 
-	ret = regmap_bulk_write(info->max77686->rtc_regmap, MAX77686_RTC_CONTROLM, data, 2);
+	ret = regmap_bulk_write(info->max77686->rtc_regmap,
+				MAX77686_RTC_CONTROLM, data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
 				__func__, ret);
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 03/10] rtc: max77686: Use usleep_range() instead of msleep()
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

Documentation/timers/timers-howto.txt suggest to use usleep_range()
instead of msleep() for small msec (1ms - 20ms) since msleep() will
often sleep for 20ms for any value in that range.

This is fine in this case since 16ms is the _minimum_ delay required
by max77686 for an RTC update but by using usleep_range() instead of
msleep(), the driver can support other RTC IP blocks with a shorter
minimum delay (i.e: in the range of usecs instead of msecs).

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

---

Changes in v3:
- Add Krzysztof Kozlowski's Tested-by tag to patch #3.
- Add Laxman Dewangan's Acked-by tag to patch #3.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #3.
- Fix typo error in changelog. Suggested by Krzysztof Kozlowski.

 drivers/rtc/rtc-max77686.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index d84a50c9f7f7..025a17a95da3 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -41,7 +41,7 @@
 #define ALARM_ENABLE_SHIFT		7
 #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
 
-#define MAX77686_RTC_UPDATE_DELAY	16
+#define MAX77686_RTC_UPDATE_DELAY	16000
 
 enum {
 	RTC_SEC = 0,
@@ -130,7 +130,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 				__func__, ret, data);
 	else {
 		/* Minimum 16ms delay required before RTC update. */
-		msleep(MAX77686_RTC_UPDATE_DELAY);
+		usleep_range(MAX77686_RTC_UPDATE_DELAY,
+			     MAX77686_RTC_UPDATE_DELAY * 2);
 	}
 
 	return ret;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 03/10] rtc: max77686: Use usleep_range() instead of msleep()
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

Documentation/timers/timers-howto.txt suggest to use usleep_range()
instead of msleep() for small msec (1ms - 20ms) since msleep() will
often sleep for 20ms for any value in that range.

This is fine in this case since 16ms is the _minimum_ delay required
by max77686 for an RTC update but by using usleep_range() instead of
msleep(), the driver can support other RTC IP blocks with a shorter
minimum delay (i.e: in the range of usecs instead of msecs).

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

---

Changes in v3:
- Add Krzysztof Kozlowski's Tested-by tag to patch #3.
- Add Laxman Dewangan's Acked-by tag to patch #3.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #3.
- Fix typo error in changelog. Suggested by Krzysztof Kozlowski.

 drivers/rtc/rtc-max77686.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index d84a50c9f7f7..025a17a95da3 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -41,7 +41,7 @@
 #define ALARM_ENABLE_SHIFT		7
 #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
 
-#define MAX77686_RTC_UPDATE_DELAY	16
+#define MAX77686_RTC_UPDATE_DELAY	16000
 
 enum {
 	RTC_SEC = 0,
@@ -130,7 +130,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 				__func__, ret, data);
 	else {
 		/* Minimum 16ms delay required before RTC update. */
-		msleep(MAX77686_RTC_UPDATE_DELAY);
+		usleep_range(MAX77686_RTC_UPDATE_DELAY,
+			     MAX77686_RTC_UPDATE_DELAY * 2);
 	}
 
 	return ret;
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The driver has some hard-coded values such as the minimum delay needed
before a RTC update or the mask used for the sec/min/hour/etc registers.

Use a data structure that contains these values and pass as driver data
using the platform device ID table for each device.

This allows to make the driver's ops callbacks more generic so other RTC
that are similar but don't have the same values can also be supported.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Fix max77686 delay. Suggested by Krzysztof Kozlowski.
- Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
- Add Laxman Dewangan's Acked-by tag to patch #4.

Changes in v2:
- Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
- Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
- Change .mask type to u8. Suggested by Krzysztof Kozlowski.
- Make .drv_data field const. Suggested by Krzysztof Kozlowski.
- Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
- Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.

 drivers/rtc/rtc-max77686.c | 51 ++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 025a17a95da3..8c4ca35029c3 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -41,8 +41,6 @@
 #define ALARM_ENABLE_SHIFT		7
 #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
 
-#define MAX77686_RTC_UPDATE_DELAY	16000
-
 enum {
 	RTC_SEC = 0,
 	RTC_MIN,
@@ -54,6 +52,13 @@ enum {
 	RTC_NR_TIME
 };
 
+struct max77686_rtc_driver_data {
+	/* Minimum usecs needed for a RTC update */
+	unsigned long		delay;
+	/* Mask used to read RTC registers value */
+	u8			mask;
+};
+
 struct max77686_rtc_info {
 	struct device		*dev;
 	struct max77686_dev	*max77686;
@@ -63,6 +68,8 @@ struct max77686_rtc_info {
 
 	struct regmap		*regmap;
 
+	const struct max77686_rtc_driver_data *drv_data;
+
 	int virq;
 	int rtc_24hr_mode;
 };
@@ -72,12 +79,19 @@ enum MAX77686_RTC_OP {
 	MAX77686_RTC_READ,
 };
 
+static const struct max77686_rtc_driver_data max77686_drv_data = {
+	.delay = 16000,
+	.mask  = 0x7f,
+};
+
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
-				   int rtc_24hr_mode)
+				    struct max77686_rtc_info *info)
 {
-	tm->tm_sec = data[RTC_SEC] & 0x7f;
-	tm->tm_min = data[RTC_MIN] & 0x7f;
-	if (rtc_24hr_mode)
+	u8 mask = info->drv_data->mask;
+
+	tm->tm_sec = data[RTC_SEC] & mask;
+	tm->tm_min = data[RTC_MIN] & mask;
+	if (info->rtc_24hr_mode)
 		tm->tm_hour = data[RTC_HOUR] & 0x1f;
 	else {
 		tm->tm_hour = data[RTC_HOUR] & 0x0f;
@@ -86,10 +100,10 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
 	}
 
 	/* Only a single bit is set in data[], so fls() would be equivalent */
-	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f) - 1;
+	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
 	tm->tm_mday = data[RTC_DATE] & 0x1f;
 	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
-	tm->tm_year = (data[RTC_YEAR] & 0x7f) + 100;
+	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
 	tm->tm_yday = 0;
 	tm->tm_isdst = 0;
 }
@@ -117,6 +131,7 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 {
 	int ret;
 	unsigned int data;
+	unsigned long delay = info->drv_data->delay;
 
 	if (op == MAX77686_RTC_WRITE)
 		data = 1 << RTC_UDR_SHIFT;
@@ -129,9 +144,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
 				__func__, ret, data);
 	else {
-		/* Minimum 16ms delay required before RTC update. */
-		usleep_range(MAX77686_RTC_UPDATE_DELAY,
-			     MAX77686_RTC_UPDATE_DELAY * 2);
+		/* Minimum delay required before RTC update. */
+		usleep_range(delay, delay * 2);
 	}
 
 	return ret;
@@ -156,7 +170,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, tm, info);
 
 	ret = rtc_valid_tm(tm);
 
@@ -213,7 +227,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, &alrm->time, info);
 
 	alrm->enabled = 0;
 	for (i = 0; i < ARRAY_SIZE(data); i++) {
@@ -260,7 +274,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, &tm, info);
 
 	for (i = 0; i < ARRAY_SIZE(data); i++)
 		data[i] &= ~ALARM_ENABLE_MASK;
@@ -299,7 +313,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, &tm, info);
 
 	data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
 	data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
@@ -307,7 +321,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 	data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
 	if (data[RTC_MONTH] & 0xf)
 		data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
-	if (data[RTC_YEAR] & 0x7f)
+	if (data[RTC_YEAR] & info->drv_data->mask)
 		data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
 	if (data[RTC_DATE] & 0x1f)
 		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
@@ -423,6 +437,7 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 {
 	struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent);
 	struct max77686_rtc_info *info;
+	const struct platform_device_id *id = platform_get_device_id(pdev);
 	int ret;
 
 	dev_info(&pdev->dev, "%s\n", __func__);
@@ -436,6 +451,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 	info->dev = &pdev->dev;
 	info->max77686 = max77686;
 	info->rtc = max77686->rtc;
+	info->drv_data = (const struct max77686_rtc_driver_data *)
+		id->driver_data;
 
 	platform_set_drvdata(pdev, info);
 
@@ -510,7 +527,7 @@ static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
 			 max77686_rtc_suspend, max77686_rtc_resume);
 
 static const struct platform_device_id rtc_id[] = {
-	{ "max77686-rtc", 0 },
+	{ "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, },
 	{},
 };
 MODULE_DEVICE_TABLE(platform, rtc_id);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The driver has some hard-coded values such as the minimum delay needed
before a RTC update or the mask used for the sec/min/hour/etc registers.

Use a data structure that contains these values and pass as driver data
using the platform device ID table for each device.

This allows to make the driver's ops callbacks more generic so other RTC
that are similar but don't have the same values can also be supported.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Fix max77686 delay. Suggested by Krzysztof Kozlowski.
- Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
- Add Laxman Dewangan's Acked-by tag to patch #4.

Changes in v2:
- Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
- Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
- Change .mask type to u8. Suggested by Krzysztof Kozlowski.
- Make .drv_data field const. Suggested by Krzysztof Kozlowski.
- Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
- Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.

 drivers/rtc/rtc-max77686.c | 51 ++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 025a17a95da3..8c4ca35029c3 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -41,8 +41,6 @@
 #define ALARM_ENABLE_SHIFT		7
 #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
 
-#define MAX77686_RTC_UPDATE_DELAY	16000
-
 enum {
 	RTC_SEC = 0,
 	RTC_MIN,
@@ -54,6 +52,13 @@ enum {
 	RTC_NR_TIME
 };
 
+struct max77686_rtc_driver_data {
+	/* Minimum usecs needed for a RTC update */
+	unsigned long		delay;
+	/* Mask used to read RTC registers value */
+	u8			mask;
+};
+
 struct max77686_rtc_info {
 	struct device		*dev;
 	struct max77686_dev	*max77686;
@@ -63,6 +68,8 @@ struct max77686_rtc_info {
 
 	struct regmap		*regmap;
 
+	const struct max77686_rtc_driver_data *drv_data;
+
 	int virq;
 	int rtc_24hr_mode;
 };
@@ -72,12 +79,19 @@ enum MAX77686_RTC_OP {
 	MAX77686_RTC_READ,
 };
 
+static const struct max77686_rtc_driver_data max77686_drv_data = {
+	.delay = 16000,
+	.mask  = 0x7f,
+};
+
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
-				   int rtc_24hr_mode)
+				    struct max77686_rtc_info *info)
 {
-	tm->tm_sec = data[RTC_SEC] & 0x7f;
-	tm->tm_min = data[RTC_MIN] & 0x7f;
-	if (rtc_24hr_mode)
+	u8 mask = info->drv_data->mask;
+
+	tm->tm_sec = data[RTC_SEC] & mask;
+	tm->tm_min = data[RTC_MIN] & mask;
+	if (info->rtc_24hr_mode)
 		tm->tm_hour = data[RTC_HOUR] & 0x1f;
 	else {
 		tm->tm_hour = data[RTC_HOUR] & 0x0f;
@@ -86,10 +100,10 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
 	}
 
 	/* Only a single bit is set in data[], so fls() would be equivalent */
-	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f) - 1;
+	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
 	tm->tm_mday = data[RTC_DATE] & 0x1f;
 	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
-	tm->tm_year = (data[RTC_YEAR] & 0x7f) + 100;
+	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
 	tm->tm_yday = 0;
 	tm->tm_isdst = 0;
 }
@@ -117,6 +131,7 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 {
 	int ret;
 	unsigned int data;
+	unsigned long delay = info->drv_data->delay;
 
 	if (op == MAX77686_RTC_WRITE)
 		data = 1 << RTC_UDR_SHIFT;
@@ -129,9 +144,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
 				__func__, ret, data);
 	else {
-		/* Minimum 16ms delay required before RTC update. */
-		usleep_range(MAX77686_RTC_UPDATE_DELAY,
-			     MAX77686_RTC_UPDATE_DELAY * 2);
+		/* Minimum delay required before RTC update. */
+		usleep_range(delay, delay * 2);
 	}
 
 	return ret;
@@ -156,7 +170,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, tm, info);
 
 	ret = rtc_valid_tm(tm);
 
@@ -213,7 +227,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, &alrm->time, info);
 
 	alrm->enabled = 0;
 	for (i = 0; i < ARRAY_SIZE(data); i++) {
@@ -260,7 +274,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, &tm, info);
 
 	for (i = 0; i < ARRAY_SIZE(data); i++)
 		data[i] &= ~ALARM_ENABLE_MASK;
@@ -299,7 +313,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		goto out;
 	}
 
-	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
+	max77686_rtc_data_to_tm(data, &tm, info);
 
 	data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
 	data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
@@ -307,7 +321,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 	data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
 	if (data[RTC_MONTH] & 0xf)
 		data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
-	if (data[RTC_YEAR] & 0x7f)
+	if (data[RTC_YEAR] & info->drv_data->mask)
 		data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
 	if (data[RTC_DATE] & 0x1f)
 		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
@@ -423,6 +437,7 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 {
 	struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent);
 	struct max77686_rtc_info *info;
+	const struct platform_device_id *id = platform_get_device_id(pdev);
 	int ret;
 
 	dev_info(&pdev->dev, "%s\n", __func__);
@@ -436,6 +451,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 	info->dev = &pdev->dev;
 	info->max77686 = max77686;
 	info->rtc = max77686->rtc;
+	info->drv_data = (const struct max77686_rtc_driver_data *)
+		id->driver_data;
 
 	platform_set_drvdata(pdev, info);
 
@@ -510,7 +527,7 @@ static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
 			 max77686_rtc_suspend, max77686_rtc_resume);
 
 static const struct platform_device_id rtc_id[] = {
-	{ "max77686-rtc", 0 },
+	{ "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, },
 	{},
 };
 MODULE_DEVICE_TABLE(platform, rtc_id);
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 05/10] rtc: max77686: Add an indirection level to access RTC registers
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The max77686 driver is generic enough that can be used for other
Maxim RTC IP blocks but these might not have the same registers
layout so instead of accessing the registers directly, add a map
to translate offsets to the real registers addresses for each IP.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #5.

Changes in v2:
- Rename rtc_reg to max77686_rtc_reg_offset. Suggested by Krzysztof Kozlowski.
- Comment what's mapped by max77686_map. Suggested by Krzysztof Kozlowski.
- Use max77686_map array indexes in init. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_UPDATE1 since is not used by neither max77686 nor max77802.

 drivers/rtc/rtc-max77686.c | 90 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 80 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 8c4ca35029c3..1f501b6fc314 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -57,6 +57,8 @@ struct max77686_rtc_driver_data {
 	unsigned long		delay;
 	/* Mask used to read RTC registers value */
 	u8			mask;
+	/* Registers offset to I2C addresses map */
+	const unsigned int	*map;
 };
 
 struct max77686_rtc_info {
@@ -79,9 +81,69 @@ enum MAX77686_RTC_OP {
 	MAX77686_RTC_READ,
 };
 
+/* These are not registers but just offsets that are mapped to addresses */
+enum max77686_rtc_reg_offset {
+	REG_RTC_CONTROLM = 0,
+	REG_RTC_CONTROL,
+	REG_RTC_UPDATE0,
+	REG_WTSR_SMPL_CNTL,
+	REG_RTC_SEC,
+	REG_RTC_MIN,
+	REG_RTC_HOUR,
+	REG_RTC_WEEKDAY,
+	REG_RTC_MONTH,
+	REG_RTC_YEAR,
+	REG_RTC_DATE,
+	REG_ALARM1_SEC,
+	REG_ALARM1_MIN,
+	REG_ALARM1_HOUR,
+	REG_ALARM1_WEEKDAY,
+	REG_ALARM1_MONTH,
+	REG_ALARM1_YEAR,
+	REG_ALARM1_DATE,
+	REG_ALARM2_SEC,
+	REG_ALARM2_MIN,
+	REG_ALARM2_HOUR,
+	REG_ALARM2_WEEKDAY,
+	REG_ALARM2_MONTH,
+	REG_ALARM2_YEAR,
+	REG_ALARM2_DATE,
+	REG_RTC_END,
+};
+
+/* Maps RTC registers offset to the MAX77686 register addresses */
+static const unsigned int max77686_map[REG_RTC_END] = {
+	[REG_RTC_CONTROLM]   = MAX77686_RTC_CONTROLM,
+	[REG_RTC_CONTROL]    = MAX77686_RTC_CONTROL,
+	[REG_RTC_UPDATE0]    = MAX77686_RTC_UPDATE0,
+	[REG_WTSR_SMPL_CNTL] = MAX77686_WTSR_SMPL_CNTL,
+	[REG_RTC_SEC]        = MAX77686_RTC_SEC,
+	[REG_RTC_MIN]        = MAX77686_RTC_MIN,
+	[REG_RTC_HOUR]       = MAX77686_RTC_HOUR,
+	[REG_RTC_WEEKDAY]    = MAX77686_RTC_WEEKDAY,
+	[REG_RTC_MONTH]      = MAX77686_RTC_MONTH,
+	[REG_RTC_YEAR]       = MAX77686_RTC_YEAR,
+	[REG_RTC_DATE]       = MAX77686_RTC_DATE,
+	[REG_ALARM1_SEC]     = MAX77686_ALARM1_SEC,
+	[REG_ALARM1_MIN]     = MAX77686_ALARM1_MIN,
+	[REG_ALARM1_HOUR]    = MAX77686_ALARM1_HOUR,
+	[REG_ALARM1_WEEKDAY] = MAX77686_ALARM1_WEEKDAY,
+	[REG_ALARM1_MONTH]   = MAX77686_ALARM1_MONTH,
+	[REG_ALARM1_YEAR]    = MAX77686_ALARM1_YEAR,
+	[REG_ALARM1_DATE]    = MAX77686_ALARM1_DATE,
+	[REG_ALARM2_SEC]     = MAX77686_ALARM2_SEC,
+	[REG_ALARM2_MIN]     = MAX77686_ALARM2_MIN,
+	[REG_ALARM2_HOUR]    = MAX77686_ALARM2_HOUR,
+	[REG_ALARM2_WEEKDAY] = MAX77686_ALARM2_WEEKDAY,
+	[REG_ALARM2_MONTH]   = MAX77686_ALARM2_MONTH,
+	[REG_ALARM2_YEAR]    = MAX77686_ALARM2_YEAR,
+	[REG_ALARM2_DATE]    = MAX77686_ALARM2_DATE,
+};
+
 static const struct max77686_rtc_driver_data max77686_drv_data = {
 	.delay = 16000,
 	.mask  = 0x7f,
+	.map   = max77686_map,
 };
 
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
@@ -139,7 +201,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 		data = 1 << RTC_RBUDR_SHIFT;
 
 	ret = regmap_update_bits(info->max77686->rtc_regmap,
-				 MAX77686_RTC_UPDATE0, data, data);
+				 info->drv_data->map[REG_RTC_UPDATE0],
+				 data, data);
 	if (ret < 0)
 		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
 				__func__, ret, data);
@@ -164,7 +227,8 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
+			       info->drv_data->map[REG_RTC_SEC],
+			       data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,	ret);
 		goto out;
@@ -192,7 +256,8 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	mutex_lock(&info->lock);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
+				info->drv_data->map[REG_RTC_SEC],
+				data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
 				ret);
@@ -211,6 +276,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	struct max77686_rtc_info *info = dev_get_drvdata(dev);
 	u8 data[RTC_NR_TIME];
 	unsigned int val;
+	const unsigned int *map = info->drv_data->map;
 	int i, ret;
 
 	mutex_lock(&info->lock);
@@ -220,7 +286,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
 				__func__, __LINE__, ret);
@@ -258,6 +324,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 	u8 data[RTC_NR_TIME];
 	int ret, i;
 	struct rtc_time tm;
+	const unsigned int *map = info->drv_data->map;
 
 	if (!mutex_is_locked(&info->lock))
 		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
@@ -267,7 +334,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -280,7 +347,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		data[i] &= ~ALARM_ENABLE_MASK;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -297,6 +364,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 	u8 data[RTC_NR_TIME];
 	int ret;
 	struct rtc_time tm;
+	const unsigned int *map = info->drv_data->map;
 
 	if (!mutex_is_locked(&info->lock))
 		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
@@ -306,7 +374,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -327,7 +395,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -356,7 +424,8 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+				info->drv_data->map[REG_ALARM1_SEC],
+				data, ARRAY_SIZE(data));
 
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
@@ -422,7 +491,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
 	info->rtc_24hr_mode = 1;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				MAX77686_RTC_CONTROLM, data, ARRAY_SIZE(data));
+				info->drv_data->map[REG_RTC_CONTROLM],
+				data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
 				__func__, ret);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 05/10] rtc: max77686: Add an indirection level to access RTC registers
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The max77686 driver is generic enough that can be used for other
Maxim RTC IP blocks but these might not have the same registers
layout so instead of accessing the registers directly, add a map
to translate offsets to the real registers addresses for each IP.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #5.

Changes in v2:
- Rename rtc_reg to max77686_rtc_reg_offset. Suggested by Krzysztof Kozlowski.
- Comment what's mapped by max77686_map. Suggested by Krzysztof Kozlowski.
- Use max77686_map array indexes in init. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_UPDATE1 since is not used by neither max77686 nor max77802.

 drivers/rtc/rtc-max77686.c | 90 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 80 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 8c4ca35029c3..1f501b6fc314 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -57,6 +57,8 @@ struct max77686_rtc_driver_data {
 	unsigned long		delay;
 	/* Mask used to read RTC registers value */
 	u8			mask;
+	/* Registers offset to I2C addresses map */
+	const unsigned int	*map;
 };
 
 struct max77686_rtc_info {
@@ -79,9 +81,69 @@ enum MAX77686_RTC_OP {
 	MAX77686_RTC_READ,
 };
 
+/* These are not registers but just offsets that are mapped to addresses */
+enum max77686_rtc_reg_offset {
+	REG_RTC_CONTROLM = 0,
+	REG_RTC_CONTROL,
+	REG_RTC_UPDATE0,
+	REG_WTSR_SMPL_CNTL,
+	REG_RTC_SEC,
+	REG_RTC_MIN,
+	REG_RTC_HOUR,
+	REG_RTC_WEEKDAY,
+	REG_RTC_MONTH,
+	REG_RTC_YEAR,
+	REG_RTC_DATE,
+	REG_ALARM1_SEC,
+	REG_ALARM1_MIN,
+	REG_ALARM1_HOUR,
+	REG_ALARM1_WEEKDAY,
+	REG_ALARM1_MONTH,
+	REG_ALARM1_YEAR,
+	REG_ALARM1_DATE,
+	REG_ALARM2_SEC,
+	REG_ALARM2_MIN,
+	REG_ALARM2_HOUR,
+	REG_ALARM2_WEEKDAY,
+	REG_ALARM2_MONTH,
+	REG_ALARM2_YEAR,
+	REG_ALARM2_DATE,
+	REG_RTC_END,
+};
+
+/* Maps RTC registers offset to the MAX77686 register addresses */
+static const unsigned int max77686_map[REG_RTC_END] = {
+	[REG_RTC_CONTROLM]   = MAX77686_RTC_CONTROLM,
+	[REG_RTC_CONTROL]    = MAX77686_RTC_CONTROL,
+	[REG_RTC_UPDATE0]    = MAX77686_RTC_UPDATE0,
+	[REG_WTSR_SMPL_CNTL] = MAX77686_WTSR_SMPL_CNTL,
+	[REG_RTC_SEC]        = MAX77686_RTC_SEC,
+	[REG_RTC_MIN]        = MAX77686_RTC_MIN,
+	[REG_RTC_HOUR]       = MAX77686_RTC_HOUR,
+	[REG_RTC_WEEKDAY]    = MAX77686_RTC_WEEKDAY,
+	[REG_RTC_MONTH]      = MAX77686_RTC_MONTH,
+	[REG_RTC_YEAR]       = MAX77686_RTC_YEAR,
+	[REG_RTC_DATE]       = MAX77686_RTC_DATE,
+	[REG_ALARM1_SEC]     = MAX77686_ALARM1_SEC,
+	[REG_ALARM1_MIN]     = MAX77686_ALARM1_MIN,
+	[REG_ALARM1_HOUR]    = MAX77686_ALARM1_HOUR,
+	[REG_ALARM1_WEEKDAY] = MAX77686_ALARM1_WEEKDAY,
+	[REG_ALARM1_MONTH]   = MAX77686_ALARM1_MONTH,
+	[REG_ALARM1_YEAR]    = MAX77686_ALARM1_YEAR,
+	[REG_ALARM1_DATE]    = MAX77686_ALARM1_DATE,
+	[REG_ALARM2_SEC]     = MAX77686_ALARM2_SEC,
+	[REG_ALARM2_MIN]     = MAX77686_ALARM2_MIN,
+	[REG_ALARM2_HOUR]    = MAX77686_ALARM2_HOUR,
+	[REG_ALARM2_WEEKDAY] = MAX77686_ALARM2_WEEKDAY,
+	[REG_ALARM2_MONTH]   = MAX77686_ALARM2_MONTH,
+	[REG_ALARM2_YEAR]    = MAX77686_ALARM2_YEAR,
+	[REG_ALARM2_DATE]    = MAX77686_ALARM2_DATE,
+};
+
 static const struct max77686_rtc_driver_data max77686_drv_data = {
 	.delay = 16000,
 	.mask  = 0x7f,
+	.map   = max77686_map,
 };
 
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
@@ -139,7 +201,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
 		data = 1 << RTC_RBUDR_SHIFT;
 
 	ret = regmap_update_bits(info->max77686->rtc_regmap,
-				 MAX77686_RTC_UPDATE0, data, data);
+				 info->drv_data->map[REG_RTC_UPDATE0],
+				 data, data);
 	if (ret < 0)
 		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
 				__func__, ret, data);
@@ -164,7 +227,8 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
+			       info->drv_data->map[REG_RTC_SEC],
+			       data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,	ret);
 		goto out;
@@ -192,7 +256,8 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	mutex_lock(&info->lock);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
+				info->drv_data->map[REG_RTC_SEC],
+				data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
 				ret);
@@ -211,6 +276,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	struct max77686_rtc_info *info = dev_get_drvdata(dev);
 	u8 data[RTC_NR_TIME];
 	unsigned int val;
+	const unsigned int *map = info->drv_data->map;
 	int i, ret;
 
 	mutex_lock(&info->lock);
@@ -220,7 +286,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
 				__func__, __LINE__, ret);
@@ -258,6 +324,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 	u8 data[RTC_NR_TIME];
 	int ret, i;
 	struct rtc_time tm;
+	const unsigned int *map = info->drv_data->map;
 
 	if (!mutex_is_locked(&info->lock))
 		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
@@ -267,7 +334,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -280,7 +347,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 		data[i] &= ~ALARM_ENABLE_MASK;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -297,6 +364,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 	u8 data[RTC_NR_TIME];
 	int ret;
 	struct rtc_time tm;
+	const unsigned int *map = info->drv_data->map;
 
 	if (!mutex_is_locked(&info->lock))
 		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
@@ -306,7 +374,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		goto out;
 
 	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -327,7 +395,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -356,7 +424,8 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 		goto out;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
+				info->drv_data->map[REG_ALARM1_SEC],
+				data, ARRAY_SIZE(data));
 
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
@@ -422,7 +491,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
 	info->rtc_24hr_mode = 1;
 
 	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				MAX77686_RTC_CONTROLM, data, ARRAY_SIZE(data));
+				info->drv_data->map[REG_RTC_CONTROLM],
+				data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
 				__func__, ret);
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 06/10] rtc: max77686: Add max77802 support
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The MAX77686 and MAX77802 RTC IP blocks are very similar with only
these differences:

0) The RTC registers layout and addresses are different.

1) The MAX77686 use 1 bit of the sec/min/hour/etc registers as the
   alarm enable while MAX77802 has a separate register for that.

2) The MAX77686 RTCYEAR register valid values range is 0..99 while
   for MAX77802 is 0..199.

3) The MAX77686 has a separate I2C address for the RTC registers
   while the MAX77802 uses the same I2C address as the PMIC regs.

5) The minimum delay before a RTC update (16 msecs vs 200 usecs).

There are separate drivers for MAX77686 and MAX77802 RTC IP blocks
but the differences are not that big so the driver can be extended
to support both instead of duplicating a lot of code in 2 drivers.

Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #6.

Changes in v2:
- Add a MAX77802 prefix to ALARM_ENABLE_VALUE. Suggested by Krzysztof Kozlowski.
- Rename .rtcae to .alarm_enable_reg and .rtcrm to .separate_i2c_addr.
  Suggested by Krzysztof Kozlowski.
- Don't use func and LINE in error messages. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_AE2 since is not used by neither max77686 nor max77802.
- Check if REG_RTC_AE1 has a valid address before accessing it.

 drivers/rtc/rtc-max77686.c | 208 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 162 insertions(+), 46 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 1f501b6fc314..09fc73016d3a 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -1,5 +1,5 @@
 /*
- * RTC driver for Maxim MAX77686
+ * RTC driver for Maxim MAX77686 and MAX77802
  *
  * Copyright (C) 2012 Samsung Electronics Co.Ltd
  *
@@ -41,6 +41,15 @@
 #define ALARM_ENABLE_SHIFT		7
 #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
 
+#define REG_RTC_NONE			0xdeadbeef
+
+/*
+ * MAX77802 has separate register (RTCAE1) for alarm enable instead
+ * using 1 bit from registers RTC{SEC,MIN,HOUR,DAY,MONTH,YEAR,DATE}
+ * as in done in MAX77686.
+ */
+#define MAX77802_ALARM_ENABLE_VALUE	0x77
+
 enum {
 	RTC_SEC = 0,
 	RTC_MIN,
@@ -59,6 +68,10 @@ struct max77686_rtc_driver_data {
 	u8			mask;
 	/* Registers offset to I2C addresses map */
 	const unsigned int	*map;
+	/* Has a separate alarm enable register? */
+	bool			alarm_enable_reg;
+	/* Has a separate I2C regmap for the RTC? */
+	bool			separate_i2c_addr;
 };
 
 struct max77686_rtc_info {
@@ -108,6 +121,7 @@ enum max77686_rtc_reg_offset {
 	REG_ALARM2_MONTH,
 	REG_ALARM2_YEAR,
 	REG_ALARM2_DATE,
+	REG_RTC_AE1,
 	REG_RTC_END,
 };
 
@@ -138,12 +152,52 @@ static const unsigned int max77686_map[REG_RTC_END] = {
 	[REG_ALARM2_MONTH]   = MAX77686_ALARM2_MONTH,
 	[REG_ALARM2_YEAR]    = MAX77686_ALARM2_YEAR,
 	[REG_ALARM2_DATE]    = MAX77686_ALARM2_DATE,
+	[REG_RTC_AE1]	     = REG_RTC_NONE,
 };
 
 static const struct max77686_rtc_driver_data max77686_drv_data = {
 	.delay = 16000,
 	.mask  = 0x7f,
 	.map   = max77686_map,
+	.alarm_enable_reg  = false,
+	.separate_i2c_addr = true,
+};
+
+static const unsigned int max77802_map[REG_RTC_END] = {
+	[REG_RTC_CONTROLM]   = MAX77802_RTC_CONTROLM,
+	[REG_RTC_CONTROL]    = MAX77802_RTC_CONTROL,
+	[REG_RTC_UPDATE0]    = MAX77802_RTC_UPDATE0,
+	[REG_WTSR_SMPL_CNTL] = MAX77802_WTSR_SMPL_CNTL,
+	[REG_RTC_SEC]        = MAX77802_RTC_SEC,
+	[REG_RTC_MIN]        = MAX77802_RTC_MIN,
+	[REG_RTC_HOUR]       = MAX77802_RTC_HOUR,
+	[REG_RTC_WEEKDAY]    = MAX77802_RTC_WEEKDAY,
+	[REG_RTC_MONTH]      = MAX77802_RTC_MONTH,
+	[REG_RTC_YEAR]       = MAX77802_RTC_YEAR,
+	[REG_RTC_DATE]       = MAX77802_RTC_DATE,
+	[REG_ALARM1_SEC]     = MAX77802_ALARM1_SEC,
+	[REG_ALARM1_MIN]     = MAX77802_ALARM1_MIN,
+	[REG_ALARM1_HOUR]    = MAX77802_ALARM1_HOUR,
+	[REG_ALARM1_WEEKDAY] = MAX77802_ALARM1_WEEKDAY,
+	[REG_ALARM1_MONTH]   = MAX77802_ALARM1_MONTH,
+	[REG_ALARM1_YEAR]    = MAX77802_ALARM1_YEAR,
+	[REG_ALARM1_DATE]    = MAX77802_ALARM1_DATE,
+	[REG_ALARM2_SEC]     = MAX77802_ALARM2_SEC,
+	[REG_ALARM2_MIN]     = MAX77802_ALARM2_MIN,
+	[REG_ALARM2_HOUR]    = MAX77802_ALARM2_HOUR,
+	[REG_ALARM2_WEEKDAY] = MAX77802_ALARM2_WEEKDAY,
+	[REG_ALARM2_MONTH]   = MAX77802_ALARM2_MONTH,
+	[REG_ALARM2_YEAR]    = MAX77802_ALARM2_YEAR,
+	[REG_ALARM2_DATE]    = MAX77802_ALARM2_DATE,
+	[REG_RTC_AE1]	     = MAX77802_RTC_AE1,
+};
+
+static const struct max77686_rtc_driver_data max77802_drv_data = {
+	.delay = 200,
+	.mask  = 0xff,
+	.map   = max77802_map,
+	.alarm_enable_reg  = true,
+	.separate_i2c_addr = false,
 };
 
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
@@ -165,12 +219,20 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
 	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
 	tm->tm_mday = data[RTC_DATE] & 0x1f;
 	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
-	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
+	tm->tm_year = data[RTC_YEAR] & mask;
 	tm->tm_yday = 0;
 	tm->tm_isdst = 0;
+
+	/*
+	 * MAX77686 uses 1 bit from sec/min/hour/etc RTC registers and the
+	 * year values are just 0..99 so add 100 to support up to 2099.
+	 */
+	if (!info->drv_data->alarm_enable_reg)
+		tm->tm_year += 100;
 }
 
-static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
+static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
+				   struct max77686_rtc_info *info)
 {
 	data[RTC_SEC] = tm->tm_sec;
 	data[RTC_MIN] = tm->tm_min;
@@ -178,13 +240,19 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
 	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
 	data[RTC_DATE] = tm->tm_mday;
 	data[RTC_MONTH] = tm->tm_mon + 1;
-	data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
 
-	if (tm->tm_year < 100) {
-		pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
-			1900 + tm->tm_year);
-		return -EINVAL;
+	if (!info->drv_data->alarm_enable_reg) {
+		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
+
+		if (tm->tm_year < 100) {
+			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
+				1900 + tm->tm_year);
+			return -EINVAL;
+		}
+	} else {
+		data[RTC_YEAR] = tm->tm_year;
 	}
+
 	return 0;
 }
 
@@ -249,7 +317,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	u8 data[RTC_NR_TIME];
 	int ret;
 
-	ret = max77686_rtc_tm_to_data(tm, data);
+	ret = max77686_rtc_tm_to_data(tm, data, info);
 	if (ret < 0)
 		return ret;
 
@@ -296,11 +364,32 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	max77686_rtc_data_to_tm(data, &alrm->time, info);
 
 	alrm->enabled = 0;
-	for (i = 0; i < ARRAY_SIZE(data); i++) {
-		if (data[i] & ALARM_ENABLE_MASK) {
-			alrm->enabled = 1;
-			break;
+
+	if (!info->drv_data->alarm_enable_reg) {
+		for (i = 0; i < ARRAY_SIZE(data); i++) {
+			if (data[i] & ALARM_ENABLE_MASK) {
+				alrm->enabled = 1;
+				break;
+			}
+		}
+	} else {
+		if (map[REG_RTC_AE1] == REG_RTC_NONE) {
+			ret = -EINVAL;
+			dev_err(info->dev,
+				"alarm enable register not set(%d)\n", ret);
+			goto out;
 		}
+
+		ret = regmap_read(info->max77686->regmap,
+				  map[REG_RTC_AE1], &val);
+		if (ret < 0) {
+			dev_err(info->dev,
+				"fail to read alarm enable(%d)\n", ret);
+			goto out;
+		}
+
+		if (val)
+			alrm->enabled = 1;
 	}
 
 	alrm->pending = 0;
@@ -333,21 +422,36 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 	if (ret < 0)
 		goto out;
 
-	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
+	if (!info->drv_data->alarm_enable_reg) {
+		ret = regmap_bulk_read(info->max77686->rtc_regmap,
+				       map[REG_ALARM1_SEC], data,
+				       ARRAY_SIZE(data));
+		if (ret < 0) {
+			dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
-		goto out;
-	}
+			goto out;
+		}
 
-	max77686_rtc_data_to_tm(data, &tm, info);
+		max77686_rtc_data_to_tm(data, &tm, info);
 
-	for (i = 0; i < ARRAY_SIZE(data); i++)
-		data[i] &= ~ALARM_ENABLE_MASK;
+		for (i = 0; i < ARRAY_SIZE(data); i++)
+			data[i] &= ~ALARM_ENABLE_MASK;
+
+		ret = regmap_bulk_write(info->max77686->rtc_regmap,
+					map[REG_ALARM1_SEC], data,
+					ARRAY_SIZE(data));
+	} else {
+		if (map[REG_RTC_AE1] == REG_RTC_NONE) {
+			ret = -EINVAL;
+			dev_err(info->dev,
+				"alarm enable register not set(%d)\n", ret);
+			goto out;
+		}
+
+		ret = regmap_write(info->max77686->regmap,
+				   map[REG_RTC_AE1], 0);
+	}
 
-	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -373,29 +477,37 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 	if (ret < 0)
 		goto out;
 
-	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
+	if (!info->drv_data->alarm_enable_reg) {
+		ret = regmap_bulk_read(info->max77686->rtc_regmap,
+				       map[REG_ALARM1_SEC], data,
+				       ARRAY_SIZE(data));
+		if (ret < 0) {
+			dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
-		goto out;
-	}
-
-	max77686_rtc_data_to_tm(data, &tm, info);
+			goto out;
+		}
 
-	data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
-	data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
-	data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
-	data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
-	if (data[RTC_MONTH] & 0xf)
-		data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
-	if (data[RTC_YEAR] & info->drv_data->mask)
-		data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
-	if (data[RTC_DATE] & 0x1f)
-		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
+		max77686_rtc_data_to_tm(data, &tm, info);
+
+		data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
+		data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
+		data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
+		data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
+		if (data[RTC_MONTH] & 0xf)
+			data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
+		if (data[RTC_YEAR] & info->drv_data->mask)
+			data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
+		if (data[RTC_DATE] & 0x1f)
+			data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
+
+		ret = regmap_bulk_write(info->max77686->rtc_regmap,
+					map[REG_ALARM1_SEC], data,
+					ARRAY_SIZE(data));
+	} else {
+		ret = regmap_write(info->max77686->regmap, map[REG_RTC_AE1],
+				   MAX77802_ALARM_ENABLE_VALUE);
+	}
 
-	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -413,7 +525,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	u8 data[RTC_NR_TIME];
 	int ret;
 
-	ret = max77686_rtc_tm_to_data(&alrm->time, data);
+	ret = max77686_rtc_tm_to_data(&alrm->time, data, info);
 	if (ret < 0)
 		return ret;
 
@@ -524,6 +636,9 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 	info->drv_data = (const struct max77686_rtc_driver_data *)
 		id->driver_data;
 
+	if (!info->drv_data->separate_i2c_addr)
+		info->max77686->rtc_regmap = info->max77686->regmap;
+
 	platform_set_drvdata(pdev, info);
 
 	ret = max77686_rtc_init_reg(info);
@@ -535,7 +650,7 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 1);
 
-	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc",
+	info->rtc_dev = devm_rtc_device_register(&pdev->dev, id->name,
 					&max77686_rtc_ops, THIS_MODULE);
 
 	if (IS_ERR(info->rtc_dev)) {
@@ -598,6 +713,7 @@ static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
 
 static const struct platform_device_id rtc_id[] = {
 	{ "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, },
+	{ "max77802-rtc", .driver_data = (kernel_ulong_t)&max77802_drv_data, },
 	{},
 };
 MODULE_DEVICE_TABLE(platform, rtc_id);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 06/10] rtc: max77686: Add max77802 support
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The MAX77686 and MAX77802 RTC IP blocks are very similar with only
these differences:

0) The RTC registers layout and addresses are different.

1) The MAX77686 use 1 bit of the sec/min/hour/etc registers as the
   alarm enable while MAX77802 has a separate register for that.

2) The MAX77686 RTCYEAR register valid values range is 0..99 while
   for MAX77802 is 0..199.

3) The MAX77686 has a separate I2C address for the RTC registers
   while the MAX77802 uses the same I2C address as the PMIC regs.

5) The minimum delay before a RTC update (16 msecs vs 200 usecs).

There are separate drivers for MAX77686 and MAX77802 RTC IP blocks
but the differences are not that big so the driver can be extended
to support both instead of duplicating a lot of code in 2 drivers.

Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #6.

Changes in v2:
- Add a MAX77802 prefix to ALARM_ENABLE_VALUE. Suggested by Krzysztof Kozlowski.
- Rename .rtcae to .alarm_enable_reg and .rtcrm to .separate_i2c_addr.
  Suggested by Krzysztof Kozlowski.
- Don't use func and LINE in error messages. Suggested by Krzysztof Kozlowski.
- Remove REG_RTC_AE2 since is not used by neither max77686 nor max77802.
- Check if REG_RTC_AE1 has a valid address before accessing it.

 drivers/rtc/rtc-max77686.c | 208 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 162 insertions(+), 46 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 1f501b6fc314..09fc73016d3a 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -1,5 +1,5 @@
 /*
- * RTC driver for Maxim MAX77686
+ * RTC driver for Maxim MAX77686 and MAX77802
  *
  * Copyright (C) 2012 Samsung Electronics Co.Ltd
  *
@@ -41,6 +41,15 @@
 #define ALARM_ENABLE_SHIFT		7
 #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
 
+#define REG_RTC_NONE			0xdeadbeef
+
+/*
+ * MAX77802 has separate register (RTCAE1) for alarm enable instead
+ * using 1 bit from registers RTC{SEC,MIN,HOUR,DAY,MONTH,YEAR,DATE}
+ * as in done in MAX77686.
+ */
+#define MAX77802_ALARM_ENABLE_VALUE	0x77
+
 enum {
 	RTC_SEC = 0,
 	RTC_MIN,
@@ -59,6 +68,10 @@ struct max77686_rtc_driver_data {
 	u8			mask;
 	/* Registers offset to I2C addresses map */
 	const unsigned int	*map;
+	/* Has a separate alarm enable register? */
+	bool			alarm_enable_reg;
+	/* Has a separate I2C regmap for the RTC? */
+	bool			separate_i2c_addr;
 };
 
 struct max77686_rtc_info {
@@ -108,6 +121,7 @@ enum max77686_rtc_reg_offset {
 	REG_ALARM2_MONTH,
 	REG_ALARM2_YEAR,
 	REG_ALARM2_DATE,
+	REG_RTC_AE1,
 	REG_RTC_END,
 };
 
@@ -138,12 +152,52 @@ static const unsigned int max77686_map[REG_RTC_END] = {
 	[REG_ALARM2_MONTH]   = MAX77686_ALARM2_MONTH,
 	[REG_ALARM2_YEAR]    = MAX77686_ALARM2_YEAR,
 	[REG_ALARM2_DATE]    = MAX77686_ALARM2_DATE,
+	[REG_RTC_AE1]	     = REG_RTC_NONE,
 };
 
 static const struct max77686_rtc_driver_data max77686_drv_data = {
 	.delay = 16000,
 	.mask  = 0x7f,
 	.map   = max77686_map,
+	.alarm_enable_reg  = false,
+	.separate_i2c_addr = true,
+};
+
+static const unsigned int max77802_map[REG_RTC_END] = {
+	[REG_RTC_CONTROLM]   = MAX77802_RTC_CONTROLM,
+	[REG_RTC_CONTROL]    = MAX77802_RTC_CONTROL,
+	[REG_RTC_UPDATE0]    = MAX77802_RTC_UPDATE0,
+	[REG_WTSR_SMPL_CNTL] = MAX77802_WTSR_SMPL_CNTL,
+	[REG_RTC_SEC]        = MAX77802_RTC_SEC,
+	[REG_RTC_MIN]        = MAX77802_RTC_MIN,
+	[REG_RTC_HOUR]       = MAX77802_RTC_HOUR,
+	[REG_RTC_WEEKDAY]    = MAX77802_RTC_WEEKDAY,
+	[REG_RTC_MONTH]      = MAX77802_RTC_MONTH,
+	[REG_RTC_YEAR]       = MAX77802_RTC_YEAR,
+	[REG_RTC_DATE]       = MAX77802_RTC_DATE,
+	[REG_ALARM1_SEC]     = MAX77802_ALARM1_SEC,
+	[REG_ALARM1_MIN]     = MAX77802_ALARM1_MIN,
+	[REG_ALARM1_HOUR]    = MAX77802_ALARM1_HOUR,
+	[REG_ALARM1_WEEKDAY] = MAX77802_ALARM1_WEEKDAY,
+	[REG_ALARM1_MONTH]   = MAX77802_ALARM1_MONTH,
+	[REG_ALARM1_YEAR]    = MAX77802_ALARM1_YEAR,
+	[REG_ALARM1_DATE]    = MAX77802_ALARM1_DATE,
+	[REG_ALARM2_SEC]     = MAX77802_ALARM2_SEC,
+	[REG_ALARM2_MIN]     = MAX77802_ALARM2_MIN,
+	[REG_ALARM2_HOUR]    = MAX77802_ALARM2_HOUR,
+	[REG_ALARM2_WEEKDAY] = MAX77802_ALARM2_WEEKDAY,
+	[REG_ALARM2_MONTH]   = MAX77802_ALARM2_MONTH,
+	[REG_ALARM2_YEAR]    = MAX77802_ALARM2_YEAR,
+	[REG_ALARM2_DATE]    = MAX77802_ALARM2_DATE,
+	[REG_RTC_AE1]	     = MAX77802_RTC_AE1,
+};
+
+static const struct max77686_rtc_driver_data max77802_drv_data = {
+	.delay = 200,
+	.mask  = 0xff,
+	.map   = max77802_map,
+	.alarm_enable_reg  = true,
+	.separate_i2c_addr = false,
 };
 
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
@@ -165,12 +219,20 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
 	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
 	tm->tm_mday = data[RTC_DATE] & 0x1f;
 	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
-	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
+	tm->tm_year = data[RTC_YEAR] & mask;
 	tm->tm_yday = 0;
 	tm->tm_isdst = 0;
+
+	/*
+	 * MAX77686 uses 1 bit from sec/min/hour/etc RTC registers and the
+	 * year values are just 0..99 so add 100 to support up to 2099.
+	 */
+	if (!info->drv_data->alarm_enable_reg)
+		tm->tm_year += 100;
 }
 
-static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
+static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
+				   struct max77686_rtc_info *info)
 {
 	data[RTC_SEC] = tm->tm_sec;
 	data[RTC_MIN] = tm->tm_min;
@@ -178,13 +240,19 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
 	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
 	data[RTC_DATE] = tm->tm_mday;
 	data[RTC_MONTH] = tm->tm_mon + 1;
-	data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
 
-	if (tm->tm_year < 100) {
-		pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
-			1900 + tm->tm_year);
-		return -EINVAL;
+	if (!info->drv_data->alarm_enable_reg) {
+		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
+
+		if (tm->tm_year < 100) {
+			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
+				1900 + tm->tm_year);
+			return -EINVAL;
+		}
+	} else {
+		data[RTC_YEAR] = tm->tm_year;
 	}
+
 	return 0;
 }
 
@@ -249,7 +317,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	u8 data[RTC_NR_TIME];
 	int ret;
 
-	ret = max77686_rtc_tm_to_data(tm, data);
+	ret = max77686_rtc_tm_to_data(tm, data, info);
 	if (ret < 0)
 		return ret;
 
@@ -296,11 +364,32 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	max77686_rtc_data_to_tm(data, &alrm->time, info);
 
 	alrm->enabled = 0;
-	for (i = 0; i < ARRAY_SIZE(data); i++) {
-		if (data[i] & ALARM_ENABLE_MASK) {
-			alrm->enabled = 1;
-			break;
+
+	if (!info->drv_data->alarm_enable_reg) {
+		for (i = 0; i < ARRAY_SIZE(data); i++) {
+			if (data[i] & ALARM_ENABLE_MASK) {
+				alrm->enabled = 1;
+				break;
+			}
+		}
+	} else {
+		if (map[REG_RTC_AE1] == REG_RTC_NONE) {
+			ret = -EINVAL;
+			dev_err(info->dev,
+				"alarm enable register not set(%d)\n", ret);
+			goto out;
 		}
+
+		ret = regmap_read(info->max77686->regmap,
+				  map[REG_RTC_AE1], &val);
+		if (ret < 0) {
+			dev_err(info->dev,
+				"fail to read alarm enable(%d)\n", ret);
+			goto out;
+		}
+
+		if (val)
+			alrm->enabled = 1;
 	}
 
 	alrm->pending = 0;
@@ -333,21 +422,36 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
 	if (ret < 0)
 		goto out;
 
-	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
+	if (!info->drv_data->alarm_enable_reg) {
+		ret = regmap_bulk_read(info->max77686->rtc_regmap,
+				       map[REG_ALARM1_SEC], data,
+				       ARRAY_SIZE(data));
+		if (ret < 0) {
+			dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
-		goto out;
-	}
+			goto out;
+		}
 
-	max77686_rtc_data_to_tm(data, &tm, info);
+		max77686_rtc_data_to_tm(data, &tm, info);
 
-	for (i = 0; i < ARRAY_SIZE(data); i++)
-		data[i] &= ~ALARM_ENABLE_MASK;
+		for (i = 0; i < ARRAY_SIZE(data); i++)
+			data[i] &= ~ALARM_ENABLE_MASK;
+
+		ret = regmap_bulk_write(info->max77686->rtc_regmap,
+					map[REG_ALARM1_SEC], data,
+					ARRAY_SIZE(data));
+	} else {
+		if (map[REG_RTC_AE1] == REG_RTC_NONE) {
+			ret = -EINVAL;
+			dev_err(info->dev,
+				"alarm enable register not set(%d)\n", ret);
+			goto out;
+		}
+
+		ret = regmap_write(info->max77686->regmap,
+				   map[REG_RTC_AE1], 0);
+	}
 
-	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -373,29 +477,37 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
 	if (ret < 0)
 		goto out;
 
-	ret = regmap_bulk_read(info->max77686->rtc_regmap,
-			       map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
+	if (!info->drv_data->alarm_enable_reg) {
+		ret = regmap_bulk_read(info->max77686->rtc_regmap,
+				       map[REG_ALARM1_SEC], data,
+				       ARRAY_SIZE(data));
+		if (ret < 0) {
+			dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
-		goto out;
-	}
-
-	max77686_rtc_data_to_tm(data, &tm, info);
+			goto out;
+		}
 
-	data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
-	data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
-	data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
-	data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
-	if (data[RTC_MONTH] & 0xf)
-		data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
-	if (data[RTC_YEAR] & info->drv_data->mask)
-		data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
-	if (data[RTC_DATE] & 0x1f)
-		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
+		max77686_rtc_data_to_tm(data, &tm, info);
+
+		data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
+		data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
+		data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
+		data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
+		if (data[RTC_MONTH] & 0xf)
+			data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
+		if (data[RTC_YEAR] & info->drv_data->mask)
+			data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
+		if (data[RTC_DATE] & 0x1f)
+			data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
+
+		ret = regmap_bulk_write(info->max77686->rtc_regmap,
+					map[REG_ALARM1_SEC], data,
+					ARRAY_SIZE(data));
+	} else {
+		ret = regmap_write(info->max77686->regmap, map[REG_RTC_AE1],
+				   MAX77802_ALARM_ENABLE_VALUE);
+	}
 
-	ret = regmap_bulk_write(info->max77686->rtc_regmap,
-				map[REG_ALARM1_SEC], data, ARRAY_SIZE(data));
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -413,7 +525,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	u8 data[RTC_NR_TIME];
 	int ret;
 
-	ret = max77686_rtc_tm_to_data(&alrm->time, data);
+	ret = max77686_rtc_tm_to_data(&alrm->time, data, info);
 	if (ret < 0)
 		return ret;
 
@@ -524,6 +636,9 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 	info->drv_data = (const struct max77686_rtc_driver_data *)
 		id->driver_data;
 
+	if (!info->drv_data->separate_i2c_addr)
+		info->max77686->rtc_regmap = info->max77686->regmap;
+
 	platform_set_drvdata(pdev, info);
 
 	ret = max77686_rtc_init_reg(info);
@@ -535,7 +650,7 @@ static int max77686_rtc_probe(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 1);
 
-	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc",
+	info->rtc_dev = devm_rtc_device_register(&pdev->dev, id->name,
 					&max77686_rtc_ops, THIS_MODULE);
 
 	if (IS_ERR(info->rtc_dev)) {
@@ -598,6 +713,7 @@ static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
 
 static const struct platform_device_id rtc_id[] = {
 	{ "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, },
+	{ "max77802-rtc", .driver_data = (kernel_ulong_t)&max77802_drv_data, },
 	{},
 };
 MODULE_DEVICE_TABLE(platform, rtc_id);
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

It is better to use dev_*() log functions instead of pr_*() to print
information about the device in the kernel log in a standardized way.

This also allows to remove the local pr_fmt() defined macro.

Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #7.

Changes in v2: None

 drivers/rtc/rtc-max77686.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 09fc73016d3a..da47b1d85793 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -12,8 +12,6 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/slab.h>
 #include <linux/rtc.h>
 #include <linux/delay.h>
@@ -245,8 +243,9 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
 		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
 
 		if (tm->tm_year < 100) {
-			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
-				1900 + tm->tm_year);
+			dev_warn(info->dev,
+				 "RTC can't handle year %d. Assume it's 2000\n",
+				 1900 + tm->tm_year);
 			return -EINVAL;
 		}
 	} else {
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

It is better to use dev_*() log functions instead of pr_*() to print
information about the device in the kernel log in a standardized way.

This also allows to remove the local pr_fmt() defined macro.

Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #7.

Changes in v2: None

 drivers/rtc/rtc-max77686.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 09fc73016d3a..da47b1d85793 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -12,8 +12,6 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/slab.h>
 #include <linux/rtc.h>
 #include <linux/delay.h>
@@ -245,8 +243,9 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
 		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
 
 		if (tm->tm_year < 100) {
-			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
-				1900 + tm->tm_year);
+			dev_warn(info->dev,
+				 "RTC can't handle year %d. Assume it's 2000\n",
+				 1900 + tm->tm_year);
 			return -EINVAL;
 		}
 	} else {
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 08/10] rtc: Remove Maxim 77802 driver
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The max77686 RTC driver now supports the max77802 RTC as
well so there's no need to have a separate driver anymore.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #8.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.

 drivers/rtc/Kconfig        |  10 -
 drivers/rtc/Makefile       |   1 -
 drivers/rtc/rtc-max77802.c | 502 ---------------------------------------------
 3 files changed, 513 deletions(-)
 delete mode 100644 drivers/rtc/rtc-max77802.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 376322f71fd5..ef456d3cf265 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -335,16 +335,6 @@ config RTC_DRV_RK808
 	  This driver can also be built as a module. If so, the module
 	  will be called rk808-rtc.
 
-config RTC_DRV_MAX77802
-	tristate "Maxim 77802 RTC"
-	depends on MFD_MAX77686
-	help
-	  If you say yes here you will get support for the
-	  RTC of Maxim MAX77802 PMIC.
-
-	  This driver can also be built as a module. If so, the module
-	  will be called rtc-max77802.
-
 config RTC_DRV_RS5C372
 	tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
 	help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 62d61b26ca7e..ed4519efa3ca 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -86,7 +86,6 @@ obj-$(CONFIG_RTC_DRV_M48T86)	+= rtc-m48t86.o
 obj-$(CONFIG_RTC_DRV_MAX6900)	+= rtc-max6900.o
 obj-$(CONFIG_RTC_DRV_MAX6902)	+= rtc-max6902.o
 obj-$(CONFIG_RTC_DRV_MAX77686)	+= rtc-max77686.o
-obj-$(CONFIG_RTC_DRV_MAX77802)	+= rtc-max77802.o
 obj-$(CONFIG_RTC_DRV_MAX8907)	+= rtc-max8907.o
 obj-$(CONFIG_RTC_DRV_MAX8925)	+= rtc-max8925.o
 obj-$(CONFIG_RTC_DRV_MAX8997)	+= rtc-max8997.o
diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
deleted file mode 100644
index 82ffcc5a5345..000000000000
--- a/drivers/rtc/rtc-max77802.c
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * RTC driver for Maxim MAX77802
- *
- * Copyright (C) 2013 Google, Inc
- *
- * Copyright (C) 2012 Samsung Electronics Co.Ltd
- *
- *  based on rtc-max8997.c
- *
- *  This program is free software; you can redistribute  it and/or modify it
- *  under  the terms of  the GNU General  Public License as published by the
- *  Free Software Foundation;  either version 2 of the  License, or (at your
- *  option) any later version.
- *
- */
-
-#include <linux/slab.h>
-#include <linux/rtc.h>
-#include <linux/delay.h>
-#include <linux/mutex.h>
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/mfd/max77686-private.h>
-#include <linux/irqdomain.h>
-#include <linux/regmap.h>
-
-/* RTC Control Register */
-#define BCD_EN_SHIFT			0
-#define BCD_EN_MASK			(1 << BCD_EN_SHIFT)
-#define MODEL24_SHIFT			1
-#define MODEL24_MASK			(1 << MODEL24_SHIFT)
-/* RTC Update Register1 */
-#define RTC_UDR_SHIFT			0
-#define RTC_UDR_MASK			(1 << RTC_UDR_SHIFT)
-#define RTC_RBUDR_SHIFT			4
-#define RTC_RBUDR_MASK			(1 << RTC_RBUDR_SHIFT)
-/* RTC Hour register */
-#define HOUR_PM_SHIFT			6
-#define HOUR_PM_MASK			(1 << HOUR_PM_SHIFT)
-/* RTC Alarm Enable */
-#define ALARM_ENABLE_SHIFT		7
-#define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
-
-/* For the RTCAE1 register, we write this value to enable the alarm */
-#define ALARM_ENABLE_VALUE		0x77
-
-#define MAX77802_RTC_UPDATE_DELAY_US	200
-
-enum {
-	RTC_SEC = 0,
-	RTC_MIN,
-	RTC_HOUR,
-	RTC_WEEKDAY,
-	RTC_MONTH,
-	RTC_YEAR,
-	RTC_DATE,
-	RTC_NR_TIME
-};
-
-struct max77802_rtc_info {
-	struct device		*dev;
-	struct max77686_dev	*max77802;
-	struct i2c_client	*rtc;
-	struct rtc_device	*rtc_dev;
-	struct mutex		lock;
-
-	struct regmap		*regmap;
-
-	int virq;
-	int rtc_24hr_mode;
-};
-
-enum MAX77802_RTC_OP {
-	MAX77802_RTC_WRITE,
-	MAX77802_RTC_READ,
-};
-
-static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
-				   int rtc_24hr_mode)
-{
-	tm->tm_sec = data[RTC_SEC] & 0xff;
-	tm->tm_min = data[RTC_MIN] & 0xff;
-	if (rtc_24hr_mode)
-		tm->tm_hour = data[RTC_HOUR] & 0x1f;
-	else {
-		tm->tm_hour = data[RTC_HOUR] & 0x0f;
-		if (data[RTC_HOUR] & HOUR_PM_MASK)
-			tm->tm_hour += 12;
-	}
-
-	/* Only a single bit is set in data[], so fls() would be equivalent */
-	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0xff) - 1;
-	tm->tm_mday = data[RTC_DATE] & 0x1f;
-	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
-
-	tm->tm_year = data[RTC_YEAR] & 0xff;
-	tm->tm_yday = 0;
-	tm->tm_isdst = 0;
-}
-
-static int max77802_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
-{
-	data[RTC_SEC] = tm->tm_sec;
-	data[RTC_MIN] = tm->tm_min;
-	data[RTC_HOUR] = tm->tm_hour;
-	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
-	data[RTC_DATE] = tm->tm_mday;
-	data[RTC_MONTH] = tm->tm_mon + 1;
-	data[RTC_YEAR] = tm->tm_year;
-
-	return 0;
-}
-
-static int max77802_rtc_update(struct max77802_rtc_info *info,
-	enum MAX77802_RTC_OP op)
-{
-	int ret;
-	unsigned int data;
-
-	if (op == MAX77802_RTC_WRITE)
-		data = 1 << RTC_UDR_SHIFT;
-	else
-		data = 1 << RTC_RBUDR_SHIFT;
-
-	ret = regmap_update_bits(info->max77802->regmap,
-				 MAX77802_RTC_UPDATE0, data, data);
-	if (ret < 0)
-		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
-				__func__, ret, data);
-	else {
-		/* Minimum delay required before RTC update. */
-		usleep_range(MAX77802_RTC_UPDATE_DELAY_US,
-			     MAX77802_RTC_UPDATE_DELAY_US * 2);
-	}
-
-	return ret;
-}
-
-static int max77802_rtc_read_time(struct device *dev, struct rtc_time *tm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	int ret;
-
-	mutex_lock(&info->lock);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_bulk_read(info->max77802->regmap,
-				MAX77802_RTC_SEC, data, RTC_NR_TIME);
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,
-			ret);
-		goto out;
-	}
-
-	max77802_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
-
-	ret = rtc_valid_tm(tm);
-
-out:
-	mutex_unlock(&info->lock);
-	return ret;
-}
-
-static int max77802_rtc_set_time(struct device *dev, struct rtc_time *tm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	int ret;
-
-	ret = max77802_rtc_tm_to_data(tm, data);
-	if (ret < 0)
-		return ret;
-
-	mutex_lock(&info->lock);
-
-	ret = regmap_bulk_write(info->max77802->regmap,
-				 MAX77802_RTC_SEC, data, RTC_NR_TIME);
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
-			ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-
-out:
-	mutex_unlock(&info->lock);
-	return ret;
-}
-
-static int max77802_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	unsigned int val;
-	int ret;
-
-	mutex_lock(&info->lock);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_bulk_read(info->max77802->regmap,
-				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
-	if (ret < 0) {
-		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
-				__func__, __LINE__, ret);
-		goto out;
-	}
-
-	max77802_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
-
-	alrm->enabled = 0;
-	ret = regmap_read(info->max77802->regmap,
-			  MAX77802_RTC_AE1, &val);
-	if (ret < 0) {
-		dev_err(info->dev, "%s:%d fail to read alarm enable(%d)\n",
-			__func__, __LINE__, ret);
-		goto out;
-	}
-	if (val)
-		alrm->enabled = 1;
-
-	alrm->pending = 0;
-	ret = regmap_read(info->max77802->regmap, MAX77802_REG_STATUS2, &val);
-	if (ret < 0) {
-		dev_err(info->dev, "%s:%d fail to read status2 reg(%d)\n",
-				__func__, __LINE__, ret);
-		goto out;
-	}
-
-	if (val & (1 << 2)) /* RTCA1 */
-		alrm->pending = 1;
-
-out:
-	mutex_unlock(&info->lock);
-	return 0;
-}
-
-static int max77802_rtc_stop_alarm(struct max77802_rtc_info *info)
-{
-	int ret;
-
-	if (!mutex_is_locked(&info->lock))
-		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_write(info->max77802->regmap,
-			   MAX77802_RTC_AE1, 0);
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
-			__func__, ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-out:
-	return ret;
-}
-
-static int max77802_rtc_start_alarm(struct max77802_rtc_info *info)
-{
-	int ret;
-
-	if (!mutex_is_locked(&info->lock))
-		dev_warn(info->dev, "%s: should have mutex locked\n",
-			 __func__);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_write(info->max77802->regmap,
-				   MAX77802_RTC_AE1,
-				   ALARM_ENABLE_VALUE);
-
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
-				__func__, ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-out:
-	return ret;
-}
-
-static int max77802_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	int ret;
-
-	ret = max77802_rtc_tm_to_data(&alrm->time, data);
-	if (ret < 0)
-		return ret;
-
-	mutex_lock(&info->lock);
-
-	ret = max77802_rtc_stop_alarm(info);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_bulk_write(info->max77802->regmap,
-				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
-
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
-				__func__, ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-	if (ret < 0)
-		goto out;
-
-	if (alrm->enabled)
-		ret = max77802_rtc_start_alarm(info);
-out:
-	mutex_unlock(&info->lock);
-	return ret;
-}
-
-static int max77802_rtc_alarm_irq_enable(struct device *dev,
-					 unsigned int enabled)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	int ret;
-
-	mutex_lock(&info->lock);
-	if (enabled)
-		ret = max77802_rtc_start_alarm(info);
-	else
-		ret = max77802_rtc_stop_alarm(info);
-	mutex_unlock(&info->lock);
-
-	return ret;
-}
-
-static irqreturn_t max77802_rtc_alarm_irq(int irq, void *data)
-{
-	struct max77802_rtc_info *info = data;
-
-	dev_dbg(info->dev, "%s:irq(%d)\n", __func__, irq);
-
-	rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
-
-	return IRQ_HANDLED;
-}
-
-static const struct rtc_class_ops max77802_rtc_ops = {
-	.read_time = max77802_rtc_read_time,
-	.set_time = max77802_rtc_set_time,
-	.read_alarm = max77802_rtc_read_alarm,
-	.set_alarm = max77802_rtc_set_alarm,
-	.alarm_irq_enable = max77802_rtc_alarm_irq_enable,
-};
-
-static int max77802_rtc_init_reg(struct max77802_rtc_info *info)
-{
-	u8 data[2];
-	int ret;
-
-	max77802_rtc_update(info, MAX77802_RTC_READ);
-
-	/* Set RTC control register : Binary mode, 24hour mdoe */
-	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
-	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
-
-	info->rtc_24hr_mode = 1;
-
-	ret = regmap_bulk_write(info->max77802->regmap,
-				MAX77802_RTC_CONTROLM, data, ARRAY_SIZE(data));
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
-				__func__, ret);
-		return ret;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-	return ret;
-}
-
-static int max77802_rtc_probe(struct platform_device *pdev)
-{
-	struct max77686_dev *max77802 = dev_get_drvdata(pdev->dev.parent);
-	struct max77802_rtc_info *info;
-	int ret;
-
-	dev_dbg(&pdev->dev, "%s\n", __func__);
-
-	info = devm_kzalloc(&pdev->dev, sizeof(struct max77802_rtc_info),
-			    GFP_KERNEL);
-	if (!info)
-		return -ENOMEM;
-
-	mutex_init(&info->lock);
-	info->dev = &pdev->dev;
-	info->max77802 = max77802;
-	info->rtc = max77802->i2c;
-
-	platform_set_drvdata(pdev, info);
-
-	ret = max77802_rtc_init_reg(info);
-
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
-		return ret;
-	}
-
-	device_init_wakeup(&pdev->dev, 1);
-
-	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77802-rtc",
-						 &max77802_rtc_ops, THIS_MODULE);
-
-	if (IS_ERR(info->rtc_dev)) {
-		ret = PTR_ERR(info->rtc_dev);
-		dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
-		if (ret == 0)
-			ret = -EINVAL;
-		return ret;
-	}
-
-	if (!max77802->rtc_irq_data) {
-		dev_err(&pdev->dev, "No RTC regmap IRQ chip\n");
-		return -EINVAL;
-	}
-
-	info->virq = regmap_irq_get_virq(max77802->rtc_irq_data,
-					 MAX77686_RTCIRQ_RTCA1);
-
-	if (info->virq <= 0) {
-		dev_err(&pdev->dev, "Failed to get virtual IRQ %d\n",
-			MAX77686_RTCIRQ_RTCA1);
-		return -EINVAL;
-	}
-
-	ret = devm_request_threaded_irq(&pdev->dev, info->virq, NULL,
-					max77802_rtc_alarm_irq, 0, "rtc-alarm1",
-					info);
-	if (ret < 0)
-		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
-			info->virq, ret);
-
-	return ret;
-}
-
-#ifdef CONFIG_PM_SLEEP
-static int max77802_rtc_suspend(struct device *dev)
-{
-	if (device_may_wakeup(dev)) {
-		struct max77802_rtc_info *info = dev_get_drvdata(dev);
-
-		return enable_irq_wake(info->virq);
-	}
-
-	return 0;
-}
-
-static int max77802_rtc_resume(struct device *dev)
-{
-	if (device_may_wakeup(dev)) {
-		struct max77802_rtc_info *info = dev_get_drvdata(dev);
-
-		return disable_irq_wake(info->virq);
-	}
-
-	return 0;
-}
-#endif
-
-static SIMPLE_DEV_PM_OPS(max77802_rtc_pm_ops,
-			 max77802_rtc_suspend, max77802_rtc_resume);
-
-static const struct platform_device_id rtc_id[] = {
-	{ "max77802-rtc", 0 },
-	{},
-};
-MODULE_DEVICE_TABLE(platform, rtc_id);
-
-static struct platform_driver max77802_rtc_driver = {
-	.driver		= {
-		.name	= "max77802-rtc",
-		.pm	= &max77802_rtc_pm_ops,
-	},
-	.probe		= max77802_rtc_probe,
-	.id_table	= rtc_id,
-};
-
-module_platform_driver(max77802_rtc_driver);
-
-MODULE_DESCRIPTION("Maxim MAX77802 RTC driver");
-MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
-MODULE_LICENSE("GPL");
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 08/10] rtc: Remove Maxim 77802 driver
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The max77686 RTC driver now supports the max77802 RTC as
well so there's no need to have a separate driver anymore.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

---

Changes in v3:
- Add Laxman Dewangan's Acked-by tag to patch #8.

Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.

 drivers/rtc/Kconfig        |  10 -
 drivers/rtc/Makefile       |   1 -
 drivers/rtc/rtc-max77802.c | 502 ---------------------------------------------
 3 files changed, 513 deletions(-)
 delete mode 100644 drivers/rtc/rtc-max77802.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 376322f71fd5..ef456d3cf265 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -335,16 +335,6 @@ config RTC_DRV_RK808
 	  This driver can also be built as a module. If so, the module
 	  will be called rk808-rtc.
 
-config RTC_DRV_MAX77802
-	tristate "Maxim 77802 RTC"
-	depends on MFD_MAX77686
-	help
-	  If you say yes here you will get support for the
-	  RTC of Maxim MAX77802 PMIC.
-
-	  This driver can also be built as a module. If so, the module
-	  will be called rtc-max77802.
-
 config RTC_DRV_RS5C372
 	tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
 	help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 62d61b26ca7e..ed4519efa3ca 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -86,7 +86,6 @@ obj-$(CONFIG_RTC_DRV_M48T86)	+= rtc-m48t86.o
 obj-$(CONFIG_RTC_DRV_MAX6900)	+= rtc-max6900.o
 obj-$(CONFIG_RTC_DRV_MAX6902)	+= rtc-max6902.o
 obj-$(CONFIG_RTC_DRV_MAX77686)	+= rtc-max77686.o
-obj-$(CONFIG_RTC_DRV_MAX77802)	+= rtc-max77802.o
 obj-$(CONFIG_RTC_DRV_MAX8907)	+= rtc-max8907.o
 obj-$(CONFIG_RTC_DRV_MAX8925)	+= rtc-max8925.o
 obj-$(CONFIG_RTC_DRV_MAX8997)	+= rtc-max8997.o
diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
deleted file mode 100644
index 82ffcc5a5345..000000000000
--- a/drivers/rtc/rtc-max77802.c
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * RTC driver for Maxim MAX77802
- *
- * Copyright (C) 2013 Google, Inc
- *
- * Copyright (C) 2012 Samsung Electronics Co.Ltd
- *
- *  based on rtc-max8997.c
- *
- *  This program is free software; you can redistribute  it and/or modify it
- *  under  the terms of  the GNU General  Public License as published by the
- *  Free Software Foundation;  either version 2 of the  License, or (at your
- *  option) any later version.
- *
- */
-
-#include <linux/slab.h>
-#include <linux/rtc.h>
-#include <linux/delay.h>
-#include <linux/mutex.h>
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/mfd/max77686-private.h>
-#include <linux/irqdomain.h>
-#include <linux/regmap.h>
-
-/* RTC Control Register */
-#define BCD_EN_SHIFT			0
-#define BCD_EN_MASK			(1 << BCD_EN_SHIFT)
-#define MODEL24_SHIFT			1
-#define MODEL24_MASK			(1 << MODEL24_SHIFT)
-/* RTC Update Register1 */
-#define RTC_UDR_SHIFT			0
-#define RTC_UDR_MASK			(1 << RTC_UDR_SHIFT)
-#define RTC_RBUDR_SHIFT			4
-#define RTC_RBUDR_MASK			(1 << RTC_RBUDR_SHIFT)
-/* RTC Hour register */
-#define HOUR_PM_SHIFT			6
-#define HOUR_PM_MASK			(1 << HOUR_PM_SHIFT)
-/* RTC Alarm Enable */
-#define ALARM_ENABLE_SHIFT		7
-#define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
-
-/* For the RTCAE1 register, we write this value to enable the alarm */
-#define ALARM_ENABLE_VALUE		0x77
-
-#define MAX77802_RTC_UPDATE_DELAY_US	200
-
-enum {
-	RTC_SEC = 0,
-	RTC_MIN,
-	RTC_HOUR,
-	RTC_WEEKDAY,
-	RTC_MONTH,
-	RTC_YEAR,
-	RTC_DATE,
-	RTC_NR_TIME
-};
-
-struct max77802_rtc_info {
-	struct device		*dev;
-	struct max77686_dev	*max77802;
-	struct i2c_client	*rtc;
-	struct rtc_device	*rtc_dev;
-	struct mutex		lock;
-
-	struct regmap		*regmap;
-
-	int virq;
-	int rtc_24hr_mode;
-};
-
-enum MAX77802_RTC_OP {
-	MAX77802_RTC_WRITE,
-	MAX77802_RTC_READ,
-};
-
-static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
-				   int rtc_24hr_mode)
-{
-	tm->tm_sec = data[RTC_SEC] & 0xff;
-	tm->tm_min = data[RTC_MIN] & 0xff;
-	if (rtc_24hr_mode)
-		tm->tm_hour = data[RTC_HOUR] & 0x1f;
-	else {
-		tm->tm_hour = data[RTC_HOUR] & 0x0f;
-		if (data[RTC_HOUR] & HOUR_PM_MASK)
-			tm->tm_hour += 12;
-	}
-
-	/* Only a single bit is set in data[], so fls() would be equivalent */
-	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0xff) - 1;
-	tm->tm_mday = data[RTC_DATE] & 0x1f;
-	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
-
-	tm->tm_year = data[RTC_YEAR] & 0xff;
-	tm->tm_yday = 0;
-	tm->tm_isdst = 0;
-}
-
-static int max77802_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
-{
-	data[RTC_SEC] = tm->tm_sec;
-	data[RTC_MIN] = tm->tm_min;
-	data[RTC_HOUR] = tm->tm_hour;
-	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
-	data[RTC_DATE] = tm->tm_mday;
-	data[RTC_MONTH] = tm->tm_mon + 1;
-	data[RTC_YEAR] = tm->tm_year;
-
-	return 0;
-}
-
-static int max77802_rtc_update(struct max77802_rtc_info *info,
-	enum MAX77802_RTC_OP op)
-{
-	int ret;
-	unsigned int data;
-
-	if (op == MAX77802_RTC_WRITE)
-		data = 1 << RTC_UDR_SHIFT;
-	else
-		data = 1 << RTC_RBUDR_SHIFT;
-
-	ret = regmap_update_bits(info->max77802->regmap,
-				 MAX77802_RTC_UPDATE0, data, data);
-	if (ret < 0)
-		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
-				__func__, ret, data);
-	else {
-		/* Minimum delay required before RTC update. */
-		usleep_range(MAX77802_RTC_UPDATE_DELAY_US,
-			     MAX77802_RTC_UPDATE_DELAY_US * 2);
-	}
-
-	return ret;
-}
-
-static int max77802_rtc_read_time(struct device *dev, struct rtc_time *tm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	int ret;
-
-	mutex_lock(&info->lock);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_bulk_read(info->max77802->regmap,
-				MAX77802_RTC_SEC, data, RTC_NR_TIME);
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,
-			ret);
-		goto out;
-	}
-
-	max77802_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
-
-	ret = rtc_valid_tm(tm);
-
-out:
-	mutex_unlock(&info->lock);
-	return ret;
-}
-
-static int max77802_rtc_set_time(struct device *dev, struct rtc_time *tm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	int ret;
-
-	ret = max77802_rtc_tm_to_data(tm, data);
-	if (ret < 0)
-		return ret;
-
-	mutex_lock(&info->lock);
-
-	ret = regmap_bulk_write(info->max77802->regmap,
-				 MAX77802_RTC_SEC, data, RTC_NR_TIME);
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
-			ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-
-out:
-	mutex_unlock(&info->lock);
-	return ret;
-}
-
-static int max77802_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	unsigned int val;
-	int ret;
-
-	mutex_lock(&info->lock);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_bulk_read(info->max77802->regmap,
-				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
-	if (ret < 0) {
-		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
-				__func__, __LINE__, ret);
-		goto out;
-	}
-
-	max77802_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
-
-	alrm->enabled = 0;
-	ret = regmap_read(info->max77802->regmap,
-			  MAX77802_RTC_AE1, &val);
-	if (ret < 0) {
-		dev_err(info->dev, "%s:%d fail to read alarm enable(%d)\n",
-			__func__, __LINE__, ret);
-		goto out;
-	}
-	if (val)
-		alrm->enabled = 1;
-
-	alrm->pending = 0;
-	ret = regmap_read(info->max77802->regmap, MAX77802_REG_STATUS2, &val);
-	if (ret < 0) {
-		dev_err(info->dev, "%s:%d fail to read status2 reg(%d)\n",
-				__func__, __LINE__, ret);
-		goto out;
-	}
-
-	if (val & (1 << 2)) /* RTCA1 */
-		alrm->pending = 1;
-
-out:
-	mutex_unlock(&info->lock);
-	return 0;
-}
-
-static int max77802_rtc_stop_alarm(struct max77802_rtc_info *info)
-{
-	int ret;
-
-	if (!mutex_is_locked(&info->lock))
-		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_write(info->max77802->regmap,
-			   MAX77802_RTC_AE1, 0);
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
-			__func__, ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-out:
-	return ret;
-}
-
-static int max77802_rtc_start_alarm(struct max77802_rtc_info *info)
-{
-	int ret;
-
-	if (!mutex_is_locked(&info->lock))
-		dev_warn(info->dev, "%s: should have mutex locked\n",
-			 __func__);
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_write(info->max77802->regmap,
-				   MAX77802_RTC_AE1,
-				   ALARM_ENABLE_VALUE);
-
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
-				__func__, ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-out:
-	return ret;
-}
-
-static int max77802_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	u8 data[RTC_NR_TIME];
-	int ret;
-
-	ret = max77802_rtc_tm_to_data(&alrm->time, data);
-	if (ret < 0)
-		return ret;
-
-	mutex_lock(&info->lock);
-
-	ret = max77802_rtc_stop_alarm(info);
-	if (ret < 0)
-		goto out;
-
-	ret = regmap_bulk_write(info->max77802->regmap,
-				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
-
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
-				__func__, ret);
-		goto out;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-	if (ret < 0)
-		goto out;
-
-	if (alrm->enabled)
-		ret = max77802_rtc_start_alarm(info);
-out:
-	mutex_unlock(&info->lock);
-	return ret;
-}
-
-static int max77802_rtc_alarm_irq_enable(struct device *dev,
-					 unsigned int enabled)
-{
-	struct max77802_rtc_info *info = dev_get_drvdata(dev);
-	int ret;
-
-	mutex_lock(&info->lock);
-	if (enabled)
-		ret = max77802_rtc_start_alarm(info);
-	else
-		ret = max77802_rtc_stop_alarm(info);
-	mutex_unlock(&info->lock);
-
-	return ret;
-}
-
-static irqreturn_t max77802_rtc_alarm_irq(int irq, void *data)
-{
-	struct max77802_rtc_info *info = data;
-
-	dev_dbg(info->dev, "%s:irq(%d)\n", __func__, irq);
-
-	rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
-
-	return IRQ_HANDLED;
-}
-
-static const struct rtc_class_ops max77802_rtc_ops = {
-	.read_time = max77802_rtc_read_time,
-	.set_time = max77802_rtc_set_time,
-	.read_alarm = max77802_rtc_read_alarm,
-	.set_alarm = max77802_rtc_set_alarm,
-	.alarm_irq_enable = max77802_rtc_alarm_irq_enable,
-};
-
-static int max77802_rtc_init_reg(struct max77802_rtc_info *info)
-{
-	u8 data[2];
-	int ret;
-
-	max77802_rtc_update(info, MAX77802_RTC_READ);
-
-	/* Set RTC control register : Binary mode, 24hour mdoe */
-	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
-	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
-
-	info->rtc_24hr_mode = 1;
-
-	ret = regmap_bulk_write(info->max77802->regmap,
-				MAX77802_RTC_CONTROLM, data, ARRAY_SIZE(data));
-	if (ret < 0) {
-		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
-				__func__, ret);
-		return ret;
-	}
-
-	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
-	return ret;
-}
-
-static int max77802_rtc_probe(struct platform_device *pdev)
-{
-	struct max77686_dev *max77802 = dev_get_drvdata(pdev->dev.parent);
-	struct max77802_rtc_info *info;
-	int ret;
-
-	dev_dbg(&pdev->dev, "%s\n", __func__);
-
-	info = devm_kzalloc(&pdev->dev, sizeof(struct max77802_rtc_info),
-			    GFP_KERNEL);
-	if (!info)
-		return -ENOMEM;
-
-	mutex_init(&info->lock);
-	info->dev = &pdev->dev;
-	info->max77802 = max77802;
-	info->rtc = max77802->i2c;
-
-	platform_set_drvdata(pdev, info);
-
-	ret = max77802_rtc_init_reg(info);
-
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
-		return ret;
-	}
-
-	device_init_wakeup(&pdev->dev, 1);
-
-	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77802-rtc",
-						 &max77802_rtc_ops, THIS_MODULE);
-
-	if (IS_ERR(info->rtc_dev)) {
-		ret = PTR_ERR(info->rtc_dev);
-		dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
-		if (ret == 0)
-			ret = -EINVAL;
-		return ret;
-	}
-
-	if (!max77802->rtc_irq_data) {
-		dev_err(&pdev->dev, "No RTC regmap IRQ chip\n");
-		return -EINVAL;
-	}
-
-	info->virq = regmap_irq_get_virq(max77802->rtc_irq_data,
-					 MAX77686_RTCIRQ_RTCA1);
-
-	if (info->virq <= 0) {
-		dev_err(&pdev->dev, "Failed to get virtual IRQ %d\n",
-			MAX77686_RTCIRQ_RTCA1);
-		return -EINVAL;
-	}
-
-	ret = devm_request_threaded_irq(&pdev->dev, info->virq, NULL,
-					max77802_rtc_alarm_irq, 0, "rtc-alarm1",
-					info);
-	if (ret < 0)
-		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
-			info->virq, ret);
-
-	return ret;
-}
-
-#ifdef CONFIG_PM_SLEEP
-static int max77802_rtc_suspend(struct device *dev)
-{
-	if (device_may_wakeup(dev)) {
-		struct max77802_rtc_info *info = dev_get_drvdata(dev);
-
-		return enable_irq_wake(info->virq);
-	}
-
-	return 0;
-}
-
-static int max77802_rtc_resume(struct device *dev)
-{
-	if (device_may_wakeup(dev)) {
-		struct max77802_rtc_info *info = dev_get_drvdata(dev);
-
-		return disable_irq_wake(info->virq);
-	}
-
-	return 0;
-}
-#endif
-
-static SIMPLE_DEV_PM_OPS(max77802_rtc_pm_ops,
-			 max77802_rtc_suspend, max77802_rtc_resume);
-
-static const struct platform_device_id rtc_id[] = {
-	{ "max77802-rtc", 0 },
-	{},
-};
-MODULE_DEVICE_TABLE(platform, rtc_id);
-
-static struct platform_driver max77802_rtc_driver = {
-	.driver		= {
-		.name	= "max77802-rtc",
-		.pm	= &max77802_rtc_pm_ops,
-	},
-	.probe		= max77802_rtc_probe,
-	.id_table	= rtc_id,
-};
-
-module_platform_driver(max77802_rtc_driver);
-
-MODULE_DESCRIPTION("Maxim MAX77802 RTC driver");
-MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
-MODULE_LICENSE("GPL");
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 09/10] ARM: exynos_defconfig: Remove MAX77802 RTC Kconfig symbol
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The driver has been removed so the Kconfig symbol is not valid anymore.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

---

Changes in v3: None
Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #9.

 arch/arm/configs/exynos_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm/configs/exynos_defconfig b/arch/arm/configs/exynos_defconfig
index 24dcd2bb1215..cdbe6dbc6e75 100644
--- a/arch/arm/configs/exynos_defconfig
+++ b/arch/arm/configs/exynos_defconfig
@@ -193,7 +193,6 @@ CONFIG_LEDS_TRIGGER_HEARTBEAT=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_MAX8997=y
 CONFIG_RTC_DRV_MAX77686=y
-CONFIG_RTC_DRV_MAX77802=y
 CONFIG_RTC_DRV_S5M=y
 CONFIG_RTC_DRV_S3C=y
 CONFIG_DMADEVICES=y
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 09/10] ARM: exynos_defconfig: Remove MAX77802 RTC Kconfig symbol
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas

The driver has been removed so the Kconfig symbol is not valid anymore.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

---

Changes in v3: None
Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #9.

 arch/arm/configs/exynos_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm/configs/exynos_defconfig b/arch/arm/configs/exynos_defconfig
index 24dcd2bb1215..cdbe6dbc6e75 100644
--- a/arch/arm/configs/exynos_defconfig
+++ b/arch/arm/configs/exynos_defconfig
@@ -193,7 +193,6 @@ CONFIG_LEDS_TRIGGER_HEARTBEAT=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_MAX8997=y
 CONFIG_RTC_DRV_MAX77686=y
-CONFIG_RTC_DRV_MAX77802=y
 CONFIG_RTC_DRV_S5M=y
 CONFIG_RTC_DRV_S3C=y
 CONFIG_DMADEVICES=y
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 10/10] ARM: multi_v7_defconfig: Remove MAX77802 RTC Kconfig symbol
  2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
  (?)
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas, Arnd Bergmann, Olof Johansson,
	linux-arm-kernel

The driver has been removed so the Kconfig symbol is not valid anymore.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>


---

Changes in v3: None
Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #10.

 arch/arm/configs/multi_v7_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index 314f6be2dca2..bdb42c09332c 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -664,7 +664,6 @@ CONFIG_RTC_DRV_MAX8907=y
 CONFIG_RTC_DRV_MAX8997=m
 CONFIG_RTC_DRV_MAX77686=y
 CONFIG_RTC_DRV_RK808=m
-CONFIG_RTC_DRV_MAX77802=m
 CONFIG_RTC_DRV_RS5C372=m
 CONFIG_RTC_DRV_PALMAS=y
 CONFIG_RTC_DRV_ST_LPC=y
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [rtc-linux] [PATCH v3 10/10] ARM: multi_v7_defconfig: Remove MAX77802 RTC Kconfig symbol
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Krzysztof Kozlowski, Laxman Dewangan, linux-samsung-soc,
	Javier Martinez Canillas, Arnd Bergmann, Olof Johansson,
	linux-arm-kernel

The driver has been removed so the Kconfig symbol is not valid anymore.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>


---

Changes in v3: None
Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #10.

 arch/arm/configs/multi_v7_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index 314f6be2dca2..bdb42c09332c 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -664,7 +664,6 @@ CONFIG_RTC_DRV_MAX8907=y
 CONFIG_RTC_DRV_MAX8997=m
 CONFIG_RTC_DRV_MAX77686=y
 CONFIG_RTC_DRV_RK808=m
-CONFIG_RTC_DRV_MAX77802=m
 CONFIG_RTC_DRV_RS5C372=m
 CONFIG_RTC_DRV_PALMAS=y
 CONFIG_RTC_DRV_ST_LPC=y
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v3 10/10] ARM: multi_v7_defconfig: Remove MAX77802 RTC Kconfig symbol
@ 2016-01-26 19:20   ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-26 19:20 UTC (permalink / raw)
  To: linux-arm-kernel

The driver has been removed so the Kconfig symbol is not valid anymore.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>


---

Changes in v3: None
Changes in v2:
- Add Krzysztof Kozlowski's Reviewed-by tag to patch #10.

 arch/arm/configs/multi_v7_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index 314f6be2dca2..bdb42c09332c 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -664,7 +664,6 @@ CONFIG_RTC_DRV_MAX8907=y
 CONFIG_RTC_DRV_MAX8997=m
 CONFIG_RTC_DRV_MAX77686=y
 CONFIG_RTC_DRV_RK808=m
-CONFIG_RTC_DRV_MAX77802=m
 CONFIG_RTC_DRV_RS5C372=m
 CONFIG_RTC_DRV_PALMAS=y
 CONFIG_RTC_DRV_ST_LPC=y
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 01/10] rtc: max77686: Fix max77686_rtc_read_alarm() return value
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:19     ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:19 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

> The function is always returning zero even in case of failures since
> the ret value was not propagated to the callers. Fix the error path.
> 
> Reported-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Krzysztof Kozlowski's Reviewed-by and Tested-by to patch #1.
> - Add Laxman Dewangan's Acked-by tag to patch #1.
> 
> Changes in v2: None
> 
>  drivers/rtc/rtc-max77686.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 7184a0eda793..6653c3d11b66 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -235,7 +235,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  
>  out:
>  	mutex_unlock(&info->lock);
> -	return 0;
> +	return ret;
>  }
>  
>  static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 01/10] rtc: max77686: Fix max77686_rtc_read_alarm() return value
@ 2016-01-27  1:19     ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:19 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

> The function is always returning zero even in case of failures since
> the ret value was not propagated to the callers. Fix the error path.
> 
> Reported-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Krzysztof Kozlowski's Reviewed-by and Tested-by to patch #1.
> - Add Laxman Dewangan's Acked-by tag to patch #1.
> 
> Changes in v2: None
> 
>  drivers/rtc/rtc-max77686.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 7184a0eda793..6653c3d11b66 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -235,7 +235,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  
>  out:
>  	mutex_unlock(&info->lock);
> -	return 0;
> +	return ret;
>  }
>  
>  static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 02/10] rtc: max77686: Use ARRAY_SIZE() instead of current array length
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:20     ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:20 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:12PM -0300, Javier Martinez Canillas wrote:
> It is better to use the ARRAY_SIZE() macro instead of the array length
> to avoid bugs if the array is later changed and the length not updated.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Krzysztof Kozlowski's Tested-by tag to patch #2.
> - Add Laxman Dewangan's Acked-by tag to patch #2.
> - Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.
> 
>  drivers/rtc/rtc-max77686.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 6653c3d11b66..d84a50c9f7f7 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -149,7 +149,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				MAX77686_RTC_SEC, data, RTC_NR_TIME);
> +				MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,	ret);
>  		goto out;
> @@ -177,7 +177,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  	mutex_lock(&info->lock);
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_RTC_SEC, data, RTC_NR_TIME);
> +				 MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
>  				ret);
> @@ -205,7 +205,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
>  				__func__, __LINE__, ret);
> @@ -215,7 +215,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
>  
>  	alrm->enabled = 0;
> -	for (i = 0; i < RTC_NR_TIME; i++) {
> +	for (i = 0; i < ARRAY_SIZE(data); i++) {
>  		if (data[i] & ALARM_ENABLE_MASK) {
>  			alrm->enabled = 1;
>  			break;
> @@ -252,7 +252,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -261,11 +261,11 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
>  
>  	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
>  
> -	for (i = 0; i < RTC_NR_TIME; i++)
> +	for (i = 0; i < ARRAY_SIZE(data); i++)
>  		data[i] &= ~ALARM_ENABLE_MASK;
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -291,7 +291,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -312,7 +312,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -341,7 +341,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
> @@ -406,7 +406,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
>  
>  	info->rtc_24hr_mode = 1;
>  
> -	ret = regmap_bulk_write(info->max77686->rtc_regmap, MAX77686_RTC_CONTROLM, data, 2);
> +	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> +				MAX77686_RTC_CONTROLM, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
>  				__func__, ret);
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 02/10] rtc: max77686: Use ARRAY_SIZE() instead of current array length
@ 2016-01-27  1:20     ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:20 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:12PM -0300, Javier Martinez Canillas wrote:
> It is better to use the ARRAY_SIZE() macro instead of the array length
> to avoid bugs if the array is later changed and the length not updated.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Krzysztof Kozlowski's Tested-by tag to patch #2.
> - Add Laxman Dewangan's Acked-by tag to patch #2.
> - Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.
> 
>  drivers/rtc/rtc-max77686.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 6653c3d11b66..d84a50c9f7f7 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -149,7 +149,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				MAX77686_RTC_SEC, data, RTC_NR_TIME);
> +				MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,	ret);
>  		goto out;
> @@ -177,7 +177,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  	mutex_lock(&info->lock);
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_RTC_SEC, data, RTC_NR_TIME);
> +				 MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
>  				ret);
> @@ -205,7 +205,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
>  				__func__, __LINE__, ret);
> @@ -215,7 +215,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
>  
>  	alrm->enabled = 0;
> -	for (i = 0; i < RTC_NR_TIME; i++) {
> +	for (i = 0; i < ARRAY_SIZE(data); i++) {
>  		if (data[i] & ALARM_ENABLE_MASK) {
>  			alrm->enabled = 1;
>  			break;
> @@ -252,7 +252,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -261,11 +261,11 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
>  
>  	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
>  
> -	for (i = 0; i < RTC_NR_TIME; i++)
> +	for (i = 0; i < ARRAY_SIZE(data); i++)
>  		data[i] &= ~ALARM_ENABLE_MASK;
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -291,7 +291,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  
>  	ret = regmap_bulk_read(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -312,7 +312,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -341,7 +341,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  
>  	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> -				 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
> +				 MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
>  
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
> @@ -406,7 +406,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
>  
>  	info->rtc_24hr_mode = 1;
>  
> -	ret = regmap_bulk_write(info->max77686->rtc_regmap, MAX77686_RTC_CONTROLM, data, 2);
> +	ret = regmap_bulk_write(info->max77686->rtc_regmap,
> +				MAX77686_RTC_CONTROLM, data, ARRAY_SIZE(data));
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
>  				__func__, ret);
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 03/10] rtc: max77686: Use usleep_range() instead of msleep()
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:21     ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:21 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:13PM -0300, Javier Martinez Canillas wrote:
> Documentation/timers/timers-howto.txt suggest to use usleep_range()
> instead of msleep() for small msec (1ms - 20ms) since msleep() will
> often sleep for 20ms for any value in that range.
> 
> This is fine in this case since 16ms is the _minimum_ delay required
> by max77686 for an RTC update but by using usleep_range() instead of
> msleep(), the driver can support other RTC IP blocks with a shorter
> minimum delay (i.e: in the range of usecs instead of msecs).
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Krzysztof Kozlowski's Tested-by tag to patch #3.
> - Add Laxman Dewangan's Acked-by tag to patch #3.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #3.
> - Fix typo error in changelog. Suggested by Krzysztof Kozlowski.
> 
>  drivers/rtc/rtc-max77686.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index d84a50c9f7f7..025a17a95da3 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -41,7 +41,7 @@
>  #define ALARM_ENABLE_SHIFT		7
>  #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
>  
> -#define MAX77686_RTC_UPDATE_DELAY	16
> +#define MAX77686_RTC_UPDATE_DELAY	16000
>  
>  enum {
>  	RTC_SEC = 0,
> @@ -130,7 +130,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
>  				__func__, ret, data);
>  	else {
>  		/* Minimum 16ms delay required before RTC update. */
> -		msleep(MAX77686_RTC_UPDATE_DELAY);
> +		usleep_range(MAX77686_RTC_UPDATE_DELAY,
> +			     MAX77686_RTC_UPDATE_DELAY * 2);
>  	}
>  
>  	return ret;
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 03/10] rtc: max77686: Use usleep_range() instead of msleep()
@ 2016-01-27  1:21     ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:21 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:13PM -0300, Javier Martinez Canillas wrote:
> Documentation/timers/timers-howto.txt suggest to use usleep_range()
> instead of msleep() for small msec (1ms - 20ms) since msleep() will
> often sleep for 20ms for any value in that range.
> 
> This is fine in this case since 16ms is the _minimum_ delay required
> by max77686 for an RTC update but by using usleep_range() instead of
> msleep(), the driver can support other RTC IP blocks with a shorter
> minimum delay (i.e: in the range of usecs instead of msecs).
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Krzysztof Kozlowski's Tested-by tag to patch #3.
> - Add Laxman Dewangan's Acked-by tag to patch #3.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #3.
> - Fix typo error in changelog. Suggested by Krzysztof Kozlowski.
> 
>  drivers/rtc/rtc-max77686.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index d84a50c9f7f7..025a17a95da3 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -41,7 +41,7 @@
>  #define ALARM_ENABLE_SHIFT		7
>  #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
>  
> -#define MAX77686_RTC_UPDATE_DELAY	16
> +#define MAX77686_RTC_UPDATE_DELAY	16000
>  
>  enum {
>  	RTC_SEC = 0,
> @@ -130,7 +130,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
>  				__func__, ret, data);
>  	else {
>  		/* Minimum 16ms delay required before RTC update. */
> -		msleep(MAX77686_RTC_UPDATE_DELAY);
> +		usleep_range(MAX77686_RTC_UPDATE_DELAY,
> +			     MAX77686_RTC_UPDATE_DELAY * 2);
>  	}
>  
>  	return ret;
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:21     ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:21 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:14PM -0300, Javier Martinez Canillas wrote:
> The driver has some hard-coded values such as the minimum delay needed
> before a RTC update or the mask used for the sec/min/hour/etc registers.
> 
> Use a data structure that contains these values and pass as driver data
> using the platform device ID table for each device.
> 
> This allows to make the driver's ops callbacks more generic so other RTC
> that are similar but don't have the same values can also be supported.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Fix max77686 delay. Suggested by Krzysztof Kozlowski.
> - Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
> - Add Laxman Dewangan's Acked-by tag to patch #4.
> 
> Changes in v2:
> - Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
> - Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
> - Change .mask type to u8. Suggested by Krzysztof Kozlowski.
> - Make .drv_data field const. Suggested by Krzysztof Kozlowski.
> - Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
> - Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.
> 
>  drivers/rtc/rtc-max77686.c | 51 ++++++++++++++++++++++++++++++----------------
>  1 file changed, 34 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 025a17a95da3..8c4ca35029c3 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -41,8 +41,6 @@
>  #define ALARM_ENABLE_SHIFT		7
>  #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
>  
> -#define MAX77686_RTC_UPDATE_DELAY	16000
> -
>  enum {
>  	RTC_SEC = 0,
>  	RTC_MIN,
> @@ -54,6 +52,13 @@ enum {
>  	RTC_NR_TIME
>  };
>  
> +struct max77686_rtc_driver_data {
> +	/* Minimum usecs needed for a RTC update */
> +	unsigned long		delay;
> +	/* Mask used to read RTC registers value */
> +	u8			mask;
> +};
> +
>  struct max77686_rtc_info {
>  	struct device		*dev;
>  	struct max77686_dev	*max77686;
> @@ -63,6 +68,8 @@ struct max77686_rtc_info {
>  
>  	struct regmap		*regmap;
>  
> +	const struct max77686_rtc_driver_data *drv_data;
> +
>  	int virq;
>  	int rtc_24hr_mode;
>  };
> @@ -72,12 +79,19 @@ enum MAX77686_RTC_OP {
>  	MAX77686_RTC_READ,
>  };
>  
> +static const struct max77686_rtc_driver_data max77686_drv_data = {
> +	.delay = 16000,
> +	.mask  = 0x7f,
> +};
> +
>  static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
> -				   int rtc_24hr_mode)
> +				    struct max77686_rtc_info *info)
>  {
> -	tm->tm_sec = data[RTC_SEC] & 0x7f;
> -	tm->tm_min = data[RTC_MIN] & 0x7f;
> -	if (rtc_24hr_mode)
> +	u8 mask = info->drv_data->mask;
> +
> +	tm->tm_sec = data[RTC_SEC] & mask;
> +	tm->tm_min = data[RTC_MIN] & mask;
> +	if (info->rtc_24hr_mode)
>  		tm->tm_hour = data[RTC_HOUR] & 0x1f;
>  	else {
>  		tm->tm_hour = data[RTC_HOUR] & 0x0f;
> @@ -86,10 +100,10 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
>  	}
>  
>  	/* Only a single bit is set in data[], so fls() would be equivalent */
> -	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f) - 1;
> +	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
>  	tm->tm_mday = data[RTC_DATE] & 0x1f;
>  	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
> -	tm->tm_year = (data[RTC_YEAR] & 0x7f) + 100;
> +	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
>  	tm->tm_yday = 0;
>  	tm->tm_isdst = 0;
>  }
> @@ -117,6 +131,7 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
>  {
>  	int ret;
>  	unsigned int data;
> +	unsigned long delay = info->drv_data->delay;
>  
>  	if (op == MAX77686_RTC_WRITE)
>  		data = 1 << RTC_UDR_SHIFT;
> @@ -129,9 +144,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
>  		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
>  				__func__, ret, data);
>  	else {
> -		/* Minimum 16ms delay required before RTC update. */
> -		usleep_range(MAX77686_RTC_UPDATE_DELAY,
> -			     MAX77686_RTC_UPDATE_DELAY * 2);
> +		/* Minimum delay required before RTC update. */
> +		usleep_range(delay, delay * 2);
>  	}
>  
>  	return ret;
> @@ -156,7 +170,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, tm, info);
>  
>  	ret = rtc_valid_tm(tm);
>  
> @@ -213,7 +227,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, &alrm->time, info);
>  
>  	alrm->enabled = 0;
>  	for (i = 0; i < ARRAY_SIZE(data); i++) {
> @@ -260,7 +274,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, &tm, info);
>  
>  	for (i = 0; i < ARRAY_SIZE(data); i++)
>  		data[i] &= ~ALARM_ENABLE_MASK;
> @@ -299,7 +313,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, &tm, info);
>  
>  	data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
>  	data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
> @@ -307,7 +321,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  	data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
>  	if (data[RTC_MONTH] & 0xf)
>  		data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
> -	if (data[RTC_YEAR] & 0x7f)
> +	if (data[RTC_YEAR] & info->drv_data->mask)
>  		data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
>  	if (data[RTC_DATE] & 0x1f)
>  		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
> @@ -423,6 +437,7 @@ static int max77686_rtc_probe(struct platform_device *pdev)
>  {
>  	struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent);
>  	struct max77686_rtc_info *info;
> +	const struct platform_device_id *id = platform_get_device_id(pdev);
>  	int ret;
>  
>  	dev_info(&pdev->dev, "%s\n", __func__);
> @@ -436,6 +451,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
>  	info->dev = &pdev->dev;
>  	info->max77686 = max77686;
>  	info->rtc = max77686->rtc;
> +	info->drv_data = (const struct max77686_rtc_driver_data *)
> +		id->driver_data;
>  
>  	platform_set_drvdata(pdev, info);
>  
> @@ -510,7 +527,7 @@ static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
>  			 max77686_rtc_suspend, max77686_rtc_resume);
>  
>  static const struct platform_device_id rtc_id[] = {
> -	{ "max77686-rtc", 0 },
> +	{ "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, },
>  	{},
>  };
>  MODULE_DEVICE_TABLE(platform, rtc_id);
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values
@ 2016-01-27  1:21     ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:21 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:14PM -0300, Javier Martinez Canillas wrote:
> The driver has some hard-coded values such as the minimum delay needed
> before a RTC update or the mask used for the sec/min/hour/etc registers.
> 
> Use a data structure that contains these values and pass as driver data
> using the platform device ID table for each device.
> 
> This allows to make the driver's ops callbacks more generic so other RTC
> that are similar but don't have the same values can also be supported.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Fix max77686 delay. Suggested by Krzysztof Kozlowski.
> - Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
> - Add Laxman Dewangan's Acked-by tag to patch #4.
> 
> Changes in v2:
> - Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
> - Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
> - Change .mask type to u8. Suggested by Krzysztof Kozlowski.
> - Make .drv_data field const. Suggested by Krzysztof Kozlowski.
> - Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
> - Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.
> 
>  drivers/rtc/rtc-max77686.c | 51 ++++++++++++++++++++++++++++++----------------
>  1 file changed, 34 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 025a17a95da3..8c4ca35029c3 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -41,8 +41,6 @@
>  #define ALARM_ENABLE_SHIFT		7
>  #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
>  
> -#define MAX77686_RTC_UPDATE_DELAY	16000
> -
>  enum {
>  	RTC_SEC = 0,
>  	RTC_MIN,
> @@ -54,6 +52,13 @@ enum {
>  	RTC_NR_TIME
>  };
>  
> +struct max77686_rtc_driver_data {
> +	/* Minimum usecs needed for a RTC update */
> +	unsigned long		delay;
> +	/* Mask used to read RTC registers value */
> +	u8			mask;
> +};
> +
>  struct max77686_rtc_info {
>  	struct device		*dev;
>  	struct max77686_dev	*max77686;
> @@ -63,6 +68,8 @@ struct max77686_rtc_info {
>  
>  	struct regmap		*regmap;
>  
> +	const struct max77686_rtc_driver_data *drv_data;
> +
>  	int virq;
>  	int rtc_24hr_mode;
>  };
> @@ -72,12 +79,19 @@ enum MAX77686_RTC_OP {
>  	MAX77686_RTC_READ,
>  };
>  
> +static const struct max77686_rtc_driver_data max77686_drv_data = {
> +	.delay = 16000,
> +	.mask  = 0x7f,
> +};
> +
>  static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
> -				   int rtc_24hr_mode)
> +				    struct max77686_rtc_info *info)
>  {
> -	tm->tm_sec = data[RTC_SEC] & 0x7f;
> -	tm->tm_min = data[RTC_MIN] & 0x7f;
> -	if (rtc_24hr_mode)
> +	u8 mask = info->drv_data->mask;
> +
> +	tm->tm_sec = data[RTC_SEC] & mask;
> +	tm->tm_min = data[RTC_MIN] & mask;
> +	if (info->rtc_24hr_mode)
>  		tm->tm_hour = data[RTC_HOUR] & 0x1f;
>  	else {
>  		tm->tm_hour = data[RTC_HOUR] & 0x0f;
> @@ -86,10 +100,10 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
>  	}
>  
>  	/* Only a single bit is set in data[], so fls() would be equivalent */
> -	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f) - 1;
> +	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
>  	tm->tm_mday = data[RTC_DATE] & 0x1f;
>  	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
> -	tm->tm_year = (data[RTC_YEAR] & 0x7f) + 100;
> +	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
>  	tm->tm_yday = 0;
>  	tm->tm_isdst = 0;
>  }
> @@ -117,6 +131,7 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
>  {
>  	int ret;
>  	unsigned int data;
> +	unsigned long delay = info->drv_data->delay;
>  
>  	if (op == MAX77686_RTC_WRITE)
>  		data = 1 << RTC_UDR_SHIFT;
> @@ -129,9 +144,8 @@ static int max77686_rtc_update(struct max77686_rtc_info *info,
>  		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
>  				__func__, ret, data);
>  	else {
> -		/* Minimum 16ms delay required before RTC update. */
> -		usleep_range(MAX77686_RTC_UPDATE_DELAY,
> -			     MAX77686_RTC_UPDATE_DELAY * 2);
> +		/* Minimum delay required before RTC update. */
> +		usleep_range(delay, delay * 2);
>  	}
>  
>  	return ret;
> @@ -156,7 +170,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, tm, info);
>  
>  	ret = rtc_valid_tm(tm);
>  
> @@ -213,7 +227,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, &alrm->time, info);
>  
>  	alrm->enabled = 0;
>  	for (i = 0; i < ARRAY_SIZE(data); i++) {
> @@ -260,7 +274,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, &tm, info);
>  
>  	for (i = 0; i < ARRAY_SIZE(data); i++)
>  		data[i] &= ~ALARM_ENABLE_MASK;
> @@ -299,7 +313,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  	}
>  
> -	max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
> +	max77686_rtc_data_to_tm(data, &tm, info);
>  
>  	data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
>  	data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
> @@ -307,7 +321,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  	data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
>  	if (data[RTC_MONTH] & 0xf)
>  		data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
> -	if (data[RTC_YEAR] & 0x7f)
> +	if (data[RTC_YEAR] & info->drv_data->mask)
>  		data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
>  	if (data[RTC_DATE] & 0x1f)
>  		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
> @@ -423,6 +437,7 @@ static int max77686_rtc_probe(struct platform_device *pdev)
>  {
>  	struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent);
>  	struct max77686_rtc_info *info;
> +	const struct platform_device_id *id = platform_get_device_id(pdev);
>  	int ret;
>  
>  	dev_info(&pdev->dev, "%s\n", __func__);
> @@ -436,6 +451,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
>  	info->dev = &pdev->dev;
>  	info->max77686 = max77686;
>  	info->rtc = max77686->rtc;
> +	info->drv_data = (const struct max77686_rtc_driver_data *)
> +		id->driver_data;
>  
>  	platform_set_drvdata(pdev, info);
>  
> @@ -510,7 +527,7 @@ static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
>  			 max77686_rtc_suspend, max77686_rtc_resume);
>  
>  static const struct platform_device_id rtc_id[] = {
> -	{ "max77686-rtc", 0 },
> +	{ "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, },
>  	{},
>  };
>  MODULE_DEVICE_TABLE(platform, rtc_id);
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:22     ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:22 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

Hi Javier,

>  		if (tm->tm_year < 100) {
> -			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> -				1900 + tm->tm_year);
> +			dev_warn(info->dev,
> +				 "RTC can't handle year %d. Assume it's 2000\n",
> +				 1900 + tm->tm_year);
>  			return -EINVAL;

Because we are returning an error value, why not use dev_err()?

>  		}
>  	} else {
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  1:22     ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:22 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

Hi Javier,

>  		if (tm->tm_year < 100) {
> -			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> -				1900 + tm->tm_year);
> +			dev_warn(info->dev,
> +				 "RTC can't handle year %d. Assume it's 2000\n",
> +				 1900 + tm->tm_year);
>  			return -EINVAL;

Because we are returning an error value, why not use dev_err()?

>  		}
>  	} else {
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 08/10] rtc: Remove Maxim 77802 driver
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:22     ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:22 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:18PM -0300, Javier Martinez Canillas wrote:
> The max77686 RTC driver now supports the max77802 RTC as
> well so there's no need to have a separate driver anymore.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #8.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.
> 
>  drivers/rtc/Kconfig        |  10 -
>  drivers/rtc/Makefile       |   1 -
>  drivers/rtc/rtc-max77802.c | 502 ---------------------------------------------
>  3 files changed, 513 deletions(-)
>  delete mode 100644 drivers/rtc/rtc-max77802.c
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 376322f71fd5..ef456d3cf265 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -335,16 +335,6 @@ config RTC_DRV_RK808
>  	  This driver can also be built as a module. If so, the module
>  	  will be called rk808-rtc.
>  
> -config RTC_DRV_MAX77802
> -	tristate "Maxim 77802 RTC"
> -	depends on MFD_MAX77686
> -	help
> -	  If you say yes here you will get support for the
> -	  RTC of Maxim MAX77802 PMIC.
> -
> -	  This driver can also be built as a module. If so, the module
> -	  will be called rtc-max77802.
> -
>  config RTC_DRV_RS5C372
>  	tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
>  	help
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 62d61b26ca7e..ed4519efa3ca 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -86,7 +86,6 @@ obj-$(CONFIG_RTC_DRV_M48T86)	+= rtc-m48t86.o
>  obj-$(CONFIG_RTC_DRV_MAX6900)	+= rtc-max6900.o
>  obj-$(CONFIG_RTC_DRV_MAX6902)	+= rtc-max6902.o
>  obj-$(CONFIG_RTC_DRV_MAX77686)	+= rtc-max77686.o
> -obj-$(CONFIG_RTC_DRV_MAX77802)	+= rtc-max77802.o
>  obj-$(CONFIG_RTC_DRV_MAX8907)	+= rtc-max8907.o
>  obj-$(CONFIG_RTC_DRV_MAX8925)	+= rtc-max8925.o
>  obj-$(CONFIG_RTC_DRV_MAX8997)	+= rtc-max8997.o
> diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
> deleted file mode 100644
> index 82ffcc5a5345..000000000000
> --- a/drivers/rtc/rtc-max77802.c
> +++ /dev/null
> @@ -1,502 +0,0 @@
> -/*
> - * RTC driver for Maxim MAX77802
> - *
> - * Copyright (C) 2013 Google, Inc
> - *
> - * Copyright (C) 2012 Samsung Electronics Co.Ltd
> - *
> - *  based on rtc-max8997.c
> - *
> - *  This program is free software; you can redistribute  it and/or modify it
> - *  under  the terms of  the GNU General  Public License as published by the
> - *  Free Software Foundation;  either version 2 of the  License, or (at your
> - *  option) any later version.
> - *
> - */
> -
> -#include <linux/slab.h>
> -#include <linux/rtc.h>
> -#include <linux/delay.h>
> -#include <linux/mutex.h>
> -#include <linux/module.h>
> -#include <linux/platform_device.h>
> -#include <linux/mfd/max77686-private.h>
> -#include <linux/irqdomain.h>
> -#include <linux/regmap.h>
> -
> -/* RTC Control Register */
> -#define BCD_EN_SHIFT			0
> -#define BCD_EN_MASK			(1 << BCD_EN_SHIFT)
> -#define MODEL24_SHIFT			1
> -#define MODEL24_MASK			(1 << MODEL24_SHIFT)
> -/* RTC Update Register1 */
> -#define RTC_UDR_SHIFT			0
> -#define RTC_UDR_MASK			(1 << RTC_UDR_SHIFT)
> -#define RTC_RBUDR_SHIFT			4
> -#define RTC_RBUDR_MASK			(1 << RTC_RBUDR_SHIFT)
> -/* RTC Hour register */
> -#define HOUR_PM_SHIFT			6
> -#define HOUR_PM_MASK			(1 << HOUR_PM_SHIFT)
> -/* RTC Alarm Enable */
> -#define ALARM_ENABLE_SHIFT		7
> -#define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
> -
> -/* For the RTCAE1 register, we write this value to enable the alarm */
> -#define ALARM_ENABLE_VALUE		0x77
> -
> -#define MAX77802_RTC_UPDATE_DELAY_US	200
> -
> -enum {
> -	RTC_SEC = 0,
> -	RTC_MIN,
> -	RTC_HOUR,
> -	RTC_WEEKDAY,
> -	RTC_MONTH,
> -	RTC_YEAR,
> -	RTC_DATE,
> -	RTC_NR_TIME
> -};
> -
> -struct max77802_rtc_info {
> -	struct device		*dev;
> -	struct max77686_dev	*max77802;
> -	struct i2c_client	*rtc;
> -	struct rtc_device	*rtc_dev;
> -	struct mutex		lock;
> -
> -	struct regmap		*regmap;
> -
> -	int virq;
> -	int rtc_24hr_mode;
> -};
> -
> -enum MAX77802_RTC_OP {
> -	MAX77802_RTC_WRITE,
> -	MAX77802_RTC_READ,
> -};
> -
> -static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
> -				   int rtc_24hr_mode)
> -{
> -	tm->tm_sec = data[RTC_SEC] & 0xff;
> -	tm->tm_min = data[RTC_MIN] & 0xff;
> -	if (rtc_24hr_mode)
> -		tm->tm_hour = data[RTC_HOUR] & 0x1f;
> -	else {
> -		tm->tm_hour = data[RTC_HOUR] & 0x0f;
> -		if (data[RTC_HOUR] & HOUR_PM_MASK)
> -			tm->tm_hour += 12;
> -	}
> -
> -	/* Only a single bit is set in data[], so fls() would be equivalent */
> -	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0xff) - 1;
> -	tm->tm_mday = data[RTC_DATE] & 0x1f;
> -	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
> -
> -	tm->tm_year = data[RTC_YEAR] & 0xff;
> -	tm->tm_yday = 0;
> -	tm->tm_isdst = 0;
> -}
> -
> -static int max77802_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
> -{
> -	data[RTC_SEC] = tm->tm_sec;
> -	data[RTC_MIN] = tm->tm_min;
> -	data[RTC_HOUR] = tm->tm_hour;
> -	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
> -	data[RTC_DATE] = tm->tm_mday;
> -	data[RTC_MONTH] = tm->tm_mon + 1;
> -	data[RTC_YEAR] = tm->tm_year;
> -
> -	return 0;
> -}
> -
> -static int max77802_rtc_update(struct max77802_rtc_info *info,
> -	enum MAX77802_RTC_OP op)
> -{
> -	int ret;
> -	unsigned int data;
> -
> -	if (op == MAX77802_RTC_WRITE)
> -		data = 1 << RTC_UDR_SHIFT;
> -	else
> -		data = 1 << RTC_RBUDR_SHIFT;
> -
> -	ret = regmap_update_bits(info->max77802->regmap,
> -				 MAX77802_RTC_UPDATE0, data, data);
> -	if (ret < 0)
> -		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
> -				__func__, ret, data);
> -	else {
> -		/* Minimum delay required before RTC update. */
> -		usleep_range(MAX77802_RTC_UPDATE_DELAY_US,
> -			     MAX77802_RTC_UPDATE_DELAY_US * 2);
> -	}
> -
> -	return ret;
> -}
> -
> -static int max77802_rtc_read_time(struct device *dev, struct rtc_time *tm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	int ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_bulk_read(info->max77802->regmap,
> -				MAX77802_RTC_SEC, data, RTC_NR_TIME);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,
> -			ret);
> -		goto out;
> -	}
> -
> -	max77802_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
> -
> -	ret = rtc_valid_tm(tm);
> -
> -out:
> -	mutex_unlock(&info->lock);
> -	return ret;
> -}
> -
> -static int max77802_rtc_set_time(struct device *dev, struct rtc_time *tm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	int ret;
> -
> -	ret = max77802_rtc_tm_to_data(tm, data);
> -	if (ret < 0)
> -		return ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = regmap_bulk_write(info->max77802->regmap,
> -				 MAX77802_RTC_SEC, data, RTC_NR_TIME);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
> -			ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -
> -out:
> -	mutex_unlock(&info->lock);
> -	return ret;
> -}
> -
> -static int max77802_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	unsigned int val;
> -	int ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_bulk_read(info->max77802->regmap,
> -				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
> -				__func__, __LINE__, ret);
> -		goto out;
> -	}
> -
> -	max77802_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
> -
> -	alrm->enabled = 0;
> -	ret = regmap_read(info->max77802->regmap,
> -			  MAX77802_RTC_AE1, &val);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s:%d fail to read alarm enable(%d)\n",
> -			__func__, __LINE__, ret);
> -		goto out;
> -	}
> -	if (val)
> -		alrm->enabled = 1;
> -
> -	alrm->pending = 0;
> -	ret = regmap_read(info->max77802->regmap, MAX77802_REG_STATUS2, &val);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s:%d fail to read status2 reg(%d)\n",
> -				__func__, __LINE__, ret);
> -		goto out;
> -	}
> -
> -	if (val & (1 << 2)) /* RTCA1 */
> -		alrm->pending = 1;
> -
> -out:
> -	mutex_unlock(&info->lock);
> -	return 0;
> -}
> -
> -static int max77802_rtc_stop_alarm(struct max77802_rtc_info *info)
> -{
> -	int ret;
> -
> -	if (!mutex_is_locked(&info->lock))
> -		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_write(info->max77802->regmap,
> -			   MAX77802_RTC_AE1, 0);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
> -			__func__, ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -out:
> -	return ret;
> -}
> -
> -static int max77802_rtc_start_alarm(struct max77802_rtc_info *info)
> -{
> -	int ret;
> -
> -	if (!mutex_is_locked(&info->lock))
> -		dev_warn(info->dev, "%s: should have mutex locked\n",
> -			 __func__);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_write(info->max77802->regmap,
> -				   MAX77802_RTC_AE1,
> -				   ALARM_ENABLE_VALUE);
> -
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
> -				__func__, ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -out:
> -	return ret;
> -}
> -
> -static int max77802_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	int ret;
> -
> -	ret = max77802_rtc_tm_to_data(&alrm->time, data);
> -	if (ret < 0)
> -		return ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = max77802_rtc_stop_alarm(info);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_bulk_write(info->max77802->regmap,
> -				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
> -
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
> -				__func__, ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -	if (ret < 0)
> -		goto out;
> -
> -	if (alrm->enabled)
> -		ret = max77802_rtc_start_alarm(info);
> -out:
> -	mutex_unlock(&info->lock);
> -	return ret;
> -}
> -
> -static int max77802_rtc_alarm_irq_enable(struct device *dev,
> -					 unsigned int enabled)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	int ret;
> -
> -	mutex_lock(&info->lock);
> -	if (enabled)
> -		ret = max77802_rtc_start_alarm(info);
> -	else
> -		ret = max77802_rtc_stop_alarm(info);
> -	mutex_unlock(&info->lock);
> -
> -	return ret;
> -}
> -
> -static irqreturn_t max77802_rtc_alarm_irq(int irq, void *data)
> -{
> -	struct max77802_rtc_info *info = data;
> -
> -	dev_dbg(info->dev, "%s:irq(%d)\n", __func__, irq);
> -
> -	rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
> -
> -	return IRQ_HANDLED;
> -}
> -
> -static const struct rtc_class_ops max77802_rtc_ops = {
> -	.read_time = max77802_rtc_read_time,
> -	.set_time = max77802_rtc_set_time,
> -	.read_alarm = max77802_rtc_read_alarm,
> -	.set_alarm = max77802_rtc_set_alarm,
> -	.alarm_irq_enable = max77802_rtc_alarm_irq_enable,
> -};
> -
> -static int max77802_rtc_init_reg(struct max77802_rtc_info *info)
> -{
> -	u8 data[2];
> -	int ret;
> -
> -	max77802_rtc_update(info, MAX77802_RTC_READ);
> -
> -	/* Set RTC control register : Binary mode, 24hour mdoe */
> -	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
> -	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
> -
> -	info->rtc_24hr_mode = 1;
> -
> -	ret = regmap_bulk_write(info->max77802->regmap,
> -				MAX77802_RTC_CONTROLM, data, ARRAY_SIZE(data));
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
> -				__func__, ret);
> -		return ret;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -	return ret;
> -}
> -
> -static int max77802_rtc_probe(struct platform_device *pdev)
> -{
> -	struct max77686_dev *max77802 = dev_get_drvdata(pdev->dev.parent);
> -	struct max77802_rtc_info *info;
> -	int ret;
> -
> -	dev_dbg(&pdev->dev, "%s\n", __func__);
> -
> -	info = devm_kzalloc(&pdev->dev, sizeof(struct max77802_rtc_info),
> -			    GFP_KERNEL);
> -	if (!info)
> -		return -ENOMEM;
> -
> -	mutex_init(&info->lock);
> -	info->dev = &pdev->dev;
> -	info->max77802 = max77802;
> -	info->rtc = max77802->i2c;
> -
> -	platform_set_drvdata(pdev, info);
> -
> -	ret = max77802_rtc_init_reg(info);
> -
> -	if (ret < 0) {
> -		dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
> -		return ret;
> -	}
> -
> -	device_init_wakeup(&pdev->dev, 1);
> -
> -	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77802-rtc",
> -						 &max77802_rtc_ops, THIS_MODULE);
> -
> -	if (IS_ERR(info->rtc_dev)) {
> -		ret = PTR_ERR(info->rtc_dev);
> -		dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
> -		if (ret == 0)
> -			ret = -EINVAL;
> -		return ret;
> -	}
> -
> -	if (!max77802->rtc_irq_data) {
> -		dev_err(&pdev->dev, "No RTC regmap IRQ chip\n");
> -		return -EINVAL;
> -	}
> -
> -	info->virq = regmap_irq_get_virq(max77802->rtc_irq_data,
> -					 MAX77686_RTCIRQ_RTCA1);
> -
> -	if (info->virq <= 0) {
> -		dev_err(&pdev->dev, "Failed to get virtual IRQ %d\n",
> -			MAX77686_RTCIRQ_RTCA1);
> -		return -EINVAL;
> -	}
> -
> -	ret = devm_request_threaded_irq(&pdev->dev, info->virq, NULL,
> -					max77802_rtc_alarm_irq, 0, "rtc-alarm1",
> -					info);
> -	if (ret < 0)
> -		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
> -			info->virq, ret);
> -
> -	return ret;
> -}
> -
> -#ifdef CONFIG_PM_SLEEP
> -static int max77802_rtc_suspend(struct device *dev)
> -{
> -	if (device_may_wakeup(dev)) {
> -		struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -
> -		return enable_irq_wake(info->virq);
> -	}
> -
> -	return 0;
> -}
> -
> -static int max77802_rtc_resume(struct device *dev)
> -{
> -	if (device_may_wakeup(dev)) {
> -		struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -
> -		return disable_irq_wake(info->virq);
> -	}
> -
> -	return 0;
> -}
> -#endif
> -
> -static SIMPLE_DEV_PM_OPS(max77802_rtc_pm_ops,
> -			 max77802_rtc_suspend, max77802_rtc_resume);
> -
> -static const struct platform_device_id rtc_id[] = {
> -	{ "max77802-rtc", 0 },
> -	{},
> -};
> -MODULE_DEVICE_TABLE(platform, rtc_id);
> -
> -static struct platform_driver max77802_rtc_driver = {
> -	.driver		= {
> -		.name	= "max77802-rtc",
> -		.pm	= &max77802_rtc_pm_ops,
> -	},
> -	.probe		= max77802_rtc_probe,
> -	.id_table	= rtc_id,
> -};
> -
> -module_platform_driver(max77802_rtc_driver);
> -
> -MODULE_DESCRIPTION("Maxim MAX77802 RTC driver");
> -MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
> -MODULE_LICENSE("GPL");
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 08/10] rtc: Remove Maxim 77802 driver
@ 2016-01-27  1:22     ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  1:22 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:18PM -0300, Javier Martinez Canillas wrote:
> The max77686 RTC driver now supports the max77802 RTC as
> well so there's no need to have a separate driver anymore.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #8.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.
> 
>  drivers/rtc/Kconfig        |  10 -
>  drivers/rtc/Makefile       |   1 -
>  drivers/rtc/rtc-max77802.c | 502 ---------------------------------------------
>  3 files changed, 513 deletions(-)
>  delete mode 100644 drivers/rtc/rtc-max77802.c
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 376322f71fd5..ef456d3cf265 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -335,16 +335,6 @@ config RTC_DRV_RK808
>  	  This driver can also be built as a module. If so, the module
>  	  will be called rk808-rtc.
>  
> -config RTC_DRV_MAX77802
> -	tristate "Maxim 77802 RTC"
> -	depends on MFD_MAX77686
> -	help
> -	  If you say yes here you will get support for the
> -	  RTC of Maxim MAX77802 PMIC.
> -
> -	  This driver can also be built as a module. If so, the module
> -	  will be called rtc-max77802.
> -
>  config RTC_DRV_RS5C372
>  	tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
>  	help
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 62d61b26ca7e..ed4519efa3ca 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -86,7 +86,6 @@ obj-$(CONFIG_RTC_DRV_M48T86)	+= rtc-m48t86.o
>  obj-$(CONFIG_RTC_DRV_MAX6900)	+= rtc-max6900.o
>  obj-$(CONFIG_RTC_DRV_MAX6902)	+= rtc-max6902.o
>  obj-$(CONFIG_RTC_DRV_MAX77686)	+= rtc-max77686.o
> -obj-$(CONFIG_RTC_DRV_MAX77802)	+= rtc-max77802.o
>  obj-$(CONFIG_RTC_DRV_MAX8907)	+= rtc-max8907.o
>  obj-$(CONFIG_RTC_DRV_MAX8925)	+= rtc-max8925.o
>  obj-$(CONFIG_RTC_DRV_MAX8997)	+= rtc-max8997.o
> diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
> deleted file mode 100644
> index 82ffcc5a5345..000000000000
> --- a/drivers/rtc/rtc-max77802.c
> +++ /dev/null
> @@ -1,502 +0,0 @@
> -/*
> - * RTC driver for Maxim MAX77802
> - *
> - * Copyright (C) 2013 Google, Inc
> - *
> - * Copyright (C) 2012 Samsung Electronics Co.Ltd
> - *
> - *  based on rtc-max8997.c
> - *
> - *  This program is free software; you can redistribute  it and/or modify it
> - *  under  the terms of  the GNU General  Public License as published by the
> - *  Free Software Foundation;  either version 2 of the  License, or (at your
> - *  option) any later version.
> - *
> - */
> -
> -#include <linux/slab.h>
> -#include <linux/rtc.h>
> -#include <linux/delay.h>
> -#include <linux/mutex.h>
> -#include <linux/module.h>
> -#include <linux/platform_device.h>
> -#include <linux/mfd/max77686-private.h>
> -#include <linux/irqdomain.h>
> -#include <linux/regmap.h>
> -
> -/* RTC Control Register */
> -#define BCD_EN_SHIFT			0
> -#define BCD_EN_MASK			(1 << BCD_EN_SHIFT)
> -#define MODEL24_SHIFT			1
> -#define MODEL24_MASK			(1 << MODEL24_SHIFT)
> -/* RTC Update Register1 */
> -#define RTC_UDR_SHIFT			0
> -#define RTC_UDR_MASK			(1 << RTC_UDR_SHIFT)
> -#define RTC_RBUDR_SHIFT			4
> -#define RTC_RBUDR_MASK			(1 << RTC_RBUDR_SHIFT)
> -/* RTC Hour register */
> -#define HOUR_PM_SHIFT			6
> -#define HOUR_PM_MASK			(1 << HOUR_PM_SHIFT)
> -/* RTC Alarm Enable */
> -#define ALARM_ENABLE_SHIFT		7
> -#define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
> -
> -/* For the RTCAE1 register, we write this value to enable the alarm */
> -#define ALARM_ENABLE_VALUE		0x77
> -
> -#define MAX77802_RTC_UPDATE_DELAY_US	200
> -
> -enum {
> -	RTC_SEC = 0,
> -	RTC_MIN,
> -	RTC_HOUR,
> -	RTC_WEEKDAY,
> -	RTC_MONTH,
> -	RTC_YEAR,
> -	RTC_DATE,
> -	RTC_NR_TIME
> -};
> -
> -struct max77802_rtc_info {
> -	struct device		*dev;
> -	struct max77686_dev	*max77802;
> -	struct i2c_client	*rtc;
> -	struct rtc_device	*rtc_dev;
> -	struct mutex		lock;
> -
> -	struct regmap		*regmap;
> -
> -	int virq;
> -	int rtc_24hr_mode;
> -};
> -
> -enum MAX77802_RTC_OP {
> -	MAX77802_RTC_WRITE,
> -	MAX77802_RTC_READ,
> -};
> -
> -static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
> -				   int rtc_24hr_mode)
> -{
> -	tm->tm_sec = data[RTC_SEC] & 0xff;
> -	tm->tm_min = data[RTC_MIN] & 0xff;
> -	if (rtc_24hr_mode)
> -		tm->tm_hour = data[RTC_HOUR] & 0x1f;
> -	else {
> -		tm->tm_hour = data[RTC_HOUR] & 0x0f;
> -		if (data[RTC_HOUR] & HOUR_PM_MASK)
> -			tm->tm_hour += 12;
> -	}
> -
> -	/* Only a single bit is set in data[], so fls() would be equivalent */
> -	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0xff) - 1;
> -	tm->tm_mday = data[RTC_DATE] & 0x1f;
> -	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
> -
> -	tm->tm_year = data[RTC_YEAR] & 0xff;
> -	tm->tm_yday = 0;
> -	tm->tm_isdst = 0;
> -}
> -
> -static int max77802_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
> -{
> -	data[RTC_SEC] = tm->tm_sec;
> -	data[RTC_MIN] = tm->tm_min;
> -	data[RTC_HOUR] = tm->tm_hour;
> -	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
> -	data[RTC_DATE] = tm->tm_mday;
> -	data[RTC_MONTH] = tm->tm_mon + 1;
> -	data[RTC_YEAR] = tm->tm_year;
> -
> -	return 0;
> -}
> -
> -static int max77802_rtc_update(struct max77802_rtc_info *info,
> -	enum MAX77802_RTC_OP op)
> -{
> -	int ret;
> -	unsigned int data;
> -
> -	if (op == MAX77802_RTC_WRITE)
> -		data = 1 << RTC_UDR_SHIFT;
> -	else
> -		data = 1 << RTC_RBUDR_SHIFT;
> -
> -	ret = regmap_update_bits(info->max77802->regmap,
> -				 MAX77802_RTC_UPDATE0, data, data);
> -	if (ret < 0)
> -		dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
> -				__func__, ret, data);
> -	else {
> -		/* Minimum delay required before RTC update. */
> -		usleep_range(MAX77802_RTC_UPDATE_DELAY_US,
> -			     MAX77802_RTC_UPDATE_DELAY_US * 2);
> -	}
> -
> -	return ret;
> -}
> -
> -static int max77802_rtc_read_time(struct device *dev, struct rtc_time *tm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	int ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_bulk_read(info->max77802->regmap,
> -				MAX77802_RTC_SEC, data, RTC_NR_TIME);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,
> -			ret);
> -		goto out;
> -	}
> -
> -	max77802_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
> -
> -	ret = rtc_valid_tm(tm);
> -
> -out:
> -	mutex_unlock(&info->lock);
> -	return ret;
> -}
> -
> -static int max77802_rtc_set_time(struct device *dev, struct rtc_time *tm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	int ret;
> -
> -	ret = max77802_rtc_tm_to_data(tm, data);
> -	if (ret < 0)
> -		return ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = regmap_bulk_write(info->max77802->regmap,
> -				 MAX77802_RTC_SEC, data, RTC_NR_TIME);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
> -			ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -
> -out:
> -	mutex_unlock(&info->lock);
> -	return ret;
> -}
> -
> -static int max77802_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	unsigned int val;
> -	int ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_bulk_read(info->max77802->regmap,
> -				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
> -				__func__, __LINE__, ret);
> -		goto out;
> -	}
> -
> -	max77802_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
> -
> -	alrm->enabled = 0;
> -	ret = regmap_read(info->max77802->regmap,
> -			  MAX77802_RTC_AE1, &val);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s:%d fail to read alarm enable(%d)\n",
> -			__func__, __LINE__, ret);
> -		goto out;
> -	}
> -	if (val)
> -		alrm->enabled = 1;
> -
> -	alrm->pending = 0;
> -	ret = regmap_read(info->max77802->regmap, MAX77802_REG_STATUS2, &val);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s:%d fail to read status2 reg(%d)\n",
> -				__func__, __LINE__, ret);
> -		goto out;
> -	}
> -
> -	if (val & (1 << 2)) /* RTCA1 */
> -		alrm->pending = 1;
> -
> -out:
> -	mutex_unlock(&info->lock);
> -	return 0;
> -}
> -
> -static int max77802_rtc_stop_alarm(struct max77802_rtc_info *info)
> -{
> -	int ret;
> -
> -	if (!mutex_is_locked(&info->lock))
> -		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_write(info->max77802->regmap,
> -			   MAX77802_RTC_AE1, 0);
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
> -			__func__, ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -out:
> -	return ret;
> -}
> -
> -static int max77802_rtc_start_alarm(struct max77802_rtc_info *info)
> -{
> -	int ret;
> -
> -	if (!mutex_is_locked(&info->lock))
> -		dev_warn(info->dev, "%s: should have mutex locked\n",
> -			 __func__);
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_READ);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_write(info->max77802->regmap,
> -				   MAX77802_RTC_AE1,
> -				   ALARM_ENABLE_VALUE);
> -
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
> -				__func__, ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -out:
> -	return ret;
> -}
> -
> -static int max77802_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	u8 data[RTC_NR_TIME];
> -	int ret;
> -
> -	ret = max77802_rtc_tm_to_data(&alrm->time, data);
> -	if (ret < 0)
> -		return ret;
> -
> -	mutex_lock(&info->lock);
> -
> -	ret = max77802_rtc_stop_alarm(info);
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = regmap_bulk_write(info->max77802->regmap,
> -				 MAX77802_ALARM1_SEC, data, RTC_NR_TIME);
> -
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
> -				__func__, ret);
> -		goto out;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -	if (ret < 0)
> -		goto out;
> -
> -	if (alrm->enabled)
> -		ret = max77802_rtc_start_alarm(info);
> -out:
> -	mutex_unlock(&info->lock);
> -	return ret;
> -}
> -
> -static int max77802_rtc_alarm_irq_enable(struct device *dev,
> -					 unsigned int enabled)
> -{
> -	struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -	int ret;
> -
> -	mutex_lock(&info->lock);
> -	if (enabled)
> -		ret = max77802_rtc_start_alarm(info);
> -	else
> -		ret = max77802_rtc_stop_alarm(info);
> -	mutex_unlock(&info->lock);
> -
> -	return ret;
> -}
> -
> -static irqreturn_t max77802_rtc_alarm_irq(int irq, void *data)
> -{
> -	struct max77802_rtc_info *info = data;
> -
> -	dev_dbg(info->dev, "%s:irq(%d)\n", __func__, irq);
> -
> -	rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
> -
> -	return IRQ_HANDLED;
> -}
> -
> -static const struct rtc_class_ops max77802_rtc_ops = {
> -	.read_time = max77802_rtc_read_time,
> -	.set_time = max77802_rtc_set_time,
> -	.read_alarm = max77802_rtc_read_alarm,
> -	.set_alarm = max77802_rtc_set_alarm,
> -	.alarm_irq_enable = max77802_rtc_alarm_irq_enable,
> -};
> -
> -static int max77802_rtc_init_reg(struct max77802_rtc_info *info)
> -{
> -	u8 data[2];
> -	int ret;
> -
> -	max77802_rtc_update(info, MAX77802_RTC_READ);
> -
> -	/* Set RTC control register : Binary mode, 24hour mdoe */
> -	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
> -	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
> -
> -	info->rtc_24hr_mode = 1;
> -
> -	ret = regmap_bulk_write(info->max77802->regmap,
> -				MAX77802_RTC_CONTROLM, data, ARRAY_SIZE(data));
> -	if (ret < 0) {
> -		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
> -				__func__, ret);
> -		return ret;
> -	}
> -
> -	ret = max77802_rtc_update(info, MAX77802_RTC_WRITE);
> -	return ret;
> -}
> -
> -static int max77802_rtc_probe(struct platform_device *pdev)
> -{
> -	struct max77686_dev *max77802 = dev_get_drvdata(pdev->dev.parent);
> -	struct max77802_rtc_info *info;
> -	int ret;
> -
> -	dev_dbg(&pdev->dev, "%s\n", __func__);
> -
> -	info = devm_kzalloc(&pdev->dev, sizeof(struct max77802_rtc_info),
> -			    GFP_KERNEL);
> -	if (!info)
> -		return -ENOMEM;
> -
> -	mutex_init(&info->lock);
> -	info->dev = &pdev->dev;
> -	info->max77802 = max77802;
> -	info->rtc = max77802->i2c;
> -
> -	platform_set_drvdata(pdev, info);
> -
> -	ret = max77802_rtc_init_reg(info);
> -
> -	if (ret < 0) {
> -		dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
> -		return ret;
> -	}
> -
> -	device_init_wakeup(&pdev->dev, 1);
> -
> -	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77802-rtc",
> -						 &max77802_rtc_ops, THIS_MODULE);
> -
> -	if (IS_ERR(info->rtc_dev)) {
> -		ret = PTR_ERR(info->rtc_dev);
> -		dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
> -		if (ret == 0)
> -			ret = -EINVAL;
> -		return ret;
> -	}
> -
> -	if (!max77802->rtc_irq_data) {
> -		dev_err(&pdev->dev, "No RTC regmap IRQ chip\n");
> -		return -EINVAL;
> -	}
> -
> -	info->virq = regmap_irq_get_virq(max77802->rtc_irq_data,
> -					 MAX77686_RTCIRQ_RTCA1);
> -
> -	if (info->virq <= 0) {
> -		dev_err(&pdev->dev, "Failed to get virtual IRQ %d\n",
> -			MAX77686_RTCIRQ_RTCA1);
> -		return -EINVAL;
> -	}
> -
> -	ret = devm_request_threaded_irq(&pdev->dev, info->virq, NULL,
> -					max77802_rtc_alarm_irq, 0, "rtc-alarm1",
> -					info);
> -	if (ret < 0)
> -		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
> -			info->virq, ret);
> -
> -	return ret;
> -}
> -
> -#ifdef CONFIG_PM_SLEEP
> -static int max77802_rtc_suspend(struct device *dev)
> -{
> -	if (device_may_wakeup(dev)) {
> -		struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -
> -		return enable_irq_wake(info->virq);
> -	}
> -
> -	return 0;
> -}
> -
> -static int max77802_rtc_resume(struct device *dev)
> -{
> -	if (device_may_wakeup(dev)) {
> -		struct max77802_rtc_info *info = dev_get_drvdata(dev);
> -
> -		return disable_irq_wake(info->virq);
> -	}
> -
> -	return 0;
> -}
> -#endif
> -
> -static SIMPLE_DEV_PM_OPS(max77802_rtc_pm_ops,
> -			 max77802_rtc_suspend, max77802_rtc_resume);
> -
> -static const struct platform_device_id rtc_id[] = {
> -	{ "max77802-rtc", 0 },
> -	{},
> -};
> -MODULE_DEVICE_TABLE(platform, rtc_id);
> -
> -static struct platform_driver max77802_rtc_driver = {
> -	.driver		= {
> -		.name	= "max77802-rtc",
> -		.pm	= &max77802_rtc_pm_ops,
> -	},
> -	.probe		= max77802_rtc_probe,
> -	.id_table	= rtc_id,
> -};
> -
> -module_platform_driver(max77802_rtc_driver);
> -
> -MODULE_DESCRIPTION("Maxim MAX77802 RTC driver");
> -MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
> -MODULE_LICENSE("GPL");
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:47     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  1:47 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The driver has some hard-coded values such as the minimum delay needed
> before a RTC update or the mask used for the sec/min/hour/etc registers.
> 
> Use a data structure that contains these values and pass as driver data
> using the platform device ID table for each device.
> 
> This allows to make the driver's ops callbacks more generic so other RTC
> that are similar but don't have the same values can also be supported.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Fix max77686 delay. Suggested by Krzysztof Kozlowski.
> - Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
> - Add Laxman Dewangan's Acked-by tag to patch #4.
> 
> Changes in v2:
> - Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
> - Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
> - Change .mask type to u8. Suggested by Krzysztof Kozlowski.
> - Make .drv_data field const. Suggested by Krzysztof Kozlowski.
> - Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
> - Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.
> 
>  drivers/rtc/rtc-max77686.c | 51 ++++++++++++++++++++++++++++++----------------
>  1 file changed, 34 insertions(+), 17 deletions(-)
> 

Tested on Trats2 (max77686):
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values
@ 2016-01-27  1:47     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  1:47 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The driver has some hard-coded values such as the minimum delay needed
> before a RTC update or the mask used for the sec/min/hour/etc registers.
> 
> Use a data structure that contains these values and pass as driver data
> using the platform device ID table for each device.
> 
> This allows to make the driver's ops callbacks more generic so other RTC
> that are similar but don't have the same values can also be supported.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Fix max77686 delay. Suggested by Krzysztof Kozlowski.
> - Assign mask to u8 instead of int. Suggested by Krzysztof Kozlowski.
> - Add Laxman Dewangan's Acked-by tag to patch #4.
> 
> Changes in v2:
> - Add a max77686 prefix to rtc_driver_data. Suggested by Krzysztof Kozlowski.
> - Comment about the .delay and .mask fields. Suggested by Krzysztof Kozlowski.
> - Change .mask type to u8. Suggested by Krzysztof Kozlowski.
> - Make .drv_data field const. Suggested by Krzysztof Kozlowski.
> - Don't cast to drop const on .drv_data asign. Suggested by Krzysztof Kozlowski.
> - Use platform_get_device_id() macro. Suggested by Krzysztof Kozlowski.
> 
>  drivers/rtc/rtc-max77686.c | 51 ++++++++++++++++++++++++++++++----------------
>  1 file changed, 34 insertions(+), 17 deletions(-)
> 

Tested on Trats2 (max77686):
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 05/10] rtc: max77686: Add an indirection level to access RTC registers
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:53     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  1:53 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The max77686 driver is generic enough that can be used for other
> Maxim RTC IP blocks but these might not have the same registers
> layout so instead of accessing the registers directly, add a map
> to translate offsets to the real registers addresses for each IP.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #5.
> 
> Changes in v2:
> - Rename rtc_reg to max77686_rtc_reg_offset. Suggested by Krzysztof Kozlowski.
> - Comment what's mapped by max77686_map. Suggested by Krzysztof Kozlowski.
> - Use max77686_map array indexes in init. Suggested by Krzysztof Kozlowski.
> - Remove REG_RTC_UPDATE1 since is not used by neither max77686 nor max77802.
> 
>  drivers/rtc/rtc-max77686.c | 90 ++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 80 insertions(+), 10 deletions(-)
> 

Thanks for changes, looks good now.

Tested on Trats2 (max77686):
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 05/10] rtc: max77686: Add an indirection level to access RTC registers
@ 2016-01-27  1:53     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  1:53 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The max77686 driver is generic enough that can be used for other
> Maxim RTC IP blocks but these might not have the same registers
> layout so instead of accessing the registers directly, add a map
> to translate offsets to the real registers addresses for each IP.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #5.
> 
> Changes in v2:
> - Rename rtc_reg to max77686_rtc_reg_offset. Suggested by Krzysztof Kozlowski.
> - Comment what's mapped by max77686_map. Suggested by Krzysztof Kozlowski.
> - Use max77686_map array indexes in init. Suggested by Krzysztof Kozlowski.
> - Remove REG_RTC_UPDATE1 since is not used by neither max77686 nor max77802.
> 
>  drivers/rtc/rtc-max77686.c | 90 ++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 80 insertions(+), 10 deletions(-)
> 

Thanks for changes, looks good now.

Tested on Trats2 (max77686):
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  1:22     ` [rtc-linux] " Andi Shyti
@ 2016-01-27  1:53       ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  1:53 UTC (permalink / raw)
  To: Andi Shyti
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

Hello Andi,

Thanks a lot for your feedback and review.

On 01/26/2016 10:22 PM, Andi Shyti wrote:
> Hi Javier,
>
>>   		if (tm->tm_year < 100) {
>> -			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> -				1900 + tm->tm_year);
>> +			dev_warn(info->dev,
>> +				 "RTC can't handle year %d. Assume it's 2000\n",
>> +				 1900 + tm->tm_year);
>>   			return -EINVAL;
>
> Because we are returning an error value, why not use dev_err()?
>

You are absolutely right. Since the driver was using pr_warn(), I used
dev_warn() but dev_err() would had been correct.

If you don't mind I plan to do it as a follow up patch to avoid having
to resend the whole series only for this change.
  
Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  1:53       ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  1:53 UTC (permalink / raw)
  To: Andi Shyti
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

Hello Andi,

Thanks a lot for your feedback and review.

On 01/26/2016 10:22 PM, Andi Shyti wrote:
> Hi Javier,
>
>>   		if (tm->tm_year < 100) {
>> -			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> -				1900 + tm->tm_year);
>> +			dev_warn(info->dev,
>> +				 "RTC can't handle year %d. Assume it's 2000\n",
>> +				 1900 + tm->tm_year);
>>   			return -EINVAL;
>
> Because we are returning an error value, why not use dev_err()?
>

You are absolutely right. Since the driver was using pr_warn(), I used
dev_warn() but dev_err() would had been correct.

If you don't mind I plan to do it as a follow up patch to avoid having
to resend the whole series only for this change.
  
Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 06/10] rtc: max77686: Add max77802 support
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  1:59     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  1:59 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The MAX77686 and MAX77802 RTC IP blocks are very similar with only
> these differences:
> 
> 0) The RTC registers layout and addresses are different.
> 
> 1) The MAX77686 use 1 bit of the sec/min/hour/etc registers as the
>    alarm enable while MAX77802 has a separate register for that.
> 
> 2) The MAX77686 RTCYEAR register valid values range is 0..99 while
>    for MAX77802 is 0..199.
> 
> 3) The MAX77686 has a separate I2C address for the RTC registers
>    while the MAX77802 uses the same I2C address as the PMIC regs.
> 
> 5) The minimum delay before a RTC update (16 msecs vs 200 usecs).
> 
> There are separate drivers for MAX77686 and MAX77802 RTC IP blocks
> but the differences are not that big so the driver can be extended
> to support both instead of duplicating a lot of code in 2 drivers.
> 
> Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #6.
> 
> Changes in v2:
> - Add a MAX77802 prefix to ALARM_ENABLE_VALUE. Suggested by Krzysztof Kozlowski.
> - Rename .rtcae to .alarm_enable_reg and .rtcrm to .separate_i2c_addr.
>   Suggested by Krzysztof Kozlowski.
> - Don't use func and LINE in error messages. Suggested by Krzysztof Kozlowski.
> - Remove REG_RTC_AE2 since is not used by neither max77686 nor max77802.
> - Check if REG_RTC_AE1 has a valid address before accessing it.
> 
>  drivers/rtc/rtc-max77686.c | 208 +++++++++++++++++++++++++++++++++++----------
>  1 file changed, 162 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 1f501b6fc314..09fc73016d3a 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -1,5 +1,5 @@
>  /*
> - * RTC driver for Maxim MAX77686
> + * RTC driver for Maxim MAX77686 and MAX77802
>   *
>   * Copyright (C) 2012 Samsung Electronics Co.Ltd
>   *
> @@ -41,6 +41,15 @@
>  #define ALARM_ENABLE_SHIFT		7
>  #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
>  
> +#define REG_RTC_NONE			0xdeadbeef
> +
> +/*
> + * MAX77802 has separate register (RTCAE1) for alarm enable instead
> + * using 1 bit from registers RTC{SEC,MIN,HOUR,DAY,MONTH,YEAR,DATE}
> + * as in done in MAX77686.
> + */
> +#define MAX77802_ALARM_ENABLE_VALUE	0x77
> +
>  enum {
>  	RTC_SEC = 0,
>  	RTC_MIN,
> @@ -59,6 +68,10 @@ struct max77686_rtc_driver_data {
>  	u8			mask;
>  	/* Registers offset to I2C addresses map */
>  	const unsigned int	*map;
> +	/* Has a separate alarm enable register? */
> +	bool			alarm_enable_reg;
> +	/* Has a separate I2C regmap for the RTC? */
> +	bool			separate_i2c_addr;
>  };
>  
>  struct max77686_rtc_info {
> @@ -108,6 +121,7 @@ enum max77686_rtc_reg_offset {
>  	REG_ALARM2_MONTH,
>  	REG_ALARM2_YEAR,
>  	REG_ALARM2_DATE,
> +	REG_RTC_AE1,
>  	REG_RTC_END,
>  };
>  
> @@ -138,12 +152,52 @@ static const unsigned int max77686_map[REG_RTC_END] = {
>  	[REG_ALARM2_MONTH]   = MAX77686_ALARM2_MONTH,
>  	[REG_ALARM2_YEAR]    = MAX77686_ALARM2_YEAR,
>  	[REG_ALARM2_DATE]    = MAX77686_ALARM2_DATE,
> +	[REG_RTC_AE1]	     = REG_RTC_NONE,
>  };
>  
>  static const struct max77686_rtc_driver_data max77686_drv_data = {
>  	.delay = 16000,
>  	.mask  = 0x7f,
>  	.map   = max77686_map,
> +	.alarm_enable_reg  = false,
> +	.separate_i2c_addr = true,
> +};
> +
> +static const unsigned int max77802_map[REG_RTC_END] = {
> +	[REG_RTC_CONTROLM]   = MAX77802_RTC_CONTROLM,
> +	[REG_RTC_CONTROL]    = MAX77802_RTC_CONTROL,
> +	[REG_RTC_UPDATE0]    = MAX77802_RTC_UPDATE0,
> +	[REG_WTSR_SMPL_CNTL] = MAX77802_WTSR_SMPL_CNTL,
> +	[REG_RTC_SEC]        = MAX77802_RTC_SEC,
> +	[REG_RTC_MIN]        = MAX77802_RTC_MIN,
> +	[REG_RTC_HOUR]       = MAX77802_RTC_HOUR,
> +	[REG_RTC_WEEKDAY]    = MAX77802_RTC_WEEKDAY,
> +	[REG_RTC_MONTH]      = MAX77802_RTC_MONTH,
> +	[REG_RTC_YEAR]       = MAX77802_RTC_YEAR,
> +	[REG_RTC_DATE]       = MAX77802_RTC_DATE,
> +	[REG_ALARM1_SEC]     = MAX77802_ALARM1_SEC,
> +	[REG_ALARM1_MIN]     = MAX77802_ALARM1_MIN,
> +	[REG_ALARM1_HOUR]    = MAX77802_ALARM1_HOUR,
> +	[REG_ALARM1_WEEKDAY] = MAX77802_ALARM1_WEEKDAY,
> +	[REG_ALARM1_MONTH]   = MAX77802_ALARM1_MONTH,
> +	[REG_ALARM1_YEAR]    = MAX77802_ALARM1_YEAR,
> +	[REG_ALARM1_DATE]    = MAX77802_ALARM1_DATE,
> +	[REG_ALARM2_SEC]     = MAX77802_ALARM2_SEC,
> +	[REG_ALARM2_MIN]     = MAX77802_ALARM2_MIN,
> +	[REG_ALARM2_HOUR]    = MAX77802_ALARM2_HOUR,
> +	[REG_ALARM2_WEEKDAY] = MAX77802_ALARM2_WEEKDAY,
> +	[REG_ALARM2_MONTH]   = MAX77802_ALARM2_MONTH,
> +	[REG_ALARM2_YEAR]    = MAX77802_ALARM2_YEAR,
> +	[REG_ALARM2_DATE]    = MAX77802_ALARM2_DATE,
> +	[REG_RTC_AE1]	     = MAX77802_RTC_AE1,
> +};
> +
> +static const struct max77686_rtc_driver_data max77802_drv_data = {
> +	.delay = 200,
> +	.mask  = 0xff,
> +	.map   = max77802_map,
> +	.alarm_enable_reg  = true,
> +	.separate_i2c_addr = false,
>  };
>  
>  static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
> @@ -165,12 +219,20 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
>  	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
>  	tm->tm_mday = data[RTC_DATE] & 0x1f;
>  	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
> -	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
> +	tm->tm_year = data[RTC_YEAR] & mask;
>  	tm->tm_yday = 0;
>  	tm->tm_isdst = 0;
> +
> +	/*
> +	 * MAX77686 uses 1 bit from sec/min/hour/etc RTC registers and the
> +	 * year values are just 0..99 so add 100 to support up to 2099.
> +	 */
> +	if (!info->drv_data->alarm_enable_reg)
> +		tm->tm_year += 100;
>  }
>  
> -static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
> +static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
> +				   struct max77686_rtc_info *info)
>  {
>  	data[RTC_SEC] = tm->tm_sec;
>  	data[RTC_MIN] = tm->tm_min;
> @@ -178,13 +240,19 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
>  	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
>  	data[RTC_DATE] = tm->tm_mday;
>  	data[RTC_MONTH] = tm->tm_mon + 1;
> -	data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
>  
> -	if (tm->tm_year < 100) {
> -		pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
> -			1900 + tm->tm_year);
> -		return -EINVAL;
> +	if (!info->drv_data->alarm_enable_reg) {

I don't like all these inverted checks. They are error-prone. This is
why I propose different name. However since you want to stick to this
name of this property, then easier to read would be:

if (info->drv_data->alarm_enable_reg) {
	data[RTC_YEAR] = tm->tm_year;
} else {
	max77686-stuff...
}
Can you reverse it here and in other places?

The patch beside that is okay and works fine:

Tested on Trats2 (max77686):
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

BR,
Krzysztof

> +		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
> +
> +		if (tm->tm_year < 100) {
> +			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> +				1900 + tm->tm_year);
> +			return -EINVAL;
> +		}
> +	} else {
> +		data[RTC_YEAR] = tm->tm_year;
>  	}
> +
>  	return 0;
>  }
>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 06/10] rtc: max77686: Add max77802 support
@ 2016-01-27  1:59     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  1:59 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The MAX77686 and MAX77802 RTC IP blocks are very similar with only
> these differences:
> 
> 0) The RTC registers layout and addresses are different.
> 
> 1) The MAX77686 use 1 bit of the sec/min/hour/etc registers as the
>    alarm enable while MAX77802 has a separate register for that.
> 
> 2) The MAX77686 RTCYEAR register valid values range is 0..99 while
>    for MAX77802 is 0..199.
> 
> 3) The MAX77686 has a separate I2C address for the RTC registers
>    while the MAX77802 uses the same I2C address as the PMIC regs.
> 
> 5) The minimum delay before a RTC update (16 msecs vs 200 usecs).
> 
> There are separate drivers for MAX77686 and MAX77802 RTC IP blocks
> but the differences are not that big so the driver can be extended
> to support both instead of duplicating a lot of code in 2 drivers.
> 
> Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #6.
> 
> Changes in v2:
> - Add a MAX77802 prefix to ALARM_ENABLE_VALUE. Suggested by Krzysztof Kozlowski.
> - Rename .rtcae to .alarm_enable_reg and .rtcrm to .separate_i2c_addr.
>   Suggested by Krzysztof Kozlowski.
> - Don't use func and LINE in error messages. Suggested by Krzysztof Kozlowski.
> - Remove REG_RTC_AE2 since is not used by neither max77686 nor max77802.
> - Check if REG_RTC_AE1 has a valid address before accessing it.
> 
>  drivers/rtc/rtc-max77686.c | 208 +++++++++++++++++++++++++++++++++++----------
>  1 file changed, 162 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 1f501b6fc314..09fc73016d3a 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -1,5 +1,5 @@
>  /*
> - * RTC driver for Maxim MAX77686
> + * RTC driver for Maxim MAX77686 and MAX77802
>   *
>   * Copyright (C) 2012 Samsung Electronics Co.Ltd
>   *
> @@ -41,6 +41,15 @@
>  #define ALARM_ENABLE_SHIFT		7
>  #define ALARM_ENABLE_MASK		(1 << ALARM_ENABLE_SHIFT)
>  
> +#define REG_RTC_NONE			0xdeadbeef
> +
> +/*
> + * MAX77802 has separate register (RTCAE1) for alarm enable instead
> + * using 1 bit from registers RTC{SEC,MIN,HOUR,DAY,MONTH,YEAR,DATE}
> + * as in done in MAX77686.
> + */
> +#define MAX77802_ALARM_ENABLE_VALUE	0x77
> +
>  enum {
>  	RTC_SEC = 0,
>  	RTC_MIN,
> @@ -59,6 +68,10 @@ struct max77686_rtc_driver_data {
>  	u8			mask;
>  	/* Registers offset to I2C addresses map */
>  	const unsigned int	*map;
> +	/* Has a separate alarm enable register? */
> +	bool			alarm_enable_reg;
> +	/* Has a separate I2C regmap for the RTC? */
> +	bool			separate_i2c_addr;
>  };
>  
>  struct max77686_rtc_info {
> @@ -108,6 +121,7 @@ enum max77686_rtc_reg_offset {
>  	REG_ALARM2_MONTH,
>  	REG_ALARM2_YEAR,
>  	REG_ALARM2_DATE,
> +	REG_RTC_AE1,
>  	REG_RTC_END,
>  };
>  
> @@ -138,12 +152,52 @@ static const unsigned int max77686_map[REG_RTC_END] = {
>  	[REG_ALARM2_MONTH]   = MAX77686_ALARM2_MONTH,
>  	[REG_ALARM2_YEAR]    = MAX77686_ALARM2_YEAR,
>  	[REG_ALARM2_DATE]    = MAX77686_ALARM2_DATE,
> +	[REG_RTC_AE1]	     = REG_RTC_NONE,
>  };
>  
>  static const struct max77686_rtc_driver_data max77686_drv_data = {
>  	.delay = 16000,
>  	.mask  = 0x7f,
>  	.map   = max77686_map,
> +	.alarm_enable_reg  = false,
> +	.separate_i2c_addr = true,
> +};
> +
> +static const unsigned int max77802_map[REG_RTC_END] = {
> +	[REG_RTC_CONTROLM]   = MAX77802_RTC_CONTROLM,
> +	[REG_RTC_CONTROL]    = MAX77802_RTC_CONTROL,
> +	[REG_RTC_UPDATE0]    = MAX77802_RTC_UPDATE0,
> +	[REG_WTSR_SMPL_CNTL] = MAX77802_WTSR_SMPL_CNTL,
> +	[REG_RTC_SEC]        = MAX77802_RTC_SEC,
> +	[REG_RTC_MIN]        = MAX77802_RTC_MIN,
> +	[REG_RTC_HOUR]       = MAX77802_RTC_HOUR,
> +	[REG_RTC_WEEKDAY]    = MAX77802_RTC_WEEKDAY,
> +	[REG_RTC_MONTH]      = MAX77802_RTC_MONTH,
> +	[REG_RTC_YEAR]       = MAX77802_RTC_YEAR,
> +	[REG_RTC_DATE]       = MAX77802_RTC_DATE,
> +	[REG_ALARM1_SEC]     = MAX77802_ALARM1_SEC,
> +	[REG_ALARM1_MIN]     = MAX77802_ALARM1_MIN,
> +	[REG_ALARM1_HOUR]    = MAX77802_ALARM1_HOUR,
> +	[REG_ALARM1_WEEKDAY] = MAX77802_ALARM1_WEEKDAY,
> +	[REG_ALARM1_MONTH]   = MAX77802_ALARM1_MONTH,
> +	[REG_ALARM1_YEAR]    = MAX77802_ALARM1_YEAR,
> +	[REG_ALARM1_DATE]    = MAX77802_ALARM1_DATE,
> +	[REG_ALARM2_SEC]     = MAX77802_ALARM2_SEC,
> +	[REG_ALARM2_MIN]     = MAX77802_ALARM2_MIN,
> +	[REG_ALARM2_HOUR]    = MAX77802_ALARM2_HOUR,
> +	[REG_ALARM2_WEEKDAY] = MAX77802_ALARM2_WEEKDAY,
> +	[REG_ALARM2_MONTH]   = MAX77802_ALARM2_MONTH,
> +	[REG_ALARM2_YEAR]    = MAX77802_ALARM2_YEAR,
> +	[REG_ALARM2_DATE]    = MAX77802_ALARM2_DATE,
> +	[REG_RTC_AE1]	     = MAX77802_RTC_AE1,
> +};
> +
> +static const struct max77686_rtc_driver_data max77802_drv_data = {
> +	.delay = 200,
> +	.mask  = 0xff,
> +	.map   = max77802_map,
> +	.alarm_enable_reg  = true,
> +	.separate_i2c_addr = false,
>  };
>  
>  static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
> @@ -165,12 +219,20 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
>  	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
>  	tm->tm_mday = data[RTC_DATE] & 0x1f;
>  	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
> -	tm->tm_year = (data[RTC_YEAR] & mask) + 100;
> +	tm->tm_year = data[RTC_YEAR] & mask;
>  	tm->tm_yday = 0;
>  	tm->tm_isdst = 0;
> +
> +	/*
> +	 * MAX77686 uses 1 bit from sec/min/hour/etc RTC registers and the
> +	 * year values are just 0..99 so add 100 to support up to 2099.
> +	 */
> +	if (!info->drv_data->alarm_enable_reg)
> +		tm->tm_year += 100;
>  }
>  
> -static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
> +static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
> +				   struct max77686_rtc_info *info)
>  {
>  	data[RTC_SEC] = tm->tm_sec;
>  	data[RTC_MIN] = tm->tm_min;
> @@ -178,13 +240,19 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
>  	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
>  	data[RTC_DATE] = tm->tm_mday;
>  	data[RTC_MONTH] = tm->tm_mon + 1;
> -	data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
>  
> -	if (tm->tm_year < 100) {
> -		pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
> -			1900 + tm->tm_year);
> -		return -EINVAL;
> +	if (!info->drv_data->alarm_enable_reg) {

I don't like all these inverted checks. They are error-prone. This is
why I propose different name. However since you want to stick to this
name of this property, then easier to read would be:

if (info->drv_data->alarm_enable_reg) {
	data[RTC_YEAR] = tm->tm_year;
} else {
	max77686-stuff...
}
Can you reverse it here and in other places?

The patch beside that is okay and works fine:

Tested on Trats2 (max77686):
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

BR,
Krzysztof

> +		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
> +
> +		if (tm->tm_year < 100) {
> +			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> +				1900 + tm->tm_year);
> +			return -EINVAL;
> +		}
> +	} else {
> +		data[RTC_YEAR] = tm->tm_year;
>  	}
> +
>  	return 0;
>  }
>

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  1:53       ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  2:05         ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  2:05 UTC (permalink / raw)
  To: Javier Martinez Canillas, Andi Shyti
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Laxman Dewangan, linux-samsung-soc

On 27.01.2016 10:53, Javier Martinez Canillas wrote:
> Hello Andi,
> 
> Thanks a lot for your feedback and review.
> 
> On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> Hi Javier,
>>
>>>           if (tm->tm_year < 100) {
>>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>>> -                1900 + tm->tm_year);
>>> +            dev_warn(info->dev,
>>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>>> +                 1900 + tm->tm_year);
>>>               return -EINVAL;
>>
>> Because we are returning an error value, why not use dev_err()?
>>
> 
> You are absolutely right. Since the driver was using pr_warn(), I used
> dev_warn() but dev_err() would had been correct.

Wait. The message says that "2000 will be assumed" which is not an
error. The message indicates that driver will proceed, thus the warning.

However the driver won't proceed because the max77686_rtc_set_time()
will abort. This came from max8997 which has the same issue.

This means that either message should be changed (dev_err() without the
"assume" verb) or the function should not abort and set the year to
2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).

The easiest would be to choose #1 - no changes in the logic.

BR,
Krzysztof

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:05         ` Krzysztof Kozlowski
  0 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  2:05 UTC (permalink / raw)
  To: Javier Martinez Canillas, Andi Shyti
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Laxman Dewangan, linux-samsung-soc

On 27.01.2016 10:53, Javier Martinez Canillas wrote:
> Hello Andi,
> 
> Thanks a lot for your feedback and review.
> 
> On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> Hi Javier,
>>
>>>           if (tm->tm_year < 100) {
>>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>>> -                1900 + tm->tm_year);
>>> +            dev_warn(info->dev,
>>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>>> +                 1900 + tm->tm_year);
>>>               return -EINVAL;
>>
>> Because we are returning an error value, why not use dev_err()?
>>
> 
> You are absolutely right. Since the driver was using pr_warn(), I used
> dev_warn() but dev_err() would had been correct.

Wait. The message says that "2000 will be assumed" which is not an
error. The message indicates that driver will proceed, thus the warning.

However the driver won't proceed because the max77686_rtc_set_time()
will abort. This came from max8997 which has the same issue.

This means that either message should be changed (dev_err() without the
"assume" verb) or the function should not abort and set the year to
2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).

The easiest would be to choose #1 - no changes in the logic.

BR,
Krzysztof


-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 08/10] rtc: Remove Maxim 77802 driver
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  2:09     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  2:09 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The max77686 RTC driver now supports the max77802 RTC as
> well so there's no need to have a separate driver anymore.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #8.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.
> 
>  drivers/rtc/Kconfig        |  10 -
>  drivers/rtc/Makefile       |   1 -
>  drivers/rtc/rtc-max77802.c | 502 ---------------------------------------------
>  3 files changed, 513 deletions(-)
>  delete mode 100644 drivers/rtc/rtc-max77802.c
> 

FWIW, this also (surprise!) works on max77686:
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 08/10] rtc: Remove Maxim 77802 driver
@ 2016-01-27  2:09     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 68+ messages in thread
From: Krzysztof Kozlowski @ 2016-01-27  2:09 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

On 27.01.2016 04:20, Javier Martinez Canillas wrote:
> The max77686 RTC driver now supports the max77802 RTC as
> well so there's no need to have a separate driver anymore.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> 
> Changes in v3:
> - Add Laxman Dewangan's Acked-by tag to patch #8.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #8.
> 
>  drivers/rtc/Kconfig        |  10 -
>  drivers/rtc/Makefile       |   1 -
>  drivers/rtc/rtc-max77802.c | 502 ---------------------------------------------
>  3 files changed, 513 deletions(-)
>  delete mode 100644 drivers/rtc/rtc-max77802.c
> 

FWIW, this also (surprise!) works on max77686:
Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  1:53       ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  2:12         ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  2:12 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

> >>  		if (tm->tm_year < 100) {
> >>-			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> >>-				1900 + tm->tm_year);
> >>+			dev_warn(info->dev,
> >>+				 "RTC can't handle year %d. Assume it's 2000\n",
> >>+				 1900 + tm->tm_year);
> >>  			return -EINVAL;
> >
> >Because we are returning an error value, why not use dev_err()?
> >
> 
> You are absolutely right. Since the driver was using pr_warn(), I used
> dev_warn() but dev_err() would had been correct.
> 
> If you don't mind I plan to do it as a follow up patch to avoid having
> to resend the whole series only for this change.

Fine for me!

Andi

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:12         ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  2:12 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

> >>  		if (tm->tm_year < 100) {
> >>-			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> >>-				1900 + tm->tm_year);
> >>+			dev_warn(info->dev,
> >>+				 "RTC can't handle year %d. Assume it's 2000\n",
> >>+				 1900 + tm->tm_year);
> >>  			return -EINVAL;
> >
> >Because we are returning an error value, why not use dev_err()?
> >
> 
> You are absolutely right. Since the driver was using pr_warn(), I used
> dev_warn() but dev_err() would had been correct.
> 
> If you don't mind I plan to do it as a follow up patch to avoid having
> to resend the whole series only for this change.

Fine for me!

Andi

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  2:05         ` [rtc-linux] " Krzysztof Kozlowski
  (?)
@ 2016-01-27  2:20           ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:20 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Andi Shyti, Linux Kernel, Kukjin Kim,
	rtc-linux, Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

Hello Krzysztof,

On Tue, Jan 26, 2016 at 11:05 PM, Krzysztof Kozlowski
<k.kozlowski@samsung.com> wrote:
> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
>> Hello Andi,
>>
>> Thanks a lot for your feedback and review.
>>
>> On 01/26/2016 10:22 PM, Andi Shyti wrote:
>>> Hi Javier,
>>>
>>>>           if (tm->tm_year < 100) {
>>>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>>>> -                1900 + tm->tm_year);
>>>> +            dev_warn(info->dev,
>>>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>>>> +                 1900 + tm->tm_year);
>>>>               return -EINVAL;
>>>
>>> Because we are returning an error value, why not use dev_err()?
>>>
>>
>> You are absolutely right. Since the driver was using pr_warn(), I used
>> dev_warn() but dev_err() would had been correct.
>
> Wait. The message says that "2000 will be assumed" which is not an
> error. The message indicates that driver will proceed, thus the warning.
>
> However the driver won't proceed because the max77686_rtc_set_time()
> will abort. This came from max8997 which has the same issue.
>
> This means that either message should be changed (dev_err() without the
> "assume" verb) or the function should not abort and set the year to
> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>
> The easiest would be to choose #1 - no changes in the logic.
>

Yes, I also prefer option #1 since technically is an error to set a
year that is not supported. Quite likely the user won't want to travel
to the past :)

Since you asked me to do other changes, I'll fix it in this patch for v4.

> BR,
> Krzysztof
>
>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:20           ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:20 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Andi Shyti, Linux Kernel, Kukjin Kim,
	rtc-linux, Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

Hello Krzysztof,

On Tue, Jan 26, 2016 at 11:05 PM, Krzysztof Kozlowski
<k.kozlowski@samsung.com> wrote:
> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
>> Hello Andi,
>>
>> Thanks a lot for your feedback and review.
>>
>> On 01/26/2016 10:22 PM, Andi Shyti wrote:
>>> Hi Javier,
>>>
>>>>           if (tm->tm_year < 100) {
>>>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>>>> -                1900 + tm->tm_year);
>>>> +            dev_warn(info->dev,
>>>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>>>> +                 1900 + tm->tm_year);
>>>>               return -EINVAL;
>>>
>>> Because we are returning an error value, why not use dev_err()?
>>>
>>
>> You are absolutely right. Since the driver was using pr_warn(), I used
>> dev_warn() but dev_err() would had been correct.
>
> Wait. The message says that "2000 will be assumed" which is not an
> error. The message indicates that driver will proceed, thus the warning.
>
> However the driver won't proceed because the max77686_rtc_set_time()
> will abort. This came from max8997 which has the same issue.
>
> This means that either message should be changed (dev_err() without the
> "assume" verb) or the function should not abort and set the year to
> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>
> The easiest would be to choose #1 - no changes in the logic.
>

Yes, I also prefer option #1 since technically is an error to set a
year that is not supported. Quite likely the user won't want to travel
to the past :)

Since you asked me to do other changes, I'll fix it in this patch for v4.

> BR,
> Krzysztof
>
>

Best regards,
Javier

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:20           ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:20 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Andi Shyti, Linux Kernel, Kukjin Kim,
	rtc-linux, Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

Hello Krzysztof,

On Tue, Jan 26, 2016 at 11:05 PM, Krzysztof Kozlowski
<k.kozlowski@samsung.com> wrote:
> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
>> Hello Andi,
>>
>> Thanks a lot for your feedback and review.
>>
>> On 01/26/2016 10:22 PM, Andi Shyti wrote:
>>> Hi Javier,
>>>
>>>>           if (tm->tm_year < 100) {
>>>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>>>> -                1900 + tm->tm_year);
>>>> +            dev_warn(info->dev,
>>>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>>>> +                 1900 + tm->tm_year);
>>>>               return -EINVAL;
>>>
>>> Because we are returning an error value, why not use dev_err()?
>>>
>>
>> You are absolutely right. Since the driver was using pr_warn(), I used
>> dev_warn() but dev_err() would had been correct.
>
> Wait. The message says that "2000 will be assumed" which is not an
> error. The message indicates that driver will proceed, thus the warning.
>
> However the driver won't proceed because the max77686_rtc_set_time()
> will abort. This came from max8997 which has the same issue.
>
> This means that either message should be changed (dev_err() without the
> "assume" verb) or the function should not abort and set the year to
> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>
> The easiest would be to choose #1 - no changes in the logic.
>

Yes, I also prefer option #1 since technically is an error to set a
year that is not supported. Quite likely the user won't want to travel
to the past :)

Since you asked me to do other changes, I'll fix it in this patch for v4.

> BR,
> Krzysztof
>
>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 06/10] rtc: max77686: Add max77802 support
  2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
@ 2016-01-27  2:22     ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  2:22 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:16PM -0300, Javier Martinez Canillas wrote:
> The MAX77686 and MAX77802 RTC IP blocks are very similar with only
> these differences:
> 
> 0) The RTC registers layout and addresses are different.
> 
> 1) The MAX77686 use 1 bit of the sec/min/hour/etc registers as the
>    alarm enable while MAX77802 has a separate register for that.
> 
> 2) The MAX77686 RTCYEAR register valid values range is 0..99 while
>    for MAX77802 is 0..199.
> 
> 3) The MAX77686 has a separate I2C address for the RTC registers
>    while the MAX77802 uses the same I2C address as the PMIC regs.
> 
> 5) The minimum delay before a RTC update (16 msecs vs 200 usecs).
> 
> There are separate drivers for MAX77686 and MAX77802 RTC IP blocks
> but the differences are not that big so the driver can be extended
> to support both instead of duplicating a lot of code in 2 drivers.
> 
> Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

Just a nitpick, though.

> -static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
> +static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
> +				   struct max77686_rtc_info *info)
>  {
>  	data[RTC_SEC] = tm->tm_sec;
>  	data[RTC_MIN] = tm->tm_min;
> @@ -178,13 +240,19 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
>  	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
>  	data[RTC_DATE] = tm->tm_mday;
>  	data[RTC_MONTH] = tm->tm_mon + 1;
> -	data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
>  
> -	if (tm->tm_year < 100) {
> -		pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
> -			1900 + tm->tm_year);
> -		return -EINVAL;
> +	if (!info->drv_data->alarm_enable_reg) {
> +		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
> +
> +		if (tm->tm_year < 100) {
> +			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> +				1900 + tm->tm_year);
> +			return -EINVAL;
> +		}
> +	} else {
> +		data[RTC_YEAR] = tm->tm_year;
>  	}
> +

This can be written als as:

if (info->drv_data->alarm_enable_reg) {
	data[RTC_YEAR] = tm->tm_year;
	return 0;
}

[ ... the rest without any indentation ...]

We make also Krzysztof happy by avoiding the if (!...)

>  	return 0;
>  }

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 06/10] rtc: max77686: Add max77802 support
@ 2016-01-27  2:22     ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  2:22 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Alexandre Belloni, Krzysztof Kozlowski, Laxman Dewangan,
	linux-samsung-soc

On Tue, Jan 26, 2016 at 04:20:16PM -0300, Javier Martinez Canillas wrote:
> The MAX77686 and MAX77802 RTC IP blocks are very similar with only
> these differences:
> 
> 0) The RTC registers layout and addresses are different.
> 
> 1) The MAX77686 use 1 bit of the sec/min/hour/etc registers as the
>    alarm enable while MAX77802 has a separate register for that.
> 
> 2) The MAX77686 RTCYEAR register valid values range is 0..99 while
>    for MAX77802 is 0..199.
> 
> 3) The MAX77686 has a separate I2C address for the RTC registers
>    while the MAX77802 uses the same I2C address as the PMIC regs.
> 
> 5) The minimum delay before a RTC update (16 msecs vs 200 usecs).
> 
> There are separate drivers for MAX77686 and MAX77802 RTC IP blocks
> but the differences are not that big so the driver can be extended
> to support both instead of duplicating a lot of code in 2 drivers.
> 
> Suggested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Laxman Dewangan <ldewangan@nvidia.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

Just a nitpick, though.

> -static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
> +static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
> +				   struct max77686_rtc_info *info)
>  {
>  	data[RTC_SEC] = tm->tm_sec;
>  	data[RTC_MIN] = tm->tm_min;
> @@ -178,13 +240,19 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
>  	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
>  	data[RTC_DATE] = tm->tm_mday;
>  	data[RTC_MONTH] = tm->tm_mon + 1;
> -	data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
>  
> -	if (tm->tm_year < 100) {
> -		pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
> -			1900 + tm->tm_year);
> -		return -EINVAL;
> +	if (!info->drv_data->alarm_enable_reg) {
> +		data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
> +
> +		if (tm->tm_year < 100) {
> +			pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> +				1900 + tm->tm_year);
> +			return -EINVAL;
> +		}
> +	} else {
> +		data[RTC_YEAR] = tm->tm_year;
>  	}
> +

This can be written als as:

if (info->drv_data->alarm_enable_reg) {
	data[RTC_YEAR] = tm->tm_year;
	return 0;
}

[ ... the rest without any indentation ...]

We make also Krzysztof happy by avoiding the if (!...)

>  	return 0;
>  }

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 06/10] rtc: max77686: Add max77802 support
  2016-01-27  1:59     ` [rtc-linux] " Krzysztof Kozlowski
  (?)
@ 2016-01-27  2:24       ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:24 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Linux Kernel, Kukjin Kim, rtc-linux,
	Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

Hello Krzysztof,

On Tue, Jan 26, 2016 at 10:59 PM, Krzysztof Kozlowski
<k.kozlowski@samsung.com> wrote:
> On 27.01.2016 04:20, Javier Martinez Canillas wrote:

[snip]

>>       data[RTC_MONTH] = tm->tm_mon + 1;
>> -     data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
>>
>> -     if (tm->tm_year < 100) {
>> -             pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
>> -                     1900 + tm->tm_year);
>> -             return -EINVAL;
>> +     if (!info->drv_data->alarm_enable_reg) {
>
> I don't like all these inverted checks. They are error-prone. This is
> why I propose different name. However since you want to stick to this
> name of this property, then easier to read would be:
>
> if (info->drv_data->alarm_enable_reg) {
>         data[RTC_YEAR] = tm->tm_year;
> } else {
>         max77686-stuff...
> }
> Can you reverse it here and in other places?
>

Fair enough, I'll reverse the logic so is more natural and also do an
early return as Andi suggested.

> The patch beside that is okay and works fine:
>
> Tested on Trats2 (max77686):
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
>
> BR,
> Krzysztof
>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 06/10] rtc: max77686: Add max77802 support
@ 2016-01-27  2:24       ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:24 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Linux Kernel, Kukjin Kim, rtc-linux,
	Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

Hello Krzysztof,

On Tue, Jan 26, 2016 at 10:59 PM, Krzysztof Kozlowski
<k.kozlowski@samsung.com> wrote:
> On 27.01.2016 04:20, Javier Martinez Canillas wrote:

[snip]

>>       data[RTC_MONTH] = tm->tm_mon + 1;
>> -     data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
>>
>> -     if (tm->tm_year < 100) {
>> -             pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
>> -                     1900 + tm->tm_year);
>> -             return -EINVAL;
>> +     if (!info->drv_data->alarm_enable_reg) {
>
> I don't like all these inverted checks. They are error-prone. This is
> why I propose different name. However since you want to stick to this
> name of this property, then easier to read would be:
>
> if (info->drv_data->alarm_enable_reg) {
>         data[RTC_YEAR] = tm->tm_year;
> } else {
>         max77686-stuff...
> }
> Can you reverse it here and in other places?
>

Fair enough, I'll reverse the logic so is more natural and also do an
early return as Andi suggested.

> The patch beside that is okay and works fine:
>
> Tested on Trats2 (max77686):
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
>
> BR,
> Krzysztof
>

Best regards,
Javier

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 06/10] rtc: max77686: Add max77802 support
@ 2016-01-27  2:24       ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:24 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Linux Kernel, Kukjin Kim, rtc-linux,
	Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

Hello Krzysztof,

On Tue, Jan 26, 2016 at 10:59 PM, Krzysztof Kozlowski
<k.kozlowski@samsung.com> wrote:
> On 27.01.2016 04:20, Javier Martinez Canillas wrote:

[snip]

>>       data[RTC_MONTH] = tm->tm_mon + 1;
>> -     data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
>>
>> -     if (tm->tm_year < 100) {
>> -             pr_warn("RTC cannot handle the year %d.  Assume it's 2000.\n",
>> -                     1900 + tm->tm_year);
>> -             return -EINVAL;
>> +     if (!info->drv_data->alarm_enable_reg) {
>
> I don't like all these inverted checks. They are error-prone. This is
> why I propose different name. However since you want to stick to this
> name of this property, then easier to read would be:
>
> if (info->drv_data->alarm_enable_reg) {
>         data[RTC_YEAR] = tm->tm_year;
> } else {
>         max77686-stuff...
> }
> Can you reverse it here and in other places?
>

Fair enough, I'll reverse the logic so is more natural and also do an
early return as Andi suggested.

> The patch beside that is okay and works fine:
>
> Tested on Trats2 (max77686):
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
>
> BR,
> Krzysztof
>

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  2:05         ` [rtc-linux] " Krzysztof Kozlowski
@ 2016-01-27  2:35           ` Andi Shyti
  -1 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  2:35 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, linux-kernel, Kukjin Kim, rtc-linux,
	Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
> >> Hi Javier,
> >>
> >>>           if (tm->tm_year < 100) {
> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> >>> -                1900 + tm->tm_year);
> >>> +            dev_warn(info->dev,
> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
> >>> +                 1900 + tm->tm_year);
> >>>               return -EINVAL;
> >>
> >> Because we are returning an error value, why not use dev_err()?
> >>
> > 
> > You are absolutely right. Since the driver was using pr_warn(), I used
> > dev_warn() but dev_err() would had been correct.
> 
> Wait. The message says that "2000 will be assumed" which is not an
> error. The message indicates that driver will proceed, thus the warning.
> 
> However the driver won't proceed because the max77686_rtc_set_time()
> will abort. This came from max8997 which has the same issue.
> 
> This means that either message should be changed (dev_err() without the
> "assume" verb) or the function should not abort and set the year to
> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
> 
> The easiest would be to choose #1 - no changes in the logic.

Nevertheless, the function fails, and those who call
max77686_rtc_tm_to_data() fail as well, so, we are printing
warning, but behaving as error.

Either we print error and return error, or we print warning, we
set:

tm->tm_year = 100; /* don't know if I got the logic right */

and return 0

Right?

Thanks,
Andi

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:35           ` Andi Shyti
  0 siblings, 0 replies; 68+ messages in thread
From: Andi Shyti @ 2016-01-27  2:35 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, linux-kernel, Kukjin Kim, rtc-linux,
	Chanwoo Choi, Alexandre Belloni, Laxman Dewangan,
	linux-samsung-soc

> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
> >> Hi Javier,
> >>
> >>>           if (tm->tm_year < 100) {
> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> >>> -                1900 + tm->tm_year);
> >>> +            dev_warn(info->dev,
> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
> >>> +                 1900 + tm->tm_year);
> >>>               return -EINVAL;
> >>
> >> Because we are returning an error value, why not use dev_err()?
> >>
> > 
> > You are absolutely right. Since the driver was using pr_warn(), I used
> > dev_warn() but dev_err() would had been correct.
> 
> Wait. The message says that "2000 will be assumed" which is not an
> error. The message indicates that driver will proceed, thus the warning.
> 
> However the driver won't proceed because the max77686_rtc_set_time()
> will abort. This came from max8997 which has the same issue.
> 
> This means that either message should be changed (dev_err() without the
> "assume" verb) or the function should not abort and set the year to
> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
> 
> The easiest would be to choose #1 - no changes in the logic.

Nevertheless, the function fails, and those who call
max77686_rtc_tm_to_data() fail as well, so, we are printing
warning, but behaving as error.

Either we print error and return error, or we print warning, we
set:

tm->tm_year = 100; /* don't know if I got the logic right */

and return 0

Right?

Thanks,
Andi

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  2:35           ` [rtc-linux] " Andi Shyti
  (?)
@ 2016-01-27  2:42             ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:42 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Krzysztof Kozlowski, Javier Martinez Canillas, Linux Kernel,
	Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

Hello Andi,

On Tue, Jan 26, 2016 at 11:35 PM, Andi Shyti <andi.shyti@samsung.com> wrote:
>> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> >> Hi Javier,
>> >>
>> >>>           if (tm->tm_year < 100) {
>> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> >>> -                1900 + tm->tm_year);
>> >>> +            dev_warn(info->dev,
>> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>> >>> +                 1900 + tm->tm_year);
>> >>>               return -EINVAL;
>> >>
>> >> Because we are returning an error value, why not use dev_err()?
>> >>
>> >
>> > You are absolutely right. Since the driver was using pr_warn(), I used
>> > dev_warn() but dev_err() would had been correct.
>>
>> Wait. The message says that "2000 will be assumed" which is not an
>> error. The message indicates that driver will proceed, thus the warning.
>>
>> However the driver won't proceed because the max77686_rtc_set_time()
>> will abort. This came from max8997 which has the same issue.
>>
>> This means that either message should be changed (dev_err() without the
>> "assume" verb) or the function should not abort and set the year to
>> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>>
>> The easiest would be to choose #1 - no changes in the logic.
>
> Nevertheless, the function fails, and those who call
> max77686_rtc_tm_to_data() fail as well, so, we are printing
> warning, but behaving as error.
>
> Either we print error and return error, or we print warning, we
> set:
>
> tm->tm_year = 100; /* don't know if I got the logic right */
>
> and return 0
>
> Right?
>

I was thinking in moving the check at the start of the function so a
on error, the RTC sec/min/hour/etc registers are untouched.

> Thanks,
> Andi
> --

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:42             ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:42 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Krzysztof Kozlowski, Javier Martinez Canillas, Linux Kernel,
	Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

Hello Andi,

On Tue, Jan 26, 2016 at 11:35 PM, Andi Shyti <andi.shyti@samsung.com> wrote:
>> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> >> Hi Javier,
>> >>
>> >>>           if (tm->tm_year < 100) {
>> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> >>> -                1900 + tm->tm_year);
>> >>> +            dev_warn(info->dev,
>> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>> >>> +                 1900 + tm->tm_year);
>> >>>               return -EINVAL;
>> >>
>> >> Because we are returning an error value, why not use dev_err()?
>> >>
>> >
>> > You are absolutely right. Since the driver was using pr_warn(), I used
>> > dev_warn() but dev_err() would had been correct.
>>
>> Wait. The message says that "2000 will be assumed" which is not an
>> error. The message indicates that driver will proceed, thus the warning.
>>
>> However the driver won't proceed because the max77686_rtc_set_time()
>> will abort. This came from max8997 which has the same issue.
>>
>> This means that either message should be changed (dev_err() without the
>> "assume" verb) or the function should not abort and set the year to
>> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>>
>> The easiest would be to choose #1 - no changes in the logic.
>
> Nevertheless, the function fails, and those who call
> max77686_rtc_tm_to_data() fail as well, so, we are printing
> warning, but behaving as error.
>
> Either we print error and return error, or we print warning, we
> set:
>
> tm->tm_year = 100; /* don't know if I got the logic right */
>
> and return 0
>
> Right?
>

I was thinking in moving the check at the start of the function so a
on error, the RTC sec/min/hour/etc registers are untouched.

> Thanks,
> Andi
> --

Best regards,
Javier

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:42             ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:42 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Krzysztof Kozlowski, Javier Martinez Canillas, Linux Kernel,
	Kukjin Kim, rtc-linux, Chanwoo Choi, Alexandre Belloni,
	Laxman Dewangan, linux-samsung-soc

Hello Andi,

On Tue, Jan 26, 2016 at 11:35 PM, Andi Shyti <andi.shyti@samsung.com> wrote:
>> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> >> Hi Javier,
>> >>
>> >>>           if (tm->tm_year < 100) {
>> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> >>> -                1900 + tm->tm_year);
>> >>> +            dev_warn(info->dev,
>> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>> >>> +                 1900 + tm->tm_year);
>> >>>               return -EINVAL;
>> >>
>> >> Because we are returning an error value, why not use dev_err()?
>> >>
>> >
>> > You are absolutely right. Since the driver was using pr_warn(), I used
>> > dev_warn() but dev_err() would had been correct.
>>
>> Wait. The message says that "2000 will be assumed" which is not an
>> error. The message indicates that driver will proceed, thus the warning.
>>
>> However the driver won't proceed because the max77686_rtc_set_time()
>> will abort. This came from max8997 which has the same issue.
>>
>> This means that either message should be changed (dev_err() without the
>> "assume" verb) or the function should not abort and set the year to
>> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>>
>> The easiest would be to choose #1 - no changes in the logic.
>
> Nevertheless, the function fails, and those who call
> max77686_rtc_tm_to_data() fail as well, so, we are printing
> warning, but behaving as error.
>
> Either we print error and return error, or we print warning, we
> set:
>
> tm->tm_year = 100; /* don't know if I got the logic right */
>
> and return 0
>
> Right?
>

I was thinking in moving the check at the start of the function so a
on error, the RTC sec/min/hour/etc registers are untouched.

> Thanks,
> Andi
> --

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  2:05         ` [rtc-linux] " Krzysztof Kozlowski
@ 2016-01-27  2:46           ` Alexandre Belloni
  -1 siblings, 0 replies; 68+ messages in thread
From: Alexandre Belloni @ 2016-01-27  2:46 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Andi Shyti, linux-kernel, Kukjin Kim,
	rtc-linux, Chanwoo Choi, Laxman Dewangan, linux-samsung-soc

Hi,

On 27/01/2016 at 11:05:36 +0900, Krzysztof Kozlowski wrote :
> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
> > Hello Andi,
> > 
> > Thanks a lot for your feedback and review.
> > 
> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
> >> Hi Javier,
> >>
> >>>           if (tm->tm_year < 100) {
> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> >>> -                1900 + tm->tm_year);
> >>> +            dev_warn(info->dev,
> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
> >>> +                 1900 + tm->tm_year);
> >>>               return -EINVAL;
> >>
> >> Because we are returning an error value, why not use dev_err()?
> >>
> > 
> > You are absolutely right. Since the driver was using pr_warn(), I used
> > dev_warn() but dev_err() would had been correct.
> 
> Wait. The message says that "2000 will be assumed" which is not an
> error. The message indicates that driver will proceed, thus the warning.
> 
> However the driver won't proceed because the max77686_rtc_set_time()
> will abort. This came from max8997 which has the same issue.
> 
> This means that either message should be changed (dev_err() without the
> "assume" verb) or the function should not abort and set the year to
> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
> 
> The easiest would be to choose #1 - no changes in the logic.
> 

My stance on that is to never set a date that differs from the requested
date. Else, userspace has no way of knowing whether this is an erroneous
date or the real date when reading back.

I think I had a look and the driver is already doing the right thing but
the message is wrong.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:46           ` Alexandre Belloni
  0 siblings, 0 replies; 68+ messages in thread
From: Alexandre Belloni @ 2016-01-27  2:46 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Javier Martinez Canillas, Andi Shyti, linux-kernel, Kukjin Kim,
	rtc-linux, Chanwoo Choi, Laxman Dewangan, linux-samsung-soc

Hi,

On 27/01/2016 at 11:05:36 +0900, Krzysztof Kozlowski wrote :
> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
> > Hello Andi,
> > 
> > Thanks a lot for your feedback and review.
> > 
> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
> >> Hi Javier,
> >>
> >>>           if (tm->tm_year < 100) {
> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
> >>> -                1900 + tm->tm_year);
> >>> +            dev_warn(info->dev,
> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
> >>> +                 1900 + tm->tm_year);
> >>>               return -EINVAL;
> >>
> >> Because we are returning an error value, why not use dev_err()?
> >>
> > 
> > You are absolutely right. Since the driver was using pr_warn(), I used
> > dev_warn() but dev_err() would had been correct.
> 
> Wait. The message says that "2000 will be assumed" which is not an
> error. The message indicates that driver will proceed, thus the warning.
> 
> However the driver won't proceed because the max77686_rtc_set_time()
> will abort. This came from max8997 which has the same issue.
> 
> This means that either message should be changed (dev_err() without the
> "assume" verb) or the function should not abort and set the year to
> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
> 
> The easiest would be to choose #1 - no changes in the logic.
> 

My stance on that is to never set a date that differs from the requested
date. Else, userspace has no way of knowing whether this is an erroneous
date or the real date when reading back.

I think I had a look and the driver is already doing the right thing but
the message is wrong.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
  2016-01-27  2:46           ` [rtc-linux] " Alexandre Belloni
  (?)
@ 2016-01-27  2:50             ` Javier Martinez Canillas
  -1 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:50 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Krzysztof Kozlowski, Javier Martinez Canillas, Andi Shyti,
	Linux Kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Laxman Dewangan, linux-samsung-soc

Hello Alexandre,

On Tue, Jan 26, 2016 at 11:46 PM, Alexandre Belloni
<alexandre.belloni@free-electrons.com> wrote:
> Hi,
>
> On 27/01/2016 at 11:05:36 +0900, Krzysztof Kozlowski wrote :
>> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
>> > Hello Andi,
>> >
>> > Thanks a lot for your feedback and review.
>> >
>> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> >> Hi Javier,
>> >>
>> >>>           if (tm->tm_year < 100) {
>> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> >>> -                1900 + tm->tm_year);
>> >>> +            dev_warn(info->dev,
>> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>> >>> +                 1900 + tm->tm_year);
>> >>>               return -EINVAL;
>> >>
>> >> Because we are returning an error value, why not use dev_err()?
>> >>
>> >
>> > You are absolutely right. Since the driver was using pr_warn(), I used
>> > dev_warn() but dev_err() would had been correct.
>>
>> Wait. The message says that "2000 will be assumed" which is not an
>> error. The message indicates that driver will proceed, thus the warning.
>>
>> However the driver won't proceed because the max77686_rtc_set_time()
>> will abort. This came from max8997 which has the same issue.
>>
>> This means that either message should be changed (dev_err() without the
>> "assume" verb) or the function should not abort and set the year to
>> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>>
>> The easiest would be to choose #1 - no changes in the logic.
>>
>
> My stance on that is to never set a date that differs from the requested
> date. Else, userspace has no way of knowing whether this is an erroneous
> date or the real date when reading back.
>
> I think I had a look and the driver is already doing the right thing but
> the message is wrong.
>

That's correct.

> --
> Alexandre Belloni, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

* [rtc-linux] Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:50             ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:50 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Krzysztof Kozlowski, Javier Martinez Canillas, Andi Shyti,
	Linux Kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Laxman Dewangan, linux-samsung-soc

Hello Alexandre,

On Tue, Jan 26, 2016 at 11:46 PM, Alexandre Belloni
<alexandre.belloni@free-electrons.com> wrote:
> Hi,
>
> On 27/01/2016 at 11:05:36 +0900, Krzysztof Kozlowski wrote :
>> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
>> > Hello Andi,
>> >
>> > Thanks a lot for your feedback and review.
>> >
>> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> >> Hi Javier,
>> >>
>> >>>           if (tm->tm_year < 100) {
>> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> >>> -                1900 + tm->tm_year);
>> >>> +            dev_warn(info->dev,
>> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>> >>> +                 1900 + tm->tm_year);
>> >>>               return -EINVAL;
>> >>
>> >> Because we are returning an error value, why not use dev_err()?
>> >>
>> >
>> > You are absolutely right. Since the driver was using pr_warn(), I used
>> > dev_warn() but dev_err() would had been correct.
>>
>> Wait. The message says that "2000 will be assumed" which is not an
>> error. The message indicates that driver will proceed, thus the warning.
>>
>> However the driver won't proceed because the max77686_rtc_set_time()
>> will abort. This came from max8997 which has the same issue.
>>
>> This means that either message should be changed (dev_err() without the
>> "assume" verb) or the function should not abort and set the year to
>> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>>
>> The easiest would be to choose #1 - no changes in the logic.
>>
>
> My stance on that is to never set a date that differs from the requested
> date. Else, userspace has no way of knowing whether this is an erroneous
> date or the real date when reading back.
>
> I think I had a look and the driver is already doing the right thing but
> the message is wrong.
>

That's correct.

> --
> Alexandre Belloni, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

Best regards,
Javier

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn()
@ 2016-01-27  2:50             ` Javier Martinez Canillas
  0 siblings, 0 replies; 68+ messages in thread
From: Javier Martinez Canillas @ 2016-01-27  2:50 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Krzysztof Kozlowski, Javier Martinez Canillas, Andi Shyti,
	Linux Kernel, Kukjin Kim, rtc-linux, Chanwoo Choi,
	Laxman Dewangan, linux-samsung-soc

Hello Alexandre,

On Tue, Jan 26, 2016 at 11:46 PM, Alexandre Belloni
<alexandre.belloni@free-electrons.com> wrote:
> Hi,
>
> On 27/01/2016 at 11:05:36 +0900, Krzysztof Kozlowski wrote :
>> On 27.01.2016 10:53, Javier Martinez Canillas wrote:
>> > Hello Andi,
>> >
>> > Thanks a lot for your feedback and review.
>> >
>> > On 01/26/2016 10:22 PM, Andi Shyti wrote:
>> >> Hi Javier,
>> >>
>> >>>           if (tm->tm_year < 100) {
>> >>> -            pr_warn("RTC can't handle year %d. Assume it's 2000.\n",
>> >>> -                1900 + tm->tm_year);
>> >>> +            dev_warn(info->dev,
>> >>> +                 "RTC can't handle year %d. Assume it's 2000\n",
>> >>> +                 1900 + tm->tm_year);
>> >>>               return -EINVAL;
>> >>
>> >> Because we are returning an error value, why not use dev_err()?
>> >>
>> >
>> > You are absolutely right. Since the driver was using pr_warn(), I used
>> > dev_warn() but dev_err() would had been correct.
>>
>> Wait. The message says that "2000 will be assumed" which is not an
>> error. The message indicates that driver will proceed, thus the warning.
>>
>> However the driver won't proceed because the max77686_rtc_set_time()
>> will abort. This came from max8997 which has the same issue.
>>
>> This means that either message should be changed (dev_err() without the
>> "assume" verb) or the function should not abort and set the year to
>> 2000+something (then dev_warn()... look at rtc-ds3234.c and rtc-mcp795.c).
>>
>> The easiest would be to choose #1 - no changes in the logic.
>>
>
> My stance on that is to never set a date that differs from the requested
> date. Else, userspace has no way of knowing whether this is an erroneous
> date or the real date when reading back.
>
> I think I had a look and the driver is already doing the right thing but
> the message is wrong.
>

That's correct.

> --
> Alexandre Belloni, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

Best regards,
Javier

^ permalink raw reply	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2016-01-27  2:50 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-26 19:20 [PATCH v3 00/10] rtc: max77686: Extend driver and add max77802 support Javier Martinez Canillas
2016-01-26 19:20 ` Javier Martinez Canillas
2016-01-26 19:20 ` [rtc-linux] " Javier Martinez Canillas
2016-01-26 19:20 ` [PATCH v3 01/10] rtc: max77686: Fix max77686_rtc_read_alarm() return value Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:19   ` Andi Shyti
2016-01-27  1:19     ` [rtc-linux] " Andi Shyti
2016-01-26 19:20 ` [PATCH v3 02/10] rtc: max77686: Use ARRAY_SIZE() instead of current array length Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:20   ` Andi Shyti
2016-01-27  1:20     ` [rtc-linux] " Andi Shyti
2016-01-26 19:20 ` [PATCH v3 03/10] rtc: max77686: Use usleep_range() instead of msleep() Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:21   ` Andi Shyti
2016-01-27  1:21     ` [rtc-linux] " Andi Shyti
2016-01-26 19:20 ` [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:21   ` Andi Shyti
2016-01-27  1:21     ` [rtc-linux] " Andi Shyti
2016-01-27  1:47   ` Krzysztof Kozlowski
2016-01-27  1:47     ` [rtc-linux] " Krzysztof Kozlowski
2016-01-26 19:20 ` [PATCH v3 05/10] rtc: max77686: Add an indirection level to access RTC registers Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:53   ` Krzysztof Kozlowski
2016-01-27  1:53     ` [rtc-linux] " Krzysztof Kozlowski
2016-01-26 19:20 ` [PATCH v3 06/10] rtc: max77686: Add max77802 support Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:59   ` Krzysztof Kozlowski
2016-01-27  1:59     ` [rtc-linux] " Krzysztof Kozlowski
2016-01-27  2:24     ` Javier Martinez Canillas
2016-01-27  2:24       ` Javier Martinez Canillas
2016-01-27  2:24       ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  2:22   ` Andi Shyti
2016-01-27  2:22     ` [rtc-linux] " Andi Shyti
2016-01-26 19:20 ` [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn() Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:22   ` Andi Shyti
2016-01-27  1:22     ` [rtc-linux] " Andi Shyti
2016-01-27  1:53     ` Javier Martinez Canillas
2016-01-27  1:53       ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  2:05       ` Krzysztof Kozlowski
2016-01-27  2:05         ` [rtc-linux] " Krzysztof Kozlowski
2016-01-27  2:20         ` Javier Martinez Canillas
2016-01-27  2:20           ` Javier Martinez Canillas
2016-01-27  2:20           ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  2:35         ` Andi Shyti
2016-01-27  2:35           ` [rtc-linux] " Andi Shyti
2016-01-27  2:42           ` Javier Martinez Canillas
2016-01-27  2:42             ` Javier Martinez Canillas
2016-01-27  2:42             ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  2:46         ` Alexandre Belloni
2016-01-27  2:46           ` [rtc-linux] " Alexandre Belloni
2016-01-27  2:50           ` Javier Martinez Canillas
2016-01-27  2:50             ` Javier Martinez Canillas
2016-01-27  2:50             ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  2:12       ` Andi Shyti
2016-01-27  2:12         ` [rtc-linux] " Andi Shyti
2016-01-26 19:20 ` [PATCH v3 08/10] rtc: Remove Maxim 77802 driver Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-27  1:22   ` Andi Shyti
2016-01-27  1:22     ` [rtc-linux] " Andi Shyti
2016-01-27  2:09   ` Krzysztof Kozlowski
2016-01-27  2:09     ` [rtc-linux] " Krzysztof Kozlowski
2016-01-26 19:20 ` [PATCH v3 09/10] ARM: exynos_defconfig: Remove MAX77802 RTC Kconfig symbol Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas
2016-01-26 19:20 ` [PATCH v3 10/10] ARM: multi_v7_defconfig: " Javier Martinez Canillas
2016-01-26 19:20   ` Javier Martinez Canillas
2016-01-26 19:20   ` [rtc-linux] " Javier Martinez Canillas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.