Skip to content

Commit 426c8d8

Browse files
rajanv-xilinxgregkh
authored andcommitted
firmware: xilinx: Use APIs instead of IOCTLs
Remove IOCTL API and use individual APIs for better readability. Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com> Signed-off-by: Jolly Shah <jolly.shah@xilinx.com> Link: https://lore.kernel.org/r/1587761887-4279-12-git-send-email-jolly.shah@xilinx.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 70c0d36 commit 426c8d8

4 files changed

Lines changed: 126 additions & 75 deletions

File tree

‎drivers/clk/zynqmp/pll.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ static inline enum pll_mode zynqmp_pll_get_mode(struct clk_hw *hw)
5050
const char *clk_name = clk_hw_get_name(hw);
5151
u32 ret_payload[PAYLOAD_ARG_CNT];
5252
int ret;
53-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
5453

55-
ret = eemi_ops->ioctl(0, IOCTL_GET_PLL_FRAC_MODE, clk_id, 0,
56-
ret_payload);
54+
ret = zynqmp_pm_get_pll_frac_mode(clk_id, ret_payload);
5755
if (ret)
5856
pr_warn_once("%s() PLL get frac mode failed for %s, ret = %d\n",
5957
__func__, clk_name, ret);
@@ -73,14 +71,13 @@ static inline void zynqmp_pll_set_mode(struct clk_hw *hw, bool on)
7371
const char *clk_name = clk_hw_get_name(hw);
7472
int ret;
7573
u32 mode;
76-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
7774

7875
if (on)
7976
mode = PLL_MODE_FRAC;
8077
else
8178
mode = PLL_MODE_INT;
8279

83-
ret = eemi_ops->ioctl(0, IOCTL_SET_PLL_FRAC_MODE, clk_id, mode, NULL);
80+
ret = zynqmp_pm_set_pll_frac_mode(clk_id, mode);
8481
if (ret)
8582
pr_warn_once("%s() PLL set frac mode failed for %s, ret = %d\n",
8683
__func__, clk_name, ret);
@@ -139,7 +136,6 @@ static unsigned long zynqmp_pll_recalc_rate(struct clk_hw *hw,
139136
unsigned long rate, frac;
140137
u32 ret_payload[PAYLOAD_ARG_CNT];
141138
int ret;
142-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
143139

144140
ret = zynqmp_pm_clock_getdivider(clk_id, &fbdiv);
145141
if (ret)
@@ -148,8 +144,7 @@ static unsigned long zynqmp_pll_recalc_rate(struct clk_hw *hw,
148144

149145
rate = parent_rate * fbdiv;
150146
if (zynqmp_pll_get_mode(hw) == PLL_MODE_FRAC) {
151-
eemi_ops->ioctl(0, IOCTL_GET_PLL_FRAC_DATA, clk_id, 0,
152-
ret_payload);
147+
zynqmp_pm_get_pll_frac_data(clk_id, ret_payload);
153148
data = ret_payload[1];
154149
frac = (parent_rate * data) / FRAC_DIV;
155150
rate = rate + frac;
@@ -177,7 +172,6 @@ static int zynqmp_pll_set_rate(struct clk_hw *hw, unsigned long rate,
177172
u32 fbdiv;
178173
long rate_div, frac, m, f;
179174
int ret;
180-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
181175

182176
if (zynqmp_pll_get_mode(hw) == PLL_MODE_FRAC) {
183177
rate_div = (rate * FRAC_DIV) / parent_rate;
@@ -194,7 +188,7 @@ static int zynqmp_pll_set_rate(struct clk_hw *hw, unsigned long rate,
194188
else if (ret)
195189
pr_warn_once("%s() set divider failed for %s, ret = %d\n",
196190
__func__, clk_name, ret);
197-
eemi_ops->ioctl(0, IOCTL_SET_PLL_FRAC_DATA, clk_id, f, NULL);
191+
zynqmp_pm_set_pll_frac_data(clk_id, f);
198192

199193
return rate + frac;
200194
}

‎drivers/firmware/xilinx/zynqmp.c‎

Lines changed: 89 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -516,47 +516,108 @@ int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id)
516516
EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getparent);
517517

518518
/**
519-
* zynqmp_is_valid_ioctl() - Check whether IOCTL ID is valid or not
520-
* @ioctl_id: IOCTL ID
519+
* zynqmp_pm_set_pll_frac_mode() - PM API for set PLL mode
521520
*
522-
* Return: 1 if IOCTL is valid else 0
521+
* @clk_id: PLL clock ID
522+
* @mode: PLL mode (PLL_MODE_FRAC/PLL_MODE_INT)
523+
*
524+
* This function sets PLL mode
525+
*
526+
* Return: Returns status, either success or error+reason
523527
*/
524-
static inline int zynqmp_is_valid_ioctl(u32 ioctl_id)
528+
int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode)
525529
{
526-
switch (ioctl_id) {
527-
case IOCTL_SD_DLL_RESET:
528-
case IOCTL_SET_SD_TAPDELAY:
529-
case IOCTL_SET_PLL_FRAC_MODE:
530-
case IOCTL_GET_PLL_FRAC_MODE:
531-
case IOCTL_SET_PLL_FRAC_DATA:
532-
case IOCTL_GET_PLL_FRAC_DATA:
533-
return 1;
534-
default:
535-
return 0;
536-
}
530+
return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_MODE,
531+
clk_id, mode, NULL);
537532
}
533+
EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_mode);
538534

