/*
 * Module-related material for wr-nic: load and unload
 *
 * Copyright (C) 2010 CERN (www.cern.ch)
 * Author: Alessandro Rubini <rubini@gnudd.com>
 * Partly from previous work by Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
 * Partly from previous work by  Emilio G. Cota <cota@braap.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/platform_data/i2c-ocores.h>

#include "module_i2c.h"


/**************************************************/

static struct resource ocores_resources[] = {
	[0] = {
		.start	= 0x400054000,
		.end	= 0x400054000 + 0x20,
		.flags	= IORESOURCE_MEM,
	},
    {}
};

#if 1
/* optional board info */
struct i2c_board_info ocores_i2c_board_info[] = {
	{
		I2C_BOARD_INFO("sfp_adapter", 0xA0),
		//.platform_data = &tsc2003_platform_data,
		//.irq = TSC_IRQ
	},
};
#endif

static struct ocores_i2c_platform_data myi2c_data = {
	.reg_shift		= 2,		/* shift regs by 2 (multiply by 4) to match byte address to word address */
    .reg_io_width	= 4,        /* AXI - WB registers are 32 bytes */
	.clock_khz		= 62500,	/* input clock of 62.5MHz */
	.bus_khz		= 100,      /* I2C bus runs @ 100kHz for now */
	.big_endian		= false,
	//.devices	= ocores_i2c_board_info, /* optional table of devices */
	//.num_devices	= ARRAY_SIZE(ocores_i2c_board_info), /* table size */
};

static void module_i2c_release(struct device *dev)
{
	/* nothing to do, but mandatory function */
	pr_debug("%s\n", __func__);
    printk("module_i2c_release()\n");
}

static struct platform_device module_i2c_dev = {
	.name			= "ocores-i2c",
	//.name			= "i2c-ohwr",
	.dev = {
		.platform_data	= &myi2c_data,
        .release = module_i2c_release,
	},
	.num_resources		= ARRAY_SIZE(ocores_resources),
	.resource		= ocores_resources,
};


/*
 * Module init and exit stuff. Here we register the platform data
 * as well, but the driver itself is in device.c
 */
int __init module_i2c_init(void)
{
    printk("module_i2c_init()\n");
	platform_device_register(&module_i2c_dev);
	platform_driver_register(&sfp_i2c_driver);
    return 0;
}

void __exit module_i2c_exit(void)
{
    printk("module_i2c_exit()\n");
	platform_driver_unregister(&sfp_i2c_driver);
	platform_device_unregister(&module_i2c_dev);
	
    return;
}

module_init(module_i2c_init);
module_exit(module_i2c_exit);

MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:module_i2c");

