Skip to content

Commit fd9a6a1

Browse files
JC-WValexandrebelloni
authored andcommitted
rtc: pcf85363: add support for the quartz-load-femtofarads property
The quartz oscillator load capacitance of the PCF85263 and PCF85363 can be adjusted to 6 pF, 7 pF (default) and 12.5 pF with the CL[1:0] bits in the oscillator control register (address 25h). Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 1b2f85a commit fd9a6a1

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

drivers/rtc/rtc-pcf85363.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
#define PIN_IO_INTA_OUT 2
102102
#define PIN_IO_INTA_HIZ 3
103103

104+
#define OSC_CAP_SEL GENMASK(1, 0)
105+
#define OSC_CAP_6000 0x01
106+
#define OSC_CAP_12500 0x02
107+
104108
#define STOP_EN_STOP BIT(0)
105109

106110
#define RESET_CPR 0xa4
@@ -117,6 +121,32 @@ struct pcf85x63_config {
117121
unsigned int num_nvram;
118122
};
119123

124+
static int pcf85363_load_capacitance(struct pcf85363 *pcf85363, struct device_node *node)
125+
{
126+
u32 load = 7000;
127+
u8 value = 0;
128+
129+
of_property_read_u32(node, "quartz-load-femtofarads", &load);
130+
131+
switch (load) {
132+
default:
133+
dev_warn(&pcf85363->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000",
134+
load);
135+
fallthrough;
136+
case 7000:
137+
break;
138+
case 6000:
139+
value = OSC_CAP_6000;
140+
break;
141+
case 12500:
142+
value = OSC_CAP_12500;
143+
break;
144+
}
145+
146+
return regmap_update_bits(pcf85363->regmap, CTRL_OSCILLATOR,
147+
OSC_CAP_SEL, value);
148+
}
149+
120150
static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm)
121151
{
122152
struct pcf85363 *pcf85363 = dev_get_drvdata(dev);
@@ -372,7 +402,7 @@ static int pcf85363_probe(struct i2c_client *client)
372402
.reg_write = pcf85363_nvram_write,
373403
},
374404
};
375-
int ret, i;
405+
int ret, i, err;
376406

377407
if (data)
378408
config = data;
@@ -394,6 +424,11 @@ static int pcf85363_probe(struct i2c_client *client)
394424
if (IS_ERR(pcf85363->rtc))
395425
return PTR_ERR(pcf85363->rtc);
396426

427+
err = pcf85363_load_capacitance(pcf85363, client->dev.of_node);
428+
if (err < 0)
429+
dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
430+
err);
431+
397432
pcf85363->rtc->ops = &rtc_ops;
398433
pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
399434
pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;

0 commit comments

Comments
 (0)