David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 1 | /* |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 2 | * Copyright 2012, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following |
| 13 | * disclaimer in the documentation and/or other materials provided |
| 14 | * with the distribution. |
| 15 | * * Neither the name of Google Inc. nor the names of its |
| 16 | * contributors may be used to endorse or promote products derived |
| 17 | * from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 30 | * |
| 31 | * Alternatively, this software may be distributed under the terms of the |
| 32 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 33 | * Software Foundation. |
| 34 | */ |
| 35 | |
| 36 | #ifndef __TPS65090_H_ |
| 37 | #define __TPS65090_H_ |
| 38 | |
| 39 | /* I2C device address for TPS65090 PMU */ |
| 40 | #define TPS65090_I2C_ADDR 0x48 |
| 41 | |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 42 | /* TPS65090 FET control registers */ |
| 43 | enum fet_id { |
| 44 | FET1_CTRL = 0x0f, |
| 45 | FET2_CTRL, |
| 46 | FET3_CTRL, |
| 47 | FET4_CTRL, |
| 48 | FET5_CTRL, |
| 49 | FET6_CTRL, |
| 50 | FET7_CTRL, |
| 51 | }; |
| 52 | |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 53 | enum { |
| 54 | /* Status register fields */ |
| 55 | TPS65090_ST1_OTC = 1 << 0, |
| 56 | TPS65090_ST1_OCC = 1 << 1, |
| 57 | TPS65090_ST1_STATE_SHIFT = 4, |
| 58 | TPS65090_ST1_STATE_MASK = 0xf << TPS65090_ST1_STATE_SHIFT, |
| 59 | }; |
| 60 | |
| 61 | /* FET errors */ |
| 62 | enum { |
| 63 | FET_ERR_COMMS = -1, /* FET comms error */ |
| 64 | FET_ERR_NOT_READY = -2, /* FET is not yet ready - retry */ |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * Enable FET |
| 69 | * |
Martin Roth | 5f066b2 | 2015-01-04 16:47:39 -0700 | [diff] [blame] | 70 | * @param bus I2C bus number the TPS65090 is on |
| 71 | * @param fet_id FET ID, value between 1 and 7 |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 72 | * return 0 on success, non-0 on failure |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 73 | */ |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 74 | int tps65090_fet_enable(unsigned int bus, enum fet_id fet_id); |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Disable FET |
| 78 | * |
Martin Roth | 5f066b2 | 2015-01-04 16:47:39 -0700 | [diff] [blame] | 79 | * @param bus I2C bus number the TPS65090 is on |
| 80 | * @param fet_id FET ID, value between 1 and 7 |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 81 | * @return 0 on success, non-0 on failure |
| 82 | */ |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 83 | int tps65090_fet_disable(unsigned int bus, enum fet_id fet_id); |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Is FET enabled? |
| 87 | * |
Martin Roth | 5f066b2 | 2015-01-04 16:47:39 -0700 | [diff] [blame] | 88 | * @param bus I2C bus number the TPS65090 is on |
| 89 | * @param fet_id FET ID, value between 1 and 7 |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 90 | * @return 1 enabled, 0 disabled, negative value on failure |
| 91 | */ |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 92 | int tps65090_fet_is_enabled(unsigned int bus, enum fet_id fet_id); |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Enable / disable the battery charger |
| 96 | * |
Martin Roth | 5f066b2 | 2015-01-04 16:47:39 -0700 | [diff] [blame] | 97 | * @param bus I2C bus number the TPS65090 is on |
| 98 | * @param enable 0 to disable charging, non-zero to enable |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 99 | */ |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 100 | int tps65090_set_charge_enable(unsigned int bus, int enable); |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Check whether we have enabled battery charging |
| 104 | * |
Martin Roth | 5f066b2 | 2015-01-04 16:47:39 -0700 | [diff] [blame] | 105 | * @param bus I2C bus number the TPS65090 is on |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 106 | * @return 1 if enabled, 0 if disabled |
| 107 | */ |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 108 | int tps65090_is_charging(unsigned int bus); |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Return the value of the status register |
| 112 | * |
Martin Roth | 5f066b2 | 2015-01-04 16:47:39 -0700 | [diff] [blame] | 113 | * @param bus I2C bus number the TPS65090 is on |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 114 | * @return status register value, or -1 on error |
| 115 | */ |
David Hendricks | 765ff76 | 2013-04-09 17:20:07 -0700 | [diff] [blame] | 116 | int tps65090_get_status(unsigned int bus); |
David Hendricks | 6e877ec | 2013-04-09 16:58:02 -0700 | [diff] [blame] | 117 | |
| 118 | #endif /* __TPS65090_H_ */ |