Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * @File	ctamixer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * @Brief
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This file contains the implementation of the Audio Mixer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * resource management object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * @Author	Liu Chun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * @Date 	May 21 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "ctamixer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "cthardware.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define AMIXER_RESOURCE_NUM	256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define SUM_RESOURCE_NUM	256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define AMIXER_Y_IMMEDIATE	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define BLANK_SLOT		4094
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static void amixer_master(struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	rsc->conj = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	rsc->idx = container_of(rsc, struct amixer, rsc)->idx[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static void amixer_next_conj(struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	rsc->conj++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int amixer_index(const struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	return container_of(rsc, struct amixer, rsc)->idx[rsc->conj];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int amixer_output_slot(const struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	return (amixer_index(rsc) << 4) + 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static const struct rsc_ops amixer_basic_rsc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.master		= amixer_master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.next_conj	= amixer_next_conj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.index		= amixer_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.output_slot	= amixer_output_slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static int amixer_set_input(struct amixer *amixer, struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	hw = amixer->rsc.hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	hw->amixer_set_mode(amixer->rsc.ctrl_blk, AMIXER_Y_IMMEDIATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	amixer->input = rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (!rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		hw->amixer_set_x(amixer->rsc.ctrl_blk, BLANK_SLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		hw->amixer_set_x(amixer->rsc.ctrl_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 					rsc->ops->output_slot(rsc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /* y is a 14-bit immediate constant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int amixer_set_y(struct amixer *amixer, unsigned int y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	hw = amixer->rsc.hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	hw->amixer_set_y(amixer->rsc.ctrl_blk, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int amixer_set_invalid_squash(struct amixer *amixer, unsigned int iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	hw = amixer->rsc.hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	hw->amixer_set_iv(amixer->rsc.ctrl_blk, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int amixer_set_sum(struct amixer *amixer, struct sum *sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	hw = amixer->rsc.hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	amixer->sum = sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!sum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		hw->amixer_set_se(amixer->rsc.ctrl_blk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		hw->amixer_set_se(amixer->rsc.ctrl_blk, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		hw->amixer_set_sadr(amixer->rsc.ctrl_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 					sum->rsc.ops->index(&sum->rsc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int amixer_commit_write(struct amixer *amixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct rsc *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct sum *sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	hw = amixer->rsc.hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	input = amixer->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	sum = amixer->sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* Program master and conjugate resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	amixer->rsc.ops->master(&amixer->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		input->ops->master(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		sum->rsc.ops->master(&sum->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	for (i = 0; i < amixer->rsc.msr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		hw->amixer_set_dirty_all(amixer->rsc.ctrl_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			hw->amixer_set_x(amixer->rsc.ctrl_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 						input->ops->output_slot(input));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			input->ops->next_conj(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (sum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			hw->amixer_set_sadr(amixer->rsc.ctrl_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 						sum->rsc.ops->index(&sum->rsc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			sum->rsc.ops->next_conj(&sum->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		index = amixer->rsc.ops->output_slot(&amixer->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		hw->amixer_commit_write(hw, index, amixer->rsc.ctrl_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		amixer->rsc.ops->next_conj(&amixer->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	amixer->rsc.ops->master(&amixer->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		input->ops->master(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		sum->rsc.ops->master(&sum->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int amixer_commit_raw_write(struct amixer *amixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	hw = amixer->rsc.hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	index = amixer->rsc.ops->output_slot(&amixer->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	hw->amixer_commit_write(hw, index, amixer->rsc.ctrl_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int amixer_get_y(struct amixer *amixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	hw = amixer->rsc.hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return hw->amixer_get_y(amixer->rsc.ctrl_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int amixer_setup(struct amixer *amixer, struct rsc *input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			unsigned int scale, struct sum *sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	amixer_set_input(amixer, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	amixer_set_y(amixer, scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	amixer_set_sum(amixer, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	amixer_commit_write(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static const struct amixer_rsc_ops amixer_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.set_input		= amixer_set_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	.set_invalid_squash	= amixer_set_invalid_squash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	.set_scale		= amixer_set_y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.set_sum		= amixer_set_sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.commit_write		= amixer_commit_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.commit_raw_write	= amixer_commit_raw_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.setup			= amixer_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.get_scale		= amixer_get_y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static int amixer_rsc_init(struct amixer *amixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			   const struct amixer_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			   struct amixer_mgr *mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	err = rsc_init(&amixer->rsc, amixer->idx[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			AMIXER, desc->msr, mgr->mgr.hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	/* Set amixer specific operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	amixer->rsc.ops = &amixer_basic_rsc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	amixer->ops = &amixer_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	amixer->input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	amixer->sum = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	amixer_setup(amixer, NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int amixer_rsc_uninit(struct amixer *amixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	amixer_setup(amixer, NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	rsc_uninit(&amixer->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	amixer->ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	amixer->input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	amixer->sum = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int get_amixer_rsc(struct amixer_mgr *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			  const struct amixer_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			  struct amixer **ramixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct amixer *amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	*ramixer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* Allocate mem for amixer resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	amixer = kzalloc(sizeof(*amixer), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (!amixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/* Check whether there are sufficient
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 * amixer resources to meet request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	spin_lock_irqsave(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	for (i = 0; i < desc->msr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		err = mgr_get_resource(&mgr->mgr, 1, &idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		amixer->idx[i] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		dev_err(mgr->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			"Can't meet AMIXER resource request!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	err = amixer_rsc_init(amixer, desc, mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	*ramixer = amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	spin_lock_irqsave(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		mgr_put_resource(&mgr->mgr, 1, amixer->idx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	kfree(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int put_amixer_rsc(struct amixer_mgr *mgr, struct amixer *amixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	spin_lock_irqsave(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	for (i = 0; i < amixer->rsc.msr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		mgr_put_resource(&mgr->mgr, 1, amixer->idx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	amixer_rsc_uninit(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	kfree(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int amixer_mgr_create(struct hw *hw, struct amixer_mgr **ramixer_mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct amixer_mgr *amixer_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	*ramixer_mgr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	amixer_mgr = kzalloc(sizeof(*amixer_mgr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (!amixer_mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	err = rsc_mgr_init(&amixer_mgr->mgr, AMIXER, AMIXER_RESOURCE_NUM, hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	spin_lock_init(&amixer_mgr->mgr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	amixer_mgr->get_amixer = get_amixer_rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	amixer_mgr->put_amixer = put_amixer_rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	amixer_mgr->card = hw->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	*ramixer_mgr = amixer_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	kfree(amixer_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int amixer_mgr_destroy(struct amixer_mgr *amixer_mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	rsc_mgr_uninit(&amixer_mgr->mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	kfree(amixer_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* SUM resource management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static void sum_master(struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	rsc->conj = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	rsc->idx = container_of(rsc, struct sum, rsc)->idx[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void sum_next_conj(struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	rsc->conj++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int sum_index(const struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	return container_of(rsc, struct sum, rsc)->idx[rsc->conj];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static int sum_output_slot(const struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return (sum_index(rsc) << 4) + 0xc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static const struct rsc_ops sum_basic_rsc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	.master		= sum_master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	.next_conj	= sum_next_conj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	.index		= sum_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	.output_slot	= sum_output_slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int sum_rsc_init(struct sum *sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			const struct sum_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			struct sum_mgr *mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	err = rsc_init(&sum->rsc, sum->idx[0], SUM, desc->msr, mgr->mgr.hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	sum->rsc.ops = &sum_basic_rsc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static int sum_rsc_uninit(struct sum *sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	rsc_uninit(&sum->rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static int get_sum_rsc(struct sum_mgr *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		       const struct sum_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		       struct sum **rsum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct sum *sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	*rsum = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	/* Allocate mem for sum resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	sum = kzalloc(sizeof(*sum), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (!sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	/* Check whether there are sufficient sum resources to meet request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	spin_lock_irqsave(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	for (i = 0; i < desc->msr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		err = mgr_get_resource(&mgr->mgr, 1, &idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		sum->idx[i] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		dev_err(mgr->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			"Can't meet SUM resource request!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	err = sum_rsc_init(sum, desc, mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	*rsum = sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	spin_lock_irqsave(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		mgr_put_resource(&mgr->mgr, 1, sum->idx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	kfree(sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static int put_sum_rsc(struct sum_mgr *mgr, struct sum *sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	spin_lock_irqsave(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	for (i = 0; i < sum->rsc.msr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		mgr_put_resource(&mgr->mgr, 1, sum->idx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	sum_rsc_uninit(sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	kfree(sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) int sum_mgr_create(struct hw *hw, struct sum_mgr **rsum_mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct sum_mgr *sum_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	*rsum_mgr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	sum_mgr = kzalloc(sizeof(*sum_mgr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (!sum_mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	err = rsc_mgr_init(&sum_mgr->mgr, SUM, SUM_RESOURCE_NUM, hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	spin_lock_init(&sum_mgr->mgr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	sum_mgr->get_sum = get_sum_rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	sum_mgr->put_sum = put_sum_rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	sum_mgr->card = hw->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	*rsum_mgr = sum_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	kfree(sum_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int sum_mgr_destroy(struct sum_mgr *sum_mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	rsc_mgr_uninit(&sum_mgr->mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	kfree(sum_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)