1 //==========================================================================
5 // PMIC support on i.MX25 3stack platforms
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
44 #include <pkgconf/hal.h>
45 #include <pkgconf/devs_pmic_arm_imx25_3stack.h>
46 #include <cyg/hal/hal_arch.h>
47 #include <cyg/hal/hal_cache.h>
48 #include <cyg/hal/hal_io.h>
49 #include <cyg/hal/fsl_board.h>
50 #include <cyg/io/mxc_i2c.h>
51 #include <cyg/io/mc34704.h>
53 #define MC34704_REG_MAX 0x59
55 static void mxc_pmic_init(void)
57 if (CYGHWR_DEVS_PMIC_I2C_PORT >= i2c_num)
60 i2c_init(i2c_base_addr[CYGHWR_DEVS_PMIC_I2C_PORT], 40000);
62 diag_printf("Turning on PMIC regulators: 1,2,3,4,5\n");
64 pmic_reg(0x02, 0x09, 1);
67 RedBoot_init(mxc_pmic_init, RedBoot_INIT_PRIO(100));
69 static void do_pmic(int argc, char *argv[]);
71 "Read/Write internal PMIC register",
72 "<reg num> [value to be written]",
75 static void do_pmic(int argc,char *argv[])
77 unsigned int reg, temp, val = 0, write = 0;
80 diag_printf("\tRead: pmic <reg num>\n");
81 diag_printf("\tWrite: pmic <reg num> <value to be written>\n");
85 if (!parse_num(*(&argv[1]), (unsigned long *)®, &argv[1], ":")) {
86 diag_printf("Error: Invalid parameter\n");
91 if (!parse_num(*(&argv[2]), (unsigned long *)&val, &argv[2], ":")) {
92 diag_printf("Error: Invalid parameter\n");
98 temp = pmic_reg(reg, val, write);
100 diag_printf("\tval: 0x%08x\n\n", temp);
103 static unsigned int pmic_reg_i2c(unsigned int reg, unsigned int val, unsigned int write)
105 struct mxc_i2c_request rq;
106 rq.dev_addr = CYGHWR_DEVS_PMIC_I2C_ADDR;
109 rq.buffer = (unsigned char *)&val;
111 write = write ? I2C_WRITE : I2C_READ;
112 if (i2c_xfer(CYGHWR_DEVS_PMIC_I2C_PORT, &rq, write) != 0) {
113 diag_printf("Error in I2C transaction\n\n");
120 * To read/write to a PMIC register. For write, it does another read for the
121 * actual register value.
123 * @param reg register number inside the PMIC
124 * @param val data to be written to the register; don't care for read
125 * @param write 0 for read; 1 for write
127 * @return the actual data in the PMIC register
129 unsigned int pmic_reg(unsigned int reg, unsigned int val, unsigned int write)
131 if (reg > MC34704_REG_MAX) {
132 diag_printf("<reg num> = %d is invalid. Should be less than %d\n",
133 reg, MC34704_REG_MAX);
136 return pmic_reg_i2c(reg, val, write);