digsy_mtc_eeprom.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include <linux/gpio.h>
  12. #include <linux/init.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/spi/spi.h>
  15. #include <linux/spi/spi_gpio.h>
  16. #include <linux/eeprom_93xx46.h>
  17. #define GPIO_EEPROM_CLK 216
  18. #define GPIO_EEPROM_CS 210
  19. #define GPIO_EEPROM_DI 217
  20. #define GPIO_EEPROM_DO 249
  21. #define GPIO_EEPROM_OE 255
  22. #define EE_SPI_BUS_NUM 1
  23. static void digsy_mtc_op_prepare(void *p)
  24. {
  25. /* enable */
  26. gpio_set_value(GPIO_EEPROM_OE, 0);
  27. }
  28. static void digsy_mtc_op_finish(void *p)
  29. {
  30. /* disable */
  31. gpio_set_value(GPIO_EEPROM_OE, 1);
  32. }
  33. struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = {
  34. .flags = EE_ADDR8,
  35. .prepare = digsy_mtc_op_prepare,
  36. .finish = digsy_mtc_op_finish,
  37. };
  38. static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
  39. .sck = GPIO_EEPROM_CLK,
  40. .mosi = GPIO_EEPROM_DI,
  41. .miso = GPIO_EEPROM_DO,
  42. .num_chipselect = 1,
  43. };
  44. static struct platform_device digsy_mtc_eeprom = {
  45. .name = "spi_gpio",
  46. .id = EE_SPI_BUS_NUM,
  47. .dev = {
  48. .platform_data = &eeprom_spi_gpio_data,
  49. },
  50. };
  51. static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
  52. {
  53. .modalias = "93xx46",
  54. .max_speed_hz = 1000000,
  55. .bus_num = EE_SPI_BUS_NUM,
  56. .chip_select = 0,
  57. .mode = SPI_MODE_0,
  58. .controller_data = (void *)GPIO_EEPROM_CS,
  59. .platform_data = &digsy_mtc_eeprom_data,
  60. },
  61. };
  62. static int __init digsy_mtc_eeprom_devices_init(void)
  63. {
  64. int ret;
  65. ret = gpio_request_one(GPIO_EEPROM_OE, GPIOF_OUT_INIT_HIGH,
  66. "93xx46 EEPROMs OE");
  67. if (ret) {
  68. pr_err("can't request gpio %d\n", GPIO_EEPROM_OE);
  69. return ret;
  70. }
  71. spi_register_board_info(digsy_mtc_eeprom_info,
  72. ARRAY_SIZE(digsy_mtc_eeprom_info));
  73. return platform_device_register(&digsy_mtc_eeprom);
  74. }
  75. device_initcall(digsy_mtc_eeprom_devices_init);