]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv7/u8500/prcmu.c
b256d27b84e7d3300687f4d9f8ce65cde6cd296d
[u-boot] / arch / arm / cpu / armv7 / u8500 / prcmu.c
1 /*
2  * Copyright (C) 2009 ST-Ericsson SA
3  *
4  * Adapted from the Linux version:
5  * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License version 2
22  * as published by the Free Software Foundation.
23  */
24
25 /*
26  * NOTE: This currently does not support the I2C workaround access method.
27  */
28
29 #include <common.h>
30 #include <config.h>
31 #include <asm/io.h>
32 #include <asm/arch/hardware.h>
33 #include <asm/types.h>
34 #include <asm/io.h>
35 #include <asm/errno.h>
36 #include <asm/arch/prcmu.h>
37
38 /* CPU mailbox registers */
39 #define PRCM_MBOX_CPU_VAL (U8500_PRCMU_BASE + 0x0fc)
40 #define PRCM_MBOX_CPU_SET (U8500_PRCMU_BASE + 0x100)
41 #define PRCM_MBOX_CPU_CLR (U8500_PRCMU_BASE + 0x104)
42
43 static int prcmu_is_ready(void)
44 {
45         int ready = readb(PRCM_XP70_CUR_PWR_STATE) == AP_EXECUTE;
46         if (!ready)
47                 printf("PRCMU firmware not ready\n");
48         return ready;
49 }
50
51 static int _wait_for_req_complete(int num)
52 {
53         int timeout = 1000;
54
55         /* checking any already on-going transaction */
56         while ((readl(PRCM_MBOX_CPU_VAL) & (1 << num)) && timeout)
57                 timeout--;
58
59         timeout = 1000;
60
61         /* Set an interrupt to XP70 */
62         writel(1 << num, PRCM_MBOX_CPU_SET);
63
64         while ((readl(PRCM_MBOX_CPU_VAL) & (1 << num)) && timeout)
65                 timeout--;
66
67         if (!timeout) {
68                 printf("PRCMU operation timed out\n");
69                 return -1;
70         }
71
72         return 0;
73 }
74
75 /**
76  * prcmu_i2c_read - PRCMU - 4500 communication using PRCMU I2C
77  * @reg: - db8500 register bank to be accessed
78  * @slave:  - db8500 register to be accessed
79  * Returns: ACK_MB5  value containing the status
80  */
81 int prcmu_i2c_read(u8 reg, u16 slave)
82 {
83         uint8_t i2c_status;
84         uint8_t i2c_val;
85
86         if (!prcmu_is_ready())
87                 return -1;
88
89         debug("\nprcmu_4500_i2c_read:bank=%x;reg=%x;\n",
90                         reg, slave);
91
92         /* prepare the data for mailbox 5 */
93         writeb((reg << 1) | I2CREAD, PRCM_REQ_MB5_I2COPTYPE_REG);
94         writeb((1 << 3) | 0x0, PRCM_REQ_MB5_BIT_FIELDS);
95         writeb(slave, PRCM_REQ_MB5_I2CSLAVE);
96         writeb(0, PRCM_REQ_MB5_I2CVAL);
97
98         _wait_for_req_complete(REQ_MB5);
99
100         /* retrieve values */
101         debug("ack-mb5:transfer status = %x\n",
102                         readb(PRCM_ACK_MB5_STATUS));
103         debug("ack-mb5:reg bank = %x\n", readb(PRCM_ACK_MB5) >> 1);
104         debug("ack-mb5:slave_add = %x\n",
105                         readb(PRCM_ACK_MB5_SLAVE));
106         debug("ack-mb5:reg_val = %d\n", readb(PRCM_ACK_MB5_VAL));
107
108         i2c_status = readb(PRCM_ACK_MB5_STATUS);
109         i2c_val = readb(PRCM_ACK_MB5_VAL);
110
111         if (i2c_status == I2C_RD_OK)
112                 return i2c_val;
113         else {
114
115                 printf("prcmu_i2c_read:read return status= %d\n",
116                                 i2c_status);
117                 return -1;
118         }
119
120 }
121
122 /**
123  * prcmu_i2c_write - PRCMU-db8500 communication using PRCMU I2C
124  * @reg: - db8500 register bank to be accessed
125  * @slave:  - db800 register to be written to
126  * @reg_data: - the data to write
127  * Returns: ACK_MB5 value containing the status
128  */
129 int prcmu_i2c_write(u8 reg, u16 slave, u8 reg_data)
130 {
131         uint8_t i2c_status;
132
133         if (!prcmu_is_ready())
134                 return -1;
135
136         debug("\nprcmu_4500_i2c_write:bank=%x;reg=%x;\n",
137                         reg, slave);
138
139         /* prepare the data for mailbox 5 */
140         writeb((reg << 1) | I2CWRITE, PRCM_REQ_MB5_I2COPTYPE_REG);
141         writeb((1 << 3) | 0x0, PRCM_REQ_MB5_BIT_FIELDS);
142         writeb(slave, PRCM_REQ_MB5_I2CSLAVE);
143         writeb(reg_data, PRCM_REQ_MB5_I2CVAL);
144
145         debug("\ncpu_is_u8500v11\n");
146         _wait_for_req_complete(REQ_MB5);
147
148         /* retrieve values */
149         debug("ack-mb5:transfer status = %x\n",
150                         readb(PRCM_ACK_MB5_STATUS));
151         debug("ack-mb5:reg bank = %x\n", readb(PRCM_ACK_MB5) >> 1);
152         debug("ack-mb5:slave_add = %x\n",
153                         readb(PRCM_ACK_MB5_SLAVE));
154         debug("ack-mb5:reg_val = %d\n", readb(PRCM_ACK_MB5_VAL));
155
156         i2c_status = readb(PRCM_ACK_MB5_STATUS);
157         debug("\ni2c_status = %x\n", i2c_status);
158         if (i2c_status == I2C_WR_OK)
159                 return 0;
160         else {
161                 printf("ape-i2c: i2c_status : 0x%x\n", i2c_status);
162                 return -1;
163         }
164 }