60
60
#define RX8025_ADJ_DATA_MAX 62
61
61
#define RX8025_ADJ_DATA_MIN -62
62
62
63
+ enum rx_model {
64
+ model_rx_unknown ,
65
+ model_rx_8025 ,
66
+ model_rx_8035 ,
67
+ model_last
68
+ };
69
+
63
70
static const struct i2c_device_id rx8025_id [] = {
64
- { "rx8025" , 0 },
71
+ { "rx8025" , model_rx_8025 },
72
+ { "rx8035" , model_rx_8035 },
65
73
{ }
66
74
};
67
75
MODULE_DEVICE_TABLE (i2c , rx8025_id );
68
76
69
77
struct rx8025_data {
70
78
struct rtc_device * rtc ;
79
+ enum rx_model model ;
71
80
u8 ctrl1 ;
72
81
};
73
82
@@ -100,10 +109,26 @@ static s32 rx8025_write_regs(const struct i2c_client *client,
100
109
length , values );
101
110
}
102
111
112
+ static int rx8025_is_osc_stopped (enum rx_model model , int ctrl2 )
113
+ {
114
+ int xstp = ctrl2 & RX8025_BIT_CTRL2_XST ;
115
+ /* XSTP bit has different polarity on RX-8025 vs RX-8035.
116
+ * RX-8025: 0 == oscillator stopped
117
+ * RX-8035: 1 == oscillator stopped
118
+ */
119
+
120
+ if (model == model_rx_8025 )
121
+ xstp = !xstp ;
122
+
123
+ return xstp ;
124
+ }
125
+
103
126
static int rx8025_check_validity (struct device * dev )
104
127
{
105
128
struct i2c_client * client = to_i2c_client (dev );
129
+ struct rx8025_data * drvdata = dev_get_drvdata (dev );
106
130
int ctrl2 ;
131
+ int xstp ;
107
132
108
133
ctrl2 = rx8025_read_reg (client , RX8025_REG_CTRL2 );
109
134
if (ctrl2 < 0 )
@@ -117,7 +142,8 @@ static int rx8025_check_validity(struct device *dev)
117
142
return - EINVAL ;
118
143
}
119
144
120
- if (!(ctrl2 & RX8025_BIT_CTRL2_XST )) {
145
+ xstp = rx8025_is_osc_stopped (drvdata -> model , ctrl2 );
146
+ if (xstp ) {
121
147
dev_warn (dev , "crystal stopped, date is invalid\n" );
122
148
return - EINVAL ;
123
149
}
@@ -127,29 +153,36 @@ static int rx8025_check_validity(struct device *dev)
127
153
128
154
static int rx8025_reset_validity (struct i2c_client * client )
129
155
{
156
+ struct rx8025_data * drvdata = i2c_get_clientdata (client );
130
157
int ctrl2 = rx8025_read_reg (client , RX8025_REG_CTRL2 );
131
158
132
159
if (ctrl2 < 0 )
133
160
return ctrl2 ;
134
161
135
162
ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET );
136
163
164
+ if (drvdata -> model == model_rx_8025 )
165
+ ctrl2 |= RX8025_BIT_CTRL2_XST ;
166
+ else
167
+ ctrl2 &= ~(RX8025_BIT_CTRL2_XST );
168
+
137
169
return rx8025_write_reg (client , RX8025_REG_CTRL2 ,
138
- ctrl2 | RX8025_BIT_CTRL2_XST );
170
+ ctrl2 );
139
171
}
140
172
141
173
static irqreturn_t rx8025_handle_irq (int irq , void * dev_id )
142
174
{
143
175
struct i2c_client * client = dev_id ;
144
176
struct rx8025_data * rx8025 = i2c_get_clientdata (client );
145
- int status ;
177
+ int status , xstp ;
146
178
147
179
rtc_lock (rx8025 -> rtc );
148
180
status = rx8025_read_reg (client , RX8025_REG_CTRL2 );
149
181
if (status < 0 )
150
182
goto out ;
151
183
152
- if (!(status & RX8025_BIT_CTRL2_XST ))
184
+ xstp = rx8025_is_osc_stopped (rx8025 -> model , status );
185
+ if (xstp )
153
186
dev_warn (& client -> dev , "Oscillation stop was detected,"
154
187
"you may have to readjust the clock\n" );
155
188
@@ -519,6 +552,9 @@ static int rx8025_probe(struct i2c_client *client,
519
552
520
553
i2c_set_clientdata (client , rx8025 );
521
554
555
+ if (id )
556
+ rx8025 -> model = id -> driver_data ;
557
+
522
558
err = rx8025_init_client (client );
523
559
if (err )
524
560
return err ;
0 commit comments