pata_samsung_cf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * PATA driver for Samsung SoCs.
  6. * Supports CF Interface in True IDE mode. Currently only PIO mode has been
  7. * implemented; UDMA support has to be added.
  8. *
  9. * Based on:
  10. * PATA driver for AT91SAM9260 Static Memory Controller
  11. * PATA driver for Toshiba SCC controller
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License version 2
  15. * as published by the Free Software Foundation.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/mod_devicetable.h>
  20. #include <linux/init.h>
  21. #include <linux/clk.h>
  22. #include <linux/libata.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/slab.h>
  25. #include <linux/platform_data/ata-samsung_cf.h>
  26. #define DRV_NAME "pata_samsung_cf"
  27. #define DRV_VERSION "0.1"
  28. #define S3C_CFATA_REG(x) (x)
  29. #define S3C_CFATA_MUX S3C_CFATA_REG(0x0)
  30. #define S3C_ATA_CTRL S3C_CFATA_REG(0x0)
  31. #define S3C_ATA_CMD S3C_CFATA_REG(0x8)
  32. #define S3C_ATA_IRQ S3C_CFATA_REG(0x10)
  33. #define S3C_ATA_IRQ_MSK S3C_CFATA_REG(0x14)
  34. #define S3C_ATA_CFG S3C_CFATA_REG(0x18)
  35. #define S3C_ATA_PIO_TIME S3C_CFATA_REG(0x2c)
  36. #define S3C_ATA_PIO_DTR S3C_CFATA_REG(0x54)
  37. #define S3C_ATA_PIO_FED S3C_CFATA_REG(0x58)
  38. #define S3C_ATA_PIO_SCR S3C_CFATA_REG(0x5c)
  39. #define S3C_ATA_PIO_LLR S3C_CFATA_REG(0x60)
  40. #define S3C_ATA_PIO_LMR S3C_CFATA_REG(0x64)
  41. #define S3C_ATA_PIO_LHR S3C_CFATA_REG(0x68)
  42. #define S3C_ATA_PIO_DVR S3C_CFATA_REG(0x6c)
  43. #define S3C_ATA_PIO_CSD S3C_CFATA_REG(0x70)
  44. #define S3C_ATA_PIO_DAD S3C_CFATA_REG(0x74)
  45. #define S3C_ATA_PIO_RDATA S3C_CFATA_REG(0x7c)
  46. #define S3C_CFATA_MUX_TRUEIDE 0x01
  47. #define S3C_ATA_CFG_SWAP 0x40
  48. #define S3C_ATA_CFG_IORDYEN 0x02
  49. enum s3c_cpu_type {
  50. TYPE_S3C64XX,
  51. TYPE_S5PV210,
  52. };
  53. /*
  54. * struct s3c_ide_info - S3C PATA instance.
  55. * @clk: The clock resource for this controller.
  56. * @ide_addr: The area mapped for the hardware registers.
  57. * @sfr_addr: The area mapped for the special function registers.
  58. * @irq: The IRQ number we are using.
  59. * @cpu_type: The exact type of this controller.
  60. * @fifo_status_reg: The ATA_FIFO_STATUS register offset.
  61. */
  62. struct s3c_ide_info {
  63. struct clk *clk;
  64. void __iomem *ide_addr;
  65. void __iomem *sfr_addr;
  66. int irq;
  67. enum s3c_cpu_type cpu_type;
  68. unsigned int fifo_status_reg;
  69. };
  70. static void pata_s3c_set_endian(void __iomem *s3c_ide_regbase, u8 mode)
  71. {
  72. u32 reg = readl(s3c_ide_regbase + S3C_ATA_CFG);
  73. reg = mode ? (reg & ~S3C_ATA_CFG_SWAP) : (reg | S3C_ATA_CFG_SWAP);
  74. writel(reg, s3c_ide_regbase + S3C_ATA_CFG);
  75. }
  76. static void pata_s3c_cfg_mode(void __iomem *s3c_ide_sfrbase)
  77. {
  78. /* Select true-ide as the internal operating mode */
  79. writel(readl(s3c_ide_sfrbase + S3C_CFATA_MUX) | S3C_CFATA_MUX_TRUEIDE,
  80. s3c_ide_sfrbase + S3C_CFATA_MUX);
  81. }
  82. static unsigned long
  83. pata_s3c_setup_timing(struct s3c_ide_info *info, const struct ata_timing *ata)
  84. {
  85. int t1 = ata->setup;
  86. int t2 = ata->act8b;
  87. int t2i = ata->rec8b;
  88. ulong piotime;
  89. piotime = ((t2i & 0xff) << 12) | ((t2 & 0xff) << 4) | (t1 & 0xf);
  90. return piotime;
  91. }
  92. static void pata_s3c_set_piomode(struct ata_port *ap, struct ata_device *adev)
  93. {
  94. struct s3c_ide_info *info = ap->host->private_data;
  95. struct ata_timing timing;
  96. int cycle_time;
  97. ulong ata_cfg = readl(info->ide_addr + S3C_ATA_CFG);
  98. ulong piotime;
  99. /* Enables IORDY if mode requires it */
  100. if (ata_pio_need_iordy(adev))
  101. ata_cfg |= S3C_ATA_CFG_IORDYEN;
  102. else
  103. ata_cfg &= ~S3C_ATA_CFG_IORDYEN;
  104. cycle_time = (int)(1000000000UL / clk_get_rate(info->clk));
  105. ata_timing_compute(adev, adev->pio_mode, &timing,
  106. cycle_time * 1000, 0);
  107. piotime = pata_s3c_setup_timing(info, &timing);
  108. writel(ata_cfg, info->ide_addr + S3C_ATA_CFG);
  109. writel(piotime, info->ide_addr + S3C_ATA_PIO_TIME);
  110. }
  111. /*
  112. * Waits until the IDE controller is able to perform next read/write
  113. * operation to the disk. Needed for 64XX series boards only.
  114. */
  115. static int wait_for_host_ready(struct s3c_ide_info *info)
  116. {
  117. ulong timeout;
  118. void __iomem *fifo_reg = info->ide_addr + info->fifo_status_reg;
  119. /* wait for maximum of 20 msec */
  120. timeout = jiffies + msecs_to_jiffies(20);
  121. while (time_before(jiffies, timeout)) {
  122. if ((readl(fifo_reg) >> 28) == 0)
  123. return 0;
  124. }
  125. return -EBUSY;
  126. }
  127. /*
  128. * Writes to one of the task file registers.
  129. */
  130. static void ata_outb(struct ata_host *host, u8 addr, void __iomem *reg)
  131. {
  132. struct s3c_ide_info *info = host->private_data;
  133. wait_for_host_ready(info);
  134. writeb(addr, reg);
  135. }
  136. /*
  137. * Reads from one of the task file registers.
  138. */
  139. static u8 ata_inb(struct ata_host *host, void __iomem *reg)
  140. {
  141. struct s3c_ide_info *info = host->private_data;
  142. u8 temp;
  143. wait_for_host_ready(info);
  144. (void) readb(reg);
  145. wait_for_host_ready(info);
  146. temp = readb(info->ide_addr + S3C_ATA_PIO_RDATA);
  147. return temp;
  148. }
  149. /*
  150. * pata_s3c_tf_load - send taskfile registers to host controller
  151. */
  152. static void pata_s3c_tf_load(struct ata_port *ap,
  153. const struct ata_taskfile *tf)
  154. {
  155. struct ata_ioports *ioaddr = &ap->ioaddr;
  156. unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
  157. if (tf->ctl != ap->last_ctl) {
  158. ata_outb(ap->host, tf->ctl, ioaddr->ctl_addr);
  159. ap->last_ctl = tf->ctl;
  160. ata_wait_idle(ap);
  161. }
  162. if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
  163. ata_outb(ap->host, tf->hob_feature, ioaddr->feature_addr);
  164. ata_outb(ap->host, tf->hob_nsect, ioaddr->nsect_addr);
  165. ata_outb(ap->host, tf->hob_lbal, ioaddr->lbal_addr);
  166. ata_outb(ap->host, tf->hob_lbam, ioaddr->lbam_addr);
  167. ata_outb(ap->host, tf->hob_lbah, ioaddr->lbah_addr);
  168. }
  169. if (is_addr) {
  170. ata_outb(ap->host, tf->feature, ioaddr->feature_addr);
  171. ata_outb(ap->host, tf->nsect, ioaddr->nsect_addr);
  172. ata_outb(ap->host, tf->lbal, ioaddr->lbal_addr);
  173. ata_outb(ap->host, tf->lbam, ioaddr->lbam_addr);
  174. ata_outb(ap->host, tf->lbah, ioaddr->lbah_addr);
  175. }
  176. if (tf->flags & ATA_TFLAG_DEVICE)
  177. ata_outb(ap->host, tf->device, ioaddr->device_addr);
  178. ata_wait_idle(ap);
  179. }
  180. /*
  181. * pata_s3c_tf_read - input device's ATA taskfile shadow registers
  182. */
  183. static void pata_s3c_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
  184. {
  185. struct ata_ioports *ioaddr = &ap->ioaddr;
  186. tf->feature = ata_inb(ap->host, ioaddr->error_addr);
  187. tf->nsect = ata_inb(ap->host, ioaddr->nsect_addr);
  188. tf->lbal = ata_inb(ap->host, ioaddr->lbal_addr);
  189. tf->lbam = ata_inb(ap->host, ioaddr->lbam_addr);
  190. tf->lbah = ata_inb(ap->host, ioaddr->lbah_addr);
  191. tf->device = ata_inb(ap->host, ioaddr->device_addr);
  192. if (tf->flags & ATA_TFLAG_LBA48) {
  193. ata_outb(ap->host, tf->ctl | ATA_HOB, ioaddr->ctl_addr);
  194. tf->hob_feature = ata_inb(ap->host, ioaddr->error_addr);
  195. tf->hob_nsect = ata_inb(ap->host, ioaddr->nsect_addr);
  196. tf->hob_lbal = ata_inb(ap->host, ioaddr->lbal_addr);
  197. tf->hob_lbam = ata_inb(ap->host, ioaddr->lbam_addr);
  198. tf->hob_lbah = ata_inb(ap->host, ioaddr->lbah_addr);
  199. ata_outb(ap->host, tf->ctl, ioaddr->ctl_addr);
  200. ap->last_ctl = tf->ctl;
  201. }
  202. }
  203. /*
  204. * pata_s3c_exec_command - issue ATA command to host controller
  205. */
  206. static void pata_s3c_exec_command(struct ata_port *ap,
  207. const struct ata_taskfile *tf)
  208. {
  209. ata_outb(ap->host, tf->command, ap->ioaddr.command_addr);
  210. ata_sff_pause(ap);
  211. }
  212. /*
  213. * pata_s3c_check_status - Read device status register
  214. */
  215. static u8 pata_s3c_check_status(struct ata_port *ap)
  216. {
  217. return ata_inb(ap->host, ap->ioaddr.status_addr);
  218. }
  219. /*
  220. * pata_s3c_check_altstatus - Read alternate device status register
  221. */
  222. static u8 pata_s3c_check_altstatus(struct ata_port *ap)
  223. {
  224. return ata_inb(ap->host, ap->ioaddr.altstatus_addr);
  225. }
  226. /*
  227. * pata_s3c_data_xfer - Transfer data by PIO
  228. */
  229. static unsigned int pata_s3c_data_xfer(struct ata_queued_cmd *qc,
  230. unsigned char *buf, unsigned int buflen, int rw)
  231. {
  232. struct ata_port *ap = qc->dev->link->ap;
  233. struct s3c_ide_info *info = ap->host->private_data;
  234. void __iomem *data_addr = ap->ioaddr.data_addr;
  235. unsigned int words = buflen >> 1, i;
  236. u16 *data_ptr = (u16 *)buf;
  237. /* Requires wait same as in ata_inb/ata_outb */
  238. if (rw == READ)
  239. for (i = 0; i < words; i++, data_ptr++) {
  240. wait_for_host_ready(info);
  241. (void) readw(data_addr);
  242. wait_for_host_ready(info);
  243. *data_ptr = readw(info->ide_addr
  244. + S3C_ATA_PIO_RDATA);
  245. }
  246. else
  247. for (i = 0; i < words; i++, data_ptr++) {
  248. wait_for_host_ready(info);
  249. writew(*data_ptr, data_addr);
  250. }
  251. if (buflen & 0x01)
  252. dev_err(ap->dev, "unexpected trailing data\n");
  253. return words << 1;
  254. }
  255. /*
  256. * pata_s3c_dev_select - Select device on ATA bus
  257. */
  258. static void pata_s3c_dev_select(struct ata_port *ap, unsigned int device)
  259. {
  260. u8 tmp = ATA_DEVICE_OBS;
  261. if (device != 0)
  262. tmp |= ATA_DEV1;
  263. ata_outb(ap->host, tmp, ap->ioaddr.device_addr);
  264. ata_sff_pause(ap);
  265. }
  266. /*
  267. * pata_s3c_devchk - PATA device presence detection
  268. */
  269. static unsigned int pata_s3c_devchk(struct ata_port *ap,
  270. unsigned int device)
  271. {
  272. struct ata_ioports *ioaddr = &ap->ioaddr;
  273. u8 nsect, lbal;
  274. pata_s3c_dev_select(ap, device);
  275. ata_outb(ap->host, 0x55, ioaddr->nsect_addr);
  276. ata_outb(ap->host, 0xaa, ioaddr->lbal_addr);
  277. ata_outb(ap->host, 0xaa, ioaddr->nsect_addr);
  278. ata_outb(ap->host, 0x55, ioaddr->lbal_addr);
  279. ata_outb(ap->host, 0x55, ioaddr->nsect_addr);
  280. ata_outb(ap->host, 0xaa, ioaddr->lbal_addr);
  281. nsect = ata_inb(ap->host, ioaddr->nsect_addr);
  282. lbal = ata_inb(ap->host, ioaddr->lbal_addr);
  283. if ((nsect == 0x55) && (lbal == 0xaa))
  284. return 1; /* we found a device */
  285. return 0; /* nothing found */
  286. }
  287. /*
  288. * pata_s3c_wait_after_reset - wait for devices to become ready after reset
  289. */
  290. static int pata_s3c_wait_after_reset(struct ata_link *link,
  291. unsigned long deadline)
  292. {
  293. int rc;
  294. ata_msleep(link->ap, ATA_WAIT_AFTER_RESET);
  295. /* always check readiness of the master device */
  296. rc = ata_sff_wait_ready(link, deadline);
  297. /* -ENODEV means the odd clown forgot the D7 pulldown resistor
  298. * and TF status is 0xff, bail out on it too.
  299. */
  300. if (rc)
  301. return rc;
  302. return 0;
  303. }
  304. /*
  305. * pata_s3c_bus_softreset - PATA device software reset
  306. */
  307. static int pata_s3c_bus_softreset(struct ata_port *ap,
  308. unsigned long deadline)
  309. {
  310. struct ata_ioports *ioaddr = &ap->ioaddr;
  311. /* software reset. causes dev0 to be selected */
  312. ata_outb(ap->host, ap->ctl, ioaddr->ctl_addr);
  313. udelay(20);
  314. ata_outb(ap->host, ap->ctl | ATA_SRST, ioaddr->ctl_addr);
  315. udelay(20);
  316. ata_outb(ap->host, ap->ctl, ioaddr->ctl_addr);
  317. ap->last_ctl = ap->ctl;
  318. return pata_s3c_wait_after_reset(&ap->link, deadline);
  319. }
  320. /*
  321. * pata_s3c_softreset - reset host port via ATA SRST
  322. */
  323. static int pata_s3c_softreset(struct ata_link *link, unsigned int *classes,
  324. unsigned long deadline)
  325. {
  326. struct ata_port *ap = link->ap;
  327. unsigned int devmask = 0;
  328. int rc;
  329. u8 err;
  330. /* determine if device 0 is present */
  331. if (pata_s3c_devchk(ap, 0))
  332. devmask |= (1 << 0);
  333. /* select device 0 again */
  334. pata_s3c_dev_select(ap, 0);
  335. /* issue bus reset */
  336. rc = pata_s3c_bus_softreset(ap, deadline);
  337. /* if link is occupied, -ENODEV too is an error */
  338. if (rc && rc != -ENODEV) {
  339. ata_link_err(link, "SRST failed (errno=%d)\n", rc);
  340. return rc;
  341. }
  342. /* determine by signature whether we have ATA or ATAPI devices */
  343. classes[0] = ata_sff_dev_classify(&ap->link.device[0],
  344. devmask & (1 << 0), &err);
  345. return 0;
  346. }
  347. /*
  348. * pata_s3c_set_devctl - Write device control register
  349. */
  350. static void pata_s3c_set_devctl(struct ata_port *ap, u8 ctl)
  351. {
  352. ata_outb(ap->host, ctl, ap->ioaddr.ctl_addr);
  353. }
  354. static struct scsi_host_template pata_s3c_sht = {
  355. ATA_PIO_SHT(DRV_NAME),
  356. };
  357. static struct ata_port_operations pata_s3c_port_ops = {
  358. .inherits = &ata_sff_port_ops,
  359. .sff_check_status = pata_s3c_check_status,
  360. .sff_check_altstatus = pata_s3c_check_altstatus,
  361. .sff_tf_load = pata_s3c_tf_load,
  362. .sff_tf_read = pata_s3c_tf_read,
  363. .sff_data_xfer = pata_s3c_data_xfer,
  364. .sff_exec_command = pata_s3c_exec_command,
  365. .sff_dev_select = pata_s3c_dev_select,
  366. .sff_set_devctl = pata_s3c_set_devctl,
  367. .softreset = pata_s3c_softreset,
  368. .set_piomode = pata_s3c_set_piomode,
  369. };
  370. static struct ata_port_operations pata_s5p_port_ops = {
  371. .inherits = &ata_sff_port_ops,
  372. .set_piomode = pata_s3c_set_piomode,
  373. };
  374. static void pata_s3c_enable(void __iomem *s3c_ide_regbase, bool state)
  375. {
  376. u32 temp = readl(s3c_ide_regbase + S3C_ATA_CTRL);
  377. temp = state ? (temp | 1) : (temp & ~1);
  378. writel(temp, s3c_ide_regbase + S3C_ATA_CTRL);
  379. }
  380. static irqreturn_t pata_s3c_irq(int irq, void *dev_instance)
  381. {
  382. struct ata_host *host = dev_instance;
  383. struct s3c_ide_info *info = host->private_data;
  384. u32 reg;
  385. reg = readl(info->ide_addr + S3C_ATA_IRQ);
  386. writel(reg, info->ide_addr + S3C_ATA_IRQ);
  387. return ata_sff_interrupt(irq, dev_instance);
  388. }
  389. static void pata_s3c_hwinit(struct s3c_ide_info *info,
  390. struct s3c_ide_platdata *pdata)
  391. {
  392. switch (info->cpu_type) {
  393. case TYPE_S3C64XX:
  394. /* Configure as big endian */
  395. pata_s3c_cfg_mode(info->sfr_addr);
  396. pata_s3c_set_endian(info->ide_addr, 1);
  397. pata_s3c_enable(info->ide_addr, true);
  398. msleep(100);
  399. /* Remove IRQ Status */
  400. writel(0x1f, info->ide_addr + S3C_ATA_IRQ);
  401. writel(0x1b, info->ide_addr + S3C_ATA_IRQ_MSK);
  402. break;
  403. case TYPE_S5PV210:
  404. /* Configure as little endian */
  405. pata_s3c_set_endian(info->ide_addr, 0);
  406. pata_s3c_enable(info->ide_addr, true);
  407. msleep(100);
  408. /* Remove IRQ Status */
  409. writel(0x3f, info->ide_addr + S3C_ATA_IRQ);
  410. writel(0x3f, info->ide_addr + S3C_ATA_IRQ_MSK);
  411. break;
  412. default:
  413. BUG();
  414. }
  415. }
  416. static int __init pata_s3c_probe(struct platform_device *pdev)
  417. {
  418. struct s3c_ide_platdata *pdata = dev_get_platdata(&pdev->dev);
  419. struct device *dev = &pdev->dev;
  420. struct s3c_ide_info *info;
  421. struct resource *res;
  422. struct ata_port *ap;
  423. struct ata_host *host;
  424. enum s3c_cpu_type cpu_type;
  425. int ret;
  426. cpu_type = platform_get_device_id(pdev)->driver_data;
  427. info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
  428. if (!info)
  429. return -ENOMEM;
  430. info->irq = platform_get_irq(pdev, 0);
  431. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  432. info->ide_addr = devm_ioremap_resource(dev, res);
  433. if (IS_ERR(info->ide_addr))
  434. return PTR_ERR(info->ide_addr);
  435. info->clk = devm_clk_get(&pdev->dev, "cfcon");
  436. if (IS_ERR(info->clk)) {
  437. dev_err(dev, "failed to get access to cf controller clock\n");
  438. ret = PTR_ERR(info->clk);
  439. info->clk = NULL;
  440. return ret;
  441. }
  442. clk_enable(info->clk);
  443. /* init ata host */
  444. host = ata_host_alloc(dev, 1);
  445. if (!host) {
  446. dev_err(dev, "failed to allocate ide host\n");
  447. ret = -ENOMEM;
  448. goto stop_clk;
  449. }
  450. ap = host->ports[0];
  451. ap->pio_mask = ATA_PIO4;
  452. if (cpu_type == TYPE_S3C64XX) {
  453. ap->ops = &pata_s3c_port_ops;
  454. info->sfr_addr = info->ide_addr + 0x1800;
  455. info->ide_addr += 0x1900;
  456. info->fifo_status_reg = 0x94;
  457. } else {
  458. ap->ops = &pata_s5p_port_ops;
  459. info->fifo_status_reg = 0x84;
  460. }
  461. info->cpu_type = cpu_type;
  462. if (info->irq <= 0) {
  463. ap->flags |= ATA_FLAG_PIO_POLLING;
  464. info->irq = 0;
  465. ata_port_desc(ap, "no IRQ, using PIO polling\n");
  466. }
  467. ap->ioaddr.cmd_addr = info->ide_addr + S3C_ATA_CMD;
  468. ap->ioaddr.data_addr = info->ide_addr + S3C_ATA_PIO_DTR;
  469. ap->ioaddr.error_addr = info->ide_addr + S3C_ATA_PIO_FED;
  470. ap->ioaddr.feature_addr = info->ide_addr + S3C_ATA_PIO_FED;
  471. ap->ioaddr.nsect_addr = info->ide_addr + S3C_ATA_PIO_SCR;
  472. ap->ioaddr.lbal_addr = info->ide_addr + S3C_ATA_PIO_LLR;
  473. ap->ioaddr.lbam_addr = info->ide_addr + S3C_ATA_PIO_LMR;
  474. ap->ioaddr.lbah_addr = info->ide_addr + S3C_ATA_PIO_LHR;
  475. ap->ioaddr.device_addr = info->ide_addr + S3C_ATA_PIO_DVR;
  476. ap->ioaddr.status_addr = info->ide_addr + S3C_ATA_PIO_CSD;
  477. ap->ioaddr.command_addr = info->ide_addr + S3C_ATA_PIO_CSD;
  478. ap->ioaddr.altstatus_addr = info->ide_addr + S3C_ATA_PIO_DAD;
  479. ap->ioaddr.ctl_addr = info->ide_addr + S3C_ATA_PIO_DAD;
  480. ata_port_desc(ap, "mmio cmd 0x%llx ",
  481. (unsigned long long)res->start);
  482. host->private_data = info;
  483. if (pdata && pdata->setup_gpio)
  484. pdata->setup_gpio();
  485. /* Set endianness and enable the interface */
  486. pata_s3c_hwinit(info, pdata);
  487. ret = ata_host_activate(host, info->irq,
  488. info->irq ? pata_s3c_irq : NULL,
  489. 0, &pata_s3c_sht);
  490. if (ret)
  491. goto stop_clk;
  492. return 0;
  493. stop_clk:
  494. clk_disable(info->clk);
  495. return ret;
  496. }
  497. static int __exit pata_s3c_remove(struct platform_device *pdev)
  498. {
  499. struct ata_host *host = platform_get_drvdata(pdev);
  500. struct s3c_ide_info *info = host->private_data;
  501. ata_host_detach(host);
  502. clk_disable(info->clk);
  503. return 0;
  504. }
  505. #ifdef CONFIG_PM_SLEEP
  506. static int pata_s3c_suspend(struct device *dev)
  507. {
  508. struct platform_device *pdev = to_platform_device(dev);
  509. struct ata_host *host = platform_get_drvdata(pdev);
  510. return ata_host_suspend(host, PMSG_SUSPEND);
  511. }
  512. static int pata_s3c_resume(struct device *dev)
  513. {
  514. struct platform_device *pdev = to_platform_device(dev);
  515. struct ata_host *host = platform_get_drvdata(pdev);
  516. struct s3c_ide_platdata *pdata = dev_get_platdata(&pdev->dev);
  517. struct s3c_ide_info *info = host->private_data;
  518. pata_s3c_hwinit(info, pdata);
  519. ata_host_resume(host);
  520. return 0;
  521. }
  522. static const struct dev_pm_ops pata_s3c_pm_ops = {
  523. .suspend = pata_s3c_suspend,
  524. .resume = pata_s3c_resume,
  525. };
  526. #endif
  527. /* driver device registration */
  528. static const struct platform_device_id pata_s3c_driver_ids[] = {
  529. {
  530. .name = "s3c64xx-pata",
  531. .driver_data = TYPE_S3C64XX,
  532. }, {
  533. .name = "s5pv210-pata",
  534. .driver_data = TYPE_S5PV210,
  535. },
  536. { }
  537. };
  538. MODULE_DEVICE_TABLE(platform, pata_s3c_driver_ids);
  539. static struct platform_driver pata_s3c_driver = {
  540. .remove = __exit_p(pata_s3c_remove),
  541. .id_table = pata_s3c_driver_ids,
  542. .driver = {
  543. .name = DRV_NAME,
  544. #ifdef CONFIG_PM_SLEEP
  545. .pm = &pata_s3c_pm_ops,
  546. #endif
  547. },
  548. };
  549. module_platform_driver_probe(pata_s3c_driver, pata_s3c_probe);
  550. MODULE_AUTHOR("Abhilash Kesavan, <a.kesavan@samsung.com>");
  551. MODULE_DESCRIPTION("low-level driver for Samsung PATA controller");
  552. MODULE_LICENSE("GPL");
  553. MODULE_VERSION(DRV_VERSION);