diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-24 00:12:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-24 00:12:49 -0400 |
commit | df462b3dbeeaae7141f1b63cbfcc1e1bae6a85fc (patch) | |
tree | bca52fce066159f136d75c69e79016422212cb1d /drivers/media/rc | |
parent | 343800e7d20944aead238c2c6e3f7789f8b6587c (diff) | |
parent | cf25220677b3f10468a74278130fe224f73632a6 (diff) |
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6
* 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (247 commits)
[media] gspca - sunplus: Fix some warnings and simplify code
[media] gspca: Fix some warnings tied to 'no debug'
[media] gspca: Unset debug by default
[media] gspca - cpia1: Remove a bad conditional compilation instruction
[media] gspca - main: Remove USB traces
[media] gspca - main: Version change to 2.13
[media] gspca - stk014 / t613: Accept the index 0 in querymenu
[media] gspca - kinect: Remove __devinitdata
[media] gspca - cpia1: Fix some warnings
[media] video/Kconfig: Fix mis-classified devices
[media] support for medion dvb stick 1660:1921
[media] tm6000: fix uninitialized field, change prink to dprintk
[media] cx231xx: Add support for Iconbit U100
[media] saa7134 add new TV cards
[media] Use a more consistent value for RC repeat period
[media] cx18: Move spinlock and vb_type initialisation into stream_init
[media] tm6000: remove tm6010 sif audio start and stop
[media] tm6000: remove unused exports
[media] tm6000: add pts logging
[media] tm6000: change from ioctl to unlocked_ioctl
...
Diffstat (limited to 'drivers/media/rc')
-rw-r--r-- | drivers/media/rc/Kconfig | 11 | ||||
-rw-r--r-- | drivers/media/rc/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/rc/imon.c | 36 | ||||
-rw-r--r-- | drivers/media/rc/ite-cir.c | 60 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/rc-avermedia-cardbus.c | 2 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/rc-imon-mce.c | 2 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/rc-imon-pad.c | 6 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c | 2 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/rc-rc6-mce.c | 4 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/rc-tivo.c | 98 | ||||
-rw-r--r-- | drivers/media/rc/keymaps/rc-winfast.c | 4 | ||||
-rw-r--r-- | drivers/media/rc/mceusb.c | 34 | ||||
-rw-r--r-- | drivers/media/rc/nuvoton-cir.c | 75 | ||||
-rw-r--r-- | drivers/media/rc/nuvoton-cir.h | 17 | ||||
-rw-r--r-- | drivers/media/rc/rc-loopback.c | 6 | ||||
-rw-r--r-- | drivers/media/rc/rc-main.c | 54 | ||||
-rw-r--r-- | drivers/media/rc/redrat3.c | 1344 | ||||
-rw-r--r-- | drivers/media/rc/winbond-cir.c | 447 |
19 files changed, 1998 insertions, 206 deletions
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig index 7f03142a329f..154c337f00fd 100644 --- a/drivers/media/rc/Kconfig +++ b/drivers/media/rc/Kconfig | |||
@@ -161,6 +161,17 @@ config IR_NUVOTON | |||
161 | To compile this driver as a module, choose M here: the | 161 | To compile this driver as a module, choose M here: the |
162 | module will be called nuvoton-cir. | 162 | module will be called nuvoton-cir. |
163 | 163 | ||
164 | config IR_REDRAT3 | ||
165 | tristate "RedRat3 IR Transceiver" | ||
166 | depends on USB_ARCH_HAS_HCD | ||
167 | depends on RC_CORE | ||
168 | select USB | ||
169 | ---help--- | ||
170 | Say Y here if you want to use a RedRat3 Infrared Transceiver. | ||
171 | |||
172 | To compile this driver as a module, choose M here: the | ||
173 | module will be called redrat3. | ||
174 | |||
164 | config IR_STREAMZAP | 175 | config IR_STREAMZAP |
165 | tristate "Streamzap PC Remote IR Receiver" | 176 | tristate "Streamzap PC Remote IR Receiver" |
166 | depends on USB_ARCH_HAS_HCD | 177 | depends on USB_ARCH_HAS_HCD |
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile index c6cfe70d862f..1f90a219a162 100644 --- a/drivers/media/rc/Makefile +++ b/drivers/media/rc/Makefile | |||
@@ -18,6 +18,7 @@ obj-$(CONFIG_IR_ITE_CIR) += ite-cir.o | |||
18 | obj-$(CONFIG_IR_MCEUSB) += mceusb.o | 18 | obj-$(CONFIG_IR_MCEUSB) += mceusb.o |
19 | obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o | 19 | obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o |
20 | obj-$(CONFIG_IR_ENE) += ene_ir.o | 20 | obj-$(CONFIG_IR_ENE) += ene_ir.o |
21 | obj-$(CONFIG_IR_REDRAT3) += redrat3.o | ||
21 | obj-$(CONFIG_IR_STREAMZAP) += streamzap.o | 22 | obj-$(CONFIG_IR_STREAMZAP) += streamzap.o |
22 | obj-$(CONFIG_IR_WINBOND_CIR) += winbond-cir.o | 23 | obj-$(CONFIG_IR_WINBOND_CIR) += winbond-cir.o |
23 | obj-$(CONFIG_RC_LOOPBACK) += rc-loopback.o | 24 | obj-$(CONFIG_RC_LOOPBACK) += rc-loopback.o |
diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c index 8fc0f081b470..3f3c70716268 100644 --- a/drivers/media/rc/imon.c +++ b/drivers/media/rc/imon.c | |||
@@ -443,16 +443,6 @@ static int display_close(struct inode *inode, struct file *file) | |||
443 | } else { | 443 | } else { |
444 | ictx->display_isopen = false; | 444 | ictx->display_isopen = false; |
445 | dev_dbg(ictx->dev, "display port closed\n"); | 445 | dev_dbg(ictx->dev, "display port closed\n"); |
446 | if (!ictx->dev_present_intf0) { | ||
447 | /* | ||
448 | * Device disconnected before close and IR port is not | ||
449 | * open. If IR port is open, context will be deleted by | ||
450 | * ir_close. | ||
451 | */ | ||
452 | mutex_unlock(&ictx->lock); | ||
453 | free_imon_context(ictx); | ||
454 | return retval; | ||
455 | } | ||
456 | } | 446 | } |
457 | 447 | ||
458 | mutex_unlock(&ictx->lock); | 448 | mutex_unlock(&ictx->lock); |
@@ -1492,7 +1482,6 @@ static void imon_incoming_packet(struct imon_context *ictx, | |||
1492 | struct device *dev = ictx->dev; | 1482 | struct device *dev = ictx->dev; |
1493 | unsigned long flags; | 1483 | unsigned long flags; |
1494 | u32 kc; | 1484 | u32 kc; |
1495 | bool norelease = false; | ||
1496 | int i; | 1485 | int i; |
1497 | u64 scancode; | 1486 | u64 scancode; |
1498 | int press_type = 0; | 1487 | int press_type = 0; |
@@ -1560,7 +1549,6 @@ static void imon_incoming_packet(struct imon_context *ictx, | |||
1560 | !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) { | 1549 | !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) { |
1561 | len = 8; | 1550 | len = 8; |
1562 | imon_pad_to_keys(ictx, buf); | 1551 | imon_pad_to_keys(ictx, buf); |
1563 | norelease = true; | ||
1564 | } | 1552 | } |
1565 | 1553 | ||
1566 | if (debug) { | 1554 | if (debug) { |
@@ -1982,7 +1970,7 @@ static struct input_dev *imon_init_touch(struct imon_context *ictx) | |||
1982 | return touch; | 1970 | return touch; |
1983 | 1971 | ||
1984 | touch_register_failed: | 1972 | touch_register_failed: |
1985 | input_free_device(ictx->touch); | 1973 | input_free_device(touch); |
1986 | 1974 | ||
1987 | touch_alloc_failed: | 1975 | touch_alloc_failed: |
1988 | return NULL; | 1976 | return NULL; |
@@ -2274,14 +2262,12 @@ static int __devinit imon_probe(struct usb_interface *interface, | |||
2274 | struct usb_host_interface *iface_desc = NULL; | 2262 | struct usb_host_interface *iface_desc = NULL; |
2275 | struct usb_interface *first_if; | 2263 | struct usb_interface *first_if; |
2276 | struct device *dev = &interface->dev; | 2264 | struct device *dev = &interface->dev; |
2277 | int ifnum, code_length, sysfs_err; | 2265 | int ifnum, sysfs_err; |
2278 | int ret = 0; | 2266 | int ret = 0; |
2279 | struct imon_context *ictx = NULL; | 2267 | struct imon_context *ictx = NULL; |
2280 | struct imon_context *first_if_ctx = NULL; | 2268 | struct imon_context *first_if_ctx = NULL; |
2281 | u16 vendor, product; | 2269 | u16 vendor, product; |
2282 | 2270 | ||
2283 | code_length = BUF_CHUNK_SIZE * 8; | ||
2284 | |||
2285 | usbdev = usb_get_dev(interface_to_usbdev(interface)); | 2271 | usbdev = usb_get_dev(interface_to_usbdev(interface)); |
2286 | iface_desc = interface->cur_altsetting; | 2272 | iface_desc = interface->cur_altsetting; |
2287 | ifnum = iface_desc->desc.bInterfaceNumber; | 2273 | ifnum = iface_desc->desc.bInterfaceNumber; |
@@ -2366,8 +2352,6 @@ static void __devexit imon_disconnect(struct usb_interface *interface) | |||
2366 | dev = ictx->dev; | 2352 | dev = ictx->dev; |
2367 | ifnum = interface->cur_altsetting->desc.bInterfaceNumber; | 2353 | ifnum = interface->cur_altsetting->desc.bInterfaceNumber; |
2368 | 2354 | ||
2369 | mutex_lock(&ictx->lock); | ||
2370 | |||
2371 | /* | 2355 | /* |
2372 | * sysfs_remove_group is safe to call even if sysfs_create_group | 2356 | * sysfs_remove_group is safe to call even if sysfs_create_group |
2373 | * hasn't been called | 2357 | * hasn't been called |
@@ -2391,24 +2375,20 @@ static void __devexit imon_disconnect(struct usb_interface *interface) | |||
2391 | if (ictx->display_supported) { | 2375 | if (ictx->display_supported) { |
2392 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) | 2376 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) |
2393 | usb_deregister_dev(interface, &imon_lcd_class); | 2377 | usb_deregister_dev(interface, &imon_lcd_class); |
2394 | else | 2378 | else if (ictx->display_type == IMON_DISPLAY_TYPE_VFD) |
2395 | usb_deregister_dev(interface, &imon_vfd_class); | 2379 | usb_deregister_dev(interface, &imon_vfd_class); |
2396 | } | 2380 | } |
2397 | } else { | 2381 | } else { |
2398 | ictx->dev_present_intf1 = false; | 2382 | ictx->dev_present_intf1 = false; |
2399 | usb_kill_urb(ictx->rx_urb_intf1); | 2383 | usb_kill_urb(ictx->rx_urb_intf1); |
2400 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) | 2384 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { |
2401 | input_unregister_device(ictx->touch); | 2385 | input_unregister_device(ictx->touch); |
2386 | del_timer_sync(&ictx->ttimer); | ||
2387 | } | ||
2402 | } | 2388 | } |
2403 | 2389 | ||
2404 | if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) { | 2390 | if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) |
2405 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) | 2391 | free_imon_context(ictx); |
2406 | del_timer_sync(&ictx->ttimer); | ||
2407 | mutex_unlock(&ictx->lock); | ||
2408 | if (!ictx->display_isopen) | ||
2409 | free_imon_context(ictx); | ||
2410 | } else | ||
2411 | mutex_unlock(&ictx->lock); | ||
2412 | 2392 | ||
2413 | mutex_unlock(&driver_lock); | 2393 | mutex_unlock(&driver_lock); |
2414 | 2394 | ||
diff --git a/drivers/media/rc/ite-cir.c b/drivers/media/rc/ite-cir.c index 43908a70bd8b..e716b931cf7e 100644 --- a/drivers/media/rc/ite-cir.c +++ b/drivers/media/rc/ite-cir.c | |||
@@ -1250,11 +1250,9 @@ static void it8709_disable(struct ite_dev *dev) | |||
1250 | ite_dbg("%s called", __func__); | 1250 | ite_dbg("%s called", __func__); |
1251 | 1251 | ||
1252 | /* clear out all interrupt enable flags */ | 1252 | /* clear out all interrupt enable flags */ |
1253 | it8709_wr(dev, | 1253 | it8709_wr(dev, it8709_rr(dev, IT85_C0IER) & |
1254 | it8709_rr(dev, | 1254 | ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE), |
1255 | IT85_C0IER) & ~(IT85_IEC | IT85_RFOIE | | 1255 | IT85_C0IER); |
1256 | IT85_RDAIE | | ||
1257 | IT85_TLDLIE), IT85_C0IER); | ||
1258 | 1256 | ||
1259 | /* disable the receiver */ | 1257 | /* disable the receiver */ |
1260 | it8709_disable_rx(dev); | 1258 | it8709_disable_rx(dev); |
@@ -1270,11 +1268,9 @@ static void it8709_init_hardware(struct ite_dev *dev) | |||
1270 | ite_dbg("%s called", __func__); | 1268 | ite_dbg("%s called", __func__); |
1271 | 1269 | ||
1272 | /* disable all the interrupts */ | 1270 | /* disable all the interrupts */ |
1273 | it8709_wr(dev, | 1271 | it8709_wr(dev, it8709_rr(dev, IT85_C0IER) & |
1274 | it8709_rr(dev, | 1272 | ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE), |
1275 | IT85_C0IER) & ~(IT85_IEC | IT85_RFOIE | | 1273 | IT85_C0IER); |
1276 | IT85_RDAIE | | ||
1277 | IT85_TLDLIE), IT85_C0IER); | ||
1278 | 1274 | ||
1279 | /* program the baud rate divisor */ | 1275 | /* program the baud rate divisor */ |
1280 | it8709_wr(dev, ITE_BAUDRATE_DIVISOR & 0xff, IT85_C0BDLR); | 1276 | it8709_wr(dev, ITE_BAUDRATE_DIVISOR & 0xff, IT85_C0BDLR); |
@@ -1282,28 +1278,22 @@ static void it8709_init_hardware(struct ite_dev *dev) | |||
1282 | IT85_C0BDHR); | 1278 | IT85_C0BDHR); |
1283 | 1279 | ||
1284 | /* program the C0MSTCR register defaults */ | 1280 | /* program the C0MSTCR register defaults */ |
1285 | it8709_wr(dev, (it8709_rr(dev, IT85_C0MSTCR) & ~(IT85_ILSEL | | 1281 | it8709_wr(dev, (it8709_rr(dev, IT85_C0MSTCR) & |
1286 | IT85_ILE | 1282 | ~(IT85_ILSEL | IT85_ILE | IT85_FIFOTL |
1287 | | IT85_FIFOTL | 1283 | | IT85_FIFOCLR | IT85_RESET)) | IT85_FIFOTL_DEFAULT, |
1288 | | | 1284 | IT85_C0MSTCR); |
1289 | IT85_FIFOCLR | ||
1290 | | | ||
1291 | IT85_RESET)) | ||
1292 | | IT85_FIFOTL_DEFAULT, IT85_C0MSTCR); | ||
1293 | 1285 | ||
1294 | /* program the C0RCR register defaults */ | 1286 | /* program the C0RCR register defaults */ |
1295 | it8709_wr(dev, | 1287 | it8709_wr(dev, (it8709_rr(dev, IT85_C0RCR) & |
1296 | (it8709_rr(dev, IT85_C0RCR) & | 1288 | ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND | IT85_RXACT |
1297 | ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND | 1289 | | IT85_RXDCR)) | ITE_RXDCR_DEFAULT, |
1298 | | IT85_RXACT | IT85_RXDCR)) | | 1290 | IT85_C0RCR); |
1299 | ITE_RXDCR_DEFAULT, IT85_C0RCR); | ||
1300 | 1291 | ||
1301 | /* program the C0TCR register defaults */ | 1292 | /* program the C0TCR register defaults */ |
1302 | it8709_wr(dev, (it8709_rr(dev, IT85_C0TCR) | 1293 | it8709_wr(dev, (it8709_rr(dev, IT85_C0TCR) & ~(IT85_TXMPM | IT85_TXMPW)) |
1303 | &~(IT85_TXMPM | IT85_TXMPW)) | 1294 | | IT85_TXRLE | IT85_TXENDF | IT85_TXMPM_DEFAULT |
1304 | |IT85_TXRLE | IT85_TXENDF | | 1295 | | IT85_TXMPW_DEFAULT, |
1305 | IT85_TXMPM_DEFAULT | | 1296 | IT85_C0TCR); |
1306 | IT85_TXMPW_DEFAULT, IT85_C0TCR); | ||
1307 | 1297 | ||
1308 | /* program the carrier parameters */ | 1298 | /* program the carrier parameters */ |
1309 | ite_set_carrier_params(dev); | 1299 | ite_set_carrier_params(dev); |
@@ -1660,6 +1650,9 @@ static int ite_suspend(struct pnp_dev *pdev, pm_message_t state) | |||
1660 | 1650 | ||
1661 | ite_dbg("%s called", __func__); | 1651 | ite_dbg("%s called", __func__); |
1662 | 1652 | ||
1653 | /* wait for any transmission to end */ | ||
1654 | wait_event_interruptible(dev->tx_ended, !dev->transmitting); | ||
1655 | |||
1663 | spin_lock_irqsave(&dev->lock, flags); | 1656 | spin_lock_irqsave(&dev->lock, flags); |
1664 | 1657 | ||
1665 | /* disable all interrupts */ | 1658 | /* disable all interrupts */ |
@@ -1680,13 +1673,10 @@ static int ite_resume(struct pnp_dev *pdev) | |||
1680 | 1673 | ||
1681 | spin_lock_irqsave(&dev->lock, flags); | 1674 | spin_lock_irqsave(&dev->lock, flags); |
1682 | 1675 | ||
1683 | if (dev->transmitting) { | 1676 | /* reinitialize hardware config registers */ |
1684 | /* wake up the transmitter */ | 1677 | dev->params.init_hardware(dev); |
1685 | wake_up_interruptible(&dev->tx_queue); | 1678 | /* enable the receiver */ |
1686 | } else { | 1679 | dev->params.enable_rx(dev); |
1687 | /* enable the receiver */ | ||
1688 | dev->params.enable_rx(dev); | ||
1689 | } | ||
1690 | 1680 | ||
1691 | spin_unlock_irqrestore(&dev->lock, flags); | 1681 | spin_unlock_irqrestore(&dev->lock, flags); |
1692 | 1682 | ||
diff --git a/drivers/media/rc/keymaps/Makefile b/drivers/media/rc/keymaps/Makefile index 85cac7ddbcec..b57fc83fb4d2 100644 --- a/drivers/media/rc/keymaps/Makefile +++ b/drivers/media/rc/keymaps/Makefile | |||
@@ -77,6 +77,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ | |||
77 | rc-terratec-slim.o \ | 77 | rc-terratec-slim.o \ |
78 | rc-terratec-slim-2.o \ | 78 | rc-terratec-slim-2.o \ |
79 | rc-tevii-nec.o \ | 79 | rc-tevii-nec.o \ |
80 | rc-tivo.o \ | ||
80 | rc-total-media-in-hand.o \ | 81 | rc-total-media-in-hand.o \ |
81 | rc-trekstor.o \ | 82 | rc-trekstor.o \ |
82 | rc-tt-1500.o \ | 83 | rc-tt-1500.o \ |
diff --git a/drivers/media/rc/keymaps/rc-avermedia-cardbus.c b/drivers/media/rc/keymaps/rc-avermedia-cardbus.c index bdf97b74cf90..22f54d413a35 100644 --- a/drivers/media/rc/keymaps/rc-avermedia-cardbus.c +++ b/drivers/media/rc/keymaps/rc-avermedia-cardbus.c | |||
@@ -52,7 +52,7 @@ static struct rc_map_table avermedia_cardbus[] = { | |||
52 | { 0x28, KEY_SELECT }, /* Select */ | 52 | { 0x28, KEY_SELECT }, /* Select */ |
53 | { 0x29, KEY_BLUE }, /* Blue/Picture */ | 53 | { 0x29, KEY_BLUE }, /* Blue/Picture */ |
54 | { 0x2a, KEY_BACKSPACE }, /* Back */ | 54 | { 0x2a, KEY_BACKSPACE }, /* Back */ |
55 | { 0x2b, KEY_MEDIA }, /* PIP (Picture-in-picture) */ | 55 | { 0x2b, KEY_VIDEO }, /* PIP (Picture-in-picture) */ |
56 | { 0x2c, KEY_DOWN }, | 56 | { 0x2c, KEY_DOWN }, |
57 | { 0x2e, KEY_DOT }, | 57 | { 0x2e, KEY_DOT }, |
58 | { 0x2f, KEY_TV }, /* Live TV */ | 58 | { 0x2f, KEY_TV }, /* Live TV */ |
diff --git a/drivers/media/rc/keymaps/rc-imon-mce.c b/drivers/media/rc/keymaps/rc-imon-mce.c index 937a81989f00..0ea2aa190d81 100644 --- a/drivers/media/rc/keymaps/rc-imon-mce.c +++ b/drivers/media/rc/keymaps/rc-imon-mce.c | |||
@@ -111,7 +111,7 @@ static struct rc_map_table imon_mce[] = { | |||
111 | { 0x800ff44d, KEY_TITLE }, | 111 | { 0x800ff44d, KEY_TITLE }, |
112 | 112 | ||
113 | { 0x800ff40c, KEY_POWER }, | 113 | { 0x800ff40c, KEY_POWER }, |
114 | { 0x800ff40d, KEY_LEFTMETA }, /* Windows MCE button */ | 114 | { 0x800ff40d, KEY_MEDIA }, /* Windows MCE button */ |
115 | 115 | ||
116 | }; | 116 | }; |
117 | 117 | ||
diff --git a/drivers/media/rc/keymaps/rc-imon-pad.c b/drivers/media/rc/keymaps/rc-imon-pad.c index 63d42bd24c9e..75d3843fdc30 100644 --- a/drivers/media/rc/keymaps/rc-imon-pad.c +++ b/drivers/media/rc/keymaps/rc-imon-pad.c | |||
@@ -87,7 +87,7 @@ static struct rc_map_table imon_pad[] = { | |||
87 | 87 | ||
88 | { 0x2b8515b7, KEY_VIDEO }, | 88 | { 0x2b8515b7, KEY_VIDEO }, |
89 | { 0x299195b7, KEY_AUDIO }, | 89 | { 0x299195b7, KEY_AUDIO }, |
90 | { 0x2ba115b7, KEY_CAMERA }, | 90 | { 0x2ba115b7, KEY_IMAGES }, |
91 | { 0x28a515b7, KEY_TV }, | 91 | { 0x28a515b7, KEY_TV }, |
92 | { 0x29a395b7, KEY_DVD }, | 92 | { 0x29a395b7, KEY_DVD }, |
93 | { 0x29a295b7, KEY_DVD }, | 93 | { 0x29a295b7, KEY_DVD }, |
@@ -97,7 +97,7 @@ static struct rc_map_table imon_pad[] = { | |||
97 | { 0x2ba395b7, KEY_MENU }, | 97 | { 0x2ba395b7, KEY_MENU }, |
98 | 98 | ||
99 | { 0x288515b7, KEY_BOOKMARKS }, | 99 | { 0x288515b7, KEY_BOOKMARKS }, |
100 | { 0x2ab715b7, KEY_MEDIA }, /* Thumbnail */ | 100 | { 0x2ab715b7, KEY_CAMERA }, /* Thumbnail */ |
101 | { 0x298595b7, KEY_SUBTITLE }, | 101 | { 0x298595b7, KEY_SUBTITLE }, |
102 | { 0x2b8595b7, KEY_LANGUAGE }, | 102 | { 0x2b8595b7, KEY_LANGUAGE }, |
103 | 103 | ||
@@ -125,7 +125,7 @@ static struct rc_map_table imon_pad[] = { | |||
125 | { 0x2b8195b7, KEY_CONTEXT_MENU }, /* Left Menu*/ | 125 | { 0x2b8195b7, KEY_CONTEXT_MENU }, /* Left Menu*/ |
126 | { 0x02000065, KEY_COMPOSE }, /* RightMenu */ | 126 | { 0x02000065, KEY_COMPOSE }, /* RightMenu */ |
127 | { 0x28b715b7, KEY_COMPOSE }, /* RightMenu */ | 127 | { 0x28b715b7, KEY_COMPOSE }, /* RightMenu */ |
128 | { 0x2ab195b7, KEY_LEFTMETA }, /* Go or MultiMon */ | 128 | { 0x2ab195b7, KEY_MEDIA }, /* Go or MultiMon */ |
129 | { 0x29b715b7, KEY_DASHBOARD }, /* AppLauncher */ | 129 | { 0x29b715b7, KEY_DASHBOARD }, /* AppLauncher */ |
130 | }; | 130 | }; |
131 | 131 | ||
diff --git a/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c b/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c index 08d183120e41..7fa17a369f2d 100644 --- a/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c +++ b/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c | |||
@@ -17,7 +17,7 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | static struct rc_map_table kworld_plus_tv_analog[] = { | 19 | static struct rc_map_table kworld_plus_tv_analog[] = { |
20 | { 0x0c, KEY_LEFTMETA }, /* Kworld key */ | 20 | { 0x0c, KEY_MEDIA }, /* Kworld key */ |
21 | { 0x16, KEY_CLOSECD }, /* -> ) */ | 21 | { 0x16, KEY_CLOSECD }, /* -> ) */ |
22 | { 0x1d, KEY_POWER2 }, | 22 | { 0x1d, KEY_POWER2 }, |
23 | 23 | ||
diff --git a/drivers/media/rc/keymaps/rc-rc6-mce.c b/drivers/media/rc/keymaps/rc-rc6-mce.c index 8dd519ecc58e..01b69bcc8666 100644 --- a/drivers/media/rc/keymaps/rc-rc6-mce.c +++ b/drivers/media/rc/keymaps/rc-rc6-mce.c | |||
@@ -30,7 +30,7 @@ static struct rc_map_table rc6_mce[] = { | |||
30 | { 0x800f040a, KEY_DELETE }, | 30 | { 0x800f040a, KEY_DELETE }, |
31 | { 0x800f040b, KEY_ENTER }, | 31 | { 0x800f040b, KEY_ENTER }, |
32 | { 0x800f040c, KEY_POWER }, /* PC Power */ | 32 | { 0x800f040c, KEY_POWER }, /* PC Power */ |
33 | { 0x800f040d, KEY_LEFTMETA }, /* Windows MCE button */ | 33 | { 0x800f040d, KEY_MEDIA }, /* Windows MCE button */ |
34 | { 0x800f040e, KEY_MUTE }, | 34 | { 0x800f040e, KEY_MUTE }, |
35 | { 0x800f040f, KEY_INFO }, | 35 | { 0x800f040f, KEY_INFO }, |
36 | 36 | ||
@@ -87,7 +87,7 @@ static struct rc_map_table rc6_mce[] = { | |||
87 | 87 | ||
88 | { 0x800f0465, KEY_POWER2 }, /* TV Power */ | 88 | { 0x800f0465, KEY_POWER2 }, /* TV Power */ |
89 | { 0x800f046e, KEY_PLAYPAUSE }, | 89 | { 0x800f046e, KEY_PLAYPAUSE }, |
90 | { 0x800f046f, KEY_MEDIA }, /* Start media application (NEW) */ | 90 | { 0x800f046f, KEY_PLAYER }, /* Start media application (NEW) */ |
91 | 91 | ||
92 | { 0x800f0480, KEY_BRIGHTNESSDOWN }, | 92 | { 0x800f0480, KEY_BRIGHTNESSDOWN }, |
93 | { 0x800f0481, KEY_PLAYPAUSE }, | 93 | { 0x800f0481, KEY_PLAYPAUSE }, |
diff --git a/drivers/media/rc/keymaps/rc-tivo.c b/drivers/media/rc/keymaps/rc-tivo.c new file mode 100644 index 000000000000..98ad085531fd --- /dev/null +++ b/drivers/media/rc/keymaps/rc-tivo.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /* rc-tivo.c - Keytable for TiVo remotes | ||
2 | * | ||
3 | * Copyright (c) 2011 by Jarod Wilson <jarod@redhat.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | */ | ||
10 | |||
11 | #include <media/rc-map.h> | ||
12 | |||
13 | /* | ||
14 | * Initial mapping is for the TiVo remote included in the Nero LiquidTV bundle, | ||
15 | * which also ships with a TiVo-branded IR transceiver, supported by the mceusb | ||
16 | * driver. Note that the remote uses an NEC-ish protocol, but instead of having | ||
17 | * a command/not_command pair, it has a vendor ID of 0xa10c, but some keys, the | ||
18 | * NEC extended checksums do pass, so the table presently has the intended | ||
19 | * values and the checksum-passed versions for those keys. | ||
20 | */ | ||
21 | static struct rc_map_table tivo[] = { | ||
22 | { 0xa10c900f, KEY_MEDIA }, /* TiVo Button */ | ||
23 | { 0xa10c0807, KEY_POWER2 }, /* TV Power */ | ||
24 | { 0xa10c8807, KEY_TV }, /* Live TV/Swap */ | ||
25 | { 0xa10c2c03, KEY_VIDEO_NEXT }, /* TV Input */ | ||
26 | { 0xa10cc807, KEY_INFO }, | ||
27 | { 0xa10cfa05, KEY_CYCLEWINDOWS }, /* Window */ | ||
28 | { 0x0085305f, KEY_CYCLEWINDOWS }, | ||
29 | { 0xa10c6c03, KEY_EPG }, /* Guide */ | ||
30 | |||
31 | { 0xa10c2807, KEY_UP }, | ||
32 | { 0xa10c6807, KEY_DOWN }, | ||
33 | { 0xa10ce807, KEY_LEFT }, | ||
34 | { 0xa10ca807, KEY_RIGHT }, | ||
35 | |||
36 | { 0xa10c1807, KEY_SCROLLDOWN }, /* Red Thumbs Down */ | ||
37 | { 0xa10c9807, KEY_SELECT }, | ||
38 | { 0xa10c5807, KEY_SCROLLUP }, /* Green Thumbs Up */ | ||
39 | |||
40 | { 0xa10c3807, KEY_VOLUMEUP }, | ||
41 | { 0xa10cb807, KEY_VOLUMEDOWN }, | ||
42 | { 0xa10cd807, KEY_MUTE }, | ||
43 | { 0xa10c040b, KEY_RECORD }, | ||
44 | { 0xa10c7807, KEY_CHANNELUP }, | ||
45 | { 0xa10cf807, KEY_CHANNELDOWN }, | ||
46 | { 0x0085301f, KEY_CHANNELDOWN }, | ||
47 | |||
48 | { 0xa10c840b, KEY_PLAY }, | ||
49 | { 0xa10cc40b, KEY_PAUSE }, | ||
50 | { 0xa10ca40b, KEY_SLOW }, | ||
51 | { 0xa10c440b, KEY_REWIND }, | ||
52 | { 0xa10c240b, KEY_FASTFORWARD }, | ||
53 | { 0xa10c640b, KEY_PREVIOUS }, | ||
54 | { 0xa10ce40b, KEY_NEXT }, /* ->| */ | ||
55 | |||
56 | { 0xa10c220d, KEY_ZOOM }, /* Aspect */ | ||
57 | { 0xa10c120d, KEY_STOP }, | ||
58 | { 0xa10c520d, KEY_DVD }, /* DVD Menu */ | ||
59 | |||
60 | { 0xa10c140b, KEY_NUMERIC_1 }, | ||
61 | { 0xa10c940b, KEY_NUMERIC_2 }, | ||
62 | { 0xa10c540b, KEY_NUMERIC_3 }, | ||
63 | { 0xa10cd40b, KEY_NUMERIC_4 }, | ||
64 | { 0xa10c340b, KEY_NUMERIC_5 }, | ||
65 | { 0xa10cb40b, KEY_NUMERIC_6 }, | ||
66 | { 0xa10c740b, KEY_NUMERIC_7 }, | ||
67 | { 0xa10cf40b, KEY_NUMERIC_8 }, | ||
68 | { 0x0085302f, KEY_NUMERIC_8 }, | ||
69 | { 0xa10c0c03, KEY_NUMERIC_9 }, | ||
70 | { 0xa10c8c03, KEY_NUMERIC_0 }, | ||
71 | { 0xa10ccc03, KEY_ENTER }, | ||
72 | { 0xa10c4c03, KEY_CLEAR }, | ||
73 | }; | ||
74 | |||
75 | static struct rc_map_list tivo_map = { | ||
76 | .map = { | ||
77 | .scan = tivo, | ||
78 | .size = ARRAY_SIZE(tivo), | ||
79 | .rc_type = RC_TYPE_NEC, | ||
80 | .name = RC_MAP_TIVO, | ||
81 | } | ||
82 | }; | ||
83 | |||
84 | static int __init init_rc_map_tivo(void) | ||
85 | { | ||
86 | return rc_map_register(&tivo_map); | ||
87 | } | ||
88 | |||
89 | static void __exit exit_rc_map_tivo(void) | ||
90 | { | ||
91 | rc_map_unregister(&tivo_map); | ||
92 | } | ||
93 | |||
94 | module_init(init_rc_map_tivo) | ||
95 | module_exit(exit_rc_map_tivo) | ||
96 | |||
97 | MODULE_LICENSE("GPL"); | ||
98 | MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>"); | ||
diff --git a/drivers/media/rc/keymaps/rc-winfast.c b/drivers/media/rc/keymaps/rc-winfast.c index 0062ca291959..d8a34c14676a 100644 --- a/drivers/media/rc/keymaps/rc-winfast.c +++ b/drivers/media/rc/keymaps/rc-winfast.c | |||
@@ -32,8 +32,8 @@ static struct rc_map_table winfast[] = { | |||
32 | { 0x02, KEY_TUNER }, /* TV/FM, not on Y0400052 */ | 32 | { 0x02, KEY_TUNER }, /* TV/FM, not on Y0400052 */ |
33 | { 0x1e, KEY_VIDEO }, /* Video Source */ | 33 | { 0x1e, KEY_VIDEO }, /* Video Source */ |
34 | { 0x16, KEY_INFO }, /* Display information */ | 34 | { 0x16, KEY_INFO }, /* Display information */ |
35 | { 0x04, KEY_LEFT }, | 35 | { 0x04, KEY_RIGHT }, |
36 | { 0x08, KEY_RIGHT }, | 36 | { 0x08, KEY_LEFT }, |
37 | { 0x0c, KEY_UP }, | 37 | { 0x0c, KEY_UP }, |
38 | { 0x10, KEY_DOWN }, | 38 | { 0x10, KEY_DOWN }, |
39 | { 0x03, KEY_ZOOM }, /* fullscreen */ | 39 | { 0x03, KEY_ZOOM }, /* fullscreen */ |
diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c index 0c273ec465c9..ad927fcaa020 100644 --- a/drivers/media/rc/mceusb.c +++ b/drivers/media/rc/mceusb.c | |||
@@ -149,6 +149,8 @@ enum mceusb_model_type { | |||
149 | POLARIS_EVK, | 149 | POLARIS_EVK, |
150 | CX_HYBRID_TV, | 150 | CX_HYBRID_TV, |
151 | MULTIFUNCTION, | 151 | MULTIFUNCTION, |
152 | TIVO_KIT, | ||
153 | MCE_GEN2_NO_TX, | ||
152 | }; | 154 | }; |
153 | 155 | ||
154 | struct mceusb_model { | 156 | struct mceusb_model { |
@@ -172,6 +174,10 @@ static const struct mceusb_model mceusb_model[] = { | |||
172 | [MCE_GEN2] = { | 174 | [MCE_GEN2] = { |
173 | .mce_gen2 = 1, | 175 | .mce_gen2 = 1, |
174 | }, | 176 | }, |
177 | [MCE_GEN2_NO_TX] = { | ||
178 | .mce_gen2 = 1, | ||
179 | .no_tx = 1, | ||
180 | }, | ||
175 | [MCE_GEN2_TX_INV] = { | 181 | [MCE_GEN2_TX_INV] = { |
176 | .mce_gen2 = 1, | 182 | .mce_gen2 = 1, |
177 | .tx_mask_normal = 1, | 183 | .tx_mask_normal = 1, |
@@ -197,6 +203,10 @@ static const struct mceusb_model mceusb_model[] = { | |||
197 | .mce_gen2 = 1, | 203 | .mce_gen2 = 1, |
198 | .ir_intfnum = 2, | 204 | .ir_intfnum = 2, |
199 | }, | 205 | }, |
206 | [TIVO_KIT] = { | ||
207 | .mce_gen2 = 1, | ||
208 | .rc_map = RC_MAP_TIVO, | ||
209 | }, | ||
200 | }; | 210 | }; |
201 | 211 | ||
202 | static struct usb_device_id mceusb_dev_table[] = { | 212 | static struct usb_device_id mceusb_dev_table[] = { |
@@ -279,7 +289,8 @@ static struct usb_device_id mceusb_dev_table[] = { | |||
279 | /* Formosa21 / eHome Infrared Receiver */ | 289 | /* Formosa21 / eHome Infrared Receiver */ |
280 | { USB_DEVICE(VENDOR_FORMOSA, 0xe016) }, | 290 | { USB_DEVICE(VENDOR_FORMOSA, 0xe016) }, |
281 | /* Formosa aim / Trust MCE Infrared Receiver */ | 291 | /* Formosa aim / Trust MCE Infrared Receiver */ |
282 | { USB_DEVICE(VENDOR_FORMOSA, 0xe017) }, | 292 | { USB_DEVICE(VENDOR_FORMOSA, 0xe017), |
293 | .driver_info = MCE_GEN2_NO_TX }, | ||
283 | /* Formosa Industrial Computing / Beanbag Emulation Device */ | 294 | /* Formosa Industrial Computing / Beanbag Emulation Device */ |
284 | { USB_DEVICE(VENDOR_FORMOSA, 0xe018) }, | 295 | { USB_DEVICE(VENDOR_FORMOSA, 0xe018) }, |
285 | /* Formosa21 / eHome Infrared Receiver */ | 296 | /* Formosa21 / eHome Infrared Receiver */ |
@@ -308,7 +319,8 @@ static struct usb_device_id mceusb_dev_table[] = { | |||
308 | /* Northstar Systems, Inc. eHome Infrared Transceiver */ | 319 | /* Northstar Systems, Inc. eHome Infrared Transceiver */ |
309 | { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) }, | 320 | { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) }, |
310 | /* TiVo PC IR Receiver */ | 321 | /* TiVo PC IR Receiver */ |
311 | { USB_DEVICE(VENDOR_TIVO, 0x2000) }, | 322 | { USB_DEVICE(VENDOR_TIVO, 0x2000), |
323 | .driver_info = TIVO_KIT }, | ||
312 | /* Conexant Hybrid TV "Shelby" Polaris SDK */ | 324 | /* Conexant Hybrid TV "Shelby" Polaris SDK */ |
313 | { USB_DEVICE(VENDOR_CONEXANT, 0x58a1), | 325 | { USB_DEVICE(VENDOR_CONEXANT, 0x58a1), |
314 | .driver_info = POLARIS_EVK }, | 326 | .driver_info = POLARIS_EVK }, |
@@ -603,11 +615,10 @@ static void mce_async_callback(struct urb *urb, struct pt_regs *regs) | |||
603 | } | 615 | } |
604 | 616 | ||
605 | /* request incoming or send outgoing usb packet - used to initialize remote */ | 617 | /* request incoming or send outgoing usb packet - used to initialize remote */ |
606 | static void mce_request_packet(struct mceusb_dev *ir, | 618 | static void mce_request_packet(struct mceusb_dev *ir, unsigned char *data, |
607 | struct usb_endpoint_descriptor *ep, | 619 | int size, int urb_type) |
608 | unsigned char *data, int size, int urb_type) | ||
609 | { | 620 | { |
610 | int res; | 621 | int res, pipe; |
611 | struct urb *async_urb; | 622 | struct urb *async_urb; |
612 | struct device *dev = ir->dev; | 623 | struct device *dev = ir->dev; |
613 | unsigned char *async_buf; | 624 | unsigned char *async_buf; |
@@ -627,10 +638,11 @@ static void mce_request_packet(struct mceusb_dev *ir, | |||
627 | } | 638 | } |
628 | 639 | ||
629 | /* outbound data */ | 640 | /* outbound data */ |
630 | usb_fill_int_urb(async_urb, ir->usbdev, | 641 | pipe = usb_sndintpipe(ir->usbdev, |
631 | usb_sndintpipe(ir->usbdev, ep->bEndpointAddress), | 642 | ir->usb_ep_out->bEndpointAddress); |
643 | usb_fill_int_urb(async_urb, ir->usbdev, pipe, | ||
632 | async_buf, size, (usb_complete_t)mce_async_callback, | 644 | async_buf, size, (usb_complete_t)mce_async_callback, |
633 | ir, ep->bInterval); | 645 | ir, ir->usb_ep_out->bInterval); |
634 | memcpy(async_buf, data, size); | 646 | memcpy(async_buf, data, size); |
635 | 647 | ||
636 | } else if (urb_type == MCEUSB_RX) { | 648 | } else if (urb_type == MCEUSB_RX) { |
@@ -658,12 +670,12 @@ static void mce_request_packet(struct mceusb_dev *ir, | |||
658 | 670 | ||
659 | static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size) | 671 | static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size) |
660 | { | 672 | { |
661 | mce_request_packet(ir, ir->usb_ep_out, data, size, MCEUSB_TX); | 673 | mce_request_packet(ir, data, size, MCEUSB_TX); |
662 | } | 674 | } |
663 | 675 | ||
664 | static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size) | 676 | static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size) |
665 | { | 677 | { |
666 | mce_request_packet(ir, ir->usb_ep_in, data, size, MCEUSB_RX); | 678 | mce_request_packet(ir, data, size, MCEUSB_RX); |
667 | } | 679 | } |
668 | 680 | ||
669 | /* Send data out the IR blaster port(s) */ | 681 | /* Send data out the IR blaster port(s) */ |
diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c index d4d64492a057..bf3060ea6107 100644 --- a/drivers/media/rc/nuvoton-cir.c +++ b/drivers/media/rc/nuvoton-cir.c | |||
@@ -37,8 +37,6 @@ | |||
37 | 37 | ||
38 | #include "nuvoton-cir.h" | 38 | #include "nuvoton-cir.h" |
39 | 39 | ||
40 | static char *chip_id = "w836x7hg"; | ||
41 | |||
42 | /* write val to config reg */ | 40 | /* write val to config reg */ |
43 | static inline void nvt_cr_write(struct nvt_dev *nvt, u8 val, u8 reg) | 41 | static inline void nvt_cr_write(struct nvt_dev *nvt, u8 val, u8 reg) |
44 | { | 42 | { |
@@ -233,6 +231,8 @@ static int nvt_hw_detect(struct nvt_dev *nvt) | |||
233 | unsigned long flags; | 231 | unsigned long flags; |
234 | u8 chip_major, chip_minor; | 232 | u8 chip_major, chip_minor; |
235 | int ret = 0; | 233 | int ret = 0; |
234 | char chip_id[12]; | ||
235 | bool chip_unknown = false; | ||
236 | 236 | ||
237 | nvt_efm_enable(nvt); | 237 | nvt_efm_enable(nvt); |
238 | 238 | ||
@@ -246,15 +246,39 @@ static int nvt_hw_detect(struct nvt_dev *nvt) | |||
246 | } | 246 | } |
247 | 247 | ||
248 | chip_minor = nvt_cr_read(nvt, CR_CHIP_ID_LO); | 248 | chip_minor = nvt_cr_read(nvt, CR_CHIP_ID_LO); |
249 | nvt_dbg("%s: chip id: 0x%02x 0x%02x", chip_id, chip_major, chip_minor); | ||
250 | 249 | ||
251 | if (chip_major != CHIP_ID_HIGH || | 250 | /* these are the known working chip revisions... */ |
252 | (chip_minor != CHIP_ID_LOW && chip_minor != CHIP_ID_LOW2)) { | 251 | switch (chip_major) { |
253 | nvt_pr(KERN_ERR, "%s: unsupported chip, id: 0x%02x 0x%02x", | 252 | case CHIP_ID_HIGH_667: |
254 | chip_id, chip_major, chip_minor); | 253 | strcpy(chip_id, "w83667hg\0"); |
255 | ret = -ENODEV; | 254 | if (chip_minor != CHIP_ID_LOW_667) |
255 | chip_unknown = true; | ||
256 | break; | ||
257 | case CHIP_ID_HIGH_677B: | ||
258 | strcpy(chip_id, "w83677hg\0"); | ||
259 | if (chip_minor != CHIP_ID_LOW_677B2 && | ||
260 | chip_minor != CHIP_ID_LOW_677B3) | ||
261 | chip_unknown = true; | ||
262 | break; | ||
263 | case CHIP_ID_HIGH_677C: | ||
264 | strcpy(chip_id, "w83677hg-c\0"); | ||
265 | if (chip_minor != CHIP_ID_LOW_677C) | ||
266 | chip_unknown = true; | ||
267 | break; | ||
268 | default: | ||
269 | strcpy(chip_id, "w836x7hg\0"); | ||
270 | chip_unknown = true; | ||
271 | break; | ||
256 | } | 272 | } |
257 | 273 | ||
274 | /* warn, but still let the driver load, if we don't know this chip */ | ||
275 | if (chip_unknown) | ||
276 | nvt_pr(KERN_WARNING, "%s: unknown chip, id: 0x%02x 0x%02x, " | ||
277 | "it may not work...", chip_id, chip_major, chip_minor); | ||
278 | else | ||
279 | nvt_dbg("%s: chip id: 0x%02x 0x%02x", | ||
280 | chip_id, chip_major, chip_minor); | ||
281 | |||
258 | nvt_efm_disable(nvt); | 282 | nvt_efm_disable(nvt); |
259 | 283 | ||
260 | spin_lock_irqsave(&nvt->nvt_lock, flags); | 284 | spin_lock_irqsave(&nvt->nvt_lock, flags); |
@@ -267,13 +291,23 @@ static int nvt_hw_detect(struct nvt_dev *nvt) | |||
267 | 291 | ||
268 | static void nvt_cir_ldev_init(struct nvt_dev *nvt) | 292 | static void nvt_cir_ldev_init(struct nvt_dev *nvt) |
269 | { | 293 | { |
270 | u8 val; | 294 | u8 val, psreg, psmask, psval; |
295 | |||
296 | if (nvt->chip_major == CHIP_ID_HIGH_667) { | ||
297 | psreg = CR_MULTIFUNC_PIN_SEL; | ||
298 | psmask = MULTIFUNC_PIN_SEL_MASK; | ||
299 | psval = MULTIFUNC_ENABLE_CIR | MULTIFUNC_ENABLE_CIRWB; | ||
300 | } else { | ||
301 | psreg = CR_OUTPUT_PIN_SEL; | ||
302 | psmask = OUTPUT_PIN_SEL_MASK; | ||
303 | psval = OUTPUT_ENABLE_CIR | OUTPUT_ENABLE_CIRWB; | ||
304 | } | ||
271 | 305 | ||
272 | /* output pin selection (Pin95=CIRRX, Pin96=CIRTX1, WB enabled */ | 306 | /* output pin selection: enable CIR, with WB sensor enabled */ |
273 | val = nvt_cr_read(nvt, CR_OUTPUT_PIN_SEL); | 307 | val = nvt_cr_read(nvt, psreg); |
274 | val &= OUTPUT_PIN_SEL_MASK; | 308 | val &= psmask; |
275 | val |= (OUTPUT_ENABLE_CIR | OUTPUT_ENABLE_CIRWB); | 309 | val |= psval; |
276 | nvt_cr_write(nvt, val, CR_OUTPUT_PIN_SEL); | 310 | nvt_cr_write(nvt, val, psreg); |
277 | 311 | ||
278 | /* Select CIR logical device and enable */ | 312 | /* Select CIR logical device and enable */ |
279 | nvt_select_logical_dev(nvt, LOGICAL_DEV_CIR); | 313 | nvt_select_logical_dev(nvt, LOGICAL_DEV_CIR); |
@@ -640,7 +674,7 @@ static void nvt_process_rx_ir_data(struct nvt_dev *nvt) | |||
640 | rawir.pulse ? "pulse" : "space", | 674 | rawir.pulse ? "pulse" : "space", |
641 | rawir.duration); | 675 | rawir.duration); |
642 | 676 | ||
643 | ir_raw_event_store(nvt->rdev, &rawir); | 677 | ir_raw_event_store_with_filter(nvt->rdev, &rawir); |
644 | } | 678 | } |
645 | 679 | ||
646 | /* | 680 | /* |
@@ -1070,18 +1104,20 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) | |||
1070 | rdev->tx_ir = nvt_tx_ir; | 1104 | rdev->tx_ir = nvt_tx_ir; |
1071 | rdev->s_tx_carrier = nvt_set_tx_carrier; | 1105 | rdev->s_tx_carrier = nvt_set_tx_carrier; |
1072 | rdev->input_name = "Nuvoton w836x7hg Infrared Remote Transceiver"; | 1106 | rdev->input_name = "Nuvoton w836x7hg Infrared Remote Transceiver"; |
1107 | rdev->input_phys = "nuvoton/cir0"; | ||
1073 | rdev->input_id.bustype = BUS_HOST; | 1108 | rdev->input_id.bustype = BUS_HOST; |
1074 | rdev->input_id.vendor = PCI_VENDOR_ID_WINBOND2; | 1109 | rdev->input_id.vendor = PCI_VENDOR_ID_WINBOND2; |
1075 | rdev->input_id.product = nvt->chip_major; | 1110 | rdev->input_id.product = nvt->chip_major; |
1076 | rdev->input_id.version = nvt->chip_minor; | 1111 | rdev->input_id.version = nvt->chip_minor; |
1112 | rdev->dev.parent = &pdev->dev; | ||
1077 | rdev->driver_name = NVT_DRIVER_NAME; | 1113 | rdev->driver_name = NVT_DRIVER_NAME; |
1078 | rdev->map_name = RC_MAP_RC6_MCE; | 1114 | rdev->map_name = RC_MAP_RC6_MCE; |
1115 | rdev->timeout = US_TO_NS(1000); | ||
1116 | /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */ | ||
1117 | rdev->rx_resolution = US_TO_NS(CIR_SAMPLE_PERIOD); | ||
1079 | #if 0 | 1118 | #if 0 |
1080 | rdev->min_timeout = XYZ; | 1119 | rdev->min_timeout = XYZ; |
1081 | rdev->max_timeout = XYZ; | 1120 | rdev->max_timeout = XYZ; |
1082 | rdev->timeout = XYZ; | ||
1083 | /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */ | ||
1084 | rdev->rx_resolution = XYZ; | ||
1085 | /* tx bits */ | 1121 | /* tx bits */ |
1086 | rdev->tx_resolution = XYZ; | 1122 | rdev->tx_resolution = XYZ; |
1087 | #endif | 1123 | #endif |
@@ -1090,8 +1126,7 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) | |||
1090 | if (ret) | 1126 | if (ret) |
1091 | goto failure; | 1127 | goto failure; |
1092 | 1128 | ||
1093 | device_set_wakeup_capable(&pdev->dev, 1); | 1129 | device_init_wakeup(&pdev->dev, true); |
1094 | device_set_wakeup_enable(&pdev->dev, 1); | ||
1095 | nvt->rdev = rdev; | 1130 | nvt->rdev = rdev; |
1096 | nvt_pr(KERN_NOTICE, "driver has been successfully loaded\n"); | 1131 | nvt_pr(KERN_NOTICE, "driver has been successfully loaded\n"); |
1097 | if (debug) { | 1132 | if (debug) { |
diff --git a/drivers/media/rc/nuvoton-cir.h b/drivers/media/rc/nuvoton-cir.h index 048135eea702..379795d61ea7 100644 --- a/drivers/media/rc/nuvoton-cir.h +++ b/drivers/media/rc/nuvoton-cir.h | |||
@@ -330,9 +330,13 @@ struct nvt_dev { | |||
330 | #define EFER_EFM_DISABLE 0xaa | 330 | #define EFER_EFM_DISABLE 0xaa |
331 | 331 | ||
332 | /* Chip IDs found in CR_CHIP_ID_{HI,LO} */ | 332 | /* Chip IDs found in CR_CHIP_ID_{HI,LO} */ |
333 | #define CHIP_ID_HIGH 0xb4 | 333 | #define CHIP_ID_HIGH_667 0xa5 |
334 | #define CHIP_ID_LOW 0x72 | 334 | #define CHIP_ID_HIGH_677B 0xb4 |
335 | #define CHIP_ID_LOW2 0x73 | 335 | #define CHIP_ID_HIGH_677C 0xc3 |
336 | #define CHIP_ID_LOW_667 0x13 | ||
337 | #define CHIP_ID_LOW_677B2 0x72 | ||
338 | #define CHIP_ID_LOW_677B3 0x73 | ||
339 | #define CHIP_ID_LOW_677C 0x33 | ||
336 | 340 | ||
337 | /* Config regs we need to care about */ | 341 | /* Config regs we need to care about */ |
338 | #define CR_SOFTWARE_RESET 0x02 | 342 | #define CR_SOFTWARE_RESET 0x02 |
@@ -341,6 +345,7 @@ struct nvt_dev { | |||
341 | #define CR_CHIP_ID_LO 0x21 | 345 | #define CR_CHIP_ID_LO 0x21 |
342 | #define CR_DEV_POWER_DOWN 0x22 /* bit 2 is CIR power, default power on */ | 346 | #define CR_DEV_POWER_DOWN 0x22 /* bit 2 is CIR power, default power on */ |
343 | #define CR_OUTPUT_PIN_SEL 0x27 | 347 | #define CR_OUTPUT_PIN_SEL 0x27 |
348 | #define CR_MULTIFUNC_PIN_SEL 0x2c | ||
344 | #define CR_LOGICAL_DEV_EN 0x30 /* valid for all logical devices */ | 349 | #define CR_LOGICAL_DEV_EN 0x30 /* valid for all logical devices */ |
345 | /* next three regs valid for both the CIR and CIR_WAKE logical devices */ | 350 | /* next three regs valid for both the CIR and CIR_WAKE logical devices */ |
346 | #define CR_CIR_BASE_ADDR_HI 0x60 | 351 | #define CR_CIR_BASE_ADDR_HI 0x60 |
@@ -364,10 +369,16 @@ struct nvt_dev { | |||
364 | #define CIR_INTR_MOUSE_IRQ_BIT 0x80 | 369 | #define CIR_INTR_MOUSE_IRQ_BIT 0x80 |
365 | #define PME_INTR_CIR_PASS_BIT 0x08 | 370 | #define PME_INTR_CIR_PASS_BIT 0x08 |
366 | 371 | ||
372 | /* w83677hg CIR pin config */ | ||
367 | #define OUTPUT_PIN_SEL_MASK 0xbc | 373 | #define OUTPUT_PIN_SEL_MASK 0xbc |
368 | #define OUTPUT_ENABLE_CIR 0x01 /* Pin95=CIRRX, Pin96=CIRTX1 */ | 374 | #define OUTPUT_ENABLE_CIR 0x01 /* Pin95=CIRRX, Pin96=CIRTX1 */ |
369 | #define OUTPUT_ENABLE_CIRWB 0x40 /* enable wide-band sensor */ | 375 | #define OUTPUT_ENABLE_CIRWB 0x40 /* enable wide-band sensor */ |
370 | 376 | ||
377 | /* w83667hg CIR pin config */ | ||
378 | #define MULTIFUNC_PIN_SEL_MASK 0x1f | ||
379 | #define MULTIFUNC_ENABLE_CIR 0x80 /* Pin75=CIRRX, Pin76=CIRTX1 */ | ||
380 | #define MULTIFUNC_ENABLE_CIRWB 0x20 /* enable wide-band sensor */ | ||
381 | |||
371 | /* MCE CIR signal length, related on sample period */ | 382 | /* MCE CIR signal length, related on sample period */ |
372 | 383 | ||
373 | /* MCE CIR controller signal length: about 43ms | 384 | /* MCE CIR controller signal length: about 43ms |
diff --git a/drivers/media/rc/rc-loopback.c b/drivers/media/rc/rc-loopback.c index 49cee61d79c6..cc846b2619cf 100644 --- a/drivers/media/rc/rc-loopback.c +++ b/drivers/media/rc/rc-loopback.c | |||
@@ -146,6 +146,12 @@ static int loop_tx_ir(struct rc_dev *dev, int *txbuf, u32 n) | |||
146 | if (rawir.duration) | 146 | if (rawir.duration) |
147 | ir_raw_event_store_with_filter(dev, &rawir); | 147 | ir_raw_event_store_with_filter(dev, &rawir); |
148 | } | 148 | } |
149 | |||
150 | /* Fake a silence long enough to cause us to go idle */ | ||
151 | rawir.pulse = false; | ||
152 | rawir.duration = dev->timeout; | ||
153 | ir_raw_event_store_with_filter(dev, &rawir); | ||
154 | |||
149 | ir_raw_event_handle(dev); | 155 | ir_raw_event_handle(dev); |
150 | 156 | ||
151 | out: | 157 | out: |
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index a2706648e365..f57cd5677ac2 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c | |||
@@ -749,6 +749,9 @@ static struct { | |||
749 | * it is trigged by reading /sys/class/rc/rc?/protocols. | 749 | * it is trigged by reading /sys/class/rc/rc?/protocols. |
750 | * It returns the protocol names of supported protocols. | 750 | * It returns the protocol names of supported protocols. |
751 | * Enabled protocols are printed in brackets. | 751 | * Enabled protocols are printed in brackets. |
752 | * | ||
753 | * dev->lock is taken to guard against races between device | ||
754 | * registration, store_protocols and show_protocols. | ||
752 | */ | 755 | */ |
753 | static ssize_t show_protocols(struct device *device, | 756 | static ssize_t show_protocols(struct device *device, |
754 | struct device_attribute *mattr, char *buf) | 757 | struct device_attribute *mattr, char *buf) |
@@ -762,6 +765,8 @@ static ssize_t show_protocols(struct device *device, | |||
762 | if (!dev) | 765 | if (!dev) |
763 | return -EINVAL; | 766 | return -EINVAL; |
764 | 767 | ||
768 | mutex_lock(&dev->lock); | ||
769 | |||
765 | if (dev->driver_type == RC_DRIVER_SCANCODE) { | 770 | if (dev->driver_type == RC_DRIVER_SCANCODE) { |
766 | enabled = dev->rc_map.rc_type; | 771 | enabled = dev->rc_map.rc_type; |
767 | allowed = dev->allowed_protos; | 772 | allowed = dev->allowed_protos; |
@@ -784,6 +789,9 @@ static ssize_t show_protocols(struct device *device, | |||
784 | if (tmp != buf) | 789 | if (tmp != buf) |
785 | tmp--; | 790 | tmp--; |
786 | *tmp = '\n'; | 791 | *tmp = '\n'; |
792 | |||
793 | mutex_unlock(&dev->lock); | ||
794 | |||
787 | return tmp + 1 - buf; | 795 | return tmp + 1 - buf; |
788 | } | 796 | } |
789 | 797 | ||
@@ -802,6 +810,9 @@ static ssize_t show_protocols(struct device *device, | |||
802 | * Writing "none" will disable all protocols. | 810 | * Writing "none" will disable all protocols. |
803 | * Returns -EINVAL if an invalid protocol combination or unknown protocol name | 811 | * Returns -EINVAL if an invalid protocol combination or unknown protocol name |
804 | * is used, otherwise @len. | 812 | * is used, otherwise @len. |
813 | * | ||
814 | * dev->lock is taken to guard against races between device | ||
815 | * registration, store_protocols and show_protocols. | ||
805 | */ | 816 | */ |
806 | static ssize_t store_protocols(struct device *device, | 817 | static ssize_t store_protocols(struct device *device, |
807 | struct device_attribute *mattr, | 818 | struct device_attribute *mattr, |
@@ -815,18 +826,22 @@ static ssize_t store_protocols(struct device *device, | |||
815 | u64 mask; | 826 | u64 mask; |
816 | int rc, i, count = 0; | 827 | int rc, i, count = 0; |
817 | unsigned long flags; | 828 | unsigned long flags; |
829 | ssize_t ret; | ||
818 | 830 | ||
819 | /* Device is being removed */ | 831 | /* Device is being removed */ |
820 | if (!dev) | 832 | if (!dev) |
821 | return -EINVAL; | 833 | return -EINVAL; |
822 | 834 | ||
835 | mutex_lock(&dev->lock); | ||
836 | |||
823 | if (dev->driver_type == RC_DRIVER_SCANCODE) | 837 | if (dev->driver_type == RC_DRIVER_SCANCODE) |
824 | type = dev->rc_map.rc_type; | 838 | type = dev->rc_map.rc_type; |
825 | else if (dev->raw) | 839 | else if (dev->raw) |
826 | type = dev->raw->enabled_protocols; | 840 | type = dev->raw->enabled_protocols; |
827 | else { | 841 | else { |
828 | IR_dprintk(1, "Protocol switching not supported\n"); | 842 | IR_dprintk(1, "Protocol switching not supported\n"); |
829 | return -EINVAL; | 843 | ret = -EINVAL; |
844 | goto out; | ||
830 | } | 845 | } |
831 | 846 | ||
832 | while ((tmp = strsep((char **) &data, " \n")) != NULL) { | 847 | while ((tmp = strsep((char **) &data, " \n")) != NULL) { |
@@ -860,7 +875,8 @@ static ssize_t store_protocols(struct device *device, | |||
860 | } | 875 | } |
861 | if (i == ARRAY_SIZE(proto_names)) { | 876 | if (i == ARRAY_SIZE(proto_names)) { |
862 | IR_dprintk(1, "Unknown protocol: '%s'\n", tmp); | 877 | IR_dprintk(1, "Unknown protocol: '%s'\n", tmp); |
863 | return -EINVAL; | 878 | ret = -EINVAL; |
879 | goto out; | ||
864 | } | 880 | } |
865 | count++; | 881 | count++; |
866 | } | 882 | } |
@@ -875,7 +891,8 @@ static ssize_t store_protocols(struct device *device, | |||
875 | 891 | ||
876 | if (!count) { | 892 | if (!count) { |
877 | IR_dprintk(1, "Protocol not specified\n"); | 893 | IR_dprintk(1, "Protocol not specified\n"); |
878 | return -EINVAL; | 894 | ret = -EINVAL; |
895 | goto out; | ||
879 | } | 896 | } |
880 | 897 | ||
881 | if (dev->change_protocol) { | 898 | if (dev->change_protocol) { |
@@ -883,7 +900,8 @@ static ssize_t store_protocols(struct device *device, | |||
883 | if (rc < 0) { | 900 | if (rc < 0) { |
884 | IR_dprintk(1, "Error setting protocols to 0x%llx\n", | 901 | IR_dprintk(1, "Error setting protocols to 0x%llx\n", |
885 | (long long)type); | 902 | (long long)type); |
886 | return -EINVAL; | 903 | ret = -EINVAL; |
904 | goto out; | ||
887 | } | 905 | } |
888 | } | 906 | } |
889 | 907 | ||
@@ -898,7 +916,11 @@ static ssize_t store_protocols(struct device *device, | |||
898 | IR_dprintk(1, "Current protocol(s): 0x%llx\n", | 916 | IR_dprintk(1, "Current protocol(s): 0x%llx\n", |
899 | (long long)type); | 917 | (long long)type); |
900 | 918 | ||
901 | return len; | 919 | ret = len; |
920 | |||
921 | out: | ||
922 | mutex_unlock(&dev->lock); | ||
923 | return ret; | ||
902 | } | 924 | } |
903 | 925 | ||
904 | static void rc_dev_release(struct device *device) | 926 | static void rc_dev_release(struct device *device) |
@@ -974,6 +996,7 @@ struct rc_dev *rc_allocate_device(void) | |||
974 | 996 | ||
975 | spin_lock_init(&dev->rc_map.lock); | 997 | spin_lock_init(&dev->rc_map.lock); |
976 | spin_lock_init(&dev->keylock); | 998 | spin_lock_init(&dev->keylock); |
999 | mutex_init(&dev->lock); | ||
977 | setup_timer(&dev->timer_keyup, ir_timer_keyup, (unsigned long)dev); | 1000 | setup_timer(&dev->timer_keyup, ir_timer_keyup, (unsigned long)dev); |
978 | 1001 | ||
979 | dev->dev.type = &rc_dev_type; | 1002 | dev->dev.type = &rc_dev_type; |
@@ -1019,12 +1042,21 @@ int rc_register_device(struct rc_dev *dev) | |||
1019 | if (dev->close) | 1042 | if (dev->close) |
1020 | dev->input_dev->close = ir_close; | 1043 | dev->input_dev->close = ir_close; |
1021 | 1044 | ||
1045 | /* | ||
1046 | * Take the lock here, as the device sysfs node will appear | ||
1047 | * when device_add() is called, which may trigger an ir-keytable udev | ||
1048 | * rule, which will in turn call show_protocols and access either | ||
1049 | * dev->rc_map.rc_type or dev->raw->enabled_protocols before it has | ||
1050 | * been initialized. | ||
1051 | */ | ||
1052 | mutex_lock(&dev->lock); | ||
1053 | |||
1022 | dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1); | 1054 | dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1); |
1023 | dev_set_name(&dev->dev, "rc%ld", dev->devno); | 1055 | dev_set_name(&dev->dev, "rc%ld", dev->devno); |
1024 | dev_set_drvdata(&dev->dev, dev); | 1056 | dev_set_drvdata(&dev->dev, dev); |
1025 | rc = device_add(&dev->dev); | 1057 | rc = device_add(&dev->dev); |
1026 | if (rc) | 1058 | if (rc) |
1027 | return rc; | 1059 | goto out_unlock; |
1028 | 1060 | ||
1029 | rc = ir_setkeytable(dev, rc_map); | 1061 | rc = ir_setkeytable(dev, rc_map); |
1030 | if (rc) | 1062 | if (rc) |
@@ -1046,6 +1078,13 @@ int rc_register_device(struct rc_dev *dev) | |||
1046 | */ | 1078 | */ |
1047 | dev->input_dev->rep[REP_DELAY] = 500; | 1079 | dev->input_dev->rep[REP_DELAY] = 500; |
1048 | 1080 | ||
1081 | /* | ||
1082 | * As a repeat event on protocols like RC-5 and NEC take as long as | ||
1083 | * 110/114ms, using 33ms as a repeat period is not the right thing | ||
1084 | * to do. | ||
1085 | */ | ||
1086 | dev->input_dev->rep[REP_PERIOD] = 125; | ||
1087 | |||
1049 | path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); | 1088 | path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); |
1050 | printk(KERN_INFO "%s: %s as %s\n", | 1089 | printk(KERN_INFO "%s: %s as %s\n", |
1051 | dev_name(&dev->dev), | 1090 | dev_name(&dev->dev), |
@@ -1058,6 +1097,7 @@ int rc_register_device(struct rc_dev *dev) | |||
1058 | if (rc < 0) | 1097 | if (rc < 0) |
1059 | goto out_input; | 1098 | goto out_input; |
1060 | } | 1099 | } |
1100 | mutex_unlock(&dev->lock); | ||
1061 | 1101 | ||
1062 | if (dev->change_protocol) { | 1102 | if (dev->change_protocol) { |
1063 | rc = dev->change_protocol(dev, rc_map->rc_type); | 1103 | rc = dev->change_protocol(dev, rc_map->rc_type); |
@@ -1083,6 +1123,8 @@ out_table: | |||
1083 | ir_free_table(&dev->rc_map); | 1123 | ir_free_table(&dev->rc_map); |
1084 | out_dev: | 1124 | out_dev: |
1085 | device_del(&dev->dev); | 1125 | device_del(&dev->dev); |
1126 | out_unlock: | ||
1127 | mutex_unlock(&dev->lock); | ||
1086 | return rc; | 1128 | return rc; |
1087 | } | 1129 | } |
1088 | EXPORT_SYMBOL_GPL(rc_register_device); | 1130 | EXPORT_SYMBOL_GPL(rc_register_device); |
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c new file mode 100644 index 000000000000..5147767ccb78 --- /dev/null +++ b/drivers/media/rc/redrat3.c | |||
@@ -0,0 +1,1344 @@ | |||
1 | /* | ||
2 | * USB RedRat3 IR Transceiver rc-core driver | ||
3 | * | ||
4 | * Copyright (c) 2011 by Jarod Wilson <jarod@redhat.com> | ||
5 | * based heavily on the work of Stephen Cox, with additional | ||
6 | * help from RedRat Ltd. | ||
7 | * | ||
8 | * This driver began life based an an old version of the first-generation | ||
9 | * lirc_mceusb driver from the lirc 0.7.2 distribution. It was then | ||
10 | * significantly rewritten by Stephen Cox with the aid of RedRat Ltd's | ||
11 | * Chris Dodge. | ||
12 | * | ||
13 | * The driver was then ported to rc-core and significantly rewritten again, | ||
14 | * by Jarod, using the in-kernel mceusb driver as a guide, after an initial | ||
15 | * port effort was started by Stephen. | ||
16 | * | ||
17 | * TODO LIST: | ||
18 | * - fix lirc not showing repeats properly | ||
19 | * -- | ||
20 | * | ||
21 | * The RedRat3 is a USB transceiver with both send & receive, | ||
22 | * with 2 separate sensors available for receive to enable | ||
23 | * both good long range reception for general use, and good | ||
24 | * short range reception when required for learning a signal. | ||
25 | * | ||
26 | * http://www.redrat.co.uk/ | ||
27 | * | ||
28 | * It uses its own little protocol to communicate, the required | ||
29 | * parts of which are embedded within this driver. | ||
30 | * -- | ||
31 | * | ||
32 | * This program is free software; you can redistribute it and/or modify | ||
33 | * it under the terms of the GNU General Public License as published by | ||
34 | * the Free Software Foundation; either version 2 of the License, or | ||
35 | * (at your option) any later version. | ||
36 | * | ||
37 | * This program is distributed in the hope that it will be useful, | ||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
40 | * GNU General Public License for more details. | ||
41 | * | ||
42 | * You should have received a copy of the GNU General Public License | ||
43 | * along with this program; if not, write to the Free Software | ||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
45 | * | ||
46 | */ | ||
47 | |||
48 | #include <linux/device.h> | ||
49 | #include <linux/module.h> | ||
50 | #include <linux/slab.h> | ||
51 | #include <linux/usb.h> | ||
52 | #include <linux/usb/input.h> | ||
53 | #include <media/rc-core.h> | ||
54 | |||
55 | /* Driver Information */ | ||
56 | #define DRIVER_VERSION "0.70" | ||
57 | #define DRIVER_AUTHOR "Jarod Wilson <jarod@redhat.com>" | ||
58 | #define DRIVER_AUTHOR2 "The Dweller, Stephen Cox" | ||
59 | #define DRIVER_DESC "RedRat3 USB IR Transceiver Driver" | ||
60 | #define DRIVER_NAME "redrat3" | ||
61 | |||
62 | /* module parameters */ | ||
63 | #ifdef CONFIG_USB_DEBUG | ||
64 | static int debug = 1; | ||
65 | #else | ||
66 | static int debug; | ||
67 | #endif | ||
68 | |||
69 | #define RR3_DEBUG_STANDARD 0x1 | ||
70 | #define RR3_DEBUG_FUNCTION_TRACE 0x2 | ||
71 | |||
72 | #define rr3_dbg(dev, fmt, ...) \ | ||
73 | do { \ | ||
74 | if (debug & RR3_DEBUG_STANDARD) \ | ||
75 | dev_info(dev, fmt, ## __VA_ARGS__); \ | ||
76 | } while (0) | ||
77 | |||
78 | #define rr3_ftr(dev, fmt, ...) \ | ||
79 | do { \ | ||
80 | if (debug & RR3_DEBUG_FUNCTION_TRACE) \ | ||
81 | dev_info(dev, fmt, ## __VA_ARGS__); \ | ||
82 | } while (0) | ||
83 | |||
84 | /* bulk data transfer types */ | ||
85 | #define RR3_ERROR 0x01 | ||
86 | #define RR3_MOD_SIGNAL_IN 0x20 | ||
87 | #define RR3_MOD_SIGNAL_OUT 0x21 | ||
88 | |||
89 | /* Get the RR firmware version */ | ||
90 | #define RR3_FW_VERSION 0xb1 | ||
91 | #define RR3_FW_VERSION_LEN 64 | ||
92 | /* Send encoded signal bulk-sent earlier*/ | ||
93 | #define RR3_TX_SEND_SIGNAL 0xb3 | ||
94 | #define RR3_SET_IR_PARAM 0xb7 | ||
95 | #define RR3_GET_IR_PARAM 0xb8 | ||
96 | /* Blink the red LED on the device */ | ||
97 | #define RR3_BLINK_LED 0xb9 | ||
98 | /* Read serial number of device */ | ||
99 | #define RR3_READ_SER_NO 0xba | ||
100 | #define RR3_SER_NO_LEN 4 | ||
101 | /* Start capture with the RC receiver */ | ||
102 | #define RR3_RC_DET_ENABLE 0xbb | ||
103 | /* Stop capture with the RC receiver */ | ||
104 | #define RR3_RC_DET_DISABLE 0xbc | ||
105 | /* Return the status of RC detector capture */ | ||
106 | #define RR3_RC_DET_STATUS 0xbd | ||
107 | /* Reset redrat */ | ||
108 | #define RR3_RESET 0xa0 | ||
109 | |||
110 | /* Max number of lengths in the signal. */ | ||
111 | #define RR3_IR_IO_MAX_LENGTHS 0x01 | ||
112 | /* Periods to measure mod. freq. */ | ||
113 | #define RR3_IR_IO_PERIODS_MF 0x02 | ||
114 | /* Size of memory for main signal data */ | ||
115 | #define RR3_IR_IO_SIG_MEM_SIZE 0x03 | ||
116 | /* Delta value when measuring lengths */ | ||
117 | #define RR3_IR_IO_LENGTH_FUZZ 0x04 | ||
118 | /* Timeout for end of signal detection */ | ||
119 | #define RR3_IR_IO_SIG_TIMEOUT 0x05 | ||
120 | /* Minumum value for pause recognition. */ | ||
121 | #define RR3_IR_IO_MIN_PAUSE 0x06 | ||
122 | |||
123 | /* Clock freq. of EZ-USB chip */ | ||
124 | #define RR3_CLK 24000000 | ||
125 | /* Clock periods per timer count */ | ||
126 | #define RR3_CLK_PER_COUNT 12 | ||
127 | /* (RR3_CLK / RR3_CLK_PER_COUNT) */ | ||
128 | #define RR3_CLK_CONV_FACTOR 2000000 | ||
129 | /* USB bulk-in IR data endpoint address */ | ||
130 | #define RR3_BULK_IN_EP_ADDR 0x82 | ||
131 | |||
132 | /* Raw Modulated signal data value offsets */ | ||
133 | #define RR3_PAUSE_OFFSET 0 | ||
134 | #define RR3_FREQ_COUNT_OFFSET 4 | ||
135 | #define RR3_NUM_PERIOD_OFFSET 6 | ||
136 | #define RR3_MAX_LENGTHS_OFFSET 8 | ||
137 | #define RR3_NUM_LENGTHS_OFFSET 9 | ||
138 | #define RR3_MAX_SIGS_OFFSET 10 | ||
139 | #define RR3_NUM_SIGS_OFFSET 12 | ||
140 | #define RR3_REPEATS_OFFSET 14 | ||
141 | |||
142 | /* Size of the fixed-length portion of the signal */ | ||
143 | #define RR3_HEADER_LENGTH 15 | ||
144 | #define RR3_DRIVER_MAXLENS 128 | ||
145 | #define RR3_MAX_SIG_SIZE 512 | ||
146 | #define RR3_MAX_BUF_SIZE \ | ||
147 | ((2 * RR3_HEADER_LENGTH) + RR3_DRIVER_MAXLENS + RR3_MAX_SIG_SIZE) | ||
148 | #define RR3_TIME_UNIT 50 | ||
149 | #define RR3_END_OF_SIGNAL 0x7f | ||
150 | #define RR3_TX_HEADER_OFFSET 4 | ||
151 | #define RR3_TX_TRAILER_LEN 2 | ||
152 | #define RR3_RX_MIN_TIMEOUT 5 | ||
153 | #define RR3_RX_MAX_TIMEOUT 2000 | ||
154 | |||
155 | /* The 8051's CPUCS Register address */ | ||
156 | #define RR3_CPUCS_REG_ADDR 0x7f92 | ||
157 | |||
158 | #define USB_RR3USB_VENDOR_ID 0x112a | ||
159 | #define USB_RR3USB_PRODUCT_ID 0x0001 | ||
160 | #define USB_RR3IIUSB_PRODUCT_ID 0x0005 | ||
161 | |||
162 | /* table of devices that work with this driver */ | ||
163 | static struct usb_device_id redrat3_dev_table[] = { | ||
164 | /* Original version of the RedRat3 */ | ||
165 | {USB_DEVICE(USB_RR3USB_VENDOR_ID, USB_RR3USB_PRODUCT_ID)}, | ||
166 | /* Second Version/release of the RedRat3 - RetRat3-II */ | ||
167 | {USB_DEVICE(USB_RR3USB_VENDOR_ID, USB_RR3IIUSB_PRODUCT_ID)}, | ||
168 | {} /* Terminating entry */ | ||
169 | }; | ||
170 | |||
171 | /* Structure to hold all of our device specific stuff */ | ||
172 | struct redrat3_dev { | ||
173 | /* core device bits */ | ||
174 | struct rc_dev *rc; | ||
175 | struct device *dev; | ||
176 | |||
177 | /* save off the usb device pointer */ | ||
178 | struct usb_device *udev; | ||
179 | |||
180 | /* the receive endpoint */ | ||
181 | struct usb_endpoint_descriptor *ep_in; | ||
182 | /* the buffer to receive data */ | ||
183 | unsigned char *bulk_in_buf; | ||
184 | /* urb used to read ir data */ | ||
185 | struct urb *read_urb; | ||
186 | |||
187 | /* the send endpoint */ | ||
188 | struct usb_endpoint_descriptor *ep_out; | ||
189 | /* the buffer to send data */ | ||
190 | unsigned char *bulk_out_buf; | ||
191 | /* the urb used to send data */ | ||
192 | struct urb *write_urb; | ||
193 | |||
194 | /* usb dma */ | ||
195 | dma_addr_t dma_in; | ||
196 | dma_addr_t dma_out; | ||
197 | |||
198 | /* true if write urb is busy */ | ||
199 | bool write_busy; | ||
200 | /* wait for the write to finish */ | ||
201 | struct completion write_finished; | ||
202 | |||
203 | /* locks this structure */ | ||
204 | struct mutex lock; | ||
205 | |||
206 | /* rx signal timeout timer */ | ||
207 | struct timer_list rx_timeout; | ||
208 | |||
209 | /* Is the device currently receiving? */ | ||
210 | bool recv_in_progress; | ||
211 | /* is the detector enabled*/ | ||
212 | bool det_enabled; | ||
213 | /* Is the device currently transmitting?*/ | ||
214 | bool transmitting; | ||
215 | |||
216 | /* store for current packet */ | ||
217 | char pbuf[RR3_MAX_BUF_SIZE]; | ||
218 | u16 pktlen; | ||
219 | u16 pkttype; | ||
220 | u16 bytes_read; | ||
221 | /* indicate whether we are going to reprocess | ||
222 | * the USB callback with a bigger buffer */ | ||
223 | int buftoosmall; | ||
224 | char *datap; | ||
225 | |||
226 | u32 carrier; | ||
227 | |||
228 | char name[128]; | ||
229 | char phys[64]; | ||
230 | }; | ||
231 | |||
232 | /* All incoming data buffers adhere to a very specific data format */ | ||
233 | struct redrat3_signal_header { | ||
234 | u16 length; /* Length of data being transferred */ | ||
235 | u16 transfer_type; /* Type of data transferred */ | ||
236 | u32 pause; /* Pause between main and repeat signals */ | ||
237 | u16 mod_freq_count; /* Value of timer on mod. freq. measurement */ | ||
238 | u16 no_periods; /* No. of periods over which mod. freq. is measured */ | ||
239 | u8 max_lengths; /* Max no. of lengths (i.e. size of array) */ | ||
240 | u8 no_lengths; /* Actual no. of elements in lengths array */ | ||
241 | u16 max_sig_size; /* Max no. of values in signal data array */ | ||
242 | u16 sig_size; /* Acuto no. of values in signal data array */ | ||
243 | u8 no_repeats; /* No. of repeats of repeat signal section */ | ||
244 | /* Here forward is the lengths and signal data */ | ||
245 | }; | ||
246 | |||
247 | static void redrat3_dump_signal_header(struct redrat3_signal_header *header) | ||
248 | { | ||
249 | pr_info("%s:\n", __func__); | ||
250 | pr_info(" * length: %u, transfer_type: 0x%02x\n", | ||
251 | header->length, header->transfer_type); | ||
252 | pr_info(" * pause: %u, freq_count: %u, no_periods: %u\n", | ||
253 | header->pause, header->mod_freq_count, header->no_periods); | ||
254 | pr_info(" * lengths: %u (max: %u)\n", | ||
255 | header->no_lengths, header->max_lengths); | ||
256 | pr_info(" * sig_size: %u (max: %u)\n", | ||
257 | header->sig_size, header->max_sig_size); | ||
258 | pr_info(" * repeats: %u\n", header->no_repeats); | ||
259 | } | ||
260 | |||
261 | static void redrat3_dump_signal_data(char *buffer, u16 len) | ||
262 | { | ||
263 | int offset, i; | ||
264 | char *data_vals; | ||
265 | |||
266 | pr_info("%s:", __func__); | ||
267 | |||
268 | offset = RR3_TX_HEADER_OFFSET + RR3_HEADER_LENGTH | ||
269 | + (RR3_DRIVER_MAXLENS * sizeof(u16)); | ||
270 | |||
271 | /* read RR3_DRIVER_MAXLENS from ctrl msg */ | ||
272 | data_vals = buffer + offset; | ||
273 | |||
274 | for (i = 0; i < len; i++) { | ||
275 | if (i % 10 == 0) | ||
276 | pr_cont("\n * "); | ||
277 | pr_cont("%02x ", *data_vals++); | ||
278 | } | ||
279 | |||
280 | pr_cont("\n"); | ||
281 | } | ||
282 | |||
283 | /* | ||
284 | * redrat3_issue_async | ||
285 | * | ||
286 | * Issues an async read to the ir data in port.. | ||
287 | * sets the callback to be redrat3_handle_async | ||
288 | */ | ||
289 | static void redrat3_issue_async(struct redrat3_dev *rr3) | ||
290 | { | ||
291 | int res; | ||
292 | |||
293 | rr3_ftr(rr3->dev, "Entering %s\n", __func__); | ||
294 | |||
295 | if (!rr3->det_enabled) { | ||
296 | dev_warn(rr3->dev, "not issuing async read, " | ||
297 | "detector not enabled\n"); | ||
298 | return; | ||
299 | } | ||
300 | |||
301 | memset(rr3->bulk_in_buf, 0, rr3->ep_in->wMaxPacketSize); | ||
302 | res = usb_submit_urb(rr3->read_urb, GFP_ATOMIC); | ||
303 | if (res) | ||
304 | rr3_dbg(rr3->dev, "%s: receive request FAILED! " | ||
305 | "(res %d, len %d)\n", __func__, res, | ||
306 | rr3->read_urb->transfer_buffer_length); | ||
307 | } | ||
308 | |||
309 | static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code) | ||
310 | { | ||
311 | if (!rr3->transmitting && (code != 0x40)) | ||
312 | dev_info(rr3->dev, "fw error code 0x%02x: ", code); | ||
313 | |||
314 | switch (code) { | ||
315 | case 0x00: | ||
316 | pr_cont("No Error\n"); | ||
317 | break; | ||
318 | |||
319 | /* Codes 0x20 through 0x2f are IR Firmware Errors */ | ||
320 | case 0x20: | ||
321 | pr_cont("Initial signal pulse not long enough " | ||
322 | "to measure carrier frequency\n"); | ||
323 | break; | ||
324 | case 0x21: | ||
325 | pr_cont("Not enough length values allocated for signal\n"); | ||
326 | break; | ||
327 | case 0x22: | ||
328 | pr_cont("Not enough memory allocated for signal data\n"); | ||
329 | break; | ||
330 | case 0x23: | ||
331 | pr_cont("Too many signal repeats\n"); | ||
332 | break; | ||
333 | case 0x28: | ||
334 | pr_cont("Insufficient memory available for IR signal " | ||
335 | "data memory allocation\n"); | ||
336 | break; | ||
337 | case 0x29: | ||
338 | pr_cont("Insufficient memory available " | ||
339 | "for IrDa signal data memory allocation\n"); | ||
340 | break; | ||
341 | |||
342 | /* Codes 0x30 through 0x3f are USB Firmware Errors */ | ||
343 | case 0x30: | ||
344 | pr_cont("Insufficient memory available for bulk " | ||
345 | "transfer structure\n"); | ||
346 | break; | ||
347 | |||
348 | /* | ||
349 | * Other error codes... These are primarily errors that can occur in | ||
350 | * the control messages sent to the redrat | ||
351 | */ | ||
352 | case 0x40: | ||
353 | if (!rr3->transmitting) | ||
354 | pr_cont("Signal capture has been terminated\n"); | ||
355 | break; | ||
356 | case 0x41: | ||
357 | pr_cont("Attempt to set/get and unknown signal I/O " | ||
358 | "algorithm parameter\n"); | ||
359 | break; | ||
360 | case 0x42: | ||
361 | pr_cont("Signal capture already started\n"); | ||
362 | break; | ||
363 | |||
364 | default: | ||
365 | pr_cont("Unknown Error\n"); | ||
366 | break; | ||
367 | } | ||
368 | } | ||
369 | |||
370 | static u32 redrat3_val_to_mod_freq(struct redrat3_signal_header *ph) | ||
371 | { | ||
372 | u32 mod_freq = 0; | ||
373 | |||
374 | if (ph->mod_freq_count != 0) | ||
375 | mod_freq = (RR3_CLK * ph->no_periods) / | ||
376 | (ph->mod_freq_count * RR3_CLK_PER_COUNT); | ||
377 | |||
378 | return mod_freq; | ||
379 | } | ||
380 | |||
381 | /* this function scales down the figures for the same result... */ | ||
382 | static u32 redrat3_len_to_us(u32 length) | ||
383 | { | ||
384 | u32 biglen = length * 1000; | ||
385 | u32 divisor = (RR3_CLK_CONV_FACTOR) / 1000; | ||
386 | u32 result = (u32) (biglen / divisor); | ||
387 | |||
388 | /* don't allow zero lengths to go back, breaks lirc */ | ||
389 | return result ? result : 1; | ||
390 | } | ||
391 | |||
392 | /* | ||
393 | * convert us back into redrat3 lengths | ||
394 | * | ||
395 | * length * 1000 length * 1000000 | ||
396 | * ------------- = ---------------- = micro | ||
397 | * rr3clk / 1000 rr3clk | ||
398 | |||
399 | * 6 * 2 4 * 3 micro * rr3clk micro * rr3clk / 1000 | ||
400 | * ----- = 4 ----- = 6 -------------- = len --------------------- | ||
401 | * 3 2 1000000 1000 | ||
402 | */ | ||
403 | static u32 redrat3_us_to_len(u32 microsec) | ||
404 | { | ||
405 | u32 result; | ||
406 | u32 divisor; | ||
407 | |||
408 | microsec &= IR_MAX_DURATION; | ||
409 | divisor = (RR3_CLK_CONV_FACTOR / 1000); | ||
410 | result = (u32)(microsec * divisor) / 1000; | ||
411 | |||
412 | /* don't allow zero lengths to go back, breaks lirc */ | ||
413 | return result ? result : 1; | ||
414 | |||
415 | } | ||
416 | |||
417 | /* timer callback to send long trailing space on receive timeout */ | ||
418 | static void redrat3_rx_timeout(unsigned long data) | ||
419 | { | ||
420 | struct redrat3_dev *rr3 = (struct redrat3_dev *)data; | ||
421 | DEFINE_IR_RAW_EVENT(rawir); | ||
422 | |||
423 | rawir.pulse = false; | ||
424 | rawir.duration = rr3->rc->timeout; | ||
425 | rr3_dbg(rr3->dev, "storing trailing space with duration %d\n", | ||
426 | rawir.duration); | ||
427 | ir_raw_event_store_with_filter(rr3->rc, &rawir); | ||
428 | |||
429 | rr3_dbg(rr3->dev, "calling ir_raw_event_handle\n"); | ||
430 | ir_raw_event_handle(rr3->rc); | ||
431 | |||
432 | rr3_dbg(rr3->dev, "calling ir_raw_event_reset\n"); | ||
433 | ir_raw_event_reset(rr3->rc); | ||
434 | } | ||
435 | |||
436 | static void redrat3_process_ir_data(struct redrat3_dev *rr3) | ||
437 | { | ||
438 | DEFINE_IR_RAW_EVENT(rawir); | ||
439 | struct redrat3_signal_header header; | ||
440 | struct device *dev; | ||
441 | int i; | ||
442 | unsigned long delay; | ||
443 | u32 mod_freq, single_len; | ||
444 | u16 *len_vals; | ||
445 | u8 *data_vals; | ||
446 | u32 tmp32; | ||
447 | u16 tmp16; | ||
448 | char *sig_data; | ||
449 | |||
450 | if (!rr3) { | ||
451 | pr_err("%s called with no context!\n", __func__); | ||
452 | return; | ||
453 | } | ||
454 | |||
455 | rr3_ftr(rr3->dev, "Entered %s\n", __func__); | ||
456 | |||
457 | dev = rr3->dev; | ||
458 | sig_data = rr3->pbuf; | ||
459 | |||
460 | header.length = rr3->pktlen; | ||
461 | header.transfer_type = rr3->pkttype; | ||
462 | |||
463 | /* Sanity check */ | ||
464 | if (!(header.length >= RR3_HEADER_LENGTH)) | ||
465 | dev_warn(dev, "read returned less than rr3 header len\n"); | ||
466 | |||
467 | delay = usecs_to_jiffies(rr3->rc->timeout / 1000); | ||
468 | mod_timer(&rr3->rx_timeout, jiffies + delay); | ||
469 | |||
470 | memcpy(&tmp32, sig_data + RR3_PAUSE_OFFSET, sizeof(tmp32)); | ||
471 | header.pause = be32_to_cpu(tmp32); | ||
472 | |||
473 | memcpy(&tmp16, sig_data + RR3_FREQ_COUNT_OFFSET, sizeof(tmp16)); | ||
474 | header.mod_freq_count = be16_to_cpu(tmp16); | ||
475 | |||
476 | memcpy(&tmp16, sig_data + RR3_NUM_PERIOD_OFFSET, sizeof(tmp16)); | ||
477 | header.no_periods = be16_to_cpu(tmp16); | ||
478 | |||
479 | header.max_lengths = sig_data[RR3_MAX_LENGTHS_OFFSET]; | ||
480 | header.no_lengths = sig_data[RR3_NUM_LENGTHS_OFFSET]; | ||
481 | |||
482 | memcpy(&tmp16, sig_data + RR3_MAX_SIGS_OFFSET, sizeof(tmp16)); | ||
483 | header.max_sig_size = be16_to_cpu(tmp16); | ||
484 | |||
485 | memcpy(&tmp16, sig_data + RR3_NUM_SIGS_OFFSET, sizeof(tmp16)); | ||
486 | header.sig_size = be16_to_cpu(tmp16); | ||
487 | |||
488 | header.no_repeats= sig_data[RR3_REPEATS_OFFSET]; | ||
489 | |||
490 | if (debug) { | ||
491 | redrat3_dump_signal_header(&header); | ||
492 | redrat3_dump_signal_data(sig_data, header.sig_size); | ||
493 | } | ||
494 | |||
495 | mod_freq = redrat3_val_to_mod_freq(&header); | ||
496 | rr3_dbg(dev, "Got mod_freq of %u\n", mod_freq); | ||
497 | |||
498 | /* Here we pull out the 'length' values from the signal */ | ||
499 | len_vals = (u16 *)(sig_data + RR3_HEADER_LENGTH); | ||
500 | |||
501 | data_vals = sig_data + RR3_HEADER_LENGTH + | ||
502 | (header.max_lengths * sizeof(u16)); | ||
503 | |||
504 | /* process each rr3 encoded byte into an int */ | ||
505 | for (i = 0; i < header.sig_size; i++) { | ||
506 | u16 val = len_vals[data_vals[i]]; | ||
507 | single_len = redrat3_len_to_us((u32)be16_to_cpu(val)); | ||
508 | |||
509 | /* cap the value to IR_MAX_DURATION */ | ||
510 | single_len &= IR_MAX_DURATION; | ||
511 | |||
512 | /* we should always get pulse/space/pulse/space samples */ | ||
513 | if (i % 2) | ||
514 | rawir.pulse = false; | ||
515 | else | ||
516 | rawir.pulse = true; | ||
517 | |||
518 | rawir.duration = US_TO_NS(single_len); | ||
519 | rr3_dbg(dev, "storing %s with duration %d (i: %d)\n", | ||
520 | rawir.pulse ? "pulse" : "space", rawir.duration, i); | ||
521 | ir_raw_event_store_with_filter(rr3->rc, &rawir); | ||
522 | } | ||
523 | |||
524 | /* add a trailing space, if need be */ | ||
525 | if (i % 2) { | ||
526 | rawir.pulse = false; | ||
527 | /* this duration is made up, and may not be ideal... */ | ||
528 | rawir.duration = rr3->rc->timeout / 2; | ||
529 | rr3_dbg(dev, "storing trailing space with duration %d\n", | ||
530 | rawir.duration); | ||
531 | ir_raw_event_store_with_filter(rr3->rc, &rawir); | ||
532 | } | ||
533 | |||
534 | rr3_dbg(dev, "calling ir_raw_event_handle\n"); | ||
535 | ir_raw_event_handle(rr3->rc); | ||
536 | |||
537 | return; | ||
538 | } | ||
539 | |||
540 | /* Util fn to send rr3 cmds */ | ||
541 | static u8 redrat3_send_cmd(int cmd, struct redrat3_dev *rr3) | ||
542 | { | ||
543 | struct usb_device *udev; | ||
544 | u8 *data; | ||
545 | int res; | ||
546 | |||
547 | data = kzalloc(sizeof(u8), GFP_KERNEL); | ||
548 | if (!data) | ||
549 | return -ENOMEM; | ||
550 | |||
551 | udev = rr3->udev; | ||
552 | res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), cmd, | ||
553 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
554 | 0x0000, 0x0000, data, sizeof(u8), HZ * 10); | ||
555 | |||
556 | if (res < 0) { | ||
557 | dev_err(rr3->dev, "%s: Error sending rr3 cmd res %d, data %d", | ||
558 | __func__, res, *data); | ||
559 | res = -EIO; | ||
560 | } else | ||
561 | res = (u8)data[0]; | ||
562 | |||
563 | kfree(data); | ||
564 | |||
565 | return res; | ||
566 | } | ||
567 | |||
568 | /* Enables the long range detector and starts async receive */ | ||
569 | static int redrat3_enable_detector(struct redrat3_dev *rr3) | ||
570 | { | ||
571 | struct device *dev = rr3->dev; | ||
572 | u8 ret; | ||
573 | |||
574 | rr3_ftr(dev, "Entering %s\n", __func__); | ||
575 | |||
576 | ret = redrat3_send_cmd(RR3_RC_DET_ENABLE, rr3); | ||
577 | if (ret != 0) | ||
578 | dev_dbg(dev, "%s: unexpected ret of %d\n", | ||
579 | __func__, ret); | ||
580 | |||
581 | ret = redrat3_send_cmd(RR3_RC_DET_STATUS, rr3); | ||
582 | if (ret != 1) { | ||
583 | dev_err(dev, "%s: detector status: %d, should be 1\n", | ||
584 | __func__, ret); | ||
585 | return -EIO; | ||
586 | } | ||
587 | |||
588 | rr3->det_enabled = true; | ||
589 | redrat3_issue_async(rr3); | ||
590 | |||
591 | return 0; | ||
592 | } | ||
593 | |||
594 | /* Disables the rr3 long range detector */ | ||
595 | static void redrat3_disable_detector(struct redrat3_dev *rr3) | ||
596 | { | ||
597 | struct device *dev = rr3->dev; | ||
598 | u8 ret; | ||
599 | |||
600 | rr3_ftr(dev, "Entering %s\n", __func__); | ||
601 | |||
602 | ret = redrat3_send_cmd(RR3_RC_DET_DISABLE, rr3); | ||
603 | if (ret != 0) | ||
604 | dev_err(dev, "%s: failure!\n", __func__); | ||
605 | |||
606 | ret = redrat3_send_cmd(RR3_RC_DET_STATUS, rr3); | ||
607 | if (ret != 0) | ||
608 | dev_warn(dev, "%s: detector status: %d, should be 0\n", | ||
609 | __func__, ret); | ||
610 | |||
611 | rr3->det_enabled = false; | ||
612 | } | ||
613 | |||
614 | static inline void redrat3_delete(struct redrat3_dev *rr3, | ||
615 | struct usb_device *udev) | ||
616 | { | ||
617 | rr3_ftr(rr3->dev, "%s cleaning up\n", __func__); | ||
618 | usb_kill_urb(rr3->read_urb); | ||
619 | usb_kill_urb(rr3->write_urb); | ||
620 | |||
621 | usb_free_urb(rr3->read_urb); | ||
622 | usb_free_urb(rr3->write_urb); | ||
623 | |||
624 | usb_free_coherent(udev, rr3->ep_in->wMaxPacketSize, | ||
625 | rr3->bulk_in_buf, rr3->dma_in); | ||
626 | usb_free_coherent(udev, rr3->ep_out->wMaxPacketSize, | ||
627 | rr3->bulk_out_buf, rr3->dma_out); | ||
628 | |||
629 | kfree(rr3); | ||
630 | } | ||
631 | |||
632 | static u32 redrat3_get_timeout(struct device *dev, | ||
633 | struct rc_dev *rc, struct usb_device *udev) | ||
634 | { | ||
635 | u32 *tmp; | ||
636 | u32 timeout = MS_TO_NS(150); /* a sane default, if things go haywire */ | ||
637 | int len, ret, pipe; | ||
638 | |||
639 | len = sizeof(*tmp); | ||
640 | tmp = kzalloc(len, GFP_KERNEL); | ||
641 | if (!tmp) { | ||
642 | dev_warn(dev, "Memory allocation faillure\n"); | ||
643 | return timeout; | ||
644 | } | ||
645 | |||
646 | pipe = usb_rcvctrlpipe(udev, 0); | ||
647 | ret = usb_control_msg(udev, pipe, RR3_GET_IR_PARAM, | ||
648 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
649 | RR3_IR_IO_SIG_TIMEOUT, 0, tmp, len, HZ * 5); | ||
650 | if (ret != len) { | ||
651 | dev_warn(dev, "Failed to read timeout from hardware\n"); | ||
652 | return timeout; | ||
653 | } | ||
654 | |||
655 | timeout = US_TO_NS(redrat3_len_to_us(be32_to_cpu(*tmp))); | ||
656 | if (timeout < rc->min_timeout) | ||
657 | timeout = rc->min_timeout; | ||
658 | else if (timeout > rc->max_timeout) | ||
659 | timeout = rc->max_timeout; | ||
660 | |||
661 | rr3_dbg(dev, "Got timeout of %d ms\n", timeout / (1000 * 1000)); | ||
662 | return timeout; | ||
663 | } | ||
664 | |||
665 | static void redrat3_reset(struct redrat3_dev *rr3) | ||
666 | { | ||
667 | struct usb_device *udev = rr3->udev; | ||
668 | struct device *dev = rr3->dev; | ||
669 | int rc, rxpipe, txpipe; | ||
670 | u8 *val; | ||
671 | int len = sizeof(u8); | ||
672 | |||
673 | rr3_ftr(dev, "Entering %s\n", __func__); | ||
674 | |||
675 | rxpipe = usb_rcvctrlpipe(udev, 0); | ||
676 | txpipe = usb_sndctrlpipe(udev, 0); | ||
677 | |||
678 | val = kzalloc(len, GFP_KERNEL); | ||
679 | if (!val) { | ||
680 | dev_err(dev, "Memory allocation failure\n"); | ||
681 | return; | ||
682 | } | ||
683 | |||
684 | *val = 0x01; | ||
685 | rc = usb_control_msg(udev, rxpipe, RR3_RESET, | ||
686 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
687 | RR3_CPUCS_REG_ADDR, 0, val, len, HZ * 25); | ||
688 | rr3_dbg(dev, "reset returned 0x%02x\n", rc); | ||
689 | |||
690 | *val = 5; | ||
691 | rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM, | ||
692 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, | ||
693 | RR3_IR_IO_LENGTH_FUZZ, 0, val, len, HZ * 25); | ||
694 | rr3_dbg(dev, "set ir parm len fuzz %d rc 0x%02x\n", *val, rc); | ||
695 | |||
696 | *val = RR3_DRIVER_MAXLENS; | ||
697 | rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM, | ||
698 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, | ||
699 | RR3_IR_IO_MAX_LENGTHS, 0, val, len, HZ * 25); | ||
700 | rr3_dbg(dev, "set ir parm max lens %d rc 0x%02x\n", *val, rc); | ||
701 | |||
702 | kfree(val); | ||
703 | } | ||
704 | |||
705 | static void redrat3_get_firmware_rev(struct redrat3_dev *rr3) | ||
706 | { | ||
707 | int rc = 0; | ||
708 | char *buffer; | ||
709 | |||
710 | rr3_ftr(rr3->dev, "Entering %s\n", __func__); | ||
711 | |||
712 | buffer = kzalloc(sizeof(char) * (RR3_FW_VERSION_LEN + 1), GFP_KERNEL); | ||
713 | if (!buffer) { | ||
714 | dev_err(rr3->dev, "Memory allocation failure\n"); | ||
715 | return; | ||
716 | } | ||
717 | |||
718 | rc = usb_control_msg(rr3->udev, usb_rcvctrlpipe(rr3->udev, 0), | ||
719 | RR3_FW_VERSION, | ||
720 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
721 | 0, 0, buffer, RR3_FW_VERSION_LEN, HZ * 5); | ||
722 | |||
723 | if (rc >= 0) | ||
724 | dev_info(rr3->dev, "Firmware rev: %s", buffer); | ||
725 | else | ||
726 | dev_err(rr3->dev, "Problem fetching firmware ID\n"); | ||
727 | |||
728 | kfree(buffer); | ||
729 | rr3_ftr(rr3->dev, "Exiting %s\n", __func__); | ||
730 | } | ||
731 | |||
732 | static void redrat3_read_packet_start(struct redrat3_dev *rr3, int len) | ||
733 | { | ||
734 | u16 tx_error; | ||
735 | u16 hdrlen; | ||
736 | |||
737 | rr3_ftr(rr3->dev, "Entering %s\n", __func__); | ||
738 | |||
739 | /* grab the Length and type of transfer */ | ||
740 | memcpy(&(rr3->pktlen), (unsigned char *) rr3->bulk_in_buf, | ||
741 | sizeof(rr3->pktlen)); | ||
742 | memcpy(&(rr3->pkttype), ((unsigned char *) rr3->bulk_in_buf + | ||
743 | sizeof(rr3->pktlen)), | ||
744 | sizeof(rr3->pkttype)); | ||
745 | |||
746 | /*data needs conversion to know what its real values are*/ | ||
747 | rr3->pktlen = be16_to_cpu(rr3->pktlen); | ||
748 | rr3->pkttype = be16_to_cpu(rr3->pkttype); | ||
749 | |||
750 | switch (rr3->pkttype) { | ||
751 | case RR3_ERROR: | ||
752 | memcpy(&tx_error, ((unsigned char *)rr3->bulk_in_buf | ||
753 | + (sizeof(rr3->pktlen) + sizeof(rr3->pkttype))), | ||
754 | sizeof(tx_error)); | ||
755 | tx_error = be16_to_cpu(tx_error); | ||
756 | redrat3_dump_fw_error(rr3, tx_error); | ||
757 | break; | ||
758 | |||
759 | case RR3_MOD_SIGNAL_IN: | ||
760 | hdrlen = sizeof(rr3->pktlen) + sizeof(rr3->pkttype); | ||
761 | rr3->bytes_read = len; | ||
762 | rr3->bytes_read -= hdrlen; | ||
763 | rr3->datap = &(rr3->pbuf[0]); | ||
764 | |||
765 | memcpy(rr3->datap, ((unsigned char *)rr3->bulk_in_buf + hdrlen), | ||
766 | rr3->bytes_read); | ||
767 | rr3->datap += rr3->bytes_read; | ||
768 | rr3_dbg(rr3->dev, "bytes_read %d, pktlen %d\n", | ||
769 | rr3->bytes_read, rr3->pktlen); | ||
770 | break; | ||
771 | |||
772 | default: | ||
773 | rr3_dbg(rr3->dev, "ignoring packet with type 0x%02x, " | ||
774 | "len of %d, 0x%02x\n", rr3->pkttype, len, rr3->pktlen); | ||
775 | break; | ||
776 | } | ||
777 | } | ||
778 | |||
779 | static void redrat3_read_packet_continue(struct redrat3_dev *rr3, int len) | ||
780 | { | ||
781 | |||
782 | rr3_ftr(rr3->dev, "Entering %s\n", __func__); | ||
783 | |||
784 | memcpy(rr3->datap, (unsigned char *)rr3->bulk_in_buf, len); | ||
785 | rr3->datap += len; | ||
786 | |||
787 | rr3->bytes_read += len; | ||
788 | rr3_dbg(rr3->dev, "bytes_read %d, pktlen %d\n", | ||
789 | rr3->bytes_read, rr3->pktlen); | ||
790 | } | ||
791 | |||
792 | /* gather IR data from incoming urb, process it when we have enough */ | ||
793 | static int redrat3_get_ir_data(struct redrat3_dev *rr3, int len) | ||
794 | { | ||
795 | struct device *dev = rr3->dev; | ||
796 | int ret = 0; | ||
797 | |||
798 | rr3_ftr(dev, "Entering %s\n", __func__); | ||
799 | |||
800 | if (rr3->pktlen > RR3_MAX_BUF_SIZE) { | ||
801 | dev_err(rr3->dev, "error: packet larger than buffer\n"); | ||
802 | ret = -EINVAL; | ||
803 | goto out; | ||
804 | } | ||
805 | |||
806 | if ((rr3->bytes_read == 0) && | ||
807 | (len >= (sizeof(rr3->pkttype) + sizeof(rr3->pktlen)))) { | ||
808 | redrat3_read_packet_start(rr3, len); | ||
809 | } else if (rr3->bytes_read != 0) { | ||
810 | redrat3_read_packet_continue(rr3, len); | ||
811 | } else if (rr3->bytes_read == 0) { | ||
812 | dev_err(dev, "error: no packet data read\n"); | ||
813 | ret = -ENODATA; | ||
814 | goto out; | ||
815 | } | ||
816 | |||
817 | if (rr3->bytes_read > rr3->pktlen) { | ||
818 | dev_err(dev, "bytes_read (%d) greater than pktlen (%d)\n", | ||
819 | rr3->bytes_read, rr3->pktlen); | ||
820 | ret = -EINVAL; | ||
821 | goto out; | ||
822 | } else if (rr3->bytes_read < rr3->pktlen) | ||
823 | /* we're still accumulating data */ | ||
824 | return 0; | ||
825 | |||
826 | /* if we get here, we've got IR data to decode */ | ||
827 | if (rr3->pkttype == RR3_MOD_SIGNAL_IN) | ||
828 | redrat3_process_ir_data(rr3); | ||
829 | else | ||
830 | rr3_dbg(dev, "discarding non-signal data packet " | ||
831 | "(type 0x%02x)\n", rr3->pkttype); | ||
832 | |||
833 | out: | ||
834 | rr3->bytes_read = 0; | ||
835 | rr3->pktlen = 0; | ||
836 | rr3->pkttype = 0; | ||
837 | return ret; | ||
838 | } | ||
839 | |||
840 | /* callback function from USB when async USB request has completed */ | ||
841 | static void redrat3_handle_async(struct urb *urb, struct pt_regs *regs) | ||
842 | { | ||
843 | struct redrat3_dev *rr3; | ||
844 | |||
845 | if (!urb) | ||
846 | return; | ||
847 | |||
848 | rr3 = urb->context; | ||
849 | if (!rr3) { | ||
850 | pr_err("%s called with invalid context!\n", __func__); | ||
851 | usb_unlink_urb(urb); | ||
852 | return; | ||
853 | } | ||
854 | |||
855 | rr3_ftr(rr3->dev, "Entering %s\n", __func__); | ||
856 | |||
857 | if (!rr3->det_enabled) { | ||
858 | rr3_dbg(rr3->dev, "received a read callback but detector " | ||
859 | "disabled - ignoring\n"); | ||
860 | return; | ||
861 | } | ||
862 | |||
863 | switch (urb->status) { | ||
864 | case 0: | ||
865 | redrat3_get_ir_data(rr3, urb->actual_length); | ||
866 | break; | ||
867 | |||
868 | case -ECONNRESET: | ||
869 | case -ENOENT: | ||
870 | case -ESHUTDOWN: | ||
871 | usb_unlink_urb(urb); | ||
872 | return; | ||
873 | |||
874 | case -EPIPE: | ||
875 | default: | ||
876 | dev_warn(rr3->dev, "Error: urb status = %d\n", urb->status); | ||
877 | rr3->bytes_read = 0; | ||
878 | rr3->pktlen = 0; | ||
879 | rr3->pkttype = 0; | ||
880 | break; | ||
881 | } | ||
882 | |||
883 | if (!rr3->transmitting) | ||
884 | redrat3_issue_async(rr3); | ||
885 | else | ||
886 | rr3_dbg(rr3->dev, "IR transmit in progress\n"); | ||
887 | } | ||
888 | |||
889 | static void redrat3_write_bulk_callback(struct urb *urb, struct pt_regs *regs) | ||
890 | { | ||
891 | struct redrat3_dev *rr3; | ||
892 | int len; | ||
893 | |||
894 | if (!urb) | ||
895 | return; | ||
896 | |||
897 | rr3 = urb->context; | ||
898 | if (rr3) { | ||
899 | len = urb->actual_length; | ||
900 | rr3_ftr(rr3->dev, "%s: called (status=%d len=%d)\n", | ||
901 | __func__, urb->status, len); | ||
902 | } | ||
903 | } | ||
904 | |||
905 | static u16 mod_freq_to_val(unsigned int mod_freq) | ||
906 | { | ||
907 | int mult = 6000000; | ||
908 | |||
909 | /* Clk used in mod. freq. generation is CLK24/4. */ | ||
910 | return (u16)(65536 - (mult / mod_freq)); | ||
911 | } | ||
912 | |||
913 | static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier) | ||
914 | { | ||
915 | struct redrat3_dev *rr3 = dev->priv; | ||
916 | |||
917 | rr3->carrier = carrier; | ||
918 | |||
919 | return carrier; | ||
920 | } | ||
921 | |||
922 | static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n) | ||
923 | { | ||
924 | struct redrat3_dev *rr3 = rcdev->priv; | ||
925 | struct device *dev = rr3->dev; | ||
926 | struct redrat3_signal_header header; | ||
927 | int i, j, count, ret, ret_len, offset; | ||
928 | int lencheck, cur_sample_len, pipe; | ||
929 | char *buffer = NULL, *sigdata = NULL; | ||
930 | int *sample_lens = NULL; | ||
931 | u32 tmpi; | ||
932 | u16 tmps; | ||
933 | u8 *datap; | ||
934 | u8 curlencheck = 0; | ||
935 | u16 *lengths_ptr; | ||
936 | int sendbuf_len; | ||
937 | |||
938 | rr3_ftr(dev, "Entering %s\n", __func__); | ||
939 | |||
940 | if (rr3->transmitting) { | ||
941 | dev_warn(dev, "%s: transmitter already in use\n", __func__); | ||
942 | return -EAGAIN; | ||
943 | } | ||
944 | |||
945 | count = n / sizeof(int); | ||
946 | if (count > (RR3_DRIVER_MAXLENS * 2)) | ||
947 | return -EINVAL; | ||
948 | |||
949 | rr3->transmitting = true; | ||
950 | |||
951 | redrat3_disable_detector(rr3); | ||
952 | |||
953 | if (rr3->det_enabled) { | ||
954 | dev_err(dev, "%s: cannot tx while rx is enabled\n", __func__); | ||
955 | ret = -EIO; | ||
956 | goto out; | ||
957 | } | ||
958 | |||
959 | sample_lens = kzalloc(sizeof(int) * RR3_DRIVER_MAXLENS, GFP_KERNEL); | ||
960 | if (!sample_lens) { | ||
961 | ret = -ENOMEM; | ||
962 | goto out; | ||
963 | } | ||
964 | |||
965 | for (i = 0; i < count; i++) { | ||
966 | for (lencheck = 0; lencheck < curlencheck; lencheck++) { | ||
967 | cur_sample_len = redrat3_us_to_len(txbuf[i]); | ||
968 | if (sample_lens[lencheck] == cur_sample_len) | ||
969 | break; | ||
970 | } | ||
971 | if (lencheck == curlencheck) { | ||
972 | cur_sample_len = redrat3_us_to_len(txbuf[i]); | ||
973 | rr3_dbg(dev, "txbuf[%d]=%u, pos %d, enc %u\n", | ||
974 | i, txbuf[i], curlencheck, cur_sample_len); | ||
975 | if (curlencheck < 255) { | ||
976 | /* now convert the value to a proper | ||
977 | * rr3 value.. */ | ||
978 | sample_lens[curlencheck] = cur_sample_len; | ||
979 | curlencheck++; | ||
980 | } else { | ||
981 | dev_err(dev, "signal too long\n"); | ||
982 | ret = -EINVAL; | ||
983 | goto out; | ||
984 | } | ||
985 | } | ||
986 | } | ||
987 | |||
988 | sigdata = kzalloc((count + RR3_TX_TRAILER_LEN), GFP_KERNEL); | ||
989 | if (!sigdata) { | ||
990 | ret = -ENOMEM; | ||
991 | goto out; | ||
992 | } | ||
993 | |||
994 | sigdata[count] = RR3_END_OF_SIGNAL; | ||
995 | sigdata[count + 1] = RR3_END_OF_SIGNAL; | ||
996 | for (i = 0; i < count; i++) { | ||
997 | for (j = 0; j < curlencheck; j++) { | ||
998 | if (sample_lens[j] == redrat3_us_to_len(txbuf[i])) | ||
999 | sigdata[i] = j; | ||
1000 | } | ||
1001 | } | ||
1002 | |||
1003 | offset = RR3_TX_HEADER_OFFSET; | ||
1004 | sendbuf_len = RR3_HEADER_LENGTH + (sizeof(u16) * RR3_DRIVER_MAXLENS) | ||
1005 | + count + RR3_TX_TRAILER_LEN + offset; | ||
1006 | |||
1007 | buffer = kzalloc(sendbuf_len, GFP_KERNEL); | ||
1008 | if (!buffer) { | ||
1009 | ret = -ENOMEM; | ||
1010 | goto out; | ||
1011 | } | ||
1012 | |||
1013 | /* fill in our packet header */ | ||
1014 | header.length = sendbuf_len - offset; | ||
1015 | header.transfer_type = RR3_MOD_SIGNAL_OUT; | ||
1016 | header.pause = redrat3_len_to_us(100); | ||
1017 | header.mod_freq_count = mod_freq_to_val(rr3->carrier); | ||
1018 | header.no_periods = 0; /* n/a to transmit */ | ||
1019 | header.max_lengths = RR3_DRIVER_MAXLENS; | ||
1020 | header.no_lengths = curlencheck; | ||
1021 | header.max_sig_size = RR3_MAX_SIG_SIZE; | ||
1022 | header.sig_size = count + RR3_TX_TRAILER_LEN; | ||
1023 | /* we currently rely on repeat handling in the IR encoding source */ | ||
1024 | header.no_repeats = 0; | ||
1025 | |||
1026 | tmps = cpu_to_be16(header.length); | ||
1027 | memcpy(buffer, &tmps, 2); | ||
1028 | |||
1029 | tmps = cpu_to_be16(header.transfer_type); | ||
1030 | memcpy(buffer + 2, &tmps, 2); | ||
1031 | |||
1032 | tmpi = cpu_to_be32(header.pause); | ||
1033 | memcpy(buffer + offset, &tmpi, sizeof(tmpi)); | ||
1034 | |||
1035 | tmps = cpu_to_be16(header.mod_freq_count); | ||
1036 | memcpy(buffer + offset + RR3_FREQ_COUNT_OFFSET, &tmps, 2); | ||
1037 | |||
1038 | buffer[offset + RR3_NUM_LENGTHS_OFFSET] = header.no_lengths; | ||
1039 | |||
1040 | tmps = cpu_to_be16(header.sig_size); | ||
1041 | memcpy(buffer + offset + RR3_NUM_SIGS_OFFSET, &tmps, 2); | ||
1042 | |||
1043 | buffer[offset + RR3_REPEATS_OFFSET] = header.no_repeats; | ||
1044 | |||
1045 | lengths_ptr = (u16 *)(buffer + offset + RR3_HEADER_LENGTH); | ||
1046 | for (i = 0; i < curlencheck; ++i) | ||
1047 | lengths_ptr[i] = cpu_to_be16(sample_lens[i]); | ||
1048 | |||
1049 | datap = (u8 *)(buffer + offset + RR3_HEADER_LENGTH + | ||
1050 | (sizeof(u16) * RR3_DRIVER_MAXLENS)); | ||
1051 | memcpy(datap, sigdata, (count + RR3_TX_TRAILER_LEN)); | ||
1052 | |||
1053 | if (debug) { | ||
1054 | redrat3_dump_signal_header(&header); | ||
1055 | redrat3_dump_signal_data(buffer, header.sig_size); | ||
1056 | } | ||
1057 | |||
1058 | pipe = usb_sndbulkpipe(rr3->udev, rr3->ep_out->bEndpointAddress); | ||
1059 | tmps = usb_bulk_msg(rr3->udev, pipe, buffer, | ||
1060 | sendbuf_len, &ret_len, 10 * HZ); | ||
1061 | rr3_dbg(dev, "sent %d bytes, (ret %d)\n", ret_len, tmps); | ||
1062 | |||
1063 | /* now tell the hardware to transmit what we sent it */ | ||
1064 | pipe = usb_rcvctrlpipe(rr3->udev, 0); | ||
1065 | ret = usb_control_msg(rr3->udev, pipe, RR3_TX_SEND_SIGNAL, | ||
1066 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
1067 | 0, 0, buffer, 2, HZ * 10); | ||
1068 | |||
1069 | if (ret < 0) | ||
1070 | dev_err(dev, "Error: control msg send failed, rc %d\n", ret); | ||
1071 | else | ||
1072 | ret = n; | ||
1073 | |||
1074 | out: | ||
1075 | kfree(sample_lens); | ||
1076 | kfree(buffer); | ||
1077 | kfree(sigdata); | ||
1078 | |||
1079 | rr3->transmitting = false; | ||
1080 | |||
1081 | redrat3_enable_detector(rr3); | ||
1082 | |||
1083 | return ret; | ||
1084 | } | ||
1085 | |||
1086 | static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) | ||
1087 | { | ||
1088 | struct device *dev = rr3->dev; | ||
1089 | struct rc_dev *rc; | ||
1090 | int ret = -ENODEV; | ||
1091 | u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct); | ||
1092 | |||
1093 | rc = rc_allocate_device(); | ||
1094 | if (!rc) { | ||
1095 | dev_err(dev, "remote input dev allocation failed\n"); | ||
1096 | goto out; | ||
1097 | } | ||
1098 | |||
1099 | snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s " | ||
1100 | "Infrared Remote Transceiver (%04x:%04x)", | ||
1101 | prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "", | ||
1102 | le16_to_cpu(rr3->udev->descriptor.idVendor), prod); | ||
1103 | |||
1104 | usb_make_path(rr3->udev, rr3->phys, sizeof(rr3->phys)); | ||
1105 | |||
1106 | rc->input_name = rr3->name; | ||
1107 | rc->input_phys = rr3->phys; | ||
1108 | usb_to_input_id(rr3->udev, &rc->input_id); | ||
1109 | rc->dev.parent = dev; | ||
1110 | rc->priv = rr3; | ||
1111 | rc->driver_type = RC_DRIVER_IR_RAW; | ||
1112 | rc->allowed_protos = RC_TYPE_ALL; | ||
1113 | rc->min_timeout = MS_TO_NS(RR3_RX_MIN_TIMEOUT); | ||
1114 | rc->max_timeout = MS_TO_NS(RR3_RX_MAX_TIMEOUT); | ||
1115 | rc->timeout = redrat3_get_timeout(dev, rc, rr3->udev); | ||
1116 | rc->tx_ir = redrat3_transmit_ir; | ||
1117 | rc->s_tx_carrier = redrat3_set_tx_carrier; | ||
1118 | rc->driver_name = DRIVER_NAME; | ||
1119 | rc->map_name = RC_MAP_HAUPPAUGE; | ||
1120 | |||
1121 | ret = rc_register_device(rc); | ||
1122 | if (ret < 0) { | ||
1123 | dev_err(dev, "remote dev registration failed\n"); | ||
1124 | goto out; | ||
1125 | } | ||
1126 | |||
1127 | return rc; | ||
1128 | |||
1129 | out: | ||
1130 | rc_free_device(rc); | ||
1131 | return NULL; | ||
1132 | } | ||
1133 | |||
1134 | static int __devinit redrat3_dev_probe(struct usb_interface *intf, | ||
1135 | const struct usb_device_id *id) | ||
1136 | { | ||
1137 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1138 | struct device *dev = &intf->dev; | ||
1139 | struct usb_host_interface *uhi; | ||
1140 | struct redrat3_dev *rr3; | ||
1141 | struct usb_endpoint_descriptor *ep; | ||
1142 | struct usb_endpoint_descriptor *ep_in = NULL; | ||
1143 | struct usb_endpoint_descriptor *ep_out = NULL; | ||
1144 | u8 addr, attrs; | ||
1145 | int pipe, i; | ||
1146 | int retval = -ENOMEM; | ||
1147 | |||
1148 | rr3_ftr(dev, "%s called\n", __func__); | ||
1149 | |||
1150 | uhi = intf->cur_altsetting; | ||
1151 | |||
1152 | /* find our bulk-in and bulk-out endpoints */ | ||
1153 | for (i = 0; i < uhi->desc.bNumEndpoints; ++i) { | ||
1154 | ep = &uhi->endpoint[i].desc; | ||
1155 | addr = ep->bEndpointAddress; | ||
1156 | attrs = ep->bmAttributes; | ||
1157 | |||
1158 | if ((ep_in == NULL) && | ||
1159 | ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) && | ||
1160 | ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == | ||
1161 | USB_ENDPOINT_XFER_BULK)) { | ||
1162 | rr3_dbg(dev, "found bulk-in endpoint at 0x%02x\n", | ||
1163 | ep->bEndpointAddress); | ||
1164 | /* data comes in on 0x82, 0x81 is for other data... */ | ||
1165 | if (ep->bEndpointAddress == RR3_BULK_IN_EP_ADDR) | ||
1166 | ep_in = ep; | ||
1167 | } | ||
1168 | |||
1169 | if ((ep_out == NULL) && | ||
1170 | ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) && | ||
1171 | ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == | ||
1172 | USB_ENDPOINT_XFER_BULK)) { | ||
1173 | rr3_dbg(dev, "found bulk-out endpoint at 0x%02x\n", | ||
1174 | ep->bEndpointAddress); | ||
1175 | ep_out = ep; | ||
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | if (!ep_in || !ep_out) { | ||
1180 | dev_err(dev, "Couldn't find both in and out endpoints\n"); | ||
1181 | retval = -ENODEV; | ||
1182 | goto no_endpoints; | ||
1183 | } | ||
1184 | |||
1185 | /* allocate memory for our device state and initialize it */ | ||
1186 | rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL); | ||
1187 | if (rr3 == NULL) { | ||
1188 | dev_err(dev, "Memory allocation failure\n"); | ||
1189 | goto error; | ||
1190 | } | ||
1191 | |||
1192 | rr3->dev = &intf->dev; | ||
1193 | |||
1194 | /* set up bulk-in endpoint */ | ||
1195 | rr3->read_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
1196 | if (!rr3->read_urb) { | ||
1197 | dev_err(dev, "Read urb allocation failure\n"); | ||
1198 | goto error; | ||
1199 | } | ||
1200 | |||
1201 | rr3->ep_in = ep_in; | ||
1202 | rr3->bulk_in_buf = usb_alloc_coherent(udev, ep_in->wMaxPacketSize, | ||
1203 | GFP_ATOMIC, &rr3->dma_in); | ||
1204 | if (!rr3->bulk_in_buf) { | ||
1205 | dev_err(dev, "Read buffer allocation failure\n"); | ||
1206 | goto error; | ||
1207 | } | ||
1208 | |||
1209 | pipe = usb_rcvbulkpipe(udev, ep_in->bEndpointAddress); | ||
1210 | usb_fill_bulk_urb(rr3->read_urb, udev, pipe, | ||
1211 | rr3->bulk_in_buf, ep_in->wMaxPacketSize, | ||
1212 | (usb_complete_t)redrat3_handle_async, rr3); | ||
1213 | |||
1214 | /* set up bulk-out endpoint*/ | ||
1215 | rr3->write_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
1216 | if (!rr3->write_urb) { | ||
1217 | dev_err(dev, "Write urb allocation failure\n"); | ||
1218 | goto error; | ||
1219 | } | ||
1220 | |||
1221 | rr3->ep_out = ep_out; | ||
1222 | rr3->bulk_out_buf = usb_alloc_coherent(udev, ep_out->wMaxPacketSize, | ||
1223 | GFP_ATOMIC, &rr3->dma_out); | ||
1224 | if (!rr3->bulk_out_buf) { | ||
1225 | dev_err(dev, "Write buffer allocation failure\n"); | ||
1226 | goto error; | ||
1227 | } | ||
1228 | |||
1229 | pipe = usb_sndbulkpipe(udev, ep_out->bEndpointAddress); | ||
1230 | usb_fill_bulk_urb(rr3->write_urb, udev, pipe, | ||
1231 | rr3->bulk_out_buf, ep_out->wMaxPacketSize, | ||
1232 | (usb_complete_t)redrat3_write_bulk_callback, rr3); | ||
1233 | |||
1234 | mutex_init(&rr3->lock); | ||
1235 | rr3->udev = udev; | ||
1236 | |||
1237 | redrat3_reset(rr3); | ||
1238 | redrat3_get_firmware_rev(rr3); | ||
1239 | |||
1240 | /* might be all we need to do? */ | ||
1241 | retval = redrat3_enable_detector(rr3); | ||
1242 | if (retval < 0) | ||
1243 | goto error; | ||
1244 | |||
1245 | /* default.. will get overridden by any sends with a freq defined */ | ||
1246 | rr3->carrier = 38000; | ||
1247 | |||
1248 | rr3->rc = redrat3_init_rc_dev(rr3); | ||
1249 | if (!rr3->rc) | ||
1250 | goto error; | ||
1251 | |||
1252 | setup_timer(&rr3->rx_timeout, redrat3_rx_timeout, (unsigned long)rr3); | ||
1253 | |||
1254 | /* we can register the device now, as it is ready */ | ||
1255 | usb_set_intfdata(intf, rr3); | ||
1256 | |||
1257 | rr3_ftr(dev, "Exiting %s\n", __func__); | ||
1258 | return 0; | ||
1259 | |||
1260 | error: | ||
1261 | redrat3_delete(rr3, rr3->udev); | ||
1262 | |||
1263 | no_endpoints: | ||
1264 | dev_err(dev, "%s: retval = %x", __func__, retval); | ||
1265 | |||
1266 | return retval; | ||
1267 | } | ||
1268 | |||
1269 | static void __devexit redrat3_dev_disconnect(struct usb_interface *intf) | ||
1270 | { | ||
1271 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1272 | struct redrat3_dev *rr3 = usb_get_intfdata(intf); | ||
1273 | |||
1274 | rr3_ftr(&intf->dev, "Entering %s\n", __func__); | ||
1275 | |||
1276 | if (!rr3) | ||
1277 | return; | ||
1278 | |||
1279 | redrat3_disable_detector(rr3); | ||
1280 | |||
1281 | usb_set_intfdata(intf, NULL); | ||
1282 | rc_unregister_device(rr3->rc); | ||
1283 | redrat3_delete(rr3, udev); | ||
1284 | |||
1285 | rr3_ftr(&intf->dev, "RedRat3 IR Transceiver now disconnected\n"); | ||
1286 | } | ||
1287 | |||
1288 | static int redrat3_dev_suspend(struct usb_interface *intf, pm_message_t message) | ||
1289 | { | ||
1290 | struct redrat3_dev *rr3 = usb_get_intfdata(intf); | ||
1291 | rr3_ftr(rr3->dev, "suspend\n"); | ||
1292 | usb_kill_urb(rr3->read_urb); | ||
1293 | return 0; | ||
1294 | } | ||
1295 | |||
1296 | static int redrat3_dev_resume(struct usb_interface *intf) | ||
1297 | { | ||
1298 | struct redrat3_dev *rr3 = usb_get_intfdata(intf); | ||
1299 | rr3_ftr(rr3->dev, "resume\n"); | ||
1300 | if (usb_submit_urb(rr3->read_urb, GFP_ATOMIC)) | ||
1301 | return -EIO; | ||
1302 | return 0; | ||
1303 | } | ||
1304 | |||
1305 | static struct usb_driver redrat3_dev_driver = { | ||
1306 | .name = DRIVER_NAME, | ||
1307 | .probe = redrat3_dev_probe, | ||
1308 | .disconnect = redrat3_dev_disconnect, | ||
1309 | .suspend = redrat3_dev_suspend, | ||
1310 | .resume = redrat3_dev_resume, | ||
1311 | .reset_resume = redrat3_dev_resume, | ||
1312 | .id_table = redrat3_dev_table | ||
1313 | }; | ||
1314 | |||
1315 | static int __init redrat3_dev_init(void) | ||
1316 | { | ||
1317 | int ret; | ||
1318 | |||
1319 | ret = usb_register(&redrat3_dev_driver); | ||
1320 | if (ret < 0) | ||
1321 | pr_err(DRIVER_NAME | ||
1322 | ": usb register failed, result = %d\n", ret); | ||
1323 | |||
1324 | return ret; | ||
1325 | } | ||
1326 | |||
1327 | static void __exit redrat3_dev_exit(void) | ||
1328 | { | ||
1329 | usb_deregister(&redrat3_dev_driver); | ||
1330 | } | ||
1331 | |||
1332 | module_init(redrat3_dev_init); | ||
1333 | module_exit(redrat3_dev_exit); | ||
1334 | |||
1335 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
1336 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
1337 | MODULE_AUTHOR(DRIVER_AUTHOR2); | ||
1338 | MODULE_LICENSE("GPL"); | ||
1339 | MODULE_DEVICE_TABLE(usb, redrat3_dev_table); | ||
1340 | |||
1341 | module_param(debug, int, S_IRUGO | S_IWUSR); | ||
1342 | MODULE_PARM_DESC(debug, "Enable module debug spew. 0 = no debugging (default) " | ||
1343 | "0x1 = standard debug messages, 0x2 = function tracing debug. " | ||
1344 | "Flag bits are addative (i.e., 0x3 for both debug types)."); | ||
diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c index 186de5522001..5d06b899e859 100644 --- a/drivers/media/rc/winbond-cir.c +++ b/drivers/media/rc/winbond-cir.c | |||
@@ -19,11 +19,12 @@ | |||
19 | * o DSDT dumps | 19 | * o DSDT dumps |
20 | * | 20 | * |
21 | * Supported features: | 21 | * Supported features: |
22 | * o IR Receive | ||
23 | * o IR Transmit | ||
22 | * o Wake-On-CIR functionality | 24 | * o Wake-On-CIR functionality |
23 | * | 25 | * |
24 | * To do: | 26 | * To do: |
25 | * o Learning | 27 | * o Learning |
26 | * o IR Transmit | ||
27 | * | 28 | * |
28 | * This program is free software; you can redistribute it and/or modify | 29 | * This program is free software; you can redistribute it and/or modify |
29 | * it under the terms of the GNU General Public License as published by | 30 | * it under the terms of the GNU General Public License as published by |
@@ -50,6 +51,8 @@ | |||
50 | #include <linux/io.h> | 51 | #include <linux/io.h> |
51 | #include <linux/bitrev.h> | 52 | #include <linux/bitrev.h> |
52 | #include <linux/slab.h> | 53 | #include <linux/slab.h> |
54 | #include <linux/wait.h> | ||
55 | #include <linux/sched.h> | ||
53 | #include <media/rc-core.h> | 56 | #include <media/rc-core.h> |
54 | 57 | ||
55 | #define DRVNAME "winbond-cir" | 58 | #define DRVNAME "winbond-cir" |
@@ -118,14 +121,24 @@ | |||
118 | #define WBCIR_IRQ_NONE 0x00 | 121 | #define WBCIR_IRQ_NONE 0x00 |
119 | /* RX data bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | 122 | /* RX data bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ |
120 | #define WBCIR_IRQ_RX 0x01 | 123 | #define WBCIR_IRQ_RX 0x01 |
124 | /* TX data low bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
125 | #define WBCIR_IRQ_TX_LOW 0x02 | ||
121 | /* Over/Under-flow bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | 126 | /* Over/Under-flow bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ |
122 | #define WBCIR_IRQ_ERR 0x04 | 127 | #define WBCIR_IRQ_ERR 0x04 |
128 | /* TX data empty bit for WBCEIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
129 | #define WBCIR_IRQ_TX_EMPTY 0x20 | ||
123 | /* Led enable/disable bit for WBCIR_REG_ECEIR_CTS */ | 130 | /* Led enable/disable bit for WBCIR_REG_ECEIR_CTS */ |
124 | #define WBCIR_LED_ENABLE 0x80 | 131 | #define WBCIR_LED_ENABLE 0x80 |
125 | /* RX data available bit for WBCIR_REG_SP3_LSR */ | 132 | /* RX data available bit for WBCIR_REG_SP3_LSR */ |
126 | #define WBCIR_RX_AVAIL 0x01 | 133 | #define WBCIR_RX_AVAIL 0x01 |
134 | /* RX data overrun error bit for WBCIR_REG_SP3_LSR */ | ||
135 | #define WBCIR_RX_OVERRUN 0x02 | ||
136 | /* TX End-Of-Transmission bit for WBCIR_REG_SP3_ASCR */ | ||
137 | #define WBCIR_TX_EOT 0x04 | ||
127 | /* RX disable bit for WBCIR_REG_SP3_ASCR */ | 138 | /* RX disable bit for WBCIR_REG_SP3_ASCR */ |
128 | #define WBCIR_RX_DISABLE 0x20 | 139 | #define WBCIR_RX_DISABLE 0x20 |
140 | /* TX data underrun error bit for WBCIR_REG_SP3_ASCR */ | ||
141 | #define WBCIR_TX_UNDERRUN 0x40 | ||
129 | /* Extended mode enable bit for WBCIR_REG_SP3_EXCR1 */ | 142 | /* Extended mode enable bit for WBCIR_REG_SP3_EXCR1 */ |
130 | #define WBCIR_EXT_ENABLE 0x01 | 143 | #define WBCIR_EXT_ENABLE 0x01 |
131 | /* Select compare register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ | 144 | /* Select compare register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ |
@@ -154,6 +167,21 @@ enum wbcir_protocol { | |||
154 | IR_PROTOCOL_RC6 = 0x2, | 167 | IR_PROTOCOL_RC6 = 0x2, |
155 | }; | 168 | }; |
156 | 169 | ||
170 | /* Possible states for IR reception */ | ||
171 | enum wbcir_rxstate { | ||
172 | WBCIR_RXSTATE_INACTIVE = 0, | ||
173 | WBCIR_RXSTATE_ACTIVE, | ||
174 | WBCIR_RXSTATE_ERROR | ||
175 | }; | ||
176 | |||
177 | /* Possible states for IR transmission */ | ||
178 | enum wbcir_txstate { | ||
179 | WBCIR_TXSTATE_INACTIVE = 0, | ||
180 | WBCIR_TXSTATE_ACTIVE, | ||
181 | WBCIR_TXSTATE_DONE, | ||
182 | WBCIR_TXSTATE_ERROR | ||
183 | }; | ||
184 | |||
157 | /* Misc */ | 185 | /* Misc */ |
158 | #define WBCIR_NAME "Winbond CIR" | 186 | #define WBCIR_NAME "Winbond CIR" |
159 | #define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */ | 187 | #define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */ |
@@ -166,22 +194,29 @@ enum wbcir_protocol { | |||
166 | /* Per-device data */ | 194 | /* Per-device data */ |
167 | struct wbcir_data { | 195 | struct wbcir_data { |
168 | spinlock_t spinlock; | 196 | spinlock_t spinlock; |
197 | struct rc_dev *dev; | ||
198 | struct led_classdev led; | ||
169 | 199 | ||
170 | unsigned long wbase; /* Wake-Up Baseaddr */ | 200 | unsigned long wbase; /* Wake-Up Baseaddr */ |
171 | unsigned long ebase; /* Enhanced Func. Baseaddr */ | 201 | unsigned long ebase; /* Enhanced Func. Baseaddr */ |
172 | unsigned long sbase; /* Serial Port Baseaddr */ | 202 | unsigned long sbase; /* Serial Port Baseaddr */ |
173 | unsigned int irq; /* Serial Port IRQ */ | 203 | unsigned int irq; /* Serial Port IRQ */ |
204 | u8 irqmask; | ||
174 | 205 | ||
175 | struct rc_dev *dev; | 206 | /* RX state */ |
176 | 207 | enum wbcir_rxstate rxstate; | |
177 | struct led_trigger *rxtrigger; | 208 | struct led_trigger *rxtrigger; |
178 | struct led_trigger *txtrigger; | 209 | struct ir_raw_event rxev; |
179 | struct led_classdev led; | ||
180 | 210 | ||
181 | /* RX irdata state */ | 211 | /* TX state */ |
182 | bool irdata_active; | 212 | enum wbcir_txstate txstate; |
183 | bool irdata_error; | 213 | struct led_trigger *txtrigger; |
184 | struct ir_raw_event ev; | 214 | u32 txlen; |
215 | u32 txoff; | ||
216 | u32 *txbuf; | ||
217 | wait_queue_head_t txwaitq; | ||
218 | u8 txmask; | ||
219 | u32 txcarrier; | ||
185 | }; | 220 | }; |
186 | 221 | ||
187 | static enum wbcir_protocol protocol = IR_PROTOCOL_RC6; | 222 | static enum wbcir_protocol protocol = IR_PROTOCOL_RC6; |
@@ -193,6 +228,10 @@ static int invert; /* default = 0 */ | |||
193 | module_param(invert, bool, 0444); | 228 | module_param(invert, bool, 0444); |
194 | MODULE_PARM_DESC(invert, "Invert the signal from the IR receiver"); | 229 | MODULE_PARM_DESC(invert, "Invert the signal from the IR receiver"); |
195 | 230 | ||
231 | static int txandrx; /* default = 0 */ | ||
232 | module_param(txandrx, bool, 0444); | ||
233 | MODULE_PARM_DESC(invert, "Allow simultaneous TX and RX"); | ||
234 | |||
196 | static unsigned int wake_sc = 0x800F040C; | 235 | static unsigned int wake_sc = 0x800F040C; |
197 | module_param(wake_sc, uint, 0644); | 236 | module_param(wake_sc, uint, 0644); |
198 | MODULE_PARM_DESC(wake_sc, "Scancode of the power-on IR command"); | 237 | MODULE_PARM_DESC(wake_sc, "Scancode of the power-on IR command"); |
@@ -228,6 +267,17 @@ wbcir_select_bank(struct wbcir_data *data, enum wbcir_bank bank) | |||
228 | outb(bank, data->sbase + WBCIR_REG_SP3_BSR); | 267 | outb(bank, data->sbase + WBCIR_REG_SP3_BSR); |
229 | } | 268 | } |
230 | 269 | ||
270 | static inline void | ||
271 | wbcir_set_irqmask(struct wbcir_data *data, u8 irqmask) | ||
272 | { | ||
273 | if (data->irqmask == irqmask) | ||
274 | return; | ||
275 | |||
276 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
277 | outb(irqmask, data->sbase + WBCIR_REG_SP3_IER); | ||
278 | data->irqmask = irqmask; | ||
279 | } | ||
280 | |||
231 | static enum led_brightness | 281 | static enum led_brightness |
232 | wbcir_led_brightness_get(struct led_classdev *led_cdev) | 282 | wbcir_led_brightness_get(struct led_classdev *led_cdev) |
233 | { | 283 | { |
@@ -279,97 +329,297 @@ wbcir_to_rc6cells(u8 val) | |||
279 | * | 329 | * |
280 | *****************************************************************************/ | 330 | *****************************************************************************/ |
281 | 331 | ||
332 | static void | ||
333 | wbcir_idle_rx(struct rc_dev *dev, bool idle) | ||
334 | { | ||
335 | struct wbcir_data *data = dev->priv; | ||
336 | |||
337 | if (!idle && data->rxstate == WBCIR_RXSTATE_INACTIVE) { | ||
338 | data->rxstate = WBCIR_RXSTATE_ACTIVE; | ||
339 | led_trigger_event(data->rxtrigger, LED_FULL); | ||
340 | } | ||
341 | |||
342 | if (idle && data->rxstate != WBCIR_RXSTATE_INACTIVE) | ||
343 | /* Tell hardware to go idle by setting RXINACTIVE */ | ||
344 | outb(WBCIR_RX_DISABLE, data->sbase + WBCIR_REG_SP3_ASCR); | ||
345 | } | ||
346 | |||
347 | static void | ||
348 | wbcir_irq_rx(struct wbcir_data *data, struct pnp_dev *device) | ||
349 | { | ||
350 | u8 irdata; | ||
351 | DEFINE_IR_RAW_EVENT(rawir); | ||
352 | |||
353 | /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */ | ||
354 | while (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_AVAIL) { | ||
355 | irdata = inb(data->sbase + WBCIR_REG_SP3_RXDATA); | ||
356 | if (data->rxstate == WBCIR_RXSTATE_ERROR) | ||
357 | continue; | ||
358 | rawir.pulse = irdata & 0x80 ? false : true; | ||
359 | rawir.duration = US_TO_NS((irdata & 0x7F) * 10); | ||
360 | ir_raw_event_store_with_filter(data->dev, &rawir); | ||
361 | } | ||
362 | |||
363 | /* Check if we should go idle */ | ||
364 | if (data->dev->idle) { | ||
365 | led_trigger_event(data->rxtrigger, LED_OFF); | ||
366 | data->rxstate = WBCIR_RXSTATE_INACTIVE; | ||
367 | } | ||
368 | |||
369 | ir_raw_event_handle(data->dev); | ||
370 | } | ||
371 | |||
372 | static void | ||
373 | wbcir_irq_tx(struct wbcir_data *data) | ||
374 | { | ||
375 | unsigned int space; | ||
376 | unsigned int used; | ||
377 | u8 bytes[16]; | ||
378 | u8 byte; | ||
379 | |||
380 | if (!data->txbuf) | ||
381 | return; | ||
382 | |||
383 | switch (data->txstate) { | ||
384 | case WBCIR_TXSTATE_INACTIVE: | ||
385 | /* TX FIFO empty */ | ||
386 | space = 16; | ||
387 | led_trigger_event(data->txtrigger, LED_FULL); | ||
388 | break; | ||
389 | case WBCIR_TXSTATE_ACTIVE: | ||
390 | /* TX FIFO low (3 bytes or less) */ | ||
391 | space = 13; | ||
392 | break; | ||
393 | case WBCIR_TXSTATE_ERROR: | ||
394 | space = 0; | ||
395 | break; | ||
396 | default: | ||
397 | return; | ||
398 | } | ||
399 | |||
400 | /* | ||
401 | * TX data is run-length coded in bytes: YXXXXXXX | ||
402 | * Y = space (1) or pulse (0) | ||
403 | * X = duration, encoded as (X + 1) * 10us (i.e 10 to 1280 us) | ||
404 | */ | ||
405 | for (used = 0; used < space && data->txoff != data->txlen; used++) { | ||
406 | if (data->txbuf[data->txoff] == 0) { | ||
407 | data->txoff++; | ||
408 | continue; | ||
409 | } | ||
410 | byte = min((u32)0x80, data->txbuf[data->txoff]); | ||
411 | data->txbuf[data->txoff] -= byte; | ||
412 | byte--; | ||
413 | byte |= (data->txoff % 2 ? 0x80 : 0x00); /* pulse/space */ | ||
414 | bytes[used] = byte; | ||
415 | } | ||
416 | |||
417 | while (data->txbuf[data->txoff] == 0 && data->txoff != data->txlen) | ||
418 | data->txoff++; | ||
419 | |||
420 | if (used == 0) { | ||
421 | /* Finished */ | ||
422 | if (data->txstate == WBCIR_TXSTATE_ERROR) | ||
423 | /* Clear TX underrun bit */ | ||
424 | outb(WBCIR_TX_UNDERRUN, data->sbase + WBCIR_REG_SP3_ASCR); | ||
425 | else | ||
426 | data->txstate = WBCIR_TXSTATE_DONE; | ||
427 | wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR); | ||
428 | led_trigger_event(data->txtrigger, LED_OFF); | ||
429 | wake_up(&data->txwaitq); | ||
430 | } else if (data->txoff == data->txlen) { | ||
431 | /* At the end of transmission, tell the hw before last byte */ | ||
432 | outsb(data->sbase + WBCIR_REG_SP3_TXDATA, bytes, used - 1); | ||
433 | outb(WBCIR_TX_EOT, data->sbase + WBCIR_REG_SP3_ASCR); | ||
434 | outb(bytes[used - 1], data->sbase + WBCIR_REG_SP3_TXDATA); | ||
435 | wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR | | ||
436 | WBCIR_IRQ_TX_EMPTY); | ||
437 | } else { | ||
438 | /* More data to follow... */ | ||
439 | outsb(data->sbase + WBCIR_REG_SP3_RXDATA, bytes, used); | ||
440 | if (data->txstate == WBCIR_TXSTATE_INACTIVE) { | ||
441 | wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR | | ||
442 | WBCIR_IRQ_TX_LOW); | ||
443 | data->txstate = WBCIR_TXSTATE_ACTIVE; | ||
444 | } | ||
445 | } | ||
446 | } | ||
447 | |||
282 | static irqreturn_t | 448 | static irqreturn_t |
283 | wbcir_irq_handler(int irqno, void *cookie) | 449 | wbcir_irq_handler(int irqno, void *cookie) |
284 | { | 450 | { |
285 | struct pnp_dev *device = cookie; | 451 | struct pnp_dev *device = cookie; |
286 | struct wbcir_data *data = pnp_get_drvdata(device); | 452 | struct wbcir_data *data = pnp_get_drvdata(device); |
287 | unsigned long flags; | 453 | unsigned long flags; |
288 | u8 irdata[8]; | ||
289 | u8 disable = true; | ||
290 | u8 status; | 454 | u8 status; |
291 | int i; | ||
292 | 455 | ||
293 | spin_lock_irqsave(&data->spinlock, flags); | 456 | spin_lock_irqsave(&data->spinlock, flags); |
294 | |||
295 | wbcir_select_bank(data, WBCIR_BANK_0); | 457 | wbcir_select_bank(data, WBCIR_BANK_0); |
296 | |||
297 | status = inb(data->sbase + WBCIR_REG_SP3_EIR); | 458 | status = inb(data->sbase + WBCIR_REG_SP3_EIR); |
459 | status &= data->irqmask; | ||
298 | 460 | ||
299 | if (!(status & (WBCIR_IRQ_RX | WBCIR_IRQ_ERR))) { | 461 | if (!status) { |
300 | spin_unlock_irqrestore(&data->spinlock, flags); | 462 | spin_unlock_irqrestore(&data->spinlock, flags); |
301 | return IRQ_NONE; | 463 | return IRQ_NONE; |
302 | } | 464 | } |
303 | 465 | ||
304 | /* Check for e.g. buffer overflow */ | ||
305 | if (status & WBCIR_IRQ_ERR) { | 466 | if (status & WBCIR_IRQ_ERR) { |
306 | data->irdata_error = true; | 467 | /* RX overflow? (read clears bit) */ |
307 | ir_raw_event_reset(data->dev); | 468 | if (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_OVERRUN) { |
308 | } | 469 | data->rxstate = WBCIR_RXSTATE_ERROR; |
309 | 470 | ir_raw_event_reset(data->dev); | |
310 | if (!(status & WBCIR_IRQ_RX)) | 471 | } |
311 | goto out; | ||
312 | 472 | ||
313 | if (!data->irdata_active) { | 473 | /* TX underflow? */ |
314 | data->irdata_active = true; | 474 | if (inb(data->sbase + WBCIR_REG_SP3_ASCR) & WBCIR_TX_UNDERRUN) |
315 | led_trigger_event(data->rxtrigger, LED_FULL); | 475 | data->txstate = WBCIR_TXSTATE_ERROR; |
316 | } | 476 | } |
317 | 477 | ||
318 | /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */ | 478 | if (status & WBCIR_IRQ_RX) |
319 | insb(data->sbase + WBCIR_REG_SP3_RXDATA, &irdata[0], 8); | 479 | wbcir_irq_rx(data, device); |
320 | 480 | ||
321 | for (i = 0; i < 8; i++) { | 481 | if (status & (WBCIR_IRQ_TX_LOW | WBCIR_IRQ_TX_EMPTY)) |
322 | u8 pulse; | 482 | wbcir_irq_tx(data); |
323 | u32 duration; | ||
324 | 483 | ||
325 | if (irdata[i] != 0xFF && irdata[i] != 0x00) | 484 | spin_unlock_irqrestore(&data->spinlock, flags); |
326 | disable = false; | 485 | return IRQ_HANDLED; |
327 | 486 | } | |
328 | if (data->irdata_error) | ||
329 | continue; | ||
330 | 487 | ||
331 | pulse = irdata[i] & 0x80 ? false : true; | 488 | /***************************************************************************** |
332 | duration = (irdata[i] & 0x7F) * 10000; /* ns */ | 489 | * |
490 | * RC-CORE INTERFACE FUNCTIONS | ||
491 | * | ||
492 | *****************************************************************************/ | ||
333 | 493 | ||
334 | if (data->ev.pulse != pulse) { | 494 | static int |
335 | if (data->ev.duration != 0) { | 495 | wbcir_txcarrier(struct rc_dev *dev, u32 carrier) |
336 | ir_raw_event_store(data->dev, &data->ev); | 496 | { |
337 | data->ev.duration = 0; | 497 | struct wbcir_data *data = dev->priv; |
338 | } | 498 | unsigned long flags; |
499 | u8 val; | ||
500 | u32 freq; | ||
501 | |||
502 | freq = DIV_ROUND_CLOSEST(carrier, 1000); | ||
503 | if (freq < 30 || freq > 60) | ||
504 | return -EINVAL; | ||
505 | |||
506 | switch (freq) { | ||
507 | case 58: | ||
508 | case 59: | ||
509 | case 60: | ||
510 | val = freq - 58; | ||
511 | freq *= 1000; | ||
512 | break; | ||
513 | case 57: | ||
514 | val = freq - 27; | ||
515 | freq = 56900; | ||
516 | break; | ||
517 | default: | ||
518 | val = freq - 27; | ||
519 | freq *= 1000; | ||
520 | break; | ||
521 | } | ||
339 | 522 | ||
340 | data->ev.pulse = pulse; | 523 | spin_lock_irqsave(&data->spinlock, flags); |
341 | } | 524 | if (data->txstate != WBCIR_TXSTATE_INACTIVE) { |
525 | spin_unlock_irqrestore(&data->spinlock, flags); | ||
526 | return -EBUSY; | ||
527 | } | ||
342 | 528 | ||
343 | data->ev.duration += duration; | 529 | if (data->txcarrier != freq) { |
530 | wbcir_select_bank(data, WBCIR_BANK_7); | ||
531 | wbcir_set_bits(data->sbase + WBCIR_REG_SP3_IRTXMC, val, 0x1F); | ||
532 | data->txcarrier = freq; | ||
344 | } | 533 | } |
345 | 534 | ||
346 | if (disable) { | 535 | spin_unlock_irqrestore(&data->spinlock, flags); |
347 | if (data->ev.duration != 0 && !data->irdata_error) { | 536 | return 0; |
348 | ir_raw_event_store(data->dev, &data->ev); | 537 | } |
349 | data->ev.duration = 0; | ||
350 | } | ||
351 | 538 | ||
352 | /* Set RXINACTIVE */ | 539 | static int |
353 | outb(WBCIR_RX_DISABLE, data->sbase + WBCIR_REG_SP3_ASCR); | 540 | wbcir_txmask(struct rc_dev *dev, u32 mask) |
541 | { | ||
542 | struct wbcir_data *data = dev->priv; | ||
543 | unsigned long flags; | ||
544 | u8 val; | ||
354 | 545 | ||
355 | /* Drain the FIFO */ | 546 | /* Four outputs, only one output can be enabled at a time */ |
356 | while (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_AVAIL) | 547 | switch (mask) { |
357 | inb(data->sbase + WBCIR_REG_SP3_RXDATA); | 548 | case 0x1: |
549 | val = 0x0; | ||
550 | break; | ||
551 | case 0x2: | ||
552 | val = 0x1; | ||
553 | break; | ||
554 | case 0x4: | ||
555 | val = 0x2; | ||
556 | break; | ||
557 | case 0x8: | ||
558 | val = 0x3; | ||
559 | break; | ||
560 | default: | ||
561 | return -EINVAL; | ||
562 | } | ||
358 | 563 | ||
359 | ir_raw_event_reset(data->dev); | 564 | spin_lock_irqsave(&data->spinlock, flags); |
360 | data->irdata_error = false; | 565 | if (data->txstate != WBCIR_TXSTATE_INACTIVE) { |
361 | data->irdata_active = false; | 566 | spin_unlock_irqrestore(&data->spinlock, flags); |
362 | led_trigger_event(data->rxtrigger, LED_OFF); | 567 | return -EBUSY; |
363 | } | 568 | } |
364 | 569 | ||
365 | ir_raw_event_handle(data->dev); | 570 | if (data->txmask != mask) { |
571 | wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CTS, val, 0x0c); | ||
572 | data->txmask = mask; | ||
573 | } | ||
366 | 574 | ||
367 | out: | ||
368 | spin_unlock_irqrestore(&data->spinlock, flags); | 575 | spin_unlock_irqrestore(&data->spinlock, flags); |
369 | return IRQ_HANDLED; | 576 | return 0; |
370 | } | 577 | } |
371 | 578 | ||
579 | static int | ||
580 | wbcir_tx(struct rc_dev *dev, int *buf, u32 bufsize) | ||
581 | { | ||
582 | struct wbcir_data *data = dev->priv; | ||
583 | u32 count; | ||
584 | unsigned i; | ||
585 | unsigned long flags; | ||
586 | |||
587 | /* bufsize has been sanity checked by the caller */ | ||
588 | count = bufsize / sizeof(int); | ||
372 | 589 | ||
590 | /* Not sure if this is possible, but better safe than sorry */ | ||
591 | spin_lock_irqsave(&data->spinlock, flags); | ||
592 | if (data->txstate != WBCIR_TXSTATE_INACTIVE) { | ||
593 | spin_unlock_irqrestore(&data->spinlock, flags); | ||
594 | return -EBUSY; | ||
595 | } | ||
596 | |||
597 | /* Convert values to multiples of 10us */ | ||
598 | for (i = 0; i < count; i++) | ||
599 | buf[i] = DIV_ROUND_CLOSEST(buf[i], 10); | ||
600 | |||
601 | /* Fill the TX fifo once, the irq handler will do the rest */ | ||
602 | data->txbuf = buf; | ||
603 | data->txlen = count; | ||
604 | data->txoff = 0; | ||
605 | wbcir_irq_tx(data); | ||
606 | |||
607 | /* Wait for the TX to complete */ | ||
608 | while (data->txstate == WBCIR_TXSTATE_ACTIVE) { | ||
609 | spin_unlock_irqrestore(&data->spinlock, flags); | ||
610 | wait_event(data->txwaitq, data->txstate != WBCIR_TXSTATE_ACTIVE); | ||
611 | spin_lock_irqsave(&data->spinlock, flags); | ||
612 | } | ||
613 | |||
614 | /* We're done */ | ||
615 | if (data->txstate == WBCIR_TXSTATE_ERROR) | ||
616 | count = -EAGAIN; | ||
617 | data->txstate = WBCIR_TXSTATE_INACTIVE; | ||
618 | data->txbuf = NULL; | ||
619 | spin_unlock_irqrestore(&data->spinlock, flags); | ||
620 | |||
621 | return count; | ||
622 | } | ||
373 | 623 | ||
374 | /***************************************************************************** | 624 | /***************************************************************************** |
375 | * | 625 | * |
@@ -382,7 +632,7 @@ wbcir_shutdown(struct pnp_dev *device) | |||
382 | { | 632 | { |
383 | struct device *dev = &device->dev; | 633 | struct device *dev = &device->dev; |
384 | struct wbcir_data *data = pnp_get_drvdata(device); | 634 | struct wbcir_data *data = pnp_get_drvdata(device); |
385 | int do_wake = 1; | 635 | bool do_wake = true; |
386 | u8 match[11]; | 636 | u8 match[11]; |
387 | u8 mask[11]; | 637 | u8 mask[11]; |
388 | u8 rc6_csl = 0; | 638 | u8 rc6_csl = 0; |
@@ -392,14 +642,14 @@ wbcir_shutdown(struct pnp_dev *device) | |||
392 | memset(mask, 0, sizeof(mask)); | 642 | memset(mask, 0, sizeof(mask)); |
393 | 643 | ||
394 | if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) { | 644 | if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) { |
395 | do_wake = 0; | 645 | do_wake = false; |
396 | goto finish; | 646 | goto finish; |
397 | } | 647 | } |
398 | 648 | ||
399 | switch (protocol) { | 649 | switch (protocol) { |
400 | case IR_PROTOCOL_RC5: | 650 | case IR_PROTOCOL_RC5: |
401 | if (wake_sc > 0xFFF) { | 651 | if (wake_sc > 0xFFF) { |
402 | do_wake = 0; | 652 | do_wake = false; |
403 | dev_err(dev, "RC5 - Invalid wake scancode\n"); | 653 | dev_err(dev, "RC5 - Invalid wake scancode\n"); |
404 | break; | 654 | break; |
405 | } | 655 | } |
@@ -418,7 +668,7 @@ wbcir_shutdown(struct pnp_dev *device) | |||
418 | 668 | ||
419 | case IR_PROTOCOL_NEC: | 669 | case IR_PROTOCOL_NEC: |
420 | if (wake_sc > 0xFFFFFF) { | 670 | if (wake_sc > 0xFFFFFF) { |
421 | do_wake = 0; | 671 | do_wake = false; |
422 | dev_err(dev, "NEC - Invalid wake scancode\n"); | 672 | dev_err(dev, "NEC - Invalid wake scancode\n"); |
423 | break; | 673 | break; |
424 | } | 674 | } |
@@ -440,7 +690,7 @@ wbcir_shutdown(struct pnp_dev *device) | |||
440 | 690 | ||
441 | if (wake_rc6mode == 0) { | 691 | if (wake_rc6mode == 0) { |
442 | if (wake_sc > 0xFFFF) { | 692 | if (wake_sc > 0xFFFF) { |
443 | do_wake = 0; | 693 | do_wake = false; |
444 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | 694 | dev_err(dev, "RC6 - Invalid wake scancode\n"); |
445 | break; | 695 | break; |
446 | } | 696 | } |
@@ -496,7 +746,7 @@ wbcir_shutdown(struct pnp_dev *device) | |||
496 | } else if (wake_sc <= 0x007FFFFF) { | 746 | } else if (wake_sc <= 0x007FFFFF) { |
497 | rc6_csl = 60; | 747 | rc6_csl = 60; |
498 | } else { | 748 | } else { |
499 | do_wake = 0; | 749 | do_wake = false; |
500 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | 750 | dev_err(dev, "RC6 - Invalid wake scancode\n"); |
501 | break; | 751 | break; |
502 | } | 752 | } |
@@ -508,14 +758,14 @@ wbcir_shutdown(struct pnp_dev *device) | |||
508 | mask[i++] = 0x0F; | 758 | mask[i++] = 0x0F; |
509 | 759 | ||
510 | } else { | 760 | } else { |
511 | do_wake = 0; | 761 | do_wake = false; |
512 | dev_err(dev, "RC6 - Invalid wake mode\n"); | 762 | dev_err(dev, "RC6 - Invalid wake mode\n"); |
513 | } | 763 | } |
514 | 764 | ||
515 | break; | 765 | break; |
516 | 766 | ||
517 | default: | 767 | default: |
518 | do_wake = 0; | 768 | do_wake = false; |
519 | break; | 769 | break; |
520 | } | 770 | } |
521 | 771 | ||
@@ -551,21 +801,18 @@ finish: | |||
551 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | 801 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); |
552 | } | 802 | } |
553 | 803 | ||
554 | /* Disable interrupts */ | ||
555 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
556 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
557 | |||
558 | /* Disable LED */ | ||
559 | data->irdata_active = false; | ||
560 | led_trigger_event(data->rxtrigger, LED_OFF); | ||
561 | |||
562 | /* | 804 | /* |
563 | * ACPI will set the HW disable bit for SP3 which means that the | 805 | * ACPI will set the HW disable bit for SP3 which means that the |
564 | * output signals are left in an undefined state which may cause | 806 | * output signals are left in an undefined state which may cause |
565 | * spurious interrupts which we need to ignore until the hardware | 807 | * spurious interrupts which we need to ignore until the hardware |
566 | * is reinitialized. | 808 | * is reinitialized. |
567 | */ | 809 | */ |
810 | wbcir_set_irqmask(data, WBCIR_IRQ_NONE); | ||
568 | disable_irq(data->irq); | 811 | disable_irq(data->irq); |
812 | |||
813 | /* Disable LED */ | ||
814 | led_trigger_event(data->rxtrigger, LED_OFF); | ||
815 | led_trigger_event(data->txtrigger, LED_OFF); | ||
569 | } | 816 | } |
570 | 817 | ||
571 | static int | 818 | static int |
@@ -581,8 +828,7 @@ wbcir_init_hw(struct wbcir_data *data) | |||
581 | u8 tmp; | 828 | u8 tmp; |
582 | 829 | ||
583 | /* Disable interrupts */ | 830 | /* Disable interrupts */ |
584 | wbcir_select_bank(data, WBCIR_BANK_0); | 831 | wbcir_set_irqmask(data, WBCIR_IRQ_NONE); |
585 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
586 | 832 | ||
587 | /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */ | 833 | /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */ |
588 | tmp = protocol << 4; | 834 | tmp = protocol << 4; |
@@ -606,10 +852,11 @@ wbcir_init_hw(struct wbcir_data *data) | |||
606 | outb(0x00, data->ebase + WBCIR_REG_ECEIR_CCTL); | 852 | outb(0x00, data->ebase + WBCIR_REG_ECEIR_CCTL); |
607 | 853 | ||
608 | /* | 854 | /* |
609 | * Clear IR LED, set SP3 clock to 24Mhz | 855 | * Clear IR LED, set SP3 clock to 24Mhz, set TX mask to IRTX1, |
610 | * set SP3_IRRX_SW to binary 01, helpfully not documented | 856 | * set SP3_IRRX_SW to binary 01, helpfully not documented |
611 | */ | 857 | */ |
612 | outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS); | 858 | outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS); |
859 | data->txmask = 0x1; | ||
613 | 860 | ||
614 | /* Enable extended mode */ | 861 | /* Enable extended mode */ |
615 | wbcir_select_bank(data, WBCIR_BANK_2); | 862 | wbcir_select_bank(data, WBCIR_BANK_2); |
@@ -657,18 +904,21 @@ wbcir_init_hw(struct wbcir_data *data) | |||
657 | wbcir_select_bank(data, WBCIR_BANK_4); | 904 | wbcir_select_bank(data, WBCIR_BANK_4); |
658 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1); | 905 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1); |
659 | 906 | ||
660 | /* Enable MSR interrupt, Clear AUX_IRX */ | 907 | /* Disable MSR interrupt, clear AUX_IRX, mask RX during TX? */ |
661 | wbcir_select_bank(data, WBCIR_BANK_5); | 908 | wbcir_select_bank(data, WBCIR_BANK_5); |
662 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR2); | 909 | outb(txandrx ? 0x03 : 0x02, data->sbase + WBCIR_REG_SP3_IRCR2); |
663 | 910 | ||
664 | /* Disable CRC */ | 911 | /* Disable CRC */ |
665 | wbcir_select_bank(data, WBCIR_BANK_6); | 912 | wbcir_select_bank(data, WBCIR_BANK_6); |
666 | outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3); | 913 | outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3); |
667 | 914 | ||
668 | /* Set RX/TX (de)modulation freq, not really used */ | 915 | /* Set RX demodulation freq, not really used */ |
669 | wbcir_select_bank(data, WBCIR_BANK_7); | 916 | wbcir_select_bank(data, WBCIR_BANK_7); |
670 | outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC); | 917 | outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC); |
918 | |||
919 | /* Set TX modulation, 36kHz, 7us pulse width */ | ||
671 | outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC); | 920 | outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC); |
921 | data->txcarrier = 36000; | ||
672 | 922 | ||
673 | /* Set invert and pin direction */ | 923 | /* Set invert and pin direction */ |
674 | if (invert) | 924 | if (invert) |
@@ -683,16 +933,23 @@ wbcir_init_hw(struct wbcir_data *data) | |||
683 | /* Clear AUX status bits */ | 933 | /* Clear AUX status bits */ |
684 | outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR); | 934 | outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR); |
685 | 935 | ||
686 | /* Clear IR decoding state */ | 936 | /* Clear RX state */ |
687 | data->irdata_active = false; | 937 | data->rxstate = WBCIR_RXSTATE_INACTIVE; |
688 | led_trigger_event(data->rxtrigger, LED_OFF); | 938 | data->rxev.duration = 0; |
689 | data->irdata_error = false; | ||
690 | data->ev.duration = 0; | ||
691 | ir_raw_event_reset(data->dev); | 939 | ir_raw_event_reset(data->dev); |
692 | ir_raw_event_handle(data->dev); | 940 | ir_raw_event_handle(data->dev); |
693 | 941 | ||
942 | /* | ||
943 | * Check TX state, if we did a suspend/resume cycle while TX was | ||
944 | * active, we will have a process waiting in txwaitq. | ||
945 | */ | ||
946 | if (data->txstate == WBCIR_TXSTATE_ACTIVE) { | ||
947 | data->txstate = WBCIR_TXSTATE_ERROR; | ||
948 | wake_up(&data->txwaitq); | ||
949 | } | ||
950 | |||
694 | /* Enable interrupts */ | 951 | /* Enable interrupts */ |
695 | outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER); | 952 | wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR); |
696 | } | 953 | } |
697 | 954 | ||
698 | static int | 955 | static int |
@@ -729,6 +986,7 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id) | |||
729 | pnp_set_drvdata(device, data); | 986 | pnp_set_drvdata(device, data); |
730 | 987 | ||
731 | spin_lock_init(&data->spinlock); | 988 | spin_lock_init(&data->spinlock); |
989 | init_waitqueue_head(&data->txwaitq); | ||
732 | data->ebase = pnp_port_start(device, 0); | 990 | data->ebase = pnp_port_start(device, 0); |
733 | data->wbase = pnp_port_start(device, 1); | 991 | data->wbase = pnp_port_start(device, 1); |
734 | data->sbase = pnp_port_start(device, 2); | 992 | data->sbase = pnp_port_start(device, 2); |
@@ -807,6 +1065,11 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id) | |||
807 | data->dev->input_id.vendor = PCI_VENDOR_ID_WINBOND; | 1065 | data->dev->input_id.vendor = PCI_VENDOR_ID_WINBOND; |
808 | data->dev->input_id.product = WBCIR_ID_FAMILY; | 1066 | data->dev->input_id.product = WBCIR_ID_FAMILY; |
809 | data->dev->input_id.version = WBCIR_ID_CHIP; | 1067 | data->dev->input_id.version = WBCIR_ID_CHIP; |
1068 | data->dev->map_name = RC_MAP_RC6_MCE; | ||
1069 | data->dev->s_idle = wbcir_idle_rx; | ||
1070 | data->dev->s_tx_mask = wbcir_txmask; | ||
1071 | data->dev->s_tx_carrier = wbcir_txcarrier; | ||
1072 | data->dev->tx_ir = wbcir_tx; | ||
810 | data->dev->priv = data; | 1073 | data->dev->priv = data; |
811 | data->dev->dev.parent = &device->dev; | 1074 | data->dev->dev.parent = &device->dev; |
812 | 1075 | ||
@@ -849,9 +1112,7 @@ wbcir_remove(struct pnp_dev *device) | |||
849 | struct wbcir_data *data = pnp_get_drvdata(device); | 1112 | struct wbcir_data *data = pnp_get_drvdata(device); |
850 | 1113 | ||
851 | /* Disable interrupts */ | 1114 | /* Disable interrupts */ |
852 | wbcir_select_bank(data, WBCIR_BANK_0); | 1115 | wbcir_set_irqmask(data, WBCIR_IRQ_NONE); |
853 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
854 | |||
855 | free_irq(data->irq, device); | 1116 | free_irq(data->irq, device); |
856 | 1117 | ||
857 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | 1118 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ |