Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 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 | |
| 12 | #ifndef _TIFM_H |
| 13 | #define _TIFM_H |
| 14 | |
| 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/wait.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/pci.h> |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame^] | 20 | #include <linux/kthread.h> |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 21 | |
| 22 | /* Host registers (relative to pci base address): */ |
| 23 | enum { |
| 24 | FM_SET_INTERRUPT_ENABLE = 0x008, |
| 25 | FM_CLEAR_INTERRUPT_ENABLE = 0x00c, |
| 26 | FM_INTERRUPT_STATUS = 0x014 }; |
| 27 | |
| 28 | /* Socket registers (relative to socket base address): */ |
| 29 | enum { |
| 30 | SOCK_CONTROL = 0x004, |
| 31 | SOCK_PRESENT_STATE = 0x008, |
| 32 | SOCK_DMA_ADDRESS = 0x00c, |
| 33 | SOCK_DMA_CONTROL = 0x010, |
| 34 | SOCK_DMA_FIFO_INT_ENABLE_SET = 0x014, |
| 35 | SOCK_DMA_FIFO_INT_ENABLE_CLEAR = 0x018, |
| 36 | SOCK_DMA_FIFO_STATUS = 0x020, |
| 37 | SOCK_FIFO_CONTROL = 0x024, |
| 38 | SOCK_FIFO_PAGE_SIZE = 0x028, |
| 39 | SOCK_MMCSD_COMMAND = 0x104, |
| 40 | SOCK_MMCSD_ARG_LOW = 0x108, |
| 41 | SOCK_MMCSD_ARG_HIGH = 0x10c, |
| 42 | SOCK_MMCSD_CONFIG = 0x110, |
| 43 | SOCK_MMCSD_STATUS = 0x114, |
| 44 | SOCK_MMCSD_INT_ENABLE = 0x118, |
| 45 | SOCK_MMCSD_COMMAND_TO = 0x11c, |
| 46 | SOCK_MMCSD_DATA_TO = 0x120, |
| 47 | SOCK_MMCSD_DATA = 0x124, |
| 48 | SOCK_MMCSD_BLOCK_LEN = 0x128, |
| 49 | SOCK_MMCSD_NUM_BLOCKS = 0x12c, |
| 50 | SOCK_MMCSD_BUFFER_CONFIG = 0x130, |
| 51 | SOCK_MMCSD_SPI_CONFIG = 0x134, |
| 52 | SOCK_MMCSD_SDIO_MODE_CONFIG = 0x138, |
| 53 | SOCK_MMCSD_RESPONSE = 0x144, |
| 54 | SOCK_MMCSD_SDIO_SR = 0x164, |
| 55 | SOCK_MMCSD_SYSTEM_CONTROL = 0x168, |
| 56 | SOCK_MMCSD_SYSTEM_STATUS = 0x16c, |
| 57 | SOCK_MS_COMMAND = 0x184, |
| 58 | SOCK_MS_DATA = 0x188, |
| 59 | SOCK_MS_STATUS = 0x18c, |
| 60 | SOCK_MS_SYSTEM = 0x190, |
| 61 | SOCK_FIFO_ACCESS = 0x200 }; |
| 62 | |
| 63 | |
| 64 | #define TIFM_IRQ_ENABLE 0x80000000 |
Alex Dubov | 6412d92 | 2006-12-11 01:55:33 +1100 | [diff] [blame] | 65 | #define TIFM_IRQ_SOCKMASK(x) (x) |
| 66 | #define TIFM_IRQ_CARDMASK(x) ((x) << 8) |
| 67 | #define TIFM_IRQ_FIFOMASK(x) ((x) << 16) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 68 | #define TIFM_IRQ_SETALL 0xffffffff |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 69 | |
| 70 | #define TIFM_CTRL_LED 0x00000040 |
| 71 | #define TIFM_CTRL_FAST_CLK 0x00000100 |
| 72 | |
| 73 | #define TIFM_SOCK_STATE_OCCUPIED 0x00000008 |
| 74 | #define TIFM_SOCK_STATE_POWERED 0x00000080 |
| 75 | |
| 76 | #define TIFM_FIFO_ENABLE 0x00000001 /* Meaning of this constant is unverified */ |
| 77 | #define TIFM_FIFO_INT_SETALL 0x0000ffff |
| 78 | #define TIFM_FIFO_INTMASK 0x00000005 /* Meaning of this constant is unverified */ |
| 79 | |
| 80 | #define TIFM_DMA_RESET 0x00000002 /* Meaning of this constant is unverified */ |
| 81 | #define TIFM_DMA_TX 0x00008000 /* Meaning of this constant is unverified */ |
| 82 | #define TIFM_DMA_EN 0x00000001 /* Meaning of this constant is unverified */ |
| 83 | |
| 84 | typedef enum {FM_NULL = 0, FM_XD = 0x01, FM_MS = 0x02, FM_SD = 0x03} tifm_media_id; |
| 85 | |
| 86 | struct tifm_driver; |
| 87 | struct tifm_dev { |
| 88 | char __iomem *addr; |
| 89 | spinlock_t lock; |
| 90 | tifm_media_id media_id; |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 91 | unsigned int socket_id; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 92 | |
Alex Dubov | 50743f4 | 2006-12-11 01:55:30 +1100 | [diff] [blame] | 93 | void (*signal_irq)(struct tifm_dev *sock, |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 94 | unsigned int sock_irq_status); |
| 95 | |
| 96 | struct tifm_driver *drv; |
| 97 | struct device dev; |
| 98 | }; |
| 99 | |
| 100 | struct tifm_driver { |
| 101 | tifm_media_id *id_table; |
| 102 | int (*probe)(struct tifm_dev *dev); |
| 103 | void (*remove)(struct tifm_dev *dev); |
| 104 | |
| 105 | struct device_driver driver; |
| 106 | }; |
| 107 | |
| 108 | struct tifm_adapter { |
| 109 | char __iomem *addr; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 110 | spinlock_t lock; |
Alex Dubov | 6412d92 | 2006-12-11 01:55:33 +1100 | [diff] [blame] | 111 | unsigned int irq_status; |
| 112 | unsigned int socket_change_set; |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame^] | 113 | wait_queue_head_t change_set_notify; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 114 | unsigned int id; |
Alex Dubov | 6412d92 | 2006-12-11 01:55:33 +1100 | [diff] [blame] | 115 | unsigned int num_sockets; |
| 116 | struct tifm_dev **sockets; |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame^] | 117 | struct task_struct *media_switcher; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 118 | struct class_device cdev; |
| 119 | struct device *dev; |
| 120 | |
| 121 | void (*eject)(struct tifm_adapter *fm, struct tifm_dev *sock); |
| 122 | }; |
| 123 | |
| 124 | struct tifm_adapter *tifm_alloc_adapter(void); |
| 125 | void tifm_free_device(struct device *dev); |
| 126 | void tifm_free_adapter(struct tifm_adapter *fm); |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame^] | 127 | int tifm_add_adapter(struct tifm_adapter *fm, int (*mediathreadfn)(void *data)); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 128 | void tifm_remove_adapter(struct tifm_adapter *fm); |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 129 | struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 130 | int tifm_register_driver(struct tifm_driver *drv); |
| 131 | void tifm_unregister_driver(struct tifm_driver *drv); |
| 132 | void tifm_eject(struct tifm_dev *sock); |
| 133 | int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, |
| 134 | int direction); |
| 135 | void tifm_unmap_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, |
| 136 | int direction); |
| 137 | |
| 138 | |
| 139 | static inline void *tifm_get_drvdata(struct tifm_dev *dev) |
| 140 | { |
| 141 | return dev_get_drvdata(&dev->dev); |
| 142 | } |
| 143 | |
| 144 | static inline void tifm_set_drvdata(struct tifm_dev *dev, void *data) |
| 145 | { |
| 146 | dev_set_drvdata(&dev->dev, data); |
| 147 | } |
| 148 | |
| 149 | struct tifm_device_id { |
| 150 | tifm_media_id media_id; |
| 151 | }; |
| 152 | |
| 153 | #endif |