100-magicbox-ide-driver.patch 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. --- a/drivers/ide/Kconfig
  2. +++ b/drivers/ide/Kconfig
  3. @@ -717,6 +717,11 @@ config BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
  4. depends on SOC_AU1200 && BLK_DEV_IDE_AU1XXX
  5. endchoice
  6. +config BLK_DEV_IDE_MAGICBOX
  7. + tristate "Magicbox CF card support"
  8. + depends on MAGICBOX || OPENRB_LIGHT
  9. + select IDE_XFER_MODE
  10. +
  11. config BLK_DEV_IDE_TX4938
  12. tristate "TX4938 internal IDE support"
  13. depends on SOC_TX4938
  14. --- a/drivers/ide/Makefile
  15. +++ b/drivers/ide/Makefile
  16. @@ -113,6 +113,7 @@ obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapi
  17. obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o
  18. obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o
  19. +obj-$(CONFIG_BLK_DEV_IDE_MAGICBOX) += magicbox_ide.o
  20. obj-$(CONFIG_BLK_DEV_IDE_TX4938) += tx4938ide.o
  21. obj-$(CONFIG_BLK_DEV_IDE_TX4939) += tx4939ide.o
  22. --- /dev/null
  23. +++ b/drivers/ide/magicbox_ide.c
  24. @@ -0,0 +1,293 @@
  25. +/*
  26. + * IDE driver for the MagicBox 2.0 onboard CompactFlash slot.
  27. + *
  28. + * Copyright (C) 2009 Gabor Juhos <[email protected]>
  29. + *
  30. + * Based on the original driver by Wojtek Kaniewski <[email protected]>
  31. + *
  32. + * This program is free software; you can redistribute it and/or modify it
  33. + * under the terms of the GNU General Public License version 2 as published
  34. + * by the Free Software Foundation.
  35. + */
  36. +
  37. +#include <linux/types.h>
  38. +#include <linux/ioport.h>
  39. +#include <linux/of.h>
  40. +#include <linux/of_device.h>
  41. +#include <linux/of_platform.h>
  42. +#include <linux/ide.h>
  43. +
  44. +#define DRV_DESC "IDE driver for Magicbox 2.0 onboard CF slot"
  45. +#define DRV_NAME "magicbox_cf"
  46. +
  47. +static inline u8 magicbox_ide_inb(unsigned long port)
  48. +{
  49. + return (u8) (readw((void __iomem *) port) >> 8) & 0xff;
  50. +}
  51. +
  52. +static inline void magicbox_ide_outb(u8 value, unsigned long port)
  53. +{
  54. + writew(value << 8, (void __iomem *) port);
  55. +}
  56. +
  57. +static inline void magicbox_ide_insw(unsigned long port, void *addr, u32 count)
  58. +{
  59. + u16 *ptr;
  60. +
  61. + for (ptr = addr; count--; ptr++)
  62. + *ptr = readw((void __iomem *) port);
  63. +}
  64. +
  65. +static inline void magicbox_ide_insl(unsigned long port, void *addr, u32 count)
  66. +{
  67. + u32 *ptr;
  68. +
  69. + for (ptr = addr; count--; ptr++)
  70. + *ptr = readl((void __iomem *) port);
  71. +}
  72. +
  73. +static inline void magicbox_ide_outsw(unsigned long port, void *addr,
  74. + u32 count)
  75. +{
  76. + u16 *ptr;
  77. +
  78. + for (ptr = addr; count--; ptr++)
  79. + writew(*ptr, (void __iomem *) port);
  80. +}
  81. +
  82. +static inline void magicbox_ide_outsl(unsigned long port, void *addr,
  83. + u32 count)
  84. +{
  85. + u32 *ptr;
  86. +
  87. + for (ptr = addr; count--; ptr++)
  88. + writel(*ptr, (void __iomem *) port);
  89. +}
  90. +
  91. +static void magicbox_ide_exec_command(ide_hwif_t *hwif, u8 cmd)
  92. +{
  93. + magicbox_ide_outb(cmd, hwif->io_ports.command_addr);
  94. +}
  95. +
  96. +static u8 magicbox_ide_read_status(ide_hwif_t *hwif)
  97. +{
  98. + return magicbox_ide_inb(hwif->io_ports.status_addr);
  99. +}
  100. +
  101. +static u8 magicbox_ide_read_altstatus(ide_hwif_t *hwif)
  102. +{
  103. + return magicbox_ide_inb(hwif->io_ports.ctl_addr);
  104. +}
  105. +
  106. +static void magicbox_ide_write_devctl(ide_hwif_t *hwif, u8 ctl)
  107. +{
  108. + magicbox_ide_outb(ctl, hwif->io_ports.ctl_addr);
  109. +}
  110. +
  111. +static void magicbox_ide_tf_load(ide_drive_t *drive, struct ide_taskfile *tf,
  112. + u8 valid)
  113. +{
  114. + struct ide_io_ports *io_ports = &drive->hwif->io_ports;
  115. +
  116. + if (valid & IDE_VALID_FEATURE)
  117. + magicbox_ide_outb(tf->feature, io_ports->feature_addr);
  118. + if (valid & IDE_VALID_NSECT)
  119. + magicbox_ide_outb(tf->nsect, io_ports->nsect_addr);
  120. + if (valid & IDE_VALID_LBAL)
  121. + magicbox_ide_outb(tf->lbal, io_ports->lbal_addr);
  122. + if (valid & IDE_VALID_LBAM)
  123. + magicbox_ide_outb(tf->lbam, io_ports->lbam_addr);
  124. + if (valid & IDE_VALID_LBAH)
  125. + magicbox_ide_outb(tf->lbah, io_ports->lbah_addr);
  126. +
  127. + if (valid & IDE_VALID_DEVICE)
  128. + magicbox_ide_outb(tf->device, io_ports->device_addr);
  129. +}
  130. +
  131. +static void magicbox_ide_tf_read(ide_drive_t *drive, struct ide_taskfile *tf,
  132. + u8 valid)
  133. +{
  134. + struct ide_io_ports *io_ports = &drive->hwif->io_ports;
  135. +
  136. + if (valid & IDE_VALID_NSECT)
  137. + tf->nsect = magicbox_ide_inb(io_ports->nsect_addr);
  138. + if (valid & IDE_VALID_LBAL)
  139. + tf->lbal = magicbox_ide_inb(io_ports->lbal_addr);
  140. + if (valid & IDE_VALID_LBAM)
  141. + tf->lbam = magicbox_ide_inb(io_ports->lbam_addr);
  142. + if (valid & IDE_VALID_LBAH)
  143. + tf->lbah = magicbox_ide_inb(io_ports->lbah_addr);
  144. + if (valid & IDE_VALID_DEVICE)
  145. + tf->device = magicbox_ide_inb(io_ports->device_addr);
  146. +}
  147. +
  148. +static void magicbox_ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
  149. + void *buf, unsigned int len)
  150. +{
  151. + unsigned long port = drive->hwif->io_ports.data_addr;
  152. +
  153. + len++;
  154. +
  155. + if (drive->io_32bit) {
  156. + magicbox_ide_insl(port, buf, len / 4);
  157. +
  158. + if ((len & 3) >= 2)
  159. + magicbox_ide_insw(port, (u8 *)buf + (len & ~3), 1);
  160. + } else {
  161. + magicbox_ide_insw(port, buf, len / 2);
  162. + }
  163. +}
  164. +
  165. +static void magicbox_ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
  166. + void *buf, unsigned int len)
  167. +{
  168. + unsigned long port = drive->hwif->io_ports.data_addr;
  169. +
  170. + len++;
  171. +
  172. + if (drive->io_32bit) {
  173. + magicbox_ide_outsl(port, buf, len / 4);
  174. +
  175. + if ((len & 3) >= 2)
  176. + magicbox_ide_outsw(port, (u8 *)buf + (len & ~3), 1);
  177. + } else {
  178. + magicbox_ide_outsw(port, buf, len / 2);
  179. + }
  180. +}
  181. +
  182. +static void magicbox_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
  183. +{
  184. +}
  185. +
  186. +static u8 magicbox_ide_cable_detect(ide_hwif_t *hwif)
  187. +{
  188. + return ATA_CBL_PATA40;
  189. +}
  190. +
  191. +static const struct ide_tp_ops magicbox_ide_tp_ops = {
  192. + .exec_command = magicbox_ide_exec_command,
  193. + .read_status = magicbox_ide_read_status,
  194. + .read_altstatus = magicbox_ide_read_altstatus,
  195. + .write_devctl = magicbox_ide_write_devctl,
  196. +
  197. + .dev_select = ide_dev_select,
  198. + .tf_load = magicbox_ide_tf_load,
  199. + .tf_read = magicbox_ide_tf_read,
  200. +
  201. + .input_data = magicbox_ide_input_data,
  202. + .output_data = magicbox_ide_output_data,
  203. +};
  204. +
  205. +static const struct ide_port_ops magicbox_ide_port_ops = {
  206. + .set_pio_mode = magicbox_ide_set_pio_mode,
  207. + .cable_detect = magicbox_ide_cable_detect,
  208. +};
  209. +
  210. +static const struct ide_port_info magicbox_ide_port_info = {
  211. + .name = DRV_NAME,
  212. + .chipset = ide_generic,
  213. + .tp_ops = &magicbox_ide_tp_ops,
  214. + .port_ops = &magicbox_ide_port_ops,
  215. + .host_flags = IDE_HFLAG_SINGLE |
  216. + IDE_HFLAG_NO_DMA |
  217. + IDE_HFLAG_MMIO |
  218. + IDE_HFLAG_UNMASK_IRQS,
  219. + .pio_mask = ATA_PIO4,
  220. +};
  221. +
  222. +static inline void magicbox_ide_setup_hw(hw_regs_t *hw, u16 __iomem *base,
  223. + u16 __iomem *ctrl, int irq)
  224. +{
  225. + unsigned long port = (unsigned long) base;
  226. + int i;
  227. +
  228. + memset(hw, 0, sizeof(*hw));
  229. + for (i = 0; i <= 7; i++)
  230. + hw->io_ports_array[i] = port + i * 2;
  231. +
  232. + /*
  233. + * the IDE control register is at ATA address 6,
  234. + * with CS1 active instead of CS0
  235. + */
  236. + hw->io_ports.ctl_addr = (unsigned long)ctrl + (6 * 2);
  237. + hw->irq = irq;
  238. + hw->chipset = ide_generic;
  239. + hw->ack_intr = NULL;
  240. +}
  241. +
  242. +static int __devinit magicbox_ide_of_probe(struct of_device *op,
  243. + const struct of_device_id *match)
  244. +{
  245. + hw_regs_t hw;
  246. + hw_regs_t *hws[] = { &hw, NULL, NULL, NULL };
  247. + struct ide_host *host;
  248. + u16 __iomem *base;
  249. + u16 __iomem *ctrl;
  250. + int irq;
  251. + int ret = 0;
  252. +
  253. + irq = irq_of_parse_and_map(op->node, 0);
  254. + if (irq < 0) {
  255. + dev_err(&op->dev, "invalid irq\n");
  256. + ret = -EINVAL;
  257. + goto err_exit;
  258. + }
  259. +
  260. + base = of_iomap(op->node, 0);
  261. + if (base == NULL) {
  262. + ret = -ENOMEM;
  263. + goto err_exit;
  264. + }
  265. +
  266. + ctrl = of_iomap(op->node, 1);
  267. + if (ctrl == NULL) {
  268. + ret = -ENOMEM;
  269. + goto err_unmap_base;
  270. + }
  271. +
  272. + hw.dev = &op->dev;
  273. + magicbox_ide_setup_hw(&hw, base, ctrl, irq);
  274. +
  275. + ret = ide_host_add(&magicbox_ide_port_info, hws, &host);
  276. + if (ret)
  277. + goto err_unmap_ctrl;
  278. +
  279. + dev_set_drvdata(&op->dev, host);
  280. +
  281. + return 0;
  282. +
  283. + err_unmap_ctrl:
  284. + iounmap(ctrl);
  285. + err_unmap_base:
  286. + iounmap(base);
  287. + err_exit:
  288. + return ret;
  289. +}
  290. +
  291. +static struct of_device_id magicbox_ide_of_match[] = {
  292. + { .compatible = "magicbox-cf", },
  293. + {},
  294. +};
  295. +
  296. +static struct of_platform_driver magicbox_ide_of_platform_driver = {
  297. + .owner = THIS_MODULE,
  298. + .name = DRV_NAME,
  299. + .match_table = magicbox_ide_of_match,
  300. + .probe = magicbox_ide_of_probe,
  301. + .driver = {
  302. + .name = DRV_NAME,
  303. + .owner = THIS_MODULE,
  304. + },
  305. +};
  306. +
  307. +static int __init magicbox_ide_init(void)
  308. +{
  309. + return of_register_platform_driver(&magicbox_ide_of_platform_driver);
  310. +}
  311. +
  312. +module_init(magicbox_ide_init);
  313. +
  314. +MODULE_DESCRIPTION(DRV_DESC);
  315. +MODULE_AUTHOR("Gabor Juhos <[email protected]>");
  316. +MODULE_LICENSE("GPL v2");
  317. +MODULE_DEVICE_TABLE(of, magicbox_ide_of_match);