G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2))
struct g762_data {
- struct i2c_client *client;
struct device *hwmon_dev;
+ struct i2c_client *client;
struct clk *clk;
/* update mutex */
/* helper to grab and cache data, at most one time per second */
static struct g762_data *g762_update_client(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct g762_data *data = i2c_get_clientdata(client);
+ struct g762_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int ret = 0;
mutex_lock(&data->update_lock);
*/
static int do_set_clk_freq(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct g762_data *data = i2c_get_clientdata(client);
+ struct g762_data *data = dev_get_drvdata(dev);
if (val > 0xffffff)
return -EINVAL;
/* Set pwm mode. Accepts either 0 (PWM mode) or 1 (DC mode) */
static int do_set_pwm_mode(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
ret = -EINVAL;
goto out;
}
- ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
data->fan_cmd1);
data->valid = false;
out:
/* Set fan clock divisor. Accepts either 1, 2, 4 or 8. */
static int do_set_fan_div(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
ret = -EINVAL;
goto out;
}
- ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
data->fan_cmd1);
data->valid = false;
out:
/* Set fan gear mode. Accepts either 0, 1 or 2. */
static int do_set_fan_gear_mode(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
ret = -EINVAL;
goto out;
}
- ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD2,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2,
data->fan_cmd2);
data->valid = false;
out:
/* Set number of fan pulses per revolution. Accepts either 2 or 4. */
static int do_set_fan_pulses(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
ret = -EINVAL;
goto out;
}
- ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
data->fan_cmd1);
data->valid = false;
out:
/* Set fan mode. Accepts either 1 (open-loop) or 2 (closed-loop). */
static int do_set_pwm_enable(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
* value of 254 if it is 255 when switching to open-loop.
*/
if (data->set_cnt == 0xff)
- i2c_smbus_write_byte_data(client, G762_REG_SET_CNT,
- 254);
+ i2c_smbus_write_byte_data(data->client,
+ G762_REG_SET_CNT, 254);
break;
default:
ret = -EINVAL;
goto out;
}
- ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
data->fan_cmd1);
data->valid = false;
out:
/* Set PWM polarity. Accepts either 0 (positive duty) or 1 (negative duty) */
static int do_set_pwm_polarity(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
ret = -EINVAL;
goto out;
}
- ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
data->fan_cmd1);
data->valid = false;
out:
*/
static int do_set_pwm(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct g762_data *data = i2c_get_clientdata(client);
+ struct g762_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int ret;
if (val > 255)
*/
static int do_set_fan_target(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
G762_PULSE_FROM_REG(data->fan_cmd1),
G762_CLKDIV_FROM_REG(data->fan_cmd1),
G762_GEARMULT_FROM_REG(data->fan_cmd2));
- ret = i2c_smbus_write_byte_data(client, G762_REG_SET_CNT,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_SET_CNT,
data->set_cnt);
data->valid = false;
mutex_unlock(&data->update_lock);
/* Set fan startup voltage. Accepted values are either 0, 1, 2 or 3. */
static int do_set_fan_startv(struct device *dev, unsigned long val)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
int ret;
ret = -EINVAL;
goto out;
}
- ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD2,
+ ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2,
data->fan_cmd2);
data->valid = false;
out:
get_fan_pulses, set_fan_pulses);
/* Driver data */
-static struct attribute *g762_attributes[] = {
+static struct attribute *g762_attrs[] = {
&dev_attr_fan1_input.attr,
&dev_attr_fan1_alarm.attr,
&dev_attr_fan1_fault.attr,
NULL
};
-static const struct attribute_group g762_group = {
- .attrs = g762_attributes,
-};
+ATTRIBUTE_GROUPS(g762);
/*
* Enable both fan failure detection and fan out of control protection. The
*/
static inline int g762_fan_init(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
struct g762_data *data = g762_update_client(dev);
if (IS_ERR(data))
data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_OOC;
data->valid = false;
- return i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1,
+ return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
data->fan_cmd1);
}
static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
struct g762_data *data;
int ret;
I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;
- data = devm_kzalloc(&client->dev, sizeof(struct g762_data), GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(struct g762_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
mutex_init(&data->update_lock);
/* Enable fan failure detection and fan out of control protection */
- ret = g762_fan_init(&client->dev);
+ ret = g762_fan_init(dev);
if (ret)
return ret;
if (ret)
goto clock_dis;
- /* Register sysfs hooks */
- ret = sysfs_create_group(&client->dev.kobj, &g762_group);
- if (ret)
- goto clock_dis;
-
- data->hwmon_dev = hwmon_device_register(&client->dev);
+ data->hwmon_dev = devm_hwmon_device_register_with_groups(dev,
+ client->name,
+ data,
+ g762_groups);
if (IS_ERR(data->hwmon_dev)) {
ret = PTR_ERR(data->hwmon_dev);
- goto sysfs_rem;
+ goto clock_dis;
}
return 0;
- sysfs_rem:
- sysfs_remove_group(&client->dev.kobj, &g762_group);
-
clock_dis:
g762_of_clock_disable(client);
struct g762_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &g762_group);
g762_of_clock_disable(client);
return 0;