Skip to content

Commit b8d665a

Browse files
tmlindherbertx
authored andcommitted
hwrng: omap3-rom - Update to use standard driver data
Let's update omap3-rom-rng to use standard driver data to make it easier to add runtime PM support in the following patch. Just use it for the rng ops and clock for now. Let's still keep also old rng_clk still around, we will remove delayed work and rng_clk with runtime PM in the next patch. Cc: Aaro Koskinen <[email protected]> Cc: Adam Ford <[email protected]> Cc: Pali Rohár <[email protected]> Cc: Sebastian Reichel <[email protected]> Cc: Tero Kristo <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent a0f19a8 commit b8d665a

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

drivers/char/hw_random/omap3-rom-rng.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
/* param1: ptr, param2: count, param3: flag */
3232
static u32 (*omap3_rom_rng_call)(u32, u32, u32);
3333

34+
struct omap_rom_rng {
35+
struct clk *clk;
36+
struct device *dev;
37+
struct hwrng ops;
38+
};
39+
3440
static struct delayed_work idle_work;
3541
static int rng_idle;
3642
static struct clk *rng_clk;
@@ -86,48 +92,57 @@ static int omap3_rom_rng_read(struct hwrng *rng, void *data, size_t max, bool w)
8692
return 4;
8793
}
8894

89-
static struct hwrng omap3_rom_rng_ops = {
90-
.name = "omap3-rom",
91-
.quality = 900,
92-
};
93-
9495
static int omap3_rom_rng_probe(struct platform_device *pdev)
9596
{
97+
struct omap_rom_rng *ddata;
9698
int ret = 0;
9799

98-
omap3_rom_rng_ops.read = of_device_get_match_data(&pdev->dev);
99-
if (!omap3_rom_rng_ops.read) {
100+
ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
101+
if (!ddata)
102+
return -ENOMEM;
103+
104+
ddata->dev = &pdev->dev;
105+
ddata->ops.priv = (unsigned long)ddata;
106+
ddata->ops.name = "omap3-rom";
107+
ddata->ops.read = of_device_get_match_data(&pdev->dev);
108+
ddata->ops.quality = 900;
109+
if (!ddata->ops.read) {
100110
dev_err(&pdev->dev, "missing rom code handler\n");
101111

102112
return -ENODEV;
103113
}
114+
dev_set_drvdata(ddata->dev, ddata);
104115

105116
omap3_rom_rng_call = pdev->dev.platform_data;
106117
if (!omap3_rom_rng_call) {
107-
pr_err("omap3_rom_rng_call is NULL\n");
118+
dev_err(ddata->dev, "rom_rng_call is NULL\n");
108119
return -EINVAL;
109120
}
110121

111122
INIT_DELAYED_WORK(&idle_work, omap3_rom_rng_idle);
112-
rng_clk = devm_clk_get(&pdev->dev, "ick");
113-
if (IS_ERR(rng_clk)) {
114-
pr_err("unable to get RNG clock\n");
115-
return PTR_ERR(rng_clk);
123+
ddata->clk = devm_clk_get(ddata->dev, "ick");
124+
if (IS_ERR(ddata->clk)) {
125+
dev_err(ddata->dev, "unable to get RNG clock\n");
126+
return PTR_ERR(ddata->clk);
116127
}
128+
rng_clk = ddata->clk;
117129

118130
/* Leave the RNG in reset state. */
119-
ret = clk_prepare_enable(rng_clk);
131+
ret = clk_prepare_enable(ddata->clk);
120132
if (ret)
121133
return ret;
122134
omap3_rom_rng_idle(0);
123135

124-
return hwrng_register(&omap3_rom_rng_ops);
136+
return hwrng_register(&ddata->ops);
125137
}
126138

127139
static int omap3_rom_rng_remove(struct platform_device *pdev)
128140
{
141+
struct omap_rom_rng *ddata;
142+
143+
ddata = dev_get_drvdata(&pdev->dev);
129144
cancel_delayed_work_sync(&idle_work);
130-
hwrng_unregister(&omap3_rom_rng_ops);
145+
hwrng_unregister(&ddata->ops);
131146
if (!rng_idle)
132147
clk_disable_unprepare(rng_clk);
133148
return 0;

0 commit comments

Comments
 (0)