Binghua Duan | 02c981c | 2011-07-08 17:40:12 +0800 | [diff] [blame] | 1 | /* |
| 2 | * reset controller for CSR SiRFprimaII |
| 3 | * |
| 4 | * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company. |
| 5 | * |
| 6 | * Licensed under GPLv2 or later. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/mutex.h> |
| 11 | #include <linux/io.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <linux/of_address.h> |
| 16 | |
| 17 | void __iomem *sirfsoc_rstc_base; |
| 18 | static DEFINE_MUTEX(rstc_lock); |
| 19 | |
| 20 | static struct of_device_id rstc_ids[] = { |
| 21 | { .compatible = "sirf,prima2-rstc" }, |
Barry Song | 0ecb40c | 2012-12-20 17:40:47 +0800 | [diff] [blame] | 22 | { .compatible = "sirf,marco-rstc" }, |
Jamie Iles | 6a53747 | 2011-08-01 21:09:36 +0100 | [diff] [blame] | 23 | {}, |
Binghua Duan | 02c981c | 2011-07-08 17:40:12 +0800 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | static int __init sirfsoc_of_rstc_init(void) |
| 27 | { |
| 28 | struct device_node *np; |
| 29 | |
| 30 | np = of_find_matching_node(NULL, rstc_ids); |
Haojian Zhuang | 7e5955d | 2013-06-07 11:17:07 +0800 | [diff] [blame] | 31 | if (!np) { |
| 32 | pr_err("unable to find compatible sirf rstc node in dtb\n"); |
| 33 | return -ENOENT; |
| 34 | } |
Binghua Duan | 02c981c | 2011-07-08 17:40:12 +0800 | [diff] [blame] | 35 | |
| 36 | sirfsoc_rstc_base = of_iomap(np, 0); |
| 37 | if (!sirfsoc_rstc_base) |
| 38 | panic("unable to map rstc cpu registers\n"); |
| 39 | |
| 40 | of_node_put(np); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | early_initcall(sirfsoc_of_rstc_init); |
| 45 | |
| 46 | int sirfsoc_reset_device(struct device *dev) |
| 47 | { |
Barry Song | 0ecb40c | 2012-12-20 17:40:47 +0800 | [diff] [blame] | 48 | u32 reset_bit; |
Binghua Duan | 02c981c | 2011-07-08 17:40:12 +0800 | [diff] [blame] | 49 | |
Barry Song | 0ecb40c | 2012-12-20 17:40:47 +0800 | [diff] [blame] | 50 | if (of_property_read_u32(dev->of_node, "reset-bit", &reset_bit)) |
| 51 | return -EINVAL; |
Binghua Duan | 02c981c | 2011-07-08 17:40:12 +0800 | [diff] [blame] | 52 | |
| 53 | mutex_lock(&rstc_lock); |
| 54 | |
Barry Song | 0ecb40c | 2012-12-20 17:40:47 +0800 | [diff] [blame] | 55 | if (of_device_is_compatible(dev->of_node, "sirf,prima2-rstc")) { |
| 56 | /* |
| 57 | * Writing 1 to this bit resets corresponding block. Writing 0 to this |
| 58 | * bit de-asserts reset signal of the corresponding block. |
| 59 | * datasheet doesn't require explicit delay between the set and clear |
| 60 | * of reset bit. it could be shorter if tests pass. |
| 61 | */ |
| 62 | writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) | reset_bit, |
| 63 | sirfsoc_rstc_base + (reset_bit / 32) * 4); |
| 64 | msleep(10); |
| 65 | writel(readl(sirfsoc_rstc_base + (reset_bit / 32) * 4) & ~reset_bit, |
| 66 | sirfsoc_rstc_base + (reset_bit / 32) * 4); |
| 67 | } else { |
| 68 | /* |
| 69 | * For MARCO and POLO |
| 70 | * Writing 1 to SET register resets corresponding block. Writing 1 to CLEAR |
| 71 | * register de-asserts reset signal of the corresponding block. |
| 72 | * datasheet doesn't require explicit delay between the set and clear |
| 73 | * of reset bit. it could be shorter if tests pass. |
| 74 | */ |
| 75 | writel(reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8); |
| 76 | msleep(10); |
| 77 | writel(reset_bit, sirfsoc_rstc_base + (reset_bit / 32) * 8 + 4); |
| 78 | } |
Binghua Duan | 02c981c | 2011-07-08 17:40:12 +0800 | [diff] [blame] | 79 | |
| 80 | mutex_unlock(&rstc_lock); |
| 81 | |
| 82 | return 0; |
| 83 | } |
Russell King | 125c403 | 2011-11-05 10:23:27 +0000 | [diff] [blame] | 84 | |
| 85 | #define SIRFSOC_SYS_RST_BIT BIT(31) |
| 86 | |
| 87 | void sirfsoc_restart(char mode, const char *cmd) |
| 88 | { |
| 89 | writel(SIRFSOC_SYS_RST_BIT, sirfsoc_rstc_base); |
| 90 | } |