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

« back to all changes in this revision

Viewing changes to drivers/media/video/ivtv/ivtv-i2c.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:
63
63
#include "ivtv-cards.h"
64
64
#include "ivtv-gpio.h"
65
65
#include "ivtv-i2c.h"
 
66
#include <media/cx25840.h>
66
67
 
67
68
/* i2c implementation for cx23415/6 chip, ivtv project.
68
69
 * Author: Kevin Thayer (nufan_wfk at yahoo.com)
88
89
#define IVTV_UPD64083_I2C_ADDR          0x5c
89
90
#define IVTV_VP27SMPX_I2C_ADDR          0x5b
90
91
#define IVTV_M52790_I2C_ADDR            0x48
 
92
#define IVTV_AVERMEDIA_IR_RX_I2C_ADDR   0x40
 
93
#define IVTV_HAUP_EXT_IR_RX_I2C_ADDR    0x1a
 
94
#define IVTV_HAUP_INT_IR_RX_I2C_ADDR    0x18
 
95
#define IVTV_Z8F0811_IR_TX_I2C_ADDR     0x70
 
96
#define IVTV_Z8F0811_IR_RX_I2C_ADDR     0x71
 
97
#define IVTV_ADAPTEC_IR_ADDR            0x6b
91
98
 
92
99
/* This array should match the IVTV_HW_ defines */
93
100
static const u8 hw_addrs[] = {
106
113
        IVTV_WM8739_I2C_ADDR,
107
114
        IVTV_VP27SMPX_I2C_ADDR,
108
115
        IVTV_M52790_I2C_ADDR,
109
 
        0               /* IVTV_HW_GPIO dummy driver ID */
110
 
};
111
 
 
112
 
/* This array should match the IVTV_HW_ defines */
113
 
static const char *hw_modules[] = {
114
 
        "cx25840",
115
 
        "saa7115",
116
 
        "saa7127",
117
 
        "msp3400",
118
 
        "tuner",
119
 
        "wm8775",
120
 
        "cs53l32a",
121
 
        NULL,
122
 
        "saa7115",
123
 
        "upd64031a",
124
 
        "upd64083",
125
 
        "saa717x",
126
 
        "wm8739",
127
 
        "vp27smpx",
128
 
        "m52790",
129
 
        NULL
 
116
        0,                              /* IVTV_HW_GPIO dummy driver ID */
 
117
        IVTV_AVERMEDIA_IR_RX_I2C_ADDR,  /* IVTV_HW_I2C_IR_RX_AVER */
 
118
        IVTV_HAUP_EXT_IR_RX_I2C_ADDR,   /* IVTV_HW_I2C_IR_RX_HAUP_EXT */
 
119
        IVTV_HAUP_INT_IR_RX_I2C_ADDR,   /* IVTV_HW_I2C_IR_RX_HAUP_INT */
 
120
        IVTV_Z8F0811_IR_TX_I2C_ADDR,    /* IVTV_HW_Z8F0811_IR_TX_HAUP */
 
121
        IVTV_Z8F0811_IR_RX_I2C_ADDR,    /* IVTV_HW_Z8F0811_IR_RX_HAUP */
 
122
        IVTV_ADAPTEC_IR_ADDR,           /* IVTV_HW_I2C_IR_RX_ADAPTEC */
130
123
};
131
124
 
132
125
/* This array should match the IVTV_HW_ defines */
147
140
        "vp27smpx",
148
141
        "m52790",
149
142
        "gpio",
 
143
        "ir_video",             /* IVTV_HW_I2C_IR_RX_AVER */
 
144
        "ir_video",             /* IVTV_HW_I2C_IR_RX_HAUP_EXT */
 
145
        "ir_video",             /* IVTV_HW_I2C_IR_RX_HAUP_INT */
 
146
        "ir_tx_z8f0811_haup",   /* IVTV_HW_Z8F0811_IR_TX_HAUP */
 
147
        "ir_rx_z8f0811_haup",   /* IVTV_HW_Z8F0811_IR_RX_HAUP */
 
