[devices]: enable sonic-platform-modules-cel

This commit is contained in:
Guohan Lu 2018-02-16 03:53:12 +00:00
parent f489bea105
commit ec9dc57704
7 changed files with 351 additions and 339 deletions

View File

@ -6,7 +6,7 @@ include $(PLATFORM_PATH)/platform-modules-dell.mk
include $(PLATFORM_PATH)/platform-modules-ingrasys.mk
include $(PLATFORM_PATH)/platform-modules-accton.mk
include $(PLATFORM_PATH)/platform-modules-inventec.mk
#include $(PLATFORM_PATH)/platform-modules-cel.mk
include $(PLATFORM_PATH)/platform-modules-cel.mk
#include $(PLATFORM_PATH)/platform-modules-delta.mk
include $(PLATFORM_PATH)/platform-modules-quanta.mk
#include $(PLATFORM_PATH)/platform-modules-mitac.mk

View File

@ -7,6 +7,9 @@
# Precompiled Headers
*.gch
*.pch
*.mod.c
*.ko.cmd
*.o.cmd
# Libraries
*.lib

View File

@ -7,6 +7,6 @@ Standards-Version: 3.9.3
Package: platform-modules-dx010
Architecture: amd64
Depends: linux-image-3.16.0-5-amd64
Depends: linux-image-4.9.0-5-amd64
Description: kernel modules for platform devices such as fan, led, sfp

View File

View File

@ -1 +1,6 @@
obj-m := dx010_cpld.o mc24lc64t.o emc2305.o dx010_wdt.o leds-dx010.o lm75.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

View File

