All of lore.kernel.org
 help / color / mirror / Atom feed
* [rtc-linux] [PATCH 1/2] rtc: rv3029: Add update_bits helper for eeprom access
       [not found] <20160310183346.73aa0f24@wiggum>
@ 2016-03-10 17:34 ` Michael Büsch
  2016-03-14 15:36   ` [rtc-linux] " Alexandre Belloni
  2016-03-10 17:34 ` [rtc-linux] [PATCH 2/2] rtc: rv3029: Add thermometer hwmon support Michael Büsch
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Büsch @ 2016-03-10 17:34 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Gregory Hermant, rtc-linux

[-- Attachment #1: Type: text/plain, Size: 2859 bytes --]

This simplifies the update of single bits in the eeprom.

Signed-off-by: Michael Buesch <m@bues.ch>
---
 drivers/rtc/rtc-rv3029c2.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index b416ed0..3bbb581 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -308,6 +308,24 @@ static int rv3029_eeprom_write(struct i2c_client *client, u8 reg,
 	return ret;
 }
 
+static int rv3029_eeprom_update_bits(struct i2c_client *client,
+				     u8 reg, u8 mask, u8 set)
+{
+	u8 buf;
+	int ret;
+
+	ret = rv3029_eeprom_read(client, reg, &buf, 1);
+	if (ret < 0)
+		return ret;
+	buf &= ~mask;
+	buf |= set & mask;
+	ret = rv3029_eeprom_write(client, reg, &buf, 1);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static int
 rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
 {
@@ -588,23 +606,16 @@ static void rv3029_trickle_config(struct i2c_client *client)
 	const struct rv3029_trickle_tab_elem *elem;
 	int i, err;
 	u32 ohms;
-	u8 eectrl;
+	u8 trickle_set_bits;
 
 	if (!of_node)
 		return;
 
 	/* Configure the trickle charger. */
-	err = rv3029_eeprom_read(client, RV3029_CONTROL_E2P_EECTRL,
-				 &eectrl, 1);
-	if (err < 0) {
-		dev_err(&client->dev,
-			"Failed to read trickle charger config\n");
-		return;
-	}
 	err = of_property_read_u32(of_node, "trickle-resistor-ohms", &ohms);
 	if (err) {
 		/* Disable trickle charger. */
-		eectrl &= ~RV3029_TRICKLE_MASK;
+		trickle_set_bits = 0;
 	} else {
 		/* Enable trickle charger. */
 		for (i = 0; i < ARRAY_SIZE(rv3029_trickle_tab); i++) {
@@ -612,17 +623,17 @@ static void rv3029_trickle_config(struct i2c_client *client)
 			if (elem->r >= ohms)
 				break;
 		}
-		eectrl &= ~RV3029_TRICKLE_MASK;
-		eectrl |= elem->conf;
+		trickle_set_bits = elem->conf;
 		dev_info(&client->dev,
 			 "Trickle charger enabled at %d ohms resistance.\n",
 			 elem->r);
 	}
-	err = rv3029_eeprom_write(client, RV3029_CONTROL_E2P_EECTRL,
-				  &eectrl, 1);
+	err = rv3029_eeprom_update_bits(client, RV3029_CONTROL_E2P_EECTRL,
+					RV3029_TRICKLE_MASK,
+					trickle_set_bits);
 	if (err < 0) {
 		dev_err(&client->dev,
-			"Failed to write trickle charger config\n");
+			"Failed to update trickle charger config\n");
 	}
 }
 
-- 
2.7.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.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* [rtc-linux] [PATCH 2/2] rtc: rv3029: Add thermometer hwmon support
       [not found] <20160310183346.73aa0f24@wiggum>
  2016-03-10 17:34 ` [rtc-linux] [PATCH 1/2] rtc: rv3029: Add update_bits helper for eeprom access Michael Büsch
@ 2016-03-10 17:34 ` Michael Büsch
  2016-03-14 15:36   ` [rtc-linux] " Alexandre Belloni
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Büsch @ 2016-03-10 17:34 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Gregory Hermant, rtc-linux

