pata_of_platform.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OF-platform PATA driver
  4. *
  5. * Copyright (c) 2007 MontaVista Software, Inc.
  6. * Anton Vorontsov <[email protected]>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/of_address.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/ata_platform.h>
  13. #include <linux/libata.h>
  14. #define DRV_NAME "pata_of_platform"
  15. static struct scsi_host_template pata_platform_sht = {
  16. ATA_PIO_SHT(DRV_NAME),
  17. };
  18. static int pata_of_platform_probe(struct platform_device *ofdev)
  19. {
  20. int ret;
  21. struct device_node *dn = ofdev->dev.of_node;
  22. struct resource io_res;
  23. struct resource ctl_res;
  24. struct resource irq_res;
  25. unsigned int reg_shift = 0;
  26. int pio_mode = 0;
  27. int pio_mask;
  28. bool use16bit;
  29. int irq;
  30. ret = of_address_to_resource(dn, 0, &io_res);
  31. if (ret) {
  32. dev_err(&ofdev->dev, "can't get IO address from "
  33. "device tree\n");
  34. return -EINVAL;
  35. }
  36. ret = of_address_to_resource(dn, 1, &ctl_res);
  37. if (ret) {
  38. dev_err(&ofdev->dev, "can't get CTL address from "
  39. "device tree\n");
  40. return -EINVAL;
  41. }
  42. memset(&irq_res, 0, sizeof(irq_res));
  43. irq = platform_get_irq_optional(ofdev, 0);
  44. if (irq < 0 && irq != -ENXIO)
  45. return irq;
  46. if (irq > 0) {
  47. irq_res.start = irq;
  48. irq_res.end = irq;
  49. }
  50. of_property_read_u32(dn, "reg-shift", &reg_shift);
  51. if (!of_property_read_u32(dn, "pio-mode", &pio_mode)) {
  52. if (pio_mode > 6) {
  53. dev_err(&ofdev->dev, "invalid pio-mode\n");
  54. return -EINVAL;
  55. }
  56. } else {
  57. dev_info(&ofdev->dev, "pio-mode unspecified, assuming PIO0\n");
  58. }
  59. use16bit = of_property_read_bool(dn, "ata-generic,use16bit");
  60. pio_mask = 1 << pio_mode;
  61. pio_mask |= (1 << pio_mode) - 1;
  62. return __pata_platform_probe(&ofdev->dev, &io_res, &ctl_res, irq > 0 ? &irq_res : NULL,
  63. reg_shift, pio_mask, &pata_platform_sht,
  64. use16bit);
  65. }
  66. static const struct of_device_id pata_of_platform_match[] = {
  67. { .compatible = "ata-generic", },
  68. { /* sentinel */ }
  69. };
  70. MODULE_DEVICE_TABLE(of, pata_of_platform_match);
  71. static struct platform_driver pata_of_platform_driver = {
  72. .driver = {
  73. .name = DRV_NAME,
  74. .of_match_table = pata_of_platform_match,
  75. },
  76. .probe = pata_of_platform_probe,
  77. .remove = ata_platform_remove_one,
  78. };
  79. module_platform_driver(pata_of_platform_driver);
  80. MODULE_DESCRIPTION("OF-platform PATA driver");
  81. MODULE_AUTHOR("Anton Vorontsov <[email protected]>");
  82. MODULE_LICENSE("GPL");