/* * rl6231.c - RL6231 class device shared support * * Copyright 2014 Realtek Semiconductor Corp. * * Author: Oder Chiou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "rl6231.h" /** * rl6231_calc_dmic_clk - Calculate the parameter of dmic. * * @rate: base clock rate. * * Choose dmic clock between 1MHz and 3MHz. * It is better for clock to approximate 3MHz. */ int rl6231_calc_dmic_clk(int rate) { int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; int i, red, bound, temp; red = 3000000 * 12; for (i = 0; i < ARRAY_SIZE(div); i++) { bound = div[i] * 3000000; if (rate > bound) continue; temp = bound - rate; if (temp < red) { red = temp; idx = i; } } return idx; } EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); MODULE_DESCRIPTION("RL6231 class device shared support"); MODULE_AUTHOR("Oder Chiou "); MODULE_LICENSE("GPL v2");