148
        "ir_video",             /* IVTV_HW_I2C_IR_RX_ADAPTEC */
150
149
};
151
150
 
 
151
static int get_key_adaptec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
 
152
{
 
153
        unsigned char keybuf[4];
 
154
 
 
155
        keybuf[0] = 0x00;
 
156
        i2c_master_send(ir->c, keybuf, 1);
 
157
        /* poll IR chip */
 
158
        if (i2c_master_recv(ir->c, keybuf, sizeof(keybuf)) != sizeof(keybuf)) {
 
159
                return 0;
 
160
        }
 
161
 
 
162
        /* key pressed ? */
 
163
        if (keybuf[2] == 0xff)
 
164
                return 0;
 
165
 
 
166
        /* remove repeat bit */
 
167
        keybuf[2] &= 0x7f;
 
168
        keybuf[3] |= 0x80;
 
169
 
 
170
        *ir_key = keybuf[3] | keybuf[2] << 8 | keybuf[1] << 16 |keybuf[0] << 24;
 
171
        *ir_raw = *ir_key;
 
172
 
 
173
        return 1;
 
174
}
 
175
 
 
176
static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
 
177
{
 
178
        struct i2c_board_info info;
 
179
        struct i2c_adapter *adap = &itv->i2c_adap;
 
180
        struct IR_i2c_init_data *init_data = &itv->ir_i2c_init_data;
 
181
        unsigned short addr_list[2] = { addr, I2C_CLIENT_END };
 
182
 
 
183
        /* Only allow one IR transmitter to be registered per board */
 
184
        if (hw & IVTV_HW_IR_TX_ANY) {
 
185
                if (itv->hw_flags & IVTV_HW_IR_TX_ANY)
 
186
                        return -1;
 
187
                memset(&info, 0, sizeof(struct i2c_board_info));
 
188
                strlcpy(info.type, type, I2C_NAME_SIZE);
 
189
                return i2c_new_probed_device(adap, &info, addr_list, NULL)
 
190
                                                           == NULL ? -1 : 0;
 
191
        }
 
192
 
 
193
        /* Only allow one IR receiver to be registered per board */
 
194
        if (itv->hw_flags & IVTV_HW_IR_RX_ANY)
 
195
                return -1;
 
196
 
 
197
        /* Our default information for ir-kbd-i2c.c to use */
 
198
        switch (hw) {
 
199
        case IVTV_HW_I2C_IR_RX_AVER:
 
200
                init_data->ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
 
201
                init_data->internal_get_key_func =
 
202
                                        IR_KBD_GET_KEY_AVERMEDIA_CARDBUS;
 
203
                init_data->type = RC_TYPE_OTHER;
 
204
                init_data->name = "AVerMedia AVerTV card";
 
205
                break;
 
206
        case IVTV_HW_I2C_IR_RX_HAUP_EXT:
 
207
        case IVTV_HW_I2C_IR_RX_HAUP_INT:
 
208
                /* Default to old black remote */
 
209
                init_data->ir_codes = RC_MAP_RC5_TV;
 
210
                init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP;
 
211
                init_data->type = RC_TYPE_RC5;
 
212
                init_data->name = itv->card_name;
 
213
                break;
 
214
        case IVTV_HW_Z8F0811_IR_RX_HAUP:
 
215
                /* Default to grey remote */
 
216
                init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW;
 
217
                init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
 
218
                init_data->type = RC_TYPE_RC5;
 
219
                init_data->name = itv->card_name;
 
220
                break;
 
221
        case IVTV_HW_I2C_IR_RX_ADAPTEC:
 
222
                init_data->get_key = get_key_adaptec;
 
223
                init_data->name = itv->card_name;
 
224
                /* FIXME: The protocol and RC_MAP needs to be corrected */
 
225
                init_data->ir_codes = RC_MAP_EMPTY;
 
226
                init_data->type = RC_TYPE_UNKNOWN;
 
227
                break;
 
228
        }
 
229
 
 
230
        memset(&info, 0, sizeof(struct i2c_board_info));
 
231
        info.platform_data = init_data;
 
232
        strlcpy(info.type, type, I2C_NAME_SIZE);
 
233
 
 
234
        return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
 
235
               -1 : 0;
 
236
}
 
