blob: e0925ab2952247920962052df4bbbfca550e19a6 [file] [log] [blame]
Channagoud Kadabi9dc19c82015-04-23 14:20:55 -07001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are
5met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above
9 copyright notice, this list of conditions and the following
10 disclaimer in the documentation and/or other materials provided
11 with the distribution.
12 * Neither the name of The Linux Foundation nor the names of its
13 contributors may be used to endorse or promote products derived
14 from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29/*===========================================================================
30
31 INCLUDE FILES
32
33===========================================================================*/
Channagoud Kadabi4ab0b172015-07-13 20:12:26 -070034#include "pm_app_smbchg.h"
Channagoud Kadabi9dc19c82015-04-23 14:20:55 -070035#include "pm_smbchg_driver.h"
Channagoud Kadabi4ab0b172015-07-13 20:12:26 -070036#include "pm_comm.h"
37
Channagoud Kadabi9dc19c82015-04-23 14:20:55 -070038/*===========================================================================
39
40 STATIC VARIABLES
41
42===========================================================================*/
43
44/* Static global variable to store the SMBCHG driver data */
Channagoud Kadabi4ab0b172015-07-13 20:12:26 -070045pm_smbchg_data_type smb_data[PM_MAX_NUM_PMICS];
46
47/* Initialize bat i/f registers */
48smbchg_bat_if_register_ds bat_if_reg[1] =
49 { /* Battery interface register base and offsets */
50 {
51 0x1200, 0x5, 0x8, 0x10, 0x11, 0x12, 0x13,
52 0x14, 0x15, 0x16, 0x18, 0x19, 0x1a, 0x1b,
53 0x40, 0x41, 0x42, 0xD0, 0xDF, 0xE0, 0xE1, 0xF0,
54 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9,
55 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
56 },
57 };
58
59/* Initialize usb charger path registers */
60smbchg_usb_chgpth_register_ds usb_chgpath_reg[1] =
61 { /* Charger path register base & offset */
62 {
63 0x1300, 0x5, 0x7, 0x8, 0x9, 0xA, 0xB,
64 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12,
65 0x13, 0x14, 0x15, 0x16, 0x18, 0x19,
66 0x1A, 0x1B, 0x40, 0x44, 0x4E, 0xD0, 0xF1,
67 0xF2, 0xF3, 0xF4, 0xF5, 0xFF
68 },
69 };
70
71/* Initialize dc charger path registers */
72smbchg_dc_chgpth_register_ds dc_chgpath_reg[1] =
73 { /* DC charge path base & offset */
74 {
75 0x1400, 0x5, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
76 0x18, 0x19, 0x1A, 0x1B, 0xD0, 0xDF, 0xE0, 0xE1, 0xE2,
77 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xFA
78 },
79 };
80
81/* Initialize misc charger registers */
82smbchg_misc_register_ds misc_reg[1] =
83 { /* Misc charge register base & offsets */
84 {
85 0x1600, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x8,
86 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
87 0x18, 0x19, 0x1A, 0x1B, 0x40, 0x41, 0x42,
88 0xD0, 0xDF, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5,
89 0xF6, 0xF7, 0xF8, 0xFF
90 },
91 };
92
93smbchg_chgr_register_ds smb_chgr_reg[1] =
94 {
95 {
96 0x1000, 0x5, 0x8, 0xB, 0xC, 0xD, 0xE, 0x10, 0x11,
97 0x12, 0x13, 0x14, 0x15, 0x16, 0x18, 0x19, 0x1A,
98 0x1B, 0xD0, 0xDF, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5,
99 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD,
100 0xFE, 0xFF,
101 },
102 };
103
104pm_comm_info_type comm_ptr[1] =
105 { /* slave_id , pmic index, and comm type (comm type is unused) */
106 {0x2, 0x1, 0x0},
107 };
108
109/* Initialize the SMB charger data structure */
110smbchg_register_ds smb_charge[1] =
111 {
112 {
113 NULL,
114 &smb_chgr_reg[0],
115 NULL,
116 &bat_if_reg[0],
117 &usb_chgpath_reg[0],
118 &dc_chgpath_reg[0],
119 &misc_reg[0],
120 },
121 };
122
123/* Initialize the SMB data */
124void pm_smbchg_driver_init(uint32_t device_index)
125{
126
127 smb_data[device_index].smbchg_register = &smb_charge[0];
128 smb_data[device_index].comm_ptr = &comm_ptr[0];
129 smb_data[device_index].chg_range_data = (chg_range_data_type *) pm_target_chg_range_data();
130}
131
Channagoud Kadabi9dc19c82015-04-23 14:20:55 -0700132/*===========================================================================
133
134 FUNCTION DEFINITIONS
135
136===========================================================================*/
Channagoud Kadabi9dc19c82015-04-23 14:20:55 -0700137
Channagoud Kadabi4ab0b172015-07-13 20:12:26 -0700138pm_smbchg_data_type* pm_smbchg_get_data(uint32 pmic_index)
Channagoud Kadabi9dc19c82015-04-23 14:20:55 -0700139{
140 if(pmic_index < PM_MAX_NUM_PMICS)
141 {
Channagoud Kadabi4ab0b172015-07-13 20:12:26 -0700142 return &smb_data[pmic_index];
Channagoud Kadabi9dc19c82015-04-23 14:20:55 -0700143 }
144
145 return NULL;
146}