~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/media/dvb/ttpci/budget-ci.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27
27
 *
28
28
 *
29
 
 * the project's page is at http://www.linuxtv.org/dvb/
 
29
 * the project's page is at http://www.linuxtv.org/ 
30
30
 */
31
31
 
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>
39
38
 
40
39
#include "budget.h"
41
40
 
54
53
#include "tda1002x.h"
55
54
#include "tda827x.h"
56
55
 
 
56
#define MODULE_NAME "budget_ci"
 
57
 
57
58
/*
58
59
 * Regarding DEBIADDR_IR:
59
60
 * Some CI modules hang if random addresses are read.
80
81
#define SLOTSTATUS_READY        8
81
82
#define SLOTSTATUS_OCCUPIED     (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
82
83
 
83
 
/*
84
 
 * Milliseconds during which a key is regarded as pressed.
85
 
 * If an identical command arrives within this time, the timer will start over.
86
 
 */
87
 
#define IR_KEYPRESS_TIMEOUT     250
88
 
 
89
84
/* RC5 device wildcard */
90
85
#define IR_DEVICE_ANY           255
91
86
 
100
95
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
101
96
 
102
97
struct budget_ci_ir {
103
 
        struct input_dev *dev;
 
98
        struct rc_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 */
107
101
        char phys[32];
108
 
        struct ir_input_state state;
109
102
        int rc5_device;
110
 
        u32 last_raw;
111
103
        u32 ir_key;
112
104
        bool have_command;
113
105
};
122
114
        u8 tuner_pll_address; /* used for philips_tdm1316l configs */
123
115
};
124
116
 
125
 
static void msp430_ir_keyup(unsigned long data)
126
 
{
127
 
        struct budget_ci_ir *ir = (struct budget_ci_ir *) data;
128
 
        ir_input_nokey(ir->dev, &ir->state);
129
 
}
130
 
 
131
117
static void msp430_ir_interrupt(unsigned long data)
132
118
{
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;
136
 
        u32 raw;
137
122
 
138
123
        /*
139
124
         * The msp430 chip can generate two different bytes, command and device
169
154
                return;
170
155
        budget_ci->ir.have_command = false;
171
156
 
 
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))
174
160
                return;
175
161
 
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;
183
 
        }
184
 
 
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);
186
163
}
187
164
 
188
165
static int msp430_ir_init(struct budget_ci *budget_ci)
189
166
{
190
167
        struct saa7146_dev *saa = budget_ci->budget.dev;
191
 
        struct input_dev *input_dev = budget_ci->ir.dev;
 
168
        struct rc_dev *dev;
192
169
        int error;
193
170
 
194
 
        budget_ci->ir.dev = input_dev = input_allocate_device();
195
 
        if (!input_dev) {
 
171
        dev = rc_allocate_device();
 
172
        if (!dev) {
196
173
                printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
197
 
                error = -ENOMEM;
198
 
                goto out1;
 
174
                return -ENOMEM;
199
175
        }
200
176
 
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));
205
181
 
206
 
        input_dev->name = budget_ci->ir.name;
207
 
 
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;
214
191
        } else {
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;
217
194
        }
218
 
        input_dev->dev.parent = &saa->pci->dev;
 
195
        dev->dev.parent = &saa->pci->dev;
 
196
 
 
197
        if (rc5_device < 0)
 
198
                budget_ci->ir.rc5_device = IR_DEVICE_ANY;
 
199
        else
 
200
                budget_ci->ir.rc5_device = rc5_device;
219
201
 
220
202
        /* Select keymap and address */
221
203
        switch (budget_ci->budget.dev->pci->subsystem_device) {
224
206
        case 0x1011:
225
207
        case 0x1012:
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;
229
210
 
230
211
                if (rc5_device < 0)
231
212
                        budget_ci->ir.rc5_device = 0x1f;
232
 
                else
233
 
                        budget_ci->ir.rc5_device = rc5_device;
234
213
                break;
235
214
        case 0x1010:
236
215
        case 0x1017:
 
216
        case 0x1019:
237
217
        case 0x101a:
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);
241
 
 
242
 
                if (rc5_device < 0)
243
 
                        budget_ci->ir.rc5_device = IR_DEVICE_ANY;
244
 
                else
245
 
                        budget_ci->ir.rc5_device = rc5_device;
 
219
                dev->map_name = RC_MAP_TT_1500;
246
220
                break;
247
221
        default:
248
222
                /* unknown remote */
249
 
                ir_input_init(input_dev, &budget_ci->ir.state,
250
 
                              IR_TYPE_RC5, &ir_codes_budget_ci_old_table);
251
 
 
252
 
                if (rc5_device < 0)
253
 
                        budget_ci->ir.rc5_device = IR_DEVICE_ANY;
254
 
                else
255
 
                        budget_ci->ir.rc5_device = rc5_device;
 
223
                dev->map_name = RC_MAP_BUDGET_CI_OLD;
256
224
                break;
257
225
        }
258
226
 
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);
265
228
        if (error) {
266
229
                printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
267
 
                goto out2;
 
230
                rc_free_device(dev);
 
231
                return error;
268
232
        }
269
233
 
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;
273
235
 
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);
279
241
 
280
242
        return 0;
281
 
 
282
 
out2:
283
 
        input_free_device(input_dev);
284
 
out1:
285
 
        return error;
286
243
}
287
244
 
288
245
static void msp430_ir_deinit(struct budget_ci *budget_ci)
289
246
{
290
247
        struct saa7146_dev *saa = budget_ci->budget.dev;
291
 
        struct input_dev *dev = budget_ci->ir.dev;
292
248
 
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);
296
252
 
297
 
        del_timer_sync(&dev->timer);
298
 
        ir_input_nokey(dev, &budget_ci->ir.state);
299
 
 
300
 
        input_unregister_device(dev);
 
253
        rc_unregister_device(budget_ci->ir.dev);
301
254
}
302
255
 
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 },