blob: 2a196982601f8b6647d2137a1e97df2a94c2bd91 [file] [log] [blame]
Alex Dubov4020f2d2006-10-04 02:15:37 -07001/*
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>
Alex Dubov4020f2d2006-10-04 02:15:37 -070017#include <linux/delay.h>
18#include <linux/pci.h>
Alex Dubov91f8d012007-04-12 17:05:26 +100019#include <linux/workqueue.h>
Alex Dubov4020f2d2006-10-04 02:15:37 -070020
21/* Host registers (relative to pci base address): */
22enum {
23 FM_SET_INTERRUPT_ENABLE = 0x008,
24 FM_CLEAR_INTERRUPT_ENABLE = 0x00c,
Alex Dubov91f8d012007-04-12 17:05:26 +100025 FM_INTERRUPT_STATUS = 0x014
26};
Alex Dubov4020f2d2006-10-04 02:15:37 -070027
28/* Socket registers (relative to socket base address): */
29enum {
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,
Alex Dubov91f8d012007-04-12 17:05:26 +100061 SOCK_FIFO_ACCESS = 0x200
62};
Alex Dubov4020f2d2006-10-04 02:15:37 -070063
Alex Dubov4020f2d2006-10-04 02:15:37 -070064#define TIFM_CTRL_LED 0x00000040
65#define TIFM_CTRL_FAST_CLK 0x00000100
66
67#define TIFM_SOCK_STATE_OCCUPIED 0x00000008
68#define TIFM_SOCK_STATE_POWERED 0x00000080
69
Alex Dubov91f8d012007-04-12 17:05:26 +100070#define TIFM_FIFO_ENABLE 0x00000001
71#define TIFM_FIFO_READY 0x00000001
Alex Dubov4020f2d2006-10-04 02:15:37 -070072#define TIFM_FIFO_INT_SETALL 0x0000ffff
Alex Dubov91f8d012007-04-12 17:05:26 +100073#define TIFM_FIFO_INTMASK 0x00000005
Alex Dubov4020f2d2006-10-04 02:15:37 -070074
Alex Dubov91f8d012007-04-12 17:05:26 +100075#define TIFM_DMA_RESET 0x00000002
76#define TIFM_DMA_TX 0x00008000
77#define TIFM_DMA_EN 0x00000001
Alex Dubov13cdf482007-04-12 17:05:25 +100078#define TIFM_DMA_TSIZE 0x0000007f
Alex Dubov4020f2d2006-10-04 02:15:37 -070079
Alex Dubove23f2b82007-04-12 16:59:14 +100080#define TIFM_TYPE_XD 1
81#define TIFM_TYPE_MS 2
82#define TIFM_TYPE_SD 3
83
84struct tifm_device_id {
85 unsigned char type;
86};
Alex Dubov4020f2d2006-10-04 02:15:37 -070087
88struct tifm_driver;
89struct tifm_dev {
Alex Dubov91f8d012007-04-12 17:05:26 +100090 char __iomem *addr;
91 spinlock_t lock;
92 unsigned char type;
93 unsigned int socket_id;
Alex Dubov4020f2d2006-10-04 02:15:37 -070094
Alex Dubov4552f0c2007-04-12 16:59:12 +100095 void (*card_event)(struct tifm_dev *sock);
96 void (*data_event)(struct tifm_dev *sock);
Alex Dubov4020f2d2006-10-04 02:15:37 -070097
Alex Dubov91f8d012007-04-12 17:05:26 +100098 struct device dev;
Alex Dubov4020f2d2006-10-04 02:15:37 -070099};
100
101struct tifm_driver {
Alex Dubove23f2b82007-04-12 16:59:14 +1000102 struct tifm_device_id *id_table;
Alex Dubov91f8d012007-04-12 17:05:26 +1000103 int (*probe)(struct tifm_dev *dev);
104 void (*remove)(struct tifm_dev *dev);
105 int (*suspend)(struct tifm_dev *dev,
106 pm_message_t state);
107 int (*resume)(struct tifm_dev *dev);
Alex Dubov4020f2d2006-10-04 02:15:37 -0700108
Alex Dubov91f8d012007-04-12 17:05:26 +1000109 struct device_driver driver;
Alex Dubov4020f2d2006-10-04 02:15:37 -0700110};
111
112struct tifm_adapter {
Alex Dubov91f8d012007-04-12 17:05:26 +1000113 char __iomem *addr;
114 spinlock_t lock;
115 unsigned int irq_status;
116 unsigned int socket_change_set;
117 unsigned int id;
118 unsigned int num_sockets;
119 struct completion *finish_me;
Alex Dubov6113ed72007-04-12 16:59:17 +1000120
Alex Dubov91f8d012007-04-12 17:05:26 +1000121 struct work_struct media_switcher;
122 struct class_device cdev;
Alex Dubov4020f2d2006-10-04 02:15:37 -0700123
Alex Dubov91f8d012007-04-12 17:05:26 +1000124 void (*eject)(struct tifm_adapter *fm,
125 struct tifm_dev *sock);
Alex Dubov6113ed72007-04-12 16:59:17 +1000126
Alex Dubov91f8d012007-04-12 17:05:26 +1000127 struct tifm_dev *sockets[0];
Alex Dubov4020f2d2006-10-04 02:15:37 -0700128};
129
Alex Dubov6113ed72007-04-12 16:59:17 +1000130struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets,
131 struct device *dev);
Alex Dubov3540af82007-04-12 16:59:15 +1000132int tifm_add_adapter(struct tifm_adapter *fm);
Alex Dubov4020f2d2006-10-04 02:15:37 -0700133void tifm_remove_adapter(struct tifm_adapter *fm);
Alex Dubov6113ed72007-04-12 16:59:17 +1000134void tifm_free_adapter(struct tifm_adapter *fm);
135
136void tifm_free_device(struct device *dev);
Alex Dubov2428a8f2007-04-12 16:59:18 +1000137struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id,
138 unsigned char type);
139
Alex Dubov4020f2d2006-10-04 02:15:37 -0700140int tifm_register_driver(struct tifm_driver *drv);
141void tifm_unregister_driver(struct tifm_driver *drv);
142void tifm_eject(struct tifm_dev *sock);
143int tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
144 int direction);
145void tifm_unmap_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents,
146 int direction);
Alex Dubov3540af82007-04-12 16:59:15 +1000147void tifm_queue_work(struct work_struct *work);
Alex Dubov4020f2d2006-10-04 02:15:37 -0700148
149static inline void *tifm_get_drvdata(struct tifm_dev *dev)
150{
Alex Dubov91f8d012007-04-12 17:05:26 +1000151 return dev_get_drvdata(&dev->dev);
Alex Dubov4020f2d2006-10-04 02:15:37 -0700152}
153
154static inline void tifm_set_drvdata(struct tifm_dev *dev, void *data)
155{
156 dev_set_drvdata(&dev->dev, data);
157}
158
Alex Dubov4020f2d2006-10-04 02:15:37 -0700159#endif