[-- Attachment #1: Type: text/plain, Size: 5072 bytes --]

This adds support to
- enable/disable the thermometer
- set the temperature scanning interval
- read the current temperature that is used for temp compensation.
via hwmon interface

Signed-off-by: Michael Buesch <m@bues.ch>
---
 drivers/rtc/Kconfig        |   9 ++++
 drivers/rtc/rtc-rv3029c2.c | 120 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e593c55..b4fda4c 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -601,6 +601,15 @@ config RTC_DRV_RV3029C2
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-rv3029c2.
 
+config RTC_DRV_RV3029_HWMON
+	bool "HWMON support for RV3029"
+	depends on RTC_DRV_RV3029C2 && HWMON
+	depends on !(RTC_DRV_RV3029C2=y && HWMON=m)
+	default y
+	help
+	  Say Y here if you want to expose temperature sensor data on
+	  rtc-rv3029c2.
+
 config RTC_DRV_RV8803
 	tristate "Micro Crystal RV8803"
 	help
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index 3bbb581..d0cbf08 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -18,6 +18,8 @@
 #include <linux/rtc.h>
 #include <linux/delay.h>
 #include <linux/of.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 
 
 /* Register map */
@@ -637,6 +639,123 @@ static void rv3029_trickle_config(struct i2c_client *client)
 	}
 }
 
