]> Pileus Git - ~andy/linux/blob - drivers/staging/phison/phison.c
571d03df8d65a5f657fb70a0fa060102ffec5584
[~andy/linux] / drivers / staging / phison / phison.c
1 /*
2  * Copyright (C) 2006           Red Hat <evan_ko@phison.com>
3  *
4  *  May be copied or modified under the terms of the GNU General Public License
5  *
6  *  [Modify History]
7  *   #0001, Evan, 2008.10.22, V0.00, New release.
8  *   #0002, Evan, 2008.11.01, V0.90, Test Work In Ubuntu Linux 8.04.
9  *   #0003, Evan, 2008.01.08, V0.91, Change Name "PCIE-SSD" to "E-BOX".
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/pci.h>
15 #include <linux/init.h>
16 #include <linux/blkdev.h>
17 #include <linux/delay.h>
18 #include <linux/device.h>
19 #include <scsi/scsi_host.h>
20 #include <linux/libata.h>
21 #include <linux/ata.h>
22
23 #define PHISON_DEBUG
24
25 #define DRV_NAME        "PHISON E-BOX" //#0003
26 #define DRV_VERSION     "0.91" //#0003
27
28 #define PCI_VENDOR_ID_PHISON   0x1987
29 #define PCI_DEVICE_ID_PS5000   0x5000
30
31 int phison_pre_reset(struct ata_link *link, unsigned long deadline)
32 {
33         int ret;
34         struct ata_port *ap = link->ap;
35         ap->cbl = ATA_CBL_NONE;
36         ret = ata_std_prereset(link, deadline);
37         #ifdef PHISON_DEBUG
38         printk("****** phison_pre_reset(), ret = %x ******\n", ret);
39         #endif
40         return ret;
41 }
42
43 void phison_error_handler(struct ata_port *ap)
44 {
45         #ifdef PHISON_DEBUG
46         printk("****** phison_error_handler() ******\n");
47         #endif
48         return ata_bmdma_drive_eh(ap, phison_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
49 }
50
51 struct scsi_host_template phison_sht = {
52         .module                 = THIS_MODULE,
53         .name                   = DRV_NAME,
54         .ioctl                  = ata_scsi_ioctl,
55         .queuecommand   = ata_scsi_queuecmd,
56         .can_queue              = ATA_DEF_QUEUE,
57         .this_id                = ATA_SHT_THIS_ID,
58         .sg_tablesize   = LIBATA_MAX_PRD,
59         .cmd_per_lun    = ATA_SHT_CMD_PER_LUN,
60         .emulated               = ATA_SHT_EMULATED,
61         .use_clustering = ATA_SHT_USE_CLUSTERING,
62         .proc_name              = DRV_NAME,
63         .dma_boundary   = ATA_DMA_BOUNDARY,
64         .slave_configure        = ata_scsi_slave_config,
65         .slave_destroy  = ata_scsi_slave_destroy,
66         /* Use standard CHS mapping rules */
67         .bios_param             = ata_std_bios_param,
68 };
69
70 const struct ata_port_operations phison_ops = {
71         /* Task file is PCI ATA format, use helpers */
72         .tf_load                = ata_tf_load,
73         .tf_read                = ata_tf_read,
74         .check_status   = ata_check_status,
75         .exec_command   = ata_exec_command,
76         .dev_select             = ata_std_dev_select,
77
78         .freeze                 = ata_bmdma_freeze,
79         .thaw                   = ata_bmdma_thaw,
80         .error_handler  = phison_error_handler,
81         .post_internal_cmd      = ata_bmdma_post_internal_cmd,
82
83         /* BMDMA handling is PCI ATA format, use helpers */
84         .bmdma_setup    = ata_bmdma_setup,
85         .bmdma_start    = ata_bmdma_start,
86         .bmdma_stop             = ata_bmdma_stop,
87         .bmdma_status           = ata_bmdma_status,
88         .qc_prep                = ata_qc_prep,
89         .qc_issue               = ata_qc_issue_prot,
90         .data_xfer              = ata_data_xfer,
91
92         /* IRQ-related hooks */
93         .irq_handler            = ata_interrupt,
94         .irq_clear              = ata_bmdma_irq_clear,
95         .irq_on                 = ata_irq_on,
96
97         /* Generic PATA PCI ATA helpers */
98         .port_start             = ata_port_start,
99 };
100
101 int phison_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
102 {
103         struct ata_port_info info = {
104                 .sht            = &phison_sht,
105                 .flags  = ATA_FLAG_NO_ATAPI,
106
107                 .pio_mask       = 0x1f,
108                 .mwdma_mask     = 0x07,
109                 .udma_mask      = ATA_UDMA5,
110
111                 .port_ops       = &phison_ops,
112         };
113         int ret;
114
115         const struct ata_port_info *ppi[] = { &info, NULL };
116
117         ret = ata_pci_init_one(pdev, ppi);
118
119         #ifdef PHISON_DEBUG
120         printk("****** phison_init_one(), ret = %x ******\n", ret);
121         #endif
122
123         return ret;
124
125 }
126
127 struct pci_device_id phison_pci_tbl[] = {
128         { PCI_VENDOR_ID_PHISON, PCI_DEVICE_ID_PS5000, PCI_ANY_ID, PCI_ANY_ID,
129           PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
130         { 0, },
131 };
132
133 MODULE_DEVICE_TABLE(pci, phison_pci_tbl);
134
135 struct pci_driver phison_pci_driver = {
136         .name           = DRV_NAME,
137         .id_table       = phison_pci_tbl,
138         .probe          = phison_init_one,
139         .remove         = ata_pci_remove_one,
140 #ifdef CONFIG_PM //haven't test it.
141         .suspend        = ata_pci_device_suspend,
142         .resume         = ata_pci_device_resume,
143 #endif
144 };
145
146 int phison_ide_init(void)
147 {
148 #if 0 //For Test.
149         struct pci_dev *pci_dev = NULL;
150         struct pci_dev *ps5k_dev = NULL;
151         int i, ret;
152         u16 vid, pid;
153         u32 addr1,addr2,addr3, addr4,addr5,addr6;
154
155         printk("****** phison_ide_init ******\n");
156
157         i = 0;
158
159         while(1)
160         {
161                 pci_dev = pci_find_device(PCI_ANY_ID,PCI_ANY_ID, pci_dev);
162
163                 if(pci_dev!=NULL)
164                 {
165                         pci_read_config_word(pci_dev, 0, &pid);
166                         pci_read_config_word(pci_dev, 2, &vid);
167                         pci_read_config_dword(pci_dev, 16, &addr1);
168                         pci_read_config_dword(pci_dev, 16, &addr1);
169                         pci_read_config_dword(pci_dev, 16, &addr1);
170                         pci_read_config_dword(pci_dev, 16, &addr1);
171                         pci_read_config_dword(pci_dev, 20, &addr2);
172                         pci_read_config_dword(pci_dev, 24, &addr3);
173                         pci_read_config_dword(pci_dev, 28, &addr4);
174                         pci_read_config_dword(pci_dev, 32, &addr5);
175                         pci_read_config_dword(pci_dev, 36, &addr6);
176
177                         printk("****** <0x%02x>, %x, %x, %x,%x,%x,%x,%x,%x ******\n", i, pid, vid, addr1, addr2, addr3, addr4,addr5,addr6);
178                         i++;
179
180                         if((pid==PCI_VENDOR_ID_PHISON)&&(vid==PCI_DEVICE_ID_PS5000)) ps5k_dev = pci_dev;
181                 }
182                 else
183                 {
184                         if(i==0) printk("****** no pci device found ******\n");
185                         break;
186                 }
187         }
188
189         if(ps5k_dev!=NULL)
190         {
191                 ret = pci_register_driver(&phison_pci_driver);
192                 printk("****** PS5000 found, Ret = %x ******\n", ret);
193                 return true;
194         }
195
196         printk("****** PS5000 not found ******\n");
197         return false;
198 #else
199         int ret;
200
201         ret = pci_register_driver(&phison_pci_driver);
202
203         #ifdef PHISON_DEBUG
204         printk("****** phison_ide_init(), ret = %x ******\n", ret);
205         #endif
206
207         return ret;
208 #endif
209
210
211 }
212
213 void phison_ide_exit(void)
214 {
215         #ifdef PHISON_DEBUG
216         printk("****** phison_ide_exit() ******\n");
217         #endif
218         pci_unregister_driver(&phison_pci_driver);
219 }
220
221 module_init(phison_ide_init);
222 module_exit(phison_ide_exit);
223
224 MODULE_AUTHOR("Evan Ko");
225 MODULE_DESCRIPTION("PCIE driver module for PHISON PS5000 E-BOX");//#0003
226 MODULE_LICENSE("GPL");
227 MODULE_VERSION(DRV_VERSION);