2 * OMAP3XXX L3 Interconnect Driver
4 * Copyright (C) 2011 Texas Corporation
5 * Felipe Balbi <balbi@ti.com>
6 * Santosh Shilimkar <santosh.shilimkar@ti.com>
7 * Sricharan <r.sricharan@ti.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/platform_device.h>
28 #include <linux/interrupt.h>
30 #include <linux/module.h>
32 #include <linux/of_device.h>
34 #include "omap_l3_smx.h"
36 static inline u64
omap3_l3_readll(void __iomem
*base
, u16 reg
)
38 return __raw_readll(base
+ reg
);
41 static inline void omap3_l3_writell(void __iomem
*base
, u16 reg
, u64 value
)
43 __raw_writell(value
, base
+ reg
);
46 static inline enum omap3_l3_code
omap3_l3_decode_error_code(u64 error
)
48 return (error
& 0x0f000000) >> L3_ERROR_LOG_CODE
;
51 static inline u32
omap3_l3_decode_addr(u64 error_addr
)
53 return error_addr
& 0xffffffff;
56 static inline unsigned omap3_l3_decode_cmd(u64 error
)
58 return (error
& 0x07) >> L3_ERROR_LOG_CMD
;
61 static inline enum omap3_l3_initiator_id
omap3_l3_decode_initid(u64 error
)
63 return (error
& 0xff00) >> L3_ERROR_LOG_INITID
;
66 static inline unsigned omap3_l3_decode_req_info(u64 error
)
68 return (error
>> 32) & 0xffff;
71 static char *omap3_l3_code_string(u8 code
)
74 case OMAP_L3_CODE_NOERROR
:
76 case OMAP_L3_CODE_UNSUP_CMD
:
77 return "Unsupported Command";
78 case OMAP_L3_CODE_ADDR_HOLE
:
79 return "Address Hole";
80 case OMAP_L3_CODE_PROTECT_VIOLATION
:
81 return "Protection Violation";
82 case OMAP_L3_CODE_IN_BAND_ERR
:
83 return "In-band Error";
84 case OMAP_L3_CODE_REQ_TOUT_NOT_ACCEPT
:
85 return "Request Timeout Not Accepted";
86 case OMAP_L3_CODE_REQ_TOUT_NO_RESP
:
87 return "Request Timeout, no response";
89 return "UNKNOWN error";
93 static char *omap3_l3_initiator_string(u8 initid
)
100 case OMAP_L3_IA_MPU_SS_1
:
101 case OMAP_L3_IA_MPU_SS_2
:
102 case OMAP_L3_IA_MPU_SS_3
:
103 case OMAP_L3_IA_MPU_SS_4
:
104 case OMAP_L3_IA_MPU_SS_5
:
106 case OMAP_L3_IA_IVA_SS_1
:
107 case OMAP_L3_IA_IVA_SS_2
:
108 case OMAP_L3_IA_IVA_SS_3
:
110 case OMAP_L3_IA_IVA_SS_DMA_1
:
111 case OMAP_L3_IA_IVA_SS_DMA_2
:
112 case OMAP_L3_IA_IVA_SS_DMA_3
:
113 case OMAP_L3_IA_IVA_SS_DMA_4
:
114 case OMAP_L3_IA_IVA_SS_DMA_5
:
115 case OMAP_L3_IA_IVA_SS_DMA_6
:
119 case OMAP_L3_IA_CAM_1
:
120 case OMAP_L3_IA_CAM_2
:
121 case OMAP_L3_IA_CAM_3
:
125 case OMAP_L3_SDMA_WR_1
:
126 case OMAP_L3_SDMA_WR_2
:
128 case OMAP_L3_SDMA_RD_1
:
129 case OMAP_L3_SDMA_RD_2
:
130 case OMAP_L3_SDMA_RD_3
:
131 case OMAP_L3_SDMA_RD_4
:
135 case OMAP_L3_USBHOST
:
138 return "UNKNOWN Initiator";
143 * omap3_l3_block_irq - handles a register block's irq
144 * @l3: struct omap3_l3 *
145 * @base: register block base address
146 * @error: L3_ERROR_LOG register of our block
148 * Called in hard-irq context. Caller should take care of locking
150 * OMAP36xx TRM gives, on page 2001, Figure 9-10, the Typical Error
151 * Analysis Sequence, we are following that sequence here, please
152 * refer to that Figure for more information on the subject.
154 static irqreturn_t
omap3_l3_block_irq(struct omap3_l3
*l3
,
155 u64 error
, int error_addr
)
157 u8 code
= omap3_l3_decode_error_code(error
);
158 u8 initid
= omap3_l3_decode_initid(error
);
159 u8 multi
= error
& L3_ERROR_LOG_MULTI
;
160 u32 address
= omap3_l3_decode_addr(error_addr
);
162 pr_err("%s seen by %s %s at address %x\n",
163 omap3_l3_code_string(code
),
164 omap3_l3_initiator_string(initid
),
165 multi
? "Multiple Errors" : "", address
);
171 static irqreturn_t
omap3_l3_app_irq(int irq
, void *_l3
)
173 struct omap3_l3
*l3
= _l3
;
180 irqreturn_t ret
= IRQ_NONE
;
182 int_type
= irq
== l3
->app_irq
? L3_APPLICATION_ERROR
: L3_DEBUG_ERROR
;
184 status
= omap3_l3_readll(l3
->rt
, L3_SI_FLAG_STATUS_0
);
186 * if we have a timeout error, there's nothing we can
187 * do besides rebooting the board. So let's BUG on any
188 * of such errors and handle the others. timeout error
189 * is severe and not expected to occur.
191 BUG_ON(status
& L3_STATUS_0_TIMEOUT_MASK
);
193 status
= omap3_l3_readll(l3
->rt
, L3_SI_FLAG_STATUS_1
);
194 /* No timeout error for debug sources */
197 /* identify the error source */
198 err_source
= __ffs(status
);
200 base
= l3
->rt
+ omap3_l3_bases
[int_type
][err_source
];
201 error
= omap3_l3_readll(base
, L3_ERROR_LOG
);
203 error_addr
= omap3_l3_readll(base
, L3_ERROR_LOG_ADDR
);
204 ret
|= omap3_l3_block_irq(l3
, error
, error_addr
);
207 /* Clear the status register */
208 clear
= (L3_AGENT_STATUS_CLEAR_IA
<< int_type
) |
209 L3_AGENT_STATUS_CLEAR_TA
;
210 omap3_l3_writell(base
, L3_AGENT_STATUS
, clear
);
212 /* clear the error log register */
213 omap3_l3_writell(base
, L3_ERROR_LOG
, error
);
218 #if IS_BUILTIN(CONFIG_OF)
219 static const struct of_device_id omap3_l3_match
[] = {
221 .compatible
= "ti,omap3-l3-smx",
225 MODULE_DEVICE_TABLE(of
, omap3_l3_match
);
228 static int omap3_l3_probe(struct platform_device
*pdev
)
231 struct resource
*res
;
234 l3
= kzalloc(sizeof(*l3
), GFP_KERNEL
);
238 platform_set_drvdata(pdev
, l3
);
240 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
242 dev_err(&pdev
->dev
, "couldn't find resource\n");
246 l3
->rt
= ioremap(res
->start
, resource_size(res
));
248 dev_err(&pdev
->dev
, "ioremap failed\n");
253 l3
->debug_irq
= platform_get_irq(pdev
, 0);
254 ret
= request_irq(l3
->debug_irq
, omap3_l3_app_irq
, IRQF_TRIGGER_RISING
,
257 dev_err(&pdev
->dev
, "couldn't request debug irq\n");
261 l3
->app_irq
= platform_get_irq(pdev
, 1);
262 ret
= request_irq(l3
->app_irq
, omap3_l3_app_irq
, IRQF_TRIGGER_RISING
,
265 dev_err(&pdev
->dev
, "couldn't request app irq\n");
272 free_irq(l3
->debug_irq
, l3
);
280 static int omap3_l3_remove(struct platform_device
*pdev
)
282 struct omap3_l3
*l3
= platform_get_drvdata(pdev
);
284 free_irq(l3
->app_irq
, l3
);
285 free_irq(l3
->debug_irq
, l3
);
292 static struct platform_driver omap3_l3_driver
= {
293 .probe
= omap3_l3_probe
,
294 .remove
= omap3_l3_remove
,
296 .name
= "omap_l3_smx",
297 .of_match_table
= of_match_ptr(omap3_l3_match
),
301 static int __init
omap3_l3_init(void)
303 return platform_driver_register(&omap3_l3_driver
);
305 postcore_initcall_sync(omap3_l3_init
);
307 static void __exit
omap3_l3_exit(void)
309 platform_driver_unregister(&omap3_l3_driver
);
311 module_exit(omap3_l3_exit
);
313 MODULE_AUTHOR("Felipe Balbi");
314 MODULE_AUTHOR("Santosh Shilimkar");
315 MODULE_AUTHOR("Sricharan R");
316 MODULE_DESCRIPTION("OMAP3XXX L3 Interconnect Driver");
317 MODULE_LICENSE("GPL");