Commit c7336815078ff3745e3130aeff35991e3e98e61e

Authored by Łukasz Majewski
Committed by Anatolij Gustschin
1 parent 452329f1d5
Exists in master and in 57 other branches 8qm-imx_v2020.04_5.4.70_2.3.0, emb_lf-6.6.52-2.2.0, emb_lf_v2022.04, emb_lf_v2023.04, emb_lf_v2024.04, imx_v2015.04_4.1.15_1.0.0_ga, pitx_8mp_lf_v2020.04, smarc-8m-android-10.0.0_2.6.0, smarc-8m-android-11.0.0_2.0.0, smarc-8mp-android-11.0.0_2.0.0, smarc-emmc-imx_v2014.04_3.10.53_1.1.0_ga, smarc-emmc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx-l5.0.0_1.0.0-ga, smarc-imx6_v2018.03_4.14.98_2.0.0_ga, smarc-imx7_v2017.03_4.9.11_1.0.0_ga, smarc-imx7_v2018.03_4.14.98_2.0.0_ga, smarc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx_v2015.04_4.1.15_1.0.0_ga, smarc-imx_v2017.03_4.9.11_1.0.0_ga, smarc-imx_v2017.03_4.9.88_2.0.0_ga, smarc-imx_v2017.03_o8.1.0_1.3.0_8m, smarc-imx_v2018.03_4.14.78_1.0.0_ga, smarc-m6.0.1_2.1.0-ga, smarc-n7.1.2_2.0.0-ga, smarc-rel_imx_4.1.15_2.0.0_ga, smarc_8m-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8m-imx_v2019.04_4.19.35_1.1.0, smarc_8m_00d0-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2019.04_4.19.35_1.1.0, smarc_8mm-imx_v2020.04_5.4.24_2.1.0, smarc_8mp_lf_v2020.04, smarc_8mq-imx_v2020.04_5.4.24_2.1.0, smarc_8mq_lf_v2020.04, ti-u-boot-2015.07, u-boot-2013.01.y, v2013.10, v2013.10-smarct33, v2013.10-smartmen, v2014.01, v2014.04, v2014.04-smarct33, v2014.04-smarct33-emmc, v2014.04-smartmen, v2014.07, v2014.07-smarct33, v2014.07-smartmen, v2015.07-smarct33, v2015.07-smarct33-emmc, v2015.07-smarct4x, v2016.05-dlt, v2016.05-smarct3x, v2016.05-smarct3x-emmc, v2016.05-smarct4x, v2017.01-smarct3x, v2017.01-smarct3x-emmc, v2017.01-smarct4x

pmic: Extend PMIC framework to support multiple instances of PMIC devices

The PMIC framework has been extended to support multiple instances of
the variety of devices responsible for power management.
This change allows supporting of e.g. fuel gauge, charger, MUIC (Micro USB
Interface Circuit).
Power related includes have been moved to ./include/power directory.
This is a first of a series of patches - in the future "pmic" will be
replaced with "power".

Two important issues:
1. The PMIC needs to be initialized just after malloc is configured
2. It uses list to hold information about available PMIC devices

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>

Showing 26 changed files with 631 additions and 449 deletions Side-by-side Diff

board/davedenx/qong/qong.c
... ... @@ -28,11 +28,12 @@
28 28 #include <asm/arch/sys_proto.h>
29 29 #include <asm/io.h>
30 30 #include <nand.h>
31   -#include <pmic.h>
  31 +#include <power/pmic.h>
32 32 #include <fsl_pmic.h>
33 33 #include <asm/gpio.h>
34 34 #include "qong_fpga.h"
35 35 #include <watchdog.h>
  36 +#include <errno.h>
