4 * Derived from ivtv-gpio.c
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include "cx18-driver.h"
25 #include "cx18-cards.h"
26 #include "cx18-gpio.h"
27 #include "tuner-xc2028.h"
29 /********************* GPIO stuffs *********************/
32 #define CX18_REG_GPIO_IN 0xc72010
33 #define CX18_REG_GPIO_OUT1 0xc78100
34 #define CX18_REG_GPIO_DIR1 0xc78108
35 #define CX18_REG_GPIO_OUT2 0xc78104
36 #define CX18_REG_GPIO_DIR2 0xc7810c
39 * HVR-1600 GPIO pins, courtesy of Hauppauge:
41 * gpio0: zilog ir process reset pin
42 * gpio1: zilog programming pin (you should never use this)
43 * gpio12: cx24227 reset pin
44 * gpio13: cs5345 reset pin
47 static void gpio_write(struct cx18 *cx)
49 u32 dir = cx->gpio_dir;
50 u32 val = cx->gpio_val;
52 write_reg((dir & 0xffff) << 16, CX18_REG_GPIO_DIR1);
53 write_reg(((dir & 0xffff) << 16) | (val & 0xffff),
55 write_reg(dir & 0xffff0000, CX18_REG_GPIO_DIR2);
56 write_reg((dir & 0xffff0000) | ((val & 0xffff0000) >> 16),
60 void cx18_gpio_init(struct cx18 *cx)
62 cx->gpio_dir = cx->card->gpio_init.direction;
63 cx->gpio_val = cx->card->gpio_init.initial_value;
65 if (cx->card->tuners[0].tuner == TUNER_XC2028) {
66 cx->gpio_dir |= 1 << cx->card->xceive_pin;
67 cx->gpio_val |= 1 << cx->card->xceive_pin;
70 if (cx->gpio_dir == 0)
73 CX18_DEBUG_INFO("GPIO initial dir: %08x/%08x out: %08x/%08x\n",
74 read_reg(CX18_REG_GPIO_DIR1), read_reg(CX18_REG_GPIO_DIR2),
75 read_reg(CX18_REG_GPIO_OUT1), read_reg(CX18_REG_GPIO_OUT2));
80 /* Xceive tuner reset function */
81 int cx18_reset_tuner_gpio(void *dev, int cmd, int value)
83 struct i2c_algo_bit_data *algo = dev;
84 struct cx18_i2c_algo_callback_data *cb_data = algo->data;
85 struct cx18 *cx = cb_data->cx;
87 if (cmd != XC2028_TUNER_RESET)
89 CX18_DEBUG_INFO("Resetting tuner\n");
91 cx->gpio_val &= ~(1 << cx->card->xceive_pin);
94 schedule_timeout_interruptible(msecs_to_jiffies(1));
96 cx->gpio_val |= 1 << cx->card->xceive_pin;
98 schedule_timeout_interruptible(msecs_to_jiffies(1));