H A D | ir-rx51.c | 40 #define DRIVER_NAME "lirc_rx51" 46 struct lirc_rx51 { struct 64 static void lirc_rx51_on(struct lirc_rx51 *lirc_rx51) lirc_rx51_on() argument 66 omap_dm_timer_set_pwm(lirc_rx51->pwm_timer, 0, 1, lirc_rx51_on() 70 static void lirc_rx51_off(struct lirc_rx51 *lirc_rx51) lirc_rx51_off() argument 72 omap_dm_timer_set_pwm(lirc_rx51->pwm_timer, 0, 1, lirc_rx51_off() 76 static int init_timing_params(struct lirc_rx51 *lirc_rx51) init_timing_params() argument 80 load = -(lirc_rx51->fclk_khz * 1000 / lirc_rx51->freq); init_timing_params() 81 match = -(lirc_rx51->duty_cycle * -load / 100); init_timing_params() 82 omap_dm_timer_set_load(lirc_rx51->pwm_timer, 1, load); init_timing_params() 83 omap_dm_timer_set_match(lirc_rx51->pwm_timer, 1, match); init_timing_params() 84 omap_dm_timer_write_counter(lirc_rx51->pwm_timer, TIMER_MAX_VALUE - 2); init_timing_params() 85 omap_dm_timer_start(lirc_rx51->pwm_timer); init_timing_params() 86 omap_dm_timer_set_int_enable(lirc_rx51->pulse_timer, 0); init_timing_params() 87 omap_dm_timer_start(lirc_rx51->pulse_timer); init_timing_params() 89 lirc_rx51->match = 0; init_timing_params() 96 static int pulse_timer_set_timeout(struct lirc_rx51 *lirc_rx51, int usec) pulse_timer_set_timeout() argument 102 if (lirc_rx51->match == 0) pulse_timer_set_timeout() 103 counter = omap_dm_timer_read_counter(lirc_rx51->pulse_timer); pulse_timer_set_timeout() 105 counter = lirc_rx51->match; pulse_timer_set_timeout() 107 counter += (u32)(lirc_rx51->fclk_khz * usec / (1000)); pulse_timer_set_timeout() 108 omap_dm_timer_set_match(lirc_rx51->pulse_timer, 1, counter); pulse_timer_set_timeout() 109 omap_dm_timer_set_int_enable(lirc_rx51->pulse_timer, pulse_timer_set_timeout() 111 if (tics_after(omap_dm_timer_read_counter(lirc_rx51->pulse_timer), pulse_timer_set_timeout() 121 struct lirc_rx51 *lirc_rx51 = ptr; lirc_rx51_interrupt_handler() local 123 retval = omap_dm_timer_read_status(lirc_rx51->pulse_timer); lirc_rx51_interrupt_handler() 128 dev_err_ratelimited(lirc_rx51->dev, lirc_rx51_interrupt_handler() 131 omap_dm_timer_write_status(lirc_rx51->pulse_timer, lirc_rx51_interrupt_handler() 135 if (lirc_rx51->wbuf_index < 0) { lirc_rx51_interrupt_handler() 136 dev_err_ratelimited(lirc_rx51->dev, lirc_rx51_interrupt_handler() 138 lirc_rx51->wbuf_index); lirc_rx51_interrupt_handler() 147 if (lirc_rx51->wbuf_index >= WBUF_LEN) lirc_rx51_interrupt_handler() 149 if (lirc_rx51->wbuf[lirc_rx51->wbuf_index] == -1) lirc_rx51_interrupt_handler() 152 if (lirc_rx51->wbuf_index % 2) lirc_rx51_interrupt_handler() 153 lirc_rx51_off(lirc_rx51); lirc_rx51_interrupt_handler() 155 lirc_rx51_on(lirc_rx51); lirc_rx51_interrupt_handler() 157 retval = pulse_timer_set_timeout(lirc_rx51, lirc_rx51_interrupt_handler() 158 lirc_rx51->wbuf[lirc_rx51->wbuf_index]); lirc_rx51_interrupt_handler() 159 lirc_rx51->wbuf_index++; lirc_rx51_interrupt_handler() 166 lirc_rx51_off(lirc_rx51); lirc_rx51_interrupt_handler() 167 lirc_rx51->wbuf_index = -1; lirc_rx51_interrupt_handler() 168 omap_dm_timer_stop(lirc_rx51->pwm_timer); lirc_rx51_interrupt_handler() 169 omap_dm_timer_stop(lirc_rx51->pulse_timer); lirc_rx51_interrupt_handler() 170 omap_dm_timer_set_int_enable(lirc_rx51->pulse_timer, 0); lirc_rx51_interrupt_handler() 171 wake_up_interruptible(&lirc_rx51->wqueue); lirc_rx51_interrupt_handler() 176 static int lirc_rx51_init_port(struct lirc_rx51 *lirc_rx51) lirc_rx51_init_port() argument 179 int retval, pwm_timer = lirc_rx51->pwm_timer_num; lirc_rx51_init_port() 181 lirc_rx51->pwm_timer = omap_dm_timer_request_specific(pwm_timer); lirc_rx51_init_port() 182 if (lirc_rx51->pwm_timer == NULL) { lirc_rx51_init_port() 183 dev_err(lirc_rx51->dev, ": Error requesting GPT%d timer\n", lirc_rx51_init_port() 188 lirc_rx51->pulse_timer = omap_dm_timer_request(); lirc_rx51_init_port() 189 if (lirc_rx51->pulse_timer == NULL) { lirc_rx51_init_port() 190 dev_err(lirc_rx51->dev, ": Error requesting pulse timer\n"); lirc_rx51_init_port() 195 omap_dm_timer_set_source(lirc_rx51->pwm_timer, OMAP_TIMER_SRC_SYS_CLK); lirc_rx51_init_port() 196 omap_dm_timer_set_source(lirc_rx51->pulse_timer, lirc_rx51_init_port() 199 omap_dm_timer_enable(lirc_rx51->pwm_timer); lirc_rx51_init_port() 200 omap_dm_timer_enable(lirc_rx51->pulse_timer); lirc_rx51_init_port() 202 lirc_rx51->irq_num = omap_dm_timer_get_irq(lirc_rx51->pulse_timer); lirc_rx51_init_port() 203 retval = request_irq(lirc_rx51->irq_num, lirc_rx51_interrupt_handler, lirc_rx51_init_port() 204 IRQF_SHARED, "lirc_pulse_timer", lirc_rx51); lirc_rx51_init_port() 206 dev_err(lirc_rx51->dev, ": Failed to request interrupt line\n"); lirc_rx51_init_port() 210 clk_fclk = omap_dm_timer_get_fclk(lirc_rx51->pwm_timer); lirc_rx51_init_port() 211 lirc_rx51->fclk_khz = clk_fclk->rate / 1000; lirc_rx51_init_port() 216 omap_dm_timer_free(lirc_rx51->pulse_timer); lirc_rx51_init_port() 218 omap_dm_timer_free(lirc_rx51->pwm_timer); lirc_rx51_init_port() 223 static int lirc_rx51_free_port(struct lirc_rx51 *lirc_rx51) lirc_rx51_free_port() argument 225 omap_dm_timer_set_int_enable(lirc_rx51->pulse_timer, 0); lirc_rx51_free_port() 226 free_irq(lirc_rx51->irq_num, lirc_rx51); lirc_rx51_free_port() 227 lirc_rx51_off(lirc_rx51); lirc_rx51_free_port() 228 omap_dm_timer_disable(lirc_rx51->pwm_timer); lirc_rx51_free_port() 229 omap_dm_timer_disable(lirc_rx51->pulse_timer); lirc_rx51_free_port() 230 omap_dm_timer_free(lirc_rx51->pwm_timer); lirc_rx51_free_port() 231 omap_dm_timer_free(lirc_rx51->pulse_timer); lirc_rx51_free_port() 232 lirc_rx51->wbuf_index = -1; lirc_rx51_free_port() 241 struct lirc_rx51 *lirc_rx51 = file->private_data; lirc_rx51_write() local 251 wait_event_interruptible(lirc_rx51->wqueue, lirc_rx51->wbuf_index < 0); lirc_rx51_write() 253 if (copy_from_user(lirc_rx51->wbuf, buf, n)) lirc_rx51_write() 258 if (lirc_rx51->wbuf[i] < 0) lirc_rx51_write() 261 init_timing_params(lirc_rx51); lirc_rx51_write() 263 lirc_rx51->wbuf[count] = -1; /* Insert termination mark */ lirc_rx51_write() 269 lirc_rx51->pdata->set_max_mpu_wakeup_lat(lirc_rx51->dev, 50); lirc_rx51_write() 271 lirc_rx51_on(lirc_rx51); lirc_rx51_write() 272 lirc_rx51->wbuf_index = 1; lirc_rx51_write() 273 pulse_timer_set_timeout(lirc_rx51, lirc_rx51->wbuf[0]); lirc_rx51_write() 279 wait_event_interruptible(lirc_rx51->wqueue, lirc_rx51->wbuf_index < 0); lirc_rx51_write() 282 lirc_rx51->pdata->set_max_mpu_wakeup_lat(lirc_rx51->dev, -1); lirc_rx51_write() 293 struct lirc_rx51 *lirc_rx51 = filep->private_data; lirc_rx51_ioctl() local 328 dev_err(lirc_rx51->dev, ": invalid duty cycle %d\n", lirc_rx51_ioctl() 333 lirc_rx51->duty_cycle = ivalue; lirc_rx51_ioctl() 342 dev_err(lirc_rx51->dev, ": invalid carrier freq %d\n", lirc_rx51_ioctl() 347 lirc_rx51->freq = ivalue; lirc_rx51_ioctl() 366 struct lirc_rx51 *lirc_rx51 = lirc_get_pdata(file); lirc_rx51_open() local 367 BUG_ON(!lirc_rx51); lirc_rx51_open() 369 file->private_data = lirc_rx51; lirc_rx51_open() 371 if (test_and_set_bit(1, &lirc_rx51->device_is_open)) lirc_rx51_open() 374 return lirc_rx51_init_port(lirc_rx51); lirc_rx51_open() 379 struct lirc_rx51 *lirc_rx51 = file->private_data; lirc_rx51_release() local 381 lirc_rx51_free_port(lirc_rx51); lirc_rx51_release() 383 clear_bit(1, &lirc_rx51->device_is_open); lirc_rx51_release() 388 static struct lirc_rx51 lirc_rx51 = { variable in typeref:struct:lirc_rx51 408 .data = &lirc_rx51, 425 if (test_and_set_bit(1, &lirc_rx51.device_is_open)) lirc_rx51_suspend() 428 clear_bit(1, &lirc_rx51.device_is_open); lirc_rx51_suspend() 448 lirc_rx51.pdata = dev->dev.platform_data; lirc_rx51_probe() 449 lirc_rx51.pwm_timer_num = lirc_rx51.pdata->pwm_timer; lirc_rx51_probe() 450 lirc_rx51.dev = &dev->dev; lirc_rx51_probe() 453 init_waitqueue_head(&lirc_rx51.wqueue); lirc_rx51_probe() 456 dev_err(lirc_rx51.dev, ": lirc_register_driver failed: %d\n", lirc_rx51_probe() 460 dev_info(lirc_rx51.dev, "registration ok, minor: %d, pwm: %d\n", lirc_rx51_probe() 461 lirc_rx51_driver.minor, lirc_rx51.pwm_timer_num); lirc_rx51_probe()
|