237
 
 
238
/* Instantiate the IR receiver device using probing -- undesirable */
 
239
struct i2c_client *ivtv_i2c_new_ir_legacy(struct ivtv *itv)
 
240
{
 
241
        struct i2c_board_info info;
 
242
        /*
 
243
         * The external IR receiver is at i2c address 0x34.
 
244
         * The internal IR receiver is at i2c address 0x30.
 
245
         *
 
246
         * In theory, both can be fitted, and Hauppauge suggests an external
 
247
         * overrides an internal.  That's why we probe 0x1a (~0x34) first. CB
 
248
         *
 
249
         * Some of these addresses we probe may collide with other i2c address
 
250
         * allocations, so this function must be called after all other i2c
 
251
         * devices we care about are registered.
 
252
         */
 
253
        const unsigned short addr_list[] = {
 
254
                0x1a,   /* Hauppauge IR external - collides with WM8739 */
 
255
                0x18,   /* Hauppauge IR internal */
 
256
                I2C_CLIENT_END
 
257
        };
 
258
 
 
259
        memset(&info, 0, sizeof(struct i2c_board_info));
 
260
        strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
 
261
        return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL);
 
262
}
 
263
 
152
264
int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
153
265
{
154
266
        struct v4l2_subdev *sd;
155
267
        struct i2c_adapter *adap = &itv->i2c_adap;
156
 
        const char *mod = hw_modules[idx];
157
268
        const char *type = hw_devicenames[idx];
158
269
        u32 hw = 1 << idx;
159
270
 
161
272
                return -1;
162
273
        if (hw == IVTV_HW_TUNER) {
163
274
                /* special tuner handling */
164
 
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
165
 
                                adap, mod, type,
166
 
                                0, itv->card_i2c->radio);
167
 
                if (sd)
168
 
                        sd->grp_id = 1 << idx;
169
 
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
170
 
                                adap, mod, type,
171
 
                                0, itv->card_i2c->demod);
172
 
                if (sd)
173
 
                        sd->grp_id = 1 << idx;
174
 
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
175
 
                                adap, mod, type,
176
 
                                0, itv->card_i2c->tv);
 
275
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0,
 
276
                                itv->card_i2c->radio);
 
277
                if (sd)
 
278
                        sd->grp_id = 1 << idx;
 
279
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0,
 
280
                                itv->card_i2c->demod);
 
281
                if (sd)
 
282
                        sd->grp_id = 1 << idx;
 
283
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0,
 
284
                                itv->card_i2c->tv);
177
285
                if (sd)
178
286
                        sd->grp_id = 1 << idx;
179
287
                return sd ? 0 : -1;
180
288
        }
 
289
 
 
290
        if (hw & IVTV_HW_IR_ANY)
 
291
                return ivtv_i2c_new_ir(itv, hw, type, hw_addrs[idx]);
 
292
 
 
293
        /* Is it not an I2C device or one we do not wish to register? */
181
294
        if (!hw_addrs[idx])
182
295
                return -1;
 
296
 
 
297
        /* It's an I2C device other than an analog tuner or IR chip */
183
298
        if (hw == IVTV_HW_UPD64031A || hw == IVTV_HW_UPD6408X) {
184
299
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
185
 
                                adap, mod, type, 0, I2C_ADDRS(hw_addrs[idx]));
 
300
                                adap, type, 0, I2C_ADDRS(hw_addrs[idx]));
 
301
        } else if (hw == IVTV_HW_CX25840) {
 
302
                struct cx25840_platform_data pdata;
 
303
                struct i2c_board_info cx25840_info = {
 
304
                        .type = "cx25840",
 
305
                        .addr = hw_addrs[idx],
 
306
                        .platform_data = &pdata,
 
307
                };
 
308
 
 
309
                pdata.pvr150_workaround = itv->pvr150_workaround;
 
310
                sd = v4l2_i2c_new_subdev_board(&itv->v4l2_dev, adap,
 
311
                                &cx25840_info, NULL);
186
312
        } else {
187
313
                sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
188
 
                                adap, mod, type, hw_addrs[idx], NULL);
 
