Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] ir-rx51: port to rc-core

This driver was written using lirc since rc-core did not support
transmitter-only hardware at that time. Now that it does, port
this driver.

Compile tested only.

Signed-off-by: Sean Young <sean@mess.org>
Cc: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Cc: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

authored by

Sean Young and committed by
Mauro Carvalho Chehab
a92def1b fe052da4

+128 -224
+4 -4
arch/arm/mach-omap2/pdata-quirks.c
··· 484 484 }; 485 485 #endif 486 486 487 - static struct lirc_rx51_platform_data __maybe_unused rx51_lirc_data = { 487 + static struct ir_rx51_platform_data __maybe_unused rx51_ir_data = { 488 488 .set_max_mpu_wakeup_lat = omap_pm_set_max_mpu_wakeup_lat, 489 489 }; 490 490 491 - static struct platform_device __maybe_unused rx51_lirc_device = { 492 - .name = "lirc_rx51", 491 + static struct platform_device __maybe_unused rx51_ir_device = { 492 + .name = "ir_rx51", 493 493 .id = -1, 494 494 .dev = { 495 - .platform_data = &rx51_lirc_data, 495 + .platform_data = &rx51_ir_data, 496 496 }, 497 497 }; 498 498
+1 -1
drivers/media/rc/Kconfig
··· 345 345 346 346 config IR_RX51 347 347 tristate "Nokia N900 IR transmitter diode" 348 - depends on OMAP_DM_TIMER && PWM_OMAP_DMTIMER && ARCH_OMAP2PLUS && LIRC 348 + depends on (OMAP_DM_TIMER && PWM_OMAP_DMTIMER && ARCH_OMAP2PLUS || COMPILE_TEST) && RC_CORE 349 349 ---help--- 350 350 Say Y or M here if you want to enable support for the IR 351 351 transmitter diode built in the Nokia N900 (RX51) device.
+120 -216
drivers/media/rc/ir-rx51.c
··· 15 15 */ 16 16 #include <linux/clk.h> 17 17 #include <linux/module.h> 18 - #include <linux/interrupt.h> 19 - #include <linux/uaccess.h> 20 18 #include <linux/platform_device.h> 21 - #include <linux/sched.h> 22 19 #include <linux/wait.h> 23 20 #include <linux/pwm.h> 24 21 #include <linux/of.h> 25 22 #include <linux/hrtimer.h> 26 23 27 - #include <media/lirc.h> 28 - #include <media/lirc_dev.h> 24 + #include <media/rc-core.h> 29 25 #include <linux/platform_data/media/ir-rx51.h> 30 - 31 - #define LIRC_RX51_DRIVER_FEATURES (LIRC_CAN_SET_SEND_DUTY_CYCLE | \ 32 - LIRC_CAN_SET_SEND_CARRIER | \ 33 - LIRC_CAN_SEND_PULSE) 34 - 35 - #define DRIVER_NAME "lirc_rx51" 36 26 37 27 #define WBUF_LEN 256 38 28 39 - struct lirc_rx51 { 29 + struct ir_rx51 { 30 + struct rc_dev *rcdev; 40 31 struct pwm_device *pwm; 41 32 struct hrtimer timer; 42 33 struct device *dev; 43 - struct lirc_rx51_platform_data *pdata; 34 + struct ir_rx51_platform_data *pdata; 44 35 wait_queue_head_t wqueue; 45 36 46 37 unsigned int freq; /* carrier frequency */ ··· 41 50 unsigned long device_is_open; 42 51 }; 43 52 44 - static inline void lirc_rx51_on(struct lirc_rx51 *lirc_rx51) 53 + static inline void ir_rx51_on(struct ir_rx51 *ir_rx51) 45 54 { 46 - pwm_enable(lirc_rx51->pwm); 55 + pwm_enable(ir_rx51->pwm); 47 56 } 48 57 49 - static inline void lirc_rx51_off(struct lirc_rx51 *lirc_rx51) 58 + static inline void ir_rx51_off(struct ir_rx51 *ir_rx51) 50 59 { 51 - pwm_disable(lirc_rx51->pwm); 60 + pwm_disable(ir_rx51->pwm); 52 61 } 53 62 54 - static int init_timing_params(struct lirc_rx51 *lirc_rx51) 63 + static int init_timing_params(struct ir_rx51 *ir_rx51) 55 64 { 56 - struct pwm_device *pwm = lirc_rx51->pwm; 57 - int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, lirc_rx51->freq); 65 + struct pwm_device *pwm = ir_rx51->pwm; 66 + int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq); 58 67 59 - duty = DIV_ROUND_CLOSEST(lirc_rx51->duty_cycle * period, 100); 68 + duty = DIV_ROUND_CLOSEST(ir_rx51->duty_cycle * period, 100); 60 69 61 70 pwm_config(pwm, duty, period); 62 71 63 72 return 0; 64 73 } 65 74 66 - static enum hrtimer_restart lirc_rx51_timer_cb(struct hrtimer *timer) 75 + static enum hrtimer_restart ir_rx51_timer_cb(struct hrtimer *timer) 67 76 { 68 - struct lirc_rx51 *lirc_rx51 = 69 - container_of(timer, struct lirc_rx51, timer); 77 + struct ir_rx51 *ir_rx51 = container_of(timer, struct ir_rx51, timer); 70 78 ktime_t now; 71 79 72 - if (lirc_rx51->wbuf_index < 0) { 73 - dev_err_ratelimited(lirc_rx51->dev, 74 - "BUG wbuf_index has value of %i\n", 75 - lirc_rx51->wbuf_index); 80 + if (ir_rx51->wbuf_index < 0) { 81 + dev_err_ratelimited(ir_rx51->dev, 82 + "BUG wbuf_index has value of %i\n", 83 + ir_rx51->wbuf_index); 76 84 goto end; 77 85 } 78 86 ··· 82 92 do { 83 93 u64 ns; 84 94 85 - if (lirc_rx51->wbuf_index >= WBUF_LEN) 95 + if (ir_rx51->wbuf_index >= WBUF_LEN) 86 96 goto end; 87 - if (lirc_rx51->wbuf[lirc_rx51->wbuf_index] == -1) 97 + if (ir_rx51->wbuf[ir_rx51->wbuf_index] == -1) 88 98 goto end; 89 99 90 - if (lirc_rx51->wbuf_index % 2) 91 - lirc_rx51_off(lirc_rx51); 100 + if (ir_rx51->wbuf_index % 2) 101 + ir_rx51_off(ir_rx51); 92 102 else 93 - lirc_rx51_on(lirc_rx51); 103 + ir_rx51_on(ir_rx51); 94 104 95 - ns = 1000 * lirc_rx51->wbuf[lirc_rx51->wbuf_index]; 105 + ns = US_TO_NS(ir_rx51->wbuf[ir_rx51->wbuf_index]); 96 106 hrtimer_add_expires_ns(timer, ns); 97 107 98 - lirc_rx51->wbuf_index++; 108 + ir_rx51->wbuf_index++; 99 109 100 110 now = timer->base->get_time(); 101 111 ··· 104 114 return HRTIMER_RESTART; 105 115 end: 106 116 /* Stop TX here */ 107 - lirc_rx51_off(lirc_rx51); 108 - lirc_rx51->wbuf_index = -1; 117 + ir_rx51_off(ir_rx51); 118 + ir_rx51->wbuf_index = -1; 109 119 110 - wake_up_interruptible(&lirc_rx51->wqueue); 120 + wake_up_interruptible(&ir_rx51->wqueue); 111 121 112 122 return HRTIMER_NORESTART; 113 123 } 114 124 115 - static ssize_t lirc_rx51_write(struct file *file, const char *buf, 116 - size_t n, loff_t *ppos) 125 + static int ir_rx51_tx(struct rc_dev *dev, unsigned int *buffer, 126 + unsigned int count) 117 127 { 118 - int count, i; 119 - struct lirc_rx51 *lirc_rx51 = file->private_data; 128 + struct ir_rx51 *ir_rx51 = dev->priv; 120 129 121 - if (n % sizeof(int)) 130 + if (count > WBUF_LEN) 122 131 return -EINVAL; 123 132 124 - count = n / sizeof(int); 125 - if ((count > WBUF_LEN) || (count % 2 == 0)) 126 - return -EINVAL; 133 + memcpy(ir_rx51->wbuf, buffer, count * sizeof(unsigned int)); 127 134 128 135 /* Wait any pending transfers to finish */ 129 - wait_event_interruptible(lirc_rx51->wqueue, lirc_rx51->wbuf_index < 0); 136 + wait_event_interruptible(ir_rx51->wqueue, ir_rx51->wbuf_index < 0); 130 137 131 - if (copy_from_user(lirc_rx51->wbuf, buf, n)) 132 - return -EFAULT; 133 - 134 - /* Sanity check the input pulses */ 135 - for (i = 0; i < count; i++) 136 - if (lirc_rx51->wbuf[i] < 0) 137 - return -EINVAL; 138 - 139 - init_timing_params(lirc_rx51); 138 + init_timing_params(ir_rx51); 140 139 if (count < WBUF_LEN) 141 - lirc_rx51->wbuf[count] = -1; /* Insert termination mark */ 140 + ir_rx51->wbuf[count] = -1; /* Insert termination mark */ 142 141 143 142 /* 144 143 * Adjust latency requirements so the device doesn't go in too 145 144 * deep sleep states 146 145 */ 147 - lirc_rx51->pdata->set_max_mpu_wakeup_lat(lirc_rx51->dev, 50); 146 + ir_rx51->pdata->set_max_mpu_wakeup_lat(ir_rx51->dev, 50); 148 147 149 - lirc_rx51_on(lirc_rx51); 150 - lirc_rx51->wbuf_index = 1; 151 - hrtimer_start(&lirc_rx51->timer, 152 - ns_to_ktime(1000 * lirc_rx51->wbuf[0]), 148 + ir_rx51_on(ir_rx51); 149 + ir_rx51->wbuf_index = 1; 150 + hrtimer_start(&ir_rx51->timer, 151 + ns_to_ktime(US_TO_NS(ir_rx51->wbuf[0])), 153 152 HRTIMER_MODE_REL); 154 153 /* 155 154 * Don't return back to the userspace until the transfer has 156 155 * finished 157 156 */ 158 - wait_event_interruptible(lirc_rx51->wqueue, lirc_rx51->wbuf_index < 0); 157 + wait_event_interruptible(ir_rx51->wqueue, ir_rx51->wbuf_index < 0); 159 158 160 159 /* We can sleep again */ 161 - lirc_rx51->pdata->set_max_mpu_wakeup_lat(lirc_rx51->dev, -1); 160 + ir_rx51->pdata->set_max_mpu_wakeup_lat(ir_rx51->dev, -1); 162 161 163 - return n; 162 + return count; 164 163 } 165 164 166 - static long lirc_rx51_ioctl(struct file *filep, 167 - unsigned int cmd, unsigned long arg) 165 + static int ir_rx51_open(struct rc_dev *dev) 168 166 { 169 - int result; 170 - unsigned long value; 171 - unsigned int ivalue; 172 - struct lirc_rx51 *lirc_rx51 = filep->private_data; 167 + struct ir_rx51 *ir_rx51 = dev->priv; 173 168 174 - switch (cmd) { 175 - case LIRC_GET_SEND_MODE: 176 - result = put_user(LIRC_MODE_PULSE, (unsigned long *)arg); 177 - if (result) 178 - return result; 179 - break; 180 - 181 - case LIRC_SET_SEND_MODE: 182 - result = get_user(value, (unsigned long *)arg); 183 - if (result) 184 - return result; 185 - 186 - /* only LIRC_MODE_PULSE supported */ 187 - if (value != LIRC_MODE_PULSE) 188 - return -ENOSYS; 189 - break; 190 - 191 - case LIRC_GET_REC_MODE: 192 - result = put_user(0, (unsigned long *) arg); 193 - if (result) 194 - return result; 195 - break; 196 - 197 - case LIRC_GET_LENGTH: 198 - return -ENOSYS; 199 - break; 200 - 201 - case LIRC_SET_SEND_DUTY_CYCLE: 202 - result = get_user(ivalue, (unsigned int *) arg); 203 - if (result) 204 - return result; 205 - 206 - if (ivalue <= 0 || ivalue > 100) { 207 - dev_err(lirc_rx51->dev, ": invalid duty cycle %d\n", 208 - ivalue); 209 - return -EINVAL; 210 - } 211 - 212 - lirc_rx51->duty_cycle = ivalue; 213 - break; 214 - 215 - case LIRC_SET_SEND_CARRIER: 216 - result = get_user(ivalue, (unsigned int *) arg); 217 - if (result) 218 - return result; 219 - 220 - if (ivalue > 500000 || ivalue < 20000) { 221 - dev_err(lirc_rx51->dev, ": invalid carrier freq %d\n", 222 - ivalue); 223 - return -EINVAL; 224 - } 225 - 226 - lirc_rx51->freq = ivalue; 227 - break; 228 - 229 - case LIRC_GET_FEATURES: 230 - result = put_user(LIRC_RX51_DRIVER_FEATURES, 231 - (unsigned long *) arg); 232 - if (result) 233 - return result; 234 - break; 235 - 236 - default: 237 - return -ENOIOCTLCMD; 238 - } 239 - 240 - return 0; 241 - } 242 - 243 - static int lirc_rx51_open(struct inode *inode, struct file *file) 244 - { 245 - struct lirc_rx51 *lirc_rx51 = lirc_get_pdata(file); 246 - BUG_ON(!lirc_rx51); 247 - 248 - file->private_data = lirc_rx51; 249 - 250 - if (test_and_set_bit(1, &lirc_rx51->device_is_open)) 169 + if (test_and_set_bit(1, &ir_rx51->device_is_open)) 251 170 return -EBUSY; 252 171 253 - lirc_rx51->pwm = pwm_get(lirc_rx51->dev, NULL); 254 - if (IS_ERR(lirc_rx51->pwm)) { 255 - int res = PTR_ERR(lirc_rx51->pwm); 172 + ir_rx51->pwm = pwm_get(ir_rx51->dev, NULL); 173 + if (IS_ERR(ir_rx51->pwm)) { 174 + int res = PTR_ERR(ir_rx51->pwm); 256 175 257 - dev_err(lirc_rx51->dev, "pwm_get failed: %d\n", res); 176 + dev_err(ir_rx51->dev, "pwm_get failed: %d\n", res); 258 177 return res; 259 178 } 260 179 261 180 return 0; 262 181 } 263 182 264 - static int lirc_rx51_release(struct inode *inode, struct file *file) 183 + static void ir_rx51_release(struct rc_dev *dev) 265 184 { 266 - struct lirc_rx51 *lirc_rx51 = file->private_data; 185 + struct ir_rx51 *ir_rx51 = dev->priv; 267 186 268 - hrtimer_cancel(&lirc_rx51->timer); 269 - lirc_rx51_off(lirc_rx51); 270 - pwm_put(lirc_rx51->pwm); 187 + hrtimer_cancel(&ir_rx51->timer); 188 + ir_rx51_off(ir_rx51); 189 + pwm_put(ir_rx51->pwm); 271 190 272 - clear_bit(1, &lirc_rx51->device_is_open); 273 - 274 - return 0; 191 + clear_bit(1, &ir_rx51->device_is_open); 275 192 } 276 193 277 - static struct lirc_rx51 lirc_rx51 = { 194 + static struct ir_rx51 ir_rx51 = { 278 195 .duty_cycle = 50, 279 196 .wbuf_index = -1, 280 197 }; 281 198 282 - static const struct file_operations lirc_fops = { 283 - .owner = THIS_MODULE, 284 - .write = lirc_rx51_write, 285 - .unlocked_ioctl = lirc_rx51_ioctl, 286 - .read = lirc_dev_fop_read, 287 - .poll = lirc_dev_fop_poll, 288 - .open = lirc_rx51_open, 289 - .release = lirc_rx51_release, 290 - }; 199 + static int ir_rx51_set_duty_cycle(struct rc_dev *dev, u32 duty) 200 + { 201 + struct ir_rx51 *ir_rx51 = dev->priv; 291 202 292 - static struct lirc_driver lirc_rx51_driver = { 293 - .name = DRIVER_NAME, 294 - .minor = -1, 295 - .code_length = 1, 296 - .data = &lirc_rx51, 297 - .fops = &lirc_fops, 298 - .owner = THIS_MODULE, 299 - }; 203 + ir_rx51->duty_cycle = duty; 204 + 205 + return 0; 206 + } 207 + 208 + static int ir_rx51_set_tx_carrier(struct rc_dev *dev, u32 carrier) 209 + { 210 + struct ir_rx51 *ir_rx51 = dev->priv; 211 + 212 + if (carrier > 500000 || carrier < 20000) 213 + return -EINVAL; 214 + 215 + ir_rx51->freq = carrier; 216 + 217 + return 0; 218 + } 300 219 301 220 #ifdef CONFIG_PM 302 221 303 - static int lirc_rx51_suspend(struct platform_device *dev, pm_message_t state) 222 + static int ir_rx51_suspend(struct platform_device *dev, pm_message_t state) 304 223 { 305 224 /* 306 225 * In case the device is still open, do not suspend. Normally ··· 219 320 * were in a middle of a transmit. Thus, we defer any suspend 220 321 * actions until transmit has completed. 221 322 */ 222 - if (test_and_set_bit(1, &lirc_rx51.device_is_open)) 323 + if (test_and_set_bit(1, &ir_rx51.device_is_open)) 223 324 return -EAGAIN; 224 325 225 - clear_bit(1, &lirc_rx51.device_is_open); 326 + clear_bit(1, &ir_rx51.device_is_open); 226 327 227 328 return 0; 228 329 } 229 330 230 - static int lirc_rx51_resume(struct platform_device *dev) 331 + static int ir_rx51_resume(struct platform_device *dev) 231 332 { 232 333 return 0; 233 334 } 234 335 235 336 #else 236 337 237 - #define lirc_rx51_suspend NULL 238 - #define lirc_rx51_resume NULL 338 + #define ir_rx51_suspend NULL 339 + #define ir_rx51_resume NULL 239 340 240 341 #endif /* CONFIG_PM */ 241 342 242 - static int lirc_rx51_probe(struct platform_device *dev) 343 + static int ir_rx51_probe(struct platform_device *dev) 243 344 { 244 345 struct pwm_device *pwm; 346 + struct rc_dev *rcdev; 245 347 246 - lirc_rx51_driver.features = LIRC_RX51_DRIVER_FEATURES; 247 - lirc_rx51.pdata = dev->dev.platform_data; 348 + ir_rx51.pdata = dev->dev.platform_data; 248 349 249 - if (!lirc_rx51.pdata) { 350 + if (!ir_rx51.pdata) { 250 351 dev_err(&dev->dev, "Platform Data is missing\n"); 251 352 return -ENXIO; 252 353 } ··· 261 362 } 262 363 263 364 /* Use default, in case userspace does not set the carrier */ 264 - lirc_rx51.freq = DIV_ROUND_CLOSEST(pwm_get_period(pwm), NSEC_PER_SEC); 365 + ir_rx51.freq = DIV_ROUND_CLOSEST(pwm_get_period(pwm), NSEC_PER_SEC); 265 366 pwm_put(pwm); 266 367 267 - hrtimer_init(&lirc_rx51.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 268 - lirc_rx51.timer.function = lirc_rx51_timer_cb; 368 + hrtimer_init(&ir_rx51.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 369 + ir_rx51.timer.function = ir_rx51_timer_cb; 269 370 270 - lirc_rx51.dev = &dev->dev; 271 - lirc_rx51_driver.dev = &dev->dev; 272 - lirc_rx51_driver.minor = lirc_register_driver(&lirc_rx51_driver); 273 - init_waitqueue_head(&lirc_rx51.wqueue); 371 + ir_rx51.dev = &dev->dev; 274 372 275 - if (lirc_rx51_driver.minor < 0) { 276 - dev_err(lirc_rx51.dev, ": lirc_register_driver failed: %d\n", 277 - lirc_rx51_driver.minor); 278 - return lirc_rx51_driver.minor; 279 - } 373 + rcdev = devm_rc_allocate_device(&dev->dev, RC_DRIVER_IR_RAW_TX); 374 + if (!rcdev) 375 + return -ENOMEM; 280 376 377 + rcdev->priv = &ir_rx51; 378 + rcdev->open = ir_rx51_open; 379 + rcdev->close = ir_rx51_release; 380 + rcdev->tx_ir = ir_rx51_tx; 381 + rcdev->s_tx_duty_cycle = ir_rx51_set_duty_cycle; 382 + rcdev->s_tx_carrier = ir_rx51_set_tx_carrier; 383 + rcdev->driver_name = KBUILD_MODNAME; 384 + 385 + ir_rx51.rcdev = rcdev; 386 + 387 + return devm_rc_register_device(&dev->dev, ir_rx51.rcdev); 388 + } 389 + 390 + static int ir_rx51_remove(struct platform_device *dev) 391 + { 281 392 return 0; 282 393 } 283 394 284 - static int lirc_rx51_remove(struct platform_device *dev) 285 - { 286 - return lirc_unregister_driver(lirc_rx51_driver.minor); 287 - } 288 - 289 - static const struct of_device_id lirc_rx51_match[] = { 395 + static const struct of_device_id ir_rx51_match[] = { 290 396 { 291 397 .compatible = "nokia,n900-ir", 292 398 }, 293 399 {}, 294 400 }; 295 - MODULE_DEVICE_TABLE(of, lirc_rx51_match); 401 + MODULE_DEVICE_TABLE(of, ir_rx51_match); 296 402 297 - struct platform_driver lirc_rx51_platform_driver = { 298 - .probe = lirc_rx51_probe, 299 - .remove = lirc_rx51_remove, 300 - .suspend = lirc_rx51_suspend, 301 - .resume = lirc_rx51_resume, 403 + static struct platform_driver ir_rx51_platform_driver = { 404 + .probe = ir_rx51_probe, 405 + .remove = ir_rx51_remove, 406 + .suspend = ir_rx51_suspend, 407 + .resume = ir_rx51_resume, 302 408 .driver = { 303 - .name = DRIVER_NAME, 304 - .of_match_table = of_match_ptr(lirc_rx51_match), 409 + .name = KBUILD_MODNAME, 410 + .of_match_table = of_match_ptr(ir_rx51_match), 305 411 }, 306 412 }; 307 - module_platform_driver(lirc_rx51_platform_driver); 413 + module_platform_driver(ir_rx51_platform_driver); 308 414 309 - MODULE_DESCRIPTION("LIRC TX driver for Nokia RX51"); 415 + MODULE_DESCRIPTION("IR TX driver for Nokia RX51"); 310 416 MODULE_AUTHOR("Nokia Corporation"); 311 417 MODULE_LICENSE("GPL");
+3 -3
include/linux/platform_data/media/ir-rx51.h
··· 1 - #ifndef _LIRC_RX51_H 2 - #define _LIRC_RX51_H 1 + #ifndef _IR_RX51_H 2 + #define _IR_RX51_H 3 3 4 - struct lirc_rx51_platform_data { 4 + struct ir_rx51_platform_data { 5 5 int(*set_max_mpu_wakeup_lat)(struct device *dev, long t); 6 6 }; 7 7