18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * tifm.h - TI FlashMedia driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2006 Alex Dubov <oakad@yahoo.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _TIFM_H 98c2ecf20Sopenharmony_ci#define _TIFM_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 128c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 138c2ecf20Sopenharmony_ci#include <linux/delay.h> 148c2ecf20Sopenharmony_ci#include <linux/pci.h> 158c2ecf20Sopenharmony_ci#include <linux/workqueue.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* Host registers (relative to pci base address): */ 188c2ecf20Sopenharmony_cienum { 198c2ecf20Sopenharmony_ci FM_SET_INTERRUPT_ENABLE = 0x008, 208c2ecf20Sopenharmony_ci FM_CLEAR_INTERRUPT_ENABLE = 0x00c, 218c2ecf20Sopenharmony_ci FM_INTERRUPT_STATUS = 0x014 228c2ecf20Sopenharmony_ci}; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Socket registers (relative to socket base address): */ 258c2ecf20Sopenharmony_cienum { 268c2ecf20Sopenharmony_ci SOCK_CONTROL = 0x004, 278c2ecf20Sopenharmony_ci SOCK_PRESENT_STATE = 0x008, 288c2ecf20Sopenharmony_ci SOCK_DMA_ADDRESS = 0x00c, 298c2ecf20Sopenharmony_ci SOCK_DMA_CONTROL = 0x010, 308c2ecf20Sopenharmony_ci SOCK_DMA_FIFO_INT_ENABLE_SET = 0x014, 318c2ecf20Sopenharmony_ci SOCK_DMA_FIFO_INT_ENABLE_CLEAR = 0x018, 328c2ecf20Sopenharmony_ci SOCK_DMA_FIFO_STATUS = 0x020, 338c2ecf20Sopenharmony_ci SOCK_FIFO_CONTROL = 0x024, 348c2ecf20Sopenharmony_ci SOCK_FIFO_PAGE_SIZE = 0x028, 358c2ecf20Sopenharmony_ci SOCK_MMCSD_COMMAND = 0x104, 368c2ecf20Sopenharmony_ci SOCK_MMCSD_ARG_LOW = 0x108, 378c2ecf20Sopenharmony_ci SOCK_MMCSD_ARG_HIGH = 0x10c, 388c2ecf20Sopenharmony_ci SOCK_MMCSD_CONFIG = 0x110, 398c2ecf20Sopenharmony_ci SOCK_MMCSD_STATUS = 0x114, 408c2ecf20Sopenharmony_ci SOCK_MMCSD_INT_ENABLE = 0x118, 418c2ecf20Sopenharmony_ci SOCK_MMCSD_COMMAND_TO = 0x11c, 428c2ecf20Sopenharmony_ci SOCK_MMCSD_DATA_TO = 0x120, 438c2ecf20Sopenharmony_ci SOCK_MMCSD_DATA = 0x124, 448c2ecf20Sopenharmony_ci SOCK_MMCSD_BLOCK_LEN = 0x128, 458c2ecf20Sopenharmony_ci SOCK_MMCSD_NUM_BLOCKS = 0x12c, 468c2ecf20Sopenharmony_ci SOCK_MMCSD_BUFFER_CONFIG = 0x130, 478c2ecf20Sopenharmony_ci SOCK_MMCSD_SPI_CONFIG = 0x134, 488c2ecf20Sopenharmony_ci SOCK_MMCSD_SDIO_MODE_CONFIG = 0x138, 498c2ecf20Sopenharmony_ci SOCK_MMCSD_RESPONSE = 0x144, 508c2ecf20Sopenharmony_ci SOCK_MMCSD_SDIO_SR = 0x164, 518c2ecf20Sopenharmony_ci SOCK_MMCSD_SYSTEM_CONTROL = 0x168, 528c2ecf20Sopenharmony_ci SOCK_MMCSD_SYSTEM_STATUS = 0x16c, 538c2ecf20Sopenharmony_ci SOCK_MS_COMMAND = 0x184, 548c2ecf20Sopenharmony_ci SOCK_MS_DATA = 0x188, 558c2ecf20Sopenharmony_ci SOCK_MS_STATUS = 0x18c, 568c2ecf20Sopenharmony_ci SOCK_MS_SYSTEM = 0x190, 578c2ecf20Sopenharmony_ci SOCK_FIFO_ACCESS = 0x200 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define TIFM_CTRL_LED 0x00000040 618c2ecf20Sopenharmony_ci#define TIFM_CTRL_FAST_CLK 0x00000100 628c2ecf20Sopenharmony_ci#define TIFM_CTRL_POWER_MASK 0x00000007 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define TIFM_SOCK_STATE_OCCUPIED 0x00000008 658c2ecf20Sopenharmony_ci#define TIFM_SOCK_STATE_POWERED 0x00000080 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define TIFM_FIFO_ENABLE 0x00000001 688c2ecf20Sopenharmony_ci#define TIFM_FIFO_READY 0x00000001 698c2ecf20Sopenharmony_ci#define TIFM_FIFO_MORE 0x00000008 708c2ecf20Sopenharmony_ci#define TIFM_FIFO_INT_SETALL 0x0000ffff 718c2ecf20Sopenharmony_ci#define TIFM_FIFO_INTMASK 0x00000005 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define TIFM_DMA_RESET 0x00000002 748c2ecf20Sopenharmony_ci#define TIFM_DMA_TX 0x00008000 758c2ecf20Sopenharmony_ci#define TIFM_DMA_EN 0x00000001 768c2ecf20Sopenharmony_ci#define TIFM_DMA_TSIZE 0x0000007f 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define TIFM_TYPE_XD 1 798c2ecf20Sopenharmony_ci#define TIFM_TYPE_MS 2 808c2ecf20Sopenharmony_ci#define TIFM_TYPE_SD 3 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistruct tifm_device_id { 838c2ecf20Sopenharmony_ci unsigned char type; 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistruct tifm_driver; 878c2ecf20Sopenharmony_cistruct tifm_dev { 888c2ecf20Sopenharmony_ci char __iomem *addr; 898c2ecf20Sopenharmony_ci spinlock_t lock; 908c2ecf20Sopenharmony_ci unsigned char type; 918c2ecf20Sopenharmony_ci unsigned int socket_id; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci void (*card_event)(struct tifm_dev *sock); 948c2ecf20Sopenharmony_ci void (*data_event)(struct tifm_dev *sock); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci struct device dev; 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistruct tifm_driver { 1008c2ecf20Sopenharmony_ci struct tifm_device_id *id_table; 1018c2ecf20Sopenharmony_ci int (*probe)(struct tifm_dev *dev); 1028c2ecf20Sopenharmony_ci void (*remove)(struct tifm_dev *dev); 1038c2ecf20Sopenharmony_ci int (*suspend)(struct tifm_dev *dev, 1048c2ecf20Sopenharmony_ci pm_message_t state); 1058c2ecf20Sopenharmony_ci int (*resume)(struct tifm_dev *dev); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci struct device_driver driver; 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistruct tifm_adapter { 1118c2ecf20Sopenharmony_ci char __iomem *addr; 1128c2ecf20Sopenharmony_ci spinlock_t lock; 1138c2ecf20Sopenharmony_ci unsigned int irq_status; 1148c2ecf20Sopenharmony_ci unsigned int socket_change_set; 1158c2ecf20Sopenharmony_ci unsigned int id; 1168c2ecf20Sopenharmony_ci unsigned int num_sockets; 1178c2ecf20Sopenharmony_ci struct completion *finish_me; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci struct work_struct media_switcher; 1208c2ecf20Sopenharmony_ci struct device dev; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci void (*eject)(struct tifm_adapter *fm, 1238c2ecf20Sopenharmony_ci struct tifm_dev *sock); 1248c2ecf20Sopenharmony_ci int (*has_ms_pif)(struct tifm_adapter *fm, 1258c2ecf20Sopenharmony_ci struct tifm_dev *sock); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci struct tifm_dev *sockets[]; 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistruct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets, 1318c2ecf20Sopenharmony_ci struct device *dev); 1328c2ecf20Sopenharmony_ciint tifm_add_adapter(struct tifm_adapter *fm); 1338c2ecf20Sopenharmony_civoid tifm_remove_adapter(struct tifm_adapter *fm); 1348c2ecf20Sopenharmony_civoid tifm_free_adapter(struct tifm_adapter *fm); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_civoid tifm_free_device(struct device *dev); 1378c2ecf20Sopenharmony_cistruct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id, 1388c2ecf20Sopenharmony_ci unsigned char type); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ciint tifm_register_driver(struct tifm_driver *drv); 1418c2ecf20Sopenharmony_civoid tifm_unregister_driver(struct tifm_driver *drv); 1428c2ecf20Sopenharmony_civoid tifm_eject(struct tifm_dev *sock); 1438c2ecf20Sopenharmony_ciint tifm_has_ms_pif(struct tifm_dev *sock); 1448c2ecf20Sopenharmony_ciint tifm_map_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, 1458c2ecf20Sopenharmony_ci int direction); 1468c2ecf20Sopenharmony_civoid tifm_unmap_sg(struct tifm_dev *sock, struct scatterlist *sg, int nents, 1478c2ecf20Sopenharmony_ci int direction); 1488c2ecf20Sopenharmony_civoid tifm_queue_work(struct work_struct *work); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic inline void *tifm_get_drvdata(struct tifm_dev *dev) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci return dev_get_drvdata(&dev->dev); 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic inline void tifm_set_drvdata(struct tifm_dev *dev, void *data) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci dev_set_drvdata(&dev->dev, data); 1588c2ecf20Sopenharmony_ci} 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#endif 161