+#ifdef CONFIG_RTC_DRV_RV3029_HWMON
+
+static int rv3029_read_temp(struct i2c_client *client, int *temp_mC)
+{
+	int ret;
+	u8 temp;
+
+	ret = rv3029_i2c_read_regs(client, RV3029_TEMP_PAGE, &temp, 1);
+	if (ret < 0)
+		return ret;
+
+	*temp_mC = ((int)temp - 60) * 1000;
+
+	return 0;
+}
+
+static ssize_t rv3029_hwmon_show_temp(struct device *dev,
+				      struct device_attribute *attr,
+				      char *buf)
+{
+	struct i2c_client *client = dev_get_drvdata(dev);
+	int ret, temp_mC;
+
+	ret = rv3029_read_temp(client, &temp_mC);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%d\n", temp_mC);
+}
+
+static ssize_t rv3029_hwmon_set_update_interval(struct device *dev,
+						struct device_attribute *attr,
+						const char *buf,
+						size_t count)
+{
+	struct i2c_client *client = dev_get_drvdata(dev);
+	unsigned long interval_ms;
+	int ret;
+	u8 th_set_bits = 0;
+
+	ret = kstrtoul(buf, 10, &interval_ms);
+	if (ret < 0)
+		return ret;
+
+	if (interval_ms != 0) {
+		th_set_bits |= RV3029_EECTRL_THE;
+		if (interval_ms >= 16000)
+			th_set_bits |= RV3029_EECTRL_THP;
+	}
+	ret = rv3029_eeprom_update_bits(client, RV3029_CONTROL_E2P_EECTRL,
+					RV3029_EECTRL_THE | RV3029_EECTRL_THP,
+					th_set_bits);
+	if (ret < 0)
+		return ret;
+
+	return count;
+}
+
+static ssize_t rv3029_hwmon_show_update_interval(struct device *dev,
+						 struct device_attribute *attr,
+						 char *buf)
+{
+	struct i2c_client *client = dev_get_drvdata(dev);
+	int ret, interval_ms;
+	u8 eectrl;
+
+	ret = rv3029_eeprom_read(client, RV3029_CONTROL_E2P_EECTRL,
+				 &eectrl, 1);
+	if (ret < 0)
+		return ret;
+
+	if (eectrl & RV3029_EECTRL_THE) {
+		if (eectrl & RV3029_EECTRL_THP)
+			interval_ms = 16000;
+		else
+			interval_ms = 1000;
+	} else {
+		interval_ms = 0;
+	}
+
+	return sprintf(buf, "%d\n", interval_ms);
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, rv3029_hwmon_show_temp,
+			  NULL, 0);
+static SENSOR_DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO,
+			  rv3029_hwmon_show_update_interval,
+			  rv3029_hwmon_set_update_interval, 0);
+
+static struct attribute *rv3029_hwmon_attrs[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_update_interval.dev_attr.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(rv3029_hwmon);
+
+static void rv3029_hwmon_register(struct i2c_client *client)
+{
+	struct device *hwmon_dev;
+
+	hwmon_dev = devm_hwmon_device_register_with_groups(
+		&client->dev, client->name, client, rv3029_hwmon_groups);
+	if (IS_ERR(hwmon_dev)) {
+		dev_warn(&client->dev,
+			"unable to register hwmon device %ld\n",
+			PTR_ERR(hwmon_dev));
+	}
+}
+
+#else /* CONFIG_RTC_DRV_RV3029_HWMON */
+
+static void rv3029_hwmon_register(struct i2c_client *client)
+{
+}
+
+#endif /* CONFIG_RTC_DRV_RV3029_HWMON */
+
 static const struct rtc_class_ops rv3029_rtc_ops = {
 	.read_time	= rv3029_rtc_read_time,
 	.set_time	= rv3029_rtc_set_time,
@@ -668,6 +787,7 @@ static int rv3029_probe(struct i2c_client *client,
 	}
 
 	rv3029_trickle_config(client);
+	rv3029_hwmon_register(client);
 
 	rtc = devm_rtc_device_register(&client->dev, client->name,
 				       &rv3029_rtc_ops, THIS_MODULE);
-- 
2.7.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.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* [rtc-linux] Re: [PATCH 1/2] rtc: rv3029: Add update_bits helper for eeprom access
  2016-03-10 17:34 ` [rtc-linux] [PATCH 1/2] rtc: rv3029: Add update_bits helper for eeprom access Michael Büsch
@ 2016-03-14 15:36   ` Alexandre Belloni
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2016-03-14 15:36 UTC (permalink / raw)
  To: Michael Büsch; +Cc: Gregory Hermant, rtc-linux

On 10/03/2016 at 18:34:23 +0100, Michael B=C3=BCsch wrote :
> This simplifies the update of single bits in the eeprom.
>=20
> Signed-off-by: Michael Buesch <m@bues.ch>
> ---
>  drivers/rtc/rtc-rv3029c2.c | 39 +++++++++++++++++++++++++--------------
>  1 file changed, 25 insertions(+), 14 deletions(-)
Applied, thanks.

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

--=20
--=20
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.
---=20
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 e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

* [rtc-linux] Re: [PATCH 2/2] rtc: rv3029: Add thermometer hwmon support
  2016-03-10 17:34 ` [rtc-linux] [PATCH 2/2] rtc: rv3029: Add thermometer hwmon support Michael Büsch
@ 2016-03-14 15:36   ` Alexandre Belloni
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2016-03-14 15:36 UTC (permalink / raw)
  To: Michael Büsch; +Cc: Gregory Hermant, rtc-linux

On 10/03/2016 at 18:34:46 +0100, Michael B=C3=BCsch wrote :
> This adds support to
> - enable/disable the thermometer
> - set the temperature scanning interval
> - read the current temperature that is used for temp compensation.
> via hwmon interface
>=20
> Signed-off-by: Michael Buesch <m@bues.ch>
> ---
>  drivers/rtc/Kconfig        |   9 ++++
>  drivers/rtc/rtc-rv3029c2.c | 120 +++++++++++++++++++++++++++++++++++++++=
++++++
>  2 files changed, 129 insertions(+)
>=20
Applied, thanks.

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

--=20
--=20
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.
---=20
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 e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

end of thread, other threads:[~2016-03-14 15:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20160310183346.73aa0f24@wiggum>
2016-03-10 17:34 ` [rtc-linux] [PATCH 1/2] rtc: rv3029: Add update_bits helper for eeprom access Michael Büsch
2016-03-14 15:36   ` [rtc-linux] " Alexandre Belloni
2016-03-10 17:34 ` [rtc-linux] [PATCH 2/2] rtc: rv3029: Add thermometer hwmon support Michael Büsch
2016-03-14 15:36   ` [rtc-linux] " Alexandre Belloni

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.