20 #include <linux/module.h>
32 #include <linux/slab.h>
66 static inline unsigned short r_tpu_read(
struct r_tpu_priv *
p,
int reg_nr)
70 unsigned long offs = reg_nr << 2;
78 static inline void r_tpu_write(
struct r_tpu_priv *
p,
int reg_nr,
83 unsigned long offs = reg_nr << 2;
100 value = r_tpu_read(p,
TSTR);
107 r_tpu_write(p,
TSTR, value);
108 spin_unlock_irqrestore(&r_tpu_lock, flags);
114 int prescaler[] = { 1, 4, 16, 64 };
122 pm_runtime_get_sync(&p->
pdev->dev);
130 r_tpu_start_stop_ch(p, 0);
137 if ((rate / prescaler[k]) < p->
min_rate)
144 dev_dbg(&p->
pdev->dev,
"rate = %lu, prescaler %u\n",
145 rate, prescaler[k - 1]);
148 r_tpu_write(p,
TCR, 0x0040 | (k - 1));
151 r_tpu_write(p,
TIOR, 0x0002);
154 r_tpu_write(p,
TGRB, rate);
162 r_tpu_write(p,
TMDR, 0x0002);
165 r_tpu_start_stop_ch(p, 1);
171 pm_runtime_put_sync(&p->
pdev->dev);
175 static void r_tpu_disable(
struct r_tpu_priv *p)
181 r_tpu_start_stop_ch(p, 0);
185 pm_runtime_put_sync(&p->
pdev->dev);
225 if ((brightness == 0) || (brightness == p->
ldev.max_brightness))
229 r_tpu_enable(p, brightness);
249 dev_err(&pdev->
dev,
"missing platform data\n");
255 dev_err(&pdev->
dev,
"failed to allocate driver data\n");
261 dev_err(&pdev->
dev,
"failed to get I/O memory\n");
268 dev_err(&pdev->
dev,
"failed to remap I/O memory\n");
274 if (IS_ERR(p->
clk)) {
276 ret = PTR_ERR(p->
clk);
285 platform_set_drvdata(pdev, p);
292 p->
ldev.brightness_set = r_tpu_set_brightness;
314 struct r_tpu_priv *p = platform_get_drvdata(pdev);
322 pm_runtime_disable(&pdev->
dev);
330 .probe = r_tpu_probe,
333 .name =
"leds-renesas-tpu",