blob: 29e43b03c85e18eaee3a4daa02eebff9ba2c7749 [file] [log] [blame]
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -03001/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030023#include "cx25821.h"
24
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030025/********************* GPIO stuffs *********************/
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030026void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
27 int pin_number, int pin_logic_value)
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030028{
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030029 int bit = pin_number;
30 u32 gpio_oe_reg = GPIO_LO_OE;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030031 u32 gpio_register = 0;
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030032 u32 value = 0;
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030033
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030034 /* Check for valid pinNumber */
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030035 if (pin_number >= 47)
36 return;
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030037
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030038 if (pin_number > 31) {
39 bit = pin_number - 31;
40 gpio_oe_reg = GPIO_HI_OE;
41 }
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030042 /* Here we will make sure that the GPIOs 0 and 1 are output. keep the
43 * rest as is */
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030044 gpio_register = cx_read(gpio_oe_reg);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030045
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030046 if (pin_logic_value == 1)
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030047 value = gpio_register | Set_GPIO_Bit(bit);
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030048 else
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030049 value = gpio_register & Clear_GPIO_Bit(bit);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030050
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030051 cx_write(gpio_oe_reg, value);
52}
Leonid V. Fedorenchik8eea4552011-09-02 11:55:32 +080053EXPORT_SYMBOL(cx25821_set_gpiopin_direction);
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030054
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030055static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev,
56 int pin_number, int pin_logic_value)
57{
58 int bit = pin_number;
59 u32 gpio_reg = GPIO_LO;
60 u32 value = 0;
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030061
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030062 /* Check for valid pinNumber */
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030063 if (pin_number >= 47)
64 return;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030065
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030066 /* change to output direction */
67 cx25821_set_gpiopin_direction(dev, pin_number, 0);
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030068
69 if (pin_number > 31) {
70 bit = pin_number - 31;
71 gpio_reg = GPIO_HI;
72 }
73
74 value = cx_read(gpio_reg);
75
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030076 if (pin_logic_value == 0)
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030077 value &= Clear_GPIO_Bit(bit);
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030078 else
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030079 value |= Set_GPIO_Bit(bit);
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030080
81 cx_write(gpio_reg, value);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030082}
83
84void cx25821_gpio_init(struct cx25821_dev *dev)
85{
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030086 if (dev == NULL)
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030087 return;
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030088
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030089 switch (dev->board) {
90 case CX25821_BOARD_CONEXANT_ATHENA10:
91 default:
Olimpiu Pascariu1c614232010-03-21 14:44:01 -030092 /* set GPIO 5 to select the path for Medusa/Athena */
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030093 cx25821_set_gpiopin_logicvalue(dev, 5, 1);
94 mdelay(20);
95 break;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030096 }
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030097
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030098}