Michal Simek | 64b889b | 2013-03-27 12:37:53 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Xilinx SLCR driver |
| 3 | * |
| 4 | * Copyright (c) 2011-2013 Xilinx Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public |
| 12 | * License along with this program; if not, write to the Free |
| 13 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA |
| 14 | * 02139, USA. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/export.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/fs.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/of_address.h> |
| 25 | #include <linux/uaccess.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/clk/zynq.h> |
| 30 | #include "common.h" |
| 31 | |
| 32 | #define SLCR_UNLOCK_MAGIC 0xDF0D |
| 33 | #define SLCR_UNLOCK 0x8 /* SCLR unlock register */ |
| 34 | |
| 35 | void __iomem *zynq_slcr_base; |
| 36 | |
| 37 | /** |
| 38 | * zynq_slcr_init |
| 39 | * Returns 0 on success, negative errno otherwise. |
| 40 | * |
| 41 | * Called early during boot from platform code to remap SLCR area. |
| 42 | */ |
| 43 | int __init zynq_slcr_init(void) |
| 44 | { |
| 45 | struct device_node *np; |
| 46 | |
| 47 | np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-slcr"); |
| 48 | if (!np) { |
| 49 | pr_err("%s: no slcr node found\n", __func__); |
| 50 | BUG(); |
| 51 | } |
| 52 | |
| 53 | zynq_slcr_base = of_iomap(np, 0); |
| 54 | if (!zynq_slcr_base) { |
| 55 | pr_err("%s: Unable to map I/O memory\n", __func__); |
| 56 | BUG(); |
| 57 | } |
| 58 | |
| 59 | /* unlock the SLCR so that registers can be changed */ |
| 60 | writel(SLCR_UNLOCK_MAGIC, zynq_slcr_base + SLCR_UNLOCK); |
| 61 | |
| 62 | pr_info("%s mapped to %p\n", np->name, zynq_slcr_base); |
| 63 | |
| 64 | xilinx_zynq_clocks_init(zynq_slcr_base); |
| 65 | |
| 66 | of_node_put(np); |
| 67 | |
| 68 | return 0; |
| 69 | } |