Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
lm80.c File Reference
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>

Go to the source code of this file.

Data Structures

struct  lm80_data
 

Macros

#define LM80_REG_IN_MAX(nr)   (0x2a + (nr) * 2)
 
#define LM80_REG_IN_MIN(nr)   (0x2b + (nr) * 2)
 
#define LM80_REG_IN(nr)   (0x20 + (nr))
 
#define LM80_REG_FAN1   0x28
 
#define LM80_REG_FAN2   0x29
 
#define LM80_REG_FAN_MIN(nr)   (0x3b + (nr))
 
#define LM80_REG_TEMP   0x27
 
#define LM80_REG_TEMP_HOT_MAX   0x38
 
#define LM80_REG_TEMP_HOT_HYST   0x39
 
#define LM80_REG_TEMP_OS_MAX   0x3a
 
#define LM80_REG_TEMP_OS_HYST   0x3b
 
#define LM80_REG_CONFIG   0x00
 
#define LM80_REG_ALARM1   0x01
 
#define LM80_REG_ALARM2   0x02
 
#define LM80_REG_MASK1   0x03
 
#define LM80_REG_MASK2   0x04
 
#define LM80_REG_FANDIV   0x05
 
#define LM80_REG_RES   0x06
 
#define LM96080_REG_CONV_RATE   0x07
 
#define LM96080_REG_MAN_ID   0x3e
 
#define LM96080_REG_DEV_ID   0x3f
 
#define IN_TO_REG(val)   (SENSORS_LIMIT(((val) + 5) / 10, 0, 255))
 
#define IN_FROM_REG(val)   ((val) * 10)
 
#define FAN_FROM_REG(val, div)
 
#define TEMP_LIMIT_FROM_REG(val)
 
#define TEMP_LIMIT_TO_REG(val)
 
#define DIV_FROM_REG(val)   (1 << (val))
 
#define show_in(suffix, value)
 
#define set_in(suffix, value, reg)
 
#define show_fan(suffix, value)
 
#define show_temp(suffix, value)
 
#define set_temp(suffix, value, reg)
 

Functions

 MODULE_DEVICE_TABLE (i2c, lm80_id)
 
 show_in (min, show_in(in_min)
 
 show_temp (hot_max, temp_hot_max)
 
 show_temp (hot_hyst, temp_hot_hyst)
 
 show_temp (os_max, temp_os_max)
 
 show_temp (os_hyst, temp_os_hyst)
 
 set_temp (hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX)
 
 set_temp (hot_hyst, temp_hot_hyst, LM80_REG_TEMP_HOT_HYST)
 
 set_temp (os_max, temp_os_max, LM80_REG_TEMP_OS_MAX)
 
 set_temp (os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST)
 
 module_i2c_driver (lm80_driver)
 
 MODULE_AUTHOR ("Frodo Looijaard <[email protected]> and ""Philip Edelbrock <[email protected]>")
 
 MODULE_DESCRIPTION ("LM80 driver")
 
 MODULE_LICENSE ("GPL")
 

Macro Definition Documentation

#define DIV_FROM_REG (   val)    (1 << (val))

Definition at line 108 of file lm80.c.

#define FAN_FROM_REG (   val,
  div 
)
Value:
((val) == 0 ? -1 : \
(val) == 255 ? 0 : 1350000/((div) * (val)))

Definition at line 86 of file lm80.c.

#define IN_FROM_REG (   val)    ((val) * 10)

Definition at line 76 of file lm80.c.

#define IN_TO_REG (   val)    (SENSORS_LIMIT(((val) + 5) / 10, 0, 255))

Definition at line 75 of file lm80.c.

#define LM80_REG_ALARM1   0x01

Definition at line 56 of file lm80.c.

#define LM80_REG_ALARM2   0x02

Definition at line 57 of file lm80.c.

#define LM80_REG_CONFIG   0x00

Definition at line 55 of file lm80.c.

#define LM80_REG_FAN1   0x28

Definition at line 45 of file lm80.c.

#define LM80_REG_FAN2   0x29

Definition at line 46 of file lm80.c.

#define LM80_REG_FAN_MIN (   nr)    (0x3b + (nr))

Definition at line 47 of file lm80.c.

#define LM80_REG_FANDIV   0x05

Definition at line 60 of file lm80.c.

#define LM80_REG_IN (   nr)    (0x20 + (nr))

Definition at line 43 of file lm80.c.

#define LM80_REG_IN_MAX (   nr)    (0x2a + (nr) * 2)

Definition at line 41 of file lm80.c.

#define LM80_REG_IN_MIN (   nr)    (0x2b + (nr) * 2)

Definition at line 42 of file lm80.c.

#define LM80_REG_MASK1   0x03

Definition at line 58 of file lm80.c.

#define LM80_REG_MASK2   0x04

Definition at line 59 of file lm80.c.

#define LM80_REG_RES   0x06

Definition at line 61 of file lm80.c.

#define LM80_REG_TEMP   0x27

Definition at line 49 of file lm80.c.

#define LM80_REG_TEMP_HOT_HYST   0x39

Definition at line 51 of file lm80.c.

#define LM80_REG_TEMP_HOT_MAX   0x38

Definition at line 50 of file lm80.c.

#define LM80_REG_TEMP_OS_HYST   0x3b

Definition at line 53 of file lm80.c.

#define LM80_REG_TEMP_OS_MAX   0x3a

Definition at line 52 of file lm80.c.

#define LM96080_REG_CONV_RATE   0x07

Definition at line 63 of file lm80.c.

#define LM96080_REG_DEV_ID   0x3f

Definition at line 65 of file lm80.c.

#define LM96080_REG_MAN_ID   0x3e

Definition at line 64 of file lm80.c.

#define set_in (   suffix,
  value,
  reg 
)
Value:
static ssize_t set_in_##suffix(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \
{ \
int nr = to_sensor_dev_attr(attr)->index; \
struct lm80_data *data = i2c_get_clientdata(client); \
long val; \
int err = kstrtol(buf, 10, &val); \
if (err < 0) \
return err; \
mutex_lock(&data->update_lock);\
data->value[nr] = IN_TO_REG(val); \
lm80_write_value(client, reg(nr), data->value[nr]); \
mutex_unlock(&data->update_lock);\
return count; \
}
#define set_temp (   suffix,
  value,
  reg 
)
Value:
static ssize_t set_temp_##suffix(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \
{ \
struct lm80_data *data = i2c_get_clientdata(client); \
long val; \
int err = kstrtol(buf, 10, &val); \
if (err < 0) \
return err; \
mutex_lock(&data->update_lock); \
data->value = TEMP_LIMIT_TO_REG(val); \
lm80_write_value(client, reg, data->value); \
mutex_unlock(&data->update_lock); \
return count; \
}

Definition at line 330 of file lm80.c.

#define show_fan (   suffix,
  value 
)
Value:
static ssize_t show_fan_##suffix(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
int nr = to_sensor_dev_attr(attr)->index; \
struct lm80_data *data = lm80_update_device(dev); \
if (IS_ERR(data)) \
return PTR_ERR(data); \
return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \
DIV_FROM_REG(data->fan_div[nr]))); \
}
#define show_in (   suffix,
  value 
)
Value:
static ssize_t show_in_##suffix(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
int nr = to_sensor_dev_attr(attr)->index; \
struct lm80_data *data = lm80_update_device(dev); \
if (IS_ERR(data)) \
return PTR_ERR(data); \
return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \
}

Definition at line 175 of file lm80.c.

#define show_temp (   suffix,
  value 
)
Value:
static ssize_t show_temp_##suffix(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
struct lm80_data *data = lm80_update_device(dev); \
if (IS_ERR(data)) \
return PTR_ERR(data); \
return sprintf(buf, "%d\n", TEMP_LIMIT_FROM_REG(data->value)); \
}

Definition at line 316 of file lm80.c.

#define TEMP_LIMIT_FROM_REG (   val)
Value:
(((val) > 0x80 ? \
(val) - 0x100 : (val)) * 1000)

Definition at line 102 of file lm80.c.

#define TEMP_LIMIT_TO_REG (   val)
Value:
SENSORS_LIMIT((val) < 0 ? \
((val) - 500) / 1000 : ((val) + 500) / 1000, 0, 255)

Definition at line 105 of file lm80.c.

Function Documentation

MODULE_AUTHOR ( "Frodo Looijaard <[email protected]> and ""Philip Edelbrock <[email protected]>"  )
MODULE_DESCRIPTION ( "LM80 driver )
MODULE_DEVICE_TABLE ( i2c  ,
lm80_id   
)
module_i2c_driver ( lm80_driver  )
MODULE_LICENSE ( "GPL"  )
set_temp ( hot_max  ,
temp_hot_max  ,
LM80_REG_TEMP_HOT_MAX   
)
set_temp ( hot_hyst  ,
temp_hot_hyst  ,
LM80_REG_TEMP_HOT_HYST   
)
set_temp ( os_max  ,
temp_os_max  ,
LM80_REG_TEMP_OS_MAX   
)
set_temp ( os_hyst  ,
temp_os_hyst  ,
LM80_REG_TEMP_OS_HYST   
)
show_in ( min  ,
show_in(  in_min 
)

Definition at line 185 of file lm80.c.

show_temp ( hot_max  ,
temp_hot_max   
)
show_temp ( hot_hyst  ,
temp_hot_hyst   
)
show_temp ( os_max  ,
temp_os_max   
)
show_temp ( os_hyst  ,
temp_os_hyst   
)