Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Nokia Corporation |
| 3 | * |
| 4 | * Based on lirc_serial.c |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 15 | */ |
Ivaylo Dimitrov | 4406d52 | 2016-06-22 22:22:17 +0300 | [diff] [blame] | 16 | #include <linux/clk.h> |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 17 | #include <linux/module.h> |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 19 | #include <linux/wait.h> |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 20 | #include <linux/pwm.h> |
Ivaylo Dimitrov | b540617 | 2016-06-22 22:22:20 +0300 | [diff] [blame] | 21 | #include <linux/of.h> |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 22 | #include <linux/hrtimer.h> |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 23 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 24 | #include <media/rc-core.h> |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 25 | |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 26 | #define WBUF_LEN 256 |
| 27 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 28 | struct ir_rx51 { |
| 29 | struct rc_dev *rcdev; |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 30 | struct pwm_device *pwm; |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 31 | struct hrtimer timer; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 32 | struct device *dev; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 33 | wait_queue_head_t wqueue; |
| 34 | |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 35 | unsigned int freq; /* carrier frequency */ |
| 36 | unsigned int duty_cycle; /* carrier duty cycle */ |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 37 | int wbuf[WBUF_LEN]; |
| 38 | int wbuf_index; |
| 39 | unsigned long device_is_open; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 40 | }; |
| 41 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 42 | static inline void ir_rx51_on(struct ir_rx51 *ir_rx51) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 43 | { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 44 | pwm_enable(ir_rx51->pwm); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 45 | } |
| 46 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 47 | static inline void ir_rx51_off(struct ir_rx51 *ir_rx51) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 48 | { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 49 | pwm_disable(ir_rx51->pwm); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 50 | } |
| 51 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 52 | static int init_timing_params(struct ir_rx51 *ir_rx51) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 53 | { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 54 | struct pwm_device *pwm = ir_rx51->pwm; |
| 55 | int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 56 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 57 | duty = DIV_ROUND_CLOSEST(ir_rx51->duty_cycle * period, 100); |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 58 | |
| 59 | pwm_config(pwm, duty, period); |
| 60 | |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 64 | static enum hrtimer_restart ir_rx51_timer_cb(struct hrtimer *timer) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 65 | { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 66 | struct ir_rx51 *ir_rx51 = container_of(timer, struct ir_rx51, timer); |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 67 | ktime_t now; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 68 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 69 | if (ir_rx51->wbuf_index < 0) { |
| 70 | dev_err_ratelimited(ir_rx51->dev, |
| 71 | "BUG wbuf_index has value of %i\n", |
| 72 | ir_rx51->wbuf_index); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 73 | goto end; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * If we happen to hit an odd latency spike, loop through the |
| 78 | * pulses until we catch up. |
| 79 | */ |
| 80 | do { |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 81 | u64 ns; |
| 82 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 83 | if (ir_rx51->wbuf_index >= WBUF_LEN) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 84 | goto end; |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 85 | if (ir_rx51->wbuf[ir_rx51->wbuf_index] == -1) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 86 | goto end; |
| 87 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 88 | if (ir_rx51->wbuf_index % 2) |
| 89 | ir_rx51_off(ir_rx51); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 90 | else |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 91 | ir_rx51_on(ir_rx51); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 92 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 93 | ns = US_TO_NS(ir_rx51->wbuf[ir_rx51->wbuf_index]); |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 94 | hrtimer_add_expires_ns(timer, ns); |
| 95 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 96 | ir_rx51->wbuf_index++; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 97 | |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 98 | now = timer->base->get_time(); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 99 | |
Thomas Gleixner | 2456e85 | 2016-12-25 11:38:40 +0100 | [diff] [blame] | 100 | } while (hrtimer_get_expires_tv64(timer) < now); |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 101 | |
| 102 | return HRTIMER_RESTART; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 103 | end: |
| 104 | /* Stop TX here */ |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 105 | ir_rx51_off(ir_rx51); |
| 106 | ir_rx51->wbuf_index = -1; |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 107 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 108 | wake_up_interruptible(&ir_rx51->wqueue); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 109 | |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 110 | return HRTIMER_NORESTART; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 111 | } |
| 112 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 113 | static int ir_rx51_tx(struct rc_dev *dev, unsigned int *buffer, |
| 114 | unsigned int count) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 115 | { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 116 | struct ir_rx51 *ir_rx51 = dev->priv; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 117 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 118 | if (count > WBUF_LEN) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 119 | return -EINVAL; |
| 120 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 121 | memcpy(ir_rx51->wbuf, buffer, count * sizeof(unsigned int)); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 122 | |
| 123 | /* Wait any pending transfers to finish */ |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 124 | wait_event_interruptible(ir_rx51->wqueue, ir_rx51->wbuf_index < 0); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 125 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 126 | init_timing_params(ir_rx51); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 127 | if (count < WBUF_LEN) |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 128 | ir_rx51->wbuf[count] = -1; /* Insert termination mark */ |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 129 | |
| 130 | /* |
Tony Lindgren | 44773ba | 2018-04-16 10:22:01 -0700 | [diff] [blame] | 131 | * REVISIT: Adjust latency requirements so the device doesn't go in too |
| 132 | * deep sleep states with pm_qos_add_request(). |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 133 | */ |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 134 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 135 | ir_rx51_on(ir_rx51); |
| 136 | ir_rx51->wbuf_index = 1; |
| 137 | hrtimer_start(&ir_rx51->timer, |
| 138 | ns_to_ktime(US_TO_NS(ir_rx51->wbuf[0])), |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 139 | HRTIMER_MODE_REL); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 140 | /* |
| 141 | * Don't return back to the userspace until the transfer has |
| 142 | * finished |
| 143 | */ |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 144 | wait_event_interruptible(ir_rx51->wqueue, ir_rx51->wbuf_index < 0); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 145 | |
Tony Lindgren | 44773ba | 2018-04-16 10:22:01 -0700 | [diff] [blame] | 146 | /* REVISIT: Remove pm_qos constraint, we can sleep again */ |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 147 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 148 | return count; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 149 | } |
| 150 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 151 | static int ir_rx51_open(struct rc_dev *dev) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 152 | { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 153 | struct ir_rx51 *ir_rx51 = dev->priv; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 154 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 155 | if (test_and_set_bit(1, &ir_rx51->device_is_open)) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 156 | return -EBUSY; |
| 157 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 158 | ir_rx51->pwm = pwm_get(ir_rx51->dev, NULL); |
| 159 | if (IS_ERR(ir_rx51->pwm)) { |
| 160 | int res = PTR_ERR(ir_rx51->pwm); |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 161 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 162 | dev_err(ir_rx51->dev, "pwm_get failed: %d\n", res); |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 163 | return res; |
| 164 | } |
| 165 | |
| 166 | return 0; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 167 | } |
| 168 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 169 | static void ir_rx51_release(struct rc_dev *dev) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 170 | { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 171 | struct ir_rx51 *ir_rx51 = dev->priv; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 172 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 173 | hrtimer_cancel(&ir_rx51->timer); |
| 174 | ir_rx51_off(ir_rx51); |
| 175 | pwm_put(ir_rx51->pwm); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 176 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 177 | clear_bit(1, &ir_rx51->device_is_open); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 178 | } |
| 179 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 180 | static struct ir_rx51 ir_rx51 = { |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 181 | .duty_cycle = 50, |
| 182 | .wbuf_index = -1, |
| 183 | }; |
| 184 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 185 | static int ir_rx51_set_duty_cycle(struct rc_dev *dev, u32 duty) |
| 186 | { |
| 187 | struct ir_rx51 *ir_rx51 = dev->priv; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 188 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 189 | ir_rx51->duty_cycle = duty; |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static int ir_rx51_set_tx_carrier(struct rc_dev *dev, u32 carrier) |
| 195 | { |
| 196 | struct ir_rx51 *ir_rx51 = dev->priv; |
| 197 | |
| 198 | if (carrier > 500000 || carrier < 20000) |
| 199 | return -EINVAL; |
| 200 | |
| 201 | ir_rx51->freq = carrier; |
| 202 | |
| 203 | return 0; |
| 204 | } |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 205 | |
| 206 | #ifdef CONFIG_PM |
| 207 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 208 | static int ir_rx51_suspend(struct platform_device *dev, pm_message_t state) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 209 | { |
| 210 | /* |
| 211 | * In case the device is still open, do not suspend. Normally |
| 212 | * this should not be a problem as lircd only keeps the device |
| 213 | * open only for short periods of time. We also don't want to |
| 214 | * get involved with race conditions that might happen if we |
| 215 | * were in a middle of a transmit. Thus, we defer any suspend |
| 216 | * actions until transmit has completed. |
| 217 | */ |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 218 | if (test_and_set_bit(1, &ir_rx51.device_is_open)) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 219 | return -EAGAIN; |
| 220 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 221 | clear_bit(1, &ir_rx51.device_is_open); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 226 | static int ir_rx51_resume(struct platform_device *dev) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 227 | { |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | #else |
| 232 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 233 | #define ir_rx51_suspend NULL |
| 234 | #define ir_rx51_resume NULL |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 235 | |
| 236 | #endif /* CONFIG_PM */ |
| 237 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 238 | static int ir_rx51_probe(struct platform_device *dev) |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 239 | { |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 240 | struct pwm_device *pwm; |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 241 | struct rc_dev *rcdev; |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 242 | |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 243 | pwm = pwm_get(&dev->dev, NULL); |
| 244 | if (IS_ERR(pwm)) { |
| 245 | int err = PTR_ERR(pwm); |
| 246 | |
| 247 | if (err != -EPROBE_DEFER) |
| 248 | dev_err(&dev->dev, "pwm_get failed: %d\n", err); |
| 249 | return err; |
| 250 | } |
| 251 | |
| 252 | /* Use default, in case userspace does not set the carrier */ |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 253 | ir_rx51.freq = DIV_ROUND_CLOSEST(pwm_get_period(pwm), NSEC_PER_SEC); |
Ivaylo Dimitrov | 3fdd152 | 2016-06-22 22:22:19 +0300 | [diff] [blame] | 254 | pwm_put(pwm); |
| 255 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 256 | hrtimer_init(&ir_rx51.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 257 | ir_rx51.timer.function = ir_rx51_timer_cb; |
Ivaylo Dimitrov | 79cdad3 | 2016-06-22 22:22:21 +0300 | [diff] [blame] | 258 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 259 | ir_rx51.dev = &dev->dev; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 260 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 261 | rcdev = devm_rc_allocate_device(&dev->dev, RC_DRIVER_IR_RAW_TX); |
| 262 | if (!rcdev) |
| 263 | return -ENOMEM; |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 264 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 265 | rcdev->priv = &ir_rx51; |
| 266 | rcdev->open = ir_rx51_open; |
| 267 | rcdev->close = ir_rx51_release; |
| 268 | rcdev->tx_ir = ir_rx51_tx; |
| 269 | rcdev->s_tx_duty_cycle = ir_rx51_set_duty_cycle; |
| 270 | rcdev->s_tx_carrier = ir_rx51_set_tx_carrier; |
| 271 | rcdev->driver_name = KBUILD_MODNAME; |
| 272 | |
| 273 | ir_rx51.rcdev = rcdev; |
| 274 | |
| 275 | return devm_rc_register_device(&dev->dev, ir_rx51.rcdev); |
| 276 | } |
| 277 | |
| 278 | static int ir_rx51_remove(struct platform_device *dev) |
| 279 | { |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 283 | static const struct of_device_id ir_rx51_match[] = { |
Ivaylo Dimitrov | b540617 | 2016-06-22 22:22:20 +0300 | [diff] [blame] | 284 | { |
| 285 | .compatible = "nokia,n900-ir", |
| 286 | }, |
| 287 | {}, |
| 288 | }; |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 289 | MODULE_DEVICE_TABLE(of, ir_rx51_match); |
Ivaylo Dimitrov | b540617 | 2016-06-22 22:22:20 +0300 | [diff] [blame] | 290 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 291 | static struct platform_driver ir_rx51_platform_driver = { |
| 292 | .probe = ir_rx51_probe, |
| 293 | .remove = ir_rx51_remove, |
| 294 | .suspend = ir_rx51_suspend, |
| 295 | .resume = ir_rx51_resume, |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 296 | .driver = { |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 297 | .name = KBUILD_MODNAME, |
| 298 | .of_match_table = of_match_ptr(ir_rx51_match), |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 299 | }, |
| 300 | }; |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 301 | module_platform_driver(ir_rx51_platform_driver); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 302 | |
Sean Young | a92def1 | 2016-12-19 18:48:29 -0200 | [diff] [blame] | 303 | MODULE_DESCRIPTION("IR TX driver for Nokia RX51"); |
Timo Kokkonen | c332e84 | 2012-08-10 06:16:36 -0300 | [diff] [blame] | 304 | MODULE_AUTHOR("Nokia Corporation"); |
| 305 | MODULE_LICENSE("GPL"); |