26
26
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
29
* the project's page is at http://www.linuxtv.org/dvb/
29
* the project's page is at http://www.linuxtv.org/
32
32
#include <linux/module.h>
33
33
#include <linux/errno.h>
34
34
#include <linux/slab.h>
35
35
#include <linux/interrupt.h>
36
#include <linux/input.h>
37
36
#include <linux/spinlock.h>
38
#include <media/ir-common.h>
37
#include <media/rc-core.h>
40
39
#include "budget.h"
80
81
#define SLOTSTATUS_READY 8
81
82
#define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
84
* Milliseconds during which a key is regarded as pressed.
85
* If an identical command arrives within this time, the timer will start over.
87
#define IR_KEYPRESS_TIMEOUT 250
89
84
/* RC5 device wildcard */
90
85
#define IR_DEVICE_ANY 255
100
95
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
102
97
struct budget_ci_ir {
103
struct input_dev *dev;
104
99
struct tasklet_struct msp430_irq_tasklet;
105
struct timer_list timer_keyup;
106
100
char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
108
struct ir_input_state state;
112
104
bool have_command;
122
114
u8 tuner_pll_address; /* used for philips_tdm1316l configs */
125
static void msp430_ir_keyup(unsigned long data)
127
struct budget_ci_ir *ir = (struct budget_ci_ir *) data;
128
ir_input_nokey(ir->dev, &ir->state);
131
117
static void msp430_ir_interrupt(unsigned long data)
133
119
struct budget_ci *budget_ci = (struct budget_ci *) data;
134
struct input_dev *dev = budget_ci->ir.dev;
120
struct rc_dev *dev = budget_ci->ir.dev;
135
121
u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
139
124
* The msp430 chip can generate two different bytes, command and device
170
155
budget_ci->ir.have_command = false;
157
/* FIXME: We should generate complete scancodes with device info */
172
158
if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&
173
159
budget_ci->ir.rc5_device != (command & 0x1f))
176
/* Is this a repeated key sequence? (same device, command, toggle) */
177
raw = budget_ci->ir.ir_key | (command << 8);
178
if (budget_ci->ir.last_raw != raw || !timer_pending(&budget_ci->ir.timer_keyup)) {
179
ir_input_nokey(dev, &budget_ci->ir.state);
180
ir_input_keydown(dev, &budget_ci->ir.state,
181
budget_ci->ir.ir_key, raw);
182
budget_ci->ir.last_raw = raw;
185
mod_timer(&budget_ci->ir.timer_keyup, jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT));
162
rc_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0);
188
165
static int msp430_ir_init(struct budget_ci *budget_ci)
190
167
struct saa7146_dev *saa = budget_ci->budget.dev;
191
struct input_dev *input_dev = budget_ci->ir.dev;
194
budget_ci->ir.dev = input_dev = input_allocate_device();
171
dev = rc_allocate_device();
196
173
printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
201
177
snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
203
179
snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
204
180
"pci-%s/ir0", pci_name(saa->pci));
206
input_dev->name = budget_ci->ir.name;
208
input_dev->phys = budget_ci->ir.phys;
209
input_dev->id.bustype = BUS_PCI;
210
input_dev->id.version = 1;
182
dev->driver_name = MODULE_NAME;
183
dev->input_name = budget_ci->ir.name;
184
dev->input_phys = budget_ci->ir.phys;
185
dev->input_id.bustype = BUS_PCI;
186
dev->input_id.version = 1;
187
dev->scanmask = 0xff;
211
188
if (saa->pci->subsystem_vendor) {
212
input_dev->id.vendor = saa->pci->subsystem_vendor;
213
input_dev->id.product = saa->pci->subsystem_device;
189
dev->input_id.vendor = saa->pci->subsystem_vendor;
190
dev->input_id.product = saa->pci->subsystem_device;
215
input_dev->id.vendor = saa->pci->vendor;
216
input_dev->id.product = saa->pci->device;
192
dev->input_id.vendor = saa->pci->vendor;
193
dev->input_id.product = saa->pci->device;
218
input_dev->dev.parent = &saa->pci->dev;
195
dev->dev.parent = &saa->pci->dev;
198
budget_ci->ir.rc5_device = IR_DEVICE_ANY;
200
budget_ci->ir.rc5_device = rc5_device;
220
202
/* Select keymap and address */
221
203
switch (budget_ci->budget.dev->pci->subsystem_device) {
226
208
/* The hauppauge keymap is a superset of these remotes */
227
ir_input_init(input_dev, &budget_ci->ir.state,
228
IR_TYPE_RC5, &ir_codes_hauppauge_new_table);
209
dev->map_name = RC_MAP_HAUPPAUGE_NEW;
230
211
if (rc5_device < 0)
231
212
budget_ci->ir.rc5_device = 0x1f;
233
budget_ci->ir.rc5_device = rc5_device;
238
218
/* for the Technotrend 1500 bundled remote */
239
ir_input_init(input_dev, &budget_ci->ir.state,
240
IR_TYPE_RC5, &ir_codes_tt_1500_table);
243
budget_ci->ir.rc5_device = IR_DEVICE_ANY;
245
budget_ci->ir.rc5_device = rc5_device;
219
dev->map_name = RC_MAP_TT_1500;
248
222
/* unknown remote */
249
ir_input_init(input_dev, &budget_ci->ir.state,
250
IR_TYPE_RC5, &ir_codes_budget_ci_old_table);
253
budget_ci->ir.rc5_device = IR_DEVICE_ANY;
255
budget_ci->ir.rc5_device = rc5_device;
223
dev->map_name = RC_MAP_BUDGET_CI_OLD;
259
/* initialise the key-up timeout handler */
260
init_timer(&budget_ci->ir.timer_keyup);
261
budget_ci->ir.timer_keyup.function = msp430_ir_keyup;
262
budget_ci->ir.timer_keyup.data = (unsigned long) &budget_ci->ir;
263
budget_ci->ir.last_raw = 0xffff; /* An impossible value */
264
error = input_register_device(input_dev);
227
error = rc_register_device(dev);
266
229
printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
270
/* note: these must be after input_register_device */
271
input_dev->rep[REP_DELAY] = 400;
272
input_dev->rep[REP_PERIOD] = 250;
234
budget_ci->ir.dev = dev;
274
236
tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
275
237
(unsigned long) budget_ci);
278
240
saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
283
input_free_device(input_dev);
288
245
static void msp430_ir_deinit(struct budget_ci *budget_ci)
290
247
struct saa7146_dev *saa = budget_ci->budget.dev;
291
struct input_dev *dev = budget_ci->ir.dev;
293
249
SAA7146_IER_DISABLE(saa, MASK_06);
294
250
saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
295
251
tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
297
del_timer_sync(&dev->timer);
298
ir_input_nokey(dev, &budget_ci->ir.state);
300
input_unregister_device(dev);
253
rc_unregister_device(budget_ci->ir.dev);
303
256
static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
1248
1201
{ STB0899_TSCFGH , 0x0c },
1249
1202
{ STB0899_TSCFGM , 0x00 },
1250
1203
{ STB0899_TSCFGL , 0x0c },
1251
{ STB0899_TSOUT , 0x0d }, /* 0x0d for CAM */
1204
{ STB0899_TSOUT , 0x4d }, /* 0x0d for CAM */
1252
1205
{ STB0899_RSSYNCDEL , 0x00 },
1253
1206
{ STB0899_TSINHDELH , 0x02 },
1254
1207
{ STB0899_TSINHDELM , 0x00 },