Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cx18 gpio functions |
| 3 | * |
| 4 | * Derived from ivtv-gpio.c |
| 5 | * |
| 6 | * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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 |
| 21 | * 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include "cx18-driver.h" |
| 25 | #include "cx18-cards.h" |
| 26 | #include "cx18-gpio.h" |
| 27 | #include "tuner-xc2028.h" |
| 28 | |
| 29 | /********************* GPIO stuffs *********************/ |
| 30 | |
| 31 | /* GPIO registers */ |
| 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 |
| 37 | |
Hans Verkuil | 9dcbf35 | 2008-05-12 13:57:18 -0300 | [diff] [blame^] | 38 | static u32 gpio_dir; |
| 39 | static u32 gpio_val; |
| 40 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 41 | /* |
| 42 | * HVR-1600 GPIO pins, courtesy of Hauppauge: |
| 43 | * |
| 44 | * gpio0: zilog ir process reset pin |
| 45 | * gpio1: zilog programming pin (you should never use this) |
| 46 | * gpio12: cx24227 reset pin |
| 47 | * gpio13: cs5345 reset pin |
| 48 | */ |
| 49 | |
Hans Verkuil | 9dcbf35 | 2008-05-12 13:57:18 -0300 | [diff] [blame^] | 50 | static void gpio_write(struct cx18 *cx) |
| 51 | { |
| 52 | write_reg((gpio_dir & 0xffff) << 16, CX18_REG_GPIO_DIR1); |
| 53 | write_reg(((gpio_dir & 0xffff) << 16) | (gpio_val & 0xffff), |
| 54 | CX18_REG_GPIO_OUT1); |
| 55 | write_reg(gpio_dir & 0xffff0000, CX18_REG_GPIO_DIR2); |
| 56 | write_reg((gpio_dir & 0xffff0000) | ((gpio_val & 0xffff0000) >> 16), |
| 57 | CX18_REG_GPIO_OUT2); |
| 58 | } |
| 59 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 60 | void cx18_gpio_init(struct cx18 *cx) |
| 61 | { |
Hans Verkuil | 9dcbf35 | 2008-05-12 13:57:18 -0300 | [diff] [blame^] | 62 | gpio_dir = cx->card->gpio_init.direction; |
| 63 | gpio_val = cx->card->gpio_init.initial_value; |
| 64 | |
| 65 | if (gpio_dir == 0) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 66 | return; |
| 67 | |
Hans Verkuil | 9dcbf35 | 2008-05-12 13:57:18 -0300 | [diff] [blame^] | 68 | gpio_dir |= 1 << cx->card->xceive_pin; |
| 69 | gpio_val |= 1 << cx->card->xceive_pin; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 70 | |
Hans Verkuil | 9dcbf35 | 2008-05-12 13:57:18 -0300 | [diff] [blame^] | 71 | CX18_DEBUG_INFO("GPIO initial dir: %08x/%08x out: %08x/%08x\n", |
| 72 | read_reg(CX18_REG_GPIO_DIR1), read_reg(CX18_REG_GPIO_DIR2), |
| 73 | read_reg(CX18_REG_GPIO_OUT1), read_reg(CX18_REG_GPIO_OUT2)); |
| 74 | |
| 75 | gpio_write(cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* Xceive tuner reset function */ |
| 79 | int cx18_reset_tuner_gpio(void *dev, int cmd, int value) |
| 80 | { |
| 81 | struct i2c_algo_bit_data *algo = dev; |
Hans Verkuil | 9dcbf35 | 2008-05-12 13:57:18 -0300 | [diff] [blame^] | 82 | struct cx18_i2c_algo_callback_data *cb_data = algo->data; |
| 83 | struct cx18 *cx = cb_data->cx; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 84 | |
| 85 | if (cmd != XC2028_TUNER_RESET) |
| 86 | return 0; |
| 87 | CX18_DEBUG_INFO("Resetting tuner\n"); |
Hans Verkuil | 9dcbf35 | 2008-05-12 13:57:18 -0300 | [diff] [blame^] | 88 | |
| 89 | gpio_dir |= 1 << cx->card->xceive_pin; |
| 90 | gpio_val &= ~(1 << cx->card->xceive_pin); |
| 91 | |
| 92 | gpio_write(cx); |
| 93 | schedule_timeout_interruptible(msecs_to_jiffies(1)); |
| 94 | |
| 95 | gpio_val |= 1 << cx->card->xceive_pin; |
| 96 | gpio_write(cx); |
| 97 | schedule_timeout_interruptible(msecs_to_jiffies(1)); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 98 | return 0; |
| 99 | } |