22 #include <linux/module.h>
26 #include <linux/sched.h>
27 #include <linux/wait.h>
30 #include <plat/clock.h>
37 #define LIRC_RX51_DRIVER_FEATURES (LIRC_CAN_SET_SEND_DUTY_CYCLE | \
38 LIRC_CAN_SET_SEND_CARRIER | \
41 #define DRIVER_NAME "lirc_rx51"
45 #define TIMER_MAX_VALUE 0xffffffff
82 match = -(lirc_rx51->
duty_cycle * -load / 100);
95 #define tics_after(a, b) ((long)(b) - (long)(a) < 0)
103 if (lirc_rx51->
match == 0)
106 counter = lirc_rx51->
match;
108 counter += (
u32)(lirc_rx51->
fclk_khz * usec / (1000));
119 static irqreturn_t lirc_rx51_interrupt_handler(
int irq,
void *
ptr)
130 ": Unexpected interrupt source: %x\n", retval);
138 ": BUG wbuf_index has value of %i\n",
154 lirc_rx51_off(lirc_rx51);
156 lirc_rx51_on(lirc_rx51);
158 retval = pulse_timer_set_timeout(lirc_rx51,
167 lirc_rx51_off(lirc_rx51);
177 static int lirc_rx51_init_port(
struct lirc_rx51 *lirc_rx51)
179 struct clk *clk_fclk;
184 dev_err(lirc_rx51->
dev,
": Error requesting GPT%d timer\n",
191 dev_err(lirc_rx51->
dev,
": Error requesting pulse timer\n");
206 "lirc_pulse_timer", lirc_rx51);
208 dev_err(lirc_rx51->
dev,
": Failed to request interrupt line\n");
225 static int lirc_rx51_free_port(
struct lirc_rx51 *lirc_rx51)
229 lirc_rx51_off(lirc_rx51);
240 size_t n, loff_t *ppos)
248 count = n /
sizeof(
int);
249 if ((count >
WBUF_LEN) || (count % 2 == 0))
259 for (i = 0; i <
count; i++)
260 if (lirc_rx51->
wbuf[i] < 0)
263 init_timing_params(lirc_rx51);
271 lirc_rx51->
pdata->set_max_mpu_wakeup_lat(lirc_rx51->
dev, 50);
273 lirc_rx51_on(lirc_rx51);
275 pulse_timer_set_timeout(lirc_rx51, lirc_rx51->
wbuf[0]);
284 lirc_rx51->
pdata->set_max_mpu_wakeup_lat(lirc_rx51->
dev, -1);
289 static long lirc_rx51_ioctl(
struct file *filep,
290 unsigned int cmd,
unsigned long arg)
305 result =
get_user(value, (
unsigned long *)arg);
315 result =
put_user(0, (
unsigned long *) arg);
325 result =
get_user(ivalue, (
unsigned int *) arg);
329 if (ivalue <= 0 || ivalue > 100) {
330 dev_err(lirc_rx51->
dev,
": invalid duty cycle %d\n",
339 result =
get_user(ivalue, (
unsigned int *) arg);
343 if (ivalue > 500000 || ivalue < 20000) {
344 dev_err(lirc_rx51->
dev,
": invalid carrier freq %d\n",
349 lirc_rx51->
freq = ivalue;
354 (
unsigned long *) arg);
366 static int lirc_rx51_open(
struct inode *
inode,
struct file *file)
376 return lirc_rx51_init_port(lirc_rx51);
379 static int lirc_rx51_release(
struct inode *inode,
struct file *file)
383 lirc_rx51_free_port(lirc_rx51);
390 static struct lirc_rx51 lirc_rx51 = {
398 .write = lirc_rx51_write,
399 .unlocked_ioctl = lirc_rx51_ioctl,
402 .open = lirc_rx51_open,
403 .release = lirc_rx51_release,
442 #define lirc_rx51_suspend NULL
443 #define lirc_rx51_resume NULL
450 lirc_rx51.
pdata = dev->
dev.platform_data;
452 lirc_rx51.
dev = &dev->
dev;
453 lirc_rx51_driver.
dev = &dev->
dev;
457 if (lirc_rx51_driver.
minor < 0) {
458 dev_err(lirc_rx51.
dev,
": lirc_register_driver failed: %d\n",
459 lirc_rx51_driver.
minor);
460 return lirc_rx51_driver.
minor;
462 dev_info(lirc_rx51.
dev,
"registration ok, minor: %d, pwm: %d\n",
474 .probe = lirc_rx51_probe,
475 .remove =
__exit_p(lirc_rx51_remove),
484 static int __init lirc_rx51_init(
void)
490 static void __exit lirc_rx51_exit(
void)