summaryrefslogtreecommitdiff
path: root/drivers/staging/greybus/gpio-gb.c
blob: 485480dc7233fad39778509c56a5b83bc0e1daea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * GPIO Greybus driver.
 *
 * Copyright 2014 Google Inc.
 *
 * Released under the GPLv2 only.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include "greybus.h"

struct gb_gpio_device {
	struct gpio_chip chip;
	struct greybus_device *gdev;
	struct gpio_chip *gpio;
	// FIXME - some lock?
};

static const struct greybus_module_id id_table[] = {
	{ GREYBUS_DEVICE(0x44, 0x44) },	/* make shit up */
	{ },	/* terminating NULL entry */
};

static int direction_input(struct gpio_chip *gpio, unsigned nr)
{
	//struct gb_gpio_device *gb_gpio_dev = container_of(gpio, struct gb_gpio_device, chip);

	// FIXME - do something there
	return 0;
}

static int direction_output(struct gpio_chip *gpio, unsigned nr, int val)
{
	// FIXME - do something there
	return 0;
}

static int gpio_get(struct gpio_chip *gpio, unsigned nr)
{
	// FIXME - do something there
	return 0;
}

static void gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
{
	// FIXME - do something there
}

int gb_gpio_probe(struct greybus_device *gdev,
		  const struct greybus_module_id *id)
{
	struct gb_gpio_device *gb_gpio;
	struct gpio_chip *gpio;
	struct device *dev = &gdev->dev;
	int retval;

	gb_gpio = kzalloc(sizeof(*gb_gpio), GFP_KERNEL);
	if (!gb_gpio)
		return -ENOMEM;
	gb_gpio->gdev = gdev;

	gpio = &gb_gpio->chip;

	gpio->label = "greybus_gpio";
	gpio->owner = THIS_MODULE;
	gpio->direction_input = direction_input;
	gpio->direction_output = direction_output;
	gpio->get = gpio_get;
	gpio->set = gpio_set;
	gpio->dbg_show = NULL;
	gpio->base = 0;			// FIXME!!!
	gpio->ngpio = 42;		// FIXME!!!
	gpio->can_sleep = false;	// FIXME!!!

	gdev->gb_gpio_dev = gb_gpio;

	retval = gpiochip_add(gpio);
	if (retval) {
		dev_err(dev, "Failed to register GPIO\n");
		return retval;
	}

	return 0;
}

void gb_gpio_disconnect(struct greybus_device *gdev)
{
	struct gb_gpio_device *gb_gpio_dev;
	int retval;

	gb_gpio_dev = gdev->gb_gpio_dev;

	retval = gpiochip_remove(&gb_gpio_dev->chip);
	kfree(gb_gpio_dev);
}

#if 0
static struct greybus_driver gpio_gb_driver = {
	.probe =	gb_gpio_probe,
	.disconnect =	gb_gpio_disconnect,
	.id_table =	id_table,
};

module_greybus_driver(gpio_gb_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Greybus GPIO driver");
MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");
#endif