Commit 9bcfca123cbcf73234ba5b82e62d189d536d1ef2

Authored by Nikita Kiryanov
Committed by Tom Rini
1 parent 5dc5a8cac7

pmic: tps65218: add useful functions and defines

Add the following functions:
tps65218_reg_read() for accessing redisters
tps65218_toggle_fseal() for toggling the fseal bit
tps65218_lock_fsea() for locking the fseal bit to 1

Add the following defines:
All status register bits

Cc: Tom Rini <trini@konsulko.com>
Cc: Albert Aribaud <albert.u.boot@aribaud.net>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Reviewed-by: Tom Rini <trini@konsulko.com>

Showing 2 changed files with 68 additions and 0 deletions Side-by-side Diff

drivers/power/pmic/pmic_tps65218.c
... ... @@ -11,6 +11,20 @@
11 11 #include <power/pmic.h>
12 12 #include <power/tps65218.h>
13 13  
  14 +int tps65218_reg_read(uchar dest_reg, uchar *dest_val)
  15 +{
  16 + uchar read_val;
  17 + int ret;
  18 +
  19 + ret = i2c_read(TPS65218_CHIP_PM, dest_reg, 1, &read_val, 1);
  20 + if (ret)
  21 + return ret;
  22 +
  23 + *dest_val = read_val;
  24 +
  25 + return 0;
  26 +}
  27 +
14 28 /**
15 29 * tps65218_reg_write() - Generic function that can write a TPS65218 PMIC
16 30 * register or bit field regardless of protection
... ... @@ -94,6 +108,48 @@
94 108 if (tps65218_reg_write(TPS65218_PROT_LEVEL_2, TPS65218_SLEW,
95 109 TPS65218_DCDC_GO, TPS65218_DCDC_GO))
96 110 return 1;
  111 +
  112 + return 0;
  113 +}
  114 +
  115 +/**
  116 + * tps65218_toggle_fseal() - Perform the sequence that toggles the FSEAL bit.
  117 + *
  118 + * @return: 0 on success, -EBADE if the sequence was broken
  119 + */
  120 +int tps65218_toggle_fseal(void)
  121 +{
  122 + if (tps65218_reg_write(TPS65218_PROT_LEVEL_NONE, TPS65218_PASSWORD,
  123 + 0xb1, TPS65218_MASK_ALL_BITS))
  124 + return -EBADE;
  125 +
  126 + if (tps65218_reg_write(TPS65218_PROT_LEVEL_NONE, TPS65218_PASSWORD,
  127 + 0xfe, TPS65218_MASK_ALL_BITS))
  128 + return -EBADE;
  129 +
  130 + if (tps65218_reg_write(TPS65218_PROT_LEVEL_NONE, TPS65218_PASSWORD,
  131 + 0xa3, TPS65218_MASK_ALL_BITS))
  132 + return -EBADE;
  133 +
  134 + return 0;
  135 +}
  136 +
  137 +/**
  138 + * tps65218_lock_fseal() - Perform the sequence that locks the FSEAL bit to 1.
  139 + *
  140 + * The FSEAL bit prevents the PMIC from turning off DCDC5 and DCDC6. It can be
  141 + * toggled at most 3 times: 0->1, 1->0, and finally 0->1. After the third switch
  142 + * its value is locked and can only be reset by powering off the PMIC entirely.
  143 + *
  144 + * @return: 0 on success, -EBADE if the sequence was broken
  145 + */
  146 +int tps65218_lock_fseal(void)
  147 +{
  148 + int i;
  149 +
  150 + for (i = 0; i < 3; i++)
  151 + if (tps65218_toggle_fseal())
  152 + return -EBADE;
97 153  
98 154 return 0;
99 155 }
include/power/tps65218.h
... ... @@ -8,6 +8,8 @@
8 8 #ifndef __POWER_TPS65218_H__
9 9 #define __POWER_TPS65218_H__
10 10  
  11 +#include <linux/bitops.h>
  12 +
11 13 /* I2C chip address */
12 14 #define TPS65218_CHIP_PM 0x24
13 15  
14 16  
... ... @@ -60,9 +62,19 @@
60 62 #define TPS65218_DCDC_VOLT_SEL_1260MV 0x29
61 63 #define TPS65218_DCDC_VOLT_SEL_1330MV 0x30
62 64  
  65 +#define TPS65218_CC_STAT (BIT(0) | BIT(1))
  66 +#define TPS65218_STATE (BIT(2) | BIT(3))
  67 +#define TPS65218_PB_STATE BIT(4)
  68 +#define TPS65218_AC_STATE BIT(5)
  69 +#define TPS65218_EE BIT(6)
  70 +#define TPS65218_FSEAL BIT(7)
  71 +
  72 +int tps65218_reg_read(uchar dest_reg, uchar *dest_val);
63 73 int tps65218_reg_write(uchar prot_level, uchar dest_reg, uchar dest_val,
64 74 uchar mask);
65 75 int tps65218_voltage_update(uchar dc_cntrl_reg, uchar volt_sel);
  76 +int tps65218_toggle_fseal(void);
  77 +int tps65218_lock_fseal(void);
66 78 int power_tps65218_init(unsigned char bus);
67 79 #endif /* __POWER_TPS65218_H__ */