digsy_mtc_eeprom.c 2.6 KB

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