Lines Matching refs:rain
40 struct rain { struct
65 static void rain_process_msg(struct rain *rain) in rain_process_msg() argument
68 const char *cmd = rain->cmd + 3; in rain_process_msg()
88 if (rain->cmd[0] == 'R') { in rain_process_msg()
90 cec_received_msg(rain->adap, &msg); in rain_process_msg()
96 cec_transmit_attempt_done(rain->adap, CEC_TX_STATUS_OK); in rain_process_msg()
99 cec_transmit_attempt_done(rain->adap, CEC_TX_STATUS_NACK); in rain_process_msg()
102 cec_transmit_attempt_done(rain->adap, CEC_TX_STATUS_LOW_DRIVE); in rain_process_msg()
109 struct rain *rain = in rain_irq_work_handler() local
110 container_of(work, struct rain, work); in rain_irq_work_handler()
116 spin_lock_irqsave(&rain->buf_lock, flags); in rain_irq_work_handler()
117 if (!rain->buf_len) { in rain_irq_work_handler()
118 spin_unlock_irqrestore(&rain->buf_lock, flags); in rain_irq_work_handler()
122 data = rain->buf[rain->buf_rd_idx]; in rain_irq_work_handler()
123 rain->buf_len--; in rain_irq_work_handler()
124 rain->buf_rd_idx = (rain->buf_rd_idx + 1) & 0xff; in rain_irq_work_handler()
126 spin_unlock_irqrestore(&rain->buf_lock, flags); in rain_irq_work_handler()
128 if (!rain->cmd_started && data != '?') in rain_irq_work_handler()
133 rain->cmd[rain->cmd_idx] = '\0'; in rain_irq_work_handler()
134 dev_dbg(rain->dev, "received: %s\n", rain->cmd); in rain_irq_work_handler()
135 if (!memcmp(rain->cmd, "REC", 3) || in rain_irq_work_handler()
136 !memcmp(rain->cmd, "STA", 3)) { in rain_irq_work_handler()
137 rain_process_msg(rain); in rain_irq_work_handler()
139 strscpy(rain->cmd_reply, rain->cmd, in rain_irq_work_handler()
140 sizeof(rain->cmd_reply)); in rain_irq_work_handler()
141 complete(&rain->cmd_done); in rain_irq_work_handler()
143 rain->cmd_idx = 0; in rain_irq_work_handler()
144 rain->cmd_started = false; in rain_irq_work_handler()
148 rain->cmd_idx = 0; in rain_irq_work_handler()
149 rain->cmd_started = false; in rain_irq_work_handler()
153 rain->cmd_idx = 0; in rain_irq_work_handler()
154 rain->cmd_started = true; in rain_irq_work_handler()
158 if (rain->cmd_idx >= DATA_SIZE - 1) { in rain_irq_work_handler()
159 dev_dbg(rain->dev, in rain_irq_work_handler()
160 "throwing away %d bytes of garbage\n", rain->cmd_idx); in rain_irq_work_handler()
161 rain->cmd_idx = 0; in rain_irq_work_handler()
163 rain->cmd[rain->cmd_idx++] = data; in rain_irq_work_handler()
172 struct rain *rain = serio_get_drvdata(serio); in rain_interrupt() local
174 if (rain->buf_len == DATA_SIZE) { in rain_interrupt()
175 dev_warn_once(rain->dev, "buffer overflow\n"); in rain_interrupt()
178 spin_lock(&rain->buf_lock); in rain_interrupt()
179 rain->buf_len++; in rain_interrupt()
180 rain->buf[rain->buf_wr_idx] = data; in rain_interrupt()
181 rain->buf_wr_idx = (rain->buf_wr_idx + 1) & 0xff; in rain_interrupt()
182 spin_unlock(&rain->buf_lock); in rain_interrupt()
183 schedule_work(&rain->work); in rain_interrupt()
189 struct rain *rain = serio_get_drvdata(serio); in rain_disconnect() local
191 cancel_work_sync(&rain->work); in rain_disconnect()
192 cec_unregister_adapter(rain->adap); in rain_disconnect()
196 kfree(rain); in rain_disconnect()
199 static int rain_send(struct rain *rain, const char *command) in rain_send() argument
201 int err = serio_write(rain->serio, '!'); in rain_send()
203 dev_dbg(rain->dev, "send: %s\n", command); in rain_send()
205 err = serio_write(rain->serio, *command++); in rain_send()
207 err = serio_write(rain->serio, '~'); in rain_send()
212 static int rain_send_and_wait(struct rain *rain, in rain_send_and_wait() argument
217 init_completion(&rain->cmd_done); in rain_send_and_wait()
219 mutex_lock(&rain->write_lock); in rain_send_and_wait()
220 err = rain_send(rain, cmd); in rain_send_and_wait()
224 if (!wait_for_completion_timeout(&rain->cmd_done, HZ)) { in rain_send_and_wait()
228 if (reply && strncmp(rain->cmd_reply, reply, strlen(reply))) { in rain_send_and_wait()
229 dev_dbg(rain->dev, in rain_send_and_wait()
231 cmd, rain->cmd_reply, reply); in rain_send_and_wait()
235 mutex_unlock(&rain->write_lock); in rain_send_and_wait()
239 static int rain_setup(struct rain *rain, struct serio *serio, in rain_setup() argument
244 err = rain_send_and_wait(rain, "R", "REV"); in rain_setup()
247 dev_info(rain->dev, "Firmware version %s\n", rain->cmd_reply + 4); in rain_setup()
249 err = rain_send_and_wait(rain, "Q 1", "QTY"); in rain_setup()
252 err = rain_send_and_wait(rain, "c0000", "CFG"); in rain_setup()
255 return rain_send_and_wait(rain, "A F 0000", "ADR"); in rain_setup()
265 struct rain *rain = cec_get_drvdata(adap); in rain_cec_adap_log_addr() local
271 return rain_send_and_wait(rain, cmd, "ADR"); in rain_cec_adap_log_addr()
277 struct rain *rain = cec_get_drvdata(adap); in rain_cec_adap_transmit() local
294 mutex_lock(&rain->write_lock); in rain_cec_adap_transmit()
295 err = rain_send(rain, cmd); in rain_cec_adap_transmit()
296 mutex_unlock(&rain->write_lock); in rain_cec_adap_transmit()
309 struct rain *rain; in rain_connect() local
314 rain = kzalloc(sizeof(*rain), GFP_KERNEL); in rain_connect()
316 if (!rain) in rain_connect()
319 rain->serio = serio; in rain_connect()
320 rain->adap = cec_allocate_adapter(&rain_cec_adap_ops, rain, in rain_connect()
322 err = PTR_ERR_OR_ZERO(rain->adap); in rain_connect()
326 rain->dev = &serio->dev; in rain_connect()
327 serio_set_drvdata(serio, rain); in rain_connect()
328 INIT_WORK(&rain->work, rain_irq_work_handler); in rain_connect()
329 mutex_init(&rain->write_lock); in rain_connect()
330 spin_lock_init(&rain->buf_lock); in rain_connect()
336 err = rain_setup(rain, serio, &log_addrs, &pa); in rain_connect()
340 err = cec_register_adapter(rain->adap, &serio->dev); in rain_connect()
344 rain->dev = &rain->adap->devnode.dev; in rain_connect()
350 cec_delete_adapter(rain->adap); in rain_connect()
353 kfree(rain); in rain_connect()