15
15
static const unsigned short
16
16
emc2305_normal_i2c [] = { 0x27 , 0x2c , 0x2d , 0x2e , 0x2f , 0x4c , 0x4d , I2C_CLIENT_END };
17
17
18
+ #define EMC2305_REG_FAN_STATUS 0x24
19
+ #define EMC2305_REG_FAN_STALL_STATUS 0x25
18
20
#define EMC2305_REG_DRIVE_FAIL_STATUS 0x27
19
21
#define EMC2305_REG_VENDOR 0xfe
20
22
#define EMC2305_FAN_MAX 0xff
21
23
#define EMC2305_FAN_MIN 0x00
22
24
#define EMC2305_FAN_MAX_STATE 10
23
- #define EMC2305_DEVICE 0x34
24
25
#define EMC2305_VENDOR 0x5d
25
26
#define EMC2305_REG_PRODUCT_ID 0xfd
26
27
#define EMC2305_TACH_REGS_UNUSE_BITS 3
@@ -39,6 +40,7 @@ emc2305_normal_i2c[] = { 0x27, 0x2c, 0x2d, 0x2e, 0x2f, 0x4c, 0x4d, I2C_CLIENT_EN
39
40
#define EMC2305_RPM_FACTOR 3932160
40
41
41
42
#define EMC2305_REG_FAN_DRIVE (n ) (0x30 + 0x10 * (n))
43
+ #define EMC2305_REG_FAN_CFG (n ) (0x32 + 0x10 * (n))
42
44
#define EMC2305_REG_FAN_MIN_DRIVE (n ) (0x38 + 0x10 * (n))
43
45
#define EMC2305_REG_FAN_TACH (n ) (0x3e + 0x10 * (n))
44
46
@@ -58,6 +60,15 @@ static const struct i2c_device_id emc2305_ids[] = {
58
60
};
59
61
MODULE_DEVICE_TABLE (i2c , emc2305_ids );
60
62
63
+ static const struct of_device_id emc2305_dt_ids [] = {
64
+ { .compatible = "microchip,emc2305" },
65
+ { .compatible = "microchip,emc2303" },
66
+ { .compatible = "microchip,emc2302" },
67
+ { .compatible = "microchip,emc2301" },
68
+ { }
69
+ };
70
+ MODULE_DEVICE_TABLE (of , emc2305_dt_ids );
71
+
61
72
/**
62
73
* @cdev: cooling device;
63
74
* @curr_state: cooling current state;
@@ -101,6 +112,7 @@ struct emc2305_data {
101
112
u8 pwm_num ;
102
113
bool pwm_separate ;
103
114
u8 pwm_min [EMC2305_PWM_MAX ];
115
+ u8 pwm_max ;
104
116
struct emc2305_cdev_data cdev_data [EMC2305_PWM_MAX ];
105
117
};
106
118
@@ -273,7 +285,7 @@ static int emc2305_set_pwm(struct device *dev, long val, int channel)
273
285
struct i2c_client * client = data -> client ;
274
286
int ret ;
275
287
276
- if (val < data -> pwm_min [channel ] || val > EMC2305_FAN_MAX )
288
+ if (val < data -> pwm_min [channel ] || val > data -> pwm_max )
277
289
return - EINVAL ;
278
290
279
291
ret = i2c_smbus_write_byte_data (client , EMC2305_REG_FAN_DRIVE (channel ), val );
@@ -284,6 +296,49 @@ static int emc2305_set_pwm(struct device *dev, long val, int channel)
284
296
return 0 ;
285
297
}
286
298
299
+ static int emc2305_get_tz_of (struct device * dev )
300
+ {
301
+ struct device_node * np = dev -> of_node ;
302
+ struct emc2305_data * data = dev_get_drvdata (dev );
303
+ int ret = 0 ;
304
+ u32 val ;
305
+ int i ;
306
+
307
+ /* OF parameters are optional - overwrite default setting
308
+ * if some of them are provided.
309
+ */
310
+
311
+ ret = of_property_read_u32 (np , "emc2305,cooling-levels" , & val );
312
+ if (!ret )
313
+ data -> max_state = (u8 )val ;
314
+ else if (ret != - EINVAL )
315
+ return ret ;
316
+
317
+ ret = of_property_read_u32 (np , "emc2305,pwm-max" , & val );
318
+ if (!ret )
319
+ data -> pwm_max = (u8 )val ;
320
+ else if (ret != - EINVAL )
321
+ return ret ;
322
+
323
+ ret = of_property_read_u32 (np , "emc2305,pwm-min" , & val );
324
+ if (!ret )
325
+ for (i = 0 ; i < EMC2305_PWM_MAX ; i ++ )
326
+ data -> pwm_min [i ] = (u8 )val ;
327
+ else if (ret != - EINVAL )
328
+ return ret ;
329
+
330
+ /* Not defined or 0 means one thermal zone over all cooling devices.
331
+ * Otherwise - separated thermal zones for each PWM channel.
332
+ */
333
+ ret = of_property_read_u32 (np , "emc2305,pwm-channel" , & val );
334
+ if (!ret )
335
+ data -> pwm_separate = (val != 0 );
336
+ else if (ret != - EINVAL )
337
+ return ret ;
338
+
339
+ return 0 ;
340
+ }
341
+
287
342
static int emc2305_set_single_tz (struct device * dev , int idx )
288
343
{
289
344
struct emc2305_data * data = dev_get_drvdata (dev );
@@ -572,11 +627,18 @@ static int emc2305_probe(struct i2c_client *client, const struct i2c_device_id *
572
627
data -> pwm_separate = pdata -> pwm_separate ;
573
628
for (i = 0 ; i < EMC2305_PWM_MAX ; i ++ )
574
629
data -> pwm_min [i ] = pdata -> pwm_min [i ];
630
+ data -> pwm_max = EMC2305_FAN_MAX ;
575
631
} else {
576
632
data -> max_state = EMC2305_FAN_MAX_STATE ;
577
633
data -> pwm_separate = false;
578
634
for (i = 0 ; i < EMC2305_PWM_MAX ; i ++ )
579
635
data -> pwm_min [i ] = EMC2305_FAN_MIN ;
636
+ data -> pwm_max = EMC2305_FAN_MAX ;
637
+ if (dev -> of_node ) {
638
+ ret = emc2305_get_tz_of (dev );
639
+ if (ret < 0 )
640
+ return ret ;
641
+ }
580
642
}
581
643
582
644
data -> hwmon_dev = devm_hwmon_device_register_with_info (dev , "emc2305" , data ,
@@ -597,6 +659,12 @@ static int emc2305_probe(struct i2c_client *client, const struct i2c_device_id *
597
659
return ret ;
598
660
}
599
661
662
+ /* Acknowledge any existing faults. Stops the device responding on the
663
+ * SMBus alert address.
664
+ */
665
+ i2c_smbus_read_byte_data (client , EMC2305_REG_FAN_STALL_STATUS );
666
+ i2c_smbus_read_byte_data (client , EMC2305_REG_FAN_STATUS );
667
+
600
668
return 0 ;
601
669
}
602
670
@@ -612,6 +680,7 @@ static struct i2c_driver emc2305_driver = {
612
680
.class = I2C_CLASS_HWMON ,
613
681
.driver = {
614
682
.name = "emc2305" ,
683
+ .of_match_table = emc2305_dt_ids ,
615
684
},
616
685
.probe = emc2305_probe ,
617
686
.remove = emc2305_remove ,
0 commit comments