3 @@ -71,6 +71,8 @@ drv_generic_i2c.c \
7 +drv_generic_spidev.c \
8 +drv_generic_spidev.h \
13 +++ b/drv_generic_spidev.c
18 + * generic driver helper for displays connected via SPI bus
20 + * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
22 + * This file is part of LCD4Linux.
24 + * LCD4Linux is free software; you can redistribute it and/or modify
25 + * it under the terms of the GNU General Public License as published by
26 + * the Free Software Foundation; either version 2, or (at your option)
27 + * any later version.
29 + * LCD4Linux is distributed in the hope that it will be useful,
30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 + * GNU General Public License for more details.
34 + * You should have received a copy of the GNU General Public License
35 + * along with this program; if not, write to the Free Software
36 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
48 +#include <sys/types.h>
49 +#include <sys/ioctl.h>
54 +#include "drv_generic_spidev.h"
56 +static char *generic_spidev_section = "";
57 +static char *generic_spidev_driver = "";
58 +static int generic_spidev_fd;
60 +int drv_generic_spidev_open(const char *section, const char *driver)
66 + generic_spidev_section = (char *) section;
67 + generic_spidev_driver = (char *) driver;
69 + spidev = cfg_get(generic_spidev_section, "Port", NULL);
71 + info("%s: initializing SPI device %s", generic_spidev_driver, spidev);
72 + generic_spidev_fd = open(spidev, O_WRONLY);
73 + if (generic_spidev_fd < 0) {
74 + error("%s: unable to open SPI device %s!\n", generic_spidev_driver, spidev);
85 +int drv_generic_spidev_close(void)
87 + close(generic_spidev_fd);
91 +int drv_generic_spidev_transfer(const int count, struct spi_ioc_transfer *tr)
95 + ret = ioctl(generic_spidev_fd, SPI_IOC_MESSAGE(count), tr);
97 + error("%s: can't send SPI message! (%s)\n",
98 + generic_spidev_driver, strerror(errno));
105 +++ b/drv_generic_spidev.h
110 + * generic driver helper for displays connected via SPI bus
112 + * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
113 + * Copyright (C) 2012 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
115 + * This file is part of LCD4Linux.
117 + * LCD4Linux is free software; you can redistribute it and/or modify
118 + * it under the terms of the GNU General Public License as published by
119 + * the Free Software Foundation; either version 2, or (at your option)
120 + * any later version.
122 + * LCD4Linux is distributed in the hope that it will be useful,
123 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
124 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
125 + * GNU General Public License for more details.
127 + * You should have received a copy of the GNU General Public License
128 + * along with this program; if not, write to the Free Software
129 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
135 + * exported fuctions:
137 + * int drv_generic_spidev_open (const char *section, const char *driver)
138 + * reads 'Port' entry from config and opens
140 + * returns 0 if ok, -1 on failure
142 + * int drv_generic_spidev_close (void)
143 + * closes SPI device
144 + * returns 0 if ok, -1 on failure
146 + * void drv_generic_spidev_transfer (int count, struct spi_ioc_transfer *tr)
147 + * transfer data to/from the SPI device
151 +#ifndef _DRV_GENERIC_SPIDEV_H_
152 +#define _DRV_GENERIC_SPIDEV_H_
154 +#include <linux/spi/spidev.h>
156 +int drv_generic_spidev_open(const char *section, const char *driver);
157 +int drv_generic_spidev_close(void);
158 +int drv_generic_spidev_transfer(const int count, struct spi_ioc_transfer *tr);
160 +#endif /* _DRV_GENERIC_SPIDEV_H_ */
163 @@ -301,6 +301,7 @@ PARPORT="no"
171 @@ -940,6 +941,12 @@ if test "$LIBJPEG" = "yes"; then
172 DRVLIBS="$DRVLIBS -ljpeg"
175 +# generic spidev driver
176 +if test "$SPIDEV" = "yes"; then
177 + DRIVERS="$DRIVERS drv_generic_spidev.o"
178 + AC_DEFINE(WITH_SPIDEV, 1, [SPIDEV driver])
182 if test "$LIBUSB" = "yes"; then
183 DRVLIBS="$DRVLIBS -lusb"
186 @@ -118,6 +118,9 @@ AC_ARG_WITH(outb,
188 AC_CHECK_HEADERS([asm/io.h] [linux/parport.h linux/ppdev.h], [has_parport="true"], [has_parport="false"])
191 +AC_CHECK_HEADERS([linux/spi/spidev.h], [has_spidev="true"], [has_spidev="false"])