9dcf1cb0361c763de12d0b6825b5bf622cc284c0
[openwrt/svn-archive/packages.git] / utils / lcd4linux / patches / 170-add-generic-spidev-driver.patch
1 --- a/Makefile.am
2 +++ b/Makefile.am
3 @@ -71,6 +71,8 @@ drv_generic_i2c.c \
4 drv_generic_i2c.h \
5 drv_generic_keypad.c \
6 drv_generic_keypad.h \
7 +drv_generic_spidev.c \
8 +drv_generic_spidev.h \
9 drv_ASTUSB.c \
10 drv_BeckmannEgle.c \
11 drv_BWCT.c \
12 --- /dev/null
13 +++ b/drv_generic_spidev.c
14 @@ -0,0 +1,89 @@
15 +/* $Id$
16 + * $URL$
17 + *
18 + * generic driver helper for displays connected via SPI bus
19 + *
20 + * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
21 + *
22 + * This file is part of LCD4Linux.
23 + *
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.
28 + *
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.
33 + *
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.
37 + *
38 + */
39 +
40 +#include "config.h"
41 +
42 +#include <stdlib.h>
43 +#include <stdio.h>
44 +#include <string.h>
45 +#include <errno.h>
46 +#include <unistd.h>
47 +#include <fcntl.h>
48 +#include <sys/types.h>
49 +#include <sys/ioctl.h>
50 +
51 +#include "debug.h"
52 +#include "qprintf.h"
53 +#include "cfg.h"
54 +#include "drv_generic_spidev.h"
55 +
56 +static char *generic_spidev_section = "";
57 +static char *generic_spidev_driver = "";
58 +static int generic_spidev_fd;
59 +
60 +int drv_generic_spidev_open(const char *section, const char *driver)
61 +{
62 + char *spidev;
63 +
64 + udelay_init();
65 +
66 + generic_spidev_section = (char *) section;
67 + generic_spidev_driver = (char *) driver;
68 +
69 + spidev = cfg_get(generic_spidev_section, "Port", NULL);
70 +
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);
75 + goto exit_error;
76 + }
77 +
78 + return 0;
79 +
80 + exit_error:
81 + free(spidev);
82 + return -1;
83 +}
84 +
85 +int drv_generic_spidev_close(void)
86 +{
87 + close(generic_spidev_fd);
88 + return 0;
89 +}
90 +
91 +int drv_generic_spidev_transfer(const int count, struct spi_ioc_transfer *tr)
92 +{
93 + int ret;
94 +
95 + ret = ioctl(generic_spidev_fd, SPI_IOC_MESSAGE(count), tr);
96 + if (ret < count) {
97 + error("%s: can't send SPI message! (%s)\n",
98 + generic_spidev_driver, strerror(errno));
99 + return -1;
100 + }
101 +
102 + return 0;
103 +}
104 --- /dev/null
105 +++ b/drv_generic_spidev.h
106 @@ -0,0 +1,54 @@
107 +/* $Id$
108 + * $URL$
109 + *
110 + * generic driver helper for displays connected via SPI bus
111 + *
112 + * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
113 + * Copyright (C) 2012 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
114 + *
115 + * This file is part of LCD4Linux.
116 + *
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.
121 + *
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.
126 + *
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.
130 + *
131 + */
132 +
133 +/*
134 + *
135 + * exported fuctions:
136 + *
137 + * int drv_generic_spidev_open (const char *section, const char *driver)
138 + * reads 'Port' entry from config and opens
139 + * the SPI device
140 + * returns 0 if ok, -1 on failure
141 + *
142 + * int drv_generic_spidev_close (void)
143 + * closes SPI device
144 + * returns 0 if ok, -1 on failure
145 + *
146 + * void drv_generic_spidev_transfer (int count, struct spi_ioc_transfer *tr)
147 + * transfer data to/from the SPI device
148 + *
149 + */
150 +
151 +#ifndef _DRV_GENERIC_SPIDEV_H_
152 +#define _DRV_GENERIC_SPIDEV_H_
153 +
154 +#include <linux/spi/spidev.h>
155 +
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);
159 +
160 +#endif /* _DRV_GENERIC_SPIDEV_H_ */
161 --- a/drivers.m4
162 +++ b/drivers.m4
163 @@ -301,6 +301,7 @@ PARPORT="no"
164 SERIAL="no"
165 I2C="no"
166 KEYPAD="no"
167 +SPIDEV="no"
168
169 # generic libraries
170 LIBUSB="no"
171 @@ -940,6 +941,12 @@ if test "$LIBJPEG" = "yes"; then
172 DRVLIBS="$DRVLIBS -ljpeg"
173 fi
174
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])
179 +fi
180 +
181 # libusb
182 if test "$LIBUSB" = "yes"; then
183 DRVLIBS="$DRVLIBS -lusb"
184 --- a/configure.in
185 +++ b/configure.in
186 @@ -118,6 +118,9 @@ AC_ARG_WITH(outb,
187
188 AC_CHECK_HEADERS([asm/io.h] [linux/parport.h linux/ppdev.h], [has_parport="true"], [has_parport="false"])
189
190 +# check for spidev
191 +AC_CHECK_HEADERS([linux/spi/spidev.h], [has_spidev="true"], [has_spidev="false"])
192 +
193 # drivers
194 sinclude(drivers.m4)
195