// 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 <[email protected]> */ #include <linux/mfd/syscon/atmel-smc.h> #include <linux/string.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) { … } EXPORT_SYMBOL_GPL(…); /** * 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) { … } /** * 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 * parameter * * This function encodes the @ncycles value as described in the datasheet * (section "SMC Timings Register"), and then stores the result in the * @conf->timings field at @shift position. * * Returns -EINVAL if shift is invalid, -ERANGE if ncycles does not fit in * the field, and 0 otherwise. */ int atmel_smc_cs_conf_set_timing(struct atmel_smc_cs_conf *conf, unsigned int shift, unsigned int ncycles) { … } EXPORT_SYMBOL_GPL(…); /** * atmel_smc_cs_conf_set_setup - set the SMC CS conf xx_SETUP parameter to a * specific value * @conf: SMC CS conf descriptor * @shift: the position of the xx_SETUP field in the SETUP register * @ncycles: value (expressed in MCK clk cycles) to assign to this xx_SETUP * parameter * * This function encodes the @ncycles value as described in the datasheet * (section "SMC Setup Register"), and then stores the result in the * @conf->setup field at @shift position. * * Returns -EINVAL if @shift is invalid, -ERANGE if @ncycles does not fit in * the field, and 0 otherwise. */ int atmel_smc_cs_conf_set_setup(struct atmel_smc_cs_conf *conf, unsigned int shift, unsigned int ncycles) { … } EXPORT_SYMBOL_GPL(…); /** * atmel_smc_cs_conf_set_pulse - set the SMC CS conf xx_PULSE parameter to a * specific value * @conf: SMC CS conf descriptor * @shift: the position of the xx_PULSE field in the PULSE register * @ncycles: value (expressed in MCK clk cycles) to assign to this xx_PULSE * parameter * * This function encodes the @ncycles value as described in the datasheet * (section "SMC Pulse Register"), and then stores the result in the * @conf->setup field at @shift position. * * Returns -EINVAL if @shift is invalid, -ERANGE if @ncycles does not fit in * the field, and 0 otherwise. */ int atmel_smc_cs_conf_set_pulse(struct atmel_smc_cs_conf *conf, unsigned int shift, unsigned int ncycles) { … } EXPORT_SYMBOL_GPL(…); /** * atmel_smc_cs_conf_set_cycle - set the SMC CS conf xx_CYCLE parameter to a * specific value * @conf: SMC CS conf descriptor * @shift: the position of the xx_CYCLE field in the CYCLE register * @ncycles: value (expressed in MCK clk cycles) to assign to this xx_CYCLE * parameter * * This function encodes the @ncycles value as described in the datasheet * (section "SMC Cycle Register"), and then stores the result in the * @conf->setup field at @shift position. * * Returns -EINVAL if @shift is invalid, -ERANGE if @ncycles does not fit in * the field, and 0 otherwise. */ int atmel_smc_cs_conf_set_cycle(struct atmel_smc_cs_conf *conf, unsigned int shift, unsigned int ncycles) { … } EXPORT_SYMBOL_GPL(…); /** * atmel_smc_cs_conf_apply - apply an SMC CS conf * @regmap: the SMC regmap * @cs: the CS id * @conf: the SMC CS conf to apply * * Applies an SMC CS configuration. * Only valid on at91sam9 SoCs. */ void atmel_smc_cs_conf_apply(struct regmap *regmap, int cs, const struct atmel_smc_cs_conf *conf) { … } EXPORT_SYMBOL_GPL(…); /** * atmel_hsmc_cs_conf_apply - apply an SMC CS conf * @regmap: the HSMC regmap * @cs: the CS id * @layout: the layout of registers * @conf: the SMC CS conf to apply * * Applies an SMC CS configuration. * Only valid on post-sama5 SoCs. */ void atmel_hsmc_cs_conf_apply(struct regmap *regmap, const struct atmel_hsmc_reg_layout *layout, int cs, const struct atmel_smc_cs_conf *conf) { … } EXPORT_SYMBOL_GPL(…); /** * atmel_smc_cs_conf_get - retrieve the current SMC CS conf * @regmap: the SMC regmap * @cs: the CS id * @conf: the SMC CS conf object to store the current conf * * Retrieve the SMC CS configuration. * Only valid on at91sam9 SoCs. */ void atmel_smc_cs_conf_get(struct regmap *regmap, int cs, struct atmel_smc_cs_conf *conf) { … } EXPORT_SYMBOL_GPL(…); /** * atmel_hsmc_cs_conf_get - retrieve the current SMC CS conf * @regmap: the HSMC regmap * @cs: the CS id * @layout: the layout of registers * @conf: the SMC CS conf object to store the current conf * * Retrieve the SMC CS configuration. * Only valid on post-sama5 SoCs. */ void atmel_hsmc_cs_conf_get(struct regmap *regmap, const struct atmel_hsmc_reg_layout *layout, int cs, struct atmel_smc_cs_conf *conf) { … } EXPORT_SYMBOL_GPL(…); static const struct atmel_hsmc_reg_layout sama5d3_reg_layout = …; static const struct atmel_hsmc_reg_layout sama5d2_reg_layout = …; static const struct of_device_id atmel_smc_ids[] __maybe_unused = …; /** * atmel_hsmc_get_reg_layout - retrieve the layout of HSMC registers * @np: the HSMC regmap * * Retrieve the layout of HSMC registers. * * Returns NULL in case of SMC, a struct atmel_hsmc_reg_layout pointer * in HSMC case, otherwise ERR_PTR(-EINVAL). */ const struct atmel_hsmc_reg_layout * atmel_hsmc_get_reg_layout(struct device_node *np) { … } EXPORT_SYMBOL_GPL(…);