Changeset bb8f69d in mainline


Ignore:
Timestamp:
2012-04-12T15:54:57Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
95060d5b
Parents:
85f2064
Message:

rtc: add support to the dev_remove driver operation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    r85f2064 rbb8f69d  
    5555
    5656#define RTC_FROM_FNODE(fnode)  ((rtc_t *) ((fnode)->dev->driver_data))
     57#define RTC_FROM_DEV(devnode)  ((rtc_t *) ((devnode)->driver_data))
    5758
    5859typedef struct rtc {
     
    6970        /** true if a client is connected to the device */
    7071        bool client_connected;
     72        /** true if device is removed */
     73        bool removed;
    7174} rtc_t;
    7275
     
    8588static void rtc_default_handler(ddf_fun_t *fun,
    8689    ipc_callid_t callid, ipc_call_t *call);
     90static int rtc_dev_remove(ddf_dev_t *dev);
    8791
    8892
     
    9296static driver_ops_t rtc_ops = {
    9397        .dev_add = rtc_dev_add,
    94         .dev_remove = NULL, /* XXX */
     98        .dev_remove = rtc_dev_remove,
    9599};
    96100
     
    394398}
    395399
     400/** The dev_remove callback for the rtc driver
     401 *
     402 * @param dev   The RTC device
     403 *
     404 * @return      EOK on success or a negative error code
     405 */
     406static int
     407rtc_dev_remove(ddf_dev_t *dev)
     408{
     409        rtc_t *rtc = RTC_FROM_DEV(dev);
     410        int rc;
     411
     412        fibril_mutex_lock(&rtc->mutex);
     413        if (rtc->client_connected) {
     414                fibril_mutex_unlock(&rtc->mutex);
     415                return EBUSY;
     416        }
     417
     418        rtc->removed = true;
     419        fibril_mutex_unlock(&rtc->mutex);
     420
     421        rc = ddf_fun_unbind(rtc->fun);
     422        if (rc != EOK) {
     423                ddf_msg(LVL_ERROR, "Failed to unbind function");
     424                return rc;
     425        }
     426
     427        ddf_fun_destroy(rtc->fun);
     428        rtc_dev_cleanup(rtc);
     429
     430        return rc;
     431}
     432
    396433/** Default handler for client requests not handled
    397434 *  by the standard interface
     
    430467
    431468        if (rtc->client_connected)
    432                 rc = EBUSY;
     469                rc = ELIMIT;
     470        else if (rtc->removed)
     471                rc = ENXIO;
    433472        else {
    434473                rc = EOK;
Note: See TracChangeset for help on using the changeset viewer.