linux/drivers/staging/solo6x10/solo6010-gpio.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
   3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
   4 *
   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.
   9 *
  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.
  14 *
  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.
  18 */
  19
  20#include <linux/kernel.h>
  21#include <linux/fs.h>
  22#include <asm/uaccess.h>
  23
  24#include "solo6010.h"
  25
  26static void solo_gpio_mode(struct solo6010_dev *solo_dev,
  27                           unsigned int port_mask, unsigned int mode)
  28{
  29        int port;
  30        unsigned int ret;
  31
  32        ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_0);
  33
  34        /* To set gpio */
  35        for (port = 0; port < 16; port++) {
  36                if (!((1 << port) & port_mask))
  37                        continue;
  38
  39                ret &= (~(3 << (port << 1)));
  40                ret |= ((mode & 3) << (port << 1));
  41        }
  42
  43        solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_0, ret);
  44
  45        /* To set extended gpio - sensor */
  46        ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_1);
  47
  48        for (port = 0; port < 16; port++) {
  49                if (!((1 << (port + 16)) & port_mask))
  50                        continue;
  51
  52                if (!mode)
  53                        ret &= ~(1 << port);
  54                else
  55                        ret |= 1 << port;
  56        }
  57
  58        solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_1, ret);
  59}
  60
  61static void solo_gpio_set(struct solo6010_dev *solo_dev, unsigned int value)
  62{
  63        solo_reg_write(solo_dev, SOLO_GPIO_DATA_OUT,
  64                       solo_reg_read(solo_dev, SOLO_GPIO_DATA_OUT) | value);
  65}
  66
  67static void solo_gpio_clear(struct solo6010_dev *solo_dev, unsigned int value)
  68{
  69        solo_reg_write(solo_dev, SOLO_GPIO_DATA_OUT,
  70                       solo_reg_read(solo_dev, SOLO_GPIO_DATA_OUT) & ~value);
  71}
  72
  73static void solo_gpio_config(struct solo6010_dev *solo_dev)
  74{
  75        /* Video reset */
  76        solo_gpio_mode(solo_dev, 0x30, 1);
  77        solo_gpio_clear(solo_dev, 0x30);
  78        udelay(100);
  79        solo_gpio_set(solo_dev, 0x30);
  80        udelay(100);
  81
  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);
  85
  86        /* We use bit 8-15 of SOLO_GPIO_CONFIG_0 for relay purposes */
  87        solo_gpio_mode(solo_dev, 0xff00, 1);
  88
  89        /* Initially set relay status to 0 */
  90        solo_gpio_clear(solo_dev, 0xff00);
  91}
  92
  93int solo_gpio_init(struct solo6010_dev *solo_dev)
  94{
  95        solo_gpio_config(solo_dev);
  96        return 0;
  97}
  98
  99void solo_gpio_exit(struct solo6010_dev *solo_dev)
 100{
 101        solo_gpio_clear(solo_dev, 0x30);
 102        solo_gpio_config(solo_dev);
 103}
 104