Skip to content

Commit 2282315

Browse files
tmaimonbebarino
authored andcommitted
reset: npcm: register npcm8xx clock auxiliary bus device
Add NPCM8xx clock controller auxiliary bus device registration. The NPCM8xx clock controller is registered as an aux device because the reset and the clock controller share the same register region. Signed-off-by: Tomer Maimon <[email protected]> Tested-by: Benjamin Fair <[email protected]> Reviewed-by: Philipp Zabel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent d62f45b commit 2282315

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

drivers/reset/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ config RESET_MESON_AUDIO_ARB
170170
config RESET_NPCM
171171
bool "NPCM BMC Reset Driver" if COMPILE_TEST
172172
default ARCH_NPCM
173+
select AUXILIARY_BUS
173174
help
174175
This enables the reset controller driver for Nuvoton NPCM
175176
BMC SoCs.

drivers/reset/reset-npcm.c

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2019 Nuvoton Technology corporation.
33

4+
#include <linux/auxiliary_bus.h>
45
#include <linux/delay.h>
56
#include <linux/err.h>
67
#include <linux/io.h>
@@ -10,11 +11,14 @@
1011
#include <linux/property.h>
1112
#include <linux/reboot.h>
1213
#include <linux/reset-controller.h>
14+
#include <linux/slab.h>
1315
#include <linux/spinlock.h>
1416
#include <linux/mfd/syscon.h>
1517
#include <linux/regmap.h>
1618
#include <linux/of_address.h>
1719

20+
#include <soc/nuvoton/clock-npcm8xx.h>
21+
1822
/* NPCM7xx GCR registers */
1923
#define NPCM_MDLR_OFFSET 0x7C
2024
#define NPCM7XX_MDLR_USBD0 BIT(9)
@@ -89,6 +93,7 @@ struct npcm_rc_data {
8993
const struct npcm_reset_info *info;
9094
struct regmap *gcr_regmap;
9195
u32 sw_reset_number;
96+
struct device *dev;
9297
void __iomem *base;
9398
spinlock_t lock;
9499
};
@@ -372,6 +377,67 @@ static const struct reset_control_ops npcm_rc_ops = {
372377
.status = npcm_rc_status,
373378
};
374379

380+
static void npcm_clock_unregister_adev(void *_adev)
381+
{
382+
struct auxiliary_device *adev = _adev;
383+
384+
auxiliary_device_delete(adev);
385+
auxiliary_device_uninit(adev);
386+
}
387+
388+
static void npcm_clock_adev_release(struct device *dev)
389+
{
390+
struct auxiliary_device *adev = to_auxiliary_dev(dev);
391+
struct npcm_clock_adev *rdev = to_npcm_clock_adev(adev);
392+
393+
kfree(rdev);
394+
}
395+
396+
static struct auxiliary_device *npcm_clock_adev_alloc(struct npcm_rc_data *rst_data, char *clk_name)
397+
{
398+
struct npcm_clock_adev *rdev;
399+
struct auxiliary_device *adev;
400+
int ret;
401+
402+
rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
403+
if (!rdev)
404+
return ERR_PTR(-ENOMEM);
405+
406+
rdev->base = rst_data->base;
407+
408+
adev = &rdev->adev;
409+
adev->name = clk_name;
410+
adev->dev.parent = rst_data->dev;
411+
adev->dev.release = npcm_clock_adev_release;
412+
adev->id = 555u;
413+
414+
ret = auxiliary_device_init(adev);
415+
if (ret) {
416+
kfree(rdev);
417+
return ERR_PTR(ret);
418+
}
419+
420+
return adev;
421+
}
422+
423+
static int npcm8xx_clock_controller_register(struct npcm_rc_data *rst_data, char *clk_name)
424+
{
425+
struct auxiliary_device *adev;
426+
int ret;
427+
428+
adev = npcm_clock_adev_alloc(rst_data, clk_name);
429+
if (IS_ERR(adev))
430+
return PTR_ERR(adev);
431+
432+
ret = auxiliary_device_add(adev);
433+
if (ret) {
434+
auxiliary_device_uninit(adev);
435+
return ret;
436+
}
437+
438+
return devm_add_action_or_reset(rst_data->dev, npcm_clock_unregister_adev, adev);
439+
}
440+
375441
static int npcm_rc_probe(struct platform_device *pdev)
376442
{
377443
struct npcm_rc_data *rc;
@@ -392,6 +458,7 @@ static int npcm_rc_probe(struct platform_device *pdev)
392458
rc->rcdev.of_node = pdev->dev.of_node;
393459
rc->rcdev.of_reset_n_cells = 2;
394460
rc->rcdev.of_xlate = npcm_reset_xlate;
461+
rc->dev = &pdev->dev;
395462

396463
ret = devm_reset_controller_register(&pdev->dev, &rc->rcdev);
397464
if (ret) {
@@ -408,12 +475,19 @@ static int npcm_rc_probe(struct platform_device *pdev)
408475
rc->restart_nb.priority = 192,
409476
rc->restart_nb.notifier_call = npcm_rc_restart,
410477
ret = register_restart_handler(&rc->restart_nb);
411-
if (ret)
478+
if (ret) {
412479
dev_warn(&pdev->dev, "failed to register restart handler\n");
480+
return ret;
481+
}
413482
}
414483
}
415484

416-
return ret;
485+
switch (rc->info->bmc_id) {
486+
case BMC_NPCM8XX:
487+
return npcm8xx_clock_controller_register(rc, "clk-npcm8xx");
488+
default:
489+
return 0;
490+
}
417491
}
418492

419493
static struct platform_driver npcm_rc_driver = {

include/soc/nuvoton/clock-npcm8xx.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __SOC_NPCM8XX_CLOCK_H
3+
#define __SOC_NPCM8XX_CLOCK_H
4+
5+
#include <linux/auxiliary_bus.h>
6+
#include <linux/container_of.h>
7+
8+
struct npcm_clock_adev {
9+
void __iomem *base;
10+
struct auxiliary_device adev;
11+
};
12+
13+
static inline struct npcm_clock_adev *to_npcm_clock_adev(struct auxiliary_device *_adev)
14+
{
15+
return container_of(_adev, struct npcm_clock_adev, adev);
16+
}
17+
18+
#endif

0 commit comments

Comments
 (0)