10
10
#include <linux/of.h>
11
11
#include <linux/pm_wakeirq.h>
12
12
13
- #define REG_CONTROL1 0x00
14
- #define REG_CONTROL1_CAP_SEL BIT(7)
15
- #define REG_CONTROL1_STOP BIT(5)
16
- #define REG_CONTROL1_AIE BIT(1)
17
-
18
- #define REG_CONTROL2 0x01
19
- #define REG_CONTROL2_AF BIT(3)
20
-
21
- #define REG_CONTROL3 0x02
22
- #define REG_CONTROL3_PM_BLD BIT(7) /* battery low detection disabled */
23
- #define REG_CONTROL3_PM_VDD BIT(6) /* switch-over disabled */
24
- #define REG_CONTROL3_PM_DSM BIT(5) /* direct switching mode */
25
- #define REG_CONTROL3_PM_MASK 0xe0
26
- #define REG_CONTROL3_BLF BIT(2) /* battery low bit, read-only */
27
-
28
- #define REG_SECONDS 0x03
29
- #define REG_SECONDS_OS BIT(7)
30
-
31
- #define REG_MINUTES 0x04
32
- #define REG_HOURS 0x05
33
- #define REG_DAYS 0x06
34
- #define REG_WEEKDAYS 0x07
35
- #define REG_MONTHS 0x08
36
- #define REG_YEARS 0x09
37
-
38
- #define REG_MINUTE_ALARM 0x0a
39
- #define REG_HOUR_ALARM 0x0b
40
- #define REG_DAY_ALARM 0x0c
41
- #define REG_WEEKDAY_ALARM 0x0d
13
+ #define PCF8523_REG_CONTROL1 0x00
14
+ #define PCF8523_CONTROL1_CAP_SEL BIT(7)
15
+ #define PCF8523_CONTROL1_STOP BIT(5)
16
+ #define PCF8523_CONTROL1_AIE BIT(1)
17
+
18
+ #define PCF8523_REG_CONTROL2 0x01
19
+ #define PCF8523_CONTROL2_AF BIT(3)
20
+
21
+ #define PCF8523_REG_CONTROL3 0x02
22
+ #define PCF8523_CONTROL3_PM_BLD BIT(7) /* battery low detection disabled */
23
+ #define PCF8523_CONTROL3_PM_VDD BIT(6) /* switch-over disabled */
24
+ #define PCF8523_CONTROL3_PM_DSM BIT(5) /* direct switching mode */
25
+ #define PCF8523_CONTROL3_PM_MASK 0xe0
26
+ #define PCF8523_CONTROL3_BLF BIT(2) /* battery low bit, read-only */
27
+
28
+ #define PCF8523_REG_SECONDS 0x03
29
+ #define PCF8523_SECONDS_OS BIT(7)
30
+
31
+ #define PCF8523_REG_MINUTES 0x04
32
+ #define PCF8523_REG_HOURS 0x05
33
+ #define PCF8523_REG_DAYS 0x06
34
+ #define PCF8523_REG_WEEKDAYS 0x07
35
+ #define PCF8523_REG_MONTHS 0x08
36
+ #define PCF8523_REG_YEARS 0x09
37
+
38
+ #define PCF8523_REG_MINUTE_ALARM 0x0a
39
+ #define PCF8523_REG_HOUR_ALARM 0x0b
40
+ #define PCF8523_REG_DAY_ALARM 0x0c
41
+ #define PCF8523_REG_WEEKDAY_ALARM 0x0d
42
42
#define ALARM_DIS BIT(7)
43
43
44
- #define REG_OFFSET 0x0e
45
- #define REG_OFFSET_MODE BIT(7)
44
+ #define PCF8523_REG_OFFSET 0x0e
45
+ #define PCF8523_OFFSET_MODE BIT(7)
46
46
47
- #define REG_TMR_CLKOUT_CTRL 0x0f
47
+ #define PCF8523_TMR_CLKOUT_CTRL 0x0f
48
48
49
49
struct pcf8523 {
50
50
struct rtc_device * rtc ;
@@ -99,11 +99,11 @@ static int pcf8523_voltage_low(struct i2c_client *client)
99
99
u8 value ;
100
100
int err ;
101
101
102
- err = pcf8523_read (client , REG_CONTROL3 , & value );
102
+ err = pcf8523_read (client , PCF8523_REG_CONTROL3 , & value );
103
103
if (err < 0 )
104
104
return err ;
105
105
106
- return !!(value & REG_CONTROL3_BLF );
106
+ return !!(value & PCF8523_CONTROL3_BLF );
107
107
}
108
108
109
109
static int pcf8523_load_capacitance (struct i2c_client * client )
@@ -112,7 +112,7 @@ static int pcf8523_load_capacitance(struct i2c_client *client)
112
112
u8 value ;
113
113
int err ;
114
114
115
- err = pcf8523_read (client , REG_CONTROL1 , & value );
115
+ err = pcf8523_read (client , PCF8523_REG_CONTROL1 , & value );
116
116
if (err < 0 )
117
117
return err ;
118
118
@@ -126,14 +126,14 @@ static int pcf8523_load_capacitance(struct i2c_client *client)
126
126
load );
127
127
fallthrough ;
128
128
case 12500 :
129
- value |= REG_CONTROL1_CAP_SEL ;
129
+ value |= PCF8523_CONTROL1_CAP_SEL ;
130
130
break ;
131
131
case 7000 :
132
- value &= ~REG_CONTROL1_CAP_SEL ;
132
+ value &= ~PCF8523_CONTROL1_CAP_SEL ;
133
133
break ;
134
134
}
135
135
136
- err = pcf8523_write (client , REG_CONTROL1 , value );
136
+ err = pcf8523_write (client , PCF8523_REG_CONTROL1 , value );
137
137
138
138
return err ;
139
139
}
@@ -143,13 +143,13 @@ static int pcf8523_set_pm(struct i2c_client *client, u8 pm)
143
143
u8 value ;
144
144
int err ;
145
145
146
- err = pcf8523_read (client , REG_CONTROL3 , & value );
146
+ err = pcf8523_read (client , PCF8523_REG_CONTROL3 , & value );
147
147
if (err < 0 )
148
148
return err ;
149
149
150
- value = (value & ~REG_CONTROL3_PM_MASK ) | pm ;
150
+ value = (value & ~PCF8523_CONTROL3_PM_MASK ) | pm ;
151
151
152
- err = pcf8523_write (client , REG_CONTROL3 , value );
152
+ err = pcf8523_write (client , PCF8523_REG_CONTROL3 , value );
153
153
if (err < 0 )
154
154
return err ;
155
155
@@ -162,13 +162,13 @@ static irqreturn_t pcf8523_irq(int irq, void *dev_id)
162
162
u8 value ;
163
163
int err ;
164
164
165
- err = pcf8523_read (pcf8523 -> client , REG_CONTROL2 , & value );
165
+ err = pcf8523_read (pcf8523 -> client , PCF8523_REG_CONTROL2 , & value );
166
166
if (err < 0 )
167
167
return IRQ_HANDLED ;
168
168
169
- if (value & REG_CONTROL2_AF ) {
170
- value &= ~REG_CONTROL2_AF ;
171
- pcf8523_write (pcf8523 -> client , REG_CONTROL2 , value );
169
+ if (value & PCF8523_CONTROL2_AF ) {
170
+ value &= ~PCF8523_CONTROL2_AF ;
171
+ pcf8523_write (pcf8523 -> client , PCF8523_REG_CONTROL2 , value );
172
172
rtc_update_irq (pcf8523 -> rtc , 1 , RTC_IRQF | RTC_AF );
173
173
174
174
return IRQ_HANDLED ;
@@ -182,13 +182,13 @@ static int pcf8523_stop_rtc(struct i2c_client *client)
182
182
u8 value ;
183
183
int err ;
184
184
185
- err = pcf8523_read (client , REG_CONTROL1 , & value );
185
+ err = pcf8523_read (client , PCF8523_REG_CONTROL1 , & value );
186
186
if (err < 0 )
187
187
return err ;
188
188
189
- value |= REG_CONTROL1_STOP ;
189
+ value |= PCF8523_CONTROL1_STOP ;
190
190
191
- err = pcf8523_write (client , REG_CONTROL1 , value );
191
+ err = pcf8523_write (client , PCF8523_REG_CONTROL1 , value );
192
192
if (err < 0 )
193
193
return err ;
194
194
@@ -200,13 +200,13 @@ static int pcf8523_start_rtc(struct i2c_client *client)
200
200
u8 value ;
201
201
int err ;
202
202
203
- err = pcf8523_read (client , REG_CONTROL1 , & value );
203
+ err = pcf8523_read (client , PCF8523_REG_CONTROL1 , & value );
204
204
if (err < 0 )
205
205
return err ;
206
206
207
- value &= ~REG_CONTROL1_STOP ;
207
+ value &= ~PCF8523_CONTROL1_STOP ;
208
208
209
- err = pcf8523_write (client , REG_CONTROL1 , value );
209
+ err = pcf8523_write (client , PCF8523_REG_CONTROL1 , value );
210
210
if (err < 0 )
211
211
return err ;
212
212
@@ -216,7 +216,7 @@ static int pcf8523_start_rtc(struct i2c_client *client)
216
216
static int pcf8523_rtc_read_time (struct device * dev , struct rtc_time * tm )
217
217
{
218
218
struct i2c_client * client = to_i2c_client (dev );
219
- u8 start = REG_SECONDS , regs [7 ];
219
+ u8 start = PCF8523_REG_SECONDS , regs [7 ];
220
220
struct i2c_msg msgs [2 ];
221
221
int err ;
222
222
@@ -242,7 +242,7 @@ static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
242
242
if (err < 0 )
243
243
return err ;
244
244
245
- if (regs [0 ] & REG_SECONDS_OS )
245
+ if (regs [0 ] & PCF8523_SECONDS_OS )
246
246
return - EINVAL ;
247
247
248
248
tm -> tm_sec = bcd2bin (regs [0 ] & 0x7f );
@@ -267,8 +267,8 @@ static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
267
267
if (err < 0 )
268
268
return err ;
269
269
270
- regs [0 ] = REG_SECONDS ;
271
- /* This will purposely overwrite REG_SECONDS_OS */
270
+ regs [0 ] = PCF8523_REG_SECONDS ;
271
+ /* This will purposely overwrite PCF8523_SECONDS_OS */
272
272
regs [1 ] = bin2bcd (tm -> tm_sec );
273
273
regs [2 ] = bin2bcd (tm -> tm_min );
274
274
regs [3 ] = bin2bcd (tm -> tm_hour );
@@ -299,7 +299,7 @@ static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
299
299
static int pcf8523_rtc_read_alarm (struct device * dev , struct rtc_wkalrm * tm )
300
300
{
301
301
struct i2c_client * client = to_i2c_client (dev );
302
- u8 start = REG_MINUTE_ALARM , regs [4 ];
302
+ u8 start = PCF8523_REG_MINUTE_ALARM , regs [4 ];
303
303
struct i2c_msg msgs [2 ];
304
304
u8 value ;
305
305
int err ;
@@ -324,15 +324,15 @@ static int pcf8523_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
324
324
tm -> time .tm_mday = bcd2bin (regs [2 ] & 0x3F );
325
325
tm -> time .tm_wday = bcd2bin (regs [3 ] & 0x7 );
326
326
327
- err = pcf8523_read (client , REG_CONTROL1 , & value );
327
+ err = pcf8523_read (client , PCF8523_REG_CONTROL1 , & value );
328
328
if (err < 0 )
329
329
return err ;
330
- tm -> enabled = !!(value & REG_CONTROL1_AIE );
330
+ tm -> enabled = !!(value & PCF8523_CONTROL1_AIE );
331
331
332
- err = pcf8523_read (client , REG_CONTROL2 , & value );
332
+ err = pcf8523_read (client , PCF8523_REG_CONTROL2 , & value );
333
333
if (err < 0 )
334
334
return err ;
335
- tm -> pending = !!(value & REG_CONTROL2_AF );
335
+ tm -> pending = !!(value & PCF8523_CONTROL2_AF );
336
336
337
337
return 0 ;
338
338
}
@@ -343,16 +343,16 @@ static int pcf8523_irq_enable(struct device *dev, unsigned int enabled)
343
343
u8 value ;
344
344
int err ;
345
345
346
- err = pcf8523_read (client , REG_CONTROL1 , & value );
346
+ err = pcf8523_read (client , PCF8523_REG_CONTROL1 , & value );
347
347
if (err < 0 )
348
348
return err ;
349
349
350
- value &= REG_CONTROL1_AIE ;
350
+ value &= PCF8523_CONTROL1_AIE ;
351
351
352
352
if (enabled )
353
- value |= REG_CONTROL1_AIE ;
353
+ value |= PCF8523_CONTROL1_AIE ;
354
354
355
- err = pcf8523_write (client , REG_CONTROL1 , value );
355
+ err = pcf8523_write (client , PCF8523_REG_CONTROL1 , value );
356
356
if (err < 0 )
357
357
return err ;
358
358
@@ -370,7 +370,7 @@ static int pcf8523_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
370
370
if (err )
371
371
return err ;
372
372
373
- err = pcf8523_write (client , REG_CONTROL2 , 0 );
373
+ err = pcf8523_write (client , PCF8523_REG_CONTROL2 , 0 );
374
374
if (err < 0 )
375
375
return err ;
376
376
@@ -382,7 +382,7 @@ static int pcf8523_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
382
382
rtc_time64_to_tm (alarm_time , & tm -> time );
383
383
}
384
384
385
- regs [0 ] = REG_MINUTE_ALARM ;
385
+ regs [0 ] = PCF8523_REG_MINUTE_ALARM ;
386
386
regs [1 ] = bin2bcd (tm -> time .tm_min );
387
387
regs [2 ] = bin2bcd (tm -> time .tm_hour );
388
388
regs [3 ] = bin2bcd (tm -> time .tm_mday );
@@ -418,11 +418,11 @@ static int pcf8523_rtc_ioctl(struct device *dev, unsigned int cmd,
418
418
if (ret )
419
419
flags |= RTC_VL_BACKUP_LOW ;
420
420
421
- ret = pcf8523_read (client , REG_SECONDS , & value );
421
+ ret = pcf8523_read (client , PCF8523_REG_SECONDS , & value );
422
422
if (ret < 0 )
423
423
return ret ;
424
424
425
- if (value & REG_SECONDS_OS )
425
+ if (value & PCF8523_SECONDS_OS )
426
426
flags |= RTC_VL_DATA_INVALID ;
427
427
428
428
return put_user (flags , (unsigned int __user * )arg );
@@ -442,13 +442,13 @@ static int pcf8523_rtc_read_offset(struct device *dev, long *offset)
442
442
u8 value ;
443
443
s8 val ;
444
444
445
- err = pcf8523_read (client , REG_OFFSET , & value );
445
+ err = pcf8523_read (client , PCF8523_REG_OFFSET , & value );
446
446
if (err < 0 )
447
447
return err ;
448
448
449
449
/* sign extend the 7-bit offset value */
450
450
val = value << 1 ;
451
- * offset = (value & REG_OFFSET_MODE ? 4069 : 4340 ) * (val >> 1 );
451
+ * offset = (value & PCF8523_OFFSET_MODE ? 4069 : 4340 ) * (val >> 1 );
452
452
453
453
return 0 ;
454
454
}
@@ -465,9 +465,9 @@ static int pcf8523_rtc_set_offset(struct device *dev, long offset)
465
465
if (abs (reg_m0 * 4340 - offset ) < abs (reg_m1 * 4069 - offset ))
466
466
value = reg_m0 & 0x7f ;
467
467
else
468
- value = (reg_m1 & 0x7f ) | REG_OFFSET_MODE ;
468
+ value = (reg_m1 & 0x7f ) | PCF8523_OFFSET_MODE ;
469
469
470
- return pcf8523_write (client , REG_OFFSET , value );
470
+ return pcf8523_write (client , PCF8523_REG_OFFSET , value );
471
471
}
472
472
473
473
static const struct rtc_class_ops pcf8523_rtc_ops = {
@@ -519,7 +519,7 @@ static int pcf8523_probe(struct i2c_client *client,
519
519
rtc -> uie_unsupported = 1 ;
520
520
521
521
if (client -> irq > 0 ) {
522
- err = pcf8523_write (client , REG_TMR_CLKOUT_CTRL , 0x38 );
522
+ err = pcf8523_write (client , PCF8523_TMR_CLKOUT_CTRL , 0x38 );
523
523
if (err < 0 )
524
524
return err ;
525
525
0 commit comments