Lines Matching refs:hc
93 static inline int smb_hc_read(struct acpi_smb_hc *hc, u8 address, u8 *data) in smb_hc_read() argument
95 return ec_read(hc->offset + address, data); in smb_hc_read()
98 static inline int smb_hc_write(struct acpi_smb_hc *hc, u8 address, u8 data) in smb_hc_write() argument
100 return ec_write(hc->offset + address, data); in smb_hc_write()
103 static inline int smb_check_done(struct acpi_smb_hc *hc) in smb_check_done() argument
106 smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw); in smb_check_done()
110 static int wait_transaction_complete(struct acpi_smb_hc *hc, int timeout) in wait_transaction_complete() argument
112 if (wait_event_timeout(hc->wait, smb_check_done(hc), in wait_transaction_complete()
120 if (smb_check_done(hc)) in wait_transaction_complete()
126 static int acpi_smbus_transaction(struct acpi_smb_hc *hc, u8 protocol, in acpi_smbus_transaction() argument
132 if (!hc) { in acpi_smbus_transaction()
137 mutex_lock(&hc->lock); in acpi_smbus_transaction()
140 if (smb_hc_read(hc, ACPI_SMB_PROTOCOL, &temp)) in acpi_smbus_transaction()
146 smb_hc_write(hc, ACPI_SMB_COMMAND, command); in acpi_smbus_transaction()
148 smb_hc_write(hc, ACPI_SMB_BLOCK_COUNT, length); in acpi_smbus_transaction()
150 smb_hc_write(hc, ACPI_SMB_DATA + i, data[i]); in acpi_smbus_transaction()
152 smb_hc_write(hc, ACPI_SMB_ADDRESS, address << 1); in acpi_smbus_transaction()
153 smb_hc_write(hc, ACPI_SMB_PROTOCOL, protocol); in acpi_smbus_transaction()
158 ret = wait_transaction_complete(hc, 1000); in acpi_smbus_transaction()
170 if (smb_hc_read(hc, ACPI_SMB_BLOCK_COUNT, &sz)) { in acpi_smbus_transaction()
178 smb_hc_read(hc, ACPI_SMB_DATA + i, &data[i]); in acpi_smbus_transaction()
180 mutex_unlock(&hc->lock); in acpi_smbus_transaction()
184 int acpi_smbus_read(struct acpi_smb_hc *hc, u8 protocol, u8 address, in acpi_smbus_read() argument
187 return acpi_smbus_transaction(hc, protocol, address, command, data, 0); in acpi_smbus_read()
192 int acpi_smbus_write(struct acpi_smb_hc *hc, u8 protocol, u8 address, in acpi_smbus_write() argument
195 return acpi_smbus_transaction(hc, protocol, address, command, data, length); in acpi_smbus_write()
200 int acpi_smbus_register_callback(struct acpi_smb_hc *hc, in acpi_smbus_register_callback() argument
203 mutex_lock(&hc->lock); in acpi_smbus_register_callback()
204 hc->callback = callback; in acpi_smbus_register_callback()
205 hc->context = context; in acpi_smbus_register_callback()
206 mutex_unlock(&hc->lock); in acpi_smbus_register_callback()
212 int acpi_smbus_unregister_callback(struct acpi_smb_hc *hc) in acpi_smbus_unregister_callback() argument
214 mutex_lock(&hc->lock); in acpi_smbus_unregister_callback()
215 hc->callback = NULL; in acpi_smbus_unregister_callback()
216 hc->context = NULL; in acpi_smbus_unregister_callback()
217 mutex_unlock(&hc->lock); in acpi_smbus_unregister_callback()
225 struct acpi_smb_hc *hc = context; in acpi_smbus_callback() local
226 if (hc->callback) in acpi_smbus_callback()
227 hc->callback(hc->context); in acpi_smbus_callback()
232 struct acpi_smb_hc *hc = context; in smbus_alarm() local
235 if (smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw)) in smbus_alarm()
239 wake_up(&hc->wait); in smbus_alarm()
242 mutex_lock(&hc->lock); in smbus_alarm()
243 smb_hc_read(hc, ACPI_SMB_ALARM_ADDRESS, &address); in smbus_alarm()
245 smb_hc_write(hc, ACPI_SMB_STATUS, status.raw); in smbus_alarm()
252 acpi_smbus_callback, hc); in smbus_alarm()
255 mutex_unlock(&hc->lock); in smbus_alarm()
284 struct acpi_smb_hc *hc; in acpi_smbus_hc_add() local
300 hc = kzalloc(sizeof(struct acpi_smb_hc), GFP_KERNEL); in acpi_smbus_hc_add()
301 if (!hc) in acpi_smbus_hc_add()
303 mutex_init(&hc->lock); in acpi_smbus_hc_add()
304 init_waitqueue_head(&hc->wait); in acpi_smbus_hc_add()
306 hc->ec = acpi_driver_data(device->parent); in acpi_smbus_hc_add()
307 hc->offset = (val >> 8) & 0xff; in acpi_smbus_hc_add()
308 hc->query_bit = val & 0xff; in acpi_smbus_hc_add()
309 device->driver_data = hc; in acpi_smbus_hc_add()
311 acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc); in acpi_smbus_hc_add()
313 hc->ec, hc->offset, hc->query_bit); in acpi_smbus_hc_add()
322 struct acpi_smb_hc *hc; in acpi_smbus_hc_remove() local
327 hc = acpi_driver_data(device); in acpi_smbus_hc_remove()
328 acpi_ec_remove_query_handler(hc->ec, hc->query_bit); in acpi_smbus_hc_remove()
329 kfree(hc); in acpi_smbus_hc_remove()