digsy_mtc_eeprom.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * EEPROMs access control driver for display configuration EEPROMs
  3. * on DigsyMTC board.
  4. *
  5. * (C) 2011 DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * FIXME: this driver is used on a device-tree probed platform: it
  12. * should be defined as a bit-banged SPI device and probed from the device
  13. * tree and not like this with static grabbing of a few numbered GPIO
  14. * lines at random.
  15. *
  16. * Add proper SPI and EEPROM in arch/powerpc/boot/dts/digsy_mtc.dts
  17. * and delete this driver.
  18. */
  19. #include <linux/gpio.h>
  20. #include <linux/gpio/machine.h>
  21. #include <linux/init.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/spi_gpio.h>
  25. #include <linux/eeprom_93xx46.h>
  26. #define GPIO_EEPROM_CLK 216
  27. #define GPIO_EEPROM_CS 210
  28. #define GPIO_EEPROM_DI 217
  29. #define GPIO_EEPROM_DO 249
  30. #define GPIO_EEPROM_OE 255
  31. #define EE_SPI_BUS_NUM 1
  32. static void digsy_mtc_op_prepare(void *p)
  33. {
  34. /* enable */
  35. gpio_set_value(GPIO_EEPROM_OE, 0);
  36. }
  37. static void digsy_mtc_op_finish(void *p)
  38. {
  39. /* disable */
  40. gpio_set_value(GPIO_EEPROM_OE, 1);
  41. }
  42. struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = {
  43. .flags = EE_ADDR8,
  44. .prepare = digsy_mtc_op_prepare,
  45. .finish = digsy_mtc_op_finish,
  46. };
  47. static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
  48. .num_chipselect = 1,
  49. };
  50. static struct platform_device digsy_mtc_eeprom = {
  51. .name = "spi_gpio",
  52. .id = EE_SPI_BUS_NUM,
  53. .dev = {
  54. .platform_data = &eeprom_spi_gpio_data,
  55. },
  56. };
  57. static struct gpiod_lookup_table eeprom_spi_gpiod_table = {
  58. .dev_id = "spi_gpio",
  59. .table = {
  60. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CLK,
  61. "sck", GPIO_ACTIVE_HIGH),
  62. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DI,
  63. "mosi", GPIO_ACTIVE_HIGH),
  64. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DO,
  65. "miso", GPIO_ACTIVE_HIGH),
  66. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS,
  67. "cs", GPIO_ACTIVE_HIGH),
  68. { },
  69. },
  70. };
  71. static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
  72. {
  73. .modalias = "93xx46",
  74. .max_speed_hz = 1000000,
  75. .bus_num = EE_SPI_BUS_NUM,
  76. .chip_select = 0,
  77. .mode = SPI_MODE_0,
  78. .platform_data = &digsy_mtc_eeprom_data,
  79. },
  80. };
  81. static int __init digsy_mtc_eeprom_devices_init(void)
  82. {
  83. int ret;
  84. ret = gpio_request_one(GPIO_EEPROM_OE, GPIOF_OUT_INIT_HIGH,
  85. "93xx46 EEPROMs OE");
  86. if (ret) {
  87. pr_err("can't request gpio %d\n", GPIO_EEPROM_OE);
  88. return ret;
  89. }
  90. gpiod_add_lookup_table(&eeprom_spi_gpiod_table);
  91. spi_register_board_info(digsy_mtc_eeprom_info,
  92. ARRAY_SIZE(digsy_mtc_eeprom_info));
  93. return platform_device_register(&digsy_mtc_eeprom);
  94. }
  95. device_initcall(digsy_mtc_eeprom_devices_init);