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>
26 static void solo_gpio_mode(struct solo6010_dev
*solo_dev
,
27 unsigned int port_mask
, unsigned int mode
)
32 ret
= solo_reg_read(solo_dev
, SOLO_GPIO_CONFIG_0
);
35 for (port
= 0; port
< 16; port
++) {
36 if (!((1 << port
) & port_mask
))
39 ret
&= (~(3 << (port
<< 1)));
40 ret
|= ((mode
& 3) << (port
<< 1));
43 solo_reg_write(solo_dev
, SOLO_GPIO_CONFIG_0
, ret
);
45 /* To set extended gpio - sensor */
46 ret
= solo_reg_read(solo_dev
, SOLO_GPIO_CONFIG_1
);
48 for (port
= 0; port
< 16; port
++) {
49 if (!((1 << (port
+ 16)) & port_mask
))
58 solo_reg_write(solo_dev
, SOLO_GPIO_CONFIG_1
, ret
);
61 static void solo_gpio_set(struct solo6010_dev
*solo_dev
, unsigned int value
)
63 solo_reg_write(solo_dev
, SOLO_GPIO_DATA_OUT
,
64 solo_reg_read(solo_dev
, SOLO_GPIO_DATA_OUT
) | value
);
67 static void solo_gpio_clear(struct solo6010_dev
*solo_dev
, unsigned int value
)
69 solo_reg_write(solo_dev
, SOLO_GPIO_DATA_OUT
,
70 solo_reg_read(solo_dev
, SOLO_GPIO_DATA_OUT
) & ~value
);
73 static void solo_gpio_config(struct solo6010_dev
*solo_dev
)
76 solo_gpio_mode(solo_dev
, 0x30, 1);
77 solo_gpio_clear(solo_dev
, 0x30);
79 solo_gpio_set(solo_dev
, 0x30);
82 /* Warning: Don't touch the next line unless you're sure of what
83 * you're doing: first four gpio [0-3] are used for video. */
84 solo_gpio_mode(solo_dev
, 0x0f, 2);
86 /* We use bit 8-15 of SOLO_GPIO_CONFIG_0 for relay purposes */
87 solo_gpio_mode(solo_dev
, 0xff00, 1);
89 /* Initially set relay status to 0 */
90 solo_gpio_clear(solo_dev
, 0xff00);
93 int solo_gpio_init(struct solo6010_dev
*solo_dev
)
95 solo_gpio_config(solo_dev
);
99 void solo_gpio_exit(struct solo6010_dev
*solo_dev
)
101 solo_gpio_clear(solo_dev
, 0x30);
102 solo_gpio_config(solo_dev
);