539535
/**
540-
* zynqmp_pm_ioctl() - PM IOCTL API for device control and configs
541-
* @node_id: Node ID of the device
542-
* @ioctl_id: ID of the requested IOCTL
543-
* @arg1: Argument 1 to requested IOCTL call
544-
* @arg2: Argument 2 to requested IOCTL call
545-
* @out: Returned output value
536+
* zynqmp_pm_get_pll_frac_mode() - PM API for get PLL mode
537+
*
538+
* @clk_id: PLL clock ID
539+
* @mode: PLL mode
546540
*
547-
* This function calls IOCTL to firmware for device control and configuration.
541+
* This function return current PLL mode
548542
*
549543
* Return: Returns status, either success or error+reason
550544
*/
551-
static int zynqmp_pm_ioctl(u32 node_id, u32 ioctl_id, u32 arg1, u32 arg2,
552-
u32 *out)
545+
int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode)
553546
{
554-
if (!zynqmp_is_valid_ioctl(ioctl_id))
555-
return -EINVAL;
547+
return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_MODE,
548+
clk_id, 0, mode);
549+
}
550+
EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_mode);
551+
552+
/**
553+
* zynqmp_pm_set_pll_frac_data() - PM API for setting pll fraction data
554+
*
555+
* @clk_id: PLL clock ID
556+
* @data: fraction data
557+
*
558+
* This function sets fraction data.
559+
* It is valid for fraction mode only.
560+
*
561+
* Return: Returns status, either success or error+reason
562+
*/
563+
int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data)
564+
{
565+
return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_DATA,
566+
clk_id, data, NULL);
567+
}
568+
EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_data);
569+
570+
/**
571+
* zynqmp_pm_get_pll_frac_data() - PM API for getting pll fraction data
572+
*
573+
* @clk_id: PLL clock ID
574+
* @data: fraction data
575+
*
576+
* This function returns fraction data value.
577+
*
578+
* Return: Returns status, either success or error+reason
579+
*/
580+
int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data)
581+
{
582+
return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_DATA,
583+
clk_id, 0, data);
584+
}
585+
EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_data);
556586

