Skip to content

Commit eb86c30

Browse files
Wolfram Sangtorvalds
authored andcommitted
rtc: ds1307: add trickle charger support
Some DS13XX devices have "trickle chargers". Its configuration register is at different locations, the setup is the same, though. Since the configuration is board specific, introduce a platform_data to this driver. Tested with a DS1339 on a custom board. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Cc: Alessandro Zummo <alessandro.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f8ae970 commit eb86c30

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎drivers/rtc/rtc-ds1307.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
#include <linux/string.h>
1818
#include <linux/rtc.h>
1919
#include <linux/bcd.h>
20-
21-
20+
#include <linux/rtc/ds1307.h>
2221

2322
/*
2423
* We can't determine type by probing, but if we expect pre-Linux code
@@ -92,7 +91,8 @@ enum ds_type {
9291
# define DS1337_BIT_A2I 0x02
9392
# define DS1337_BIT_A1I 0x01
9493
#define DS1339_REG_ALARM1_SECS 0x07
95-
#define DS1339_REG_TRICKLE 0x10
94+
95+
#define DS13XX_TRICKLE_CHARGER_MAGIC 0xa0
9696

9797
#define RX8025_REG_CTRL1 0x0e
9898
# define RX8025_BIT_2412 0x20
@@ -124,6 +124,7 @@ struct chip_desc {
124124
unsigned alarm:1;
125125
u16 nvram_offset;
126126
u16 nvram_size;
127+
u16 trickle_charger_reg;
127128
};
128129

129130
static const struct chip_desc chips[last_ds_type] = {
@@ -140,6 +141,13 @@ static const struct chip_desc chips[last_ds_type] = {
140141
},
141142
[ds_1339] = {
142143
.alarm = 1,
144+
.trickle_charger_reg = 0x10,
145+
},
146+
[ds_1340] = {
147+
.trickle_charger_reg = 0x08,
148+
},
149+
[ds_1388] = {
150+
.trickle_charger_reg = 0x0a,
143151
},
144152
[ds_3231] = {
145153
.alarm = 1,
@@ -619,6 +627,7 @@ static int __devinit ds1307_probe(struct i2c_client *client,
619627
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
620628
int want_irq = false;
621629
unsigned char *buf;
630+
struct ds1307_platform_data *pdata = client->dev.platform_data;
622631
static const int bbsqi_bitpos[] = {
623632
[ds_1337] = 0,
624633
[ds_1339] = DS1339_BIT_BBSQI,
@@ -638,6 +647,10 @@ static int __devinit ds1307_probe(struct i2c_client *client,
638647
ds1307->client = client;
639648
ds1307->type = id->driver_data;
640649

650+
if (pdata && pdata->trickle_charger_setup && chip->trickle_charger_reg)
651+
i2c_smbus_write_byte_data(client, chip->trickle_charger_reg,
652+
DS13XX_TRICKLE_CHARGER_MAGIC | pdata->trickle_charger_setup);
653+
641654
buf = ds1307->regs;
642655
if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
643656
ds1307->read_block_data = i2c_smbus_read_i2c_block_data;

‎include/linux/rtc/ds1307.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* ds1307.h - platform_data for the ds1307 (and variants) rtc driver
3+
* (C) Copyright 2012 by Wolfram Sang, Pengutronix e.K.
4+
* same license as the driver
5+
*/
6+
7+
#ifndef _LINUX_DS1307_H
8+
#define _LINUX_DS1307_H
9+
10+
#include <linux/types.h>
11+
12+
#define DS1307_TRICKLE_CHARGER_250_OHM 0x01
13+
#define DS1307_TRICKLE_CHARGER_2K_OHM 0x02
14+
#define DS1307_TRICKLE_CHARGER_4K_OHM 0x03
15+
#define DS1307_TRICKLE_CHARGER_NO_DIODE 0x04
16+
#define DS1307_TRICKLE_CHARGER_DIODE 0x08
17+
18+
struct ds1307_platform_data {
19+
u8 trickle_charger_setup;
20+
};
21+
22+
#endif /* _LINUX_DS1307_H */

0 commit comments

Comments
 (0)