static int fan53555_restore_working_reg(struct device_node *node, struct fan53555_device_info *di) { int ret; u32 val; /* Restore register from back up register */ ret = fan53555_read(di, di->sleep_reg, &val); if (ret < 0) { dev_err(di->dev, "Failed to get backup data from reg %d, ret = %d\n", di->sleep_reg, ret); return ret; } ret = fan53555_update_bits(di, di->vol_reg, VSEL_FULL_MASK, val); if (ret < 0) { dev_err(di->dev, "Failed to update working reg %d, ret = %d\n", di->vol_reg, ret); return ret; } return ret; }
static int fan53555_read_reg(struct fan53555_chip *fan, u8 reg) { int data; mutex_lock(&fan->io_lock); data = fan53555_read(fan, reg); if (data < 0) dev_err(fan->dev, "Read from reg 0x%x failed\n", reg); mutex_unlock(&fan->io_lock); return data; }
static unsigned int fan53555_get_mode(struct regulator_dev *rdev) { struct fan53555_device_info *di = rdev_get_drvdata(rdev); unsigned int val; int ret = 0; ret = fan53555_read(di, di->vol_reg, &val); if (ret < 0) return ret; if (val & VSEL_MODE) return REGULATOR_MODE_FAST; else return REGULATOR_MODE_NORMAL; }
static int get_reg(void *data, u64 *val) { struct fan53555_device_info *di = data; int rc; unsigned int temp = 0; rc = fan53555_read(di, di->peek_poke_address, &temp); if (rc < 0) dev_err(di->dev, "Couldn't read reg %x rc = %d\n", di->peek_poke_address, rc); else *val = temp; return rc; }
static int fan53555_regulator_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct fan53555_device_info *di; struct fan53555_platform_data *pdata; struct regulator_config config = { }; unsigned int val; int ret; if (client->dev.of_node) pdata = fan53555_get_of_platform_data(client); else pdata = client->dev.platform_data; if (!pdata || !pdata->regulator) { dev_err(&client->dev, "Platform data not found!\n"); return -ENODEV; } di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), GFP_KERNEL); if (!di) { dev_err(&client->dev, "Failed to allocate device info data!\n"); return -ENOMEM; } di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); if (IS_ERR(di->regmap)) { dev_err(&client->dev, "Failed to allocate regmap!\n"); return PTR_ERR(di->regmap); } di->dev = &client->dev; di->regulator = pdata->regulator; i2c_set_clientdata(client, di); /* Get chip ID */ ret = fan53555_read(di, FAN53555_ID1, &val); if (ret < 0) { dev_err(&client->dev, "Failed to get chip ID!\n"); return -ENODEV; } di->chip_id = val & DIE_ID; /* Get chip revision */ ret = fan53555_read(di, FAN53555_ID2, &val); if (ret < 0) { dev_err(&client->dev, "Failed to get chip Rev!\n"); return -ENODEV; } di->chip_rev = val & DIE_REV; dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n", di->chip_id, di->chip_rev); /* Device init */ ret = fan53555_device_setup(di, pdata); if (ret < 0) { dev_err(&client->dev, "Failed to setup device!\n"); return ret; } /* Set up from device tree */ if (client->dev.of_node) { ret = fan53555_of_init(client->dev.of_node, di); if (ret) return ret; } /* Register regulator */ config.dev = di->dev; config.init_data = di->regulator; config.regmap = di->regmap; config.driver_data = di; config.of_node = client->dev.of_node; ret = fan53555_regulator_register(di, &config); if (ret < 0) dev_err(&client->dev, "Failed to register regulator!\n"); di->debug_root = debugfs_create_dir("fan53555", NULL); if (!di->debug_root) dev_err(&client->dev, "Couldn't create debug dir\n"); if (di->debug_root) { struct dentry *ent; ent = debugfs_create_x32("address", S_IFREG | S_IWUSR | S_IRUGO, di->debug_root, &(di->peek_poke_address)); if (!ent) dev_err(&client->dev, "Couldn't create address debug file rc = %d\n", ret); ent = debugfs_create_file("data", S_IFREG | S_IWUSR | S_IRUGO, di->debug_root, di, &poke_poke_debug_ops); if (!ent) dev_err(&client->dev, "Couldn't create data debug file rc = %d\n", ret); } return ret; }