557-
return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, ioctl_id,
558-
arg1, arg2, out);
587+
/**
588+
* zynqmp_pm_set_sd_tapdelay() - Set tap delay for the SD device
589+
*
590+
* @node_id Node ID of the device
591+
* @type Type of tap delay to set (input/output)
592+
* @value Value to set fot the tap delay
593+
*
594+
* This function sets input/output tap delay for the SD device.
595+
*
596+
* @return Returns status, either success or error+reason
597+
*/
598+
int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value)
599+
{
600+
return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, IOCTL_SET_SD_TAPDELAY,
601+
type, value, NULL);
602+
}
603+
EXPORT_SYMBOL_GPL(zynqmp_pm_set_sd_tapdelay);
604+
605+
/**
606+
* zynqmp_pm_sd_dll_reset() - Reset DLL logic
607+
*
608+
* @node_id Node ID of the device
609+
* @type Reset type
610+
*
611+
* This function resets DLL logic for the SD device.
612+
*
613+
* @return Returns status, either success or error+reason
614+
*/
615+
int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type)
616+
{
617+
return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, IOCTL_SET_SD_TAPDELAY,
618+
type, 0, NULL);
559619
}
620+
EXPORT_SYMBOL_GPL(zynqmp_pm_sd_dll_reset);
560621

561622
/**
562623
* zynqmp_pm_reset_assert - Request setting of reset (1 - assert, 0 - release)
@@ -746,7 +807,6 @@ static int zynqmp_pm_aes_engine(const u64 address, u32 *out)
746807
}
747808

748809
static const struct zynqmp_eemi_ops eemi_ops = {
749-
.ioctl = zynqmp_pm_ioctl,
750810
.reset_assert = zynqmp_pm_reset_assert,
751811
.reset_get_status = zynqmp_pm_reset_get_status,
752812
.init_finalize = zynqmp_pm_init_finalize,

‎drivers/mmc/host/sdhci-of-arasan.c‎

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ struct sdhci_arasan_clk_data {
9898
void *clk_of_data;
9999
};
100100

101-
struct sdhci_arasan_zynqmp_clk_data {
102-
const struct zynqmp_eemi_ops *eemi_ops;
103-
};
104-
105101
/**
106102
* struct sdhci_arasan_data
107103
* @host: Pointer to the main SDHCI host structure.
@@ -630,9 +626,6 @@ static int sdhci_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
630626
struct sdhci_arasan_data *sdhci_arasan =
631627
container_of(clk_data, struct sdhci_arasan_data, clk_data);
632628
struct sdhci_host *host = sdhci_arasan->host;
633-
struct sdhci_arasan_zynqmp_clk_data *zynqmp_clk_data =
634-
clk_data->clk_of_data;
635-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_clk_data->eemi_ops;
636629
const char *clk_name = clk_hw_get_name(hw);
637630
u32 node_id = !strcmp(clk_name, "clk_out_sd0") ? NODE_SD_0 : NODE_SD_1;
638631
u8 tap_delay, tap_max = 0;
@@ -672,8 +665,7 @@ static int sdhci_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
672665
tap_delay = (degrees * tap_max) / 360;
673666

674667
/* Set the Clock Phase */
675-
ret = eemi_ops->ioctl(node_id, IOCTL_SET_SD_TAPDELAY,
676-
PM_TAPDELAY_OUTPUT, tap_delay, NULL);
668+
ret = zynqmp_pm_set_sd_tapdelay(node_id, PM_TAPDELAY_OUTPUT, tap_delay);
677669
if (ret)
678670
pr_err("Error setting Output Tap Delay\n");
679671

@@ -702,9 +694,6 @@ static int sdhci_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)
702694
struct sdhci_arasan_data *sdhci_arasan =
703695
container_of(clk_data, struct sdhci_arasan_data, clk_data);
704696
struct sdhci_host *host = sdhci_arasan->host;
705-
struct sdhci_arasan_zynqmp_clk_data *zynqmp_clk_data =
706-
clk_data->clk_of_data;
707-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_clk_data->eemi_ops;
708697
const char *clk_name = clk_hw_get_name(hw);
709698
u32 node_id = !strcmp(clk_name, "clk_in_sd0") ? NODE_SD_0 : NODE_SD_1;
710699
u8 tap_delay, tap_max = 0;
@@ -744,8 +733,7 @@ static int sdhci_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)
744733
tap_delay = (degrees * tap_max) / 360;
745734

746735
/* Set the Clock Phase */
747-
ret = eemi_ops->ioctl(node_id, IOCTL_SET_SD_TAPDELAY,
748-
PM_TAPDELAY_INPUT, tap_delay, NULL);
736+
ret = zynqmp_pm_set_sd_tapdelay(node_id, PM_TAPDELAY_INPUT, tap_delay);
749737
if (ret)
750738
pr_err("Error setting Input Tap Delay\n");
751739

