ahci_seattle.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * AMD Seattle AHCI SATA driver
  4. *
  5. * Copyright (c) 2015, Advanced Micro Devices
  6. * Author: Brijesh Singh <brijesh.singh@amd.com>
  7. *
  8. * based on the AHCI SATA platform driver by Jeff Garzik and Anton Vorontsov
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/pm.h>
  13. #include <linux/device.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/libata.h>
  16. #include <linux/ahci_platform.h>
  17. #include <linux/acpi.h>
  18. #include <linux/pci_ids.h>
  19. #include "ahci.h"
  20. /* SGPIO Control Register definition
  21. *
  22. * Bit Type Description
  23. * 31 RW OD7.2 (activity)
  24. * 30 RW OD7.1 (locate)
  25. * 29 RW OD7.0 (fault)
  26. * 28...8 RW OD6.2...OD0.0 (3bits per port, 1 bit per LED)
  27. * 7 RO SGPIO feature flag
  28. * 6:4 RO Reserved
  29. * 3:0 RO Number of ports (0 means no port supported)
  30. */
  31. #define ACTIVITY_BIT_POS(x) (8 + (3 * x))
  32. #define LOCATE_BIT_POS(x) (ACTIVITY_BIT_POS(x) + 1)
  33. #define FAULT_BIT_POS(x) (LOCATE_BIT_POS(x) + 1)
  34. #define ACTIVITY_MASK 0x00010000
  35. #define LOCATE_MASK 0x00080000
  36. #define FAULT_MASK 0x00400000
  37. #define DRV_NAME "ahci-seattle"
  38. static ssize_t seattle_transmit_led_message(struct ata_port *ap, u32 state,
  39. ssize_t size);
  40. struct seattle_plat_data {
  41. void __iomem *sgpio_ctrl;
  42. };
  43. static struct ata_port_operations ahci_port_ops = {
  44. .inherits = &ahci_ops,
  45. };
  46. static const struct ata_port_info ahci_port_info = {
  47. .flags = AHCI_FLAG_COMMON,
  48. .pio_mask = ATA_PIO4,
  49. .udma_mask = ATA_UDMA6,
  50. .port_ops = &ahci_port_ops,
  51. };
  52. static struct ata_port_operations ahci_seattle_ops = {
  53. .inherits = &ahci_ops,
  54. .transmit_led_message = seattle_transmit_led_message,
  55. };
  56. static const struct ata_port_info ahci_port_seattle_info = {
  57. .flags = AHCI_FLAG_COMMON | ATA_FLAG_EM | ATA_FLAG_SW_ACTIVITY,
  58. .link_flags = ATA_LFLAG_SW_ACTIVITY,
  59. .pio_mask = ATA_PIO4,
  60. .udma_mask = ATA_UDMA6,
  61. .port_ops = &ahci_seattle_ops,
  62. };
  63. static const struct scsi_host_template ahci_platform_sht = {
  64. AHCI_SHT(DRV_NAME),
  65. };
  66. static ssize_t seattle_transmit_led_message(struct ata_port *ap, u32 state,
  67. ssize_t size)
  68. {
  69. struct ahci_host_priv *hpriv = ap->host->private_data;
  70. struct ahci_port_priv *pp = ap->private_data;
  71. struct seattle_plat_data *plat_data = hpriv->plat_data;
  72. unsigned long flags;
  73. int pmp;
  74. struct ahci_em_priv *emp;
  75. u32 val;
  76. /* get the slot number from the message */
  77. pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
  78. if (pmp >= EM_MAX_SLOTS)
  79. return -EINVAL;
  80. emp = &pp->em_priv[pmp];
  81. val = ioread32(plat_data->sgpio_ctrl);
  82. if (state & ACTIVITY_MASK)
  83. val |= 1 << ACTIVITY_BIT_POS((ap->port_no));
  84. else
  85. val &= ~(1 << ACTIVITY_BIT_POS((ap->port_no)));
  86. if (state & LOCATE_MASK)
  87. val |= 1 << LOCATE_BIT_POS((ap->port_no));
  88. else
  89. val &= ~(1 << LOCATE_BIT_POS((ap->port_no)));
  90. if (state & FAULT_MASK)
  91. val |= 1 << FAULT_BIT_POS((ap->port_no));
  92. else
  93. val &= ~(1 << FAULT_BIT_POS((ap->port_no)));
  94. iowrite32(val, plat_data->sgpio_ctrl);
  95. spin_lock_irqsave(ap->lock, flags);
  96. /* save off new led state for port/slot */
  97. emp->led_state = state;
  98. spin_unlock_irqrestore(ap->lock, flags);
  99. return size;
  100. }
  101. static const struct ata_port_info *ahci_seattle_get_port_info(
  102. struct platform_device *pdev, struct ahci_host_priv *hpriv)
  103. {
  104. struct device *dev = &pdev->dev;
  105. struct seattle_plat_data *plat_data;
  106. u32 val;
  107. plat_data = devm_kzalloc(dev, sizeof(*plat_data), GFP_KERNEL);
  108. if (!plat_data)
  109. return &ahci_port_info;
  110. plat_data->sgpio_ctrl = devm_platform_ioremap_resource(pdev, 1);
  111. if (IS_ERR(plat_data->sgpio_ctrl))
  112. return &ahci_port_info;
  113. val = ioread32(plat_data->sgpio_ctrl);
  114. if (!(val & 0xf))
  115. return &ahci_port_info;
  116. hpriv->em_loc = 0;
  117. hpriv->em_buf_sz = 4;
  118. hpriv->em_msg_type = EM_MSG_TYPE_LED;
  119. hpriv->plat_data = plat_data;
  120. dev_info(dev, "SGPIO LED control is enabled.\n");
  121. return &ahci_port_seattle_info;
  122. }
  123. static int ahci_seattle_probe(struct platform_device *pdev)
  124. {
  125. int rc;
  126. struct ahci_host_priv *hpriv;
  127. hpriv = ahci_platform_get_resources(pdev, 0);
  128. if (IS_ERR(hpriv))
  129. return PTR_ERR(hpriv);
  130. rc = ahci_platform_enable_resources(hpriv);
  131. if (rc)
  132. return rc;
  133. rc = ahci_platform_init_host(pdev, hpriv,
  134. ahci_seattle_get_port_info(pdev, hpriv),
  135. &ahci_platform_sht);
  136. if (rc)
  137. goto disable_resources;
  138. return 0;
  139. disable_resources:
  140. ahci_platform_disable_resources(hpriv);
  141. return rc;
  142. }
  143. static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
  144. ahci_platform_resume);
  145. static const struct acpi_device_id ahci_acpi_match[] = {
  146. { "AMDI0600", 0 },
  147. {}
  148. };
  149. MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
  150. static struct platform_driver ahci_seattle_driver = {
  151. .probe = ahci_seattle_probe,
  152. .remove_new = ata_platform_remove_one,
  153. .driver = {
  154. .name = DRV_NAME,
  155. .acpi_match_table = ahci_acpi_match,
  156. .pm = &ahci_pm_ops,
  157. },
  158. };
  159. module_platform_driver(ahci_seattle_driver);
  160. MODULE_DESCRIPTION("Seattle AHCI SATA platform driver");
  161. MODULE_AUTHOR("Brijesh Singh <brijesh.singh@amd.com>");
  162. MODULE_LICENSE("GPL");
  163. MODULE_ALIAS("platform:" DRV_NAME);