regmap: clean up debugfs if regmap_init fails

If debugfs isn't cleaned up, stale files will be left in the filesystem
which will cause an OOPS when accessed the first time, and hang the
accessing application when accessed again, presumably due to some lock
being left held.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regmap: Fix the size calculation for map->format.buf_size

The word to be transmitted/received via regmap is composed by the following
parts:

config->reg_bits
config->val_bits
config->pad_bits

,so the total size should be calculated by summing up the number of bits of
each element and using a DIV_ROUND_UP to return the number of bytes.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regulator: palmas: Fix wrong kfree calls

The devm_kzalloc function eliminates the need for manual resource releasing
and simplify error handling. Resources allocated by devm_* are freed
automatically on driver detach.

Thus adding kfree calls here will introduce double free bug.

The memory of desc array and the pointers to the rdev[] are allocated by
devm_kzalloc call for struct palmas_pmic.

struct palmas_pmic {
        struct palmas *palmas;
        struct device *dev;
        struct regulator_desc desc[PALMAS_NUM_REGS];
        struct regulator_dev *rdev[PALMAS_NUM_REGS];
        struct mutex mutex;

        int smps123;
        int smps457;

        int range[PALMAS_REG_SMPS10];
};

Which means we should not call kfree for pmic->rdev and pmic->desc.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regulator: anatop: Use correct __devexit_p annotation

__devexit functions are discarded when CONFIG_HOTPLUG
is not set, so the symbol needs to be referenced carefully.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regulator: gpio-regulator: do not pass drvdata pointer as reference

Commit c172708d38a4 (regulator: core: Use a struct to pass in
regulator runtime configuration) added the drvdata pointer
only per reference to the new config array in the gpio-regulator.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regulator: gpio-regulator: Fix finding of smallest value

Commit 4dbd8f63f07a (regulator: gpio-regulator: Set the smallest
voltage/current in the specified range) forgot to set the newly
introduced best_val.

Therefore it stayed always at INT_MAX thus breaking the setting
of the voltage.

Included is also an init value for target, as warnings about
a possibly uninitialised target started appearing with this fix.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regulator: gpio-regulator: populate selector from set_voltage

This was missing until now and the underlying
_regulator_do_set_voltage is using this value when calling list_voltage.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regulator: max8649: fix missing regmap in rdev

In probe(), rdev->regmap must be assigned.

Signed-off-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regmap: Export regmap_reinit_cache()

It's supposed to be there for drivers.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
regulator: core: Properly handle the case min_uV < rdev->desc->min_uV in map_voltage_linear

Properly handle the case if the specified min_uV is less than the voltage given
by the lowest selector.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Merge tag 'regulator-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator

Pull regulator fixes from Mark Brown:
 "A couple of small fixes, plus larger fixes for the gpio-regulator
  driver the most recent changes for which had apparently not been
  tested at all in -next (or elsewhere from the looks of it)."

* tag 'regulator-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator:
  regulator: core: Properly handle the case min_uV < rdev->desc->min_uV in map_voltage_linear
  regulator: max8649: fix missing regmap in rdev
  regulator: gpio-regulator: populate selector from set_voltage
  regulator: gpio-regulator: Fix finding of smallest value
  regulator: gpio-regulator: do not pass drvdata pointer as reference
  regulator: anatop: Use correct __devexit_p annotation
  regulator: palmas: Fix wrong kfree calls
Merge tag 'regmap-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap fixes from Mark Brown:
 "Nothing too exciting - a cleanup for debugfs in error handling and a
  fix for the padding (which has only just acquired real use) and
  exporting a function that's supposed to be usable by drivers."

* tag 'regmap-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: Export regmap_reinit_cache()
  regmap: Fix the size calculation for map->format.buf_size
  regmap: clean up debugfs if regmap_init fails