ina2xx.c (a0de56c81fcf9f1a691e22e519b0dff21c48c645) ina2xx.c (001e2e730ce4e6dc2cd97fcb169097febfc7b200)
1/*
2 * Driver for Texas Instruments INA219, INA226 power monitor chips
3 *
4 * INA219:
5 * Zero Drift Bi-Directional Current/Power Monitor with I2C Interface
6 * Datasheet: http://www.ti.com/product/ina219
7 *
8 * INA220:

--- 406 unchanged lines hidden (view full) ---

415
416static const struct attribute_group ina226_group = {
417 .attrs = ina226_attrs,
418};
419
420static int ina2xx_probe(struct i2c_client *client,
421 const struct i2c_device_id *id)
422{
1/*
2 * Driver for Texas Instruments INA219, INA226 power monitor chips
3 *
4 * INA219:
5 * Zero Drift Bi-Directional Current/Power Monitor with I2C Interface
6 * Datasheet: http://www.ti.com/product/ina219
7 *
8 * INA220:

--- 406 unchanged lines hidden (view full) ---

415
416static const struct attribute_group ina226_group = {
417 .attrs = ina226_attrs,
418};
419
420static int ina2xx_probe(struct i2c_client *client,
421 const struct i2c_device_id *id)
422{
423 struct ina2xx_platform_data *pdata;
424 struct device *dev = &client->dev;
425 struct ina2xx_data *data;
426 struct device *hwmon_dev;
427 u32 val;
428 int ret, group = 0;
429
430 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
431 if (!data)
432 return -ENOMEM;
433
423 struct device *dev = &client->dev;
424 struct ina2xx_data *data;
425 struct device *hwmon_dev;
426 u32 val;
427 int ret, group = 0;
428
429 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
430 if (!data)
431 return -ENOMEM;
432
434 if (dev_get_platdata(dev)) {
435 pdata = dev_get_platdata(dev);
436 data->rshunt = pdata->shunt_uohms;
437 } else if (!of_property_read_u32(dev->of_node,
438 "shunt-resistor", &val)) {
439 data->rshunt = val;
440 } else {
441 data->rshunt = INA2XX_RSHUNT_DEFAULT;
442 }
443
444 /* set the device type */
445 data->kind = id->driver_data;
446 data->config = &ina2xx_config[data->kind];
447
433 /* set the device type */
434 data->kind = id->driver_data;
435 data->config = &ina2xx_config[data->kind];
436
448 if (data->rshunt <= 0 ||
449 data->rshunt > data->config->calibration_factor)
437 if (of_property_read_u32(dev->of_node, "shunt-resistor", &val) < 0) {
438 struct ina2xx_platform_data *pdata = dev_get_platdata(dev);
439
440 if (pdata)
441 val = pdata->shunt_uohms;
442 else
443 val = INA2XX_RSHUNT_DEFAULT;
444 }
445
446 if (val <= 0 || val > data->config->calibration_factor)
450 return -ENODEV;
451
447 return -ENODEV;
448
449 data->rshunt = val;
450
452 ina2xx_regmap_config.max_register = data->config->registers;
453
454 data->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config);
455 if (IS_ERR(data->regmap)) {
456 dev_err(dev, "failed to allocate register map\n");
457 return PTR_ERR(data->regmap);
458 }
459

--- 46 unchanged lines hidden ---
451 ina2xx_regmap_config.max_register = data->config->registers;
452
453 data->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config);
454 if (IS_ERR(data->regmap)) {
455 dev_err(dev, "failed to allocate register map\n");
456 return PTR_ERR(data->regmap);
457 }
458

--- 46 unchanged lines hidden ---