pata_of_platform.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * OF-platform PATA driver
  3. *
  4. * Copyright (c) 2007 MontaVista Software, Inc.
  5. * Anton Vorontsov <avorontsov@ru.mvista.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License (Version 2) as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/of_address.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/ata_platform.h>
  16. #include <linux/libata.h>
  17. static int pata_of_platform_probe(struct platform_device *ofdev)
  18. {
  19. int ret;
  20. struct device_node *dn = ofdev->dev.of_node;
  21. struct resource io_res;
  22. struct resource ctl_res;
  23. struct resource *irq_res;
  24. unsigned int reg_shift = 0;
  25. int pio_mode = 0;
  26. int pio_mask;
  27. const u32 *prop;
  28. ret = of_address_to_resource(dn, 0, &io_res);
  29. if (ret) {
  30. dev_err(&ofdev->dev, "can't get IO address from "
  31. "device tree\n");
  32. return -EINVAL;
  33. }
  34. ret = of_address_to_resource(dn, 1, &ctl_res);
  35. if (ret) {
  36. dev_err(&ofdev->dev, "can't get CTL address from "
  37. "device tree\n");
  38. return -EINVAL;
  39. }
  40. irq_res = platform_get_resource(ofdev, IORESOURCE_IRQ, 0);
  41. prop = of_get_property(dn, "reg-shift", NULL);
  42. if (prop)
  43. reg_shift = be32_to_cpup(prop);
  44. prop = of_get_property(dn, "pio-mode", NULL);
  45. if (prop) {
  46. pio_mode = be32_to_cpup(prop);
  47. if (pio_mode > 6) {
  48. dev_err(&ofdev->dev, "invalid pio-mode\n");
  49. return -EINVAL;
  50. }
  51. } else {
  52. dev_info(&ofdev->dev, "pio-mode unspecified, assuming PIO0\n");
  53. }
  54. pio_mask = 1 << pio_mode;
  55. pio_mask |= (1 << pio_mode) - 1;
  56. return __pata_platform_probe(&ofdev->dev, &io_res, &ctl_res, irq_res,
  57. reg_shift, pio_mask);
  58. }
  59. static struct of_device_id pata_of_platform_match[] = {
  60. { .compatible = "ata-generic", },
  61. { },
  62. };
  63. MODULE_DEVICE_TABLE(of, pata_of_platform_match);
  64. static struct platform_driver pata_of_platform_driver = {
  65. .driver = {
  66. .name = "pata_of_platform",
  67. .owner = THIS_MODULE,
  68. .of_match_table = pata_of_platform_match,
  69. },
  70. .probe = pata_of_platform_probe,
  71. .remove = ata_platform_remove_one,
  72. };
  73. module_platform_driver(pata_of_platform_driver);
  74. MODULE_DESCRIPTION("OF-platform PATA driver");
  75. MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
  76. MODULE_LICENSE("GPL");