/* * amc6821.c - Part of lm_sensors, Linux kernel modules for hardware * monitoring * Copyright (C) 2009 T. Mertelj * * Based on max6650.c: * Copyright (C) 2007 Hans J. Koch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include /* Needed for KERN_INFO */ #include #include #include #include #include #include #include #include #include /* * Addresses to scan. */ static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END}; /* * Insmod parameters */ static int pwminv; /*Inverted PWM output. */ module_param(pwminv, int, S_IRUGO); static int init = 1; /*Power-on initialization.*/ module_param(init, int, S_IRUGO); enum chips { amc6821 }; #define AMC6821_REG_DEV_ID 0x3D #define AMC6821_REG_COMP_ID 0x3E #define AMC6821_REG_CONF1 0x00 #define AMC6821_REG_CONF2 0x01 #define AMC6821_REG_CONF3 0x3F #define AMC6821_REG_CONF4 0x04 #define AMC6821_REG_STAT1 0x02 #define AMC6821_REG_STAT2 0x03 #define AMC6821_REG_TDATA_LOW 0x08 #define AMC6821_REG_TDATA_HI 0x09 #define AMC6821_REG_LTEMP_HI 0x0A #define AMC6821_REG_RTEMP_HI 0x0B #define AMC6821_REG_LTEMP_LIMIT_MIN 0x15 #define AMC6821_REG_LTEMP_LIMIT_MAX 0x14 #define AMC6821_REG_RTEMP_LIMIT_MIN 0x19 #define AMC6821_REG_RTEMP_LIMIT_MAX 0x18 #define AMC6821_REG_LTEMP_CRIT 0x1B #define AMC6821_REG_RTEMP_CRIT 0x1D #define AMC6821_REG_PSV_TEMP 0x1C #define AMC6821_REG_DCY 0x22 #define AMC6821_REG_LTEMP_FAN_CTRL 0x24 #define AMC6821_REG_RTEMP_FAN_CTRL 0x25 #define AMC6821_REG_DCY_LOW_TEMP 0x21 #define AMC6821_REG_TACH_LLIMITL 0x10 #define AMC6821_REG_TACH_LLIMITH 0x11 #define AMC6821_REG_TACH_HLIMITL 0x12 #define AMC6821_REG_TACH_HLIMITH 0x13 #define AMC6821_CONF1_START 0x01 #define AMC6821_CONF1_FAN_INT_EN 0x02 #define AMC6821_CONF1_FANIE 0x04 #define AMC6821_CONF1_PWMINV 0x08 #define AMC6821_CONF1_FAN_FAULT_EN 0x10 #define AMC6821_CONF1_FDRC0 0x20 #define AMC6821_CONF1_FDRC1 0x40 #define AMC6821_CONF1_THERMOVIE 0x80 #define AMC6821_CONF2_PWM_EN 0x01 #define AMC6821_CONF2_TACH_MODE 0x02 #define AMC6821_CONF2_TACH_EN 0x04 #define AMC6821_CONF2_RTFIE 0x08 #define AMC6821_CONF2_LTOIE 0x10 #define AMC6821_CONF2_RTOIE 0x20 #define AMC6821_CONF2_PSVIE 0x40 #define AMC6821_CONF2_RST 0x80 #define AMC6821_CONF3_THERM_FAN_EN 0x80 #define AMC6821_CONF3_REV_MASK 0x0F #define AMC6821_CONF4_OVREN 0x10 #define AMC6821_CONF4_TACH_FAST 0x20 #define AMC6821_CONF4_PSPR 0x40 #define AMC6821_CONF4_MODE 0x80 #define AMC6821_STAT1_RPM_ALARM 0x01 #define AMC6821_STAT1_FANS 0x02 #define AMC6821_STAT1_RTH 0x04 #define AMC6821_STAT1_RTL 0x08 #define AMC6821_STAT1_R_THERM 0x10 #define AMC6821_STAT1_RTF 0x20 #define AMC6821_STAT1_LTH 0x40 #define AMC6821_STAT1_LTL 0x80 #define AMC6821_STAT2_RTC 0x08 #define AMC6821_STAT2_LTC 0x10 #define AMC6821_STAT2_LPSV 0x20 #define AMC6821_STAT2_L_THERM 0x40 #define AMC6821_STAT2_THERM_IN 0x80 enum {IDX_TEMP1_INPUT = 0, IDX_TEMP1_MIN, IDX_TEMP1_MAX, IDX_TEMP1_CRIT, IDX_TEMP2_INPUT, IDX_TEMP2_MIN, IDX_TEMP2_MAX, IDX_TEMP2_CRIT, TEMP_IDX_LEN, }; static const u8 temp_reg[] = {AMC6821_REG_LTEMP_HI, AMC6821_REG_LTEMP_LIMIT_MIN, AMC6821_REG_LTEMP_LIMIT_MAX, AMC6821_REG_LTEMP_CRIT, AMC6821_REG_RTEMP_HI, AMC6821_REG_RTEMP_LIMIT_MIN, AMC6821_REG_RTEMP_LIMIT_MAX, AMC6821_REG_RTEMP_CRIT, }; enum {IDX_FAN1_INPUT = 0, IDX_FAN1_MIN, IDX_FAN1_MAX, FAN1_IDX_LEN, }; static const u8 fan_reg_low[] = {AMC6821_REG_TDATA_LOW, AMC6821_REG_TACH_LLIMITL, AMC6821_REG_TACH_HLIMITL, }; static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI, AMC6821_REG_TACH_LLIMITH, AMC6821_REG_TACH_HLIMITH, }; /* * Client data (each client gets its own) */ struct amc6821_data { struct i2c_client *client; struct mutex update_lock; char valid; /* zero until following fields are valid */ unsigned long last_updated; /* in jiffies */ /* register values */ int temp[TEMP_IDX_LEN]; u16 fan[FAN1_IDX_LEN]; u8 fan1_div; u8 pwm1; u8 temp1_auto_point_temp[3]; u8 temp2_auto_point_temp[3]; u8 pwm1_auto_point_pwm[3]; u8 pwm1_enable; u8 pwm1_auto_channels_temp; u8 stat1; u8 stat2; }; static struct amc6821_data *amc6821_update_device(struct device *dev) { struct amc6821_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; int timeout = HZ; u8 reg; int i; mutex_lock(&data->update_lock); if (time_after(jiffies, data->last_updated + timeout) || !data->valid) { for (i = 0; i < TEMP_IDX_
#!/usr/bin/python
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import functest.core.feature_base as base


