Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Nuvoton Technology Corporation w83667hg/w83677hg-i CIR |
| 3 | * |
| 4 | * Copyright (C) 2010 Jarod Wilson <jarod@redhat.com> |
| 5 | * Copyright (C) 2009 Nuvoton PS Team |
| 6 | * |
| 7 | * Special thanks to Nuvoton for providing hardware, spec sheets and |
| 8 | * sample code upon which portions of this driver are based. Indirect |
| 9 | * thanks also to Maxim Levitsky, whose ene_ir driver this driver is |
| 10 | * modeled after. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of the |
| 15 | * License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, but |
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * General Public License for more details. |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 21 | */ |
| 22 | |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/pnp.h> |
| 28 | #include <linux/io.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/sched.h> |
| 31 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 32 | #include <media/rc-core.h> |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 33 | #include <linux/pci_ids.h> |
| 34 | |
| 35 | #include "nuvoton-cir.h" |
| 36 | |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 37 | static void nvt_clear_cir_wake_fifo(struct nvt_dev *nvt); |
| 38 | |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 39 | static const struct nvt_chip nvt_chips[] = { |
| 40 | { "w83667hg", NVT_W83667HG }, |
| 41 | { "NCT6775F", NVT_6775F }, |
| 42 | { "NCT6776F", NVT_6776F }, |
Heiner Kallweit | d0b528d | 2015-10-29 19:22:23 -0200 | [diff] [blame] | 43 | { "NCT6779D", NVT_6779D }, |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 44 | }; |
| 45 | |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 46 | static inline struct device *nvt_get_dev(const struct nvt_dev *nvt) |
| 47 | { |
| 48 | return nvt->rdev->dev.parent; |
| 49 | } |
| 50 | |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 51 | static inline bool is_w83667hg(struct nvt_dev *nvt) |
| 52 | { |
| 53 | return nvt->chip_ver == NVT_W83667HG; |
| 54 | } |
| 55 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 56 | /* write val to config reg */ |
| 57 | static inline void nvt_cr_write(struct nvt_dev *nvt, u8 val, u8 reg) |
| 58 | { |
| 59 | outb(reg, nvt->cr_efir); |
| 60 | outb(val, nvt->cr_efdr); |
| 61 | } |
| 62 | |
| 63 | /* read val from config reg */ |
| 64 | static inline u8 nvt_cr_read(struct nvt_dev *nvt, u8 reg) |
| 65 | { |
| 66 | outb(reg, nvt->cr_efir); |
| 67 | return inb(nvt->cr_efdr); |
| 68 | } |
| 69 | |
| 70 | /* update config register bit without changing other bits */ |
| 71 | static inline void nvt_set_reg_bit(struct nvt_dev *nvt, u8 val, u8 reg) |
| 72 | { |
| 73 | u8 tmp = nvt_cr_read(nvt, reg) | val; |
| 74 | nvt_cr_write(nvt, tmp, reg); |
| 75 | } |
| 76 | |
| 77 | /* clear config register bit without changing other bits */ |
| 78 | static inline void nvt_clear_reg_bit(struct nvt_dev *nvt, u8 val, u8 reg) |
| 79 | { |
| 80 | u8 tmp = nvt_cr_read(nvt, reg) & ~val; |
| 81 | nvt_cr_write(nvt, tmp, reg); |
| 82 | } |
| 83 | |
| 84 | /* enter extended function mode */ |
Heiner Kallweit | 3def9ad | 2015-12-30 14:39:22 -0200 | [diff] [blame] | 85 | static inline int nvt_efm_enable(struct nvt_dev *nvt) |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 86 | { |
Heiner Kallweit | 3def9ad | 2015-12-30 14:39:22 -0200 | [diff] [blame] | 87 | if (!request_muxed_region(nvt->cr_efir, 2, NVT_DRIVER_NAME)) |
| 88 | return -EBUSY; |
| 89 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 90 | /* Enabling Extended Function Mode explicitly requires writing 2x */ |
| 91 | outb(EFER_EFM_ENABLE, nvt->cr_efir); |
| 92 | outb(EFER_EFM_ENABLE, nvt->cr_efir); |
Heiner Kallweit | 3def9ad | 2015-12-30 14:39:22 -0200 | [diff] [blame] | 93 | |
| 94 | return 0; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* exit extended function mode */ |
| 98 | static inline void nvt_efm_disable(struct nvt_dev *nvt) |
| 99 | { |
| 100 | outb(EFER_EFM_DISABLE, nvt->cr_efir); |
Heiner Kallweit | 3def9ad | 2015-12-30 14:39:22 -0200 | [diff] [blame] | 101 | |
| 102 | release_region(nvt->cr_efir, 2); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * When you want to address a specific logical device, write its logical |
| 107 | * device number to CR_LOGICAL_DEV_SEL, then enable/disable by writing |
| 108 | * 0x1/0x0 respectively to CR_LOGICAL_DEV_EN. |
| 109 | */ |
| 110 | static inline void nvt_select_logical_dev(struct nvt_dev *nvt, u8 ldev) |
| 111 | { |
Heiner Kallweit | 7a89836 | 2015-12-30 14:39:34 -0200 | [diff] [blame] | 112 | nvt_cr_write(nvt, ldev, CR_LOGICAL_DEV_SEL); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 113 | } |
| 114 | |
Heiner Kallweit | 0890655 | 2015-12-30 14:40:12 -0200 | [diff] [blame] | 115 | /* select and enable logical device with setting EFM mode*/ |
| 116 | static inline void nvt_enable_logical_dev(struct nvt_dev *nvt, u8 ldev) |
| 117 | { |
| 118 | nvt_efm_enable(nvt); |
| 119 | nvt_select_logical_dev(nvt, ldev); |
| 120 | nvt_cr_write(nvt, LOGICAL_DEV_ENABLE, CR_LOGICAL_DEV_EN); |
| 121 | nvt_efm_disable(nvt); |
| 122 | } |
| 123 | |
Heiner Kallweit | a17ede9 | 2015-12-30 14:40:05 -0200 | [diff] [blame] | 124 | /* select and disable logical device with setting EFM mode*/ |
| 125 | static inline void nvt_disable_logical_dev(struct nvt_dev *nvt, u8 ldev) |
| 126 | { |
| 127 | nvt_efm_enable(nvt); |
| 128 | nvt_select_logical_dev(nvt, ldev); |
| 129 | nvt_cr_write(nvt, LOGICAL_DEV_DISABLE, CR_LOGICAL_DEV_EN); |
| 130 | nvt_efm_disable(nvt); |
| 131 | } |
| 132 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 133 | /* write val to cir config register */ |
| 134 | static inline void nvt_cir_reg_write(struct nvt_dev *nvt, u8 val, u8 offset) |
| 135 | { |
| 136 | outb(val, nvt->cir_addr + offset); |
| 137 | } |
| 138 | |
| 139 | /* read val from cir config register */ |
| 140 | static u8 nvt_cir_reg_read(struct nvt_dev *nvt, u8 offset) |
| 141 | { |
Heiner Kallweit | 7ac7b02 | 2016-06-24 02:39:28 -0300 | [diff] [blame] | 142 | return inb(nvt->cir_addr + offset); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* write val to cir wake register */ |
| 146 | static inline void nvt_cir_wake_reg_write(struct nvt_dev *nvt, |
| 147 | u8 val, u8 offset) |
| 148 | { |
| 149 | outb(val, nvt->cir_wake_addr + offset); |
| 150 | } |
| 151 | |
| 152 | /* read val from cir wake config register */ |
| 153 | static u8 nvt_cir_wake_reg_read(struct nvt_dev *nvt, u8 offset) |
| 154 | { |
Heiner Kallweit | 7ac7b02 | 2016-06-24 02:39:28 -0300 | [diff] [blame] | 155 | return inb(nvt->cir_wake_addr + offset); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 156 | } |
| 157 | |
Heiner Kallweit | fb16aaf | 2015-12-30 14:42:05 -0200 | [diff] [blame] | 158 | /* don't override io address if one is set already */ |
| 159 | static void nvt_set_ioaddr(struct nvt_dev *nvt, unsigned long *ioaddr) |
| 160 | { |
| 161 | unsigned long old_addr; |
| 162 | |
| 163 | old_addr = nvt_cr_read(nvt, CR_CIR_BASE_ADDR_HI) << 8; |
| 164 | old_addr |= nvt_cr_read(nvt, CR_CIR_BASE_ADDR_LO); |
| 165 | |
| 166 | if (old_addr) |
| 167 | *ioaddr = old_addr; |
| 168 | else { |
| 169 | nvt_cr_write(nvt, *ioaddr >> 8, CR_CIR_BASE_ADDR_HI); |
| 170 | nvt_cr_write(nvt, *ioaddr & 0xff, CR_CIR_BASE_ADDR_LO); |
| 171 | } |
| 172 | } |
| 173 | |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 174 | static void nvt_write_wakeup_codes(struct rc_dev *dev, |
| 175 | const u8 *wbuf, int count) |
| 176 | { |
| 177 | u8 tolerance, config; |
| 178 | struct nvt_dev *nvt = dev->priv; |
Heiner Kallweit | c1305a4 | 2017-02-12 15:01:22 -0200 | [diff] [blame] | 179 | unsigned long flags; |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 180 | int i; |
| 181 | |
| 182 | /* hardcode the tolerance to 10% */ |
| 183 | tolerance = DIV_ROUND_UP(count, 10); |
| 184 | |
Heiner Kallweit | c1305a4 | 2017-02-12 15:01:22 -0200 | [diff] [blame] | 185 | spin_lock_irqsave(&nvt->lock, flags); |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 186 | |
| 187 | nvt_clear_cir_wake_fifo(nvt); |
| 188 | nvt_cir_wake_reg_write(nvt, count, CIR_WAKE_FIFO_CMP_DEEP); |
| 189 | nvt_cir_wake_reg_write(nvt, tolerance, CIR_WAKE_FIFO_CMP_TOL); |
| 190 | |
| 191 | config = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRCON); |
| 192 | |
| 193 | /* enable writes to wake fifo */ |
| 194 | nvt_cir_wake_reg_write(nvt, config | CIR_WAKE_IRCON_MODE1, |
| 195 | CIR_WAKE_IRCON); |
| 196 | |
| 197 | if (count) |
| 198 | pr_info("Wake samples (%d) =", count); |
| 199 | else |
| 200 | pr_info("Wake sample fifo cleared"); |
| 201 | |
| 202 | for (i = 0; i < count; i++) |
| 203 | nvt_cir_wake_reg_write(nvt, wbuf[i], CIR_WAKE_WR_FIFO_DATA); |
| 204 | |
| 205 | nvt_cir_wake_reg_write(nvt, config, CIR_WAKE_IRCON); |
| 206 | |
Heiner Kallweit | c1305a4 | 2017-02-12 15:01:22 -0200 | [diff] [blame] | 207 | spin_unlock_irqrestore(&nvt->lock, flags); |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 208 | } |
| 209 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 210 | static ssize_t wakeup_data_show(struct device *dev, |
| 211 | struct device_attribute *attr, |
| 212 | char *buf) |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 213 | { |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 214 | struct rc_dev *rc_dev = to_rc_dev(dev); |
| 215 | struct nvt_dev *nvt = rc_dev->priv; |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 216 | int fifo_len, duration; |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 217 | unsigned long flags; |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 218 | ssize_t buf_len = 0; |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 219 | int i; |
| 220 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 221 | spin_lock_irqsave(&nvt->lock, flags); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 222 | |
| 223 | fifo_len = nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_COUNT); |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 224 | fifo_len = min(fifo_len, WAKEUP_MAX_SIZE); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 225 | |
| 226 | /* go to first element to be read */ |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 227 | while (nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY_IDX)) |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 228 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY); |
| 229 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 230 | for (i = 0; i < fifo_len; i++) { |
| 231 | duration = nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY); |
| 232 | duration = (duration & BUF_LEN_MASK) * SAMPLE_PERIOD; |
| 233 | buf_len += snprintf(buf + buf_len, PAGE_SIZE - buf_len, |
| 234 | "%d ", duration); |
| 235 | } |
| 236 | buf_len += snprintf(buf + buf_len, PAGE_SIZE - buf_len, "\n"); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 237 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 238 | spin_unlock_irqrestore(&nvt->lock, flags); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 239 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 240 | return buf_len; |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 241 | } |
| 242 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 243 | static ssize_t wakeup_data_store(struct device *dev, |
| 244 | struct device_attribute *attr, |
| 245 | const char *buf, size_t len) |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 246 | { |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 247 | struct rc_dev *rc_dev = to_rc_dev(dev); |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 248 | u8 wake_buf[WAKEUP_MAX_SIZE]; |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 249 | char **argv; |
| 250 | int i, count; |
| 251 | unsigned int val; |
| 252 | ssize_t ret; |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 253 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 254 | argv = argv_split(GFP_KERNEL, buf, &count); |
| 255 | if (!argv) |
| 256 | return -ENOMEM; |
| 257 | if (!count || count > WAKEUP_MAX_SIZE) { |
| 258 | ret = -EINVAL; |
| 259 | goto out; |
| 260 | } |
| 261 | |
| 262 | for (i = 0; i < count; i++) { |
| 263 | ret = kstrtouint(argv[i], 10, &val); |
| 264 | if (ret) |
| 265 | goto out; |
| 266 | val = DIV_ROUND_CLOSEST(val, SAMPLE_PERIOD); |
| 267 | if (!val || val > 0x7f) { |
| 268 | ret = -EINVAL; |
| 269 | goto out; |
| 270 | } |
| 271 | wake_buf[i] = val; |
| 272 | /* sequence must start with a pulse */ |
| 273 | if (i % 2 == 0) |
| 274 | wake_buf[i] |= BUF_PULSE_BIT; |
| 275 | } |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 276 | |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 277 | nvt_write_wakeup_codes(rc_dev, wake_buf, count); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 278 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 279 | ret = len; |
| 280 | out: |
| 281 | argv_free(argv); |
| 282 | return ret; |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 283 | } |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 284 | static DEVICE_ATTR_RW(wakeup_data); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 285 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 286 | /* dump current cir register contents */ |
| 287 | static void cir_dump_regs(struct nvt_dev *nvt) |
| 288 | { |
| 289 | nvt_efm_enable(nvt); |
| 290 | nvt_select_logical_dev(nvt, LOGICAL_DEV_CIR); |
| 291 | |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 292 | pr_info("%s: Dump CIR logical device registers:\n", NVT_DRIVER_NAME); |
| 293 | pr_info(" * CR CIR ACTIVE : 0x%x\n", |
| 294 | nvt_cr_read(nvt, CR_LOGICAL_DEV_EN)); |
| 295 | pr_info(" * CR CIR BASE ADDR: 0x%x\n", |
| 296 | (nvt_cr_read(nvt, CR_CIR_BASE_ADDR_HI) << 8) | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 297 | nvt_cr_read(nvt, CR_CIR_BASE_ADDR_LO)); |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 298 | pr_info(" * CR CIR IRQ NUM: 0x%x\n", |
| 299 | nvt_cr_read(nvt, CR_CIR_IRQ_RSRC)); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 300 | |
| 301 | nvt_efm_disable(nvt); |
| 302 | |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 303 | pr_info("%s: Dump CIR registers:\n", NVT_DRIVER_NAME); |
| 304 | pr_info(" * IRCON: 0x%x\n", nvt_cir_reg_read(nvt, CIR_IRCON)); |
| 305 | pr_info(" * IRSTS: 0x%x\n", nvt_cir_reg_read(nvt, CIR_IRSTS)); |
| 306 | pr_info(" * IREN: 0x%x\n", nvt_cir_reg_read(nvt, CIR_IREN)); |
| 307 | pr_info(" * RXFCONT: 0x%x\n", nvt_cir_reg_read(nvt, CIR_RXFCONT)); |
| 308 | pr_info(" * CP: 0x%x\n", nvt_cir_reg_read(nvt, CIR_CP)); |
| 309 | pr_info(" * CC: 0x%x\n", nvt_cir_reg_read(nvt, CIR_CC)); |
| 310 | pr_info(" * SLCH: 0x%x\n", nvt_cir_reg_read(nvt, CIR_SLCH)); |
| 311 | pr_info(" * SLCL: 0x%x\n", nvt_cir_reg_read(nvt, CIR_SLCL)); |
| 312 | pr_info(" * FIFOCON: 0x%x\n", nvt_cir_reg_read(nvt, CIR_FIFOCON)); |
| 313 | pr_info(" * IRFIFOSTS: 0x%x\n", nvt_cir_reg_read(nvt, CIR_IRFIFOSTS)); |
| 314 | pr_info(" * SRXFIFO: 0x%x\n", nvt_cir_reg_read(nvt, CIR_SRXFIFO)); |
| 315 | pr_info(" * TXFCONT: 0x%x\n", nvt_cir_reg_read(nvt, CIR_TXFCONT)); |
| 316 | pr_info(" * STXFIFO: 0x%x\n", nvt_cir_reg_read(nvt, CIR_STXFIFO)); |
| 317 | pr_info(" * FCCH: 0x%x\n", nvt_cir_reg_read(nvt, CIR_FCCH)); |
| 318 | pr_info(" * FCCL: 0x%x\n", nvt_cir_reg_read(nvt, CIR_FCCL)); |
| 319 | pr_info(" * IRFSM: 0x%x\n", nvt_cir_reg_read(nvt, CIR_IRFSM)); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /* dump current cir wake register contents */ |
| 323 | static void cir_wake_dump_regs(struct nvt_dev *nvt) |
| 324 | { |
| 325 | u8 i, fifo_len; |
| 326 | |
| 327 | nvt_efm_enable(nvt); |
| 328 | nvt_select_logical_dev(nvt, LOGICAL_DEV_CIR_WAKE); |
| 329 | |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 330 | pr_info("%s: Dump CIR WAKE logical device registers:\n", |
| 331 | NVT_DRIVER_NAME); |
| 332 | pr_info(" * CR CIR WAKE ACTIVE : 0x%x\n", |
| 333 | nvt_cr_read(nvt, CR_LOGICAL_DEV_EN)); |
| 334 | pr_info(" * CR CIR WAKE BASE ADDR: 0x%x\n", |
| 335 | (nvt_cr_read(nvt, CR_CIR_BASE_ADDR_HI) << 8) | |
Jarod Wilson | 4e6e29a | 2010-10-15 11:07:37 -0300 | [diff] [blame] | 336 | nvt_cr_read(nvt, CR_CIR_BASE_ADDR_LO)); |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 337 | pr_info(" * CR CIR WAKE IRQ NUM: 0x%x\n", |
| 338 | nvt_cr_read(nvt, CR_CIR_IRQ_RSRC)); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 339 | |
| 340 | nvt_efm_disable(nvt); |
| 341 | |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 342 | pr_info("%s: Dump CIR WAKE registers\n", NVT_DRIVER_NAME); |
| 343 | pr_info(" * IRCON: 0x%x\n", |
| 344 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRCON)); |
| 345 | pr_info(" * IRSTS: 0x%x\n", |
| 346 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRSTS)); |
| 347 | pr_info(" * IREN: 0x%x\n", |
| 348 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_IREN)); |
| 349 | pr_info(" * FIFO CMP DEEP: 0x%x\n", |
| 350 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_CMP_DEEP)); |
| 351 | pr_info(" * FIFO CMP TOL: 0x%x\n", |
| 352 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_CMP_TOL)); |
| 353 | pr_info(" * FIFO COUNT: 0x%x\n", |
| 354 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_COUNT)); |
| 355 | pr_info(" * SLCH: 0x%x\n", |
| 356 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_SLCH)); |
| 357 | pr_info(" * SLCL: 0x%x\n", |
| 358 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_SLCL)); |
| 359 | pr_info(" * FIFOCON: 0x%x\n", |
| 360 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFOCON)); |
| 361 | pr_info(" * SRXFSTS: 0x%x\n", |
| 362 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_SRXFSTS)); |
| 363 | pr_info(" * SAMPLE RX FIFO: 0x%x\n", |
| 364 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_SAMPLE_RX_FIFO)); |
| 365 | pr_info(" * WR FIFO DATA: 0x%x\n", |
| 366 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_WR_FIFO_DATA)); |
| 367 | pr_info(" * RD FIFO ONLY: 0x%x\n", |
| 368 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY)); |
| 369 | pr_info(" * RD FIFO ONLY IDX: 0x%x\n", |
| 370 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY_IDX)); |
| 371 | pr_info(" * FIFO IGNORE: 0x%x\n", |
| 372 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_IGNORE)); |
| 373 | pr_info(" * IRFSM: 0x%x\n", |
| 374 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRFSM)); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 375 | |
| 376 | fifo_len = nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_COUNT); |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 377 | pr_info("%s: Dump CIR WAKE FIFO (len %d)\n", NVT_DRIVER_NAME, fifo_len); |
| 378 | pr_info("* Contents ="); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 379 | for (i = 0; i < fifo_len; i++) |
Joe Perches | 563cd5c | 2012-05-20 18:45:15 -0300 | [diff] [blame] | 380 | pr_cont(" %02x", |
| 381 | nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY)); |
| 382 | pr_cont("\n"); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 383 | } |
| 384 | |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 385 | static inline const char *nvt_find_chip(struct nvt_dev *nvt, int id) |
| 386 | { |
| 387 | int i; |
| 388 | |
| 389 | for (i = 0; i < ARRAY_SIZE(nvt_chips); i++) |
| 390 | if ((id & SIO_ID_MASK) == nvt_chips[i].chip_ver) { |
| 391 | nvt->chip_ver = nvt_chips[i].chip_ver; |
| 392 | return nvt_chips[i].name; |
| 393 | } |
| 394 | |
| 395 | return NULL; |
| 396 | } |
| 397 | |
| 398 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 399 | /* detect hardware features */ |
Heiner Kallweit | 3f1321c | 2015-12-30 14:43:29 -0200 | [diff] [blame] | 400 | static int nvt_hw_detect(struct nvt_dev *nvt) |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 401 | { |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 402 | struct device *dev = nvt_get_dev(nvt); |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 403 | const char *chip_name; |
| 404 | int chip_id; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 405 | |
| 406 | nvt_efm_enable(nvt); |
| 407 | |
| 408 | /* Check if we're wired for the alternate EFER setup */ |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 409 | nvt->chip_major = nvt_cr_read(nvt, CR_CHIP_ID_HI); |
| 410 | if (nvt->chip_major == 0xff) { |
Heiner Kallweit | 5cac1f67 | 2016-07-07 03:17:39 -0300 | [diff] [blame] | 411 | nvt_efm_disable(nvt); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 412 | nvt->cr_efir = CR_EFIR2; |
| 413 | nvt->cr_efdr = CR_EFDR2; |
| 414 | nvt_efm_enable(nvt); |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 415 | nvt->chip_major = nvt_cr_read(nvt, CR_CHIP_ID_HI); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 416 | } |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 417 | nvt->chip_minor = nvt_cr_read(nvt, CR_CHIP_ID_LO); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 418 | |
Heiner Kallweit | 3f1321c | 2015-12-30 14:43:29 -0200 | [diff] [blame] | 419 | nvt_efm_disable(nvt); |
| 420 | |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 421 | chip_id = nvt->chip_major << 8 | nvt->chip_minor; |
Heiner Kallweit | 3f1321c | 2015-12-30 14:43:29 -0200 | [diff] [blame] | 422 | if (chip_id == NVT_INVALID) { |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 423 | dev_err(dev, "No device found on either EFM port\n"); |
Heiner Kallweit | 3f1321c | 2015-12-30 14:43:29 -0200 | [diff] [blame] | 424 | return -ENODEV; |
| 425 | } |
| 426 | |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 427 | chip_name = nvt_find_chip(nvt, chip_id); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 428 | |
Jarod Wilson | 362d3a3 | 2011-04-12 14:00:07 -0300 | [diff] [blame] | 429 | /* warn, but still let the driver load, if we don't know this chip */ |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 430 | if (!chip_name) |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 431 | dev_warn(dev, |
Heiner Kallweit | 211477f | 2015-10-29 19:23:01 -0200 | [diff] [blame] | 432 | "unknown chip, id: 0x%02x 0x%02x, it may not work...", |
| 433 | nvt->chip_major, nvt->chip_minor); |
Jarod Wilson | 362d3a3 | 2011-04-12 14:00:07 -0300 | [diff] [blame] | 434 | else |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 435 | dev_info(dev, "found %s or compatible: chip id: 0x%02x 0x%02x", |
Heiner Kallweit | af08233 | 2015-10-29 19:23:22 -0200 | [diff] [blame] | 436 | chip_name, nvt->chip_major, nvt->chip_minor); |
Jarod Wilson | 362d3a3 | 2011-04-12 14:00:07 -0300 | [diff] [blame] | 437 | |
Heiner Kallweit | 3f1321c | 2015-12-30 14:43:29 -0200 | [diff] [blame] | 438 | return 0; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static void nvt_cir_ldev_init(struct nvt_dev *nvt) |
| 442 | { |
Jarod Wilson | 39381d4 | 2011-04-12 13:38:27 -0300 | [diff] [blame] | 443 | u8 val, psreg, psmask, psval; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 444 | |
Heiner Kallweit | b5cf725 | 2015-10-29 19:21:38 -0200 | [diff] [blame] | 445 | if (is_w83667hg(nvt)) { |
Jarod Wilson | 39381d4 | 2011-04-12 13:38:27 -0300 | [diff] [blame] | 446 | psreg = CR_MULTIFUNC_PIN_SEL; |
| 447 | psmask = MULTIFUNC_PIN_SEL_MASK; |
| 448 | psval = MULTIFUNC_ENABLE_CIR | MULTIFUNC_ENABLE_CIRWB; |
| 449 | } else { |
| 450 | psreg = CR_OUTPUT_PIN_SEL; |
| 451 | psmask = OUTPUT_PIN_SEL_MASK; |
| 452 | psval = OUTPUT_ENABLE_CIR | OUTPUT_ENABLE_CIRWB; |
| 453 | } |
| 454 | |
| 455 | /* output pin selection: enable CIR, with WB sensor enabled */ |
| 456 | val = nvt_cr_read(nvt, psreg); |
| 457 | val &= psmask; |
| 458 | val |= psval; |
| 459 | nvt_cr_write(nvt, val, psreg); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 460 | |
Heiner Kallweit | ccca00d | 2015-12-30 14:43:59 -0200 | [diff] [blame] | 461 | /* Select CIR logical device */ |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 462 | nvt_select_logical_dev(nvt, LOGICAL_DEV_CIR); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 463 | |
Heiner Kallweit | fb16aaf | 2015-12-30 14:42:05 -0200 | [diff] [blame] | 464 | nvt_set_ioaddr(nvt, &nvt->cir_addr); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 465 | |
| 466 | nvt_cr_write(nvt, nvt->cir_irq, CR_CIR_IRQ_RSRC); |
| 467 | |
| 468 | nvt_dbg("CIR initialized, base io port address: 0x%lx, irq: %d", |
| 469 | nvt->cir_addr, nvt->cir_irq); |
| 470 | } |
| 471 | |
| 472 | static void nvt_cir_wake_ldev_init(struct nvt_dev *nvt) |
| 473 | { |
Heiner Kallweit | ccca00d | 2015-12-30 14:43:59 -0200 | [diff] [blame] | 474 | /* Select ACPI logical device and anable it */ |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 475 | nvt_select_logical_dev(nvt, LOGICAL_DEV_ACPI); |
| 476 | nvt_cr_write(nvt, LOGICAL_DEV_ENABLE, CR_LOGICAL_DEV_EN); |
| 477 | |
| 478 | /* Enable CIR Wake via PSOUT# (Pin60) */ |
| 479 | nvt_set_reg_bit(nvt, CIR_WAKE_ENABLE_BIT, CR_ACPI_CIR_WAKE); |
| 480 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 481 | /* enable pme interrupt of cir wakeup event */ |
| 482 | nvt_set_reg_bit(nvt, PME_INTR_CIR_PASS_BIT, CR_ACPI_IRQ_EVENTS2); |
| 483 | |
Heiner Kallweit | ccca00d | 2015-12-30 14:43:59 -0200 | [diff] [blame] | 484 | /* Select CIR Wake logical device */ |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 485 | nvt_select_logical_dev(nvt, LOGICAL_DEV_CIR_WAKE); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 486 | |
Heiner Kallweit | fb16aaf | 2015-12-30 14:42:05 -0200 | [diff] [blame] | 487 | nvt_set_ioaddr(nvt, &nvt->cir_wake_addr); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 488 | |
Heiner Kallweit | cb48b36 | 2016-06-24 02:38:54 -0300 | [diff] [blame] | 489 | nvt_dbg("CIR Wake initialized, base io port address: 0x%lx", |
| 490 | nvt->cir_wake_addr); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* clear out the hardware's cir rx fifo */ |
| 494 | static void nvt_clear_cir_fifo(struct nvt_dev *nvt) |
| 495 | { |
Heiner Kallweit | 7ac7b02 | 2016-06-24 02:39:28 -0300 | [diff] [blame] | 496 | u8 val = nvt_cir_reg_read(nvt, CIR_FIFOCON); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 497 | nvt_cir_reg_write(nvt, val | CIR_FIFOCON_RXFIFOCLR, CIR_FIFOCON); |
| 498 | } |
| 499 | |
| 500 | /* clear out the hardware's cir wake rx fifo */ |
| 501 | static void nvt_clear_cir_wake_fifo(struct nvt_dev *nvt) |
| 502 | { |
Heiner Kallweit | e1a7d98 | 2015-12-30 14:40:47 -0200 | [diff] [blame] | 503 | u8 val, config; |
| 504 | |
| 505 | config = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRCON); |
| 506 | |
| 507 | /* clearing wake fifo works in learning mode only */ |
| 508 | nvt_cir_wake_reg_write(nvt, config & ~CIR_WAKE_IRCON_MODE0, |
| 509 | CIR_WAKE_IRCON); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 510 | |
| 511 | val = nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFOCON); |
| 512 | nvt_cir_wake_reg_write(nvt, val | CIR_WAKE_FIFOCON_RXFIFOCLR, |
| 513 | CIR_WAKE_FIFOCON); |
Heiner Kallweit | e1a7d98 | 2015-12-30 14:40:47 -0200 | [diff] [blame] | 514 | |
| 515 | nvt_cir_wake_reg_write(nvt, config, CIR_WAKE_IRCON); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /* clear out the hardware's cir tx fifo */ |
| 519 | static void nvt_clear_tx_fifo(struct nvt_dev *nvt) |
| 520 | { |
| 521 | u8 val; |
| 522 | |
| 523 | val = nvt_cir_reg_read(nvt, CIR_FIFOCON); |
| 524 | nvt_cir_reg_write(nvt, val | CIR_FIFOCON_TXFIFOCLR, CIR_FIFOCON); |
| 525 | } |
| 526 | |
Jarod Wilson | fbdc781 | 2010-10-08 16:16:23 -0300 | [diff] [blame] | 527 | /* enable RX Trigger Level Reach and Packet End interrupts */ |
| 528 | static void nvt_set_cir_iren(struct nvt_dev *nvt) |
| 529 | { |
| 530 | u8 iren; |
| 531 | |
Heiner Kallweit | 398d9da | 2016-05-22 10:43:40 -0300 | [diff] [blame] | 532 | iren = CIR_IREN_RTR | CIR_IREN_PE | CIR_IREN_RFO; |
Jarod Wilson | fbdc781 | 2010-10-08 16:16:23 -0300 | [diff] [blame] | 533 | nvt_cir_reg_write(nvt, iren, CIR_IREN); |
| 534 | } |
| 535 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 536 | static void nvt_cir_regs_init(struct nvt_dev *nvt) |
| 537 | { |
| 538 | /* set sample limit count (PE interrupt raised when reached) */ |
| 539 | nvt_cir_reg_write(nvt, CIR_RX_LIMIT_COUNT >> 8, CIR_SLCH); |
| 540 | nvt_cir_reg_write(nvt, CIR_RX_LIMIT_COUNT & 0xff, CIR_SLCL); |
| 541 | |
| 542 | /* set fifo irq trigger levels */ |
| 543 | nvt_cir_reg_write(nvt, CIR_FIFOCON_TX_TRIGGER_LEV | |
| 544 | CIR_FIFOCON_RX_TRIGGER_LEV, CIR_FIFOCON); |
| 545 | |
| 546 | /* |
| 547 | * Enable TX and RX, specify carrier on = low, off = high, and set |
| 548 | * sample period (currently 50us) |
| 549 | */ |
Jarod Wilson | 4e6e29a | 2010-10-15 11:07:37 -0300 | [diff] [blame] | 550 | nvt_cir_reg_write(nvt, |
| 551 | CIR_IRCON_TXEN | CIR_IRCON_RXEN | |
| 552 | CIR_IRCON_RXINV | CIR_IRCON_SAMPLE_PERIOD_SEL, |
| 553 | CIR_IRCON); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 554 | |
| 555 | /* clear hardware rx and tx fifos */ |
| 556 | nvt_clear_cir_fifo(nvt); |
| 557 | nvt_clear_tx_fifo(nvt); |
| 558 | |
| 559 | /* clear any and all stray interrupts */ |
| 560 | nvt_cir_reg_write(nvt, 0xff, CIR_IRSTS); |
| 561 | |
Jarod Wilson | fbdc781 | 2010-10-08 16:16:23 -0300 | [diff] [blame] | 562 | /* and finally, enable interrupts */ |
| 563 | nvt_set_cir_iren(nvt); |
Heiner Kallweit | ccca00d | 2015-12-30 14:43:59 -0200 | [diff] [blame] | 564 | |
| 565 | /* enable the CIR logical device */ |
| 566 | nvt_enable_logical_dev(nvt, LOGICAL_DEV_CIR); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | static void nvt_cir_wake_regs_init(struct nvt_dev *nvt) |
| 570 | { |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 571 | /* |
Heiner Kallweit | 594ccee | 2016-06-24 02:39:04 -0300 | [diff] [blame] | 572 | * Disable RX, set specific carrier on = low, off = high, |
| 573 | * and sample period (currently 50us) |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 574 | */ |
Heiner Kallweit | 594ccee | 2016-06-24 02:39:04 -0300 | [diff] [blame] | 575 | nvt_cir_wake_reg_write(nvt, CIR_WAKE_IRCON_MODE0 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 576 | CIR_WAKE_IRCON_R | CIR_WAKE_IRCON_RXINV | |
| 577 | CIR_WAKE_IRCON_SAMPLE_PERIOD_SEL, |
| 578 | CIR_WAKE_IRCON); |
| 579 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 580 | /* clear any and all stray interrupts */ |
| 581 | nvt_cir_wake_reg_write(nvt, 0xff, CIR_WAKE_IRSTS); |
Heiner Kallweit | ccca00d | 2015-12-30 14:43:59 -0200 | [diff] [blame] | 582 | |
| 583 | /* enable the CIR WAKE logical device */ |
| 584 | nvt_enable_logical_dev(nvt, LOGICAL_DEV_CIR_WAKE); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static void nvt_enable_wake(struct nvt_dev *nvt) |
| 588 | { |
Heiner Kallweit | b883af3 | 2016-02-01 18:50:26 -0200 | [diff] [blame] | 589 | unsigned long flags; |
| 590 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 591 | nvt_efm_enable(nvt); |
| 592 | |
| 593 | nvt_select_logical_dev(nvt, LOGICAL_DEV_ACPI); |
| 594 | nvt_set_reg_bit(nvt, CIR_WAKE_ENABLE_BIT, CR_ACPI_CIR_WAKE); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 595 | nvt_set_reg_bit(nvt, PME_INTR_CIR_PASS_BIT, CR_ACPI_IRQ_EVENTS2); |
| 596 | |
| 597 | nvt_select_logical_dev(nvt, LOGICAL_DEV_CIR_WAKE); |
| 598 | nvt_cr_write(nvt, LOGICAL_DEV_ENABLE, CR_LOGICAL_DEV_EN); |
| 599 | |
| 600 | nvt_efm_disable(nvt); |
| 601 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 602 | spin_lock_irqsave(&nvt->lock, flags); |
Heiner Kallweit | b883af3 | 2016-02-01 18:50:26 -0200 | [diff] [blame] | 603 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 604 | nvt_cir_wake_reg_write(nvt, CIR_WAKE_IRCON_MODE0 | CIR_WAKE_IRCON_RXEN | |
| 605 | CIR_WAKE_IRCON_R | CIR_WAKE_IRCON_RXINV | |
Jarod Wilson | 4e6e29a | 2010-10-15 11:07:37 -0300 | [diff] [blame] | 606 | CIR_WAKE_IRCON_SAMPLE_PERIOD_SEL, |
| 607 | CIR_WAKE_IRCON); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 608 | nvt_cir_wake_reg_write(nvt, 0xff, CIR_WAKE_IRSTS); |
| 609 | nvt_cir_wake_reg_write(nvt, 0, CIR_WAKE_IREN); |
Heiner Kallweit | b883af3 | 2016-02-01 18:50:26 -0200 | [diff] [blame] | 610 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 611 | spin_unlock_irqrestore(&nvt->lock, flags); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 612 | } |
| 613 | |
Mauro Carvalho Chehab | 230dc94 | 2012-10-27 13:54:09 -0300 | [diff] [blame] | 614 | #if 0 /* Currently unused */ |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 615 | /* rx carrier detect only works in learning mode, must be called w/lock */ |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 616 | static u32 nvt_rx_carrier_detect(struct nvt_dev *nvt) |
| 617 | { |
| 618 | u32 count, carrier, duration = 0; |
| 619 | int i; |
| 620 | |
| 621 | count = nvt_cir_reg_read(nvt, CIR_FCCL) | |
| 622 | nvt_cir_reg_read(nvt, CIR_FCCH) << 8; |
| 623 | |
| 624 | for (i = 0; i < nvt->pkts; i++) { |
| 625 | if (nvt->buf[i] & BUF_PULSE_BIT) |
| 626 | duration += nvt->buf[i] & BUF_LEN_MASK; |
| 627 | } |
| 628 | |
| 629 | duration *= SAMPLE_PERIOD; |
| 630 | |
| 631 | if (!count || !duration) { |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 632 | dev_notice(nvt_get_dev(nvt), |
Heiner Kallweit | 211477f | 2015-10-29 19:23:01 -0200 | [diff] [blame] | 633 | "Unable to determine carrier! (c:%u, d:%u)", |
| 634 | count, duration); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
Jarod Wilson | b4608fa | 2011-01-18 17:31:24 -0300 | [diff] [blame] | 638 | carrier = MS_TO_NS(count) / duration; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 639 | |
| 640 | if ((carrier > MAX_CARRIER) || (carrier < MIN_CARRIER)) |
| 641 | nvt_dbg("WTF? Carrier frequency out of range!"); |
| 642 | |
| 643 | nvt_dbg("Carrier frequency: %u (count %u, duration %u)", |
| 644 | carrier, count, duration); |
| 645 | |
| 646 | return carrier; |
| 647 | } |
Mauro Carvalho Chehab | 230dc94 | 2012-10-27 13:54:09 -0300 | [diff] [blame] | 648 | #endif |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 649 | /* |
| 650 | * set carrier frequency |
| 651 | * |
| 652 | * set carrier on 2 registers: CP & CC |
| 653 | * always set CP as 0x81 |
| 654 | * set CC by SPEC, CC = 3MHz/carrier - 1 |
| 655 | */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 656 | static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier) |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 657 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 658 | struct nvt_dev *nvt = dev->priv; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 659 | u16 val; |
| 660 | |
Dan Carpenter | 48cafec | 2012-09-11 07:11:24 -0300 | [diff] [blame] | 661 | if (carrier == 0) |
| 662 | return -EINVAL; |
| 663 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 664 | nvt_cir_reg_write(nvt, 1, CIR_CP); |
| 665 | val = 3000000 / (carrier) - 1; |
| 666 | nvt_cir_reg_write(nvt, val & 0xff, CIR_CC); |
| 667 | |
| 668 | nvt_dbg("cp: 0x%x cc: 0x%x\n", |
| 669 | nvt_cir_reg_read(nvt, CIR_CP), nvt_cir_reg_read(nvt, CIR_CC)); |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 674 | static int nvt_ir_raw_set_wakeup_filter(struct rc_dev *dev, |
| 675 | struct rc_scancode_filter *sc_filter) |
| 676 | { |
| 677 | u8 buf_val; |
| 678 | int i, ret, count; |
| 679 | unsigned int val; |
| 680 | struct ir_raw_event *raw; |
| 681 | u8 wake_buf[WAKEUP_MAX_SIZE]; |
| 682 | bool complete; |
| 683 | |
| 684 | /* Require mask to be set */ |
| 685 | if (!sc_filter->mask) |
| 686 | return 0; |
| 687 | |
| 688 | raw = kmalloc_array(WAKEUP_MAX_SIZE, sizeof(*raw), GFP_KERNEL); |
| 689 | if (!raw) |
| 690 | return -ENOMEM; |
| 691 | |
| 692 | ret = ir_raw_encode_scancode(dev->wakeup_protocol, sc_filter->data, |
| 693 | raw, WAKEUP_MAX_SIZE); |
| 694 | complete = (ret != -ENOBUFS); |
| 695 | if (!complete) |
| 696 | ret = WAKEUP_MAX_SIZE; |
| 697 | else if (ret < 0) |
| 698 | goto out_raw; |
| 699 | |
| 700 | /* Inspect the ir samples */ |
| 701 | for (i = 0, count = 0; i < ret && count < WAKEUP_MAX_SIZE; ++i) { |
| 702 | /* NS to US */ |
| 703 | val = DIV_ROUND_UP(raw[i].duration, 1000L) / SAMPLE_PERIOD; |
| 704 | |
| 705 | /* Split too large values into several smaller ones */ |
| 706 | while (val > 0 && count < WAKEUP_MAX_SIZE) { |
| 707 | /* Skip last value for better comparison tolerance */ |
| 708 | if (complete && i == ret - 1 && val < BUF_LEN_MASK) |
| 709 | break; |
| 710 | |
| 711 | /* Clamp values to BUF_LEN_MASK at most */ |
| 712 | buf_val = (val > BUF_LEN_MASK) ? BUF_LEN_MASK : val; |
| 713 | |
| 714 | wake_buf[count] = buf_val; |
| 715 | val -= buf_val; |
| 716 | if ((raw[i]).pulse) |
| 717 | wake_buf[count] |= BUF_PULSE_BIT; |
| 718 | count++; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | nvt_write_wakeup_codes(dev, wake_buf, count); |
| 723 | ret = 0; |
| 724 | out_raw: |
| 725 | kfree(raw); |
| 726 | |
| 727 | return ret; |
| 728 | } |
| 729 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 730 | /* dump contents of the last rx buffer we got from the hw rx fifo */ |
| 731 | static void nvt_dump_rx_buf(struct nvt_dev *nvt) |
| 732 | { |
| 733 | int i; |
| 734 | |
Jarod Wilson | 4e6e29a | 2010-10-15 11:07:37 -0300 | [diff] [blame] | 735 | printk(KERN_DEBUG "%s (len %d): ", __func__, nvt->pkts); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 736 | for (i = 0; (i < nvt->pkts) && (i < RX_BUF_LEN); i++) |
Jarod Wilson | 4e6e29a | 2010-10-15 11:07:37 -0300 | [diff] [blame] | 737 | printk(KERN_CONT "0x%02x ", nvt->buf[i]); |
| 738 | printk(KERN_CONT "\n"); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* |
| 742 | * Process raw data in rx driver buffer, store it in raw IR event kfifo, |
| 743 | * trigger decode when appropriate. |
| 744 | * |
| 745 | * We get IR data samples one byte at a time. If the msb is set, its a pulse, |
| 746 | * otherwise its a space. The lower 7 bits are the count of SAMPLE_PERIOD |
| 747 | * (default 50us) intervals for that pulse/space. A discrete signal is |
| 748 | * followed by a series of 0x7f packets, then either 0x7<something> or 0x80 |
| 749 | * to signal more IR coming (repeats) or end of IR, respectively. We store |
| 750 | * sample data in the raw event kfifo until we see 0x7<something> (except f) |
| 751 | * or 0x80, at which time, we trigger a decode operation. |
| 752 | */ |
| 753 | static void nvt_process_rx_ir_data(struct nvt_dev *nvt) |
| 754 | { |
Maxim Levitsky | 4651918 | 2010-10-16 19:56:28 -0300 | [diff] [blame] | 755 | DEFINE_IR_RAW_EVENT(rawir); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 756 | u8 sample; |
| 757 | int i; |
| 758 | |
| 759 | nvt_dbg_verbose("%s firing", __func__); |
| 760 | |
| 761 | if (debug) |
| 762 | nvt_dump_rx_buf(nvt); |
| 763 | |
Jarod Wilson | de4ed0c11 | 2011-08-08 17:20:40 -0300 | [diff] [blame] | 764 | nvt_dbg_verbose("Processing buffer of len %d", nvt->pkts); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 765 | |
Jarod Wilson | de4ed0c11 | 2011-08-08 17:20:40 -0300 | [diff] [blame] | 766 | for (i = 0; i < nvt->pkts; i++) { |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 767 | sample = nvt->buf[i]; |
| 768 | |
| 769 | rawir.pulse = ((sample & BUF_PULSE_BIT) != 0); |
Jarod Wilson | b4608fa | 2011-01-18 17:31:24 -0300 | [diff] [blame] | 770 | rawir.duration = US_TO_NS((sample & BUF_LEN_MASK) |
| 771 | * SAMPLE_PERIOD); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 772 | |
Jarod Wilson | de4ed0c11 | 2011-08-08 17:20:40 -0300 | [diff] [blame] | 773 | nvt_dbg("Storing %s with duration %d", |
| 774 | rawir.pulse ? "pulse" : "space", rawir.duration); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 775 | |
Jarod Wilson | de4ed0c11 | 2011-08-08 17:20:40 -0300 | [diff] [blame] | 776 | ir_raw_event_store_with_filter(nvt->rdev, &rawir); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 777 | } |
| 778 | |
Jarod Wilson | de4ed0c11 | 2011-08-08 17:20:40 -0300 | [diff] [blame] | 779 | nvt->pkts = 0; |
| 780 | |
Heiner Kallweit | a2006ca | 2016-08-02 02:45:30 -0300 | [diff] [blame] | 781 | nvt_dbg("Calling ir_raw_event_handle\n"); |
Jarod Wilson | b758281 | 2010-11-09 18:11:04 -0300 | [diff] [blame] | 782 | ir_raw_event_handle(nvt->rdev); |
| 783 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 784 | nvt_dbg_verbose("%s done", __func__); |
| 785 | } |
| 786 | |
Jarod Wilson | fbdc781 | 2010-10-08 16:16:23 -0300 | [diff] [blame] | 787 | static void nvt_handle_rx_fifo_overrun(struct nvt_dev *nvt) |
| 788 | { |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 789 | dev_warn(nvt_get_dev(nvt), "RX FIFO overrun detected, flushing data!"); |
Jarod Wilson | fbdc781 | 2010-10-08 16:16:23 -0300 | [diff] [blame] | 790 | |
| 791 | nvt->pkts = 0; |
| 792 | nvt_clear_cir_fifo(nvt); |
| 793 | ir_raw_event_reset(nvt->rdev); |
| 794 | } |
| 795 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 796 | /* copy data from hardware rx fifo into driver buffer */ |
| 797 | static void nvt_get_rx_ir_data(struct nvt_dev *nvt) |
| 798 | { |
Heiner Kallweit | 6db0168 | 2016-08-02 02:45:51 -0300 | [diff] [blame] | 799 | u8 fifocount; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 800 | int i; |
| 801 | |
| 802 | /* Get count of how many bytes to read from RX FIFO */ |
| 803 | fifocount = nvt_cir_reg_read(nvt, CIR_RXFCONT); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 804 | |
| 805 | nvt_dbg("attempting to fetch %u bytes from hw rx fifo", fifocount); |
| 806 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 807 | /* Read fifocount bytes from CIR Sample RX FIFO register */ |
Heiner Kallweit | 6db0168 | 2016-08-02 02:45:51 -0300 | [diff] [blame] | 808 | for (i = 0; i < fifocount; i++) |
| 809 | nvt->buf[i] = nvt_cir_reg_read(nvt, CIR_SRXFIFO); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 810 | |
Heiner Kallweit | bacf835 | 2016-08-02 02:44:44 -0300 | [diff] [blame] | 811 | nvt->pkts = fifocount; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 812 | nvt_dbg("%s: pkts now %d", __func__, nvt->pkts); |
| 813 | |
| 814 | nvt_process_rx_ir_data(nvt); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | static void nvt_cir_log_irqs(u8 status, u8 iren) |
| 818 | { |
Heiner Kallweit | 068fb7d | 2015-10-29 19:22:41 -0200 | [diff] [blame] | 819 | nvt_dbg("IRQ 0x%02x (IREN 0x%02x) :%s%s%s%s%s%s%s%s%s", |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 820 | status, iren, |
| 821 | status & CIR_IRSTS_RDR ? " RDR" : "", |
| 822 | status & CIR_IRSTS_RTR ? " RTR" : "", |
| 823 | status & CIR_IRSTS_PE ? " PE" : "", |
| 824 | status & CIR_IRSTS_RFO ? " RFO" : "", |
| 825 | status & CIR_IRSTS_TE ? " TE" : "", |
| 826 | status & CIR_IRSTS_TTR ? " TTR" : "", |
| 827 | status & CIR_IRSTS_TFU ? " TFU" : "", |
| 828 | status & CIR_IRSTS_GH ? " GH" : "", |
| 829 | status & ~(CIR_IRSTS_RDR | CIR_IRSTS_RTR | CIR_IRSTS_PE | |
| 830 | CIR_IRSTS_RFO | CIR_IRSTS_TE | CIR_IRSTS_TTR | |
| 831 | CIR_IRSTS_TFU | CIR_IRSTS_GH) ? " ?" : ""); |
| 832 | } |
| 833 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 834 | /* interrupt service routine for incoming and outgoing CIR data */ |
| 835 | static irqreturn_t nvt_cir_isr(int irq, void *data) |
| 836 | { |
| 837 | struct nvt_dev *nvt = data; |
Heiner Kallweit | e5283f5 | 2016-06-24 02:39:45 -0300 | [diff] [blame] | 838 | u8 status, iren; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 839 | |
| 840 | nvt_dbg_verbose("%s firing", __func__); |
| 841 | |
Heiner Kallweit | c044170 | 2016-10-25 17:23:52 -0200 | [diff] [blame] | 842 | spin_lock(&nvt->lock); |
Heiner Kallweit | e60c1e8 | 2015-12-30 14:46:29 -0200 | [diff] [blame] | 843 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 844 | /* |
| 845 | * Get IR Status register contents. Write 1 to ack/clear |
| 846 | * |
| 847 | * bit: reg name - description |
| 848 | * 7: CIR_IRSTS_RDR - RX Data Ready |
| 849 | * 6: CIR_IRSTS_RTR - RX FIFO Trigger Level Reach |
| 850 | * 5: CIR_IRSTS_PE - Packet End |
| 851 | * 4: CIR_IRSTS_RFO - RX FIFO Overrun (RDR will also be set) |
| 852 | * 3: CIR_IRSTS_TE - TX FIFO Empty |
| 853 | * 2: CIR_IRSTS_TTR - TX FIFO Trigger Level Reach |
| 854 | * 1: CIR_IRSTS_TFU - TX FIFO Underrun |
| 855 | * 0: CIR_IRSTS_GH - Min Length Detected |
| 856 | */ |
| 857 | status = nvt_cir_reg_read(nvt, CIR_IRSTS); |
Heiner Kallweit | d42fd29 | 2015-12-30 14:45:51 -0200 | [diff] [blame] | 858 | iren = nvt_cir_reg_read(nvt, CIR_IREN); |
| 859 | |
Heiner Kallweit | d14f291 | 2016-07-31 10:42:55 -0300 | [diff] [blame] | 860 | /* At least NCT6779D creates a spurious interrupt when the |
| 861 | * logical device is being disabled. |
| 862 | */ |
| 863 | if (status == 0xff && iren == 0xff) { |
Heiner Kallweit | c044170 | 2016-10-25 17:23:52 -0200 | [diff] [blame] | 864 | spin_unlock(&nvt->lock); |
Heiner Kallweit | d14f291 | 2016-07-31 10:42:55 -0300 | [diff] [blame] | 865 | nvt_dbg_verbose("Spurious interrupt detected"); |
| 866 | return IRQ_HANDLED; |
| 867 | } |
| 868 | |
Heiner Kallweit | d42fd29 | 2015-12-30 14:45:51 -0200 | [diff] [blame] | 869 | /* IRQ may be shared with CIR WAKE, therefore check for each |
| 870 | * status bit whether the related interrupt source is enabled |
| 871 | */ |
| 872 | if (!(status & iren)) { |
Heiner Kallweit | c044170 | 2016-10-25 17:23:52 -0200 | [diff] [blame] | 873 | spin_unlock(&nvt->lock); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 874 | nvt_dbg_verbose("%s exiting, IRSTS 0x0", __func__); |
Heiner Kallweit | 2bbf9e0 | 2015-10-29 19:18:45 -0200 | [diff] [blame] | 875 | return IRQ_NONE; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | /* ack/clear all irq flags we've got */ |
| 879 | nvt_cir_reg_write(nvt, status, CIR_IRSTS); |
| 880 | nvt_cir_reg_write(nvt, 0, CIR_IRSTS); |
| 881 | |
Heiner Kallweit | 068fb7d | 2015-10-29 19:22:41 -0200 | [diff] [blame] | 882 | nvt_cir_log_irqs(status, iren); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 883 | |
Heiner Kallweit | 398d9da | 2016-05-22 10:43:40 -0300 | [diff] [blame] | 884 | if (status & CIR_IRSTS_RFO) |
| 885 | nvt_handle_rx_fifo_overrun(nvt); |
Heiner Kallweit | 8728427 | 2017-07-15 17:13:14 -0400 | [diff] [blame] | 886 | else if (status & (CIR_IRSTS_RTR | CIR_IRSTS_PE)) |
| 887 | nvt_get_rx_ir_data(nvt); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 888 | |
Heiner Kallweit | c044170 | 2016-10-25 17:23:52 -0200 | [diff] [blame] | 889 | spin_unlock(&nvt->lock); |
Heiner Kallweit | f7ceec4 | 2016-10-25 17:23:45 -0200 | [diff] [blame] | 890 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 891 | nvt_dbg_verbose("%s done", __func__); |
Heiner Kallweit | 2bbf9e0 | 2015-10-29 19:18:45 -0200 | [diff] [blame] | 892 | return IRQ_HANDLED; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 893 | } |
| 894 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 895 | static void nvt_disable_cir(struct nvt_dev *nvt) |
| 896 | { |
Heiner Kallweit | 137aa36 | 2016-02-01 18:50:55 -0200 | [diff] [blame] | 897 | unsigned long flags; |
| 898 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 899 | spin_lock_irqsave(&nvt->lock, flags); |
Heiner Kallweit | 137aa36 | 2016-02-01 18:50:55 -0200 | [diff] [blame] | 900 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 901 | /* disable CIR interrupts */ |
| 902 | nvt_cir_reg_write(nvt, 0, CIR_IREN); |
| 903 | |
| 904 | /* clear any and all pending interrupts */ |
| 905 | nvt_cir_reg_write(nvt, 0xff, CIR_IRSTS); |
| 906 | |
| 907 | /* clear all function enable flags */ |
| 908 | nvt_cir_reg_write(nvt, 0, CIR_IRCON); |
| 909 | |
| 910 | /* clear hardware rx and tx fifos */ |
| 911 | nvt_clear_cir_fifo(nvt); |
| 912 | nvt_clear_tx_fifo(nvt); |
| 913 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 914 | spin_unlock_irqrestore(&nvt->lock, flags); |
Heiner Kallweit | 137aa36 | 2016-02-01 18:50:55 -0200 | [diff] [blame] | 915 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 916 | /* disable the CIR logical device */ |
Heiner Kallweit | a17ede9 | 2015-12-30 14:40:05 -0200 | [diff] [blame] | 917 | nvt_disable_logical_dev(nvt, LOGICAL_DEV_CIR); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 918 | } |
| 919 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 920 | static int nvt_open(struct rc_dev *dev) |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 921 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 922 | struct nvt_dev *nvt = dev->priv; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 923 | unsigned long flags; |
| 924 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 925 | spin_lock_irqsave(&nvt->lock, flags); |
Heiner Kallweit | 842096f | 2016-02-01 18:49:32 -0200 | [diff] [blame] | 926 | |
| 927 | /* set function enable flags */ |
| 928 | nvt_cir_reg_write(nvt, CIR_IRCON_TXEN | CIR_IRCON_RXEN | |
| 929 | CIR_IRCON_RXINV | CIR_IRCON_SAMPLE_PERIOD_SEL, |
| 930 | CIR_IRCON); |
| 931 | |
| 932 | /* clear all pending interrupts */ |
| 933 | nvt_cir_reg_write(nvt, 0xff, CIR_IRSTS); |
| 934 | |
| 935 | /* enable interrupts */ |
| 936 | nvt_set_cir_iren(nvt); |
| 937 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 938 | spin_unlock_irqrestore(&nvt->lock, flags); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 939 | |
Heiner Kallweit | 842096f | 2016-02-01 18:49:32 -0200 | [diff] [blame] | 940 | /* enable the CIR logical device */ |
| 941 | nvt_enable_logical_dev(nvt, LOGICAL_DEV_CIR); |
| 942 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 943 | return 0; |
| 944 | } |
| 945 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 946 | static void nvt_close(struct rc_dev *dev) |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 947 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 948 | struct nvt_dev *nvt = dev->priv; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 949 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 950 | nvt_disable_cir(nvt); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | /* Allocate memory, probe hardware, and initialize everything */ |
| 954 | static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) |
| 955 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 956 | struct nvt_dev *nvt; |
| 957 | struct rc_dev *rdev; |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 958 | int ret; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 959 | |
Heiner Kallweit | 099256e | 2015-10-29 19:19:36 -0200 | [diff] [blame] | 960 | nvt = devm_kzalloc(&pdev->dev, sizeof(struct nvt_dev), GFP_KERNEL); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 961 | if (!nvt) |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 962 | return -ENOMEM; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 963 | |
Heiner Kallweit | 8728427 | 2017-07-15 17:13:14 -0400 | [diff] [blame] | 964 | /* input device for IR remote */ |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 965 | nvt->rdev = devm_rc_allocate_device(&pdev->dev, RC_DRIVER_IR_RAW); |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 966 | if (!nvt->rdev) |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 967 | return -ENOMEM; |
Heiner Kallweit | b24cccc | 2016-10-25 17:23:37 -0200 | [diff] [blame] | 968 | rdev = nvt->rdev; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 969 | |
Antti Seppälä | c3c2077 | 2014-02-16 07:16:02 -0300 | [diff] [blame] | 970 | /* activate pnp device */ |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 971 | ret = pnp_activate_dev(pdev); |
| 972 | if (ret) { |
Antti Seppälä | c3c2077 | 2014-02-16 07:16:02 -0300 | [diff] [blame] | 973 | dev_err(&pdev->dev, "Could not activate PNP device!\n"); |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 974 | return ret; |
Antti Seppälä | c3c2077 | 2014-02-16 07:16:02 -0300 | [diff] [blame] | 975 | } |
| 976 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 977 | /* validate pnp resources */ |
| 978 | if (!pnp_port_valid(pdev, 0) || |
| 979 | pnp_port_len(pdev, 0) < CIR_IOREG_LENGTH) { |
| 980 | dev_err(&pdev->dev, "IR PNP Port not valid!\n"); |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 981 | return -EINVAL; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | if (!pnp_irq_valid(pdev, 0)) { |
| 985 | dev_err(&pdev->dev, "PNP IRQ not valid!\n"); |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 986 | return -EINVAL; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | if (!pnp_port_valid(pdev, 1) || |
| 990 | pnp_port_len(pdev, 1) < CIR_IOREG_LENGTH) { |
| 991 | dev_err(&pdev->dev, "Wake PNP Port not valid!\n"); |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 992 | return -EINVAL; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | nvt->cir_addr = pnp_port_start(pdev, 0); |
| 996 | nvt->cir_irq = pnp_irq(pdev, 0); |
| 997 | |
| 998 | nvt->cir_wake_addr = pnp_port_start(pdev, 1); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 999 | |
| 1000 | nvt->cr_efir = CR_EFIR; |
| 1001 | nvt->cr_efdr = CR_EFDR; |
| 1002 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 1003 | spin_lock_init(&nvt->lock); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1004 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1005 | pnp_set_drvdata(pdev, nvt); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1006 | |
Heiner Kallweit | 3f1321c | 2015-12-30 14:43:29 -0200 | [diff] [blame] | 1007 | ret = nvt_hw_detect(nvt); |
| 1008 | if (ret) |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 1009 | return ret; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1010 | |
| 1011 | /* Initialize CIR & CIR Wake Logical Devices */ |
| 1012 | nvt_efm_enable(nvt); |
| 1013 | nvt_cir_ldev_init(nvt); |
| 1014 | nvt_cir_wake_ldev_init(nvt); |
| 1015 | nvt_efm_disable(nvt); |
| 1016 | |
Heiner Kallweit | ccca00d | 2015-12-30 14:43:59 -0200 | [diff] [blame] | 1017 | /* |
| 1018 | * Initialize CIR & CIR Wake Config Registers |
| 1019 | * and enable logical devices |
| 1020 | */ |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1021 | nvt_cir_regs_init(nvt); |
| 1022 | nvt_cir_wake_regs_init(nvt); |
| 1023 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1024 | /* Set up the rc device */ |
| 1025 | rdev->priv = nvt; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1026 | rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; |
| 1027 | rdev->allowed_wakeup_protocols = RC_PROTO_BIT_ALL_IR_ENCODER; |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 1028 | rdev->encode_wakeup = true; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1029 | rdev->open = nvt_open; |
| 1030 | rdev->close = nvt_close; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1031 | rdev->s_tx_carrier = nvt_set_tx_carrier; |
Antti Seppälä | 97c1297 | 2015-03-31 14:48:12 -0300 | [diff] [blame] | 1032 | rdev->s_wakeup_filter = nvt_ir_raw_set_wakeup_filter; |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 1033 | rdev->device_name = "Nuvoton w836x7hg Infrared Remote Transceiver"; |
Jarod Wilson | 46872d2 | 2011-04-21 15:21:47 -0300 | [diff] [blame] | 1034 | rdev->input_phys = "nuvoton/cir0"; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1035 | rdev->input_id.bustype = BUS_HOST; |
| 1036 | rdev->input_id.vendor = PCI_VENDOR_ID_WINBOND2; |
| 1037 | rdev->input_id.product = nvt->chip_major; |
| 1038 | rdev->input_id.version = nvt->chip_minor; |
| 1039 | rdev->driver_name = NVT_DRIVER_NAME; |
| 1040 | rdev->map_name = RC_MAP_RC6_MCE; |
Jarod Wilson | d7b290a | 2011-07-11 12:09:00 -0300 | [diff] [blame] | 1041 | rdev->timeout = MS_TO_NS(100); |
Jarod Wilson | 46872d2 | 2011-04-21 15:21:47 -0300 | [diff] [blame] | 1042 | /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */ |
| 1043 | rdev->rx_resolution = US_TO_NS(CIR_SAMPLE_PERIOD); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1044 | #if 0 |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1045 | rdev->min_timeout = XYZ; |
| 1046 | rdev->max_timeout = XYZ; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1047 | #endif |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 1048 | ret = devm_rc_register_device(&pdev->dev, rdev); |
Matthijs Kooijman | 9fa3520 | 2012-11-02 09:13:56 -0300 | [diff] [blame] | 1049 | if (ret) |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 1050 | return ret; |
Matthijs Kooijman | 9fa3520 | 2012-11-02 09:13:56 -0300 | [diff] [blame] | 1051 | |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1052 | /* now claim resources */ |
Heiner Kallweit | 099256e | 2015-10-29 19:19:36 -0200 | [diff] [blame] | 1053 | if (!devm_request_region(&pdev->dev, nvt->cir_addr, |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1054 | CIR_IOREG_LENGTH, NVT_DRIVER_NAME)) |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 1055 | return -EBUSY; |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1056 | |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 1057 | ret = devm_request_irq(&pdev->dev, nvt->cir_irq, nvt_cir_isr, |
| 1058 | IRQF_SHARED, NVT_DRIVER_NAME, nvt); |
| 1059 | if (ret) |
| 1060 | return ret; |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1061 | |
Heiner Kallweit | 099256e | 2015-10-29 19:19:36 -0200 | [diff] [blame] | 1062 | if (!devm_request_region(&pdev->dev, nvt->cir_wake_addr, |
Heiner Kallweit | 33cb540 | 2015-11-27 19:38:44 -0200 | [diff] [blame] | 1063 | CIR_IOREG_LENGTH, NVT_DRIVER_NAME "-wake")) |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 1064 | return -EBUSY; |
Luis Henriques | 9ef449c | 2012-04-21 12:25:21 -0300 | [diff] [blame] | 1065 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 1066 | ret = device_create_file(&rdev->dev, &dev_attr_wakeup_data); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 1067 | if (ret) |
Heiner Kallweit | b6f3ece | 2016-09-30 17:42:17 -0300 | [diff] [blame] | 1068 | return ret; |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 1069 | |
Jarod Wilson | 46872d2 | 2011-04-21 15:21:47 -0300 | [diff] [blame] | 1070 | device_init_wakeup(&pdev->dev, true); |
Matthijs Kooijman | d62b681 | 2012-11-02 09:13:55 -0300 | [diff] [blame] | 1071 | |
Heiner Kallweit | 211477f | 2015-10-29 19:23:01 -0200 | [diff] [blame] | 1072 | dev_notice(&pdev->dev, "driver has been successfully loaded\n"); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1073 | if (debug) { |
| 1074 | cir_dump_regs(nvt); |
| 1075 | cir_wake_dump_regs(nvt); |
| 1076 | } |
| 1077 | |
| 1078 | return 0; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1079 | } |
| 1080 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1081 | static void nvt_remove(struct pnp_dev *pdev) |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1082 | { |
| 1083 | struct nvt_dev *nvt = pnp_get_drvdata(pdev); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1084 | |
Heiner Kallweit | 0221200 | 2016-03-04 16:11:40 -0300 | [diff] [blame] | 1085 | device_remove_file(&nvt->rdev->dev, &dev_attr_wakeup_data); |
Heiner Kallweit | 449c1fc | 2016-02-08 17:25:59 -0200 | [diff] [blame] | 1086 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1087 | nvt_disable_cir(nvt); |
Heiner Kallweit | b883af3 | 2016-02-01 18:50:26 -0200 | [diff] [blame] | 1088 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1089 | /* enable CIR Wake (for IR power-on) */ |
| 1090 | nvt_enable_wake(nvt); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static int nvt_suspend(struct pnp_dev *pdev, pm_message_t state) |
| 1094 | { |
| 1095 | struct nvt_dev *nvt = pnp_get_drvdata(pdev); |
| 1096 | unsigned long flags; |
| 1097 | |
| 1098 | nvt_dbg("%s called", __func__); |
| 1099 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 1100 | spin_lock_irqsave(&nvt->lock, flags); |
Heiner Kallweit | fb2b006 | 2015-12-30 14:44:36 -0200 | [diff] [blame] | 1101 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1102 | /* disable all CIR interrupts */ |
| 1103 | nvt_cir_reg_write(nvt, 0, CIR_IREN); |
| 1104 | |
Heiner Kallweit | 73d4576 | 2016-10-25 17:23:49 -0200 | [diff] [blame] | 1105 | spin_unlock_irqrestore(&nvt->lock, flags); |
Heiner Kallweit | b883af3 | 2016-02-01 18:50:26 -0200 | [diff] [blame] | 1106 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1107 | /* disable cir logical dev */ |
Heiner Kallweit | a17ede9 | 2015-12-30 14:40:05 -0200 | [diff] [blame] | 1108 | nvt_disable_logical_dev(nvt, LOGICAL_DEV_CIR); |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1109 | |
| 1110 | /* make sure wake is enabled */ |
| 1111 | nvt_enable_wake(nvt); |
| 1112 | |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | static int nvt_resume(struct pnp_dev *pdev) |
| 1117 | { |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1118 | struct nvt_dev *nvt = pnp_get_drvdata(pdev); |
| 1119 | |
| 1120 | nvt_dbg("%s called", __func__); |
| 1121 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1122 | nvt_cir_regs_init(nvt); |
| 1123 | nvt_cir_wake_regs_init(nvt); |
| 1124 | |
Mauro Carvalho Chehab | f2747cf | 2014-09-03 16:03:41 -0300 | [diff] [blame] | 1125 | return 0; |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | static void nvt_shutdown(struct pnp_dev *pdev) |
| 1129 | { |
| 1130 | struct nvt_dev *nvt = pnp_get_drvdata(pdev); |
Heiner Kallweit | fb2b006 | 2015-12-30 14:44:36 -0200 | [diff] [blame] | 1131 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1132 | nvt_enable_wake(nvt); |
| 1133 | } |
| 1134 | |
| 1135 | static const struct pnp_device_id nvt_ids[] = { |
| 1136 | { "WEC0530", 0 }, /* CIR */ |
| 1137 | { "NTN0530", 0 }, /* CIR for new chip's pnp id*/ |
| 1138 | { "", 0 }, |
| 1139 | }; |
| 1140 | |
| 1141 | static struct pnp_driver nvt_driver = { |
| 1142 | .name = NVT_DRIVER_NAME, |
| 1143 | .id_table = nvt_ids, |
| 1144 | .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, |
| 1145 | .probe = nvt_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1146 | .remove = nvt_remove, |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1147 | .suspend = nvt_suspend, |
| 1148 | .resume = nvt_resume, |
| 1149 | .shutdown = nvt_shutdown, |
| 1150 | }; |
| 1151 | |
Jarod Wilson | 6d2f5c2 | 2010-10-07 17:50:34 -0300 | [diff] [blame] | 1152 | module_param(debug, int, S_IRUGO | S_IWUSR); |
| 1153 | MODULE_PARM_DESC(debug, "Enable debugging output"); |
| 1154 | |
| 1155 | MODULE_DEVICE_TABLE(pnp, nvt_ids); |
| 1156 | MODULE_DESCRIPTION("Nuvoton W83667HG-A & W83677HG-I CIR driver"); |
| 1157 | |
| 1158 | MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>"); |
| 1159 | MODULE_LICENSE("GPL"); |
| 1160 | |
Peter Huewe | af638a0 | 2015-03-16 21:46:34 +0100 | [diff] [blame] | 1161 | module_pnp_driver(nvt_driver); |