linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] Fixed ds1390_get_reg returned value
@ 2015-09-18 15:27 Ivan Grimaldi
  2015-09-18 15:27 ` [PATCH v3 2/2] Added trickle charger device tree binding Ivan Grimaldi
  2015-09-18 22:01 ` [rtc-linux] [PATCH v3 1/2] Fixed ds1390_get_reg returned value Alexandre Belloni
  0 siblings, 2 replies; 6+ messages in thread
From: Ivan Grimaldi @ 2015-09-18 15:27 UTC (permalink / raw)
  To: a.zummo, mpfj; +Cc: rtc-linux, linux-kernel

spi_write_then_read puts in rx_buf the received data starting from
the first byte of the rx_buf

Signed-off-by: Ivan Grimaldi <grimaldi.ivan@gmail.com>
---
 drivers/rtc/rtc-ds1390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index e67bfcb..a4303b4 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -62,7 +62,7 @@ static int ds1390_get_reg(struct device *dev, unsigned char address,
 	if (status != 0)
 		return status;
 
-	*data = chip->txrx_buf[1];
+	*data = chip->txrx_buf[0];
 
 	return 0;
 }
-- 
2.5.2


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

* [PATCH v3 2/2] Added trickle charger device tree binding
  2015-09-18 15:27 [PATCH v3 1/2] Fixed ds1390_get_reg returned value Ivan Grimaldi
@ 2015-09-18 15:27 ` Ivan Grimaldi
  2015-09-18 22:01 ` [rtc-linux] [PATCH v3 1/2] Fixed ds1390_get_reg returned value Alexandre Belloni
  1 sibling, 0 replies; 6+ messages in thread
From: Ivan Grimaldi @ 2015-09-18 15:27 UTC (permalink / raw)
  To: a.zummo, mpfj; +Cc: rtc-linux, linux-kernel

Introduce a device tree binding for specifying the trickle charger
configuration for ds1339.

Signed-off-by: Ivan Grimaldi <grimaldi.ivan@gmail.com>
---
 .../devicetree/bindings/rtc/dallas,ds1390.txt      | 18 +++++++
 drivers/rtc/rtc-ds1390.c                           | 62 ++++++++++++++++++++++
 2 files changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/dallas,ds1390.txt

diff --git a/Documentation/devicetree/bindings/rtc/dallas,ds1390.txt b/Documentation/devicetree/bindings/rtc/dallas,ds1390.txt
new file mode 100644
index 0000000..8e76f26
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/dallas,ds1390.txt
@@ -0,0 +1,18 @@
+* Dallas DS1390		SPI Serial Real-Time Clock
+
+Required properties:
+- compatible: Should contain "dallas,ds1390".
+- reg: SPI address for chip
+
+Optional properties:
+- trickle-resistor-ohms : Selected resistor for trickle charger
+	Values usable for ds1390 are 250, 2000, 4000
+	Should be given if trickle charger should be enabled
+- trickle-diode-disable : Do not use internal trickle charger diode
+	Should be given if internal trickle charger diode should be disabled
+Example:
+	ds1390: rtc@68 {
+		compatible = "dallas,ds1390";
+		trickle-resistor-ohms = <250>;
+		reg = <0>;
+	};
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index a4303b4..8daebf4 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -20,6 +20,7 @@
 #include <linux/spi/spi.h>
 #include <linux/bcd.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #define DS1390_REG_100THS		0x00
 #define DS1390_REG_SECONDS		0x01
@@ -40,11 +41,31 @@
 #define DS1390_REG_STATUS		0x0E
 #define DS1390_REG_TRICKLE		0x0F
 
