Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 2 | /* |
| 3 | * tifm.h - TI FlashMedia driver |
| 4 | * |
| 5 | * Copyright (C) 2006 Alex Dubov <oakad@yahoo.com> |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _TIFM_H |
| 9 | #define _TIFM_H |
| 10 | |
| 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/interrupt.h> |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 13 | #include <linux/delay.h> |
| 14 | #include <linux/pci.h> |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 15 | #include <linux/workqueue.h> |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 16 | |
| 17 | /* Host registers (relative to pci base address): */ |
| 18 | enum { |
| 19 | FM_SET_INTERRUPT_ENABLE = 0x008, |
| 20 | FM_CLEAR_INTERRUPT_ENABLE = 0x00c, |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 21 | FM_INTERRUPT_STATUS = 0x014 |
| 22 | }; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 23 | |
| 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, |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 57 | SOCK_FIFO_ACCESS = 0x200 |
| 58 | }; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 59 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 60 | #define TIFM_CTRL_LED 0x00000040 |
| 61 | #define TIFM_CTRL_FAST_CLK 0x00000100 |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 62 | #define TIFM_CTRL_POWER_MASK 0x00000007 |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 63 | |
| 64 | #define TIFM_SOCK_STATE_OCCUPIED 0x00000008 |
| 65 | #define TIFM_SOCK_STATE_POWERED 0x00000080 |
| 66 | |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 67 | #define TIFM_FIFO_ENABLE 0x00000001 |
| 68 | #define TIFM_FIFO_READY 0x00000001 |
Alex Dubov | 92b22d9 | 2008-03-10 11:43:40 -0700 | [diff] [blame] | 69 | #define TIFM_FIFO_MORE 0x00000008 |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 70 | #define TIFM_FIFO_INT_SETALL 0x0000ffff |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 71 | #define TIFM_FIFO_INTMASK 0x00000005 |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 72 | |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 73 | #define TIFM_DMA_RESET 0x00000002 |
| 74 | #define TIFM_DMA_TX 0x00008000 |
| 75 | #define TIFM_DMA_EN 0x00000001 |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame] | 76 | #define TIFM_DMA_TSIZE 0x0000007f |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 77 | |
Alex Dubov | e23f2b8 | 2007-04-12 16:59:14 +1000 | [diff] [blame] | 78 | #define TIFM_TYPE_XD 1 |
| 79 | #define TIFM_TYPE_MS 2 |
| 80 | #define TIFM_TYPE_SD 3 |
| 81 | |
| 82 | struct tifm_device_id { |
| 83 | unsigned char type; |
| 84 | }; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 85 | |
| 86 | struct tifm_driver; |
| 87 | struct tifm_dev { |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 88 | char __iomem *addr; |
| 89 | spinlock_t lock; |
| 90 | unsigned char type; |
| 91 | unsigned int socket_id; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 92 | |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 93 | void (*card_event)(struct tifm_dev *sock); |
| 94 | void (*data_event)(struct tifm_dev *sock); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 95 | |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 96 | struct device dev; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | struct tifm_driver { |
Alex Dubov | e23f2b8 | 2007-04-12 16:59:14 +1000 | [diff] [blame] | 100 | struct tifm_device_id *id_table; |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 101 | int (*probe)(struct tifm_dev *dev); |
| 102 | void (*remove)(struct tifm_dev *dev); |
| 103 | int (*suspend)(struct tifm_dev *dev, |
| 104 | pm_message_t state); |
| 105 | int (*resume)(struct tifm_dev *dev); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 106 | |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 107 | struct device_driver driver; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct tifm_adapter { |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 111 | char __iomem *addr; |
| 112 | spinlock_t lock; |
| 113 | unsigned int irq_status; |
| 114 | unsigned int socket_change_set; |
| 115 | unsigned int id; |
| 116 | unsigned int num_sockets; |
| 117 | struct completion *finish_me; |
Alex Dubov | 6113ed73 | 2007-04-12 16:59:17 +1000 | [diff] [blame] | 118 | |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 119 | struct work_struct media_switcher; |
Tony Jones | 7dd817d | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 120 | struct device dev; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 121 | |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 122 | void (*eject)(struct tifm_adapter *fm, |
| 123 | struct tifm_dev *sock); |
Alex Dubov | baf8532 | 2008-02-09 10:20:54 -0800 | [diff] [blame] | 124 | int (*has_ms_pif)(struct tifm_adapter *fm, |
| 125 | struct tifm_dev *sock); |
Alex Dubov | 6113ed73 | 2007-04-12 16:59:17 +1000 | [diff] [blame] | 126 | |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 127 | struct tifm_dev *sockets[0]; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
Alex Dubov | 6113ed73 | 2007-04-12 16:59:17 +1000 | [diff] [blame] | 130 | struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets, |
| 131 | struct device *dev); |
Alex Dubov | 3540af8ff | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 132 | int tifm_add_adapter(struct tifm_adapter *fm); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 133 | void tifm_remove_adapter(struct tifm_adapter *fm); |
Alex Dubov | 6113ed73 | 2007-04-12 16:59:17 +1000 | [diff] [blame] | 134 | void tifm_free_adapter(struct tifm_adapter *fm); |
| 135 | |
| 136 | void tifm_free_device(struct device *dev); |
Alex Dubov | 2428a8f | 2007-04-12 16:59:18 +1000 | [diff] [blame] | 137 | struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id, |
| 138 | unsigned char type); |
| 139 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 140 | int tifm_register_driver(struct tifm_driver *drv); |
| 141 | void tifm_unregister_driver(struct tifm_driver *drv); |
| 142 | void tifm_eject(struct tifm_dev *sock); |
Alex Dubov | baf8532 | 2008-02-09 10:20:54 -0800 | [diff] [blame] | 143 | int tifm_has_ms_pif(struct tifm_dev *sock); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 144 | int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, |
| 145 | int direction); |
| 146 | void tifm_unmap_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, |
| 147 | int direction); |
Alex Dubov | 3540af8ff | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 148 | void tifm_queue_work(struct work_struct *work); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 149 | |
| 150 | static inline void *tifm_get_drvdata(struct tifm_dev *dev) |
| 151 | { |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 152 | return dev_get_drvdata(&dev->dev); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static inline void tifm_set_drvdata(struct tifm_dev *dev, void *data) |
| 156 | { |
| 157 | dev_set_drvdata(&dev->dev, data); |
| 158 | } |
| 159 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 160 | #endif |