forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/nvmem/mxs-ocotp.c
....@@ -1,20 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Freescale MXS On-Chip OTP driver
34 *
45 * Copyright (C) 2015 Stefan Wahren <stefan.wahren@i2se.com>
56 *
67 * Based on the driver from Huang Shijie and Christoph G. Baumann
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
188 */
199 #include <linux/clk.h>
2010 #include <linux/delay.h>
....@@ -140,12 +130,16 @@
140130 };
141131 MODULE_DEVICE_TABLE(of, mxs_ocotp_match);
142132
133
+static void mxs_ocotp_action(void *data)
134
+{
135
+ clk_unprepare(data);
136
+}
137
+
143138 static int mxs_ocotp_probe(struct platform_device *pdev)
144139 {
145140 struct device *dev = &pdev->dev;
146141 const struct mxs_data *data;
147142 struct mxs_ocotp *otp;
148
- struct resource *res;
149143 const struct of_device_id *match;
150144 int ret;
151145
....@@ -157,8 +151,7 @@
157151 if (!otp)
158152 return -ENOMEM;
159153
160
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
161
- otp->base = devm_ioremap_resource(dev, res);
154
+ otp->base = devm_platform_ioremap_resource(pdev, 0);
162155 if (IS_ERR(otp->base))
163156 return PTR_ERR(otp->base);
164157
....@@ -172,39 +165,26 @@
172165 return ret;
173166 }
174167
168
+ ret = devm_add_action_or_reset(&pdev->dev, mxs_ocotp_action, otp->clk);
169
+ if (ret)
170
+ return ret;
171
+
175172 data = match->data;
176173
177174 ocotp_config.size = data->size;
178175 ocotp_config.priv = otp;
179176 ocotp_config.dev = dev;
180
- otp->nvmem = nvmem_register(&ocotp_config);
181
- if (IS_ERR(otp->nvmem)) {
182
- ret = PTR_ERR(otp->nvmem);
183
- goto err_clk;
184
- }
177
+ otp->nvmem = devm_nvmem_register(dev, &ocotp_config);
178
+ if (IS_ERR(otp->nvmem))
179
+ return PTR_ERR(otp->nvmem);
185180
186181 platform_set_drvdata(pdev, otp);
187182
188183 return 0;
189
-
190
-err_clk:
191
- clk_unprepare(otp->clk);
192
-
193
- return ret;
194
-}
195
-
196
-static int mxs_ocotp_remove(struct platform_device *pdev)
197
-{
198
- struct mxs_ocotp *otp = platform_get_drvdata(pdev);
199
-
200
- clk_unprepare(otp->clk);
201
-
202
- return nvmem_unregister(otp->nvmem);
203184 }
204185
205186 static struct platform_driver mxs_ocotp_driver = {
206187 .probe = mxs_ocotp_probe,
207
- .remove = mxs_ocotp_remove,
208188 .driver = {
209189 .name = "mxs-ocotp",
210190 .of_match_table = mxs_ocotp_match,
....@@ -212,6 +192,6 @@
212192 };
213193
214194 module_platform_driver(mxs_ocotp_driver);
215
-MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>");
195
+MODULE_AUTHOR("Stefan Wahren <wahrenst@gmx.net");
216196 MODULE_DESCRIPTION("driver for OCOTP in i.MX23/i.MX28");
217197 MODULE_LICENSE("GPL v2");