36 37  
37 38 DECLARE_GLOBAL_DATA_PTR;
38 39  
39 40  
40 41  
... ... @@ -172,10 +173,15 @@
172 173 {
173 174 u32 val;
174 175 struct pmic *p;
  176 + int ret;
175 177  
176   - pmic_init();
177   - p = get_pmic();
  178 + ret = pmic_init(I2C_PMIC);
  179 + if (ret)
  180 + return ret;
178 181  
  182 + p = pmic_get("FSL_PMIC");
  183 + if (!p)
  184 + return -ENODEV;
179 185 /* Enable RTC battery */
180 186 pmic_reg_read(p, REG_POWER_CTL0, &val);
181 187 pmic_reg_write(p, REG_POWER_CTL0, val | COINCHEN);
board/freescale/mx31pdk/mx31pdk.c
... ... @@ -30,8 +30,9 @@
30 30 #include <asm/arch/imx-regs.h>
31 31 #include <asm/arch/sys_proto.h>
32 32 #include <watchdog.h>
33   -#include <pmic.h>
  33 +#include <power/pmic.h>
34 34 #include <fsl_pmic.h>
  35 +#include <errno.h>
35 36  
36 37 DECLARE_GLOBAL_DATA_PTR;
37 38  
38 39  
39 40  
... ... @@ -83,10 +84,15 @@
83 84 {
84 85 u32 val;
85 86 struct pmic *p;
  87 + int ret;
86 88  
87   - pmic_init();
88   - p = get_pmic();
  89 + ret = pmic_init(I2C_PMIC);
  90 + if (ret)
  91 + return ret;
89 92  
  93 + p = pmic_get("FSL_PMIC");
  94 + if (!p)
  95 + return -ENODEV;
90 96 /* Enable RTC battery */
91 97 pmic_reg_read(p, REG_POWER_CTL0, &val);
92 98 pmic_reg_write(p, REG_POWER_CTL0, val | COINCHEN);
board/freescale/mx35pdk/mx35pdk.c
... ... @@ -31,7 +31,7 @@
31 31 #include <asm/arch/mx35_pins.h>
32 32 #include <asm/arch/iomux.h>
33 33 #include <i2c.h>
34   -#include <pmic.h>
  34 +#include <power/pmic.h>
35 35 #include <fsl_pmic.h>
36 36 #include <mmc.h>
37 37 #include <fsl_esdhc.h>
... ... @@ -207,7 +207,9 @@
207 207 static inline int pmic_detect(void)
208 208 {
209 209 unsigned int id;
210   - struct pmic *p = get_pmic();
  210 + struct pmic *p = pmic_get("FSL_PMIC");
  211 + if (!p)
  212 + return -ENODEV;
211 213  
212 214 pmic_reg_read(p, REG_IDENTIFICATION, &id);
213 215  
214 216  
215 217  
... ... @@ -231,10 +233,14 @@
231 233 u8 val;
232 234 u32 pmic_val;
233 235 struct pmic *p;
  236 + int ret;
234 237  
235   - pmic_init();
  238 + ret = pmic_init(I2C_PMIC);
  239 + if (ret)
  240 + return ret;
  241 +
236 242 if (pmic_detect()) {
237   - p = get_pmic();
  243 + p = pmic_get("FSL_PMIC");
238 244 mxc_request_iomux(MX35_PIN_WATCHDOG_RST, MUX_CONFIG_SION |
239 245 MUX_CONFIG_ALT1);
240 246  
board/freescale/mx51evk/mx51evk.c
... ... @@ -33,7 +33,7 @@
33 33 #include <i2c.h>
34 34 #include <mmc.h>
35 35 #include <fsl_esdhc.h>
36   -#include <pmic.h>
  36 +#include <power/pmic.h>
37 37 #include <fsl_pmic.h>
38 38 #include <mc13892.h>
39 39 #include <usb/ehci-fsl.h>
40 40  
... ... @@ -252,9 +252,15 @@
252 252 unsigned int val;
253 253 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
254 254 struct pmic *p;
  255 + int ret;
255 256  
256   - pmic_init();
257   - p = get_pmic();
  257 + ret = pmic_init(I2C_PMIC);
  258 + if (ret)
  259 + return;
  260 +
  261 + p = pmic_get("FSL_PMIC");
  262 + if (!p)
  263 + return;
258 264  
259 265 /* Write needed to Power Gate 2 register */
260 266 pmic_reg_read(p, REG_POWER_MISC, &val);
board/freescale/mx53evk/mx53evk.c
... ... @@ -34,7 +34,7 @@
34 34 #include <i2c.h>
35 35 #include <mmc.h>
36 36 #include <fsl_esdhc.h>
37   -#include <pmic.h>
  37 +#include <power/pmic.h>
38 38 #include <fsl_pmic.h>
39 39 #include <asm/gpio.h>
40 40 #include <mc13892.h>
41 41  
... ... @@ -123,9 +123,15 @@
123 123 {
124 124 unsigned int val;
125 125 struct pmic *p;
  126 + int ret;
126 127  
127   - pmic_init();
128   - p = get_pmic();
  128 + ret = pmic_init(I2C_PMIC);
  129 + if (ret)
  130 + return;
  131 +
  132 + p = pmic_get("FSL_PMIC");
  133 + if (!p)
  134 + return;
129 135  
130 136 /* Set VDDA to 1.25V */
131 137 pmic_reg_read(p, REG_SW_2, &val);
board/freescale/mx53loco/mx53loco.c
... ... @@ -36,7 +36,7 @@
36 36 #include <mmc.h>
37 37 #include <fsl_esdhc.h>
38 38 #include <asm/gpio.h>
39   -#include <pmic.h>
  39 +#include <power/pmic.h>
40 40 #include <dialog_pmic.h>
41 41 #include <fsl_pmic.h>
42 42 #include <linux/fb.h>
43 43  
44 44  
... ... @@ -344,11 +344,17 @@
344 344 unsigned int val;
345 345 int ret = -1;
346 346 struct pmic *p;
  347 + int retval;
347 348  
348 349 if (!i2c_probe(CONFIG_SYS_DIALOG_PMIC_I2C_ADDR)) {
349   - pmic_dialog_init();
350   - p = get_pmic();
  350 + retval = pmic_dialog_init(I2C_PMIC);
  351 + if (retval)
  352 + return retval;
351 353  
  354 + p = pmic_get("DIALOG_PMIC");
  355 + if (!p)
  356 + return -ENODEV;
  357 +
352 358 /* Set VDDA to 1.25V */
353 359 val = DA9052_BUCKCORE_BCOREEN | DA_BUCKCORE_VBCORE_1_250V;
354 360 ret = pmic_reg_write(p, DA9053_BUCKCORE_REG, val);
... ... @@ -363,8 +369,13 @@
363 369 }
364 370  
365 371 if (!i2c_probe(CONFIG_SYS_FSL_PMIC_I2C_ADDR)) {
366   - pmic_init();
367   - p = get_pmic();
  372 + retval = pmic_init(I2C_PMIC);
  373 + if (retval)
  374 + return retval;
  375 +
  376 + p = pmic_get("DIALOG_PMIC");
  377 + if (!p)
  378 + return -ENODEV;
368 379  
369 380 /* Set VDDGP to 1.25V for 1GHz on SW1 */
370 381 pmic_reg_read(p, REG_SW_0, &val);
board/genesi/mx51_efikamx/efikamx.c
... ... @@ -33,7 +33,7 @@
33 33 #include <i2c.h>
34 34 #include <mmc.h>
35 35 #include <fsl_esdhc.h>
36   -#include <pmic.h>
  36 +#include <power/pmic.h>
37 37 #include <fsl_pmic.h>
38 38 #include <mc13892.h>
39 39  
40 40  
... ... @@ -173,9 +173,15 @@
173 173 unsigned int val;
174 174 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
175 175 struct pmic *p;
  176 + int ret;
176 177  
177   - pmic_init();
178   - p = get_pmic();
  178 + ret = pmic_init(I2C_PMIC);
  179 + if (ret)
  180 + return;
  181 +
  182 + p = pmic_get("FSL_PMIC");
  183 + if (!p)
  184 + return;
179 185  
180 186 /* Write needed to Power Gate 2 register */
181 187 pmic_reg_read(p, REG_POWER_MISC, &val);
board/hale/tt01/tt01.c
... ... @@ -25,12 +25,13 @@
25 25 #include <common.h>
26 26 #include <netdev.h>
27 27 #include <command.h>
28   -#include <pmic.h>
  28 +#include <power/pmic.h>
29 29 #include <fsl_pmic.h>
30 30 #include <mc13783.h>
31 31 #include <asm/arch/clock.h>
32 32 #include <asm/arch/sys_proto.h>
33 33 #include <asm/io.h>
  34 +#include <errno.h>
34 35  
35 36 DECLARE_GLOBAL_DATA_PTR;
36 37  
37 38  
... ... @@ -195,14 +196,21 @@
195 196 {
196 197 u32 val;
197 198 struct pmic *p;
  199 + int ret;
198 200  
199 201 /*
200 202 * this is the first driver to use the pmic, so call
201 203 * pmic_init() here. board_late_init() is too late for
202 204 * the MMC driver.
203 205 */
204   - pmic_init();
205   - p = get_pmic();
  206 +
  207 + ret = pmic_init(I2C_PMIC);
  208 + if (ret)
  209 + return ret;
  210 +
  211 + p = pmic_get("FSL_PMIC");
  212 + if (!p)
  213 + return -ENODEV;
206 214  
207 215 /* configure pins for SDHC1 only */
208 216 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SD1_CLK, MUX_CTL_FUNC));
board/samsung/goni/goni.c
... ... @@ -25,10 +25,10 @@
25 25 #include <common.h>
26 26 #include <asm/arch/gpio.h>
27 27 #include <asm/arch/mmc.h>
28   -#include <pmic.h>
  28 +#include <power/pmic.h>
29 29 #include <usb/s3c_udc.h>
30 30 #include <asm/arch/cpu.h>
31   -#include <max8998_pmic.h>
  31 +#include <power/max8998_pmic.h>
32 32 DECLARE_GLOBAL_DATA_PTR;
33 33  
34 34 static struct s5pc110_gpio *s5pc110_gpio;
35 35  
... ... @@ -42,8 +42,9 @@
42 42 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
43 43  
44 44 #if defined(CONFIG_PMIC)
45   - pmic_init();
  45 + pmic_init(I2C_5);
46 46 #endif
  47 +
47 48 return 0;
48 49 }
49 50  
... ... @@ -108,7 +109,9 @@
108 109 {
109 110 int ret;
110 111 static int status;
111   - struct pmic *p = get_pmic();
  112 + struct pmic *p = pmic_get("MAX8998_PMIC");
  113 + if (!p)
  114 + return -ENODEV;
112 115  
113 116 if (pmic_probe(p))
114 117 return -1;
board/samsung/trats/trats.c
... ... @@ -34,9 +34,9 @@
34 34 #include <asm/arch/mipi_dsim.h>
35 35 #include <asm/arch/watchdog.h>
36 36 #include <asm/arch/power.h>
37   -#include <pmic.h>
  37 +#include <power/pmic.h>
38 38 #include <usb/s3c_udc.h>
39   -#include <max8997_pmic.h>
  39 +#include <power/max8997_pmic.h>
40 40 #include <libtizen.h>
41 41  
42 42 #include "setup.h"
... ... @@ -69,7 +69,7 @@
69 69 printf("HW Revision:\t0x%x\n", board_rev);
70 70  
71 71 #if defined(CONFIG_PMIC)
72   - pmic_init();
  72 + pmic_init(I2C_5);
73 73 #endif
74 74  
75 75 return 0;
... ... @@ -238,7 +238,9 @@
238 238 {
239 239 int ret = 0;
240 240 u32 val = 0;
241   - struct pmic *p = get_pmic();
  241 + struct pmic *p = pmic_get("MAX8997_PMIC");
  242 + if (!p)
  243 + return -ENODEV;
242 244  
243 245 if (pmic_probe(p))
244 246 return -1;
... ... @@ -413,7 +415,9 @@
413 415 static int lcd_power(void)
414 416 {
415 417 int ret = 0;
416   - struct pmic *p = get_pmic();
  418 + struct pmic *p = pmic_get("MAX8997_PMIC");
  419 + if (!p)
  420 + return -ENODEV;
417 421  
418 422 if (pmic_probe(p))
419 423 return 0;
... ... @@ -473,7 +477,9 @@
473 477 static int mipi_power(void)
474 478 {
475 479 int ret = 0;
476   - struct pmic *p = get_pmic();
  480 + struct pmic *p = pmic_get("MAX8997_PMIC");
  481 + if (!p)
  482 + return -ENODEV;
477 483  
478 484 if (pmic_probe(p))
479 485 return 0;
board/samsung/universal_c210/universal.c
... ... @@ -27,10 +27,10 @@
27 27 #include <asm/arch/adc.h>
28 28 #include <asm/arch/gpio.h>
29 29 #include <asm/arch/mmc.h>
30   -#include <pmic.h>
  30 +#include <power/pmic.h>
31 31 #include <usb/s3c_udc.h>
32 32 #include <asm/arch/cpu.h>
33   -#include <max8998_pmic.h>
  33 +#include <power/max8998_pmic.h>
34 34  
35 35 DECLARE_GLOBAL_DATA_PTR;
36 36  
... ... @@ -59,7 +59,7 @@
59 59 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
60 60  
61 61 #if defined(CONFIG_PMIC)
62   - pmic_init();
  62 + pmic_init(I2C_5);
63 63 #endif
64 64  
65 65 check_hw_revision();
... ... @@ -112,7 +112,9 @@
112 112 static int adc_power_control(int on)
113 113 {
114 114 int ret;
115   - struct pmic *p = get_pmic();
  115 + struct pmic *p = pmic_get("MAX8998_PMIC");
  116 + if (!p)
  117 + return -ENODEV;
116 118  
117 119 if (pmic_probe(p))
118 120 return -1;
... ... @@ -280,7 +282,9 @@
280 282 static int s5pc210_phy_control(int on)
281 283 {
282 284 int ret = 0;
283   - struct pmic *p = get_pmic();
  285 + struct pmic *p = pmic_get("MAX8998_PMIC");
  286 + if (!p)
  287 + return -ENODEV;
284 288  
285 289 if (pmic_probe(p))
286 290 return -1;
board/ttcontrol/vision2/vision2.c
... ... @@ -34,7 +34,7 @@
34 34 #include <asm/arch/sys_proto.h>
35 35 #include <i2c.h>
36 36 #include <mmc.h>
37   -#include <pmic.h>
  37 +#include <power/pmic.h>
38 38 #include <fsl_esdhc.h>
39 39 #include <fsl_pmic.h>
40 40 #include <mc13892.h>
41 41  
... ... @@ -306,9 +306,15 @@
306 306 {
307 307 unsigned int val;
308 308 struct pmic *p;
  309 + int ret;
309 310  
310   - pmic_init();
311   - p = get_pmic();
  311 + ret = pmic_init(I2C_PMIC);
  312 + if (ret)
  313 + return;
  314 +
  315 + p = pmic_get("FSL_PMIC");
  316 + if (!p)
  317 + return;
312 318  
313 319 /* Write needed to Power Gate 2 register */
314 320 pmic_reg_read(p, REG_POWER_MISC, &val);
drivers/misc/pmic_core.c
... ... @@ -27,18 +27,21 @@
27 27 */
28 28  
29 29 #include <common.h>
  30 +#include <malloc.h>
30 31 #include <linux/types.h>
31   -#include <pmic.h>
  32 +#include <linux/list.h>
  33 +#include <power/pmic.h>
32 34  
33   -static struct pmic pmic;
  35 +static LIST_HEAD(pmic_list);
34 36  
35   -int check_reg(u32 reg)
  37 +int check_reg(struct pmic *p, u32 reg)
36 38 {
37   - if (reg >= pmic.number_of_regs) {
  39 + if (reg >= p->number_of_regs) {
38 40 printf("<reg num> = %d is invalid. Should be less than %d\n",
39   - reg, pmic.number_of_regs);
  41 + reg, p->number_of_regs);
40 42 return -1;
41 43 }
  44 +
42 45 return 0;
43 46 }
44 47  
45 48  
... ... @@ -65,11 +68,16 @@
65 68 printf("PMIC: %s\n", p->name);
66 69 }
67 70  
68   -static void pmic_dump(struct pmic *p)
  71 +static int pmic_dump(struct pmic *p)
69 72 {
70 73 int i, ret;
71 74 u32 val;
72 75  
  76 + if (!p) {
  77 + puts("Wrong PMIC name!\n");
  78 + return -1;
  79 + }
  80 +
73 81 pmic_show_info(p);
74 82 for (i = 0; i < p->number_of_regs; i++) {
75 83 ret = pmic_reg_read(p, i, &val);
76 84  
77 85  
78 86  
79 87  
80 88  
81 89  
82 90  
83 91  
84 92  
85 93  
... ... @@ -82,35 +90,84 @@
82 90 printf("%08x ", val);
83 91 }
84 92 puts("\n");
  93 + return 0;
85 94 }
86 95  
87   -struct pmic *get_pmic(void)
  96 +struct pmic *pmic_alloc(void)
88 97 {
89   - return &pmic;
  98 + struct pmic *p;
  99 +
  100 + p = calloc(sizeof(*p), 1);
  101 + if (!p) {
  102 + printf("%s: No available memory for allocation!\n", __func__);
  103 + return NULL;
  104 + }
  105 +
  106 + list_add_tail(&p->list, &pmic_list);
  107 +
  108 + debug("%s: new pmic struct: 0x%p\n", __func__, p);
  109 +
  110 + return p;
90 111 }
91 112  
  113 +struct pmic *pmic_get(const char *s)
  114 +{
  115 + struct pmic *p;
  116 +
  117 + list_for_each_entry(p, &pmic_list, list) {
  118 + if (strcmp(p->name, s) == 0) {
  119 + debug("%s: pmic %s -> 0x%p\n", __func__, p->name, p);
  120 + return p;
  121 + }
  122 + }
  123 +
  124 + return NULL;
  125 +}
  126 +
  127 +static void pmic_list_names(void)
  128 +{
  129 + struct pmic *p;
  130 +
  131 + puts("PMIC devices:\n");
  132 + list_for_each_entry(p, &pmic_list, list) {
  133 + printf("name: %s\n", p->name);
  134 + }
  135 +}
  136 +
92 137 int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
93 138 {
94 139 u32 ret, reg, val;
  140 + struct pmic *p;
95 141 char *cmd;
96 142  
97   - struct pmic *p = &pmic;
98   -
99 143 /* at least two arguments please */
100 144 if (argc < 2)
101   - return cmd_usage(cmdtp);
  145 + return CMD_RET_USAGE;
102 146  
103 147 cmd = argv[1];
  148 +
  149 + if (strcmp(cmd, "list") == 0) {
  150 + pmic_list_names();
  151 + return CMD_RET_SUCCESS;
  152 + }
  153 +
104 154 if (strcmp(cmd, "dump") == 0) {
105   - pmic_dump(p);
106   - return 0;
  155 + p = pmic_get(argv[2]);
  156 + if (!p)
  157 + return CMD_RET_FAILURE;
  158 + if (pmic_dump(p))
  159 + return CMD_RET_FAILURE;
  160 + return CMD_RET_SUCCESS;
107 161 }
108 162  
109 163 if (strcmp(cmd, "read") == 0) {
110   - if (argc < 3)
111   - return cmd_usage(cmdtp);
  164 + if (argc < 4)
  165 + return CMD_RET_USAGE;
112 166  
113   - reg = simple_strtoul(argv[2], NULL, 16);
  167 + reg = simple_strtoul(argv[3], NULL, 16);
  168 + p = pmic_get(argv[2]);
  169 + if (!p)
  170 + return CMD_RET_FAILURE;
114 171  
115 172 ret = pmic_reg_read(p, reg, &val);
116 173  
117 174  
118 175  
119 176  
120 177  
121 178  
... ... @@ -119,30 +176,33 @@
119 176  
120 177 printf("\n0x%02x: 0x%08x\n", reg, val);
121 178  
122   - return 0;
  179 + return CMD_RET_SUCCESS;
123 180 }
124 181  
125 182 if (strcmp(cmd, "write") == 0) {
126   - if (argc < 4)
127   - return cmd_usage(cmdtp);
  183 + if (argc < 5)
  184 + return CMD_RET_USAGE;
128 185  
129   - reg = simple_strtoul(argv[2], NULL, 16);
130   - val = simple_strtoul(argv[3], NULL, 16);
131   -
  186 + reg = simple_strtoul(argv[3], NULL, 16);
  187 + val = simple_strtoul(argv[4], NULL, 16);
  188 + p = pmic_get(argv[2]);
  189 + if (!p)
  190 + return CMD_RET_FAILURE;
132 191 pmic_reg_write(p, reg, val);
133 192  
134   - return 0;
  193 + return CMD_RET_SUCCESS;
135 194 }
136 195  
137 196 /* No subcommand found */
138   - return 1;
  197 + return CMD_RET_SUCCESS;
139 198 }
140 199  
141 200 U_BOOT_CMD(
142 201 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
143 202 "PMIC",
144   - "dump - dump PMIC registers\n"
145   - "pmic read <reg> - read register\n"
146   - "pmic write <reg> <value> - write register"
  203 + "list - list available PMICs\n"
  204 + "pmic dump name - dump named PMIC registers\n"
  205 + "pmic name read <reg> - read register\n"
  206 + "pmic name write <reg> <value> - write register"
147 207 );
drivers/misc/pmic_dialog.c
... ... @@ -17,21 +17,27 @@
17 17 */
18 18  
19 19 #include <common.h>
20   -#include <pmic.h>
  20 +#include <power/pmic.h>
21 21 #include <dialog_pmic.h>
  22 +#include <errno.h>
22 23  
23   -int pmic_dialog_init(void)
  24 +int pmic_dialog_init(unsigned char bus)
24 25 {
25   - struct pmic *p = get_pmic();
26 26 static const char name[] = "DIALOG_PMIC";
  27 + struct pmic *p = pmic_alloc();
27 28  
  29 + if (!p) {
  30 + printf("%s: POWER allocation error!\n", __func__);
  31 + return -ENOMEM;
  32 + }
  33 +
28 34 p->name = name;
29 35 p->number_of_regs = DIALOG_NUM_OF_REGS;
30 36  
31 37 p->interface = PMIC_I2C;
32 38 p->hw.i2c.addr = CONFIG_SYS_DIALOG_PMIC_I2C_ADDR;
33 39 p->hw.i2c.tx_num = 1;
34   - p->bus = I2C_PMIC;
  40 + p->bus = bus;
35 41  
36 42 return 0;
37 43 }
drivers/misc/pmic_fsl.c
... ... @@ -23,8 +23,9 @@
23 23  
24 24 #include <common.h>
25 25 #include <spi.h>
26   -#include <pmic.h>
  26 +#include <power/pmic.h>
27 27 #include <fsl_pmic.h>
  28 +#include <errno.h>
28 29  
29 30 #if defined(CONFIG_PMIC_SPI)
30 31 static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
31 32  
32 33  
33 34  
... ... @@ -33,11 +34,16 @@
33 34 }
34 35 #endif
35 36  
36   -int pmic_init(void)
  37 +int pmic_init(unsigned char bus)
37 38 {
38   - struct pmic *p = get_pmic();
39 39 static const char name[] = "FSL_PMIC";
  40 + struct pmic *p = pmic_alloc();
40 41  
  42 + if (!p) {
  43 + printf("%s: POWER allocation error!\n", __func__);
  44 + return -ENOMEM;
  45 + }
  46 +
41 47 p->name = name;
42 48 p->number_of_regs = PMIC_NUM_OF_REGS;
43 49  
... ... @@ -54,7 +60,7 @@
54 60 p->interface = PMIC_I2C;
55 61 p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR;
56 62 p->hw.i2c.tx_num = 3;
57   - p->bus = I2C_PMIC;
  63 + p->bus = bus;
58 64 #else
59 65 #error "You must select CONFIG_PMIC_SPI or CONFIG_PMIC_I2C"
60 66 #endif
drivers/misc/pmic_i2c.c
... ... @@ -28,7 +28,7 @@
28 28  
29 29 #include <common.h>
30 30 #include <linux/types.h>
31   -#include <pmic.h>
  31 +#include <power/pmic.h>
32 32 #include <i2c.h>
33 33 #include <compiler.h>
34 34  
... ... @@ -36,7 +36,7 @@
36 36 {
37 37 unsigned char buf[4] = { 0 };
38 38  
39   - if (check_reg(reg))
  39 + if (check_reg(p, reg))
40 40 return -1;
41 41  
42 42 switch (pmic_i2c_tx_num) {
... ... @@ -79,7 +79,7 @@
79 79 unsigned char buf[4] = { 0 };
80 80 u32 ret_val = 0;
81 81  
82   - if (check_reg(reg))
  82 + if (check_reg(p, reg))
83 83 return -1;
84 84  
85 85 if (i2c_read(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
drivers/misc/pmic_max8997.c
... ... @@ -22,15 +22,21 @@
22 22 */
23 23  
24 24 #include <common.h>
25   -#include <pmic.h>
26   -#include <max8997_pmic.h>
  25 +#include <power/pmic.h>
  26 +#include <power/max8997_pmic.h>
27 27 #include <i2c.h>
  28 +#include <errno.h>
28 29  
29   -int pmic_init(void)
  30 +int pmic_init(unsigned char bus)
30 31 {
31   - struct pmic *p = get_pmic();
32 32 static const char name[] = "MAX8997_PMIC";
  33 + struct pmic *p = pmic_alloc();
33 34  
  35 + if (!p) {
  36 + printf("%s: POWER allocation error!\n", __func__);
  37 + return -ENOMEM;
  38 + }
  39 +
34 40 puts("Board PMIC init\n");
35 41  
36 42 p->name = name;
... ... @@ -38,7 +44,7 @@
38 44 p->number_of_regs = PMIC_NUM_OF_REGS;
39 45 p->hw.i2c.addr = MAX8997_I2C_ADDR;
40 46 p->hw.i2c.tx_num = 1;
41   - p->bus = I2C_0;
  47 + p->bus = bus;
42 48  
43 49 return 0;
44 50 }
drivers/misc/pmic_max8998.c
... ... @@ -22,14 +22,20 @@
22 22 */
23 23  
24 24 #include <common.h>
25   -#include <pmic.h>
26   -#include <max8998_pmic.h>
  25 +#include <power/pmic.h>
  26 +#include <power/max8998_pmic.h>
  27 +#include <errno.h>
27 28  
28   -int pmic_init(void)
  29 +int pmic_init(unsigned char bus)
29 30 {
30   - struct pmic *p = get_pmic();
31 31 static const char name[] = "MAX8998_PMIC";
  32 + struct pmic *p = pmic_alloc();
32 33  
  34 + if (!p) {
  35 + printf("%s: POWER allocation error!\n", __func__);
  36 + return -ENOMEM;
  37 + }
  38 +
33 39 puts("Board PMIC init\n");
34 40  
35 41 p->name = name;
... ... @@ -37,7 +43,7 @@
37 43 p->number_of_regs = PMIC_NUM_OF_REGS;
38 44 p->hw.i2c.addr = MAX8998_I2C_ADDR;
39 45 p->hw.i2c.tx_num = 1;
40   - p->bus = I2C_PMIC;
  46 + p->bus = bus;
41 47  
42 48 return 0;
43 49 }
drivers/misc/pmic_spi.c
... ... @@ -28,7 +28,7 @@
28 28  
29 29 #include <common.h>
30 30 #include <linux/types.h>
31   -#include <pmic.h>
  31 +#include <power/pmic.h>
32 32 #include <spi.h>
33 33  
34 34 static struct spi_slave *slave;
... ... @@ -59,7 +59,7 @@
59 59 return -1;
60 60 }
61 61  
62   - if (check_reg(reg))
  62 + if (check_reg(p, reg))
63 63 return -1;
64 64  
65 65 if (spi_claim_bus(slave))
drivers/rtc/mc13xxx-rtc.c
... ... @@ -23,16 +23,18 @@
23 23 #include <common.h>
24 24 #include <rtc.h>
25 25 #include <spi.h>
26   -#include <pmic.h>
  26 +#include <power/pmic.h>
27 27 #include <fsl_pmic.h>
28 28  
29 29 int rtc_get(struct rtc_time *rtc)
30 30 {
31 31 u32 day1, day2, time;
32 32 int tim, i = 0;
33   - struct pmic *p = get_pmic();
  33 + struct pmic *p = pmic_get("FSL_PMIC");
34 34 int ret;
35 35  
  36 + if (!p)
  37 + return -1;
36 38 do {
37 39 ret = pmic_reg_read(p, REG_RTC_DAY, &day1);
38 40 if (ret < 0)
... ... @@ -61,7 +63,9 @@
61 63 int rtc_set(struct rtc_time *rtc)
62 64 {
63 65 u32 time, day;
64   - struct pmic *p = get_pmic();
  66 + struct pmic *p = pmic_get("FSL_PMIC");
  67 + if (!p)
  68 + return -1;
65 69  
66 70 time = mktime(rtc->tm_year, rtc->tm_mon, rtc->tm_mday,
67 71 rtc->tm_hour, rtc->tm_min, rtc->tm_sec);
include/max8997_pmic.h
1   -/*
2   - * Copyright (C) 2011 Samsung Electronics
3   - * Lukasz Majewski <l.majewski@samsung.com>
4   - *
5   - * See file CREDITS for list of people who contributed to this
6   - * project.
7   - *
8   - * This program is free software; you can redistribute it and/or
9   - * modify it under the terms of the GNU General Public License as
10   - * published by the Free Software Foundation; either version 2 of
11   - * the License, or (at your option) any later version.
12   - *
13   - * This program is distributed in the hope that it will be useful,
14   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16   - * GNU General Public License for more details.
17   - *
18   - * You should have received a copy of the GNU General Public License
19   - * along with this program; if not, write to the Free Software
20   - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21   - * MA 02111-1307 USA
22   - */
23   -
24   -#ifndef __MAX8997_PMIC_H_
25   -#define __MAX8997_PMIC_H_
26   -
27   -/* MAX 8997 registers */
28   -enum {
29   - MAX8997_REG_PMIC_ID0 = 0x00,
30   - MAX8997_REG_PMIC_ID1 = 0x01,
31   - MAX8997_REG_INTSRC = 0x02,
32   - MAX8997_REG_INT1 = 0x03,
33   - MAX8997_REG_INT2 = 0x04,
34   - MAX8997_REG_INT3 = 0x05,
35   - MAX8997_REG_INT4 = 0x06,
36   -
37   - MAX8997_REG_INT1MSK = 0x08,
38   - MAX8997_REG_INT2MSK = 0x09,
39   - MAX8997_REG_INT3MSK = 0x0a,
40   - MAX8997_REG_INT4MSK = 0x0b,
41   -
42   - MAX8997_REG_STATUS1 = 0x0d,
43   - MAX8997_REG_STATUS2 = 0x0e,
44   - MAX8997_REG_STATUS3 = 0x0f,
45   - MAX8997_REG_STATUS4 = 0x10,
46   -
47   - MAX8997_REG_MAINCON1 = 0x13,
48   - MAX8997_REG_MAINCON2 = 0x14,
49   - MAX8997_REG_BUCKRAMP = 0x15,
50   -
51   - MAX8997_REG_BUCK1CTRL = 0x18,
52   - MAX8997_REG_BUCK1DVS1 = 0x19,
53   - MAX8997_REG_BUCK1DVS2 = 0x1a,
54   - MAX8997_REG_BUCK1DVS3 = 0x1b,
55   - MAX8997_REG_BUCK1DVS4 = 0x1c,
56   - MAX8997_REG_BUCK1DVS5 = 0x1d,
57   - MAX8997_REG_BUCK1DVS6 = 0x1e,
58   - MAX8997_REG_BUCK1DVS7 = 0x1f,
59   - MAX8997_REG_BUCK1DVS8 = 0x20,
60   - MAX8997_REG_BUCK2CTRL = 0x21,
61   - MAX8997_REG_BUCK2DVS1 = 0x22,
62   - MAX8997_REG_BUCK2DVS2 = 0x23,
63   - MAX8997_REG_BUCK2DVS3 = 0x24,
64   - MAX8997_REG_BUCK2DVS4 = 0x25,
65   - MAX8997_REG_BUCK2DVS5 = 0x26,
66   - MAX8997_REG_BUCK2DVS6 = 0x27,
67   - MAX8997_REG_BUCK2DVS7 = 0x28,
68   - MAX8997_REG_BUCK2DVS8 = 0x29,
69   - MAX8997_REG_BUCK3CTRL = 0x2a,
70   - MAX8997_REG_BUCK3DVS = 0x2b,
71   - MAX8997_REG_BUCK4CTRL = 0x2c,
72   - MAX8997_REG_BUCK4DVS = 0x2d,
73   - MAX8997_REG_BUCK5CTRL = 0x2e,
74   - MAX8997_REG_BUCK5DVS1 = 0x2f,
75   - MAX8997_REG_BUCK5DVS2 = 0x30,
76   - MAX8997_REG_BUCK5DVS3 = 0x31,
77   - MAX8997_REG_BUCK5DVS4 = 0x32,
78   - MAX8997_REG_BUCK5DVS5 = 0x33,
79   - MAX8997_REG_BUCK5DVS6 = 0x34,
80   - MAX8997_REG_BUCK5DVS7 = 0x35,
81   - MAX8997_REG_BUCK5DVS8 = 0x36,
82   - MAX8997_REG_BUCK6CTRL = 0x37,
83   - MAX8997_REG_BUCK6BPSKIPCTRL = 0x38,
84   - MAX8997_REG_BUCK7CTRL = 0x39,
85   - MAX8997_REG_BUCK7DVS = 0x3a,
86   - MAX8997_REG_LDO1CTRL = 0x3b,
87   - MAX8997_REG_LDO2CTRL = 0x3c,
88   - MAX8997_REG_LDO3CTRL = 0x3d,
89   - MAX8997_REG_LDO4CTRL = 0x3e,
90   - MAX8997_REG_LDO5CTRL = 0x3f,
91   - MAX8997_REG_LDO6CTRL = 0x40,
92   - MAX8997_REG_LDO7CTRL = 0x41,
93   - MAX8997_REG_LDO8CTRL = 0x42,
94   - MAX8997_REG_LDO9CTRL = 0x43,
95   - MAX8997_REG_LDO10CTRL = 0x44,
96   - MAX8997_REG_LDO11CTRL = 0x45,
97   - MAX8997_REG_LDO12CTRL = 0x46,
98   - MAX8997_REG_LDO13CTRL = 0x47,
99   - MAX8997_REG_LDO14CTRL = 0x48,
100   - MAX8997_REG_LDO15CTRL = 0x49,
101   - MAX8997_REG_LDO16CTRL = 0x4a,
102   - MAX8997_REG_LDO17CTRL = 0x4b,
103   - MAX8997_REG_LDO18CTRL = 0x4c,
104   - MAX8997_REG_LDO21CTRL = 0x4d,
105   -
106   - MAX8997_REG_MBCCTRL1 = 0x50,
107   - MAX8997_REG_MBCCTRL2 = 0x51,
108   - MAX8997_REG_MBCCTRL3 = 0x52,
109   - MAX8997_REG_MBCCTRL4 = 0x53,
110   - MAX8997_REG_MBCCTRL5 = 0x54,
111   - MAX8997_REG_MBCCTRL6 = 0x55,
112   - MAX8997_REG_OTPCGHCVS = 0x56,
113   -
114   - MAX8997_REG_SAFEOUTCTRL = 0x5a,
115   -
116   - MAX8997_REG_LBCNFG1 = 0x5e,
117   - MAX8997_REG_LBCNFG2 = 0x5f,
118   - MAX8997_REG_BBCCTRL = 0x60,
119   -
120   - MAX8997_REG_FLASH1_CUR = 0x63, /* 0x63 ~ 0x6e for FLASH */
121   - MAX8997_REG_FLASH2_CUR = 0x64,
122   - MAX8997_REG_MOVIE_CUR = 0x65,
123   - MAX8997_REG_GSMB_CUR = 0x66,
124   - MAX8997_REG_BOOST_CNTL = 0x67,
125   - MAX8997_REG_LEN_CNTL = 0x68,
126   - MAX8997_REG_FLASH_CNTL = 0x69,
127   - MAX8997_REG_WDT_CNTL = 0x6a,
128   - MAX8997_REG_MAXFLASH1 = 0x6b,
129   - MAX8997_REG_MAXFLASH2 = 0x6c,
130   - MAX8997_REG_FLASHSTATUS = 0x6d,
131   - MAX8997_REG_FLASHSTATUSMASK = 0x6e,
132   -
133   - MAX8997_REG_GPIOCNTL1 = 0x70,
134   - MAX8997_REG_GPIOCNTL2 = 0x71,
135   - MAX8997_REG_GPIOCNTL3 = 0x72,
136   - MAX8997_REG_GPIOCNTL4 = 0x73,
137   - MAX8997_REG_GPIOCNTL5 = 0x74,
138   - MAX8997_REG_GPIOCNTL6 = 0x75,
139   - MAX8997_REG_GPIOCNTL7 = 0x76,
140   - MAX8997_REG_GPIOCNTL8 = 0x77,
141   - MAX8997_REG_GPIOCNTL9 = 0x78,
142   - MAX8997_REG_GPIOCNTL10 = 0x79,
143   - MAX8997_REG_GPIOCNTL11 = 0x7a,
144   - MAX8997_REG_GPIOCNTL12 = 0x7b,
145   -
146   - MAX8997_REG_LDO1CONFIG = 0x80,
147   - MAX8997_REG_LDO2CONFIG = 0x81,
148   - MAX8997_REG_LDO3CONFIG = 0x82,
149   - MAX8997_REG_LDO4CONFIG = 0x83,
150   - MAX8997_REG_LDO5CONFIG = 0x84,
151   - MAX8997_REG_LDO6CONFIG = 0x85,
152   - MAX8997_REG_LDO7CONFIG = 0x86,
153   - MAX8997_REG_LDO8CONFIG = 0x87,
154   - MAX8997_REG_LDO9CONFIG = 0x88,
155   - MAX8997_REG_LDO10CONFIG = 0x89,
156   - MAX8997_REG_LDO11CONFIG = 0x8a,
157   - MAX8997_REG_LDO12CONFIG = 0x8b,
158   - MAX8997_REG_LDO13CONFIG = 0x8c,
159   - MAX8997_REG_LDO14CONFIG = 0x8d,
160   - MAX8997_REG_LDO15CONFIG = 0x8e,
161   - MAX8997_REG_LDO16CONFIG = 0x8f,
162   - MAX8997_REG_LDO17CONFIG = 0x90,
163   - MAX8997_REG_LDO18CONFIG = 0x91,
164   - MAX8997_REG_LDO21CONFIG = 0x92,
165   -
166   - MAX8997_REG_DVSOKTIMER1 = 0x97,
167   - MAX8997_REG_DVSOKTIMER2 = 0x98,
168   - MAX8997_REG_DVSOKTIMER4 = 0x99,
169   - MAX8997_REG_DVSOKTIMER5 = 0x9a,
170   -
171   - PMIC_NUM_OF_REGS = 0x9b,
172   -};
173   -
174   -#define ENSAFEOUT1 (1 << 6)
175   -#define ENSAFEOUT2 (1 << 7)
176   -
177   -#define MAX8997_I2C_ADDR (0xCC >> 1)
178   -#define MAX8997_RTC_ADDR (0x0C >> 1)
179   -#define MAX8997_MUIC_ADDR (0x4A >> 1)
180   -#define MAX8997_FG_ADDR (0x6C >> 1)
181   -
182   -enum {
183   - LDO_OFF = 0,
184   - LDO_ON = 1,
185   -
186   - DIS_LDO = (0x00 << 6),
187   - EN_LDO = (0x3 << 6),
188   -};
189   -
190   -#endif /* __MAX8997_PMIC_H_ */
include/max8998_pmic.h
1   -/*
2   - * Copyright (C) 2011 Samsung Electronics
3   - * Lukasz Majewski <l.majewski@samsung.com>
4   - *
5   - * See file CREDITS for list of people who contributed to this
6   - * project.
7   - *
8   - * This program is free software; you can redistribute it and/or
9   - * modify it under the terms of the GNU General Public License as
10   - * published by the Free Software Foundation; either version 2 of
11   - * the License, or (at your option) any later version.
12   - *
13   - * This program is distributed in the hope that it will be useful,
14   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16   - * GNU General Public License for more details.
17   - *
18   - * You should have received a copy of the GNU General Public License
19   - * along with this program; if not, write to the Free Software
20   - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21   - * MA 02111-1307 USA
22   - */
23   -
24   -#ifndef __MAX8998_PMIC_H_
25   -#define __MAX8998_PMIC_H_
26   -
27   -/* MAX 8998 registers */
28   -enum {
29   - MAX8998_REG_IRQ1,
30   - MAX8998_REG_IRQ2,
31   - MAX8998_REG_IRQ3,
32   - MAX8998_REG_IRQ4,
33   - MAX8998_REG_IRQM1,
34   - MAX8998_REG_IRQM2,
35   - MAX8998_REG_IRQM3,
36   - MAX8998_REG_IRQM4,
37   - MAX8998_REG_STATUS1,
38   - MAX8998_REG_STATUS2,
39   - MAX8998_REG_STATUSM1,
40   - MAX8998_REG_STATUSM2,
41   - MAX8998_REG_CHGR1,
42   - MAX8998_REG_CHGR2,
43   - MAX8998_REG_LDO_ACTIVE_DISCHARGE1,
44   - MAX8998_REG_LDO_ACTIVE_DISCHARGE2,
45   - MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
46   - MAX8998_REG_ONOFF1,
47   - MAX8998_REG_ONOFF2,
48   - MAX8998_REG_ONOFF3,
49   - MAX8998_REG_ONOFF4,
50   - MAX8998_REG_BUCK1_VOLTAGE1,
51   - MAX8998_REG_BUCK1_VOLTAGE2,
52   - MAX8998_REG_BUCK1_VOLTAGE3,
53   - MAX8998_REG_BUCK1_VOLTAGE4,
54   - MAX8998_REG_BUCK2_VOLTAGE1,
55   - MAX8998_REG_BUCK2_VOLTAGE2,
56   - MAX8998_REG_BUCK3,
57   - MAX8998_REG_BUCK4,
58   - MAX8998_REG_LDO2_LDO3,
59   - MAX8998_REG_LDO4,
60   - MAX8998_REG_LDO5,
61   - MAX8998_REG_LDO6,
62   - MAX8998_REG_LDO7,
63   - MAX8998_REG_LDO8_LDO9,
64   - MAX8998_REG_LDO10_LDO11,
65   - MAX8998_REG_LDO12,
66   - MAX8998_REG_LDO13,
67   - MAX8998_REG_LDO14,
68   - MAX8998_REG_LDO15,
69   - MAX8998_REG_LDO16,
70   - MAX8998_REG_LDO17,
71   - MAX8998_REG_BKCHR,
72   - MAX8998_REG_LBCNFG1,
73   - MAX8998_REG_LBCNFG2,
74   - PMIC_NUM_OF_REGS,
75   -};
76   -
77   -#define MAX8998_LDO3 (1 << 2)
78   -#define MAX8998_LDO4 (1 << 1)
79   -#define MAX8998_LDO8 (1 << 5)
80   -#define MAX8998_SAFEOUT1 (1 << 4)
81   -
82   -#define MAX8998_I2C_ADDR (0xCC >> 1)
83   -
84   -enum { LDO_OFF, LDO_ON };
85   -
86   -#endif /* __MAX8998_PMIC_H_ */
include/pmic.h
1   -/*
2   - * Copyright (C) 2011 Samsung Electronics
3   - * Lukasz Majewski <l.majewski@samsung.com>
4   - *
5   - * See file CREDITS for list of people who contributed to this
6   - * project.
7   - *
8   - * This program is free software; you can redistribute it and/or
9   - * modify it under the terms of the GNU General Public License as
10   - * published by the Free Software Foundation; either version 2 of
11   - * the License, or (at your option) any later version.
12   - *
13   - * This program is distributed in the hope that it will be useful,
14   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16   - * GNU General Public License for more details.
17   - *
18   - * You should have received a copy of the GNU General Public License
19   - * along with this program; if not, write to the Free Software
20   - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21   - * MA 02111-1307 USA
22   - */
23   -
24   -#ifndef __CORE_PMIC_H_
25   -#define __CORE_PMIC_H_
26   -
27   -enum { PMIC_I2C, PMIC_SPI, };
28   -enum { I2C_PMIC, I2C_NUM, };
29   -enum { PMIC_READ, PMIC_WRITE, };
30   -enum { PMIC_SENSOR_BYTE_ORDER_LITTLE, PMIC_SENSOR_BYTE_ORDER_BIG, };
31   -
32   -struct p_i2c {
33   - unsigned char addr;
34   - unsigned char *buf;
35   - unsigned char tx_num;
36   -};
37   -
38   -struct p_spi {
39   - unsigned int cs;
40   - unsigned int mode;
41   - unsigned int bitlen;
42   - unsigned int clk;
43   - unsigned int flags;
44   - u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
45   -};
46   -
47   -struct pmic {
48   - const char *name;
49   - unsigned char bus;
50   - unsigned char interface;
51   - unsigned char sensor_byte_order;
52   - unsigned char number_of_regs;
53   - union hw {
54   - struct p_i2c i2c;
55   - struct p_spi spi;
56   - } hw;
57   -};
58   -
59   -int pmic_init(void);
60   -int pmic_dialog_init(void);
61   -int check_reg(u32 reg);
62   -struct pmic *get_pmic(void);
63   -int pmic_probe(struct pmic *p);
64   -int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
65   -int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
66   -int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
67   -
68   -#define pmic_i2c_addr (p->hw.i2c.addr)
69   -#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
70   -
71   -#define pmic_spi_bitlen (p->hw.spi.bitlen)
72   -#define pmic_spi_flags (p->hw.spi.flags)
73   -
74   -#endif /* __CORE_PMIC_H_ */
include/power/max8997_pmic.h
  1 +/*
  2 + * Copyright (C) 2011 Samsung Electronics
  3 + * Lukasz Majewski <l.majewski@samsung.com>
  4 + *
  5 + * See file CREDITS for list of people who contributed to this
  6 + * project.
  7 + *
  8 + * This program is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of
  11 + * the License, or (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 + * MA 02111-1307 USA
  22 + */
  23 +
  24 +#ifndef __MAX8997_PMIC_H_
  25 +#define __MAX8997_PMIC_H_
  26 +
  27 +/* MAX 8997 registers */
  28 +enum {
  29 + MAX8997_REG_PMIC_ID0 = 0x00,
  30 + MAX8997_REG_PMIC_ID1 = 0x01,
  31 + MAX8997_REG_INTSRC = 0x02,
  32 + MAX8997_REG_INT1 = 0x03,
  33 + MAX8997_REG_INT2 = 0x04,
  34 + MAX8997_REG_INT3 = 0x05,
  35 + MAX8997_REG_INT4 = 0x06,
  36 +
  37 + MAX8997_REG_INT1MSK = 0x08,
  38 + MAX8997_REG_INT2MSK = 0x09,
  39 + MAX8997_REG_INT3MSK = 0x0a,
  40 + MAX8997_REG_INT4MSK = 0x0b,
  41 +
  42 + MAX8997_REG_STATUS1 = 0x0d,
  43 + MAX8997_REG_STATUS2 = 0x0e,
  44 + MAX8997_REG_STATUS3 = 0x0f,
  45 + MAX8997_REG_STATUS4 = 0x10,
  46 +
  47 + MAX8997_REG_MAINCON1 = 0x13,
  48 + MAX8997_REG_MAINCON2 = 0x14,
  49 + MAX8997_REG_BUCKRAMP = 0x15,
  50 +
  51 + MAX8997_REG_BUCK1CTRL = 0x18,
  52 + MAX8997_REG_BUCK1DVS1 = 0x19,
  53 + MAX8997_REG_BUCK1DVS2 = 0x1a,
  54 + MAX8997_REG_BUCK1DVS3 = 0x1b,
  55 + MAX8997_REG_BUCK1DVS4 = 0x1c,
  56 + MAX8997_REG_BUCK1DVS5 = 0x1d,
  57 + MAX8997_REG_BUCK1DVS6 = 0x1e,
  58 + MAX8997_REG_BUCK1DVS7 = 0x1f,
  59 + MAX8997_REG_BUCK1DVS8 = 0x20,
  60 + MAX8997_REG_BUCK2CTRL = 0x21,
  61 + MAX8997_REG_BUCK2DVS1 = 0x22,
  62 + MAX8997_REG_BUCK2DVS2 = 0x23,
  63 + MAX8997_REG_BUCK2DVS3 = 0x24,
  64 + MAX8997_REG_BUCK2DVS4 = 0x25,
  65 + MAX8997_REG_BUCK2DVS5 = 0x26,
  66 + MAX8997_REG_BUCK2DVS6 = 0x27,
  67 + MAX8997_REG_BUCK2DVS7 = 0x28,
  68 + MAX8997_REG_BUCK2DVS8 = 0x29,
  69 + MAX8997_REG_BUCK3CTRL = 0x2a,
  70 + MAX8997_REG_BUCK3DVS = 0x2b,
  71 + MAX8997_REG_BUCK4CTRL = 0x2c,
  72 + MAX8997_REG_BUCK4DVS = 0x2d,
  73 + MAX8997_REG_BUCK5CTRL = 0x2e,
  74 + MAX8997_REG_BUCK5DVS1 = 0x2f,
  75 + MAX8997_REG_BUCK5DVS2 = 0x30,
  76 + MAX8997_REG_BUCK5DVS3 = 0x31,
  77 + MAX8997_REG_BUCK5DVS4 = 0x32,
  78 + MAX8997_REG_BUCK5DVS5 = 0x33,
  79 + MAX8997_REG_BUCK5DVS6 = 0x34,
  80 + MAX8997_REG_BUCK5DVS7 = 0x35,
  81 + MAX8997_REG_BUCK5DVS8 = 0x36,
  82 + MAX8997_REG_BUCK6CTRL = 0x37,
  83 + MAX8997_REG_BUCK6BPSKIPCTRL = 0x38,
  84 + MAX8997_REG_BUCK7CTRL = 0x39,
  85 + MAX8997_REG_BUCK7DVS = 0x3a,
  86 + MAX8997_REG_LDO1CTRL = 0x3b,
  87 + MAX8997_REG_LDO2CTRL = 0x3c,
  88 + MAX8997_REG_LDO3CTRL = 0x3d,
  89 + MAX8997_REG_LDO4CTRL = 0x3e,
  90 + MAX8997_REG_LDO5CTRL = 0x3f,
  91 + MAX8997_REG_LDO6CTRL = 0x40,
  92 + MAX8997_REG_LDO7CTRL = 0x41,
  93 + MAX8997_REG_LDO8CTRL = 0x42,
  94 + MAX8997_REG_LDO9CTRL = 0x43,
  95 + MAX8997_REG_LDO10CTRL = 0x44,
  96 + MAX8997_REG_LDO11CTRL = 0x45,
  97 + MAX8997_REG_LDO12CTRL = 0x46,
  98 + MAX8997_REG_LDO13CTRL = 0x47,
  99 + MAX8997_REG_LDO14CTRL = 0x48,
  100 + MAX8997_REG_LDO15CTRL = 0x49,
  101 + MAX8997_REG_LDO16CTRL = 0x4a,
  102 + MAX8997_REG_LDO17CTRL = 0x4b,
  103 + MAX8997_REG_LDO18CTRL = 0x4c,
  104 + MAX8997_REG_LDO21CTRL = 0x4d,
  105 +
  106 + MAX8997_REG_MBCCTRL1 = 0x50,
  107 + MAX8997_REG_MBCCTRL2 = 0x51,
  108 + MAX8997_REG_MBCCTRL3 = 0x52,
  109 + MAX8997_REG_MBCCTRL4 = 0x53,
  110 + MAX8997_REG_MBCCTRL5 = 0x54,
  111 + MAX8997_REG_MBCCTRL6 = 0x55,
  112 + MAX8997_REG_OTPCGHCVS = 0x56,
  113 +
  114 + MAX8997_REG_SAFEOUTCTRL = 0x5a,
  115 +
  116 + MAX8997_REG_LBCNFG1 = 0x5e,
  117 + MAX8997_REG_LBCNFG2 = 0x5f,
  118 + MAX8997_REG_BBCCTRL = 0x60,
  119 +
  120 + MAX8997_REG_FLASH1_CUR = 0x63, /* 0x63 ~ 0x6e for FLASH */
  121 + MAX8997_REG_FLASH2_CUR = 0x64,
  122 + MAX8997_REG_MOVIE_CUR = 0x65,
  123 + MAX8997_REG_GSMB_CUR = 0x66,
  124 + MAX8997_REG_BOOST_CNTL = 0x67,
  125 + MAX8997_REG_LEN_CNTL = 0x68,
  126 + MAX8997_REG_FLASH_CNTL = 0x69,
  127 + MAX8997_REG_WDT_CNTL = 0x6a,
  128 + MAX8997_REG_MAXFLASH1 = 0x6b,
  129 + MAX8997_REG_MAXFLASH2 = 0x6c,
  130 + MAX8997_REG_FLASHSTATUS = 0x6d,
  131 + MAX8997_REG_FLASHSTATUSMASK = 0x6e,
  132 +
  133 + MAX8997_REG_GPIOCNTL1 = 0x70,
  134 + MAX8997_REG_GPIOCNTL2 = 0x71,
  135 + MAX8997_REG_GPIOCNTL3 = 0x72,
  136 + MAX8997_REG_GPIOCNTL4 = 0x73,
  137 + MAX8997_REG_GPIOCNTL5 = 0x74,
  138 + MAX8997_REG_GPIOCNTL6 = 0x75,
  139 + MAX8997_REG_GPIOCNTL7 = 0x76,
  140 + MAX8997_REG_GPIOCNTL8 = 0x77,
  141 + MAX8997_REG_GPIOCNTL9 = 0x78,
  142 + MAX8997_REG_GPIOCNTL10 = 0x79,
  143 + MAX8997_REG_GPIOCNTL11 = 0x7a,
  144 + MAX8997_REG_GPIOCNTL12 = 0x7b,
  145 +
  146 + MAX8997_REG_LDO1CONFIG = 0x80,
  147 + MAX8997_REG_LDO2CONFIG = 0x81,
  148 + MAX8997_REG_LDO3CONFIG = 0x82,
  149 + MAX8997_REG_LDO4CONFIG = 0x83,
  150 + MAX8997_REG_LDO5CONFIG = 0x84,
  151 + MAX8997_REG_LDO6CONFIG = 0x85,
  152 + MAX8997_REG_LDO7CONFIG = 0x86,
  153 + MAX8997_REG_LDO8CONFIG = 0x87,
  154 + MAX8997_REG_LDO9CONFIG = 0x88,
  155 + MAX8997_REG_LDO10CONFIG = 0x89,
  156 + MAX8997_REG_LDO11CONFIG = 0x8a,
  157 + MAX8997_REG_LDO12CONFIG = 0x8b,
  158 + MAX8997_REG_LDO13CONFIG = 0x8c,
  159 + MAX8997_REG_LDO14CONFIG = 0x8d,
  160 + MAX8997_REG_LDO15CONFIG = 0x8e,
  161 + MAX8997_REG_LDO16CONFIG = 0x8f,
  162 + MAX8997_REG_LDO17CONFIG = 0x90,
  163 + MAX8997_REG_LDO18CONFIG = 0x91,
  164 + MAX8997_REG_LDO21CONFIG = 0x92,
  165 +
  166 + MAX8997_REG_DVSOKTIMER1 = 0x97,
  167 + MAX8997_REG_DVSOKTIMER2 = 0x98,
  168 + MAX8997_REG_DVSOKTIMER4 = 0x99,
  169 + MAX8997_REG_DVSOKTIMER5 = 0x9a,
  170 +
  171 + PMIC_NUM_OF_REGS = 0x9b,
  172 +};
  173 +
  174 +#define ACTDISSAFEO1 (1 << 4)
  175 +#define ACTDISSAFEO2 (1 << 5)
  176 +#define ENSAFEOUT1 (1 << 6)
  177 +#define ENSAFEOUT2 (1 << 7)
  178 +
  179 +/* Charger */
  180 +enum {CHARGER_ENABLE, CHARGER_DISABLE};
  181 +#define DETBAT (1 << 2)
  182 +#define MBCICHFCSET (1 << 4)
  183 +#define MBCHOSTEN (1 << 6)
  184 +#define VCHGR_FC (1 << 7)
  185 +
  186 +#define CHARGER_MIN_CURRENT 200
  187 +#define CHARGER_MAX_CURRENT 950
  188 +#define CHARGER_CURRENT_RESOLUTION 50
  189 +
  190 +#define MAX8997_I2C_ADDR (0xCC >> 1)
  191 +#define MAX8997_RTC_ADDR (0x0C >> 1)
  192 +#define MAX8997_MUIC_ADDR (0x4A >> 1)
  193 +#define MAX8997_FG_ADDR (0x6C >> 1)
  194 +
  195 +enum {
  196 + LDO_OFF = 0,
  197 + LDO_ON = 1,
  198 +
  199 + DIS_LDO = (0x00 << 6),
  200 + EN_LDO = (0x3 << 6),
  201 +};
  202 +
  203 +#endif /* __MAX8997_PMIC_H_ */
include/power/max8998_pmic.h
  1 +/*
  2 + * Copyright (C) 2011 Samsung Electronics
  3 + * Lukasz Majewski <l.majewski@samsung.com>
  4 + *
  5 + * See file CREDITS for list of people who contributed to this
  6 + * project.
  7 + *
  8 + * This program is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of
  11 + * the License, or (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 + * MA 02111-1307 USA
  22 + */
  23 +
  24 +#ifndef __MAX8998_PMIC_H_
  25 +#define __MAX8998_PMIC_H_
  26 +
  27 +/* MAX 8998 registers */
  28 +enum {
  29 + MAX8998_REG_IRQ1,
  30 + MAX8998_REG_IRQ2,
  31 + MAX8998_REG_IRQ3,
  32 + MAX8998_REG_IRQ4,
  33 + MAX8998_REG_IRQM1,
  34 + MAX8998_REG_IRQM2,
  35 + MAX8998_REG_IRQM3,
  36 + MAX8998_REG_IRQM4,
  37 + MAX8998_REG_STATUS1,
  38 + MAX8998_REG_STATUS2,
  39 + MAX8998_REG_STATUSM1,
  40 + MAX8998_REG_STATUSM2,
  41 + MAX8998_REG_CHGR1,
  42 + MAX8998_REG_CHGR2,
  43 + MAX8998_REG_LDO_ACTIVE_DISCHARGE1,
  44 + MAX8998_REG_LDO_ACTIVE_DISCHARGE2,
  45 + MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
  46 + MAX8998_REG_ONOFF1,
  47 + MAX8998_REG_ONOFF2,
  48 + MAX8998_REG_ONOFF3,
  49 + MAX8998_REG_ONOFF4,
  50 + MAX8998_REG_BUCK1_VOLTAGE1,
  51 + MAX8998_REG_BUCK1_VOLTAGE2,
  52 + MAX8998_REG_BUCK1_VOLTAGE3,
  53 + MAX8998_REG_BUCK1_VOLTAGE4,
  54 + MAX8998_REG_BUCK2_VOLTAGE1,
  55 + MAX8998_REG_BUCK2_VOLTAGE2,
  56 + MAX8998_REG_BUCK3,
  57 + MAX8998_REG_BUCK4,
  58 + MAX8998_REG_LDO2_LDO3,
  59 + MAX8998_REG_LDO4,
  60 + MAX8998_REG_LDO5,
  61 + MAX8998_REG_LDO6,
  62 + MAX8998_REG_LDO7,
  63 + MAX8998_REG_LDO8_LDO9,
  64 + MAX8998_REG_LDO10_LDO11,
  65 + MAX8998_REG_LDO12,
  66 + MAX8998_REG_LDO13,
  67 + MAX8998_REG_LDO14,
  68 + MAX8998_REG_LDO15,
  69 + MAX8998_REG_LDO16,
  70 + MAX8998_REG_LDO17,
  71 + MAX8998_REG_BKCHR,
  72 + MAX8998_REG_LBCNFG1,
  73 + MAX8998_REG_LBCNFG2,
  74 + PMIC_NUM_OF_REGS,
  75 +};
  76 +
  77 +#define MAX8998_LDO3 (1 << 2)
  78 +#define MAX8998_LDO4 (1 << 1)
  79 +#define MAX8998_LDO8 (1 << 5)
  80 +#define MAX8998_SAFEOUT1 (1 << 4)
  81 +
  82 +#define MAX8998_I2C_ADDR (0xCC >> 1)
  83 +
  84 +enum { LDO_OFF, LDO_ON };
  85 +
  86 +#endif /* __MAX8998_PMIC_H_ */
include/power/pmic.h
  1 +/*
  2 + * Copyright (C) 2011-2012 Samsung Electronics
  3 + * Lukasz Majewski <l.majewski@samsung.com>
  4 + *
  5 + * See file CREDITS for list of people who contributed to this
  6 + * project.
  7 + *
  8 + * This program is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of
  11 + * the License, or (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 + * MA 02111-1307 USA
  22 + */
  23 +
  24 +#ifndef __CORE_PMIC_H_
  25 +#define __CORE_PMIC_H_
  26 +
  27 +#include <common.h>
  28 +#include <linux/list.h>
  29 +#include <i2c.h>
  30 +
  31 +enum { PMIC_I2C, PMIC_SPI, };
  32 +enum { I2C_PMIC, I2C_NUM, };
  33 +enum { PMIC_READ, PMIC_WRITE, };
  34 +enum { PMIC_SENSOR_BYTE_ORDER_LITTLE, PMIC_SENSOR_BYTE_ORDER_BIG, };
  35 +
  36 +struct p_i2c {
  37 + unsigned char addr;
  38 + unsigned char *buf;
  39 + unsigned char tx_num;
  40 +};
  41 +
  42 +struct p_spi {
  43 + unsigned int cs;
  44 + unsigned int mode;
  45 + unsigned int bitlen;
  46 + unsigned int clk;
  47 + unsigned int flags;
  48 + u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
  49 +};
  50 +
  51 +struct pmic {
  52 + const char *name;
  53 + unsigned char bus;
  54 + unsigned char interface;
  55 + unsigned char sensor_byte_order;
  56 + unsigned int number_of_regs;
  57 + union hw {
  58 + struct p_i2c i2c;
  59 + struct p_spi spi;
  60 + } hw;
  61 +
  62 + struct list_head list;
  63 +};
  64 +
  65 +int pmic_init(unsigned char bus);
  66 +int pmic_dialog_init(unsigned char bus);
  67 +int check_reg(struct pmic *p, u32 reg);
  68 +struct pmic *pmic_alloc(void);
  69 +struct pmic *pmic_get(const char *s);
  70 +int pmic_probe(struct pmic *p);
  71 +int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
  72 +int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
  73 +int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
  74 +
  75 +#define pmic_i2c_addr (p->hw.i2c.addr)
  76 +#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
  77 +
  78 +#define pmic_spi_bitlen (p->hw.spi.bitlen)
  79 +#define pmic_spi_flags (p->hw.spi.flags)
  80 +
  81 +#endif /* __CORE_PMIC_H_ */