pata_samsung_cf.c 17 KB

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