class Orchestra(base.FeatureBase):
    def __init__(self):
        super(Orchestra, self).__init__(project='orchestra',
                                        case='orchestra',
                                        repo='dir_repo_orchestra')
        # TODO
        # self.cmd = "%s/tests/run.sh %s/tests" % (self.repo, self.repo)
{ struct amc6821_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; long val; int config = kstrtol(buf, 10, &val); if (config) return config; mutex_lock(&data->update_lock); config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); if (config < 0) { dev_err(&client->dev, "Error reading configuration register, aborting.\n"); count = config; goto EXIT; } switch (val) { case 2: config &= ~AMC6821_CONF4_PSPR; data->fan1_div = 2; break; case 4: config |= AMC6821_CONF4_PSPR; data->fan1_div = 4; break; default: count = -EINVAL; goto EXIT; } if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF4, config)) { dev_err(&client->dev, "Configuration register write error, aborting.\n"); count = -EIO; } EXIT: mutex_unlock(&data->update_lock); return count; } static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, get_temp, NULL, IDX_TEMP1_INPUT); static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, get_temp, set_temp, IDX_TEMP1_MIN); static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, get_temp, set_temp, IDX_TEMP1_MAX); static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, get_temp, set_temp, IDX_TEMP1_CRIT); static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, get_temp_alarm, NULL, IDX_TEMP1_MIN); static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, get_temp_alarm, NULL, IDX_TEMP1_MAX); static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, get_temp_alarm, NULL, IDX_TEMP1_CRIT); static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, get_temp, NULL, IDX_TEMP2_INPUT); static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, get_temp, set_temp, IDX_TEMP2_MIN); static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, get_temp, set_temp, IDX_TEMP2_MAX); static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR, get_temp, set_temp, IDX_TEMP2_CRIT); static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, get_temp2_fault, NULL, 0); static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, get_temp_alarm, NULL, IDX_TEMP2_MIN); static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, get_temp_alarm, NULL, IDX_TEMP2_MAX); static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, get_temp_alarm, NULL, IDX_TEMP2_CRIT); static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan, NULL, IDX_FAN1_INPUT); static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, get_fan, set_fan, IDX_FAN1_MIN); static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR, get_fan, set_fan, IDX_FAN1_MAX); static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, get_fan1_fault, NULL, 0); static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, get_fan1_div, set_fan1_div, 0); static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm1, set_pwm1, 0); static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, get_pwm1_enable, set_pwm1_enable, 0); static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO, get_pwm1_auto_point_pwm, NULL, 0); static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, get_pwm1_auto_point_pwm, set_pwm1_auto_point_pwm, 1); static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO, get_pwm1_auto_point_pwm, NULL, 2); static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO, get_pwm1_auto_channels_temp, NULL, 0); static SENSOR_DEVICE_ATTR_2(temp1_auto_point1_temp, S_IRUGO, get_temp_auto_point_temp, NULL, 1, 0); static SENSOR_DEVICE_ATTR_2(temp1_auto_point2_temp, S_IWUSR | S_IRUGO, get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 1); static SENSOR_DEVICE_ATTR_2(temp1_auto_point3_temp, S_IWUSR | S_IRUGO, get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 2); static SENSOR_DEVICE_ATTR_2(temp2_auto_point1_temp, S_IWUSR | S_IRUGO, get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 0); static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IWUSR | S_IRUGO, get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 1); static SENSOR_DEVICE_ATTR_2(temp2_auto_point3_temp, S_IWUSR | S_IRUGO, get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 2); static struct attribute *amc6821_attrs[] = { &sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp1_min.dev_attr.attr, &sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp1_crit.dev_attr.attr, &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, &sensor_dev_attr_temp2_input.dev_attr.attr, &sensor_dev_attr_temp2_min.dev_attr.attr, &sensor_dev_attr_temp2_max.dev_attr.attr, &sensor_dev_attr_temp2_crit.dev_attr.attr, &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, &sensor_dev_attr_temp2_fault.dev_attr.attr, &sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan1_min.dev_attr.attr, &sensor_dev_attr_fan1_max.dev_attr.attr, &sensor_dev_attr_fan1_fault.dev_attr.attr, &sensor_dev_attr_fan1_div.dev_attr.attr, &sensor_dev_attr_pwm1.dev_attr.attr, &sensor_dev_attr_pwm1_enable.dev_attr.attr, &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_temp1_auto_point3_temp.dev_attr.attr, &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_temp2_auto_point3_temp.dev_attr.attr, NULL }; ATTRIBUTE_GROUPS(amc6821); /* Return 0 if detection is successful, -ENODEV otherwise */ static int amc6821_detect( struct i2c_client *client, struct i2c_board_info *info) { struct i2c_adapter *adapter = client->adapter; int address = client->addr; int dev_id, comp_id; dev_dbg(&adapter->dev, "amc6821_detect called.\n"); if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_dbg(&adapter->dev, "amc6821: I2C bus doesn't support byte mode, " "skipping.\n"); return -ENODEV; } dev_id = i2c_smbus_read_byte_data(client, AMC6821_REG_DEV_ID); comp_id = i2c_smbus_read_byte_data(client, AMC6821_REG_COMP_ID); if (dev_id != 0x21 || comp_id != 0x49) { dev_dbg(&adapter->dev, "amc6821: detection failed at 0x%02x.\n", address); return -ENODEV; } /* * Bit 7 of the address register is ignored, so we can check the * ID registers again */ dev_id = i2c_smbus_read_byte_data(client, 0x80 | AMC6821_REG_DEV_ID); comp_id = i2c_smbus_read_byte_data(client, 0x80 | AMC6821_REG_COMP_ID); if (dev_id != 0x21 || comp_id != 0x49) { dev_dbg(&adapter->dev, "amc6821: detection failed at 0x%02x.\n", address); return -ENODEV; } dev_info(&adapter->dev, "amc6821: chip found at 0x%02x.\n", address); strlcpy(info->type, "amc6821", I2C_NAME_SIZE); return 0; } static int amc6821_init_client(struct i2c_client *client) { int config; int err = -EIO; if (init) { config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); if (config < 0) { dev_err(&client->dev, "Error reading configuration register, aborting.\n"); return err; } config |= AMC6821_CONF4_MODE; if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF4, config)) { dev_err(&client->dev, "Configuration register write error, aborting.\n"); return err; } config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF3); if (config < 0) { dev_err(&client->dev, "Error reading configuration register, aborting.\n"); return err; } dev_info(&client->dev, "Revision %d\n", config & 0x0f); config &= ~AMC6821_CONF3_THERM_FAN_EN; if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF3, config)) { dev_err(&client->dev, "Configuration register write error, aborting.\n"); return err; } config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF2); if (config < 0) { dev_err(&client->dev, "Error reading configuration register, aborting.\n"); return err; } config &= ~AMC6821_CONF2_RTFIE; config &= ~AMC6821_CONF2_LTOIE; config &= ~AMC6821_CONF2_RTOIE; if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF2, config)) { dev_err(&client->dev, "Configuration register write error, aborting.\n"); return err; } config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); if (config < 0) { dev_err(&client->dev, "Error reading configuration register, aborting.\n"); return err; } config &= ~AMC6821_CONF1_THERMOVIE; config &= ~AMC6821_CONF1_FANIE; config |= AMC6821_CONF1_START; if (pwminv) config |= AMC6821_CONF1_PWMINV; else config &= ~AMC6821_CONF1_PWMINV; if (i2c_smbus_write_byte_data( client, AMC6821_REG_CONF1, config)) { dev_err(&client->dev, "Configuration register write error, aborting.\n"); return err; } } return 0; } static int amc6821_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct amc6821_data *data; struct device *hwmon_dev; int err; data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL); if (!data) return -ENOMEM; data->client = client; mutex_init(&data->update_lock); /* * Initialize the amc6821 chip */ err = amc6821_init_client(client); if (err) return err; hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, amc6821_groups); return PTR_ERR_OR_ZERO(hwmon_dev); } static const struct i2c_device_id amc6821_id[] = { { "amc6821", amc6821 }, { } }; MODULE_DEVICE_TABLE(i2c, amc6821_id); static struct i2c_driver amc6821_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "amc6821", }, .probe = amc6821_probe, .id_table = amc6821_id, .detect = amc6821_detect, .address_list = normal_i2c, }; module_i2c_driver(amc6821_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("T. Mertelj "); MODULE_DESCRIPTION("Texas Instruments amc6821 hwmon driver");