Commit ee85bb5b authored by Raghavendra Ganiga's avatar Raghavendra Ganiga Committed by Alexandre Belloni

rtc: ds1347: changed raw spi calls to register map calls

This patch changes calls of spi read write calls to register map
read and write calls in rtc ds1347
Signed-off-by: default avatarRaghavendra Chandra Ganiga <ravi23ganiga@gmail.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 68669d55
...@@ -665,6 +665,7 @@ config RTC_DRV_DS1343 ...@@ -665,6 +665,7 @@ config RTC_DRV_DS1343
will be called rtc-ds1343. will be called rtc-ds1343.
config RTC_DRV_DS1347 config RTC_DRV_DS1347
select REGMAP_SPI
tristate "Dallas/Maxim DS1347" tristate "Dallas/Maxim DS1347"
help help
If you say yes here you get support for the If you say yes here you get support for the
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/bcd.h> #include <linux/bcd.h>
#include <linux/regmap.h>
/* Registers in ds1347 rtc */ /* Registers in ds1347 rtc */
...@@ -32,37 +33,28 @@ ...@@ -32,37 +33,28 @@
#define DS1347_STATUS_REG 0x17 #define DS1347_STATUS_REG 0x17
#define DS1347_CLOCK_BURST 0x3F #define DS1347_CLOCK_BURST 0x3F
static int ds1347_read_reg(struct device *dev, unsigned char address, static const struct regmap_range ds1347_ranges[] = {
unsigned char *data) {
{ .range_min = DS1347_SECONDS_REG,
struct spi_device *spi = to_spi_device(dev); .range_max = DS1347_STATUS_REG,
},
*data = address | 0x80; };
return spi_write_then_read(spi, data, 1, data, 1);
}
static int ds1347_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 const struct regmap_access_table ds1347_access_table = {
} .yes_ranges = ds1347_ranges,
.n_yes_ranges = ARRAY_SIZE(ds1347_ranges),
};
static int ds1347_read_time(struct device *dev, struct rtc_time *dt) static int ds1347_read_time(struct device *dev, struct rtc_time *dt)
{ {
struct spi_device *spi = to_spi_device(dev); struct spi_device *spi = to_spi_device(dev);
struct regmap *map;
int err; int err;
unsigned char buf[8]; unsigned char buf[8];
buf[0] = DS1347_CLOCK_BURST | 0x80; map = spi_get_drvdata(spi);
err = spi_write_then_read(spi, buf, 1, buf, 8); err = regmap_bulk_read(map, DS1347_CLOCK_BURST, buf, 8);
if (err) if (err)
return err; return err;
...@@ -80,25 +72,27 @@ static int ds1347_read_time(struct device *dev, struct rtc_time *dt) ...@@ -80,25 +72,27 @@ static int ds1347_read_time(struct device *dev, struct rtc_time *dt)
static int ds1347_set_time(struct device *dev, struct rtc_time *dt) static int ds1347_set_time(struct device *dev, struct rtc_time *dt)
{ {
struct spi_device *spi = to_spi_device(dev); struct spi_device *spi = to_spi_device(dev);
unsigned char buf[9]; struct regmap *map;
unsigned char buf[8];
map = spi_get_drvdata(spi);
buf[0] = DS1347_CLOCK_BURST & 0x7F; buf[0] = bin2bcd(dt->tm_sec);
buf[1] = bin2bcd(dt->tm_sec); buf[1] = bin2bcd(dt->tm_min);
buf[2] = bin2bcd(dt->tm_min); buf[2] = (bin2bcd(dt->tm_hour) & 0x3F);
buf[3] = (bin2bcd(dt->tm_hour) & 0x3F); buf[3] = bin2bcd(dt->tm_mday);
buf[4] = bin2bcd(dt->tm_mday); buf[4] = bin2bcd(dt->tm_mon + 1);
buf[5] = bin2bcd(dt->tm_mon + 1); buf[5] = bin2bcd(dt->tm_wday + 1);
buf[6] = bin2bcd(dt->tm_wday + 1);
/* year in linux is from 1900 i.e in range of 100 /* year in linux is from 1900 i.e in range of 100
in rtc it is from 00 to 99 */ in rtc it is from 00 to 99 */
dt->tm_year = dt->tm_year % 100; dt->tm_year = dt->tm_year % 100;
buf[7] = bin2bcd(dt->tm_year); buf[6] = bin2bcd(dt->tm_year);
buf[8] = bin2bcd(0x00); buf[7] = bin2bcd(0x00);
/* write the rtc settings */ /* write the rtc settings */
return spi_write_then_read(spi, buf, 9, NULL, 0); return regmap_bulk_write(map, DS1347_CLOCK_BURST, buf, 8);
} }
static const struct rtc_class_ops ds1347_rtc_ops = { static const struct rtc_class_ops ds1347_rtc_ops = {
...@@ -109,35 +103,53 @@ static const struct rtc_class_ops ds1347_rtc_ops = { ...@@ -109,35 +103,53 @@ static const struct rtc_class_ops ds1347_rtc_ops = {
static int ds1347_probe(struct spi_device *spi) static int ds1347_probe(struct spi_device *spi)
{ {
struct rtc_device *rtc; struct rtc_device *rtc;
unsigned char data; struct regmap_config config;
struct regmap *map;
unsigned int data;
int res; int res;
memset(&config, 0, sizeof(config));
config.reg_bits = 8;
config.val_bits = 8;
config.read_flag_mask = 0x80;
config.max_register = 0x3F;
config.wr_table = &ds1347_access_table;
/* spi setup with ds1347 in mode 3 and bits per word as 8 */ /* spi setup with ds1347 in mode 3 and bits per word as 8 */
spi->mode = SPI_MODE_3; spi->mode = SPI_MODE_3;
spi->bits_per_word = 8; spi->bits_per_word = 8;
spi_setup(spi); spi_setup(spi);
map = devm_regmap_init_spi(spi, &config);
if (IS_ERR(map)) {
dev_err(&spi->dev, "ds1347 regmap init spi failed\n");
return PTR_ERR(map);
}
spi_set_drvdata(spi, map);
/* RTC Settings */ /* RTC Settings */
res = ds1347_read_reg(&spi->dev, DS1347_SECONDS_REG, &data); res = regmap_read(map, DS1347_SECONDS_REG, &data);
if (res) if (res)
return res; return res;
/* Disable the write protect of rtc */ /* Disable the write protect of rtc */
ds1347_read_reg(&spi->dev, DS1347_CONTROL_REG, &data); regmap_read(map, DS1347_CONTROL_REG, &data);
data = data & ~(1<<7); data = data & ~(1<<7);
ds1347_write_reg(&spi->dev, DS1347_CONTROL_REG, data); regmap_write(map, DS1347_CONTROL_REG, data);
/* Enable the oscillator , disable the oscillator stop flag, /* Enable the oscillator , disable the oscillator stop flag,
and glitch filter to reduce current consumption */ and glitch filter to reduce current consumption */
ds1347_read_reg(&spi->dev, DS1347_STATUS_REG, &data); regmap_read(map, DS1347_STATUS_REG, &data);
data = data & 0x1B; data = data & 0x1B;
ds1347_write_reg(&spi->dev, DS1347_STATUS_REG, data); regmap_write(map, DS1347_STATUS_REG, data);
/* display the settings */ /* display the settings */
ds1347_read_reg(&spi->dev, DS1347_CONTROL_REG, &data); regmap_read(map, DS1347_CONTROL_REG, &data);
dev_info(&spi->dev, "DS1347 RTC CTRL Reg = 0x%02x\n", data); dev_info(&spi->dev, "DS1347 RTC CTRL Reg = 0x%02x\n", data);
ds1347_read_reg(&spi->dev, DS1347_STATUS_REG, &data); regmap_read(map, DS1347_STATUS_REG, &data);
dev_info(&spi->dev, "DS1347 RTC Status Reg = 0x%02x\n", data); dev_info(&spi->dev, "DS1347 RTC Status Reg = 0x%02x\n", data);
rtc = devm_rtc_device_register(&spi->dev, "ds1347", rtc = devm_rtc_device_register(&spi->dev, "ds1347",
...@@ -146,8 +158,6 @@ static int ds1347_probe(struct spi_device *spi) ...@@ -146,8 +158,6 @@ static int ds1347_probe(struct spi_device *spi)
if (IS_ERR(rtc)) if (IS_ERR(rtc))
return PTR_ERR(rtc); return PTR_ERR(rtc);
spi_set_drvdata(spi, rtc);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment