Paul Walmsley | c02060d | 2013-02-10 11:22:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP IP block custom reset and preprogramming stubs |
| 3 | * |
| 4 | * Copyright (C) 2012 Texas Instruments, Inc. |
| 5 | * Paul Walmsley |
| 6 | * |
| 7 | * A small number of IP blocks need custom reset and preprogramming |
| 8 | * functions. The stubs in this file provide a standard way for the |
| 9 | * hwmod code to call these functions, which are to be located under |
| 10 | * drivers/. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation version 2. |
| 15 | * |
| 16 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 17 | * kind, whether express or implied; without even the implied warranty |
| 18 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 24 | * 02110-1301 USA |
| 25 | */ |
| 26 | #include <linux/kernel.h> |
Arnd Bergmann | 55ccb1a | 2013-02-14 17:47:35 +0100 | [diff] [blame] | 27 | #include <linux/errno.h> |
Paul Walmsley | c02060d | 2013-02-10 11:22:23 -0700 | [diff] [blame] | 28 | |
| 29 | #include <sound/aess.h> |
| 30 | |
| 31 | #include "omap_hwmod.h" |
Lokesh Vutla | 461932d | 2016-04-10 13:20:10 -0600 | [diff] [blame] | 32 | #include "common.h" |
| 33 | |
| 34 | #define OMAP_RTC_STATUS_REG 0x44 |
| 35 | #define OMAP_RTC_KICK0_REG 0x6c |
| 36 | #define OMAP_RTC_KICK1_REG 0x70 |
| 37 | |
| 38 | #define OMAP_RTC_KICK0_VALUE 0x83E70B13 |
| 39 | #define OMAP_RTC_KICK1_VALUE 0x95A4F1E0 |
| 40 | #define OMAP_RTC_STATUS_BUSY BIT(0) |
| 41 | #define OMAP_RTC_MAX_READY_TIME 50 |
Paul Walmsley | c02060d | 2013-02-10 11:22:23 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * omap_hwmod_aess_preprogram - enable AESS internal autogating |
| 45 | * @oh: struct omap_hwmod * |
| 46 | * |
| 47 | * The AESS will not IdleAck to the PRCM until its internal autogating |
| 48 | * is enabled. Since internal autogating is disabled by default after |
| 49 | * AESS reset, we must enable autogating after the hwmod code resets |
| 50 | * the AESS. Returns 0. |
| 51 | */ |
| 52 | int omap_hwmod_aess_preprogram(struct omap_hwmod *oh) |
| 53 | { |
| 54 | void __iomem *va; |
| 55 | |
| 56 | va = omap_hwmod_get_mpu_rt_va(oh); |
| 57 | if (!va) |
| 58 | return -EINVAL; |
| 59 | |
| 60 | aess_enable_autogating(va); |
| 61 | |
| 62 | return 0; |
| 63 | } |
Lokesh Vutla | 461932d | 2016-04-10 13:20:10 -0600 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * omap_rtc_wait_not_busy - Wait for the RTC BUSY flag |
| 67 | * @oh: struct omap_hwmod * |
| 68 | * |
| 69 | * For updating certain RTC registers, the MPU must wait |
| 70 | * for the BUSY status in OMAP_RTC_STATUS_REG to become zero. |
| 71 | * Once the BUSY status is zero, there is a 15 microseconds access |
| 72 | * period in which the MPU can program. |
| 73 | */ |
| 74 | static void omap_rtc_wait_not_busy(struct omap_hwmod *oh) |
| 75 | { |
| 76 | int i; |
| 77 | |
| 78 | /* BUSY may stay active for 1/32768 second (~30 usec) */ |
| 79 | omap_test_timeout(omap_hwmod_read(oh, OMAP_RTC_STATUS_REG) |
| 80 | & OMAP_RTC_STATUS_BUSY, OMAP_RTC_MAX_READY_TIME, i); |
| 81 | /* now we have ~15 microseconds to read/write various registers */ |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * omap_hwmod_rtc_unlock - Unlock the Kicker mechanism. |
| 86 | * @oh: struct omap_hwmod * |
| 87 | * |
| 88 | * RTC IP have kicker feature. This prevents spurious writes to its registers. |
| 89 | * In order to write into any of the RTC registers, KICK values has te be |
| 90 | * written in respective KICK registers. This is needed for hwmod to write into |
| 91 | * sysconfig register. |
| 92 | */ |
| 93 | void omap_hwmod_rtc_unlock(struct omap_hwmod *oh) |
| 94 | { |
Dave Gerlach | 6d609b3 | 2018-06-21 14:43:08 +0530 | [diff] [blame] | 95 | unsigned long flags; |
| 96 | |
| 97 | local_irq_save(flags); |
Lokesh Vutla | 461932d | 2016-04-10 13:20:10 -0600 | [diff] [blame] | 98 | omap_rtc_wait_not_busy(oh); |
| 99 | omap_hwmod_write(OMAP_RTC_KICK0_VALUE, oh, OMAP_RTC_KICK0_REG); |
| 100 | omap_hwmod_write(OMAP_RTC_KICK1_VALUE, oh, OMAP_RTC_KICK1_REG); |
Dave Gerlach | 6d609b3 | 2018-06-21 14:43:08 +0530 | [diff] [blame] | 101 | local_irq_restore(flags); |
Lokesh Vutla | 461932d | 2016-04-10 13:20:10 -0600 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
| 105 | * omap_hwmod_rtc_lock - Lock the Kicker mechanism. |
| 106 | * @oh: struct omap_hwmod * |
| 107 | * |
| 108 | * RTC IP have kicker feature. This prevents spurious writes to its registers. |
| 109 | * Once the RTC registers are written, KICK mechanism needs to be locked, |
| 110 | * in order to prevent any spurious writes. This function locks back the RTC |
| 111 | * registers once hwmod completes its write into sysconfig register. |
| 112 | */ |
| 113 | void omap_hwmod_rtc_lock(struct omap_hwmod *oh) |
| 114 | { |
Dave Gerlach | 6d609b3 | 2018-06-21 14:43:08 +0530 | [diff] [blame] | 115 | unsigned long flags; |
| 116 | |
| 117 | local_irq_save(flags); |
Lokesh Vutla | 461932d | 2016-04-10 13:20:10 -0600 | [diff] [blame] | 118 | omap_rtc_wait_not_busy(oh); |
| 119 | omap_hwmod_write(0x0, oh, OMAP_RTC_KICK0_REG); |
| 120 | omap_hwmod_write(0x0, oh, OMAP_RTC_KICK1_REG); |
Dave Gerlach | 6d609b3 | 2018-06-21 14:43:08 +0530 | [diff] [blame] | 121 | local_irq_restore(flags); |
Lokesh Vutla | 461932d | 2016-04-10 13:20:10 -0600 | [diff] [blame] | 122 | } |