+#define DS1390_TRICKLE_ENABLE_CHARGER   0xA0
+#define DS1390_TRICKLE_CHARGER_250_OHM  0x01
+#define DS1390_TRICKLE_CHARGER_2K_OHM   0x02
+#define DS1390_TRICKLE_CHARGER_4K_OHM   0x03
+#define DS1390_TRICKLE_CHARGER_NO_DIODE 0x04
+#define DS1390_TRICKLE_CHARGER_DIODE    0x08
+
 struct ds1390 {
 	struct rtc_device *rtc;
 	u8 txrx_buf[9];	/* cmd + 8 registers */
 };
 
+static void ds1390_set_reg(struct device *dev, unsigned char address,
+		unsigned char data)
+{
+	struct spi_device *spi = to_spi_device(dev);
+	unsigned char buf[2];
+
+	/* MSB must be '1' to write */
+	buf[0] = address | 0x80;
+	buf[1] = data;
+
+	spi_write(spi, buf, 2);
+}
+
 static int ds1390_get_reg(struct device *dev, unsigned char address,
 				unsigned char *data)
 {
@@ -67,6 +88,44 @@ static int ds1390_get_reg(struct device *dev, unsigned char address,
 	return 0;
 }
 
+static void ds1390_trickle_of_init(struct spi_device *spi)
+{
+	uint32_t ohms = 0;
+	uint8_t value;
+
+	if (of_property_read_u32(spi->dev.of_node, "trickle-resistor-ohms", &ohms))
+		goto out;
+
+	/* Enable charger */
+	value = DS1390_TRICKLE_ENABLE_CHARGER;
+	if (of_property_read_bool(spi->dev.of_node, "trickle-diode-disable"))
+		value |= DS1390_TRICKLE_CHARGER_NO_DIODE;
+	else
+		value |= DS1390_TRICKLE_CHARGER_DIODE;
+
+	/* Resistor select */
+	switch (ohms) {
+	case 250:
+		value |= DS1390_TRICKLE_CHARGER_250_OHM;
+		break;
+	case 2000:
+		value |= DS1390_TRICKLE_CHARGER_2K_OHM;
+		break;
+	case 4000:
+		value |= DS1390_TRICKLE_CHARGER_4K_OHM;
+		break;
+	default:
+		dev_warn(&spi->dev,
+			 "Unsupported ohm value %02ux in dt\n", ohms);
+		return;
+	}
+
+	ds1390_set_reg(&spi->dev, DS1390_REG_TRICKLE, value);
+
+out:
+	return;
+}
+
 static int ds1390_read_time(struct device *dev, struct rtc_time *dt)
 {
 	struct spi_device *spi = to_spi_device(dev);
@@ -143,6 +202,9 @@ static int ds1390_probe(struct spi_device *spi)
 		return res;
 	}
 
+	if (spi->dev.of_node)
+		ds1390_trickle_of_init(spi);
+
 	chip->rtc = devm_rtc_device_register(&spi->dev, "ds1390",
 					&ds1390_rtc_ops, THIS_MODULE);
 	if (IS_ERR(chip->rtc)) {
-- 
2.5.2


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

* Re: [rtc-linux] [PATCH v3 1/2] Fixed ds1390_get_reg returned value
  2015-09-18 15:27 [PATCH v3 1/2] Fixed ds1390_get_reg returned value Ivan Grimaldi
  2015-09-18 15:27 ` [PATCH v3 2/2] Added trickle charger device tree binding Ivan Grimaldi
@ 2015-09-18 22:01 ` Alexandre Belloni
  1 sibling, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2015-09-18 22:01 UTC (permalink / raw)
  To: Ivan Grimaldi; +Cc: a.zummo, mpfj, rtc-linux, linux-kernel

Hi,

You've sent that series so many times that I'm not sure which one I
should look at...

Also, please include a changelog when submitting a new version of a
patch.

On 18/09/2015 at 17:27:56 +0200, Ivan Grimaldi wrote :
> spi_write_then_read puts in rx_buf the received data starting from
> the first byte of the rx_buf
> 
> Signed-off-by: Ivan Grimaldi <grimaldi.ivan@gmail.com>
> ---
>  drivers/rtc/rtc-ds1390.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
> index e67bfcb..a4303b4 100644
> --- a/drivers/rtc/rtc-ds1390.c
> +++ b/drivers/rtc/rtc-ds1390.c
> @@ -62,7 +62,7 @@ static int ds1390_get_reg(struct device *dev, unsigned char address,
>  	if (status != 0)
>  		return status;
>  
> -	*data = chip->txrx_buf[1];
> +	*data = chip->txrx_buf[0];
>  
>  	return 0;
>  }
> -- 
> 2.5.2
> 
> -- 
> -- 
> 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.

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

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

* Re: [PATCH v3 1/2] Fixed ds1390_get_reg returned value
  2015-09-18 15:22 Ivan Grimaldi
@ 2015-10-03 12:40 ` Alexandre Belloni
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2015-10-03 12:40 UTC (permalink / raw)
  To: Ivan Grimaldi; +Cc: a.zummo, mpfj, rtc-linux, linux-kernel

On 18/09/2015 at 17:22:38 +0200, Ivan Grimaldi wrote :
> spi_write_then_read puts in rx_buf the received data starting from
> the first byte of the rx_buf
> 
> Signed-off-by: Ivan Grimaldi <grimaldi.ivan@gmail.com>
> ---
>  drivers/rtc/rtc-ds1390.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
Applied, thanks.

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

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

* [PATCH v3 1/2] Fixed ds1390_get_reg returned value
@ 2015-09-18 15:22 Ivan Grimaldi
  2015-10-03 12:40 ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Ivan Grimaldi @ 2015-09-18 15:22 UTC (permalink / raw)
  To: a.zummo, mpfj, alexandre.belloni; +Cc: rtc-linux, linux-kernel

spi_write_then_read puts in rx_buf the received data starting from
the first byte of the rx_buf

Signed-off-by: Ivan Grimaldi <grimaldi.ivan@gmail.com>
---
 drivers/rtc/rtc-ds1390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index e67bfcb..a4303b4 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -62,7 +62,7 @@ static int ds1390_get_reg(struct device *dev, unsigned char address,
 	if (status != 0)
 		return status;
 
-	*data = chip->txrx_buf[1];
+	*data = chip->txrx_buf[0];
 
 	return 0;
 }
-- 
2.5.2


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

* [PATCH v3 1/2] Fixed ds1390_get_reg returned value
@ 2015-09-18 15:20 Ivan Grimaldi
  0 siblings, 0 replies; 6+ messages in thread
From: Ivan Grimaldi @ 2015-09-18 15:20 UTC (permalink / raw)
  To: a.zummo, mpfj, alexandre.belloni; +Cc: rtc-linux, linux-kernel

spi_write_then_read puts in rx_buf the received data starting from
the first byte of the rx_buf

Signed-off-by: Ivan Grimaldi <grimaldi.ivan@gmail.com>
---
 drivers/rtc/rtc-ds1390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index e67bfcb..a4303b4 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -62,7 +62,7 @@ static int ds1390_get_reg(struct device *dev, unsigned char address,
 	if (status != 0)
 		return status;
 
-	*data = chip->txrx_buf[1];
+	*data = chip->txrx_buf[0];
 
 	return 0;
 }
-- 
2.5.2


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

end of thread, other threads:[~2015-10-03 12:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-18 15:27 [PATCH v3 1/2] Fixed ds1390_get_reg returned value Ivan Grimaldi
2015-09-18 15:27 ` [PATCH v3 2/2] Added trickle charger device tree binding Ivan Grimaldi
2015-09-18 22:01 ` [rtc-linux] [PATCH v3 1/2] Fixed ds1390_get_reg returned value Alexandre Belloni
  -- strict thread matches above, loose matches on Subject: below --
2015-09-18 15:22 Ivan Grimaldi
2015-10-03 12:40 ` Alexandre Belloni
2015-09-18 15:20 Ivan Grimaldi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).