ahci_seattle.c 5.4 KB

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