[PATCH v1] DMA:omap-dma:Avoid build error by changing the function name

2017-12-11 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

Change the name of the function omap_dma_filter_fn to avoid
the following build error in linux kernel version 4.4 :

drivers/dma/dma-omap.c:1273:6: error:
redefinition of 'omap_dma_filter_fn'

Signed-off-by: Venkat Prashanth B U 
Changes for v1:
- Edited subject and description of the patch to fit with the change
  done in the code base, as suggested by Vinod Koul.

- In order to avoid  issues like backporting on stable the
  checkpatch.pl issues are dropped as suggested by Vinod Koul.
---
 drivers/dma/omap-dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/omap-dma.c b/drivers/dma/omap-dma.c
index 1dfc71c..8545dda 100644
--- a/drivers/dma/omap-dma.c
+++ b/drivers/dma/omap-dma.c
@@ -1269,7 +1269,7 @@ static struct platform_driver omap_dma_driver = {
},
 };
 
-bool omap_dma_filter_fn(struct dma_chan *chan, void *param)
+bool omap_dma_filter_func(struct dma_chan *chan, void *param)
 {
if (chan->device->dev->driver == _dma_driver.driver) {
struct omap_dmadev *od = to_omap_dma_dev(chan->device);
-- 
1.9.1


[PATCH v1] DMA:omap-dma:Avoid build error by changing the function name

2017-12-11 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

Change the name of the function omap_dma_filter_fn to avoid
the following build error in linux kernel version 4.4 :

drivers/dma/dma-omap.c:1273:6: error:
redefinition of 'omap_dma_filter_fn'

Signed-off-by: Venkat Prashanth B U 
Changes for v1:
- Edited subject and description of the patch to fit with the change
  done in the code base, as suggested by Vinod Koul.

- In order to avoid  issues like backporting on stable the
  checkpatch.pl issues are dropped as suggested by Vinod Koul.
---
 drivers/dma/omap-dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/omap-dma.c b/drivers/dma/omap-dma.c
index 1dfc71c..8545dda 100644
--- a/drivers/dma/omap-dma.c
+++ b/drivers/dma/omap-dma.c
@@ -1269,7 +1269,7 @@ static struct platform_driver omap_dma_driver = {
},
 };
 
-bool omap_dma_filter_fn(struct dma_chan *chan, void *param)
+bool omap_dma_filter_func(struct dma_chan *chan, void *param)
 {
if (chan->device->dev->driver == _dma_driver.driver) {
struct omap_dmadev *od = to_omap_dma_dev(chan->device);
-- 
1.9.1


[PATCH] DMA:omap-dma: Fix kernel compilation error and checkpatch issues

2017-12-11 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

This is the patch to the omap-dma.c file that fixes
the following issues:

1.redefinition of 'omap_dma_filter_fn' in the line 1273
of drivers/dma/omap-dma.c

2.drivers/dma/omap-dma.c:341: ERROR: code indent should
use tabs where possible reported by ./checkpatch.pl

3.drivers/dma/omap-dma.c:749: WARNING: Missing a blank
line after declarations reported by ./checkpatch.pl

Signed-off-by: Venkat Prashanth B U 
---
 drivers/dma/omap-dma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/omap-dma.c b/drivers/dma/omap-dma.c
index 1dfc71c..2a40485 100644
--- a/drivers/dma/omap-dma.c
+++ b/drivers/dma/omap-dma.c
@@ -338,7 +338,7 @@ static void omap_dma_stop(struct omap_chan *c)
if (val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE))
dev_err(c->vc.chan.device->dev,
"DMA drain did not complete on lch %d\n",
-   c->dma_ch);
+   c->dma_ch);
 
omap_dma_glbl_write(od, OCP_SYSCONFIG, sysconfig);
} else {
@@ -746,6 +746,7 @@ static void omap_dma_issue_pending(struct dma_chan *chan)
 */
if (!c->cyclic) {
struct omap_dmadev *d = to_omap_dma_dev(chan->device);
+
spin_lock(>lock);
if (list_empty(>node))
list_add_tail(>node, >pending);
@@ -1269,7 +1270,7 @@ static struct platform_driver omap_dma_driver = {
},
 };
 
-bool omap_dma_filter_fn(struct dma_chan *chan, void *param)
+bool omap_dma_filter_func(struct dma_chan *chan, void *param)
 {
if (chan->device->dev->driver == _dma_driver.driver) {
struct omap_dmadev *od = to_omap_dma_dev(chan->device);
-- 
1.9.1



[PATCH] DMA:omap-dma: Fix kernel compilation error and checkpatch issues

2017-12-11 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

This is the patch to the omap-dma.c file that fixes
the following issues:

1.redefinition of 'omap_dma_filter_fn' in the line 1273
of drivers/dma/omap-dma.c

2.drivers/dma/omap-dma.c:341: ERROR: code indent should
use tabs where possible reported by ./checkpatch.pl

3.drivers/dma/omap-dma.c:749: WARNING: Missing a blank
line after declarations reported by ./checkpatch.pl

Signed-off-by: Venkat Prashanth B U 
---
 drivers/dma/omap-dma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/omap-dma.c b/drivers/dma/omap-dma.c
index 1dfc71c..2a40485 100644
--- a/drivers/dma/omap-dma.c
+++ b/drivers/dma/omap-dma.c
@@ -338,7 +338,7 @@ static void omap_dma_stop(struct omap_chan *c)
if (val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE))
dev_err(c->vc.chan.device->dev,
"DMA drain did not complete on lch %d\n",
-   c->dma_ch);
+   c->dma_ch);
 
omap_dma_glbl_write(od, OCP_SYSCONFIG, sysconfig);
} else {
@@ -746,6 +746,7 @@ static void omap_dma_issue_pending(struct dma_chan *chan)
 */
if (!c->cyclic) {
struct omap_dmadev *d = to_omap_dma_dev(chan->device);
+
spin_lock(>lock);
if (list_empty(>node))
list_add_tail(>node, >pending);
@@ -1269,7 +1270,7 @@ static struct platform_driver omap_dma_driver = {
},
 };
 
-bool omap_dma_filter_fn(struct dma_chan *chan, void *param)
+bool omap_dma_filter_func(struct dma_chan *chan, void *param)
 {
if (chan->device->dev->driver == _dma_driver.driver) {
struct omap_dmadev *od = to_omap_dma_dev(chan->device);
-- 
1.9.1



[PATCH] rtc: rtc-ds1683 Maxim/Dallas I2C compatible

2017-11-29 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

This is a patch to add support for
maxim/dallas I2C rtc ds1683 chip.

Signed-off-by: Venkat Prashanth B U 
---
 drivers/rtc/Kconfig  |   9 +++
 drivers/rtc/Makefile |   1 +
 drivers/rtc/rtc-ds1683.c | 203 +++
 3 files changed, 213 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e0e58f3..2528b79 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -294,6 +294,15 @@ config RTC_DRV_DS1672
  This driver can also be built as a module. If so, the module
  will be called rtc-ds1672.

+config RTC_DRV_DS1683
+   tristate "Dallas/Maxim DS1683"
+   help
+ If you say yes here you get support for the
+ Dallas/Maxim DS1683 I2C timekeeping chip.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-ds1683.
+
 config RTC_DRV_HYM8563
tristate "Haoyu Microelectronics HYM8563"
depends on OF
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0bf1fc0..a6f4419 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_RTC_DRV_DS1390)  += rtc-ds1390.o
 obj-$(CONFIG_RTC_DRV_DS1511)   += rtc-ds1511.o
 obj-$(CONFIG_RTC_DRV_DS1553)   += rtc-ds1553.o
 obj-$(CONFIG_RTC_DRV_DS1672)   += rtc-ds1672.o
+obj-$(CONFIG_RTC_DRV_DS1683)   += rtc-ds1683.o
 obj-$(CONFIG_RTC_DRV_DS1685_FAMILY)+= rtc-ds1685.o
 obj-$(CONFIG_RTC_DRV_DS1742)   += rtc-ds1742.o
 obj-$(CONFIG_RTC_DRV_DS2404)   += rtc-ds2404.o
diff --git a/drivers/rtc/rtc-ds1683.c b/drivers/rtc/rtc-ds1683.c
index e69de29..7b6dac3 100644
--- a/drivers/rtc/rtc-ds1683.c
+++ b/drivers/rtc/rtc-ds1683.c
@@ -0,0 +1,203 @@
+/* rtc-ds1683.c
+ *
+ * Driver for Maxim/Dallas ds1683, I2C Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+/* Registers */
+
+#define ds1683_REG_CNT_BASE0
+#define ds1683_REG_EVENT   4
+
+#define ds1683_REG_CONTROL_EOSC0x80
+
+static struct i2c_driver ds1683_driver;
+
+static int ds1683_get_datetime(struct i2c_client *client, struct rtc_time *tm)
+{
+   unsigned long time;
+   unsigned char addr = ds1683_REG_CNT_BASE;
+   unsigned char buf[4];
+
+   struct i2c_msg msgs[] = {
+   {   /* setup read pointer */
+   .addr = client->addr,
+   .len = 1,
+   .buf = 
+   },
+   {/* read date */
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = 4,
+   .buf = buf
+   },
+   };
+
+   /* read date registers */
+   if ((i2c_transfer(client->adapter, [0], 2)) != 2) {
+   dev_err(>dev, "%s: read error\n", __func__);
+   return -EIO;
+   }
+
+   time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+
+   rtc_time_to_tm(time, tm);
+
+   return 0;
+}
+
+static int ds1683_set_mmss(struct i2c_client *client, unsigned long secs)
+{
+   int xfer;
+   unsigned char buf[6];
+
+   buf[0] = ds1683_REG_CNT_BASE;
+   buf[1] = secs & 0x00FF;
+   buf[2] = (secs & 0xFF00) >> 8;
+   buf[3] = (secs & 0x00FF) >> 16;
+   buf[4] = (secs & 0xFF00) >> 24;
+   buf[5] = 0; /* set control reg to enable counting */
+
+   xfer = i2c_master_send(client, buf, 6);
+   if (xfer != 6) {
+   dev_err(>dev, "%s: send: %d\n", __func__, xfer);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int ds1683_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   return ds1683_get_datetime(to_i2c_client(dev), tm);
+}
+
+static int ds1683_rtc_set_mmss(struct device *dev, unsigned long secs)
+{
+   return ds1683_set_mmss(to_i2c_client(dev), secs);
+}
+
+static int ds1683_get_control(struct i2c_client *client, u8 *status)
+{
+   unsigned char addr = ds1683_REG_CONTROL;
+
+   struct i2c_msg msgs[] = {
+   {/* setup read pointer */
+   .addr = client->addr,
+   .len = 1,
+   .buf = 
+   },
+   {/* read control */
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = 1,
+   .buf = status
+   },
+   };
+
+   /* read control register */
+   if ((i2c_transfer(client->adapter, [0], 2)) != 2) {
+   dev_err(>dev, "%s: read error\n", __func__);
+   return -EIO;
+   }
+
+   return 

[PATCH] rtc: rtc-ds1683 Maxim/Dallas I2C compatible

2017-11-29 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

This is a patch to add support for
maxim/dallas I2C rtc ds1683 chip.

Signed-off-by: Venkat Prashanth B U 
---
 drivers/rtc/Kconfig  |   9 +++
 drivers/rtc/Makefile |   1 +
 drivers/rtc/rtc-ds1683.c | 203 +++
 3 files changed, 213 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e0e58f3..2528b79 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -294,6 +294,15 @@ config RTC_DRV_DS1672
  This driver can also be built as a module. If so, the module
  will be called rtc-ds1672.

+config RTC_DRV_DS1683
+   tristate "Dallas/Maxim DS1683"
+   help
+ If you say yes here you get support for the
+ Dallas/Maxim DS1683 I2C timekeeping chip.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-ds1683.
+
 config RTC_DRV_HYM8563
tristate "Haoyu Microelectronics HYM8563"
depends on OF
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0bf1fc0..a6f4419 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_RTC_DRV_DS1390)  += rtc-ds1390.o
 obj-$(CONFIG_RTC_DRV_DS1511)   += rtc-ds1511.o
 obj-$(CONFIG_RTC_DRV_DS1553)   += rtc-ds1553.o
 obj-$(CONFIG_RTC_DRV_DS1672)   += rtc-ds1672.o
+obj-$(CONFIG_RTC_DRV_DS1683)   += rtc-ds1683.o
 obj-$(CONFIG_RTC_DRV_DS1685_FAMILY)+= rtc-ds1685.o
 obj-$(CONFIG_RTC_DRV_DS1742)   += rtc-ds1742.o
 obj-$(CONFIG_RTC_DRV_DS2404)   += rtc-ds2404.o
diff --git a/drivers/rtc/rtc-ds1683.c b/drivers/rtc/rtc-ds1683.c
index e69de29..7b6dac3 100644
--- a/drivers/rtc/rtc-ds1683.c
+++ b/drivers/rtc/rtc-ds1683.c
@@ -0,0 +1,203 @@
+/* rtc-ds1683.c
+ *
+ * Driver for Maxim/Dallas ds1683, I2C Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+/* Registers */
+
+#define ds1683_REG_CNT_BASE0
+#define ds1683_REG_EVENT   4
+
+#define ds1683_REG_CONTROL_EOSC0x80
+
+static struct i2c_driver ds1683_driver;
+
+static int ds1683_get_datetime(struct i2c_client *client, struct rtc_time *tm)
+{
+   unsigned long time;
+   unsigned char addr = ds1683_REG_CNT_BASE;
+   unsigned char buf[4];
+
+   struct i2c_msg msgs[] = {
+   {   /* setup read pointer */
+   .addr = client->addr,
+   .len = 1,
+   .buf = 
+   },
+   {/* read date */
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = 4,
+   .buf = buf
+   },
+   };
+
+   /* read date registers */
+   if ((i2c_transfer(client->adapter, [0], 2)) != 2) {
+   dev_err(>dev, "%s: read error\n", __func__);
+   return -EIO;
+   }
+
+   time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+
+   rtc_time_to_tm(time, tm);
+
+   return 0;
+}
+
+static int ds1683_set_mmss(struct i2c_client *client, unsigned long secs)
+{
+   int xfer;
+   unsigned char buf[6];
+
+   buf[0] = ds1683_REG_CNT_BASE;
+   buf[1] = secs & 0x00FF;
+   buf[2] = (secs & 0xFF00) >> 8;
+   buf[3] = (secs & 0x00FF) >> 16;
+   buf[4] = (secs & 0xFF00) >> 24;
+   buf[5] = 0; /* set control reg to enable counting */
+
+   xfer = i2c_master_send(client, buf, 6);
+   if (xfer != 6) {
+   dev_err(>dev, "%s: send: %d\n", __func__, xfer);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int ds1683_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   return ds1683_get_datetime(to_i2c_client(dev), tm);
+}
+
+static int ds1683_rtc_set_mmss(struct device *dev, unsigned long secs)
+{
+   return ds1683_set_mmss(to_i2c_client(dev), secs);
+}
+
+static int ds1683_get_control(struct i2c_client *client, u8 *status)
+{
+   unsigned char addr = ds1683_REG_CONTROL;
+
+   struct i2c_msg msgs[] = {
+   {/* setup read pointer */
+   .addr = client->addr,
+   .len = 1,
+   .buf = 
+   },
+   {/* read control */
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = 1,
+   .buf = status
+   },
+   };
+
+   /* read control register */
+   if ((i2c_transfer(client->adapter, [0], 2)) != 2) {
+   dev_err(>dev, "%s: read error\n", __func__);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+/* sysfs callback functions */
+static ssize_t show_control(struct device *dev, struct 

[PATCH] rtc: add support for maxim dallas ds1682

2017-11-26 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

Add supporting driver for Dallas Semiconductor
DS1682 2 wire total elapsed time recorder.

Signed-off-by: Venkat Prashanth B U 
---
 drivers/rtc/rtc-ds1682.c | 284 +++
 1 file changed, 284 insertions(+)

diff --git a/drivers/rtc/rtc-ds1682.c b/drivers/rtc/rtc-ds1682.c
index e69de29..a21c94d 100644
--- a/drivers/rtc/rtc-ds1682.c
+++ b/drivers/rtc/rtc-ds1682.c
@@ -0,0 +1,284 @@
+/* Driver for Dallas Semiconductor DS1682 2 wire total elapsed
+ * time recorder
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DS1682_READ_MEMORY_CMD 0x1D
+
+#ifndef __LINUX_DS1682_H
+#define __LINUX_DS1682_H
+
+const struct ds1682_platform_data {
+
+   unsigned int gpio_rst;
+   unsigned int gpio_clk;
+   unsigned int gpio_dq;
+};
+#endif
+
+const struct ds1682;
+
+const struct ds1682_chip_ops {
+   int (*map_io)(const struct ds1682 *chip, struct platform_device *pdev,
+ const struct ds1682_platform_data *pdata);
+   void (*unmap_io)(const struct ds1682 *chip);
+};
+
+#define DS1682_RST 0
+#define DS1682_CLK 1
+#define DS1682_DQ  2
+
+const struct ds1682_gpio {
+   const char *name;
+   unsigned int gpio;
+};
+
+const struct ds1682 {
+   const struct ds1682_gpio *gpio;
+   const struct ds1682_chip_ops *ops;
+   const struct rtc_device *rtc;
+};
+
+const struct ds1682_gpio ds1682_gpio[] = {
+   { "RTC RST", 0 },
+   { "RTC CLK", 0 },
+   { "RTC DQ", 0 },
+};
+
+int ds1682_gpio_map(const struct ds1682 *chip, struct platform_device *pdev,
+ const struct ds1682_platform_data *pdata)
+{
+   int i, err;
+
+   ds1682_gpio[DS1682_RST].gpio = pdata->gpio_rst;
+   ds1682_gpio[DS1682_CLK].gpio = pdata->gpio_clk;
+   ds1682_gpio[DS1682_DQ].gpio = pdata->gpio_dq;
+
+   for (i = 0; i < ARRAY_SIZE(ds1682_gpio); i++) {
+   err = gpio_request(ds1682_gpio[i].gpio, ds1682_gpio[i].name);
+   if (err) {
+   dev_err(>dev, "error mapping gpio %s: %d\n",
+   ds1682_gpio[i].name, err);
+   goto err_request;
+   }
+   if (i != DS1682_DQ)
+   gpio_direction_output(ds1682_gpio[i].gpio, 1);
+   }
+
+   chip->gpio = ds1682_gpio;
+   return 0;
+
+err_request:
+   while (--i >= 0)
+   gpio_free(ds1682_gpio[i].gpio);
+   return err;
+}
+
+static void ds1682_gpio_unmap(const struct ds1682 *chip)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(ds1682_gpio); i++)
+   gpio_free(ds1682_gpio[i].gpio);
+}
+
+static const struct ds1682_chip_ops ds1682_gpio_ops = {
+   .map_io = ds1682_gpio_map,
+   .unmap_io   = ds1682_gpio_unmap,
+};
+
+static void ds1682_reset(const struct device *dev)
+{
+   gpio_set_value(ds1682_gpio[DS1682_RST].gpio, 0);
+   udelay(1000);
+   gpio_set_value(ds1682_gpio[DS1682_RST].gpio, 1);
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 0);
+   gpio_direction_output(ds1682_gpio[DS1682_DQ].gpio, 0);
+   udelay(10);
+}
+
+static void ds1682_write_byte(const struct device *dev, u8 byte)
+{
+   int i;
+
+   gpio_direction_output(ds1682_gpio[DS1682_DQ].gpio, 1);
+   for (i = 0; i < 8; i++) {
+   gpio_set_value(ds1682_gpio[DS1682_DQ].gpio, byte & (1 << i));
+   udelay(10);
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 1);
+   udelay(10);
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 0);
+   udelay(10);
+   }
+}
+
+static u8 ds1682_read_byte(const struct device *dev)
+{
+   int i;
+   u8 ret = 0;
+
+   gpio_direction_input(ds1682_gpio[DS1682_DQ].gpio);
+
+   for (i = 0; i < 8; i++) {
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 0);
+   udelay(10);
+   if (gpio_get_value(ds1682_gpio[DS1682_DQ].gpio))
+   ret |= 1 << i;
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 1);
+   udelay(10);
+   }
+   return ret;
+}
+
+static void ds1682_read_memory(const struct device *dev, u16 offset,
+  int length, u8 *out)
+{
+   ds1682_reset(dev);
+   ds1682_write_byte(dev, DS1682_READ_MEMORY_CMD);
+   ds1682_write_byte(dev, offset & 0xff);
+   ds1682_write_byte(dev, (offset >> 8) & 0xff);
+   while (length--)
+   *out++ = ds1682_read_byte(dev);
+}
+
+static void ds1682_write_memory(const 

[PATCH] rtc: add support for maxim dallas ds1682

2017-11-26 Thread venkat . prashanth2498
From: Venkat Prashanth B U 

Add supporting driver for Dallas Semiconductor
DS1682 2 wire total elapsed time recorder.

Signed-off-by: Venkat Prashanth B U 
---
 drivers/rtc/rtc-ds1682.c | 284 +++
 1 file changed, 284 insertions(+)

diff --git a/drivers/rtc/rtc-ds1682.c b/drivers/rtc/rtc-ds1682.c
index e69de29..a21c94d 100644
--- a/drivers/rtc/rtc-ds1682.c
+++ b/drivers/rtc/rtc-ds1682.c
@@ -0,0 +1,284 @@
+/* Driver for Dallas Semiconductor DS1682 2 wire total elapsed
+ * time recorder
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DS1682_READ_MEMORY_CMD 0x1D
+
+#ifndef __LINUX_DS1682_H
+#define __LINUX_DS1682_H
+
+const struct ds1682_platform_data {
+
+   unsigned int gpio_rst;
+   unsigned int gpio_clk;
+   unsigned int gpio_dq;
+};
+#endif
+
+const struct ds1682;
+
+const struct ds1682_chip_ops {
+   int (*map_io)(const struct ds1682 *chip, struct platform_device *pdev,
+ const struct ds1682_platform_data *pdata);
+   void (*unmap_io)(const struct ds1682 *chip);
+};
+
+#define DS1682_RST 0
+#define DS1682_CLK 1
+#define DS1682_DQ  2
+
+const struct ds1682_gpio {
+   const char *name;
+   unsigned int gpio;
+};
+
+const struct ds1682 {
+   const struct ds1682_gpio *gpio;
+   const struct ds1682_chip_ops *ops;
+   const struct rtc_device *rtc;
+};
+
+const struct ds1682_gpio ds1682_gpio[] = {
+   { "RTC RST", 0 },
+   { "RTC CLK", 0 },
+   { "RTC DQ", 0 },
+};
+
+int ds1682_gpio_map(const struct ds1682 *chip, struct platform_device *pdev,
+ const struct ds1682_platform_data *pdata)
+{
+   int i, err;
+
+   ds1682_gpio[DS1682_RST].gpio = pdata->gpio_rst;
+   ds1682_gpio[DS1682_CLK].gpio = pdata->gpio_clk;
+   ds1682_gpio[DS1682_DQ].gpio = pdata->gpio_dq;
+
+   for (i = 0; i < ARRAY_SIZE(ds1682_gpio); i++) {
+   err = gpio_request(ds1682_gpio[i].gpio, ds1682_gpio[i].name);
+   if (err) {
+   dev_err(>dev, "error mapping gpio %s: %d\n",
+   ds1682_gpio[i].name, err);
+   goto err_request;
+   }
+   if (i != DS1682_DQ)
+   gpio_direction_output(ds1682_gpio[i].gpio, 1);
+   }
+
+   chip->gpio = ds1682_gpio;
+   return 0;
+
+err_request:
+   while (--i >= 0)
+   gpio_free(ds1682_gpio[i].gpio);
+   return err;
+}
+
+static void ds1682_gpio_unmap(const struct ds1682 *chip)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(ds1682_gpio); i++)
+   gpio_free(ds1682_gpio[i].gpio);
+}
+
+static const struct ds1682_chip_ops ds1682_gpio_ops = {
+   .map_io = ds1682_gpio_map,
+   .unmap_io   = ds1682_gpio_unmap,
+};
+
+static void ds1682_reset(const struct device *dev)
+{
+   gpio_set_value(ds1682_gpio[DS1682_RST].gpio, 0);
+   udelay(1000);
+   gpio_set_value(ds1682_gpio[DS1682_RST].gpio, 1);
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 0);
+   gpio_direction_output(ds1682_gpio[DS1682_DQ].gpio, 0);
+   udelay(10);
+}
+
+static void ds1682_write_byte(const struct device *dev, u8 byte)
+{
+   int i;
+
+   gpio_direction_output(ds1682_gpio[DS1682_DQ].gpio, 1);
+   for (i = 0; i < 8; i++) {
+   gpio_set_value(ds1682_gpio[DS1682_DQ].gpio, byte & (1 << i));
+   udelay(10);
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 1);
+   udelay(10);
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 0);
+   udelay(10);
+   }
+}
+
+static u8 ds1682_read_byte(const struct device *dev)
+{
+   int i;
+   u8 ret = 0;
+
+   gpio_direction_input(ds1682_gpio[DS1682_DQ].gpio);
+
+   for (i = 0; i < 8; i++) {
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 0);
+   udelay(10);
+   if (gpio_get_value(ds1682_gpio[DS1682_DQ].gpio))
+   ret |= 1 << i;
+   gpio_set_value(ds1682_gpio[DS1682_CLK].gpio, 1);
+   udelay(10);
+   }
+   return ret;
+}
+
+static void ds1682_read_memory(const struct device *dev, u16 offset,
+  int length, u8 *out)
+{
+   ds1682_reset(dev);
+   ds1682_write_byte(dev, DS1682_READ_MEMORY_CMD);
+   ds1682_write_byte(dev, offset & 0xff);
+   ds1682_write_byte(dev, (offset >> 8) & 0xff);
+   while (length--)
+   *out++ = ds1682_read_byte(dev);
+}
+
+static void ds1682_write_memory(const struct device *dev, u16 offset,
+   int length, u8 *out)
+{
+   

[PATCH v4] rtc:add support for maxim rtc max6916

2016-06-01 Thread venkat . prashanth2498
From: VENKAT PRASHANTH B U 

This is a patch to add support for
maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---
changelog v4:
- fixed the line wrapping to around 72 characters
- Aligned the values with tabs
- inserted the correct coding style in the conditional statements
- removed the empty lines towards the end of the code
- fixed the checkpatch issues
- code clean up on max6916_read_reg()

changelog v3:
- saperated the logical code sections with an empty line
- used indentations after if statements.
- fixed the out of tree makefile
- placed the test condition at the begining of the function

change log v2:
- deleted the port i/o's
- clock burst value is modified from 0x00 to 0x3F
- The time in linux is in binary format so get_rtc()replaced with bcd2bin()
- enforced the year range instead of accepting any value
---
---
 drivers/rtc/Kconfig|  12 
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max6916.c  | 167 
++
 3 files changed, 180 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 83b4b89..5bc38f0 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -681,6 +681,18 @@ config RTC_DRV_MAX6902
  This driver can also be built as a module. If so, the module
  will be called rtc-max6902.
 
+config RTC_DRV_MAX6916
+   tristate "Maxim MAX6916"
+   help
+ If you say yes here you will get support for the
+ Maxim MAX6916 SPI RTC chip.
+
+ This driver only supports the RTC feature, and not other chip
+ features such as alarms.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-max6916.
+
 config RTC_DRV_R9701
tristate "Epson RTC-9701JE"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1b09a62..702c167 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_RTC_DRV_M48T59)  += rtc-m48t59.o
 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_MAX6916)  += rtc-max6916.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
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..4d1ef9a 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,1 +1,167 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x3F
+
+static int max6916_read_reg(struct device *dev, unsigned char address,
+   unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address,
+unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+
+   if (err)
+   return err;
+
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & 0x3F);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   if (dt->tm_year < 100 || dt->tm_year > 199) {
+   dev_err(>dev, "Year must be between 2000 and 

[PATCH v4] rtc:add support for maxim rtc max6916

2016-06-01 Thread venkat . prashanth2498
From: VENKAT PRASHANTH B U 

This is a patch to add support for
maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---
changelog v4:
- fixed the line wrapping to around 72 characters
- Aligned the values with tabs
- inserted the correct coding style in the conditional statements
- removed the empty lines towards the end of the code
- fixed the checkpatch issues
- code clean up on max6916_read_reg()

changelog v3:
- saperated the logical code sections with an empty line
- used indentations after if statements.
- fixed the out of tree makefile
- placed the test condition at the begining of the function

change log v2:
- deleted the port i/o's
- clock burst value is modified from 0x00 to 0x3F
- The time in linux is in binary format so get_rtc()replaced with bcd2bin()
- enforced the year range instead of accepting any value
---
---
 drivers/rtc/Kconfig|  12 
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max6916.c  | 167 
++
 3 files changed, 180 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 83b4b89..5bc38f0 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -681,6 +681,18 @@ config RTC_DRV_MAX6902
  This driver can also be built as a module. If so, the module
  will be called rtc-max6902.
 
+config RTC_DRV_MAX6916
+   tristate "Maxim MAX6916"
+   help
+ If you say yes here you will get support for the
+ Maxim MAX6916 SPI RTC chip.
+
+ This driver only supports the RTC feature, and not other chip
+ features such as alarms.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-max6916.
+
 config RTC_DRV_R9701
tristate "Epson RTC-9701JE"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1b09a62..702c167 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_RTC_DRV_M48T59)  += rtc-m48t59.o
 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_MAX6916)  += rtc-max6916.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
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..4d1ef9a 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,1 +1,167 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x3F
+
+static int max6916_read_reg(struct device *dev, unsigned char address,
+   unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address,
+unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+
+   if (err)
+   return err;
+
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & 0x3F);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   if (dt->tm_year < 100 || dt->tm_year > 199) {
+   dev_err(>dev, "Year must be between 2000 and 2099. It's 
%d.\n",
+   dt->tm_year + 1900);
+   return -EINVAL;
+   }
+

[PATCH v4] rtc:add support for maxim rtc max6916

2016-05-16 Thread venkat . prashanth2498
From: VENKAT PRASHANTH B U 

This is a patch to add support for
maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---
changelog v4:
- fixed the line wrapping to around 72 characters
- Aligned the values with tabs
- inserted the correct coding style in the conditional statements
- removed the empty lines towards the end of the code
- fixed the checkpatch issues
- code clean up on max6916_read_reg()

changelog v3:
- saperated the logical code sections with an empty line
- used indentations after if statements.
- fixed the out of tree makefile
- placed the test condition at the begining of the function

change log v2:
- deleted the port i/o's
- clock burst value is modified from 0x00 to 0x3F
- The time in linux is in binary format so get_rtc()replaced with bcd2bin()
- enforced the year range instead of accepting any value
---
---
 drivers/rtc/Kconfig|  12 
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max6916.c  | 167 
++
 3 files changed, 180 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 83b4b89..5bc38f0 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -681,6 +681,18 @@ config RTC_DRV_MAX6902
  This driver can also be built as a module. If so, the module
  will be called rtc-max6902.
 
+config RTC_DRV_MAX6916
+   tristate "Maxim MAX6916"
+   help
+ If you say yes here you will get support for the
+ Maxim MAX6916 SPI RTC chip.
+
+ This driver only supports the RTC feature, and not other chip
+ features such as alarms.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-max6916.
+
 config RTC_DRV_R9701
tristate "Epson RTC-9701JE"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1b09a62..702c167 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_RTC_DRV_M48T59)  += rtc-m48t59.o
 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_MAX6916)  += rtc-max6916.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
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..4d1ef9a 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,1 +1,167 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x3F
+
+static int max6916_read_reg(struct device *dev, unsigned char address,
+   unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address,
+unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+
+   if (err)
+   return err;
+
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & 0x3F);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   if (dt->tm_year < 100 || dt->tm_year > 199) {
+   dev_err(>dev, "Year must be between 2000 and 

[PATCH v4] rtc:add support for maxim rtc max6916

2016-05-16 Thread venkat . prashanth2498
From: VENKAT PRASHANTH B U 

This is a patch to add support for
maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---
changelog v4:
- fixed the line wrapping to around 72 characters
- Aligned the values with tabs
- inserted the correct coding style in the conditional statements
- removed the empty lines towards the end of the code
- fixed the checkpatch issues
- code clean up on max6916_read_reg()

changelog v3:
- saperated the logical code sections with an empty line
- used indentations after if statements.
- fixed the out of tree makefile
- placed the test condition at the begining of the function

change log v2:
- deleted the port i/o's
- clock burst value is modified from 0x00 to 0x3F
- The time in linux is in binary format so get_rtc()replaced with bcd2bin()
- enforced the year range instead of accepting any value
---
---
 drivers/rtc/Kconfig|  12 
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max6916.c  | 167 
++
 3 files changed, 180 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 83b4b89..5bc38f0 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -681,6 +681,18 @@ config RTC_DRV_MAX6902
  This driver can also be built as a module. If so, the module
  will be called rtc-max6902.
 
+config RTC_DRV_MAX6916
+   tristate "Maxim MAX6916"
+   help
+ If you say yes here you will get support for the
+ Maxim MAX6916 SPI RTC chip.
+
+ This driver only supports the RTC feature, and not other chip
+ features such as alarms.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-max6916.
+
 config RTC_DRV_R9701
tristate "Epson RTC-9701JE"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1b09a62..702c167 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_RTC_DRV_M48T59)  += rtc-m48t59.o
 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_MAX6916)  += rtc-max6916.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
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..4d1ef9a 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,1 +1,167 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x3F
+
+static int max6916_read_reg(struct device *dev, unsigned char address,
+   unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address,
+unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+
+   if (err)
+   return err;
+
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & 0x3F);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   if (dt->tm_year < 100 || dt->tm_year > 199) {
+   dev_err(>dev, "Year must be between 2000 and 2099. It's 
%d.\n",
+   dt->tm_year + 1900);
+   return -EINVAL;
+   }
+

[PATCH] rtc: add support for Maxim rtc max6916 v3.0

2016-05-13 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add support 
for Maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---

   #Change Log: from v2.0 to v3.0

 - fixed the out-of-tree Makefile and suitably added
   the modifications in the Makefile

 - fixed the bad indented Kconfig file

 -used a define instead of 0x1B as follows
#define MAX6916_REG_MAP_ADDRESS 0x1B

 -moved and placed the test at the begining of the function
  after the range is properly enforced
   if (dt->tm_year < 100 || dt->tm_year > 199) {
  dev_err(>dev,"Year must be between 2000 and 2099.
  It's %d.\n", dt->tm_year + 1900);
  return -EINVAL;
  }

 - A magic number is a direct usage of a number
   in the code,instead has been refactored in  the
   current version v3.0 which use defines as follows:-
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
 -max6916_write_reg(>dev,
  int MAX6916_CONTROL_REG= 0x08, data);
 -max6916_write_reg(>dev,
  int MAX6916_STATUS_REG = 0x0C, data);
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
   -max6916_read_reg(>dev,
  int MAX6916_STATUS_REG  = 0X0C,  );
 -Unnecessary test function if(dt->tm_year >= 100)
  dt->tm_year -= 100;
  is deleted after the range is properly enforced.
 -seperated logical code sections with an empty line
  and used indentation after if-statements.
---
---
 Kconfig   |   9 
 Makefile  |   1 +
 rtc-max6916.c | 162 ++
 3 files changed, 172 insertions(+)

diff --git a/driver/rtc/Kconfig b/driver/rtc/Kconfig
index fcf87da..5321e8f 100644
--- a/driver/rtc/Kconfig
+++ b/driver/rtc/Kconfig
@@ -699,6 +699,15 @@
  
   This driver can also be built as a module. If so, the module
   will be called rtc-max6902.
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+help
+  If you say yes here you will get support for the
+  Maxim MAX6916 SPI RTC chip.
+
+  This driver can also be built as a module. If so, the module
+  will be called rtc-max6916.
+
  
 config RTC_DRV_R9701
 tristate "Epson RTC-9701JE"
diff --git a/driver/rtc/Makefile b/driver/rtc/Makefile
index 9421959..0b3fded 100644
--- a/driver/rtc/Makefile
+++ b/driver/rtc/Makefile
@@ -85,6 +85,7 @@
 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_MAX6916)   += rtc-max6916.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
diff --git a/driver/rtc/rtc-max6916.c b/driver/rtc/rtc-max6916.c
index e69de29..ced341a 100644
--- a/driver/rtc/rtc-max6916.c
+++ b/driver/rtc/rtc-max6916.c
@@ -0,0 +1,162 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG  0x01
+#define MAX6916_MINUTES_REG  0x02
+#define MAX6916_HOURS_REG0x03
+#define MAX6916_DATE_REG 0x04
+#define MAX6916_MONTH_REG0x05
+#define MAX6916_DAY_REG  0x06
+#define MAX6916_YEAR_REG 0x07
+#define MAX6916_CONTROL_REG  0x08
+#define MAX6916_STATUS_REG   0x0C
+#define MAX6916_CLOCK_BURST  0x3F
+#define MAX6916_REG_MAP_ADDRESS  0x1B
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi 

[PATCH] rtc: add support for Maxim rtc max6916 v3.0

2016-05-13 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add support 
for Maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---

   #Change Log: from v2.0 to v3.0

 - fixed the out-of-tree Makefile and suitably added
   the modifications in the Makefile

 - fixed the bad indented Kconfig file

 -used a define instead of 0x1B as follows
#define MAX6916_REG_MAP_ADDRESS 0x1B

 -moved and placed the test at the begining of the function
  after the range is properly enforced
   if (dt->tm_year < 100 || dt->tm_year > 199) {
  dev_err(>dev,"Year must be between 2000 and 2099.
  It's %d.\n", dt->tm_year + 1900);
  return -EINVAL;
  }

 - A magic number is a direct usage of a number
   in the code,instead has been refactored in  the
   current version v3.0 which use defines as follows:-
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
 -max6916_write_reg(>dev,
  int MAX6916_CONTROL_REG= 0x08, data);
 -max6916_write_reg(>dev,
  int MAX6916_STATUS_REG = 0x0C, data);
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
   -max6916_read_reg(>dev,
  int MAX6916_STATUS_REG  = 0X0C,  );
 -Unnecessary test function if(dt->tm_year >= 100)
  dt->tm_year -= 100;
  is deleted after the range is properly enforced.
 -seperated logical code sections with an empty line
  and used indentation after if-statements.
---
---
 Kconfig   |   9 
 Makefile  |   1 +
 rtc-max6916.c | 162 ++
 3 files changed, 172 insertions(+)

diff --git a/driver/rtc/Kconfig b/driver/rtc/Kconfig
index fcf87da..5321e8f 100644
--- a/driver/rtc/Kconfig
+++ b/driver/rtc/Kconfig
@@ -699,6 +699,15 @@
  
   This driver can also be built as a module. If so, the module
   will be called rtc-max6902.
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+help
+  If you say yes here you will get support for the
+  Maxim MAX6916 SPI RTC chip.
+
+  This driver can also be built as a module. If so, the module
+  will be called rtc-max6916.
+
  
 config RTC_DRV_R9701
 tristate "Epson RTC-9701JE"
diff --git a/driver/rtc/Makefile b/driver/rtc/Makefile
index 9421959..0b3fded 100644
--- a/driver/rtc/Makefile
+++ b/driver/rtc/Makefile
@@ -85,6 +85,7 @@
 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_MAX6916)   += rtc-max6916.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
diff --git a/driver/rtc/rtc-max6916.c b/driver/rtc/rtc-max6916.c
index e69de29..ced341a 100644
--- a/driver/rtc/rtc-max6916.c
+++ b/driver/rtc/rtc-max6916.c
@@ -0,0 +1,162 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG  0x01
+#define MAX6916_MINUTES_REG  0x02
+#define MAX6916_HOURS_REG0x03
+#define MAX6916_DATE_REG 0x04
+#define MAX6916_MONTH_REG0x05
+#define MAX6916_DAY_REG  0x06
+#define MAX6916_YEAR_REG 0x07
+#define MAX6916_CONTROL_REG  0x08
+#define MAX6916_STATUS_REG   0x0C
+#define MAX6916_CLOCK_BURST  0x3F
+#define MAX6916_REG_MAP_ADDRESS  0x1B
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+

[PATCH] rtc: add support for Maxim rtc max6916 v3.0

2016-05-13 Thread venkat . prashanth2498
From: venkat-prashanth 

 [PATCH] rtc: add support to maxim rtc max6916

 #Change Log: from v2.0 to v3.0

 - fixed the out-of-tree Makefile and suitably added
   the modifications in the Makefile

 - fixed the bad indented Kconfig file

 -used a define instead of 0x1B as follows
#define MAX6916_REG_MAP_ADDRESS 0x1B

 -moved and placed the test at the begining of the function
  after the range is properly enforced
   if (dt->tm_year < 100 || dt->tm_year > 199) {
  dev_err(>dev,"Year must be between 2000 and 2099.
  It's %d.\n", dt->tm_year + 1900);
  return -EINVAL;
  }

 - A magic number is a direct usage of a number
   in the code,instead has been refactored in  the
   current version v3.0 which use defines as follows:-
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
 -max6916_write_reg(>dev,
  int MAX6916_CONTROL_REG= 0x08, data);
 -max6916_write_reg(>dev,
  int MAX6916_STATUS_REG = 0x0C, data);
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
   -max6916_read_reg(>dev,
  int MAX6916_STATUS_REG  = 0X0C,  );
 -Unnecessary test function if(dt->tm_year >= 100)
  dt->tm_year -= 100;
  is deleted after the range is properly enforced.
 -seperated logical code sections with an empty line
  and used indentation after if-statements.
---
---
 Kconfig   |   9 
 Makefile  |   1 +
 rtc-max6916.c | 162 ++
 3 files changed, 172 insertions(+)

diff --git a/driver/rtc/Kconfig b/driver/rtc/Kconfig
index fcf87da..5321e8f 100644
--- a/driver/rtc/Kconfig
+++ b/driver/rtc/Kconfig
@@ -699,6 +699,15 @@
  
   This driver can also be built as a module. If so, the module
   will be called rtc-max6902.
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+help
+  If you say yes here you will get support for the
+  Maxim MAX6916 SPI RTC chip.
+
+  This driver can also be built as a module. If so, the module
+  will be called rtc-max6916.
+
  
 config RTC_DRV_R9701
 tristate "Epson RTC-9701JE"
diff --git a/driver/rtc/Makefile b/driver/rtc/Makefile
index 9421959..0b3fded 100644
--- a/driver/rtc/Makefile
+++ b/driver/rtc/Makefile
@@ -85,6 +85,7 @@
 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_MAX6916)   += rtc-max6916.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
diff --git a/driver/rtc/rtc-max6916.c b/driver/rtc/rtc-max6916.c
index e69de29..ced341a 100644
--- a/driver/rtc/rtc-max6916.c
+++ b/driver/rtc/rtc-max6916.c
@@ -0,0 +1,162 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG  0x01
+#define MAX6916_MINUTES_REG  0x02
+#define MAX6916_HOURS_REG0x03
+#define MAX6916_DATE_REG 0x04
+#define MAX6916_MONTH_REG0x05
+#define MAX6916_DAY_REG  0x06
+#define MAX6916_YEAR_REG 0x07
+#define MAX6916_CONTROL_REG  0x08
+#define MAX6916_STATUS_REG   0x0C
+#define MAX6916_CLOCK_BURST  0x3F
+#define MAX6916_REG_MAP_ADDRESS  0x1B
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   

[PATCH] rtc: add support for Maxim rtc max6916 v3.0

2016-05-13 Thread venkat . prashanth2498
From: venkat-prashanth 

 [PATCH] rtc: add support to maxim rtc max6916

 #Change Log: from v2.0 to v3.0

 - fixed the out-of-tree Makefile and suitably added
   the modifications in the Makefile

 - fixed the bad indented Kconfig file

 -used a define instead of 0x1B as follows
#define MAX6916_REG_MAP_ADDRESS 0x1B

 -moved and placed the test at the begining of the function
  after the range is properly enforced
   if (dt->tm_year < 100 || dt->tm_year > 199) {
  dev_err(>dev,"Year must be between 2000 and 2099.
  It's %d.\n", dt->tm_year + 1900);
  return -EINVAL;
  }

 - A magic number is a direct usage of a number
   in the code,instead has been refactored in  the
   current version v3.0 which use defines as follows:-
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
 -max6916_write_reg(>dev,
  int MAX6916_CONTROL_REG= 0x08, data);
 -max6916_write_reg(>dev,
  int MAX6916_STATUS_REG = 0x0C, data);
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
   -max6916_read_reg(>dev,
  int MAX6916_STATUS_REG  = 0X0C,  );
 -Unnecessary test function if(dt->tm_year >= 100)
  dt->tm_year -= 100;
  is deleted after the range is properly enforced.
 -seperated logical code sections with an empty line
  and used indentation after if-statements.
---
---
 Kconfig   |   9 
 Makefile  |   1 +
 rtc-max6916.c | 162 ++
 3 files changed, 172 insertions(+)

diff --git a/driver/rtc/Kconfig b/driver/rtc/Kconfig
index fcf87da..5321e8f 100644
--- a/driver/rtc/Kconfig
+++ b/driver/rtc/Kconfig
@@ -699,6 +699,15 @@
  
   This driver can also be built as a module. If so, the module
   will be called rtc-max6902.
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+help
+  If you say yes here you will get support for the
+  Maxim MAX6916 SPI RTC chip.
+
+  This driver can also be built as a module. If so, the module
+  will be called rtc-max6916.
+
  
 config RTC_DRV_R9701
 tristate "Epson RTC-9701JE"
diff --git a/driver/rtc/Makefile b/driver/rtc/Makefile
index 9421959..0b3fded 100644
--- a/driver/rtc/Makefile
+++ b/driver/rtc/Makefile
@@ -85,6 +85,7 @@
 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_MAX6916)   += rtc-max6916.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
diff --git a/driver/rtc/rtc-max6916.c b/driver/rtc/rtc-max6916.c
index e69de29..ced341a 100644
--- a/driver/rtc/rtc-max6916.c
+++ b/driver/rtc/rtc-max6916.c
@@ -0,0 +1,162 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG  0x01
+#define MAX6916_MINUTES_REG  0x02
+#define MAX6916_HOURS_REG0x03
+#define MAX6916_DATE_REG 0x04
+#define MAX6916_MONTH_REG0x05
+#define MAX6916_DAY_REG  0x06
+#define MAX6916_YEAR_REG 0x07
+#define MAX6916_CONTROL_REG  0x08
+#define MAX6916_STATUS_REG   0x0C
+#define MAX6916_CLOCK_BURST  0x3F
+#define MAX6916_REG_MAP_ADDRESS  0x1B
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char 

[PATCH] rtc: add support for Maxim rtc max6916 v3.0

2016-05-12 Thread venkat . prashanth2498
From: venkat-prashanth 

 #Change Log: from v2.0 to v3.0

 - fixed the out-of-tree Makefile and suitably added
   the modifications in the Makefile

 - fixed the bad indented Kconfig file

 -used a define instead of 0x1B as follows
#define MAX6916_REG_MAP_ADDRESS 0x1B

 -moved and placed the test at the begining of the function
  after the range is properly enforced
   if (dt->tm_year < 100 || dt->tm_year > 199) {
  dev_err(>dev,"Year must be between 2000 and 2099.
  It's %d.\n", dt->tm_year + 1900);
  return -EINVAL;
  }

 - A magic number is a direct usage of a number
   in the code,instead has been refactored in  the
   current version v3.0 which use defines as follows:-
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
 -max6916_write_reg(>dev,
  int MAX6916_CONTROL_REG= 0x08, data);
 -max6916_write_reg(>dev,
  int MAX6916_STATUS_REG = 0x0C, data);
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
   -max6916_read_reg(>dev,
  int MAX6916_STATUS_REG  = 0X0C,  );
 -Unnecessary test function if(dt->tm_year >= 100)
  dt->tm_year -= 100;
  is deleted after the range is properly enforced.
 -seperated logical code sections with an empty line
  and used indentation after if-statements.
---
---
 Kconfig   |   9 
 Makefile  |   1 +
 rtc-max6916.c | 162 ++
 3 files changed, 172 insertions(+)

diff --git a/driver/rtc/Kconfig b/driver/rtc/Kconfig
index fcf87da..5321e8f 100644
--- a/driver/rtc/Kconfig
+++ b/driver/rtc/Kconfig
@@ -699,6 +699,15 @@
  
   This driver can also be built as a module. If so, the module
   will be called rtc-max6902.
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+help
+  If you say yes here you will get support for the
+  Maxim MAX6916 SPI RTC chip.
+
+  This driver can also be built as a module. If so, the module
+  will be called rtc-max6916.
+
  
 config RTC_DRV_R9701
 tristate "Epson RTC-9701JE"
diff --git a/driver/rtc/Makefile b/driver/rtc/Makefile
index 9421959..0b3fded 100644
--- a/driver/rtc/Makefile
+++ b/driver/rtc/Makefile
@@ -85,6 +85,7 @@
 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_MAX6916)   += rtc-max6916.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
diff --git a/driver/rtc/rtc-max6916.c b/driver/rtc/rtc-max6916.c
index e69de29..ced341a 100644
--- a/driver/rtc/rtc-max6916.c
+++ b/driver/rtc/rtc-max6916.c
@@ -0,0 +1,162 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG  0x01
+#define MAX6916_MINUTES_REG  0x02
+#define MAX6916_HOURS_REG0x03
+#define MAX6916_DATE_REG 0x04
+#define MAX6916_MONTH_REG0x05
+#define MAX6916_DAY_REG  0x06
+#define MAX6916_YEAR_REG 0x07
+#define MAX6916_CONTROL_REG  0x08
+#define MAX6916_STATUS_REG   0x0C
+#define MAX6916_CLOCK_BURST  0x3F
+#define MAX6916_REG_MAP_ADDRESS  0x1B
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   

[PATCH] rtc: add support for Maxim rtc max6916 v3.0

2016-05-12 Thread venkat . prashanth2498
From: venkat-prashanth 

 #Change Log: from v2.0 to v3.0

 - fixed the out-of-tree Makefile and suitably added
   the modifications in the Makefile

 - fixed the bad indented Kconfig file

 -used a define instead of 0x1B as follows
#define MAX6916_REG_MAP_ADDRESS 0x1B

 -moved and placed the test at the begining of the function
  after the range is properly enforced
   if (dt->tm_year < 100 || dt->tm_year > 199) {
  dev_err(>dev,"Year must be between 2000 and 2099.
  It's %d.\n", dt->tm_year + 1900);
  return -EINVAL;
  }

 - A magic number is a direct usage of a number
   in the code,instead has been refactored in  the
   current version v3.0 which use defines as follows:-
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
 -max6916_write_reg(>dev,
  int MAX6916_CONTROL_REG= 0x08, data);
 -max6916_write_reg(>dev,
  int MAX6916_STATUS_REG = 0x0C, data);
 -max6916_read_reg(>dev,
  int MAX6916_CONTROL_REG = 0x08, );
   -max6916_read_reg(>dev,
  int MAX6916_STATUS_REG  = 0X0C,  );
 -Unnecessary test function if(dt->tm_year >= 100)
  dt->tm_year -= 100;
  is deleted after the range is properly enforced.
 -seperated logical code sections with an empty line
  and used indentation after if-statements.
---
---
 Kconfig   |   9 
 Makefile  |   1 +
 rtc-max6916.c | 162 ++
 3 files changed, 172 insertions(+)

diff --git a/driver/rtc/Kconfig b/driver/rtc/Kconfig
index fcf87da..5321e8f 100644
--- a/driver/rtc/Kconfig
+++ b/driver/rtc/Kconfig
@@ -699,6 +699,15 @@
  
   This driver can also be built as a module. If so, the module
   will be called rtc-max6902.
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+help
+  If you say yes here you will get support for the
+  Maxim MAX6916 SPI RTC chip.
+
+  This driver can also be built as a module. If so, the module
+  will be called rtc-max6916.
+
  
 config RTC_DRV_R9701
 tristate "Epson RTC-9701JE"
diff --git a/driver/rtc/Makefile b/driver/rtc/Makefile
index 9421959..0b3fded 100644
--- a/driver/rtc/Makefile
+++ b/driver/rtc/Makefile
@@ -85,6 +85,7 @@
 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_MAX6916)   += rtc-max6916.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
diff --git a/driver/rtc/rtc-max6916.c b/driver/rtc/rtc-max6916.c
index e69de29..ced341a 100644
--- a/driver/rtc/rtc-max6916.c
+++ b/driver/rtc/rtc-max6916.c
@@ -0,0 +1,162 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG  0x01
+#define MAX6916_MINUTES_REG  0x02
+#define MAX6916_HOURS_REG0x03
+#define MAX6916_DATE_REG 0x04
+#define MAX6916_MONTH_REG0x05
+#define MAX6916_DAY_REG  0x06
+#define MAX6916_YEAR_REG 0x07
+#define MAX6916_CONTROL_REG  0x08
+#define MAX6916_STATUS_REG   0x0C
+#define MAX6916_CLOCK_BURST  0x3F
+#define MAX6916_REG_MAP_ADDRESS  0x1B
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 

[PATCH] rtc: add support to maxim rtc max6916 v2.0

2016-05-06 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add 
support for maxim rtc MAX6916

Signed-off-by : Venkat Prashanth B U 
---
 Kconfig   |  10 
 changeLOG |  36 
 rtc-max6916.c | 172 ++
 3 files changed, 218 insertions(+)

diff --git a/drivers/rtcKconfig b/drivers/rtc/Kconfig
index e69de29..81aaa1e 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -0,0 +1,10 @@
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+
+help
+If you say yes here you get support for the
+Maxim MAX6916 chips.
+This driver only supports the RTC feature, and not other chip
+features such as alarms.
+This driver can also be built as a module. If so, the module
+will be called rtc‐max6916.
diff --git a/changeLOG b/changeLOG
index e69de29..6aa0a76 100644
--- a/drivers/rtc/changeLOG
+++ b/drivers/rtc/changeLOG
@@ -0,0 +1,36 @@
+Changes incorporated after pre-commit review
+
+1./*created folders 
+drivers/rtc/rtc-max6916.c
+drivers/rtc/Kconfig/
+
+2./*deleted the port i/o's since it does not add 
+any significance in overall system design aspect*/
+/* 
+#define ADDRESS_REG  0x70
+#define DATA_REG 0x71
+#define ADDRESS_REG_MASK 0xe0
+
+static unsigned char get_rtc(unsigned char addr)
+{
+outb(addr, ADDRESS_REG);
+return inb(DATA_REG);
+}*/
+
+3./* Clock burst value is modified from 0X00 to 0X3F and 
+further get_rtc() function is replaced with bcd2bin() 
+since the time in Linux is in binary format so the conversion is done*/
+
+
+4./*enforced the year range instead of accepting any value
+which is as follows:
+/* starting from year 2000,limit to 100 years from now
+that is subtract the year by 100 */
+dt->tm_year = dt->tm_year % 100;
+if(dt->tm_year >= 100)
+dt->tm_year -= 100;
+
+if (dt->tm_year < 100 || dt->tm_year > 199) {
+   dev_err(>dev, "Year must be between 2000 and 2099. It's 
%d.\n",dt->tm_year + 1900);
+   return -EINVAL;
+}*/
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..f5e396f 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,0 +1,172 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+ 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG 0x03
+#define MAX6916_DATE_REG  0x04
+#define MAX6916_MONTH_REG 0x05
+#define MAX6916_DAY_REG   0x06
+#define MAX6916_YEAR_REG  0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG0x0C
+#define MAX6916_CLOCK_BURST0x3F
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
+  unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
+   unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & 0x3F);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bin2bcd(dt->tm_sec);
+   buf[2] = bin2bcd(dt->tm_min);
+   buf[3] = (bin2bcd(dt->tm_hour)& 0X3F);
+   buf[4] = bin2bcd(dt->tm_mday);
+   buf[5] = bin2bcd(dt->tm_mon + 1);
+   buf[6] = bin2bcd(dt->tm_wday + 1);
+
+   /* starting from year 2000,limit to 100 years 
+   from now that is subtract the year by 100 */
+ 

[PATCH] rtc: add support to maxim rtc max6916 v2.0

2016-05-06 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add 
support for maxim rtc MAX6916

Signed-off-by : Venkat Prashanth B U 
---
 Kconfig   |  10 
 changeLOG |  36 
 rtc-max6916.c | 172 ++
 3 files changed, 218 insertions(+)

diff --git a/drivers/rtcKconfig b/drivers/rtc/Kconfig
index e69de29..81aaa1e 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -0,0 +1,10 @@
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+
+help
+If you say yes here you get support for the
+Maxim MAX6916 chips.
+This driver only supports the RTC feature, and not other chip
+features such as alarms.
+This driver can also be built as a module. If so, the module
+will be called rtc‐max6916.
diff --git a/changeLOG b/changeLOG
index e69de29..6aa0a76 100644
--- a/drivers/rtc/changeLOG
+++ b/drivers/rtc/changeLOG
@@ -0,0 +1,36 @@
+Changes incorporated after pre-commit review
+
+1./*created folders 
+drivers/rtc/rtc-max6916.c
+drivers/rtc/Kconfig/
+
+2./*deleted the port i/o's since it does not add 
+any significance in overall system design aspect*/
+/* 
+#define ADDRESS_REG  0x70
+#define DATA_REG 0x71
+#define ADDRESS_REG_MASK 0xe0
+
+static unsigned char get_rtc(unsigned char addr)
+{
+outb(addr, ADDRESS_REG);
+return inb(DATA_REG);
+}*/
+
+3./* Clock burst value is modified from 0X00 to 0X3F and 
+further get_rtc() function is replaced with bcd2bin() 
+since the time in Linux is in binary format so the conversion is done*/
+
+
+4./*enforced the year range instead of accepting any value
+which is as follows:
+/* starting from year 2000,limit to 100 years from now
+that is subtract the year by 100 */
+dt->tm_year = dt->tm_year % 100;
+if(dt->tm_year >= 100)
+dt->tm_year -= 100;
+
+if (dt->tm_year < 100 || dt->tm_year > 199) {
+   dev_err(>dev, "Year must be between 2000 and 2099. It's 
%d.\n",dt->tm_year + 1900);
+   return -EINVAL;
+}*/
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..f5e396f 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,0 +1,172 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+ 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG 0x03
+#define MAX6916_DATE_REG  0x04
+#define MAX6916_MONTH_REG 0x05
+#define MAX6916_DAY_REG   0x06
+#define MAX6916_YEAR_REG  0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG0x0C
+#define MAX6916_CLOCK_BURST0x3F
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
+  unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
+   unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & 0x3F);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bin2bcd(dt->tm_sec);
+   buf[2] = bin2bcd(dt->tm_min);
+   buf[3] = (bin2bcd(dt->tm_hour)& 0X3F);
+   buf[4] = bin2bcd(dt->tm_mday);
+   buf[5] = bin2bcd(dt->tm_mon + 1);
+   buf[6] = bin2bcd(dt->tm_wday + 1);
+
+   /* starting from year 2000,limit to 100 years 
+   from now that is subtract the year by 100 */
+   dt->tm_year = dt->tm_year % 100;
+   if(dt->tm_year >= 100)
+   dt->tm_year 

[PATCH] rtc: add support for maxim rtc max6916

2016-05-05 Thread venkat . prashanth2498
From: venkat-prashanth 

This a patch to add support for
maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---
---
 drivers/rtc/rtc-max6916.c | 165 
++
 1 file changed, 165 insertions(+)

diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..2085151 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,0 +1,165 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+ 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG 0x03
+#define MAX6916_DATE_REG  0x04
+#define MAX6916_MONTH_REG 0x05
+#define MAX6916_DAY_REG   0x06
+#define MAX6916_YEAR_REG  0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x00
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
+   unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
+unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & MAX6916_CLOCK_BURST);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bcd2bin(dt->tm_sec);
+   buf[2] = bcd2bin(dt->tm_min);
+   buf[3] = (bcd2bin(dt->tm_hour)_CLOCK_BURST);
+   buf[4] = bcd2bin(dt->tm_mday);
+   buf[5] = bcd2bin(dt->tm_mon + 1);
+   buf[6] = bcd2bin(dt->tm_wday + 1);
+
+   /* year from 1900-range of 100 in rtc from 00 to 99 */
+   dt->tm_year = dt->tm_year % 100;
+
+   buf[7] = bcd2bin(dt->tm_year);
+   buf[8] = bcd2bin(0x00);
+   
+   /* write the rtc settings */
+   return spi_write_then_read(spi, buf, 9, NULL, 0);
+}
+
+static const struct rtc_class_ops max6916_rtc_ops = {
+   .read_time = max6916_read_time,
+   .set_time = max6916_set_time,
+};
+
+static int max6916_probe(struct spi_device *spi)
+{
+   struct rtc_device *rtc;
+   unsigned char data;
+   int res;
+
+   /* spi setup with max6916 in mode 3 and bits per word as 8 */
+   spi->mode = SPI_MODE_3;
+   spi->bits_per_word = 8;
+   spi_setup(spi);
+
+   /* RTC Settings */
+   res = max6916_read_reg(>dev, MAX6916_SECONDS_REG, );
+   
+   if (res)
+   return res;
+
+   /* Disable the write protect of rtc */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   data = data & ~(1<<7);
+   max6916_write_reg(>dev, MAX6916_CONTROL_REG, data);
+
+   /* Enable the oscillator,disable the oscillator stop flag,
+   and glitch filter to reduce current consumption */
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   data = data & 0x1B;
+   max6916_write_reg(>dev, MAX6916_STATUS_REG, data);
+
+   /* display the settings */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   dev_info(>dev, "MAX6916 RTC CTRL Reg = 0x%02x\n", data);
+
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   dev_info(>dev, "MAX6916 RTC Status Reg = 0x%02x\n", data);
+
+   rtc = devm_rtc_device_register(>dev, "max6916", 
+ _rtc_ops, THIS_MODULE);
+ 
+   if (IS_ERR(rtc))
+   return PTR_ERR(rtc);
+   
+   

[PATCH] rtc: add support for maxim rtc max6916

2016-05-05 Thread venkat . prashanth2498
From: venkat-prashanth 

This a patch to add support for
maxim rtc max6916

Signed-off-by: Venkat Prashanth B U 
---
---
 drivers/rtc/rtc-max6916.c | 165 
++
 1 file changed, 165 insertions(+)

diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index e69de29..2085151 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,0 +1,165 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+ 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG 0x03
+#define MAX6916_DATE_REG  0x04
+#define MAX6916_MONTH_REG 0x05
+#define MAX6916_DAY_REG   0x06
+#define MAX6916_YEAR_REG  0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x00
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
+   unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+
+   *data = address | 0x80;
+
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
+unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & MAX6916_CLOCK_BURST);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bcd2bin(dt->tm_sec);
+   buf[2] = bcd2bin(dt->tm_min);
+   buf[3] = (bcd2bin(dt->tm_hour)_CLOCK_BURST);
+   buf[4] = bcd2bin(dt->tm_mday);
+   buf[5] = bcd2bin(dt->tm_mon + 1);
+   buf[6] = bcd2bin(dt->tm_wday + 1);
+
+   /* year from 1900-range of 100 in rtc from 00 to 99 */
+   dt->tm_year = dt->tm_year % 100;
+
+   buf[7] = bcd2bin(dt->tm_year);
+   buf[8] = bcd2bin(0x00);
+   
+   /* write the rtc settings */
+   return spi_write_then_read(spi, buf, 9, NULL, 0);
+}
+
+static const struct rtc_class_ops max6916_rtc_ops = {
+   .read_time = max6916_read_time,
+   .set_time = max6916_set_time,
+};
+
+static int max6916_probe(struct spi_device *spi)
+{
+   struct rtc_device *rtc;
+   unsigned char data;
+   int res;
+
+   /* spi setup with max6916 in mode 3 and bits per word as 8 */
+   spi->mode = SPI_MODE_3;
+   spi->bits_per_word = 8;
+   spi_setup(spi);
+
+   /* RTC Settings */
+   res = max6916_read_reg(>dev, MAX6916_SECONDS_REG, );
+   
+   if (res)
+   return res;
+
+   /* Disable the write protect of rtc */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   data = data & ~(1<<7);
+   max6916_write_reg(>dev, MAX6916_CONTROL_REG, data);
+
+   /* Enable the oscillator,disable the oscillator stop flag,
+   and glitch filter to reduce current consumption */
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   data = data & 0x1B;
+   max6916_write_reg(>dev, MAX6916_STATUS_REG, data);
+
+   /* display the settings */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   dev_info(>dev, "MAX6916 RTC CTRL Reg = 0x%02x\n", data);
+
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   dev_info(>dev, "MAX6916 RTC Status Reg = 0x%02x\n", data);
+
+   rtc = devm_rtc_device_register(>dev, "max6916", 
+ _rtc_ops, THIS_MODULE);
+ 
+   if (IS_ERR(rtc))
+   return PTR_ERR(rtc);
+   
+   spi_set_drvdata(spi, rtc);
+
+   return 0;
+}
+
+static struct spi_driver max6916_driver = {
+   .driver = 

[PATCH] rtc:add support for maxim rtc max6916

2016-05-04 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add support for
maxim rtc max6916
Signed-off-by:Venkat Prashanth B U 
---
 Kconfig   |   9 
 Makefile  |   6 +++
 rtc-max6916.c | 133 ++
 3 files changed, 148 insertions(+)
 create mode 100644 Kconfig
 create mode 100644 Makefile
 create mode 100644 rtc-max6916.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
new file mode 100644
index 000..fa7a2fa
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -0,0 +1,9 @@
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+ help
+  If you say yes here you get support for the
+  Maxim MAX6916 chips.
+  This driver only supports the RTC feature, and not other chip
+  features such as alarms.
+  This driver can also be built as a module. If so, the module
+  will be called rtc‐max6916.
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
new file mode 100644
index 000..db34a02
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -0,0 +1,6 @@
+CONFIG_MODULE_SIG=n
+obj-m+=rtc-max6916.o
+all:
+   make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
+clean:
+   make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
new file mode 100644
index 000..8e9bcdc
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,0 +1,133 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+/* Registers in max6916 rtc */
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x00
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   *data = address | 0x80;
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & MAX6916_CLOCK_BURST);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+   return rtc_valid_tm(dt);
+}
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bcd2bin(dt->tm_sec);
+   buf[2] = bcd2bin(dt->tm_min);
+   buf[3] = (bcd2bin(dt->tm_hour)_CLOCK_BURST);
+   buf[4] = bcd2bin(dt->tm_mday);
+   buf[5] = bcd2bin(dt->tm_mon + 1);
+   buf[6] = bcd2bin(dt->tm_wday + 1);
+   /* year from 1900-range of 100 in rtc from 00 to 99 */
+   dt->tm_year = dt->tm_year % 100;
+   buf[7] = bcd2bin(dt->tm_year);
+   buf[8] = bcd2bin(0x00);
+   /* write the rtc settings */
+   return spi_write_then_read(spi, buf, 9, NULL, 0);
+}
+static const struct rtc_class_ops max6916_rtc_ops = {
+   .read_time = max6916_read_time,
+   .set_time = max6916_set_time,
+};
+static int max6916_probe(struct spi_device *spi)
+{
+   struct rtc_device *rtc;
+   unsigned char data;
+   int res;
+
+   /* spi setup with max6916 in mode 3 and bits per word as 8 */
+   spi->mode = SPI_MODE_3;
+   spi->bits_per_word = 8;
+   spi_setup(spi);
+   /* RTC Settings */
+   res = max6916_read_reg(>dev, MAX6916_SECONDS_REG, );
+   if (res)
+   return res;
+   /* Disable the write protect of rtc */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   data = data & ~(1<<7);
+   max6916_write_reg(>dev, 

[PATCH] rtc:add support for maxim rtc max6916

2016-05-04 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add support for
maxim rtc max6916
Signed-off-by:Venkat Prashanth B U 
---
 Kconfig   |   9 
 Makefile  |   6 +++
 rtc-max6916.c | 133 ++
 3 files changed, 148 insertions(+)
 create mode 100644 Kconfig
 create mode 100644 Makefile
 create mode 100644 rtc-max6916.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
new file mode 100644
index 000..fa7a2fa
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -0,0 +1,9 @@
+config RTC_DRV_MAX6916
+tristate "Maxim MAX6916"
+ help
+  If you say yes here you get support for the
+  Maxim MAX6916 chips.
+  This driver only supports the RTC feature, and not other chip
+  features such as alarms.
+  This driver can also be built as a module. If so, the module
+  will be called rtc‐max6916.
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
new file mode 100644
index 000..db34a02
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -0,0 +1,6 @@
+CONFIG_MODULE_SIG=n
+obj-m+=rtc-max6916.o
+all:
+   make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
+clean:
+   make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
new file mode 100644
index 000..8e9bcdc
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -0,0 +1,133 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+/* Registers in max6916 rtc */
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x00
+
+static int max6916_read_reg(struct device *dev, unsigned char address, 
unsigned char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   *data = address | 0x80;
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char address, 
unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+
+   buf[0] = address&0x7F;
+   buf[1] = data;
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   dt->tm_sec = bcd2bin(buf[0]);
+   dt->tm_min = bcd2bin(buf[1]);
+   dt->tm_hour = bcd2bin(buf[2] & MAX6916_CLOCK_BURST);
+   dt->tm_mday = bcd2bin(buf[3]);
+   dt->tm_mon = bcd2bin(buf[4]) - 1;
+   dt->tm_wday = bcd2bin(buf[5]) - 1;
+   dt->tm_year = bcd2bin(buf[6]) + 100;
+   return rtc_valid_tm(dt);
+}
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bcd2bin(dt->tm_sec);
+   buf[2] = bcd2bin(dt->tm_min);
+   buf[3] = (bcd2bin(dt->tm_hour)_CLOCK_BURST);
+   buf[4] = bcd2bin(dt->tm_mday);
+   buf[5] = bcd2bin(dt->tm_mon + 1);
+   buf[6] = bcd2bin(dt->tm_wday + 1);
+   /* year from 1900-range of 100 in rtc from 00 to 99 */
+   dt->tm_year = dt->tm_year % 100;
+   buf[7] = bcd2bin(dt->tm_year);
+   buf[8] = bcd2bin(0x00);
+   /* write the rtc settings */
+   return spi_write_then_read(spi, buf, 9, NULL, 0);
+}
+static const struct rtc_class_ops max6916_rtc_ops = {
+   .read_time = max6916_read_time,
+   .set_time = max6916_set_time,
+};
+static int max6916_probe(struct spi_device *spi)
+{
+   struct rtc_device *rtc;
+   unsigned char data;
+   int res;
+
+   /* spi setup with max6916 in mode 3 and bits per word as 8 */
+   spi->mode = SPI_MODE_3;
+   spi->bits_per_word = 8;
+   spi_setup(spi);
+   /* RTC Settings */
+   res = max6916_read_reg(>dev, MAX6916_SECONDS_REG, );
+   if (res)
+   return res;
+   /* Disable the write protect of rtc */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   data = data & ~(1<<7);
+   max6916_write_reg(>dev, MAX6916_CONTROL_REG, data);
+   /* Enable the oscillator,disable the oscillator stop flag,and glitch 

[PATCH] rtc: add support for maxim rtc max6916

2016-05-03 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add support for
maxim rtc max6916

Signed-off-by:Venkat Prashanth B U 
---
---
 rtc-max6916.c | 157 ++
 txtfile   |  11 
 2 files changed, 168 insertions(+)
 create mode 100644 rtc-max6916.c
 create mode 100644 txtfile

diff --git a/rtc-max6916.c b/rtc-max6916.c
new file mode 100644
index 000..7fabaa2
--- /dev/null
+++ b/rtc-max6916.c
@@ -0,0 +1,157 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x00
+#define ADDRESS_REG0x70
+#define DATA_REG   0x71
+#define ADDRESS_REG_MASK   0xe0
+
+static unsigned char get_rtc(unsigned char addr)
+{
+   outb(addr, ADDRESS_REG);
+   return inb(DATA_REG);
+}
+
+static int max6916_read_reg(struct device *dev, unsigned char address,unsigned 
char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   *data = address | 0x80;
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char 
address,unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+   buf[0] = address & 0x7F;
+   buf[1] = data;
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   dt->tm_sec = get_rtc(buf[0]);
+   dt->tm_min = get_rtc(buf[1]);
+   dt->tm_hour = get_rtc(buf[2] & 0x00);
+   dt->tm_mday = get_rtc(buf[3]);
+   dt->tm_mon = get_rtc(buf[4]) - 1;
+   dt->tm_wday = get_rtc(buf[5]) - 1;
+   dt->tm_year = get_rtc(buf[6]) + 100;
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bcd2bin(dt->tm_sec);
+   buf[2] = bcd2bin(dt->tm_min);
+   buf[3] = (bcd2bin(dt->tm_hour) & 0x00);
+   buf[4] = bcd2bin(dt->tm_mday);
+   buf[5] = bcd2bin(dt->tm_mon + 1);
+   buf[6] = bcd2bin(dt->tm_wday + 1);
+
+   /* year in linux is from 1900 i.e in range of 100
+   in rtc it is from 00 to 99 */
+   dt->tm_year = dt->tm_year % 100;
+
+   buf[7] = bcd2bin(dt->tm_year);
+   buf[8] = bcd2bin(0x00);
+
+   /* write the rtc settings */
+   return spi_write_then_read(spi, buf, 9, NULL, 0);
+}
+
+static const struct rtc_class_ops max6916_rtc_ops = {
+   .read_time = max6916_read_time,
+   .set_time = max6916_set_time,
+};
+
+static int max6916_probe(struct spi_device *spi)
+{
+   struct rtc_device *rtc;
+   unsigned char data;
+   int res;
+
+   /* spi setup with max6916 in mode 3 and bits per word as 8 */
+   spi->mode = SPI_MODE_3;
+   spi->bits_per_word = 8;
+   spi_setup(spi);
+
+   /* RTC Settings */
+   res = max6916_read_reg(>dev, MAX6916_SECONDS_REG, );
+   if (res)
+   return res;
+   /* Disable the write protect of rtc */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   data = data & ~(1<<7);
+   max6916_write_reg(>dev, MAX6916_CONTROL_REG, data);
+   /* Enable the oscillator , disable the oscillator stop flag,
+and glitch filter to reduce current consumption */
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   data = data & 0x1B;
+   max6916_write_reg(>dev, MAX6916_STATUS_REG, data);
+   /* display the settings */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   dev_info(>dev, "MAX6916 RTC CTRL Reg = 0x%02x\n", data);
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   dev_info(>dev, "MAX6916 RTC Status Reg = 0x%02x\n", data);
+   rtc = devm_rtc_device_register(>dev, "max6916",_rtc_ops, 
THIS_MODULE);
+   if (IS_ERR(rtc))
+   return 

[PATCH] rtc: add support for maxim rtc max6916

2016-05-03 Thread venkat . prashanth2498
From: venkat-prashanth 

This is a patch to add support for
maxim rtc max6916

Signed-off-by:Venkat Prashanth B U 
---
---
 rtc-max6916.c | 157 ++
 txtfile   |  11 
 2 files changed, 168 insertions(+)
 create mode 100644 rtc-max6916.c
 create mode 100644 txtfile

diff --git a/rtc-max6916.c b/rtc-max6916.c
new file mode 100644
index 000..7fabaa2
--- /dev/null
+++ b/rtc-max6916.c
@@ -0,0 +1,157 @@
+/* rtc-max6916.c
+ *
+ * Driver for MAXIM  max6916 Low Current, SPI Compatible
+ * Real Time Clock
+ *
+ * Author : Venkat Prashanth B U 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers in max6916 rtc */
+
+#define MAX6916_SECONDS_REG0x01
+#define MAX6916_MINUTES_REG0x02
+#define MAX6916_HOURS_REG  0x03
+#define MAX6916_DATE_REG   0x04
+#define MAX6916_MONTH_REG  0x05
+#define MAX6916_DAY_REG0x06
+#define MAX6916_YEAR_REG   0x07
+#define MAX6916_CONTROL_REG0x08
+#define MAX6916_STATUS_REG 0x0C
+#define MAX6916_CLOCK_BURST0x00
+#define ADDRESS_REG0x70
+#define DATA_REG   0x71
+#define ADDRESS_REG_MASK   0xe0
+
+static unsigned char get_rtc(unsigned char addr)
+{
+   outb(addr, ADDRESS_REG);
+   return inb(DATA_REG);
+}
+
+static int max6916_read_reg(struct device *dev, unsigned char address,unsigned 
char *data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   *data = address | 0x80;
+   return spi_write_then_read(spi, data, 1, data, 1);
+}
+
+static int max6916_write_reg(struct device *dev, unsigned char 
address,unsigned char data)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[2];
+   buf[0] = address & 0x7F;
+   buf[1] = data;
+   return spi_write_then_read(spi, buf, 2, NULL, 0);
+}
+
+static int max6916_read_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   int err;
+   unsigned char buf[8];
+   buf[0] = MAX6916_CLOCK_BURST | 0x80;
+   err = spi_write_then_read(spi, buf, 1, buf, 8);
+   if (err)
+   return err;
+   dt->tm_sec = get_rtc(buf[0]);
+   dt->tm_min = get_rtc(buf[1]);
+   dt->tm_hour = get_rtc(buf[2] & 0x00);
+   dt->tm_mday = get_rtc(buf[3]);
+   dt->tm_mon = get_rtc(buf[4]) - 1;
+   dt->tm_wday = get_rtc(buf[5]) - 1;
+   dt->tm_year = get_rtc(buf[6]) + 100;
+   return rtc_valid_tm(dt);
+}
+
+static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+{
+   struct spi_device *spi = to_spi_device(dev);
+   unsigned char buf[9];
+
+   buf[0] = MAX6916_CLOCK_BURST & 0x7F;
+   buf[1] = bcd2bin(dt->tm_sec);
+   buf[2] = bcd2bin(dt->tm_min);
+   buf[3] = (bcd2bin(dt->tm_hour) & 0x00);
+   buf[4] = bcd2bin(dt->tm_mday);
+   buf[5] = bcd2bin(dt->tm_mon + 1);
+   buf[6] = bcd2bin(dt->tm_wday + 1);
+
+   /* year in linux is from 1900 i.e in range of 100
+   in rtc it is from 00 to 99 */
+   dt->tm_year = dt->tm_year % 100;
+
+   buf[7] = bcd2bin(dt->tm_year);
+   buf[8] = bcd2bin(0x00);
+
+   /* write the rtc settings */
+   return spi_write_then_read(spi, buf, 9, NULL, 0);
+}
+
+static const struct rtc_class_ops max6916_rtc_ops = {
+   .read_time = max6916_read_time,
+   .set_time = max6916_set_time,
+};
+
+static int max6916_probe(struct spi_device *spi)
+{
+   struct rtc_device *rtc;
+   unsigned char data;
+   int res;
+
+   /* spi setup with max6916 in mode 3 and bits per word as 8 */
+   spi->mode = SPI_MODE_3;
+   spi->bits_per_word = 8;
+   spi_setup(spi);
+
+   /* RTC Settings */
+   res = max6916_read_reg(>dev, MAX6916_SECONDS_REG, );
+   if (res)
+   return res;
+   /* Disable the write protect of rtc */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   data = data & ~(1<<7);
+   max6916_write_reg(>dev, MAX6916_CONTROL_REG, data);
+   /* Enable the oscillator , disable the oscillator stop flag,
+and glitch filter to reduce current consumption */
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   data = data & 0x1B;
+   max6916_write_reg(>dev, MAX6916_STATUS_REG, data);
+   /* display the settings */
+   max6916_read_reg(>dev, MAX6916_CONTROL_REG, );
+   dev_info(>dev, "MAX6916 RTC CTRL Reg = 0x%02x\n", data);
+   max6916_read_reg(>dev, MAX6916_STATUS_REG, );
+   dev_info(>dev, "MAX6916 RTC Status Reg = 0x%02x\n", data);
+   rtc = devm_rtc_device_register(>dev, "max6916",_rtc_ops, 
THIS_MODULE);
+   if (IS_ERR(rtc))
+   return PTR_ERR(rtc);
+   spi_set_drvdata(spi, rtc);
+
+   return 0;
+}
+static struct spi_driver