drivers/mfd/atmel-smc.c
Source file repositories/reference/linux-study-clean/drivers/mfd/atmel-smc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mfd/atmel-smc.c- Extension
.c- Size
- 11107 bytes
- Lines
- 359
- Domain
- Driver Families
- Bucket
- drivers/mfd
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/err.hlinux/export.hlinux/mod_devicetable.hlinux/of.hlinux/regmap.hlinux/string.hlinux/mfd/syscon/atmel-smc.h
Detected Declarations
function SMCfunction atmel_smc_cs_encode_ncyclesfunction atmel_smc_cs_conf_set_timingfunction atmel_smc_cs_conf_set_setupfunction atmel_smc_cs_conf_set_pulsefunction atmel_smc_cs_conf_set_cyclefunction atmel_smc_cs_conf_applyfunction atmel_hsmc_cs_conf_applyfunction atmel_smc_cs_conf_getfunction atmel_hsmc_cs_conf_getfunction atmel_hsmc_get_reg_layoutexport atmel_smc_cs_conf_initexport atmel_smc_cs_conf_set_timingexport atmel_smc_cs_conf_set_setupexport atmel_smc_cs_conf_set_pulseexport atmel_smc_cs_conf_set_cycleexport atmel_smc_cs_conf_applyexport atmel_hsmc_cs_conf_applyexport atmel_smc_cs_conf_getexport atmel_hsmc_cs_conf_getexport atmel_hsmc_get_reg_layout
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Atmel SMC (Static Memory Controller) helper functions.
*
* Copyright (C) 2017 Atmel
* Copyright (C) 2017 Free Electrons
*
* Author: Boris Brezillon <boris.brezillon@free-electrons.com>
*/
#include <linux/bits.h>
#include <linux/err.h>
#include <linux/export.h>
#include <linux/mod_devicetable.h>
#include <linux/of.h>
#include <linux/regmap.h>
#include <linux/string.h>
#include <linux/mfd/syscon/atmel-smc.h>
/**
* atmel_smc_cs_conf_init - initialize a SMC CS conf
* @conf: the SMC CS conf to initialize
*
* Set all fields to 0 so that one can start defining a new config.
*/
void atmel_smc_cs_conf_init(struct atmel_smc_cs_conf *conf)
{
memset(conf, 0, sizeof(*conf));
}
EXPORT_SYMBOL_GPL(atmel_smc_cs_conf_init);
/**
* atmel_smc_cs_encode_ncycles - encode a number of MCK clk cycles in the
* format expected by the SMC engine
* @ncycles: number of MCK clk cycles
* @msbpos: position of the MSB part of the timing field
* @msbwidth: width of the MSB part of the timing field
* @msbfactor: factor applied to the MSB
* @encodedval: param used to store the encoding result
*
* This function encodes the @ncycles value as described in the datasheet
* (section "SMC Setup/Pulse/Cycle/Timings Register"). This is a generic
* helper which called with different parameter depending on the encoding
* scheme.
*
* If the @ncycles value is too big to be encoded, -ERANGE is returned and
* the encodedval is contains the maximum val. Otherwise, 0 is returned.
*/
static int atmel_smc_cs_encode_ncycles(unsigned int ncycles,
unsigned int msbpos,
unsigned int msbwidth,
unsigned int msbfactor,
unsigned int *encodedval)
{
unsigned int lsbmask = GENMASK(msbpos - 1, 0);
unsigned int msbmask = GENMASK(msbwidth - 1, 0);
unsigned int msb, lsb;
int ret = 0;
msb = ncycles / msbfactor;
lsb = ncycles % msbfactor;
if (lsb > lsbmask) {
lsb = 0;
msb++;
}
/*
* Let's just put the maximum we can if the requested setting does
* not fit in the register field.
* We still return -ERANGE in case the caller cares.
*/
if (msb > msbmask) {
msb = msbmask;
lsb = lsbmask;
ret = -ERANGE;
}
*encodedval = (msb << msbpos) | lsb;
return ret;
}
/**
* atmel_smc_cs_conf_set_timing - set the SMC CS conf Txx parameter to a
* specific value
* @conf: SMC CS conf descriptor
* @shift: the position of the Txx field in the TIMINGS register
* @ncycles: value (expressed in MCK clk cycles) to assign to this Txx
Annotation
- Immediate include surface: `linux/bits.h`, `linux/err.h`, `linux/export.h`, `linux/mod_devicetable.h`, `linux/of.h`, `linux/regmap.h`, `linux/string.h`, `linux/mfd/syscon/atmel-smc.h`.
- Detected declarations: `function SMC`, `function atmel_smc_cs_encode_ncycles`, `function atmel_smc_cs_conf_set_timing`, `function atmel_smc_cs_conf_set_setup`, `function atmel_smc_cs_conf_set_pulse`, `function atmel_smc_cs_conf_set_cycle`, `function atmel_smc_cs_conf_apply`, `function atmel_hsmc_cs_conf_apply`, `function atmel_smc_cs_conf_get`, `function atmel_hsmc_cs_conf_get`.
- Atlas domain: Driver Families / drivers/mfd.
- Implementation status: integration 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.