Commit 199d68d4 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

greybus: start moving the function types into the greybus core

parent caaa8a83
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
greybus-y := core.o gbuf.o
greybus-y := core.o gbuf.o i2c-gb.o

obj-m += greybus.o
obj-m += i2c-gb.o
obj-m += sdio-gb.o
obj-m += gpio-gb.o
obj-m += uart-gb.o
+24 −0
Original line number Diff line number Diff line
@@ -149,5 +149,29 @@ void greybus_deregister(struct greybus_driver *driver)
}
EXPORT_SYMBOL_GPL(greybus_deregister);


static int new_device(struct greybus_device *gdev,
		      const struct greybus_device_id *id)
{
	int retval;

	/* Allocate all of the different "sub device types" for this device */
	retval = gb_i2c_probe(gdev, id);
	return 0;
}


int __init gb_init(void)
{
	return 0;
}

void __exit gb_exit(void)
{
}

module_init(gb_init);
module_exit(gb_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");
+6 −6
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
#include <linux/gpio/driver.h>
#include "greybus.h"

struct gb_gpio {
struct gb_gpio_device {
	struct gpio_chip chip;
	struct greybus_device *gdev;
	struct gpio_chip *gpio;
@@ -27,7 +27,7 @@ static const struct greybus_device_id id_table[] = {

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

	// FIXME - do something there
	return 0;
@@ -53,7 +53,7 @@ static void gpio_set(struct gpio_chip *gpio, unsigned nr, int val)

static int gpio_gb_probe(struct greybus_device *gdev, const struct greybus_device_id *id)
{
	struct gb_gpio *gb_gpio;
	struct gb_gpio_device *gb_gpio;
	struct gpio_chip *gpio;
	struct device *dev = &gdev->dev;
	int retval;
@@ -89,11 +89,11 @@ static int gpio_gb_probe(struct greybus_device *gdev, const struct greybus_devic

static void gpio_gb_disconnect(struct greybus_device *gdev)
{
	struct gb_gpio *gb_gpio;
	struct gb_gpio_device *gb_gpio_dev;

	gb_gpio = greybus_get_drvdata(gdev);
	gb_gpio_dev = greybus_get_drvdata(gdev);

	gpiochip_remove(&gb_gpio->chip);
	gpiochip_remove(&gb_gpio_dev->chip);
}

static struct greybus_driver gpio_gb_driver = {
+29 −0
Original line number Diff line number Diff line
@@ -72,15 +72,44 @@ struct gbuf {
 */
#define GBUF_FREE_BUFFER	BIT(0)	/* Free the transfer buffer with the gbuf */

/* For SP1 hardware, we are going to "hardcode" each device to have all logical
 * blocks in order to be able to address them as one unified "unit".  Then
 * higher up layers will then be able to talk to them as one logical block and
 * properly know how they are hooked together (i.e. which i2c port is on the
 * same module as the gpio pins, etc.)
 *
 * So, put the "private" data structures here in greybus.h and link to them off
 * of the "main" greybus_device structure.
 */

struct gb_i2c_device;
struct gb_gpio_device;
struct gb_sdio_host;
struct gb_tty;
struct gb_usb_device;

struct greybus_device {
	struct device dev;
	struct greybus_descriptor descriptor;
	int num_cport;
	struct cport cport[0];

	struct gb_i2c_device *gb_i2c_dev;
	struct gb_gpio_device *gb_gpio_dev;
	struct gb_sdio_host *gb_sdio_host;
	struct gb_tty *gb_tty;
	struct gb_usb_device *gb_usb_dev;
};
#define to_greybus_device(d) container_of(d, struct greybus_device, dev)

/*
 * Because we are allocating a data structure per "type" in the greybus device,
 * we have static functions for this, not "dynamic" drivers like we really
 * should in the end.
 */
int gb_i2c_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
void gb_i2c_disconnect(struct greybus_device *gdev);


struct gbuf *greybus_alloc_gbuf(struct greybus_device *gdev,
				struct cport *cport,
+25 −22
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
#include <linux/i2c.h>
#include "greybus.h"

struct i2c_gb_data {
struct gb_i2c_device {
	struct i2c_adapter *adapter;
	struct greybus_device *gdev;
};
@@ -32,11 +32,11 @@ static s32 i2c_gb_access(struct i2c_adapter *adap, u16 addr,
			 unsigned short flags, char read_write, u8 command,
			 int size, union i2c_smbus_data *data)
{
	struct i2c_gb_data *i2c_gb_data;
	struct gb_i2c_device *i2c_gb_dev;
	struct greybus_device *gdev;

	i2c_gb_data = i2c_get_adapdata(adap);
	gdev = i2c_gb_data->gdev;
	i2c_gb_dev = i2c_get_adapdata(adap);
	gdev = i2c_gb_dev->gdev;

	// FIXME - do the actual work of sending a i2c message here...
	switch (size) {
@@ -75,22 +75,23 @@ static const struct i2c_algorithm smbus_algorithm = {
	.functionality	= i2c_gb_func,
};

static int i2c_gb_probe(struct greybus_device *gdev, const struct greybus_device_id *id)
int gb_i2c_probe(struct greybus_device *gdev,
		 const struct greybus_device_id *id)
{
	struct i2c_gb_data *i2c_gb_data;
	struct gb_i2c_device *i2c_gb_dev;
	struct i2c_adapter *adapter;
	int retval;

	i2c_gb_data = kzalloc(sizeof(*i2c_gb_data), GFP_KERNEL);
	if (!i2c_gb_data)
	i2c_gb_dev = kzalloc(sizeof(*i2c_gb_dev), GFP_KERNEL);
	if (!i2c_gb_dev)
		return -ENOMEM;
	adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
	if (!adapter) {
		kfree(i2c_gb_data);
		kfree(i2c_gb_dev);
		return -ENOMEM;
	}

	i2c_set_adapdata(adapter, i2c_gb_data);
	i2c_set_adapdata(adapter, i2c_gb_dev);
	adapter->owner = THIS_MODULE;
	adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
	adapter->algo = &smbus_algorithm;
@@ -103,33 +104,35 @@ static int i2c_gb_probe(struct greybus_device *gdev, const struct greybus_device
		goto error;
	}

	i2c_gb_data->gdev = gdev;
	i2c_gb_data->adapter = adapter;
	i2c_gb_dev->gdev = gdev;
	i2c_gb_dev->adapter = adapter;

	greybus_set_drvdata(gdev, i2c_gb_data);
	greybus_set_drvdata(gdev, i2c_gb_dev);
	return 0;
error:
	kfree(adapter);
	kfree(i2c_gb_data);
	kfree(i2c_gb_dev);
	return retval;
}

static void i2c_gb_disconnect(struct greybus_device *gdev)
void gb_i2c_disconnect(struct greybus_device *gdev)
{
	struct i2c_gb_data *i2c_gb_data;
	struct gb_i2c_device *i2c_gb_dev;

	i2c_gb_data = greybus_get_drvdata(gdev);
	i2c_del_adapter(i2c_gb_data->adapter);
	kfree(i2c_gb_data->adapter);
	kfree(i2c_gb_data);
	i2c_gb_dev = greybus_get_drvdata(gdev);
	i2c_del_adapter(i2c_gb_dev->adapter);
	kfree(i2c_gb_dev->adapter);
	kfree(i2c_gb_dev);
}

#if 0
static struct greybus_driver i2c_gb_driver = {
	.probe =	i2c_gb_probe,
	.disconnect =	i2c_gb_disconnect,
	.probe =	gb_i2c_probe,
	.disconnect =	gb_i2c_disconnect,
	.id_table =	id_table,
};

module_greybus_driver(i2c_gb_driver);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");
#endif
Loading