ahci_seattle.c 5.0 KB

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