Lines Matching refs:ba431
47 static inline u32 ba431_trng_read_reg(struct ba431_trng *ba431, u32 reg) in ba431_trng_read_reg() argument
49 return ioread32(ba431->base + reg); in ba431_trng_read_reg()
52 static inline void ba431_trng_write_reg(struct ba431_trng *ba431, u32 reg, in ba431_trng_write_reg() argument
55 iowrite32(val, ba431->base + reg); in ba431_trng_write_reg()
58 static inline enum ba431_state ba431_trng_get_state(struct ba431_trng *ba431) in ba431_trng_get_state() argument
60 u32 status = ba431_trng_read_reg(ba431, BA431_REG_STATUS); in ba431_trng_get_state()
65 static int ba431_trng_is_in_error(struct ba431_trng *ba431) in ba431_trng_is_in_error() argument
67 enum ba431_state state = ba431_trng_get_state(ba431); in ba431_trng_is_in_error()
76 static int ba431_trng_reset(struct ba431_trng *ba431) in ba431_trng_reset() argument
81 ba431_trng_write_reg(ba431, BA431_REG_CTRL, BA431_CTRL_SOFTRESET); in ba431_trng_reset()
83 ba431_trng_write_reg(ba431, BA431_REG_CTRL, BA431_CTRL_ENABLE); in ba431_trng_reset()
86 if (readx_poll_timeout(ba431_trng_is_in_error, ba431, ret, !ret, in ba431_trng_reset()
89 dev_err(ba431->dev, "reset failed (state: %d)\n", in ba431_trng_reset()
90 ba431_trng_get_state(ba431)); in ba431_trng_reset()
94 dev_info(ba431->dev, "reset done\n"); in ba431_trng_reset()
101 struct ba431_trng *ba431 = container_of(work, struct ba431_trng, in ba431_trng_reset_work() local
103 ba431_trng_reset(ba431); in ba431_trng_reset_work()
104 atomic_set(&ba431->reset_pending, 0); in ba431_trng_reset_work()
107 static void ba431_trng_schedule_reset(struct ba431_trng *ba431) in ba431_trng_schedule_reset() argument
109 if (atomic_cmpxchg(&ba431->reset_pending, 0, 1)) in ba431_trng_schedule_reset()
112 schedule_work(&ba431->reset_work); in ba431_trng_schedule_reset()
117 struct ba431_trng *ba431 = container_of(rng, struct ba431_trng, rng); in ba431_trng_read() local
123 level = ba431_trng_read_reg(ba431, BA431_REG_FIFO_LEVEL); in ba431_trng_read()
125 if (ba431_trng_is_in_error(ba431)) { in ba431_trng_read()
126 ba431_trng_schedule_reset(ba431); in ba431_trng_read()
139 data[n++] = ba431_trng_read_reg(ba431, in ba431_trng_read()
144 if (ba431_trng_is_in_error(ba431)) { in ba431_trng_read()
146 ba431_trng_schedule_reset(ba431); in ba431_trng_read()
157 struct ba431_trng *ba431 = container_of(rng, struct ba431_trng, rng); in ba431_trng_cleanup() local
159 ba431_trng_write_reg(ba431, BA431_REG_CTRL, 0); in ba431_trng_cleanup()
160 cancel_work_sync(&ba431->reset_work); in ba431_trng_cleanup()
165 struct ba431_trng *ba431 = container_of(rng, struct ba431_trng, rng); in ba431_trng_init() local
167 return ba431_trng_reset(ba431); in ba431_trng_init()
172 struct ba431_trng *ba431; in ba431_trng_probe() local
176 ba431 = devm_kzalloc(&pdev->dev, sizeof(*ba431), GFP_KERNEL); in ba431_trng_probe()
177 if (!ba431) in ba431_trng_probe()
180 ba431->dev = &pdev->dev; in ba431_trng_probe()
183 ba431->base = devm_ioremap_resource(&pdev->dev, res); in ba431_trng_probe()
184 if (IS_ERR(ba431->base)) in ba431_trng_probe()
185 return PTR_ERR(ba431->base); in ba431_trng_probe()
187 atomic_set(&ba431->reset_pending, 0); in ba431_trng_probe()
188 INIT_WORK(&ba431->reset_work, ba431_trng_reset_work); in ba431_trng_probe()
189 ba431->rng.name = pdev->name; in ba431_trng_probe()
190 ba431->rng.init = ba431_trng_init; in ba431_trng_probe()
191 ba431->rng.cleanup = ba431_trng_cleanup; in ba431_trng_probe()
192 ba431->rng.read = ba431_trng_read; in ba431_trng_probe()
194 platform_set_drvdata(pdev, ba431); in ba431_trng_probe()
196 ret = hwrng_register(&ba431->rng); in ba431_trng_probe()
209 struct ba431_trng *ba431 = platform_get_drvdata(pdev); in ba431_trng_remove() local
211 hwrng_unregister(&ba431->rng); in ba431_trng_remove()