314
                                adap, type, hw_addrs[idx], NULL);
189
315
        }
190
316
        if (sd)
191
317
                sd->grp_id = 1 << idx;
564
690
        .owner = THIS_MODULE,
565
691
};
566
692
 
 
693
#define IVTV_ALGO_BIT_TIMEOUT   (2)     /* seconds */
 
694
 
567
695
static const struct i2c_algo_bit_data ivtv_i2c_algo_template = {
568
696
        .setsda         = ivtv_setsda_old,
569
697
        .setscl         = ivtv_setscl_old,
570
698
        .getsda         = ivtv_getsda_old,
571
699
        .getscl         = ivtv_getscl_old,
572
 
        .udelay         = 10,
573
 
        .timeout        = 200,
 
700
        .udelay         = IVTV_DEFAULT_I2C_CLOCK_PERIOD / 2,  /* microseconds */
 
701
        .timeout        = IVTV_ALGO_BIT_TIMEOUT * HZ,         /* jiffies */
574
702
};
575
703
 
576
704
static struct i2c_client ivtv_i2c_client_template = {
577
705
        .name = "ivtv internal",
578
706
};
579
707
 
580
 
/* init + register i2c adapter + instantiate IR receiver */
 
708
/* init + register i2c adapter */
581
709
int init_ivtv_i2c(struct ivtv *itv)
582
710
{
583
711
        int retval;
585
713
        IVTV_DEBUG_I2C("i2c init\n");
586
714
 
587
715
        /* Sanity checks for the I2C hardware arrays. They must be the
588
 
         * same size and GPIO must be the last entry.
 
716
         * same size.
589
717
         */
590
 
        if (ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_addrs) ||
591
 
            ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_modules) ||
592
 
            IVTV_HW_GPIO != (1 << (ARRAY_SIZE(hw_addrs) - 1))) {
 
718
        if (ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_addrs)) {
593
719
                IVTV_ERR("Mismatched I2C hardware arrays\n");
594
720
                return -ENODEV;
595
721
        }
602
728
                memcpy(&itv->i2c_algo, &ivtv_i2c_algo_template,
603
729
                       sizeof(struct i2c_algo_bit_data));
604
730
        }
 
731
        itv->i2c_algo.udelay = itv->options.i2c_clock_period / 2;
605
732
        itv->i2c_algo.data = itv;
606
733
        itv->i2c_adap.algo_data = &itv->i2c_algo;
607
734
 
623
750
        else
624
751
                retval = i2c_bit_add_bus(&itv->i2c_adap);
625
752
 
626
 
        /* Instantiate the IR receiver device, if present */
627
 
        if (retval == 0) {
628
 
                struct i2c_board_info info;
629
 
                /* The external IR receiver is at i2c address 0x34 (0x35 for
630
 
                   reads).  Future Hauppauge cards will have an internal
631
 
                   receiver at 0x30 (0x31 for reads).  In theory, both can be
632
 
                   fitted, and Hauppauge suggest an external overrides an
633
 
                   internal.
634
 
 
635
 
                   That's why we probe 0x1a (~0x34) first. CB
636
 
                */
637
 
                const unsigned short addr_list[] = {
638
 
                        0x1a,   /* Hauppauge IR external */
639
 
                        0x18,   /* Hauppauge IR internal */
640
 
                        0x71,   /* Hauppauge IR (PVR150) */
641
 
                        0x64,   /* Pixelview IR */
642
 
                        0x30,   /* KNC ONE IR */
643
 
                        0x6b,   /* Adaptec IR */
644
 
                        I2C_CLIENT_END
645
 
                };
646
 
 
647
 
                memset(&info, 0, sizeof(struct i2c_board_info));
648
 
                strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
649
 
                i2c_new_probed_device(&itv->i2c_adap, &info, addr_list);
650
 
        }
651
 
 
652
753
        return retval;
653
754
}
654
755