6060#define RX8025_ADJ_DATA_MAX 62
6161#define RX8025_ADJ_DATA_MIN -62
6262
63+ enum rx_model {
64+ model_rx_unknown ,
65+ model_rx_8025 ,
66+ model_rx_8035 ,
67+ model_last
68+ };
69+
6370static const struct i2c_device_id rx8025_id [] = {
64- { "rx8025" , 0 },
71+ { "rx8025" , model_rx_8025 },
72+ { "rx8035" , model_rx_8035 },
6573 { }
6674};
6775MODULE_DEVICE_TABLE (i2c , rx8025_id );
6876
6977struct rx8025_data {
7078 struct rtc_device * rtc ;
79+ enum rx_model model ;
7180 u8 ctrl1 ;
7281};
7382
@@ -100,10 +109,26 @@ static s32 rx8025_write_regs(const struct i2c_client *client,
100109 length , values );
101110}
102111
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+
103126static int rx8025_check_validity (struct device * dev )
104127{
105128 struct i2c_client * client = to_i2c_client (dev );
129+ struct rx8025_data * drvdata = dev_get_drvdata (dev );
106130 int ctrl2 ;
131+ int xstp ;
107132
108133 ctrl2 = rx8025_read_reg (client , RX8025_REG_CTRL2 );
109134 if (ctrl2 < 0 )
@@ -117,7 +142,8 @@ static int rx8025_check_validity(struct device *dev)
117142 return - EINVAL ;
118143 }
119144
120- if (!(ctrl2 & RX8025_BIT_CTRL2_XST )) {
145+ xstp = rx8025_is_osc_stopped (drvdata -> model , ctrl2 );
146+ if (xstp ) {
121147 dev_warn (dev , "crystal stopped, date is invalid\n" );
122148 return - EINVAL ;
123149 }
@@ -127,29 +153,36 @@ static int rx8025_check_validity(struct device *dev)
127153
128154static int rx8025_reset_validity (struct i2c_client * client )
129155{
156+ struct rx8025_data * drvdata = i2c_get_clientdata (client );
130157 int ctrl2 = rx8025_read_reg (client , RX8025_REG_CTRL2 );
131158
132159 if (ctrl2 < 0 )
133160 return ctrl2 ;
134161
135162 ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET );
136163
164+ if (drvdata -> model == model_rx_8025 )
165+ ctrl2 |= RX8025_BIT_CTRL2_XST ;
166+ else
167+ ctrl2 &= ~(RX8025_BIT_CTRL2_XST );
168+
137169 return rx8025_write_reg (client , RX8025_REG_CTRL2 ,
138- ctrl2 | RX8025_BIT_CTRL2_XST );
170+ ctrl2 );
139171}
140172
141173static irqreturn_t rx8025_handle_irq (int irq , void * dev_id )
142174{
143175 struct i2c_client * client = dev_id ;
144176 struct rx8025_data * rx8025 = i2c_get_clientdata (client );
145- int status ;
177+ int status , xstp ;
146178
147179 rtc_lock (rx8025 -> rtc );
148180 status = rx8025_read_reg (client , RX8025_REG_CTRL2 );
149181 if (status < 0 )
150182 goto out ;
151183
152- if (!(status & RX8025_BIT_CTRL2_XST ))
184+ xstp = rx8025_is_osc_stopped (rx8025 -> model , status );
185+ if (xstp )
153186 dev_warn (& client -> dev , "Oscillation stop was detected,"
154187 "you may have to readjust the clock\n" );
155188
@@ -519,6 +552,9 @@ static int rx8025_probe(struct i2c_client *client,
519552
520553 i2c_set_clientdata (client , rx8025 );
521554
555+ if (id )
556+ rx8025 -> model = id -> driver_data ;
557+
522558 err = rx8025_init_client (client );
523559 if (err )
524560 return err ;
0 commit comments