| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * intel-mid_wdt: generic Intel MID SCU watchdog driver |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * Copyright (C) 2014 Intel Corporation. All rights reserved. |
|---|
| 8 | 9 | * Contact: David Cohen <david.a.cohen@linux.intel.com> |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or |
|---|
| 11 | | - * modify it under the terms of version 2 of the GNU General |
|---|
| 12 | | - * Public License as published by the Free Software Foundation. |
|---|
| 13 | 10 | */ |
|---|
| 14 | 11 | |
|---|
| 15 | 12 | #include <linux/interrupt.h> |
|---|
| .. | .. |
|---|
| 36 | 33 | SCU_WATCHDOG_KEEPALIVE, |
|---|
| 37 | 34 | }; |
|---|
| 38 | 35 | |
|---|
| 39 | | -static inline int wdt_command(int sub, u32 *in, int inlen) |
|---|
| 36 | +struct mid_wdt { |
|---|
| 37 | + struct watchdog_device wd; |
|---|
| 38 | + struct device *dev; |
|---|
| 39 | + struct intel_scu_ipc_dev *scu; |
|---|
| 40 | +}; |
|---|
| 41 | + |
|---|
| 42 | +static inline int |
|---|
| 43 | +wdt_command(struct mid_wdt *mid, int sub, const void *in, size_t inlen, size_t size) |
|---|
| 40 | 44 | { |
|---|
| 41 | | - return intel_scu_ipc_command(IPC_WATCHDOG, sub, in, inlen, NULL, 0); |
|---|
| 45 | + struct intel_scu_ipc_dev *scu = mid->scu; |
|---|
| 46 | + |
|---|
| 47 | + return intel_scu_ipc_dev_command_with_size(scu, IPC_WATCHDOG, sub, in, |
|---|
| 48 | + inlen, size, NULL, 0); |
|---|
| 42 | 49 | } |
|---|
| 43 | 50 | |
|---|
| 44 | 51 | static int wdt_start(struct watchdog_device *wd) |
|---|
| 45 | 52 | { |
|---|
| 46 | | - struct device *dev = watchdog_get_drvdata(wd); |
|---|
| 53 | + struct mid_wdt *mid = watchdog_get_drvdata(wd); |
|---|
| 47 | 54 | int ret, in_size; |
|---|
| 48 | 55 | int timeout = wd->timeout; |
|---|
| 49 | 56 | struct ipc_wd_start { |
|---|
| .. | .. |
|---|
| 52 | 59 | } ipc_wd_start = { timeout - MID_WDT_PRETIMEOUT, timeout }; |
|---|
| 53 | 60 | |
|---|
| 54 | 61 | /* |
|---|
| 55 | | - * SCU expects the input size for watchdog IPC to |
|---|
| 56 | | - * be based on 4 bytes |
|---|
| 62 | + * SCU expects the input size for watchdog IPC to be 2 which is the |
|---|
| 63 | + * size of the structure in dwords. SCU IPC normally takes bytes |
|---|
| 64 | + * but this is a special case where we specify size to be different |
|---|
| 65 | + * than inlen. |
|---|
| 57 | 66 | */ |
|---|
| 58 | 67 | in_size = DIV_ROUND_UP(sizeof(ipc_wd_start), 4); |
|---|
| 59 | 68 | |
|---|
| 60 | | - ret = wdt_command(SCU_WATCHDOG_START, (u32 *)&ipc_wd_start, in_size); |
|---|
| 69 | + ret = wdt_command(mid, SCU_WATCHDOG_START, &ipc_wd_start, |
|---|
| 70 | + sizeof(ipc_wd_start), in_size); |
|---|
| 61 | 71 | if (ret) |
|---|
| 62 | | - dev_crit(dev, "error starting watchdog: %d\n", ret); |
|---|
| 72 | + dev_crit(mid->dev, "error starting watchdog: %d\n", ret); |
|---|
| 63 | 73 | |
|---|
| 64 | 74 | return ret; |
|---|
| 65 | 75 | } |
|---|
| 66 | 76 | |
|---|
| 67 | 77 | static int wdt_ping(struct watchdog_device *wd) |
|---|
| 68 | 78 | { |
|---|
| 69 | | - struct device *dev = watchdog_get_drvdata(wd); |
|---|
| 79 | + struct mid_wdt *mid = watchdog_get_drvdata(wd); |
|---|
| 70 | 80 | int ret; |
|---|
| 71 | 81 | |
|---|
| 72 | | - ret = wdt_command(SCU_WATCHDOG_KEEPALIVE, NULL, 0); |
|---|
| 82 | + ret = wdt_command(mid, SCU_WATCHDOG_KEEPALIVE, NULL, 0, 0); |
|---|
| 73 | 83 | if (ret) |
|---|
| 74 | | - dev_crit(dev, "Error executing keepalive: %d\n", ret); |
|---|
| 84 | + dev_crit(mid->dev, "Error executing keepalive: %d\n", ret); |
|---|
| 75 | 85 | |
|---|
| 76 | 86 | return ret; |
|---|
| 77 | 87 | } |
|---|
| 78 | 88 | |
|---|
| 79 | 89 | static int wdt_stop(struct watchdog_device *wd) |
|---|
| 80 | 90 | { |
|---|
| 81 | | - struct device *dev = watchdog_get_drvdata(wd); |
|---|
| 91 | + struct mid_wdt *mid = watchdog_get_drvdata(wd); |
|---|
| 82 | 92 | int ret; |
|---|
| 83 | 93 | |
|---|
| 84 | | - ret = wdt_command(SCU_WATCHDOG_STOP, NULL, 0); |
|---|
| 94 | + ret = wdt_command(mid, SCU_WATCHDOG_STOP, NULL, 0, 0); |
|---|
| 85 | 95 | if (ret) |
|---|
| 86 | | - dev_crit(dev, "Error stopping watchdog: %d\n", ret); |
|---|
| 96 | + dev_crit(mid->dev, "Error stopping watchdog: %d\n", ret); |
|---|
| 87 | 97 | |
|---|
| 88 | 98 | return ret; |
|---|
| 89 | 99 | } |
|---|
| .. | .. |
|---|
| 110 | 120 | |
|---|
| 111 | 121 | static int mid_wdt_probe(struct platform_device *pdev) |
|---|
| 112 | 122 | { |
|---|
| 123 | + struct device *dev = &pdev->dev; |
|---|
| 113 | 124 | struct watchdog_device *wdt_dev; |
|---|
| 114 | | - struct intel_mid_wdt_pdata *pdata = pdev->dev.platform_data; |
|---|
| 125 | + struct intel_mid_wdt_pdata *pdata = dev->platform_data; |
|---|
| 126 | + struct mid_wdt *mid; |
|---|
| 115 | 127 | int ret; |
|---|
| 116 | 128 | |
|---|
| 117 | 129 | if (!pdata) { |
|---|
| 118 | | - dev_err(&pdev->dev, "missing platform data\n"); |
|---|
| 130 | + dev_err(dev, "missing platform data\n"); |
|---|
| 119 | 131 | return -EINVAL; |
|---|
| 120 | 132 | } |
|---|
| 121 | 133 | |
|---|
| .. | .. |
|---|
| 125 | 137 | return ret; |
|---|
| 126 | 138 | } |
|---|
| 127 | 139 | |
|---|
| 128 | | - wdt_dev = devm_kzalloc(&pdev->dev, sizeof(*wdt_dev), GFP_KERNEL); |
|---|
| 129 | | - if (!wdt_dev) |
|---|
| 140 | + mid = devm_kzalloc(dev, sizeof(*mid), GFP_KERNEL); |
|---|
| 141 | + if (!mid) |
|---|
| 130 | 142 | return -ENOMEM; |
|---|
| 143 | + |
|---|
| 144 | + mid->dev = dev; |
|---|
| 145 | + wdt_dev = &mid->wd; |
|---|
| 131 | 146 | |
|---|
| 132 | 147 | wdt_dev->info = &mid_wdt_info; |
|---|
| 133 | 148 | wdt_dev->ops = &mid_wdt_ops; |
|---|
| 134 | 149 | wdt_dev->min_timeout = MID_WDT_TIMEOUT_MIN; |
|---|
| 135 | 150 | wdt_dev->max_timeout = MID_WDT_TIMEOUT_MAX; |
|---|
| 136 | 151 | wdt_dev->timeout = MID_WDT_DEFAULT_TIMEOUT; |
|---|
| 137 | | - wdt_dev->parent = &pdev->dev; |
|---|
| 152 | + wdt_dev->parent = dev; |
|---|
| 138 | 153 | |
|---|
| 139 | | - watchdog_set_drvdata(wdt_dev, &pdev->dev); |
|---|
| 154 | + watchdog_set_nowayout(wdt_dev, WATCHDOG_NOWAYOUT); |
|---|
| 155 | + watchdog_set_drvdata(wdt_dev, mid); |
|---|
| 140 | 156 | |
|---|
| 141 | | - ret = devm_request_irq(&pdev->dev, pdata->irq, mid_wdt_irq, |
|---|
| 157 | + mid->scu = devm_intel_scu_ipc_dev_get(dev); |
|---|
| 158 | + if (!mid->scu) |
|---|
| 159 | + return -EPROBE_DEFER; |
|---|
| 160 | + |
|---|
| 161 | + ret = devm_request_irq(dev, pdata->irq, mid_wdt_irq, |
|---|
| 142 | 162 | IRQF_SHARED | IRQF_NO_SUSPEND, "watchdog", |
|---|
| 143 | 163 | wdt_dev); |
|---|
| 144 | 164 | if (ret) { |
|---|
| 145 | | - dev_err(&pdev->dev, "error requesting warning irq %d\n", |
|---|
| 146 | | - pdata->irq); |
|---|
| 165 | + dev_err(dev, "error requesting warning irq %d\n", pdata->irq); |
|---|
| 147 | 166 | return ret; |
|---|
| 148 | 167 | } |
|---|
| 149 | 168 | |
|---|
| .. | .. |
|---|
| 163 | 182 | /* Make sure the watchdog is serviced */ |
|---|
| 164 | 183 | set_bit(WDOG_HW_RUNNING, &wdt_dev->status); |
|---|
| 165 | 184 | |
|---|
| 166 | | - ret = devm_watchdog_register_device(&pdev->dev, wdt_dev); |
|---|
| 167 | | - if (ret) { |
|---|
| 168 | | - dev_err(&pdev->dev, "error registering watchdog device\n"); |
|---|
| 185 | + ret = devm_watchdog_register_device(dev, wdt_dev); |
|---|
| 186 | + if (ret) |
|---|
| 169 | 187 | return ret; |
|---|
| 170 | | - } |
|---|
| 171 | 188 | |
|---|
| 172 | | - dev_info(&pdev->dev, "Intel MID watchdog device probed\n"); |
|---|
| 189 | + dev_info(dev, "Intel MID watchdog device probed\n"); |
|---|
| 173 | 190 | |
|---|
| 174 | 191 | return 0; |
|---|
| 175 | 192 | } |
|---|
| .. | .. |
|---|
| 186 | 203 | MODULE_AUTHOR("David Cohen <david.a.cohen@linux.intel.com>"); |
|---|
| 187 | 204 | MODULE_DESCRIPTION("Watchdog Driver for Intel MID platform"); |
|---|
| 188 | 205 | MODULE_LICENSE("GPL"); |
|---|
| 206 | +MODULE_ALIAS("platform:intel_mid_wdt"); |
|---|