/* * Driver for Nuvoton Technology Corporation w83667hg/w83677hg-i CIR * * Copyright (C) 2010 Jarod Wilson <jarod@redhat.com> * Copyright (C) 2009 Nuvoton PS Team * * Special thanks to Nuvoton for providing hardware, spec sheets and * sample code upon which portions of this driver are based. Indirect * thanks also to Maxim Levitsky, whose ene_ir driver this driver is * modeled after. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/
/* * When you want to address a specific logical device, write its logical * device number to CR_LOGICAL_DEV_SEL, then enable/disable by writing * 0x1/0x0 respectively to CR_LOGICAL_DEV_EN.
*/ staticinlinevoid nvt_select_logical_dev(struct nvt_dev *nvt, u8 ldev)
{
nvt_cr_write(nvt, ldev, CR_LOGICAL_DEV_SEL);
}
argv = argv_split(GFP_KERNEL, buf, &count); if (!argv) return -ENOMEM; if (!count || count > WAKEUP_MAX_SIZE) {
ret = -EINVAL; goto out;
}
for (i = 0; i < count; i++) {
ret = kstrtouint(argv[i], 10, &val); if (ret) goto out;
val = DIV_ROUND_CLOSEST(val, SAMPLE_PERIOD); if (!val || val > 0x7f) {
ret = -EINVAL; goto out;
}
wake_buf[i] = val; /* sequence must start with a pulse */ if (i % 2 == 0)
wake_buf[i] |= BUF_PULSE_BIT;
}
nvt_write_wakeup_codes(rc_dev, wake_buf, count);
ret = len;
out:
argv_free(argv); return ret;
} static DEVICE_ATTR_RW(wakeup_data);
fifo_len = nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_COUNT);
pr_info("%s: Dump CIR WAKE FIFO (len %d)\n", NVT_DRIVER_NAME, fifo_len);
pr_info("* Contents ="); for (i = 0; i < fifo_len; i++)
pr_cont(" %02x",
nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY));
pr_cont("\n");
}
staticinlineconstchar *nvt_find_chip(struct nvt_dev *nvt, int id)
{ int i;
for (i = 0; i < ARRAY_SIZE(nvt_chips); i++) if ((id & SIO_ID_MASK) == nvt_chips[i].chip_ver) {
nvt->chip_ver = nvt_chips[i].chip_ver; return nvt_chips[i].name;
}
return NULL;
}
/* detect hardware features */ staticint nvt_hw_detect(struct nvt_dev *nvt)
{ struct device *dev = nvt_get_dev(nvt); constchar *chip_name; int chip_id;
nvt_efm_enable(nvt);
/* Check if we're wired for the alternate EFER setup */
nvt->chip_major = nvt_cr_read(nvt, CR_CHIP_ID_HI); if (nvt->chip_major == 0xff) {
nvt_efm_disable(nvt);
nvt->cr_efir = CR_EFIR2;
nvt->cr_efdr = CR_EFDR2;
nvt_efm_enable(nvt);
nvt->chip_major = nvt_cr_read(nvt, CR_CHIP_ID_HI);
}
nvt->chip_minor = nvt_cr_read(nvt, CR_CHIP_ID_LO);
nvt_efm_disable(nvt);
chip_id = nvt->chip_major << 8 | nvt->chip_minor; if (chip_id == NVT_INVALID) {
dev_err(dev, "No device found on either EFM port\n"); return -ENODEV;
}
chip_name = nvt_find_chip(nvt, chip_id);
/* warn, but still let the driver load, if we don't know this chip */ if (!chip_name)
dev_warn(dev, "unknown chip, id: 0x%02x 0x%02x, it may not work...",
nvt->chip_major, nvt->chip_minor); else
dev_info(dev, "found %s or compatible: chip id: 0x%02x 0x%02x",
chip_name, nvt->chip_major, nvt->chip_minor);
/* * Disable RX, set specific carrier on = low, off = high, * and sample period (currently 50us)
*/
nvt_cir_wake_reg_write(nvt, CIR_WAKE_IRCON_MODE0 |
CIR_WAKE_IRCON_R | CIR_WAKE_IRCON_RXINV |
CIR_WAKE_IRCON_SAMPLE_PERIOD_SEL,
CIR_WAKE_IRCON);
/* clear any and all stray interrupts */
nvt_cir_wake_reg_write(nvt, 0xff, CIR_WAKE_IRSTS);
}
#if 0 /* Currently unused */ /* rx carrier detect only works in learning mode, must be called w/lock */ static u32 nvt_rx_carrier_detect(struct nvt_dev *nvt)
{
u32 count, carrier, duration = 0; int i;
/* Require mask to be set */ if (!sc_filter->mask) return 0;
raw = kmalloc_array(WAKEUP_MAX_SIZE, sizeof(*raw), GFP_KERNEL); if (!raw) return -ENOMEM;
ret = ir_raw_encode_scancode(dev->wakeup_protocol, sc_filter->data,
raw, WAKEUP_MAX_SIZE);
complete = (ret != -ENOBUFS); if (!complete)
ret = WAKEUP_MAX_SIZE; elseif (ret < 0) goto out_raw;
/* Inspect the ir samples */ for (i = 0, count = 0; i < ret && count < WAKEUP_MAX_SIZE; ++i) {
val = raw[i].duration / SAMPLE_PERIOD;
/* Split too large values into several smaller ones */ while (val > 0 && count < WAKEUP_MAX_SIZE) { /* Skip last value for better comparison tolerance */ if (complete && i == ret - 1 && val < BUF_LEN_MASK) break;
/* Clamp values to BUF_LEN_MASK at most */
buf_val = (val > BUF_LEN_MASK) ? BUF_LEN_MASK : val;
wake_buf[count] = buf_val;
val -= buf_val; if ((raw[i]).pulse)
wake_buf[count] |= BUF_PULSE_BIT;
count++;
}
}
nvt_write_wakeup_codes(dev, wake_buf, count);
ret = 0;
out_raw:
kfree(raw);
return ret;
}
/* dump contents of the last rx buffer we got from the hw rx fifo */ staticvoid nvt_dump_rx_buf(struct nvt_dev *nvt)
{ int i;
printk(KERN_DEBUG "%s (len %d): ", __func__, nvt->pkts); for (i = 0; (i < nvt->pkts) && (i < RX_BUF_LEN); i++)
printk(KERN_CONT "0x%02x ", nvt->buf[i]);
printk(KERN_CONT "\n");
}
/* * Process raw data in rx driver buffer, store it in raw IR event kfifo, * trigger decode when appropriate. * * We get IR data samples one byte at a time. If the msb is set, its a pulse, * otherwise its a space. The lower 7 bits are the count of SAMPLE_PERIOD * (default 50us) intervals for that pulse/space. A discrete signal is * followed by a series of 0x7f packets, then either 0x7<something> or 0x80 * to signal more IR coming (repeats) or end of IR, respectively. We store * sample data in the raw event kfifo until we see 0x7<something> (except f) * or 0x80, at which time, we trigger a decode operation.
*/ staticvoid nvt_process_rx_ir_data(struct nvt_dev *nvt)
{ struct ir_raw_event rawir = {};
u8 sample; int i;
nvt_dbg_verbose("%s firing", __func__);
if (debug)
nvt_dump_rx_buf(nvt);
nvt_dbg_verbose("Processing buffer of len %d", nvt->pkts);
for (i = 0; i < nvt->pkts; i++) {
sample = nvt->buf[i];
/* interrupt service routine for incoming and outgoing CIR data */ static irqreturn_t nvt_cir_isr(int irq, void *data)
{ struct nvt_dev *nvt = data;
u8 status, iren;
nvt_dbg_verbose("%s firing", __func__);
spin_lock(&nvt->lock);
/* * Get IR Status register contents. Write 1 to ack/clear * * bit: reg name - description * 7: CIR_IRSTS_RDR - RX Data Ready * 6: CIR_IRSTS_RTR - RX FIFO Trigger Level Reach * 5: CIR_IRSTS_PE - Packet End * 4: CIR_IRSTS_RFO - RX FIFO Overrun (RDR will also be set) * 3: CIR_IRSTS_TE - TX FIFO Empty * 2: CIR_IRSTS_TTR - TX FIFO Trigger Level Reach * 1: CIR_IRSTS_TFU - TX FIFO Underrun * 0: CIR_IRSTS_GH - Min Length Detected
*/
status = nvt_cir_reg_read(nvt, CIR_IRSTS);
iren = nvt_cir_reg_read(nvt, CIR_IREN);
/* At least NCT6779D creates a spurious interrupt when the * logical device is being disabled.
*/ if (status == 0xff && iren == 0xff) {
spin_unlock(&nvt->lock);
nvt_dbg_verbose("Spurious interrupt detected"); return IRQ_HANDLED;
}
/* IRQ may be shared with CIR WAKE, therefore check for each * status bit whether the related interrupt source is enabled
*/ if (!(status & iren)) {
spin_unlock(&nvt->lock);
nvt_dbg_verbose("%s exiting, IRSTS 0x0", __func__); return IRQ_NONE;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.