Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <mmio.h> |
| 32 | #include <sp805.h> |
| 33 | #include <stdint.h> |
| 34 | |
| 35 | /* Inline register access functions */ |
| 36 | |
| 37 | static inline void sp805_write_wdog_load(uintptr_t base, unsigned long value) |
| 38 | { |
| 39 | mmio_write_32(base + SP805_WDOG_LOAD_OFF, value); |
| 40 | } |
| 41 | |
| 42 | static inline void sp805_write_wdog_ctrl(uintptr_t base, unsigned long value) |
| 43 | { |
| 44 | mmio_write_32(base + SP805_WDOG_CTR_OFF, value); |
| 45 | } |
| 46 | |
| 47 | static inline void sp805_write_wdog_lock(uintptr_t base, unsigned long value) |
| 48 | { |
| 49 | mmio_write_32(base + SP805_WDOG_LOCK_OFF, value); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /* Public API implementation */ |
| 54 | |
| 55 | void sp805_start(uintptr_t base, unsigned long ticks) |
| 56 | { |
| 57 | sp805_write_wdog_load(base, ticks); |
| 58 | sp805_write_wdog_ctrl(base, SP805_CTR_RESEN | SP805_CTR_INTEN); |
| 59 | /* Lock registers access */ |
| 60 | sp805_write_wdog_lock(base, 0); |
| 61 | } |
| 62 | |
| 63 | void sp805_stop(uintptr_t base) |
| 64 | { |
| 65 | sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY); |
| 66 | sp805_write_wdog_ctrl(base, 0); |
| 67 | } |
| 68 | |
| 69 | void sp805_refresh(uintptr_t base, unsigned long ticks) |
| 70 | { |
| 71 | sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY); |
| 72 | sp805_write_wdog_load(base, ticks); |
| 73 | sp805_write_wdog_lock(base, 0); |
| 74 | } |