@@ -759,20 +747,14 @@ static const struct clk_ops zynqmp_sampleclk_ops = {
759747

760748
static void arasan_zynqmp_dll_reset(struct sdhci_host *host, u32 deviceid)
761749
{
762-
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
763-
struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host);
764-
struct sdhci_arasan_zynqmp_clk_data *zynqmp_clk_data =
765-
sdhci_arasan->clk_data.clk_of_data;
766-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_clk_data->eemi_ops;
767750
u16 clk;
768751

769752
clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
770753
clk &= ~(SDHCI_CLOCK_CARD_EN | SDHCI_CLOCK_INT_EN);
771754
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
772755

773756
/* Issue DLL Reset */
774-
eemi_ops->ioctl(deviceid, IOCTL_SD_DLL_RESET,
775-
PM_DLL_RESET_PULSE, 0, NULL);
757+
zynqmp_pm_sd_dll_reset(deviceid, PM_DLL_RESET_PULSE);
776758

777759
clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
778760

@@ -1277,20 +1259,6 @@ static int sdhci_arasan_probe(struct platform_device *pdev)
12771259
goto clk_disable_all;
12781260

12791261
if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) {
1280-
struct sdhci_arasan_zynqmp_clk_data *zynqmp_clk_data;
1281-
const struct zynqmp_eemi_ops *eemi_ops;
1282-
1283-
zynqmp_clk_data = devm_kzalloc(&pdev->dev,
1284-
sizeof(*zynqmp_clk_data),
1285-
GFP_KERNEL);
1286-
eemi_ops = zynqmp_pm_get_eemi_ops();
1287-
if (IS_ERR(eemi_ops)) {
1288-
ret = PTR_ERR(eemi_ops);
1289-
goto unreg_clk;
1290-
}
1291-
1292-
zynqmp_clk_data->eemi_ops = eemi_ops;
1293-
sdhci_arasan->clk_data.clk_of_data = zynqmp_clk_data;
12941262
host->mmc_host_ops.execute_tuning =
12951263
arasan_zynqmp_execute_tuning;
12961264
}

‎include/linux/firmware/xlnx-zynqmp.h‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ struct zynqmp_pm_query_data {
296296
struct zynqmp_eemi_ops {
297297
int (*fpga_load)(const u64 address, const u32 size, const u32 flags);
298298
int (*fpga_get_status)(u32 *value);
299-
int (*ioctl)(u32 node_id, u32 ioctl_id, u32 arg1, u32 arg2, u32 *out);
300299
int (*reset_assert)(const enum zynqmp_pm_reset reset,
301300
const enum zynqmp_pm_reset_action assert_flag);
302301
int (*reset_get_status)(const enum zynqmp_pm_reset reset, u32 *status);
@@ -331,6 +330,12 @@ int zynqmp_pm_clock_setrate(u32 clock_id, u64 rate);
331330
int zynqmp_pm_clock_getrate(u32 clock_id, u64 *rate);
332331
int zynqmp_pm_clock_setparent(u32 clock_id, u32 parent_id);
333332
int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id);
333+
int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode);
334+
int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode);
335+
int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data);
336+
int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data);
337+
int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value);
338+
int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type);
334339
#else
335340
static inline struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
336341
{
@@ -385,6 +390,30 @@ static inline int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id)
385390
{
386391
return -ENODEV;
387392
}
393+
static inline int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode)
394+
{
395+
return -ENODEV;
396+
}
397+
static inline int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode)
398+
{
399+
return -ENODEV;
400+
}
401+
static inline int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data)
402+
{
403+
return -ENODEV;
404+
}
405+
static inline int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data)
406+
{
407+
return -ENODEV;
408+
}
409+
static inline int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value)
410+
{
411+
return -ENODEV;
412+
}
413+
static inline int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type)
414+
{
415+
return -ENODEV;
416+
}
388417
#endif
389418

390419
#endif /* __FIRMWARE_ZYNQMP_H__ */

0 commit comments

Comments
 (0)