10
10
#include <linux/module.h>
11
11
#include <linux/delay.h>
12
12
#include <linux/i2c.h>
13
+ #include <linux/gpio/driver.h>
13
14
#include <linux/spi/spi.h>
14
15
#include <asm/unaligned.h>
15
16
26
27
27
28
#define SPI_XCOMM_CMD_UPDATE_CONFIG 0x03
28
29
#define SPI_XCOMM_CMD_WRITE 0x04
30
+ #define SPI_XCOMM_CMD_GPIO_SET 0x05
29
31
30
32
#define SPI_XCOMM_CLOCK 48000000
31
33
32
34
struct spi_xcomm {
33
35
struct i2c_client * i2c ;
34
36
37
+ struct gpio_chip gc ;
38
+
35
39
uint16_t settings ;
36
40
uint16_t chipselect ;
37
41
@@ -40,6 +44,42 @@ struct spi_xcomm {
40
44
uint8_t buf [63 ];
41
45
};
42
46
47
+ static void spi_xcomm_gpio_set_value (struct gpio_chip * chip ,
48
+ unsigned int offset , int val )
49
+ {
50
+ struct spi_xcomm * spi_xcomm = gpiochip_get_data (chip );
51
+ unsigned char buf [2 ];
52
+
53
+ buf [0 ] = SPI_XCOMM_CMD_GPIO_SET ;
54
+ buf [1 ] = !!val ;
55
+
56
+ i2c_master_send (spi_xcomm -> i2c , buf , 2 );
57
+ }
58
+
59
+ static int spi_xcomm_gpio_get_direction (struct gpio_chip * chip ,
60
+ unsigned int offset )
61
+ {
62
+ return GPIO_LINE_DIRECTION_OUT ;
63
+ }
64
+
65
+ static int spi_xcomm_gpio_add (struct spi_xcomm * spi_xcomm )
66
+ {
67
+ struct device * dev = & spi_xcomm -> i2c -> dev ;
68
+
69
+ if (!IS_ENABLED (CONFIG_GPIOLIB ))
70
+ return 0 ;
71
+
72
+ spi_xcomm -> gc .get_direction = spi_xcomm_gpio_get_direction ;
73
+ spi_xcomm -> gc .set = spi_xcomm_gpio_set_value ;
74
+ spi_xcomm -> gc .can_sleep = 1 ;
75
+ spi_xcomm -> gc .base = -1 ;
76
+ spi_xcomm -> gc .ngpio = 1 ;
77
+ spi_xcomm -> gc .label = spi_xcomm -> i2c -> name ;
78
+ spi_xcomm -> gc .owner = THIS_MODULE ;
79
+
80
+ return devm_gpiochip_add_data (dev , & spi_xcomm -> gc , spi_xcomm );
81
+ }
82
+
43
83
static int spi_xcomm_sync_config (struct spi_xcomm * spi_xcomm , unsigned int len )
44
84
{
45
85
uint16_t settings ;
@@ -227,7 +267,7 @@ static int spi_xcomm_probe(struct i2c_client *i2c)
227
267
if (ret < 0 )
228
268
spi_controller_put (host );
229
269
230
- return ret ;
270
+ return spi_xcomm_gpio_add ( spi_xcomm ) ;
231
271
}
232
272
233
273
static const struct i2c_device_id spi_xcomm_ids [] = {
0 commit comments