tifm.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * tifm.h - TI FlashMedia driver
  3. *
  4. * Copyright (C) 2006 Alex Dubov <oakad@yahoo.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #ifndef _TIFM_H
  12. #define _TIFM_H
  13. #include <linux/spinlock.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/wait.h>
  16. #include <linux/delay.h>
  17. #include <linux/pci.h>
  18. #include <linux/kthread.h>
  19. /* Host registers (relative to pci base address): */
  20. enum {
  21. FM_SET_INTERRUPT_ENABLE = 0x008,
  22. FM_CLEAR_INTERRUPT_ENABLE = 0x00c,
  23. FM_INTERRUPT_STATUS = 0x014 };
  24. /* Socket registers (relative to socket base address): */
  25. enum {
  26. SOCK_CONTROL = 0x004,
  27. SOCK_PRESENT_STATE = 0x008,
  28. SOCK_DMA_ADDRESS = 0x00c,
  29. SOCK_DMA_CONTROL = 0x010,
  30. SOCK_DMA_FIFO_INT_ENABLE_SET = 0x014,
  31. SOCK_DMA_FIFO_INT_ENABLE_CLEAR = 0x018,
  32. SOCK_DMA_FIFO_STATUS = 0x020,
  33. SOCK_FIFO_CONTROL = 0x024,
  34. SOCK_FIFO_PAGE_SIZE = 0x028,
  35. SOCK_MMCSD_COMMAND = 0x104,
  36. SOCK_MMCSD_ARG_LOW = 0x108,
  37. SOCK_MMCSD_ARG_HIGH = 0x10c,
  38. SOCK_MMCSD_CONFIG = 0x110,
  39. SOCK_MMCSD_STATUS = 0x114,
  40. SOCK_MMCSD_INT_ENABLE = 0x118,
  41. SOCK_MMCSD_COMMAND_TO = 0x11c,
  42. SOCK_MMCSD_DATA_TO = 0x120,
  43. SOCK_MMCSD_DATA = 0x124,
  44. SOCK_MMCSD_BLOCK_LEN = 0x128,
  45. SOCK_MMCSD_NUM_BLOCKS = 0x12c,
  46. SOCK_MMCSD_BUFFER_CONFIG = 0x130,
  47. SOCK_MMCSD_SPI_CONFIG = 0x134,
  48. SOCK_MMCSD_SDIO_MODE_CONFIG = 0x138,
  49. SOCK_MMCSD_RESPONSE = 0x144,
  50. SOCK_MMCSD_SDIO_SR = 0x164,
  51. SOCK_MMCSD_SYSTEM_CONTROL = 0x168,
  52. SOCK_MMCSD_SYSTEM_STATUS = 0x16c,
  53. SOCK_MS_COMMAND = 0x184,
  54. SOCK_MS_DATA = 0x188,
  55. SOCK_MS_STATUS = 0x18c,
  56. SOCK_MS_SYSTEM = 0x190,
  57. SOCK_FIFO_ACCESS = 0x200 };
  58. #define TIFM_IRQ_ENABLE 0x80000000
  59. #define TIFM_IRQ_SOCKMASK(x) (x)
  60. #define TIFM_IRQ_CARDMASK(x) ((x) << 8)
  61. #define TIFM_IRQ_FIFOMASK(x) ((x) << 16)
  62. #define TIFM_IRQ_SETALL 0xffffffff
  63. #define TIFM_CTRL_LED 0x00000040
  64. #define TIFM_CTRL_FAST_CLK 0x00000100
  65. #define TIFM_SOCK_STATE_OCCUPIED 0x00000008
  66. #define TIFM_SOCK_STATE_POWERED 0x00000080
  67. #define TIFM_FIFO_ENABLE 0x00000001 /* Meaning of this constant is unverified */
  68. #define TIFM_FIFO_INT_SETALL 0x0000ffff
  69. #define TIFM_FIFO_INTMASK 0x00000005 /* Meaning of this constant is unverified */
  70. #define TIFM_DMA_RESET 0x00000002 /* Meaning of this constant is unverified */
  71. #define TIFM_DMA_TX 0x00008000 /* Meaning of this constant is unverified */
  72. #define TIFM_DMA_EN 0x00000001 /* Meaning of this constant is unverified */
  73. typedef enum {FM_NULL = 0, FM_XD = 0x01, FM_MS = 0x02, FM_SD = 0x03} tifm_media_id;
  74. struct tifm_driver;
  75. struct tifm_dev {
  76. char __iomem *addr;
  77. spinlock_t lock;
  78. tifm_media_id media_id;
  79. unsigned int socket_id;
  80. void (*signal_irq)(struct tifm_dev *sock,
  81. unsigned int sock_irq_status);
  82. struct tifm_driver *drv;
  83. struct device dev;
  84. };
  85. struct tifm_driver {
  86. tifm_media_id *id_table;
  87. int (*probe)(struct tifm_dev *dev);
  88. void (*remove)(struct tifm_dev *dev);
  89. int (*suspend)(struct tifm_dev *dev,
  90. pm_message_t state);
  91. int (*resume)(struct tifm_dev *dev);
  92. struct device_driver driver;
  93. };
  94. struct tifm_adapter {
  95. char __iomem *addr;
  96. spinlock_t lock;
  97. unsigned int irq_status;
  98. unsigned int socket_change_set;
  99. wait_queue_head_t change_set_notify;
  100. unsigned int id;
  101. unsigned int num_sockets;
  102. struct tifm_dev **sockets;
  103. struct task_struct *media_switcher;
  104. struct class_device cdev;
  105. struct device *dev;
  106. void (*eject)(struct tifm_adapter *fm, struct tifm_dev *sock);
  107. };
  108. struct tifm_adapter *tifm_alloc_adapter(void);
  109. void tifm_free_device(struct device *dev);
  110. void tifm_free_adapter(struct tifm_adapter *fm);
  111. int tifm_add_adapter(struct tifm_adapter *fm, int (*mediathreadfn)(void *data));
  112. void tifm_remove_adapter(struct tifm_adapter *fm);
  113. struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm);
  114. int tifm_register_driver(struct tifm_driver *drv);
  115. void tifm_unregister_driver(struct tifm_driver *drv);
  116. void tifm_eject(struct tifm_dev *sock);
  117. int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
  118. int direction);
  119. void tifm_unmap_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
  120. int direction);
  121. static inline void *tifm_get_drvdata(struct tifm_dev *dev)
  122. {
  123. return dev_get_drvdata(&dev->dev);
  124. }
  125. static inline void tifm_set_drvdata(struct tifm_dev *dev, void *data)
  126. {
  127. dev_set_drvdata(&dev->dev, data);
  128. }
  129. struct tifm_device_id {
  130. tifm_media_id media_id;
  131. };
  132. #endif