digsy_mtc_eeprom.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/machine.h>
  17. #include <linux/init.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/property.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/spi/spi_gpio.h>
  22. #define GPIO_EEPROM_CLK 216
  23. #define GPIO_EEPROM_CS 210
  24. #define GPIO_EEPROM_DI 217
  25. #define GPIO_EEPROM_DO 249
  26. #define GPIO_EEPROM_OE 255
  27. #define EE_SPI_BUS_NUM 1
  28. static const struct property_entry digsy_mtc_spi_properties[] = {
  29. PROPERTY_ENTRY_U32("data-size", 8),
  30. { }
  31. };
  32. static const struct software_node digsy_mtc_spi_node = {
  33. .properties = digsy_mtc_spi_properties,
  34. };
  35. static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
  36. .num_chipselect = 1,
  37. };
  38. static struct platform_device digsy_mtc_eeprom = {
  39. .name = "spi_gpio",
  40. .id = EE_SPI_BUS_NUM,
  41. .dev = {
  42. .platform_data = &eeprom_spi_gpio_data,
  43. },
  44. };
  45. static struct gpiod_lookup_table eeprom_spi_gpiod_table = {
  46. .dev_id = "spi_gpio.1",
  47. .table = {
  48. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CLK,
  49. "sck", GPIO_ACTIVE_HIGH),
  50. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DI,
  51. "mosi", GPIO_ACTIVE_HIGH),
  52. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DO,
  53. "miso", GPIO_ACTIVE_HIGH),
  54. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS,
  55. "cs", GPIO_ACTIVE_HIGH),
  56. GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_OE,
  57. "select", GPIO_ACTIVE_LOW),
  58. { },
  59. },
  60. };
  61. static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
  62. {
  63. .modalias = "eeprom-93xx46",
  64. .max_speed_hz = 1000000,
  65. .bus_num = EE_SPI_BUS_NUM,
  66. .chip_select = 0,
  67. .mode = SPI_MODE_0,
  68. },
  69. };
  70. static int __init digsy_mtc_eeprom_devices_init(void)
  71. {
  72. int ret;
  73. gpiod_add_lookup_table(&eeprom_spi_gpiod_table);
  74. spi_register_board_info(digsy_mtc_eeprom_info,
  75. ARRAY_SIZE(digsy_mtc_eeprom_info));
  76. ret = device_add_software_node(&digsy_mtc_eeprom.dev, &digsy_mtc_spi_node);
  77. if (ret)
  78. return ret;
  79. ret = platform_device_register(&digsy_mtc_eeprom);
  80. if (ret)
  81. device_remove_software_node(&digsy_mtc_eeprom.dev);
  82. return ret;
  83. }
  84. device_initcall(digsy_mtc_eeprom_devices_init);