MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_ofw_get_clk_array

Function rt_ofw_get_clk_array

components/drivers/clk/clk.c:1276–1331  ·  view source on GitHub ↗

* @brief Get clock array from ofw * * @param np point to ofw node * * @return struct rt_clk_array* point to the newly created clock array, or an error pointer */

Source from the content-addressed store, hash-verified

1274 * @return struct rt_clk_array* point to the newly created clock array, or an error pointer
1275 */
1276struct rt_clk_array *rt_ofw_get_clk_array(struct rt_ofw_node *np)
1277{
1278 int count;
1279 struct rt_clk_array *clk_arr = RT_NULL;
1280
1281 if (!np)
1282 {
1283 return rt_err_ptr(-RT_EINVAL);
1284 }
1285
1286 if ((count = rt_ofw_count_phandle_cells(np, "clocks", "#clock-cells")) > 0)
1287 {
1288 clk_arr = rt_calloc(1, sizeof(*clk_arr) + sizeof(clk_arr->clks[0]) * count);
1289
1290 if (clk_arr)
1291 {
1292 int i;
1293 rt_err_t err = RT_EOK;
1294 rt_bool_t has_name = rt_ofw_prop_read_bool(np, "clock-names");
1295
1296 clk_arr->count = count;
1297
1298 rt_hw_spin_lock(&_clk_lock.lock);
1299
1300 for (i = 0; i < count; ++i)
1301 {
1302 const char *name = RT_NULL;
1303
1304 if (has_name)
1305 {
1306 rt_ofw_prop_read_string_index(np, "clock-names", i, &name);
1307 }
1308
1309 clk_arr->clks[i] = ofw_get_clk_no_lock(np, i, name, RT_FALSE);
1310
1311 if (rt_is_err(clk_arr->clks[i]))
1312 {
1313 err = rt_ptr_err(clk_arr->clks[i]);
1314
1315 --i;
1316 break;
1317 }
1318 }
1319
1320 rt_hw_spin_unlock(&_clk_lock.lock);
1321
1322 if (i > 0 && i < count)
1323 {
1324 rt_clk_array_put(clk_arr);
1325 clk_arr = rt_err_ptr(err);
1326 }
1327 }
1328 }
1329
1330 return clk_arr;
1331}
1332
1333/**

Callers 1

rt_clk_get_arrayFunction · 0.85

Calls 8

rt_callocFunction · 0.85
rt_ofw_prop_read_boolFunction · 0.85
ofw_get_clk_no_lockFunction · 0.85
rt_clk_array_putFunction · 0.85
rt_hw_spin_lockFunction · 0.50
rt_hw_spin_unlockFunction · 0.50

Tested by

no test coverage detected