0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/gpio.h>
0018 #include <linux/gpio/machine.h>
0019 #include <linux/init.h>
0020 #include <linux/platform_device.h>
0021 #include <linux/spi/spi.h>
0022 #include <linux/spi/spi_gpio.h>
0023 #include <linux/eeprom_93xx46.h>
0024
0025 #define GPIO_EEPROM_CLK 216
0026 #define GPIO_EEPROM_CS 210
0027 #define GPIO_EEPROM_DI 217
0028 #define GPIO_EEPROM_DO 249
0029 #define GPIO_EEPROM_OE 255
0030 #define EE_SPI_BUS_NUM 1
0031
0032 static void digsy_mtc_op_prepare(void *p)
0033 {
0034
0035 gpio_set_value(GPIO_EEPROM_OE, 0);
0036 }
0037
0038 static void digsy_mtc_op_finish(void *p)
0039 {
0040
0041 gpio_set_value(GPIO_EEPROM_OE, 1);
0042 }
0043
0044 struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = {
0045 .flags = EE_ADDR8,
0046 .prepare = digsy_mtc_op_prepare,
0047 .finish = digsy_mtc_op_finish,
0048 };
0049
0050 static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
0051 .num_chipselect = 1,
0052 };
0053
0054 static struct platform_device digsy_mtc_eeprom = {
0055 .name = "spi_gpio",
0056 .id = EE_SPI_BUS_NUM,
0057 .dev = {
0058 .platform_data = &eeprom_spi_gpio_data,
0059 },
0060 };
0061
0062 static struct gpiod_lookup_table eeprom_spi_gpiod_table = {
0063 .dev_id = "spi_gpio",
0064 .table = {
0065 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CLK,
0066 "sck", GPIO_ACTIVE_HIGH),
0067 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DI,
0068 "mosi", GPIO_ACTIVE_HIGH),
0069 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DO,
0070 "miso", GPIO_ACTIVE_HIGH),
0071 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS,
0072 "cs", GPIO_ACTIVE_HIGH),
0073 { },
0074 },
0075 };
0076
0077 static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
0078 {
0079 .modalias = "93xx46",
0080 .max_speed_hz = 1000000,
0081 .bus_num = EE_SPI_BUS_NUM,
0082 .chip_select = 0,
0083 .mode = SPI_MODE_0,
0084 .platform_data = &digsy_mtc_eeprom_data,
0085 },
0086 };
0087
0088 static int __init digsy_mtc_eeprom_devices_init(void)
0089 {
0090 int ret;
0091
0092 ret = gpio_request_one(GPIO_EEPROM_OE, GPIOF_OUT_INIT_HIGH,
0093 "93xx46 EEPROMs OE");
0094 if (ret) {
0095 pr_err("can't request gpio %d\n", GPIO_EEPROM_OE);
0096 return ret;
0097 }
0098 gpiod_add_lookup_table(&eeprom_spi_gpiod_table);
0099 spi_register_board_info(digsy_mtc_eeprom_info,
0100 ARRAY_SIZE(digsy_mtc_eeprom_info));
0101 return platform_device_register(&digsy_mtc_eeprom);
0102 }
0103 device_initcall(digsy_mtc_eeprom_devices_init);