Shashank Mittal | 402d097 | 2010-09-29 10:09:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * * Copyright (c) 2010, Code Aurora Forum. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include <debug.h> |
| 31 | #include <reg.h> |
| 32 | #include <platform/iomap.h> |
| 33 | #include <platform/pmic.h> |
| 34 | |
| 35 | typedef int (*pm8058_write_func) (unsigned char *, unsigned short, |
| 36 | unsigned short); |
| 37 | extern int pa1_ssbi2_write_bytes(unsigned char *buffer, unsigned short length, |
| 38 | unsigned short slave_addr); |
| 39 | |
| 40 | /*PM8058*/ |
| 41 | void pm8058_write_one(unsigned data, unsigned address) |
| 42 | { |
| 43 | pm8058_write_func wr_function = &pa1_ssbi2_write_bytes; |
| 44 | if (wr_function == NULL) |
| 45 | return; |
| 46 | if ((*wr_function) (&data, 1, address)) |
| 47 | dprintf(CRITICAL, "Error in initializing register\n"); |
| 48 | |
| 49 | } |
| 50 | |
| 51 | /*PM8901*/ |
| 52 | extern int pa2_ssbi2_write_bytes(unsigned char *buffer, unsigned short length, |
| 53 | unsigned short slave_addr); |
| 54 | extern int pa2_ssbi2_read_bytes(unsigned char *buffer, unsigned short length, |
| 55 | unsigned short slave_addr); |
| 56 | /* |
| 57 | * Write to the control registers on PMIC via the SSBI2 interface. |
| 58 | * Returns : (0) on success and (-1) on error. |
| 59 | */ |
| 60 | int pm8901_write(uint8_t * buffer, uint32_t length, uint32_t slave_addr) |
| 61 | { |
| 62 | return pa2_ssbi2_write_bytes(buffer, length, slave_addr); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Read from the control registers on PMIC via the SSBI2 interface. |
| 67 | * Returns : (0) on success and (-1) on error. |
| 68 | */ |
| 69 | int pm8901_read(uint8_t * buffer, uint32_t length, uint32_t slave_addr) |
| 70 | { |
| 71 | return pa2_ssbi2_read_bytes(buffer, length, slave_addr); |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * PMIC 8901 LDO vreg read. |
| 76 | */ |
| 77 | int pm8901_test_bank_read(uint8_t * buffer, uint8_t bank, uint16_t addr) |
| 78 | { |
| 79 | int ret = pm8901_write(&bank, 1, addr); |
| 80 | /* if the write does not work we can't read. */ |
| 81 | if (ret) { |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | return pm8901_read(buffer, 1, addr); |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * PMIC 8901 LDO vreg write. |
| 90 | */ |
| 91 | int pm8901_vreg_write(uint8_t * buffer, uint8_t mask, uint16_t addr, |
| 92 | uint8_t prev_val) |
| 93 | { |
| 94 | uint8_t reg; |
| 95 | |
| 96 | /* Clear the bits we want to try and set. */ |
| 97 | reg = (prev_val & ~mask); |
| 98 | /* Set the bits we want to set, before writing them to addr */ |
| 99 | reg |= (*buffer & mask); |
| 100 | return pm8901_write(®, 1, addr); |
| 101 | } |