| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 Yang Ling <gnaygnil@gmail.com> |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 5 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 6 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 7 | | - * option) any later version. |
|---|
| 8 | 4 | */ |
|---|
| 9 | 5 | |
|---|
| 10 | 6 | #include <linux/clk.h> |
|---|
| .. | .. |
|---|
| 83 | 79 | .set_timeout = ls1x_wdt_set_timeout, |
|---|
| 84 | 80 | }; |
|---|
| 85 | 81 | |
|---|
| 82 | +static void ls1x_clk_disable_unprepare(void *data) |
|---|
| 83 | +{ |
|---|
| 84 | + clk_disable_unprepare(data); |
|---|
| 85 | +} |
|---|
| 86 | + |
|---|
| 86 | 87 | static int ls1x_wdt_probe(struct platform_device *pdev) |
|---|
| 87 | 88 | { |
|---|
| 89 | + struct device *dev = &pdev->dev; |
|---|
| 88 | 90 | struct ls1x_wdt_drvdata *drvdata; |
|---|
| 89 | 91 | struct watchdog_device *ls1x_wdt; |
|---|
| 90 | 92 | unsigned long clk_rate; |
|---|
| 91 | | - struct resource *res; |
|---|
| 92 | 93 | int err; |
|---|
| 93 | 94 | |
|---|
| 94 | | - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); |
|---|
| 95 | + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
|---|
| 95 | 96 | if (!drvdata) |
|---|
| 96 | 97 | return -ENOMEM; |
|---|
| 97 | 98 | |
|---|
| 98 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 99 | | - drvdata->base = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 99 | + drvdata->base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 100 | 100 | if (IS_ERR(drvdata->base)) |
|---|
| 101 | 101 | return PTR_ERR(drvdata->base); |
|---|
| 102 | 102 | |
|---|
| 103 | | - drvdata->clk = devm_clk_get(&pdev->dev, pdev->name); |
|---|
| 103 | + drvdata->clk = devm_clk_get(dev, pdev->name); |
|---|
| 104 | 104 | if (IS_ERR(drvdata->clk)) |
|---|
| 105 | 105 | return PTR_ERR(drvdata->clk); |
|---|
| 106 | 106 | |
|---|
| 107 | 107 | err = clk_prepare_enable(drvdata->clk); |
|---|
| 108 | 108 | if (err) { |
|---|
| 109 | | - dev_err(&pdev->dev, "clk enable failed\n"); |
|---|
| 109 | + dev_err(dev, "clk enable failed\n"); |
|---|
| 110 | 110 | return err; |
|---|
| 111 | 111 | } |
|---|
| 112 | + err = devm_add_action_or_reset(dev, ls1x_clk_disable_unprepare, |
|---|
| 113 | + drvdata->clk); |
|---|
| 114 | + if (err) |
|---|
| 115 | + return err; |
|---|
| 112 | 116 | |
|---|
| 113 | 117 | clk_rate = clk_get_rate(drvdata->clk); |
|---|
| 114 | | - if (!clk_rate) { |
|---|
| 115 | | - err = -EINVAL; |
|---|
| 116 | | - goto err0; |
|---|
| 117 | | - } |
|---|
| 118 | + if (!clk_rate) |
|---|
| 119 | + return -EINVAL; |
|---|
| 118 | 120 | drvdata->clk_rate = clk_rate; |
|---|
| 119 | 121 | |
|---|
| 120 | 122 | ls1x_wdt = &drvdata->wdt; |
|---|
| .. | .. |
|---|
| 123 | 125 | ls1x_wdt->timeout = DEFAULT_HEARTBEAT; |
|---|
| 124 | 126 | ls1x_wdt->min_timeout = 1; |
|---|
| 125 | 127 | ls1x_wdt->max_hw_heartbeat_ms = U32_MAX / clk_rate * 1000; |
|---|
| 126 | | - ls1x_wdt->parent = &pdev->dev; |
|---|
| 128 | + ls1x_wdt->parent = dev; |
|---|
| 127 | 129 | |
|---|
| 128 | | - watchdog_init_timeout(ls1x_wdt, heartbeat, &pdev->dev); |
|---|
| 130 | + watchdog_init_timeout(ls1x_wdt, heartbeat, dev); |
|---|
| 129 | 131 | watchdog_set_nowayout(ls1x_wdt, nowayout); |
|---|
| 130 | 132 | watchdog_set_drvdata(ls1x_wdt, drvdata); |
|---|
| 131 | 133 | |
|---|
| 132 | | - err = watchdog_register_device(&drvdata->wdt); |
|---|
| 133 | | - if (err) { |
|---|
| 134 | | - dev_err(&pdev->dev, "failed to register watchdog device\n"); |
|---|
| 135 | | - goto err0; |
|---|
| 136 | | - } |
|---|
| 134 | + err = devm_watchdog_register_device(dev, &drvdata->wdt); |
|---|
| 135 | + if (err) |
|---|
| 136 | + return err; |
|---|
| 137 | 137 | |
|---|
| 138 | 138 | platform_set_drvdata(pdev, drvdata); |
|---|
| 139 | 139 | |
|---|
| 140 | | - dev_info(&pdev->dev, "Loongson1 Watchdog driver registered\n"); |
|---|
| 141 | | - |
|---|
| 142 | | - return 0; |
|---|
| 143 | | -err0: |
|---|
| 144 | | - clk_disable_unprepare(drvdata->clk); |
|---|
| 145 | | - return err; |
|---|
| 146 | | -} |
|---|
| 147 | | - |
|---|
| 148 | | -static int ls1x_wdt_remove(struct platform_device *pdev) |
|---|
| 149 | | -{ |
|---|
| 150 | | - struct ls1x_wdt_drvdata *drvdata = platform_get_drvdata(pdev); |
|---|
| 151 | | - |
|---|
| 152 | | - watchdog_unregister_device(&drvdata->wdt); |
|---|
| 153 | | - clk_disable_unprepare(drvdata->clk); |
|---|
| 140 | + dev_info(dev, "Loongson1 Watchdog driver registered\n"); |
|---|
| 154 | 141 | |
|---|
| 155 | 142 | return 0; |
|---|
| 156 | 143 | } |
|---|
| 157 | 144 | |
|---|
| 158 | 145 | static struct platform_driver ls1x_wdt_driver = { |
|---|
| 159 | 146 | .probe = ls1x_wdt_probe, |
|---|
| 160 | | - .remove = ls1x_wdt_remove, |
|---|
| 161 | 147 | .driver = { |
|---|
| 162 | 148 | .name = "ls1x-wdt", |
|---|
| 163 | 149 | }, |
|---|