88pm8607.c (d3d7bccc07a06a33fb9ba97ab764df8d46fb87d0) | 88pm8607.c (53b6949ef3291778aa9f921985206fbfd95449d7) |
---|---|
1/* 2 * Regulators driver for Marvell 88PM8607 3 * 4 * Copyright (C) 2009 Marvell International Ltd. 5 * Haojian Zhuang <haojian.zhuang@marvell.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 15 unchanged lines hidden (view full) --- 24 struct regulator_dev *regulator; 25 struct i2c_client *i2c; 26 27 unsigned int *vol_table; 28 unsigned int *vol_suspend; 29 30 int vol_reg; 31 int vol_shift; | 1/* 2 * Regulators driver for Marvell 88PM8607 3 * 4 * Copyright (C) 2009 Marvell International Ltd. 5 * Haojian Zhuang <haojian.zhuang@marvell.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 15 unchanged lines hidden (view full) --- 24 struct regulator_dev *regulator; 25 struct i2c_client *i2c; 26 27 unsigned int *vol_table; 28 unsigned int *vol_suspend; 29 30 int vol_reg; 31 int vol_shift; |
32 int vol_nbits; | |
33 int update_reg; 34 int update_bit; 35 int enable_reg; 36 int enable_bit; 37 int slope_double; 38}; 39 40static const unsigned int BUCK1_table[] = { --- 170 unchanged lines hidden (view full) --- 211 1800000, 1850000, 2700000, 2750000, 2800000, 2850000, 2900000, 2900000, 212}; 213 214static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) 215{ 216 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 217 int ret = -EINVAL; 218 | 32 int update_reg; 33 int update_bit; 34 int enable_reg; 35 int enable_bit; 36 int slope_double; 37}; 38 39static const unsigned int BUCK1_table[] = { --- 170 unchanged lines hidden (view full) --- 210 1800000, 1850000, 2700000, 2750000, 2800000, 2850000, 2900000, 2900000, 211}; 212 213static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) 214{ 215 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 216 int ret = -EINVAL; 217 |
219 if (info->vol_table && (index < (1 << info->vol_nbits))) { | 218 if (info->vol_table && (index < rdev->desc->n_voltages)) { |
220 ret = info->vol_table[index]; 221 if (info->slope_double) 222 ret <<= 1; 223 } 224 return ret; 225} 226 227static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 228{ 229 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 230 int i, ret = -ENOENT; 231 232 if (info->slope_double) { 233 min_uV = min_uV >> 1; 234 max_uV = max_uV >> 1; 235 } 236 if (info->vol_table) { | 219 ret = info->vol_table[index]; 220 if (info->slope_double) 221 ret <<= 1; 222 } 223 return ret; 224} 225 226static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 227{ 228 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 229 int i, ret = -ENOENT; 230 231 if (info->slope_double) { 232 min_uV = min_uV >> 1; 233 max_uV = max_uV >> 1; 234 } 235 if (info->vol_table) { |
237 for (i = 0; i < (1 << info->vol_nbits); i++) { | 236 for (i = 0; i < rdev->desc->n_voltages; i++) { |
238 if (!info->vol_table[i]) 239 break; 240 if ((min_uV <= info->vol_table[i]) 241 && (max_uV >= info->vol_table[i])) { 242 ret = i; 243 break; 244 } 245 } --- 15 unchanged lines hidden (view full) --- 261 return -EINVAL; 262 } 263 264 ret = choose_voltage(rdev, min_uV, max_uV); 265 if (ret < 0) 266 return -EINVAL; 267 *selector = ret; 268 val = (uint8_t)(ret << info->vol_shift); | 237 if (!info->vol_table[i]) 238 break; 239 if ((min_uV <= info->vol_table[i]) 240 && (max_uV >= info->vol_table[i])) { 241 ret = i; 242 break; 243 } 244 } --- 15 unchanged lines hidden (view full) --- 260 return -EINVAL; 261 } 262 263 ret = choose_voltage(rdev, min_uV, max_uV); 264 if (ret < 0) 265 return -EINVAL; 266 *selector = ret; 267 val = (uint8_t)(ret << info->vol_shift); |
269 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 268 mask = (rdev->desc->n_voltages - 1) << info->vol_shift; |
270 271 ret = pm860x_set_bits(info->i2c, info->vol_reg, mask, val); 272 if (ret) 273 return ret; 274 switch (info->desc.id) { 275 case PM8607_ID_BUCK1: 276 case PM8607_ID_BUCK3: 277 ret = pm860x_set_bits(info->i2c, info->update_reg, --- 9 unchanged lines hidden (view full) --- 287 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 288 uint8_t val, mask; 289 int ret; 290 291 ret = pm860x_reg_read(info->i2c, info->vol_reg); 292 if (ret < 0) 293 return ret; 294 | 269 270 ret = pm860x_set_bits(info->i2c, info->vol_reg, mask, val); 271 if (ret) 272 return ret; 273 switch (info->desc.id) { 274 case PM8607_ID_BUCK1: 275 case PM8607_ID_BUCK3: 276 ret = pm860x_set_bits(info->i2c, info->update_reg, --- 9 unchanged lines hidden (view full) --- 286 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 287 uint8_t val, mask; 288 int ret; 289 290 ret = pm860x_reg_read(info->i2c, info->vol_reg); 291 if (ret < 0) 292 return ret; 293 |
295 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 294 mask = (rdev->desc->n_voltages - 1) << info->vol_shift; |
296 val = ((unsigned char)ret & mask) >> info->vol_shift; 297 298 return pm8607_list_voltage(rdev, val); 299} 300 301static int pm8607_enable(struct regulator_dev *rdev) 302{ 303 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); --- 27 unchanged lines hidden (view full) --- 331 .list_voltage = pm8607_list_voltage, 332 .set_voltage = pm8607_set_voltage, 333 .get_voltage = pm8607_get_voltage, 334 .enable = pm8607_enable, 335 .disable = pm8607_disable, 336 .is_enabled = pm8607_is_enabled, 337}; 338 | 295 val = ((unsigned char)ret & mask) >> info->vol_shift; 296 297 return pm8607_list_voltage(rdev, val); 298} 299 300static int pm8607_enable(struct regulator_dev *rdev) 301{ 302 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); --- 27 unchanged lines hidden (view full) --- 330 .list_voltage = pm8607_list_voltage, 331 .set_voltage = pm8607_set_voltage, 332 .get_voltage = pm8607_get_voltage, 333 .enable = pm8607_enable, 334 .disable = pm8607_disable, 335 .is_enabled = pm8607_is_enabled, 336}; 337 |
339#define PM8607_DVC(vreg, nbits, ureg, ubit, ereg, ebit) \ | 338#define PM8607_DVC(vreg, ureg, ubit, ereg, ebit) \ |
340{ \ 341 .desc = { \ 342 .name = #vreg, \ 343 .ops = &pm8607_regulator_ops, \ 344 .type = REGULATOR_VOLTAGE, \ 345 .id = PM8607_ID_##vreg, \ 346 .owner = THIS_MODULE, \ | 339{ \ 340 .desc = { \ 341 .name = #vreg, \ 342 .ops = &pm8607_regulator_ops, \ 343 .type = REGULATOR_VOLTAGE, \ 344 .id = PM8607_ID_##vreg, \ 345 .owner = THIS_MODULE, \ |
346 .n_voltages = ARRAY_SIZE(vreg##_table), \ |
|
347 }, \ 348 .vol_reg = PM8607_##vreg, \ 349 .vol_shift = (0), \ | 347 }, \ 348 .vol_reg = PM8607_##vreg, \ 349 .vol_shift = (0), \ |
350 .vol_nbits = (nbits), \ | |
351 .update_reg = PM8607_##ureg, \ 352 .update_bit = (ubit), \ 353 .enable_reg = PM8607_##ereg, \ 354 .enable_bit = (ebit), \ 355 .slope_double = (0), \ 356 .vol_table = (unsigned int *)&vreg##_table, \ 357 .vol_suspend = (unsigned int *)&vreg##_suspend_table, \ 358} 359 | 350 .update_reg = PM8607_##ureg, \ 351 .update_bit = (ubit), \ 352 .enable_reg = PM8607_##ereg, \ 353 .enable_bit = (ebit), \ 354 .slope_double = (0), \ 355 .vol_table = (unsigned int *)&vreg##_table, \ 356 .vol_suspend = (unsigned int *)&vreg##_suspend_table, \ 357} 358 |
360#define PM8607_LDO(_id, vreg, shift, nbits, ereg, ebit) \ | 359#define PM8607_LDO(_id, vreg, shift, ereg, ebit) \ |
361{ \ 362 .desc = { \ 363 .name = "LDO" #_id, \ 364 .ops = &pm8607_regulator_ops, \ 365 .type = REGULATOR_VOLTAGE, \ 366 .id = PM8607_ID_LDO##_id, \ 367 .owner = THIS_MODULE, \ | 360{ \ 361 .desc = { \ 362 .name = "LDO" #_id, \ 363 .ops = &pm8607_regulator_ops, \ 364 .type = REGULATOR_VOLTAGE, \ 365 .id = PM8607_ID_LDO##_id, \ 366 .owner = THIS_MODULE, \ |
367 .n_voltages = ARRAY_SIZE(LDO##_id##_table), \ |
|
368 }, \ 369 .vol_reg = PM8607_##vreg, \ 370 .vol_shift = (shift), \ | 368 }, \ 369 .vol_reg = PM8607_##vreg, \ 370 .vol_shift = (shift), \ |
371 .vol_nbits = (nbits), \ | |
372 .enable_reg = PM8607_##ereg, \ 373 .enable_bit = (ebit), \ 374 .slope_double = (0), \ 375 .vol_table = (unsigned int *)&LDO##_id##_table, \ 376 .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \ 377} 378 379static struct pm8607_regulator_info pm8607_regulator_info[] = { | 371 .enable_reg = PM8607_##ereg, \ 372 .enable_bit = (ebit), \ 373 .slope_double = (0), \ 374 .vol_table = (unsigned int *)&LDO##_id##_table, \ 375 .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \ 376} 377 378static struct pm8607_regulator_info pm8607_regulator_info[] = { |
380 PM8607_DVC(BUCK1, 6, GO, 0, SUPPLIES_EN11, 0), 381 PM8607_DVC(BUCK2, 6, GO, 1, SUPPLIES_EN11, 1), 382 PM8607_DVC(BUCK3, 6, GO, 2, SUPPLIES_EN11, 2), | 379 PM8607_DVC(BUCK1, GO, 0, SUPPLIES_EN11, 0), 380 PM8607_DVC(BUCK2, GO, 1, SUPPLIES_EN11, 1), 381 PM8607_DVC(BUCK3, GO, 2, SUPPLIES_EN11, 2), |
383 | 382 |
384 PM8607_LDO( 1, LDO1, 0, 2, SUPPLIES_EN11, 3), 385 PM8607_LDO( 2, LDO2, 0, 3, SUPPLIES_EN11, 4), 386 PM8607_LDO( 3, LDO3, 0, 3, SUPPLIES_EN11, 5), 387 PM8607_LDO( 4, LDO4, 0, 3, SUPPLIES_EN11, 6), 388 PM8607_LDO( 5, LDO5, 0, 2, SUPPLIES_EN11, 7), 389 PM8607_LDO( 6, LDO6, 0, 3, SUPPLIES_EN12, 0), 390 PM8607_LDO( 7, LDO7, 0, 3, SUPPLIES_EN12, 1), 391 PM8607_LDO( 8, LDO8, 0, 3, SUPPLIES_EN12, 2), 392 PM8607_LDO( 9, LDO9, 0, 3, SUPPLIES_EN12, 3), 393 PM8607_LDO(10, LDO10, 0, 4, SUPPLIES_EN12, 4), 394 PM8607_LDO(12, LDO12, 0, 4, SUPPLIES_EN12, 5), 395 PM8607_LDO(13, VIBRATOR_SET, 1, 3, VIBRATOR_SET, 0), 396 PM8607_LDO(14, LDO14, 0, 3, SUPPLIES_EN12, 6), | 383 PM8607_LDO(1, LDO1, 0, SUPPLIES_EN11, 3), 384 PM8607_LDO(2, LDO2, 0, SUPPLIES_EN11, 4), 385 PM8607_LDO(3, LDO3, 0, SUPPLIES_EN11, 5), 386 PM8607_LDO(4, LDO4, 0, SUPPLIES_EN11, 6), 387 PM8607_LDO(5, LDO5, 0, SUPPLIES_EN11, 7), 388 PM8607_LDO(6, LDO6, 0, SUPPLIES_EN12, 0), 389 PM8607_LDO(7, LDO7, 0, SUPPLIES_EN12, 1), 390 PM8607_LDO(8, LDO8, 0, SUPPLIES_EN12, 2), 391 PM8607_LDO(9, LDO9, 0, SUPPLIES_EN12, 3), 392 PM8607_LDO(10, LDO10, 0, SUPPLIES_EN12, 4), 393 PM8607_LDO(12, LDO12, 0, SUPPLIES_EN12, 5), 394 PM8607_LDO(13, VIBRATOR_SET, 1, VIBRATOR_SET, 0), 395 PM8607_LDO(14, LDO14, 0, SUPPLIES_EN12, 6), |
397}; 398 399static int __devinit pm8607_regulator_probe(struct platform_device *pdev) 400{ 401 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 402 struct pm8607_regulator_info *info = NULL; 403 struct regulator_init_data *pdata = pdev->dev.platform_data; 404 struct resource *res; --- 71 unchanged lines hidden --- | 396}; 397 398static int __devinit pm8607_regulator_probe(struct platform_device *pdev) 399{ 400 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 401 struct pm8607_regulator_info *info = NULL; 402 struct regulator_init_data *pdata = pdev->dev.platform_data; 403 struct resource *res; --- 71 unchanged lines hidden --- |