2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <linux/kernel.h>
22 #include <asm/uaccess.h>
25 static void solo_gpio_mode(struct solo6010_dev *solo_dev,
26 unsigned int port_mask, unsigned int mode)
31 ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_0);
34 for (port = 0; port < 16; port++) {
35 if (!((1 << port) & port_mask))
38 ret &= (~(3 << (port << 1)));
39 ret |= ((mode & 3) << (port << 1));
42 solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_0, ret);
44 /* To set extended gpio - sensor */
45 ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_1);
47 for (port = 0; port < 16; port++) {
48 if (!((1 << (port + 16)) & port_mask))
57 solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_1, ret);
60 static void solo_gpio_set(struct solo6010_dev *solo_dev, unsigned int value)
62 solo_reg_write(solo_dev, SOLO_GPIO_DATA_OUT,
63 solo_reg_read(solo_dev, SOLO_GPIO_DATA_OUT) | value);
66 static void solo_gpio_clear(struct solo6010_dev *solo_dev, unsigned int value)
68 solo_reg_write(solo_dev, SOLO_GPIO_DATA_OUT,
69 solo_reg_read(solo_dev, SOLO_GPIO_DATA_OUT) & ~value);
72 static void solo_gpio_config(struct solo6010_dev *solo_dev)
75 solo_gpio_mode(solo_dev, 0x30, 1);
76 solo_gpio_clear(solo_dev, 0x30);
78 solo_gpio_set(solo_dev, 0x30);
81 /* Warning: Don't touch the next line unless you're sure of what
82 * you're doing: first four gpio [0-3] are used for video. */
83 solo_gpio_mode(solo_dev, 0x0f, 2);
85 /* We use bit 8-15 of SOLO_GPIO_CONFIG_0 for relay purposes */
86 solo_gpio_mode(solo_dev, 0xff00, 1);
88 /* Initially set relay status to 0 */
89 solo_gpio_clear(solo_dev, 0xff00);
92 int solo_gpio_init(struct solo6010_dev *solo_dev)
94 solo_gpio_config(solo_dev);
98 void solo_gpio_exit(struct solo6010_dev *solo_dev)
100 solo_gpio_clear(solo_dev, 0x30);
101 solo_gpio_config(solo_dev);