Commit 60c185f059c88ad4b9b170b1f9322e3adcccca07

Authored by Laxman Dewangan
Committed by Samuel Ortiz
1 parent a36516b016

mfd: palmas: Add APIs to access the Palmas' registers

Palmas register set is divided into different blocks (base and offset)
and hence different i2c addresses. The i2c address offsets are derived
from base address of block of registers.

Add inline APIs to access the Palma's registers which takes the base of
register block and register offset. The i2c address offset is  derived
from the base address of register blocks.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

Showing 1 changed file with 52 additions and 0 deletions Side-by-side Diff

include/linux/mfd/palmas.h
... ... @@ -2789,5 +2789,57 @@
2789 2789 #define PALMAS_GPADC_TRIM15 0xE
2790 2790 #define PALMAS_GPADC_TRIM16 0xF
2791 2791  
  2792 +static inline int palmas_read(struct palmas *palmas, unsigned int base,
  2793 + unsigned int reg, unsigned int *val)
  2794 +{
  2795 + unsigned int addr = PALMAS_BASE_TO_REG(base, reg);
  2796 + int slave_id = PALMAS_BASE_TO_SLAVE(base);
  2797 +
  2798 + return regmap_read(palmas->regmap[slave_id], addr, val);
  2799 +}
  2800 +
  2801 +static inline int palmas_write(struct palmas *palmas, unsigned int base,
  2802 + unsigned int reg, unsigned int value)
  2803 +{
  2804 + unsigned int addr = PALMAS_BASE_TO_REG(base, reg);
  2805 + int slave_id = PALMAS_BASE_TO_SLAVE(base);
  2806 +
  2807 + return regmap_write(palmas->regmap[slave_id], addr, value);
  2808 +}
  2809 +
  2810 +static inline int palmas_bulk_write(struct palmas *palmas, unsigned int base,
  2811 + unsigned int reg, const void *val, size_t val_count)
  2812 +{
  2813 + unsigned int addr = PALMAS_BASE_TO_REG(base, reg);
  2814 + int slave_id = PALMAS_BASE_TO_SLAVE(base);
  2815 +
  2816 + return regmap_bulk_write(palmas->regmap[slave_id], addr,
  2817 + val, val_count);
  2818 +}
  2819 +
  2820 +static inline int palmas_bulk_read(struct palmas *palmas, unsigned int base,
  2821 + unsigned int reg, void *val, size_t val_count)
  2822 +{
  2823 + unsigned int addr = PALMAS_BASE_TO_REG(base, reg);
  2824 + int slave_id = PALMAS_BASE_TO_SLAVE(base);
  2825 +
  2826 + return regmap_bulk_read(palmas->regmap[slave_id], addr,
  2827 + val, val_count);
  2828 +}
  2829 +
  2830 +static inline int palmas_update_bits(struct palmas *palmas, unsigned int base,
  2831 + unsigned int reg, unsigned int mask, unsigned int val)
  2832 +{
  2833 + unsigned int addr = PALMAS_BASE_TO_REG(base, reg);
  2834 + int slave_id = PALMAS_BASE_TO_SLAVE(base);
  2835 +
  2836 + return regmap_update_bits(palmas->regmap[slave_id], addr, mask, val);
  2837 +}
  2838 +
  2839 +static inline int palmas_irq_get_virq(struct palmas *palmas, int irq)
  2840 +{
  2841 + return regmap_irq_get_virq(palmas->irq_data, irq);
  2842 +}
  2843 +
2792 2844 #endif /* __LINUX_MFD_PALMAS_H */