Lokesh Vutla | 341e8cb | 2020-03-05 13:57:10 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/arm/plat-omap/dmtimer.c |
| 4 | * |
| 5 | * OMAP Dual-Mode Timers |
| 6 | * |
Alexander A. Klimov | dcf30fc | 2020-07-08 18:58:56 +0200 | [diff] [blame] | 7 | * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/ |
Tarun Kanti DebBarma | 97933d6 | 2011-09-20 17:00:17 +0530 | [diff] [blame] | 8 | * Tarun Kanti DebBarma <tarun.kanti@ti.com> |
| 9 | * Thara Gopinath <thara@ti.com> |
| 10 | * |
| 11 | * dmtimer adaptation to platform_driver. |
| 12 | * |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 13 | * Copyright (C) 2005 Nokia Corporation |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 14 | * OMAP2 support by Juha Yrjola |
| 15 | * API improvements and OMAP2 clock framework support by Timo Teras |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 16 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 17 | * Copyright (C) 2009 Texas Instruments |
| 18 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
Jon Hunter | b153883 | 2012-09-28 11:43:30 -0500 | [diff] [blame] | 21 | #include <linux/clk.h> |
Suman Anna | ea05d2e | 2015-10-05 18:28:21 -0500 | [diff] [blame] | 22 | #include <linux/clk-provider.h> |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 23 | #include <linux/cpu_pm.h> |
Axel Lin | 869dec1 | 2011-11-02 09:49:46 +0800 | [diff] [blame] | 24 | #include <linux/module.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 25 | #include <linux/io.h> |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 26 | #include <linux/device.h> |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 27 | #include <linux/err.h> |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 28 | #include <linux/pm_runtime.h> |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 29 | #include <linux/of.h> |
| 30 | #include <linux/of_device.h> |
Jon Hunter | 40fc3bb | 2012-09-28 11:34:49 -0500 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/platform_data/dmtimer-omap.h> |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 33 | |
Keerthy | 5ca467c | 2018-02-15 11:31:44 +0530 | [diff] [blame] | 34 | #include <clocksource/timer-ti-dm.h> |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 35 | |
Jon Hunter | b7b4ff7 | 2012-06-05 12:34:51 -0500 | [diff] [blame] | 36 | static u32 omap_reserved_systimers; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 37 | static LIST_HEAD(omap_timer_list); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 38 | static DEFINE_SPINLOCK(dm_timer_lock); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 39 | |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 40 | enum { |
| 41 | REQUEST_ANY = 0, |
| 42 | REQUEST_BY_ID, |
| 43 | REQUEST_BY_CAP, |
| 44 | REQUEST_BY_NODE, |
| 45 | }; |
| 46 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 47 | /** |
| 48 | * omap_dm_timer_read_reg - read timer registers in posted and non-posted mode |
| 49 | * @timer: timer pointer over which read operation to perform |
| 50 | * @reg: lowest byte holds the register offset |
| 51 | * |
| 52 | * The posted mode bit is encoded in reg. Note that in posted mode write |
| 53 | * pending bit must be checked. Otherwise a read of a non completed write |
| 54 | * will produce an error. |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 55 | */ |
| 56 | static inline u32 omap_dm_timer_read_reg(struct omap_dm_timer *timer, u32 reg) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 57 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 58 | WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET); |
| 59 | return __omap_dm_timer_read(timer, reg, timer->posted); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 62 | /** |
| 63 | * omap_dm_timer_write_reg - write timer registers in posted and non-posted mode |
| 64 | * @timer: timer pointer over which write operation is to perform |
| 65 | * @reg: lowest byte holds the register offset |
| 66 | * @value: data to write into the register |
| 67 | * |
| 68 | * The posted mode bit is encoded in reg. Note that in posted mode the write |
| 69 | * pending bit must be checked. Otherwise a write on a register which has a |
| 70 | * pending write will be lost. |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 71 | */ |
| 72 | static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, u32 reg, |
| 73 | u32 value) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 74 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 75 | WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET); |
| 76 | __omap_dm_timer_write(timer, reg, value, timer->posted); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 79 | static void omap_timer_restore_context(struct omap_dm_timer *timer) |
| 80 | { |
Tony Lindgren | 9517c57 | 2021-04-15 11:55:06 +0300 | [diff] [blame] | 81 | __omap_dm_timer_write(timer, OMAP_TIMER_OCP_CFG_OFFSET, |
| 82 | timer->context.ocp_cfg, 0); |
| 83 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 84 | omap_dm_timer_write_reg(timer, OMAP_TIMER_WAKEUP_EN_REG, |
| 85 | timer->context.twer); |
| 86 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, |
| 87 | timer->context.tcrr); |
| 88 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, |
| 89 | timer->context.tldr); |
| 90 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, |
| 91 | timer->context.tmar); |
| 92 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, |
| 93 | timer->context.tsicr); |
Victor Kamensky | 834cacf | 2014-04-15 20:37:47 +0300 | [diff] [blame] | 94 | writel_relaxed(timer->context.tier, timer->irq_ena); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 95 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, |
| 96 | timer->context.tclr); |
| 97 | } |
| 98 | |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 99 | static void omap_timer_save_context(struct omap_dm_timer *timer) |
| 100 | { |
Tony Lindgren | 9517c57 | 2021-04-15 11:55:06 +0300 | [diff] [blame] | 101 | timer->context.ocp_cfg = |
| 102 | __omap_dm_timer_read(timer, OMAP_TIMER_OCP_CFG_OFFSET, 0); |
| 103 | |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 104 | timer->context.tclr = |
| 105 | omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 106 | timer->context.twer = |
| 107 | omap_dm_timer_read_reg(timer, OMAP_TIMER_WAKEUP_EN_REG); |
| 108 | timer->context.tldr = |
| 109 | omap_dm_timer_read_reg(timer, OMAP_TIMER_LOAD_REG); |
| 110 | timer->context.tmar = |
| 111 | omap_dm_timer_read_reg(timer, OMAP_TIMER_MATCH_REG); |
| 112 | timer->context.tier = readl_relaxed(timer->irq_ena); |
| 113 | timer->context.tsicr = |
| 114 | omap_dm_timer_read_reg(timer, OMAP_TIMER_IF_CTRL_REG); |
| 115 | } |
| 116 | |
| 117 | static int omap_timer_context_notifier(struct notifier_block *nb, |
| 118 | unsigned long cmd, void *v) |
| 119 | { |
| 120 | struct omap_dm_timer *timer; |
| 121 | |
| 122 | timer = container_of(nb, struct omap_dm_timer, nb); |
| 123 | |
| 124 | switch (cmd) { |
| 125 | case CPU_CLUSTER_PM_ENTER: |
| 126 | if ((timer->capability & OMAP_TIMER_ALWON) || |
| 127 | !atomic_read(&timer->enabled)) |
| 128 | break; |
| 129 | omap_timer_save_context(timer); |
| 130 | break; |
Tony Lindgren | 3d41fff | 2021-05-18 10:53:06 +0300 | [diff] [blame] | 131 | case CPU_CLUSTER_PM_ENTER_FAILED: /* No need to restore context */ |
| 132 | break; |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 133 | case CPU_CLUSTER_PM_EXIT: |
| 134 | if ((timer->capability & OMAP_TIMER_ALWON) || |
| 135 | !atomic_read(&timer->enabled)) |
| 136 | break; |
| 137 | omap_timer_restore_context(timer); |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | return NOTIFY_OK; |
| 142 | } |
| 143 | |
Jon Hunter | ae6672c | 2012-07-11 13:47:38 -0500 | [diff] [blame] | 144 | static int omap_dm_timer_reset(struct omap_dm_timer *timer) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 145 | { |
Jon Hunter | ae6672c | 2012-07-11 13:47:38 -0500 | [diff] [blame] | 146 | u32 l, timeout = 100000; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 147 | |
Jon Hunter | ae6672c | 2012-07-11 13:47:38 -0500 | [diff] [blame] | 148 | if (timer->revision != 1) |
| 149 | return -EINVAL; |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 150 | |
Jon Hunter | ffc957b | 2012-07-06 16:46:35 -0500 | [diff] [blame] | 151 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0x06); |
Jon Hunter | ae6672c | 2012-07-11 13:47:38 -0500 | [diff] [blame] | 152 | |
| 153 | do { |
| 154 | l = __omap_dm_timer_read(timer, |
| 155 | OMAP_TIMER_V1_SYS_STAT_OFFSET, 0); |
| 156 | } while (!l && timeout--); |
| 157 | |
| 158 | if (!timeout) { |
| 159 | dev_err(&timer->pdev->dev, "Timer failed to reset\n"); |
| 160 | return -ETIMEDOUT; |
| 161 | } |
| 162 | |
| 163 | /* Configure timer for smart-idle mode */ |
| 164 | l = __omap_dm_timer_read(timer, OMAP_TIMER_OCP_CFG_OFFSET, 0); |
| 165 | l |= 0x2 << 0x3; |
| 166 | __omap_dm_timer_write(timer, OMAP_TIMER_OCP_CFG_OFFSET, l, 0); |
| 167 | |
| 168 | timer->posted = 0; |
| 169 | |
| 170 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 173 | static int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source) |
| 174 | { |
| 175 | int ret; |
Ladislav Michl | ad6e4b6 | 2018-02-23 11:14:22 +0100 | [diff] [blame] | 176 | const char *parent_name; |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 177 | struct clk *parent; |
| 178 | struct dmtimer_platform_data *pdata; |
| 179 | |
Ladislav Michl | ad6e4b6 | 2018-02-23 11:14:22 +0100 | [diff] [blame] | 180 | if (unlikely(!timer) || IS_ERR(timer->fclk)) |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 181 | return -EINVAL; |
| 182 | |
Ladislav Michl | ad6e4b6 | 2018-02-23 11:14:22 +0100 | [diff] [blame] | 183 | switch (source) { |
| 184 | case OMAP_TIMER_SRC_SYS_CLK: |
| 185 | parent_name = "timer_sys_ck"; |
| 186 | break; |
| 187 | case OMAP_TIMER_SRC_32_KHZ: |
| 188 | parent_name = "timer_32k_ck"; |
| 189 | break; |
| 190 | case OMAP_TIMER_SRC_EXT_CLK: |
| 191 | parent_name = "timer_ext_ck"; |
| 192 | break; |
| 193 | default: |
| 194 | return -EINVAL; |
| 195 | } |
| 196 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 197 | pdata = timer->pdev->dev.platform_data; |
| 198 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 199 | /* |
| 200 | * FIXME: Used for OMAP1 devices only because they do not currently |
| 201 | * use the clock framework to set the parent clock. To be removed |
| 202 | * once OMAP1 migrated to using clock framework for dmtimers |
| 203 | */ |
| 204 | if (pdata && pdata->set_timer_src) |
| 205 | return pdata->set_timer_src(timer->pdev, source); |
| 206 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 207 | #if defined(CONFIG_COMMON_CLK) |
| 208 | /* Check if the clock has configurable parents */ |
| 209 | if (clk_hw_get_num_parents(__clk_get_hw(timer->fclk)) < 2) |
| 210 | return 0; |
| 211 | #endif |
| 212 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 213 | parent = clk_get(&timer->pdev->dev, parent_name); |
| 214 | if (IS_ERR(parent)) { |
| 215 | pr_err("%s: %s not found\n", __func__, parent_name); |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
| 219 | ret = clk_set_parent(timer->fclk, parent); |
| 220 | if (ret < 0) |
| 221 | pr_err("%s: failed to set %s as parent\n", __func__, |
| 222 | parent_name); |
| 223 | |
| 224 | clk_put(parent); |
| 225 | |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | static void omap_dm_timer_enable(struct omap_dm_timer *timer) |
| 230 | { |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 231 | pm_runtime_get_sync(&timer->pdev->dev); |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static void omap_dm_timer_disable(struct omap_dm_timer *timer) |
| 235 | { |
| 236 | pm_runtime_put_sync(&timer->pdev->dev); |
| 237 | } |
| 238 | |
Jon Hunter | b0cadb3 | 2012-09-28 12:21:09 -0500 | [diff] [blame] | 239 | static int omap_dm_timer_prepare(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 240 | { |
Jon Hunter | ae6672c | 2012-07-11 13:47:38 -0500 | [diff] [blame] | 241 | int rc; |
| 242 | |
Jon Hunter | bca4580 | 2012-06-05 12:34:58 -0500 | [diff] [blame] | 243 | /* |
| 244 | * FIXME: OMAP1 devices do not use the clock framework for dmtimers so |
| 245 | * do not call clk_get() for these devices. |
| 246 | */ |
| 247 | if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) { |
| 248 | timer->fclk = clk_get(&timer->pdev->dev, "fck"); |
Russell King | 8628795 | 2013-02-24 10:46:59 +0000 | [diff] [blame] | 249 | if (WARN_ON_ONCE(IS_ERR(timer->fclk))) { |
Jon Hunter | bca4580 | 2012-06-05 12:34:58 -0500 | [diff] [blame] | 250 | dev_err(&timer->pdev->dev, ": No fclk handle.\n"); |
| 251 | return -EINVAL; |
| 252 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 253 | } |
| 254 | |
Jon Hunter | 7b44cf2 | 2012-07-06 16:45:04 -0500 | [diff] [blame] | 255 | omap_dm_timer_enable(timer); |
| 256 | |
Jon Hunter | ae6672c | 2012-07-11 13:47:38 -0500 | [diff] [blame] | 257 | if (timer->capability & OMAP_TIMER_NEEDS_RESET) { |
| 258 | rc = omap_dm_timer_reset(timer); |
| 259 | if (rc) { |
| 260 | omap_dm_timer_disable(timer); |
| 261 | return rc; |
| 262 | } |
| 263 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 264 | |
Jon Hunter | 7b44cf2 | 2012-07-06 16:45:04 -0500 | [diff] [blame] | 265 | __omap_dm_timer_enable_posted(timer); |
| 266 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 267 | |
Lokesh Vutla | 264418e | 2020-04-27 22:58:31 +0530 | [diff] [blame] | 268 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Jon Hunter | b7b4ff7 | 2012-06-05 12:34:51 -0500 | [diff] [blame] | 271 | static inline u32 omap_dm_timer_reserved_systimer(int id) |
| 272 | { |
| 273 | return (omap_reserved_systimers & (1 << (id - 1))) ? 1 : 0; |
| 274 | } |
| 275 | |
| 276 | int omap_dm_timer_reserve_systimer(int id) |
| 277 | { |
| 278 | if (omap_dm_timer_reserved_systimer(id)) |
| 279 | return -ENODEV; |
| 280 | |
| 281 | omap_reserved_systimers |= (1 << (id - 1)); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 286 | static struct omap_dm_timer *_omap_dm_timer_request(int req_type, void *data) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 287 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 288 | struct omap_dm_timer *timer = NULL, *t; |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 289 | struct device_node *np = NULL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 290 | unsigned long flags; |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 291 | u32 cap = 0; |
| 292 | int id = 0; |
| 293 | |
| 294 | switch (req_type) { |
| 295 | case REQUEST_BY_ID: |
| 296 | id = *(int *)data; |
| 297 | break; |
| 298 | case REQUEST_BY_CAP: |
| 299 | cap = *(u32 *)data; |
| 300 | break; |
| 301 | case REQUEST_BY_NODE: |
| 302 | np = (struct device_node *)data; |
| 303 | break; |
| 304 | default: |
| 305 | /* REQUEST_ANY */ |
| 306 | break; |
| 307 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 308 | |
| 309 | spin_lock_irqsave(&dm_timer_lock, flags); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 310 | list_for_each_entry(t, &omap_timer_list, node) { |
| 311 | if (t->reserved) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 312 | continue; |
| 313 | |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 314 | switch (req_type) { |
| 315 | case REQUEST_BY_ID: |
| 316 | if (id == t->pdev->id) { |
| 317 | timer = t; |
| 318 | timer->reserved = 1; |
| 319 | goto found; |
| 320 | } |
| 321 | break; |
| 322 | case REQUEST_BY_CAP: |
| 323 | if (cap == (t->capability & cap)) { |
| 324 | /* |
| 325 | * If timer is not NULL, we have already found |
Markus Elfring | 28fd7e9 | 2017-10-03 21:24:00 +0200 | [diff] [blame] | 326 | * one timer. But it was not an exact match |
| 327 | * because it had more capabilities than what |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 328 | * was required. Therefore, unreserve the last |
| 329 | * timer found and see if this one is a better |
| 330 | * match. |
| 331 | */ |
| 332 | if (timer) |
| 333 | timer->reserved = 0; |
| 334 | timer = t; |
| 335 | timer->reserved = 1; |
| 336 | |
| 337 | /* Exit loop early if we find an exact match */ |
| 338 | if (t->capability == cap) |
| 339 | goto found; |
| 340 | } |
| 341 | break; |
| 342 | case REQUEST_BY_NODE: |
| 343 | if (np == t->pdev->dev.of_node) { |
| 344 | timer = t; |
| 345 | timer->reserved = 1; |
| 346 | goto found; |
| 347 | } |
| 348 | break; |
| 349 | default: |
| 350 | /* REQUEST_ANY */ |
| 351 | timer = t; |
| 352 | timer->reserved = 1; |
| 353 | goto found; |
| 354 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 355 | } |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 356 | found: |
Timo Kokkonen | c5491d1 | 2012-08-12 13:45:34 +0300 | [diff] [blame] | 357 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 358 | |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 359 | if (timer && omap_dm_timer_prepare(timer)) { |
| 360 | timer->reserved = 0; |
| 361 | timer = NULL; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 362 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 363 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 364 | if (!timer) |
| 365 | pr_debug("%s: timer request failed!\n", __func__); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 366 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 367 | return timer; |
| 368 | } |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 369 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 370 | static struct omap_dm_timer *omap_dm_timer_request(void) |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 371 | { |
| 372 | return _omap_dm_timer_request(REQUEST_ANY, NULL); |
| 373 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 374 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 375 | static struct omap_dm_timer *omap_dm_timer_request_specific(int id) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 376 | { |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 377 | /* Requesting timer by ID is not supported when device tree is used */ |
| 378 | if (of_have_populated_dt()) { |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 379 | pr_warn("%s: Please use omap_dm_timer_request_by_node()\n", |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 380 | __func__); |
| 381 | return NULL; |
| 382 | } |
| 383 | |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 384 | return _omap_dm_timer_request(REQUEST_BY_ID, &id); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Jon Hunter | 373fe0b | 2012-09-06 15:28:00 -0500 | [diff] [blame] | 387 | /** |
| 388 | * omap_dm_timer_request_by_cap - Request a timer by capability |
| 389 | * @cap: Bit mask of capabilities to match |
| 390 | * |
| 391 | * Find a timer based upon capabilities bit mask. Callers of this function |
| 392 | * should use the definitions found in the plat/dmtimer.h file under the |
| 393 | * comment "timer capabilities used in hwmod database". Returns pointer to |
| 394 | * timer handle on success and a NULL pointer on failure. |
| 395 | */ |
| 396 | struct omap_dm_timer *omap_dm_timer_request_by_cap(u32 cap) |
| 397 | { |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 398 | return _omap_dm_timer_request(REQUEST_BY_CAP, &cap); |
Jon Hunter | 373fe0b | 2012-09-06 15:28:00 -0500 | [diff] [blame] | 399 | } |
Jon Hunter | 373fe0b | 2012-09-06 15:28:00 -0500 | [diff] [blame] | 400 | |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 401 | /** |
| 402 | * omap_dm_timer_request_by_node - Request a timer by device-tree node |
| 403 | * @np: Pointer to device-tree timer node |
| 404 | * |
| 405 | * Request a timer based upon a device node pointer. Returns pointer to |
| 406 | * timer handle on success and a NULL pointer on failure. |
| 407 | */ |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 408 | static struct omap_dm_timer *omap_dm_timer_request_by_node(struct device_node *np) |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 409 | { |
| 410 | if (!np) |
| 411 | return NULL; |
| 412 | |
| 413 | return _omap_dm_timer_request(REQUEST_BY_NODE, np); |
| 414 | } |
Jon Hunter | 8fc7fcb | 2013-03-19 12:38:17 -0500 | [diff] [blame] | 415 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 416 | static int omap_dm_timer_free(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 417 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 418 | if (unlikely(!timer)) |
| 419 | return -EINVAL; |
| 420 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 421 | clk_put(timer->fclk); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 422 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 423 | WARN_ON(!timer->reserved); |
| 424 | timer->reserved = 0; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 425 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | int omap_dm_timer_get_irq(struct omap_dm_timer *timer) |
| 429 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 430 | if (timer) |
| 431 | return timer->irq; |
| 432 | return -EINVAL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | #if defined(CONFIG_ARCH_OMAP1) |
Tony Lindgren | 7136f8d | 2012-10-31 12:38:43 -0700 | [diff] [blame] | 436 | #include <mach/hardware.h> |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 437 | |
| 438 | static struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer) |
| 439 | { |
| 440 | return NULL; |
| 441 | } |
| 442 | |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 443 | /** |
| 444 | * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR |
| 445 | * @inputmask: current value of idlect mask |
| 446 | */ |
| 447 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 448 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 449 | int i = 0; |
| 450 | struct omap_dm_timer *timer = NULL; |
| 451 | unsigned long flags; |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 452 | |
| 453 | /* If ARMXOR cannot be idled this function call is unnecessary */ |
| 454 | if (!(inputmask & (1 << 1))) |
| 455 | return inputmask; |
| 456 | |
| 457 | /* If any active timer is using ARMXOR return modified mask */ |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 458 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 459 | list_for_each_entry(timer, &omap_timer_list, node) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 460 | u32 l; |
| 461 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 462 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 463 | if (l & OMAP_TIMER_CTRL_ST) { |
| 464 | if (((omap_readl(MOD_CONF_CTRL_1) >> (i * 2)) & 0x03) == 0) |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 465 | inputmask &= ~(1 << 1); |
| 466 | else |
| 467 | inputmask &= ~(1 << 2); |
| 468 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 469 | i++; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 470 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 471 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 472 | |
| 473 | return inputmask; |
| 474 | } |
| 475 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 476 | #else |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 477 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 478 | static struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 479 | { |
Russell King | 8628795 | 2013-02-24 10:46:59 +0000 | [diff] [blame] | 480 | if (timer && !IS_ERR(timer->fclk)) |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 481 | return timer->fclk; |
| 482 | return NULL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 486 | { |
| 487 | BUG(); |
Dirk Behme | 2121880 | 2006-12-06 17:14:00 -0800 | [diff] [blame] | 488 | |
| 489 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | #endif |
| 493 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 494 | int omap_dm_timer_trigger(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 495 | { |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 496 | if (unlikely(!timer || !atomic_read(&timer->enabled))) { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 497 | pr_err("%s: timer not available or enabled.\n", __func__); |
| 498 | return -EINVAL; |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 499 | } |
| 500 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 501 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 502 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 505 | static int omap_dm_timer_start(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 506 | { |
| 507 | u32 l; |
| 508 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 509 | if (unlikely(!timer)) |
| 510 | return -EINVAL; |
| 511 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 512 | omap_dm_timer_enable(timer); |
| 513 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 514 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 515 | if (!(l & OMAP_TIMER_CTRL_ST)) { |
| 516 | l |= OMAP_TIMER_CTRL_ST; |
| 517 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 518 | } |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 519 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 520 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 523 | static int omap_dm_timer_stop(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 524 | { |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 525 | unsigned long rate = 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 526 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 527 | if (unlikely(!timer)) |
| 528 | return -EINVAL; |
| 529 | |
Jon Hunter | 6615975 | 2012-06-05 12:34:57 -0500 | [diff] [blame] | 530 | if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 531 | rate = clk_get_rate(timer->fclk); |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 532 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 533 | __omap_dm_timer_stop(timer, timer->posted, rate); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 534 | |
Tarun Kanti DebBarma | dffc9da | 2012-03-05 16:11:00 -0800 | [diff] [blame] | 535 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 536 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Lokesh Vutla | 02e6d54 | 2020-03-05 13:57:15 +0530 | [diff] [blame] | 539 | static int omap_dm_timer_set_load(struct omap_dm_timer *timer, |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 540 | unsigned int load) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 541 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 542 | if (unlikely(!timer)) |
| 543 | return -EINVAL; |
| 544 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 545 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 546 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 547 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 548 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 549 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 552 | static int omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, |
| 553 | unsigned int match) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 554 | { |
| 555 | u32 l; |
| 556 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 557 | if (unlikely(!timer)) |
| 558 | return -EINVAL; |
| 559 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 560 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 561 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 562 | if (enable) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 563 | l |= OMAP_TIMER_CTRL_CE; |
| 564 | else |
| 565 | l &= ~OMAP_TIMER_CTRL_CE; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 566 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, match); |
Jon Hunter | 991ad16 | 2012-10-04 18:17:42 -0500 | [diff] [blame] | 567 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 568 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 569 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 570 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 571 | } |
| 572 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 573 | static int omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, |
Lokesh Vutla | 02e6d54 | 2020-03-05 13:57:15 +0530 | [diff] [blame] | 574 | int toggle, int trigger, int autoreload) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 575 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 576 | u32 l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 577 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 578 | if (unlikely(!timer)) |
| 579 | return -EINVAL; |
| 580 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 581 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 582 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 583 | l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM | |
Lokesh Vutla | 02e6d54 | 2020-03-05 13:57:15 +0530 | [diff] [blame] | 584 | OMAP_TIMER_CTRL_PT | (0x03 << 10) | OMAP_TIMER_CTRL_AR); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 585 | if (def_on) |
| 586 | l |= OMAP_TIMER_CTRL_SCPWM; |
| 587 | if (toggle) |
| 588 | l |= OMAP_TIMER_CTRL_PT; |
| 589 | l |= trigger << 10; |
Lokesh Vutla | 02e6d54 | 2020-03-05 13:57:15 +0530 | [diff] [blame] | 590 | if (autoreload) |
| 591 | l |= OMAP_TIMER_CTRL_AR; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 592 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 593 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 594 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 595 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Lokesh Vutla | 92fd868 | 2020-03-05 13:57:14 +0530 | [diff] [blame] | 598 | static int omap_dm_timer_get_pwm_status(struct omap_dm_timer *timer) |
| 599 | { |
| 600 | u32 l; |
| 601 | |
| 602 | if (unlikely(!timer)) |
| 603 | return -EINVAL; |
| 604 | |
| 605 | omap_dm_timer_enable(timer); |
| 606 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 607 | omap_dm_timer_disable(timer); |
| 608 | |
| 609 | return l; |
| 610 | } |
| 611 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 612 | static int omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, |
| 613 | int prescaler) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 614 | { |
| 615 | u32 l; |
| 616 | |
Ladislav Michl | 58a54f0 | 2018-02-23 11:15:01 +0100 | [diff] [blame] | 617 | if (unlikely(!timer) || prescaler < -1 || prescaler > 7) |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 618 | return -EINVAL; |
| 619 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 620 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 621 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 622 | l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2)); |
Ladislav Michl | 58a54f0 | 2018-02-23 11:15:01 +0100 | [diff] [blame] | 623 | if (prescaler >= 0) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 624 | l |= OMAP_TIMER_CTRL_PRE; |
| 625 | l |= prescaler << 2; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 626 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 627 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 628 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 629 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 630 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 631 | } |
| 632 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 633 | static int omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, |
| 634 | unsigned int value) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 635 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 636 | if (unlikely(!timer)) |
| 637 | return -EINVAL; |
| 638 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 639 | omap_dm_timer_enable(timer); |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 640 | __omap_dm_timer_int_enable(timer, value); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 641 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 642 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 643 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 644 | } |
| 645 | |
Jon Hunter | 4249d96 | 2012-07-13 14:03:18 -0500 | [diff] [blame] | 646 | /** |
| 647 | * omap_dm_timer_set_int_disable - disable timer interrupts |
| 648 | * @timer: pointer to timer handle |
| 649 | * @mask: bit mask of interrupts to be disabled |
| 650 | * |
| 651 | * Disables the specified timer interrupts for a timer. |
| 652 | */ |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 653 | static int omap_dm_timer_set_int_disable(struct omap_dm_timer *timer, u32 mask) |
Jon Hunter | 4249d96 | 2012-07-13 14:03:18 -0500 | [diff] [blame] | 654 | { |
| 655 | u32 l = mask; |
| 656 | |
| 657 | if (unlikely(!timer)) |
| 658 | return -EINVAL; |
| 659 | |
| 660 | omap_dm_timer_enable(timer); |
| 661 | |
| 662 | if (timer->revision == 1) |
Victor Kamensky | 834cacf | 2014-04-15 20:37:47 +0300 | [diff] [blame] | 663 | l = readl_relaxed(timer->irq_ena) & ~mask; |
Jon Hunter | 4249d96 | 2012-07-13 14:03:18 -0500 | [diff] [blame] | 664 | |
Victor Kamensky | 834cacf | 2014-04-15 20:37:47 +0300 | [diff] [blame] | 665 | writel_relaxed(l, timer->irq_dis); |
Jon Hunter | 4249d96 | 2012-07-13 14:03:18 -0500 | [diff] [blame] | 666 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_WAKEUP_EN_REG) & ~mask; |
| 667 | omap_dm_timer_write_reg(timer, OMAP_TIMER_WAKEUP_EN_REG, l); |
| 668 | |
Jon Hunter | 4249d96 | 2012-07-13 14:03:18 -0500 | [diff] [blame] | 669 | omap_dm_timer_disable(timer); |
| 670 | return 0; |
| 671 | } |
Jon Hunter | 4249d96 | 2012-07-13 14:03:18 -0500 | [diff] [blame] | 672 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 673 | static unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 674 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 675 | unsigned int l; |
| 676 | |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 677 | if (unlikely(!timer || !atomic_read(&timer->enabled))) { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 678 | pr_err("%s: timer not available or enabled.\n", __func__); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 679 | return 0; |
| 680 | } |
| 681 | |
Victor Kamensky | 834cacf | 2014-04-15 20:37:47 +0300 | [diff] [blame] | 682 | l = readl_relaxed(timer->irq_stat); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 683 | |
| 684 | return l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 685 | } |
| 686 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 687 | static int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 688 | { |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 689 | if (unlikely(!timer || !atomic_read(&timer->enabled))) |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 690 | return -EINVAL; |
| 691 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 692 | __omap_dm_timer_write_status(timer, value); |
Jon Hunter | 1eaff71 | 2012-10-04 17:01:14 -0500 | [diff] [blame] | 693 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 694 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 695 | } |
| 696 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 697 | static unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 698 | { |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 699 | if (unlikely(!timer || !atomic_read(&timer->enabled))) { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 700 | pr_err("%s: timer not iavailable or enabled.\n", __func__); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 701 | return 0; |
| 702 | } |
| 703 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 704 | return __omap_dm_timer_read_counter(timer, timer->posted); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 705 | } |
| 706 | |
Ladislav Michl | 592ea6b | 2018-02-28 08:25:19 +0100 | [diff] [blame] | 707 | static int omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value) |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 708 | { |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 709 | if (unlikely(!timer || !atomic_read(&timer->enabled))) { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 710 | pr_err("%s: timer not available or enabled.\n", __func__); |
| 711 | return -EINVAL; |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 712 | } |
| 713 | |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 714 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 715 | |
| 716 | /* Save the context */ |
| 717 | timer->context.tcrr = value; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 718 | return 0; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 721 | int omap_dm_timers_active(void) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 722 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 723 | struct omap_dm_timer *timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 724 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 725 | list_for_each_entry(timer, &omap_timer_list, node) { |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 726 | if (!timer->reserved) |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 727 | continue; |
| 728 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 729 | if (omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG) & |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 730 | OMAP_TIMER_CTRL_ST) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 731 | return 1; |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 732 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 733 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 734 | return 0; |
| 735 | } |
| 736 | |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 737 | static int __maybe_unused omap_dm_timer_runtime_suspend(struct device *dev) |
| 738 | { |
| 739 | struct omap_dm_timer *timer = dev_get_drvdata(dev); |
| 740 | |
| 741 | atomic_set(&timer->enabled, 0); |
| 742 | |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 743 | if (timer->capability & OMAP_TIMER_ALWON || !timer->func_base) |
| 744 | return 0; |
| 745 | |
| 746 | omap_timer_save_context(timer); |
| 747 | |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static int __maybe_unused omap_dm_timer_runtime_resume(struct device *dev) |
| 752 | { |
| 753 | struct omap_dm_timer *timer = dev_get_drvdata(dev); |
| 754 | |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 755 | if (!(timer->capability & OMAP_TIMER_ALWON) && timer->func_base) |
| 756 | omap_timer_restore_context(timer); |
| 757 | |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 758 | atomic_set(&timer->enabled, 1); |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | static const struct dev_pm_ops omap_dm_timer_pm_ops = { |
| 764 | SET_RUNTIME_PM_OPS(omap_dm_timer_runtime_suspend, |
| 765 | omap_dm_timer_runtime_resume, NULL) |
| 766 | }; |
| 767 | |
Jon Hunter | d1c6ccf | 2013-03-19 12:38:19 -0500 | [diff] [blame] | 768 | static const struct of_device_id omap_timer_match[]; |
| 769 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 770 | /** |
| 771 | * omap_dm_timer_probe - probe function called for every registered device |
| 772 | * @pdev: pointer to current timer platform device |
| 773 | * |
| 774 | * Called by driver framework at the end of device registration for all |
| 775 | * timer devices. |
| 776 | */ |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 777 | static int omap_dm_timer_probe(struct platform_device *pdev) |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 778 | { |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 779 | unsigned long flags; |
| 780 | struct omap_dm_timer *timer; |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 781 | struct device *dev = &pdev->dev; |
Jon Hunter | d1c6ccf | 2013-03-19 12:38:19 -0500 | [diff] [blame] | 782 | const struct dmtimer_platform_data *pdata; |
Suman Anna | a76fc9d | 2015-03-16 20:14:02 -0500 | [diff] [blame] | 783 | int ret; |
Jon Hunter | d1c6ccf | 2013-03-19 12:38:19 -0500 | [diff] [blame] | 784 | |
Ladislav Michl | 1a3acad | 2018-02-15 11:31:49 +0530 | [diff] [blame] | 785 | pdata = of_device_get_match_data(dev); |
| 786 | if (!pdata) |
| 787 | pdata = dev_get_platdata(dev); |
| 788 | else |
| 789 | dev->platform_data = (void *)pdata; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 790 | |
Ladislav Michl | 1a3acad | 2018-02-15 11:31:49 +0530 | [diff] [blame] | 791 | if (!pdata) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 792 | dev_err(dev, "%s: no platform data.\n", __func__); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 793 | return -ENODEV; |
| 794 | } |
| 795 | |
Markus Elfring | 16e7ea5 | 2017-10-03 20:46:48 +0200 | [diff] [blame] | 796 | timer = devm_kzalloc(dev, sizeof(*timer), GFP_KERNEL); |
Markus Elfring | d679950 | 2017-10-03 13:10:26 +0200 | [diff] [blame] | 797 | if (!timer) |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 798 | return -ENOMEM; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 799 | |
Tony Lindgren | 4341067 | 2020-01-06 12:37:00 -0800 | [diff] [blame] | 800 | timer->irq = platform_get_irq(pdev, 0); |
| 801 | if (timer->irq < 0) |
| 802 | return timer->irq; |
| 803 | |
Russell King | 8628795 | 2013-02-24 10:46:59 +0000 | [diff] [blame] | 804 | timer->fclk = ERR_PTR(-ENODEV); |
Yangtao Li | cdab83f | 2019-12-21 17:30:26 +0000 | [diff] [blame] | 805 | timer->io_base = devm_platform_ioremap_resource(pdev, 0); |
Thierry Reding | 5857bd9 | 2013-01-21 11:08:55 +0100 | [diff] [blame] | 806 | if (IS_ERR(timer->io_base)) |
| 807 | return PTR_ERR(timer->io_base); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 808 | |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 809 | platform_set_drvdata(pdev, timer); |
| 810 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 811 | if (dev->of_node) { |
| 812 | if (of_find_property(dev->of_node, "ti,timer-alwon", NULL)) |
| 813 | timer->capability |= OMAP_TIMER_ALWON; |
| 814 | if (of_find_property(dev->of_node, "ti,timer-dsp", NULL)) |
| 815 | timer->capability |= OMAP_TIMER_HAS_DSP_IRQ; |
| 816 | if (of_find_property(dev->of_node, "ti,timer-pwm", NULL)) |
| 817 | timer->capability |= OMAP_TIMER_HAS_PWM; |
| 818 | if (of_find_property(dev->of_node, "ti,timer-secure", NULL)) |
| 819 | timer->capability |= OMAP_TIMER_SECURE; |
| 820 | } else { |
| 821 | timer->id = pdev->id; |
| 822 | timer->capability = pdata->timer_capability; |
| 823 | timer->reserved = omap_dm_timer_reserved_systimer(timer->id); |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | if (!(timer->capability & OMAP_TIMER_ALWON)) { |
| 827 | timer->nb.notifier_call = omap_timer_context_notifier; |
| 828 | cpu_pm_register_notifier(&timer->nb); |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 829 | } |
| 830 | |
Jon Hunter | d1c6ccf | 2013-03-19 12:38:19 -0500 | [diff] [blame] | 831 | if (pdata) |
| 832 | timer->errata = pdata->timer_errata; |
| 833 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 834 | timer->pdev = pdev; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 835 | |
Tony Lindgren | ba68878 | 2018-02-22 10:02:49 -0800 | [diff] [blame] | 836 | pm_runtime_enable(dev); |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 837 | |
Tony Lindgren | 0dad9fa | 2011-09-21 16:38:51 -0700 | [diff] [blame] | 838 | if (!timer->reserved) { |
Suman Anna | a76fc9d | 2015-03-16 20:14:02 -0500 | [diff] [blame] | 839 | ret = pm_runtime_get_sync(dev); |
| 840 | if (ret < 0) { |
| 841 | dev_err(dev, "%s: pm_runtime_get_sync failed!\n", |
| 842 | __func__); |
| 843 | goto err_get_sync; |
| 844 | } |
Tony Lindgren | 0dad9fa | 2011-09-21 16:38:51 -0700 | [diff] [blame] | 845 | __omap_dm_timer_init_regs(timer); |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 846 | pm_runtime_put(dev); |
Tony Lindgren | 0dad9fa | 2011-09-21 16:38:51 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 849 | /* add the timer element to the list */ |
| 850 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 851 | list_add_tail(&timer->node, &omap_timer_list); |
| 852 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 853 | |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 854 | dev_dbg(dev, "Device Probed.\n"); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 855 | |
| 856 | return 0; |
Suman Anna | a76fc9d | 2015-03-16 20:14:02 -0500 | [diff] [blame] | 857 | |
| 858 | err_get_sync: |
| 859 | pm_runtime_put_noidle(dev); |
| 860 | pm_runtime_disable(dev); |
| 861 | return ret; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | /** |
| 865 | * omap_dm_timer_remove - cleanup a registered timer device |
| 866 | * @pdev: pointer to current timer platform device |
| 867 | * |
| 868 | * Called by driver framework whenever a timer device is unregistered. |
| 869 | * In addition to freeing platform resources it also deletes the timer |
| 870 | * entry from the local list. |
| 871 | */ |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 872 | static int omap_dm_timer_remove(struct platform_device *pdev) |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 873 | { |
| 874 | struct omap_dm_timer *timer; |
| 875 | unsigned long flags; |
| 876 | int ret = -EINVAL; |
| 877 | |
| 878 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 879 | list_for_each_entry(timer, &omap_timer_list, node) |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 880 | if (!strcmp(dev_name(&timer->pdev->dev), |
| 881 | dev_name(&pdev->dev))) { |
Lokesh Vutla | b34677b | 2020-03-16 16:44:53 +0530 | [diff] [blame] | 882 | if (!(timer->capability & OMAP_TIMER_ALWON)) |
| 883 | cpu_pm_unregister_notifier(&timer->nb); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 884 | list_del(&timer->node); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 885 | ret = 0; |
| 886 | break; |
| 887 | } |
| 888 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 889 | |
Suman Anna | 51b7e57 | 2015-03-16 20:14:03 -0500 | [diff] [blame] | 890 | pm_runtime_disable(&pdev->dev); |
| 891 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 892 | return ret; |
| 893 | } |
| 894 | |
Philippe Mazenauer | cda03a9 | 2019-05-21 12:26:04 +0000 | [diff] [blame] | 895 | static const struct omap_dm_timer_ops dmtimer_ops = { |
Keerthy | 76234f7 | 2018-02-15 11:31:48 +0530 | [diff] [blame] | 896 | .request_by_node = omap_dm_timer_request_by_node, |
| 897 | .request_specific = omap_dm_timer_request_specific, |
| 898 | .request = omap_dm_timer_request, |
| 899 | .set_source = omap_dm_timer_set_source, |
| 900 | .get_irq = omap_dm_timer_get_irq, |
| 901 | .set_int_enable = omap_dm_timer_set_int_enable, |
| 902 | .set_int_disable = omap_dm_timer_set_int_disable, |
| 903 | .free = omap_dm_timer_free, |
| 904 | .enable = omap_dm_timer_enable, |
| 905 | .disable = omap_dm_timer_disable, |
| 906 | .get_fclk = omap_dm_timer_get_fclk, |
| 907 | .start = omap_dm_timer_start, |
| 908 | .stop = omap_dm_timer_stop, |
| 909 | .set_load = omap_dm_timer_set_load, |
| 910 | .set_match = omap_dm_timer_set_match, |
| 911 | .set_pwm = omap_dm_timer_set_pwm, |
Lokesh Vutla | 92fd868 | 2020-03-05 13:57:14 +0530 | [diff] [blame] | 912 | .get_pwm_status = omap_dm_timer_get_pwm_status, |
Keerthy | 76234f7 | 2018-02-15 11:31:48 +0530 | [diff] [blame] | 913 | .set_prescaler = omap_dm_timer_set_prescaler, |
| 914 | .read_counter = omap_dm_timer_read_counter, |
| 915 | .write_counter = omap_dm_timer_write_counter, |
| 916 | .read_status = omap_dm_timer_read_status, |
| 917 | .write_status = omap_dm_timer_write_status, |
| 918 | }; |
| 919 | |
Jon Hunter | d1c6ccf | 2013-03-19 12:38:19 -0500 | [diff] [blame] | 920 | static const struct dmtimer_platform_data omap3plus_pdata = { |
| 921 | .timer_errata = OMAP_TIMER_ERRATA_I103_I767, |
Keerthy | 76234f7 | 2018-02-15 11:31:48 +0530 | [diff] [blame] | 922 | .timer_ops = &dmtimer_ops, |
Jon Hunter | d1c6ccf | 2013-03-19 12:38:19 -0500 | [diff] [blame] | 923 | }; |
| 924 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 925 | static const struct of_device_id omap_timer_match[] = { |
Jon Hunter | d1c6ccf | 2013-03-19 12:38:19 -0500 | [diff] [blame] | 926 | { |
| 927 | .compatible = "ti,omap2420-timer", |
| 928 | }, |
| 929 | { |
| 930 | .compatible = "ti,omap3430-timer", |
| 931 | .data = &omap3plus_pdata, |
| 932 | }, |
| 933 | { |
| 934 | .compatible = "ti,omap4430-timer", |
| 935 | .data = &omap3plus_pdata, |
| 936 | }, |
| 937 | { |
| 938 | .compatible = "ti,omap5430-timer", |
| 939 | .data = &omap3plus_pdata, |
| 940 | }, |
| 941 | { |
| 942 | .compatible = "ti,am335x-timer", |
| 943 | .data = &omap3plus_pdata, |
| 944 | }, |
| 945 | { |
| 946 | .compatible = "ti,am335x-timer-1ms", |
| 947 | .data = &omap3plus_pdata, |
| 948 | }, |
Neil Armstrong | 8c0cabd | 2015-10-22 11:18:53 +0200 | [diff] [blame] | 949 | { |
| 950 | .compatible = "ti,dm816-timer", |
| 951 | .data = &omap3plus_pdata, |
| 952 | }, |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 953 | {}, |
| 954 | }; |
| 955 | MODULE_DEVICE_TABLE(of, omap_timer_match); |
| 956 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 957 | static struct platform_driver omap_dm_timer_driver = { |
| 958 | .probe = omap_dm_timer_probe, |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 959 | .remove = omap_dm_timer_remove, |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 960 | .driver = { |
| 961 | .name = "omap_timer", |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 962 | .of_match_table = of_match_ptr(omap_timer_match), |
Tony Lindgren | 5e20931 | 2020-03-05 13:57:11 +0530 | [diff] [blame] | 963 | .pm = &omap_dm_timer_pm_ops, |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 964 | }, |
| 965 | }; |
| 966 | |
Srinivas Kandagatla | e4e9f7e | 2012-12-16 11:30:02 -0800 | [diff] [blame] | 967 | module_platform_driver(omap_dm_timer_driver); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 968 | |
| 969 | MODULE_DESCRIPTION("OMAP Dual-Mode Timer Driver"); |
| 970 | MODULE_LICENSE("GPL"); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 971 | MODULE_AUTHOR("Texas Instruments Inc"); |