// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for ITE Tech Inc. IT8712F/IT8512 CIR * * Copyright (C) 2010 Juan Jesús García de Soria <[email protected]> * * Inspired by the original lirc_it87 and lirc_ite8709 drivers, on top of the * skeleton provided by the nuvoton-cir driver. * * The lirc_it87 driver was originally written by Hans-Gunter Lutke Uphues * <[email protected]> in 2001, with enhancements by Christoph Bartelmus * <[email protected]>, Andrew Calkin <[email protected]> and James Edwards * <[email protected]>. * * The lirc_ite8709 driver was written by Grégory Lardière * <[email protected]> in 2008. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/pnp.h> #include <linux/io.h> #include <linux/interrupt.h> #include <linux/sched.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/input.h> #include <linux/bitops.h> #include <media/rc-core.h> #include <linux/pci_ids.h> #include "ite-cir.h" /* module parameters */ /* default sample period */ static long sample_period = …; module_param(sample_period, long, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(…) …; /* override detected model id */ static int model_number = …; module_param(model_number, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(…) …; /* HW-independent code functions */ /* check whether carrier frequency is high frequency */ static inline bool ite_is_high_carrier_freq(unsigned int freq) { … } /* get the bits required to program the carrier frequency in CFQ bits, * unshifted */ static u8 ite_get_carrier_freq_bits(unsigned int freq) { … } /* get the bits required to program the pulse with in TXMPW */ static u8 ite_get_pulse_width_bits(unsigned int freq, int duty_cycle) { … } /* decode raw bytes as received by the hardware, and push them to the ir-core * layer */ static void ite_decode_bytes(struct ite_dev *dev, const u8 * data, int length) { … } /* set all the rx/tx carrier parameters; this must be called with the device * spinlock held */ static void ite_set_carrier_params(struct ite_dev *dev) { … } /* interrupt service routine for incoming and outgoing CIR data */ static irqreturn_t ite_cir_isr(int irq, void *data) { … } /* set the rx carrier freq range, guess it's in Hz... */ static int ite_set_rx_carrier_range(struct rc_dev *rcdev, u32 carrier_low, u32 carrier_high) { … } /* set the tx carrier freq, guess it's in Hz... */ static int ite_set_tx_carrier(struct rc_dev *rcdev, u32 carrier) { … } /* set the tx duty cycle by controlling the pulse width */ static int ite_set_tx_duty_cycle(struct rc_dev *rcdev, u32 duty_cycle) { … } /* transmit out IR pulses; what you get here is a batch of alternating * pulse/space/pulse/space lengths that we should write out completely through * the FIFO, blocking on a full FIFO */ static int ite_tx_ir(struct rc_dev *rcdev, unsigned *txbuf, unsigned n) { … } /* idle the receiver if needed */ static void ite_s_idle(struct rc_dev *rcdev, bool enable) { … } /* IT8712F HW-specific functions */ /* retrieve a bitmask of the current causes for a pending interrupt; this may * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN * */ static int it87_get_irq_causes(struct ite_dev *dev) { … } /* set the carrier parameters; to be called with the spinlock held */ static void it87_set_carrier_params(struct ite_dev *dev, bool high_freq, bool use_demodulator, u8 carrier_freq_bits, u8 allowance_bits, u8 pulse_width_bits) { … } /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock * held */ static int it87_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size) { … } /* return how many bytes are still in the FIFO; this will be called * with the device spinlock NOT HELD while waiting for the TX FIFO to get * empty; let's expect this won't be a problem */ static int it87_get_tx_used_slots(struct ite_dev *dev) { … } /* put a byte to the TX fifo; this should be called with the spinlock held */ static void it87_put_tx_byte(struct ite_dev *dev, u8 value) { … } /* idle the receiver so that we won't receive samples until another pulse is detected; this must be called with the device spinlock held */ static void it87_idle_rx(struct ite_dev *dev) { … } /* disable the receiver; this must be called with the device spinlock held */ static void it87_disable_rx(struct ite_dev *dev) { … } /* enable the receiver; this must be called with the device spinlock held */ static void it87_enable_rx(struct ite_dev *dev) { … } /* disable the transmitter interrupt; this must be called with the device * spinlock held */ static void it87_disable_tx_interrupt(struct ite_dev *dev) { … } /* enable the transmitter interrupt; this must be called with the device * spinlock held */ static void it87_enable_tx_interrupt(struct ite_dev *dev) { … } /* disable the device; this must be called with the device spinlock held */ static void it87_disable(struct ite_dev *dev) { … } /* initialize the hardware */ static void it87_init_hardware(struct ite_dev *dev) { … } /* IT8512F on ITE8708 HW-specific functions */ /* retrieve a bitmask of the current causes for a pending interrupt; this may * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN * */ static int it8708_get_irq_causes(struct ite_dev *dev) { … } /* set the carrier parameters; to be called with the spinlock held */ static void it8708_set_carrier_params(struct ite_dev *dev, bool high_freq, bool use_demodulator, u8 carrier_freq_bits, u8 allowance_bits, u8 pulse_width_bits) { … } /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock * held */ static int it8708_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size) { … } /* return how many bytes are still in the FIFO; this will be called * with the device spinlock NOT HELD while waiting for the TX FIFO to get * empty; let's expect this won't be a problem */ static int it8708_get_tx_used_slots(struct ite_dev *dev) { … } /* put a byte to the TX fifo; this should be called with the spinlock held */ static void it8708_put_tx_byte(struct ite_dev *dev, u8 value) { … } /* idle the receiver so that we won't receive samples until another pulse is detected; this must be called with the device spinlock held */ static void it8708_idle_rx(struct ite_dev *dev) { … } /* disable the receiver; this must be called with the device spinlock held */ static void it8708_disable_rx(struct ite_dev *dev) { … } /* enable the receiver; this must be called with the device spinlock held */ static void it8708_enable_rx(struct ite_dev *dev) { … } /* disable the transmitter interrupt; this must be called with the device * spinlock held */ static void it8708_disable_tx_interrupt(struct ite_dev *dev) { … } /* enable the transmitter interrupt; this must be called with the device * spinlock held */ static void it8708_enable_tx_interrupt(struct ite_dev *dev) { … } /* disable the device; this must be called with the device spinlock held */ static void it8708_disable(struct ite_dev *dev) { … } /* initialize the hardware */ static void it8708_init_hardware(struct ite_dev *dev) { … } /* IT8512F on ITE8709 HW-specific functions */ /* read a byte from the SRAM module */ static inline u8 it8709_rm(struct ite_dev *dev, int index) { … } /* write a byte to the SRAM module */ static inline void it8709_wm(struct ite_dev *dev, u8 val, int index) { … } static void it8709_wait(struct ite_dev *dev) { … } /* read the value of a CIR register */ static u8 it8709_rr(struct ite_dev *dev, int index) { … } /* write the value of a CIR register */ static void it8709_wr(struct ite_dev *dev, u8 val, int index) { … } /* retrieve a bitmask of the current causes for a pending interrupt; this may * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN * */ static int it8709_get_irq_causes(struct ite_dev *dev) { … } /* set the carrier parameters; to be called with the spinlock held */ static void it8709_set_carrier_params(struct ite_dev *dev, bool high_freq, bool use_demodulator, u8 carrier_freq_bits, u8 allowance_bits, u8 pulse_width_bits) { … } /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock * held */ static int it8709_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size) { … } /* return how many bytes are still in the FIFO; this will be called * with the device spinlock NOT HELD while waiting for the TX FIFO to get * empty; let's expect this won't be a problem */ static int it8709_get_tx_used_slots(struct ite_dev *dev) { … } /* put a byte to the TX fifo; this should be called with the spinlock held */ static void it8709_put_tx_byte(struct ite_dev *dev, u8 value) { … } /* idle the receiver so that we won't receive samples until another pulse is detected; this must be called with the device spinlock held */ static void it8709_idle_rx(struct ite_dev *dev) { … } /* disable the receiver; this must be called with the device spinlock held */ static void it8709_disable_rx(struct ite_dev *dev) { … } /* enable the receiver; this must be called with the device spinlock held */ static void it8709_enable_rx(struct ite_dev *dev) { … } /* disable the transmitter interrupt; this must be called with the device * spinlock held */ static void it8709_disable_tx_interrupt(struct ite_dev *dev) { … } /* enable the transmitter interrupt; this must be called with the device * spinlock held */ static void it8709_enable_tx_interrupt(struct ite_dev *dev) { … } /* disable the device; this must be called with the device spinlock held */ static void it8709_disable(struct ite_dev *dev) { … } /* initialize the hardware */ static void it8709_init_hardware(struct ite_dev *dev) { … } /* generic hardware setup/teardown code */ /* activate the device for use */ static int ite_open(struct rc_dev *rcdev) { … } /* deactivate the device for use */ static void ite_close(struct rc_dev *rcdev) { … } /* supported models and their parameters */ static const struct ite_dev_params ite_dev_descs[] = …; static const struct pnp_device_id ite_ids[] = …; /* allocate memory, probe hardware, and initialize everything */ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) { … } static void ite_remove(struct pnp_dev *pdev) { … } static int ite_suspend(struct pnp_dev *pdev, pm_message_t state) { … } static int ite_resume(struct pnp_dev *pdev) { … } static void ite_shutdown(struct pnp_dev *pdev) { … } static struct pnp_driver ite_driver = …; MODULE_DEVICE_TABLE(pnp, ite_ids); MODULE_DESCRIPTION(…) …; MODULE_AUTHOR(…) …; MODULE_LICENSE(…) …; module_pnp_driver(…);