Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1 | /* |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 2 | * driver for ENE KB3926 B/C/D/E/F CIR (pnp id: ENE0XXX) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2010 Maxim Levitsky <maximlevitsky@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 | * USA |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 20 | * |
| 21 | * Special thanks to: |
| 22 | * Sami R. <maesesami@gmail.com> for lot of help in debugging and therefore |
| 23 | * bringing to life support for transmission & learning mode. |
| 24 | * |
| 25 | * Charlie Andrews <charliethepilot@googlemail.com> for lots of help in |
| 26 | * bringing up the support of new firmware buffer that is popular |
| 27 | * on latest notebooks |
| 28 | * |
| 29 | * ENE for partial device documentation |
| 30 | * |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 31 | */ |
| 32 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 33 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 34 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 35 | #include <linux/kernel.h> |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/pnp.h> |
| 38 | #include <linux/io.h> |
| 39 | #include <linux/interrupt.h> |
| 40 | #include <linux/sched.h> |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 41 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 42 | #include <media/rc-core.h> |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 43 | #include "ene_ir.h" |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 44 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 45 | static int sample_period; |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 46 | static bool learning_mode_force; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 47 | static int debug; |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 48 | static bool txsim; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 49 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 50 | static void ene_set_reg_addr(struct ene_device *dev, u16 reg) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 51 | { |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 52 | outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); |
| 53 | outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 54 | } |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 55 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 56 | /* read a hardware register */ |
| 57 | static u8 ene_read_reg(struct ene_device *dev, u16 reg) |
| 58 | { |
| 59 | u8 retval; |
| 60 | ene_set_reg_addr(dev, reg); |
| 61 | retval = inb(dev->hw_io + ENE_IO); |
| 62 | dbg_regs("reg %04x == %02x", reg, retval); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 63 | return retval; |
| 64 | } |
| 65 | |
| 66 | /* write a hardware register */ |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 67 | static void ene_write_reg(struct ene_device *dev, u16 reg, u8 value) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 68 | { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 69 | dbg_regs("reg %04x <- %02x", reg, value); |
| 70 | ene_set_reg_addr(dev, reg); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 71 | outb(value, dev->hw_io + ENE_IO); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 72 | } |
| 73 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 74 | /* Set bits in hardware register */ |
| 75 | static void ene_set_reg_mask(struct ene_device *dev, u16 reg, u8 mask) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 76 | { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 77 | dbg_regs("reg %04x |= %02x", reg, mask); |
| 78 | ene_set_reg_addr(dev, reg); |
| 79 | outb(inb(dev->hw_io + ENE_IO) | mask, dev->hw_io + ENE_IO); |
| 80 | } |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 81 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 82 | /* Clear bits in hardware register */ |
| 83 | static void ene_clear_reg_mask(struct ene_device *dev, u16 reg, u8 mask) |
| 84 | { |
| 85 | dbg_regs("reg %04x &= ~%02x ", reg, mask); |
| 86 | ene_set_reg_addr(dev, reg); |
| 87 | outb(inb(dev->hw_io + ENE_IO) & ~mask, dev->hw_io + ENE_IO); |
| 88 | } |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 89 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 90 | /* A helper to set/clear a bit in register according to boolean variable */ |
| 91 | static void ene_set_clear_reg_mask(struct ene_device *dev, u16 reg, u8 mask, |
| 92 | bool set) |
| 93 | { |
| 94 | if (set) |
| 95 | ene_set_reg_mask(dev, reg, mask); |
| 96 | else |
| 97 | ene_clear_reg_mask(dev, reg, mask); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /* detect hardware features */ |
| 101 | static int ene_hw_detect(struct ene_device *dev) |
| 102 | { |
| 103 | u8 chip_major, chip_minor; |
| 104 | u8 hw_revision, old_ver; |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 105 | u8 fw_reg2, fw_reg1; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 106 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 107 | ene_clear_reg_mask(dev, ENE_ECSTS, ENE_ECSTS_RSRVD); |
| 108 | chip_major = ene_read_reg(dev, ENE_ECVER_MAJOR); |
| 109 | chip_minor = ene_read_reg(dev, ENE_ECVER_MINOR); |
| 110 | ene_set_reg_mask(dev, ENE_ECSTS, ENE_ECSTS_RSRVD); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 111 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 112 | hw_revision = ene_read_reg(dev, ENE_ECHV); |
| 113 | old_ver = ene_read_reg(dev, ENE_HW_VER_OLD); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 114 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 115 | dev->pll_freq = (ene_read_reg(dev, ENE_PLLFRH) << 4) + |
| 116 | (ene_read_reg(dev, ENE_PLLFRL) >> 4); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 117 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 118 | if (sample_period != ENE_DEFAULT_SAMPLE_PERIOD) |
| 119 | dev->rx_period_adjust = |
| 120 | dev->pll_freq == ENE_DEFAULT_PLL_FREQ ? 2 : 4; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 121 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 122 | if (hw_revision == 0xFF) { |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 123 | pr_warn("device seems to be disabled\n"); |
| 124 | pr_warn("send a mail to lirc-list@lists.sourceforge.net\n"); |
| 125 | pr_warn("please attach output of acpidump and dmidecode\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 126 | return -ENODEV; |
| 127 | } |
| 128 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 129 | pr_notice("chip is 0x%02x%02x - kbver = 0x%02x, rev = 0x%02x\n", |
| 130 | chip_major, chip_minor, old_ver, hw_revision); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 131 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 132 | pr_notice("PLL freq = %d\n", dev->pll_freq); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 133 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 134 | if (chip_major == 0x33) { |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 135 | pr_warn("chips 0x33xx aren't supported\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 136 | return -ENODEV; |
| 137 | } |
| 138 | |
| 139 | if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) { |
| 140 | dev->hw_revision = ENE_HW_C; |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 141 | pr_notice("KB3926C detected\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 142 | } else if (old_ver == 0x24 && hw_revision == 0xC0) { |
| 143 | dev->hw_revision = ENE_HW_B; |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 144 | pr_notice("KB3926B detected\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 145 | } else { |
| 146 | dev->hw_revision = ENE_HW_D; |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 147 | pr_notice("KB3926D or higher detected\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 148 | } |
| 149 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 150 | /* detect features hardware supports */ |
| 151 | if (dev->hw_revision < ENE_HW_C) |
| 152 | return 0; |
| 153 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 154 | fw_reg1 = ene_read_reg(dev, ENE_FW1); |
| 155 | fw_reg2 = ene_read_reg(dev, ENE_FW2); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 156 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 157 | pr_notice("Firmware regs: %02x %02x\n", fw_reg1, fw_reg2); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 158 | |
Maxim Levitsky | a06423c | 2010-10-15 13:06:37 -0300 | [diff] [blame] | 159 | dev->hw_use_gpio_0a = !!(fw_reg2 & ENE_FW2_GP0A); |
| 160 | dev->hw_learning_and_tx_capable = !!(fw_reg2 & ENE_FW2_LEARNING); |
| 161 | dev->hw_extra_buffer = !!(fw_reg1 & ENE_FW1_HAS_EXTRA_BUF); |
| 162 | |
| 163 | if (dev->hw_learning_and_tx_capable) |
| 164 | dev->hw_fan_input = !!(fw_reg2 & ENE_FW2_FAN_INPUT); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 165 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 166 | pr_notice("Hardware features:\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 167 | |
| 168 | if (dev->hw_learning_and_tx_capable) { |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 169 | pr_notice("* Supports transmitting & learning mode\n"); |
| 170 | pr_notice(" This feature is rare and therefore,\n"); |
| 171 | pr_notice(" you are welcome to test it,\n"); |
| 172 | pr_notice(" and/or contact the author via:\n"); |
| 173 | pr_notice(" lirc-list@lists.sourceforge.net\n"); |
| 174 | pr_notice(" or maximlevitsky@gmail.com\n"); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 175 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 176 | pr_notice("* Uses GPIO %s for IR raw input\n", |
| 177 | dev->hw_use_gpio_0a ? "40" : "0A"); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 178 | |
| 179 | if (dev->hw_fan_input) |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 180 | pr_notice("* Uses unused fan feedback input as source of demodulated IR data\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 181 | } |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 182 | |
| 183 | if (!dev->hw_fan_input) |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 184 | pr_notice("* Uses GPIO %s for IR demodulated input\n", |
| 185 | dev->hw_use_gpio_0a ? "0A" : "40"); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 186 | |
| 187 | if (dev->hw_extra_buffer) |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 188 | pr_notice("* Uses new style input buffer\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 192 | /* Read properities of hw sample buffer */ |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 193 | static void ene_rx_setup_hw_buffer(struct ene_device *dev) |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 194 | { |
| 195 | u16 tmp; |
| 196 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 197 | ene_rx_read_hw_pointer(dev); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 198 | dev->r_pointer = dev->w_pointer; |
| 199 | |
| 200 | if (!dev->hw_extra_buffer) { |
| 201 | dev->buffer_len = ENE_FW_PACKET_SIZE * 2; |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER); |
| 206 | tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER+1) << 8; |
| 207 | dev->extra_buf1_address = tmp; |
| 208 | |
| 209 | dev->extra_buf1_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 2); |
| 210 | |
| 211 | tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 3); |
| 212 | tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 4) << 8; |
| 213 | dev->extra_buf2_address = tmp; |
| 214 | |
| 215 | dev->extra_buf2_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 5); |
| 216 | |
| 217 | dev->buffer_len = dev->extra_buf1_len + dev->extra_buf2_len + 8; |
| 218 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 219 | pr_notice("Hardware uses 2 extended buffers:\n"); |
| 220 | pr_notice(" 0x%04x - len : %d\n", |
| 221 | dev->extra_buf1_address, dev->extra_buf1_len); |
| 222 | pr_notice(" 0x%04x - len : %d\n", |
| 223 | dev->extra_buf2_address, dev->extra_buf2_len); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 224 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 225 | pr_notice("Total buffer len = %d\n", dev->buffer_len); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 226 | |
| 227 | if (dev->buffer_len > 64 || dev->buffer_len < 16) |
| 228 | goto error; |
| 229 | |
| 230 | if (dev->extra_buf1_address > 0xFBFC || |
| 231 | dev->extra_buf1_address < 0xEC00) |
| 232 | goto error; |
| 233 | |
| 234 | if (dev->extra_buf2_address > 0xFBFC || |
| 235 | dev->extra_buf2_address < 0xEC00) |
| 236 | goto error; |
| 237 | |
| 238 | if (dev->r_pointer > dev->buffer_len) |
| 239 | goto error; |
| 240 | |
| 241 | ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND); |
| 242 | return; |
| 243 | error: |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 244 | pr_warn("Error validating extra buffers, device probably won't work\n"); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 245 | dev->hw_extra_buffer = false; |
| 246 | ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | /* Restore the pointers to extra buffers - to make module reload work*/ |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 251 | static void ene_rx_restore_hw_buffer(struct ene_device *dev) |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 252 | { |
| 253 | if (!dev->hw_extra_buffer) |
| 254 | return; |
| 255 | |
| 256 | ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 0, |
| 257 | dev->extra_buf1_address & 0xFF); |
| 258 | ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 1, |
| 259 | dev->extra_buf1_address >> 8); |
| 260 | ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 2, dev->extra_buf1_len); |
| 261 | |
| 262 | ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 3, |
| 263 | dev->extra_buf2_address & 0xFF); |
| 264 | ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 4, |
| 265 | dev->extra_buf2_address >> 8); |
| 266 | ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 5, |
| 267 | dev->extra_buf2_len); |
| 268 | ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND); |
| 269 | } |
| 270 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 271 | /* Read hardware write pointer */ |
| 272 | static void ene_rx_read_hw_pointer(struct ene_device *dev) |
| 273 | { |
| 274 | if (dev->hw_extra_buffer) |
| 275 | dev->w_pointer = ene_read_reg(dev, ENE_FW_RX_POINTER); |
| 276 | else |
| 277 | dev->w_pointer = ene_read_reg(dev, ENE_FW2) |
| 278 | & ENE_FW2_BUF_WPTR ? 0 : ENE_FW_PACKET_SIZE; |
| 279 | |
| 280 | dbg_verbose("RB: HW write pointer: %02x, driver read pointer: %02x", |
| 281 | dev->w_pointer, dev->r_pointer); |
| 282 | } |
| 283 | |
| 284 | /* Gets address of next sample from HW ring buffer */ |
| 285 | static int ene_rx_get_sample_reg(struct ene_device *dev) |
| 286 | { |
| 287 | int r_pointer; |
| 288 | |
| 289 | if (dev->r_pointer == dev->w_pointer) { |
| 290 | dbg_verbose("RB: hit end, try update w_pointer"); |
| 291 | ene_rx_read_hw_pointer(dev); |
| 292 | } |
| 293 | |
| 294 | if (dev->r_pointer == dev->w_pointer) { |
| 295 | dbg_verbose("RB: end of data at %d", dev->r_pointer); |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | dbg_verbose("RB: reading at offset %d", dev->r_pointer); |
| 300 | r_pointer = dev->r_pointer; |
| 301 | |
| 302 | dev->r_pointer++; |
| 303 | if (dev->r_pointer == dev->buffer_len) |
| 304 | dev->r_pointer = 0; |
| 305 | |
| 306 | dbg_verbose("RB: next read will be from offset %d", dev->r_pointer); |
| 307 | |
| 308 | if (r_pointer < 8) { |
| 309 | dbg_verbose("RB: read at main buffer at %d", r_pointer); |
| 310 | return ENE_FW_SAMPLE_BUFFER + r_pointer; |
| 311 | } |
| 312 | |
| 313 | r_pointer -= 8; |
| 314 | |
| 315 | if (r_pointer < dev->extra_buf1_len) { |
| 316 | dbg_verbose("RB: read at 1st extra buffer at %d", r_pointer); |
| 317 | return dev->extra_buf1_address + r_pointer; |
| 318 | } |
| 319 | |
| 320 | r_pointer -= dev->extra_buf1_len; |
| 321 | |
| 322 | if (r_pointer < dev->extra_buf2_len) { |
| 323 | dbg_verbose("RB: read at 2nd extra buffer at %d", r_pointer); |
| 324 | return dev->extra_buf2_address + r_pointer; |
| 325 | } |
| 326 | |
Paul Bolle | 90802ed | 2011-12-05 13:00:34 +0100 | [diff] [blame] | 327 | dbg("attempt to read beyond ring buffer end"); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | /* Sense current received carrier */ |
Mauro Carvalho Chehab | e03cd64 | 2012-10-27 13:46:53 -0300 | [diff] [blame] | 332 | static void ene_rx_sense_carrier(struct ene_device *dev) |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 333 | { |
| 334 | DEFINE_IR_RAW_EVENT(ev); |
| 335 | |
| 336 | int carrier, duty_cycle; |
| 337 | int period = ene_read_reg(dev, ENE_CIRCAR_PRD); |
| 338 | int hperiod = ene_read_reg(dev, ENE_CIRCAR_HPRD); |
| 339 | |
| 340 | if (!(period & ENE_CIRCAR_PRD_VALID)) |
| 341 | return; |
| 342 | |
| 343 | period &= ~ENE_CIRCAR_PRD_VALID; |
| 344 | |
| 345 | if (!period) |
| 346 | return; |
| 347 | |
| 348 | dbg("RX: hardware carrier period = %02x", period); |
| 349 | dbg("RX: hardware carrier pulse period = %02x", hperiod); |
| 350 | |
| 351 | carrier = 2000000 / period; |
| 352 | duty_cycle = (hperiod * 100) / period; |
| 353 | dbg("RX: sensed carrier = %d Hz, duty cycle %d%%", |
| 354 | carrier, duty_cycle); |
| 355 | if (dev->carrier_detect_enabled) { |
| 356 | ev.carrier_report = true; |
| 357 | ev.carrier = carrier; |
| 358 | ev.duty_cycle = duty_cycle; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 359 | ir_raw_event_store(dev->rdev, &ev); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | /* this enables/disables the CIR RX engine */ |
| 364 | static void ene_rx_enable_cir_engine(struct ene_device *dev, bool enable) |
| 365 | { |
| 366 | ene_set_clear_reg_mask(dev, ENE_CIRCFG, |
| 367 | ENE_CIRCFG_RX_EN | ENE_CIRCFG_RX_IRQ, enable); |
| 368 | } |
| 369 | |
| 370 | /* this selects input for CIR engine. Ether GPIO 0A or GPIO40*/ |
| 371 | static void ene_rx_select_input(struct ene_device *dev, bool gpio_0a) |
| 372 | { |
| 373 | ene_set_clear_reg_mask(dev, ENE_CIRCFG2, ENE_CIRCFG2_GPIO0A, gpio_0a); |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | * this enables alternative input via fan tachometer sensor and bypasses |
| 378 | * the hw CIR engine |
| 379 | */ |
| 380 | static void ene_rx_enable_fan_input(struct ene_device *dev, bool enable) |
| 381 | { |
| 382 | if (!dev->hw_fan_input) |
| 383 | return; |
| 384 | |
| 385 | if (!enable) |
| 386 | ene_write_reg(dev, ENE_FAN_AS_IN1, 0); |
| 387 | else { |
| 388 | ene_write_reg(dev, ENE_FAN_AS_IN1, ENE_FAN_AS_IN1_EN); |
| 389 | ene_write_reg(dev, ENE_FAN_AS_IN2, ENE_FAN_AS_IN2_EN); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /* setup the receiver for RX*/ |
| 394 | static void ene_rx_setup(struct ene_device *dev) |
| 395 | { |
| 396 | bool learning_mode = dev->learning_mode_enabled || |
| 397 | dev->carrier_detect_enabled; |
| 398 | int sample_period_adjust = 0; |
| 399 | |
| 400 | dbg("RX: setup receiver, learning mode = %d", learning_mode); |
| 401 | |
| 402 | |
| 403 | /* This selects RLC input and clears CFG2 settings */ |
| 404 | ene_write_reg(dev, ENE_CIRCFG2, 0x00); |
| 405 | |
| 406 | /* set sample period*/ |
| 407 | if (sample_period == ENE_DEFAULT_SAMPLE_PERIOD) |
| 408 | sample_period_adjust = |
| 409 | dev->pll_freq == ENE_DEFAULT_PLL_FREQ ? 1 : 2; |
| 410 | |
| 411 | ene_write_reg(dev, ENE_CIRRLC_CFG, |
| 412 | (sample_period + sample_period_adjust) | |
| 413 | ENE_CIRRLC_CFG_OVERFLOW); |
| 414 | /* revB doesn't support inputs */ |
| 415 | if (dev->hw_revision < ENE_HW_C) |
| 416 | goto select_timeout; |
| 417 | |
| 418 | if (learning_mode) { |
| 419 | |
| 420 | WARN_ON(!dev->hw_learning_and_tx_capable); |
| 421 | |
| 422 | /* Enable the opposite of the normal input |
| 423 | That means that if GPIO40 is normally used, use GPIO0A |
| 424 | and vice versa. |
| 425 | This input will carry non demodulated |
| 426 | signal, and we will tell the hw to demodulate it itself */ |
| 427 | ene_rx_select_input(dev, !dev->hw_use_gpio_0a); |
| 428 | dev->rx_fan_input_inuse = false; |
| 429 | |
| 430 | /* Enable carrier demodulation */ |
| 431 | ene_set_reg_mask(dev, ENE_CIRCFG, ENE_CIRCFG_CARR_DEMOD); |
| 432 | |
| 433 | /* Enable carrier detection */ |
| 434 | ene_write_reg(dev, ENE_CIRCAR_PULS, 0x63); |
| 435 | ene_set_clear_reg_mask(dev, ENE_CIRCFG2, ENE_CIRCFG2_CARR_DETECT, |
| 436 | dev->carrier_detect_enabled || debug); |
| 437 | } else { |
| 438 | if (dev->hw_fan_input) |
| 439 | dev->rx_fan_input_inuse = true; |
| 440 | else |
| 441 | ene_rx_select_input(dev, dev->hw_use_gpio_0a); |
| 442 | |
| 443 | /* Disable carrier detection & demodulation */ |
| 444 | ene_clear_reg_mask(dev, ENE_CIRCFG, ENE_CIRCFG_CARR_DEMOD); |
| 445 | ene_clear_reg_mask(dev, ENE_CIRCFG2, ENE_CIRCFG2_CARR_DETECT); |
| 446 | } |
| 447 | |
| 448 | select_timeout: |
| 449 | if (dev->rx_fan_input_inuse) { |
Jarod Wilson | 5aad724 | 2011-01-06 16:59:36 -0300 | [diff] [blame] | 450 | dev->rdev->rx_resolution = US_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 451 | |
| 452 | /* Fan input doesn't support timeouts, it just ends the |
| 453 | input with a maximum sample */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 454 | dev->rdev->min_timeout = dev->rdev->max_timeout = |
Jarod Wilson | 5aad724 | 2011-01-06 16:59:36 -0300 | [diff] [blame] | 455 | US_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK * |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 456 | ENE_FW_SAMPLE_PERIOD_FAN); |
| 457 | } else { |
Jarod Wilson | 5aad724 | 2011-01-06 16:59:36 -0300 | [diff] [blame] | 458 | dev->rdev->rx_resolution = US_TO_NS(sample_period); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 459 | |
| 460 | /* Theoreticly timeout is unlimited, but we cap it |
| 461 | * because it was seen that on one device, it |
| 462 | * would stop sending spaces after around 250 msec. |
| 463 | * Besides, this is close to 2^32 anyway and timeout is u32. |
| 464 | */ |
Jarod Wilson | 5aad724 | 2011-01-06 16:59:36 -0300 | [diff] [blame] | 465 | dev->rdev->min_timeout = US_TO_NS(127 * sample_period); |
| 466 | dev->rdev->max_timeout = US_TO_NS(200000); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | if (dev->hw_learning_and_tx_capable) |
Jarod Wilson | 5aad724 | 2011-01-06 16:59:36 -0300 | [diff] [blame] | 470 | dev->rdev->tx_resolution = US_TO_NS(sample_period); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 471 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 472 | if (dev->rdev->timeout > dev->rdev->max_timeout) |
| 473 | dev->rdev->timeout = dev->rdev->max_timeout; |
| 474 | if (dev->rdev->timeout < dev->rdev->min_timeout) |
| 475 | dev->rdev->timeout = dev->rdev->min_timeout; |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /* Enable the device for receive */ |
| 479 | static void ene_rx_enable(struct ene_device *dev) |
| 480 | { |
| 481 | u8 reg_value; |
| 482 | |
| 483 | /* Enable system interrupt */ |
| 484 | if (dev->hw_revision < ENE_HW_C) { |
| 485 | ene_write_reg(dev, ENEB_IRQ, dev->irq << 1); |
| 486 | ene_write_reg(dev, ENEB_IRQ_UNK1, 0x01); |
| 487 | } else { |
| 488 | reg_value = ene_read_reg(dev, ENE_IRQ) & 0xF0; |
| 489 | reg_value |= ENE_IRQ_UNK_EN; |
| 490 | reg_value &= ~ENE_IRQ_STATUS; |
| 491 | reg_value |= (dev->irq & ENE_IRQ_MASK); |
| 492 | ene_write_reg(dev, ENE_IRQ, reg_value); |
| 493 | } |
| 494 | |
| 495 | /* Enable inputs */ |
| 496 | ene_rx_enable_fan_input(dev, dev->rx_fan_input_inuse); |
| 497 | ene_rx_enable_cir_engine(dev, !dev->rx_fan_input_inuse); |
| 498 | |
| 499 | /* ack any pending irqs - just in case */ |
| 500 | ene_irq_status(dev); |
| 501 | |
| 502 | /* enable firmware bits */ |
| 503 | ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_ENABLE | ENE_FW1_IRQ); |
| 504 | |
| 505 | /* enter idle mode */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 506 | ir_raw_event_set_idle(dev->rdev, true); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 507 | dev->rx_enabled = true; |
| 508 | } |
| 509 | |
| 510 | /* Disable the device receiver */ |
| 511 | static void ene_rx_disable(struct ene_device *dev) |
| 512 | { |
| 513 | /* disable inputs */ |
| 514 | ene_rx_enable_cir_engine(dev, false); |
| 515 | ene_rx_enable_fan_input(dev, false); |
| 516 | |
| 517 | /* disable hardware IRQ and firmware flag */ |
| 518 | ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_ENABLE | ENE_FW1_IRQ); |
| 519 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 520 | ir_raw_event_set_idle(dev->rdev, true); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 521 | dev->rx_enabled = false; |
| 522 | } |
| 523 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 524 | /* This resets the receiver. Useful to stop stream of spaces at end of |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 525 | * transmission |
| 526 | */ |
| 527 | static void ene_rx_reset(struct ene_device *dev) |
| 528 | { |
| 529 | ene_clear_reg_mask(dev, ENE_CIRCFG, ENE_CIRCFG_RX_EN); |
| 530 | ene_set_reg_mask(dev, ENE_CIRCFG, ENE_CIRCFG_RX_EN); |
| 531 | } |
| 532 | |
| 533 | /* Set up the TX carrier frequency and duty cycle */ |
| 534 | static void ene_tx_set_carrier(struct ene_device *dev) |
| 535 | { |
| 536 | u8 tx_puls_width; |
| 537 | unsigned long flags; |
| 538 | |
| 539 | spin_lock_irqsave(&dev->hw_lock, flags); |
| 540 | |
| 541 | ene_set_clear_reg_mask(dev, ENE_CIRCFG, |
| 542 | ENE_CIRCFG_TX_CARR, dev->tx_period > 0); |
| 543 | |
| 544 | if (!dev->tx_period) |
| 545 | goto unlock; |
| 546 | |
| 547 | BUG_ON(dev->tx_duty_cycle >= 100 || dev->tx_duty_cycle <= 0); |
| 548 | |
| 549 | tx_puls_width = dev->tx_period / (100 / dev->tx_duty_cycle); |
| 550 | |
| 551 | if (!tx_puls_width) |
| 552 | tx_puls_width = 1; |
| 553 | |
| 554 | dbg("TX: pulse distance = %d * 500 ns", dev->tx_period); |
| 555 | dbg("TX: pulse width = %d * 500 ns", tx_puls_width); |
| 556 | |
| 557 | ene_write_reg(dev, ENE_CIRMOD_PRD, dev->tx_period | ENE_CIRMOD_PRD_POL); |
| 558 | ene_write_reg(dev, ENE_CIRMOD_HPRD, tx_puls_width); |
| 559 | unlock: |
| 560 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 561 | } |
| 562 | |
| 563 | /* Enable/disable transmitters */ |
| 564 | static void ene_tx_set_transmitters(struct ene_device *dev) |
| 565 | { |
| 566 | unsigned long flags; |
| 567 | |
| 568 | spin_lock_irqsave(&dev->hw_lock, flags); |
| 569 | ene_set_clear_reg_mask(dev, ENE_GPIOFS8, ENE_GPIOFS8_GPIO41, |
| 570 | !!(dev->transmitter_mask & 0x01)); |
| 571 | ene_set_clear_reg_mask(dev, ENE_GPIOFS1, ENE_GPIOFS1_GPIO0D, |
| 572 | !!(dev->transmitter_mask & 0x02)); |
| 573 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 574 | } |
| 575 | |
| 576 | /* prepare transmission */ |
| 577 | static void ene_tx_enable(struct ene_device *dev) |
| 578 | { |
| 579 | u8 conf1 = ene_read_reg(dev, ENE_CIRCFG); |
| 580 | u8 fwreg2 = ene_read_reg(dev, ENE_FW2); |
| 581 | |
| 582 | dev->saved_conf1 = conf1; |
| 583 | |
| 584 | /* Show information about currently connected transmitter jacks */ |
| 585 | if (fwreg2 & ENE_FW2_EMMITER1_CONN) |
| 586 | dbg("TX: Transmitter #1 is connected"); |
| 587 | |
| 588 | if (fwreg2 & ENE_FW2_EMMITER2_CONN) |
| 589 | dbg("TX: Transmitter #2 is connected"); |
| 590 | |
| 591 | if (!(fwreg2 & (ENE_FW2_EMMITER1_CONN | ENE_FW2_EMMITER2_CONN))) |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 592 | pr_warn("TX: transmitter cable isn't connected!\n"); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 593 | |
| 594 | /* disable receive on revc */ |
| 595 | if (dev->hw_revision == ENE_HW_C) |
| 596 | conf1 &= ~ENE_CIRCFG_RX_EN; |
| 597 | |
| 598 | /* Enable TX engine */ |
| 599 | conf1 |= ENE_CIRCFG_TX_EN | ENE_CIRCFG_TX_IRQ; |
| 600 | ene_write_reg(dev, ENE_CIRCFG, conf1); |
| 601 | } |
| 602 | |
| 603 | /* end transmission */ |
| 604 | static void ene_tx_disable(struct ene_device *dev) |
| 605 | { |
| 606 | ene_write_reg(dev, ENE_CIRCFG, dev->saved_conf1); |
| 607 | dev->tx_buffer = NULL; |
| 608 | } |
| 609 | |
| 610 | |
| 611 | /* TX one sample - must be called with dev->hw_lock*/ |
| 612 | static void ene_tx_sample(struct ene_device *dev) |
| 613 | { |
| 614 | u8 raw_tx; |
| 615 | u32 sample; |
| 616 | bool pulse = dev->tx_sample_pulse; |
| 617 | |
| 618 | if (!dev->tx_buffer) { |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 619 | pr_warn("TX: BUG: attempt to transmit NULL buffer\n"); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 620 | return; |
| 621 | } |
| 622 | |
| 623 | /* Grab next TX sample */ |
| 624 | if (!dev->tx_sample) { |
| 625 | |
| 626 | if (dev->tx_pos == dev->tx_len) { |
| 627 | if (!dev->tx_done) { |
| 628 | dbg("TX: no more data to send"); |
| 629 | dev->tx_done = true; |
| 630 | goto exit; |
| 631 | } else { |
| 632 | dbg("TX: last sample sent by hardware"); |
| 633 | ene_tx_disable(dev); |
| 634 | complete(&dev->tx_complete); |
| 635 | return; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | sample = dev->tx_buffer[dev->tx_pos++]; |
| 640 | dev->tx_sample_pulse = !dev->tx_sample_pulse; |
| 641 | |
| 642 | dev->tx_sample = DIV_ROUND_CLOSEST(sample, sample_period); |
| 643 | |
| 644 | if (!dev->tx_sample) |
| 645 | dev->tx_sample = 1; |
| 646 | } |
| 647 | |
| 648 | raw_tx = min(dev->tx_sample , (unsigned int)ENE_CIRRLC_OUT_MASK); |
| 649 | dev->tx_sample -= raw_tx; |
| 650 | |
| 651 | dbg("TX: sample %8d (%s)", raw_tx * sample_period, |
| 652 | pulse ? "pulse" : "space"); |
| 653 | if (pulse) |
| 654 | raw_tx |= ENE_CIRRLC_OUT_PULSE; |
| 655 | |
| 656 | ene_write_reg(dev, |
| 657 | dev->tx_reg ? ENE_CIRRLC_OUT1 : ENE_CIRRLC_OUT0, raw_tx); |
| 658 | |
| 659 | dev->tx_reg = !dev->tx_reg; |
| 660 | exit: |
| 661 | /* simulate TX done interrupt */ |
| 662 | if (txsim) |
| 663 | mod_timer(&dev->tx_sim_timer, jiffies + HZ / 500); |
| 664 | } |
| 665 | |
| 666 | /* timer to simulate tx done interrupt */ |
| 667 | static void ene_tx_irqsim(unsigned long data) |
| 668 | { |
| 669 | struct ene_device *dev = (struct ene_device *)data; |
| 670 | unsigned long flags; |
| 671 | |
| 672 | spin_lock_irqsave(&dev->hw_lock, flags); |
| 673 | ene_tx_sample(dev); |
| 674 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 675 | } |
| 676 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 677 | |
| 678 | /* read irq status and ack it */ |
| 679 | static int ene_irq_status(struct ene_device *dev) |
| 680 | { |
| 681 | u8 irq_status; |
| 682 | u8 fw_flags1, fw_flags2; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 683 | int retval = 0; |
| 684 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 685 | fw_flags2 = ene_read_reg(dev, ENE_FW2); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 686 | |
| 687 | if (dev->hw_revision < ENE_HW_C) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 688 | irq_status = ene_read_reg(dev, ENEB_IRQ_STATUS); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 689 | |
| 690 | if (!(irq_status & ENEB_IRQ_STATUS_IR)) |
| 691 | return 0; |
| 692 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 693 | ene_clear_reg_mask(dev, ENEB_IRQ_STATUS, ENEB_IRQ_STATUS_IR); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 694 | return ENE_IRQ_RX; |
| 695 | } |
| 696 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 697 | irq_status = ene_read_reg(dev, ENE_IRQ); |
| 698 | if (!(irq_status & ENE_IRQ_STATUS)) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 699 | return 0; |
| 700 | |
| 701 | /* original driver does that twice - a workaround ? */ |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 702 | ene_write_reg(dev, ENE_IRQ, irq_status & ~ENE_IRQ_STATUS); |
| 703 | ene_write_reg(dev, ENE_IRQ, irq_status & ~ENE_IRQ_STATUS); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 704 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 705 | /* check RX interrupt */ |
| 706 | if (fw_flags2 & ENE_FW2_RXIRQ) { |
| 707 | retval |= ENE_IRQ_RX; |
| 708 | ene_write_reg(dev, ENE_FW2, fw_flags2 & ~ENE_FW2_RXIRQ); |
| 709 | } |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 710 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 711 | /* check TX interrupt */ |
| 712 | fw_flags1 = ene_read_reg(dev, ENE_FW1); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 713 | if (fw_flags1 & ENE_FW1_TXIRQ) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 714 | ene_write_reg(dev, ENE_FW1, fw_flags1 & ~ENE_FW1_TXIRQ); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 715 | retval |= ENE_IRQ_TX; |
| 716 | } |
| 717 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 718 | return retval; |
| 719 | } |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 720 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 721 | /* interrupt handler */ |
| 722 | static irqreturn_t ene_isr(int irq, void *data) |
| 723 | { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 724 | u16 hw_value, reg; |
| 725 | int hw_sample, irq_status; |
| 726 | bool pulse; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 727 | unsigned long flags; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 728 | irqreturn_t retval = IRQ_NONE; |
| 729 | struct ene_device *dev = (struct ene_device *)data; |
Maxim Levitsky | 4651918 | 2010-10-16 19:56:28 -0300 | [diff] [blame] | 730 | DEFINE_IR_RAW_EVENT(ev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 731 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 732 | spin_lock_irqsave(&dev->hw_lock, flags); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 733 | |
| 734 | dbg_verbose("ISR called"); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 735 | ene_rx_read_hw_pointer(dev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 736 | irq_status = ene_irq_status(dev); |
| 737 | |
| 738 | if (!irq_status) |
| 739 | goto unlock; |
| 740 | |
| 741 | retval = IRQ_HANDLED; |
| 742 | |
| 743 | if (irq_status & ENE_IRQ_TX) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 744 | dbg_verbose("TX interrupt"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 745 | if (!dev->hw_learning_and_tx_capable) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 746 | dbg("TX interrupt on unsupported device!"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 747 | goto unlock; |
| 748 | } |
| 749 | ene_tx_sample(dev); |
| 750 | } |
| 751 | |
| 752 | if (!(irq_status & ENE_IRQ_RX)) |
| 753 | goto unlock; |
| 754 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 755 | dbg_verbose("RX interrupt"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 756 | |
Maxim Levitsky | e1b1ddb | 2010-10-16 19:56:29 -0300 | [diff] [blame] | 757 | if (dev->hw_learning_and_tx_capable) |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 758 | ene_rx_sense_carrier(dev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 759 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 760 | /* On hardware that don't support extra buffer we need to trust |
| 761 | the interrupt and not track the read pointer */ |
| 762 | if (!dev->hw_extra_buffer) |
| 763 | dev->r_pointer = dev->w_pointer == 0 ? ENE_FW_PACKET_SIZE : 0; |
| 764 | |
| 765 | while (1) { |
| 766 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 767 | reg = ene_rx_get_sample_reg(dev); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 768 | |
| 769 | dbg_verbose("next sample to read at: %04x", reg); |
| 770 | if (!reg) |
| 771 | break; |
| 772 | |
| 773 | hw_value = ene_read_reg(dev, reg); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 774 | |
| 775 | if (dev->rx_fan_input_inuse) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 776 | |
| 777 | int offset = ENE_FW_SMPL_BUF_FAN - ENE_FW_SAMPLE_BUFFER; |
| 778 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 779 | /* read high part of the sample */ |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 780 | hw_value |= ene_read_reg(dev, reg + offset) << 8; |
| 781 | pulse = hw_value & ENE_FW_SMPL_BUF_FAN_PLS; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 782 | |
| 783 | /* clear space bit, and other unused bits */ |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 784 | hw_value &= ENE_FW_SMPL_BUF_FAN_MSK; |
| 785 | hw_sample = hw_value * ENE_FW_SAMPLE_PERIOD_FAN; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 786 | |
| 787 | } else { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 788 | pulse = !(hw_value & ENE_FW_SAMPLE_SPACE); |
| 789 | hw_value &= ~ENE_FW_SAMPLE_SPACE; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 790 | hw_sample = hw_value * sample_period; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 791 | |
| 792 | if (dev->rx_period_adjust) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 793 | hw_sample *= 100; |
| 794 | hw_sample /= (100 + dev->rx_period_adjust); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 795 | } |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 796 | } |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 797 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 798 | if (!dev->hw_extra_buffer && !hw_sample) { |
| 799 | dev->r_pointer = dev->w_pointer; |
| 800 | continue; |
| 801 | } |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 802 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 803 | dbg("RX: %d (%s)", hw_sample, pulse ? "pulse" : "space"); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 804 | |
Jarod Wilson | 5aad724 | 2011-01-06 16:59:36 -0300 | [diff] [blame] | 805 | ev.duration = US_TO_NS(hw_sample); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 806 | ev.pulse = pulse; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 807 | ir_raw_event_store_with_filter(dev->rdev, &ev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 808 | } |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 809 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 810 | ir_raw_event_handle(dev->rdev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 811 | unlock: |
| 812 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 813 | return retval; |
| 814 | } |
| 815 | |
| 816 | /* Initialize default settings */ |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 817 | static void ene_setup_default_settings(struct ene_device *dev) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 818 | { |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 819 | dev->tx_period = 32; |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 820 | dev->tx_duty_cycle = 50; /*%*/ |
| 821 | dev->transmitter_mask = 0x03; |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 822 | dev->learning_mode_enabled = learning_mode_force; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 823 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 824 | /* Set reasonable default timeout */ |
Jarod Wilson | 5aad724 | 2011-01-06 16:59:36 -0300 | [diff] [blame] | 825 | dev->rdev->timeout = US_TO_NS(150000); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 826 | } |
| 827 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 828 | /* Upload all hardware settings at once. Used at load and resume time */ |
| 829 | static void ene_setup_hw_settings(struct ene_device *dev) |
| 830 | { |
| 831 | if (dev->hw_learning_and_tx_capable) { |
| 832 | ene_tx_set_carrier(dev); |
| 833 | ene_tx_set_transmitters(dev); |
| 834 | } |
| 835 | |
| 836 | ene_rx_setup(dev); |
| 837 | } |
| 838 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 839 | /* outside interface: called on first open*/ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 840 | static int ene_open(struct rc_dev *rdev) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 841 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 842 | struct ene_device *dev = rdev->priv; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 843 | unsigned long flags; |
| 844 | |
| 845 | spin_lock_irqsave(&dev->hw_lock, flags); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 846 | ene_rx_enable(dev); |
| 847 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | /* outside interface: called on device close*/ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 852 | static void ene_close(struct rc_dev *rdev) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 853 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 854 | struct ene_device *dev = rdev->priv; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 855 | unsigned long flags; |
| 856 | spin_lock_irqsave(&dev->hw_lock, flags); |
| 857 | |
| 858 | ene_rx_disable(dev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 859 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 860 | } |
| 861 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 862 | /* outside interface: set transmitter mask */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 863 | static int ene_set_tx_mask(struct rc_dev *rdev, u32 tx_mask) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 864 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 865 | struct ene_device *dev = rdev->priv; |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 866 | dbg("TX: attempt to set transmitter mask %02x", tx_mask); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 867 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 868 | /* invalid txmask */ |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 869 | if (!tx_mask || tx_mask & ~0x03) { |
| 870 | dbg("TX: invalid mask"); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 871 | /* return count of transmitters */ |
| 872 | return 2; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 873 | } |
| 874 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 875 | dev->transmitter_mask = tx_mask; |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 876 | ene_tx_set_transmitters(dev); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 877 | return 0; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 878 | } |
| 879 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 880 | /* outside interface : set tx carrier */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 881 | static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 882 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 883 | struct ene_device *dev = rdev->priv; |
Dan Carpenter | 48cafec | 2012-09-11 07:11:24 -0300 | [diff] [blame] | 884 | u32 period; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 885 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 886 | dbg("TX: attempt to set tx carrier to %d kHz", carrier); |
Dan Carpenter | 48cafec | 2012-09-11 07:11:24 -0300 | [diff] [blame] | 887 | if (carrier == 0) |
| 888 | return -EINVAL; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 889 | |
Dan Carpenter | 48cafec | 2012-09-11 07:11:24 -0300 | [diff] [blame] | 890 | period = 2000000 / carrier; |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 891 | if (period && (period > ENE_CIRMOD_PRD_MAX || |
| 892 | period < ENE_CIRMOD_PRD_MIN)) { |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 893 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 894 | dbg("TX: out of range %d-%d kHz carrier", |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 895 | 2000 / ENE_CIRMOD_PRD_MIN, 2000 / ENE_CIRMOD_PRD_MAX); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 896 | return -1; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 897 | } |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 898 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 899 | dev->tx_period = period; |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 900 | ene_tx_set_carrier(dev); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 901 | return 0; |
| 902 | } |
| 903 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 904 | /*outside interface : set tx duty cycle */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 905 | static int ene_set_tx_duty_cycle(struct rc_dev *rdev, u32 duty_cycle) |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 906 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 907 | struct ene_device *dev = rdev->priv; |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 908 | dbg("TX: setting duty cycle to %d%%", duty_cycle); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 909 | dev->tx_duty_cycle = duty_cycle; |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 910 | ene_tx_set_carrier(dev); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 911 | return 0; |
| 912 | } |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 913 | |
| 914 | /* outside interface: enable learning mode */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 915 | static int ene_set_learning_mode(struct rc_dev *rdev, int enable) |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 916 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 917 | struct ene_device *dev = rdev->priv; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 918 | unsigned long flags; |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 919 | if (enable == dev->learning_mode_enabled) |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 920 | return 0; |
| 921 | |
| 922 | spin_lock_irqsave(&dev->hw_lock, flags); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 923 | dev->learning_mode_enabled = enable; |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 924 | ene_rx_disable(dev); |
| 925 | ene_rx_setup(dev); |
| 926 | ene_rx_enable(dev); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 927 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 928 | return 0; |
| 929 | } |
| 930 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 931 | static int ene_set_carrier_report(struct rc_dev *rdev, int enable) |
Maxim Levitsky | e1b1ddb | 2010-10-16 19:56:29 -0300 | [diff] [blame] | 932 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 933 | struct ene_device *dev = rdev->priv; |
Maxim Levitsky | e1b1ddb | 2010-10-16 19:56:29 -0300 | [diff] [blame] | 934 | unsigned long flags; |
| 935 | |
| 936 | if (enable == dev->carrier_detect_enabled) |
| 937 | return 0; |
| 938 | |
| 939 | spin_lock_irqsave(&dev->hw_lock, flags); |
| 940 | dev->carrier_detect_enabled = enable; |
| 941 | ene_rx_disable(dev); |
| 942 | ene_rx_setup(dev); |
| 943 | ene_rx_enable(dev); |
| 944 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 945 | return 0; |
| 946 | } |
| 947 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 948 | /* outside interface: enable or disable idle mode */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 949 | static void ene_set_idle(struct rc_dev *rdev, bool idle) |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 950 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 951 | struct ene_device *dev = rdev->priv; |
| 952 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 953 | if (idle) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 954 | ene_rx_reset(dev); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 955 | dbg("RX: end of data"); |
| 956 | } |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 957 | } |
| 958 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 959 | /* outside interface: transmit */ |
David Härdeman | 5588dc2 | 2011-04-28 12:13:58 -0300 | [diff] [blame] | 960 | static int ene_transmit(struct rc_dev *rdev, unsigned *buf, unsigned n) |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 961 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 962 | struct ene_device *dev = rdev->priv; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 963 | unsigned long flags; |
| 964 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 965 | dev->tx_buffer = buf; |
David Härdeman | 5588dc2 | 2011-04-28 12:13:58 -0300 | [diff] [blame] | 966 | dev->tx_len = n; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 967 | dev->tx_pos = 0; |
| 968 | dev->tx_reg = 0; |
| 969 | dev->tx_done = 0; |
| 970 | dev->tx_sample = 0; |
| 971 | dev->tx_sample_pulse = 0; |
| 972 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 973 | dbg("TX: %d samples", dev->tx_len); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 974 | |
| 975 | spin_lock_irqsave(&dev->hw_lock, flags); |
| 976 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 977 | ene_tx_enable(dev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 978 | |
| 979 | /* Transmit first two samples */ |
| 980 | ene_tx_sample(dev); |
| 981 | ene_tx_sample(dev); |
| 982 | |
| 983 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 984 | |
| 985 | if (wait_for_completion_timeout(&dev->tx_complete, 2 * HZ) == 0) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 986 | dbg("TX: timeout"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 987 | spin_lock_irqsave(&dev->hw_lock, flags); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 988 | ene_tx_disable(dev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 989 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 990 | } else |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 991 | dbg("TX: done"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 992 | return n; |
| 993 | } |
| 994 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 995 | /* probe entry */ |
| 996 | static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 997 | { |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 998 | int error = -ENOMEM; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 999 | struct rc_dev *rdev; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1000 | struct ene_device *dev; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1001 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1002 | /* allocate memory */ |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1003 | dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1004 | rdev = rc_allocate_device(); |
| 1005 | if (!dev || !rdev) |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1006 | goto failure; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1007 | |
| 1008 | /* validate resources */ |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1009 | error = -ENODEV; |
| 1010 | |
Kyle McMartin | 2e4c556 | 2011-01-06 16:59:33 -0300 | [diff] [blame] | 1011 | /* init these to -1, as 0 is valid for both */ |
| 1012 | dev->hw_io = -1; |
| 1013 | dev->irq = -1; |
| 1014 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1015 | if (!pnp_port_valid(pnp_dev, 0) || |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1016 | pnp_port_len(pnp_dev, 0) < ENE_IO_SIZE) |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1017 | goto failure; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1018 | |
| 1019 | if (!pnp_irq_valid(pnp_dev, 0)) |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1020 | goto failure; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1021 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1022 | spin_lock_init(&dev->hw_lock); |
| 1023 | |
Luis Henriques | b31b021 | 2012-06-19 11:29:49 -0300 | [diff] [blame] | 1024 | dev->hw_io = pnp_port_start(pnp_dev, 0); |
| 1025 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1026 | pnp_set_drvdata(pnp_dev, dev); |
| 1027 | dev->pnp_dev = pnp_dev; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1028 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1029 | /* don't allow too short/long sample periods */ |
| 1030 | if (sample_period < 5 || sample_period > 0x7F) |
| 1031 | sample_period = ENE_DEFAULT_SAMPLE_PERIOD; |
| 1032 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1033 | /* detect hardware version and features */ |
| 1034 | error = ene_hw_detect(dev); |
| 1035 | if (error) |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1036 | goto failure; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1037 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1038 | if (!dev->hw_learning_and_tx_capable && txsim) { |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1039 | dev->hw_learning_and_tx_capable = true; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1040 | setup_timer(&dev->tx_sim_timer, ene_tx_irqsim, |
| 1041 | (long unsigned int)dev); |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 1042 | pr_warn("Simulation of TX activated\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1043 | } |
| 1044 | |
Maxim Levitsky | a06423c | 2010-10-15 13:06:37 -0300 | [diff] [blame] | 1045 | if (!dev->hw_learning_and_tx_capable) |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 1046 | learning_mode_force = false; |
Maxim Levitsky | a06423c | 2010-10-15 13:06:37 -0300 | [diff] [blame] | 1047 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1048 | rdev->driver_type = RC_DRIVER_IR_RAW; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1049 | rdev->allowed_protos = RC_BIT_ALL; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1050 | rdev->priv = dev; |
| 1051 | rdev->open = ene_open; |
| 1052 | rdev->close = ene_close; |
| 1053 | rdev->s_idle = ene_set_idle; |
| 1054 | rdev->driver_name = ENE_DRIVER_NAME; |
| 1055 | rdev->map_name = RC_MAP_RC6_MCE; |
| 1056 | rdev->input_name = "ENE eHome Infrared Remote Receiver"; |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1057 | |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1058 | if (dev->hw_learning_and_tx_capable) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1059 | rdev->s_learning_mode = ene_set_learning_mode; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1060 | init_completion(&dev->tx_complete); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1061 | rdev->tx_ir = ene_transmit; |
| 1062 | rdev->s_tx_mask = ene_set_tx_mask; |
| 1063 | rdev->s_tx_carrier = ene_set_tx_carrier; |
| 1064 | rdev->s_tx_duty_cycle = ene_set_tx_duty_cycle; |
| 1065 | rdev->s_carrier_report = ene_set_carrier_report; |
| 1066 | rdev->input_name = "ENE eHome Infrared Remote Transceiver"; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1067 | } |
| 1068 | |
Kyle McMartin | 2e4c556 | 2011-01-06 16:59:33 -0300 | [diff] [blame] | 1069 | dev->rdev = rdev; |
| 1070 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 1071 | ene_rx_setup_hw_buffer(dev); |
| 1072 | ene_setup_default_settings(dev); |
| 1073 | ene_setup_hw_settings(dev); |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1074 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1075 | device_set_wakeup_capable(&pnp_dev->dev, true); |
| 1076 | device_set_wakeup_enable(&pnp_dev->dev, true); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1077 | |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1078 | /* claim the resources */ |
| 1079 | error = -EBUSY; |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1080 | if (!request_region(dev->hw_io, ENE_IO_SIZE, ENE_DRIVER_NAME)) { |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1081 | goto failure; |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | dev->irq = pnp_irq(pnp_dev, 0); |
| 1085 | if (request_irq(dev->irq, ene_isr, |
| 1086 | IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) { |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1087 | goto failure2; |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1088 | } |
| 1089 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1090 | error = rc_register_device(rdev); |
| 1091 | if (error < 0) |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1092 | goto failure3; |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1093 | |
Joe Perches | 7de3461 | 2011-08-21 19:56:46 -0300 | [diff] [blame] | 1094 | pr_notice("driver has been successfully loaded\n"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1095 | return 0; |
Matthijs Kooijman | 56411c0 | 2012-10-15 07:13:44 -0300 | [diff] [blame] | 1096 | |
| 1097 | failure3: |
| 1098 | free_irq(dev->irq, dev); |
| 1099 | failure2: |
| 1100 | release_region(dev->hw_io, ENE_IO_SIZE); |
| 1101 | failure: |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1102 | rc_free_device(rdev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1103 | kfree(dev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1104 | return error; |
| 1105 | } |
| 1106 | |
| 1107 | /* main unload function */ |
| 1108 | static void ene_remove(struct pnp_dev *pnp_dev) |
| 1109 | { |
| 1110 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); |
| 1111 | unsigned long flags; |
| 1112 | |
| 1113 | spin_lock_irqsave(&dev->hw_lock, flags); |
| 1114 | ene_rx_disable(dev); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 1115 | ene_rx_restore_hw_buffer(dev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1116 | spin_unlock_irqrestore(&dev->hw_lock, flags); |
| 1117 | |
| 1118 | free_irq(dev->irq, dev); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1119 | release_region(dev->hw_io, ENE_IO_SIZE); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1120 | rc_unregister_device(dev->rdev); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1121 | kfree(dev); |
| 1122 | } |
| 1123 | |
| 1124 | /* enable wake on IR (wakes on specific button on original remote) */ |
| 1125 | static void ene_enable_wake(struct ene_device *dev, int enable) |
| 1126 | { |
| 1127 | enable = enable && device_may_wakeup(&dev->pnp_dev->dev); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1128 | dbg("wake on IR %s", enable ? "enabled" : "disabled"); |
| 1129 | ene_set_clear_reg_mask(dev, ENE_FW1, ENE_FW1_WAKE, enable); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | #ifdef CONFIG_PM |
| 1133 | static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state) |
| 1134 | { |
| 1135 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1136 | ene_enable_wake(dev, true); |
| 1137 | |
| 1138 | /* TODO: add support for wake pattern */ |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | static int ene_resume(struct pnp_dev *pnp_dev) |
| 1143 | { |
| 1144 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 1145 | ene_setup_hw_settings(dev); |
| 1146 | |
| 1147 | if (dev->rx_enabled) |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1148 | ene_rx_enable(dev); |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 1149 | |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1150 | ene_enable_wake(dev, false); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1151 | return 0; |
| 1152 | } |
| 1153 | #endif |
| 1154 | |
| 1155 | static void ene_shutdown(struct pnp_dev *pnp_dev) |
| 1156 | { |
| 1157 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1158 | ene_enable_wake(dev, true); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | static const struct pnp_device_id ene_ids[] = { |
| 1162 | {.id = "ENE0100",}, |
| 1163 | {.id = "ENE0200",}, |
| 1164 | {.id = "ENE0201",}, |
Maxim Levitsky | 931e39a | 2010-07-31 11:59:26 -0300 | [diff] [blame] | 1165 | {.id = "ENE0202",}, |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1166 | {}, |
| 1167 | }; |
| 1168 | |
| 1169 | static struct pnp_driver ene_driver = { |
| 1170 | .name = ENE_DRIVER_NAME, |
| 1171 | .id_table = ene_ids, |
| 1172 | .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, |
| 1173 | |
| 1174 | .probe = ene_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame^] | 1175 | .remove = ene_remove, |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1176 | #ifdef CONFIG_PM |
| 1177 | .suspend = ene_suspend, |
| 1178 | .resume = ene_resume, |
| 1179 | #endif |
| 1180 | .shutdown = ene_shutdown, |
| 1181 | }; |
| 1182 | |
| 1183 | static int __init ene_init(void) |
| 1184 | { |
| 1185 | return pnp_register_driver(&ene_driver); |
| 1186 | } |
| 1187 | |
| 1188 | static void ene_exit(void) |
| 1189 | { |
| 1190 | pnp_unregister_driver(&ene_driver); |
| 1191 | } |
| 1192 | |
| 1193 | module_param(sample_period, int, S_IRUGO); |
| 1194 | MODULE_PARM_DESC(sample_period, "Hardware sample period (50 us default)"); |
| 1195 | |
Maxim Levitsky | c29bc4d | 2010-10-16 19:56:30 -0300 | [diff] [blame] | 1196 | module_param(learning_mode_force, bool, S_IRUGO); |
| 1197 | MODULE_PARM_DESC(learning_mode_force, "Enable learning mode by default"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1198 | |
| 1199 | module_param(debug, int, S_IRUGO | S_IWUSR); |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1200 | MODULE_PARM_DESC(debug, "Debug level"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1201 | |
| 1202 | module_param(txsim, bool, S_IRUGO); |
| 1203 | MODULE_PARM_DESC(txsim, |
| 1204 | "Simulate TX features on unsupported hardware (dangerous)"); |
| 1205 | |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1206 | MODULE_DEVICE_TABLE(pnp, ene_ids); |
| 1207 | MODULE_DESCRIPTION |
Maxim Levitsky | 11b64d3 | 2010-09-06 18:26:11 -0300 | [diff] [blame] | 1208 | ("Infrared input driver for KB3926B/C/D/E/F " |
| 1209 | "(aka ENE0100/ENE0200/ENE0201/ENE0202) CIR port"); |
Maxim Levitsky | 9ea53b7 | 2010-07-31 11:59:25 -0300 | [diff] [blame] | 1210 | |
| 1211 | MODULE_AUTHOR("Maxim Levitsky"); |
| 1212 | MODULE_LICENSE("GPL"); |
| 1213 | |
| 1214 | module_init(ene_init); |
| 1215 | module_exit(ene_exit); |