@ -37,26 +37,26 @@
*/
enum lm75_type { /* keep sorted in alphabetical order */
adt75,
ds1775,
ds75,
ds7505,
g751,
lm75,
lm75a,
lm75b,
max6625,
max6626,
mcp980x,
stds75,
tcn75,
tmp100,
tmp101,
tmp105,
tmp112,
tmp175,
tmp275,
tmp75,
adt75,
ds1775,
ds75,
ds7505,
g751,
lm75,
lm75a,
lm75b,
max6625,
max6626,
mcp980x,
stds75,
tcn75,
tmp100,
tmp101,
tmp105,
tmp112,
tmp175,
tmp275,
tmp75,
};
/* Addresses scanned */
@ -66,14 +66,14 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
/* The LM75 registers */
#define LM75_REG_CONF 0x01
static const u8 LM75_REG_TEMP[3] = {
static const u8 LM75_REG_TEMP[3] = {
0x00, /* input */
0x03, /* max */
0x02, /* hyst */
};
};
/* Each client has this additional data */
struct lm75_data {
struct lm75_data {
struct i2c_client *client;
struct device *hwmon_dev;
struct thermal_zone_device *tz;
@ -88,24 +88,24 @@ struct lm75_data {
0 = input
1 = max
2 = hyst */
};
};
static int lm75_read_value(struct i2c_client *client, u8 reg);
static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value);
static struct lm75_data *lm75_update_device(struct device *dev);
static int lm75_read_value(struct i2c_client *client, u8 reg);
static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value);
static struct lm75_data *lm75_update_device(struct device *dev);
/*-----------------------------------------------------------------------*/
static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
{
static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
{
return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
}
}
/* sysfs attributes for hwmon */
static int lm75_read_temp(void *dev, long *temp)
{
static int lm75_read_temp(void *dev, int *temp)
{
struct lm75_data *data = lm75_update_device(dev);
if (IS_ERR(data))
@ -114,11 +114,11 @@ static int lm75_read_temp(void *dev, long *temp)
*temp = lm75_reg_to_mc(data->temp[0], data->resolution);
return 0;
}
}
static ssize_t show_temp(struct device *dev, struct device_attribute *da,
static ssize_t show_temp(struct device *dev, struct device_attribute *da,
char *buf)
{
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct lm75_data *data = lm75_update_device(dev);
@ -127,11 +127,11 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da,
return sprintf(buf, "%ld\n", lm75_reg_to_mc(data->temp[attr->index],
data->resolution));
}
}
static ssize_t set_temp(struct device *dev, struct device_attribute *da,
static ssize_t set_temp(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct lm75_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
@ -160,30 +160,34 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
lm75_write_value(client, LM75_REG_TEMP[nr], data->temp[nr]);
mutex_unlock(&data->update_lock);
return count;
}
}
static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
show_temp, set_temp, 1);
static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
show_temp, set_temp, 2);
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
static struct attribute *lm75_attrs[] = {
static struct attribute *lm75_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp1_max.dev_attr.attr,
&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
NULL
};
ATTRIBUTE_GROUPS(lm75);
};
ATTRIBUTE_GROUPS(lm75);
/*-----------------------------------------------------------------------*/
static const struct thermal_zone_of_device_ops lm75_of_thermal_ops = {
.get_temp = lm75_read_temp,
};
/* device probe and removal */
static int
lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
static int
lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct device *dev = &client->dev;
struct lm75_data *data;
int status;
@ -299,7 +303,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
data->tz = thermal_zone_of_sensor_register(data->hwmon_dev,
0,
data->hwmon_dev,
lm75_read_temp, NULL);
&lm75_of_thermal_ops);
if (IS_ERR(data->tz))
data->tz = NULL;
@ -307,19 +311,19 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
dev_name(data->hwmon_dev), client->name);
return 0;
}
}
static int lm75_remove(struct i2c_client *client)
{
static int lm75_remove(struct i2c_client *client)
{
struct lm75_data *data = i2c_get_clientdata(client);
thermal_zone_of_sensor_unregister(data->hwmon_dev, data->tz);
hwmon_device_unregister(data->hwmon_dev);
lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
return 0;
}
}
static const struct i2c_device_id lm75_ids[] = {
static const struct i2c_device_id lm75_ids[] = {
{ "adt75", adt75, },
{ "ds1775", ds1775, },
{ "ds75", ds75, },
@ -341,15 +345,15 @@ static const struct i2c_device_id lm75_ids[] = {
{ "tmp275", tmp275, },
{ "tmp75", tmp75, },
{ /* LIST END */ }
};
MODULE_DEVICE_TABLE(i2c, lm75_ids);
};
MODULE_DEVICE_TABLE(i2c, lm75_ids);
#define LM75A_ID 0xA1
/* Return 0 if detection is successful, -ENODEV otherwise */
static int lm75_detect(struct i2c_client *new_client,
static int lm75_detect(struct i2c_client *new_client,
struct i2c_board_info *info)
{
{
struct i2c_adapter *adapter = new_client->adapter;
int i;
int conf, hyst, os;
@ -430,11 +434,11 @@ static int lm75_detect(struct i2c_client *new_client,
strlcpy(info->type, is_lm75a ? "lm75a" : "lm75", I2C_NAME_SIZE);
return 0;
}
}
#ifdef CONFIG_PM
static int lm75_suspend(struct device *dev)
{
static int lm75_suspend(struct device *dev)
{
int status;
struct i2c_client *client = to_i2c_client(dev);
status = lm75_read_value(client, LM75_REG_CONF);
@ -445,10 +449,10 @@ static int lm75_suspend(struct device *dev)
status = status | LM75_SHUTDOWN;
lm75_write_value(client, LM75_REG_CONF, status);
return 0;
}
}
static int lm75_resume(struct device *dev)
{
static int lm75_resume(struct device *dev)
{
int status;
struct i2c_client *client = to_i2c_client(dev);
status = lm75_read_value(client, LM75_REG_CONF);
@ -459,18 +463,18 @@ static int lm75_resume(struct device *dev)
status = status & ~LM75_SHUTDOWN;
lm75_write_value(client, LM75_REG_CONF, status);
return 0;
}
}
static const struct dev_pm_ops lm75_dev_pm_ops = {
static const struct dev_pm_ops lm75_dev_pm_ops = {
.suspend = lm75_suspend,
.resume = lm75_resume,
};
};
#define LM75_DEV_PM_OPS (&lm75_dev_pm_ops)
#else
#define LM75_DEV_PM_OPS NULL
#endif /* CONFIG_PM */
static struct i2c_driver lm75_driver = {
static struct i2c_driver lm75_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "dx010_lm75",
@ -483,7 +487,7 @@ static struct i2c_driver lm75_driver = {
.detect = lm75_detect,
.address_list = normal_i2c,
*/
};
};
/*-----------------------------------------------------------------------*/
@ -494,24 +498,24 @@ static struct i2c_driver lm75_driver = {
* LM75 uses a high-byte first convention, which is exactly opposite to
* the SMBus standard.
*/
static int lm75_read_value(struct i2c_client *client, u8 reg)
{
static int lm75_read_value(struct i2c_client *client, u8 reg)
{
if (reg == LM75_REG_CONF)
return i2c_smbus_read_byte_data(client, reg);
else
return i2c_smbus_read_word_swapped(client, reg);
}
}
static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
{
static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
{
if (reg == LM75_REG_CONF)
return i2c_smbus_write_byte_data(client, reg, value);
else
return i2c_smbus_write_word_swapped(client, reg, value);
}
}
static struct lm75_data *lm75_update_device(struct device *dev)
{
static struct lm75_data *lm75_update_device(struct device *dev)
{
struct lm75_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
struct lm75_data *ret = data;
@ -541,7 +545,7 @@ static struct lm75_data *lm75_update_device(struct device *dev)
data->valid = 1;
}
abort:
abort:
mutex_unlock(&data->update_lock);
return ret;
}