drivers/ata/ahci_dm816.c
Source file repositories/reference/linux-study-clean/drivers/ata/ahci_dm816.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ata/ahci_dm816.c- Extension
.c- Size
- 5121 bytes
- Lines
- 197
- Domain
- Driver Families
- Bucket
- drivers/ata
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/device.hlinux/pm.hlinux/platform_device.hlinux/libata.hlinux/ahci_platform.hahci.h
Detected Declarations
function ahci_dm816_get_mpy_bitsfunction ahci_dm816_phy_initfunction ahci_dm816_softresetfunction ahci_dm816_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* DaVinci DM816 AHCI SATA platform driver
*
* Copyright (C) 2017 BayLibre SAS
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/pm.h>
#include <linux/platform_device.h>
#include <linux/libata.h>
#include <linux/ahci_platform.h>
#include "ahci.h"
#define AHCI_DM816_DRV_NAME "ahci-dm816"
#define AHCI_DM816_PHY_ENPLL(x) ((x) << 0)
#define AHCI_DM816_PHY_MPY(x) ((x) << 1)
#define AHCI_DM816_PHY_LOS(x) ((x) << 12)
#define AHCI_DM816_PHY_RXCDR(x) ((x) << 13)
#define AHCI_DM816_PHY_RXEQ(x) ((x) << 16)
#define AHCI_DM816_PHY_TXSWING(x) ((x) << 23)
#define AHCI_DM816_P0PHYCR_REG 0x178
#define AHCI_DM816_P1PHYCR_REG 0x1f8
#define AHCI_DM816_PLL_OUT 1500000000LU
static const unsigned long pll_mpy_table[] = {
400, 500, 600, 800, 825, 1000, 1200,
1250, 1500, 1600, 1650, 2000, 2200, 2500
};
static int ahci_dm816_get_mpy_bits(unsigned long refclk_rate)
{
unsigned long pll_multiplier;
int i;
/*
* We need to determine the value of the multiplier (MPY) bits.
* In order to include the 8.25 multiplier we need to first divide
* the refclk rate by 100.
*/
pll_multiplier = AHCI_DM816_PLL_OUT / (refclk_rate / 100);
for (i = 0; i < ARRAY_SIZE(pll_mpy_table); i++) {
if (pll_mpy_table[i] == pll_multiplier)
return i;
}
/*
* We should have divided evenly - if not, return an invalid
* value.
*/
return -1;
}
static int ahci_dm816_phy_init(struct ahci_host_priv *hpriv, struct device *dev)
{
unsigned long refclk_rate;
int mpy;
u32 val;
/*
* We should have been supplied two clocks: the functional and
* keep-alive clock and the external reference clock. We need the
* rate of the latter to calculate the correct value of MPY bits.
*/
if (hpriv->n_clks < 2) {
dev_err(dev, "reference clock not supplied\n");
return -EINVAL;
}
refclk_rate = clk_get_rate(hpriv->clks[1].clk);
if ((refclk_rate % 100) != 0) {
dev_err(dev, "reference clock rate must be divisible by 100\n");
return -EINVAL;
}
mpy = ahci_dm816_get_mpy_bits(refclk_rate);
if (mpy < 0) {
dev_err(dev, "can't calculate the MPY bits value\n");
return -EINVAL;
}
/* Enable the PHY and configure the first HBA port. */
val = AHCI_DM816_PHY_MPY(mpy) | AHCI_DM816_PHY_LOS(1) |
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/device.h`, `linux/pm.h`, `linux/platform_device.h`, `linux/libata.h`, `linux/ahci_platform.h`, `ahci.h`.
- Detected declarations: `function ahci_dm816_get_mpy_bits`, `function ahci_dm816_phy_init`, `function ahci_dm816_softreset`, `function ahci_dm816_probe`.
- Atlas domain: Driver Families / drivers/ata.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.