12 #include <linux/device.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
24 #define DIAG_NORMAL 0x03
25 #define DIAG_OVERLOAD 0x02
26 #define DIAG_OPEN 0x01
27 #define DIAG_SHORTGND 0x00
43 unsigned char *buff = st->
tx_buff;
49 buff[1] = gpio_state >> 8;
55 dev_dbg(&st->
us->dev,
"buff %02x,%02x,%02x\n",
56 buff[0], buff[1], buff[2]);
58 return spi_write(st->
us, buff, (st->
nr_gpio == 16) ? 3 : 2);
63 unsigned char *txbuff = st->
tx_buff;
76 spi_message_init(&
msg);
77 spi_message_add_tail(&xfer, &
msg);
82 static unsigned char *decode_fault(
unsigned int fault_code)
105 unsigned char *buff = st->
rx_buff;
106 unsigned long fault = 0;
111 ret = tle62x0_read(st);
112 dev_dbg(dev,
"tle62x0_read() returned %d\n", ret);
118 for (ptr = 0; ptr < (st->
nr_gpio * 2)/8; ptr += 1) {
120 fault |= ((
unsigned long)buff[ptr]);
122 dev_dbg(dev,
"byte %d is %02x\n", ptr, buff[ptr]);
125 for (ptr = 0; ptr < st->
nr_gpio; ptr++) {
126 bp +=
sprintf(bp,
"%s ", decode_fault(fault >> (ptr * 2)));
141 int gpio_num = to_gpio_num(attr);
153 const char *buf,
size_t len)
156 int gpio_num = to_gpio_num(attr);
164 dev_dbg(dev,
"setting gpio %d to %ld\n", gpio_num, val);
180 tle62x0_gpio_show, tle62x0_gpio_store);
182 tle62x0_gpio_show, tle62x0_gpio_store);
184 tle62x0_gpio_show, tle62x0_gpio_store);
186 tle62x0_gpio_show, tle62x0_gpio_store);
188 tle62x0_gpio_show, tle62x0_gpio_store);
190 tle62x0_gpio_show, tle62x0_gpio_store);
192 tle62x0_gpio_show, tle62x0_gpio_store);
194 tle62x0_gpio_show, tle62x0_gpio_store);
196 tle62x0_gpio_show, tle62x0_gpio_store);
198 tle62x0_gpio_show, tle62x0_gpio_store);
200 tle62x0_gpio_show, tle62x0_gpio_store);
202 tle62x0_gpio_show, tle62x0_gpio_store);
204 tle62x0_gpio_show, tle62x0_gpio_store);
206 tle62x0_gpio_show, tle62x0_gpio_store);
208 tle62x0_gpio_show, tle62x0_gpio_store);
210 tle62x0_gpio_show, tle62x0_gpio_store);
213 [0] = &dev_attr_gpio1,
214 [1] = &dev_attr_gpio2,
215 [2] = &dev_attr_gpio3,
216 [3] = &dev_attr_gpio4,
217 [4] = &dev_attr_gpio5,
218 [5] = &dev_attr_gpio6,
219 [6] = &dev_attr_gpio7,
220 [7] = &dev_attr_gpio8,
221 [8] = &dev_attr_gpio9,
222 [9] = &dev_attr_gpio10,
223 [10] = &dev_attr_gpio11,
224 [11] = &dev_attr_gpio12,
225 [12] = &dev_attr_gpio13,
226 [13] = &dev_attr_gpio14,
227 [14] = &dev_attr_gpio15,
228 [15] = &dev_attr_gpio16
235 for (ptr = 0; ptr <
ARRAY_SIZE(gpio_attrs); ptr++) {
236 if (gpio_attrs[ptr] == attr)
250 pdata = spi->
dev.platform_data;
252 dev_err(&spi->
dev,
"no device data specified\n");
258 dev_err(&spi->
dev,
"no memory for device state\n");
270 dev_err(&spi->
dev,
"cannot create status attribute\n");
274 for (ptr = 0; ptr < pdata->
gpio_count; ptr++) {
277 dev_err(&spi->
dev,
"cannot create gpio attribute\n");
283 spi_set_drvdata(spi, st);
302 for (ptr = 0; ptr < st->
nr_gpio; ptr++)
315 .probe = tle62x0_probe,